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