Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:50

0001 #include "FWCore/Framework/interface/Frameworkfwd.h"
0002 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0003 
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0010 #include "FWCore/Utilities/interface/InputTag.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "FWCore/Utilities/interface/Exception.h"
0013 
0014 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0015 #include "DataFormats/ForwardDetId/interface/HGCScintillatorDetId.h"
0016 
0017 #include "SimDataFormats/CaloHit/interface/PCaloHit.h"
0018 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
0019 
0020 #include "Geometry/CaloTopology/interface/HGCalTopology.h"
0021 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0022 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0023 
0024 #include <map>
0025 #include <string>
0026 #include <vector>
0027 
0028 class HGcalHitIdCheck : public edm::one::EDAnalyzer<> {
0029 public:
0030   HGcalHitIdCheck(const edm::ParameterSet& ps);
0031   ~HGcalHitIdCheck() override {}
0032   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0033 
0034 protected:
0035   void analyze(edm::Event const&, edm::EventSetup const&) override;
0036   void beginJob() override {}
0037   void endJob() override {}
0038 
0039 private:
0040   const std::string g4Label_, caloHitSource_, nameSense_, nameDetector_;
0041   const int verbosity_;
0042   const edm::EDGetTokenT<edm::PCaloHitContainer> tok_calo_;
0043   const edm::ESGetToken<HGCalGeometry, IdealGeometryRecord> geomToken_;
0044 };
0045 
0046 HGcalHitIdCheck::HGcalHitIdCheck(const edm::ParameterSet& ps)
0047     : g4Label_(ps.getParameter<std::string>("moduleLabel")),
0048       caloHitSource_(ps.getParameter<std::string>("caloHitSource")),
0049       nameSense_(ps.getParameter<std::string>("nameSense")),
0050       nameDetector_(ps.getParameter<std::string>("nameDevice")),
0051       verbosity_(ps.getParameter<int>("Verbosity")),
0052       tok_calo_(consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, caloHitSource_))),
0053       geomToken_(esConsumes<HGCalGeometry, IdealGeometryRecord>(edm::ESInputTag{"", nameSense_})) {
0054   edm::LogVerbatim("HitStudy") << "Test Hit ID for " << nameDetector_ << " using SimHits for " << nameSense_
0055                                << " with module Label: " << g4Label_ << "   Hits: " << caloHitSource_;
0056 }
0057 
0058 void HGcalHitIdCheck::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0059   edm::ParameterSetDescription desc;
0060   desc.add<std::string>("moduleLabel", "g4SimHits");
0061   desc.add<std::string>("caloHitSource", "HGCHitsEE");
0062   desc.add<std::string>("nameSense", "HGCalEESensitive");
0063   desc.add<std::string>("nameDevice", "HGCal EE");
0064   desc.add<int>("Verbosity", 0);
0065   descriptions.add("hgcalHitIdCheckEE", desc);
0066 }
0067 
0068 void HGcalHitIdCheck::analyze(const edm::Event& e, const edm::EventSetup& iS) {
0069   if (verbosity_ > 0)
0070     edm::LogVerbatim("HitStudy") << "Run = " << e.id().run() << " Event = " << e.id().event();
0071 
0072   // get hcalGeometry
0073   const HGCalGeometry* geom = &iS.getData(geomToken_);
0074   const std::vector<DetId>& validIds = geom->getValidDetIds();
0075 
0076   const edm::Handle<edm::PCaloHitContainer>& hitsCalo = e.getHandle(tok_calo_);
0077   bool getHits = (hitsCalo.isValid());
0078   uint32_t nhits = (getHits) ? hitsCalo->size() : 0;
0079   uint32_t good(0), all(0);
0080   if (verbosity_ > 1)
0081     edm::LogVerbatim("HitStudy") << "HGcalHitIdCheck: Input flags Hits " << getHits << " with " << nhits << " hits";
0082 
0083   if (getHits) {
0084     std::vector<PCaloHit> hits;
0085     hits.insert(hits.end(), hitsCalo->begin(), hitsCalo->end());
0086     if (!hits.empty()) {
0087       for (auto hit : hits) {
0088         ++all;
0089         DetId id(hit.id());
0090         if (std::find(validIds.begin(), validIds.end(), id) != validIds.end()) {
0091           ++good;
0092           if (verbosity_ > 2) {
0093             if ((id.det() == DetId::HGCalEE) || (id.det() == DetId::HGCalHSi)) {
0094               edm::LogVerbatim("HitStudy") << "Hit[" << all << ":" << good << "]" << HGCSiliconDetId(id);
0095             } else if (id.det() == DetId::HGCalHSc) {
0096               edm::LogVerbatim("HitStudy") << "Hit[" << all << ":" << good << "]" << HGCScintillatorDetId(id);
0097             } else {
0098               edm::LogVerbatim("HitStudy") << "Hit[" << all << ":" << good << "]" << std::hex << id.rawId() << std::dec;
0099             }
0100           }
0101         } else {
0102           if (verbosity_ > 0) {
0103             if ((id.det() == DetId::HGCalEE) || (id.det() == DetId::HGCalHSi)) {
0104               edm::LogVerbatim("HitStudy")
0105                   << "Hit[" << all << ":" << good << "]" << HGCSiliconDetId(id) << " not valid *****";
0106             } else if (id.det() == DetId::HGCalHSc) {
0107               HGCScintillatorDetId hid1(id);
0108               HGCScintillatorDetId hid2(hid1.type(), hid1.layer(), hid1.ring(), hid1.iphi(), false, 0);
0109               bool ok = (std::find(validIds.begin(), validIds.end(), DetId(hid2)) != validIds.end());
0110               edm::LogVerbatim("HitStudy") << "Hit[" << all << ":" << good << "]" << hid1 << " not valid ***** but "
0111                                            << hid2 << " in list " << ok;
0112             } else {
0113               edm::LogVerbatim("HitStudy")
0114                   << "Hit[" << all << ":" << good << "]" << std::hex << id.rawId() << std::dec << " not valid *****";
0115             }
0116           }
0117         }
0118       }
0119     }
0120   }
0121   edm::LogVerbatim("HitStudy") << "Total hits = " << all << ":" << nhits << " Good DetIds = " << good
0122                                << " Invalid DetIds = " << (all - good);
0123 }
0124 
0125 //define this as a plug-in
0126 DEFINE_FWK_MODULE(HGcalHitIdCheck);