ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/yangyong/combineICEB/common_functions.cc
Revision: 1.2
Committed: Tue Apr 10 19:41:08 2012 UTC (13 years ago) by yangyong
Content type: text/plain
Branch: MAIN
CVS Tags: V2012combv2c, V2012combv2b, V2012combv2a, V2012combv2, V2012combv1, V2011combv1, pi0etaeb_laser20111122, HEAD
Changes since 1.1: +216 -0 lines
Log Message:
LaserTag:
EcalLaserAPDPNRatios_data_20111122_158851_180363

and alpha Tag ( for Endcap Only)
EcalLaserAlphas_lto420-620_progr_data_20111122

File Contents

# Content
1
2 /////////////////////////////////////////////////////////////////////////////////////////////////
3
4 void convxtalid(Int_t &nphi,Int_t &neta)
5 {
6 // Changed to what Yong's convention; output will give just two indices
7 // phi is unchanged; only eta now runs from
8 //
9 // 03/01/2008 changed to the new definition in CMSSW. The output is still the same...
10 // Barrel only
11 // Output nphi 0...359; neta 0...84; nside=+1 (for eta>0), or 0 (for eta<0).
12 // neta will be [-85,-1] , or [0,84], the minus sign indicates the z<0 side.
13
14 if(neta > 0) neta -= 1;
15 if(nphi > 359) nphi=nphi-360;
16
17 // final check
18 if(nphi >359 || nphi <0 || neta< -85 || neta > 84)
19 {
20 cout <<" output not in range: "<< nphi << " " << neta << " " <<endl;
21 exit(1);
22 }
23 } //end of convxtalid
24
25
26 // Calculate the distance in xtals taking into account possibly different sides
27 // change to coincide with yongs definition
28 Int_t diff_neta(Int_t neta1, Int_t neta2){
29 Int_t mdiff;
30 mdiff=abs(neta1-neta2);
31 return mdiff;
32 }
33
34 // Calculate the absolute distance in xtals taking into account the periodicity of the Barrel
35 Int_t diff_nphi(Int_t nphi1,Int_t nphi2) {
36 Int_t mdiff;
37 mdiff=abs(nphi1-nphi2);
38 if (mdiff > (360-abs(nphi1-nphi2))) mdiff=(360-abs(nphi1-nphi2));
39 return mdiff;
40 }
41
42 // Calculate the distance in xtals taking into account possibly different sides
43 // Then the distance would be from the 1st to the 2nd argument
44 // _s means that it gives the sign; the only difference from the above !
45 // also changed to coincide with Yong's definition
46 Int_t diff_neta_s(Int_t neta1, Int_t neta2){
47 Int_t mdiff;
48 mdiff=(neta1-neta2);
49 return mdiff;
50 }
51
52 // Calculate the distance in xtals taking into account the periodicity of the Barrel
53 Int_t diff_nphi_s(Int_t nphi1,Int_t nphi2) {
54 Int_t mdiff;
55 if(abs(nphi1-nphi2) < (360-abs(nphi1-nphi2))) {
56 mdiff=nphi1-nphi2;
57 }
58 else {
59 mdiff=360-abs(nphi1-nphi2);
60 if(nphi1>nphi2) mdiff=-mdiff;
61 }
62 return mdiff;
63 }
64
65
66
67 void sortPtvector(vector<float> pt, vector<int> &ind){
68
69 ind.clear();
70
71 int n = int( pt.size());
72
73 vector<float> pt0;
74 for(int j=0; j< n ; j++){
75 pt0.push_back(pt[j]);
76 }
77
78 sort(pt.begin(),pt.end());
79
80 for(int j = n -1; j>=0; j--){
81
82 float dptmin = 0.1;
83 int jmin = -1;
84 for(int k=0; k< n; k++){
85
86 float dpt = fabs( pt[j] - pt0[k]);
87 vector<int>::iterator it = find( ind.begin(),ind.end(),k);
88 if( it != ind.end()) continue;
89
90 if( dpt < dptmin){
91 dptmin = dpt;
92 jmin = k;
93 }
94
95 }
96 ind.push_back(jmin);
97
98 }
99
100 if(int(ind.size()) != n){
101 cout<<"erorr_sortPtvector.."<<endl;
102 exit(1);
103 }
104
105 }
106
107
108 float calculateS4(int nn, float en[],int ieta[], int iphi[]){
109 ///shower-shape
110 Float_t S4_0 =0.; Float_t S4_1 =0.;
111 Float_t S4_2 =0.; Float_t S4_3 =0.;
112
113
114 for(int n=0; n< nn; n++){
115 float energy = en[n];
116 int deta = diff_neta_s(ieta[0],ieta[n]);
117 int dphi = diff_nphi_s(iphi[0],iphi[n]);
118 if( abs(deta) <=1 && abs(dphi) <= 1){
119 if( dphi <= 0 && deta <= 0) S4_0+=energy;
120 if( dphi >= 0 && deta <= 0) S4_1+=energy;
121 if( dphi <= 0 && deta >= 0) S4_2+=energy;
122 if( dphi >= 0 && deta >= 0) S4_3+=energy;
123 }
124 }
125 Float_t S4max=S4_0;
126 if(S4_1 > S4max) S4max=S4_1;
127 if(S4_2 > S4max) S4max=S4_2;
128 if(S4_3 > S4max) S4max=S4_3;
129
130 return S4max;
131
132 }
133
134 void calculateS4_v1(int nn, float en[],int ieta[], int iphi[],float res[]){
135 ///shower-shape
136 Float_t S4_0 =0.; Float_t S4_1 =0.;
137 Float_t S4_2 =0.; Float_t S4_3 =0.;
138
139 float S9 = 0;
140
141 for(int n=0; n< nn; n++){
142 float energy = en[n];
143 int deta = diff_neta_s(ieta[0],ieta[n]);
144 int dphi = diff_nphi_s(iphi[0],iphi[n]);
145 if( abs(deta) <=1 && abs(dphi) <= 1){
146
147 S9 += energy;
148
149 if( dphi <= 0 && deta <= 0) S4_0+=energy;
150 if( dphi >= 0 && deta <= 0) S4_1+=energy;
151 if( dphi <= 0 && deta >= 0) S4_2+=energy;
152 if( dphi >= 0 && deta >= 0) S4_3+=energy;
153 }
154 }
155 Float_t S4max=S4_0;
156 if(S4_1 > S4max) S4max=S4_1;
157 if(S4_2 > S4max) S4max=S4_2;
158 if(S4_3 > S4max) S4max=S4_3;
159
160 //// return S4max;
161
162 res[0] = S4max;
163 res[1] = S9;
164
165
166 }
167
168
169 ///input ieta iphi originall
170
171 void calculateS4_v2(int nn, float en[],int ieta[], int iphi[],float res[]){
172 ///shower-shape
173 Float_t S4_0 =0.; Float_t S4_1 =0.;
174 Float_t S4_2 =0.; Float_t S4_3 =0.;
175
176 float S9 = 0;
177
178 int ieta_seed = ieta[0];
179 int iphi_seed = iphi[0];
180
181 convxtalid(iphi_seed,ieta_seed);
182
183
184
185 for(int n=0; n< nn; n++){
186 float energy = en[n];
187
188 int eta = ieta[n];
189 int phi = iphi[n];
190 convxtalid(phi,eta);
191
192 int deta = diff_neta_s(ieta_seed,eta);
193 int dphi = diff_nphi_s(iphi_seed,phi);
194
195 if( abs(deta) <=1 && abs(dphi) <= 1){
196
197 S9 += energy;
198
199 if( dphi <= 0 && deta <= 0) S4_0+=energy;
200 if( dphi >= 0 && deta <= 0) S4_1+=energy;
201 if( dphi <= 0 && deta >= 0) S4_2+=energy;
202 if( dphi >= 0 && deta >= 0) S4_3+=energy;
203 }
204 }
205 Float_t S4max=S4_0;
206 if(S4_1 > S4max) S4max=S4_1;
207 if(S4_2 > S4max) S4max=S4_2;
208 if(S4_3 > S4max) S4max=S4_3;
209
210 //// return S4max;
211
212 res[0] = S4max;
213 res[1] = S9;
214
215
216 }