ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/yangyong/ECALG4SIM/analysis/testSim.C
Revision: 1.2
Committed: Thu Apr 4 10:56:42 2013 UTC (12 years, 1 month ago) by yangyong
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +5 -4 lines
Error occurred while calculating annotation data.
Log Message:
*** empty log message ***

File Contents

# Content
1 #include "rootheader.h"
2
3 #include "testSim.h"
4
5 bool debug = 0;
6
7 TChain *fChain;
8 TChain *fChain1;
9 int entry;
10
11 map<int,map<int, vector<double> > > map_planes_eb; /// ix, iy 6planes 0: 0123, 1: 0145, 2: 1256, 3:2367, 4:0347, 5: 4567
12
13 map<int,map<int, map<int, vector<double> > > > map_planes_ee; /// iz , ix, iy 6planes 0: 0123, 1: 0145, 2: 1256, 3:2367, 4:0347, 5: 4567
14
15 int coindall[6][5] ={
16 {0,1,2,3,0},
17 {0,1,5,4,0},
18 {1,2,6,5,1},
19 {2,3,7,6,2},
20 {0,3,7,4,0},
21 {4,5,6,7,4}
22 };
23
24
25
26 #include "setbranchaddress.cc"
27
28 #include "utils.cc"
29
30 #include "th3f.cc"
31
32 #include "planes.cc"
33
34 void testSim(){
35
36 ///sims tep
37 fChain = new TChain("G4SIM");
38 fChain->Add("g4simhitsEcal.root");
39 fChain1 = new TChain("Analysis");
40
41 setbranchaddress_g4step();
42
43 int N = fChain->GetEntries();
44
45 fChain1->Add("analysis.root");
46 setbranchaddress_g4sim();
47
48 get_xyzEBrechits();
49
50 TFile *fnew = new TFile("testSime.root","recreate");
51 TTree *mytree = new TTree("Analysis","conv xy in front face");
52
53 int isconv;
54 int indplane;
55 float distplane;
56 float split_new_x;
57 float split_new_y;
58 float prepos[3];
59 float pretime;
60
61 float pretimev1[10]; //E>1, E>2, E>3, 4., ...10
62
63 int pids[3]; //0: primary id, 1: particle id, 2: parent id
64 mytree->Branch("split_new_x",&split_new_x,"split_new_x/F");
65 mytree->Branch("split_new_y",&split_new_y,"split_new_y/F");
66 mytree->Branch("indplane",&indplane,"indplane/I");
67 mytree->Branch("distplane",&distplane,"distplane/F");
68 mytree->Branch("prepos",prepos,"prepos[3]/F");
69 mytree->Branch("pretime",&pretime,"pretime/F");
70 mytree->Branch("pretimev1",pretimev1,"pretimev1[10]/F");
71 mytree->Branch("isconv",&isconv,"isconv/I");
72 mytree->Branch("pids",pids,"pids[3]/I");
73 float ine;
74 mytree->Branch("ine",&ine,"ine/F");
75
76
77 //one in eb
78 makeTH1F("pretmin_0",30000,3,6);
79 makeTH1F("pretmin_unconv_0",30000,3,6);
80 makeTH1F("pretmin_conv_0",30000,3,6);
81
82 //one xtal in ee
83 makeTH1F("pretmin_1",30000,8,14);
84 makeTH1F("pretmin_unconv_1",30000,8,14);
85 makeTH1F("pretmin_conv_1",30000,8,14);
86
87 double speedoflight = 29.9792458; //cm /ns
88 double p[4];
89 bool interset;
90
91 ofstream txtout("testSim.txt",ios::out);
92
93 double pzero[3] = {0,0,0};
94
95
96 /// calculates here 6planes 0: 0123, 1: 0145, 2: 1256, 3:2367, 4:0347, 5: 4567
97 int coind[6][3] ={
98 {0,1,2},
99 {0,1,4},
100 {1,2,5},
101 {2,3,6},
102 {0,3,4},
103 {4,5,6}
104 };
105
106 for(int k= 0; k<=169; k++){
107 for(int j=0; j<=359; j++){
108
109 double a[3] = {coxEBAll[k][j][0],coyEBAll[k][j][0],cozEBAll[k][j][0]};
110 double b[3] = {coxEBAll[k][j][1],coyEBAll[k][j][1],cozEBAll[k][j][1]};
111 double c[3] = {coxEBAll[k][j][2],coyEBAll[k][j][2],cozEBAll[k][j][2]};
112 computePlane(a,b,c,p);
113
114 double center[3]= {0};
115 double cop[8][3];
116 for(int n=0; n<8; n++){
117 cop[n][0] = coxEBAll[k][j][n];
118 cop[n][1] = coyEBAll[k][j][n];
119 cop[n][2] = cozEBAll[k][j][n];
120
121 center[0] += 1./8 * coxEBAll[k][j][n];
122 center[1] += 1./8 * coyEBAll[k][j][n];
123 center[2] += 1./8 * cozEBAll[k][j][n];
124
125 xctEBAll[k][j] += 1./8 * coxEBAll[k][j][n];
126 yctEBAll[k][j] += 1./8 * coyEBAll[k][j][n];
127 zctEBAll[k][j] += 1./8 * cozEBAll[k][j][n];
128 }
129
130 /// calculates here 6planes 0: 0123, 1: 0145, 2: 1256, 3:2367, 4:0347, 5: 4567
131 for(int n=0; n<6; n++){
132 computePlane( cop[coind[n][0]], cop[coind[n][1]],cop[coind[n][2]], p);
133 for(int kk=0; kk<4; kk++){
134 map_planes_eb[k][j].push_back(p[kk]);
135 }
136 }
137
138 }
139 }
140
141
142
143 for(int iz=0; iz<2; iz++){
144 for(int k= 1; k<=100; k++){
145 for(int j=1; j<=100; j++){
146
147 if ( fabs(zEEAll[iz][k][j])<1) continue; //not valid
148 double a[3] = {coxEEAll[iz][k][j][0],coyEEAll[iz][k][j][0],cozEEAll[iz][k][j][0]};
149 double b[3] = {coxEEAll[iz][k][j][1],coyEEAll[iz][k][j][1],cozEEAll[iz][k][j][1]};
150 double c[3] = {coxEEAll[iz][k][j][2],coyEEAll[iz][k][j][2],cozEEAll[iz][k][j][2]};
151 computePlane(a,b,c,p);
152
153 double center[3]= {0};
154 double cop[8][3];
155 for(int n=0; n<8; n++){
156 cop[n][0] = coxEEAll[iz][k][j][n];
157 cop[n][1] = coyEEAll[iz][k][j][n];
158 cop[n][2] = cozEEAll[iz][k][j][n];
159
160 center[0] += 1./8 * coxEEAll[iz][k][j][n];
161 center[1] += 1./8 * coyEEAll[iz][k][j][n];
162 center[2] += 1./8 * cozEEAll[iz][k][j][n];
163
164 xctEEAll[iz][k][j] += 1./8 * coxEEAll[iz][k][j][n];
165 yctEEAll[iz][k][j] += 1./8 * coyEEAll[iz][k][j][n];
166 zctEEAll[iz][k][j] += 1./8 * cozEEAll[iz][k][j][n];
167 }
168 /// calculates here 6planes 0: 0123, 1: 0145, 2: 1256, 3:2367, 4:0347, 5: 4567
169 for(int n=0; n<6; n++){
170 computePlane( cop[coind[n][0]], cop[coind[n][1]],cop[coind[n][2]], p);
171 for(int kk=0; kk<4; kk++){
172 map_planes_ee[iz][k][j].push_back(p[kk]);
173 }
174 }
175
176 }
177 }
178 }
179
180 float res[10];
181
182 cout<<"N " << N <<endl;
183
184 // N = 1;
185 for(entry =0; entry< N; entry++){
186
187 if(entry%10==0) cout<<"entry "<< entry <<endl;
188
189 fChain->GetEntry(entry);
190 fChain1->GetEntry(entry);
191
192
193 for(int j=0; j<nGenPht; j++){
194 float egen = ptGenPht[j]/sin(2*atan(exp(-etaGenPht[j])));
195
196 vector<int> vj2 = get5x5CrystalStep(etaGenPht[j],phiGenPht[j],vxGenPht[j],vyGenPht[j],vzGenPht[j]);
197
198
199 if(vj2.size()<1) continue;
200 double pretmin[25];
201 double pretminv1[25][10];
202 int ind_pretmin[25];
203
204 for(int jj=0; jj<25; jj++){
205 pretmin[jj] =1E3;
206 ind_pretmin[jj] = 0;
207 for(int kk=0; kk<10; kk++){
208 pretminv1[jj][kk] = 1E3;
209 }
210 }
211
212 if( fabs(etaGenPht[j])<1.5){
213 for(int jj=0; jj< int(vj2.size()); jj++){
214
215 int jmax = vj2[jj];
216 int ieta1 = ietag4EB[jmax];
217 int iphi1 = iphig4EB[jmax];
218 convxtalid(iphi1,ieta1);
219 int ieta = ieta1+85;
220 int iphi = getIndphixyzEBAll(iphi1);
221
222 vector<int> id = idg4EB->at(jmax);
223 vector<int> pid = pidg4EB->at(jmax);
224 vector<int> parentid = parentidg4EB->at(jmax);
225
226 vector<float> posx = postxg4EB->at(jmax);
227 vector<float> posy = postyg4EB->at(jmax);
228 vector<float> posz = postzg4EB->at(jmax);
229
230
231 vector<float> prex = prexg4EB->at(jmax);
232 vector<float> prey = preyg4EB->at(jmax);
233 vector<float> prez = prezg4EB->at(jmax);
234 vector<float> pret = pretg4EB->at(jmax);
235 vector<float> pree = preeg4EB->at(jmax);
236 vector<int> enter = enterg4EB->at(jmax);
237
238 for(int k=0; k<int(posx.size()); k++){
239 if(enter[k]==1){
240 if( pretmin[jj] > pret[k]){
241 ind_pretmin[jj] = k;
242 pretmin[jj] = pret[k];
243 }
244
245 for(int kk=0; kk<10; kk++){
246 if(pree[k]/1000.>1+kk){
247 if( pretminv1[jj][kk] > pret[k]){
248 pretminv1[jj][kk] = pret[k];
249 }
250 }
251 }
252 }
253 }
254
255
256
257 if(ietag4EB[jmax]==8 && iphig4EB[jmax]==9) {
258
259 int ind = ind_pretmin[jj];
260 double pos[3] = {posx[ind]/10,posy[ind]/10,posz[ind]/10};
261 double pre[3] = {prex[ind]/10,prey[ind]/10,prez[ind]/10};
262 distPreStepPointAllSides(pos, pre, ieta, iphi,res,0,1);
263
264 distplane = res[0];
265 indplane = int(res[1]+0.1);
266 split_new_x = res[2];
267 split_new_y = res[3];
268 prepos[0] = pre[0];
269 prepos[1] = pre[1];
270 prepos[2] = pre[2];
271 pretime = pretmin[jj];
272
273 for(int k1=0; k1<10;k1++){
274 pretimev1[k1] = pretminv1[jj][k1];
275 }
276
277 isconv = convGenPht[j];
278 pids[0] = id[ind];
279 pids[1] = pid[ind];
280 pids[2] = parentid[ind];
281 ine = pree[ind];
282
283 mytree->Fill();
284
285 fillTH1F("pretmin_0",pretmin[jj]);
286 if(convGenPht[j]==0) {
287 fillTH1F("pretmin_unconv_0",pretmin[jj]);
288 }
289 else {
290 fillTH1F("pretmin_conv_0",pretmin[jj]);
291 }
292
293 }///for this crystal
294
295 }///all 5x5
296
297 }else{//endcap
298
299
300 bool fillxtal1ee = false;
301
302 for(int jj=0; jj< int(vj2.size()); jj++){
303 int jmax = vj2[jj];
304 int ieta = ixg4EE[jmax];
305 int iphi = iyg4EE[jmax];
306 int indz = izg4EE[jmax]>0;
307
308 vector<float> posx = postxg4EE->at(jmax);
309 vector<float> posy = postyg4EE->at(jmax);
310 vector<float> posz = postzg4EE->at(jmax);
311
312 vector<float> prex = prexg4EE->at(jmax);
313 vector<float> prey = preyg4EE->at(jmax);
314 vector<float> prez = prezg4EE->at(jmax);
315 vector<int> pid = pidg4EE->at(jmax);
316 vector<int> id = idg4EE->at(jmax);
317 vector<int> parentid = parentidg4EE->at(jmax);
318 vector<float> pree = preeg4EE->at(jmax);
319 vector<float> pret = pretg4EE->at(jmax);
320 vector<int> enter = enterg4EE->at(jmax);
321 for(int k=0; k<int(posx.size()); k++){
322 if(enter[k]==1){
323 if( pretmin[jj] > pret[k] ){
324 ind_pretmin[jj] = k;
325 pretmin[jj] = pret[k];
326 }
327 for(int kk=0; kk<10; kk++){
328 if(pree[k]/1000.>1+kk){
329 if( pretminv1[jj][kk] > pret[k]){
330 pretminv1[jj][kk] = pret[k];
331 }
332 }
333 }
334 }
335 }//all steps
336
337 if(ixg4EE[jmax]==20 && iyg4EE[jmax]==50 && izg4EE[jmax] ==1) {
338 fillxtal1ee = true; //found in 5x5
339 int ind = ind_pretmin[jj];
340
341 double pos[3] = {posx[ind]/10,posy[ind]/10,posz[ind]/10};
342 double pre[3] = {prex[ind]/10,prey[ind]/10,prez[ind]/10};
343 distPreStepPointAllSides(pos, pre, ieta,iphi,res,indz,0);
344
345 distplane = res[0];
346 indplane = int(res[1]+0.1);
347 split_new_x = res[2];
348 split_new_y = res[3];
349 prepos[0] = pre[0];
350 prepos[1] = pre[1];
351 prepos[2] = pre[2];
352 pretime = pretmin[jj];
353 isconv = convGenPht[j];
354
355 pids[0] = id[ind];
356 pids[1] = pid[ind];
357 pids[2] = parentid[ind];
358 for(int k1=0; k1<10;k1++){
359 pretimev1[k1] = pretminv1[jj][k1];
360 }
361
362 ine = pree[ind];
363
364 mytree->Fill();
365
366 fillTH1F("pretmin_1",pretmin[jj]);
367 if(convGenPht[j]==0){
368 fillTH1F("pretmin_unconv_1",pretmin[jj]);
369 }else {
370 fillTH1F("pretmin_conv_1",pretmin[jj]);
371 }
372 }
373
374 } ///5x5
375
376 if( fillxtal1ee == false){
377 //cout<<"not found xtal1ee in 5x5 .. " <<endl;
378 bool notfilled = false;
379
380 for(int k1=0; k1<10; k1++){
381 pretimev1[k1] = 1E3;
382 }
383
384 for(int j1=0; j1< ng4EE; j1++){
385
386 if(ixg4EE[j1]==20 && iyg4EE[j1]==50 && izg4EE[j1] ==1) {
387 vector<float> posx = postxg4EE->at(j1);
388 vector<float> posy = postyg4EE->at(j1);
389 vector<float> posz = postzg4EE->at(j1);
390
391 vector<float> pret = pretg4EE->at(j1);
392 vector<float> pree = preeg4EE->at(j1);
393 vector<int> enter = enterg4EE->at(j1);
394 vector<float> prex = prexg4EE->at(j1);
395 vector<float> prey = preyg4EE->at(j1);
396 vector<float> prez = prezg4EE->at(j1);
397 vector<int> id = idg4EE->at(j1);
398 vector<int> pid = pidg4EE->at(j1);
399 vector<int> parentid = parentidg4EE->at(j1);
400
401 float tmin = 1E9;
402 int ind = 0;
403 for(int k=0; k<int(pret.size()); k++){
404 if(enter[k]==0) continue;
405 if(tmin> pret[k] ){
406 tmin = pret[k];
407 ind = k;
408 }
409 for(int k1=0; k1<10;k1++){
410 if( pree[k1]/1000.>1+k1){
411 if( pretimev1[k1] < pret[k]) pretimev1[k1] = pret[k];
412 }
413 }
414 }
415 notfilled = true;
416 fillTH1F("pretmin_1",tmin);
417 if(convGenPht[j]==0){
418 fillTH1F("pretmin_unconv_1",tmin);
419 }else {
420 fillTH1F("pretmin_conv_1",tmin);
421 }
422
423 int ieta = ixg4EE[j1];
424 int iphi = iyg4EE[j1];
425 int indz = izg4EE[j1]>0;
426
427 double pos[3] = {posx[ind]/10,posy[ind]/10,posz[ind]/10};
428 double pre[3] = {prex[ind]/10,prey[ind]/10,prez[ind]/10};
429 distPreStepPointAllSides(pos, pre, ieta,iphi,res,indz,0);
430
431 distplane = res[0];
432 indplane = int(res[1]+0.1);
433 split_new_x = res[2];
434 split_new_y = res[3];
435 prepos[0] = pre[0];
436 prepos[1] = pre[1];
437 prepos[2] = pre[2];
438 pretime = tmin;
439 isconv = convGenPht[j];
440 pids[0] = id[ind];
441 pids[1] = pid[ind];
442 pids[2] = parentid[ind];
443 ine = pree[ind];
444 mytree->Fill();
445
446
447 }
448 }
449
450 if( !notfilled){
451 cout<<"not found at all?? "<< entry <<endl;
452 //return;
453 }
454 }
455
456 } //endcap
457
458
459 } ///all genPht
460
461
462
463 }
464
465
466
467 mytree->Write();
468 fnew->Write();
469 fnew->Close();
470
471 }