CMS 3D CMS Logo

myFunctions.cc
Go to the documentation of this file.
1 // -------------------------------------------
2 // useful functions
3 // -------------------------------------------
4 
5 // return the position [0->49] of the max amplitude crystal
6 int maxAmplitInMatrix(double myMatrix[])
7 {
8  int maxXtal = 999;
9  double maxADC = -999.;
10 
11  for (int icry=0; icry<49; icry++) {
12  if (myMatrix[icry] > maxADC){
13  maxADC = myMatrix[icry];
14  maxXtal = icry;
15  }}
16 
17  return maxXtal;
18 }
19 
20 // max amplitude xtal energy - passing the xtal number in the matrix
21 double ene1x1_xtal(double mymatrix[], int xtal)
22 {
23  double E1x1 = 0.;
24  if (mymatrix[xtal]<-50) { E1x1 = -1000.; }
25  else { E1x1 = mymatrix[xtal]; }
26  return E1x1;
27 }
28 
29 // 3x3 matrix energy around the max amplitude xtal
30 double ene3x3_xtal(double mymatrix[], int xtal)
31 {
32  double E3x3 = 0.;
33 
34  if ( (mymatrix[xtal-8]<-50) || (mymatrix[xtal-7]<-50) || (mymatrix[xtal-6]<-50) || (mymatrix[xtal-1]<-50) || (mymatrix[xtal]<-50) || (mymatrix[xtal+1]<-50) || (mymatrix[xtal+6]<-50) || (mymatrix[xtal+7]<-50) || (mymatrix[xtal+8]<-50) )
35  { E3x3 = -1000.; }
36  else
37  { E3x3 = mymatrix[xtal-8] + mymatrix[xtal-7] + mymatrix[xtal-6] + mymatrix[xtal-1] + mymatrix[xtal] + mymatrix[xtal+1] + mymatrix[xtal+6] + mymatrix[xtal+7] + mymatrix[xtal+8]; }
38 
39  return E3x3;
40 }
41 
42 // 5x5 matrix energy around the max amplitude xtal
43 double ene5x5_xtal(double mymatrix[], int xtal)
44 {
45  double E5x5 = 0.;
46 
47  if( (mymatrix[xtal-16]<-50) || (mymatrix[xtal-15]<-50) || (mymatrix[xtal-14]<-50) || (mymatrix[xtal-13]<-50) || (mymatrix[xtal-12]<-50) || (mymatrix[xtal-9]<-50) || (mymatrix[xtal-8]<-50) || (mymatrix[xtal-7]<-50) || (mymatrix[xtal-6]<-50) || (mymatrix[xtal-5]<-50) || (mymatrix[xtal-2]<-50) || (mymatrix[xtal-1]<-50) || (mymatrix[xtal]<-50) || (mymatrix[xtal+1]<-50) || (mymatrix[xtal+2]<-50) || (mymatrix[xtal+5]<-50) || (mymatrix[xtal+6]<-50) || (mymatrix[xtal+7]<-50) || (mymatrix[xtal+8]<-50) || (mymatrix[xtal+9]<-50) || (mymatrix[xtal+12]<-50) || (mymatrix[xtal+13]<-50) || (mymatrix[xtal+14]<-50) || (mymatrix[xtal+15]<-50) || (mymatrix[xtal+16]<-50) )
48  { E5x5 = -1000.; }
49  else
50  { E5x5 = mymatrix[xtal-16] + mymatrix[xtal-15] + mymatrix[xtal-14] + mymatrix[xtal-13] + mymatrix[xtal-12] + mymatrix[xtal-9] + mymatrix[xtal-8] + mymatrix[xtal-7] + mymatrix[xtal-6] + mymatrix[xtal-5] + mymatrix[xtal-2] + mymatrix[xtal-1] + mymatrix[xtal] + mymatrix[xtal+1] + mymatrix[xtal+2] + mymatrix[xtal+5] + mymatrix[xtal+6] + mymatrix[xtal+7] + mymatrix[xtal+8] + mymatrix[xtal+9] + mymatrix[xtal+12] + mymatrix[xtal+13] + mymatrix[xtal+14] + mymatrix[xtal+15] + mymatrix[xtal+16]; }
51 
52  return E5x5;
53 }
54 
55 // lateral energy along ieta - syjun
56 void energy_ieta(double mymatrix[], double *energyieta)
57 {
58  for(int jj = 0 ; jj < 5 ; jj++) energyieta[jj] = 0.0;
59 
60  for(int jj = 0 ; jj < 5 ; jj++){
61  for (int ii = 0; ii < 5 ; ii++) energyieta[jj] += mymatrix[(8+jj)+7*ii];
62  }
63 }
64 
65 // lateral energy along iphi - syjun
66 void energy_iphi(double mymatrix[], double *energyiphi)
67 {
68  for(int jj = 0 ; jj < 5 ; jj++) energyiphi[jj] = 0.0;
69 
70  for(int jj = 0 ; jj < 5 ; jj++){
71  for (int ii = 0; ii < 5 ; ii++) energyiphi[jj] += mymatrix[(8+7*jj)+ii];
72  }
73 }
74 
75 
76 // 7x7 matrix energy around the max amplitude xtal
77 double ene7x7_xtal(double mymatrix[])
78 {
79  double E7x7 = 0.;
80 
81  for (int ii=0;ii<49;ii++)
82  {
83  if (mymatrix[ii]<-50)
84  E7x7 = -1000.;
85  else
86  E7x7 += mymatrix[ii];
87  }
88 
89  return E7x7;
90 }
91 
92 
93 // -------------------------------------------
94 // fitting functions
95 // -------------------------------------------
96 
97 // crystal ball fit
98 double crystalball(double *x, double *par) {
99  // par[0]: mean
100  // par[1]: sigma
101  // par[2]: alpha, crossover point
102  // par[3]: n, length of tail
103  // par[4]: N, normalization
104 
105  double cb = 0.0;
106  double exponent = 0.0;
107  double bla = 0.0;
108 
109  if (x[0] > par[0] - par[2]*par[1]) {
110  exponent = (x[0] - par[0])/par[1];
111  cb = exp(-exponent*exponent/2.);
112  } else {
113  double nenner = pow(par[3]/par[2], par[3])*exp(-par[2]*par[2]/2.);
114  double zaehler = (par[0] - x[0])/par[1] + par[3]/par[2] - par[2];
115  zaehler = pow(zaehler, par[3]);
116  cb = nenner/zaehler;
117  }
118 
119  if (par[4] > 0.) {
120  cb *= par[4];
121  }
122  return cb;
123 }
124 
125 double shapeFunction(double *x, double *par) {
126 
127  // par[0] = constant value
128  // par[1], par[2], par[3]: a3, a2 x>0 pol3
129  // par[4], par[5], par[6]: a3, a2 x<=0 pol3
130 
131  double ret_val;
132  if(x[0]>0.)
133  ret_val = par[0] + par[1]*x[0]*x[0] + par[2]*x[0]*x[0]*x[0] + par[3]*x[0]*x[0]*x[0]*x[0];
134  else
135  ret_val = par[0] + par[4]*x[0]*x[0] + par[5]*x[0]*x[0]*x[0] + par[6]*x[0]*x[0]*x[0]*x[0];
136 
137  return ret_val;
138 }
maxAmplitInMatrix
int maxAmplitInMatrix(double myMatrix[])
Definition: myFunctions.cc:6
energy_iphi
void energy_iphi(double mymatrix[], double *energyiphi)
Definition: myFunctions.cc:66
ene3x3_xtal
double ene3x3_xtal(double mymatrix[], int xtal)
Definition: myFunctions.cc:30
ene5x5_xtal
double ene5x5_xtal(double mymatrix[], int xtal)
Definition: myFunctions.cc:43
ene1x1_xtal
double ene1x1_xtal(double mymatrix[], int xtal)
Definition: myFunctions.cc:21
HLT_FULL_cff.exponent
exponent
Definition: HLT_FULL_cff.py:52799
shapeFunction
double shapeFunction(double *x, double *par)
Definition: myFunctions.cc:125
ene7x7_xtal
double ene7x7_xtal(double mymatrix[])
Definition: myFunctions.cc:77
crystalball
double crystalball(double *x, double *par)
Definition: myFunctions.cc:98
genVertex_cff.x
x
Definition: genVertex_cff.py:12
findQualityFiles.jj
string jj
Definition: findQualityFiles.py:188
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
energy_ieta
void energy_ieta(double mymatrix[], double *energyieta)
Definition: myFunctions.cc:56
cuy.ii
ii
Definition: cuy.py:590