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
CaloTDigitizer
Definition: CaloTDigitizer.h:42
CaloTDigitizer::add
void add(const std::vector< PCaloHit > &hits, int bunchCrossing, CLHEP::HepRandomEngine *engine)
Definition: CaloTDigitizer.h:75
CaloTDigitizer::DigiCollection
Traits::DigiCollection DigiCollection
Definition: CaloTDigitizer.h:49
funct::false
false
Definition: Factorize.h:29
CaloTDigitizer::csColl_
CaloSamplesCollection csColl_
Definition: CaloTDigitizer.h:154
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
CaloTDigitizer::theElectronicsSim
ElectronicsSim * theElectronicsSim
Definition: CaloTDigitizer.h:150
CaloTDigitizerDefaultRun::operator()
void operator()(DigiCollection &output, CLHEP::HepRandomEngine *engine, CaloSamples *analogSignal, std::vector< DetId >::const_iterator idItr, ElectronicsSim *theElectronicsSim)
Definition: CaloTDigitizer.h:28
CaloTDigitizer::run
void run(DigiCollection &output, CLHEP::HepRandomEngine *engine)
Collects the digis.
Definition: CaloTDigitizer.h:90
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
TrendClient_cfi.Digi
Digi
Definition: TrendClient_cfi.py:7
cms::cuda::assert
assert(be >=bs)
CaloTDigitizer::initializeHits
void initializeHits()
Definition: CaloTDigitizer.h:83
CaloTDigitizer::setDetIds
void setDetIds(const std::vector< DetId > &detIds)
Definition: CaloTDigitizer.h:67
CaloTDigitizer::theHitResponse
CaloHitResponse * theHitResponse
Definition: CaloTDigitizer.h:148
CaloHitResponse::withinBunchRange
bool withinBunchRange(int bunchCrossing) const
check if crossing is within bunch range:
Definition: CaloHitResponse.h:112
CaloTDigitizer::detIds
const std::vector< DetId > & detIds() const
tell the digitizer which cells exist
Definition: CaloTDigitizer.h:63
CaloVNoiseSignalGenerator.h
CaloTDigitizer::CaloTDigitizer
CaloTDigitizer(CaloHitResponse *hitResponse, ElectronicsSim *electronicsSim, bool addNoise)
Definition: CaloTDigitizer.h:51
debug
#define debug
Definition: HDRShower.cc:19
CaloHitResponse::nSignals
int nSignals() const
number of signals in the current cache
Definition: CaloHitResponse.h:98
MixCollection.h
MixCollection
Definition: MixCollection.h:10
CaloHitResponse::initializeHits
virtual void initializeHits()
Initialize hits.
Definition: CaloHitResponse.h:54
CaloVNoiseSignalGenerator
Definition: CaloVNoiseSignalGenerator.h:11
CaloTDigitizer::addNoiseSignals
void addNoiseSignals(CLHEP::HepRandomEngine *engine)
Definition: CaloTDigitizer.h:134
CLHEP
Definition: CocoaGlobals.h:27
CaloHitResponse::add
virtual void add(const PCaloHit &hit, CLHEP::HepRandomEngine *)
process a single SimHit
Definition: CaloHitResponse.cc:66
CaloHitResponse::finalizeHits
virtual void finalizeHits(CLHEP::HepRandomEngine *)
Finalize hits.
Definition: CaloHitResponse.h:57
CaloTDigitizer::setNoiseSignalGenerator
void setNoiseSignalGenerator(CaloVNoiseSignalGenerator *generator)
Definition: CaloTDigitizer.h:69
CaloTDigitizerDefaultRun::DigiCollection
Traits::DigiCollection DigiCollection
Definition: CaloTDigitizer.h:26
CaloTDigitizerDefaultRun
Definition: CaloTDigitizer.h:22
PCaloHit.h
CaloHitResponse
Creates electronics signals from hits.
Definition: CaloHitResponse.h:33
CaloTDigitizer::~CaloTDigitizer
~CaloTDigitizer()
doesn't delete the pointers passed in
Definition: CaloTDigitizer.h:60
CaloTDigitizer::addNoise_
bool addNoise_
Definition: CaloTDigitizer.h:152
CaloTDigitizerDefaultRun::Digi
Traits::Digi Digi
Definition: CaloTDigitizer.h:25
CaloTDigitizer::Digi
Traits::Digi Digi
Definition: CaloTDigitizer.h:48
CaloSamples
Definition: CaloSamples.h:14
CaloHitResponse::makeBlankSignal
CaloSamples makeBlankSignal(const DetId &detId) const
creates an empty signal for this DetId
Definition: CaloHitResponse.cc:175
CaloHitResponse.h
CaloTDigitizer::theNoiseSignalGenerator
CaloVNoiseSignalGenerator * theNoiseSignalGenerator
Definition: CaloTDigitizer.h:149
CaloVNoiseSignalGenerator::getNoiseSignals
void getNoiseSignals(std::vector< CaloSamples > &noiseSignals)
Definition: CaloVNoiseSignalGenerator.h:21
genfragment_ptgun_cfg.generator
generator
Definition: genfragment_ptgun_cfg.py:4
CaloTDigitizer::runAnalogToDigital
runHelper< Traits > runAnalogToDigital
Definition: CaloTDigitizer.h:147
siStripShotFilter_cfi.DigiCollection
DigiCollection
Definition: siStripShotFilter_cfi.py:6
eostools.move
def move(src, dest)
Definition: eostools.py:511
CaloTDigitizer::getCaloSamples
const CaloSamplesCollection & getCaloSamples() const
Definition: CaloTDigitizer.h:73
CaloTDigitizer::debugCS_
bool debugCS_
Definition: CaloTDigitizer.h:153
CaloTDigitizer::run
void run(MixCollection< PCaloHit > &, DigiCollection &)
turns hits into digis
Definition: CaloTDigitizer.h:86
CaloTDigitizer::ElectronicsSim
Traits::ElectronicsSim ElectronicsSim
Definition: CaloTDigitizer.h:47
CaloHitResponse::findSignal
CaloSamples * findSignal(const DetId &detId)
users can look for the signal for a given cell
Definition: CaloHitResponse.cc:164
CaloVNoiseSignalGenerator::fillEvent
void fillEvent(CLHEP::HepRandomEngine *)
fill theNoiseSignals with one event's worth of noise, in units of pe
Definition: CaloVNoiseSignalGenerator.cc:7
CaloTDigitizer::setDebugCaloSamples
void setDebugCaloSamples(bool debug)
Definition: CaloTDigitizer.h:71
CaloTDigitizer::theDetIds
const std::vector< DetId > * theDetIds
Definition: CaloTDigitizer.h:151
CaloSamplesCollection
std::vector< CaloSamples > CaloSamplesCollection
Definition: CaloSamples.h:99
CaloHitResponse::clear
void clear()
frees up memory
Definition: CaloHitResponse.h:79
CaloHitResponse::setStorePrecise
void setStorePrecise(bool sp)
Definition: CaloHitResponse.h:116
CaloTDigitizerDefaultRun::ElectronicsSim
Traits::ElectronicsSim ElectronicsSim
Definition: CaloTDigitizer.h:24