Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:53

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 
0016 #include "SimDataFormats/CaloHit/interface/PCaloHit.h"
0017 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
0018 
0019 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0020 #include "Geometry/CaloTopology/interface/HGCalTopology.h"
0021 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0022 #include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
0023 #include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
0024 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0025 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0026 
0027 #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"
0028 
0029 #include <string>
0030 #include <vector>
0031 
0032 class HGCalToolTesterPartialWafer : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0033 public:
0034   HGCalToolTesterPartialWafer(const edm::ParameterSet& ps);
0035   ~HGCalToolTesterPartialWafer() override = default;
0036   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0037 
0038 protected:
0039   void beginRun(edm::Run const&, edm::EventSetup const&) override;
0040   void analyze(edm::Event const&, edm::EventSetup const&) override;
0041   void endRun(edm::Run const&, edm::EventSetup const&) override {}
0042   void beginJob() override {}
0043   void endJob() override {}
0044 
0045 private:
0046   const std::string g4Label_, caloHitSource_, nameSense_;
0047   const edm::EDGetTokenT<edm::PCaloHitContainer> tok_calo_;
0048   const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geomToken_;
0049   const HGCalGeometry* geom_;
0050   CaloGeometry geo_;
0051   hgcal::RecHitTools tool_;
0052 };
0053 
0054 HGCalToolTesterPartialWafer::HGCalToolTesterPartialWafer(const edm::ParameterSet& ps)
0055     : g4Label_(ps.getParameter<std::string>("moduleLabel")),
0056       caloHitSource_(ps.getParameter<std::string>("caloHitSource")),
0057       nameSense_(ps.getParameter<std::string>("nameSense")),
0058       tok_calo_(consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, caloHitSource_))),
0059       geomToken_(esConsumes<CaloGeometry, CaloGeometryRecord, edm::Transition::BeginRun>()),
0060       geom_(nullptr) {
0061   edm::LogVerbatim("HGCalSim") << "Test Hit ID using SimHits for " << nameSense_ << " with module Label: " << g4Label_
0062                                << "   Hits: " << caloHitSource_;
0063 }
0064 
0065 void HGCalToolTesterPartialWafer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0066   edm::ParameterSetDescription desc;
0067   desc.add<std::string>("moduleLabel", "g4SimHits");
0068   desc.add<std::string>("caloHitSource", "HGCHitsEE");
0069   desc.add<std::string>("nameSense", "HGCalEESensitive");
0070   descriptions.add("hgcalToolTesterPartialWaferEE", desc);
0071 }
0072 
0073 void HGCalToolTesterPartialWafer::beginRun(const edm::Run&, const edm::EventSetup& iSetup) {
0074   //Setup the tool
0075   geo_ = iSetup.getData(geomToken_);
0076   geom_ = (nameSense_ == "HGCalEESensitive") ? static_cast<const HGCalGeometry*>(geo_.getSubdetectorGeometry(
0077                                                    DetId::HGCalEE, ForwardSubdetector::ForwardEmpty))
0078                                              : static_cast<const HGCalGeometry*>(geo_.getSubdetectorGeometry(
0079                                                    DetId::HGCalHSi, ForwardSubdetector::ForwardEmpty));
0080   edm::LogVerbatim("HGCalSim") << "HGCalToolTesterPartialWafer: beginRun Called for " << nameSense_;
0081 }
0082 
0083 void HGCalToolTesterPartialWafer::analyze(const edm::Event& e, const edm::EventSetup& iS) {
0084   // get HGCal geometry constant
0085   tool_.setGeometry(geo_);
0086   const HGCalDDDConstants& hgc = geom_->topology().dddConstants();
0087 
0088   // get the hit collection
0089   const edm::Handle<edm::PCaloHitContainer>& hitsCalo = e.getHandle(tok_calo_);
0090   bool getHits = (hitsCalo.isValid());
0091   uint32_t nhits = (getHits) ? hitsCalo->size() : 0;
0092   uint32_t good(0), allSi(0), all(0);
0093   edm::LogVerbatim("HGCalSim") << "HGCalToolTesterPartialWafer: Input flags Hits " << getHits << " with " << nhits
0094                                << " hits";
0095 
0096   if (getHits) {
0097     std::vector<PCaloHit> hits;
0098     hits.insert(hits.end(), hitsCalo->begin(), hitsCalo->end());
0099     if (!hits.empty()) {
0100       // Loop over all hits
0101       for (auto hit : hits) {
0102         ++all;
0103         DetId id(hit.id());
0104         if ((id.det() == DetId::HGCalEE) || (id.det() == DetId::HGCalHSi)) {
0105           ++allSi;
0106           HGCSiliconDetId hid(id);
0107           const auto& info = hgc.waferInfo(hid.layer(), hid.waferU(), hid.waferV());
0108           // Only partial wafers
0109           if (info.part != HGCalTypes::WaferFull) {
0110             ++good;
0111             GlobalPoint pos1 = geom_->getPosition(id);
0112             GlobalPoint pos2 = tool_.getPosition(id);
0113             edm::LogVerbatim("HGCalSim") << "Hit[" << all << ":" << allSi << ":" << good << "]" << HGCSiliconDetId(id)
0114                                          << " Wafer Type:Part:Orient:Cassette " << info.type << ":" << info.part << ":"
0115                                          << info.orient << ":" << info.cassette << " at (" << pos1.x() << ", "
0116                                          << pos1.y() << ", " << pos1.z() << ") or (" << pos2.x() << ", " << pos2.y()
0117                                          << ", " << pos2.z() << ")";
0118           }
0119         }
0120       }
0121     }
0122   }
0123   edm::LogVerbatim("HGCalSim") << "Total hits = " << all << ":" << nhits << " Good DetIds = " << allSi << ":" << good;
0124 }
0125 
0126 //define this as a plug-in
0127 DEFINE_FWK_MODULE(HGCalToolTesterPartialWafer);