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

Contents of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.23