Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-08-04 22:45:10

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     edm::LogVerbatim("HGCalGeom")
0081         << "Old Partial types: 1|Five, 2|ChopTwo, 3|ChopTwoM, 4|Half, 5|Semi, 6|Semi2, 7|Three, 8|Half2, 9|Five2\nNew "
0082            "Partial types: 11|LDTop, 12|LDBottom, 13|LDLeft, 14|LDRight, 15|LDFive, 16|LDThree, 21|HDTop, 22|HDBottom, "
0083            "23|HDLeft, 24|HDRight, 25|HDFive\nCommon Partial types: 0|Full, 99|Out";
0084     // See if all entries in the file are valid
0085     int bad1(0);
0086     for (unsigned int k = 0; k < hgdc.waferFileSize(); ++k) {
0087       int indx = hgdc.waferFileIndex(k);
0088       int layer = HGCalWaferIndex::waferLayer(indx);
0089       int waferU = HGCalWaferIndex::waferU(indx);
0090       int waferV = HGCalWaferIndex::waferV(indx);
0091       int type = std::get<0>(hgdc.waferFileInfo(k));
0092       HGCSiliconDetId id(det, 1, type, layer, waferU, waferV, 0, 0);
0093       if (!geom->topology().validModule(id, 3)) {
0094         int part = std::get<1>(hgdc.waferFileInfoFromIndex(indx));
0095         const auto& xy = hgdc.waferPosition(layer, waferU, waferV, true, false);
0096         edm::LogVerbatim("HGCalGeom") << "ID[" << k << "]: (" << (hgdc.getLayerOffset() + layer) << ", " << waferU
0097                                       << ", " << waferV << ", " << part << ") at (" << std::setprecision(4) << xy.first
0098                                       << ", " << xy.second << ", " << hgdc.waferZ(layer, true) << ") not valid";
0099         ++bad1;
0100       }
0101     }
0102     edm::LogVerbatim("HGCalGeom") << "\n\nFinds " << bad1 << " invalid wafers among " << hgdc.waferFileSize()
0103                                   << " wafers in the list\n";
0104 
0105     // See if some of the valid wafers are missing
0106     auto const& ids = geom->getValidGeomDetIds();
0107     int all(0), bad2(0), xtra(0);
0108     for (unsigned int k = 0; k < ids.size(); ++k) {
0109       HGCSiliconDetId id(ids[k]);
0110       if ((ids[k].rawId() != 0) && (id.zside() == 1)) {
0111         ++all;
0112         int indx = HGCalWaferIndex::waferIndex(id.layer(), id.waferU(), id.waferV());
0113         if (!hgdc.waferFileInfoExist(indx)) {
0114           int part = hgdc.waferTypeRotation(id.layer(), id.waferU(), id.waferV(), false, false).first;
0115           if (part != HGCalTypes::WaferOut) {
0116             const auto& xy = hgdc.waferPosition(id.layer(), id.waferU(), id.waferV(), true, false);
0117             edm::LogVerbatim("HGCalGeom")
0118                 << "ID[" << k << "]: (" << (hgdc.getLayerOffset() + id.layer()) << ", " << id.waferU() << ", "
0119                 << id.waferV() << ", " << part << ")  at (" << std::setprecision(4) << xy.first << ", " << xy.second
0120                 << ", " << hgdc.waferZ(id.layer(), true) << ") not in wafer-list";
0121             ++bad2;
0122           } else {
0123             ++xtra;
0124           }
0125         }
0126       }
0127     }
0128     edm::LogVerbatim("HGCalGeom") << "\n\nFinds " << bad2 << " missing wafers among " << all << " valid wafers and "
0129                                   << xtra << " extra ones\n";
0130 
0131     // Now cross check the content
0132     int allG(0), badT(0), badP(0), badP2(0), badR(0), badG(0), badT1(0), badT2(0);
0133     for (unsigned int k = 0; k < hgdc.waferFileSize(); ++k) {
0134       int indx = hgdc.waferFileIndex(k);
0135       int type1 = std::get<0>(hgdc.waferFileInfo(k));
0136       int part1 = std::get<1>(hgdc.waferFileInfo(k));
0137       int rotn1 = std::get<2>(hgdc.waferFileInfo(k));
0138       int layer = HGCalWaferIndex::waferLayer(indx);
0139       int waferU = HGCalWaferIndex::waferU(indx);
0140       int waferV = HGCalWaferIndex::waferV(indx);
0141       int type2 = hgdc.waferType(layer, waferU, waferV, false);
0142       HGCSiliconDetId id(det, 1, type2, layer, waferU, waferV, 0, 0);
0143       if (geom->topology().validModule(id, 3)) {
0144         ++allG;
0145         int part2 = hgdc.waferTypeRotation(id.layer(), id.waferU(), id.waferV(), false, false).first;
0146         int rotn2 = hgdc.waferTypeRotation(id.layer(), id.waferU(), id.waferV(), false, false).second;
0147         bool typeOK = (type1 == type2);
0148         bool partOK = ((part1 == part2) || ((part1 == HGCalTypes::WaferFull) && (part2 == HGCalTypes::WaferOut)) ||
0149                        ((part2 == HGCalTypes::WaferFull) && (part1 != HGCalTypes::WaferOut)));
0150         bool rotnOK = ((rotn1 == rotn2) || (part1 == HGCalTypes::WaferFull) || (part2 == HGCalTypes::WaferFull));
0151         if (part1 < part2)
0152           ++badP2;
0153         if (!typeOK) {
0154           ++badT;
0155           if (type1 == 0)
0156             ++badT1;
0157           else if (type2 == 0)
0158             ++badT2;
0159         }
0160         if (!partOK)
0161           ++badP;
0162         if (!rotnOK)
0163           ++badR;
0164         if ((!typeOK) || (!partOK) || (!rotnOK)) {
0165           ++badG;
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 << ", " << part1 << ":"
0169                                         << part2 << ", " << 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);