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 
15 // Constructor...
17 {
18 
19  fNsamples = 0;
22 }
23 
24 // Destructor
26 {
27 }
28 
29 void TPNFit::init(int nsamples, int firstsample, int lastsample)
30 {
31  fNsamples = nsamples ;
34  //printf("nsamples=%d firstsample=%d lastsample=%d\n",nsamples,firstsample,lastsample);
35 
36  if(fNsamples > NMAXSAMP2)
37  printf("number of PN samples exceed maximum\n");
38 
39  for(int k=0;k<NMAXSAMP2;k++)
40  t[k]= (double) k;
41 
42  return ;
43 }
44 
45 double TPNFit::doFit(int maxsample, double *adc)
46 {
47  double chi2=0.;
48  ampl=0.; timeatmax=0.;
49 
50  //printf("maxsample=%d\n",maxsample);
51  firstsample= maxsample - fNum_samp_bef_max;
52  lastsample= maxsample + fNum_samp_after_max;
53 
54  if(firstsample <= 0) return 101;
56  if(lastsample-firstsample < 1) return 102;
57  int nval= lastsample-firstsample +1;
58  //printf("firstsample=%d lastsample=%d nval=%d\n",
59  // firstsample,lastsample,nval);
60  int testneg=0;
61  for(int kn=firstsample;kn<=lastsample;kn++) {
62  //printf("adc[%d]=%f\n",kn,adc[kn]);
63  if(adc[kn] < 0.) testneg=1;
64  }
65  if(testneg == 1) return 103;
66 
67  for(int i=firstsample;i<=lastsample;i++) {
68  val[i-firstsample]= adc[i];
69  fv1[i-firstsample]= 1.;
70  fv2[i-firstsample]= (double) (i);
71  fv3[i-firstsample]= ((double)(i))*((double)(i));
72  }
73 
74  TVectorD y(nval,val);
75  //y.Print();
76  TVectorD f1(nval,fv1);
77  //f1.Print();
78  TVectorD f2(nval,fv2);
79  //f2.Print();
80  TVectorD f3(nval,fv3);
81  //f3.Print();
82 
83  double bj[3];
84  bj[0]= f1*y; bj[1]=f2*y; bj[2]= f3*y;
85  TVectorD b(3,bj);
86  //b.Print();
87 
88  double aij[9];
89  aij[0]= f1*f1; aij[1]=f1*f2; aij[2]=f1*f3;
90  aij[3]= f2*f1; aij[4]=f2*f2; aij[5]=f2*f3;
91  aij[6]= f3*f1; aij[7]=f3*f2; aij[8]=f3*f3;
92  TMatrixD a(3,3,aij);
93  //a.Print();
94 
95  double det1;
96  a.InvertFast(&det1);
97  //a.Print();
98 
99  TVectorD c= a*b;
100  //c.Print();
101 
102  double *par= c.GetMatrixArray();
103  //printf("par0=%f par1=%f par2=%f\n",par[0],par[1],par[2]);
104  if(par[2] != 0.) {
105  timeatmax= -par[1]/(2.*par[2]);
106  ampl= par[0]-par[2]*(timeatmax*timeatmax);
107  }
108  //printf("amp=%f time=%f\n",amp_max,timeatmax);
109 
110  if(ampl <= 0.) {
111  ampl=adc[maxsample];
112  return 1.;
113  }
114 
115  if((int)timeatmax > lastsample)
116  return 103;
117  if((int)timeatmax < firstsample)
118  return 103;
119 
120  return chi2;
121 }
int adc(sample_type sample)
get the ADC sample (12 bits)
int fNum_samp_bef_max
Definition: TPNFit.h:14
double fv3[50]
Definition: TPNFit.h:19
void init(int, int, int)
Definition: TPNFit.cc:29
int fNum_samp_after_max
Definition: TPNFit.h:15
double timeatmax
Definition: TPNFit.h:21
int fNsamples
Definition: TPNFit.h:13
double t[50]
Definition: TPNFit.h:18
#define NMAXSAMP2
Definition: TPNFit.h:6
TPNFit()
Definition: TPNFit.cc:16
double fv2[50]
Definition: TPNFit.h:19
int k[5][pyjets_maxn]
double val[50]
Definition: TPNFit.h:18
double fv1[50]
Definition: TPNFit.h:19
double b
Definition: hdecay.h:120
int lastsample
Definition: TPNFit.h:17
return(e1-e2)*(e1-e2)+dp *dp
double a
Definition: hdecay.h:121
int firstsample
Definition: TPNFit.h:17
double doFit(int, double *)
Definition: TPNFit.cc:45
~TPNFit() override
Definition: TPNFit.cc:25
double ampl
Definition: TPNFit.h:20