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 template<class Traits>
19 {
20 public:
24  typedef typename Traits::ElectronicsSim ElectronicsSim;
25  typedef typename Traits::Digi Digi;
26  typedef typename Traits::DigiCollection DigiCollection;
27 
28  CaloTDigitizer(CaloHitResponse * hitResponse, ElectronicsSim * electronicsSim, bool addNoise)
29  : theHitResponse(hitResponse),
32  theElectronicsSim(electronicsSim),
33  theDetIds(0),
34  addNoise_(addNoise)
35  {
36  }
37 
38 
41 
43  const std::vector<DetId>& detIds() const {assert( 0 != theDetIds ) ; return *theDetIds;}
44  void setDetIds(const std::vector<DetId> & detIds) {theDetIds = &detIds;}
45 
47  {
49  }
50 
52  {
54  }
55 
56  void setRandomEngine(CLHEP::HepRandomEngine & engine)
57  {
59  theElectronicsSim->setRandomEngine(engine);
60  }
61 
62  void add(const std::vector<PCaloHit> & hits, int bunchCrossing) {
63  if(theHitResponse->withinBunchRange(bunchCrossing)) {
64  for(std::vector<PCaloHit>::const_iterator it = hits.begin(), itEnd = hits.end(); it != itEnd; ++it) {
65  theHitResponse->add(*it);
66  }
67  }
68  }
69 
70  void initializeHits() {
72  }
73 
76  assert(0);
77  }
78 
82 
83  assert(theDetIds->size() != 0);
84 
87 
88  theElectronicsSim->newEvent();
89 
90  // reserve space for how many digis we expect
91  int nDigisExpected = addNoise_ ? theDetIds->size() : theHitResponse->nSignals();
92  output.reserve(nDigisExpected);
93 
94  // make a raw digi for evey cell
95  for(std::vector<DetId>::const_iterator idItr = theDetIds->begin();
96  idItr != theDetIds->end(); ++idItr)
97  {
98  Digi digi(*idItr);
99  CaloSamples * analogSignal = theHitResponse->findSignal(*idItr);
100  bool needToDeleteSignal = false;
101  // don't bother digitizing if no signal and no noise
102  if(analogSignal == 0 && addNoise_) {
103  // I guess we need to make a blank signal for this cell.
104  // Don't bother storing it anywhere.
105  analogSignal = new CaloSamples(theHitResponse->makeBlankSignal(*idItr));
106  needToDeleteSignal = true;
107  }
108  if(analogSignal != 0) {
109  theElectronicsSim->analogToDigital(*analogSignal , digi);
110  output.push_back(std::move(digi));
111  if(needToDeleteSignal) delete analogSignal;
112  }
113  }
114 
115  // free up some memory
117  }
118 
119 
121  {
122  std::vector<PCaloHit> noiseHits;
124  for(std::vector<PCaloHit>::const_iterator hitItr = noiseHits.begin(),
125  hitEnd = noiseHits.end(); hitItr != hitEnd; ++hitItr)
126  {
127  theHitResponse->add(*hitItr);
128  }
129  }
130 
132  {
133  std::vector<CaloSamples> noiseSignals;
134  // noise signals need to be in units of photoelectrons. Fractional is OK
137  for(std::vector<CaloSamples>::const_iterator signalItr = noiseSignals.begin(),
138  signalEnd = noiseSignals.end(); signalItr != signalEnd; ++signalItr)
139  {
140  theHitResponse->add(*signalItr);
141  }
142  }
143 
144 private:
149  const std::vector<DetId>* theDetIds;
150  bool addNoise_;
151 };
152 
153 #endif
154 
void setNoiseHitGenerator(CaloVNoiseHitGenerator *generator)
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)
virtual void getNoiseHits(std::vector< PCaloHit > &noiseHits)=0
Traits::DigiCollection DigiCollection
Creates electronics signals from hits.
virtual void initializeHits()
Initialize hits.
virtual void add(const PCaloHit &hit)
process a single SimHit
CaloVNoiseHitGenerator * theNoiseHitGenerator
void setNoiseSignalGenerator(CaloVNoiseSignalGenerator *generator)
void run(DigiCollection &output)
Collects the digis.
CaloVNoiseSignalGenerator * theNoiseSignalGenerator
CaloHitResponse * theHitResponse
void addNoiseSignals()
virtual void finalizeHits()
Finalize hits.
void run(MixCollection< PCaloHit > &, DigiCollection &)
turns hits into digis
ElectronicsSim * theElectronicsSim
void fillEvent()
fill theNoiseSignals with one event&#39;s worth of noise, in units of pe
Traits::ElectronicsSim ElectronicsSim
CaloSamples * findSignal(const DetId &detId)
users can look for the signal for a given cell
void clear()
frees up memory
void setDetIds(const std::vector< DetId > &detIds)
void getNoiseSignals(std::vector< CaloSamples > &noiseSignals)
const std::vector< DetId > * theDetIds
virtual void setRandomEngine(CLHEP::HepRandomEngine &engine)
void setRandomEngine(CLHEP::HepRandomEngine &engine)
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