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