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

Contents of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.50 - (show annotations) (download)
Fri Oct 26 09:08:51 2007 UTC (17 years, 4 months ago) by mocchiut
Branch: MAIN
Changes since 1.49: +2 -1 lines
Added method PamLevel2::SetMaxShift(Int_t shift) in order to handle maximum discrepancy btw L2 and L0 data

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

  ViewVC Help
Powered by ViewVC 1.1.23