CMS 3D CMS Logo

ESRecHitFitAlgo.cc
Go to the documentation of this file.
3 
4 #include "TMath.h"
5 #include "TGraph.h"
6 
7 #include <iostream>
8 #include <cmath>
9 
10 // fit function
11 Double_t fitf(Double_t* x, Double_t* par) {
12  Double_t wc = 0.07291;
13  Double_t n = 1.798; // n-1 (in fact)
14  Double_t v1 = pow(wc / n * (x[0] - par[1]), n);
15  Double_t v2 = TMath::Exp(n - wc * (x[0] - par[1]));
16  Double_t v = par[0] * v1 * v2;
17 
18  if (x[0] < par[1])
19  v = 0;
20 
21  return v;
22 }
23 
25  fit_ = new TF1("fit", fitf, -200, 200, 2);
26  fit_->SetParameters(50, 10);
27 }
28 
30 
31 double* ESRecHitFitAlgo::EvalAmplitude(const ESDataFrame& digi, double ped) const {
32  double* fitresults = new double[3]{};
33  double adc[3]{};
34  double tx[3]{};
35  tx[0] = -5.;
36  tx[1] = 20.;
37  tx[2] = 45.;
38 
39  for (int i = 0; i < digi.size(); i++)
40  adc[i] = digi.sample(i).adc() - ped;
41 
42  double status = 0;
43  if (adc[0] > 20)
44  status = 14;
45  if (adc[1] < 0 || adc[2] < 0)
46  status = 10;
47  if (adc[0] > adc[1] && adc[0] > adc[2])
48  status = 8;
49  if (adc[2] > adc[1] && adc[2] > adc[0])
50  status = 9;
51  double r12 = (adc[1] != 0) ? adc[0] / adc[1] : 99999;
52  double r23 = (adc[2] != 0) ? adc[1] / adc[2] : 99999;
53  if (r12 > ratioCuts_->getR12High())
54  status = 5;
55  if (r23 > ratioCuts_->getR23High())
56  status = 6;
57  if (r23 < ratioCuts_->getR23Low())
58  status = 7;
59 
60  if (int(status) == 0) {
61  double para[10]{};
62  TGraph* gr = new TGraph(3, tx, adc);
63  fit_->SetParameters(50, 10);
64  gr->Fit(fit_, "MQ");
65  fit_->GetParameters(para);
66  fitresults[0] = para[0];
67  fitresults[1] = para[1];
68  delete gr;
69 
70  if (adc[1] > 2800 && adc[2] > 2800)
71  status = 11;
72  else if (adc[1] > 2800)
73  status = 12;
74  else if (adc[2] > 2800)
75  status = 13;
76 
77  } else {
78  fitresults[0] = 0;
79  fitresults[1] = -999;
80  }
81 
82  fitresults[2] = status;
83 
84  return fitresults;
85 }
86 
88  ESPedestals::const_iterator it_ped = peds_->find(digi.id());
89 
92 
94 
95  double* results;
96 
97  results = EvalAmplitude(digi, it_ped->getMean());
98 
99  double energy = results[0];
100  double t0 = results[1];
101  int status = (int)results[2];
102  delete[] results;
103 
104  double mipCalib = (std::fabs(cos(*it_ang)) != 0.) ? (*it_mip) / fabs(cos(*it_ang)) : 0.;
105  energy *= (mipCalib != 0.) ? MIPGeV_ / mipCalib : 0.;
106 
107  LogDebug("ESRecHitFitAlgo") << "ESRecHitFitAlgo : reconstructed energy " << energy << " T0 " << t0;
108 
109  EcalRecHit rechit(digi.id(), energy, t0);
110 
111  if (it_status->getStatusCode() == 1) {
113  } else {
114  if (status == 0)
115  rechit.setFlag(EcalRecHit::kESGood);
116  else if (status == 5)
117  rechit.setFlag(EcalRecHit::kESBadRatioFor12);
118  else if (status == 6)
119  rechit.setFlag(EcalRecHit::kESBadRatioFor23Upper);
120  else if (status == 7)
121  rechit.setFlag(EcalRecHit::kESBadRatioFor23Lower);
122  else if (status == 8)
123  rechit.setFlag(EcalRecHit::kESTS1Largest);
124  else if (status == 9)
125  rechit.setFlag(EcalRecHit::kESTS3Largest);
126  else if (status == 10)
127  rechit.setFlag(EcalRecHit::kESTS3Negative);
128  else if (status == 11)
129  rechit.setFlag(EcalRecHit::kESSaturated);
130  else if (status == 12)
131  rechit.setFlag(EcalRecHit::kESTS2Saturated);
132  else if (status == 13)
133  rechit.setFlag(EcalRecHit::kESTS3Saturated);
134  else if (status == 14)
135  rechit.setFlag(EcalRecHit::kESTS13Sigmas);
136  }
137 
138  return rechit;
139 }
const ESDetId & id() const
Definition: ESDataFrame.h:19
float getR12High() const
const ESChannelStatus * channelStatus_
int size() const
Definition: ESDataFrame.h:21
double * EvalAmplitude(const ESDataFrame &digi, double ped) const
void setFlag(int flag)
set the flags (from Flags or ESFlags)
Definition: EcalRecHit.h:183
Double_t fitf(Double_t *x, Double_t *par)
const_iterator find(uint32_t rawId) const
const ESRecHitRatioCuts * ratioCuts_
float getR23High() const
int adc() const
get the ADC sample (singed 16 bits)
Definition: ESSample.h:16
const ESSample & sample(int i) const
Definition: ESDataFrame.h:24
const ESAngleCorrectionFactors * ang_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
EcalRecHit reconstruct(const ESDataFrame &digi) const
std::vector< Item >::const_iterator const_iterator
results
Definition: mysort.py:8
float x
const self & getMap() const
const ESIntercalibConstants * mips_
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
uint16_t *__restrict__ uint16_t const *__restrict__ adc
#define LogDebug(id)
const ESPedestals * peds_