Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-12 22:41:52

0001 // -*- C++ -*-
0002 //
0003 // Package:    HGCalWaferInFileCheck
0004 // Class:      HGCalWaferInFileCheck
0005 //
0006 /**\class HGCalWaferInFileCheck HGCalWaferInFileCheck.cc
0007  test/HGCalWaferInFileCheck.cc
0008 
0009  Description: <one line class summary>
0010 
0011  Implementation:
0012      <Notes on implementation>
0013 */
0014 //
0015 // Original Author:  Sunanda Banerjee
0016 //         Created:  Mon 2020/06/24
0017 //
0018 //
0019 
0020 // system include files
0021 #include <fstream>
0022 #include <iostream>
0023 #include <memory>
0024 #include <string>
0025 #include <vector>
0026 
0027 // user include files
0028 #include "FWCore/Framework/interface/Frameworkfwd.h"
0029 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0030 #include "FWCore/Framework/interface/Event.h"
0031 #include "FWCore/Framework/interface/EventSetup.h"
0032 #include "FWCore/Framework/interface/MakerMacros.h"
0033 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0035 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0036 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0037 #include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
0038 #include "Geometry/HGCalCommonData/interface/HGCalWaferIndex.h"
0039 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0040 
0041 class HGCalWaferInFileCheck : public edm::one::EDAnalyzer<> {
0042 public:
0043   explicit HGCalWaferInFileCheck(const edm::ParameterSet&);
0044 
0045   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0046 
0047   void beginJob() override {}
0048   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0049   void endJob() override {}
0050 
0051 private:
0052   const std::string nameSense_, nameDetector_;
0053   const edm::ESGetToken<HGCalGeometry, IdealGeometryRecord> geomToken_;
0054 };
0055 
0056 HGCalWaferInFileCheck::HGCalWaferInFileCheck(const edm::ParameterSet& iC)
0057     : nameSense_(iC.getParameter<std::string>("NameSense")),
0058       nameDetector_(iC.getParameter<std::string>("NameDevice")),
0059       geomToken_(esConsumes<HGCalGeometry, IdealGeometryRecord>(edm::ESInputTag{"", nameSense_})) {
0060   edm::LogVerbatim("HGCalGeom") << "Test numbering for " << nameDetector_ << " using constants of " << nameSense_;
0061 }
0062 
0063 void HGCalWaferInFileCheck::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0064   edm::ParameterSetDescription desc;
0065   desc.add<std::string>("NameSense", "HGCalEESensitive");
0066   desc.add<std::string>("NameDevice", "HGCal EE");
0067   descriptions.add("hgcalEEWaferInFileCheck", desc);
0068 }
0069 
0070 // ------------ method called to produce the data  ------------
0071 void HGCalWaferInFileCheck::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0072   const auto& geomR = iSetup.getData(geomToken_);
0073   const HGCalGeometry* geom = &geomR;
0074   const auto& hgdc = geom->topology().dddConstants();
0075 
0076   edm::LogVerbatim("HGCalGeom") << nameDetector_ << "\nCheck Wafers in file are all valid for " << nameDetector_
0077                                 << "\n";
0078   if (hgdc.waferHexagon8()) {
0079     DetId::Detector det = (nameSense_ == "HGCalHESiliconSensitive") ? DetId::HGCalHSi : DetId::HGCalEE;
0080     static std::vector<std::string> types = {"F", "b", "g", "gm", "a", "d", "dm", "c", "am", "bm", "X"};
0081     // See if all entries in the file are valid
0082     int bad1(0);
0083     for (unsigned int k = 0; k < hgdc.waferFileSize(); ++k) {
0084       int indx = hgdc.waferFileIndex(k);
0085       int layer = HGCalWaferIndex::waferLayer(indx);
0086       int waferU = HGCalWaferIndex::waferU(indx);
0087       int waferV = HGCalWaferIndex::waferV(indx);
0088       int type = std::get<0>(hgdc.waferFileInfo(k));
0089       HGCSiliconDetId id(det, 1, type, layer, waferU, waferV, 0, 0);
0090       if (!geom->topology().validModule(id, 3)) {
0091         int part = std::get<1>(hgdc.waferFileInfoFromIndex(indx));
0092         std::string typex = (part < static_cast<int>(types.size())) ? types[part] : "X";
0093         const auto& xy = hgdc.waferPosition(layer, waferU, waferV, true, false);
0094         edm::LogVerbatim("HGCalGeom") << "ID[" << k << "]: (" << (hgdc.getLayerOffset() + layer) << ", " << waferU
0095                                       << ", " << waferV << ", " << typex << ") at (" << std::setprecision(4) << xy.first
0096                                       << ", " << xy.second << ", " << hgdc.waferZ(layer, true) << ") not valid";
0097         ++bad1;
0098       }
0099     }
0100     edm::LogVerbatim("HGCalGeom") << "\n\nFinds " << bad1 << " invalid wafers among " << hgdc.waferFileSize()
0101                                   << " wafers in the list\n";
0102 
0103     // See if some of the valid wafers are missing
0104     auto const& ids = geom->getValidGeomDetIds();
0105     int all(0), bad2(0), xtra(0);
0106     for (unsigned int k = 0; k < ids.size(); ++k) {
0107       HGCSiliconDetId id(ids[k]);
0108       if ((ids[k].rawId() != 0) && (id.zside() == 1)) {
0109         ++all;
0110         int indx = HGCalWaferIndex::waferIndex(id.layer(), id.waferU(), id.waferV());
0111         if (!hgdc.waferFileInfoExist(indx)) {
0112           int part = hgdc.waferTypeRotation(id.layer(), id.waferU(), id.waferV(), false, false).first;
0113           if (part != HGCalTypes::WaferOut) {
0114             std::string typex = (part < static_cast<int>(types.size())) ? types[part] : "X";
0115             const auto& xy = hgdc.waferPosition(id.layer(), id.waferU(), id.waferV(), true, false);
0116             edm::LogVerbatim("HGCalGeom")
0117                 << "ID[" << k << "]: (" << (hgdc.getLayerOffset() + id.layer()) << ", " << id.waferU() << ", "
0118                 << id.waferV() << ", " << typex << ")  at (" << std::setprecision(4) << xy.first << ", " << xy.second
0119                 << ", " << hgdc.waferZ(id.layer(), true) << ") not in wafer-list";
0120             ++bad2;
0121           } else {
0122             ++xtra;
0123           }
0124         }
0125       }
0126     }
0127     edm::LogVerbatim("HGCalGeom") << "\n\nFinds " << bad2 << " missing wafers among " << all << " valid wafers and "
0128                                   << xtra << " extra ones\n";
0129 
0130     // Now cross check the content
0131     int allG(0), badT(0), badP(0), badP2(0), badR(0), badG(0), badT1(0), badT2(0);
0132     for (unsigned int k = 0; k < hgdc.waferFileSize(); ++k) {
0133       int indx = hgdc.waferFileIndex(k);
0134       int type1 = std::get<0>(hgdc.waferFileInfo(k));
0135       int part1 = std::get<1>(hgdc.waferFileInfo(k));
0136       int rotn1 = std::get<2>(hgdc.waferFileInfo(k));
0137       int layer = HGCalWaferIndex::waferLayer(indx);
0138       int waferU = HGCalWaferIndex::waferU(indx);
0139       int waferV = HGCalWaferIndex::waferV(indx);
0140       int type2 = hgdc.waferType(layer, waferU, waferV, false);
0141       HGCSiliconDetId id(det, 1, type2, layer, waferU, waferV, 0, 0);
0142       if (geom->topology().validModule(id, 3)) {
0143         ++allG;
0144         int part2 = hgdc.waferTypeRotation(id.layer(), id.waferU(), id.waferV(), false, false).first;
0145         int rotn2 = hgdc.waferTypeRotation(id.layer(), id.waferU(), id.waferV(), false, false).second;
0146         bool typeOK = (type1 == type2);
0147         bool partOK = ((part1 == part2) || ((part1 == HGCalTypes::WaferFull) && (part2 == HGCalTypes::WaferOut)));
0148         bool rotnOK = ((rotn1 == rotn2) || (part1 == HGCalTypes::WaferFull) || (part2 == HGCalTypes::WaferFull));
0149         if (part1 < part2)
0150           ++badP2;
0151         if (!typeOK) {
0152           ++badT;
0153           if (type1 == 0)
0154             ++badT1;
0155           else if (type2 == 0)
0156             ++badT2;
0157         }
0158         if (!partOK)
0159           ++badP;
0160         if (!rotnOK)
0161           ++badR;
0162         if ((!typeOK) || (!partOK) || (!rotnOK)) {
0163           ++badG;
0164           std::string partx1 = (part1 < static_cast<int>(types.size())) ? types[part1] : "X";
0165           std::string partx2 = (part2 < static_cast<int>(types.size())) ? types[part2] : "X";
0166           const auto& xy = hgdc.waferPosition(layer, waferU, waferV, true, false);
0167           edm::LogVerbatim("HGCalGeom") << "ID[" << k << "]: (" << (hgdc.getLayerOffset() + layer) << ", " << waferU
0168                                         << ", " << waferV << ", " << type1 << ":" << type2 << ", " << partx1 << ":"
0169                                         << partx2 << ", " << rotn1 << ":" << rotn2 << ") at (" << std::setprecision(4)
0170                                         << xy.first << ", " << xy.second << ", " << hgdc.waferZ(layer, true)
0171                                         << ") failure flag " << typeOK << ":" << partOK << ":" << rotnOK << ":"
0172                                         << (part1 >= part2);
0173         }
0174       }
0175     }
0176     edm::LogVerbatim("HGCalGeom") << "\n\nFinds " << badG << " (" << badT << "[" << badT1 << ":" << badT2
0177                                   << "]:" << badP << ":" << badP2 << ":" << badR << ") mismatch among " << allG
0178                                   << " wafers with the same indices";
0179   }
0180 }
0181 
0182 // define this as a plug-in
0183 DEFINE_FWK_MODULE(HGCalWaferInFileCheck);