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_, std::vector<double> pars, double respCorr) {
21  for(int fi=0; fi<9; fi++){
22  fpars[fi] = pars.at(fi);
23  }
24 
25  applyTimeSlew_=iApplyTimeSlew;
26  fTimeSlew=tsParam;
27  fTimeSlewBias=bias;
28  fPedestalSubFxn_=pedSubFxn_;
29  frespCorr=respCorr;
30 
31 }
32 
34 // Landau function integrated in 1 ns intervals
35 //Landau pulse shape from https://indico.cern.ch/event/345283/contribution/3/material/slides/0.pdf
36 //Landau turn on by default at left edge of time slice
37 // normalized to 1 on [0,10000]
38 void HcalDeterministicFit::getLandauFrac(float tStart, float tEnd, float &sum) const{
39 
40  if (std::abs(tStart-tEnd-tsWidth)<0.1) {
41  sum=0;
42  return;
43  }
44  sum= landauFrac[int(ceil(tStart+tsWidth))];
45  return;
46 }
47 
48 
50 void HcalDeterministicFit::get205Frac(float tStart, float tEnd, float &sum) const{
51 
52  if (std::abs(tStart-tEnd-tsWidth)<0.1) {
53  sum=0;
54  return;
55  }
56  sum= siPM205Frac[int(ceil(tStart+tsWidth))];
57  return;
58 }
59 
61  float& reconstructedEnergy,
62  float& reconstructedTime) const
63 {
64 
65  std::vector<double> corrCharge;
66  std::vector<double> inputCharge;
67  std::vector<double> inputPedestal;
68  double gainCorr = 0;
69  double respCorr = 0;
70 
71  for(unsigned int ip=0; ip<channelData.nSamples(); ip++){
72 
73  double charge = channelData.tsRawCharge(ip);
74  double ped = channelData.tsPedestal(ip);
75  double gain = channelData.tsGain(ip);
76 
77  gainCorr = gain;
78  inputCharge.push_back(charge);
79  inputPedestal.push_back(ped);
80 
81  }
82 
83  fPedestalSubFxn_.calculate(inputCharge, inputPedestal, corrCharge);
84 
85  const HcalDetId& cell = channelData.id();
86 
87  double fpar0, fpar1, fpar2;
88  if(std::abs(cell.ieta())<HcalRegion[0]){
89  fpar0 = fpars[0];
90  fpar1 = fpars[1];
91  fpar2 = fpars[2];
92  }else if(std::abs(cell.ieta())==HcalRegion[0]||std::abs(cell.ieta())==HcalRegion[1]){
93  fpar0 = fpars[3];
94  fpar1 = fpars[4];
95  fpar2 = fpars[5];
96  }else{
97  fpar0 = fpars[6];
98  fpar1 = fpars[7];
99  fpar2 = fpars[8];
100  }
101 
102  if (fTimeSlew==0)respCorr=1.0;
103  else if (fTimeSlew==1) channelData.hasTimeInfo()?respCorr=rCorrSiPM[0]:respCorr=rCorr[0];
104  else if (fTimeSlew==2) channelData.hasTimeInfo()?respCorr=rCorrSiPM[1]:respCorr=rCorr[1];
105  else if (fTimeSlew==3)respCorr=frespCorr;
106 
107  float tsShift3=0;
108  float tsShift4=0;
109  float tsShift5=0;
110 
111  if(applyTimeSlew_) {
112 
113  tsShift3=HcalTimeSlew::delay(inputCharge[3], fTimeSlew, fTimeSlewBias, fpar0, fpar1 ,fpar2,!channelData.hasTimeInfo());
114  tsShift4=HcalTimeSlew::delay(inputCharge[4], fTimeSlew, fTimeSlewBias, fpar0, fpar1 ,fpar2,!channelData.hasTimeInfo());
115  tsShift5=HcalTimeSlew::delay(inputCharge[5], fTimeSlew, fTimeSlewBias, fpar0, fpar1 ,fpar2,!channelData.hasTimeInfo());
116 
117  }
118 
119  float ch3=0;
120  float ch4=0;
121  float ch5=0;
122 
123  float i3=0;
124  float n3=0;
125  float nn3=0;
126 
127  float i4=0;
128  float n4=0;
129  float i5=0;
130  float n5=0;
131 
132  if(channelData.hasTimeInfo() && channelData.recoShape()==205) {
133  get205Frac(-tsShift3,-tsShift3+tsWidth,i3);
134  get205Frac(-tsShift3+tsWidth,-tsShift3+tsWidth*2,n3);
135  get205Frac(-tsShift3+tsWidth*2,-tsShift3+tsWidth*3,nn3);
136 
137  get205Frac(-tsShift4,-tsShift4+tsWidth,i4);
138  get205Frac(-tsShift4+tsWidth,-tsShift4+tsWidth*2,n4);
139 
140  get205Frac(-tsShift5,-tsShift5+tsWidth,i5);
141  get205Frac(-tsShift5+tsWidth,-tsShift5+tsWidth*2,n5);
142  } else {
143  getLandauFrac(-tsShift3,-tsShift3+tsWidth,i3);
144  getLandauFrac(-tsShift3+tsWidth,-tsShift3+tsWidth*2,n3);
145  getLandauFrac(-tsShift3+tsWidth*2,-tsShift3+tsWidth*3,nn3);
146 
147  getLandauFrac(-tsShift4,-tsShift4+tsWidth,i4);
148  getLandauFrac(-tsShift4+tsWidth,-tsShift4+tsWidth*2,n4);
149 
150  getLandauFrac(-tsShift5,-tsShift5+tsWidth,i5);
151  getLandauFrac(-tsShift5+tsWidth,-tsShift5+tsWidth*2,n5);
152  }
153 
154  if (i3 != 0 && i4 != 0 && i5 != 0) {
155 
156  ch3=corrCharge[3]/i3;
157  ch4=(i3*corrCharge[4]-n3*corrCharge[3])/(i3*i4);
158  ch5=(n3*n4*corrCharge[3]-i4*nn3*corrCharge[3]-i3*n4*corrCharge[4]+i3*i4*corrCharge[5])/(i3*i4*i5);
159 
160  if (ch3<negThresh[0]) {
161  ch3=negThresh[0];
162  ch4=corrCharge[4]/i4;
163  ch5=(i4*corrCharge[5]-n4*corrCharge[4])/(i4*i5);
164  }
165  if (ch5<negThresh[0] && ch4>negThresh[1]) {
166  double ratio = (corrCharge[4]-ch3*i3)/(corrCharge[5]-negThresh[0]*i5);
167  if (ratio < 5 && ratio > 0.5) {
168  double invG = invGpar[0]+invGpar[1]*std::sqrt(2*std::log(invGpar[2]/ratio));
169  float iG=0;
170 
171  if(channelData.hasTimeInfo() && channelData.recoShape()==205) {
172  get205Frac(-invG,-invG+tsWidth,iG);
173  } else {
174  getLandauFrac(-invG,-invG+tsWidth,iG);
175  }
176  if (iG != 0 ) {
177  ch4=(corrCharge[4]-ch3*n3)/(iG);
178  tsShift4=invG;
179  }
180  }
181  }
182  }
183 
184  if (ch4<1) {
185  ch4=0;
186  }
187 
188  reconstructedEnergy=ch4*gainCorr*respCorr;
189  reconstructedTime=tsShift4;
190 }
static constexpr float rCorr[2]
bool hasTimeInfo() const
double tsGain(const unsigned ts) const
static constexpr float rCorrSiPM[2]
static constexpr int HcalRegion[2]
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime) const
HcalDetId id() const
#define constexpr
double tsPedestal(const unsigned ts) const
double tsRawCharge(const unsigned ts) const
T sqrt(T t)
Definition: SSEVec.h:18
void get205Frac(float tStart, float tEnd, float &sum) const
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static constexpr float siPM205Frac[125]
void getLandauFrac(float tStart, float tEnd, float &sum) const
int recoShape() const
static constexpr float landauFrac[125]
void init(HcalTimeSlew::ParaSource tsParam, HcalTimeSlew::BiasSetting bias, bool iApplyTimeSlew, PedestalSub pedSubFxn_, std::vector< double > pars, double respCorr)
static constexpr float negThresh[2]
unsigned nSamples() const
static double delay(double fC, BiasSetting bias=Medium)
Returns the amount (ns) by which a pulse of the given number of fC will be delayed by the timeslew ef...
Definition: HcalTimeSlew.cc:16
static constexpr float invGpar[3]