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]; }
size
Write out results.
double time() const
Definition: PCaloHit.h:30
double simToPEHigh() const
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
const self & getMap() const
std::vector< EBSamples > m_vSam
Definition: EBHitResponse.h:94
EcalSamples * operator[](unsigned int i) override
double energy() const
Definition: PCaloHit.h:24
#define nullptr
const CaloVShape * m_apdShape
Definition: EBHitResponse.h:84
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
void putAPDSignal(const DetId &detId, double npe, double time)
unsigned int samplesSize() const override
virtual void putAnalogSignal(const PCaloHit &inputHit, CLHEP::HepRandomEngine *)
Electronic response of the preamp.
Definition: CaloVShape.h:11
uint16_t depth() const
Definition: PCaloHit.h:43
double timeOfFlight(const DetId &detId) const
const APDSimParameters * apdParameters() const
const APDSimParameters * m_apdPars
Definition: EBHitResponse.h:83
Main class for Parameters in different subdetectors.
const CaloSimParameters * params(const DetId &detId) const
static EBDetId detIdFromDenseIndex(uint32_t di)
Definition: EBDetId.h:107
void findIntercalibConstant(const DetId &detId, double &icalconst) const
virtual bool accepts(const PCaloHit &hit) const =0
unsigned int samplesSizeAll() const override
double phaseShift() const
~EBHitResponse() override
void setIntercal(const EcalIntercalibConstantsMC *ical)
const CaloVHitFilter * hitFilter() const
const VecD & offsets() const
Definition: EBHitResponse.h:62
void initializeHits() override
int maxBunch() const
virtual const CaloSimParameters & simParameters(const DetId &id) const =0
void blankOutUsedSamples()
double apdSignalAmplitude(const PCaloHit &hit, CLHEP::HepRandomEngine *) const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
double simHitToPhotoelectrons() const
iterator end() const
int minBunch() const
unsigned int id() const
Definition: PCaloHit.h:37
const EcalIntercalibConstantsMC * m_intercal
Definition: EBHitResponse.h:85
std::vector< double > m_timeOffVec
Definition: EBHitResponse.h:87
EcalSamples * vSamAll(unsigned int i) override
#define M_PI
bin
set the eta bin as selection string.
EBHitResponse(const CaloVSimParameterMap *parameterMap, const CaloVShape *shape, bool apdOnly, const APDSimParameters *apdPars, const CaloVShape *apdShape)
Definition: DetId.h:18
EcalSamples * vSam(unsigned int i) override
std::vector< Item >::const_iterator const_iterator
bool m_isInitialized
Definition: EBHitResponse.h:96
const double nonlFunc(double enr) const
Definition: EBHitResponse.h:64
uint32_t size() const
void initialize(CLHEP::HepRandomEngine *)
static const double tzero[3]
EcalSamples * findSignal(const DetId &detId)
float EcalIntercalibConstantMC
iterator begin() const
const bool m_apdOnly
Definition: EBHitResponse.h:82
void run(MixCollection< PCaloHit > &hits, CLHEP::HepRandomEngine *) override
int binOfMaximum() const
double simToPELow() const
void finalizeHits() override
std::vector< double > m_apdTimeVec
Definition: EBHitResponse.h:90
std::vector< double > m_apdNpeVec
Definition: EBHitResponse.h:89
const CaloVShape * apdShape() const
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39
void add(const PCaloHit &hit, CLHEP::HepRandomEngine *) override
static const int kEcalDepthIdMask
Definition: PCaloHit.h:60