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

Contents of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.17 - (show annotations) (download)
Tue Jan 16 15:26:55 2007 UTC (18 years, 1 month ago) by mocchiut
Branch: MAIN
Changes since 1.16: +50 -3 lines
Added method UpdateRunInfo to synchronize reading of events and runs (see example3.C)

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 = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
935 flisttxt = fullpath;
936
937 if( !gSystem->ChangeDirectory(ddir) ){
938 cout << "Cannot change directory : "<<ddir<<endl;
939 return 0;
940 }
941
942 cout <<"Input file list : " << flisttxt <<endl;
943 ifstream in;
944 in.open(flisttxt, ios::in); //open input file list
945 int line=0;
946 while (1) {
947 TString file;
948 in >> file;
949 if (!in.good()) break;
950 line++;
951 // cout <<"(1) " << file << endl;
952 if(file.IsNull()){
953 cout << "-- list interrupted at line "<<line <<endl;
954 break;
955 }
956 if(file.Contains("#"))file = file(0,file.First("#"));
957 // cout <<"(2) " << file << endl;
958 // if( gSystem->IsFileInIncludePath(file,&fullpath) ){
959 if( (fullpath = gSystem->FindFile(ddir,file)) ){
960
961 contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
962
963 }else{
964 // if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
965 };
966 };
967 in.close();
968
969 }else{
970
971 cout << "No input file list given."<<endl;
972 cout << "Check for existing root files."<<endl;
973 // cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
974
975 TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
976 TList *temp = datadir->GetListOfFiles();
977 // temp->Print();
978 // cout << "*************************************" << endl;
979
980 TIter next(temp);
981 TSystemFile *questo = 0;
982
983
984 while ( (questo = (TSystemFile*) next()) ) {
985 TString name = questo-> GetName();
986 if( name.EndsWith(".root") ){
987 const char *fullpath = gSystem->FindFile(ddir,name);
988 // char *fullpath;
989 // gSystem->IsFileInIncludePath(name,&fullpath);
990 contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));
991 };
992 }
993 delete temp;
994 delete datadir;
995
996 };
997 gSystem->ChangeDirectory(wdir); // back to the working directory
998 // cout << endl << "Selected files:" << endl;
999 // contents->Print();
1000 cout << contents->GetEntries()<<" files selected\n";
1001 // cout << endl;
1002 // cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;
1003 return contents;
1004 };
1005 //--------------------------------------
1006 //
1007 //
1008 //--------------------------------------
1009 /**
1010 * Get the Pamela detector chains from a list of files and make them friends.
1011 * @param fl Pointer to a TList of TSystemFiles
1012 * @param detlist String to select trees to be included
1013 * @return Pointer to a TChain
1014 */
1015 TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){
1016
1017 TChain *Trout =0;
1018
1019 // if( !detlist.IsNull() )SetWhichTrees(detlist);
1020 SetWhichTrees(detlist);
1021
1022 cout<< "GetPamTree(TList*,TString): input detector list --> ";
1023 if(TRK1)cout<<"TRK1 ";
1024 if(TRK2)cout<<"TRK2 ";
1025 if(TRKh)cout<<"TRKH ";
1026 if(CAL1)cout<<"CAL1 ";
1027 if(CAL2)cout<<"CAL2 ";
1028 if(TOF)cout<<"TOF ";
1029 if(TRG)cout<<"TRG ";
1030 if(AC)cout<<"AC ";
1031 if(ND)cout<<"ND ";
1032 if(S4)cout<<"S4 ";
1033 if(ORB)cout<<"ORB ";
1034 cout << endl;
1035
1036 TChain *T = 0;
1037 TChain *C = 0;
1038 TChain *O = 0;
1039 TChain *R = 0;
1040 TChain *S = 0;
1041 TChain *N = 0;
1042 TChain *A = 0;
1043 TChain *B = 0;
1044
1045 if(TRK2||TRK1||TRKh) T = new TChain("Tracker");
1046 if(CAL2||CAL1) C = new TChain("Calorimeter");
1047 if(TOF) O = new TChain("ToF");
1048 if(TRG) R = new TChain("Trigger");
1049 if(S4) S = new TChain("S4");
1050 if(ND) N = new TChain("NeutronD");
1051 if(AC) A = new TChain("Anticounter");
1052 if(ORB) B = new TChain("OrbitalInfo");
1053
1054 // loop over files and create chains
1055 TIter next(fl);
1056 TSystemFile *questo = 0;
1057 while ( (questo = (TSystemFile*) next()) ) {
1058 TString name = questo->GetName();
1059 cout << "File: "<< name << endl;
1060 if( CheckLevel2File(name) ){
1061 if(TRK2||TRK1||TRKh) T->Add(name);
1062 if(CAL1||CAL2) C->Add(name);
1063 if(TOF) O->Add(name);
1064 if(TRG) R->Add(name);
1065 if(S4) S->Add(name);
1066 if(ND) N->Add(name);
1067 if(AC) A->Add(name);
1068 if(ORB) B->Add(name);
1069 };
1070 }
1071
1072 cout << "done chain \n";
1073
1074 UInt_t *found=0;
1075 // Tracker
1076 if(T && (TRK2||TRK1||TRKh)) {
1077 if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1078 else T->SetBranchStatus("TrkLevel2",0,found);
1079 if(TRK2)cout << "Tracker : set branch address TrkLevel2"<<endl;
1080 if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1081 else T->SetBranchStatus("TrkLevel1",0,found);
1082 if(TRK1)cout << "Tracker : set branch address TrkLevel1"<<endl;
1083 if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1084 else T->SetBranchStatus("TrkHough",0,found);
1085 if(TRKh)cout << "Tracker : set branch address TrkHough"<<endl;
1086 if(!Trout)Trout=T;
1087 else Trout->AddFriend("Tracker");
1088 }else{
1089 cout << "Tracker : missing tree"<<endl;
1090 };
1091 // Calorimeter
1092 if(C && (CAL2||CAL1)) {
1093 if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1094 else C->SetBranchStatus("CaloLevel2",0,found);
1095 if(CAL2)cout << "Calorimeter : set branch address CaloLevel2"<<endl;
1096 if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1097 else C->SetBranchStatus("CaloLevel1",0,found);
1098 if(CAL1)cout << "Calorimeter : set branch address CaloLevel1"<<endl;
1099 if(!Trout)Trout=C;
1100 else Trout->AddFriend("Calorimeter");
1101 }else{
1102 cout << "Calorimeter : missing tree"<<endl;
1103 };
1104 // ToF
1105 if(O && TOF) {
1106 O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
1107 cout << "ToF : set branch address ToFLevel2"<<endl;
1108 if(!Trout)Trout=O;
1109 else Trout->AddFriend("ToF");
1110 }else{
1111 cout << "ToF : missing tree"<<endl;
1112 };
1113 // Trigger
1114 if(R && TRG) {
1115 R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1116 cout << "Trigger : set branch address TrigLevel2"<<endl;
1117 if(!Trout)Trout=O;
1118 else Trout->AddFriend("Trigger");
1119 }else{
1120 cout << "Trigger : missing tree"<<endl;
1121 };
1122 // S4
1123 if(S && S4) {
1124 S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1125 cout << "S4 : set branch address S4Level2"<<endl;
1126 if(!Trout)Trout=O;
1127 else Trout->AddFriend("S4");
1128 }else{
1129 cout << "S4 : missing tree"<<endl;
1130 };
1131 // Neutron Detector
1132 if(N && ND) {
1133 N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1134 cout << "NeutronD : set branch address NDLevel2"<<endl;
1135 if(!Trout)Trout=O;
1136 else Trout->AddFriend("NeutronD");
1137 }else{
1138 cout << "NeutronD : missing tree"<<endl;
1139 };
1140 // Anticounters
1141 if(A && AC) {
1142 A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1143 cout << "Anticounter : set branch address AcLevel2"<<endl;
1144 if(!Trout)Trout=O;
1145 else Trout->AddFriend("Anticounter");
1146 }else{
1147 cout << "Anticounter : missing tree"<<endl;
1148 };
1149 // Orbital Info
1150 if(B && ORB) {
1151 B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1152 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
1153 if(!Trout)Trout=O;
1154 else Trout->AddFriend("OrbitalInfo");
1155 }else{
1156 cout << "OrbitalInfo : missing tree"<<endl;
1157 };
1158
1159 // cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1160
1161
1162 // // Tracker
1163 // if(TRK2||TRK1||TRKh){
1164 // if(!Tout)Tout=T;
1165 // else Tout->AddFriend("Tracker");
1166 // }
1167 // // Calorimeter
1168 // if(CAL2||CAL1) {
1169 // if(!Tout)Tout=C;
1170 // else Tout->AddFriend("Calorimeter");
1171 // };
1172 // // ToF
1173 // if(TOF) {
1174 // if(!Tout)Tout=O;
1175 // else Tout->AddFriend("ToF");
1176 // };
1177 // // Trigger
1178 // if(TRG) {
1179 // if(!Tout)Tout=R;
1180 // else Tout->AddFriend("Trigger");
1181 // };
1182 // // S4
1183 // if(S4) {
1184 // if(!Tout)Tout=S;
1185 // else Tout->AddFriend("S4");
1186 // };
1187 // // Neutron Detector
1188 // if(ND) {
1189 // if(!Tout)Tout=N;
1190 // else Tout->AddFriend("NeutronD");
1191 // };
1192 // // Anticounters
1193 // if(AC) {
1194 // if(!Tout)Tout=A;
1195 // else Tout->AddFriend("Anticounter");
1196 // };
1197 // // OrbitalInfo
1198 // if(ORB) {
1199 // if(!Tout)Tout=B;
1200 // else Tout->AddFriend("OrbitalInfo");
1201 // };
1202
1203 // cout<<endl<<" Number of entries: "<<Tout->GetEntries()<<endl<<endl;
1204
1205 // if( Tout->GetEntries() )PamLevel2::SetBranchAddress( Tout );
1206
1207 return Trout;
1208 }
1209
1210
1211
1212 //--------------------------------------
1213 //
1214 //
1215 //--------------------------------------
1216 /**
1217 * Set branch addresses for Pamela friend trees
1218 */
1219 void PamLevel2::SetBranchAddress(TTree *t){
1220
1221 TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
1222 TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
1223 TRKh = TRKh & t->GetBranchStatus("TrkHough");
1224 CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
1225 CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
1226 TOF = TOF & t->GetBranchStatus("ToFLevel2");
1227 TRG = TRG & t->GetBranchStatus("TrigLevel2");
1228 S4 = S4 & t->GetBranchStatus("S4Level2");
1229 ND = ND & t->GetBranchStatus("NDLevel2");
1230 AC = AC & t->GetBranchStatus("AcLevel2");
1231 ORB = ORB & t->GetBranchStatus("OrbitalInfo");
1232
1233
1234 // Tracker
1235 if(TRK1) {
1236 t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel2"));
1237 cout << "Tracker : set branch address TrkLevel1"<<endl;
1238 };
1239 if(TRK2) {
1240 t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));
1241 cout << "Tracker : set branch address TrkLevel2"<<endl;
1242 };
1243 if(TRKh) {
1244 t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1245 cout << "Tracker : set branch address TrkHough"<<endl;
1246 };
1247
1248 // Calorimeter
1249 if(CAL1) {
1250 t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1251 cout << "Calorimeter : set branch address CaloLevel1"<<endl;
1252 };
1253 if(CAL2) {
1254 t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1255 cout << "Calorimeter : set branch address CaloLevel2"<<endl;
1256 };
1257
1258 // ToF
1259 if(TOF) {
1260 t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
1261 cout << "ToF : set branch address ToFLevel2"<<endl;
1262 };
1263 // Trigger
1264 if(TRG) {
1265 t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1266 cout << "Trigger : set branch address TrigLevel2"<<endl;
1267 };
1268 // S4
1269 if(S4) {
1270 t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1271 cout << "S4 : set branch address S4Level2"<<endl;
1272 };
1273 // Neutron Detector
1274 if(ND) {
1275 t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1276 cout << "NeutronD : set branch address NDLevel2"<<endl;
1277 };
1278 // Anticounters
1279 if(AC) {
1280 t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1281 cout << "Anticounter : set branch address AcLevel2"<<endl;
1282 };
1283 // OrbitalInfo
1284 if(ORB) {
1285 t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1286 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
1287 };
1288
1289 }
1290 /**
1291 * Set branch addresses for Pamela friend trees
1292 */
1293 void PamLevel2::SetBranchAddress(TChain *t){
1294
1295 TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
1296 TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
1297 TRKh = TRKh & t->GetBranchStatus("TrkHough");
1298 CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
1299 CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
1300 TOF = TOF & t->GetBranchStatus("ToFLevel2");
1301 TRG = TRG & t->GetBranchStatus("TrigLevel2");
1302 S4 = S4 & t->GetBranchStatus("S4Level2");
1303 ND = ND & t->GetBranchStatus("NDLevel2");
1304 AC = AC & t->GetBranchStatus("AcLevel2");
1305 ORB = ORB & t->GetBranchStatus("OrbitalInfo");
1306
1307 // Tracker
1308 if(TRK2) {
1309 t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1310 cout << "Tracker : set branch address TrkLevel2"<<endl;
1311 };
1312 if(TRK1) {
1313 t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1314 cout << "Tracker : set branch address TrkLevel1"<<endl;
1315 };
1316 if(TRKh) {
1317 t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1318 cout << "Tracker : set branch address TrkHough"<<endl;
1319 };
1320
1321 // Calorimeter
1322 if(CAL2) {
1323 t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1324 cout << "Calorimeter : set branch address CaloLevel2"<<endl;
1325 };
1326 if(CAL1) {
1327 t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1328 cout << "Calorimeter : set branch address CaloLevel1"<<endl;
1329 };
1330
1331 // ToF
1332 if(TOF) {
1333 t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
1334 cout << "ToF : set branch address ToFLevel2"<<endl;
1335 };
1336 // Trigger
1337 if(TRG) {
1338 t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1339 cout << "Trigger : set branch address TrigLevel2"<<endl;
1340 };
1341 // S4
1342 if(S4) {
1343 t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1344 cout << "S4 : set branch address S4Level2"<<endl;
1345 };
1346 // Neutron Detector
1347 if(ND) {
1348 t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1349 cout << "NeutronD : set branch address NDLevel2"<<endl;
1350 };
1351 // Anticounters
1352 if(AC) {
1353 t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1354 cout << "Anticounter : set branch address AcLevel2"<<endl;
1355 };
1356 // OrbitalInfo
1357 if(ORB) {
1358 t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1359 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
1360 };
1361
1362 }
1363
1364
1365 //--------------------------------------
1366 //
1367 //
1368 //--------------------------------------
1369 /**
1370 * Get the Run tree chain from a list of files.
1371 * @param fl Pointer to a TList of TSystemFiles
1372 * @return Pointer to a TChain
1373 */
1374 TChain *PamLevel2::GetRunTree(TList *fl){
1375
1376 TChain *R = new TChain("Run");
1377
1378 // loop over files and create chains
1379 TIter next(fl);
1380 TSystemFile *questo = 0;
1381 while ( (questo = (TSystemFile*) next()) ) {
1382 TString name = questo->GetName();
1383 // cout << "File: "<< name << endl;
1384 if( CheckLevel2File(name) ){
1385 R->Add(name);
1386 };
1387 }
1388
1389 R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1390 cout << "Run : set branch address RunInfo"<<endl;
1391 R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1392 cout << "Software : set branch address SoftInfo"<<endl; // Emiliano
1393
1394 return R;
1395
1396 }
1397 //--------------------------------------
1398 //
1399 //
1400 //--------------------------------------
1401 /**
1402 * Get the Run tree from a file.
1403 * @param f Pointer to a TFile
1404 * @return Pointer to a TTree
1405 */
1406 TTree *PamLevel2::GetRunTree(TFile *f){
1407
1408
1409 TTree *R = (TTree*)f->Get("Run");
1410
1411 R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1412 cout << "Run : set branch address RunInfo"<<endl;
1413 R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1414 cout << "Software : set branch address SoftInfo"<<endl; // Emiliano
1415
1416 return R;
1417
1418 }
1419 /**
1420 * Update the runinfo informations (to be used to have Run infos event by event basis)
1421 * @param run Pointer to the chain/tree which contains run infos
1422 * @return true if a new run has been read, false if it is still the same run
1423 */
1424 Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev){
1425 //
1426 // check if we have already called once GetEntry, if not call it
1427 //
1428 if ( run->GetEntries() <= 0 ) return(false);
1429 //
1430 Int_t oldrun = irun;
1431 if ( irun < 0 ){
1432 irun = 0;
1433 run->GetEntry(0);
1434 runfirstentry = 0ULL;
1435 runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS) - 1ULL;
1436 };
1437 while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
1438 // printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
1439 irun++;
1440 run->GetEntry(irun);
1441 runfirstentry = runlastentry+1ULL;
1442 runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS);
1443 };
1444 //
1445 if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
1446 //
1447 // printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
1448 //
1449 return(true);
1450 //
1451 };
1452 /**
1453 * Update the runinfo informations (to be used to have Run infos event by event basis)
1454 * @param run Pointer to the chain/tree which contains run infos
1455 * @return true if a new run has been read, false if it is still the same run
1456 */
1457 Bool_t PamLevel2::UpdateRunInfo(TTree *run, ULong64_t iev){
1458 return(UpdateRunInfo((TChain*)run,iev));
1459 };
1460
1461 //--------------------------------------
1462 //
1463 //
1464 //--------------------------------------
1465 /**
1466 * Set which trees shoul be analysed
1467 * @param detlist TString containing the sequence of trees required
1468 */
1469 void PamLevel2::SetWhichTrees(TString detlist){
1470
1471 if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
1472 CAL1 = true;
1473 CAL2 = true;
1474 TRK2 = true;
1475 TRK1 = false;
1476 TRKh = false;
1477 TRG = true;
1478 TOF = true;
1479 S4 = true;
1480 ND = true;
1481 AC = true;
1482 ORB = true;
1483 }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
1484 CAL1 = false;
1485 CAL2 = false;
1486 TRK2 = false;
1487 TRK1 = false;
1488 TRKh = false;
1489 TRG = false;
1490 TOF = false;
1491 S4 = false;
1492 ND = false;
1493 AC = false;
1494 ORB = false;
1495 };
1496
1497 // -------------------------------------------------------------------------
1498 if( detlist.Contains("CAL1", TString::kIgnoreCase) ){
1499 if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;
1500 if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;
1501 };
1502
1503 if( detlist.Contains("CAL2", TString::kIgnoreCase)){
1504 if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;
1505 if ( detlist.Contains("+CAL2", TString::kIgnoreCase) )CAL2=true;
1506 };
1507
1508 if( detlist.Contains("+CAL", TString::kIgnoreCase) && !CAL1 && !CAL2 )CAL2=true;
1509 if( detlist.Contains("-CAL", TString::kIgnoreCase) && CAL1 && CAL2 ){
1510 CAL2=false;
1511 CAL1=false;
1512 }
1513 // -------------------------------------------------------------------------
1514 if( detlist.Contains("TRK1", TString::kIgnoreCase) ){
1515 if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;
1516 if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;
1517 };
1518
1519 if( detlist.Contains("TRK2", TString::kIgnoreCase)){
1520 if ( detlist.Contains("-TRK2", TString::kIgnoreCase) )TRK2=false;
1521 if ( detlist.Contains("+TRK2", TString::kIgnoreCase) )TRK2=true;
1522 };
1523
1524 if( detlist.Contains("TRKh", TString::kIgnoreCase)){
1525 if ( detlist.Contains("-TRKh", TString::kIgnoreCase) )TRKh=false;
1526 if ( detlist.Contains("+TRKh", TString::kIgnoreCase) )TRKh=true;
1527 };
1528
1529 if( detlist.Contains("+TRK", TString::kIgnoreCase) && !TRK1 && !TRK2 && !TRKh )TRK2=true;
1530 if( detlist.Contains("-TRK", TString::kIgnoreCase) && TRK1 && TRK2 && TRKh){
1531 TRK2=false;
1532 TRK1=false;
1533 TRKh=false;
1534 }
1535 // -------------------------------------------------------------------------
1536
1537 if( detlist.Contains("-TRG", TString::kIgnoreCase) )TRG = false;
1538 else if( detlist.Contains("+TRG", TString::kIgnoreCase) )TRG = true;
1539
1540 if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
1541 else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
1542
1543 if( detlist.Contains("-S4", TString::kIgnoreCase) )S4 = false;
1544 else if( detlist.Contains("+S4", TString::kIgnoreCase) )S4 = true;
1545
1546 if( detlist.Contains("-ND", TString::kIgnoreCase) )ND = false;
1547 else if( detlist.Contains("+ND", TString::kIgnoreCase) )ND = true;
1548
1549 if( detlist.Contains("-AC", TString::kIgnoreCase) )AC = false;
1550 else if( detlist.Contains("+AC", TString::kIgnoreCase) )AC = true;
1551
1552 if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;
1553 else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;
1554
1555 // cout<< "Set detector list --> ";
1556 // if(TRK1)cout<<"TRK1 ";
1557 // if(TRK2)cout<<"TRK2 ";
1558 // if(TRKh)cout<<"TRKH ";
1559 // if(CAL1)cout<<"CAL1 ";
1560 // if(CAL2)cout<<"CAL2 ";
1561 // if(TOF)cout<<"TOF ";
1562 // if(TRG)cout<<"TRG ";
1563 // if(AC)cout<<"AC ";
1564 // if(ND)cout<<"ND ";
1565 // if(S4)cout<<"S4 ";
1566 // if(ORB)cout<<"ORB ";
1567 // cout << endl;
1568
1569 };
1570
1571
1572 /**
1573 * Set tree/branch detector flags from the content of a tree
1574 */
1575 void PamLevel2::GetWhichTrees(TFile* f){
1576
1577 // -----------
1578 // reset flags
1579 // -----------
1580 CAL1 = false;
1581 CAL2 = false;
1582 TRK2 = false;
1583 TRK1 = false;
1584 TRKh = false;
1585 TRG = false;
1586 TOF = false;
1587 S4 = false;
1588 ND = false;
1589 AC = false;
1590 ORB = false;
1591
1592 RUN = false;
1593
1594 cout << "Checking file: "<<f->GetName()<<endl;
1595 if( !f || f->IsZombie() ){
1596 cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;
1597 return;
1598 }
1599
1600 TList *lk = f->GetListOfKeys();
1601 TIter next(lk);
1602 TKey *key =0;
1603
1604 Int_t nev = 0;
1605
1606 while( (key = (TKey*)next()) ){
1607
1608 if( !strcmp(key->GetName(),"Run" ) )RUN = true;
1609
1610 //=========================================================
1611 if( !strcmp(key->GetName(),"Trigger" ) ){
1612 TRG = true;
1613 Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries();
1614 if( nev && nevt!=nev){
1615 cout << "File: "<< f->GetName() <<" Trigger tree has "<<nevt<<" events instead of "<<nev<< endl;
1616 TRG = false;
1617 }else nev=nevt;
1618 }
1619 //=========================================================
1620 if( !strcmp(key->GetName(),"ToF" ) ){
1621 TOF = true;
1622 Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries();
1623 if( nev && nevt!=nev){
1624 cout << "File: "<< f->GetName() <<" ToF tree has "<<nevt<<" events instead of "<<nev<< endl;
1625 TOF = false;
1626 }else nev=nevt;
1627 }
1628 //=========================================================
1629 if( !strcmp(key->GetName(),"S4" ) ){
1630 S4 = true;
1631 Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries();
1632 if( nev && nevt!=nev){
1633 cout << "File: "<< f->GetName() <<" S4 tree has "<<nevt<<" events instead of "<<nev<< endl;
1634 S4 = false;
1635 }else nev=nevt;
1636 }
1637 //=========================================================
1638
1639 if( !strcmp(key->GetName(),"NeutronD" ) ){
1640 ND = true;
1641 Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries();
1642 if( nev && nevt!=nev){
1643 cout << "File: "<< f->GetName() <<"NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl;
1644 ND =false;
1645 }else nev=nevt;
1646 }
1647 //=========================================================
1648 if( !strcmp(key->GetName(),"Anticounter") ){
1649 AC = true;
1650 Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries();
1651 if( nev && nevt!=nev){
1652 cout << "File: "<< f->GetName() <<" Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl;
1653 AC =false;
1654 }else nev=nevt;
1655 }
1656 //=========================================================
1657 if( !strcmp(key->GetName(),"OrbitalInfo") ){
1658 ORB = true;
1659 Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries();
1660 if( nev && nevt!=nev){
1661 cout << "File: "<< f->GetName() <<" OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
1662 ORB = false;
1663 }else nev=nevt;
1664 }
1665 //=========================================================
1666 if( !strcmp(key->GetName(),"Tracker" ) ){
1667 TTree *T = (TTree*)f->Get("Tracker");
1668 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
1669 TString name = T->GetListOfBranches()->At(i)->GetName();
1670 if( !name.CompareTo("TrkLevel1") )TRK1=true;
1671 if( !name.CompareTo("TrkLevel2") )TRK2=true;
1672 if( !name.CompareTo("TrkHough") )TRKh=true;
1673 };
1674 Int_t nevt = T->GetEntries();
1675 if( nev && nevt!=nev){
1676 cout << "File: "<< f->GetName() <<" Tracker tree has "<<nevt<<" events instead of "<<nev<< endl;
1677 TRK1 = false;
1678 TRK2 = false;
1679 TRKh = false;
1680 }else nev=nevt;
1681 T->Delete();
1682 };
1683 //=========================================================
1684 if( !strcmp(key->GetName(),"Calorimeter" ) ){
1685 TTree *T = (TTree*)f->Get("Calorimeter");
1686 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
1687 TString name = T->GetListOfBranches()->At(i)->GetName();
1688 if( !name.CompareTo("CaloLevel1") )CAL1=true;
1689 if( !name.CompareTo("CaloLevel2") )CAL2=true;
1690 };
1691 Int_t nevt = T->GetEntries();
1692 if( nev && nevt!=nev){
1693 cout << "File: "<< f->GetName() <<" Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl;
1694 CAL1 = false;
1695 CAL2 = false;
1696 }else nev=nevt;
1697 T->Delete();
1698 };
1699
1700 };
1701
1702 delete lk;
1703
1704 // cout<< "Get detector list from input file --> ";
1705 // if(TRK1)cout<<"TRK1 ";
1706 // if(TRK2)cout<<"TRK2 ";
1707 // if(TRKh)cout<<"TRKH ";
1708 // if(CAL1)cout<<"CAL1 ";
1709 // if(CAL2)cout<<"CAL2 ";
1710 // if(TOF)cout<<"TOF ";
1711 // if(TRG)cout<<"TRG ";
1712 // if(AC)cout<<"AC ";
1713 // if(ND)cout<<"ND ";
1714 // if(S4)cout<<"S4 ";
1715 // if(ORB)cout<<"ORB ";
1716 // cout << endl;
1717
1718 return ;
1719
1720 };
1721
1722
1723 //--------------------------------------
1724 //
1725 //
1726 //--------------------------------------
1727 /**
1728 * Check if a file contains selected Pamela Level2 trees.
1729 * @param name File name
1730 * @return true if the file is ok.
1731 */
1732 Bool_t PamLevel2::CheckLevel2File(TString name){
1733
1734 Bool_t CAL1__ok = false;
1735 Bool_t CAL2__ok = false;
1736 Bool_t TRK2__ok = false;
1737 Bool_t TRK1__ok = false;
1738 Bool_t TRKh__ok = false;
1739 Bool_t TRG__ok = false;
1740 Bool_t TOF__ok = false;
1741 Bool_t S4__ok = false;
1742 Bool_t ND__ok = false;
1743 Bool_t AC__ok = false;
1744 Bool_t ORB__ok = false;
1745
1746 Bool_t RUN__ok = false;
1747
1748
1749
1750 cout << "Checking file: "<<name<<endl;
1751 TFile *f = new TFile(name.Data());
1752 if( !f || f->IsZombie() ){
1753 cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false;
1754 }
1755 // cout << "Get list of keys: "<<f<<endl;
1756 TList *lk = f->GetListOfKeys();
1757 // lk->Print();
1758 TIter next(lk);
1759 TKey *key =0;
1760
1761 Int_t nev = 0;
1762
1763 while( (key = (TKey*)next()) ){
1764
1765 // cout << key->GetName() << ""<<key->GetClassName()<<endl;
1766 // cout << " Get tree: " << f->Get(key->GetName())<<endl;
1767 // nev_previous = nev;
1768 // cout << " n.entries "<< nev <<endl;
1769 // if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){
1770 // nev = ((TTree*)f->Get(key->GetName()))->GetEntries();
1771 // cout << "File: "<< f->GetName() <<" discarded ---- "<< key->GetName() << " tree: n.entries does not match "<<nev<<" "<<nev_previous<< endl;
1772 // return false;
1773 // };
1774
1775 if( !strcmp(key->GetName(),"Run" ) )RUN__ok = true;
1776
1777 //=========================================================
1778 if( !strcmp(key->GetName(),"Trigger" ) ){
1779 TRG__ok = true;
1780 if(TRG){
1781 Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries();
1782 if( nev && nevt!=nev){
1783 cout << "File: "<< f->GetName() <<" discarded ---- Trigger tree has "<<nevt<<" events instead of "<<nev<< endl;
1784 return false;
1785 }
1786 nev=nevt;
1787 }
1788 }
1789 //=========================================================
1790 if( !strcmp(key->GetName(),"ToF" ) ){
1791 TOF__ok = true;
1792 if(TOF){
1793 Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries();
1794 if( nev && nevt!=nev){
1795 cout << "File: "<< f->GetName() <<" discarded ---- ToF tree has "<<nevt<<" events instead of "<<nev<< endl;
1796 return false;
1797 }
1798 nev=nevt;
1799 }
1800 }
1801 //=========================================================
1802 if( !strcmp(key->GetName(),"S4" ) ){
1803 S4__ok = true;
1804 if(S4){
1805 Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries();
1806 if( nev && nevt!=nev){
1807 cout << "File: "<< f->GetName() <<" discarded ---- S4 tree has "<<nevt<<" events instead of "<<nev<< endl;
1808 return false;
1809 }
1810 nev=nevt;
1811 }
1812 }
1813 //=========================================================
1814
1815 if( !strcmp(key->GetName(),"NeutronD" ) ){
1816 ND__ok = true;
1817 if(ND){
1818 Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries();
1819 if( nev && nevt!=nev){
1820 cout << "File: "<< f->GetName() <<" discarded ---- NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl;
1821 return false;
1822 }
1823 nev=nevt;
1824 }
1825 }
1826 //=========================================================
1827 if( !strcmp(key->GetName(),"Anticounter") ){
1828 AC__ok = true;
1829 if(AC){
1830 Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries();
1831 if( nev && nevt!=nev){
1832 cout << "File: "<< f->GetName() <<" discarded ---- Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl;
1833 return false;
1834 }
1835 nev=nevt;
1836 }
1837 }
1838 //=========================================================
1839 if( !strcmp(key->GetName(),"OrbitalInfo") ){
1840 ORB__ok = true;
1841 if(ORB){
1842 Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries();
1843 if( nev && nevt!=nev){
1844 cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
1845 return false;
1846 }
1847 nev=nevt;
1848 }
1849 }
1850 //=========================================================
1851 if( !strcmp(key->GetName(),"Tracker" ) ){
1852 TTree *T = (TTree*)f->Get("Tracker");
1853 if(TRK1||TRK2||TRKh){
1854 Int_t nevt = T->GetEntries();
1855 if( nev && nevt!=nev){
1856 cout << "File: "<< f->GetName() <<" discarded ---- Tracker tree has "<<nevt<<" events instead of "<<nev<< endl;
1857 return false;
1858 }
1859 nev=nevt;
1860 }
1861 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
1862 TString name = T->GetListOfBranches()->At(i)->GetName();
1863 if( !name.CompareTo("TrkLevel1") )TRK1__ok=true;
1864 if( !name.CompareTo("TrkLevel2") )TRK2__ok=true;
1865 if( !name.CompareTo("TrkHough") )TRKh__ok=true;
1866 };
1867 T->Delete();
1868 };
1869 //=========================================================
1870 if( !strcmp(key->GetName(),"Calorimeter" ) ){
1871 TTree *T = (TTree*)f->Get("Calorimeter");
1872 if(CAL1||CAL2){
1873 Int_t nevt = T->GetEntries();
1874 if( nev && nevt!=nev){
1875 cout << "File: "<< f->GetName() <<" discarded ---- Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl;
1876 return false;
1877 }
1878 nev=nevt;
1879 }
1880 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
1881 TString name = T->GetListOfBranches()->At(i)->GetName();
1882 if( !name.CompareTo("CaloLevel1") )CAL1__ok=true;
1883 if( !name.CompareTo("CaloLevel2") )CAL2__ok=true;
1884 };
1885 T->Delete();
1886 };
1887
1888 };
1889
1890 // cout<< "CheckLevel2File(TString): detector list --> ";
1891 // if(TRK1__ok)cout<<"TRK1 ";
1892 // if(TRK2__ok)cout<<"TRK2 ";
1893 // if(TRKh__ok)cout<<"TRKH ";
1894 // if(CAL1__ok)cout<<"CAL1 ";
1895 // if(CAL2__ok)cout<<"CAL2 ";
1896 // if(TOF__ok)cout<<"TOF ";
1897 // if(TRG__ok)cout<<"TRG ";
1898 // if(AC__ok)cout<<"AC ";
1899 // if(ND__ok)cout<<"ND ";
1900 // if(S4__ok)cout<<"S4 ";
1901 // if(ORB__ok)cout<<"ORB ";
1902 // cout << endl;
1903
1904
1905 if(TRK2 && TRK1__ok)TRK1=1;
1906 // ----------------------------------------------------------------------------
1907 // NOTA
1908 // se c'e` il level1, lo devo necessarimente leggere.
1909 // infatti (non ho capito perche`) i cluster vengono letti e allocati in memoria
1910 // comunque, ma non vengono disallocati da PamLevel2::Clear()
1911 // ----------------------------------------------------------------------------
1912
1913
1914 if(!RUN__ok) {
1915 cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree"<< endl;
1916 // return false;
1917 };
1918
1919 if(CAL1 && !CAL1__ok){
1920 cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel1 branch"<< endl;
1921 return false;
1922 };
1923 if(CAL2 && !CAL2__ok){
1924 cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel2 branch"<< endl;
1925 return false;
1926 };
1927 if(TRK2 && !TRK2__ok){
1928 cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel2 branch"<< endl;
1929 return false;
1930 };
1931 if(TRK1 && !TRK1__ok){
1932 cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel1 branch"<< endl;
1933 return false;
1934 };
1935 if(TRKh && !TRKh__ok){
1936 cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkHough branch"<< endl;
1937 return false;
1938 };
1939 if(ORB && !ORB__ok){
1940 cout << "File: "<< f->GetName() <<" discarded ---- Missing ORB tree"<< endl;
1941 return false;
1942 };
1943 if(AC && !AC__ok){
1944 cout << "File: "<< f->GetName() <<" discarded ---- Missing AC tree"<< endl;
1945 return false;
1946 };
1947 if(S4 && !S4__ok){
1948 cout << "File: "<< f->GetName() <<" discarded ---- Missing S4 tree"<< endl;
1949 return false;
1950 };
1951 if(TOF && !TOF__ok){
1952 cout << "File: "<< f->GetName() <<" discarded ---- Missing ToF tree"<< endl;
1953 return false;
1954 };
1955
1956 if(ND && !ND__ok){
1957 cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl;
1958 return false;
1959 };
1960 if(TRG && !TRG__ok){
1961 cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;
1962 return false;
1963 };
1964
1965
1966 // lk->Delete();
1967 // delete lk;
1968 f->Close();
1969
1970 // cout<< "CheckLevel2File(TString): detector list --> ";
1971 // if(TRK1)cout<<"TRK1 ";
1972 // if(TRK2)cout<<"TRK2 ";
1973 // if(TRKh)cout<<"TRKH ";
1974 // if(CAL1)cout<<"CAL1 ";
1975 // if(CAL2)cout<<"CAL2 ";
1976 // if(TOF)cout<<"TOF ";
1977 // if(TRG)cout<<"TRG ";
1978 // if(AC)cout<<"AC ";
1979 // if(ND)cout<<"ND ";
1980 // if(S4)cout<<"S4 ";
1981 // if(ORB)cout<<"ORB ";
1982 // cout << endl;
1983
1984 return true;
1985
1986 };
1987
1988
1989 /**
1990 * Create clone-trees
1991 */
1992 void PamLevel2::CreateCloneTrees0( TChain *fChain, TFile *ofile ){
1993
1994 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1995 cout << "Create clones of PAMELA trees "<<endl;
1996
1997 Int_t i=0;
1998 tree_clone[i] = fChain->GetTree()->CloneTree(0);
1999 TString name = tree_clone[i]->GetName();
2000 name.Append("_clone");
2001 // tree_clone[i]->SetName(name.Data());
2002 cout << tree_clone[i]->GetName() <<endl;
2003 i++;
2004
2005 TList *li = fChain->GetListOfFriends();
2006 TIter next(li);
2007 TFriendElement* T_friend=0;
2008 ofile->cd();
2009 while( (T_friend = (TFriendElement*)next()) ){
2010 // cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;
2011 // cout<<T_friend->GetTree()->GetName()<< endl;
2012 tree_clone[i] = T_friend->GetTree()->CloneTree(0);
2013 tree_clone[i]->SetAutoSave(1000000);
2014 name = tree_clone[i]->GetName();
2015 name.Append("_clone");
2016 // tree_clone[i]->SetName(name.Data());
2017 cout << tree_clone[i]->GetName() << endl;
2018 i++;
2019 }
2020
2021 delete li;
2022
2023 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2024
2025 }
2026
2027 /**
2028 * Create clone-trees
2029 */
2030 void PamLevel2::CreateCloneTrees(TFile *ofile){
2031
2032 ofile->cd();
2033
2034 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2035 cout << "Create new PAMELA trees "<<endl;
2036
2037 Int_t i=0;
2038
2039 if(TRK1||TRK2||TRKh){
2040 tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");
2041 if(TRK1) {
2042 tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
2043 tree_clone[i]->BranchRef();
2044 cout << "Tracker : branch TrkLevel1"<<endl;
2045 };
2046 if(TRK2) {
2047 tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
2048 cout << "Tracker : branch TrkLevel2"<<endl;
2049 };
2050 if(TRKh) {
2051 tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));
2052 cout << "Tracker : branch TrkHough"<<endl;
2053 };
2054 i++;
2055 }
2056
2057 // Calorimeter
2058 if(CAL1||CAL2){
2059 tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");
2060 if(CAL1) {
2061 tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
2062 cout << "Calorimeter : branch CaloLevel1"<<endl;
2063 };
2064 if(CAL2) {
2065 tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));
2066 cout << "Calorimeter : branch CaloLevel2"<<endl;
2067 };
2068 i++;
2069 }
2070
2071 // ToF
2072 if(TOF) {
2073 tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");
2074 tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));
2075 cout << "ToF : branch ToFLevel2"<<endl;
2076 i++;
2077 };
2078 // Trigger
2079 if(TRG) {
2080 tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");
2081 tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));
2082 cout << "Trigger : branch TrigLevel2"<<endl;
2083 i++;
2084 };
2085 // S4
2086 if(S4) {
2087 tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");
2088 tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));
2089 cout << "S4 : branch S4Level2"<<endl;
2090 i++;
2091 };
2092 // Neutron Detector
2093 if(ND) {
2094 tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");
2095 tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));
2096 cout << "NeutronD : branch NDLevel2"<<endl;
2097 i++;
2098 };
2099 // Anticounters
2100 if(AC) {
2101 tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");
2102 tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));
2103 cout << "Anticounter : branch AcLevel2"<<endl;
2104 i++;
2105 };
2106 // OrbitalInfo
2107 if(ORB) {
2108 tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info ");
2109 tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));
2110 cout << "OrbitalInfo : branch OrbitalInfo"<<endl;
2111 i++;
2112 };
2113 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2114
2115 }
2116
2117
2118 /**
2119 * Fill tree (created with CreateCloneTrees)
2120 *
2121 */
2122 //void PamLevel2::FillNewPamTree(TTree *T){
2123 void PamLevel2::FillCloneTrees(){
2124
2125 for(Int_t i=0; i<8; i++){
2126 if(tree_clone[i])tree_clone[i]->Fill();
2127 }
2128 }
2129
2130
2131 TTree* PamLevel2::GetCloneTree(TString name){
2132
2133 for(Int_t i=0; i<8; i++){
2134 if(tree_clone[i]){
2135 TString na = tree_clone[i]->GetName();
2136 if(!name.CompareTo(na))return tree_clone[i];
2137 };
2138 }
2139 return NULL;
2140
2141 }
2142 void PamLevel2::WriteCloneTrees(){
2143 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2144 cout << "Write clones of PAMELA trees "<<endl;
2145 for(Int_t i=0; i<8; i++){
2146 if(tree_clone[i]){
2147 cout << tree_clone[i]->GetName()<<endl;
2148 tree_clone[i]->Write();
2149 };
2150 }
2151 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2152
2153 }
2154
2155 /**
2156 * Create a new (empty) Pamela trees
2157 */
2158 // TTree* PamLevel2::GetNewPamTree(){
2159
2160 // if(tree_clone)return tree_clone;
2161
2162 // TTree *Tout = 0;
2163
2164 // cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2165 // cout << "Create new PAMELA trees "<<endl;
2166
2167
2168 // if(TRK1||TRK2||TRKh){
2169 // TTree *T = new TTree("Tracker_clone","PAMELA tracker level2 data ");
2170 // if(TRK1) {
2171 // trk1_clone = new TrkLevel1();
2172 // T->Branch("TrkLevel1","TrkLevel1", &trk1_clone);
2173 // T->BranchRef();
2174 // cout << "Tracker : branch TrkLevel1"<<endl;
2175 // };
2176 // if(TRK2) {
2177 // trk2_clone = new TrkLevel2();
2178 // T->Branch("TrkLevel2", "TrkLevel2",&trk2_clone);
2179 // cout << "Tracker : branch TrkLevel2"<<endl;
2180 // };
2181 // if(TRKh) {
2182 // trkh_clone = new TrkHough();
2183 // T->Branch("TrkHough","TrkHough", &trkh_clone);
2184 // cout << "Tracker : branch TrkHough"<<endl;
2185 // };
2186 // if(!Tout)Tout=T;
2187 // else Tout->AddFriend("Tracker_clone");
2188 // }
2189
2190 // // Calorimeter
2191 // if(CAL1||CAL2){
2192 // TTree *C = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");
2193 // if(CAL1) {
2194 // calo1_clone = new CaloLevel1();
2195 // C->Branch("CaloLevel1", "CaloLevel1", &calo1_clone);
2196 // cout << "Calorimeter : branch CaloLevel1"<<endl;
2197 // };
2198 // if(CAL2) {
2199 // calo2_clone = new CaloLevel2();
2200 // C->Branch("CaloLevel2","CaloLevel2", &calo2_clone);
2201 // cout << "Calorimeter : branch CaloLevel2"<<endl;
2202 // };
2203 // if(!Tout)Tout=C;
2204 // else Tout->AddFriend("Calorimeter_clone");
2205 // }
2206
2207 // // ToF
2208 // if(TOF) {
2209 // TTree *O = new TTree("ToF_clone","PAMELA ToF level2 data ");
2210 // tof_clone = new ToFLevel2();
2211 // O->Branch("ToFLevel2","ToFLevel2", &tof_clone);
2212 // cout << "ToF : branch ToFLevel2"<<endl;
2213 // if(!Tout)Tout=O;
2214 // else Tout->AddFriend("ToF_clone");
2215 // };
2216 // // Trigger
2217 // if(TRG) {
2218 // TTree *R = new TTree("Trigger_clone","PAMELA trigger level2 data ");
2219 // trig_clone = new TrigLevel2();
2220 // R->Branch("TrigLevel2","TrigLevel2", &trig_clone);
2221 // cout << "Trigger : branch TrigLevel2"<<endl;
2222 // if(!Tout)Tout=R;
2223 // else Tout->AddFriend("Trigger_clone");
2224 // };
2225 // // S4
2226 // if(S4) {
2227 // TTree *S = new TTree("S4_clone","PAMELA S4 level2 data ");
2228 // s4_clone = new S4Level2();
2229 // S->Branch("S4Level2","S4Level2", &s4_clone);
2230 // cout << "S4 : branch S4Level2"<<endl;
2231 // if(!Tout)Tout=S;
2232 // else Tout->AddFriend("S4_clone");
2233 // };
2234 // // Neutron Detector
2235 // if(ND) {
2236 // TTree *N = new TTree("NeutronD_clone","PAMELA neutron detector level2 data ");
2237 // nd_clone = new NDLevel2();
2238 // N->Branch("NDLevel2","NDLevel2", &nd_clone);
2239 // cout << "NeutronD : branch NDLevel2"<<endl;
2240 // if(!Tout)Tout=N;
2241 // else Tout->AddFriend("NeutronD_clone");
2242 // };
2243 // // Anticounters
2244 // if(AC) {
2245 // TTree *A = new TTree("Anticounter_clone","PAMELA anticounter detector level2 data ");
2246 // ac_clone = new AcLevel2();
2247 // A->Branch("AcLevel2","AcLevel2", &ac_clone);
2248 // cout << "Anticounter : branch AcLevel2"<<endl;
2249 // if(!Tout)Tout=A;
2250 // else Tout->AddFriend("Anticounter_clone");
2251 // };
2252 // // OrbitalInfo
2253 // if(ORB) {
2254 // TTree *B = new TTree("OrbitalInfo_clone","PAMELA oribital info ");
2255 // orb_clone = new OrbitalInfo();
2256 // B->Branch("OrbitalInfo","OrbitalInfo", &orb_clone);
2257 // cout << "OrbitalInfo : branch OrbitalInfo"<<endl;
2258 // if(!Tout)Tout=B;
2259 // else Tout->AddFriend("OrbitalInfo_clone");
2260 // };
2261 // cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2262
2263 // tree_clone = Tout;
2264 // tree_clone->SetDirectory(0);
2265
2266 // return Tout;
2267 // }
2268 // /**
2269 // * Fill a tree (created with GetNewPamTree)
2270 // *
2271 // */
2272 // //void PamLevel2::FillNewPamTree(TTree *T){
2273 // void PamLevel2::FillNewPamTree(){
2274
2275
2276 // if(trk1_clone) *trk1_clone = *trk1_obj;
2277 // if(trk2_clone){
2278 // trk2_clone->Clear();
2279 // trk2_obj->Copy(*trk2_clone);
2280 // // *trk2_clone = *trk2_obj;
2281 // }
2282 // if(trkh_clone) *trkh_clone = *trkh_obj;
2283 // if(calo1_clone){
2284 // // *calo1_clone = *calo1_obj;
2285 // calo1_clone->Clear();
2286 // calo1_obj->Copy(*calo1_clone);
2287 // }
2288 // if(calo2_clone){
2289 // // *calo2_clone = *calo2_obj;
2290 // calo2_clone->Clear();
2291 // calo2_obj->Copy(*calo2_clone);
2292 // }
2293 // if(tof_clone) *tof_clone = *tof_obj;
2294 // if(trig_clone) *trig_clone = *trig_obj;
2295 // if(s4_clone) *s4_clone = *s4_obj;
2296 // if(nd_clone) *nd_clone = *nd_obj;
2297 // if(ac_clone) *ac_clone = *ac_obj;
2298 // if(orb_clone) *orb_clone = *orb_obj;
2299
2300 // TTree *T = tree_clone;
2301
2302 // T->Fill(); //fill main tree
2303 // // cout<<T->IsA()->GetName()<<" "<<T->GetName()<<endl;
2304 // TList *li = T->GetListOfFriends();
2305 // TIter next(li);
2306 // TFriendElement* T_friend=0;
2307 // while( (T_friend = (TFriendElement*)next()) ){
2308 // // cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;
2309 // T_friend->GetTree()->Fill();//fill friends
2310 // }
2311
2312 // }

  ViewVC Help
Powered by ViewVC 1.1.23