Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-22 04:08:42

0001 // -*- C++ -*-
0002 //
0003 // Package:     SimG4CMS/Calo
0004 // Class  :     CaloTrkProcessingBuilder
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Sunanda Banerjee
0010 //         Created:  Tue, 12 Jul 2021 23:18:17 GMT
0011 //
0012 
0013 // system include files
0014 #include <string>
0015 #include <vector>
0016 
0017 // user include files
0018 #include "SimG4Core/SensitiveDetector/interface/SensitiveDetectorMakerBase.h"
0019 #include "SimG4Core/Notification/interface/SimActivityRegistryEnroller.h"
0020 #include "SimG4Core/SensitiveDetector/interface/SensitiveDetectorPluginFactory.h"
0021 
0022 #include "CondFormats/GeometryObjects/interface/CaloSimulationParameters.h"
0023 #include "Geometry/Records/interface/HcalParametersRcd.h"
0024 #include "SimG4CMS/Calo/interface/CaloTrkProcessing.h"
0025 
0026 #include "FWCore/Framework/interface/ESHandle.h"
0027 #include "FWCore/Framework/interface/EventSetup.h"
0028 #include "FWCore/Framework/interface/ConsumesCollector.h"
0029 #include "FWCore/Utilities/interface/ESGetToken.h"
0030 #include "FWCore/PluginManager/interface/ModuleDef.h"
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0032 
0033 class CaloTrkProcessingBuilder : public SensitiveDetectorMakerBase {
0034 public:
0035   explicit CaloTrkProcessingBuilder(edm::ParameterSet const& p, edm::ConsumesCollector cc)
0036       : cspsToken_{cc.esConsumes<edm::Transition::BeginRun>()}, caloSimPar_{nullptr} {
0037     bool dd4hep = p.getParameter<bool>("g4GeometryDD4hepSource");
0038     addlevel_ = dd4hep ? 1 : 0;
0039     edm::ParameterSet csps = p.getParameter<edm::ParameterSet>("CaloTrkProcessing");
0040     testBeam_ = csps.getParameter<bool>("TestBeam");
0041     eMin_ = csps.getParameter<double>("EminTrack") * CLHEP::MeV;
0042     putHistory_ = csps.getParameter<bool>("PutHistory");
0043     doFineCalo_ = csps.getParameter<bool>("DoFineCalo");
0044     eMinFine_ = csps.getParameter<double>("EminFineTrack") * CLHEP::MeV;
0045     fineNames_ = csps.getParameter<std::vector<std::string> >("FineCaloNames");
0046     fineLevels_ = csps.getParameter<std::vector<int> >("FineCaloLevels");
0047     useFines_ = csps.getParameter<std::vector<int> >("UseFineCalo");
0048     for (auto& level : fineLevels_)
0049       level += addlevel_;
0050   }
0051 
0052   void beginRun(const edm::EventSetup& es) final { caloSimPar_ = &es.getData(cspsToken_); }
0053 
0054   std::unique_ptr<SensitiveDetector> make(const std::string& iname,
0055                                           const SensitiveDetectorCatalog& clg,
0056                                           const edm::ParameterSet& p,
0057                                           const SimTrackManager* man,
0058                                           SimActivityRegistry& reg) const final {
0059     auto sd = std::make_unique<CaloTrkProcessing>(iname,
0060                                                   *caloSimPar_,
0061                                                   clg,
0062                                                   testBeam_,
0063                                                   eMin_,
0064                                                   putHistory_,
0065                                                   doFineCalo_,
0066                                                   eMinFine_,
0067                                                   addlevel_,
0068                                                   fineNames_,
0069                                                   fineLevels_,
0070                                                   useFines_,
0071                                                   man);
0072     SimActivityRegistryEnroller::enroll(reg, sd.get());
0073     return sd;
0074   }
0075 
0076 private:
0077   const edm::ESGetToken<CaloSimulationParameters, HcalParametersRcd> cspsToken_;
0078   const CaloSimulationParameters* caloSimPar_;
0079   bool testBeam_;
0080   double eMin_;
0081   bool putHistory_;
0082   bool doFineCalo_;
0083   double eMinFine_;
0084   int addlevel_;
0085   std::vector<std::string> fineNames_;
0086   std::vector<int> fineLevels_;
0087   std::vector<int> useFines_;
0088 };
0089 
0090 DEFINE_SENSITIVEDETECTORBUILDER(CaloTrkProcessingBuilder, CaloTrkProcessing);