test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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, cdfpair
cdfmap
 
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

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

Definition at line 50 of file HcalSiPM.h.

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

Definition at line 49 of file HcalSiPM.h.

Constructor & Destructor Documentation

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

Definition at line 14 of file HcalSiPM.cc.

References assert(), resetSiPM(), setTau(), and theCellCount.

14  :
15  theCellCount(nCells), theSiPM(nCells,1.),
16  theCrossTalk(0.), theTempDep(0.), theLastHitTime(-1.), nonlin(0)
17 {
18  setTau(tau);
20  resetSiPM();
21 }
double theTempDep
Definition: HcalSiPM.h:66
void resetSiPM()
Definition: HcalSiPM.h:28
assert(m_qm.get())
double theCrossTalk
Definition: HcalSiPM.h:65
std::vector< double > theSiPM
Definition: HcalSiPM.h:62
void setTau(double tau)
Definition: HcalSiPM.cc:151
double theLastHitTime
Definition: HcalSiPM.h:67
HcalSiPMnonlinearity * nonlin
Definition: HcalSiPM.h:69
unsigned int theCellCount
Definition: HcalSiPM.h:61
HcalSiPM::~HcalSiPM ( )
virtual

Definition at line 23 of file HcalSiPM.cc.

23  {
24 }

Member Function Documentation

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

Definition at line 81 of file HcalSiPM.cc.

References BorelCDF(), LogDebug, and up.

Referenced by hitCells().

82  {
83  const cdfpair& cdf = BorelCDF(in_pes);
84 
85  double U = CLHEP::RandFlat::shoot(engine);
86  std::vector<double>::const_iterator up;
87  up= std::lower_bound (cdf.second.cbegin(), cdf.second.cend(), U);
88 
89  LogDebug("HcalSiPM") << "cdf size = " << cdf.second.size()
90  << ", U = " << U
91  << ", 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 }
#define LogDebug(id)
Definition: BitonicSort.h:8
const cdfpair & BorelCDF(unsigned int k)
Definition: HcalSiPM.cc:46
std::pair< unsigned int, std::vector< double > > cdfpair
Definition: HcalSiPM.h:49
double HcalSiPM::Borel ( unsigned int  n,
double  lambda,
unsigned int  k 
)
protected

Definition at line 28 of file HcalSiPM.cc.

References b, create_public_lumi_plots::exp, dqm-mbProfile::log, and funct::pow().

Referenced by BorelCDF().

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

Definition at line 46 of file HcalSiPM.cc.

References b, Borel(), borelcdfs, alignCSCRings::e, kinem::EPSILON, plotBeamSpotDB::first, i, and theCrossTalk.

Referenced by addCrossTalkCells(), and setCrossTalk().

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

Definition at line 182 of file HcalSiPM.cc.

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

Referenced by hitCells(), and totalCharge().

182  {
183  if (deltaTime <= 0.) return 0.;
184  if (deltaTime*theTauInv > 10.) return 1.;
185  double result(1. - std::exp(-deltaTime*theTauInv));
186  return (result > 0.99) ? 1.0 : result;
187 }
double theTauInv
Definition: HcalSiPM.h:64
tuple result
Definition: mps_fire.py:84
double HcalSiPM::getCrossTalk ( ) const
inline

Definition at line 38 of file HcalSiPM.h.

References theCrossTalk.

38 { return theCrossTalk; }
double theCrossTalk
Definition: HcalSiPM.h:65
int HcalSiPM::getNCells ( ) const
inline

Definition at line 36 of file HcalSiPM.h.

References theCellCount.

36 { return theCellCount; }
unsigned int theCellCount
Definition: HcalSiPM.h:61
double HcalSiPM::getTau ( ) const
inline

Definition at line 37 of file HcalSiPM.h.

References theTau.

37 { return theTau; }
double theTau
Definition: HcalSiPM.h:63
double HcalSiPM::getTempDep ( ) const
inline

Definition at line 39 of file HcalSiPM.h.

References theTempDep.

39 { return theTempDep; }
double theTempDep
Definition: HcalSiPM.h:66
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(), theCellCount, theCrossTalk, theLastHitTime, theSiPM, theTau, and theTempDep.

Referenced by HcalSiPMHitResponse::makeSiPMSignal().

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

Definition at line 28 of file HcalSiPM.h.

References lumiContext::fill, and theSiPM.

Referenced by HcalSiPM(), and setNCells().

28 { std::fill(theSiPM.begin(), theSiPM.end(), -999.); }
string fill
Definition: lumiContext.py:319
std::vector< double > theSiPM
Definition: HcalSiPM.h:62
void HcalSiPM::setCrossTalk ( double  xtalk)

Definition at line 157 of file HcalSiPM.cc.

References BorelCDF(), borelcdfs, relval_2017::k, and theCrossTalk.

Referenced by HcalSiPMHitResponse::makeSiPMSignal().

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

Definition at line 144 of file HcalSiPM.cc.

References assert(), resetSiPM(), theCellCount, and theSiPM.

Referenced by HcalSiPMHitResponse::makeSiPMSignal().

144  {
145  assert(nCells>0);
146  theCellCount = nCells;
147  theSiPM.resize(nCells);
148  resetSiPM();
149 }
void resetSiPM()
Definition: HcalSiPM.h:28
assert(m_qm.get())
std::vector< double > theSiPM
Definition: HcalSiPM.h:62
unsigned int theCellCount
Definition: HcalSiPM.h:61
void HcalSiPM::setSaturationPars ( const std::vector< float > &  pars)

Definition at line 189 of file HcalSiPM.cc.

References nonlin.

Referenced by HcalSiPMHitResponse::makeSiPMSignal().

190 {
191  if (nonlin)
192  delete nonlin;
193 
194  nonlin = new HcalSiPMnonlinearity(pars);
195 }
HcalSiPMnonlinearity * nonlin
Definition: HcalSiPM.h:69
void HcalSiPM::setTau ( double  tau)

Definition at line 151 of file HcalSiPM.cc.

References metsig::tau, theTau, and theTauInv.

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

151  {
152  theTau = tau;
153  if(theTau > 0) theTauInv = 1./theTau;
154  else theTauInv = 0;
155 }
double theTauInv
Definition: HcalSiPM.h:64
double theTau
Definition: HcalSiPM.h:63
void HcalSiPM::setTemperatureDependence ( double  tempDep)

Definition at line 177 of file HcalSiPM.cc.

References theTempDep.

177  {
178  // set the temperature dependence
179  theTempDep = dTemp;
180 }
double theTempDep
Definition: HcalSiPM.h:66
virtual double HcalSiPM::totalCharge ( ) const
inlinevirtual

Definition at line 33 of file HcalSiPM.h.

References theLastHitTime, and totalCharge().

Referenced by totalCharge().

33 { return totalCharge(theLastHitTime); }
virtual double totalCharge() const
Definition: HcalSiPM.h:33
double theLastHitTime
Definition: HcalSiPM.h:67
double HcalSiPM::totalCharge ( double  time) const
virtual

Definition at line 133 of file HcalSiPM.cc.

References cellCharge(), i, theCellCount, and theSiPM.

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

Member Data Documentation

cdfmap HcalSiPM::borelcdfs
protected

Definition at line 71 of file HcalSiPM.h.

Referenced by BorelCDF(), and setCrossTalk().

HcalSiPMnonlinearity* HcalSiPM::nonlin
protected

Definition at line 69 of file HcalSiPM.h.

Referenced by setSaturationPars().

unsigned int HcalSiPM::theCellCount
protected

Definition at line 61 of file HcalSiPM.h.

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

double HcalSiPM::theCrossTalk
protected

Definition at line 65 of file HcalSiPM.h.

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

double HcalSiPM::theLastHitTime
protected

Definition at line 67 of file HcalSiPM.h.

Referenced by hitCells(), and totalCharge().

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

Definition at line 62 of file HcalSiPM.h.

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

double HcalSiPM::theTau
protected

Definition at line 63 of file HcalSiPM.h.

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

double HcalSiPM::theTauInv
protected

Definition at line 64 of file HcalSiPM.h.

Referenced by cellCharge(), and setTau().

double HcalSiPM::theTempDep
protected

Definition at line 66 of file HcalSiPM.h.

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