CMS 3D CMS Logo

TPNFit.cc
Go to the documentation of this file.
1 /*
2  * \class TPNFit
3  *
4  * \author: Patrice Verrecchia - CEA/Saclay
5  */
6 
8 
9 #include <iostream>
10 #include "TVectorD.h"
11 
12 //ClassImp(TPNFit)
13 
14 // Constructor...
16  fNsamples = 0;
19 }
20 
21 // Destructor
23 
24 void TPNFit::init(int nsamples, int firstsample, int lastsample) {
25  fNsamples = nsamples;
28  //printf("nsamples=%d firstsample=%d lastsample=%d\n",nsamples,firstsample,lastsample);
29 
30  if (fNsamples > NMAXSAMP2)
31  printf("number of PN samples exceed maximum\n");
32 
33  for (int k = 0; k < NMAXSAMP2; k++)
34  t[k] = (double)k;
35 
36  return;
37 }
38 
39 double TPNFit::doFit(int maxsample, double *adc) {
40  double chi2 = 0.;
41  ampl = 0.;
42  timeatmax = 0.;
43 
44  //printf("maxsample=%d\n",maxsample);
45  firstsample = maxsample - fNum_samp_bef_max;
46  lastsample = maxsample + fNum_samp_after_max;
47 
48  if (firstsample <= 0)
49  return 101;
50  if (lastsample >= fNsamples)
51  lastsample = fNsamples - 1;
52  if (lastsample - firstsample < 1)
53  return 102;
54  int nval = lastsample - firstsample + 1;
55  //printf("firstsample=%d lastsample=%d nval=%d\n",
56  // firstsample,lastsample,nval);
57  int testneg = 0;
58  for (int kn = firstsample; kn <= lastsample; kn++) {
59  //printf("adc[%d]=%f\n",kn,adc[kn]);
60  if (adc[kn] < 0.)
61  testneg = 1;
62  }
63  if (testneg == 1)
64  return 103;
65 
66  for (int i = firstsample; i <= lastsample; i++) {
67  val[i - firstsample] = adc[i];
68  fv1[i - firstsample] = 1.;
69  fv2[i - firstsample] = (double)(i);
70  fv3[i - firstsample] = ((double)(i)) * ((double)(i));
71  }
72 
73  TVectorD y(nval, val);
74  //y.Print();
75  TVectorD f1(nval, fv1);
76  //f1.Print();
77  TVectorD f2(nval, fv2);
78  //f2.Print();
79  TVectorD f3(nval, fv3);
80  //f3.Print();
81 
82  double bj[3];
83  bj[0] = f1 * y;
84  bj[1] = f2 * y;
85  bj[2] = f3 * y;
86  TVectorD b(3, bj);
87  //b.Print();
88 
89  double aij[9];
90  aij[0] = f1 * f1;
91  aij[1] = f1 * f2;
92  aij[2] = f1 * f3;
93  aij[3] = f2 * f1;
94  aij[4] = f2 * f2;
95  aij[5] = f2 * f3;
96  aij[6] = f3 * f1;
97  aij[7] = f3 * f2;
98  aij[8] = f3 * f3;
99  TMatrixD a(3, 3, aij);
100  //a.Print();
101 
102  double det1;
103  a.InvertFast(&det1);
104  //a.Print();
105 
106  TVectorD c = a * b;
107  //c.Print();
108 
109  double *par = c.GetMatrixArray();
110  //printf("par0=%f par1=%f par2=%f\n",par[0],par[1],par[2]);
111  if (par[2] != 0.) {
112  timeatmax = -par[1] / (2. * par[2]);
113  ampl = par[0] - par[2] * (timeatmax * timeatmax);
114  }
115  //printf("amp=%f time=%f\n",amp_max,timeatmax);
116 
117  if (ampl <= 0.) {
118  ampl = adc[maxsample];
119  return 1.;
120  }
121 
122  if ((int)timeatmax > lastsample)
123  return 103;
124  if ((int)timeatmax < firstsample)
125  return 103;
126 
127  return chi2;
128 }
DDAxes::y
TPNFit::ampl
double ampl
Definition: TPNFit.h:18
mps_fire.i
i
Definition: mps_fire.py:428
TPNFit::val
double val[NMAXSAMP2]
Definition: TPNFit.h:16
gpuClustering::adc
uint16_t *__restrict__ uint16_t const *__restrict__ adc
Definition: gpuClusterChargeCut.h:20
TPNFit::fNum_samp_after_max
int fNum_samp_after_max
Definition: TPNFit.h:13
TPNFit::timeatmax
double timeatmax
Definition: TPNFit.h:19
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
TPNFit::~TPNFit
~TPNFit() override
Definition: TPNFit.cc:22
dqmdumpme.k
k
Definition: dqmdumpme.py:60
b
double b
Definition: hdecay.h:118
TPNFit::fNum_samp_bef_max
int fNum_samp_bef_max
Definition: TPNFit.h:12
TPNFit::TPNFit
TPNFit()
Definition: TPNFit.cc:15
TPNFit.h
a
double a
Definition: hdecay.h:119
DeadROC_duringRun.f2
f2
Definition: DeadROC_duringRun.py:220
TPNFit::t
double t[NMAXSAMP2]
Definition: TPNFit.h:16
TPNFit::fv1
double fv1[NMAXSAMP2]
Definition: TPNFit.h:17
TPNFit::init
void init(int, int, int)
Definition: TPNFit.cc:24
TPNFit::lastsample
int lastsample
Definition: TPNFit.h:15
TPNFit::firstsample
int firstsample
Definition: TPNFit.h:15
TPNFit::doFit
double doFit(int, double *)
Definition: TPNFit.cc:39
TPNFit::NMAXSAMP2
static constexpr int NMAXSAMP2
Definition: TPNFit.h:8
TPNFit::fv3
double fv3[NMAXSAMP2]
Definition: TPNFit.h:17
TPNFit::fNsamples
int fNsamples
Definition: TPNFit.h:11
TPNFit::fv2
double fv2[NMAXSAMP2]
Definition: TPNFit.h:17
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
DeadROC_duringRun.f1
f1
Definition: DeadROC_duringRun.py:219