CMS 3D CMS Logo

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 public:
24  typedef typename Traits::ElectronicsSim ElectronicsSim;
25  typedef typename Traits::Digi Digi;
26  typedef typename Traits::DigiCollection DigiCollection;
27 
28  void operator()(DigiCollection &output,
29  CLHEP::HepRandomEngine *engine,
30  CaloSamples *analogSignal,
31  std::vector<DetId>::const_iterator idItr,
32  ElectronicsSim *theElectronicsSim) {
33  Digi digi(*idItr);
34  theElectronicsSim->analogToDigital(engine, *analogSignal, digi);
35  output.push_back(std::move(digi));
36  }
37 };
38 
39 // second parameter changes the operation of run() slightly (default value for
40 // old-style with edm::SortedCollection instead of edm::DataFrameContainer)
41 template <class Traits, template <class> class runHelper = CaloTDigitizerDefaultRun>
43 public:
47  typedef typename Traits::ElectronicsSim ElectronicsSim;
48  typedef typename Traits::Digi Digi;
49  typedef typename Traits::DigiCollection DigiCollection;
50 
51  CaloTDigitizer(CaloHitResponse *hitResponse, ElectronicsSim *electronicsSim, bool addNoise)
52  : theHitResponse(hitResponse),
53  theNoiseSignalGenerator(nullptr),
54  theElectronicsSim(electronicsSim),
55  theDetIds(nullptr),
56  addNoise_(addNoise),
57  debugCS_(false) {}
58 
61 
63  const std::vector<DetId> &detIds() const {
64  assert(0 != theDetIds);
65  return *theDetIds;
66  }
67  void setDetIds(const std::vector<DetId> &detIds) { theDetIds = &detIds; }
68 
70 
71  void setDebugCaloSamples(bool debug) { debugCS_ = debug; }
72 
73  const CaloSamplesCollection &getCaloSamples() const { return csColl_; }
74 
75  void add(const std::vector<PCaloHit> &hits, int bunchCrossing, CLHEP::HepRandomEngine *engine) {
76  if (theHitResponse->withinBunchRange(bunchCrossing)) {
77  for (std::vector<PCaloHit>::const_iterator it = hits.begin(), itEnd = hits.end(); it != itEnd; ++it) {
78  theHitResponse->add(*it, engine);
79  }
80  }
81  }
82 
83  void initializeHits() { theHitResponse->initializeHits(); }
84 
86  void run(MixCollection<PCaloHit> &, DigiCollection &) { assert(0); }
87 
89 
90  void run(DigiCollection &output, CLHEP::HepRandomEngine *engine) {
91  assert(!theDetIds->empty());
92 
93  if (theNoiseSignalGenerator != nullptr)
94  addNoiseSignals(engine);
95 
96  theHitResponse->finalizeHits(engine);
97  // std::cout << " In CaloTDigitizer, after finalize hits " << std::endl;
98 
99  theElectronicsSim->newEvent(engine);
100 
101  // reserve space for how many digis we expect
102  int nDigisExpected = addNoise_ ? theDetIds->size() : theHitResponse->nSignals();
103  output.reserve(nDigisExpected);
104  if (debugCS_) {
105  csColl_.clear();
106  csColl_.reserve(nDigisExpected);
107  theHitResponse->setStorePrecise(true);
108  }
109 
110  // make a raw digi for evey cell
111  for (std::vector<DetId>::const_iterator idItr = theDetIds->begin(); idItr != theDetIds->end(); ++idItr) {
112  CaloSamples *analogSignal = theHitResponse->findSignal(*idItr);
113  if (analogSignal && debugCS_)
114  csColl_.push_back(*analogSignal);
115  bool needToDeleteSignal = false;
116  // don't bother digitizing if no signal and no noise
117  if (analogSignal == nullptr && addNoise_) {
118  // I guess we need to make a blank signal for this cell.
119  // Don't bother storing it anywhere.
120  analogSignal = new CaloSamples(theHitResponse->makeBlankSignal(*idItr));
121  needToDeleteSignal = true;
122  }
123  if (analogSignal != nullptr) {
124  runAnalogToDigital(output, engine, analogSignal, idItr, theElectronicsSim);
125  if (needToDeleteSignal)
126  delete analogSignal;
127  }
128  }
129 
130  // free up some memory
131  theHitResponse->clear();
132  }
133 
134  void addNoiseSignals(CLHEP::HepRandomEngine *engine) {
135  std::vector<CaloSamples> noiseSignals;
136  // noise signals need to be in units of photoelectrons. Fractional is OK
137  theNoiseSignalGenerator->fillEvent(engine);
138  theNoiseSignalGenerator->getNoiseSignals(noiseSignals);
139  for (std::vector<CaloSamples>::const_iterator signalItr = noiseSignals.begin(), signalEnd = noiseSignals.end();
140  signalItr != signalEnd;
141  ++signalItr) {
142  theHitResponse->add(*signalItr);
143  }
144  }
145 
146 private:
147  runHelper<Traits> runAnalogToDigital;
150  ElectronicsSim *theElectronicsSim;
151  const std::vector<DetId> *theDetIds;
152  bool addNoise_;
153  bool debugCS_;
155 };
156 
157 #endif
CaloSamplesCollection csColl_
std::vector< CaloSamples > CaloSamplesCollection
Definition: CaloSamples.h:99
void add(const std::vector< PCaloHit > &hits, int bunchCrossing, CLHEP::HepRandomEngine *engine)
Traits::ElectronicsSim ElectronicsSim
#define nullptr
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)
std::tuple< unsigned int, int, int, DigiType, int, int, int, float > Digi
Definition: GenericDigi.h:40
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:511
void run(DigiCollection &output, CLHEP::HepRandomEngine *engine)
Collects the digis.
void setDetIds(const std::vector< DetId > &detIds)
const std::vector< DetId > * theDetIds