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

Annotation of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (hide annotations) (download)
Mon Jan 15 11:51:40 2007 UTC (17 years, 10 months ago) by pam-fi
Branch: MAIN
Changes since 1.12: +392 -271 lines
v3r00 **NEW**

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

  ViewVC Help
Powered by ViewVC 1.1.23