test
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  //std::cout << " In CaloTDigitizer, after finalize hits " << std::endl;
82 
83  assert(theDetIds->size() != 0);
84 
85  if(theNoiseHitGenerator != 0) addNoiseHits(engine);
87 
88  theElectronicsSim->newEvent(engine);
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 
110  theElectronicsSim->analogToDigital(engine, *analogSignal , digi);
111  output.push_back(std::move(digi));
112  if(needToDeleteSignal) delete analogSignal;
113  }
114  }
115 
116  // free up some memory
118  }
119 
120 
121  void addNoiseHits(CLHEP::HepRandomEngine* engine)
122  {
123  std::vector<PCaloHit> noiseHits;
125  for(std::vector<PCaloHit>::const_iterator hitItr = noiseHits.begin(),
126  hitEnd = noiseHits.end(); hitItr != hitEnd; ++hitItr)
127  {
128  theHitResponse->add(*hitItr, engine);
129  }
130  }
131 
132  void addNoiseSignals(CLHEP::HepRandomEngine* engine)
133  {
134  std::vector<CaloSamples> noiseSignals;
135  // noise signals need to be in units of photoelectrons. Fractional is OK
138  for(std::vector<CaloSamples>::const_iterator signalItr = noiseSignals.begin(),
139  signalEnd = noiseSignals.end(); signalItr != signalEnd; ++signalItr)
140  {
141  theHitResponse->add(*signalItr);
142  }
143  }
144 
145 private:
150  const std::vector<DetId>* theDetIds;
151  bool addNoise_;
152 };
153 
154 #endif
155 
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:
assert(m_qm.get())
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.
def move
Definition: eostools.py:510
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