CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes
HcalSiPM Class Reference

A general implementation for the response of a SiPM. More...

#include <HcalSiPM.h>

Public Member Functions

double getCrossTalk () const
 
int getNCells () const
 
double getTau () const
 
double getTempDep () const
 
 HcalSiPM (int nCells=1, double tau=15.)
 
virtual double hitCells (CLHEP::HepRandomEngine *, unsigned int pes, double tempDiff=0., double photonTime=0.)
 
void resetSiPM ()
 
void setCrossTalk (double xtalk)
 
void setNCells (int nCells)
 
void setSaturationPars (const std::vector< float > &pars)
 
void setTau (double tau)
 
void setTemperatureDependence (double tempDep)
 
virtual double totalCharge () const
 
virtual double totalCharge (double time) const
 
virtual ~HcalSiPM ()
 

Protected Types

typedef std::unordered_map< unsigned int, cdfpaircdfmap
 
typedef std::pair< unsigned int, std::vector< double > > cdfpair
 

Protected Member Functions

unsigned int addCrossTalkCells (CLHEP::HepRandomEngine *engine, unsigned int in_pes)
 
double Borel (unsigned int n, double lambda, unsigned int k)
 
const cdfpairBorelCDF (unsigned int k)
 
double cellCharge (double deltaTime) const
 

Protected Attributes

cdfmap borelcdfs
 
HcalSiPMnonlinearitynonlin
 
unsigned int theCellCount
 
double theCrossTalk
 
double theLastHitTime
 
std::vector< double > theSiPM
 
double theTau
 
double theTauInv
 
double theTempDep
 

Detailed Description

A general implementation for the response of a SiPM.

Definition at line 22 of file HcalSiPM.h.

Member Typedef Documentation

◆ cdfmap

typedef std::unordered_map<unsigned int, cdfpair> HcalSiPM::cdfmap
protected

Definition at line 47 of file HcalSiPM.h.

◆ cdfpair

typedef std::pair<unsigned int, std::vector<double> > HcalSiPM::cdfpair
protected

Definition at line 46 of file HcalSiPM.h.

Constructor & Destructor Documentation

◆ HcalSiPM()

HcalSiPM::HcalSiPM ( int  nCells = 1,
double  tau = 15. 
)

Definition at line 14 of file HcalSiPM.cc.

References cms::cuda::assert(), resetSiPM(), setTau(), metsig::tau, and theCellCount.

15  : theCellCount(nCells), theSiPM(nCells, 1.), theCrossTalk(0.), theTempDep(0.), theLastHitTime(-1.), nonlin(nullptr) {
16  setTau(tau);
17  assert(theCellCount > 0);
18  resetSiPM();
19 }
double theTempDep
Definition: HcalSiPM.h:63
void resetSiPM()
Definition: HcalSiPM.h:28
assert(be >=bs)
double theCrossTalk
Definition: HcalSiPM.h:62
std::vector< double > theSiPM
Definition: HcalSiPM.h:59
void setTau(double tau)
Definition: HcalSiPM.cc:150
double theLastHitTime
Definition: HcalSiPM.h:64
TupleMultiplicity< TrackerTraits > const HitToTuple< TrackerTraits > const cms::cuda::AtomicPairCounter GPUCACellT< TrackerTraits > const *__restrict__ uint32_t const *__restrict__ nCells
HcalSiPMnonlinearity * nonlin
Definition: HcalSiPM.h:66
unsigned int theCellCount
Definition: HcalSiPM.h:58

◆ ~HcalSiPM()

HcalSiPM::~HcalSiPM ( )
virtual

Definition at line 21 of file HcalSiPM.cc.

References nonlin.

21  {
22  if (nonlin)
23  delete nonlin;
24 }
HcalSiPMnonlinearity * nonlin
Definition: HcalSiPM.h:66

Member Function Documentation

◆ addCrossTalkCells()

unsigned int HcalSiPM::addCrossTalkCells ( CLHEP::HepRandomEngine *  engine,
unsigned int  in_pes 
)
protected

Definition at line 84 of file HcalSiPM.cc.

References BorelCDF(), LogDebug, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, mitigatedMETSequence_cff::U, and up.

Referenced by hitCells().

84  {
85  const cdfpair& cdf = BorelCDF(in_pes);
86 
87  double U = CLHEP::RandFlat::shoot(engine);
88  std::vector<double>::const_iterator up;
89  up = std::lower_bound(cdf.second.cbegin(), cdf.second.cend(), U);
90 
91  LogDebug("HcalSiPM") << "cdf size = " << cdf.second.size() << ", U = " << U << ", in_pes = " << in_pes
92  << ", 2ndary_pes = " << (up - cdf.second.cbegin() + cdf.first);
93 
94  // returns the number of secondary pes produced
95  return (up - cdf.second.cbegin() + cdf.first);
96 }
Definition: BitonicSort.h:7
const cdfpair & BorelCDF(unsigned int k)
Definition: HcalSiPM.cc:47
std::pair< unsigned int, std::vector< double > > cdfpair
Definition: HcalSiPM.h:46
#define LogDebug(id)

◆ Borel()

double HcalSiPM::Borel ( unsigned int  n,
double  lambda,
unsigned int  k 
)
protected

Definition at line 28 of file HcalSiPM.cc.

References b, JetChargeProducer_cfi::exp, dqmdumpme::k, dqm-mbProfile::log, dqmiodumpmetadata::n, and funct::pow().

Referenced by BorelCDF().

28  {
29  if (n < k)
30  return 0;
31  double dn = double(n);
32  double dk = double(k);
33  double dnk = dn - dk;
34  double ldn = lambda * dn;
35  double logb = -ldn + dnk * log(ldn) - TMath::LnGamma(dnk + 1);
36  double b = 0;
37  if (logb >= -20) { // protect against underflow
38  b = (dk / dn);
39  if ((n - k) < 100)
40  b *= (exp(-ldn) * pow(ldn, dnk)) / TMath::Factorial(n - k);
41  else
42  b *= exp(logb);
43  }
44  return b;
45 }
double b
Definition: hdecay.h:118
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ BorelCDF()

const HcalSiPM::cdfpair & HcalSiPM::BorelCDF ( unsigned int  k)
protected

Definition at line 47 of file HcalSiPM.cc.

References b, Borel(), borelcdfs, MillePedeFileConverter_cfg::e, kinem::EPSILON, dqmdumpme::first, mps_fire::i, dqmdumpme::k, and theCrossTalk.

Referenced by addCrossTalkCells(), and setCrossTalk().

47  {
48  // EPSILON determines the min and max # of xtalk cells that can be
49  // simulated.
50  static const double EPSILON = 1e-6;
51  typename cdfmap::const_iterator it;
52  it = borelcdfs.find(k);
53  if (it == borelcdfs.end()) {
54  vector<double> cdf;
55 
56  // Find the first n=k+i value for which cdf[i] > EPSILON
57  unsigned int i;
58  double b = 0., sumb = 0.;
59  for (i = 0;; i++) {
60  b = Borel(k + i, theCrossTalk, k);
61  sumb += b;
62  if (sumb >= EPSILON)
63  break;
64  }
65 
66  cdf.push_back(sumb);
67  unsigned int borelstartn = i;
68 
69  // calculate cdf[i]
70  for (++i;; ++i) {
71  b = Borel(k + i, theCrossTalk, k);
72  sumb += b;
73  cdf.push_back(sumb);
74  if (1 - sumb < EPSILON)
75  break;
76  }
77 
78  it = (borelcdfs.emplace(k, make_pair(borelstartn, cdf))).first;
79  }
80 
81  return it->second;
82 }
double theCrossTalk
Definition: HcalSiPM.h:62
double Borel(unsigned int n, double lambda, unsigned int k)
Definition: HcalSiPM.cc:28
cdfmap borelcdfs
Definition: HcalSiPM.h:68
const float EPSILON
Definition: AnglesUtil.h:22
double b
Definition: hdecay.h:118

◆ cellCharge()

double HcalSiPM::cellCharge ( double  deltaTime) const
protected

Definition at line 183 of file HcalSiPM.cc.

References JetChargeProducer_cfi::exp, mps_fire::result, and theTauInv.

Referenced by hitCells(), and totalCharge().

183  {
184  if (deltaTime <= 0.)
185  return 0.;
186  if (deltaTime * theTauInv > 10.)
187  return 1.;
188  double result(1. - std::exp(-deltaTime * theTauInv));
189  return (result > 0.99) ? 1.0 : result;
190 }
double theTauInv
Definition: HcalSiPM.h:61

◆ getCrossTalk()

double HcalSiPM::getCrossTalk ( ) const
inline

Definition at line 36 of file HcalSiPM.h.

References theCrossTalk.

36 { return theCrossTalk; }
double theCrossTalk
Definition: HcalSiPM.h:62

◆ getNCells()

int HcalSiPM::getNCells ( ) const
inline

Definition at line 34 of file HcalSiPM.h.

References theCellCount.

34 { return theCellCount; }
unsigned int theCellCount
Definition: HcalSiPM.h:58

◆ getTau()

double HcalSiPM::getTau ( ) const
inline

Definition at line 35 of file HcalSiPM.h.

References theTau.

35 { return theTau; }
double theTau
Definition: HcalSiPM.h:60

◆ getTempDep()

double HcalSiPM::getTempDep ( ) const
inline

Definition at line 37 of file HcalSiPM.h.

References theTempDep.

37 { return theTempDep; }
double theTempDep
Definition: HcalSiPM.h:63

◆ hitCells()

double HcalSiPM::hitCells ( CLHEP::HepRandomEngine *  engine,
unsigned int  pes,
double  tempDiff = 0.,
double  photonTime = 0. 
)
virtual

Definition at line 100 of file HcalSiPM.cc.

References addCrossTalkCells(), cellCharge(), muonClassificationByHits_cfi::pixel, theCellCount, theCrossTalk, theLastHitTime, theSiPM, theTau, and theTempDep.

Referenced by HcalSiPMHitResponse::makeSiPMSignal().

100  {
101  // response to light impulse with pes input photons. The return is the number
102  // of micro-pixels hit. If a fraction other than 0. is supplied then the
103  // micro-pixel doesn't fully discharge. The tempDiff is the temperature
104  // difference from nominal and is used to modify the relative strength of a
105  // hit pixel. Pixels which are fractionally charged return a fractional
106  // number of hit pixels.
107 
108  if ((theCrossTalk > 0.) && (theCrossTalk < 1.))
109  pes += addCrossTalkCells(engine, pes);
110 
111  // Account for saturation - disabled in lieu of recovery model below
112  //pes = nonlin->getPixelsFired(pes);
113 
114  //disable saturation/recovery model for bad tau values
115  if (theTau <= 0)
116  return pes;
117 
118  unsigned int pixel;
119  double sum(0.), hit(0.);
120  for (unsigned int pe(0); pe < pes; ++pe) {
121  pixel = CLHEP::RandFlat::shootInt(engine, theCellCount);
122  hit = (theSiPM[pixel] < 0.) ? 1.0 : (cellCharge(photonTime - theSiPM[pixel]));
123  sum += hit * (1 + (tempDiff * theTempDep));
124  theSiPM[pixel] = photonTime;
125  }
126 
127  theLastHitTime = photonTime;
128 
129  return sum;
130 }
double theTempDep
Definition: HcalSiPM.h:63
double theCrossTalk
Definition: HcalSiPM.h:62
std::vector< double > theSiPM
Definition: HcalSiPM.h:59
double theLastHitTime
Definition: HcalSiPM.h:64
unsigned int addCrossTalkCells(CLHEP::HepRandomEngine *engine, unsigned int in_pes)
Definition: HcalSiPM.cc:84
double theTau
Definition: HcalSiPM.h:60
unsigned int theCellCount
Definition: HcalSiPM.h:58
double cellCharge(double deltaTime) const
Definition: HcalSiPM.cc:183

◆ resetSiPM()

void HcalSiPM::resetSiPM ( )
inline

Definition at line 28 of file HcalSiPM.h.

References ntuplemaker::fill, and theSiPM.

Referenced by HcalSiPM(), and setNCells().

28 { std::fill(theSiPM.begin(), theSiPM.end(), -999.); }
std::vector< double > theSiPM
Definition: HcalSiPM.h:59

◆ setCrossTalk()

void HcalSiPM::setCrossTalk ( double  xtalk)

Definition at line 158 of file HcalSiPM.cc.

References BorelCDF(), borelcdfs, dqmdumpme::k, theCrossTalk, and hgchebackDigitizer_cfi::xTalk.

Referenced by HcalSiPMHitResponse::makeSiPMSignal().

158  {
159  // set the cross-talk probability
160 
161  double oldCrossTalk = theCrossTalk;
162 
163  if ((xTalk < 0) || (xTalk >= 1)) {
164  theCrossTalk = 0.;
165  } else {
167  }
168 
169  // Recalculate the crosstalk CDFs
170  if (theCrossTalk != oldCrossTalk) {
171  borelcdfs.clear();
172  if (theCrossTalk > 0)
173  for (int k = 1; k <= 100; k++)
174  BorelCDF(k);
175  }
176 }
double theCrossTalk
Definition: HcalSiPM.h:62
const cdfpair & BorelCDF(unsigned int k)
Definition: HcalSiPM.cc:47
cdfmap borelcdfs
Definition: HcalSiPM.h:68

◆ setNCells()

void HcalSiPM::setNCells ( int  nCells)

Definition at line 143 of file HcalSiPM.cc.

References cms::cuda::assert(), caHitNtupletGeneratorKernels::nCells, resetSiPM(), theCellCount, and theSiPM.

Referenced by HcalSiPMHitResponse::makeSiPMSignal().

143  {
144  assert(nCells > 0);
146  theSiPM.resize(nCells);
147  resetSiPM();
148 }
void resetSiPM()
Definition: HcalSiPM.h:28
assert(be >=bs)
std::vector< double > theSiPM
Definition: HcalSiPM.h:59
TupleMultiplicity< TrackerTraits > const HitToTuple< TrackerTraits > const cms::cuda::AtomicPairCounter GPUCACellT< TrackerTraits > const *__restrict__ uint32_t const *__restrict__ nCells
unsigned int theCellCount
Definition: HcalSiPM.h:58

◆ setSaturationPars()

void HcalSiPM::setSaturationPars ( const std::vector< float > &  pars)

Definition at line 192 of file HcalSiPM.cc.

References nonlin.

Referenced by HcalSiPMHitResponse::makeSiPMSignal().

192  {
193  if (nonlin)
194  delete nonlin;
195 
196  nonlin = new HcalSiPMnonlinearity(pars);
197 }
HcalSiPMnonlinearity * nonlin
Definition: HcalSiPM.h:66

◆ setTau()

void HcalSiPM::setTau ( double  tau)

Definition at line 150 of file HcalSiPM.cc.

References metsig::tau, theTau, and theTauInv.

Referenced by HcalSiPM(), and HcalSiPMHitResponse::makeSiPMSignal().

150  {
151  theTau = tau;
152  if (theTau > 0)
153  theTauInv = 1. / theTau;
154  else
155  theTauInv = 0;
156 }
double theTauInv
Definition: HcalSiPM.h:61
double theTau
Definition: HcalSiPM.h:60

◆ setTemperatureDependence()

void HcalSiPM::setTemperatureDependence ( double  tempDep)

Definition at line 178 of file HcalSiPM.cc.

References theTempDep.

178  {
179  // set the temperature dependence
180  theTempDep = dTemp;
181 }
double theTempDep
Definition: HcalSiPM.h:63

◆ totalCharge() [1/2]

virtual double HcalSiPM::totalCharge ( ) const
inlinevirtual

Definition at line 31 of file HcalSiPM.h.

References theLastHitTime, and totalCharge().

Referenced by totalCharge().

31 { return totalCharge(theLastHitTime); }
double theLastHitTime
Definition: HcalSiPM.h:64
virtual double totalCharge() const
Definition: HcalSiPM.h:31

◆ totalCharge() [2/2]

double HcalSiPM::totalCharge ( double  time) const
virtual

Definition at line 132 of file HcalSiPM.cc.

References cellCharge(), mps_fire::i, theCellCount, theSiPM, protons_cff::time, and compareTotals::tot.

132  {
133  // sum of the micro-pixels. NP is a fully charged device.
134  // 0 is a fullly depleted device.
135  double tot(0.), hit(0.);
136  for (unsigned int i = 0; i < theCellCount; ++i) {
137  hit = (theSiPM[i] < 0.) ? 1. : cellCharge(time - theSiPM[i]);
138  tot += hit;
139  }
140  return tot;
141 }
std::vector< double > theSiPM
Definition: HcalSiPM.h:59
unsigned int theCellCount
Definition: HcalSiPM.h:58
double cellCharge(double deltaTime) const
Definition: HcalSiPM.cc:183

Member Data Documentation

◆ borelcdfs

cdfmap HcalSiPM::borelcdfs
protected

Definition at line 68 of file HcalSiPM.h.

Referenced by BorelCDF(), and setCrossTalk().

◆ nonlin

HcalSiPMnonlinearity* HcalSiPM::nonlin
protected

Definition at line 66 of file HcalSiPM.h.

Referenced by setSaturationPars(), and ~HcalSiPM().

◆ theCellCount

unsigned int HcalSiPM::theCellCount
protected

Definition at line 58 of file HcalSiPM.h.

Referenced by getNCells(), HcalSiPM(), hitCells(), setNCells(), and totalCharge().

◆ theCrossTalk

double HcalSiPM::theCrossTalk
protected

Definition at line 62 of file HcalSiPM.h.

Referenced by BorelCDF(), getCrossTalk(), hitCells(), and setCrossTalk().

◆ theLastHitTime

double HcalSiPM::theLastHitTime
protected

Definition at line 64 of file HcalSiPM.h.

Referenced by hitCells(), and totalCharge().

◆ theSiPM

std::vector<double> HcalSiPM::theSiPM
protected

Definition at line 59 of file HcalSiPM.h.

Referenced by hitCells(), resetSiPM(), setNCells(), and totalCharge().

◆ theTau

double HcalSiPM::theTau
protected

Definition at line 60 of file HcalSiPM.h.

Referenced by getTau(), hitCells(), and setTau().

◆ theTauInv

double HcalSiPM::theTauInv
protected

Definition at line 61 of file HcalSiPM.h.

Referenced by cellCharge(), and setTau().

◆ theTempDep

double HcalSiPM::theTempDep
protected

Definition at line 63 of file HcalSiPM.h.

Referenced by getTempDep(), hitCells(), and setTemperatureDependence().