ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/yangyong/ECALG4SIM/analysis/testSim.C
Revision: 1.1
Committed: Thu Apr 4 08:29:22 2013 UTC (12 years, 1 month ago) by yangyong
Content type: text/plain
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 yangyong 1.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     for(entry =0; entry< N; entry++){
185    
186     if(entry%10==0) cout<<"entry "<< entry <<endl;
187    
188     fChain->GetEntry(entry);
189     fChain1->GetEntry(entry);
190    
191    
192     for(int j=0; j<nGenPht; j++){
193     float egen = ptGenPht[j]/sin(2*atan(exp(-etaGenPht[j])));
194    
195     vector<int> vj2 = get5x5CrystalStep(etaGenPht[j],phiGenPht[j],vxGenPht[j],vyGenPht[j],vzGenPht[j]);
196    
197     if(vj2.size()<1) continue;
198     double pretmin[25];
199     double pretminv1[25][10];
200     int ind_pretmin[25];
201    
202     for(int jj=0; jj<25; jj++){
203     pretmin[jj] =1E3;
204     ind_pretmin[jj] = 0;
205     for(int kk=0; kk<10; kk++){
206     pretminv1[jj][kk] = 1E3;
207     }
208     }
209    
210     if( fabs(etaGenPht[j])<1.5){
211     for(int jj=0; jj< int(vj2.size()); jj++){
212    
213     int jmax = vj2[jj];
214     int ieta1 = ietag4EB[jmax];
215     int iphi1 = iphig4EB[jmax];
216     convxtalid(iphi1,ieta1);
217     int ieta = ieta1+85;
218     int iphi = getIndphixyzEBAll(iphi1);
219    
220     vector<int> id = idg4EB->at(jmax);
221     vector<int> pid = pidg4EB->at(jmax);
222     vector<int> parentid = parentidg4EB->at(jmax);
223    
224     vector<float> posx = postxg4EB->at(jmax);
225     vector<float> posy = postyg4EB->at(jmax);
226     vector<float> posz = postzg4EB->at(jmax);
227    
228    
229     vector<float> prex = prexg4EB->at(jmax);
230     vector<float> prey = preyg4EB->at(jmax);
231     vector<float> prez = prezg4EB->at(jmax);
232     vector<float> pret = pretg4EB->at(jmax);
233     vector<float> pree = preeg4EB->at(jmax);
234     vector<int> enter = enterg4EB->at(jmax);
235    
236     for(int k=0; k<int(posx.size()); k++){
237     if(enter[k]==1){
238     if( pretmin[jj] > pret[k]){
239     ind_pretmin[jj] = k;
240     pretmin[jj] = pret[k];
241     }
242    
243     for(int kk=0; kk<10; kk++){
244     if(pree[k]/1000.>1+kk){
245     if( pretminv1[jj][kk] > pret[k]){
246     pretminv1[jj][kk] = pret[k];
247     }
248     }
249     }
250     }
251     }
252    
253     if(ietag4EB[jmax]==8 && iphig4EB[jmax]==9) {
254    
255     int ind = ind_pretmin[jj];
256     double pos[3] = {posx[ind]/10,posy[ind]/10,posz[ind]/10};
257     double pre[3] = {prex[ind]/10,prey[ind]/10,prez[ind]/10};
258     distPreStepPointAllSides(pos, pre, ieta, iphi,res,0,1);
259     double ddmin = res[0];
260     fillTH1F("ddpremin_0",ddmin);
261    
262    
263     distplane = res[0];
264     indplane = int(res[1]+0.1);
265     split_new_x = res[2];
266     split_new_y = res[3];
267     prepos[0] = pre[0];
268     prepos[1] = pre[1];
269     prepos[2] = pre[2];
270     pretime = pretmin[jj];
271    
272     for(int k1=0; k1<10;k1++){
273     pretimev1[k1] = pretminv1[jj][k1];
274     }
275    
276     isconv = convGenPht[j];
277     pids[0] = id[ind];
278     pids[1] = pid[ind];
279     pids[2] = parentid[ind];
280     ine = pree[ind];
281    
282     mytree->Fill();
283    
284     fillTH1F("pretmin_0",pretmin[jj]);
285     if(convGenPht[j]==0) {
286     fillTH1F("pretmin_unconv_0",pretmin[jj]);
287     }
288     else {
289     fillTH1F("pretmin_conv_0",pretmin[jj]);
290     }
291    
292     }///for this crystal
293    
294     }///all 5x5
295    
296     }else{//endcap
297    
298    
299     bool fillxtal1ee = false;
300    
301     for(int jj=0; jj< int(vj2.size()); jj++){
302     int jmax = vj2[jj];
303     int ieta = ixg4EE[jmax];
304     int iphi = iyg4EE[jmax];
305     int indz = izg4EE[jmax]>0;
306    
307     vector<float> posx = postxg4EE->at(jmax);
308     vector<float> posy = postyg4EE->at(jmax);
309     vector<float> posz = postzg4EE->at(jmax);
310    
311     vector<float> prex = prexg4EE->at(jmax);
312     vector<float> prey = preyg4EE->at(jmax);
313     vector<float> prez = prezg4EE->at(jmax);
314     vector<int> pid = pidg4EE->at(jmax);
315     vector<int> id = idg4EE->at(jmax);
316     vector<int> parentid = parentidg4EE->at(jmax);
317     vector<float> pree = preeg4EE->at(jmax);
318     vector<float> pret = pretg4EE->at(jmax);
319     vector<int> enter = enterg4EE->at(jmax);
320     for(int k=0; k<int(posx.size()); k++){
321     if(enter[k]==1){
322     if( pretmin[jj] > pret[k] ){
323     ind_pretmin[jj] = k;
324     pretmin[jj] = pret[k];
325     }
326     for(int kk=0; kk<10; kk++){
327     if(pree[k]/1000.>1+kk){
328     if( pretminv1[jj][kk] > pret[k]){
329     pretminv1[jj][kk] = pret[k];
330     }
331     }
332     }
333     }
334     }//all steps
335    
336     if(ixg4EE[jmax]==20 && iyg4EE[jmax]==50 && izg4EE[jmax] ==1) {
337     fillxtal1ee = true; //found in 5x5
338     int ind = ind_pretmin[jj];
339    
340     double pos[3] = {posx[ind]/10,posy[ind]/10,posz[ind]/10};
341     double pre[3] = {prex[ind]/10,prey[ind]/10,prez[ind]/10};
342     distPreStepPointAllSides(pos, pre, ieta,iphi,res,indz,0);
343    
344     distplane = res[0];
345     indplane = int(res[1]+0.1);
346     split_new_x = res[2];
347     split_new_y = res[3];
348     prepos[0] = pre[0];
349     prepos[1] = pre[1];
350     prepos[2] = pre[2];
351     pretime = pretmin[jj];
352     isconv = convGenPht[j];
353    
354     pids[0] = id[ind];
355     pids[1] = pid[ind];
356     pids[2] = parentid[ind];
357     for(int k1=0; k1<10;k1++){
358     pretimev1[k1] = pretminv1[jj][k1];
359     }
360    
361     ine = pree[ind];
362    
363     mytree->Fill();
364    
365     fillTH1F("pretmin_1",pretmin[jj]);
366     if(convGenPht[j]==0){
367     fillTH1F("pretmin_unconv_1",pretmin[jj]);
368     }else {
369     fillTH1F("pretmin_conv_1",pretmin[jj]);
370     }
371     }
372    
373     } ///5x5
374    
375     if( fillxtal1ee == false){
376     //cout<<"not found xtal1ee in 5x5 .. " <<endl;
377     bool notfilled = false;
378    
379     for(int k1=0; k1<10; k1++){
380     pretimev1[k1] = 1E3;
381     }
382    
383     for(int j1=0; j1< ng4EE; j1++){
384    
385     if(ixg4EE[j1]==20 && iyg4EE[j1]==50 && izg4EE[j1] ==1) {
386     vector<float> posx = postxg4EE->at(j1);
387     vector<float> posy = postyg4EE->at(j1);
388     vector<float> posz = postzg4EE->at(j1);
389    
390     vector<float> pret = pretg4EE->at(j1);
391     vector<float> pree = preeg4EE->at(j1);
392     vector<int> enter = enterg4EE->at(j1);
393     vector<float> prex = prexg4EE->at(j1);
394     vector<float> prey = preyg4EE->at(j1);
395     vector<float> prez = prezg4EE->at(j1);
396     vector<int> id = idg4EE->at(j1);
397     vector<int> pid = pidg4EE->at(j1);
398     vector<int> parentid = parentidg4EE->at(j1);
399    
400     float tmin = 1E9;
401     int ind = 0;
402     for(int k=0; k<int(pret.size()); k++){
403     if(enter[k]==0) continue;
404     if(tmin> pret[k] ){
405     tmin = pret[k];
406     ind = k;
407     }
408     for(int k1=0; k1<10;k1++){
409     if( pree[k1]/1000.>1+k1){
410     if( pretimev1[k1] < pret[k]) pretimev1[k1] = pret[k];
411     }
412     }
413     }
414     notfilled = true;
415     fillTH1F("pretmin_1",tmin);
416     if(convGenPht[j]==0){
417     fillTH1F("pretmin_unconv_1",tmin);
418     }else {
419     fillTH1F("pretmin_conv_1",tmin);
420     }
421    
422     int ieta = ixg4EE[j1];
423     int iphi = iyg4EE[j1];
424     int indz = izg4EE[j1]>0;
425    
426     double pos[3] = {posx[ind]/10,posy[ind]/10,posz[ind]/10};
427     double pre[3] = {prex[ind]/10,prey[ind]/10,prez[ind]/10};
428     distPreStepPointAllSides(pos, pre, ieta,iphi,res,indz,0);
429    
430     distplane = res[0];
431     indplane = int(res[1]+0.1);
432     split_new_x = res[2];
433     split_new_y = res[3];
434     prepos[0] = pre[0];
435     prepos[1] = pre[1];
436     prepos[2] = pre[2];
437     pretime = tmin;
438     isconv = convGenPht[j];
439     pids[0] = id[ind];
440     pids[1] = pid[ind];
441     pids[2] = parentid[ind];
442     ine = pree[ind];
443     mytree->Fill();
444    
445    
446     }
447     }
448    
449     if( !notfilled){
450     cout<<"not found at all?? "<< entry <<endl;
451     //return;
452     }
453     }
454    
455     } //endcap
456    
457    
458     } ///all genPht
459    
460    
461    
462     }
463    
464    
465    
466     mytree->Write();
467     fnew->Write();
468     fnew->Close();
469    
470     }