CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalUncalibRecHitRecAnalFitAlgo.h
Go to the documentation of this file.
1 #ifndef RecoLocalCalo_EcalRecAlgos_EcalUncalibRecHitRecAnalFitAlgo_HH
2 #define RecoLocalCalo_EcalRecAlgos_EcalUncalibRecHitRecAnalFitAlgo_HH
3 
11 #include "CLHEP/Matrix/Matrix.h"
12 #include "CLHEP/Matrix/SymMatrix.h"
14 #include <vector>
15 #include <string>
16 
17 #include "TROOT.h"
18 #include "TMinuit.h"
19 #include "TGraph.h"
20 #include "TF1.h"
21 
23 {
24 
25 
26  private:
27 
28  double pulseShapeFunction(double* var, double* par) {
29  double x = var[0];
30  double ampl = par[0];
31  double tp = par[1];
32  double alpha = par[2];
33  double t0 = par[3];
34 
35  double f = pow( (x-t0)/tp , alpha ) * exp( -alpha*(x-tp-t0)/tp );
36  return ampl*f;
37  };
38 
39  double pedestalFunction(double* var, double* par) {
40  double x = var[0];
41  double ped = par[0];
42  return ped;
43  };
44 
45  public:
46  // destructor
48 
49 
51  virtual EcalUncalibratedRecHit makeRecHit(const C& dataFrame, const double* pedestals,
52  const double* gainRatios,
54  const EcalWeightSet::EcalChi2WeightMatrix** chi2Matrix)
55  {
56  double amplitude_(-1.), pedestal_(-1.), jitter_(-1.), chi2_(-1.);
57 
58  // Get time samples
59  //HepMatrix frame(C::MAXSAMPLES, 1);
60  double frame[C::MAXSAMPLES];
61  // int gainId0 = dataFrame.sample(0).gainId();
62  int gainId0 = 1;
63  int iGainSwitch = 0;
64  double maxsample(-1);
65  int imax(-1);
66  bool isSaturated = 0;
67  uint32_t flag = 0;
68  for(int iSample = 0; iSample < C::MAXSAMPLES; iSample++) {
69  int gainId = dataFrame.sample(iSample).gainId();
70  if ( dataFrame.isSaturated() != -1 )
71  {
72  gainId = 3;
73  isSaturated = 1;
74  }
75 
76  if (gainId != gainId0) iGainSwitch++ ;
77  if (!iGainSwitch)
78  frame[iSample] = double(dataFrame.sample(iSample).adc());
79  else
80  frame[iSample] = double(((double)(dataFrame.sample(iSample).adc()) - pedestals[gainId-1]) * gainRatios[gainId-1]);
81 
82  if( frame[iSample]>maxsample ) {
83  maxsample= frame[iSample];
84  imax=iSample;
85  }
86  }
87 
88  // Compute parameters
89  //std::cout << "EcalUncalibRecHitRecAnalFitAlgo::makeRecHit() not yey implemented. returning dummy rechit" << std::endl;
90 
91  // prepare TGraph for analytic fit
92  double xarray[10]={0.,1.,2.,3.,4.,5.,6.,7.,8.,9.};
93  TGraph graph(10,xarray,frame);
94 
95  // fit functions
96  TF1 pulseShape = TF1("pulseShape",
97  "[0]*pow((x - [3])/[1],[2])*exp(-[2]*(x - [1] - [3])/[1])",
98  imax-1.,imax+3.);
99  TF1 pedestal = TF1("pedestal","[0]",0.,2.);
100 
101  //TF1 pulseShape = TF1("pulseShape",pulseShapeFunction,imax-1.,imax+3.);
102  //TF1 pedestal = TF1("pedestal",pedestalFunction,0.,2.);
103  TF1 pluseAndPed = TF1("pulseAndPed","pedestal+pulseShape");
104 
105  //pulseShape parameters
106  // Amplitude
107  double FIT_A=(double)maxsample; //Amplitude
108  pulseShape.SetParameter(0,FIT_A);
109  pulseShape.SetParName(0,"Amplitude");
110  // T peak
111  double FIT_Tp=(double)imax; //T peak
112  pulseShape.SetParameter(1,FIT_Tp);
113  pulseShape.SetParName(1,"t_{P}");
114  // Alpha
115  double FIT_ALFA=1.5; //Alpha
116  pulseShape.SetParameter(2,FIT_ALFA);
117  pulseShape.SetParName(2,"\\alpha");
118  // T off
119  double FIT_To=3.; //T off
120  pulseShape.SetParameter(3,FIT_To);
121  pulseShape.SetParName(3,"t_{0}");
122 
123  // pedestal
124  pedestal.SetParameter(0,frame[0]);
125  pedestal.SetParName(0,"Pedestal");
126 
127 
128 
129  graph.Fit("pulseShape","QRM");
130  //TF1 *pulseShape2=graph.GetFunction("pulseShape");
131 
132  if ( std::string(gMinuit->fCstatu.Data()) == std::string("CONVERGED ") ) {
133 
134  double amplitude_value=pulseShape.GetParameter(0);
135 
136  graph.Fit("pedestal","QRL");
137  //TF1 *pedestal2=graph.GetFunction("pedestal");
138  double pedestal_value=pedestal.GetParameter(0);
139 
140  if (!iGainSwitch)
141  amplitude_ = amplitude_value - pedestal_value;
142  else
143  amplitude_ = amplitude_value;
144 
145  pedestal_ = pedestal_value;
146  jitter_ = pulseShape.GetParameter(3);
147  chi2_ = 1.; // successful fit
148  if (isSaturated) flag = EcalUncalibratedRecHit::kSaturated;
149  /*
150  std::cout << "separate fits\nA: " << amplitude_value << ", Ped: " << pedestal_value
151  << ", t0: " << jitter_ << ", tp: " << pulseShape.GetParameter(1)
152  << ", alpha: " << pulseShape.GetParameter(2)
153  << std::endl;
154  */
155 
156  }
157 
158  return EcalUncalibratedRecHit( dataFrame.id(), amplitude_, pedestal_, jitter_ - 6, chi2_, flag);
159  }
160 };
161 #endif
float alpha
Definition: AMPTWrapper.h:95
double pedestalFunction(double *var, double *par)
int gainId(sample_type sample)
get the gainId (2 bits)
double f[11][100]
virtual EcalUncalibratedRecHit makeRecHit(const C &dataFrame, const double *pedestals, const double *gainRatios, const EcalWeightSet::EcalWeightMatrix **weights, const EcalWeightSet::EcalChi2WeightMatrix **chi2Matrix)
Compute parameters.
math::Matrix< 10, 10 >::type EcalChi2WeightMatrix
Definition: EcalWeightSet.h:21
Definition: adjgraph.h:12
bool isSaturated(const Digi &digi, const int &maxADCvalue, int ifirst, int n)
tuple gMinuit
Definition: fitWZ.py:35
math::Matrix< 3, 10 >::type EcalWeightMatrix
Definition: EcalWeightSet.h:20
Definition: DDAxes.h:10
double pulseShapeFunction(double *var, double *par)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40