CMS 3D CMS Logo

CaloTDigitizer.h
Go to the documentation of this file.
1 #ifndef CaloSimAlgos_CaloTDigitizer_h
2 #define CaloSimAlgos_CaloTDigitizer_h
3 
13 #include <cassert>
14 #include <vector>
15 
16 namespace CLHEP {
17  class HepRandomEngine;
18 }
19 
20 template<class Traits>
22 public:
23  typedef typename Traits::ElectronicsSim ElectronicsSim;
24  typedef typename Traits::Digi Digi;
25  typedef typename Traits::DigiCollection DigiCollection;
26 
27  void operator()(DigiCollection & output, CLHEP::HepRandomEngine* engine, CaloSamples * analogSignal, std::vector<DetId>::const_iterator idItr, ElectronicsSim* theElectronicsSim){
28  Digi digi(*idItr);
29  theElectronicsSim->analogToDigital(engine, *analogSignal , digi);
30  output.push_back(std::move(digi));
31  }
32 
33 };
34 
35 //second parameter changes the operation of run() slightly (default value for old-style with edm::SortedCollection instead of edm::DataFrameContainer)
36 template<class Traits, template <class> class runHelper=CaloTDigitizerDefaultRun>
38 {
39 public:
43  typedef typename Traits::ElectronicsSim ElectronicsSim;
44  typedef typename Traits::Digi Digi;
45  typedef typename Traits::DigiCollection DigiCollection;
46 
47  CaloTDigitizer(CaloHitResponse * hitResponse, ElectronicsSim * electronicsSim, bool addNoise)
48  : theHitResponse(hitResponse),
49  theNoiseSignalGenerator(nullptr),
50  theElectronicsSim(electronicsSim),
51  theDetIds(nullptr),
52  addNoise_(addNoise),
53  debugCS_(false)
54  {
55  }
56 
57 
60 
62  const std::vector<DetId>& detIds() const {assert( 0 != theDetIds ) ; return *theDetIds;}
63  void setDetIds(const std::vector<DetId> & detIds) {theDetIds = &detIds;}
64 
66  {
67  theNoiseSignalGenerator = generator;
68  }
69 
71  debugCS_ = debug;
72  }
73 
75  return csColl_;
76  }
77 
78  void add(const std::vector<PCaloHit> & hits, int bunchCrossing, CLHEP::HepRandomEngine* engine) {
79  if(theHitResponse->withinBunchRange(bunchCrossing)) {
80  for(std::vector<PCaloHit>::const_iterator it = hits.begin(), itEnd = hits.end(); it != itEnd; ++it) {
81  theHitResponse->add(*it, engine);
82  }
83  }
84  }
85 
86  void initializeHits() {
87  theHitResponse->initializeHits();
88  }
89 
91  void run(MixCollection<PCaloHit> &, DigiCollection &) {
92  assert(0);
93  }
94 
96 
97  void run(DigiCollection & output, CLHEP::HepRandomEngine* engine) {
98  assert(!theDetIds->empty());
99 
100  if(theNoiseSignalGenerator != nullptr) addNoiseSignals(engine);
101 
102  theHitResponse->finalizeHits(engine);
103  //std::cout << " In CaloTDigitizer, after finalize hits " << std::endl;
104 
105  theElectronicsSim->newEvent(engine);
106 
107  // reserve space for how many digis we expect
108  int nDigisExpected = addNoise_ ? theDetIds->size() : theHitResponse->nSignals();
109  output.reserve(nDigisExpected);
110  if(debugCS_) {
111  csColl_.clear();
112  csColl_.reserve(nDigisExpected);
113  theHitResponse->setStorePrecise(true);
114  }
115 
116  // make a raw digi for evey cell
117  for(std::vector<DetId>::const_iterator idItr = theDetIds->begin();
118  idItr != theDetIds->end(); ++idItr)
119  {
120  CaloSamples * analogSignal = theHitResponse->findSignal(*idItr);
121  if(analogSignal && debugCS_) csColl_.push_back(*analogSignal);
122  bool needToDeleteSignal = false;
123  // don't bother digitizing if no signal and no noise
124  if(analogSignal == nullptr && addNoise_) {
125  // I guess we need to make a blank signal for this cell.
126  // Don't bother storing it anywhere.
127  analogSignal = new CaloSamples(theHitResponse->makeBlankSignal(*idItr));
128  needToDeleteSignal = true;
129  }
130  if(analogSignal != nullptr) {
131  runAnalogToDigital(output,engine,analogSignal,idItr,theElectronicsSim);
132  if(needToDeleteSignal) delete analogSignal;
133  }
134  }
135 
136  // free up some memory
137  theHitResponse->clear();
138  }
139 
140  void addNoiseSignals(CLHEP::HepRandomEngine* engine)
141  {
142  std::vector<CaloSamples> noiseSignals;
143  // noise signals need to be in units of photoelectrons. Fractional is OK
144  theNoiseSignalGenerator->fillEvent(engine);
145  theNoiseSignalGenerator->getNoiseSignals(noiseSignals);
146  for(std::vector<CaloSamples>::const_iterator signalItr = noiseSignals.begin(),
147  signalEnd = noiseSignals.end(); signalItr != signalEnd; ++signalItr)
148  {
149  theHitResponse->add(*signalItr);
150  }
151  }
152 
153 private:
154  runHelper<Traits> runAnalogToDigital;
157  ElectronicsSim * theElectronicsSim;
158  const std::vector<DetId>* theDetIds;
159  bool addNoise_;
160  bool debugCS_;
162 };
163 
164 #endif
165 
CaloSamplesCollection csColl_
std::vector< CaloSamples > CaloSamplesCollection
Definition: CaloSamples.h:88
void add(const std::vector< PCaloHit > &hits, int bunchCrossing, CLHEP::HepRandomEngine *engine)
Traits::ElectronicsSim ElectronicsSim
const std::vector< DetId > & detIds() const
tell the digitizer which cells exist
void operator()(DigiCollection &output, CLHEP::HepRandomEngine *engine, CaloSamples *analogSignal, std::vector< DetId >::const_iterator idItr, ElectronicsSim *theElectronicsSim)
#define nullptr
std::tuple< unsigned int, int, int, DigiType, int, int, int, float > Digi
Definition: GenericDigi.h:30
Traits::ElectronicsSim ElectronicsSim
CaloVNoiseSignalGenerator * theNoiseSignalGenerator
Creates electronics signals from hits.
void initializeHits()
CaloTDigitizer(CaloHitResponse *hitResponse, ElectronicsSim *electronicsSim, bool addNoise)
void addNoiseSignals(CLHEP::HepRandomEngine *engine)
void setNoiseSignalGenerator(CaloVNoiseSignalGenerator *generator)
CaloHitResponse * theHitResponse
runHelper< Traits > runAnalogToDigital
~CaloTDigitizer()
doesn&#39;t delete the pointers passed in
#define debug
Definition: HDRShower.cc:19
void run(MixCollection< PCaloHit > &, DigiCollection &)
turns hits into digis
ElectronicsSim * theElectronicsSim
Traits::Digi Digi
Traits::DigiCollection DigiCollection
void setDebugCaloSamples(bool debug)
Traits::DigiCollection DigiCollection
const CaloSamplesCollection & getCaloSamples() const
def move(src, dest)
Definition: eostools.py:510
void run(DigiCollection &output, CLHEP::HepRandomEngine *engine)
Collects the digis.
void setDetIds(const std::vector< DetId > &detIds)
const std::vector< DetId > * theDetIds