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 
16 template<class Traits>
18 {
19 public:
23  typedef typename Traits::ElectronicsSim ElectronicsSim;
24  typedef typename Traits::Digi Digi;
25  typedef typename Traits::DigiCollection DigiCollection;
26 
27  CaloTDigitizer(CaloHitResponse * hitResponse, ElectronicsSim * electronicsSim, bool addNoise)
28  : theHitResponse(hitResponse),
31  theElectronicsSim(electronicsSim),
32  theDetIds(0),
33  addNoise_(addNoise)
34  {
35  }
36 
37 
40 
42  const std::vector<DetId>& detIds() const {assert( 0 != theDetIds ) ; return *theDetIds;}
43  void setDetIds(const std::vector<DetId> & detIds) {theDetIds = &detIds;}
44 
46  {
48  }
49 
51  {
53  }
54 
55  void setRandomEngine(CLHEP::HepRandomEngine & engine)
56  {
58  theElectronicsSim->setRandomEngine(engine);
59  }
60 
63  assert(theDetIds->size() != 0);
64 
67 
68  theHitResponse->run(input);
69  theElectronicsSim->newEvent();
70 
71  // reserve space for how many digis we expect
72  int nDigisExpected = addNoise_ ? theDetIds->size() : theHitResponse->nSignals();
73  output.reserve(nDigisExpected);
74 
75  // make a raw digi for evey cell
76  for(std::vector<DetId>::const_iterator idItr = theDetIds->begin();
77  idItr != theDetIds->end(); ++idItr)
78  {
79  Digi digi(*idItr);
80  CaloSamples * analogSignal = theHitResponse->findSignal(*idItr);
81  bool needToDeleteSignal = false;
82  // don't bother digitizing if no signal and no noise
83  if(analogSignal == 0 && addNoise_) {
84  // I guess we need to make a blank signal for this cell.
85  // Don't bother storing it anywhere.
86  analogSignal = new CaloSamples(theHitResponse->makeBlankSignal(*idItr));
87  needToDeleteSignal = true;
88  }
89  if(analogSignal != 0) {
90  theElectronicsSim->analogToDigital(*analogSignal , digi);
91  output.push_back(digi);
92  if(needToDeleteSignal) delete analogSignal;
93  }
94  }
95 
96  // free up some memory
98  }
99 
100 
102  {
103  std::vector<PCaloHit> noiseHits;
105  for(std::vector<PCaloHit>::const_iterator hitItr = noiseHits.begin(),
106  hitEnd = noiseHits.end(); hitItr != hitEnd; ++hitItr)
107  {
108  theHitResponse->add(*hitItr);
109  }
110  }
111 
113  {
114  std::vector<CaloSamples> noiseSignals;
115  // noise signals need to be in units of photoelectrons. Fractional is OK
118  for(std::vector<CaloSamples>::const_iterator signalItr = noiseSignals.begin(),
119  signalEnd = noiseSignals.end(); signalItr != signalEnd; ++signalItr)
120  {
121  theHitResponse->add(*signalItr);
122  }
123  }
124 
125 private:
130  const std::vector<DetId>* theDetIds;
131  bool addNoise_;
132 };
133 
134 #endif
135 
void setNoiseHitGenerator(CaloVNoiseHitGenerator *generator)
CaloSamples makeBlankSignal(const DetId &detId) const
creates an empty signal for this DetId
Traits::Digi Digi
CaloTDigitizer(CaloHitResponse *hitResponse, ElectronicsSim *electronicsSim, bool addNoise)
virtual void getNoiseHits(std::vector< PCaloHit > &noiseHits)=0
Traits::DigiCollection DigiCollection
Creates electronics signals from hits.
void run(MixCollection< PCaloHit > &input, DigiCollection &output)
turns hits into digis
virtual void add(const PCaloHit &hit)
process a single SimHit
CaloVNoiseHitGenerator * theNoiseHitGenerator
void setNoiseSignalGenerator(CaloVNoiseSignalGenerator *generator)
CaloVNoiseSignalGenerator * theNoiseSignalGenerator
CaloHitResponse * theHitResponse
void addNoiseSignals()
virtual void run(MixCollection< PCaloHit > &hits)
Complete cell digitization.
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