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 
81 
82  //std::cout << " In CaloTDigitizer " << std::endl;
83 
85 
86  //std::cout << " In CaloTDigitizer, after finalize hits " << std::endl;
87 
88  assert(theDetIds->size() != 0);
89 
92 
93  //std::cout << " In CaloTDigitizer, after addNoiseSignals " << std::endl;
94 
95  theElectronicsSim->newEvent();
96 
97  // reserve space for how many digis we expect
98  int nDigisExpected = addNoise_ ? theDetIds->size() : theHitResponse->nSignals();
99  output.reserve(nDigisExpected);
100 
101  //std::cout << " In CaloTDigitizer, nDigisExpected " << nDigisExpected << std::endl;
102 
103  // make a raw digi for evey cell
104  for(std::vector<DetId>::const_iterator idItr = theDetIds->begin();
105  idItr != theDetIds->end(); ++idItr)
106  {
107  Digi digi(*idItr);
108  CaloSamples * analogSignal = theHitResponse->findSignal(*idItr);
109  bool needToDeleteSignal = false;
110  // don't bother digitizing if no signal and no noise
111  if(analogSignal == 0 && addNoise_) {
112  // I guess we need to make a blank signal for this cell.
113  // Don't bother storing it anywhere.
114  analogSignal = new CaloSamples(theHitResponse->makeBlankSignal(*idItr));
115  needToDeleteSignal = true;
116  }
117  if(analogSignal != 0) {
118  theElectronicsSim->analogToDigital(*analogSignal , digi);
119 
120  // std::cout << " New Digi: " << digi << std::endl;
121  output.push_back(std::move(digi));
122  if(needToDeleteSignal) delete analogSignal;
123  }
124  }
125 
126  // free up some memory
128  }
129 
130 
132  {
133  std::vector<PCaloHit> noiseHits;
135  for(std::vector<PCaloHit>::const_iterator hitItr = noiseHits.begin(),
136  hitEnd = noiseHits.end(); hitItr != hitEnd; ++hitItr)
137  {
138  theHitResponse->add(*hitItr);
139  }
140  }
141 
143  {
144  std::vector<CaloSamples> noiseSignals;
145  // noise signals need to be in units of photoelectrons. Fractional is OK
148  for(std::vector<CaloSamples>::const_iterator signalItr = noiseSignals.begin(),
149  signalEnd = noiseSignals.end(); signalItr != signalEnd; ++signalItr)
150  {
151  theHitResponse->add(*signalItr);
152  }
153  }
154 
155 private:
160  const std::vector<DetId>* theDetIds;
161  bool addNoise_;
162 };
163 
164 #endif
165 
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