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 {
24 public:
28  typedef typename Traits::ElectronicsSim ElectronicsSim;
29  typedef typename Traits::Digi Digi;
30  typedef typename Traits::DigiCollection DigiCollection;
31 
32  CaloTDigitizer(CaloHitResponse * hitResponse, ElectronicsSim * electronicsSim, bool addNoise)
33  : theHitResponse(hitResponse),
36  theElectronicsSim(electronicsSim),
37  theDetIds(0),
38  addNoise_(addNoise)
39  {
40  }
41 
42 
45 
47  const std::vector<DetId>& detIds() const {assert( 0 != theDetIds ) ; return *theDetIds;}
48  void setDetIds(const std::vector<DetId> & detIds) {theDetIds = &detIds;}
49 
51  {
53  }
54 
56  {
58  }
59 
60  void add(const std::vector<PCaloHit> & hits, int bunchCrossing, CLHEP::HepRandomEngine* engine) {
61  if(theHitResponse->withinBunchRange(bunchCrossing)) {
62  for(std::vector<PCaloHit>::const_iterator it = hits.begin(), itEnd = hits.end(); it != itEnd; ++it) {
63  theHitResponse->add(*it, engine);
64  }
65  }
66  }
67 
68  void initializeHits() {
70  }
71 
74  assert(0);
75  }
76 
78 
79  void run(DigiCollection & output, CLHEP::HepRandomEngine* engine) {
81 
82  //std::cout << " In CaloTDigitizer, after finalize hits " << std::endl;
83 
84  assert(theDetIds->size() != 0);
85 
86  if(theNoiseHitGenerator != 0) addNoiseHits(engine);
88 
89  theElectronicsSim->newEvent(engine);
90 
91  // reserve space for how many digis we expect
92  int nDigisExpected = addNoise_ ? theDetIds->size() : theHitResponse->nSignals();
93  output.reserve(nDigisExpected);
94 
95  //std::cout << " In CaloTDigitizer, nDigisExpected " << nDigisExpected << std::endl;
96 
97  // make a raw digi for evey cell
98  for(std::vector<DetId>::const_iterator idItr = theDetIds->begin();
99  idItr != theDetIds->end(); ++idItr)
100  {
101  Digi digi(*idItr);
102  CaloSamples * analogSignal = theHitResponse->findSignal(*idItr);
103  bool needToDeleteSignal = false;
104  // don't bother digitizing if no signal and no noise
105  if(analogSignal == 0 && addNoise_) {
106  // I guess we need to make a blank signal for this cell.
107  // Don't bother storing it anywhere.
108  analogSignal = new CaloSamples(theHitResponse->makeBlankSignal(*idItr));
109  needToDeleteSignal = true;
110  }
111  if(analogSignal != 0) {
112  theElectronicsSim->analogToDigital(engine, *analogSignal , digi);
113  output.push_back(std::move(digi));
114  if(needToDeleteSignal) delete analogSignal;
115  }
116  }
117 
118  // free up some memory
120  }
121 
122 
123  void addNoiseHits(CLHEP::HepRandomEngine* engine)
124  {
125  std::vector<PCaloHit> noiseHits;
127  for(std::vector<PCaloHit>::const_iterator hitItr = noiseHits.begin(),
128  hitEnd = noiseHits.end(); hitItr != hitEnd; ++hitItr)
129  {
130  theHitResponse->add(*hitItr, engine);
131  }
132  }
133 
134  void addNoiseSignals(CLHEP::HepRandomEngine* engine)
135  {
136  std::vector<CaloSamples> noiseSignals;
137  // noise signals need to be in units of photoelectrons. Fractional is OK
140  for(std::vector<CaloSamples>::const_iterator signalItr = noiseSignals.begin(),
141  signalEnd = noiseSignals.end(); signalItr != signalEnd; ++signalItr)
142  {
143  theHitResponse->add(*signalItr);
144  }
145  }
146 
147 private:
152  const std::vector<DetId>* theDetIds;
153  bool addNoise_;
154 };
155 
156 #endif
157 
void setNoiseHitGenerator(CaloVNoiseHitGenerator *generator)
void run(DigiCollection &output, CLHEP::HepRandomEngine *engine)
Collects the digis.
CaloSamples makeBlankSignal(const DetId &detId) const
creates an empty signal for this DetId
Traits::Digi Digi
void initializeHits()
CaloTDigitizer(CaloHitResponse *hitResponse, ElectronicsSim *electronicsSim, bool addNoise)
bool withinBunchRange(int bunchCrossing) const
check if crossing is within bunch range:
void add(const std::vector< PCaloHit > &hits, int bunchCrossing, CLHEP::HepRandomEngine *engine)
virtual void getNoiseHits(std::vector< PCaloHit > &noiseHits)=0
Traits::DigiCollection DigiCollection
virtual void finalizeHits(CLHEP::HepRandomEngine *)
Finalize hits.
Creates electronics signals from hits.
virtual void initializeHits()
Initialize hits.
CaloVNoiseHitGenerator * theNoiseHitGenerator
void setNoiseSignalGenerator(CaloVNoiseSignalGenerator *generator)
CaloVNoiseSignalGenerator * theNoiseSignalGenerator
CaloHitResponse * theHitResponse
void run(MixCollection< PCaloHit > &, DigiCollection &)
turns hits into digis
ElectronicsSim * theElectronicsSim
Traits::ElectronicsSim ElectronicsSim
void addNoiseHits(CLHEP::HepRandomEngine *engine)
CaloSamples * findSignal(const DetId &detId)
users can look for the signal for a given cell
void addNoiseSignals(CLHEP::HepRandomEngine *engine)
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
void setDetIds(const std::vector< DetId > &detIds)
void getNoiseSignals(std::vector< CaloSamples > &noiseSignals)
const std::vector< DetId > * theDetIds
int nSignals() const
number of signals in the current cache
~CaloTDigitizer()
doesn&#39;t delete the pointers passed in
const std::vector< DetId > & detIds() const
tell the digitizer which cells exist