CMS 3D CMS Logo

MTDDigitizer.h
Go to the documentation of this file.
1 #ifndef FastTimingSimProducers_FastTimingCommon_MTDDigitizer_h
2 #define FastTimingSimProducers_FastTimingCommon_MTDDigitizer_h
3 
6 
9 
14 
16 
17 #include <vector>
18 #include <unordered_map>
19 #include <unordered_set>
20 #include <memory>
21 #include <tuple>
22 
23 
24 namespace mtd_digitizer {
25 
26  namespace MTDHelpers {
27  // index , det id, time
28  typedef std::tuple<int,uint32_t,float> MTDCaloHitTuple_t;
29 
30  bool orderByDetIdThenTime(const MTDCaloHitTuple_t &a, const MTDCaloHitTuple_t &b)
31  {
32  unsigned int detId_a(std::get<1>(a)), detId_b(std::get<1>(b));
33 
34  if(detId_a<detId_b) return true;
35  if(detId_a>detId_b) return false;
36 
37  double time_a(std::get<2>(a)), time_b(std::get<2>(b));
38  if(time_a<time_b) return true;
39 
40  return false;
41  }
42  }
43 
44  template<class Traits>
46  {
47  public:
48 
49  typedef typename Traits::DeviceSim DeviceSim ;
50  typedef typename Traits::ElectronicsSim ElectronicsSim;
51  typedef typename Traits::DigiCollection DigiCollection;
52 
56  MTDDigitizerBase(config,iC,parent),
57  deviceSim_( config.getParameterSet("DeviceSimulation") ),
58  electronicsSim_( config.getParameterSet("ElectronicsSimulation") ),
59  maxSimHitsAccTime_( config.getParameter< uint32_t >("maxSimHitsAccTime") ) { }
60 
61  ~MTDDigitizer() override { }
62 
66  void accumulate(edm::Event const& e, edm::EventSetup const& c, CLHEP::HepRandomEngine* hre) override;
67  void accumulate(PileUpEventPrincipal const& e, edm::EventSetup const& c, CLHEP::HepRandomEngine* hre) override;
68  void accumulate(edm::Handle<edm::PSimHitContainer> const &hits, int bxCrossing, CLHEP::HepRandomEngine* hre) override;
69 
73  void initializeEvent(edm::Event const& e, edm::EventSetup const& c) override;
74  void finalizeEvent(edm::Event& e, edm::EventSetup const& c, CLHEP::HepRandomEngine* hre) override;
75 
79  void beginRun(const edm::EventSetup & es) override;
80  void endRun() override {}
81 
82  private :
83 
85  MTDSimHitDataAccumulator().swap(simHitAccumulator_);
86  }
87 
88  // implementations
89  DeviceSim deviceSim_; // processes a given simhit into an entry in a MTDSimHitDataAccumulator
90  ElectronicsSim electronicsSim_; // processes a MTDSimHitDataAccumulator into a BTLDigiCollection/ETLDigiCollection
91 
92  //handle sim hits
93  const int maxSimHitsAccTime_;
95 
96  };
97 
98  template<class Traits>
100  edm::EventSetup const& c,
101  CLHEP::HepRandomEngine* hre) {
103  e.getByLabel(inputSimHits_, simHits);
104  accumulate(simHits,0,hre);
105  }
106 
107  template<class Traits>
109  edm::EventSetup const& c,
110  CLHEP::HepRandomEngine* hre){
112  e.getByLabel(inputSimHits_, simHits);
113  accumulate(simHits,e.bunchCrossing(),hre);
114  }
115 
116  template<class Traits>
118  int bxCrossing,
119  CLHEP::HepRandomEngine* hre) {
120  using namespace MTDHelpers;
121 
122  //create list of tuples (pos in container, RECO DetId, time) to be sorted first
123  int nchits=(int)hits->size();
124  std::vector< MTDCaloHitTuple_t > hitRefs;
125  hitRefs.reserve(nchits);
126  for(int i=0; i<nchits; ++i) {
127  const auto& the_hit = hits->at(i);
128 
129  DetId id = the_hit.detUnitId();
130 
131  if (verbosity_>0) {
132  edm::LogInfo("MTDDigitizer") << " i/p " << std::hex << the_hit.detUnitId() << std::dec
133  << " o/p " << id.rawId() << std::endl;
134  }
135 
136  if( 0 != id.rawId() ) {
137  hitRefs.emplace_back( i, id.rawId(), the_hit.tof() );
138  }
139  }
140  std::sort(hitRefs.begin(),hitRefs.end(),MTDHelpers::orderByDetIdThenTime);
141 
142  deviceSim_.getHitsResponse(hitRefs, hits, &simHitAccumulator_, hre);
143 
144  hitRefs.clear();
145 
146  }
147 
148  template<class Traits>
150  deviceSim_.getEvent(e);
151  electronicsSim_.getEvent(e);
152  }
153 
154  template<class Traits>
156  CLHEP::HepRandomEngine* hre) {
157 
158  auto digiCollection = std::make_unique<DigiCollection>();
159  electronicsSim_.run(simHitAccumulator_,*digiCollection, hre);
160  e.put(std::move(digiCollection),digiCollection_);
161 
162  //release memory for next event
163  resetSimHitDataAccumulator();
164  }
165 
166 
167  template<class Traits>
169  deviceSim_.getEventSetup(es);
170  electronicsSim_.getEventSetup(es);
171  }
172 }
173 
174 #endif
void accumulate(edm::Event const &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *hre) override
handle SimHit accumulation
Definition: MTDDigitizer.h:99
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
ParameterSet const & getParameterSet(ParameterSetID const &id)
MTDSimHitDataAccumulator simHitAccumulator_
Definition: MTDDigitizer.h:94
Definition: config.py:1
void finalizeEvent(edm::Event &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *hre) override
Definition: MTDDigitizer.h:155
void beginRun(const edm::EventSetup &es) override
actions at the start/end of run
Definition: MTDDigitizer.h:168
Traits::ElectronicsSim ElectronicsSim
Definition: MTDDigitizer.h:50
Traits::DigiCollection DigiCollection
Definition: MTDDigitizer.h:51
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:535
void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
actions at the start/end of event
Definition: MTDDigitizer.h:149
Definition: DetId.h:18
bool orderByDetIdThenTime(const MTDCaloHitTuple_t &a, const MTDCaloHitTuple_t &b)
Definition: MTDDigitizer.h:30
double b
Definition: hdecay.h:120
std::tuple< int, uint32_t, float > MTDCaloHitTuple_t
Definition: MTDDigitizer.h:28
std::unordered_map< uint32_t, MTDCellInfo > MTDSimHitDataAccumulator
double a
Definition: hdecay.h:121
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
MTDDigitizer(const edm::ParameterSet &config, edm::ConsumesCollector &iC, edm::ProducerBase &parent)
Definition: MTDDigitizer.h:53
ElectronicsSim electronicsSim_
Definition: MTDDigitizer.h:90
Traits::DeviceSim DeviceSim
Definition: MTDDigitizer.h:49
def move(src, dest)
Definition: eostools.py:510