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 }
int fNum_samp_bef_max
Definition: TPNFit.h:12
double fv1[NMAXSAMP2]
Definition: TPNFit.h:17
void init(int, int, int)
Definition: TPNFit.cc:24
double fv3[NMAXSAMP2]
Definition: TPNFit.h:17
int fNum_samp_after_max
Definition: TPNFit.h:13
double timeatmax
Definition: TPNFit.h:19
int fNsamples
Definition: TPNFit.h:11
double t[NMAXSAMP2]
Definition: TPNFit.h:16
TPNFit()
Definition: TPNFit.cc:15
static constexpr int NMAXSAMP2
Definition: TPNFit.h:8
double b
Definition: hdecay.h:120
int lastsample
Definition: TPNFit.h:15
double a
Definition: hdecay.h:121
int firstsample
Definition: TPNFit.h:15
double doFit(int, double *)
Definition: TPNFit.cc:39
~TPNFit() override
Definition: TPNFit.cc:22
double fv2[NMAXSAMP2]
Definition: TPNFit.h:17
double val[NMAXSAMP2]
Definition: TPNFit.h:16
uint16_t *__restrict__ uint16_t const *__restrict__ adc
double ampl
Definition: TPNFit.h:18