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

Contents of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (show annotations) (download)
Thu Jan 18 08:51:16 2007 UTC (18 years, 1 month ago) by pam-fi
Branch: MAIN
Changes since 1.17: +23 -15 lines
removed call to gSystem->IsFileInIncludePath(....)

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 };
15 //--------------------------------------
16 //
17 //
18 //--------------------------------------
19 /**
20 * Constructor
21 */
22 PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o){
23
24 trk_track = 0;
25 calo_track = 0;
26 tof_track = 0;
27 // if(t)trk_track = new TrkTrack(*t);
28 // if(c)calo_track = new CaloTrkVar(*c);
29 // if(o)tof_track = new ToFTrkVar(*o);
30 if(t)trk_track = t;
31 if(c)calo_track = c;
32 if(o)tof_track = o;
33 candeleteobj = 0;
34
35 };
36 PamTrack::PamTrack(const PamTrack& track){
37
38 TrkTrack *t = track.trk_track;
39 CaloTrkVar *c = track.calo_track;
40 ToFTrkVar *o = track.tof_track;
41
42 trk_track = 0;
43 calo_track = 0;
44 tof_track = 0;
45 if(t)trk_track = new TrkTrack(*t);
46 if(c)calo_track = new CaloTrkVar(*c);
47 if(o)tof_track = new ToFTrkVar(*o);
48 candeleteobj = 1;
49
50 }
51 void PamTrack::Clear(){
52
53 // cout << "PamTrack::Clear() "<<candeleteobj<<endl;
54 if(candeleteobj){
55 if(trk_track) trk_track->TrkTrack::Clear();
56 if(calo_track) calo_track->CaloTrkVar::Clear();//???
57 if(tof_track) tof_track->ToFTrkVar::Clear();//???
58 }else{
59 trk_track = 0;
60 calo_track = 0;
61 tof_track = 0;
62 }
63 }
64 void PamTrack::Delete(){
65 // cout << "PamTrack::Delete() "<<candeleteobj<<endl;
66 if(candeleteobj){
67 if(trk_track) {
68 trk_track->TrkTrack::Clear();
69 delete trk_track;
70 }
71 if(calo_track){
72 calo_track->CaloTrkVar::Clear();//???
73 delete calo_track;
74 }
75 if(tof_track){
76 tof_track->ToFTrkVar::Clear();//???
77 delete tof_track;
78 }
79 }else{
80 Clear();
81 }
82 }
83 //--------------------------------------
84 //
85 //
86 //--------------------------------------
87 /**
88 * Constructor
89 */
90 PamLevel2::PamLevel2(){
91
92 // trk2_obj = TrkLevel2::GetTrkLevel2();
93 // trk1_obj = TrkLevel1::GetTrkLevel1();
94 // trkh_obj = TrkHough::GetTrkHough();
95 // calo1_obj = CaloLevel1::GetCaloLevel1();
96 // calo2_obj = CaloLevel2::GetCaloLevel2();
97 // tof_obj = ToFLevel2::GetToFLevel2();
98 // trig_obj = TrigLevel2::GetTrigLevel2();
99 // s4_obj = S4Level2::GetS4Level2();
100 // nd_obj = NDLevel2::GetNDLevel2();
101 // ac_obj = AcLevel2::GetAcLevel2();
102 // orb_obj = OrbitalInfo::GetOrbitalInfo();
103 trk2_obj = 0;
104 trk1_obj = 0;
105 trkh_obj = 0;
106 calo1_obj = 0;
107 calo2_obj = 0;
108 tof_obj = 0;
109 trig_obj = 0;
110 s4_obj = 0;
111 nd_obj = 0;
112 ac_obj = 0;
113 orb_obj = 0;
114
115 run_obj = 0;//new GL_RUN();
116 soft_obj = 0;// Emiliano
117 irun = -1;
118 runfirstentry = 0ULL;
119 runlastentry = 0ULL;
120
121 for(Int_t i=0; i<8; i++ )tree_clone[i]=NULL;
122
123 // sorted_tracks = 0;//new TRefArray();
124
125 CAL1 = true;
126 CAL2 = true;
127 TRK2 = true;
128 TRK1 = false;
129 TRKh = false;
130 TRG = true;
131 TOF = true;
132 S4 = true;
133 ND = true;
134 AC = true;
135 ORB = true;
136
137 RUN = true;
138
139 tsorted=0;
140 timage=0;
141
142 };
143 /**
144 * Delete the event (act as Dtor)
145 */
146 void PamLevel2::Delete(){
147
148 if(run_obj)delete run_obj;
149 if(soft_obj)delete soft_obj; //Emiliano
150
151 // cout << "void PamLevel2::Clear()"<<endl;
152 if(trk1_obj) delete trk1_obj;
153 if(trk2_obj) delete trk2_obj;
154 if(trkh_obj) delete trkh_obj;
155 if(calo1_obj)delete calo1_obj;
156 if(calo2_obj)delete calo2_obj;
157 if(tof_obj) delete tof_obj;
158 if(trig_obj) delete trig_obj;
159 if(s4_obj) delete s4_obj;
160 if(nd_obj) delete nd_obj;
161 if(ac_obj) delete ac_obj;
162 if(orb_obj) delete orb_obj;
163
164 if(tsorted){
165 tsorted->Delete();
166 delete tsorted;
167 }
168 if(timage){
169 timage->Delete();
170 delete timage;
171 }
172 };
173
174 /**
175 * Clear the event (NB! does not deallocate objects)
176 */
177 void PamLevel2::Clear(){
178
179 // cout << "void PamLevel2::Clear()"<<endl;
180
181 //
182 // 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
183 // want to load them for each event even if they are the same...
184 //
185 // if(run_obj)delete run_obj;
186 // if(run_obj) run_obj->Clear(); // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead
187 // if(soft_obj) soft_obj->Clear();
188
189 if(trk1_obj) trk1_obj->Clear();
190 if(trk2_obj) trk2_obj->Clear();
191 if(trkh_obj) trkh_obj->Clear();
192 if(calo1_obj)calo1_obj->Clear();
193 if(calo2_obj)calo2_obj->Clear();
194 if(tof_obj) tof_obj->Clear();
195 if(trig_obj) trig_obj->Clear();
196 if(s4_obj) s4_obj->Clear();
197 if(nd_obj) nd_obj->Clear();
198 if(ac_obj) ac_obj->Clear();
199 if(orb_obj) orb_obj->Clear();
200
201 // if(sorted_tracks)sorted_tracks->Clear();
202 // sorted_tracks.Clear();
203
204 if(tsorted){
205 tsorted->Delete();
206 }
207 if(timage){
208 timage->Delete();
209 }
210
211 };
212
213
214 //--------------------------------------
215 //
216 //
217 //--------------------------------------
218 void *PamLevel2::GetPointerTo(const char* c ){
219
220 TString objname = c;
221
222 if(!objname.CompareTo("TrkLevel1")) {
223 if(!trk1_obj){
224 trk1_obj = new TrkLevel1();
225 trk1_obj->Set();
226 }
227 return &trk1_obj;
228 };
229 if(!objname.CompareTo("TrkLevel2")) {
230 if(!trk2_obj){
231 trk2_obj = new TrkLevel2();
232 trk2_obj->Set();
233 }
234 return &trk2_obj;
235 };
236 if(!objname.CompareTo("TrkHough")) {
237 if(!trkh_obj) trkh_obj = new TrkHough();
238 return &trkh_obj;
239 };
240 if(!objname.CompareTo("CaloLevel1")) {
241 if(!calo1_obj) calo1_obj = new CaloLevel1();
242 return &calo1_obj;
243 };
244 if(!objname.CompareTo("CaloLevel2")) {
245 if(!calo2_obj){
246 calo2_obj = new CaloLevel2();
247 calo2_obj->Set();
248 };
249 return &calo2_obj;
250 };
251 if(!objname.CompareTo("ToFLevel2")) {
252 if(!tof_obj){
253 tof_obj = new ToFLevel2();
254 tof_obj->Set();
255 }
256 return &tof_obj;
257 };
258 if(!objname.CompareTo("TrigLevel2")) {
259 if(!trig_obj) trig_obj = new TrigLevel2();
260 return &trig_obj;
261 };
262 if(!objname.CompareTo("S4Level2")) {
263 if(!s4_obj) s4_obj = new S4Level2();
264 return &s4_obj;
265 };
266 if(!objname.CompareTo("NDLevel2")) {
267 if(!nd_obj) nd_obj = new NDLevel2();
268 return &nd_obj;
269 };
270 if(!objname.CompareTo("AcLevel2")) {
271 if(!ac_obj) ac_obj = new AcLevel2();
272 return &ac_obj;
273 };
274 if(!objname.CompareTo("OrbitalInfo")){
275 if(!orb_obj) orb_obj = new OrbitalInfo();
276 return &orb_obj;
277 };
278
279 if(!objname.CompareTo("RunInfo"))return &run_obj;
280
281 if(!objname.CompareTo("SoftInfo"))return &soft_obj; // Emiliano
282
283 return NULL;
284 };
285 //--------------------------------------
286 //
287 //
288 //--------------------------------------
289 /**
290 * Retrieves the calorimeter track matching the seqno-th tracker stored track.
291 * (If seqno = -1 retrieves the self-trigger calorimeter track)
292 */
293 CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
294
295 if( !calo2_obj )return 0;
296
297 if( calo2_obj->CaloLevel2::ntrk()==0 ){
298 cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;
299 return NULL;
300 };
301
302 CaloTrkVar *c = 0;
303 Int_t it_calo=0;
304
305 do{
306 c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
307 it_calo++;
308 } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());
309
310 if(!c || seqno != c->trkseqno){
311 c = 0;
312 if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;
313 };
314 return c;
315
316 };
317 //--------------------------------------
318 //
319 //
320 //--------------------------------------
321 /**
322 * Retrieves the ToF track matching the seqno-th tracker stored track.
323 * (If seqno = -1 retrieves the tracker-independent tof track)
324 */
325 ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
326
327 if( !tof_obj )return 0;
328
329 if( tof_obj->ToFLevel2::ntrk()==0 ){
330 cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;
331 return NULL;
332 };
333
334 ToFTrkVar *c = 0;
335 Int_t it_tof=0;
336
337 do{
338 c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);
339 it_tof++;
340 } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());
341
342 if(!c || seqno != c->trkseqno){
343 c = 0;
344 if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;
345 };
346 return c;
347
348 };
349
350 //--------------------------------------
351 //
352 //
353 //--------------------------------------
354 /**
355 * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.
356 */
357 PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
358
359 cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;
360 cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
361
362 CaloTrkVar *c = 0;
363 ToFTrkVar *o = 0;
364
365 if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());
366 if(TOF) o = GetToFStoredTrack(t->GetSeqNo());
367
368 // if(t && c && o)track = new PamTrack(t,c,o);
369 PamTrack *track = new PamTrack(t,c,o);
370
371 return track;
372
373 };
374 //--------------------------------------
375 //
376 //
377 //--------------------------------------
378 /**
379 * Retrieves the it-th stored track.
380 * It override TrkLevel2::GetTrack(int it).
381 * @param itrk Track number, ranging from 0 to GetNTracks().
382 */
383
384 PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
385
386 cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;
387 cout <<"for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack)"<<endl;
388 cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
389 PamTrack *track = 0;
390
391 if( itrk >=0 && itrk < trk2_obj->TrkLevel2::ntrk() ){
392
393 TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk);
394 track = GetPamTrackAlong(t);
395
396
397
398 }else{
399 cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
400 };
401
402 return track;
403
404 }
405 //--------------------------------------
406 //
407 //
408 //--------------------------------------
409 /**
410 * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is PamLevel2::sorted_tracks.
411 * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...).
412 * Sorting cryteria:
413 * TRK: lower chi**2
414 * CAL: lower Y spatial residual on the first calorimeter plane
415 * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis).
416 * The default sorting cryterium is "TOF+CAL".
417 *
418 * 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).
419 */
420 void PamLevel2::SortTracks(TString how){
421
422 // cout <<" PamLevel2::SortTracks(TString how) "<<endl;
423 if( !trk2_obj ){
424 cout << "void PamLevel2::SortTracks(TString how): TrkLevel2 not loaded !!!";
425 return;
426 };
427 // cout << "call SortTracs() "<<endl;
428 //Save current Object count
429 Int_t ObjectNumber = TProcessID::GetObjectCount();
430
431 // cout << "ObjectNumber "<<ObjectNumber <<endl;
432
433 // if(!sorted_tracks)sorted_tracks = new TRefArray();
434 // sorted_tracks->Clear();
435 // sorted_tracks.Clear();
436
437 if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
438 tsorted->Delete();
439 TClonesArray &ttsorted = *tsorted;
440 if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
441 timage->Delete();
442 TClonesArray &ttimage = *timage;
443
444
445 // loop over the tracks sorted by the tracker
446 Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
447 Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
448 Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
449
450 if( !CAL2 && use_CAL) use_CAL = false;
451 if( !TOF && use_TOF) use_TOF = false;
452
453 if( !TRK2 ){
454 // cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
455 return;
456 };
457
458 // cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
459
460 for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
461
462 TrkTrack *ts = 0;
463 CaloTrkVar *cs = 0;
464 ToFTrkVar *os = 0;
465
466 // get tracker tracks
467 TrkTrack *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
468 CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
469 ToFTrkVar *op = GetToFStoredTrack(tp->GetSeqNo());
470
471 TrkTrack *ti = 0; //tracker (image)
472 CaloTrkVar *ci = 0;
473 ToFTrkVar *oi = 0;
474 // cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
475 // if track has an image, check image selection
476 if(tp->HasImage()){
477
478 ti = trk2_obj->TrkLevel2::GetTrackImage(i); //tracker (image)
479 ci = GetCaloStoredTrack(ti->GetSeqNo());
480 oi = GetToFStoredTrack(ti->GetSeqNo());
481
482 // cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
483
484 //assign starting scores
485 Int_t tp_score = 0; //main track sorted by the tracker
486 Int_t ti_score = 0; //image track
487
488 // ------------------------
489 // calorimeter check
490 // ------------------------
491 // check the Y spatial residual on the first calorimeter plane
492 // (cut on calorimeter variables from Emiliano)
493 if( use_CAL && !calo2_obj ){
494 cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but CaloLevel2 not loaded !!!";
495 return;
496 };
497 if(
498 use_CAL &&
499 calo2_obj->npcfit[1] > 15 && //no. of fit planes on Y view
500 calo2_obj->varcfit[1] < 1000. && //fit variance on Y view
501 true){
502
503
504 Float_t resy_p = cp->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_p < 0)resy_p= - resy_p;
505 Float_t resy_i = ci->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_i < 0)resy_i= - resy_i;
506
507 if(resy_p <= resy_i) tp_score++;
508 else ti_score++;
509
510 // cout << "CALO "<<tp_score<<ti_score<<endl;
511
512 };
513 // ------------------------
514 // TOF check
515 // ------------------------
516 // check the number of hit pmts along the track
517 // on S12 S21 and S32, where paddles are parallel to Y axis
518 if( use_TOF && !tof_obj ){
519 cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but ToFLevel2 not loaded !!!";
520 return;
521 };
522 if( use_TOF ){
523
524 Int_t nphit_p =0;
525 Int_t nphit_i =0;
526
527
528 /* cout << "track: npmtadc "<< op->npmtadc << endl;
529 cout << "track: npmttdc "<< op->npmttdc << endl;
530 cout << "image: npmtadc "<< oi->npmtadc << endl;
531 cout << "image: npmttdc "<< oi->npmttdc << endl;*/
532
533 for (Int_t ih=0; ih < op->npmtadc; ih++){
534 Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
535 if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
536 };
537
538 for (Int_t ih=0; ih < oi->npmtadc; ih++){
539 Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
540 if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
541 };
542
543 if(
544 use_TOF &&
545 (nphit_p+nphit_i) !=0 &&
546 true){
547
548 if( nphit_p >= nphit_i) tp_score++;
549 else ti_score++;
550 };
551 // cout << "TOF "<<tp_score<<ti_score<<endl;
552 };
553 if(tp_score == ti_score) use_TRK = true;
554 // ------------------------
555 // tracker check
556 // ------------------------
557 // chi**2 difference is not always large enough to distinguish among
558 // the real track and its image.
559 // Tracker check will be applied always when calorimeter and tof information is ambiguous.
560 if(use_TRK){
561 if( tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
562 else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
563 // cout << "TRK "<<tp_score<<ti_score<<endl;
564 };
565
566 // ------------------------
567 // the winner is....
568 // ------------------------
569 if (tp_score > ti_score) {
570 // ts = tp;//the track sorted by the tracker!!
571 // cs = cp;
572 // os = op;
573 }else if (tp_score < ti_score) {
574 ts = ti;//its image!!
575 cs = ci;
576 os = oi;
577
578 ti = tp;//its image!!
579 ci = cp;
580 oi = op;
581
582 tp = ts;//its image!!
583 cp = cs;
584 op = os;
585
586
587 }else {
588 // ts = tp;
589 // cs = cp;
590 // os = op;
591 // cout << "Warning - track image ambiguity not solved" << endl;
592 // cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;
593 };
594
595 }else{
596 // ts = tp;
597 // cs = cp;
598 // os = op;
599 };
600
601 // cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
602 // sorted_tracks->Add(ts);//save the track in the sorted array
603 // sorted_tracks.Add(ts);//save the track in the sorted array
604 // sorted_tracks.Add(tp);//save the track in the sorted array
605 // cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
606 // cout<<"o "<<tp<<endl;
607 // cout<<"o "<<cp<<endl;
608 // cout<<"o "<<op<<endl;
609 new(ttsorted[i]) PamTrack(tp,cp,op);
610 new(ttimage[i]) PamTrack(ti,ci,oi);
611 };
612
613 if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
614 cout << "void PamLevel2::SortTracks(TString how): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;
615 tsorted->Delete(); tsorted=0;
616 timage->Delete(); timage=0;
617 }
618
619 //Restore Object count
620 //To save space in the table keeping track of all referenced objects
621 //We reset the object count to what it was at the beginning of the event.
622 TProcessID::SetObjectCount(ObjectNumber);
623
624 };
625 //--------------------------------------
626 //
627 //
628 //--------------------------------------
629 /**
630 * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.
631 * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.
632 */
633 // TRefArray *PamLevel2::GetTracks(){
634
635 // // *-*-*-*-*-*-*-*-*-*-*-*-*
636 // SortTracks("+CAL+TOF");
637 // // *-*-*-*-*-*-*-*-*-*-*-*-*
638
639 // // return sorted_tracks;
640 // return &sorted_tracks;
641
642 // };
643 TClonesArray *PamLevel2::GetTracks(){
644
645 // *-*-*-*-*-*-*-*-*-*-*-*-*
646 SortTracks("+CAL+TOF");
647 // *-*-*-*-*-*-*-*-*-*-*-*-*
648
649 return tsorted;
650
651 };
652 //--------------------------------------
653 //
654 //
655 //--------------------------------------
656 /**
657 * Retrieves the it-th Pamela "physical" track.
658 * It override TrkLevel2::GetTrack(int it).
659 * @param it Track number, ranging from 0 to GetNTracks().
660 */
661 PamTrack *PamLevel2::GetTrack(int it){
662
663 // if(!trk2_obj) return 0;
664
665 // // *-*-*-*-*-*-*-*-*-*-*-*-*
666 // SortTracks("+CAL+TOF");
667 // // *-*-*-*-*-*-*-*-*-*-*-*-*
668 // // if(!sorted_tracks)return 0;
669 // if(sorted_tracks.IsEmpty())return 0;
670
671 // PamTrack *track = 0;
672
673 // if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() && it<sorted_tracks.GetEntriesFast() ){
674 // TrkTrack *t = (TrkTrack*)sorted_tracks.At(it);
675 // track = GetPamTrackAlong(t);
676 // }else{
677 // cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
678 // };
679
680 // return track;
681
682 // cout << "PamLevel2::GetTrack(int it) "<<endl;
683 // *-*-*-*-*-*-*-*-*-*-*-*-*
684 SortTracks("+CAL+TOF");
685 // *-*-*-*-*-*-*-*-*-*-*-*-*
686 if(!tsorted)return 0;
687 if(!tsorted->GetEntries())return 0;
688
689 PamTrack *track = 0;
690
691 if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks()){
692 // TrkTrack *t = (TrkTrack*)sorted_tracks.At(it);
693 // track = GetPamTrackAlong(t);
694 TClonesArray &t = *(tsorted);
695 track = (PamTrack*)t[it];
696
697 }else{
698 cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
699 };
700
701 return track;
702
703 };
704
705 //--------------------------------------
706 //
707 //
708 //--------------------------------------
709 /**
710 * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().
711 * @param it Track number, ranging from 0 to GetNTracks().
712 */
713 PamTrack *PamLevel2::GetTrackImage(int it){
714
715 // if(!trk2_obj) return 0;
716
717 // // *-*-*-*-*-*-*-*-*-*-*-*-*
718 // SortTracks("+CAL+TOF");
719 // // *-*-*-*-*-*-*-*-*-*-*-*-*
720 // // if(!sorted_tracks)return 0;
721 // if(sorted_tracks.IsEmpty())return 0;
722
723 // PamTrack *image = 0;
724
725 // if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){
726 // TrkTrack *temp = (TrkTrack*)sorted_tracks.At(it);
727 // if( temp->HasImage() ){
728 // TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());
729 // image = GetPamTrackAlong(t);
730 // }else{
731 // cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
732 // };
733 // }else{
734 // cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
735 // };
736
737 // return image;
738
739
740 // *-*-*-*-*-*-*-*-*-*-*-*-*
741 SortTracks("+CAL+TOF");
742 // *-*-*-*-*-*-*-*-*-*-*-*-*
743 if(!timage)return 0;
744 if(!timage->GetEntries())return 0;
745
746 PamTrack *image = 0;
747
748 if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){
749 TClonesArray &t = *(tsorted);
750 PamTrack *temp = (PamTrack*)t[it];
751 if( temp->GetTrkTrack()->HasImage() ){
752 TClonesArray &t = *(timage);
753 image = (PamTrack*)t[it];
754 }else{
755 // cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
756 };
757 }else{
758 cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
759 };
760
761 return image;
762 }
763
764 //--------------------------------------
765 //
766 //
767 //--------------------------------------
768 /**
769 * Get the Pamela detector trees in a single file and make them friends.
770 * @param f TFile pointer
771 * @param detlist String to select trees to be included
772 * @return Pointer to a TTree
773 */
774 TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){
775
776 // if( !detlist.IsNull() ) SetWhichTrees(detlist);
777 // else GetWhichTrees(f);
778 SetWhichTrees(detlist);
779
780 TTree *Trout =0;
781
782 TString fname = f->GetName();
783 if(!CheckLevel2File(fname))return NULL;
784
785 UInt_t *found=0;
786
787 cout<< "GetPamTree(TFile*,TString): detector list --> ";
788 if(TRK1)cout<<"TRK1 ";
789 if(TRK2)cout<<"TRK2 ";
790 if(TRKh)cout<<"TRKH ";
791 if(CAL1)cout<<"CAL1 ";
792 if(CAL2)cout<<"CAL2 ";
793 if(TOF)cout<<"TOF ";
794 if(TRG)cout<<"TRG ";
795 if(AC)cout<<"AC ";
796 if(ND)cout<<"ND ";
797 if(S4)cout<<"S4 ";
798 if(ORB)cout<<"ORB ";
799 cout << endl;
800
801 f->cd();
802
803 // Tracker
804 TTree *T = (TTree*)f->Get("Tracker");
805 if(T && (TRK2||TRK1||TRKh)) {
806 if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
807 else T->SetBranchStatus("TrkLevel2",0,found);
808 if(TRK2)cout << "Tracker : set branch address TrkLevel2"<<endl;
809 if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
810 else T->SetBranchStatus("TrkLevel1",0,found);
811 if(TRK1)cout << "Tracker : set branch address TrkLevel1"<<endl;
812 if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
813 else T->SetBranchStatus("TrkHough",0,found);
814 if(TRKh)cout << "Tracker : set branch address TrkHough"<<endl;
815 if(!Trout)Trout=T;
816 else Trout->AddFriend(T);
817 }else{
818 cout << "Tracker : missing tree"<<endl;
819 };
820 // Calorimeter
821 TTree *C = (TTree*)f->Get("Calorimeter");
822 if(C && (CAL2||CAL1)) {
823 if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
824 else C->SetBranchStatus("CaloLevel2",0,found);
825 if(CAL2)cout << "Calorimeter : set branch address CaloLevel2"<<endl;
826 if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
827 else C->SetBranchStatus("CaloLevel1",0,found);
828 if(CAL1)cout << "Calorimeter : set branch address CaloLevel1"<<endl;
829 if(!Trout)Trout=C;
830 else Trout->AddFriend(C);
831 }else{
832 cout << "Calorimeter : missing tree"<<endl;
833 };
834
835 // ToF
836 TTree *O = (TTree*)f->Get("ToF");
837 if(O && TOF) {
838 O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
839 cout << "ToF : set branch address ToFLevel2"<<endl;
840 if(!Trout)Trout=O;
841 else Trout->AddFriend(O);
842 }else{
843 cout << "ToF : missing tree"<<endl;
844 };
845 // Trigger
846 TTree *R = (TTree*)f->Get("Trigger");
847 if(R && TRG) {
848 R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
849 cout << "Trigger : set branch address TrigLevel2"<<endl;
850 if(!Trout)Trout=O;
851 else Trout->AddFriend(R);
852 }else{
853 cout << "Trigger : missing tree"<<endl;
854 };
855 // S4
856 TTree *S = (TTree*)f->Get("S4");
857 if(S && S4) {
858 S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
859 cout << "S4 : set branch address S4Level2"<<endl;
860 if(!Trout)Trout=O;
861 else Trout->AddFriend(S);
862 }else{
863 cout << "S4 : missing tree"<<endl;
864 };
865 // Neutron Detector
866 TTree *N = (TTree*)f->Get("NeutronD");
867 if(N && ND) {
868 N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
869 cout << "NeutronD : set branch address NDLevel2"<<endl;
870 if(!Trout)Trout=O;
871 else Trout->AddFriend(N);
872 }else{
873 cout << "NeutronD : missing tree"<<endl;
874 };
875 // Anticounters
876 TTree *A = (TTree*)f->Get("Anticounter");
877 if(A && AC) {
878 A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
879 cout << "Anticounter : set branch address AcLevel2"<<endl;
880 if(!Trout)Trout=O;
881 else Trout->AddFriend(A);
882 }else{
883 cout << "Anticounter : missing tree"<<endl;
884 };
885 // Orbital Info
886 TTree *B = (TTree*)f->Get("OrbitalInfo");
887 if(B && ORB) {
888 B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
889 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
890 if(!Trout)Trout=O;
891 else Trout->AddFriend(B);
892 }else{
893 cout << "OrbitalInfo : missing tree"<<endl;
894 };
895
896 cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
897
898 return Trout;
899
900 }
901 //--------------------------------------
902 //
903 //
904 //--------------------------------------
905 /**
906 * Get list of Level2 files.
907 * @param ddir Level2 data directory.
908 * @param flisttxt Name of txt file containing file list.
909 * @return Pointer to a TList of TSystemFiles
910 * If no input file list is given , all the Level2 files inside the directory are processed.
911 */
912 TList* PamLevel2::GetListOfLevel2Files(TString ddir, TString flisttxt = ""){
913
914 TString wdir = gSystem->WorkingDirectory();
915
916 if(ddir=="")ddir = wdir;
917 // TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
918 cout << "Level2 data directory : "<< ddir << endl;
919
920 TList *contents = new TList; // create output list
921 contents->SetOwner();
922
923 // char *fullpath;
924 // const char *fullpath;
925
926 // if no input file list is given:
927 if ( flisttxt != "" ){
928
929 // if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){
930 // if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){
931 // cout <<"File "<<flisttxt<<" not found"<<endl;
932 // return 0;
933 // }
934 // flisttxt = fullpath;
935
936 flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
937
938 if( !gSystem->ChangeDirectory(ddir) ){
939 cout << "Cannot change directory : "<<ddir<<endl;
940 return 0;
941 }
942
943 cout <<"Input file list : " << flisttxt <<endl;
944 ifstream in;
945 in.open(flisttxt, ios::in); //open input file list
946 if(!in.good()){
947 cout <<" ERROR opening the file "<<endl;
948 gSystem->ChangeDirectory(wdir); // back to the working directory
949 return 0;
950 }
951 int line=0;
952 while (1) {
953 TString file;
954 in >> file;
955 if (!in.good()) break;
956 line++;
957 // cout <<"(1) " << file << endl;
958 if(file.IsNull()){
959 cout << "-- list interrupted at line "<<line <<endl;
960 break;
961 }
962 if(file.Contains("#"))file = file(0,file.First("#"));
963 // cout <<"(2) " << file << endl;
964 // if( gSystem->IsFileInIncludePath(file,&fullpath) ){
965 // if( (fullpath = gSystem->FindFile(ddir,file)) ){
966 char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(file));
967 contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
968 delete fullpath;
969 // }else{
970 // if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
971 // };
972 };
973 in.close();
974
975 }else{
976
977 cout << "No input file list given."<<endl;
978 cout << "Check for existing root files."<<endl;
979 // cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
980
981 TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
982 TList *temp = datadir->GetListOfFiles();
983 // temp->Print();
984 // cout << "*************************************" << endl;
985
986 TIter next(temp);
987 TSystemFile *questo = 0;
988
989
990 while ( (questo = (TSystemFile*) next()) ) {
991 TString name = questo-> GetName();
992 if( name.EndsWith(".root") ){
993 // const char *fullpath = gSystem->FindFile(ddir,name);
994 // char *fullpath;
995 // gSystem->IsFileInIncludePath(name,&fullpath);
996 char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(name));
997 contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));
998 delete fullpath;
999 };
1000 }
1001 delete temp;
1002 delete datadir;
1003
1004 };
1005 gSystem->ChangeDirectory(wdir); // back to the working directory
1006 // cout << endl << "Selected files:" << endl;
1007 // contents->Print();
1008 cout << contents->GetEntries()<<" files \n";
1009 // cout << endl;
1010 // cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;
1011 return contents;
1012 };
1013 //--------------------------------------
1014 //
1015 //
1016 //--------------------------------------
1017 /**
1018 * Get the Pamela detector chains from a list of files and make them friends.
1019 * @param fl Pointer to a TList of TSystemFiles
1020 * @param detlist String to select trees to be included
1021 * @return Pointer to a TChain
1022 */
1023 TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){
1024
1025 TChain *Trout =0;
1026
1027 // if( !detlist.IsNull() )SetWhichTrees(detlist);
1028 SetWhichTrees(detlist);
1029
1030 cout<< "GetPamTree(TList*,TString): input detector list --> ";
1031 if(TRK1)cout<<"TRK1 ";
1032 if(TRK2)cout<<"TRK2 ";
1033 if(TRKh)cout<<"TRKH ";
1034 if(CAL1)cout<<"CAL1 ";
1035 if(CAL2)cout<<"CAL2 ";
1036 if(TOF)cout<<"TOF ";
1037 if(TRG)cout<<"TRG ";
1038 if(AC)cout<<"AC ";
1039 if(ND)cout<<"ND ";
1040 if(S4)cout<<"S4 ";
1041 if(ORB)cout<<"ORB ";
1042 cout << endl;
1043
1044 TChain *T = 0;
1045 TChain *C = 0;
1046 TChain *O = 0;
1047 TChain *R = 0;
1048 TChain *S = 0;
1049 TChain *N = 0;
1050 TChain *A = 0;
1051 TChain *B = 0;
1052
1053 if(TRK2||TRK1||TRKh) T = new TChain("Tracker");
1054 if(CAL2||CAL1) C = new TChain("Calorimeter");
1055 if(TOF) O = new TChain("ToF");
1056 if(TRG) R = new TChain("Trigger");
1057 if(S4) S = new TChain("S4");
1058 if(ND) N = new TChain("NeutronD");
1059 if(AC) A = new TChain("Anticounter");
1060 if(ORB) B = new TChain("OrbitalInfo");
1061
1062 // loop over files and create chains
1063 TIter next(fl);
1064 TSystemFile *questo = 0;
1065 while ( (questo = (TSystemFile*) next()) ) {
1066 TString name = questo->GetName();
1067 cout << "File: "<< name << endl;
1068 if( CheckLevel2File(name) ){
1069 if(TRK2||TRK1||TRKh) T->Add(name);
1070 if(CAL1||CAL2) C->Add(name);
1071 if(TOF) O->Add(name);
1072 if(TRG) R->Add(name);
1073 if(S4) S->Add(name);
1074 if(ND) N->Add(name);
1075 if(AC) A->Add(name);
1076 if(ORB) B->Add(name);
1077 };
1078 }
1079
1080 cout << "done chain \n";
1081
1082 UInt_t *found=0;
1083 // Tracker
1084 if(T && (TRK2||TRK1||TRKh)) {
1085 if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1086 else T->SetBranchStatus("TrkLevel2",0,found);
1087 if(TRK2)cout << "Tracker : set branch address TrkLevel2"<<endl;
1088 if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1089 else T->SetBranchStatus("TrkLevel1",0,found);
1090 if(TRK1)cout << "Tracker : set branch address TrkLevel1"<<endl;
1091 if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1092 else T->SetBranchStatus("TrkHough",0,found);
1093 if(TRKh)cout << "Tracker : set branch address TrkHough"<<endl;
1094 if(!Trout)Trout=T;
1095 else Trout->AddFriend("Tracker");
1096 }else{
1097 cout << "Tracker : missing tree"<<endl;
1098 };
1099 // Calorimeter
1100 if(C && (CAL2||CAL1)) {
1101 if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1102 else C->SetBranchStatus("CaloLevel2",0,found);
1103 if(CAL2)cout << "Calorimeter : set branch address CaloLevel2"<<endl;
1104 if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1105 else C->SetBranchStatus("CaloLevel1",0,found);
1106 if(CAL1)cout << "Calorimeter : set branch address CaloLevel1"<<endl;
1107 if(!Trout)Trout=C;
1108 else Trout->AddFriend("Calorimeter");
1109 }else{
1110 cout << "Calorimeter : missing tree"<<endl;
1111 };
1112 // ToF
1113 if(O && TOF) {
1114 O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
1115 cout << "ToF : set branch address ToFLevel2"<<endl;
1116 if(!Trout)Trout=O;
1117 else Trout->AddFriend("ToF");
1118 }else{
1119 cout << "ToF : missing tree"<<endl;
1120 };
1121 // Trigger
1122 if(R && TRG) {
1123 R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1124 cout << "Trigger : set branch address TrigLevel2"<<endl;
1125 if(!Trout)Trout=O;
1126 else Trout->AddFriend("Trigger");
1127 }else{
1128 cout << "Trigger : missing tree"<<endl;
1129 };
1130 // S4
1131 if(S && S4) {
1132 S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1133 cout << "S4 : set branch address S4Level2"<<endl;
1134 if(!Trout)Trout=O;
1135 else Trout->AddFriend("S4");
1136 }else{
1137 cout << "S4 : missing tree"<<endl;
1138 };
1139 // Neutron Detector
1140 if(N && ND) {
1141 N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1142 cout << "NeutronD : set branch address NDLevel2"<<endl;
1143 if(!Trout)Trout=O;
1144 else Trout->AddFriend("NeutronD");
1145 }else{
1146 cout << "NeutronD : missing tree"<<endl;
1147 };
1148 // Anticounters
1149 if(A && AC) {
1150 A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1151 cout << "Anticounter : set branch address AcLevel2"<<endl;
1152 if(!Trout)Trout=O;
1153 else Trout->AddFriend("Anticounter");
1154 }else{
1155 cout << "Anticounter : missing tree"<<endl;
1156 };
1157 // Orbital Info
1158 if(B && ORB) {
1159 B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1160 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
1161 if(!Trout)Trout=O;
1162 else Trout->AddFriend("OrbitalInfo");
1163 }else{
1164 cout << "OrbitalInfo : missing tree"<<endl;
1165 };
1166
1167 // cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1168
1169
1170 // // Tracker
1171 // if(TRK2||TRK1||TRKh){
1172 // if(!Tout)Tout=T;
1173 // else Tout->AddFriend("Tracker");
1174 // }
1175 // // Calorimeter
1176 // if(CAL2||CAL1) {
1177 // if(!Tout)Tout=C;
1178 // else Tout->AddFriend("Calorimeter");
1179 // };
1180 // // ToF
1181 // if(TOF) {
1182 // if(!Tout)Tout=O;
1183 // else Tout->AddFriend("ToF");
1184 // };
1185 // // Trigger
1186 // if(TRG) {
1187 // if(!Tout)Tout=R;
1188 // else Tout->AddFriend("Trigger");
1189 // };
1190 // // S4
1191 // if(S4) {
1192 // if(!Tout)Tout=S;
1193 // else Tout->AddFriend("S4");
1194 // };
1195 // // Neutron Detector
1196 // if(ND) {
1197 // if(!Tout)Tout=N;
1198 // else Tout->AddFriend("NeutronD");
1199 // };
1200 // // Anticounters
1201 // if(AC) {
1202 // if(!Tout)Tout=A;
1203 // else Tout->AddFriend("Anticounter");
1204 // };
1205 // // OrbitalInfo
1206 // if(ORB) {
1207 // if(!Tout)Tout=B;
1208 // else Tout->AddFriend("OrbitalInfo");
1209 // };
1210
1211 // cout<<endl<<" Number of entries: "<<Tout->GetEntries()<<endl<<endl;
1212
1213 // if( Tout->GetEntries() )PamLevel2::SetBranchAddress( Tout );
1214
1215 return Trout;
1216 }
1217
1218
1219
1220 //--------------------------------------
1221 //
1222 //
1223 //--------------------------------------
1224 /**
1225 * Set branch addresses for Pamela friend trees
1226 */
1227 void PamLevel2::SetBranchAddress(TTree *t){
1228
1229 TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
1230 TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
1231 TRKh = TRKh & t->GetBranchStatus("TrkHough");
1232 CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
1233 CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
1234 TOF = TOF & t->GetBranchStatus("ToFLevel2");
1235 TRG = TRG & t->GetBranchStatus("TrigLevel2");
1236 S4 = S4 & t->GetBranchStatus("S4Level2");
1237 ND = ND & t->GetBranchStatus("NDLevel2");
1238 AC = AC & t->GetBranchStatus("AcLevel2");
1239 ORB = ORB & t->GetBranchStatus("OrbitalInfo");
1240
1241
1242 // Tracker
1243 if(TRK1) {
1244 t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel2"));
1245 cout << "Tracker : set branch address TrkLevel1"<<endl;
1246 };
1247 if(TRK2) {
1248 t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));
1249 cout << "Tracker : set branch address TrkLevel2"<<endl;
1250 };
1251 if(TRKh) {
1252 t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1253 cout << "Tracker : set branch address TrkHough"<<endl;
1254 };
1255
1256 // Calorimeter
1257 if(CAL1) {
1258 t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1259 cout << "Calorimeter : set branch address CaloLevel1"<<endl;
1260 };
1261 if(CAL2) {
1262 t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1263 cout << "Calorimeter : set branch address CaloLevel2"<<endl;
1264 };
1265
1266 // ToF
1267 if(TOF) {
1268 t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
1269 cout << "ToF : set branch address ToFLevel2"<<endl;
1270 };
1271 // Trigger
1272 if(TRG) {
1273 t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1274 cout << "Trigger : set branch address TrigLevel2"<<endl;
1275 };
1276 // S4
1277 if(S4) {
1278 t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1279 cout << "S4 : set branch address S4Level2"<<endl;
1280 };
1281 // Neutron Detector
1282 if(ND) {
1283 t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1284 cout << "NeutronD : set branch address NDLevel2"<<endl;
1285 };
1286 // Anticounters
1287 if(AC) {
1288 t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1289 cout << "Anticounter : set branch address AcLevel2"<<endl;
1290 };
1291 // OrbitalInfo
1292 if(ORB) {
1293 t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1294 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
1295 };
1296
1297 }
1298 /**
1299 * Set branch addresses for Pamela friend trees
1300 */
1301 void PamLevel2::SetBranchAddress(TChain *t){
1302
1303 TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
1304 TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
1305 TRKh = TRKh & t->GetBranchStatus("TrkHough");
1306 CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
1307 CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
1308 TOF = TOF & t->GetBranchStatus("ToFLevel2");
1309 TRG = TRG & t->GetBranchStatus("TrigLevel2");
1310 S4 = S4 & t->GetBranchStatus("S4Level2");
1311 ND = ND & t->GetBranchStatus("NDLevel2");
1312 AC = AC & t->GetBranchStatus("AcLevel2");
1313 ORB = ORB & t->GetBranchStatus("OrbitalInfo");
1314
1315 // Tracker
1316 if(TRK2) {
1317 t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1318 cout << "Tracker : set branch address TrkLevel2"<<endl;
1319 };
1320 if(TRK1) {
1321 t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1322 cout << "Tracker : set branch address TrkLevel1"<<endl;
1323 };
1324 if(TRKh) {
1325 t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1326 cout << "Tracker : set branch address TrkHough"<<endl;
1327 };
1328
1329 // Calorimeter
1330 if(CAL2) {
1331 t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1332 cout << "Calorimeter : set branch address CaloLevel2"<<endl;
1333 };
1334 if(CAL1) {
1335 t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1336 cout << "Calorimeter : set branch address CaloLevel1"<<endl;
1337 };
1338
1339 // ToF
1340 if(TOF) {
1341 t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
1342 cout << "ToF : set branch address ToFLevel2"<<endl;
1343 };
1344 // Trigger
1345 if(TRG) {
1346 t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1347 cout << "Trigger : set branch address TrigLevel2"<<endl;
1348 };
1349 // S4
1350 if(S4) {
1351 t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1352 cout << "S4 : set branch address S4Level2"<<endl;
1353 };
1354 // Neutron Detector
1355 if(ND) {
1356 t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1357 cout << "NeutronD : set branch address NDLevel2"<<endl;
1358 };
1359 // Anticounters
1360 if(AC) {
1361 t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1362 cout << "Anticounter : set branch address AcLevel2"<<endl;
1363 };
1364 // OrbitalInfo
1365 if(ORB) {
1366 t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1367 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
1368 };
1369
1370 }
1371
1372
1373 //--------------------------------------
1374 //
1375 //
1376 //--------------------------------------
1377 /**
1378 * Get the Run tree chain from a list of files.
1379 * @param fl Pointer to a TList of TSystemFiles
1380 * @return Pointer to a TChain
1381 */
1382 TChain *PamLevel2::GetRunTree(TList *fl){
1383
1384 TChain *R = new TChain("Run");
1385
1386 // loop over files and create chains
1387 TIter next(fl);
1388 TSystemFile *questo = 0;
1389 while ( (questo = (TSystemFile*) next()) ) {
1390 TString name = questo->GetName();
1391 // cout << "File: "<< name << endl;
1392 if( CheckLevel2File(name) ){
1393 R->Add(name);
1394 };
1395 }
1396
1397 R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1398 cout << "Run : set branch address RunInfo"<<endl;
1399 R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1400 cout << "Software : set branch address SoftInfo"<<endl; // Emiliano
1401
1402 return R;
1403
1404 }
1405 //--------------------------------------
1406 //
1407 //
1408 //--------------------------------------
1409 /**
1410 * Get the Run tree from a file.
1411 * @param f Pointer to a TFile
1412 * @return Pointer to a TTree
1413 */
1414 TTree *PamLevel2::GetRunTree(TFile *f){
1415
1416
1417 TTree *R = (TTree*)f->Get("Run");
1418
1419 R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1420 cout << "Run : set branch address RunInfo"<<endl;
1421 R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1422 cout << "Software : set branch address SoftInfo"<<endl; // Emiliano
1423
1424 return R;
1425
1426 }
1427 /**
1428 * Update the runinfo informations (to be used to have Run infos event by event basis)
1429 * @param run Pointer to the chain/tree which contains run infos
1430 * @return true if a new run has been read, false if it is still the same run
1431 */
1432 Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev){
1433 //
1434 // check if we have already called once GetEntry, if not call it
1435 //
1436 if ( run->GetEntries() <= 0 ) return(false);
1437 //
1438 Int_t oldrun = irun;
1439 if ( irun < 0 ){
1440 irun = 0;
1441 run->GetEntry(0);
1442 runfirstentry = 0ULL;
1443 runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS) - 1ULL;
1444 };
1445 while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
1446 // printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
1447 irun++;
1448 run->GetEntry(irun);
1449 runfirstentry = runlastentry+1ULL;
1450 runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS);
1451 };
1452 //
1453 if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
1454 //
1455 // printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
1456 //
1457 return(true);
1458 //
1459 };
1460 /**
1461 * Update the runinfo informations (to be used to have Run infos event by event basis)
1462 * @param run Pointer to the chain/tree which contains run infos
1463 * @return true if a new run has been read, false if it is still the same run
1464 */
1465 Bool_t PamLevel2::UpdateRunInfo(TTree *run, ULong64_t iev){
1466 return(UpdateRunInfo((TChain*)run,iev));
1467 };
1468
1469 //--------------------------------------
1470 //
1471 //
1472 //--------------------------------------
1473 /**
1474 * Set which trees shoul be analysed
1475 * @param detlist TString containing the sequence of trees required
1476 */
1477 void PamLevel2::SetWhichTrees(TString detlist){
1478
1479 if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
1480 CAL1 = true;
1481 CAL2 = true;
1482 TRK2 = true;
1483 TRK1 = false;
1484 TRKh = false;
1485 TRG = true;
1486 TOF = true;
1487 S4 = true;
1488 ND = true;
1489 AC = true;
1490 ORB = true;
1491 }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
1492 CAL1 = false;
1493 CAL2 = false;
1494 TRK2 = false;
1495 TRK1 = false;
1496 TRKh = false;
1497 TRG = false;
1498 TOF = false;
1499 S4 = false;
1500 ND = false;
1501 AC = false;
1502 ORB = false;
1503 };
1504
1505 // -------------------------------------------------------------------------
1506 if( detlist.Contains("CAL1", TString::kIgnoreCase) ){
1507 if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;
1508 if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;
1509 };
1510
1511 if( detlist.Contains("CAL2", TString::kIgnoreCase)){
1512 if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;
1513 if ( detlist.Contains("+CAL2", TString::kIgnoreCase) )CAL2=true;
1514 };
1515
1516 if( detlist.Contains("+CAL", TString::kIgnoreCase) && !CAL1 && !CAL2 )CAL2=true;
1517 if( detlist.Contains("-CAL", TString::kIgnoreCase) && CAL1 && CAL2 ){
1518 CAL2=false;
1519 CAL1=false;
1520 }
1521 // -------------------------------------------------------------------------
1522 if( detlist.Contains("TRK1", TString::kIgnoreCase) ){
1523 if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;
1524 if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;
1525 };
1526
1527 if( detlist.Contains("TRK2", TString::kIgnoreCase)){
1528 if ( detlist.Contains("-TRK2", TString::kIgnoreCase) )TRK2=false;
1529 if ( detlist.Contains("+TRK2", TString::kIgnoreCase) )TRK2=true;
1530 };
1531
1532 if( detlist.Contains("TRKh", TString::kIgnoreCase)){
1533 if ( detlist.Contains("-TRKh", TString::kIgnoreCase) )TRKh=false;
1534 if ( detlist.Contains("+TRKh", TString::kIgnoreCase) )TRKh=true;
1535 };
1536
1537 if( detlist.Contains("+TRK", TString::kIgnoreCase) && !TRK1 && !TRK2 && !TRKh )TRK2=true;
1538 if( detlist.Contains("-TRK", TString::kIgnoreCase) && TRK1 && TRK2 && TRKh){
1539 TRK2=false;
1540 TRK1=false;
1541 TRKh=false;
1542 }
1543 // -------------------------------------------------------------------------
1544
1545 if( detlist.Contains("-TRG", TString::kIgnoreCase) )TRG = false;
1546 else if( detlist.Contains("+TRG", TString::kIgnoreCase) )TRG = true;
1547
1548 if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
1549 else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
1550
1551 if( detlist.Contains("-S4", TString::kIgnoreCase) )S4 = false;
1552 else if( detlist.Contains("+S4", TString::kIgnoreCase) )S4 = true;
1553
1554 if( detlist.Contains("-ND", TString::kIgnoreCase) )ND = false;
1555 else if( detlist.Contains("+ND", TString::kIgnoreCase) )ND = true;
1556
1557 if( detlist.Contains("-AC", TString::kIgnoreCase) )AC = false;
1558 else if( detlist.Contains("+AC", TString::kIgnoreCase) )AC = true;
1559
1560 if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;
1561 else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;
1562
1563 // cout<< "Set detector list --> ";
1564 // if(TRK1)cout<<"TRK1 ";
1565 // if(TRK2)cout<<"TRK2 ";
1566 // if(TRKh)cout<<"TRKH ";
1567 // if(CAL1)cout<<"CAL1 ";
1568 // if(CAL2)cout<<"CAL2 ";
1569 // if(TOF)cout<<"TOF ";
1570 // if(TRG)cout<<"TRG ";
1571 // if(AC)cout<<"AC ";
1572 // if(ND)cout<<"ND ";
1573 // if(S4)cout<<"S4 ";
1574 // if(ORB)cout<<"ORB ";
1575 // cout << endl;
1576
1577 };
1578
1579
1580 /**
1581 * Set tree/branch detector flags from the content of a tree
1582 */
1583 void PamLevel2::GetWhichTrees(TFile* f){
1584
1585 // -----------
1586 // reset flags
1587 // -----------
1588 CAL1 = false;
1589 CAL2 = false;
1590 TRK2 = false;
1591 TRK1 = false;
1592 TRKh = false;
1593 TRG = false;
1594 TOF = false;
1595 S4 = false;
1596 ND = false;
1597 AC = false;
1598 ORB = false;
1599
1600 RUN = false;
1601
1602 cout << "Checking file: "<<f->GetName()<<endl;
1603 if( !f || f->IsZombie() ){
1604 cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;
1605 return;
1606 }
1607
1608 TList *lk = f->GetListOfKeys();
1609 TIter next(lk);
1610 TKey *key =0;
1611
1612 Int_t nev = 0;
1613
1614 while( (key = (TKey*)next()) ){
1615
1616 if( !strcmp(key->GetName(),"Run" ) )RUN = true;
1617
1618 //=========================================================
1619 if( !strcmp(key->GetName(),"Trigger" ) ){
1620 TRG = true;
1621 Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries();
1622 if( nev && nevt!=nev){
1623 cout << "File: "<< f->GetName() <<" Trigger tree has "<<nevt<<" events instead of "<<nev<< endl;
1624 TRG = false;
1625 }else nev=nevt;
1626 }
1627 //=========================================================
1628 if( !strcmp(key->GetName(),"ToF" ) ){
1629 TOF = true;
1630 Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries();
1631 if( nev && nevt!=nev){
1632 cout << "File: "<< f->GetName() <<" ToF tree has "<<nevt<<" events instead of "<<nev<< endl;
1633 TOF = false;
1634 }else nev=nevt;
1635 }
1636 //=========================================================
1637 if( !strcmp(key->GetName(),"S4" ) ){
1638 S4 = true;
1639 Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries();
1640 if( nev && nevt!=nev){
1641 cout << "File: "<< f->GetName() <<" S4 tree has "<<nevt<<" events instead of "<<nev<< endl;
1642 S4 = false;
1643 }else nev=nevt;
1644 }
1645 //=========================================================
1646
1647 if( !strcmp(key->GetName(),"NeutronD" ) ){
1648 ND = true;
1649 Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries();
1650 if( nev && nevt!=nev){
1651 cout << "File: "<< f->GetName() <<"NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl;
1652 ND =false;
1653 }else nev=nevt;
1654 }
1655 //=========================================================
1656 if( !strcmp(key->GetName(),"Anticounter") ){
1657 AC = true;
1658 Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries();
1659 if( nev && nevt!=nev){
1660 cout << "File: "<< f->GetName() <<" Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl;
1661 AC =false;
1662 }else nev=nevt;
1663 }
1664 //=========================================================
1665 if( !strcmp(key->GetName(),"OrbitalInfo") ){
1666 ORB = true;
1667 Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries();
1668 if( nev && nevt!=nev){
1669 cout << "File: "<< f->GetName() <<" OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
1670 ORB = false;
1671 }else nev=nevt;
1672 }
1673 //=========================================================
1674 if( !strcmp(key->GetName(),"Tracker" ) ){
1675 TTree *T = (TTree*)f->Get("Tracker");
1676 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
1677 TString name = T->GetListOfBranches()->At(i)->GetName();
1678 if( !name.CompareTo("TrkLevel1") )TRK1=true;
1679 if( !name.CompareTo("TrkLevel2") )TRK2=true;
1680 if( !name.CompareTo("TrkHough") )TRKh=true;
1681 };
1682 Int_t nevt = T->GetEntries();
1683 if( nev && nevt!=nev){
1684 cout << "File: "<< f->GetName() <<" Tracker tree has "<<nevt<<" events instead of "<<nev<< endl;
1685 TRK1 = false;
1686 TRK2 = false;
1687 TRKh = false;
1688 }else nev=nevt;
1689 T->Delete();
1690 };
1691 //=========================================================
1692 if( !strcmp(key->GetName(),"Calorimeter" ) ){
1693 TTree *T = (TTree*)f->Get("Calorimeter");
1694 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
1695 TString name = T->GetListOfBranches()->At(i)->GetName();
1696 if( !name.CompareTo("CaloLevel1") )CAL1=true;
1697 if( !name.CompareTo("CaloLevel2") )CAL2=true;
1698 };
1699 Int_t nevt = T->GetEntries();
1700 if( nev && nevt!=nev){
1701 cout << "File: "<< f->GetName() <<" Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl;
1702 CAL1 = false;
1703 CAL2 = false;
1704 }else nev=nevt;
1705 T->Delete();
1706 };
1707
1708 };
1709
1710 delete lk;
1711
1712 // cout<< "Get detector list from input file --> ";
1713 // if(TRK1)cout<<"TRK1 ";
1714 // if(TRK2)cout<<"TRK2 ";
1715 // if(TRKh)cout<<"TRKH ";
1716 // if(CAL1)cout<<"CAL1 ";
1717 // if(CAL2)cout<<"CAL2 ";
1718 // if(TOF)cout<<"TOF ";
1719 // if(TRG)cout<<"TRG ";
1720 // if(AC)cout<<"AC ";
1721 // if(ND)cout<<"ND ";
1722 // if(S4)cout<<"S4 ";
1723 // if(ORB)cout<<"ORB ";
1724 // cout << endl;
1725
1726 return ;
1727
1728 };
1729
1730
1731 //--------------------------------------
1732 //
1733 //
1734 //--------------------------------------
1735 /**
1736 * Check if a file contains selected Pamela Level2 trees.
1737 * @param name File name
1738 * @return true if the file is ok.
1739 */
1740 Bool_t PamLevel2::CheckLevel2File(TString name){
1741
1742 Bool_t CAL1__ok = false;
1743 Bool_t CAL2__ok = false;
1744 Bool_t TRK2__ok = false;
1745 Bool_t TRK1__ok = false;
1746 Bool_t TRKh__ok = false;
1747 Bool_t TRG__ok = false;
1748 Bool_t TOF__ok = false;
1749 Bool_t S4__ok = false;
1750 Bool_t ND__ok = false;
1751 Bool_t AC__ok = false;
1752 Bool_t ORB__ok = false;
1753
1754 Bool_t RUN__ok = false;
1755
1756
1757
1758 cout << "Checking file: "<<name<<endl;
1759 TFile *f = new TFile(name.Data());
1760 if( !f || f->IsZombie() ){
1761 cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false;
1762 }
1763 // cout << "Get list of keys: "<<f<<endl;
1764 TList *lk = f->GetListOfKeys();
1765 // lk->Print();
1766 TIter next(lk);
1767 TKey *key =0;
1768
1769 Int_t nev = 0;
1770
1771 while( (key = (TKey*)next()) ){
1772
1773 // cout << key->GetName() << ""<<key->GetClassName()<<endl;
1774 // cout << " Get tree: " << f->Get(key->GetName())<<endl;
1775 // nev_previous = nev;
1776 // cout << " n.entries "<< nev <<endl;
1777 // if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){
1778 // nev = ((TTree*)f->Get(key->GetName()))->GetEntries();
1779 // cout << "File: "<< f->GetName() <<" discarded ---- "<< key->GetName() << " tree: n.entries does not match "<<nev<<" "<<nev_previous<< endl;
1780 // return false;
1781 // };
1782
1783 if( !strcmp(key->GetName(),"Run" ) )RUN__ok = true;
1784
1785 //=========================================================
1786 if( !strcmp(key->GetName(),"Trigger" ) ){
1787 TRG__ok = true;
1788 if(TRG){
1789 Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries();
1790 if( nev && nevt!=nev){
1791 cout << "File: "<< f->GetName() <<" discarded ---- Trigger tree has "<<nevt<<" events instead of "<<nev<< endl;
1792 return false;
1793 }
1794 nev=nevt;
1795 }
1796 }
1797 //=========================================================
1798 if( !strcmp(key->GetName(),"ToF" ) ){
1799 TOF__ok = true;
1800 if(TOF){
1801 Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries();
1802 if( nev && nevt!=nev){
1803 cout << "File: "<< f->GetName() <<" discarded ---- ToF tree has "<<nevt<<" events instead of "<<nev<< endl;
1804 return false;
1805 }
1806 nev=nevt;
1807 }
1808 }
1809 //=========================================================
1810 if( !strcmp(key->GetName(),"S4" ) ){
1811 S4__ok = true;
1812 if(S4){
1813 Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries();
1814 if( nev && nevt!=nev){
1815 cout << "File: "<< f->GetName() <<" discarded ---- S4 tree has "<<nevt<<" events instead of "<<nev<< endl;
1816 return false;
1817 }
1818 nev=nevt;
1819 }
1820 }
1821 //=========================================================
1822
1823 if( !strcmp(key->GetName(),"NeutronD" ) ){
1824 ND__ok = true;
1825 if(ND){
1826 Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries();
1827 if( nev && nevt!=nev){
1828 cout << "File: "<< f->GetName() <<" discarded ---- NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl;
1829 return false;
1830 }
1831 nev=nevt;
1832 }
1833 }
1834 //=========================================================
1835 if( !strcmp(key->GetName(),"Anticounter") ){
1836 AC__ok = true;
1837 if(AC){
1838 Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries();
1839 if( nev && nevt!=nev){
1840 cout << "File: "<< f->GetName() <<" discarded ---- Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl;
1841 return false;
1842 }
1843 nev=nevt;
1844 }
1845 }
1846 //=========================================================
1847 if( !strcmp(key->GetName(),"OrbitalInfo") ){
1848 ORB__ok = true;
1849 if(ORB){
1850 Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries();
1851 if( nev && nevt!=nev){
1852 cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
1853 return false;
1854 }
1855 nev=nevt;
1856 }
1857 }
1858 //=========================================================
1859 if( !strcmp(key->GetName(),"Tracker" ) ){
1860 TTree *T = (TTree*)f->Get("Tracker");
1861 if(TRK1||TRK2||TRKh){
1862 Int_t nevt = T->GetEntries();
1863 if( nev && nevt!=nev){
1864 cout << "File: "<< f->GetName() <<" discarded ---- Tracker tree has "<<nevt<<" events instead of "<<nev<< endl;
1865 return false;
1866 }
1867 nev=nevt;
1868 }
1869 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
1870 TString name = T->GetListOfBranches()->At(i)->GetName();
1871 if( !name.CompareTo("TrkLevel1") )TRK1__ok=true;
1872 if( !name.CompareTo("TrkLevel2") )TRK2__ok=true;
1873 if( !name.CompareTo("TrkHough") )TRKh__ok=true;
1874 };
1875 T->Delete();
1876 };
1877 //=========================================================
1878 if( !strcmp(key->GetName(),"Calorimeter" ) ){
1879 TTree *T = (TTree*)f->Get("Calorimeter");
1880 if(CAL1||CAL2){
1881 Int_t nevt = T->GetEntries();
1882 if( nev && nevt!=nev){
1883 cout << "File: "<< f->GetName() <<" discarded ---- Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl;
1884 return false;
1885 }
1886 nev=nevt;
1887 }
1888 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
1889 TString name = T->GetListOfBranches()->At(i)->GetName();
1890 if( !name.CompareTo("CaloLevel1") )CAL1__ok=true;
1891 if( !name.CompareTo("CaloLevel2") )CAL2__ok=true;
1892 };
1893 T->Delete();
1894 };
1895
1896 };
1897
1898 // cout<< "CheckLevel2File(TString): detector list --> ";
1899 // if(TRK1__ok)cout<<"TRK1 ";
1900 // if(TRK2__ok)cout<<"TRK2 ";
1901 // if(TRKh__ok)cout<<"TRKH ";
1902 // if(CAL1__ok)cout<<"CAL1 ";
1903 // if(CAL2__ok)cout<<"CAL2 ";
1904 // if(TOF__ok)cout<<"TOF ";
1905 // if(TRG__ok)cout<<"TRG ";
1906 // if(AC__ok)cout<<"AC ";
1907 // if(ND__ok)cout<<"ND ";
1908 // if(S4__ok)cout<<"S4 ";
1909 // if(ORB__ok)cout<<"ORB ";
1910 // cout << endl;
1911
1912
1913 if(TRK2 && TRK1__ok)TRK1=1;
1914 // ----------------------------------------------------------------------------
1915 // NOTA
1916 // se c'e` il level1, lo devo necessarimente leggere.
1917 // infatti (non ho capito perche`) i cluster vengono letti e allocati in memoria
1918 // comunque, ma non vengono disallocati da PamLevel2::Clear()
1919 // ----------------------------------------------------------------------------
1920
1921
1922 if(!RUN__ok) {
1923 cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree"<< endl;
1924 // return false;
1925 };
1926
1927 if(CAL1 && !CAL1__ok){
1928 cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel1 branch"<< endl;
1929 return false;
1930 };
1931 if(CAL2 && !CAL2__ok){
1932 cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel2 branch"<< endl;
1933 return false;
1934 };
1935 if(TRK2 && !TRK2__ok){
1936 cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel2 branch"<< endl;
1937 return false;
1938 };
1939 if(TRK1 && !TRK1__ok){
1940 cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel1 branch"<< endl;
1941 return false;
1942 };
1943 if(TRKh && !TRKh__ok){
1944 cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkHough branch"<< endl;
1945 return false;
1946 };
1947 if(ORB && !ORB__ok){
1948 cout << "File: "<< f->GetName() <<" discarded ---- Missing ORB tree"<< endl;
1949 return false;
1950 };
1951 if(AC && !AC__ok){
1952 cout << "File: "<< f->GetName() <<" discarded ---- Missing AC tree"<< endl;
1953 return false;
1954 };
1955 if(S4 && !S4__ok){
1956 cout << "File: "<< f->GetName() <<" discarded ---- Missing S4 tree"<< endl;
1957 return false;
1958 };
1959 if(TOF && !TOF__ok){
1960 cout << "File: "<< f->GetName() <<" discarded ---- Missing ToF tree"<< endl;
1961 return false;
1962 };
1963
1964 if(ND && !ND__ok){
1965 cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl;
1966 return false;
1967 };
1968 if(TRG && !TRG__ok){
1969 cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;
1970 return false;
1971 };
1972
1973
1974 // lk->Delete();
1975 // delete lk;
1976 f->Close();
1977
1978 // cout<< "CheckLevel2File(TString): detector list --> ";
1979 // if(TRK1)cout<<"TRK1 ";
1980 // if(TRK2)cout<<"TRK2 ";
1981 // if(TRKh)cout<<"TRKH ";
1982 // if(CAL1)cout<<"CAL1 ";
1983 // if(CAL2)cout<<"CAL2 ";
1984 // if(TOF)cout<<"TOF ";
1985 // if(TRG)cout<<"TRG ";
1986 // if(AC)cout<<"AC ";
1987 // if(ND)cout<<"ND ";
1988 // if(S4)cout<<"S4 ";
1989 // if(ORB)cout<<"ORB ";
1990 // cout << endl;
1991
1992 return true;
1993
1994 };
1995
1996
1997 /**
1998 * Create clone-trees
1999 */
2000 void PamLevel2::CreateCloneTrees0( TChain *fChain, TFile *ofile ){
2001
2002 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2003 cout << "Create clones of PAMELA trees "<<endl;
2004
2005 Int_t i=0;
2006 tree_clone[i] = fChain->GetTree()->CloneTree(0);
2007 TString name = tree_clone[i]->GetName();
2008 name.Append("_clone");
2009 // tree_clone[i]->SetName(name.Data());
2010 cout << tree_clone[i]->GetName() <<endl;
2011 i++;
2012
2013 TList *li = fChain->GetListOfFriends();
2014 TIter next(li);
2015 TFriendElement* T_friend=0;
2016 ofile->cd();
2017 while( (T_friend = (TFriendElement*)next()) ){
2018 // cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;
2019 // cout<<T_friend->GetTree()->GetName()<< endl;
2020 tree_clone[i] = T_friend->GetTree()->CloneTree(0);
2021 tree_clone[i]->SetAutoSave(1000000);
2022 name = tree_clone[i]->GetName();
2023 name.Append("_clone");
2024 // tree_clone[i]->SetName(name.Data());
2025 cout << tree_clone[i]->GetName() << endl;
2026 i++;
2027 }
2028
2029 delete li;
2030
2031 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2032
2033 }
2034
2035 /**
2036 * Create clone-trees
2037 */
2038 void PamLevel2::CreateCloneTrees(TFile *ofile){
2039
2040 ofile->cd();
2041
2042 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2043 cout << "Create new PAMELA trees "<<endl;
2044
2045 Int_t i=0;
2046
2047 if(TRK1||TRK2||TRKh){
2048 tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");
2049 if(TRK1) {
2050 tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
2051 tree_clone[i]->BranchRef();
2052 cout << "Tracker : branch TrkLevel1"<<endl;
2053 };
2054 if(TRK2) {
2055 tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
2056 cout << "Tracker : branch TrkLevel2"<<endl;
2057 };
2058 if(TRKh) {
2059 tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));
2060 cout << "Tracker : branch TrkHough"<<endl;
2061 };
2062 i++;
2063 }
2064
2065 // Calorimeter
2066 if(CAL1||CAL2){
2067 tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");
2068 if(CAL1) {
2069 tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
2070 cout << "Calorimeter : branch CaloLevel1"<<endl;
2071 };
2072 if(CAL2) {
2073 tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));
2074 cout << "Calorimeter : branch CaloLevel2"<<endl;
2075 };
2076 i++;
2077 }
2078
2079 // ToF
2080 if(TOF) {
2081 tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");
2082 tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));
2083 cout << "ToF : branch ToFLevel2"<<endl;
2084 i++;
2085 };
2086 // Trigger
2087 if(TRG) {
2088 tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");
2089 tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));
2090 cout << "Trigger : branch TrigLevel2"<<endl;
2091 i++;
2092 };
2093 // S4
2094 if(S4) {
2095 tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");
2096 tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));
2097 cout << "S4 : branch S4Level2"<<endl;
2098 i++;
2099 };
2100 // Neutron Detector
2101 if(ND) {
2102 tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");
2103 tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));
2104 cout << "NeutronD : branch NDLevel2"<<endl;
2105 i++;
2106 };
2107 // Anticounters
2108 if(AC) {
2109 tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");
2110 tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));
2111 cout << "Anticounter : branch AcLevel2"<<endl;
2112 i++;
2113 };
2114 // OrbitalInfo
2115 if(ORB) {
2116 tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info ");
2117 tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));
2118 cout << "OrbitalInfo : branch OrbitalInfo"<<endl;
2119 i++;
2120 };
2121 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2122
2123 }
2124
2125
2126 /**
2127 * Fill tree (created with CreateCloneTrees)
2128 *
2129 */
2130 //void PamLevel2::FillNewPamTree(TTree *T){
2131 void PamLevel2::FillCloneTrees(){
2132
2133 for(Int_t i=0; i<8; i++){
2134 if(tree_clone[i])tree_clone[i]->Fill();
2135 }
2136 }
2137
2138
2139 TTree* PamLevel2::GetCloneTree(TString name){
2140
2141 for(Int_t i=0; i<8; i++){
2142 if(tree_clone[i]){
2143 TString na = tree_clone[i]->GetName();
2144 if(!name.CompareTo(na))return tree_clone[i];
2145 };
2146 }
2147 return NULL;
2148
2149 }
2150 void PamLevel2::WriteCloneTrees(){
2151 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2152 cout << "Write clones of PAMELA trees "<<endl;
2153 for(Int_t i=0; i<8; i++){
2154 if(tree_clone[i]){
2155 cout << tree_clone[i]->GetName()<<endl;
2156 tree_clone[i]->Write();
2157 };
2158 }
2159 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2160
2161 }
2162
2163 /**
2164 * Create a new (empty) Pamela trees
2165 */
2166 // TTree* PamLevel2::GetNewPamTree(){
2167
2168 // if(tree_clone)return tree_clone;
2169
2170 // TTree *Tout = 0;
2171
2172 // cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2173 // cout << "Create new PAMELA trees "<<endl;
2174
2175
2176 // if(TRK1||TRK2||TRKh){
2177 // TTree *T = new TTree("Tracker_clone","PAMELA tracker level2 data ");
2178 // if(TRK1) {
2179 // trk1_clone = new TrkLevel1();
2180 // T->Branch("TrkLevel1","TrkLevel1", &trk1_clone);
2181 // T->BranchRef();
2182 // cout << "Tracker : branch TrkLevel1"<<endl;
2183 // };
2184 // if(TRK2) {
2185 // trk2_clone = new TrkLevel2();
2186 // T->Branch("TrkLevel2", "TrkLevel2",&trk2_clone);
2187 // cout << "Tracker : branch TrkLevel2"<<endl;
2188 // };
2189 // if(TRKh) {
2190 // trkh_clone = new TrkHough();
2191 // T->Branch("TrkHough","TrkHough", &trkh_clone);
2192 // cout << "Tracker : branch TrkHough"<<endl;
2193 // };
2194 // if(!Tout)Tout=T;
2195 // else Tout->AddFriend("Tracker_clone");
2196 // }
2197
2198 // // Calorimeter
2199 // if(CAL1||CAL2){
2200 // TTree *C = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");
2201 // if(CAL1) {
2202 // calo1_clone = new CaloLevel1();
2203 // C->Branch("CaloLevel1", "CaloLevel1", &calo1_clone);
2204 // cout << "Calorimeter : branch CaloLevel1"<<endl;
2205 // };
2206 // if(CAL2) {
2207 // calo2_clone = new CaloLevel2();
2208 // C->Branch("CaloLevel2","CaloLevel2", &calo2_clone);
2209 // cout << "Calorimeter : branch CaloLevel2"<<endl;
2210 // };
2211 // if(!Tout)Tout=C;
2212 // else Tout->AddFriend("Calorimeter_clone");
2213 // }
2214
2215 // // ToF
2216 // if(TOF) {
2217 // TTree *O = new TTree("ToF_clone","PAMELA ToF level2 data ");
2218 // tof_clone = new ToFLevel2();
2219 // O->Branch("ToFLevel2","ToFLevel2", &tof_clone);
2220 // cout << "ToF : branch ToFLevel2"<<endl;
2221 // if(!Tout)Tout=O;
2222 // else Tout->AddFriend("ToF_clone");
2223 // };
2224 // // Trigger
2225 // if(TRG) {
2226 // TTree *R = new TTree("Trigger_clone","PAMELA trigger level2 data ");
2227 // trig_clone = new TrigLevel2();
2228 // R->Branch("TrigLevel2","TrigLevel2", &trig_clone);
2229 // cout << "Trigger : branch TrigLevel2"<<endl;
2230 // if(!Tout)Tout=R;
2231 // else Tout->AddFriend("Trigger_clone");
2232 // };
2233 // // S4
2234 // if(S4) {
2235 // TTree *S = new TTree("S4_clone","PAMELA S4 level2 data ");
2236 // s4_clone = new S4Level2();
2237 // S->Branch("S4Level2","S4Level2", &s4_clone);
2238 // cout << "S4 : branch S4Level2"<<endl;
2239 // if(!Tout)Tout=S;
2240 // else Tout->AddFriend("S4_clone");
2241 // };
2242 // // Neutron Detector
2243 // if(ND) {
2244 // TTree *N = new TTree("NeutronD_clone","PAMELA neutron detector level2 data ");
2245 // nd_clone = new NDLevel2();
2246 // N->Branch("NDLevel2","NDLevel2", &nd_clone);
2247 // cout << "NeutronD : branch NDLevel2"<<endl;
2248 // if(!Tout)Tout=N;
2249 // else Tout->AddFriend("NeutronD_clone");
2250 // };
2251 // // Anticounters
2252 // if(AC) {
2253 // TTree *A = new TTree("Anticounter_clone","PAMELA anticounter detector level2 data ");
2254 // ac_clone = new AcLevel2();
2255 // A->Branch("AcLevel2","AcLevel2", &ac_clone);
2256 // cout << "Anticounter : branch AcLevel2"<<endl;
2257 // if(!Tout)Tout=A;
2258 // else Tout->AddFriend("Anticounter_clone");
2259 // };
2260 // // OrbitalInfo
2261 // if(ORB) {
2262 // TTree *B = new TTree("OrbitalInfo_clone","PAMELA oribital info ");
2263 // orb_clone = new OrbitalInfo();
2264 // B->Branch("OrbitalInfo","OrbitalInfo", &orb_clone);
2265 // cout << "OrbitalInfo : branch OrbitalInfo"<<endl;
2266 // if(!Tout)Tout=B;
2267 // else Tout->AddFriend("OrbitalInfo_clone");
2268 // };
2269 // cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2270
2271 // tree_clone = Tout;
2272 // tree_clone->SetDirectory(0);
2273
2274 // return Tout;
2275 // }
2276 // /**
2277 // * Fill a tree (created with GetNewPamTree)
2278 // *
2279 // */
2280 // //void PamLevel2::FillNewPamTree(TTree *T){
2281 // void PamLevel2::FillNewPamTree(){
2282
2283
2284 // if(trk1_clone) *trk1_clone = *trk1_obj;
2285 // if(trk2_clone){
2286 // trk2_clone->Clear();
2287 // trk2_obj->Copy(*trk2_clone);
2288 // // *trk2_clone = *trk2_obj;
2289 // }
2290 // if(trkh_clone) *trkh_clone = *trkh_obj;
2291 // if(calo1_clone){
2292 // // *calo1_clone = *calo1_obj;
2293 // calo1_clone->Clear();
2294 // calo1_obj->Copy(*calo1_clone);
2295 // }
2296 // if(calo2_clone){
2297 // // *calo2_clone = *calo2_obj;
2298 // calo2_clone->Clear();
2299 // calo2_obj->Copy(*calo2_clone);
2300 // }
2301 // if(tof_clone) *tof_clone = *tof_obj;
2302 // if(trig_clone) *trig_clone = *trig_obj;
2303 // if(s4_clone) *s4_clone = *s4_obj;
2304 // if(nd_clone) *nd_clone = *nd_obj;
2305 // if(ac_clone) *ac_clone = *ac_obj;
2306 // if(orb_clone) *orb_clone = *orb_obj;
2307
2308 // TTree *T = tree_clone;
2309
2310 // T->Fill(); //fill main tree
2311 // // cout<<T->IsA()->GetName()<<" "<<T->GetName()<<endl;
2312 // TList *li = T->GetListOfFriends();
2313 // TIter next(li);
2314 // TFriendElement* T_friend=0;
2315 // while( (T_friend = (TFriendElement*)next()) ){
2316 // // cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;
2317 // T_friend->GetTree()->Fill();//fill friends
2318 // }
2319
2320 // }

  ViewVC Help
Powered by ViewVC 1.1.23