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

Contents of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (show annotations) (download)
Tue Jan 16 10:20:21 2007 UTC (18 years, 1 month ago) by pam-fi
Branch: MAIN
Changes since 1.13: +16 -4 lines
Set()

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

  ViewVC Help
Powered by ViewVC 1.1.23