CMS 3D CMS Logo

EcalHitResponse.cc
Go to the documentation of this file.
13 #include "CLHEP/Random/RandPoissonQ.h"
15 
16 #include "CLHEP/Units/GlobalPhysicalConstants.h"
17 #include "CLHEP/Units/GlobalSystemOfUnits.h"
18 #include <iostream>
19 
21  : m_parameterMap(parameterMap),
22  m_shape(shape),
23  m_hitCorrection(nullptr),
24  m_PECorrection(nullptr),
25  m_hitFilter(nullptr),
26  m_geometry(nullptr),
27  m_lasercals(nullptr),
28  m_minBunch(-32),
29  m_maxBunch(10),
30  m_phaseShift(1),
31  m_iTime(0),
32  m_useLCcorrection(false) {}
33 
35 
36 const CaloSimParameters* EcalHitResponse::params(const DetId& detId) const {
37  assert(nullptr != m_parameterMap);
38  return &m_parameterMap->simParameters(detId);
39 }
40 
42  assert(nullptr != m_shape);
43  return m_shape;
44 }
45 
47  assert(nullptr != m_geometry);
48  return m_geometry;
49 }
50 
54 }
55 
57 
59 
60 double EcalHitResponse::phaseShift() const { return m_phaseShift; }
61 
63 
64 void EcalHitResponse::setHitCorrection(const CaloVHitCorrection* hitCorrection) { m_hitCorrection = hitCorrection; }
65 
66 void EcalHitResponse::setPECorrection(const CaloVPECorrection* peCorrection) { m_PECorrection = peCorrection; }
67 
69  m_iTime = iTime;
70  //clear the laser cache for each event time
72 }
73 
74 void EcalHitResponse::setLaserConstants(const EcalLaserDbService* laser, bool& useLCcorrection) {
76  m_useLCcorrection = useLCcorrection;
77 }
78 
79 void EcalHitResponse::blankOutUsedSamples() // blank out previously used elements
80 {
81  const unsigned int size(m_index.size());
82 
83  for (unsigned int i(0); i != size; ++i) {
84  vSamAll(m_index[i])->setZero();
85  }
86  m_index.erase(m_index.begin(), // done and make ready to start over
87  m_index.end());
88 }
89 
90 void EcalHitResponse::add(const PCaloHit& hit, CLHEP::HepRandomEngine* engine) {
91  if (!edm::isNotFinite(hit.time()) && (nullptr == m_hitFilter || m_hitFilter->accepts(hit))) {
92  putAnalogSignal(hit, engine);
93  }
94 }
95 
97  const DetId detId(hit.id());
98 
99  EcalSamples& result(*findSignal(detId));
100 
101  const int rsize(result.size());
102 
103  if (rsize != hit.size()) {
104  throw cms::Exception("EcalDigitization") << "CaloSamples and EcalSamples have different sizes. Type Mismatach";
105  }
106 
107  for (int bin(0); bin != rsize; ++bin) {
108  result[bin] += hit[bin];
109  }
110 }
111 
112 bool EcalHitResponse::withinBunchRange(int bunchCrossing) const {
113  return (m_minBunch <= bunchCrossing && m_maxBunch >= bunchCrossing);
114 }
115 
117 
119 
120 void EcalHitResponse::run(MixCollection<PCaloHit>& hits, CLHEP::HepRandomEngine* engine) {
122 
123  for (MixCollection<PCaloHit>::MixItr hitItr(hits.begin()); hitItr != hits.end(); ++hitItr) {
124  const PCaloHit& hit(*hitItr);
125  const int bunch(hitItr.bunch());
126  if (withinBunchRange(bunch) && !edm::isNotFinite(hit.time()) &&
127  (nullptr == m_hitFilter || m_hitFilter->accepts(hit)))
128  putAnalogSignal(hit, engine);
129  }
130 }
131 
132 void EcalHitResponse::putAnalogSignal(const PCaloHit& hit, CLHEP::HepRandomEngine* engine) {
133  const DetId detId(hit.id());
134 
135  const CaloSimParameters* parameters(params(detId));
136 
137  const double signal(analogSignalAmplitude(detId, hit.energy(), engine));
138 
139  double time = hit.time();
140 
141  if (m_hitCorrection) {
142  time += m_hitCorrection->delay(hit, engine);
143  }
144 
145  const double jitter(time - timeOfFlight(detId));
146 
147  const double tzero = (shape()->timeToRise() + parameters->timePhase() - jitter -
148  kSamplePeriod * (parameters->binOfMaximum() - m_phaseShift));
149  double binTime(tzero);
150 
151  EcalSamples& result(*findSignal(detId));
152 
153  const unsigned int rsize(result.size());
154 
155  for (unsigned int bin(0); bin != rsize; ++bin) {
156  result[bin] += (*shape())(binTime)*signal;
157  binTime += kSamplePeriod;
158  }
159 }
160 
161 double EcalHitResponse::findLaserConstant(const DetId& detId) const {
162  const edm::Timestamp& evtTimeStamp = edm::Timestamp(m_iTime);
163  return (m_lasercals->getLaserCorrection(detId, evtTimeStamp));
164 }
165 
167  const unsigned int di(CaloGenericDetId(detId).denseIndex());
168  EcalSamples* result(vSamAll(di));
169  if (result->zero())
170  m_index.push_back(di);
171  return result;
172 }
173 
174 double EcalHitResponse::analogSignalAmplitude(const DetId& detId, double energy, CLHEP::HepRandomEngine* engine) {
175  const CaloSimParameters& parameters(*params(detId));
176 
177  // OK, the "energy" in the hit could be a real energy, deposited energy,
178  // or pe count. This factor converts to photoelectrons
179 
180  double lasercalib = 1.;
181  if (m_useLCcorrection == true && detId.subdetId() != 3) {
182  auto cache = m_laserCalibCache.find(detId);
183  if (cache != m_laserCalibCache.end()) {
184  lasercalib = cache->second;
185  } else {
186  lasercalib = 1.0 / findLaserConstant(detId);
187  m_laserCalibCache.emplace(detId, lasercalib);
188  }
189  }
190 
191  double npe(energy * lasercalib * parameters.simHitToPhotoelectrons(detId));
192 
193  // do we need to doPoisson statistics for the photoelectrons?
194  if (parameters.doPhotostatistics()) {
195  npe = CLHEP::RandPoissonQ::shoot(engine, npe);
196  }
197  if (nullptr != m_PECorrection)
198  npe = m_PECorrection->correctPE(detId, npe, engine);
199 
200  return npe;
201 }
202 
203 double EcalHitResponse::timeOfFlight(const DetId& detId) const {
204  auto cellGeometry(geometry()->getGeometry(detId));
205  assert(nullptr != cellGeometry);
206  return cellGeometry->getPosition().mag() * cm / c_light; // Units of c_light: mm/ns
207 }
208 
210  EcalSamples& sam(*findSignal(pSam->id()));
211  sam += (*pSam);
212 }
213 
214 int EcalHitResponse::minBunch() const { return m_minBunch; }
215 
216 int EcalHitResponse::maxBunch() const { return m_maxBunch; }
217 
219 
221 
223 
225  const unsigned int di(CaloGenericDetId(detId).denseIndex());
226  return vSamAll(di);
227 }
EcalHitResponse.h
EcalHitResponse::setBunchRange
void setBunchRange(int minBunch, int maxBunch)
Definition: EcalHitResponse.cc:51
EcalHitResponse::~EcalHitResponse
virtual ~EcalHitResponse()
Definition: EcalHitResponse.cc:34
CaloGenericDetId.h
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:30
EcalHitResponse::m_phaseShift
double m_phaseShift
Definition: EcalHitResponse.h:131
mps_fire.i
i
Definition: mps_fire.py:428
EcalHitResponse::withinBunchRange
bool withinBunchRange(int bunchCrossing) const
Definition: EcalHitResponse.cc:112
funct::false
false
Definition: Factorize.h:29
CaloTSamplesBase::id
DetId id() const
hit::id
unsigned int id
Definition: SiStripHitEffFromCalibTree.cc:92
EcalHitResponse::minBunch
int minBunch() const
Definition: EcalHitResponse.cc:214
EcalHitResponse::findDetId
const EcalSamples * findDetId(const DetId &detId) const
Definition: EcalHitResponse.cc:224
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
CaloGenericDetId
Definition: CaloGenericDetId.h:12
EcalHitResponse::CalibCache
std::unordered_map< uint32_t, double > CalibCache
Definition: EcalHitResponse.h:35
CaloVSimParameterMap
Definition: CaloVSimParameterMap.h:7
EcalHitResponse::blankOutUsedSamples
void blankOutUsedSamples()
Definition: EcalHitResponse.cc:79
MixingModule_cfi.maxBunch
maxBunch
Definition: MixingModule_cfi.py:42
edm::isNotFinite
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
EcalHitResponse::m_hitFilter
const CaloVHitFilter * m_hitFilter
Definition: EcalHitResponse.h:124
geometry
Definition: geometry.py:1
EcalHitResponse::timeOfFlight
double timeOfFlight(const DetId &detId) const
Definition: EcalHitResponse.cc:203
CaloVPECorrection::correctPE
virtual double correctPE(const DetId &detId, double npe, CLHEP::HepRandomEngine *) const =0
EcalHitResponse::setEventTime
void setEventTime(const edm::TimeValue_t &iTime)
Definition: EcalHitResponse.cc:68
CaloTSamplesBase
Definition: CaloTSamplesBase.h:9
EcalHitResponse::putAnalogSignal
virtual void putAnalogSignal(const PCaloHit &inputHit, CLHEP::HepRandomEngine *)
Definition: EcalHitResponse.cc:132
cms::cuda::assert
assert(be >=bs)
protons_cff.time
time
Definition: protons_cff.py:39
CaloSimParameters.h
EcalHitResponse::phaseShift
double phaseShift() const
Definition: EcalHitResponse.cc:60
CaloVHitCorrection.h
EcalHitResponse::m_minBunch
int m_minBunch
Definition: EcalHitResponse.h:129
ESDetId.h
CaloVShape::timeToRise
virtual double timeToRise() const =0
EcalHitResponse::m_shape
const CaloVShape * m_shape
Definition: EcalHitResponse.h:121
MixCollection::MixItr
Definition: MixCollection.h:61
CaloVPECorrection
Definition: CaloVPECorrection.h:14
EcalHitResponse::setPhaseShift
void setPhaseShift(double phaseShift)
Definition: EcalHitResponse.cc:58
CaloVHitFilter.h
CaloVHitCorrection::delay
virtual double delay(const PCaloHit &hit, CLHEP::HepRandomEngine *) const =0
EcalHitResponse::setLaserConstants
void setLaserConstants(const EcalLaserDbService *laser, bool &useLCcorrection)
Definition: EcalHitResponse.cc:74
DetId
Definition: DetId.h:17
EcalHitResponse::m_lasercals
const EcalLaserDbService * m_lasercals
Definition: EcalHitResponse.h:126
EcalHitResponse::m_iTime
edm::TimeValue_t m_iTime
Definition: EcalHitResponse.h:133
EcalLaserDbService
Definition: EcalLaserDbService.h:25
MixCollection
Definition: MixCollection.h:10
EcalHitResponse::setHitCorrection
void setHitCorrection(const CaloVHitCorrection *hitCorrection)
Definition: EcalHitResponse.cc:64
CaloVPECorrection.h
EcalLaserDbService.h
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
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
tzero
static const double tzero[3]
Definition: CastorTimeSlew.cc:5
ALCARECOTkAlBeamHalo_cff.filter
filter
Definition: ALCARECOTkAlBeamHalo_cff.py:27
EcalHitResponse::findLaserConstant
double findLaserConstant(const DetId &detId) const
Definition: EcalHitResponse.cc:161
utilities.cache
def cache(function)
Definition: utilities.py:3
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
EcalHitResponse::setPECorrection
void setPECorrection(const CaloVPECorrection *peCorrection)
Definition: EcalHitResponse.cc:66
EcalHitResponse::index
VecInd & index()
Definition: EcalHitResponse.cc:218
EcalHitResponse::params
const CaloSimParameters * params(const DetId &detId) const
Definition: EcalHitResponse.cc:36
CaloSubdetectorGeometry.h
EcalHitResponse::setHitFilter
void setHitFilter(const CaloVHitFilter *filter)
Definition: EcalHitResponse.cc:62
EcalHitResponse::vSamAll
virtual EcalSamples * vSamAll(unsigned int i)=0
EcalHitResponse::m_maxBunch
int m_maxBunch
Definition: EcalHitResponse.h:130
CaloVHitCorrection
Definition: CaloVHitCorrection.h:10
EcalHitResponse::setGeometry
void setGeometry(const CaloSubdetectorGeometry *geometry)
Definition: EcalHitResponse.cc:56
EcalHitResponse::m_index
VecInd m_index
Definition: EcalHitResponse.h:137
EcalHitResponse::EcalHitResponse
EcalHitResponse(const CaloVSimParameterMap *parameterMap, const CaloVShape *shape)
Definition: EcalHitResponse.cc:20
CaloTSamplesBase::setZero
void setZero()
CaloVSimParameterMap.h
EcalHitResponse::m_parameterMap
const CaloVSimParameterMap * m_parameterMap
Definition: EcalHitResponse.h:120
CaloSamples
Definition: CaloSamples.h:14
EcalHitResponse::m_hitCorrection
const CaloVHitCorrection * m_hitCorrection
Definition: EcalHitResponse.h:122
PCaloHit
Definition: PCaloHit.h:8
EcalHitResponse::geometry
const CaloSubdetectorGeometry * geometry() const
Definition: EcalHitResponse.cc:46
CaloVShape
Electronic response of the preamp.
Definition: CaloVShape.h:11
EcalHitResponse::findSignal
EcalSamples * findSignal(const DetId &detId)
Definition: EcalHitResponse.cc:166
EcalHitResponse::maxBunch
int maxBunch() const
Definition: EcalHitResponse.cc:216
EcalHitResponse::initializeHits
virtual void initializeHits()
Definition: EcalHitResponse.cc:116
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
EcalHitResponse::add
void add(const EcalSamples *pSam)
Definition: EcalHitResponse.cc:209
EcalLaserDbService::getLaserCorrection
float getLaserCorrection(DetId const &xid, edm::Timestamp const &iTime) const
Definition: EcalLaserDbService.cc:30
EcalHitResponse::m_PECorrection
const CaloVPECorrection * m_PECorrection
Definition: EcalHitResponse.h:123
CaloVShape.h
CaloCellGeometry.h
EcalHitResponse::VecInd
std::vector< unsigned int > VecInd
Definition: EcalHitResponse.h:33
EcalHitResponse::m_useLCcorrection
bool m_useLCcorrection
Definition: EcalHitResponse.h:134
EcalHitResponse::shape
const CaloVShape * shape() const
Definition: EcalHitResponse.cc:41
isFinite.h
EcalHitResponse::hitFilter
const CaloVHitFilter * hitFilter() const
Definition: EcalHitResponse.cc:222
EcalHitResponse::finalizeHits
virtual void finalizeHits()
Definition: EcalHitResponse.cc:118
Exception
Definition: hltDiff.cc:245
CaloVHitFilter
Definition: CaloVHitFilter.h:6
MixingModule_cfi.minBunch
minBunch
Definition: MixingModule_cfi.py:43
CaloSubdetectorGeometry
Definition: CaloSubdetectorGeometry.h:22
EcalHitResponse::m_geometry
const CaloSubdetectorGeometry * m_geometry
Definition: EcalHitResponse.h:125
EcalHitResponse::run
virtual void run(MixCollection< PCaloHit > &hits, CLHEP::HepRandomEngine *)
Definition: EcalHitResponse.cc:120
mps_fire.result
result
Definition: mps_fire.py:311
EcalHitResponse::kSamplePeriod
const float kSamplePeriod
Definition: EcalHitResponse.h:41
EcalHitResponse::m_laserCalibCache
CalibCache m_laserCalibCache
Definition: EcalHitResponse.h:135
EcalHitResponse::analogSignalAmplitude
double analogSignalAmplitude(const DetId &id, double energy, CLHEP::HepRandomEngine *)
Definition: EcalHitResponse.cc:174
EcalCondDBWriter_cfi.laser
laser
Definition: EcalCondDBWriter_cfi.py:46
hit
Definition: SiStripHitEffFromCalibTree.cc:88
edm::TimeValue_t
unsigned long long TimeValue_t
Definition: Timestamp.h:28
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
edm::Timestamp
Definition: Timestamp.h:30