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

Contents of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15 - (show annotations) (download)
Tue Jan 16 13:00:26 2007 UTC (18 years, 1 month ago) by mocchiut
Branch: MAIN
Changes since 1.14: +14 -1 lines
Added SoftInfo object, RunInfo crash bug fixed, Makefile bug fixed

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

  ViewVC Help
Powered by ViewVC 1.1.23