CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloTDigitizer.h
Go to the documentation of this file.
1 #ifndef CaloSimAlgos_CaloTDigitizer_h
2 #define CaloSimAlgos_CaloTDigitizer_h
3 
14 #include <cassert>
15 #include <vector>
16 
17 namespace CLHEP {
18  class HepRandomEngine;
19 }
20 
21 template<class Traits>
23 public:
24  typedef typename Traits::ElectronicsSim ElectronicsSim;
25  typedef typename Traits::Digi Digi;
26  typedef typename Traits::DigiCollection DigiCollection;
27 
28  void operator()(DigiCollection & output, CLHEP::HepRandomEngine* engine, CaloSamples * analogSignal, std::vector<DetId>::const_iterator idItr, ElectronicsSim* theElectronicsSim){
29  Digi digi(*idItr);
30  theElectronicsSim->analogToDigital(engine, *analogSignal , digi);
31  output.push_back(std::move(digi));
32  }
33 
34 };
35 
36 //second parameter changes the operation of run() slightly (default value for old-style with edm::SortedCollection instead of edm::DataFrameContainer)
37 template<class Traits, template <class> class runHelper=CaloTDigitizerDefaultRun>
39 {
40 public:
44  typedef typename Traits::ElectronicsSim ElectronicsSim;
45  typedef typename Traits::Digi Digi;
46  typedef typename Traits::DigiCollection DigiCollection;
47 
48  CaloTDigitizer(CaloHitResponse * hitResponse, ElectronicsSim * electronicsSim, bool addNoise)
49  : theHitResponse(hitResponse),
52  theElectronicsSim(electronicsSim),
53  theDetIds(0),
54  addNoise_(addNoise)
55  {
56  }
57 
58 
61 
63  const std::vector<DetId>& detIds() const {assert( 0 != theDetIds ) ; return *theDetIds;}
64  void setDetIds(const std::vector<DetId> & detIds) {theDetIds = &detIds;}
65 
67  {
69  }
70 
72  {
74  }
75 
76  void add(const std::vector<PCaloHit> & hits, int bunchCrossing, CLHEP::HepRandomEngine* engine) {
77  if(theHitResponse->withinBunchRange(bunchCrossing)) {
78  for(std::vector<PCaloHit>::const_iterator it = hits.begin(), itEnd = hits.end(); it != itEnd; ++it) {
79  theHitResponse->add(*it, engine);
80  }
81  }
82  }
83 
84  void initializeHits() {
86  }
87 
90  assert(0);
91  }
92 
94 
95  void run(DigiCollection & output, CLHEP::HepRandomEngine* engine) {
97  //std::cout << " In CaloTDigitizer, after finalize hits " << std::endl;
98 
99  assert(theDetIds->size() != 0);
100 
101  if(theNoiseHitGenerator != 0) addNoiseHits(engine);
102  if(theNoiseSignalGenerator != 0) addNoiseSignals(engine);
103 
104  theElectronicsSim->newEvent(engine);
105 
106  // reserve space for how many digis we expect
107  int nDigisExpected = addNoise_ ? theDetIds->size() : theHitResponse->nSignals();
108  output.reserve(nDigisExpected);
109 
110  // make a raw digi for evey cell
111  for(std::vector<DetId>::const_iterator idItr = theDetIds->begin();
112  idItr != theDetIds->end(); ++idItr)
113  {
114  CaloSamples * analogSignal = theHitResponse->findSignal(*idItr);
115  bool needToDeleteSignal = false;
116  // don't bother digitizing if no signal and no noise
117  if(analogSignal == 0 && addNoise_) {
118  // I guess we need to make a blank signal for this cell.
119  // Don't bother storing it anywhere.
120  analogSignal = new CaloSamples(theHitResponse->makeBlankSignal(*idItr));
121  needToDeleteSignal = true;
122  }
123  if(analogSignal != 0) {
124  runAnalogToDigital(output,engine,analogSignal,idItr,theElectronicsSim);
125  if(needToDeleteSignal) delete analogSignal;
126  }
127  }
128 
129  // free up some memory
131  }
132 
133  void addNoiseHits(CLHEP::HepRandomEngine* engine)
134  {
135  std::vector<PCaloHit> noiseHits;
137  for(std::vector<PCaloHit>::const_iterator hitItr = noiseHits.begin(),
138  hitEnd = noiseHits.end(); hitItr != hitEnd; ++hitItr)
139  {
140  theHitResponse->add(*hitItr, engine);
141  }
142  }
143 
144  void addNoiseSignals(CLHEP::HepRandomEngine* engine)
145  {
146  std::vector<CaloSamples> noiseSignals;
147  // noise signals need to be in units of photoelectrons. Fractional is OK
150  for(std::vector<CaloSamples>::const_iterator signalItr = noiseSignals.begin(),
151  signalEnd = noiseSignals.end(); signalItr != signalEnd; ++signalItr)
152  {
153  theHitResponse->add(*signalItr);
154  }
155  }
156 
157 private:
158  runHelper<Traits> runAnalogToDigital;
163  const std::vector<DetId>* theDetIds;
164  bool addNoise_;
165 };
166 
167 #endif
168 
void setNoiseHitGenerator(CaloVNoiseHitGenerator *generator)
CaloSamples makeBlankSignal(const DetId &detId) const
creates an empty signal for this DetId
void add(const std::vector< PCaloHit > &hits, int bunchCrossing, CLHEP::HepRandomEngine *engine)
Traits::ElectronicsSim ElectronicsSim
bool withinBunchRange(int bunchCrossing) const
check if crossing is within bunch range:
assert(m_qm.get())
const std::vector< DetId > & detIds() const
tell the digitizer which cells exist
virtual void getNoiseHits(std::vector< PCaloHit > &noiseHits)=0
void operator()(DigiCollection &output, CLHEP::HepRandomEngine *engine, CaloSamples *analogSignal, std::vector< DetId >::const_iterator idItr, ElectronicsSim *theElectronicsSim)
std::tuple< unsigned int, int, int, DigiType, int, int, int, float > Digi
Definition: GenericDigi.h:30
Traits::ElectronicsSim ElectronicsSim
CaloVNoiseSignalGenerator * theNoiseSignalGenerator
virtual void finalizeHits(CLHEP::HepRandomEngine *)
Finalize hits.
Creates electronics signals from hits.
void initializeHits()
CaloTDigitizer(CaloHitResponse *hitResponse, ElectronicsSim *electronicsSim, bool addNoise)
virtual void initializeHits()
Initialize hits.
def move
Definition: eostools.py:510
void addNoiseSignals(CLHEP::HepRandomEngine *engine)
void addNoiseHits(CLHEP::HepRandomEngine *engine)
void setNoiseSignalGenerator(CaloVNoiseSignalGenerator *generator)
CaloHitResponse * theHitResponse
runHelper< Traits > runAnalogToDigital
~CaloTDigitizer()
doesn&#39;t delete the pointers passed in
CaloVNoiseHitGenerator * theNoiseHitGenerator
void run(MixCollection< PCaloHit > &, DigiCollection &)
turns hits into digis
ElectronicsSim * theElectronicsSim
Traits::Digi Digi
CaloSamples * findSignal(const DetId &detId)
users can look for the signal for a given cell
virtual void add(const PCaloHit &hit, CLHEP::HepRandomEngine *)
process a single SimHit
void fillEvent(CLHEP::HepRandomEngine *)
fill theNoiseSignals with one event&#39;s worth of noise, in units of pe
void clear()
frees up memory
Traits::DigiCollection DigiCollection
void getNoiseSignals(std::vector< CaloSamples > &noiseSignals)
Traits::DigiCollection DigiCollection
int nSignals() const
number of signals in the current cache
void run(DigiCollection &output, CLHEP::HepRandomEngine *engine)
Collects the digis.
void setDetIds(const std::vector< DetId > &detIds)
const std::vector< DetId > * theDetIds