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;
27 
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;
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(nullptr != theDetIds);
65  return *theDetIds;
66  }
67  void setDetIds(const std::vector<DetId> &detIds) { theDetIds = &detIds; }
68 
70 
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 
84 
87 
89 
90  void run(DigiCollection &output, CLHEP::HepRandomEngine *engine) {
91  assert(!theDetIds->empty());
92 
93  if (theNoiseSignalGenerator != nullptr)
94  addNoiseSignals(engine);
95 
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);
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
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
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;
151  const std::vector<DetId> *theDetIds;
152  bool addNoise_;
153  bool debugCS_;
155 };
156 
157 #endif
void setStorePrecise(bool sp)
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
int nSignals() const
number of signals in the current cache
void operator()(DigiCollection &output, CLHEP::HepRandomEngine *engine, CaloSamples *analogSignal, std::vector< DetId >::const_iterator idItr, ElectronicsSim *theElectronicsSim)
assert(be >=bs)
Traits::ElectronicsSim ElectronicsSim
const std::vector< DetId > & detIds() const
tell the digitizer which cells exist
CaloVNoiseSignalGenerator * theNoiseSignalGenerator
Creates electronics signals from hits.
void initializeHits()
CaloTDigitizer(CaloHitResponse *hitResponse, ElectronicsSim *electronicsSim, bool addNoise)
virtual void initializeHits()
Initialize hits.
void addNoiseSignals(CLHEP::HepRandomEngine *engine)
void setNoiseSignalGenerator(CaloVNoiseSignalGenerator *generator)
CaloHitResponse * theHitResponse
bool withinBunchRange(int bunchCrossing) const
check if crossing is within bunch range:
runHelper< Traits > runAnalogToDigital
const CaloSamplesCollection & getCaloSamples() const
~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
CaloSamples * findSignal(const DetId &detId)
users can look for the signal for a given cell
virtual void finalizeHits(CLHEP::HepRandomEngine *)
Finalize hits.
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
Traits::DigiCollection DigiCollection
void setDebugCaloSamples(bool debug)
void getNoiseSignals(std::vector< CaloSamples > &noiseSignals)
Definition: output.py:1
Traits::DigiCollection DigiCollection
CaloSamples makeBlankSignal(const DetId &detId) const
creates an empty signal for this DetId
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