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

Annotation of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

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

  ViewVC Help
Powered by ViewVC 1.1.23