/[PAMELA software]/PamelaLevel2/src/PamLevel2.cpp
ViewVC logotype

Contents of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.59 - (show annotations) (download)
Thu Feb 14 09:13:44 2008 UTC (17 years ago) by pam-fi
Branch: MAIN
CVS Tags: v5r00
Changes since 1.58: +52 -39 lines
small changes in text output

1 #include <PamLevel2.h>
2
3
4
5 /////////////////////////////////////////////////////////////////////////////
6 /////////////////////////////////////////////////////////////////////////////
7 /////////////////////////////////////////////////////////////////////////////
8 /////////////////////////////////////////////////////////////////////////////
9
10 void GPamela::Clear(){
11 Irun = 0;
12 Ievnt = 0;
13 Ipa = 0;
14 X0 = 0.;
15 Y0 = 0.;
16 Z0 = 0.;
17 Theta = 0.;
18 Phi = 0.;
19 P0 = 0.;
20 Nthtof = 0;
21 Nthcat = 0;
22 Nthcas = 0;
23 Nthspe = 0;
24 Nstrpx = 0;
25 Nstrpy = 0;
26 Nthcali = 0;
27 Nthcal = 0;
28 Nthnd = 0;
29 Nthcard = 0;
30 }
31
32 void GPamela::Delete(){
33
34 Clear();
35
36 delete [] Ipltof;
37 delete [] Ipaddle;
38 delete [] Ipartof;
39 delete [] Xintof;
40 delete [] Yintof;
41 delete [] Zintof;
42 delete [] Xouttof;
43 delete [] Youttof;
44 delete [] Zouttof;
45 delete [] Ereltof;
46 delete [] Timetof;
47 delete [] Pathtof;
48 delete [] P0tof;
49 delete [] Iparcat;
50 delete [] Icat;
51 delete [] Xincat;
52 delete [] Yincat;
53 delete [] Zincat;
54 delete [] Xoutcat;
55 delete [] Youtcat;
56 delete [] Zoutcat;
57 delete [] Erelcat;
58 delete [] Timecat;
59 delete [] Pathcat;
60 delete [] P0cat;
61 delete [] Iparcas;
62 delete [] Icas;
63 delete [] Xincas;
64 delete [] Yincas;
65 delete [] Zincas;
66 delete [] Xoutcas;
67 delete [] Youtcas;
68 delete [] Zoutcas;
69 delete [] Erelcas;
70 delete [] Timecas;
71 delete [] Pathcas;
72 delete [] P0cas;
73 delete [] Iparspe;
74 delete [] Itrpb;
75 delete [] Itrsl;
76 delete [] Itspa;
77 delete [] Xinspe;
78 delete [] Yinspe;
79 delete [] Zinspe;
80 delete [] Xoutspe;
81 delete [] Youtspe;
82 delete [] Zoutspe;
83 delete [] Xavspe;
84 delete [] Yavspe;
85 delete [] Zavspe;
86 delete [] Erelspe;
87 delete [] Pathspe;
88 delete [] P0spe;
89 delete [] Nxmult;
90 delete [] Nymult;
91 delete [] Npstripx;
92 delete [] Ntstripx;
93 delete [] Istripx;
94 delete [] Qstripx;
95 delete [] Xstripx;
96 delete [] Npstripy;
97 delete [] Ntstripy;
98 delete [] Istripy;
99 delete [] Qstripy;
100 delete [] Ystripy;
101 delete [] Icaplane;
102 delete [] Icastrip;
103 delete [] Icamod;
104 delete [] Enestrip;
105 delete [] Icapl;
106 delete [] Icasi;
107 delete [] Icast;
108 delete [] Xincal;
109 delete [] Yincal;
110 delete [] Zincal;
111 delete [] Erelcal;
112 delete [] Itubend;
113 delete [] Iparnd;
114 delete [] Xinnd;
115 delete [] Yinnd;
116 delete [] Zinnd;
117 delete [] Xoutnd;
118 delete [] Youtnd;
119 delete [] Zoutnd;
120 delete [] Erelnd;
121 delete [] Timend;
122 delete [] Pathnd;
123 delete [] P0nd;
124 delete [] Iparcard;
125 delete [] Icard;
126 delete [] Xincard;
127 delete [] Yincard;
128 delete [] Zincard;
129 delete [] Xoutcard;
130 delete [] Youtcard;
131 delete [] Zoutcard;
132 delete [] Erelcard;
133 delete [] Timecard;
134 delete [] Pathcard;
135 delete [] P0card;
136
137
138 };
139
140
141
142 void GPamela::SetBranchAddress( TChain* fhBookTree ){
143
144 // cout << "fhBookTree "<<fhBookTree << endl;
145 // prepare tree
146 fhBookTree->SetBranchAddress("Irun",&Irun);
147 fhBookTree->SetBranchAddress("Ievnt",&Ievnt);
148 fhBookTree->SetBranchAddress("Ipa",&Ipa);
149 fhBookTree->SetBranchAddress("X0",&X0);
150 fhBookTree->SetBranchAddress("Y0",&Y0);
151 fhBookTree->SetBranchAddress("Z0",&Z0);
152 fhBookTree->SetBranchAddress("Theta",&Theta);
153 fhBookTree->SetBranchAddress("Phi",&Phi);
154 fhBookTree->SetBranchAddress("P0",&P0);
155 fhBookTree->SetBranchAddress("Nthtof",&Nthtof);
156 fhBookTree->SetBranchAddress("Ipltof",Ipltof);
157 fhBookTree->SetBranchAddress("Ipaddle",Ipaddle);
158 fhBookTree->SetBranchAddress("Ipartof",Ipartof);
159 fhBookTree->SetBranchAddress("Xintof",Xintof);
160 fhBookTree->SetBranchAddress("Yintof",Yintof);
161 fhBookTree->SetBranchAddress("Zintof",Zintof);
162 fhBookTree->SetBranchAddress("Xouttof",Xouttof);
163 fhBookTree->SetBranchAddress("Youttof",Youttof);
164 fhBookTree->SetBranchAddress("Zouttof",Zouttof);
165 fhBookTree->SetBranchAddress("Ereltof",Ereltof);
166 fhBookTree->SetBranchAddress("Timetof",Timetof);
167 fhBookTree->SetBranchAddress("Pathtof",Pathtof);
168 fhBookTree->SetBranchAddress("P0tof",P0tof);
169 fhBookTree->SetBranchAddress("Nthcat",&Nthcat);
170 fhBookTree->SetBranchAddress("Iparcat",Iparcat);
171 fhBookTree->SetBranchAddress("Icat",Icat);
172 fhBookTree->SetBranchAddress("Xincat",Xincat);
173 fhBookTree->SetBranchAddress("Yincat",Yincat);
174 fhBookTree->SetBranchAddress("Zincat",Zincat);
175 fhBookTree->SetBranchAddress("Xoutcat",Xoutcat);
176 fhBookTree->SetBranchAddress("Youtcat",Youtcat);
177 fhBookTree->SetBranchAddress("Zoutcat",Zoutcat);
178 fhBookTree->SetBranchAddress("Erelcat",Erelcat);
179 fhBookTree->SetBranchAddress("Timecat",Timecat);
180 fhBookTree->SetBranchAddress("Pathcat",Pathcat);
181 fhBookTree->SetBranchAddress("P0cat",P0cat);
182 fhBookTree->SetBranchAddress("Nthcas",&Nthcas);
183 fhBookTree->SetBranchAddress("Iparcas",Iparcas);
184 fhBookTree->SetBranchAddress("Icas",Icas);
185 fhBookTree->SetBranchAddress("Xincas",Xincas);
186 fhBookTree->SetBranchAddress("Yincas",Yincas);
187 fhBookTree->SetBranchAddress("Zincas",Zincas);
188 fhBookTree->SetBranchAddress("Xoutcas",Xoutcas);
189 fhBookTree->SetBranchAddress("Youtcas",Youtcas);
190 fhBookTree->SetBranchAddress("Zoutcas",Zoutcas);
191 fhBookTree->SetBranchAddress("Erelcas",Erelcas);
192 fhBookTree->SetBranchAddress("Timecas",Timecas);
193 fhBookTree->SetBranchAddress("Pathcas",Pathcas);
194 fhBookTree->SetBranchAddress("P0cas",P0cas);
195 fhBookTree->SetBranchAddress("Nthspe",&Nthspe);
196 fhBookTree->SetBranchAddress("Iparspe",Iparspe);
197 fhBookTree->SetBranchAddress("Itrpb",Itrpb);
198 fhBookTree->SetBranchAddress("Itrsl",Itrsl);
199 fhBookTree->SetBranchAddress("Itspa",Itspa);
200 fhBookTree->SetBranchAddress("Xinspe",Xinspe);
201 fhBookTree->SetBranchAddress("Yinspe",Yinspe);
202 fhBookTree->SetBranchAddress("Zinspe",Zinspe);
203 fhBookTree->SetBranchAddress("Xoutspe",Xoutspe);
204 fhBookTree->SetBranchAddress("Youtspe",Youtspe);
205 fhBookTree->SetBranchAddress("Zoutspe",Zoutspe);
206 fhBookTree->SetBranchAddress("Xavspe",Xavspe);
207 fhBookTree->SetBranchAddress("Yavspe",Yavspe);
208 fhBookTree->SetBranchAddress("Zavspe",Zavspe);
209 fhBookTree->SetBranchAddress("Erelspe",Erelspe);
210 fhBookTree->SetBranchAddress("Pathspe",Pathspe);
211 fhBookTree->SetBranchAddress("P0spe",P0spe);
212 fhBookTree->SetBranchAddress("Nxmult",Nxmult);
213 fhBookTree->SetBranchAddress("Nymult",Nymult);
214 fhBookTree->SetBranchAddress("Nstrpx",&Nstrpx);
215 fhBookTree->SetBranchAddress("Npstripx",Npstripx);
216 fhBookTree->SetBranchAddress("Ntstripx",Ntstripx);
217 fhBookTree->SetBranchAddress("Istripx",Istripx);
218 fhBookTree->SetBranchAddress("Qstripx",Qstripx);
219 fhBookTree->SetBranchAddress("Xstripx",Xstripx);
220 fhBookTree->SetBranchAddress("Nstrpy",&Nstrpy);
221 fhBookTree->SetBranchAddress("Npstripy",Npstripy);
222 fhBookTree->SetBranchAddress("Ntstripy",Ntstripy);
223 fhBookTree->SetBranchAddress("Istripy",Istripy);
224 fhBookTree->SetBranchAddress("Qstripy",Qstripy);
225 fhBookTree->SetBranchAddress("Ystripy",Ystripy);
226 fhBookTree->SetBranchAddress("Nthcali",&Nthcali);
227 fhBookTree->SetBranchAddress("Icaplane",Icaplane);
228 fhBookTree->SetBranchAddress("Icastrip",Icastrip);
229 fhBookTree->SetBranchAddress("Icamod",Icamod);
230 fhBookTree->SetBranchAddress("Enestrip",Enestrip);
231 fhBookTree->SetBranchAddress("Nthcal",&Nthcal);
232 fhBookTree->SetBranchAddress("Icapl",Icapl);
233 fhBookTree->SetBranchAddress("Icasi",Icasi);
234 fhBookTree->SetBranchAddress("Icast",Icast);
235 fhBookTree->SetBranchAddress("Xincal",Xincal);
236 fhBookTree->SetBranchAddress("Yincal",Yincal);
237 fhBookTree->SetBranchAddress("Zincal",Zincal);
238 fhBookTree->SetBranchAddress("Erelcal",Erelcal);
239 fhBookTree->SetBranchAddress("Nthnd",&Nthnd);
240 fhBookTree->SetBranchAddress("Itubend",Itubend);
241 fhBookTree->SetBranchAddress("Iparnd",Iparnd);
242 fhBookTree->SetBranchAddress("Xinnd",Xinnd);
243 fhBookTree->SetBranchAddress("Yinnd",Yinnd);
244 fhBookTree->SetBranchAddress("Zinnd",Zinnd);
245 fhBookTree->SetBranchAddress("Xoutnd",Xoutnd);
246 fhBookTree->SetBranchAddress("Youtnd",Youtnd);
247 fhBookTree->SetBranchAddress("Zoutnd",Zoutnd);
248 fhBookTree->SetBranchAddress("Erelnd",Erelnd);
249 fhBookTree->SetBranchAddress("Timend",Timend);
250 fhBookTree->SetBranchAddress("Pathnd",Pathnd);
251 fhBookTree->SetBranchAddress("P0nd",P0nd);
252 fhBookTree->SetBranchAddress("Nthcard",&Nthcard);
253 fhBookTree->SetBranchAddress("Iparcard",Iparcard);
254 fhBookTree->SetBranchAddress("Icard",Icard);
255 fhBookTree->SetBranchAddress("Xincard",Xincard);
256 fhBookTree->SetBranchAddress("Yincard",Yincard);
257 fhBookTree->SetBranchAddress("Zincard",Zincard);
258 fhBookTree->SetBranchAddress("Xoutcard",Xoutcard);
259 fhBookTree->SetBranchAddress("Youtcard",Youtcard);
260 fhBookTree->SetBranchAddress("Zoutcard",Zoutcard);
261 fhBookTree->SetBranchAddress("Erelcard",Erelcard);
262 fhBookTree->SetBranchAddress("Timecard",Timecard);
263 fhBookTree->SetBranchAddress("Pathcard",Pathcard);
264 fhBookTree->SetBranchAddress("P0card",P0card);
265
266 // fhBookTree->SetBranchStatus("*",0);
267
268 }
269
270 ClassImp(GPamela);
271
272 /////////////////////////////////////////////////////////////////////////////
273 /////////////////////////////////////////////////////////////////////////////
274 /////////////////////////////////////////////////////////////////////////////
275 /////////////////////////////////////////////////////////////////////////////
276 //--------------------------------------
277 //
278 //
279 //--------------------------------------
280 /**
281 * Default constructor
282 */
283 PamTrack::PamTrack(){
284 trk_track = 0;
285 calo_track = 0;
286 tof_track = 0;
287 candeleteobj = 0;
288 pscore = 0;
289 iscore = 0;
290 };
291 //--------------------------------------
292 //
293 //
294 //--------------------------------------
295 /**
296 * Constructor
297 */
298 PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o){
299
300 trk_track = 0;
301 calo_track = 0;
302 tof_track = 0;
303 // if(t)trk_track = new TrkTrack(*t);
304 // if(c)calo_track = new CaloTrkVar(*c);
305 // if(o)tof_track = new ToFTrkVar(*o);
306 if(t)trk_track = t;
307 if(c)calo_track = c;
308 if(o)tof_track = o;
309 candeleteobj = 0;
310
311 };
312 PamTrack::PamTrack(const PamTrack& track){
313
314 TrkTrack *t = track.trk_track;
315 CaloTrkVar *c = track.calo_track;
316 ToFTrkVar *o = track.tof_track;
317
318 trk_track = 0;
319 calo_track = 0;
320 tof_track = 0;
321 if(t)trk_track = new TrkTrack(*t);
322 if(c)calo_track = new CaloTrkVar(*c);
323 if(o)tof_track = new ToFTrkVar(*o);
324 candeleteobj = 1;
325
326 }
327 void PamTrack::Clear(){
328
329 // cout << "PamTrack::Clear() "<<candeleteobj<<endl;
330 if(candeleteobj){
331 if(trk_track) trk_track->TrkTrack::Clear();
332 if(calo_track) calo_track->CaloTrkVar::Clear();//???
333 if(tof_track) tof_track->ToFTrkVar::Clear();//???
334 }else{
335 trk_track = 0;
336 calo_track = 0;
337 tof_track = 0;
338 }
339 pscore = 0;
340 iscore = 0;
341
342 }
343 void PamTrack::Delete(){
344 // cout << "PamTrack::Delete() "<<candeleteobj<<endl;
345 if(candeleteobj){
346 if(trk_track) {
347 trk_track->TrkTrack::Clear();
348 delete trk_track;
349 }
350 if(calo_track){
351 calo_track->CaloTrkVar::Clear();//???
352 delete calo_track;
353 }
354 if(tof_track){
355 tof_track->ToFTrkVar::Clear();//???
356 delete tof_track;
357 }
358 }else{
359 Clear();
360 }
361 }
362 //--------------------------------------
363 //
364 //
365 //--------------------------------------
366 /**
367 * Default Constructor
368 */
369 PamLevel2::PamLevel2(){
370 Initialize();
371 };
372
373 /**
374 * Constructor
375 * @param ddir Name of directory where level2 files are stored.
376 * @param list Name of an ascii file containing the list of file names
377 * @param detlist Options to chose what to load.
378 * Possible options are:
379 * +AUTO --> load all trees/branches in the input files
380 * +(-)ALL --> inlcude(exclude) all trees/branches
381 * +(-)TRK1+(-)TRK2+(-)CAL1+(-)CAL2+(-)TOF+(-)TRG+(-)ND+(-)S4+(-)ORB+(-)AC --> inlcude(exclude) trees and branches
382 * +(-)TRK0 --> include(exclude) tracker level0 tree
383 * +(-)GP --> include exclude GPAMELA output tree
384 * If no options are specified, the default is assumed. Default is:
385 * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
386 */
387 PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){
388 Initialize();
389 TList* listf = GetListOfLevel2Files(ddir,list);
390 GetPamTree(listf,detlist);
391 GetRunTree(listf);
392 };
393
394 /**
395 * Constructor
396 * @param ddir Name of directory where level2 files are stored.
397 * @param list Name of an ascii file containing the list of file names
398 * Default trees/branches are loaded. Default is:
399 * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
400 */
401 PamLevel2::PamLevel2(TString ddir,TString list){
402 Initialize();
403 TList* listf = GetListOfLevel2Files(ddir,list);
404 GetPamTree(listf,"");
405 GetRunTree(listf);
406 };
407
408
409 void PamLevel2::Initialize(){
410
411 h0_obj = 0;
412 trk0_obj = 0;
413 calo0_obj = 0;
414
415 trk2_obj = 0;
416 trk1_obj = 0;
417 trkh_obj = 0;
418 calo1_obj = 0;
419 calo2_obj = 0;
420 tof_obj = 0;
421 trig_obj = 0;
422 s4_obj = 0;
423 nd_obj = 0;
424 ac_obj = 0;
425 orb_obj = 0;
426 gp_obj = 0;
427
428 run_obj = 0;//new GL_RUN();
429 soft_obj = 0;// Emiliano
430 irun = -1LL;
431 irunt = -1LL;
432 runfirstentry = 0LL;
433 runlastentry = 0LL;
434
435 l0_file = NULL;
436 l0_tree = NULL;
437 iroot = -1;
438 dbc = 0;
439
440 prevshift = 0;
441 maxshift = 10; //EMILIANO
442
443 run_tree = NULL;
444 run_tree_clone = NULL;
445 sel_tree = NULL;
446 sel_tree_clone = NULL;
447
448 irunentry = -1LL;
449 pam_tree = NULL;
450 for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;
451
452 totdltime[0] = 0LL;
453 totdltime[1] = 0LL;
454 totdltime[2] = 0LL;
455
456 host = "mysql://localhost/pamelaprod";
457 user = "anonymous";
458 psw = "";
459 const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
460 const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
461 const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
462 if ( !pamdbhost ) pamdbhost = "";
463 if ( !pamdbuser ) pamdbuser = "";
464 if ( !pamdbpsw ) pamdbpsw = "";
465 if ( strcmp(pamdbhost,"") ) host = pamdbhost;
466 if ( strcmp(pamdbuser,"") ) user = pamdbuser;
467 if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
468
469
470
471 // sorted_tracks = 0;//new TRefArray();
472
473 CAL0 = false;
474 CAL1 = true;
475 CAL2 = true;
476 TRK2 = true;
477 TRK1 = false;
478 TRK0 = false;
479 TRKh = false;
480 TRG = true;
481 TOF = true;
482 TOF0 = false;
483 S4 = true;
484 ND = true;
485 AC = true;
486 ORB = true;
487 GP = false;
488
489 RUN = true;
490
491 SELLI = -1;
492
493 ISGP = false;
494
495 DBG = false;
496
497 tsorted=0;
498 timage=0;
499
500 howtosort = "+CAL+TOF";
501 //howtosort = "+TOF";
502 sortthr = 100.;
503
504 };
505 /**
506 * Delete the event (act as Dtor)
507 */
508 void PamLevel2::Delete(){
509
510 if(run_obj)delete run_obj;
511 if(soft_obj)delete soft_obj; //Emiliano
512
513 // cout << "void PamLevel2::Clear()"<<endl;
514 if(h0_obj) delete h0_obj;
515 if(trk0_obj) delete trk0_obj;
516 if(calo0_obj) delete calo0_obj;
517 if(trk1_obj) delete trk1_obj;
518 if(trk2_obj) delete trk2_obj;
519 if(trkh_obj) delete trkh_obj;
520 if(calo1_obj)delete calo1_obj;
521 if(calo2_obj)delete calo2_obj;
522 if(tof_obj) delete tof_obj;
523 if(trig_obj) delete trig_obj;
524 if(s4_obj) delete s4_obj;
525 if(nd_obj) delete nd_obj;
526 if(ac_obj) delete ac_obj;
527 if(orb_obj) delete orb_obj;
528 if(gp_obj) delete gp_obj;
529
530 if(tsorted){
531 tsorted->Delete();
532 delete tsorted;
533 }
534 if(timage){
535 timage->Delete();
536 delete timage;
537 }
538
539 if(dbc){
540 dbc->Close();
541 delete dbc;
542 }
543
544 if(l0_file)l0_file->Close();
545 // if(pam_tree)pam_tree->Delete();;
546
547 if ( pam_tree ){
548 //
549 // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault...
550 //
551 TList *temp = pam_tree->GetListOfFriends();
552 TList *contents = new TList; // create chain friend list
553 contents->SetOwner();
554 TIter next(temp);
555 TChain *questo = 0;
556 while ( (questo = (TChain*) next()) ){
557 TString name = questo->GetName();
558 contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
559 };
560 //
561 // deleting the main chain
562 //
563 pam_tree->Delete();
564 //
565 // deleting the friends...
566 //
567 TIter next2(contents);
568 TChain *questa = 0;
569 while ( questa = (TChain*)next2() ){
570 TString name = questa->GetName();
571 questa->Delete();
572 questa=NULL;
573 };
574 //
575 };
576 pam_tree = NULL;
577
578 if(run_tree)run_tree->Delete();;
579 if(sel_tree)sel_tree->Delete();;
580 for(Int_t i=0; i<NCLONES; i++ )if(pam_tree_clone[i])pam_tree_clone[i]->Delete();;
581 if(run_tree_clone)run_tree_clone->Delete();;
582 if(sel_tree_clone)sel_tree_clone->Delete();;
583
584 if(irunoffset) delete [] irunoffset;
585
586 };
587
588 /**
589 * Clear the event (NB! does not deallocate objects)
590 */
591 void PamLevel2::Clear(){
592
593 // cout << "void PamLevel2::Clear()"<<endl;
594
595 //
596 // This method is called once for every entry but RunInfo and SoftInfo do not change until the next run so we cannot clear them here unless we don't
597 // want to load them for each event even if they are the same...
598 //
599 // if(run_obj)delete run_obj;
600 // if(run_obj) run_obj->Clear(); // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead
601 // if(soft_obj) soft_obj->Clear();
602
603 if(h0_obj) h0_obj->Clear();
604 // if(trk0_obj) trk0_obj->Clear();
605 if(trk1_obj) trk1_obj->Clear();
606 if(trk2_obj) trk2_obj->Clear();
607 if(trkh_obj) trkh_obj->Clear();
608 if(calo0_obj) calo0_obj->Clear();
609 if(calo1_obj)calo1_obj->Clear();
610 if(calo2_obj)calo2_obj->Clear();
611 if(tof_obj) tof_obj->Clear();
612 if(trig_obj) trig_obj->Clear();
613 if(s4_obj) s4_obj->Clear();
614 if(nd_obj) nd_obj->Clear();
615 if(ac_obj) ac_obj->Clear();
616 if(orb_obj) orb_obj->Clear();
617 if(gp_obj) gp_obj->Clear();
618
619 // if(sorted_tracks)sorted_tracks->Clear();
620 // sorted_tracks.Clear();
621
622 if(tsorted){
623 tsorted->Delete();
624 }
625 if(timage){
626 timage->Delete();
627 }
628 };
629
630 void PamLevel2::Reset(){
631 //
632 // First of all clear everything
633 //
634 Clear();
635 //
636 // close and reset chains and pointers
637 //
638 if ( pam_tree ){
639 //
640 // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault...
641 //
642 TList *temp = pam_tree->GetListOfFriends();
643 TList *contents = new TList; // create chain friend list
644 contents->SetOwner();
645 TIter next(temp);
646 TChain *questo = 0;
647 while ( (questo = (TChain*) next()) ){
648 TString name = questo->GetName();
649 contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
650 };
651 //
652 // deleting the main chain
653 //
654 pam_tree->Delete();
655 //
656 // deleting the friends...
657 //
658 TIter next2(contents);
659 TChain *questa = 0;
660 while ( questa = (TChain*)next2() ){
661 TString name = questa->GetName();
662 questa->Delete();
663 questa=NULL;
664 };
665 //
666 };
667 pam_tree = NULL;
668 //
669 if(run_tree)run_tree->Delete();;
670 run_tree = NULL;
671 if(sel_tree)sel_tree->Delete();;
672 sel_tree = NULL;
673 //
674 // Close file
675 //
676 if(l0_file)l0_file->Close("R");
677 l0_file = NULL;
678 //
679 h0_obj = 0;
680 trk0_obj = 0;
681 calo0_obj = 0;
682 //
683 trk2_obj = 0;
684 trk1_obj = 0;
685 trkh_obj = 0;
686 calo1_obj = 0;
687 calo2_obj = 0;
688 tof_obj = 0;
689 trig_obj = 0;
690 s4_obj = 0;
691 nd_obj = 0;
692 ac_obj = 0;
693 orb_obj = 0;
694 gp_obj = 0;
695 //
696 // Reset run pointers
697 //
698 run_obj = 0;//new GL_RUN();
699 soft_obj = 0;// Emiliano
700 irun = -1;
701 irunt = -1;
702 runfirstentry = 0ULL;
703 runlastentry = 0ULL;
704 //
705 totdltime[0] = 0LL;
706 totdltime[1] = 0LL;
707 totdltime[2] = 0LL;
708 //
709 };
710
711 Bool_t PamLevel2::IsGood(){
712 Bool_t goodev=true;
713 // if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;
714 if(calo2_obj && calo2_obj->good != 1) goodev = false;
715 if(tof_obj && tof_obj->unpackError != 0) goodev = false;
716 if(trig_obj && trig_obj->unpackError != 0) goodev = false;
717 if(s4_obj && s4_obj->unpackError != 0) goodev = false;
718 if(nd_obj && nd_obj->unpackError != 0) goodev = false;
719 if(ac_obj && ac_obj->unpackError != 255) goodev = false;
720 // if(orb_obj)
721 return goodev;
722 };
723
724 //--------------------------------------
725 //
726 //
727 //--------------------------------------
728 void *PamLevel2::GetPointerTo(const char* c ){
729
730 TString objname = c;
731
732 if(!objname.CompareTo("TrkLevel1")) {
733 if(!trk1_obj){
734 trk1_obj = new TrkLevel1();
735 trk1_obj->Set();
736 }
737 return &trk1_obj;
738 };
739 if(!objname.CompareTo("TrkLevel2")) {
740 if(!trk2_obj){
741 trk2_obj = new TrkLevel2();
742 trk2_obj->Set();
743 }
744 return &trk2_obj;
745 };
746 if(!objname.CompareTo("TrkHough")) {
747 if(!trkh_obj) trkh_obj = new TrkHough();
748 return &trkh_obj;
749 };
750 if(!objname.CompareTo("CaloLevel1")) {
751 if(!calo1_obj) calo1_obj = new CaloLevel1();
752 return &calo1_obj;
753 };
754 if(!objname.CompareTo("CaloLevel2")) {
755 if(!calo2_obj){
756 calo2_obj = new CaloLevel2();
757 calo2_obj->Set();
758 };
759 return &calo2_obj;
760 };
761 if(!objname.CompareTo("ToFLevel2")) {
762 if(!tof_obj){
763 tof_obj = new ToFLevel2();
764 tof_obj->Set();
765 }
766 return &tof_obj;
767 };
768 if(!objname.CompareTo("TrigLevel2")) {
769 if(!trig_obj) trig_obj = new TrigLevel2();
770 return &trig_obj;
771 };
772 if(!objname.CompareTo("S4Level2")) {
773 if(!s4_obj) s4_obj = new S4Level2();
774 return &s4_obj;
775 };
776 if(!objname.CompareTo("NDLevel2")) {
777 if(!nd_obj) nd_obj = new NDLevel2();
778 return &nd_obj;
779 };
780 if(!objname.CompareTo("AcLevel2")) {
781 if(!ac_obj) ac_obj = new AcLevel2();
782 return &ac_obj;
783 };
784 if(!objname.CompareTo("OrbitalInfo")){
785 if(!orb_obj) orb_obj = new OrbitalInfo();
786 return &orb_obj;
787 };
788 if(!objname.CompareTo("GPamela")){
789 if(!gp_obj) gp_obj = new GPamela();
790 return &gp_obj;
791 };
792
793 if(!objname.CompareTo("RunInfo"))return &run_obj;
794
795 if(!objname.CompareTo("SoftInfo"))return &soft_obj; // Emiliano
796
797 return NULL;
798 };
799 //--------------------------------------
800 //
801 //
802 //--------------------------------------
803 /**
804 * Retrieves the calorimeter track matching the seqno-th tracker stored track.
805 * (If seqno = -1 retrieves the self-trigger calorimeter track)
806 */
807 CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
808
809 if( !calo2_obj )return 0;
810
811 if( calo2_obj->CaloLevel2::ntrk()==0 ){
812 cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;
813 return NULL;
814 };
815
816 CaloTrkVar *c = 0;
817 Int_t it_calo=0;
818
819 do{
820 c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
821 it_calo++;
822 } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());
823
824 if(!c || seqno != c->trkseqno){
825 c = 0;
826 if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;
827 };
828 return c;
829
830 };
831 //--------------------------------------
832 //
833 //
834 //--------------------------------------
835 /**
836 * Retrieves the ToF track matching the seqno-th tracker stored track.
837 * (If seqno = -1 retrieves the tracker-independent tof track)
838 */
839 ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
840
841 if( !tof_obj )return 0;
842
843 if( tof_obj->ToFLevel2::ntrk()==0 ){
844 cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;
845 return NULL;
846 };
847
848 ToFTrkVar *c = 0;
849 Int_t it_tof=0;
850
851 do{
852 c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);
853 it_tof++;
854 } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());
855
856 if(!c || seqno != c->trkseqno){
857 c = 0;
858 if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;
859 };
860 return c;
861
862 };
863
864 //--------------------------------------
865 //
866 //
867 //--------------------------------------
868 /**
869 * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.
870 */
871 PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
872
873 cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;
874 cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
875
876 CaloTrkVar *c = 0;
877 ToFTrkVar *o = 0;
878
879 if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());
880 if(TOF) o = GetToFStoredTrack(t->GetSeqNo());
881
882 // if(t && c && o)track = new PamTrack(t,c,o);
883 PamTrack *track = new PamTrack(t,c,o);
884
885 return track;
886
887 };
888 //--------------------------------------
889 //
890 //
891 //--------------------------------------
892 /**
893 * Retrieves the it-th stored track.
894 * It override TrkLevel2::GetTrack(int it).
895 * @param itrk Track number, ranging from 0 to GetNTracks().
896 */
897
898 PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
899
900 cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;
901 cout <<"for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack)"<<endl;
902 cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
903 PamTrack *track = 0;
904
905 if( itrk >=0 && itrk < trk2_obj->TrkLevel2::ntrk() ){
906
907 TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk);
908 track = GetPamTrackAlong(t);
909
910
911
912 }else{
913 cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
914 };
915
916 return track;
917
918 }
919 //--------------------------------------
920 //
921
922 /**
923 * Sort physical (tracker) tracks. Left here as backward compatibility method.
924 **/
925 void PamLevel2::SortTracks(TString how){
926 printf(" WARNING! obsolete, use SortTracks() and SetSortingMethod(TString) instead! \n Setting sorting method to %s \n",how.Data());
927 howtosort = how;
928 SortTracks();
929 };
930
931 //
932 //--------------------------------------
933 /**
934 * Sort physical (tracker) tracks.
935 * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...).
936 * Sorting cryteria:
937 * TRK: lower chi**2
938 * CAL: lower Y spatial residual on the first calorimeter plane
939 * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis).
940 * S1: (ask Emiliano)
941 * S2: (ask Emiliano)
942 * S3: (ask Emiliano)
943 * GP: more GP hits
944 * The default sorting cryterium is "TOF+CAL".
945 *
946 * The total number of physical tracks is always given by GetNTracks() and the it-th physical track can be retrieved by means of the methods GetTrack(int it) and GetTrack(int it, TString how).
947 */
948 void PamLevel2::SortTracks(){
949 TString how = howtosort;
950
951 // cout <<" PamLevel2::SortTracks(TString how) "<<endl;
952 if( !trk2_obj ){
953 cout << "void PamLevel2::SortTracks(): TrkLevel2 not loaded !!!";
954 return;
955 };
956 //Save current Object count
957 Int_t ObjectNumber = TProcessID::GetObjectCount();
958
959 // create TCloneArrays to store tracks and its images
960 if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
961 tsorted->Delete();
962 TClonesArray &ttsorted = *tsorted;
963
964 if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
965 timage->Delete();
966 TClonesArray &ttimage = *timage;
967
968
969
970 //--------------------------------------------------
971 // retrieve sorting method
972 //--------------------------------------------------
973 Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
974 Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
975 Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
976 Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
977 Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
978 Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
979 Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
980
981 if ( use_TOF ){
982 use_S1 = true;
983 use_S2 = true;
984 use_S3 = true;
985 };
986 if( !CAL2 && use_CAL) use_CAL = false;
987 if( !TOF ){
988 use_TOF = false;
989 use_S1 = false;
990 use_S2 = false;
991 use_S3 = false;
992 }
993 if( !GP ){
994 use_GP = false;
995 }
996
997 if( !TRK2 ){
998 cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
999 return;
1000 };
1001
1002 // cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
1003
1004
1005 //--------------------------------------------------
1006 // loop over "physical" tracks sorted by the tracker
1007 //--------------------------------------------------
1008 for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
1009
1010 TrkTrack *ts = 0;
1011 CaloTrkVar *cs = 0;
1012 ToFTrkVar *os = 0;
1013
1014 // get tracker tracks
1015 TrkTrack *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
1016 CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
1017 ToFTrkVar *op = GetToFStoredTrack(tp->GetSeqNo());
1018
1019 TrkTrack *ti = 0; //tracker (image)
1020 CaloTrkVar *ci = 0;
1021 ToFTrkVar *oi = 0;
1022 // cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
1023 // if track has an image, check image selection
1024
1025 Int_t tp_score = 0; //main track sorted by the tracker
1026 Int_t ti_score = 0; //image track
1027 Int_t totp_score = 0; //main track sorted by the tracker
1028 Int_t toti_score = 0; //image track
1029
1030 if(tp->HasImage()){
1031
1032 ti = trk2_obj->TrkLevel2::GetTrackImage(i); //tracker (image)
1033 ci = GetCaloStoredTrack(ti->GetSeqNo());
1034 oi = GetToFStoredTrack(ti->GetSeqNo());
1035
1036 // cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
1037
1038 //assign starting scores
1039 tp_score = 0; //main track sorted by the tracker
1040 ti_score = 0; //image track
1041
1042 // -----------------------------------------------------------------------------------------
1043 // *****************************************************************************************
1044 // -----------------------------------------------------------------------------------------
1045 // calorimeter check
1046 // -----------------------------------------------------------------------------------------
1047 if( use_CAL && !calo2_obj ){
1048 cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";
1049 return;
1050 };
1051 if( use_CAL && !cp && ci ){
1052 ti_score++;
1053 toti_score++;
1054 };
1055 if( use_CAL && cp && !ci ){
1056 tp_score++;
1057 totp_score++;
1058 };
1059 if(
1060 use_CAL &&
1061 cp && ci &&
1062 true){
1063
1064
1065 if(
1066 cp->npresh > ci->npresh &&
1067 true){
1068 tp_score++;
1069 totp_score++;
1070 };
1071 if(
1072 cp->npresh < ci->npresh &&
1073 true){
1074 ti_score++;
1075 toti_score++;
1076 };
1077
1078 // cout << "CALO "<<tp_score<<ti_score<<endl;
1079
1080 };
1081 // -----------------------------------------------------------------------------------------
1082 // *****************************************************************************************
1083 // -----------------------------------------------------------------------------------------
1084 // TOF check
1085 // -----------------------------------------------------------------------------------------
1086 // check the number of hit pmts along the track
1087 // on S12 S21 and S32, where paddles are parallel to Y axis
1088 if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !tof_obj ){
1089 cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";
1090 return;
1091 };
1092 //
1093 if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !op && oi ){
1094 ti_score++;
1095 toti_score++;
1096 };
1097 if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && !oi ){
1098 tp_score++;
1099 totp_score++;
1100 };
1101 if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && oi ){
1102 //
1103 Float_t sen = 0.;
1104 for (Int_t ih=0; ih < op->npmtadc; ih++){
1105 Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1106 if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih);
1107 };
1108 for (Int_t ih=0; ih < oi->npmtadc; ih++){
1109 Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1110 if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);
1111 };
1112 //
1113 if ( sen >= sortthr && false){ // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
1114 //printf(" IS A NUCLEUS! en = %f \n",sen);
1115 //
1116 // is a nucleus use a different algorithm
1117 //
1118 Int_t nz = 6; Float_t zin[6]; // << define TOF z-coordinates
1119 for(Int_t ip=0; ip<nz; ip++)
1120 zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip)); // << read ToF plane z-coordinates
1121 Trajectory *tr = new Trajectory(nz,zin);
1122 //
1123 Int_t nphit_p =0;
1124 Int_t nphit_i =0;
1125 Float_t enhit_p = 0.;
1126 Float_t enhit_i = 0.;
1127 //
1128 for (Int_t ih=0; ih < op->npmtadc; ih++){
1129 Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1130 if(pl == 1 || pl == 2 || pl == 5){
1131 nphit_p++;
1132 enhit_p += (op->dedx).At(ih);
1133 };
1134 };
1135 //
1136 tp->DoTrack2(tr);
1137 //
1138 if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1139 for (Int_t ih=0; ih < op->npmtadc; ih++){
1140 Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1141 if(pl == 0){
1142 nphit_p++;
1143 enhit_p += (op->dedx).At(ih);
1144 };
1145 };
1146 };
1147 if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1148 for (Int_t ih=0; ih < op->npmtadc; ih++){
1149 Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1150 if(pl == 3){
1151 nphit_p++;
1152 enhit_p += (op->dedx).At(ih);
1153 };
1154 };
1155 };
1156 if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1157 for (Int_t ih=0; ih < op->npmtadc; ih++){
1158 Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1159 if(pl == 4){
1160 nphit_p++;
1161 enhit_p += (op->dedx).At(ih);
1162 };
1163 };
1164 };
1165
1166 for (Int_t ih=0; ih < oi->npmtadc; ih++){
1167 Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1168 if(pl == 1 || pl == 2 || pl == 5){
1169 nphit_i++;
1170 enhit_i += (op->dedx).At(ih);
1171 };
1172 };
1173 //
1174 ti->DoTrack2(tr);
1175 //
1176 if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1177 for (Int_t ih=0; ih < oi->npmtadc; ih++){
1178 Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1179 if(pl == 0){
1180 nphit_i++;
1181 enhit_i += (op->dedx).At(ih);
1182 };
1183 };
1184 };
1185 if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1186 for (Int_t ih=0; ih < oi->npmtadc; ih++){
1187 Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1188 if(pl == 3){
1189 nphit_i++;
1190 enhit_i += (op->dedx).At(ih);
1191 };
1192 };
1193 };
1194 if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1195 for (Int_t ih=0; ih < oi->npmtadc; ih++){
1196 Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1197 if(pl == 4){
1198 nphit_i++;
1199 enhit_i += (op->dedx).At(ih);
1200 };
1201 };
1202 };
1203
1204
1205 if(
1206 (use_TOF || use_S1 || use_S2 || use_S3) &&
1207 (nphit_p+nphit_i) !=0 &&
1208 true){
1209
1210 // printf(" seqno %i nphit_p %i nphit_i %i enhit_p %f enhit_i %f \n",trk2_obj->TrkLevel2::GetSeqNo(i),nphit_p,nphit_i,enhit_p,enhit_i);
1211 // printf(" score p %i score i %i \n",tp_score,ti_score);
1212 // if( enhit_p > enhit_i ) tp_score++;
1213 // if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
1214 if ( nphit_p > nphit_i ) tp_score++;
1215 if ( nphit_p < nphit_i ) ti_score++;
1216 if ( nphit_p == nphit_i ){
1217 if ( enhit_p > enhit_i ) tp_score++;
1218 else ti_score++;
1219 };
1220 // printf(" dopo score p %i score i %i \n",tp_score,ti_score);
1221 };
1222 delete tr;
1223 //
1224 } else {
1225 // -------------
1226 // NOT a NUCLEUS
1227 // -------------
1228 //printf(" NOT a NUCLEUS! en = %f \n",sen);
1229
1230 Int_t nphit_p =0;
1231 Int_t nphit_i =0;
1232
1233
1234 /* cout << "track: npmtadc "<< op->npmtadc << endl;
1235 cout << "track: npmttdc "<< op->npmttdc << endl;
1236 cout << "image: npmtadc "<< oi->npmtadc << endl;
1237 cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1238
1239 // for (Int_t ih=0; ih < op->npmtadc; ih++){
1240 // Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1241 // if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
1242 // };
1243
1244 // for (Int_t ih=0; ih < oi->npmtadc; ih++){
1245 // Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1246 // if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1247 // };
1248 // --- modified to count tdc signals (more efficient?)
1249 // --- and to implement check on tdcflag
1250 for (Int_t ih=0; ih < op->npmttdc; ih++){
1251 Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );
1252 // if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
1253 if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){
1254 if( (op->tdcflag).At(ih)==0 )nphit_p++;
1255 };
1256 };
1257
1258 for (Int_t ih=0; ih < oi->npmttdc; ih++){
1259 Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );
1260 // if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;
1261 if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){
1262 if( (oi->tdcflag).At(ih)==0 )nphit_i++;
1263 };
1264 };
1265
1266 if(
1267 (nphit_p+nphit_i) !=0 &&
1268 true){
1269
1270 if ( nphit_p != nphit_i ){
1271 totp_score += nphit_p;
1272 toti_score += nphit_i;
1273 tp_score+=nphit_p;
1274 ti_score+=nphit_i;
1275 };
1276 // if ( nphit_p > nphit_i) tp_score+=nphit_p;
1277 // else if( nphit_p < nphit_i) ti_score+=nphit_i;
1278 // else ;//niente
1279 };
1280 };
1281 // cout << "TOF "<<tp_score<<ti_score<<endl;
1282 };
1283
1284
1285 // if(tp_score == ti_score) use_TRK = true;
1286
1287
1288 // -----------------------------------------------------------------------------------------
1289 // *****************************************************************************************
1290 // -----------------------------------------------------------------------------------------
1291 // tracker check
1292 // -----------------------------------------------------------------------------------------
1293 // chi**2 difference is not always large enough to distinguish among
1294 // the real track and its image.
1295 // Tracker check will be applied always when calorimeter and tof information is ambiguous.
1296 // *** MODIFIED ON AUGUST 2007 ***
1297 if(use_TRK){
1298 // if( tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
1299 // else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
1300
1301 // CHECK 1 : number of points along X
1302 if ( tp->GetNX() >= ti->GetNX() ){
1303 tp_score++ ;
1304 totp_score++ ;
1305 };
1306 if ( tp->GetNX() <= ti->GetNX() ){
1307 ti_score++ ;
1308 toti_score++ ;
1309 };
1310 // CHECK 2 : number of points along Y
1311 if ( tp->GetNY() >= ti->GetNY() ){
1312 tp_score++ ;
1313 totp_score++ ;
1314 };
1315 if ( tp->GetNY() <= ti->GetNY() ){
1316 ti_score++ ;
1317 toti_score++ ;
1318 };
1319
1320 // cout << "TRK "<<tp_score<<ti_score<<endl;
1321 };
1322
1323
1324 // -----------------------------------------------------------------------------------------
1325 // *****************************************************************************************
1326 // -----------------------------------------------------------------------------------------
1327 // GPamela check
1328 // -----------------------------------------------------------------------------------------
1329
1330 //---------------------------------------------------
1331 // count the number of GP hits
1332 //---------------------------------------------------
1333 if(use_GP){
1334 int ngphits_p=0;
1335 int ngphits_i=0;
1336 float toll = 0.02; //200 micron
1337 for(int ih=0; ih<GetGPamela()->Nthspe; ih++){
1338 int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
1339 if(
1340 tp &&
1341 tp->YGood(ip) &&
1342 fabs(tp->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1343 true) ngphits_p++;
1344 if( ti &&
1345 ti->YGood(ip) &&
1346 fabs(ti->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1347 true) ngphits_i++;
1348 }
1349 if(
1350 ngphits_p > ngphits_i &&
1351 true){
1352 tp_score++ ;
1353 totp_score++ ;
1354 }
1355 if(
1356 ngphits_p < ngphits_i &&
1357 true){
1358 ti_score++ ;
1359 toti_score++ ;
1360 }
1361 }
1362
1363
1364 // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1365 // the winner is....
1366 // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1367 if (tp_score > ti_score) {
1368
1369
1370 }else if (tp_score < ti_score) {
1371
1372
1373 ts = ti;//its image!!
1374 cs = ci;
1375 os = oi;
1376 Int_t totis = toti_score;
1377
1378 ti = tp;//its image!!
1379 ci = cp;
1380 oi = op;
1381
1382 tp = ts;//its image!!
1383 cp = cs;
1384 op = os;
1385
1386 toti_score = totp_score;
1387 totp_score = totis;
1388
1389
1390 }else {
1391
1392 // cout << "Warning - track image ambiguity not solved" << endl;
1393
1394 };
1395
1396 }else{
1397 totp_score = 1;
1398 toti_score = 0;
1399
1400 // ts = tp;
1401 // cs = cp;
1402 // os = op;
1403 };
1404
1405 // cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
1406 // sorted_tracks->Add(ts);//save the track in the sorted array
1407 // sorted_tracks.Add(ts);//save the track in the sorted array
1408 // sorted_tracks.Add(tp);//save the track in the sorted array
1409 // cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
1410 // cout<<"o "<<tp<<endl;
1411 // cout<<"o "<<cp<<endl;
1412 // cout<<"o "<<op<<endl;
1413
1414 new(ttsorted[i]) PamTrack(tp,cp,op);
1415 new(ttimage[i]) PamTrack(ti,ci,oi);
1416
1417 ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);
1418 ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);
1419 ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);
1420 ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);
1421 };
1422
1423 if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
1424 cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;
1425 tsorted->Delete(); tsorted=0;
1426 timage->Delete(); timage=0;
1427 }
1428
1429 //Restore Object count
1430 //To save space in the table keeping track of all referenced objects
1431 //We reset the object count to what it was at the beginning of the event.
1432 TProcessID::SetObjectCount(ObjectNumber);
1433
1434 };
1435 //--------------------------------------
1436 //
1437 //
1438 //--------------------------------------
1439 /**
1440 * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.
1441 * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.
1442 */
1443 // TRefArray *PamLevel2::GetTracks(){
1444
1445 // // *-*-*-*-*-*-*-*-*-*-*-*-*
1446 // SortTracks("+CAL+TOF");
1447 // // *-*-*-*-*-*-*-*-*-*-*-*-*
1448
1449 // // return sorted_tracks;
1450 // return &sorted_tracks;
1451
1452 // };
1453 TClonesArray *PamLevel2::GetTracks(){
1454
1455 // *-*-*-*-*-*-*-*-*-*-*-*-*
1456 SortTracks();
1457 // *-*-*-*-*-*-*-*-*-*-*-*-*
1458
1459 return tsorted;
1460
1461 };
1462 //--------------------------------------
1463 //
1464 //
1465 //--------------------------------------
1466 /**
1467 * Retrieves the it-th Pamela "physical" track.
1468 * It override TrkLevel2::GetTrack(int it).
1469 * @param it Track number, ranging from 0 to GetNTracks().
1470 */
1471 PamTrack *PamLevel2::GetTrack(int it){
1472
1473 // if(!trk2_obj) return 0;
1474
1475 // // *-*-*-*+-*-*-*-*-*-*-*-*-*
1476 // SortTracks("+CAL+TOF");
1477 // // *-*-*-*-*-*-*-*-*-*-*-*-*
1478 // // if(!sorted_tracks)return 0;
1479 // if(sorted_tracks.IsEmpty())return 0;
1480
1481 // PamTrack *track = 0;
1482
1483 // if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() && it<sorted_tracks.GetEntriesFast() ){
1484 // TrkTrack *t = (TrkTrack*)sorted_tracks.At(it);
1485 // track = GetPamTrackAlong(t);
1486 // }else{
1487 // cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
1488 // };
1489
1490 // return track;
1491
1492 // cout << "PamLevel2::GetTrack(int it) "<<endl;
1493 // *-*-*-*-*-*-*-*-*-*-*-*-*
1494 SortTracks();
1495 // *-*-*-*-*-*-*-*-*-*-*-*-*
1496 if(!tsorted)return 0;
1497 if(!tsorted->GetEntries())return 0;
1498
1499 PamTrack *track = 0;
1500
1501 if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks()){
1502 // TrkTrack *t = (TrkTrack*)sorted_tracks.At(it);
1503 // track = GetPamTrackAlong(t);
1504 TClonesArray &t = *(tsorted);
1505 track = (PamTrack*)t[it];
1506
1507 }else{
1508 cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
1509 };
1510
1511 return track;
1512
1513 };
1514
1515 //--------------------------------------
1516 //
1517 //
1518 //--------------------------------------
1519 /**
1520 * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().
1521 * @param it Track number, ranging from 0 to GetNTracks().
1522 */
1523 PamTrack *PamLevel2::GetTrackImage(int it){
1524
1525 // if(!trk2_obj) return 0;
1526
1527 // // *-*-*-*-*-*-*-*-*-*-*-*-*
1528 // SortTracks("+CAL+TOF");
1529 // // *-*-*-*-*-*-*-*-*-*-*-*-*
1530 // // if(!sorted_tracks)return 0;
1531 // if(sorted_tracks.IsEmpty())return 0;
1532
1533 // PamTrack *image = 0;
1534
1535 // if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){
1536 // TrkTrack *temp = (TrkTrack*)sorted_tracks.At(it);
1537 // if( temp->HasImage() ){
1538 // TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());
1539 // image = GetPamTrackAlong(t);
1540 // }else{
1541 // cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
1542 // };
1543 // }else{
1544 // cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
1545 // };
1546
1547 // return image;
1548
1549
1550 // *-*-*-*-*-*-*-*-*-*-*-*-*
1551 SortTracks();
1552 // *-*-*-*-*-*-*-*-*-*-*-*-*
1553 if(!timage)return 0;
1554 if(!timage->GetEntries())return 0;
1555
1556 PamTrack *image = 0;
1557
1558 if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){
1559 TClonesArray &t = *(tsorted);
1560 PamTrack *temp = (PamTrack*)t[it];
1561 if( temp->GetTrkTrack()->HasImage() ){
1562 TClonesArray &t = *(timage);
1563 image = (PamTrack*)t[it];
1564 }else{
1565 // cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
1566 };
1567 }else{
1568 cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
1569 };
1570
1571 return image;
1572 }
1573
1574 //--------------------------------------
1575 //
1576 //
1577 //--------------------------------------
1578 /**
1579 * Get the Pamela detector trees in a single file and make them friends.
1580 * @param f TFile pointer
1581 * @param detlist String to select trees to be included
1582 * @return Pointer to a TTree
1583 */
1584 TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){
1585
1586 if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {
1587 cout << "+AUTO"<<endl;
1588 GetWhichTrees(f);
1589 };
1590 SetWhichTrees(detlist);
1591
1592 if ( pam_tree ){
1593 printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");
1594 return pam_tree;
1595 };
1596 //
1597
1598 cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
1599
1600 // SetWhichTrees(detlist);
1601
1602 TTree *Trout =0;
1603
1604 TString fname = f->GetName();
1605 if(!CheckLevel2File(fname))return NULL;
1606
1607 // UInt_t *found=0;
1608
1609 cout<< "GetPamTree(TFile*,TString): detector list --> ";
1610 if(TRK1)cout<<"TRK1 ";
1611 if(TRK2)cout<<"TRK2 ";
1612 if(TRKh)cout<<"TRKH ";
1613 if(CAL1)cout<<"CAL1 ";
1614 if(CAL2)cout<<"CAL2 ";
1615 if(TOF)cout<<"TOF ";
1616 if(TRG)cout<<"TRG ";
1617 if(AC)cout<<"AC ";
1618 if(ND)cout<<"ND ";
1619 if(S4)cout<<"S4 ";
1620 if(ORB)cout<<"ORB ";
1621 if(GP)cout<<"GP ";
1622 cout << endl;
1623 if(SELLI)cout<<">>> Found selection-list <<<"<<endl;
1624
1625 f->cd();
1626
1627 // Tracker
1628 TTree *T = (TTree*)f->Get("Tracker");
1629 if(T && (TRK2||TRK1||TRKh)) {
1630 if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1631 // else T->SetBranchStatus("TrkLevel2",0,found);
1632 if(TRK2)cout << "Tracker : set branch address TrkLevel2"<<endl;
1633 if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1634 // else T->SetBranchStatus("TrkLevel1",0,found);
1635 if(TRK1)cout << "Tracker : set branch address TrkLevel1"<<endl;
1636 if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1637 // else T->SetBranchStatus("TrkHough",0,found);
1638 if(TRKh)cout << "Tracker : set branch address TrkHough"<<endl;
1639 if(!Trout)Trout=T;
1640 else Trout->AddFriend(T);
1641 }else{
1642 cout << "Tracker : missing tree"<<endl;
1643 };
1644 // Calorimeter
1645 TTree *C = (TTree*)f->Get("Calorimeter");
1646 if(C && (CAL2||CAL1)) {
1647 if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1648 // else C->SetBranchStatus("CaloLevel2",0,found);
1649 if(CAL2)cout << "Calorimeter : set branch address CaloLevel2"<<endl;
1650 if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1651 // else C->SetBranchStatus("CaloLevel1",0,found);
1652 if(CAL1)cout << "Calorimeter : set branch address CaloLevel1"<<endl;
1653 if(!Trout)Trout=C;
1654 else Trout->AddFriend(C);
1655 }else{
1656 cout << "Calorimeter : missing tree"<<endl;
1657 };
1658
1659 // ToF
1660 TTree *O = (TTree*)f->Get("ToF");
1661 if(O && TOF) {
1662 O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
1663 cout << "ToF : set branch address ToFLevel2"<<endl;
1664 if(!Trout)Trout=O;
1665 else Trout->AddFriend(O);
1666 }else{
1667 cout << "ToF : missing tree"<<endl;
1668 };
1669 // Trigger
1670 TTree *R = (TTree*)f->Get("Trigger");
1671 if(R && TRG) {
1672 R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1673 cout << "Trigger : set branch address TrigLevel2"<<endl;
1674 if(!Trout)Trout=R;
1675 else Trout->AddFriend(R);
1676 }else{
1677 cout << "Trigger : missing tree"<<endl;
1678 };
1679 // S4
1680 TTree *S = (TTree*)f->Get("S4");
1681 if(S && S4) {
1682 S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1683 cout << "S4 : set branch address S4Level2"<<endl;
1684 if(!Trout)Trout=S;
1685 else Trout->AddFriend(S);
1686 }else{
1687 cout << "S4 : missing tree"<<endl;
1688 };
1689 // Neutron Detector
1690 TTree *N = (TTree*)f->Get("NeutronD");
1691 if(N && ND) {
1692 N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1693 cout << "NeutronD : set branch address NDLevel2"<<endl;
1694 if(!Trout)Trout=N;
1695 else Trout->AddFriend(N);
1696 }else{
1697 cout << "NeutronD : missing tree"<<endl;
1698 };
1699 // Anticounters
1700 TTree *A = (TTree*)f->Get("Anticounter");
1701 if(A && AC) {
1702 A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1703 cout << "Anticounter : set branch address AcLevel2"<<endl;
1704 if(!Trout)Trout=A;
1705 else Trout->AddFriend(A);
1706 }else{
1707 cout << "Anticounter : missing tree"<<endl;
1708 };
1709 // Orbital Info
1710 TTree *B = (TTree*)f->Get("OrbitalInfo");
1711 if(B && ORB) {
1712 B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1713 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
1714 if(!Trout)Trout=B;
1715 else Trout->AddFriend(B);
1716 }else{
1717 cout << "OrbitalInfo : missing tree"<<endl;
1718 };
1719
1720 // GPamela
1721 TTree *G = (TTree*)f->Get("h20");
1722 if(G && GP) {
1723 if(!gp_obj)gp_obj=new GPamela();
1724 // ------------------------------------
1725 // ATTENZIONE!!!
1726 // non so per quale arcano motivo,
1727 // per l'albero di gpamela il branch address lo devo settare
1728 // DOPO aver fatto friend
1729 // FGRRRVZZZZUTSALKJMSLKJ!!!
1730 // ------------------------------------
1731 // gp_obj->SetBranchAddress(G); //ho dovuto fare in maniera diversa dagli altri
1732 // cout << "h20 : set branch address GPamela "<<endl;
1733 if(!Trout)Trout=G;
1734 else Trout->AddFriend(G);
1735 }else{
1736 // cout << "h20 : missing tree"<<endl;
1737 };
1738
1739
1740 TTree *L = (TTree*)f->Get("SelectionList");
1741 if(L && SELLI==1) {
1742 cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemented!!!!"<<endl;
1743 sel_tree = 0;
1744 }else{
1745 cout << "SelectionList : missing tree"<<endl;
1746 };
1747
1748 cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1749
1750 // ------------------------------------
1751 // ATTENZIONE!!!
1752 // non so per quale arcano motivo,
1753 // per l'albero di gpamela il branch address lo devo settare
1754 // DOPO aver fatto friend
1755 // FGRRRVZZZZUTSALKJMSLKJ!!!
1756 // ------------------------------------
1757 if(G && GP) {
1758 gp_obj->SetBranchAddress(Trout); //ho dovuto fare in maniera diversa dagli altri
1759 cout << "h20 : set branch address GPamela "<<endl;
1760 }else{
1761 cout << "h20 : missing tree"<<endl;
1762 };
1763
1764 pam_tree = (TChain*)Trout;
1765
1766 return Trout;
1767
1768 }
1769 //--------------------------------------
1770 //
1771 //
1772 //--------------------------------------
1773 /**
1774 * Get list of Level2 files.
1775 * @param ddir Level2 data directory.
1776 * @param flisttxt Name of txt file containing file list.
1777 * @return Pointer to a TList of TSystemFiles
1778 * If no input file list is given , all the Level2 files inside the directory are processed.
1779 */
1780 TList* PamLevel2::GetListOfLevel2Files(TString ddir, TString flisttxt = ""){
1781
1782 TString wdir = gSystem->WorkingDirectory();
1783
1784 // if(ddir=="")ddir = wdir;
1785 // TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1786 if ( ddir != ""){
1787 cout << "Level2 data directory : "<< ddir << endl;
1788 } else {
1789 cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory " << endl;
1790 };
1791 TList *contents = new TList; // create output list
1792 contents->SetOwner();
1793
1794 // char *fullpath;
1795 // const char *fullpath;
1796
1797 // if no input file list is given:
1798 if ( flisttxt != "" ){
1799
1800 // if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){
1801 // if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){
1802 // cout <<"File "<<flisttxt<<" not found"<<endl;
1803 // return 0;
1804 // }
1805 // flisttxt = fullpath;
1806 if ( !flisttxt.EndsWith(".root") ){
1807
1808 flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1809
1810 if( !gSystem->ChangeDirectory(ddir) ){
1811 cout << "Cannot change directory : "<<ddir<<endl;
1812 return 0;
1813 }
1814
1815 cout <<"Input file list : " << flisttxt <<endl;
1816 ifstream in;
1817 in.open(flisttxt, ios::in); //open input file list
1818 if(!in.good()){
1819 cout <<" ERROR opening the file "<<endl;
1820 gSystem->ChangeDirectory(wdir); // back to the working directory
1821 return 0;
1822 }
1823 int line=0;
1824 while (1) {
1825 TString file;
1826 in >> file;
1827 if (!in.good()) break;
1828 line++;
1829 // cout <<"(1) " << file << endl;
1830 if(file.IsNull()){
1831 cout << "-- list interrupted at line "<<line <<endl;
1832 break;
1833 }
1834 if(file.Contains("#"))file = file(0,file.First("#"));
1835 // cout <<"(2) " << file << endl;
1836 // if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1837 // if( (fullpath = gSystem->FindFile(ddir,file)) ){
1838 if( file.EndsWith(".root") ){
1839 TString filedir;
1840 if (ddir != ""){
1841 filedir = ddir; // take the input dir
1842 } else {
1843 gSystem->ChangeDirectory(wdir); // back to the working directory
1844 filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir
1845 };
1846 char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));
1847 contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1848 delete fullpath;
1849 }
1850 // }else{
1851 // if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1852 // };
1853 };
1854 in.close();
1855 } else {
1856 if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));
1857 char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1858 contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1859 delete fullpath;
1860 };
1861 }else{
1862
1863 cout << "No input file list given."<<endl;
1864 cout << "Check for existing root files."<<endl;
1865 // cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
1866 if ( ddir == "" ){
1867 ddir = wdir;
1868 cout << "Level2 data directory : "<< ddir << endl;
1869 };
1870
1871 TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1872 TList *temp = datadir->GetListOfFiles();
1873 // temp->Print();
1874 // cout << "*************************************" << endl;
1875
1876 TIter next(temp);
1877 TSystemFile *questo = 0;
1878
1879
1880 while ( (questo = (TSystemFile*) next()) ) {
1881 TString name = questo-> GetName();
1882 if( name.EndsWith(".root") ){
1883 // const char *fullpath = gSystem->FindFile(ddir,name);
1884 // char *fullpath;
1885 // gSystem->IsFileInIncludePath(name,&fullpath);
1886 char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(name));
1887 contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));
1888 delete fullpath;
1889 };
1890 }
1891 delete temp;
1892 delete datadir;
1893
1894 };
1895 gSystem->ChangeDirectory(wdir); // back to the working directory
1896 // cout << endl << "Selected files:" << endl;
1897 // contents->Print();
1898 cout << contents->GetEntries()<<" files \n";
1899 // cout << endl;
1900 // cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;
1901 return contents;
1902 };
1903 //--------------------------------------
1904 //
1905 //
1906 //--------------------------------------
1907 /**
1908 * Get the Pamela detector chains from a list of files and make them friends.
1909 * @param fl Pointer to a TList of TSystemFiles
1910 * @param detlist String to select trees to be included
1911 * @return Pointer to a TChain
1912 */
1913 TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){
1914 //
1915 //
1916 //
1917 if ( pam_tree ){
1918 printf("WARNING: TChain *PamLevel2::GetPamTree(TList *fl, TString detlist) -- pam_tree already exists!\n ");
1919 return pam_tree;
1920 };
1921 //
1922
1923 TChain *Trout =0;
1924
1925 // -------------------------------------------
1926 // set flags to include/exclude trees/branches
1927 // -------------------------------------------
1928 if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {
1929 if( fl->GetEntries()>0 ){
1930 cout << "+AUTO"<<endl;
1931 TFile *fprimo = new TFile( fl->At(0)->GetName() );
1932 GetWhichTrees(fprimo);
1933 fprimo->Close();// AAAAARGGGGGHHHHH!!!!!!! non commentare questa riga, altrimenti si incasina il TChain
1934 fprimo->Delete();
1935 }
1936 };
1937 SetWhichTrees(detlist);
1938
1939
1940 // -------------------------------------------
1941 // build chains
1942 // -------------------------------------------
1943 TChain *T = 0;
1944 TChain *C = 0;
1945 TChain *O = 0;
1946 TChain *R = 0;
1947 TChain *S = 0;
1948 TChain *N = 0;
1949 TChain *A = 0;
1950 TChain *B = 0;
1951 TChain *G = 0;
1952
1953 TChain *L = 0;
1954
1955 if(TRK2||TRK1||TRKh) T = new TChain("Tracker");
1956 if(CAL2||CAL1) C = new TChain("Calorimeter");
1957 if(TOF) O = new TChain("ToF");
1958 if(TRG) R = new TChain("Trigger");
1959 if(S4) S = new TChain("S4");
1960 if(ND) N = new TChain("NeutronD");
1961 if(AC) A = new TChain("Anticounter");
1962 if(ORB) B = new TChain("OrbitalInfo");
1963 if(GP) G = new TChain("h20");
1964 L = new TChain("SelectionList");
1965
1966 // loop over files and create chains
1967 TIter next(fl);
1968 TSystemFile *questo = 0;
1969 while ( (questo = (TSystemFile*) next()) ) {
1970 TString name = questo->GetName();
1971 cout << "File: "<< name << endl;
1972 if( CheckLevel2File(name) ){
1973 if(TRK2||TRK1||TRKh) T->Add(name);
1974 if(CAL1||CAL2) C->Add(name);
1975 if(TOF) O->Add(name);
1976 if(TRG) R->Add(name);
1977 if(S4) S->Add(name);
1978 if(ND) N->Add(name);
1979 if(AC) A->Add(name);
1980 if(ORB) B->Add(name);
1981 if(GP) G->Add(name);
1982 if(SELLI==1) L->Add(name);
1983 };
1984 };
1985
1986 cout << "done chains\n";
1987 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1988
1989
1990 // -------------------------------------------
1991 // make friends
1992 // -------------------------------------------
1993
1994 // Tracker
1995 cout << "Friends: "<<endl;
1996 if(T && (TRK2||TRK1||TRKh)) {
1997 if(!Trout)Trout=T;
1998 else Trout->AddFriend("Tracker");
1999 // cout << "+Tacker"<<endl;
2000 };
2001 // Calorimeter
2002 if(C && (CAL2||CAL1)) {
2003 if(!Trout)Trout=C;
2004 else Trout->AddFriend("Calorimeter");
2005 // cout << "+Calorimeter"<<endl;
2006 };
2007 // ToF
2008 if(O && TOF) {
2009 if(!Trout)Trout=O;
2010 else Trout->AddFriend("ToF");
2011 // cout << "+ToF"<<endl;
2012 };
2013 // Trigger
2014 if(R && TRG) {
2015 if(!Trout)Trout=O;
2016 else Trout->AddFriend("Trigger");
2017 // cout << "+Trigger"<<endl;
2018 };
2019 // S4
2020 if(S && S4) {
2021 if(!Trout)Trout=O;
2022 else Trout->AddFriend("S4");
2023 // cout << "+S4"<<endl;
2024 };
2025 // Neutron Detector
2026 if(N && ND) {
2027 if(!Trout)Trout=O;
2028 else Trout->AddFriend("NeutronD");
2029 // cout << "+NeutronD"<<endl;
2030 };
2031 // Anticounters
2032 if(A && AC) {
2033 if(!Trout)Trout=O;
2034 else Trout->AddFriend("Anticounter");
2035 // cout << "+Anticounter"<<endl;
2036 };
2037 // Orbital Info
2038 if(B && ORB) {
2039 if(!Trout)Trout=O;
2040 else Trout->AddFriend("OrbitalInfo");
2041 // cout << "+OrbitalInfo"<<endl;
2042 };
2043 // GPamela
2044 if(G && GP) {
2045 if(!Trout)Trout=G;
2046 else Trout->AddFriend("h20");
2047 // cout << "+h20"<<endl;
2048 };
2049
2050 // =====================================
2051 // SET BRANCH-ADDRESS AFTER CHAIN+FRIEND
2052 // =====================================
2053 SetBranchAddress(Trout);
2054
2055
2056 // ------------------------------------
2057 // finally handle selection trees...
2058 // (it is not friend of pamela tree)
2059 // ------------------------------------
2060
2061 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2062
2063 // Selection List
2064 if(L && SELLI==1) {
2065 cout<<">>> Found selection-list <<<"<<endl;
2066 // L->SetBranchAddress("RunEntry",&irun);
2067 L->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2068 cout << "SelectionList: set branch address RunEntry"<<endl;
2069 L->SetBranchAddress("EventEntry",&irunentry);
2070 cout << "SelectionList: set branch address EventEntry"<<endl;
2071 sel_tree = L;
2072 // if(!Trout)Trout=O;
2073 // else Trout->AddFriend("SelectionList");
2074 cout << "+SelectionList"<<endl;
2075 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2076 }else{
2077 // cout << "SelectionList : missing tree"<<endl;
2078 if(L)L->Delete();
2079 };
2080
2081 // --------------------------------------------
2082 // return the pamela chain with all the friends
2083 // --------------------------------------------
2084
2085 pam_tree = Trout;
2086
2087 return Trout;
2088 }
2089
2090
2091
2092 //--------------------------------------
2093 //
2094 //
2095 //--------------------------------------
2096 /**
2097 * Set branch addresses for Pamela friend trees
2098 */
2099 void PamLevel2::SetBranchAddress(TTree *t){
2100
2101 TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
2102 TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
2103 TRKh = TRKh & t->GetBranchStatus("TrkHough");
2104 CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
2105 CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
2106 TOF = TOF & t->GetBranchStatus("ToFLevel2");
2107 TRG = TRG & t->GetBranchStatus("TrigLevel2");
2108 S4 = S4 & t->GetBranchStatus("S4Level2");
2109 ND = ND & t->GetBranchStatus("NDLevel2");
2110 AC = AC & t->GetBranchStatus("AcLevel2");
2111 ORB = ORB & t->GetBranchStatus("OrbitalInfo");
2112 GP = GP & t->GetBranchStatus("h20");
2113
2114
2115 // Tracker
2116 if(TRK1) {
2117 t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel2"));
2118 cout << "Tracker : set branch address TrkLevel1"<<endl;
2119 };
2120 if(TRK2) {
2121 t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));
2122 cout << "Tracker : set branch address TrkLevel2"<<endl;
2123 };
2124 if(TRKh) {
2125 t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
2126 cout << "Tracker : set branch address TrkHough"<<endl;
2127 };
2128
2129 // Calorimeter
2130 if(CAL1) {
2131 t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
2132 cout << "Calorimeter : set branch address CaloLevel1"<<endl;
2133 };
2134 if(CAL2) {
2135 t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
2136 cout << "Calorimeter : set branch address CaloLevel2"<<endl;
2137 };
2138
2139 // ToF
2140 if(TOF) {
2141 t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
2142 cout << "ToF : set branch address ToFLevel2"<<endl;
2143 };
2144 // Trigger
2145 if(TRG) {
2146 t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
2147 cout << "Trigger : set branch address TrigLevel2"<<endl;
2148 };
2149 // S4
2150 if(S4) {
2151 t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
2152 cout << "S4 : set branch address S4Level2"<<endl;
2153 };
2154 // Neutron Detector
2155 if(ND) {
2156 t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
2157 cout << "NeutronD : set branch address NDLevel2"<<endl;
2158 };
2159 // Anticounters
2160 if(AC) {
2161 t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
2162 cout << "Anticounter : set branch address AcLevel2"<<endl;
2163 };
2164 // OrbitalInfo
2165 if(ORB) {
2166 t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
2167 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
2168 };
2169 // GPamela
2170 if(GP) {
2171 // GetPointerTo("GPamela");
2172 if(!gp_obj)gp_obj = new GPamela();
2173 gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2174 // t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2175 cout << "h20 : set branch address GPamela "<<endl;
2176 };
2177
2178 }
2179 /**
2180 * Set branch addresses for Pamela friend trees
2181 */
2182 void PamLevel2::SetBranchAddress(TChain *t){
2183
2184 // TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
2185 // TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
2186 // TRKh = TRKh & t->GetBranchStatus("TrkHough");
2187 // CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
2188 // CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
2189 // TOF = TOF & t->GetBranchStatus("ToFLevel2");
2190 // TRG = TRG & t->GetBranchStatus("TrigLevel2");
2191 // S4 = S4 & t->GetBranchStatus("S4Level2");
2192 // ND = ND & t->GetBranchStatus("NDLevel2");
2193 // AC = AC & t->GetBranchStatus("AcLevel2");
2194 // ORB = ORB & t->GetBranchStatus("OrbitalInfo");
2195 // GP = GP & t->GetBranchStatus("h20");
2196
2197 // Tracker
2198 if(TRK2) {
2199 t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
2200 cout << "Tracker : set branch address TrkLevel2"<<endl;
2201 };
2202 if(TRK1) {
2203 t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
2204 cout << "Tracker : set branch address TrkLevel1"<<endl;
2205 };
2206 if(TRKh) {
2207 t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
2208 cout << "Tracker : set branch address TrkHough"<<endl;
2209 };
2210
2211 // Calorimeter
2212 if(CAL2) {
2213 t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
2214 cout << "Calorimeter : set branch address CaloLevel2"<<endl;
2215 };
2216 if(CAL1) {
2217 t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
2218 cout << "Calorimeter : set branch address CaloLevel1"<<endl;
2219 };
2220
2221 // ToF
2222 if(TOF) {
2223 t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
2224 cout << "ToF : set branch address ToFLevel2"<<endl;
2225 };
2226 // Trigger
2227 if(TRG) {
2228 t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
2229 cout << "Trigger : set branch address TrigLevel2"<<endl;
2230 };
2231 // S4
2232 if(S4) {
2233 t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
2234 cout << "S4 : set branch address S4Level2"<<endl;
2235 };
2236 // Neutron Detector
2237 if(ND) {
2238 t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
2239 cout << "NeutronD : set branch address NDLevel2"<<endl;
2240 };
2241 // Anticounters
2242 if(AC) {
2243 t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
2244 cout << "Anticounter : set branch address AcLevel2"<<endl;
2245 };
2246 // OrbitalInfo
2247 if(ORB) {
2248 t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
2249 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
2250 };
2251 // GPamela
2252 // cout <<"GP "<<GP<<endl;
2253 if(GP) {
2254 // GetPointerTo("GPamela");
2255 if(!gp_obj)gp_obj = new GPamela();
2256 gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2257 cout << "h20 : set branch address GPamela "<<endl;
2258 };
2259 // SelectionList
2260 // if(SELLI==1){
2261 // t->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2262 // cout << "SelectionList: set branch address RunEntry"<<endl;
2263 // t->SetBranchAddress("EventEntry",&irunentry);
2264 // cout << "SelectionList: set branch address EventEntry"<<endl;
2265
2266 // }
2267
2268 }
2269
2270
2271 //--------------------------------------
2272 //
2273 //
2274 //--------------------------------------
2275 /**
2276 * Get the Run tree chain from a list of files.
2277 * @param fl Pointer to a TList of TSystemFiles
2278 * @return Pointer to a TChain
2279 */
2280 TChain *PamLevel2::GetRunTree(TList *fl){
2281 //
2282 //
2283 //
2284 if ( run_tree ){
2285 printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
2286 return run_tree;
2287 };
2288 //
2289 TChain *R = new TChain("Run");
2290
2291 // loop over files and create chains
2292 TIter next(fl);
2293 TSystemFile *questo = 0;
2294 while ( (questo = (TSystemFile*) next()) ) {
2295 TString name = questo->GetName();
2296 // cout << "File: "<< name << endl;
2297 if( CheckLevel2File(name) ){
2298 R->Add(name);
2299 };
2300 }
2301
2302 if(R->GetNtrees()){
2303
2304 R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
2305 cout << "Run : set branch address RunInfo"<<endl;
2306 R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2307 cout << "Software : set branch address SoftInfo"<<endl; // Emiliano
2308
2309 irunoffset = new int[R->GetNtrees()];
2310 if(DBG){
2311 cout << "----------------------------------------------------"<<endl;
2312 cout << "irun\t | ";
2313 cout << "tree\t |";
2314 // cout << "offset\t |";
2315 cout << "RUN\t";
2316 cout << "FRAG\t";
2317 cout << "NEVENTS\t";
2318 cout << "absolute time\t\t\t";
2319 cout << "on-board time";
2320 cout<<endl;
2321 }
2322 for (Int_t ii=0; ii<R->GetEntries(); ii++){
2323 R->GetEntry(ii);
2324 if(DBG){
2325 cout << ii<< "\t | ";
2326 cout << R->GetTreeNumber()<< "\t |";
2327 // cout << R->GetChainOffset()<< "\t |";
2328 cout <<GetRunInfo()->ID<<"\t";
2329 cout <<GetRunInfo()->ID_RUN_FRAG<<"\t";
2330 cout <<GetRunInfo()->NEVENTS<< "\t";
2331 cout <<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME <<"\t";
2332 cout <<GetRunInfo()->RUNHEADER_OBT<<" <---> "<<GetRunInfo()->RUNTRAILER_OBT<<"\t";
2333 cout <<endl;
2334 }
2335 irunoffset[R->GetTreeNumber()]=R->GetChainOffset();
2336 }
2337 cout << "N.run = "<<R->GetEntries()<<endl;
2338 cout << "----------------------------------------------------"<<endl;
2339
2340
2341 }else{
2342 delete R;
2343 R=0;
2344 }
2345
2346 run_tree = R;
2347
2348 return R;
2349
2350 }
2351 //--------------------------------------
2352 //
2353 //
2354 //--------------------------------------
2355 /**
2356 * Get the Run tree from a file.
2357 * @param f Pointer to a TFile
2358 * @return Pointer to a TTree
2359 */
2360 TTree *PamLevel2::GetRunTree(TFile *f){
2361 if ( run_tree ){
2362 printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
2363 return run_tree;
2364 };
2365
2366
2367 cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
2368
2369 TTree *T = (TTree*)f->Get("Run");
2370
2371 if(T){
2372 T->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
2373 cout << "Run : set branch address RunInfo"<<endl;
2374 T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2375 cout << "Software : set branch address SoftInfo"<<endl; // Emiliano
2376
2377 }
2378
2379 run_tree = (TChain*)T;
2380
2381 return T;
2382
2383 }
2384 /**
2385 * Update the runinfo informations (to be used to have Run infos event by event basis)
2386 * @param run Pointer to the chain/tree which contains run infos
2387 * @return true if a new run has been read, false if it is still the same run
2388 */
2389 Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){
2390 //
2391 // check if we have already called once GetEntry, if not call it
2392 //
2393 cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- ATTENZIONE --- NON E` MANTENUTA!!!!!!!.... "<<endl;
2394 if(!run){
2395 cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree "<<endl;
2396 return(false);
2397 }
2398 if ( run->GetEntries() <= 0 ) return(false);
2399 //
2400
2401 // Int_t oldrun = irun;
2402 Long64_t oldrun = irun;
2403
2404 // --------------------------------------
2405 // if it is a full file (not preselected)
2406 // --------------------------------------
2407 if(SELLI==0){
2408
2409 //
2410 // the absolute time is necessary to relate the event with the run
2411 //
2412 if( !GetOrbitalInfo() && !ISGP){
2413 cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2414 return(false);
2415 }
2416
2417 ULong64_t abstime = 0;
2418 if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;
2419
2420
2421 //
2422 // the first time the routine is called, set run search from the beginning
2423 //
2424 if ( irun < 0LL ){
2425 irun = 0LL;
2426 run->GetEntry(irun);
2427 runfirstentry = 0LL;
2428 runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2429 if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2430
2431 if( ISGP && run->GetEntries()!=1 ){
2432 cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl;
2433 cout << "** WARNING ** run will not be updated"<<endl;
2434 }
2435
2436 };
2437 //
2438 if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2439 //
2440 if ( irun == run->GetEntries()-1LL &&
2441 !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2442 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2443 ){
2444 irun = -1LL;
2445 irunt = -1LL;
2446 runfirstentry = 0LL;
2447 runlastentry = -1LL;
2448 };
2449 // modificato il controllo sull'aggiornamento del run, per evitare problemi
2450 // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
2451 //
2452 bool fromfirst = true;
2453 //
2454 while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){
2455 // while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
2456 irun++;
2457 run->GetEntry(irun);
2458 runfirstentry = runlastentry;
2459 if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;
2460 runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2461 // cout << " ))))) UPDATE RUN INFO ((((( @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2462 // cout << "runfirstentry "<<runfirstentry<<endl;
2463 // printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
2464 // printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);
2465 // printf(" IDRUN %u \n",GetRunInfo()->ID);
2466 //
2467 // prevshift = 0;
2468 //
2469 if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){
2470 printf(" resetting irun (it should NOT happen!!!)\n");
2471 fromfirst = false;
2472 irun = 0;
2473 run->GetEntry(irun);
2474 runfirstentry = 0ULL;
2475 runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2476 if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2477 };
2478 //
2479 };
2480 //
2481 if (
2482 !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2483 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2484 ) {
2485 printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n",abstime);
2486 return false;
2487 }
2488 //
2489 if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
2490 //
2491 // printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
2492 //
2493 prevshift = 0;
2494 cout << " ))))) UPDATE RUN INFO ((((( @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2495 // cout << "runfirstentry "<<runfirstentry<<endl;
2496 return(true);
2497 };
2498 // ----------------------------------------------------
2499 // if it is a preselected file (there is SelectionList)
2500 // NBNB - the event tree MUST be read first
2501 // ----------------------------------------------------
2502 if(SELLI==1){
2503 sel_tree->GetEntry(iev);
2504 // cout << irun << " "<< irunentry << endl;
2505 if(irun != oldrun){
2506 run->GetEntry(irun);
2507 cout << " ))))) UPDATE RUN INFO ((((( @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2508 prevshift = 0;
2509 return true;
2510 }
2511 return false;
2512 }
2513
2514 return false;
2515 //
2516 };
2517
2518 Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){
2519
2520 if(!run_tree){
2521 cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded"<<endl;
2522 return false;
2523 }
2524 if ( run_tree->GetEntries() <= 0 ) {
2525 cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty"<<endl;
2526 return(false);
2527 }
2528
2529 Int_t oldrun = irun; // store current run index
2530
2531 // -----------------------------------------------------------------------
2532 // the first time the routine is called, set run search from the beginning
2533 // -----------------------------------------------------------------------
2534
2535 if ( irun < 0 ){
2536 irun = 0LL;
2537 irunt = 0LL;
2538 irunentry = 0;
2539 prevshift = 0;
2540 run_tree->GetEntry(irun);
2541 if( !GetOrbitalInfo() )cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated "<<endl;
2542 };
2543 // ---------------------------------------------------------------
2544 // retrieve OBT and absolute time of the event
2545 // ---------------------------------------------------------------
2546 ULong64_t abstime = 0LL;
2547 ULong64_t obt = 0LL;
2548 if( GetOrbitalInfo() ){
2549 abstime = GetOrbitalInfo()->absTime;
2550 obt = GetOrbitalInfo()->OBT;
2551 // cout << " ABS >>> "<<abstime<<" OBT >>> "<<obt<<" "<<endl;
2552 }else{
2553 abstime = GetRunInfo()->RUNHEADER_TIME;
2554 obt = GetRunInfo()->RUNHEADER_OBT;
2555 }
2556 // cout << ISGP << " "<<abstime<<endl;
2557 // ---------------------------------------------------------------
2558 // the absolute time is necessary to relate the event with the run
2559 // ---------------------------------------------------------------
2560 // if( !GetOrbitalInfo() && !ISGP ){
2561 // cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2562 // return(false);
2563 // }
2564 // -----------------------------------------------------------------------
2565 // if it is simulation, assign abstime by hand (temporaneo!!!)
2566 // -----------------------------------------------------------------------
2567 // if(ISGP){
2568 // abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2569 // obt = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO
2570 // }
2571
2572
2573 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2574 // if it is a full file (not preselected)
2575 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2576 if(SELLI==0){
2577
2578 // ---------------------------------------------------------------
2579 // increment dead and live-time counters
2580 // (only when reading a file not preselected)
2581 // ---------------------------------------------------------------
2582 if(SELLI==0){
2583 if( GetTrigLevel2() ){
2584 totdltime[0]+=GetTrigLevel2()->dltime[0];
2585 totdltime[1]+=GetTrigLevel2()->dltime[1];
2586 }
2587 totdltime[2]++;
2588 }
2589 // cout << setw(10)<<totdltime[0]<<setw(10)<<totdltime[1]<<setw(10)<<totdltime[2]<<endl;
2590
2591 // // ---------------------------------------------------------------
2592 // // retrieve OBT and absolute time of the event
2593 // // ---------------------------------------------------------------
2594 // ULong64_t abstime = 0;
2595 // ULong64_t obt = 0;
2596 // if( GetOrbitalInfo() ){
2597 // abstime = GetOrbitalInfo()->absTime;
2598 // obt = GetOrbitalInfo()->OBT;
2599 // }
2600 // // ---------------------------------------------------------------
2601 // // the absolute time is necessary to relate the event with the run
2602 // // ---------------------------------------------------------------
2603 // if( !GetOrbitalInfo() && !ISGP ){
2604 // cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2605 // return(false);
2606 // }
2607
2608 // // -----------------------------------------------------------------------
2609 // // the first time the routine is called, set run search from the beginning
2610 // // -----------------------------------------------------------------------
2611 // if ( irun < 0 ){
2612 // irun = 0LL;
2613 // irunt = 0LL;
2614 // irunentry = 0;
2615 // prevshift = 0;
2616 // run_tree->GetEntry(irun);
2617
2618 // if( ISGP && run_tree->GetEntries()!=1 ){
2619 // cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl;
2620 // cout << "** WARNING ** run will not be updated"<<endl;
2621 // }
2622 // };
2623
2624 // // -----------------------------------------------------------------------
2625 // // if it is simulation, assign abstime by hand (temporaneo!!!)
2626 // // -----------------------------------------------------------------------
2627 // if(ISGP){
2628 // abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2629 // obt = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO
2630 // }
2631 //
2632 bool fromfirst = true; // first loop over runs
2633
2634 // Bool_t hasfrag = false;
2635 // if( GetRunInfo()->ID_RUN_FRAG!=0 && GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID)hasfrag=true;
2636 // ULong64_t fragid = GetRunInfo()->ID_RUN_FRAG;
2637
2638 // ------------------------------------------------------
2639 // loop over runs to find the one that contains the event
2640 // ------------------------------------------------------
2641 while (
2642 (
2643 (
2644 !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s)
2645 abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
2646 !(obt >= GetRunInfo()->RUNHEADER_OBT && // additional check on OBT (ms)
2647 obt <= GetRunInfo()->RUNTRAILER_OBT)
2648 )
2649 || GetRunInfo()->NEVENTS==0
2650 // || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento
2651 || !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)
2652 )
2653 && irun < run_tree->GetEntries() ){
2654
2655 // - - - - - - - - - - - - -
2656 // irunentry = position of current entry, relative to the run
2657 // prevshift = shift needed to synchronize l0 and l2 data (nested events)
2658 // - - - - - - - - - - - - -
2659
2660 // -----------------------------------------
2661 // store dead and live-time of previous run
2662 // -----------------------------------------
2663 // if(SELLI==0){
2664 if(fromfirst){
2665 if(oldrun==irun){
2666 /// decrement counters
2667 if( GetTrigLevel2()){
2668 totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time
2669 totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time
2670 }
2671 totdltime[2]--; //event counter
2672 cout << endl;
2673 cout << "n.events : "<<totdltime[2]<<endl;
2674 cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;
2675 cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;
2676 }else{
2677 totdltime[0]=0;//live-time
2678 totdltime[1]=0;//dead-time
2679 totdltime[2]=0; //event counter
2680 cout << " *** JUMP RUN *** irun "<<irun<<endl;
2681 }
2682 /// add an entry
2683 if(run_tree_clone)
2684 if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2685 run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2686 /// reset counters
2687 if( GetTrigLevel2() ){
2688 totdltime[0]=GetTrigLevel2()->dltime[0];//live-time
2689 totdltime[1]=0; //dead-time
2690 }
2691 totdltime[2]=1; //event counter
2692 }
2693 // }
2694
2695 irun++;
2696 // ------------------------------------
2697 // if the end of run tree is reached...
2698 // ------------------------------------
2699 if( irun == run_tree->GetEntries() ){
2700 if(!fromfirst){
2701 // -----------------------------------------------------
2702 // if it happened already once and the run was not found
2703 // ---> exit with error
2704 // -----------------------------------------------------
2705 cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- event entry #"<<iev<<" does not belong to any run (should not happen)" <<endl;
2706 return false;
2707 }
2708 // -----------------------------------------
2709 // ...otherwise repeat search from beginning
2710 // -----------------------------------------
2711 cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- reached end of run tree. searchin again from beginning " <<endl;
2712 fromfirst = false;
2713 irun = 0LL;
2714 runfirstentry = 0LL;
2715 }
2716 // -------------------------------------------------------------------
2717 // save the index of the first entry of the run, relative to pam_tree,
2718 // and read a new run
2719 // -------------------------------------------------------------------
2720 if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;
2721 irunentry = 0;
2722 prevshift = 0;
2723 run_tree->GetEntry(irun);
2724 irunt = irun - irunoffset[run_tree->GetTreeNumber()];
2725 if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){
2726 cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<" has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl;
2727 cout << " (NB!! in this case some events are assigned to a wrong run)"<<endl;
2728 }
2729 // if(hasfrag && fragid != GetRunInfo()->ID){
2730 // cout << "... where is the next fragment ??"<<endl;
2731 // }
2732 };
2733
2734
2735 // --------------------------------------
2736 // if there was no need to update the run
2737 // ---> exit with FALSE
2738 // --------------------------------------
2739 if ( irun == oldrun ) return(false);
2740
2741 // --------------------------------------
2742 // ... otherwise
2743 // --------------------------------------
2744
2745
2746
2747
2748 // --------------------------------------
2749 // ---> exit with TRUE
2750 // --------------------------------------
2751 cout << endl << " ))))) UPDATE RUN INFO ((((( @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2752 // ----------------------------------------------------
2753 // then check if the run has a fragment
2754 // in this case we have to switch to the next fragment
2755 // when the end of the first fragment is reached
2756 // ----------------------------------------------------
2757 if(
2758 GetRunInfo()->ID_RUN_FRAG != 0 &&
2759 // GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&
2760 true ){
2761 cout << "* fragment *"<<endl;
2762 }
2763
2764 return(true);
2765 };
2766 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2767 // if it is a preselected file (there is SelectionList)
2768 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2769 // irun = run entry relative to the chain
2770 // irunt = run entry relative to the tree
2771 if(SELLI==1){
2772 sel_tree->GetEntry(iev);// read irunt from SelectionList
2773 irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
2774 if(irun != oldrun ){
2775 if( irun < run_tree->GetEntries() )run_tree->GetEntry(irun);
2776 // check if the time is ok (with merged files it is not...)
2777 // if not loop over run and look for the proper entry
2778 bool SECONDO_GIRO=false;
2779 Long64_t irun_start = irun;
2780 int offset_start = irunoffset[sel_tree->GetTreeNumber()];
2781 while (
2782 (
2783 (
2784 !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s)
2785 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2786 // ||
2787 // !(obt >= GetRunInfo()->RUNHEADER_OBT && // additional check on OBT (ms)
2788 // obt <= GetRunInfo()->RUNTRAILER_OBT)
2789 )
2790 || GetRunInfo()->NEVENTS==0
2791 )
2792 // && irun < run_tree->GetEntries()
2793 ){
2794
2795 if(DBG){
2796 cout << " (test) ";
2797 cout << " tree "<<sel_tree->GetTreeNumber();
2798 cout << " irunt "<<irunt;
2799 cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2800 cout << " abs "<<abstime;
2801 cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2802 cout << " obt "<<obt;
2803 cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2804 cout << " *** JUMP RUN *** irun "<<irun;
2805 // if(!SECONDO_GIRO)cout << " (don't worry)";
2806 // else cout << " (start worring...)";
2807 cout << endl;
2808 }
2809 // irun++;
2810 irunoffset[sel_tree->GetTreeNumber()]++;
2811 irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
2812 if(irun == run_tree->GetEntries() && SECONDO_GIRO){
2813 // if(irun == irun_start ){
2814 cout << " ...grrrvzzkhhhajsdkj!!!! "<<endl;
2815 irunoffset[sel_tree->GetTreeNumber()] = offset_start;
2816 return false;
2817 }
2818 if( irun >= run_tree->GetEntries() || irun < 0){
2819 cout << "irun = "<<irun<<" >> search from the beginning... <<"<<endl;
2820 SECONDO_GIRO=true;
2821 irun=0;
2822 irunoffset[sel_tree->GetTreeNumber()]=-irunt;
2823 }
2824 run_tree->GetEntry(irun);
2825 }
2826
2827
2828 if(DBG){
2829 cout << " (test) ";
2830 cout << " tree "<<sel_tree->GetTreeNumber();
2831 cout << " irunt "<<irunt;
2832 cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2833 cout << " abs "<<abstime;
2834 cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2835 cout << " obt "<<obt;
2836 cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2837 }
2838 cout << endl;
2839 cout << endl << " ))))) UPDATE RUN INFO ((((( @iev "<<iev<<" run "<<GetRunInfo()->ID<<" (run-entry "<<irun<<")"<<endl;
2840 // cout << endl;
2841 prevshift = 0;
2842 return true;
2843 }
2844 return false;
2845 }
2846
2847 return false;
2848 //
2849 };
2850 /**
2851 * Update the runinfo informations (to be used to have Run infos event by event basis)
2852 * @param run Pointer to the chain/tree which contains run infos
2853 * @return true if a new run has been read, false if it is still the same run
2854 */
2855 Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){
2856 return(UpdateRunInfo((TChain*)run,iev));
2857 };
2858
2859 //--------------------------------------
2860 //
2861 //
2862 //--------------------------------------
2863 /**
2864 * Set which trees shoul be analysed
2865 * @param detlist TString containing the sequence of trees required
2866 */
2867 void PamLevel2::SetWhichTrees(TString detlist){
2868
2869 // if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
2870 if( detlist.Contains("+ALL", TString::kIgnoreCase)){
2871
2872 cout << " ======================================================== "<<endl;
2873 cout << " (( WARNING )) "<<endl;
2874 cout << " The meaning of the option +ALL has changed!! "<<endl;
2875 cout << " Now it includes really all (level0+level1+level2+gpamela)"<<endl;
2876 cout << " and the file is discarded if it does not contain "<<endl;
2877 cout << " all trees or if level0 files are not available!! "<<endl;
2878 cout << " ======================================================== "<<endl;
2879
2880 CAL0 = true;
2881 CAL1 = true;
2882 CAL2 = true;
2883 TRK2 = true;
2884 TRK1 = true;
2885 TRKh = true;
2886 TRK0 = true;
2887 TRG = true;
2888 TOF = true;
2889 TOF0 = true;
2890 S4 = true;
2891 ND = true;
2892 AC = true;
2893 ORB = true;
2894 GP = true;
2895 }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
2896 CAL0 = false;
2897 CAL1 = false;
2898 CAL2 = false;
2899 TRK2 = false;
2900 TRK1 = false;
2901 TRKh = false;
2902 TRK0 = false;
2903 TRG = false;
2904 TOF = false;
2905 TOF0 = false;
2906 S4 = false;
2907 ND = false;
2908 AC = false;
2909 ORB = false;
2910 GP = false;
2911 };
2912
2913 // -------------------------------------------------------------------------
2914 if( detlist.Contains("CAL1", TString::kIgnoreCase) ){
2915 if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;
2916 if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;
2917 };
2918
2919 if( detlist.Contains("CAL0", TString::kIgnoreCase) ){
2920 if ( detlist.Contains("-CAL0", TString::kIgnoreCase) )CAL0=false;
2921 if ( detlist.Contains("+CAL0", TString::kIgnoreCase) )CAL0=true;
2922 };
2923
2924 if( detlist.Contains("CAL2", TString::kIgnoreCase)){
2925 if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;
2926 if ( detlist.Contains("+CAL2", TString::kIgnoreCase) )CAL2=true;
2927 };
2928
2929 if( detlist.Contains("+CAL", TString::kIgnoreCase) && !CAL1 && !CAL2 )CAL2=true;
2930 if( detlist.Contains("-CAL", TString::kIgnoreCase) && CAL1 && CAL2 ){
2931 CAL2=false;
2932 CAL1=false;
2933 }
2934 // -------------------------------------------------------------------------
2935 if( detlist.Contains("TRK0", TString::kIgnoreCase) ){
2936 if ( detlist.Contains("-TRK0", TString::kIgnoreCase) )TRK0=false;
2937 if ( detlist.Contains("+TRK0", TString::kIgnoreCase) )TRK0=true;
2938 };
2939
2940 if( detlist.Contains("TRK1", TString::kIgnoreCase) ){
2941 if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;
2942 if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;
2943 };
2944
2945 if( detlist.Contains("TRK2", TString::kIgnoreCase)){
2946 if ( detlist.Contains("-TRK2", TString::kIgnoreCase) )TRK2=false;
2947 if ( detlist.Contains("+TRK2", TString::kIgnoreCase) )TRK2=true;
2948 };
2949
2950 if( detlist.Contains("TRKh", TString::kIgnoreCase)){
2951 if ( detlist.Contains("-TRKh", TString::kIgnoreCase) )TRKh=false;
2952 if ( detlist.Contains("+TRKh", TString::kIgnoreCase) )TRKh=true;
2953 };
2954
2955 if( detlist.Contains("+TRK", TString::kIgnoreCase) && !TRK1 && !TRK2 && !TRKh )TRK2=true;
2956 if( detlist.Contains("-TRK", TString::kIgnoreCase) && TRK1 && TRK2 && TRKh){
2957 TRK2=false;
2958 TRK1=false;
2959 TRKh=false;
2960 }
2961 // -------------------------------------------------------------------------
2962
2963 if( detlist.Contains("-TRG", TString::kIgnoreCase) )TRG = false;
2964 else if( detlist.Contains("+TRG", TString::kIgnoreCase) )TRG = true;
2965
2966 if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
2967 else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
2968
2969 if( detlist.Contains("-TOF0", TString::kIgnoreCase) )TOF0 = false;
2970 else if( detlist.Contains("+TOF0", TString::kIgnoreCase) )TOF0 = true;
2971
2972 if( detlist.Contains("-S4", TString::kIgnoreCase) )S4 = false;
2973 else if( detlist.Contains("+S4", TString::kIgnoreCase) )S4 = true;
2974
2975 if( detlist.Contains("-ND", TString::kIgnoreCase) )ND = false;
2976 else if( detlist.Contains("+ND", TString::kIgnoreCase) )ND = true;
2977
2978 if( detlist.Contains("-AC", TString::kIgnoreCase) )AC = false;
2979 else if( detlist.Contains("+AC", TString::kIgnoreCase) )AC = true;
2980
2981 if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;
2982 else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;
2983
2984 if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false;
2985 else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true;
2986
2987 cout<< "tree/branch list from input --> ";
2988 if(TRK0)cout<<"TRK0 ";
2989 if(TRK1)cout<<"TRK1 ";
2990 if(TRK2)cout<<"TRK2 ";
2991 if(TRKh)cout<<"TRKH ";
2992 if(CAL0)cout<<"CAL0 ";
2993 if(CAL1)cout<<"CAL1 ";
2994 if(CAL2)cout<<"CAL2 ";
2995 if(TOF)cout<<"TOF ";
2996 if(TRG)cout<<"TRG ";
2997 if(AC)cout<<"AC ";
2998 if(ND)cout<<"ND ";
2999 if(S4)cout<<"S4 ";
3000 if(ORB)cout<<"ORB ";
3001 if(GP)cout<<"GP ";
3002 cout << endl;
3003 // cout<< "Set detector list --> ";
3004 // if(TRK1)cout<<"TRK1 ";
3005 // if(TRK2)cout<<"TRK2 ";
3006 // if(TRKh)cout<<"TRKH ";
3007 // if(CAL1)cout<<"CAL1 ";
3008 // if(CAL2)cout<<"CAL2 ";
3009 // if(TOF0)cout<<"TOF0 ";
3010 // if(TOF)cout<<"TOF ";
3011 // if(TRG)cout<<"TRG ";
3012 // if(AC)cout<<"AC ";
3013 // if(ND)cout<<"ND ";
3014 // if(S4)cout<<"S4 ";
3015 // if(ORB)cout<<"ORB ";
3016 // cout << endl;
3017
3018 };
3019
3020
3021 /**
3022 * Set tree/branch detector flags from the content of a tree
3023 */
3024 void PamLevel2::GetWhichTrees(TFile* f){
3025
3026
3027
3028 // cout << "void PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
3029 // -----------
3030 // reset flags
3031 // -----------
3032 CAL1 = false;
3033 CAL2 = false;
3034 TRK2 = false;
3035 TRK1 = false;
3036 TRKh = false;
3037 TRG = false;
3038 TOF = false;
3039 S4 = false;
3040 ND = false;
3041 AC = false;
3042 ORB = false;
3043 GP = false;
3044
3045 RUN = false;
3046
3047 // cout << "Checking file: "<<f->GetName()<<endl;
3048 if( !f || f->IsZombie() ){
3049 cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;
3050 return;
3051 }
3052
3053 TList *lk = f->GetListOfKeys();
3054 TIter next(lk);
3055 TKey *key =0;
3056
3057 Int_t nev = 0;
3058
3059 while( (key = (TKey*)next()) ){
3060
3061 if( !strcmp(key->GetName(),"Run" ) )RUN = true;
3062
3063 //=========================================================
3064 if( !strcmp(key->GetName(),"Trigger" ) ){
3065 TRG = true;
3066 Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries();
3067 if( nev && nevt!=nev){
3068 cout << "File: "<< f->GetName() <<" Trigger tree has "<<nevt<<" events instead of "<<nev<< endl;
3069 TRG = false;
3070 }else nev=nevt;
3071 }
3072 //=========================================================
3073 if( !strcmp(key->GetName(),"ToF" ) ){
3074 TOF = true;
3075 Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries();
3076 if( nev && nevt!=nev){
3077 cout << "File: "<< f->GetName() <<" ToF tree has "<<nevt<<" events instead of "<<nev<< endl;
3078 TOF = false;
3079 }else nev=nevt;
3080 }
3081 //=========================================================
3082 if( !strcmp(key->GetName(),"S4" ) ){
3083 S4 = true;
3084 Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries();
3085 if( nev && nevt!=nev){
3086 cout << "File: "<< f->GetName() <<" S4 tree has "<<nevt<<" events instead of "<<nev<< endl;
3087 S4 = false;
3088 }else nev=nevt;
3089 }
3090 //=========================================================
3091
3092 if( !strcmp(key->GetName(),"NeutronD" ) ){
3093 ND = true;
3094 Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries();
3095 if( nev && nevt!=nev){
3096 cout << "File: "<< f->GetName() <<"NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl;
3097 ND =false;
3098 }else nev=nevt;
3099 }
3100 //=========================================================
3101 if( !strcmp(key->GetName(),"Anticounter") ){
3102 AC = true;
3103 Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries();
3104 if( nev && nevt!=nev){
3105 cout << "File: "<< f->GetName() <<" Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl;
3106 AC =false;
3107 }else nev=nevt;
3108 }
3109 //=========================================================
3110 if( !strcmp(key->GetName(),"OrbitalInfo") ){
3111 ORB = true;
3112 Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries();
3113 if( nev && nevt!=nev){
3114 cout << "File: "<< f->GetName() <<" OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
3115 ORB = false;
3116 }else nev=nevt;
3117 }
3118 //=========================================================
3119 if( !strcmp(key->GetName(),"Tracker" ) ){
3120 TTree *T = (TTree*)f->Get("Tracker");
3121 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
3122 TString name = T->GetListOfBranches()->At(i)->GetName();
3123 if( !name.CompareTo("TrkLevel1") )TRK1=true;
3124 if( !name.CompareTo("TrkLevel2") )TRK2=true;
3125 if( !name.CompareTo("TrkHough") )TRKh=true;
3126 };
3127 Int_t nevt = T->GetEntries();
3128 if( nev && nevt!=nev){
3129 cout << "File: "<< f->GetName() <<" Tracker tree has "<<nevt<<" events instead of "<<nev<< endl;
3130 TRK1 = false;
3131 TRK2 = false;
3132 TRKh = false;
3133 }else nev=nevt;
3134 // T->Delete();
3135 };
3136 //=========================================================
3137 if( !strcmp(key->GetName(),"Calorimeter" ) ){
3138 TTree *T = (TTree*)f->Get("Calorimeter");
3139 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
3140 TString name = T->GetListOfBranches()->At(i)->GetName();
3141 if( !name.CompareTo("CaloLevel1") )CAL1=true;
3142 if( !name.CompareTo("CaloLevel2") )CAL2=true;
3143 };
3144 Int_t nevt = T->GetEntries();
3145 if( nev && nevt!=nev){
3146 cout << "File: "<< f->GetName() <<" Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl;
3147 CAL1 = false;
3148 CAL2 = false;
3149 }else nev=nevt;
3150 // T->Delete();
3151 };
3152 //=========================================================
3153 if( !strcmp(key->GetName(),"h20") ){
3154 GP = true;
3155 Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();
3156 if( nev && nevt!=nev){
3157 cout << "File: "<< f->GetName() <<" h20 tree has "<<nevt<<" events instead of "<<nev<< endl;
3158 GP = false;
3159 }else nev=nevt;
3160 }
3161
3162 };
3163
3164 // delete lk;
3165
3166 cout<< "tree/branch list from file --> ";
3167 if(TRK1)cout<<"TRK1 ";
3168 if(TRK2)cout<<"TRK2 ";
3169 if(TRKh)cout<<"TRKH ";
3170 if(CAL1)cout<<"CAL1 ";
3171 if(CAL2)cout<<"CAL2 ";
3172 if(TOF)cout<<"TOF ";
3173 if(TRG)cout<<"TRG ";
3174 if(AC)cout<<"AC ";
3175 if(ND)cout<<"ND ";
3176 if(S4)cout<<"S4 ";
3177 if(ORB)cout<<"ORB ";
3178 if(GP)cout<<"GP ";
3179 cout << endl;
3180
3181 return ;
3182
3183 };
3184
3185
3186 //--------------------------------------
3187 //
3188 //
3189 //--------------------------------------
3190 /**
3191 * Check if a file contains selected Pamela Level2 trees.
3192 * @param name File name
3193 * @return true if the file is ok.
3194 */
3195 Bool_t PamLevel2::CheckLevel2File(TString name){
3196
3197 Bool_t CAL1__ok = false;
3198 Bool_t CAL2__ok = false;
3199 Bool_t TRK2__ok = false;
3200 Bool_t TRK1__ok = false;
3201 Bool_t TRKh__ok = false;
3202 Bool_t TRG__ok = false;
3203 Bool_t TOF__ok = false;
3204 Bool_t S4__ok = false;
3205 Bool_t ND__ok = false;
3206 Bool_t AC__ok = false;
3207 Bool_t ORB__ok = false;
3208 Bool_t GP__ok = false;
3209
3210 Bool_t RUN__ok = false;
3211
3212 Bool_t SELLI__ok = false;
3213
3214 // cout << "Checking file: "<<name<<endl;
3215 TFile *f = new TFile(name.Data());
3216 if( !f || f->IsZombie() ){
3217 cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false;
3218 }
3219 // cout << "Get list of keys: "<<f<<endl;
3220 TList *lk = f->GetListOfKeys();
3221 // lk->Print();
3222 TIter next(lk);
3223 TKey *key =0;
3224
3225 Int_t nev = 0;
3226
3227 while( (key = (TKey*)next()) ){
3228
3229 // cout << key->GetName() << endl;
3230 // cout << key->GetName() << ""<<key->GetClassName()<<endl;
3231 // cout << " Get tree: " << f->Get(key->GetName())<<endl;
3232 // nev_previous = nev;
3233 // cout << " n.entries "<< nev <<endl;
3234 // if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){
3235 // nev = ((TTree*)f->Get(key->GetName()))->GetEntries();
3236 // cout << "File: "<< f->GetName() <<" discarded ---- "<< key->GetName() << " tree: n.entries does not match "<<nev<<" "<<nev_previous<< endl;
3237 // return false;
3238 // };
3239
3240 //=========================================================
3241 // check if the file
3242
3243
3244 if( !strcmp(key->GetName(),"Run" ) )RUN__ok = true;
3245
3246 //=========================================================
3247 if( !strcmp(key->GetName(),"SelectionList" ) ){
3248 SELLI__ok = true;
3249 if(SELLI==1){
3250 Int_t nevt = ((TTree*)f->Get("SelectionList"))->GetEntries();
3251 if( nev && nevt!=nev){
3252 cout << "File: "<< f->GetName() <<" discarded ---- SelectionList tree has "<<nevt<<" events instead of "<<nev<< endl;
3253 return false;
3254 }
3255 nev=nevt;
3256 }
3257 }
3258
3259 //=========================================================
3260 if( !strcmp(key->GetName(),"Trigger" ) ){
3261 TRG__ok = true;
3262 if(TRG){
3263 Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries();
3264 if( nev && nevt!=nev){
3265 cout << "File: "<< f->GetName() <<" discarded ---- Trigger tree has "<<nevt<<" events instead of "<<nev<< endl;
3266 return false;
3267 }
3268 nev=nevt;
3269 }
3270 }
3271 //=========================================================
3272 if( !strcmp(key->GetName(),"ToF" ) ){
3273 TOF__ok = true;
3274 if(TOF){
3275 Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries();
3276 if( nev && nevt!=nev){
3277 cout << "File: "<< f->GetName() <<" discarded ---- ToF tree has "<<nevt<<" events instead of "<<nev<< endl;
3278 return false;
3279 }
3280 nev=nevt;
3281 }
3282 }
3283 //=========================================================
3284 if( !strcmp(key->GetName(),"S4" ) ){
3285 S4__ok = true;
3286 if(S4){
3287 Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries();
3288 if( nev && nevt!=nev){
3289 cout << "File: "<< f->GetName() <<" discarded ---- S4 tree has "<<nevt<<" events instead of "<<nev<< endl;
3290 return false;
3291 }
3292 nev=nevt;
3293 }
3294 }
3295 //=========================================================
3296
3297 if( !strcmp(key->GetName(),"NeutronD" ) ){
3298 ND__ok = true;
3299 if(ND){
3300 Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries();
3301 if( nev && nevt!=nev){
3302 cout << "File: "<< f->GetName() <<" discarded ---- NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl;
3303 return false;
3304 }
3305 nev=nevt;
3306 }
3307 }
3308 //=========================================================
3309 if( !strcmp(key->GetName(),"Anticounter") ){
3310 AC__ok = true;
3311 if(AC){
3312 Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries();
3313 if( nev && nevt!=nev){
3314 cout << "File: "<< f->GetName() <<" discarded ---- Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl;
3315 return false;
3316 }
3317 nev=nevt;
3318 }
3319 }
3320 //=========================================================
3321 if( !strcmp(key->GetName(),"OrbitalInfo") ){
3322 ORB__ok = true;
3323 if(ORB){
3324 Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries();
3325 if( nev && nevt!=nev){
3326 cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
3327 return false;
3328 }
3329 nev=nevt;
3330 }
3331 }
3332 //=========================================================
3333 if( !strcmp(key->GetName(),"Tracker" ) ){
3334 TTree *T = (TTree*)f->Get("Tracker");
3335 if(TRK1||TRK2||TRKh){
3336 Int_t nevt = T->GetEntries();
3337 if( nev && nevt!=nev){
3338 cout << "File: "<< f->GetName() <<" discarded ---- Tracker tree has "<<nevt<<" events instead of "<<nev<< endl;
3339 return false;
3340 }
3341 nev=nevt;
3342 }
3343 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
3344 TString name = T->GetListOfBranches()->At(i)->GetName();
3345 if( !name.CompareTo("TrkLevel1") )TRK1__ok=true;
3346 if( !name.CompareTo("TrkLevel2") )TRK2__ok=true;
3347 if( !name.CompareTo("TrkHough") )TRKh__ok=true;
3348 };
3349 T->Delete();
3350 };
3351 //=========================================================
3352 if( !strcmp(key->GetName(),"Calorimeter" ) ){
3353 TTree *T = (TTree*)f->Get("Calorimeter");
3354 if(CAL1||CAL2){
3355 Int_t nevt = T->GetEntries();
3356 if( nev && nevt!=nev){
3357 cout << "File: "<< f->GetName() <<" discarded ---- Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl;
3358 return false;
3359 }
3360 nev=nevt;
3361 }
3362 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
3363 TString name = T->GetListOfBranches()->At(i)->GetName();
3364 if( !name.CompareTo("CaloLevel1") )CAL1__ok=true;
3365 if( !name.CompareTo("CaloLevel2") )CAL2__ok=true;
3366 };
3367 T->Delete();
3368 };
3369 //=========================================================
3370 if( !strcmp(key->GetName(),"h20") ){
3371 ISGP = true;
3372 GP__ok = true;
3373 if(GP){
3374 Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();
3375 if( nev && nevt!=nev){
3376 cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
3377 return false;
3378 }
3379 nev=nevt;
3380 }
3381 }
3382
3383 };
3384
3385 if( SELLI==-1 )SELLI = (Int_t)SELLI__ok;
3386 if( SELLI==0 && SELLI__ok ){
3387 cout << "File: "<< f->GetName() <<" discarded ---- found SelectionList (it is not a full-event file)" << endl;
3388 return false;
3389 }
3390 if( SELLI==1 && !SELLI__ok ){
3391 cout << "File: "<< f->GetName() <<" discarded ---- SelectionList missing" << endl;
3392 return false;
3393 }
3394
3395 // cout << "SELLI "<<SELLI<<endl;
3396
3397 // cout<< "CheckLevel2File(TString): detector list --> ";
3398 // if(TRK1__ok)cout<<"TRK1 ";
3399 // if(TRK2__ok)cout<<"TRK2 ";
3400 // if(TRKh__ok)cout<<"TRKH ";
3401 // if(CAL1__ok)cout<<"CAL1 ";
3402 // if(CAL2__ok)cout<<"CAL2 ";
3403 // if(TOF__ok)cout<<"TOF ";
3404 // if(TRG__ok)cout<<"TRG ";
3405 // if(AC__ok)cout<<"AC ";
3406 // if(ND__ok)cout<<"ND ";
3407 // if(S4__ok)cout<<"S4 ";
3408 // if(ORB__ok)cout<<"ORB ";
3409 // cout << endl;
3410
3411
3412 if(TRK2 && TRK1__ok)TRK1=1;
3413 // ----------------------------------------------------------------------------
3414 // NOTA
3415 // se c'e` il level1, lo devo necessarimente leggere.
3416 // infatti (non ho capito perche`) i cluster vengono letti e allocati in memoria
3417 // comunque, ma non vengono disallocati da PamLevel2::Clear()
3418 // ----------------------------------------------------------------------------
3419
3420
3421 if(!RUN__ok) {
3422 cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree"<< endl;
3423 // return false;
3424 };
3425
3426 if(CAL1 && !CAL1__ok){
3427 cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel1 branch"<< endl;
3428 return false;
3429 };
3430 if(CAL2 && !CAL2__ok){
3431 cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel2 branch"<< endl;
3432 return false;
3433 };
3434 if(TRK2 && !TRK2__ok){
3435 cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel2 branch"<< endl;
3436 return false;
3437 };
3438 if(TRK1 && !TRK1__ok){
3439 cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel1 branch"<< endl;
3440 return false;
3441 };
3442 if(TRKh && !TRKh__ok){
3443 cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkHough branch"<< endl;
3444 return false;
3445 };
3446 if(ORB && !ORB__ok){
3447 cout << "File: "<< f->GetName() <<" discarded ---- Missing ORB tree"<< endl;
3448 return false;
3449 };
3450 if(AC && !AC__ok){
3451 cout << "File: "<< f->GetName() <<" discarded ---- Missing AC tree"<< endl;
3452 return false;
3453 };
3454 if(S4 && !S4__ok){
3455 cout << "File: "<< f->GetName() <<" discarded ---- Missing S4 tree"<< endl;
3456 return false;
3457 };
3458 if(TOF && !TOF__ok){
3459 cout << "File: "<< f->GetName() <<" discarded ---- Missing ToF tree"<< endl;
3460 return false;
3461 };
3462
3463 if(ND && !ND__ok){
3464 cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl;
3465 return false;
3466 };
3467 if(TRG && !TRG__ok){
3468 cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;
3469 return false;
3470 };
3471 if(GP && !GP__ok){
3472 cout << "File: "<< f->GetName() <<" discarded ---- Missing h20 tree"<< endl;
3473 return false;
3474 };
3475
3476
3477 // lk->Delete();
3478 // delete lk;
3479 f->Close();
3480
3481 // cout<< "CheckLevel2File(TString): detector list --> ";
3482 // if(TRK1)cout<<"TRK1 ";
3483 // if(TRK2)cout<<"TRK2 ";
3484 // if(TRKh)cout<<"TRKH ";
3485 // if(CAL1)cout<<"CAL1 ";
3486 // if(CAL2)cout<<"CAL2 ";
3487 // if(TOF)cout<<"TOF ";
3488 // if(TRG)cout<<"TRG ";
3489 // if(AC)cout<<"AC ";
3490 // if(ND)cout<<"ND ";
3491 // if(S4)cout<<"S4 ";
3492 // if(ORB)cout<<"ORB ";
3493 // if(GP)cout<<"GP ";
3494 // cout << endl;
3495
3496 return true;
3497
3498 };
3499
3500
3501 /**
3502 * Create clone-trees
3503 */
3504 void PamLevel2::CreateCloneTrees0( TChain *fChain, TFile *ofile ){
3505
3506 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3507 cout << "Create clones of PAMELA trees "<<endl;
3508
3509 Int_t i=0;
3510 pam_tree_clone[i] = fChain->GetTree()->CloneTree(0);
3511 TString name = pam_tree_clone[i]->GetName();
3512 name.Append("_clone");
3513 // pam_tree_clone[i]->SetName(name.Data());
3514 cout << pam_tree_clone[i]->GetName() <<endl;
3515 i++;
3516
3517 TList *li = fChain->GetListOfFriends();
3518 TIter next(li);
3519 TFriendElement* T_friend=0;
3520 ofile->cd();
3521 while( (T_friend = (TFriendElement*)next()) ){
3522 // cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;
3523 // cout<<T_friend->GetTree()->GetName()<< endl;
3524 pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0);
3525 pam_tree_clone[i]->SetAutoSave(1000000);
3526 name = pam_tree_clone[i]->GetName();
3527 name.Append("_clone");
3528 // pam_tree_clone[i]->SetName(name.Data());
3529 cout << pam_tree_clone[i]->GetName() << endl;
3530 i++;
3531 }
3532
3533 delete li;
3534
3535 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3536
3537 }
3538
3539 /**
3540 * Create clone-trees
3541 */
3542 void PamLevel2::CreateCloneTrees(TFile *ofile){
3543
3544
3545 // if the pointer is null, create a default file
3546
3547 if(!ofile){
3548 cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;
3549 ofile = new TFile("clone-tree.root","recreate");
3550 }
3551
3552 ofile->cd();
3553
3554 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3555 cout << "Create new PAMELA trees "<<endl;
3556
3557
3558 run_tree_clone = new TTree("Run","PAMELA Level2 data from the GL_RUN table ");
3559 run_tree_clone->Branch("RunInfo","GL_RUN",GetPointerTo("RunInfo"));
3560 cout << "Run : branch RunInfo"<<endl;
3561 run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));
3562 cout << "Run : branch SoftInfo"<<endl;
3563 // ------------------
3564 // replicate run tree
3565 // ------------------
3566 // cout << "----------------------------------------------------"<<endl;
3567 // cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
3568 for (Int_t i=0; i<run_tree->GetEntries(); i++){
3569 run_tree->GetEntry(i);
3570 // cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;
3571 run_tree_clone->Fill();
3572 }
3573 cout << "----------------------------------------------------"<<endl;
3574
3575 // ------------------------------------
3576 // add branch with dead and live times
3577 // ------------------------------------
3578 run_tree_clone->Branch("DeadLiveTime",totdltime,"dltime[3]/l");
3579 cout << "Run : branch DeadLiveTime"<<endl;
3580
3581
3582 sel_tree_clone = new TTree("SelectionList","List of selected events ");
3583 // sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
3584 sel_tree_clone->Branch("RunEntry",&irunt,"runentry/L");//NEWNEW
3585 sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");
3586
3587
3588 Int_t i=0;
3589 if(TRK1||TRK2||TRKh){
3590 pam_tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");
3591 if(TRK1) {
3592 pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
3593 pam_tree_clone[i]->BranchRef();
3594 cout << "Tracker : branch TrkLevel1"<<endl;
3595 // cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;
3596 };
3597 if(TRK2) {
3598 pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
3599 cout << "Tracker : branch TrkLevel2"<<endl;
3600 };
3601 if(TRKh) {
3602 pam_tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));
3603 cout << "Tracker : branch TrkHough"<<endl;
3604 };
3605 i++;
3606 }
3607
3608 // Calorimeter
3609 if(CAL1||CAL2){
3610 pam_tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");
3611 if(CAL1) {
3612 pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
3613 cout << "Calorimeter : branch CaloLevel1"<<endl;
3614 };
3615 if(CAL2) {
3616 pam_tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));
3617 cout << "Calorimeter : branch CaloLevel2"<<endl;
3618 };
3619 i++;
3620 }
3621
3622 // ToF
3623 if(TOF) {
3624 pam_tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");
3625 pam_tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));
3626 cout << "ToF : branch ToFLevel2"<<endl;
3627 i++;
3628 };
3629 // Trigger
3630 if(TRG) {
3631 pam_tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");
3632 pam_tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));
3633 cout << "Trigger : branch TrigLevel2"<<endl;
3634 i++;
3635 };
3636 // S4
3637 if(S4) {
3638 pam_tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");
3639 pam_tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));
3640 cout << "S4 : branch S4Level2"<<endl;
3641 i++;
3642 };
3643 // Neutron Detector
3644 if(ND) {
3645 pam_tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");
3646 pam_tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));
3647 cout << "NeutronD : branch NDLevel2"<<endl;
3648 i++;
3649 };
3650 // Anticounters
3651 if(AC) {
3652 pam_tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");
3653 pam_tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));
3654 cout << "Anticounter : branch AcLevel2"<<endl;
3655 i++;
3656 };
3657 // OrbitalInfo
3658 if(ORB) {
3659 pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info ");
3660 pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));
3661 cout << "OrbitalInfo : branch OrbitalInfo"<<endl;
3662 i++;
3663 };
3664 // GPamela
3665 if(GP) {
3666 pam_tree_clone[i] = new TTree("h20","PAMELA oribital info ");
3667 pam_tree_clone[i]->Branch("GPamela","GPamela", GetPointerTo("GPamela"),32000,1);//split
3668 cout << "OrbitalInfo : branch OrbitalInfo"<<endl;
3669 i++;
3670 };
3671 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3672
3673 }
3674
3675
3676 /**
3677 * Fill tree (created with CreateCloneTrees)
3678 *
3679 */
3680 //void PamLevel2::FillNewPamTree(TTree *T){
3681 void PamLevel2::FillCloneTrees(){
3682
3683 // cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;
3684
3685 for(Int_t i=0; i<NCLONES; i++){
3686 if(pam_tree_clone[i])pam_tree_clone[i]->Fill();
3687 }
3688 if(sel_tree_clone)sel_tree_clone->Fill();
3689
3690 }
3691
3692
3693 TTree* PamLevel2::GetCloneTree(TString name){
3694
3695 for(Int_t i=0; i<NCLONES; i++){
3696 if(pam_tree_clone[i]){
3697 TString na = pam_tree_clone[i]->GetName();
3698 if(!name.CompareTo(na))return pam_tree_clone[i];
3699 };
3700 }
3701 if(run_tree_clone){
3702 TString na = run_tree_clone->GetName();
3703 if(!name.CompareTo(na))return run_tree_clone;
3704 }
3705 if(sel_tree_clone){
3706 TString na = sel_tree_clone->GetName();
3707 if(!name.CompareTo(na))return sel_tree_clone;
3708 }
3709 return NULL;
3710
3711 }
3712 void PamLevel2::WriteCloneTrees(){
3713 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3714 cout << "Write clones of PAMELA trees "<<endl;
3715 cout << run_tree_clone->GetName()<<endl;
3716 if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
3717 run_tree_clone->GetBranch("DeadLiveTime")->Fill();
3718 run_tree_clone->Write();
3719 cout << sel_tree_clone->GetName()<<endl;
3720 sel_tree_clone->Write();
3721 for(Int_t i=0; i<NCLONES; i++){
3722 if(pam_tree_clone[i]){
3723 cout << pam_tree_clone[i]->GetName()<<endl;
3724 pam_tree_clone[i]->Write();
3725 };
3726 }
3727 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3728
3729 }
3730
3731 /**
3732 * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.
3733 */
3734 //Int_t PamLevel2::GetEntry(Int_t iee){
3735 Int_t PamLevel2::GetEntry(Long64_t iee){
3736
3737 // cout << "-------------------------------------"<<endl;
3738 // cout << "Int_t PamLevel2::GetEntry("<<iee<<")"<<endl;
3739
3740 if(!pam_tree){
3741 cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded"<<endl;
3742 return 0;
3743 }
3744
3745
3746 //
3747 // This is a sort of bug: if you don't have the run tree you don't want to exit here you want to have loaded the event anyway...
3748 //
3749 // if(!run_tree ){
3750 // cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl;
3751 // return 0;
3752 // }
3753
3754 Long64_t ii=0;
3755 //-------------------------------
3756 ii = iee;
3757 if( !pam_tree->GetEntry(ii) ){
3758 cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<<endl;
3759 return 0;
3760 }
3761
3762 //
3763 // ... that's way I put it here. Notice that nothing change in the code (is backward compatible) since in any case you return with 0.
3764 // in theory one would like to return 1 if run is not loaded but now I don't have the will to add that 2 lines of code and it is not
3765 // a problem if you don't check the return code of getentry.
3766 //
3767 if(!run_tree ){
3768 if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?
3769 cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
3770 return 0;
3771 } else {
3772 return 1; //cosi` se non c'e` run esce qua...
3773 }
3774 }
3775
3776 //-------------------------------
3777 ii = iee;
3778 // Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
3779 // Bool_t UPDATED = UpdateRunInfo(ii);
3780 UpdateRunInfo(ii);
3781 if(SELLI==0)irunentry = iee-runfirstentry;
3782 // if(UPDATED && run_tree_clone)run_tree_clone->Fill();
3783
3784 // cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
3785
3786 // cout << "irunentry "<<irunentry << endl;
3787 // cout << "runfirstentry "<<runfirstentry << endl;
3788 // cout << "nevents "<<GetRunInfo()->NEVENTS<< endl;
3789
3790 // if( TRK0 || CAL0 || TOF0 ){
3791 // if( !GetYodaEntry( ) ){
3792 // cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl;
3793 // return 0;
3794 // }
3795 // }
3796
3797
3798 return 1;
3799
3800 }
3801
3802 TrkLevel0 *PamLevel2::GetTrkLevel0(){
3803 if( !TRK0 )return NULL;
3804 if( !GetYodaEntry( ) ){
3805 cout << " Int_t PamLevel2::GetTrkLevel0() -- ERROR -- error reading level0 tree"<<endl;
3806 return 0;
3807 }
3808 return trk0_obj;
3809 };
3810 CaloLevel0 *PamLevel2::GetCaloLevel0(){
3811 if( !CAL0 )return NULL;
3812 if( !GetYodaEntry( ) ){
3813 cout << " Int_t PamLevel2::GetCaloLevel0() -- ERROR -- error reading level0 tree"<<endl;
3814 return 0;
3815 }
3816 return calo0_obj;
3817 };
3818
3819
3820 /**
3821 * Method to retrieve the level0 tree (YODA tree) that contains the current event.
3822 * Given the run ID (...), if needed it query the DB and load the proper file.
3823 * @return Pointer to the tree
3824 */
3825
3826
3827 TTree* PamLevel2::GetYodaTree( ){
3828
3829 // cout << "TTree* PamLevel2::GetYodaTree( )"<<endl;
3830 //===================================
3831 // check if iroot has changed
3832 //===================================
3833 if( irun<0 ){
3834 cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = "<<irun<<endl;
3835 // cout << "In order to use this method you have to first load the RunInfo tree "<<endl;
3836 return NULL;
3837 }
3838 Int_t irootnew = run_obj->ID_ROOT_L0;
3839 // cout << "iroot "<<iroot<<endl;
3840 // cout << "irootnew "<<irootnew<<endl;
3841
3842 //===================================
3843 // load the level0 file
3844 // (if not already loaded)
3845 //===================================
3846 if( iroot != irootnew || !l0_tree){
3847 iroot = irootnew;
3848 //===================================
3849 // open the DB connection
3850 // (if not already opened)
3851 //===================================
3852 if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
3853 GL_ROOT glroot = GL_ROOT();
3854 if( glroot.Query_GL_ROOT(iroot,dbc) ){
3855 cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;
3856 return NULL;
3857 };
3858 TString filename = glroot.PATH + glroot.NAME;
3859 if(l0_file){
3860 l0_file->Close();
3861 l0_file->Delete();
3862 }
3863 cout << "Opening LEVEL0 file: "<< filename << endl;
3864 FileStat_t t;
3865 if( gSystem->GetPathInfo(filename.Data(),t) ){
3866 cout << " PamLevel2::GetYodaTree() -- ERROR opening file "<<endl;
3867 return NULL;
3868 }
3869 l0_file = new TFile(filename);
3870 if( !l0_file )return NULL;
3871 l0_tree = (TTree*)l0_file->Get("Physics");
3872 if(!h0_obj)h0_obj = new EventHeader();
3873 l0_tree->SetBranchAddress("Header" ,&h0_obj);
3874 prevshift = 0;
3875 //---------------------------------------------------
3876 // TRACKER:
3877 if(TRK0){
3878 if(!trk0_obj){
3879 trk0_obj = new TrkLevel0();
3880 trk0_obj->Set();
3881 };
3882 l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());
3883 }
3884 //--------------------------------------------------
3885 // CALORIMETER:
3886 if(CAL0){
3887 if(!calo0_obj){
3888 calo0_obj = new CaloLevel0();
3889 calo0_obj->Set();
3890 };
3891 l0_tree->SetBranchAddress("Calorimeter" ,calo0_obj->GetPointerToCalorimeterEvent());
3892 // cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;
3893 }
3894 //---------------------------------------------------
3895 // TOF:
3896 if(TOF0){
3897 cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
3898 }
3899
3900 dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
3901
3902
3903 };
3904
3905 // if(!dbc || (dbc && !dbc->IsConnected())){
3906 // cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;
3907 // }
3908
3909 if ( TRK0 ){
3910 TrkParams::Load(6);
3911 if( !TrkParams::IsLoaded(6) ){
3912 cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;
3913 };
3914 if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
3915 TrkParams::SetCalib(run_obj,dbc);
3916 TrkParams::LoadCalib( );
3917 if( !TrkParams::CalibIsLoaded() ){
3918 cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;
3919 };
3920 dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
3921 }
3922
3923
3924 // cout << l0_tree << endl;
3925 return l0_tree;
3926
3927 }
3928
3929 /**
3930 * Method to retrieve the level0 tree (YODA tree) that contains the current event.
3931 */
3932 Int_t PamLevel2::GetYodaEntry(){
3933
3934 // cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;
3935 if(!GetYodaTree())return 0;
3936
3937 // patch
3938 if( irunentry < 0){
3939 // cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
3940 irunentry=0LL;
3941 }
3942 // ---------------------------------
3943 // if file is NOT a preselected file
3944 // ---------------------------------
3945 Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM);
3946 // cout << " irunentry "<<irunentry<<endl;
3947 // cout << " EV_FROM "<<run_obj->EV_FROM<<endl;
3948 // cout << " quellagiusta = irunentry + EV_FROM "<< quellagiusta << endl;
3949
3950 // cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
3951 // cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
3952 // cout << " time "<< abstime << endl;
3953 // cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;
3954
3955 ULong64_t obt = 0;
3956 ULong64_t pktn = 0;
3957 if( GetOrbitalInfo() ){
3958 obt = GetOrbitalInfo()->OBT;
3959 pktn = GetOrbitalInfo()->pkt_num;
3960 }
3961
3962 if( !GetOrbitalInfo() && !ISGP){
3963 cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;
3964 return 0;
3965 }
3966 if( obt==0 && pktn==0 && !ISGP ){
3967 cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl;
3968 return 0;
3969 }
3970
3971 // ---------------------------------------------------------------------
3972 // ATTENTION!!!
3973 // If data are not pre-processed with cleaner, the level0 tree may contain
3974 // spurious nested physics packets.
3975 // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries
3976 // while level2 tree DOES NOT!!
3977 // This means that "quellagiusta" in these cases is not correct.
3978 // In order to retrieve the correct level0 event, I implemented a check
3979 // of the OBT and pkt-number. In case of mismatch, the level0 entry number
3980 // is shift forward until when the packets match.
3981 // ---------------------------------------------------------------------
3982 Int_t answer = 0;
3983 Int_t shift =0;
3984 // printf(" siamo qui %i %i \n",shift,prevshift);
3985 // Int_t maxshift = 50; // EMILIANO
3986 do{
3987 if(shift>0){
3988 cout << " PKTNUM L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
3989 cout << " RUN: ID "<< GetRunInfo()->ID << " ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<" ID_RUN_FRAG "<<GetRunInfo()->ID_RUN_FRAG << " EV_FROM "<<GetRunInfo()->EV_FROM <<endl;
3990 cout << " L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;
3991 }
3992 answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);
3993 shift++;
3994 if( !GetEventHeader() ){
3995 cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;
3996 return 0;
3997 }
3998
3999 if(ISGP){
4000 obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO
4001 pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO
4002 }
4003
4004 // cout << "PKTNUM "<<shift<<" == L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
4005 // cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;
4006 // if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;
4007 // cout << " obt "<< obt << endl;
4008 // cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;
4009 // cout << " pktn "<< pktn << endl;
4010 // cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
4011 // printf(" IDRUN %u \n",GetRunInfo()->ID);
4012 //
4013 if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){
4014 prevshift = 0;
4015 shift = -1;
4016 };
4017
4018 }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||
4019 pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) )
4020 && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);
4021
4022 if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {
4023 cout << " Big trouble here, no such event in Level0 data! " <<endl;
4024 return 0;
4025 }
4026 // cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
4027 // return GetYodaTree()->GetEntry(quellagiusta);
4028 if ( shift > 1 ) prevshift += (shift-1);
4029
4030 return answer;
4031
4032 }
4033 /**
4034 * \Brief Set DB connection
4035 */
4036 Bool_t PamLevel2::SetDBConnection(){
4037
4038 cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
4039 cout<<"Connecting to DB"<<endl;
4040 cout<<"HOST "<<host<<endl;
4041 cout<<"USER "<<user<<endl;
4042 cout<<"PSW "<<psw<<endl;
4043 dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
4044 if( !dbc )return false;
4045 if( !dbc->IsConnected() )return false;
4046 stringstream myquery; // EMILIANO
4047 myquery.str(""); // EMILIANO
4048 myquery << "SET time_zone='+0:00'"; // EMILIANO
4049 dbc->Query(myquery.str().c_str()); // EMILIANO
4050 cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
4051 return true;
4052
4053 }
4054
4055 /**
4056 * \Brief Add a friend to the pamela chain.
4057 * @param cname name of the chain to be added
4058 */
4059
4060 TChain* PamLevel2::AddFriend(TString cname){
4061
4062 if(!GetPamTree()){
4063 cout << " TChain* PamLevel2::AddFriend(TString cname) --- a pamela tree must be created first"<<endl;
4064 return NULL;
4065 }
4066
4067
4068 TChain *c = new TChain( cname.Data() );
4069
4070 TIter next( GetPamTree()->GetListOfFiles() );
4071 Int_t nf = 0;
4072 TChainElement* element = 0;
4073 while ((element = (TChainElement*) next())) {
4074 c->Add(element->GetTitle());
4075 nf++;
4076 }
4077
4078 GetPamTree()->AddFriend(cname.Data());
4079
4080 cout << "external chain created and added to pamela friends :"<<cname<<endl;
4081 cout << "n.files "<<nf<<endl;
4082
4083
4084 return c;
4085
4086 }
4087
4088

  ViewVC Help
Powered by ViewVC 1.1.23