CMS 3D CMS Logo

EBHitResponse.cc
Go to the documentation of this file.
8 #include "CLHEP/Random/RandPoissonQ.h"
9 #include "CLHEP/Random/RandGaussQ.h"
14 
16  const CaloVShape* shape,
17  bool apdOnly,
18  const APDSimParameters* apdPars = nullptr,
19  const CaloVShape* apdShape = nullptr)
20  :
21 
22  EcalHitResponse(parameterMap, shape),
23 
24  m_apdOnly(apdOnly),
25  m_apdPars(apdPars),
26  m_apdShape(apdShape),
27  m_timeOffVec(kNOffsets, apdParameters()->timeOffset()),
28  pcub(nullptr == apdPars ? 0 : apdParameters()->nonlParms()[0]),
29  pqua(nullptr == apdPars ? 0 : apdParameters()->nonlParms()[1]),
30  plin(nullptr == apdPars ? 0 : apdParameters()->nonlParms()[2]),
31  pcon(nullptr == apdPars ? 0 : apdParameters()->nonlParms()[3]),
32  pelo(nullptr == apdPars ? 0 : apdParameters()->nonlParms()[4]),
33  pehi(nullptr == apdPars ? 0 : apdParameters()->nonlParms()[5]),
34  pasy(nullptr == apdPars ? 0 : apdParameters()->nonlParms()[6]),
35  pext(nullptr == apdPars ? 0 : nonlFunc1(pelo)),
36  poff(nullptr == apdPars ? 0 : nonlFunc1(pehi)),
37  pfac(nullptr == apdPars ? 0 : (pasy - poff) * 2. / M_PI),
38  m_isInitialized(false) {
39  const EBDetId detId(EBDetId::detIdFromDenseIndex(0));
40  const CaloSimParameters& parameters(parameterMap->simParameters(detId));
41 
42  const unsigned int rSize(parameters.readoutFrameSize());
43  const unsigned int nPre(parameters.binOfMaximum() - 1);
44 
45  const unsigned int size(EBDetId::kSizeForDenseIndexing);
46 
47  m_vSam.reserve(size);
48 
49  for (unsigned int i(0); i != size; ++i) {
50  m_vSam.emplace_back(CaloGenericDetId(detId.det(), detId.subdetId(), i), rSize, nPre);
51  }
52 }
53 
55 
56 void EBHitResponse::initialize(CLHEP::HepRandomEngine* engine) {
57  m_isInitialized = true;
58  for (unsigned int i(0); i != kNOffsets; ++i) {
59  m_timeOffVec[i] += CLHEP::RandGaussQ::shoot(engine, 0, apdParameters()->timeOffWidth());
60  }
61 }
62 
64  assert(nullptr != m_apdPars);
65  return m_apdPars;
66 }
67 
69  assert(nullptr != m_apdShape);
70  return m_apdShape;
71 }
72 
73 void EBHitResponse::putAPDSignal(const DetId& detId, double npe, double time) {
74  const CaloSimParameters& parameters(*params(detId));
75 
76  const double energyFac(1. / parameters.simHitToPhotoelectrons(detId));
77 
78  // std::cout<<"******** Input APD Npe="<<npe<<", Efactor="<<energyFac
79  // <<", Energy="<<npe*energyFac
80  // <<", nonlFunc="<<nonlFunc( npe*energyFac )<<std::endl ;
81 
82  const double signal(npe * nonlFunc(npe * energyFac));
83 
84  const double jitter(time - timeOfFlight(detId));
85 
86  if (!m_isInitialized) {
87  throw cms::Exception("LogicError") << "EBHitResponse::putAPDSignal called without initializing\n";
88  }
89 
90  const double tzero(apdShape()->timeToRise() - jitter - offsets()[EBDetId(detId).denseIndex() % kNOffsets] -
91  BUNCHSPACE * (parameters.binOfMaximum() - phaseShift()));
92 
93  double binTime(tzero);
94 
95  EcalSamples& result(*findSignal(detId));
96 
97  for (unsigned int bin(0); bin != result.size(); ++bin) {
98  result[bin] += (*apdShape())(binTime)*signal;
99  binTime += BUNCHSPACE;
100  }
101 }
102 
103 double EBHitResponse::apdSignalAmplitude(const PCaloHit& hit, CLHEP::HepRandomEngine* engine) const {
104  int iddepth = (hit.depth() & PCaloHit::kEcalDepthIdMask);
105  assert(1 == iddepth || 2 == iddepth);
106 
107  double npe(hit.energy() * (2 == iddepth ? apdParameters()->simToPELow() : apdParameters()->simToPEHigh()));
108 
109  // do we need to do Poisson statistics for the photoelectrons?
110  if (apdParameters()->doPEStats() && !m_apdOnly) {
111  CLHEP::RandPoissonQ randPoissonQ(*engine, npe);
112  npe = randPoissonQ.fire();
113  }
114  assert(nullptr != m_intercal);
115  double fac(1);
116  findIntercalibConstant(hit.id(), fac);
117 
118  npe *= fac;
119 
120  // edm::LogError( "EBHitResponse" ) << "--- # photoelectrons for "
121  /* std::cout << "--- # photoelectrons for "
122  << EBDetId( hit.id() )
123  <<" is " << npe //;
124  <<std::endl ;*/
125 
126  return npe;
127 }
128 
130 
131 void EBHitResponse::findIntercalibConstant(const DetId& detId, double& icalconst) const {
132  EcalIntercalibConstantMC thisconst(1.);
133 
134  if (nullptr == m_intercal) {
135  edm::LogError("EBHitResponse") << "No intercal constant defined for EBHitResponse";
136  } else {
137  const EcalIntercalibConstantMCMap& icalMap(m_intercal->getMap());
138  EcalIntercalibConstantMCMap::const_iterator icalit(icalMap.find(detId));
139  if (icalit != icalMap.end()) {
140  thisconst = *icalit;
141  if (thisconst == 0.)
142  thisconst = 1.;
143  } else {
144  edm::LogError("EBHitResponse") << "No intercalib const found for xtal " << detId.rawId()
145  << "! something wrong with EcalIntercalibConstants in your DB? ";
146  }
147  }
148  icalconst = thisconst;
149 }
150 
152  if (!index().empty())
154 
155  const unsigned int bSize(EBDetId::kSizeForDenseIndexing);
156 
157  if (m_apdNpeVec.empty()) {
158  m_apdNpeVec = std::vector<double>(bSize, (double)0.0);
159  m_apdTimeVec = std::vector<double>(bSize, (double)0.0);
160  }
161 }
162 
164  const unsigned int bSize(EBDetId::kSizeForDenseIndexing);
165  if (apdParameters()->addToBarrel() || m_apdOnly) {
166  for (unsigned int i(0); i != bSize; ++i) {
167  if (0 < m_apdNpeVec[i]) {
169 
170  // now zero out for next time
171  m_apdNpeVec[i] = 0.;
172  m_apdTimeVec[i] = 0.;
173  }
174  }
175  }
176 }
177 
178 void EBHitResponse::add(const PCaloHit& hit, CLHEP::HepRandomEngine* engine) {
179  if (!edm::isNotFinite(hit.time()) && (nullptr == hitFilter() || hitFilter()->accepts(hit))) {
180  int iddepth = (hit.depth() & PCaloHit::kEcalDepthIdMask);
181  if (0 == iddepth) // for now take only nonAPD hits
182  {
183  if (!m_apdOnly)
184  putAnalogSignal(hit, engine);
185  } else // APD hits here
186  {
187  if (apdParameters()->addToBarrel() || m_apdOnly) {
188  const unsigned int icell(EBDetId(hit.id()).denseIndex());
189  m_apdNpeVec[icell] += apdSignalAmplitude(hit, engine);
190  if (0 == m_apdTimeVec[icell])
191  m_apdTimeVec[icell] = hit.time();
192  }
193  }
194  }
195 }
196 
197 void EBHitResponse::run(MixCollection<PCaloHit>& hits, CLHEP::HepRandomEngine* engine) {
198  if (!index().empty())
200 
201  const unsigned int bSize(EBDetId::kSizeForDenseIndexing);
202 
203  if (m_apdNpeVec.empty()) {
204  m_apdNpeVec = std::vector<double>(bSize, (double)0.0);
205  m_apdTimeVec = std::vector<double>(bSize, (double)0.0);
206  }
207 
208  for (MixCollection<PCaloHit>::MixItr hitItr(hits.begin()); hitItr != hits.end(); ++hitItr) {
209  const PCaloHit& hit(*hitItr);
210  const int bunch(hitItr.bunch());
211  if (minBunch() <= bunch && maxBunch() >= bunch && !edm::isNotFinite(hit.time()) &&
212  (nullptr == hitFilter() || hitFilter()->accepts(hit))) {
213  int iddepth = (hit.depth() & PCaloHit::kEcalDepthIdMask);
214  if (0 == iddepth) // for now take only nonAPD hits
215  {
216  if (!m_apdOnly)
217  putAnalogSignal(hit, engine);
218  } else // APD hits here
219  {
220  if (apdParameters()->addToBarrel() || m_apdOnly) {
221  const unsigned int icell(EBDetId(hit.id()).denseIndex());
222  m_apdNpeVec[icell] += apdSignalAmplitude(hit, engine);
223  if (0 == m_apdTimeVec[icell])
224  m_apdTimeVec[icell] = hit.time();
225  }
226  }
227  }
228  }
229 
230  if (apdParameters()->addToBarrel() || m_apdOnly) {
231  for (unsigned int i(0); i != bSize; ++i) {
232  if (0 < m_apdNpeVec[i]) {
234 
235  // now zero out for next time
236  m_apdNpeVec[i] = 0.;
237  m_apdTimeVec[i] = 0.;
238  }
239  }
240  }
241 }
242 
243 unsigned int EBHitResponse::samplesSize() const { return m_vSam.size(); }
244 
245 unsigned int EBHitResponse::samplesSizeAll() const { return m_vSam.size(); }
246 
247 const EcalHitResponse::EcalSamples* EBHitResponse::operator[](unsigned int i) const { return &m_vSam[i]; }
248 
250 
252 
254 
255 const EcalHitResponse::EcalSamples* EBHitResponse::vSamAll(unsigned int i) const { return &m_vSam[i]; }
EcalCondObjectContainer::getMap
const self & getMap() const
Definition: EcalCondObjectContainer.h:80
EBHitResponse::run
void run(MixCollection< PCaloHit > &hits, CLHEP::HepRandomEngine *) override
Definition: EBHitResponse.cc:197
CaloGenericDetId.h
EBHitResponse::m_apdNpeVec
std::vector< double > m_apdNpeVec
Definition: EBHitResponse.h:89
EBHitResponse::m_isInitialized
bool m_isInitialized
Definition: EBHitResponse.h:96
mps_fire.i
i
Definition: mps_fire.py:355
funct::false
false
Definition: Factorize.h:34
hit::id
unsigned int id
Definition: SiStripHitEffFromCalibTree.cc:92
APDSimParameters::simToPEHigh
double simToPEHigh() const
Definition: APDSimParameters.h:36
EcalHitResponse::minBunch
int minBunch() const
Definition: EcalHitResponse.cc:214
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
CaloGenericDetId
Definition: CaloGenericDetId.h:12
EBHitResponse::add
void add(const PCaloHit &hit, CLHEP::HepRandomEngine *) override
Definition: EBHitResponse.cc:178
EBHitResponse::m_timeOffVec
std::vector< double > m_timeOffVec
Definition: EBHitResponse.h:87
CaloVSimParameterMap
Definition: CaloVSimParameterMap.h:7
EcalHitResponse::blankOutUsedSamples
void blankOutUsedSamples()
Definition: EcalHitResponse.cc:79
edm::isNotFinite
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
EBDetId
Definition: EBDetId.h:17
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
EBHitResponse::apdSignalAmplitude
double apdSignalAmplitude(const PCaloHit &hit, CLHEP::HepRandomEngine *) const
Definition: EBHitResponse.cc:103
EcalHitResponse::timeOfFlight
double timeOfFlight(const DetId &detId) const
Definition: EcalHitResponse.cc:203
EBDetId.h
CaloTSamplesBase
Definition: CaloTSamplesBase.h:9
EBHitResponse::initializeHits
void initializeHits() override
Definition: EBHitResponse.cc:151
EcalHitResponse::putAnalogSignal
virtual void putAnalogSignal(const PCaloHit &inputHit, CLHEP::HepRandomEngine *)
Definition: EcalHitResponse.cc:132
cms::cuda::assert
assert(be >=bs)
EBHitResponse::apdShape
const CaloVShape * apdShape() const
Definition: EBHitResponse.cc:68
CaloSimParameters.h
hgcalLayerClusters_cfi.timeOffset
timeOffset
Definition: hgcalLayerClusters_cfi.py:56
EBHitResponse.h
EcalHitResponse::phaseShift
double phaseShift() const
Definition: EcalHitResponse.cc:60
APDSimParameters
Definition: APDSimParameters.h:8
EcalCondObjectContainer< float >
EBHitResponse::m_intercal
const EcalIntercalibConstantsMC * m_intercal
Definition: EBHitResponse.h:85
EBHitResponse::m_apdShape
const CaloVShape * m_apdShape
Definition: EBHitResponse.h:84
MixCollection::MixItr
Definition: MixCollection.h:62
CaloVHitFilter.h
parameters
parameters
Definition: BeamSpot_PayloadInspector.cc:14
EBHitResponse::setIntercal
void setIntercal(const EcalIntercalibConstantsMC *ical)
Definition: EBHitResponse.cc:129
DetId
Definition: DetId.h:17
EBHitResponse::putAPDSignal
void putAPDSignal(const DetId &detId, double npe, double time)
Definition: EBHitResponse.cc:73
EBHitResponse::nonlFunc
const double nonlFunc(double enr) const
Definition: EBHitResponse.h:64
EBHitResponse::EBHitResponse
EBHitResponse(const CaloVSimParameterMap *parameterMap, const CaloVShape *shape, bool apdOnly, const APDSimParameters *apdPars, const CaloVShape *apdShape)
Definition: EBHitResponse.cc:15
MixCollection
Definition: MixCollection.h:11
EBHitResponse::m_apdPars
const APDSimParameters * m_apdPars
Definition: EBHitResponse.h:83
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
EBHitResponse::samplesSize
unsigned int samplesSize() const override
Definition: EBHitResponse.cc:243
tzero
static const double tzero[3]
Definition: CastorTimeSlew.cc:5
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::index
VecInd & index()
Definition: EcalHitResponse.cc:218
EcalHitResponse::params
const CaloSimParameters * params(const DetId &detId) const
Definition: EcalHitResponse.cc:36
edm::LogError
Definition: MessageLogger.h:183
EBDetId::detIdFromDenseIndex
static EBDetId detIdFromDenseIndex(uint32_t di)
Definition: EBDetId.h:107
PCaloHit.h
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:50
CaloVSimParameterMap.h
EcalHitResponse
Definition: EcalHitResponse.h:28
EBHitResponse::vSamAll
EcalSamples * vSamAll(unsigned int i) override
Definition: EBHitResponse.cc:253
PCaloHit
Definition: PCaloHit.h:8
CaloVShape
Electronic response of the preamp.
Definition: CaloVShape.h:11
EBHitResponse::m_vSam
std::vector< EBSamples > m_vSam
Definition: EBHitResponse.h:94
EcalHitResponse::findSignal
EcalSamples * findSignal(const DetId &detId)
Definition: EcalHitResponse.cc:166
EBHitResponse::offsets
const VecD & offsets() const
Definition: EBHitResponse.h:62
EBHitResponse::finalizeHits
void finalizeHits() override
Definition: EBHitResponse.cc:163
EcalHitResponse::maxBunch
int maxBunch() const
Definition: EcalHitResponse.cc:216
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
APDSimParameters.h
CaloVShape.h
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
EcalIntercalibConstantMC
float EcalIntercalibConstantMC
Definition: EcalIntercalibConstantsMC.h:10
isFinite.h
EcalHitResponse::hitFilter
const CaloVHitFilter * hitFilter() const
Definition: EcalHitResponse.cc:222
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
Exception
Definition: hltDiff.cc:246
EBHitResponse::apdParameters
const APDSimParameters * apdParameters() const
Definition: EBHitResponse.cc:63
EBDetId::kSizeForDenseIndexing
Definition: EBDetId.h:155
EBHitResponse::m_apdOnly
const bool m_apdOnly
Definition: EBHitResponse.h:82
Exception.h
EBHitResponse::findIntercalibConstant
void findIntercalibConstant(const DetId &detId, double &icalconst) const
Definition: EBHitResponse.cc:131
EcalCondObjectContainer< float >::const_iterator
std::vector< Item >::const_iterator const_iterator
Definition: EcalCondObjectContainer.h:19
mps_fire.result
result
Definition: mps_fire.py:303
EBHitResponse::m_apdTimeVec
std::vector< double > m_apdTimeVec
Definition: EBHitResponse.h:90
EBHitResponse::operator[]
EcalSamples * operator[](unsigned int i) override
Definition: EBHitResponse.cc:249
EBHitResponse::~EBHitResponse
~EBHitResponse() override
Definition: EBHitResponse.cc:54
ntuplemaker.time
time
Definition: ntuplemaker.py:310
EBHitResponse::kNOffsets
Definition: EBHitResponse.h:20
EBHitResponse::initialize
void initialize(CLHEP::HepRandomEngine *)
Definition: EBHitResponse.cc:56
EcalHitResponse::BUNCHSPACE
Definition: EcalHitResponse.h:36
APDSimParameters::simToPELow
double simToPELow() const
Definition: APDSimParameters.h:35
EBHitResponse::vSam
EcalSamples * vSam(unsigned int i) override
Definition: EBHitResponse.cc:251
EBHitResponse::samplesSizeAll
unsigned int samplesSizeAll() const override
Definition: EBHitResponse.cc:245
hit
Definition: SiStripHitEffFromCalibTree.cc:88
PCaloHit::kEcalDepthIdMask
static const int kEcalDepthIdMask
Definition: PCaloHit.h:60
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443