Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-29 22:51:24

0001 
0002 // system include files
0003 #include <string>
0004 #include <vector>
0005 
0006 // user include files
0007 #include "SimG4Core/SensitiveDetector/interface/SensitiveDetectorMakerBase.h"
0008 #include "SimG4Core/Notification/interface/SimActivityRegistryEnroller.h"
0009 #include "SimG4Core/SensitiveDetector/interface/SensitiveDetectorPluginFactory.h"
0010 
0011 #include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
0012 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0013 #include "SimG4CMS/Calo/interface/HGCalSD.h"
0014 
0015 #include "FWCore/Framework/interface/ConsumesCollector.h"
0016 #include "FWCore/Framework/interface/ESHandle.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 #include "FWCore/Utilities/interface/ESGetToken.h"
0019 #include "FWCore/PluginManager/interface/ModuleDef.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 
0022 //#define EDM_ML_DEBUG
0023 
0024 class HGCalSensitiveDetectorBuilder : public SensitiveDetectorMakerBase {
0025 public:
0026   explicit HGCalSensitiveDetectorBuilder(edm::ParameterSet const& p, edm::ConsumesCollector cc)
0027       : hgcEEToken_{cc.esConsumes<edm::Transition::BeginRun>(edm::ESInputTag{"", "HGCalEESensitive"})},
0028         hgcHEToken_{cc.esConsumes<edm::Transition::BeginRun>(edm::ESInputTag{"", "HGCalHESiliconSensitive"})} {
0029     edm::ParameterSet m_HGC = p.getParameter<edm::ParameterSet>("HGCSD");
0030     int num = m_HGC.getUntrackedParameter<int>("UseDetector");
0031     doEE_ = ((num % 2) == 1);
0032     doHE_ = (((num / 2) % 2) == 1);
0033   }
0034 
0035   void beginRun(const edm::EventSetup& es) final {
0036     if (doEE_)
0037       hgcalEE_ = es.getHandle(hgcEEToken_);
0038     if (doHE_)
0039       hgcalHE_ = es.getHandle(hgcHEToken_);
0040   }
0041 
0042   std::unique_ptr<SensitiveDetector> make(const std::string& iname,
0043                                           const SensitiveDetectorCatalog& clg,
0044                                           const edm::ParameterSet& p,
0045                                           const SimTrackManager* man,
0046                                           SimActivityRegistry& reg) const final {
0047     auto hgc =
0048         (((iname.find("HitsEE") != std::string::npos) && doEE_ && hgcalEE_.isValid())
0049              ? hgcalEE_.product()
0050              : (((iname.find("HitsHEfront") != std::string::npos) && doHE_ && hgcalHE_.isValid()) ? hgcalHE_.product()
0051                                                                                                   : nullptr));
0052     auto sd = std::make_unique<HGCalSD>(iname, hgc, clg, p, man);
0053     SimActivityRegistryEnroller::enroll(reg, sd.get());
0054 #ifdef EDM_ML_DEBUG
0055     const auto& dets = clg.logicalNames(iname);
0056     edm::LogVerbatim("HGCSim") << "HGCalSensitiveDetectorBuilder for " << iname << " utilizes " << dets.size()
0057                                << " detectors";
0058     for (unsigned int k = 0; k < dets.size(); ++k)
0059       edm::LogVerbatim("HGCSim") << "Detector [" << k << "] " << dets[k];
0060 #endif
0061     return sd;
0062   }
0063 
0064 private:
0065   const edm::ESGetToken<HGCalDDDConstants, IdealGeometryRecord> hgcEEToken_;
0066   const edm::ESGetToken<HGCalDDDConstants, IdealGeometryRecord> hgcHEToken_;
0067   bool doEE_, doHE_;
0068   edm::ESHandle<HGCalDDDConstants> hgcalEE_, hgcalHE_;
0069 };
0070 
0071 typedef HGCalSD HGCalSensitiveDetector;
0072 DEFINE_SENSITIVEDETECTORBUILDER(HGCalSensitiveDetectorBuilder, HGCalSensitiveDetector);