CMS 3D CMS Logo

HcalDeterministicFit.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <cmath>
3 #include <climits>
5 
11 
12 using namespace std;
13 
15 }
16 
18 }
19 
20 void HcalDeterministicFit::init(HcalTimeSlew::ParaSource tsParam, HcalTimeSlew::BiasSetting bias, bool iApplyTimeSlew, PedestalSub pedSubFxn, double respCorr) {
21  fTimeSlew_=tsParam;
22  fTimeSlewBias_=bias;
23  applyTimeSlew_=iApplyTimeSlew;
24  fPedestalSubFxn_=pedSubFxn;
25  frespCorr_=respCorr;
26 }
27 
29 // Landau function integrated in 1 ns intervals
30 //Landau pulse shape from https://indico.cern.ch/event/345283/contribution/3/material/slides/0.pdf
31 //Landau turn on by default at left edge of time slice
32 // normalized to 1 on [0,10000]
33 void HcalDeterministicFit::getLandauFrac(float tStart, float tEnd, float &sum) const{
34 
35  if (std::abs(tStart-tEnd-tsWidth)<0.1f) {
36  sum=0.f;
37  return;
38  }
39  sum= landauFrac[int(ceil(tStart+tsWidth))];
40  return;
41 }
42 
44 void HcalDeterministicFit::get205Frac(float tStart, float tEnd, float &sum) const{
45 
46  if (std::abs(tStart-tEnd-tsWidth)<0.1f) {
47  sum=0.f;
48  return;
49  }
50  sum= siPM205Frac[int(ceil(tStart+tsWidth))];
51  return;
52 }
53 
55 void HcalDeterministicFit::get206Frac(float tStart, float tEnd, float &sum) const{
56 
57  if (std::abs(tStart-tEnd-tsWidth)<0.1f) {
58  sum=0.f;
59  return;
60  }
61  sum= siPM206Frac[int(ceil(tStart+tsWidth))];
62  return;
63 }
64 
65 
67 void HcalDeterministicFit::get207Frac(float tStart, float tEnd, float &sum) const{
68 
69  if (std::abs(tStart-tEnd-tsWidth)<0.1f) {
70  sum=0.f;
71  return;
72  }
73  sum= siPM207Frac[int(ceil(tStart+tsWidth))];
74  return;
75 }
76 
77 void HcalDeterministicFit::getFrac(float tStart, float tEnd, float &sum, FType fType) const{
78  switch(fType){
79  case shape205: get205Frac(tStart,tEnd,sum); break;
80  case shape206: get206Frac(tStart,tEnd,sum); break;
81  case shape207: get207Frac(tStart,tEnd,sum); break;
82  case shapeLandau: getLandauFrac(tStart,tEnd,sum); break;
83  }
84 }
85 
87  float& reconstructedEnergy,
88  float& reconstructedTime,
89  const HcalTimeSlew* hcalTimeSlew_delay) const
90 {
91 
92 
93  unsigned int soi=channelData.soi();
94 
95  std::vector<double> corrCharge;
96  std::vector<double> inputCharge;
97  std::vector<double> inputPedestal;
98  std::vector<double> inputNoise;
99  double gainCorr = 0;
100  double respCorr = 0;
101 
102  for(unsigned int ip=0; ip<channelData.nSamples(); ip++){
103 
104  double charge = channelData.tsRawCharge(ip);
105  double ped = channelData.tsPedestal(ip);
106  double noise = channelData.tsPedestalWidth(ip);
107  double gain = channelData.tsGain(ip);
108 
109  gainCorr = gain;
110  inputCharge.push_back(charge);
111  inputPedestal.push_back(ped);
112  inputNoise.push_back(noise);
113 
114  }
115 
116  fPedestalSubFxn_.calculate(inputCharge, inputPedestal, inputNoise, corrCharge, soi, channelData.nSamples());
117 
118  if (fTimeSlew_==0) respCorr=1.0;
119  else if (fTimeSlew_==1) channelData.hasTimeInfo()?respCorr=rCorrSiPM[0]:respCorr=rCorr[0];
120  else if (fTimeSlew_==2) channelData.hasTimeInfo()?respCorr=rCorrSiPM[1]:respCorr=rCorr[1];
121  else if (fTimeSlew_==3) respCorr=frespCorr_;
122 
123  float tsShift3,tsShift4,tsShift5;
124  tsShift3=0.f,tsShift4=0.f,tsShift5=0.f;
125 
126  if(applyTimeSlew_) {
127  tsShift3=hcalTimeSlew_delay->delay(inputCharge[soi-1], fTimeSlew_, fTimeSlewBias_, !channelData.hasTimeInfo());
128  tsShift4=hcalTimeSlew_delay->delay(inputCharge[soi], fTimeSlew_, fTimeSlewBias_, !channelData.hasTimeInfo());
129  tsShift5=hcalTimeSlew_delay->delay(inputCharge[soi+1], fTimeSlew_, fTimeSlewBias_, !channelData.hasTimeInfo());
130  }
131 
132  float ch3,ch4,ch5, i3,n3,nn3, i4,n4,i5,n5;
133  ch3=0.f,ch4=0.f,ch5=0.f,i3=0.f,n3=0.f,nn3=0.f,i4=0.f,n4=0.f,i5=0.f,n5=0.f;
134 
135  FType fType;
136  if(channelData.hasTimeInfo() && channelData.recoShape()==205) fType = shape205;
137  else if(channelData.hasTimeInfo() && channelData.recoShape()==206) fType = shape206;
138  else if(channelData.hasTimeInfo() && channelData.recoShape()==207) fType = shape207;
139  else fType = shapeLandau;
140 
141  getFrac(-tsShift3,-tsShift3+tsWidth,i3,fType);
142  getFrac(-tsShift3+tsWidth,-tsShift3+tsWidth*2,n3,fType);
143  getFrac(-tsShift3+tsWidth*2,-tsShift3+tsWidth*3,nn3,fType);
144 
145  getFrac(-tsShift4,-tsShift4+tsWidth,i4,fType);
146  getFrac(-tsShift4+tsWidth,-tsShift4+tsWidth*2,n4,fType);
147 
148  getFrac(-tsShift5,-tsShift5+tsWidth,i5,fType);
149  getFrac(-tsShift5+tsWidth,-tsShift5+tsWidth*2,n5,fType);
150 
151  if (i3 != 0 && i4 != 0 && i5 != 0) {
152 
153  ch3=corrCharge[soi-1]/i3;
154  ch4=(i3*corrCharge[soi]-n3*corrCharge[soi-1])/(i3*i4);
155  ch5=(n3*n4*corrCharge[soi-1]-i4*nn3*corrCharge[soi-1]-i3*n4*corrCharge[soi]+i3*i4*corrCharge[soi+1])/(i3*i4*i5);
156 
157  if (ch3<negThresh[0]) {
158  ch3=negThresh[0];
159  ch4=corrCharge[soi]/i4;
160  ch5=(i4*corrCharge[soi+1]-n4*corrCharge[soi])/(i4*i5);
161  }
162  if (ch5<negThresh[0] && ch4>negThresh[1]) {
163  double ratio = (corrCharge[soi]-ch3*i3)/(corrCharge[soi+1]-negThresh[0]*i5);
164  if (ratio < 5 && ratio > 0.5) {
165  double invG = invGpar[0]+invGpar[1]*std::sqrt(2*std::log(invGpar[2]/ratio));
166  float iG=0.f;
167  getFrac(-invG,-invG+tsWidth,iG,fType);
168  if (iG != 0 ) {
169  ch4=(corrCharge[soi]-ch3*n3)/(iG);
170  tsShift4=invG;
171  }
172  }
173  }
174  }
175 
176  if (ch4<1) {
177  ch4=0.f;
178  }
179 
180  reconstructedEnergy=ch4*gainCorr*respCorr;
181  reconstructedTime=tsShift4;
182 }
void getFrac(float, float, float &, FType) const
static constexpr float rCorr[2]
bool hasTimeInfo() const
double tsGain(const unsigned ts) const
static constexpr float rCorrSiPM[2]
void get206Frac(float tStart, float tEnd, float &sum) const
static constexpr int HcalRegion[2]
double delay(double fC, BiasSetting bias=Medium) const
Returns the amount (ns) by which a pulse of the given number of fC will be delayed by the timeslew ef...
Definition: HcalTimeSlew.cc:14
unsigned soi() const
#define constexpr
double tsPedestal(const unsigned ts) const
double tsRawCharge(const unsigned ts) const
static constexpr float siPM206Frac[125]
T sqrt(T t)
Definition: SSEVec.h:18
void get205Frac(float tStart, float tEnd, float &sum) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static constexpr float siPM205Frac[125]
double f[11][100]
void getLandauFrac(float tStart, float tEnd, float &sum) const
void get207Frac(float tStart, float tEnd, float &sum) const
int recoShape() const
void init(HcalTimeSlew::ParaSource tsParam, HcalTimeSlew::BiasSetting bias, bool iApplyTimeSlew, PedestalSub pedSubFxn, double respCorr)
static constexpr float landauFrac[125]
double tsPedestalWidth(const unsigned ts) const
static constexpr float siPM207Frac[125]
static constexpr float negThresh[2]
unsigned nSamples() const
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime, const HcalTimeSlew *hcalTimeSlew_delay) const
static constexpr float invGpar[3]