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

Annotation of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (hide annotations) (download)
Mon Dec 11 17:49:03 2006 UTC (17 years, 11 months ago) by pam-fi
Branch: MAIN
Changes since 1.10: +410 -196 lines
*** empty log message ***

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

  ViewVC Help
Powered by ViewVC 1.1.23