CMS 3D CMS Logo

CaloHitResponse.cc
Go to the documentation of this file.
14 
15 #include "CLHEP/Random/RandPoissonQ.h"
16 #include "CLHEP/Units/GlobalPhysicalConstants.h"
17 #include "CLHEP/Units/GlobalSystemOfUnits.h"
18 
19 #include <iostream>
20 
22  : theAnalogSignalMap(),
23  theParameterMap(parametersMap),
24  theShapes(nullptr),
25  theShape(shape),
26  theHitCorrection(nullptr),
27  thePECorrection(nullptr),
28  theHitFilter(nullptr),
29  theGeometry(nullptr),
30  theMinBunch(-10),
31  theMaxBunch(10),
32  thePhaseShift_(1.),
33  storePrecise(false),
34  ignoreTime(false) {}
35 
38  theParameterMap(parametersMap),
39  theShapes(shapes),
45  theMinBunch(-10),
46  theMaxBunch(10),
47  thePhaseShift_(1.),
49  ignoreTime(false) {}
50 
52 
56 }
57 
58 void CaloHitResponse::run(const MixCollection<PCaloHit> &hits, CLHEP::HepRandomEngine *engine) {
59  for (MixCollection<PCaloHit>::MixItr hitItr = hits.begin(); hitItr != hits.end(); ++hitItr) {
60  if (withinBunchRange(hitItr.bunch())) {
61  add(*hitItr, engine);
62  } // loop over hits
63  }
64 }
65 
66 void CaloHitResponse::add(const PCaloHit &hit, CLHEP::HepRandomEngine *engine) {
67  // check the hit time makes sense
68  if (edm::isNotFinite(hit.time())) {
69  return;
70  }
71 
72  // maybe it's not from this subdetector
73  if (theHitFilter == nullptr || theHitFilter->accepts(hit)) {
74  LogDebug("CaloHitResponse") << hit;
75  CaloSamples signal(makeAnalogSignal(hit, engine));
76  bool keep(keepBlank()); // here we check for blank signal if not keeping them
77  if (!keep) {
78  const unsigned int size(signal.size());
79  if (0 != size) {
80  for (unsigned int i(0); i != size; ++i) {
81  keep = keep || signal[i] > 1.e-7;
82  }
83  }
84  }
85 
86  if (keep)
87  add(signal);
88  }
89 }
90 
91 void CaloHitResponse::add(const CaloSamples &signal) {
92  DetId id(signal.id());
93  CaloSamples *oldSignal = findSignal(id);
94  if (oldSignal == nullptr) {
95  theAnalogSignalMap[id] = signal;
96 
97  } else {
98  (*oldSignal) += signal;
99  }
100 }
101 
102 CaloSamples CaloHitResponse::makeAnalogSignal(const PCaloHit &hit, CLHEP::HepRandomEngine *engine) const {
103  DetId detId(hit.id());
105  double signal = analogSignalAmplitude(detId, hit.energy(), parameters, engine);
106 
107  double time = hit.time();
108  double tof = timeOfFlight(detId);
109  if (ignoreTime)
110  time = tof;
111  if (theHitCorrection != nullptr) {
112  time += theHitCorrection->delay(hit, engine);
113  }
114  double jitter = time - tof;
115 
116  const CaloVShape *shape = theShape;
117  if (!shape) {
118  shape = theShapes->shape(detId, storePrecise);
119  }
120  // assume bins count from zero, go for center of bin
121  const double tzero = (shape->timeToRise() + parameters.timePhase() - jitter -
122  BUNCHSPACE * (parameters.binOfMaximum() - thePhaseShift_));
123  double binTime = tzero;
124 
126 
127  if (storePrecise) {
128  result.resetPrecise();
129  int sampleBin(0);
130  // use 1ns binning for precise sample
131  for (int bin = 0; bin < result.size() * BUNCHSPACE; bin++) {
132  sampleBin = bin / BUNCHSPACE;
133  double pulseBit = (*shape)(binTime)*signal;
134  result[sampleBin] += pulseBit;
135  result.preciseAtMod(bin) += pulseBit;
136  binTime += 1.0;
137  }
138  } else {
139  for (int bin = 0; bin < result.size(); bin++) {
140  result[bin] += (*shape)(binTime)*signal;
141  binTime += BUNCHSPACE;
142  }
143  }
144  return result;
145 }
146 
148  float energy,
150  CLHEP::HepRandomEngine *engine) const {
151  // OK, the "energy" in the hit could be a real energy, deposited energy,
152  // or pe count. This factor converts to photoelectrons
153  // GMA Smeared in photon production it self
154  double npe = energy * parameters.simHitToPhotoelectrons(detId);
155  // do we need to doPoisson statistics for the photoelectrons?
156  if (parameters.doPhotostatistics()) {
157  npe = CLHEP::RandPoissonQ::shoot(engine, npe);
158  }
159  if (thePECorrection)
160  npe = thePECorrection->correctPE(detId, npe, engine);
161  return npe;
162 }
163 
165  CaloSamples *result = nullptr;
166  AnalogSignalMap::iterator signalItr = theAnalogSignalMap.find(detId);
167  if (signalItr == theAnalogSignalMap.end()) {
168  result = nullptr;
169  } else {
170  result = &(signalItr->second);
171  }
172  return result;
173 }
174 
177  int preciseSize(storePrecise ? parameters.readoutFrameSize() * BUNCHSPACE : 0);
178  CaloSamples result(detId, parameters.readoutFrameSize(), preciseSize);
179  result.setPresamples(parameters.binOfMaximum() - 1);
180  if (storePrecise)
181  result.setPrecise(result.presamples() * BUNCHSPACE, 1.0);
182  return result;
183 }
184 
185 double CaloHitResponse::timeOfFlight(const DetId &detId) const {
186  // not going to assume there's one of these per subdetector.
187  // Take the whole CaloGeometry and find the right subdet
188  double result = 0.;
189  if (theGeometry == nullptr) {
190  edm::LogWarning("CaloHitResponse") << "No Calo Geometry set, so no time of flight correction";
191  } else {
192  auto cellGeometry = theGeometry->getSubdetectorGeometry(detId)->getGeometry(detId);
193  if (cellGeometry == nullptr) {
194  edm::LogWarning("CaloHitResponse") << "No Calo cell found for ID" << detId.rawId()
195  << " so no time-of-flight subtraction will be done";
196  } else {
197  double distance = cellGeometry->getPosition().mag();
198  result = distance * cm / c_light; // Units of c_light: mm/ns
199  }
200  }
201  return result;
202 }
#define LogDebug(id)
size
Write out results.
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:49
CaloSamples makeBlankSignal(const DetId &detId) const
creates an empty signal for this DetId
double time() const
Definition: PCaloHit.h:30
virtual ~CaloHitResponse()
doesn&#39;t delete the pointers passed in
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
virtual const CaloVShape * shape(const DetId &detId, bool precise=false) const
Definition: CaloShapes.h:14
bool withinBunchRange(int bunchCrossing) const
check if crossing is within bunch range:
double energy() const
Definition: PCaloHit.h:24
#define nullptr
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
bool doPhotostatistics() const
whether or not to apply Poisson statistics to photoelectrons
virtual bool keepBlank() const
virtual double delay(const PCaloHit &hit, CLHEP::HepRandomEngine *) const =0
Electronic response of the preamp.
Definition: CaloVShape.h:11
void resetPrecise()
Definition: CaloSamples.cc:31
CaloHitResponse(const CaloVSimParameterMap *parameterMap, const CaloVShape *shape)
virtual void run(const MixCollection< PCaloHit > &hits, CLHEP::HepRandomEngine *)
Complete cell digitization.
Main class for Parameters in different subdetectors.
const CaloGeometry * theGeometry
const CaloVPECorrection * thePECorrection
const int keep
virtual bool accepts(const PCaloHit &hit) const =0
virtual double timeToRise() const =0
virtual CaloSamples makeAnalogSignal(const PCaloHit &inputHit, CLHEP::HepRandomEngine *) const
creates the signal corresponding to this hit
virtual const CaloSimParameters & simParameters(const DetId &id) const =0
double simHitToPhotoelectrons() const
iterator end() const
unsigned int id() const
Definition: PCaloHit.h:37
double timeOfFlight(const DetId &detId) const
int readoutFrameSize() const
for now, the LinearFrames and trhe digis will be one-to-one.
const CaloVHitCorrection * theHitCorrection
bin
set the eta bin as selection string.
AnalogSignalMap theAnalogSignalMap
Definition: DetId.h:18
double analogSignalAmplitude(const DetId &id, float energy, const CaloSimParameters &parameters, CLHEP::HepRandomEngine *) const
const CaloShapes * theShapes
const CaloVSimParameterMap * theParameterMap
int size() const
get the size
Definition: CaloSamples.h:24
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
virtual double correctPE(const DetId &detId, double npe, CLHEP::HepRandomEngine *) const =0
void setBunchRange(int minBunch, int maxBunch)
tells it which pileup bunches to do
CaloSamples * findSignal(const DetId &detId)
users can look for the signal for a given cell
float & preciseAtMod(int i)
mutable function to access precise samples
Definition: CaloSamples.h:31
virtual void add(const PCaloHit &hit, CLHEP::HepRandomEngine *)
process a single SimHit
static const double tzero[3]
const CaloVHitFilter * theHitFilter
const CaloVShape * theShape
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
iterator begin() const
int binOfMaximum() const