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 
37  : theAnalogSignalMap(),
38  theParameterMap(parametersMap),
39  theShapes(shapes),
40  theShape(nullptr),
41  theHitCorrection(nullptr),
42  thePECorrection(nullptr),
43  theHitFilter(nullptr),
44  theGeometry(nullptr),
45  theMinBunch(-10),
46  theMaxBunch(10),
47  thePhaseShift_(1.),
48  storePrecise(false),
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 }
CaloHitResponse::CaloHitResponse
CaloHitResponse(const CaloVSimParameterMap *parameterMap, const CaloVShape *shape)
Definition: CaloHitResponse.cc:21
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:30
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
hit::id
unsigned int id
Definition: SiStripHitEffFromCalibTree.cc:92
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
CaloHitResponse::analogSignalAmplitude
double analogSignalAmplitude(const DetId &id, float energy, const CaloSimParameters &parameters, CLHEP::HepRandomEngine *) const
Definition: CaloHitResponse.cc:147
CaloVSimParameterMap
Definition: CaloVSimParameterMap.h:7
MixingModule_cfi.maxBunch
maxBunch
Definition: MixingModule_cfi.py:42
edm::isNotFinite
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
CaloSamples::size
int size() const
get the size
Definition: CaloSamples.h:24
CaloVPECorrection::correctPE
virtual double correctPE(const DetId &detId, double npe, CLHEP::HepRandomEngine *) const =0
CaloGeometry::getSubdetectorGeometry
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
protons_cff.time
time
Definition: protons_cff.py:39
CaloShapes.h
CaloSimParameters.h
CaloHitResponse::thePhaseShift_
double thePhaseShift_
Definition: CaloHitResponse.h:135
CaloHitResponse::keepBlank
virtual bool keepBlank() const
Definition: CaloHitResponse.h:51
CaloHitResponse::withinBunchRange
bool withinBunchRange(int bunchCrossing) const
check if crossing is within bunch range:
Definition: CaloHitResponse.h:112
CaloVHitCorrection.h
CaloVShape::timeToRise
virtual double timeToRise() const =0
MixCollection::MixItr
Definition: MixCollection.h:61
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
CaloVHitFilter.h
CaloVHitCorrection::delay
virtual double delay(const PCaloHit &hit, CLHEP::HepRandomEngine *) const =0
DetId
Definition: DetId.h:17
MixCollection
Definition: MixCollection.h:10
CaloHitResponse::~CaloHitResponse
virtual ~CaloHitResponse()
doesn't delete the pointers passed in
Definition: CaloHitResponse.cc:51
CaloVHitFilter::accepts
virtual bool accepts(const PCaloHit &hit) const =0
CaloSimParameters
Main class for Parameters in different subdetectors.
Definition: CaloSimParameters.h:14
CaloVSimParameterMap::simParameters
virtual const CaloSimParameters & simParameters(const DetId &id) const =0
CaloHitResponse::theHitCorrection
const CaloVHitCorrection * theHitCorrection
Definition: CaloHitResponse.h:126
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
CaloHitResponse::timeOfFlight
double timeOfFlight(const DetId &detId) const
Definition: CaloHitResponse.cc:185
tzero
static const double tzero[3]
Definition: CastorTimeSlew.cc:5
CaloHitResponse::add
virtual void add(const PCaloHit &hit, CLHEP::HepRandomEngine *)
process a single SimHit
Definition: CaloHitResponse.cc:66
CaloSubdetectorGeometry.h
CaloHitResponse::makeAnalogSignal
virtual CaloSamples makeAnalogSignal(const PCaloHit &inputHit, CLHEP::HepRandomEngine *) const
creates the signal corresponding to this hit
Definition: CaloHitResponse.cc:102
CaloHitResponse::theShapes
const CaloShapes * theShapes
Definition: CaloHitResponse.h:124
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
HcalDetId.h
CaloHitResponse::setBunchRange
void setBunchRange(int minBunch, int maxBunch)
tells it which pileup bunches to do
Definition: CaloHitResponse.cc:53
PCaloHit.h
CaloHitResponse::theHitFilter
const CaloVHitFilter * theHitFilter
Definition: CaloHitResponse.h:128
CaloSamples::id
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
CaloHitResponse::theParameterMap
const CaloVSimParameterMap * theParameterMap
Definition: CaloHitResponse.h:123
CaloVSimParameterMap.h
CaloSubdetectorGeometry::getGeometry
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.
Definition: CaloSubdetectorGeometry.cc:36
CaloHitResponse::theMaxBunch
int theMaxBunch
Definition: CaloHitResponse.h:133
CaloSamples
Definition: CaloSamples.h:14
CaloHitResponse::makeBlankSignal
CaloSamples makeBlankSignal(const DetId &detId) const
creates an empty signal for this DetId
Definition: CaloHitResponse.cc:175
PCaloHit
Definition: PCaloHit.h:8
CaloHitResponse.h
CaloVShape
Electronic response of the preamp.
Definition: CaloVShape.h:11
CaloShapes
Definition: CaloShapes.h:9
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
CaloHitResponse::thePECorrection
const CaloVPECorrection * thePECorrection
Definition: CaloHitResponse.h:127
CaloVShape.h
CaloCellGeometry.h
CaloHitResponse::theAnalogSignalMap
AnalogSignalMap theAnalogSignalMap
Definition: CaloHitResponse.h:121
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
isFinite.h
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
CaloHitResponse::BUNCHSPACE
Definition: CaloHitResponse.h:37
CaloHitResponse::theGeometry
const CaloGeometry * theGeometry
Definition: CaloHitResponse.h:130
CaloShapes::shape
virtual const CaloVShape * shape(const DetId &detId, bool precise=false) const
Definition: CaloShapes.h:14
CaloHitResponse::theShape
const CaloVShape * theShape
Definition: CaloHitResponse.h:125
MixingModule_cfi.minBunch
minBunch
Definition: MixingModule_cfi.py:43
CaloHitResponse::ignoreTime
bool ignoreTime
Definition: CaloHitResponse.h:137
CaloHitResponse::findSignal
CaloSamples * findSignal(const DetId &detId)
users can look for the signal for a given cell
Definition: CaloHitResponse.cc:164
mps_fire.result
result
Definition: mps_fire.py:311
CaloHitResponse::theMinBunch
int theMinBunch
Definition: CaloHitResponse.h:132
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7733
keep
const int keep
Definition: GenParticlePruner.cc:48
CaloHitResponse::storePrecise
bool storePrecise
Definition: CaloHitResponse.h:136
hit
Definition: SiStripHitEffFromCalibTree.cc:88
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
CaloHitResponse::run
virtual void run(const MixCollection< PCaloHit > &hits, CLHEP::HepRandomEngine *)
Complete cell digitization.
Definition: CaloHitResponse.cc:58