CMS 3D CMS Logo

HcalSiPMHitResponse.cc
Go to the documentation of this file.
13 
14 #include "CLHEP/Random/RandPoissonQ.h"
15 
16 #include <cmath>
17 #include <list>
18 
20  const CaloShapes* shapes,
21  bool PreMix1,
22  bool HighFidelity)
23  : CaloHitResponse(parameterMap, shapes),
24  theSiPM(),
25  PreMixDigis(PreMix1),
26  HighFidelityPreMix(HighFidelity),
27  nbins((PreMixDigis and HighFidelityPreMix) ? 1 : BUNCHSPACE * HcalPulseShapes::invDeltaTSiPM_),
28  dt(HcalPulseShapes::deltaTSiPM_),
29  invdt(HcalPulseShapes::invDeltaTSiPM_) {
30  //fill shape map
35 }
36 
38 
40 
43  int readoutFrameSize = parameters.readoutFrameSize();
45  //preserve fidelity of time info
47  }
48  return readoutFrameSize;
49 }
50 
51 void HcalSiPMHitResponse::finalizeHits(CLHEP::HepRandomEngine* engine) {
52  //do not add PE noise for initial premix
53  if (!PreMixDigis)
54  addPEnoise(engine);
55 
56  photonTimeMap::iterator channelPhotons;
57  for (channelPhotons = precisionTimedPhotons.begin(); channelPhotons != precisionTimedPhotons.end();
58  ++channelPhotons) {
59  CaloSamples signal(makeSiPMSignal(channelPhotons->first, channelPhotons->second, engine));
60  bool keep(keepBlank());
61  if (!keep) {
62  const unsigned int size(signal.size());
63  if (0 != size) {
64  for (unsigned int i(0); i != size; ++i) {
65  keep = keep || signal[i] > 1.e-7;
66  }
67  }
68  }
69 
70  LogDebug("HcalSiPMHitResponse") << HcalDetId(signal.id()) << ' ' << signal;
71 
72  //if we don't want to keep precise info at the end
73  if (!HighFidelityPreMix) {
74  signal.setPreciseSize(0);
75  }
76 
77  if (keep)
78  CaloHitResponse::add(signal);
79  }
80 }
81 
82 //used for premixing - premixed CaloSamples have fine time binning
84  if (!HighFidelityPreMix) {
85  CaloHitResponse::add(signal);
86  return;
87  }
88  DetId id(signal.id());
89  int photonTimeHistSize = nbins * getReadoutFrameSize(id);
90  assert(photonTimeHistSize == signal.size());
91  if (precisionTimedPhotons.find(id) == precisionTimedPhotons.end()) {
92  precisionTimedPhotons.insert(std::pair<DetId, photonTimeHist>(id, photonTimeHist(photonTimeHistSize, 0)));
93  }
94  for (int i = 0; i < signal.size(); ++i) {
95  unsigned int photons(signal[i] + 0.5);
97  }
98 }
99 
100 void HcalSiPMHitResponse::add(const PCaloHit& hit, CLHEP::HepRandomEngine* engine) {
101  if (!edm::isNotFinite(hit.time()) && ((theHitFilter == nullptr) || (theHitFilter->accepts(hit)))) {
102  HcalDetId id(hit.id());
103  const HcalSimParameters& pars = dynamic_cast<const HcalSimParameters&>(theParameterMap->simParameters(id));
104  //divide out mean of crosstalk distribution 1/(1-lambda) = multiply by (1-lambda)
105  double signal(analogSignalAmplitude(id, hit.energy(), pars, engine) * (1 - pars.sipmCrossTalk(id)));
106  unsigned int photons(signal + 0.5);
107  double tof(timeOfFlight(id));
108  double time(hit.time());
109  if (ignoreTime)
110  time = tof;
111 
112  if (photons > 0)
113  if (precisionTimedPhotons.find(id) == precisionTimedPhotons.end()) {
114  precisionTimedPhotons.insert(
115  std::pair<DetId, photonTimeHist>(id, photonTimeHist(nbins * getReadoutFrameSize(id), 0)));
116  }
117 
118  LogDebug("HcalSiPMHitResponse") << id;
119  LogDebug("HcalSiPMHitResponse") << " fCtoGeV: " << pars.fCtoGeV(id)
120  << " samplingFactor: " << pars.samplingFactor(id)
121  << " photoelectronsToAnalog: " << pars.photoelectronsToAnalog(id)
122  << " simHitToPhotoelectrons: " << pars.simHitToPhotoelectrons(id);
123  LogDebug("HcalSiPMHitResponse") << " energy: " << hit.energy() << " photons: " << photons << " time: " << time;
124  LogDebug("HcalSiPMHitResponse") << " timePhase: " << pars.timePhase() << " tof: " << tof
125  << " binOfMaximum: " << pars.binOfMaximum() << " phaseShift: " << thePhaseShift_;
126  double tzero(0.0 + pars.timePhase() - (time - tof) - BUNCHSPACE * (pars.binOfMaximum() - thePhaseShift_));
127  LogDebug("HcalSiPMHitResponse") << " tzero: " << tzero;
128  double tzero_bin(-tzero * invdt);
129  LogDebug("HcalSiPMHitResponse") << " corrected tzero: " << tzero_bin << '\n';
130  double t_pe(0.);
131  int t_bin(0);
132  unsigned signalShape = pars.signalShape(id);
133  for (unsigned int pe(0); pe < photons; ++pe) {
134  t_pe = HcalPulseShapes::generatePhotonTime(engine, signalShape);
135  t_bin = int(t_pe * invdt + tzero_bin + 0.5);
136  LogDebug("HcalSiPMHitResponse") << "t_pe: " << t_pe << " t_pe + tzero: " << (t_pe + tzero_bin * dt)
137  << " t_bin: " << t_bin << '\n';
138  if ((t_bin >= 0) && (static_cast<unsigned int>(t_bin) < precisionTimedPhotons[id].size()))
139  precisionTimedPhotons[id][t_bin] += 1;
140  }
141  }
142 }
143 
144 void HcalSiPMHitResponse::addPEnoise(CLHEP::HepRandomEngine* engine) {
145  // Add SiPM dark current noise to all cells
146  for (std::vector<DetId>::const_iterator idItr = theDetIds->begin(); idItr != theDetIds->end(); ++idItr) {
147  HcalDetId id(*idItr);
148  const HcalSimParameters& pars = static_cast<const HcalSimParameters&>(theParameterMap->simParameters(id));
149 
150  // uA * ns / (fC/pe) = pe!
151  double dc_pe_avg = pars.sipmDarkCurrentuA(id) * dt / pars.photoelectronsToAnalog(id);
152 
153  if (dc_pe_avg <= 0.)
154  continue;
155 
156  int nPreciseBins = nbins * getReadoutFrameSize(id);
157 
158  unsigned int sumnoisePE(0);
159  for (int tprecise(0); tprecise < nPreciseBins; ++tprecise) {
160  int noisepe = CLHEP::RandPoissonQ::shoot(engine, dc_pe_avg); // add dark current noise
161 
162  if (noisepe > 0) {
163  if (precisionTimedPhotons.find(id) == precisionTimedPhotons.end()) {
164  photonTimeHist photons(nPreciseBins, 0);
165  photons[tprecise] = noisepe;
166  precisionTimedPhotons.insert(std::pair<DetId, photonTimeHist>(id, photons));
167  } else {
168  precisionTimedPhotons[id][tprecise] += noisepe;
169  }
170 
171  sumnoisePE += noisepe;
172  }
173 
174  } // precise time loop
175 
176  LogDebug("HcalSiPMHitResponse") << id;
177  LogDebug("HcalSiPMHitResponse") << " total noise (PEs): " << sumnoisePE;
178 
179  } // detId loop
180 } // HcalSiPMHitResponse::addPEnoise()
181 
185  int preciseSize(readoutFrameSize * nbins);
186  CaloSamples result(detId, readoutFrameSize, preciseSize);
187  result.setPresamples(parameters.binOfMaximum() - 1);
188  result.setPrecise(result.presamples() * nbins, dt);
189  return result;
190 }
191 
193  photonTimeHist const& photonTimeBins,
194  CLHEP::HepRandomEngine* engine) {
195  const HcalSimParameters& pars = static_cast<const HcalSimParameters&>(theParameterMap->simParameters(id));
196  theSiPM.setNCells(pars.pixels(id));
197  theSiPM.setTau(pars.sipmTau());
200 
201  //use to make signal
202  CaloSamples signal(makeBlankSignal(id));
203  int sampleBin(0), preciseBin(0);
204  signal.resetPrecise();
205  unsigned int pe(0);
206  double hitPixels(0.), elapsedTime(0.);
207 
208  auto& sipmPulseShape(shapeMap[pars.signalShape(id)]);
209 
210  std::list<std::pair<double, double> > pulses;
211  std::list<std::pair<double, double> >::iterator pulse;
212  double timeDiff, pulseBit;
213  LogDebug("HcalSiPMHitResponse") << "makeSiPMSignal for " << HcalDetId(id);
214 
215  for (unsigned int tbin(0); tbin < photonTimeBins.size(); ++tbin) {
216  pe = photonTimeBins[tbin];
217  preciseBin = tbin;
218  sampleBin = preciseBin / nbins;
219  if (pe > 0) {
220  //skip saturation/recovery and pulse smearing for premix stage 1
222  signal[sampleBin] += pe;
223  signal.preciseAtMod(preciseBin) += pe;
224  elapsedTime += dt;
225  continue;
226  }
227 
228  hitPixels = theSiPM.hitCells(engine, pe, 0., elapsedTime);
229  LogDebug("HcalSiPMHitResponse") << " elapsedTime: " << elapsedTime << " sampleBin: " << sampleBin
230  << " preciseBin: " << preciseBin << " pe: " << pe << " hitPixels: " << hitPixels;
231  if (pars.doSiPMSmearing()) {
232  pulses.push_back(std::pair<double, double>(elapsedTime, hitPixels));
233  } else {
234  signal[sampleBin] += hitPixels;
235  signal.preciseAtMod(preciseBin) += 0.6 * hitPixels;
236  if (preciseBin > 0)
237  signal.preciseAtMod(preciseBin - 1) += 0.2 * hitPixels;
238  if (preciseBin < signal.preciseSize() - 1)
239  signal.preciseAtMod(preciseBin + 1) += 0.2 * hitPixels;
240  }
241  }
242 
243  if (pars.doSiPMSmearing()) {
244  pulse = pulses.begin();
245  while (pulse != pulses.end()) {
246  timeDiff = elapsedTime - pulse->first;
247  pulseBit = sipmPulseShape(timeDiff) * pulse->second;
248  LogDebug("HcalSiPMHitResponse") << " pulse t: " << pulse->first << " pulse A: " << pulse->second
249  << " timeDiff: " << timeDiff << " pulseBit: " << pulseBit;
250  signal[sampleBin] += pulseBit;
251  signal.preciseAtMod(preciseBin) += pulseBit;
252 
253  if (timeDiff > 1 && sipmPulseShape(timeDiff) < 1e-7)
254  pulse = pulses.erase(pulse);
255  else
256  ++pulse;
257  }
258  }
259  elapsedTime += dt;
260  }
261 
262  return signal;
263 }
264 
265 void HcalSiPMHitResponse::setDetIds(const std::vector<DetId>& detIds) { theDetIds = &detIds; }
size
Write out results.
float dt
Definition: AMPTWrapper.h:136
int size() const
get the size
Definition: CaloSamples.h:24
const std::vector< DetId > * theDetIds
void finalizeHits(CLHEP::HepRandomEngine *) override
Finalize hits.
void setSaturationPars(const std::vector< float > &pars)
Definition: HcalSiPM.cc:192
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
virtual int getReadoutFrameSize(const DetId &id) const
int pixels(const DetId &detId) const
void resetPrecise()
Definition: CaloSamples.cc:31
assert(be >=bs)
Main class for Parameters in different subdetectors.
double sipmCrossTalk(const DetId &detId) const
virtual void addPEnoise(CLHEP::HepRandomEngine *engine)
double analogSignalAmplitude(const DetId &id, float energy, const CaloSimParameters &parameters, CLHEP::HepRandomEngine *) const
virtual CaloSamples makeBlankSignal(const DetId &detId) const
bool doSiPMSmearing() const
Creates electronics signals from hits.
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
virtual double hitCells(CLHEP::HepRandomEngine *, unsigned int pes, double tempDiff=0., double photonTime=0.)
Definition: HcalSiPM.cc:100
void setNCells(int nCells)
Definition: HcalSiPM.cc:143
void setTau(double tau)
Definition: HcalSiPM.cc:150
virtual bool keepBlank() const
double sipmDarkCurrentuA(const DetId &detId) const
int preciseSize() const
get the size
Definition: CaloSamples.h:70
virtual const CaloSimParameters & simParameters(const DetId &id) const =0
void add(const PCaloHit &hit, CLHEP::HepRandomEngine *) override
process a single SimHit
void setCrossTalk(double xtalk)
Definition: HcalSiPM.cc:158
virtual void setDetIds(const std::vector< DetId > &detIds)
virtual bool accepts(const PCaloHit &hit) const =0
unsigned int signalShape(const DetId &detId) const
unsigned int id
static constexpr float invDeltaTSiPM_
Definition: DetId.h:17
std::vector< unsigned int > photonTimeHist
double pulse(double x, double y, double z, double t)
const CaloVSimParameterMap * theParameterMap
static double generatePhotonTime(CLHEP::HepRandomEngine *engine, unsigned int signalShape)
void initializeHits() override
Initialize hits.
virtual CaloSamples makeSiPMSignal(DetId const &id, photonTimeHist const &photons, CLHEP::HepRandomEngine *)
double timeOfFlight(const DetId &detId) const
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
std::map< int, HcalSiPMShape > shapeMap
static const double tzero[3]
HcalSiPMHitResponse(const CaloVSimParameterMap *parameterMap, const CaloShapes *shapes, bool PreMix1=false, bool HighFidelity=true)
const CaloVHitFilter * theHitFilter
photonTimeMap precisionTimedPhotons
void setPreciseSize(unsigned int size)
Definition: CaloSamples.h:60
double photoelectronsToAnalog(const DetId &detId) const override
std::vector< float > sipmNonlinearity(const DetId &detId) const
#define LogDebug(id)
double sipmTau() const