CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCxTalk.h
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <math.h>
3 
4 
5 class Conv{
6 
7  public:
8 
9  Conv(){}
10 
11  //square wave fcn convoluted with 1/(t+2.5)
12  float elec(float t,float vs){
13  float f;
14  if (t<=vs){
15  f=log(t+2.5)-log(2.5);
16  }
17  else{
18  f=log(t+2.5)-log(t-50+2.5);
19  }
20  return f;
21  }//end elec
22 
23 
24  //calculate single electron distribution in 6.25 ns steps
25  void mkbins(float vs){
26  int i,k;
27  float t;
28  for(i=0;i<120;i++) conve[i]=0.0;
29  for(i=0;i<120;i++){
30  for(k=0;k<16;k++){
31  t=(6.25*i)+(k*0.625);
32  conve[i]=conve[i]+elec(t,vs);
33  }
34  }
35  } //end mkbins
36 
37 
38  //convolution function
39  void convolution(float *xleft_a, float *xleft_b, float *min_left, float *xright_a, float *xright_b, float *min_right, float *pTime){
40  //void(convolution){
41 
42  float max, cross0,cross2,min_l,min_r,sum_x=0.0,sumx2=0.;
43  float sum_y_left=0.0,sum_y_right=0.0,sum_xy_left=0.0,sum_xy_right=0.0;
44  float a_left=0.0,a_right=0.0,b_left=0.0,b_right=0.0,chi2_left=0.0,chi2_right=0.0,chi_left=0.0,chi_right=0.0;
45  float aleft=0.0,aright=0.0,bleft=0.0,bright=0.0;
46  int i,j,k,l,imax=0;
47 
48  for(l=0;l<3;l++){
49  for(i=0;i<119;i++)conv[l][i]=0.0;
50  for(j=0;j<119;j++){
51  for(k=0;k<119;k++){
52  if(j+k<119)conv[l][j+k]=conv[l][j+k]+convd[l][j]*conve[k];
53  }
54  }
55  }
56  max=0;
57  min_l=9999999999999999.0;
58  min_r=9999999999999999.0;
59  for(i=0;i<119;i++){
60  if(conv[1][i]>max){
61  max=conv[1][i];
62  imax=i;
63  }
64  }
65 
66  //find the max peak time from 3 timebins when line intersects x axis a+b*x=0 -> x=-a/b
67  float time1=-999.0, time2=-999.0, time3=-999.0;
68  float data1=-999.0, data2=-999.0, data3=-999.0;
69  float peakTime=0.0;
70 
71  time1=imax-1;
72  time2=imax;
73  time3=imax+1;
74 
75  data1=conv[1][imax-1];
76  data2=conv[1][imax];
77  data3=conv[1][imax+1];
78 
79  peakTime=(0.5)*((time1*time1*(data3-data2)+time2*time2*(data1-data3)+time3*time3*(data2-data1))/(time1*(data3-data2)+time2*(data1-data3)+time3*(data2-data1)))*6.25;
80 
81  for(l=0;l<3;l++){
82  for(i=0;i<119;i++)conv[l][i]=conv[l][i]/max;
83  }
84 
85  int nobs = 0;
86  for (int j=0; j<119; j++){
87  if (conv[1][j]>0.6) nobs++;
88  }
89 
90  for(i=0;i<119;i++){
91  cross0=0.0;
92  cross2=0.0;
93 
94  if(conv[1][i]>0.6){
95  cross0=conv[0][i]/(conv[0][i]+conv[1][i]+conv[2][i]);
96  cross2=conv[2][i]/(conv[0][i]+conv[1][i]+conv[2][i]);
97 
98  sum_x += i;
99  sum_y_left += cross0;
100  sum_y_right += cross2;
101  sumx2 += i*i;
102  sum_xy_left += i*cross0;
103  sum_xy_right += i*cross2;
104  }
105  }
106 
107  //LMS fitting straight line y=a+b*x
108 
109  bleft = ((nobs*sum_xy_left) - (sum_x * sum_y_left))/((nobs*sumx2) - (sum_x*sum_x));
110  bright = ((nobs*sum_xy_right) - (sum_x * sum_y_right))/((nobs*sumx2) - (sum_x*sum_x));
111 
112  aleft = ((sum_y_left*sumx2)-(sum_x*sum_xy_left))/((nobs*sumx2)-(sum_x*sum_x));
113  aright = ((sum_y_right*sumx2)-(sum_x*sum_xy_right))/((nobs*sumx2)-(sum_x*sum_x));
114 
115  for(i=0;i<119;i++ ){
116  chi2_left += (cross0 -(aleft+(bleft*i)))*(cross0 -(aleft+(bleft*i)));
117  chi2_right += (cross2 -(aright+(bright*i)))*(cross2 -(aright+(bright*i)));
118  }
119 
120  if(chi_left<min_l){
121  min_l=chi_left;
122  bleft=bleft;
123  aleft=aleft;
124  }
125  if(chi_right<min_r){
126  min_r=chi_right;
127  bright=bright;
128  aright=aright;
129  }
130 
131 
132  //Now calculating parameters in ns to compensate for drift in peak time
133  b_left = bleft/6.25;
134  b_right = bright/6.25;
135 
136  a_left = aleft + (bleft*peakTime/6.25);
137  a_right = aright + (bright*peakTime/6.25);
138 
139  *xleft_a = a_left;
140  *xleft_b = b_left;
141  *min_left = chi2_left;
142  *xright_a = a_right;
143  *xright_b = b_right;
144  *min_right = chi2_right;
145  *pTime = peakTime;
146 
147  } //end CONVOLUTION
148 
149  ~Conv(){}
150 
151 
152  float convd[3][120];
153  float nconvd[3][120];
154  float conve[120];
155  float conv[3][120];
156 
157 private:
158 
159 
160 
161 } ;
162 
tuple t
Definition: tree.py:139
int i
Definition: DBlmapReader.cc:9
~Conv()
Definition: CSCxTalk.h:149
auto cross2(V1 x, V2 y) -> typename std::remove_reference< decltype(x[0])>::type
Definition: ExtVec.h:118
float conve[120]
Definition: CSCxTalk.h:154
float elec(float t, float vs)
Definition: CSCxTalk.h:12
Conv()
Definition: CSCxTalk.h:9
Definition: CSCxTalk.h:5
float conv[3][120]
Definition: CSCxTalk.h:155
int j
Definition: DBlmapReader.cc:9
double f[11][100]
void convolution(float *xleft_a, float *xleft_b, float *min_left, float *xright_a, float *xright_b, float *min_right, float *pTime)
Definition: CSCxTalk.h:39
void mkbins(float vs)
Definition: CSCxTalk.h:25
float nconvd[3][120]
Definition: CSCxTalk.h:153
float convd[3][120]
Definition: CSCxTalk.h:152