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

Annotation of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (hide annotations) (download)
Tue Nov 28 10:58:34 2006 UTC (18 years ago) by pam-fi
Branch: MAIN
Changes since 1.7: +430 -158 lines
implemented CaloLevel1, TrkHough and other things...

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.8 trk1_obj = this->TrkLevel1::GetTrkLevel1();
40     trk2_obj = this->TrkLevel2::GetTrkLevel2();
41     trkh_obj = this->TrkHough::GetTrkHough();
42     calo1_obj = this->CaloLevel1::GetCaloLevel1();
43     calo2_obj = this->CaloLevel2::GetCaloLevel2();
44     tof_obj = this->ToFLevel2::GetToFLevel2();
45     trig_obj = this->TrigLevel2::GetTrigLevel2();
46     s4_obj = this->S4Level2::GetS4Level2();
47     nd_obj = this->NDLevel2::GetNDLevel2();
48     ac_obj = this->AcLevel2::GetAcLevel2();
49     orb_obj = this->OrbitalInfo::GetOrbitalInfo();
50 pam-fi 1.2
51 pam-fi 1.8 run_obj = new GL_RUN();
52 pam-fi 1.6
53     sorted_tracks = new TRefArray();
54    
55 pam-fi 1.8 CAL2 = true;
56     TRK2 = true;
57     TRK1 = false;
58     TRKh = false;
59 pam-fi 1.6 TRG = true;
60     TOF = true;
61     S4 = true;
62     ND = true;
63     AC = true;
64     ORB = true;
65    
66 pam-fi 1.8
67 pam-fi 1.2 };
68     /**
69     * Destructor
70     */
71     PamLevel2::~PamLevel2(){
72    
73 pam-fi 1.6 TrkLevel1::Clear();
74    
75     TrkLevel2::Clear();
76     CaloLevel2::Clear();
77     ToFLevel2::Clear();
78     TrigLevel2::Clear();
79     S4Level2::Clear();
80     NDLevel2::Clear();
81     AcLevel2::Clear();
82     OrbitalInfo::Clear();
83    
84     delete run_obj;
85    
86 pam-fi 1.4 // delete sorted_tracks;
87 pam-fi 1.6 sorted_tracks->Delete(); // clean the reference array
88 pam-fi 1.4
89 pam-fi 1.2
90     };
91     /**
92     * Clear the event
93     */
94     void PamLevel2::Clear(){
95 pam-fi 1.3
96 pam-fi 1.6 TrkLevel1::Clear();
97 pam-fi 1.2
98 pam-fi 1.6 TrkLevel2::Clear();
99     CaloLevel2::Clear();
100     ToFLevel2::Clear();
101     TrigLevel2::Clear();
102     S4Level2::Clear();
103     NDLevel2::Clear();
104     AcLevel2::Clear();
105     OrbitalInfo::Clear();
106    
107     sorted_tracks->Delete(); // clean the reference array
108    
109 pam-fi 1.1 };
110 pam-fi 1.2
111    
112 pam-fi 1.1 //--------------------------------------
113     //
114     //
115     //--------------------------------------
116     /**
117 pam-fi 1.3 * Retrieves the calorimeter track matching the seqno-th tracker stored track.
118     * (If seqno = -1 retrieves the self-trigger calorimeter track)
119     */
120     CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
121    
122 pam-fi 1.6 if( CaloLevel2::ntrk()==0 ){
123     cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;
124     return NULL;
125     };
126    
127     CaloTrkVar *c = 0;
128     Int_t it_calo=0;
129    
130     do{
131     c = CaloLevel2::GetCaloTrkVar(it_calo);
132     it_calo++;
133     } while( c && seqno != c->trkseqno && it_calo < CaloLevel2::ntrk());
134    
135     if(!c || seqno != c->trkseqno){
136     c = 0;
137     if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;
138     };
139     return c;
140    
141 pam-fi 1.3 };
142     //--------------------------------------
143     //
144     //
145     //--------------------------------------
146     /**
147     * Retrieves the ToF track matching the seqno-th tracker stored track.
148     * (If seqno = -1 retrieves the tracker-independent tof track)
149     */
150     ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
151    
152 pam-fi 1.6 if( ToFLevel2::ntrk()==0 ){
153     cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;
154     return NULL;
155     };
156    
157     ToFTrkVar *c = 0;
158     Int_t it_tof=0;
159    
160     do{
161     c = ToFLevel2::GetToFTrkVar(it_tof);
162     it_tof++;
163     } while( c && seqno != c->trkseqno && it_tof < ToFLevel2::ntrk());
164    
165     if(!c || seqno != c->trkseqno){
166     c = 0;
167     if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;
168     };
169     return c;
170    
171 pam-fi 1.3 };
172    
173     //--------------------------------------
174     //
175     //
176     //--------------------------------------
177     /**
178     * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.
179     */
180     PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
181    
182 pam-fi 1.6 CaloTrkVar *c = 0;
183     ToFTrkVar *o = 0;
184    
185 pam-fi 1.8 if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());
186 pam-fi 1.6 if(TOF) o = GetToFStoredTrack(t->GetSeqNo());
187    
188 pam-fi 1.3 // if(t && c && o)track = new PamTrack(t,c,o);
189 pam-fi 1.6 PamTrack *track = new PamTrack(t,c,o);
190    
191     return track;
192 pam-fi 1.3
193     };
194     //--------------------------------------
195     //
196     //
197     //--------------------------------------
198     /**
199 pam-fi 1.1 * Retrieves the it-th stored track.
200     * It override TrkLevel2::GetTrack(int it).
201     * @param itrk Track number, ranging from 0 to GetNTracks().
202     */
203    
204     PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
205    
206 pam-fi 1.6 PamTrack *track = 0;
207    
208     if( itrk >=0 && itrk < TrkLevel2::ntrk() ){
209 pam-fi 1.3
210 pam-fi 1.6 TrkTrack *t = TrkLevel2::GetStoredTrack(itrk);
211     track = GetPamTrackAlong(t);
212 pam-fi 1.2
213 pam-fi 1.6 }else{
214     cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;
215     };
216    
217     return track;
218    
219 pam-fi 1.1 }
220     //--------------------------------------
221     //
222     //
223     //--------------------------------------
224     /**
225 pam-fi 1.3 * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is PamLevel2::sorted_tracks.
226     * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...).
227     * Sorting cryteria:
228 pam-fi 1.8 * TRK: lower chi**2
229 pam-fi 1.3 * CAL: lower Y spatial residual on the first calorimeter plane
230     * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis).
231     * The default sorting cryterium is "TOF+CAL".
232     *
233     * 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).
234 pam-fi 1.1 */
235 pam-fi 1.3 void PamLevel2::SortTracks(TString how){
236 pam-fi 1.1
237 pam-fi 1.4 //Save current Object count
238 pam-fi 1.6 Int_t ObjectNumber = TProcessID::GetObjectCount();
239    
240     sorted_tracks->Delete(); //temporaneo???
241 pam-fi 1.4
242 pam-fi 1.6 // loop over the tracks sorted by the tracker
243     Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
244     Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
245     Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
246    
247 pam-fi 1.8 if( !CAL2 && use_CAL) use_CAL = false;
248 pam-fi 1.6 if( !TOF && use_TOF) use_TOF = false;
249    
250 pam-fi 1.8 if( !TRK2 ){
251 pam-fi 1.6 cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
252     return;
253     };
254    
255     for(Int_t i=0; i < TrkLevel2::GetNTracks(); i++){
256 pam-fi 1.4
257 pam-fi 1.6 TrkTrack *ts = 0;
258 pam-fi 1.3
259 pam-fi 1.1 // get tracker tracks
260 pam-fi 1.6 TrkTrack *tp = TrkLevel2::GetTrack(i); //tracker
261     CaloTrkVar *cp = 0;
262     ToFTrkVar *op = 0;
263    
264 pam-fi 1.1 // if track has an image, check image selection
265 pam-fi 1.6 if(tp->HasImage()){
266    
267     TrkTrack *ti = TrkLevel2::GetTrackImage(i); //tracker (image)
268     CaloTrkVar *ci = 0;
269     ToFTrkVar *oi = 0;
270    
271 pam-fi 1.1 //assign starting scores
272 pam-fi 1.6 Int_t tp_score = 0; //main track sorted by the tracker
273     Int_t ti_score = 0; //image track
274    
275 pam-fi 1.1 // ------------------------
276     // calorimeter check
277     // ------------------------
278 pam-fi 1.6 // check the Y spatial residual on the first calorimeter plane
279     // (cut on calorimeter variables from Emiliano)
280     if(
281     use_CAL &&
282     npcfit[1] > 15 && //no. of fit planes on Y view
283     varcfit[1] < 1000. && //fit variance on Y view
284     true){
285    
286     cp = GetCaloStoredTrack(tp->GetSeqNo());
287     ci = GetCaloStoredTrack(ti->GetSeqNo());
288    
289     Float_t resy_p = cp->tbar[0][1] - cbar[0][1]; if(resy_p < 0)resy_p= - resy_p;
290     Float_t resy_i = ci->tbar[0][1] - cbar[0][1]; if(resy_i < 0)resy_i= - resy_i;
291    
292     if(resy_p <= resy_i) tp_score++;
293     else ti_score++;
294     };
295 pam-fi 1.1 // ------------------------
296     // TOF check
297     // ------------------------
298 pam-fi 1.6 // check the number of hit pmts along the track
299     // on S12 S21 and S32, where paddles are parallel to Y axis
300     if( use_TOF ){
301    
302     Int_t nphit_p =0;
303     Int_t nphit_i =0;
304    
305     op = GetToFStoredTrack(tp->GetSeqNo());
306     oi = GetToFStoredTrack(ti->GetSeqNo());
307    
308 pam-fi 1.5 /* cout << "track: npmtadc "<< op->npmtadc << endl;
309     cout << "track: npmttdc "<< op->npmttdc << endl;
310     cout << "image: npmtadc "<< oi->npmtadc << endl;
311     cout << "image: npmttdc "<< oi->npmttdc << endl;*/
312 pam-fi 1.6
313     for (Int_t ih=0; ih < op->npmtadc; ih++){
314     Int_t pl = GetPlaneIndex( (op->pmtadc).At(ih) );
315     if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
316     };
317    
318     for (Int_t ih=0; ih < oi->npmtadc; ih++){
319     Int_t pl = GetPlaneIndex( (oi->pmtadc).At(ih) );
320     if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
321     };
322    
323     if(
324     use_TOF &&
325     (nphit_p+nphit_i) !=0 &&
326     true){
327    
328     if( nphit_p >= nphit_i) tp_score++;
329     else ti_score++;
330     };
331     };
332     if(tp_score == ti_score) use_TRK = true;
333     // ------------------------
334 pam-fi 1.3 // tracker check
335     // ------------------------
336 pam-fi 1.6 // chi**2 difference is not always large enough to distinguish among
337     // the real track and its image.
338     // Tracker check will be applied always when calorimeter and tof information is ambiguous.
339     if(use_TRK){
340     if( tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
341     else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
342     };
343    
344 pam-fi 1.1 // ------------------------
345     // the winner is....
346     // ------------------------
347 pam-fi 1.6 if (tp_score > ti_score) ts = tp;//the track sorted by the tracker!!
348     else if (tp_score < ti_score) ts = ti;//its image!!
349     else {
350     ts = tp;
351 pam-fi 1.3 // cout << "Warning - track image ambiguity not solved" << endl;
352     // cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;
353 pam-fi 1.6 };
354    
355     }else{
356     ts = tp;
357     };
358    
359 pam-fi 1.4 // cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
360 pam-fi 1.6 sorted_tracks->Add(ts);//save the track in the sorted array
361 pam-fi 1.4 // cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
362 pam-fi 1.6
363     };
364     //Restore Object count
365     //To save space in the table keeping track of all referenced objects
366     //we assume that our events do not address each other. We reset the
367     //object count to what it was at the beginning of the event.
368     TProcessID::SetObjectCount(ObjectNumber);
369    
370 pam-fi 1.1 };
371     //--------------------------------------
372     //
373     //
374     //--------------------------------------
375     /**
376 pam-fi 1.2 * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.
377     * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.
378     */
379 pam-fi 1.8 TRefArray *PamLevel2::GetTracks(){
380    
381     // *-*-*-*-*-*-*-*-*-*-*-*-*
382     SortTracks("+CAL+TOF");
383     // *-*-*-*-*-*-*-*-*-*-*-*-*
384    
385     return sorted_tracks;
386 pam-fi 1.2 };
387     //--------------------------------------
388 pam-fi 1.3 //
389     //
390 pam-fi 1.2 //--------------------------------------
391     /**
392 pam-fi 1.1 * Retrieves the it-th Pamela "physical" track.
393     * It override TrkLevel2::GetTrack(int it).
394     * @param it Track number, ranging from 0 to GetNTracks().
395     */
396     PamTrack *PamLevel2::GetTrack(int it){
397 pam-fi 1.3
398 pam-fi 1.8 // *-*-*-*-*-*-*-*-*-*-*-*-*
399     SortTracks("+CAL+TOF");
400     // *-*-*-*-*-*-*-*-*-*-*-*-*
401    
402 pam-fi 1.6 PamTrack *track = 0;
403    
404     if( it >=0 && it < TrkLevel2::GetNTracks() && it<sorted_tracks->GetEntriesFast() ){
405     TrkTrack *t = (TrkTrack*)sorted_tracks->At(it);
406     track = GetPamTrackAlong(t);
407     }else{
408     cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;
409     };
410    
411     return track;
412    
413 pam-fi 1.1 };
414 pam-fi 1.3
415 pam-fi 1.1 //--------------------------------------
416     //
417     //
418     //--------------------------------------
419     /**
420 pam-fi 1.3 * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().
421 pam-fi 1.1 * @param it Track number, ranging from 0 to GetNTracks().
422     */
423     PamTrack *PamLevel2::GetTrackImage(int it){
424    
425 pam-fi 1.8 // *-*-*-*-*-*-*-*-*-*-*-*-*
426     SortTracks("+CAL+TOF");
427     // *-*-*-*-*-*-*-*-*-*-*-*-*
428    
429     PamTrack *image = 0;
430    
431     if( it >=0 && it < TrkLevel2::GetNTracks() ){
432     TrkTrack *temp = (TrkTrack*)sorted_tracks->At(it);
433     if( temp->HasImage() ){
434     TrkTrack *t = TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());
435     image = GetPamTrackAlong(t);
436 pam-fi 1.2 }else{
437 pam-fi 1.8 cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
438 pam-fi 1.1 };
439 pam-fi 1.8 }else{
440     cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;
441     };
442 pam-fi 1.1
443 pam-fi 1.8 return image;
444 pam-fi 1.1 }
445    
446     //--------------------------------------
447     //
448     //
449     //--------------------------------------
450     /**
451 pam-fi 1.2 * Get the Pamela detector trees in a single file and make them friends.
452     * @param f TFile pointer
453     * @param detlist String to select trees to be included
454     * @return Pointer to a TTree
455 pam-fi 1.1 */
456 pam-fi 1.4 TTree *PamLevel2::GetPamTree(TFile *f, TString detlist="+ALL"){
457    
458 pam-fi 1.5 // cout << "WARNING!!! -- obsolete method -- \n";
459     // cout << "better use TChain *PamLevel2::GetPamTree(TList*, TString) \n";
460 pam-fi 1.4
461 pam-fi 1.6 TTree *Trout =0;
462    
463     SetWhichTrees(detlist);
464 pam-fi 1.4 // Tracker
465 pam-fi 1.1 TTree *T = (TTree*)f->Get("Tracker");
466 pam-fi 1.8 if(T && (TRK2||TRK1||TRKh)) {
467     if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerToTrk(2));
468     if(TRK2)cout << "Tracker : set branch address TrkLevel2"<<endl;
469     if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerToTrk(1));
470     if(TRK1)cout << "Tracker : set branch address TrkLevel1"<<endl;
471     // if(TRKh)T->SetBranchAddress("TrkHough", GetPointerToTrk(3));
472     // if(TRKh)cout << "Tracker : set branch address TrkHough"<<endl;
473 pam-fi 1.6 Trout=T;
474 pam-fi 1.1 }else{
475     cout << "Tracker : missing tree"<<endl;
476     };
477     // Calorimeter
478     TTree *C = (TTree*)f->Get("Calorimeter");
479 pam-fi 1.8 if(C && CAL2) {
480 pam-fi 1.1 C->SetBranchAddress("CaloLevel2", GetPointerToCalo());
481     cout << "Calorimeter : set branch address CaloLevel2"<<endl;
482 pam-fi 1.4 if(!Trout)Trout=C;
483     else Trout->AddFriend(C);
484 pam-fi 1.1 }else{
485     cout << "Calorimeter : missing tree"<<endl;
486     };
487     // ToF
488     TTree *O = (TTree*)f->Get("ToF");
489 pam-fi 1.2 if(O && TOF) {
490 pam-fi 1.1 O->SetBranchAddress("ToFLevel2", GetPointerToToF());
491     cout << "ToF : set branch address ToFLevel2"<<endl;
492 pam-fi 1.4 if(!Trout)Trout=O;
493     else Trout->AddFriend(O);
494 pam-fi 1.1 }else{
495     cout << "ToF : missing tree"<<endl;
496     };
497     // Trigger
498     TTree *R = (TTree*)f->Get("Trigger");
499 pam-fi 1.2 if(R && TRG) {
500 pam-fi 1.1 R->SetBranchAddress("TrigLevel2", GetPointerToTrig());
501     cout << "Trigger : set branch address TrigLevel2"<<endl;
502 pam-fi 1.4 if(!Trout)Trout=O;
503     else Trout->AddFriend(R);
504 pam-fi 1.1 }else{
505     cout << "Trigger : missing tree"<<endl;
506     };
507     // S4
508     TTree *S = (TTree*)f->Get("S4");
509 pam-fi 1.2 if(S && S4) {
510 pam-fi 1.1 S->SetBranchAddress("S4Level2", GetPointerToS4());
511     cout << "S4 : set branch address S4Level2"<<endl;
512 pam-fi 1.4 if(!Trout)Trout=O;
513     else Trout->AddFriend(S);
514 pam-fi 1.1 }else{
515     cout << "S4 : missing tree"<<endl;
516     };
517     // Neutron Detector
518     TTree *N = (TTree*)f->Get("NeutronD");
519 pam-fi 1.2 if(N && ND) {
520 pam-fi 1.1 N->SetBranchAddress("NDLevel2", GetPointerToND());
521     cout << "NeutronD : set branch address NDLevel2"<<endl;
522 pam-fi 1.4 if(!Trout)Trout=O;
523     else Trout->AddFriend(N);
524 pam-fi 1.1 }else{
525     cout << "NeutronD : missing tree"<<endl;
526     };
527     // Anticounters
528     TTree *A = (TTree*)f->Get("Anticounter");
529 pam-fi 1.2 if(A && AC) {
530 pam-fi 1.1 A->SetBranchAddress("AcLevel2", GetPointerToAc());
531     cout << "Anticounter : set branch address AcLevel2"<<endl;
532 pam-fi 1.4 if(!Trout)Trout=O;
533     else Trout->AddFriend(A);
534 pam-fi 1.1 }else{
535     cout << "Anticounter : missing tree"<<endl;
536     };
537 pam-fi 1.2 // Orbital Info
538     TTree *B = (TTree*)f->Get("OrbitalInfo");
539     if(B && ORB) {
540     B->SetBranchAddress("OrbitalInfo", GetPointerToOrb());
541     cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
542 pam-fi 1.4 if(!Trout)Trout=O;
543     else Trout->AddFriend(B);
544 pam-fi 1.2 }else{
545     cout << "OrbitalInfo : missing tree"<<endl;
546     };
547 pam-fi 1.1
548 pam-fi 1.5 cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
549    
550     return Trout;
551 pam-fi 1.1
552     }
553 pam-fi 1.2 //--------------------------------------
554     //
555     //
556     //--------------------------------------
557     /**
558     * Get list of Level2 files.
559     * @param ddir Level2 data directory.
560     * @param flisttxt Name of txt file containing file list.
561     * @return Pointer to a TList of TSystemFiles
562     * If no input file list is given , all the Level2 files inside the directory are processed.
563     */
564     TList* PamLevel2::GetListOfLevel2Files(TString ddir, TString flisttxt = ""){
565    
566 pam-fi 1.6 TString wdir = gSystem->WorkingDirectory();
567    
568     if(ddir=="")ddir = wdir;
569     // TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
570     cout << "Level2 data directory : "<< ddir << endl;
571    
572     TList *contents = new TList; // create output list
573     contents->SetOwner();
574    
575     char *fullpath;
576    
577     // if no input file list is given:
578     if ( flisttxt != "" ){
579 pam-fi 1.2
580 pam-fi 1.6 if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) )return 0;
581 pam-fi 1.4
582     // flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
583 pam-fi 1.6 flisttxt = fullpath;
584    
585     if( !gSystem->ChangeDirectory(ddir) )return 0;
586 pam-fi 1.2
587 pam-fi 1.6 cout <<"Input file list : " << flisttxt <<endl;
588     ifstream in;
589     in.open(flisttxt, ios::in); //open input file list
590     while (1) {
591     TString file;
592     in >> file;
593     if (!in.good()) break;
594 pam-fi 1.8 // cout <<"(1) " << file << endl;
595     if(file.Contains("#"))file = file(0,file.First("#"));
596     // cout <<"(2) " << file << endl;
597    
598 pam-fi 1.6 if( gSystem->IsFileInIncludePath(file,&fullpath) ){
599 pam-fi 1.8
600 pam-fi 1.6 contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
601 pam-fi 1.8
602 pam-fi 1.6 }else{
603 pam-fi 1.8 if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
604 pam-fi 1.6 };
605     };
606     in.close();
607    
608     }else{
609 pam-fi 1.2
610 pam-fi 1.6 cout << "No input file list given."<<endl;
611     cout << "Check for existing root files."<<endl;
612 pam-fi 1.2 // cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
613 pam-fi 1.6
614     TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
615     TList *temp = datadir->GetListOfFiles();
616 pam-fi 1.2 // temp->Print();
617     // cout << "*************************************" << endl;
618    
619 pam-fi 1.6 TIter next(temp);
620     TSystemFile *questo = 0;
621    
622    
623     while ( (questo = (TSystemFile*) next()) ) {
624     TString name = questo-> GetName();
625     if( name.EndsWith(".root") ){
626     char *fullpath;
627     gSystem->IsFileInIncludePath(name,&fullpath);
628     contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));
629     };
630     }
631     delete temp;
632     delete datadir;
633    
634     };
635     gSystem->ChangeDirectory(wdir); // back to the working directory
636 pam-fi 1.5 // cout << endl << "Selected files:" << endl;
637     // contents->Print();
638 pam-fi 1.6 cout << contents->GetEntries()<<" files selected\n";
639 pam-fi 1.5 // cout << endl;
640 pam-fi 1.4 // cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;
641 pam-fi 1.6 return contents;
642 pam-fi 1.2 };
643     //--------------------------------------
644     //
645     //
646     //--------------------------------------
647     /**
648     * Get the Pamela detector chains from a list of files and make them friends.
649     * @param fl Pointer to a TList of TSystemFiles
650     * @param detlist String to select trees to be included
651     * @return Pointer to a TChain
652     */
653 pam-fi 1.4 TChain *PamLevel2::GetPamTree(TList *fl, TString detlist="+ALL"){
654 pam-fi 1.2
655 pam-fi 1.4 // TChain *Tout=0;
656 pam-fi 1.8 // if(Tout)Tout->Delete();
657     // Tout = NULL;
658 pam-fi 1.6
659 pam-fi 1.8 TChain *Tout =0;
660    
661 pam-fi 1.6 SetWhichTrees(detlist);
662    
663     TChain *T = 0;
664     TChain *C = 0;
665     TChain *O = 0;
666     TChain *R = 0;
667     TChain *S = 0;
668     TChain *N = 0;
669     TChain *A = 0;
670     TChain *B = 0;
671    
672 pam-fi 1.8 if(TRK2||TRK1||TRKh) T = new TChain("Tracker");
673     if(CAL2||CAL1) C = new TChain("Calorimeter");
674 pam-fi 1.6 if(TOF) O = new TChain("ToF");
675     if(TRG) R = new TChain("Trigger");
676     if(S4) S = new TChain("S4");
677     if(ND) N = new TChain("NeutronD");
678     if(AC) A = new TChain("Anticounter");
679     if(ORB) B = new TChain("OrbitalInfo");
680    
681     // loop over files and create chains
682     TIter next(fl);
683     TSystemFile *questo = 0;
684     while ( (questo = (TSystemFile*) next()) ) {
685     TString name = questo->GetName();
686 pam-fi 1.2 // cout << "File: "<< name << endl;
687 pam-fi 1.6 if( CheckLevel2File(name) ){
688 pam-fi 1.8 if(TRK2||TRK1||TRKh) T->Add(name);
689     if(CAL1||CAL2) C->Add(name);
690 pam-fi 1.6 if(TOF) O->Add(name);
691     if(TRG) R->Add(name);
692     if(S4) S->Add(name);
693     if(ND) N->Add(name);
694     if(AC) A->Add(name);
695     if(ORB) B->Add(name);
696 pam-fi 1.4 };
697 pam-fi 1.6 }
698    
699     cout << "done chain \n";
700 pam-fi 1.8
701 pam-fi 1.6 // Tracker
702 pam-fi 1.8 if(TRK2||TRK1||TRKh)if(!Tout)Tout=T;
703 pam-fi 1.6 // Calorimeter
704 pam-fi 1.8 if(CAL2||CAL1) {
705 pam-fi 1.6 if(!Tout)Tout=C;
706     else Tout->AddFriend("Calorimeter");
707     };
708 pam-fi 1.4 // ToF
709 pam-fi 1.6 if(TOF) {
710     if(!Tout)Tout=O;
711     else Tout->AddFriend("ToF");
712     };
713 pam-fi 1.4 // Trigger
714 pam-fi 1.6 if(TRG) {
715     if(!Tout)Tout=O;
716     else Tout->AddFriend("Trigger");
717     };
718 pam-fi 1.4 // S4
719 pam-fi 1.6 if(S4) {
720     if(!Tout)Tout=O;
721     else Tout->AddFriend("S4");
722     };
723 pam-fi 1.4 // Neutron Detector
724 pam-fi 1.6 if(ND) {
725     if(!Tout)Tout=O;
726     else Tout->AddFriend("NeutronD");
727     };
728 pam-fi 1.4 // Anticounters
729 pam-fi 1.6 if(AC) {
730     if(!Tout)Tout=O;
731     else Tout->AddFriend("Anticounter");
732     };
733 pam-fi 1.4 // OrbitalInfo
734 pam-fi 1.6 if(ORB) {
735     if(!Tout)Tout=O;
736     else Tout->AddFriend("OrbitalInfo");
737     };
738    
739     // cout<<endl<<" Number of entries: "<<Tout->GetEntries()<<endl<<endl;
740    
741 pam-fi 1.8 // if( Tout->GetEntries() )PamLevel2::SetBranchAddress();
742     if( Tout->GetEntries() )PamLevel2::SetBranchAddress( Tout );
743 pam-fi 1.6
744     return Tout;
745 pam-fi 1.4 }
746 pam-fi 1.8
747    
748    
749 pam-fi 1.4 //--------------------------------------
750     //
751     //
752     //--------------------------------------
753     /**
754     * Set branch addresses for Pamela friend trees
755     */
756 pam-fi 1.8 void PamLevel2::SetBranchAddress(TTree *t){
757    
758    
759    
760     TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
761     TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
762     TRKh = TRKh & t->GetBranchStatus("TrkHough");
763     CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
764     CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
765     TOF = TOF & t->GetBranchStatus("ToFLevel2");
766     TRG = TRG & t->GetBranchStatus("TrigLevel2");
767     S4 = S4 & t->GetBranchStatus("S4Level2");
768     ND = ND & t->GetBranchStatus("NDLevel2");
769     AC = AC & t->GetBranchStatus("AcLevel2");
770     ORB = ORB & t->GetBranchStatus("OrbitalInfo");
771    
772    
773 pam-fi 1.4 // Tracker
774 pam-fi 1.8 if(TRK1) {
775     t->SetBranchAddress("TrkLevel1", GetPointerToTrk(1));
776     cout << "Tracker : set branch address TrkLevel1"<<endl;
777     };
778     if(TRK2) {
779     t->SetBranchAddress("TrkLevel2", GetPointerToTrk(2));
780 pam-fi 1.6 cout << "Tracker : set branch address TrkLevel2"<<endl;
781     };
782 pam-fi 1.8 if(TRKh) {
783     t->SetBranchAddress("TrkHough", GetPointerToTrk(3));
784     cout << "Tracker : set branch address TrkHough"<<endl;
785     };
786 pam-fi 1.6
787     // Calorimeter
788 pam-fi 1.8 if(CAL1) {
789     t->SetBranchAddress("CaloLevel1", GetPointerToCalo(1));
790     cout << "Calorimeter : set branch address CaloLevel1"<<endl;
791     };
792     if(CAL2) {
793     t->SetBranchAddress("CaloLevel2", GetPointerToCalo(2));
794 pam-fi 1.6 cout << "Calorimeter : set branch address CaloLevel2"<<endl;
795     };
796    
797 pam-fi 1.4 // ToF
798 pam-fi 1.6 if(TOF) {
799 pam-fi 1.8 t->SetBranchAddress("ToFLevel2", GetPointerToToF());
800 pam-fi 1.6 cout << "ToF : set branch address ToFLevel2"<<endl;
801     };
802 pam-fi 1.4 // Trigger
803 pam-fi 1.6 if(TRG) {
804 pam-fi 1.8 t->SetBranchAddress("TrigLevel2", GetPointerToTrig());
805 pam-fi 1.6 cout << "Trigger : set branch address TrigLevel2"<<endl;
806     };
807 pam-fi 1.4 // S4
808 pam-fi 1.6 if(S4) {
809 pam-fi 1.8 t->SetBranchAddress("S4Level2", GetPointerToS4());
810 pam-fi 1.6 cout << "S4 : set branch address S4Level2"<<endl;
811     };
812 pam-fi 1.4 // Neutron Detector
813 pam-fi 1.6 if(ND) {
814 pam-fi 1.8 t->SetBranchAddress("NDLevel2", GetPointerToND());
815 pam-fi 1.6 cout << "NeutronD : set branch address NDLevel2"<<endl;
816     };
817 pam-fi 1.4 // Anticounters
818 pam-fi 1.6 if(AC) {
819 pam-fi 1.8 t->SetBranchAddress("AcLevel2", GetPointerToAc());
820 pam-fi 1.6 cout << "Anticounter : set branch address AcLevel2"<<endl;
821     };
822 pam-fi 1.4 // OrbitalInfo
823 pam-fi 1.6 if(ORB) {
824 pam-fi 1.8 t->SetBranchAddress("OrbitalInfo", GetPointerToOrb());
825 pam-fi 1.6 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
826     };
827    
828 pam-fi 1.4 }
829 pam-fi 1.8 /**
830     * Set branch addresses for Pamela friend trees
831     */
832     void PamLevel2::SetBranchAddress(TChain *t){
833 pam-fi 1.4
834 pam-fi 1.8
835    
836    
837     TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
838     TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
839     TRKh = TRKh & t->GetBranchStatus("TrkHough");
840     CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
841     CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
842     TOF = TOF & t->GetBranchStatus("ToFLevel2");
843     TRG = TRG & t->GetBranchStatus("TrigLevel2");
844     S4 = S4 & t->GetBranchStatus("S4Level2");
845     ND = ND & t->GetBranchStatus("NDLevel2");
846     AC = AC & t->GetBranchStatus("AcLevel2");
847     ORB = ORB & t->GetBranchStatus("OrbitalInfo");
848    
849    
850    
851     // Tracker
852     if(TRK1) {
853     t->SetBranchAddress("TrkLevel1", GetPointerToTrk(1));
854     cout << "Tracker : set branch address TrkLevel1"<<endl;
855     };
856     if(TRK2) {
857     t->SetBranchAddress("TrkLevel2", GetPointerToTrk(2));
858     cout << "Tracker : set branch address TrkLevel2"<<endl;
859     };
860     if(TRKh) {
861     t->SetBranchAddress("TrkHough", GetPointerToTrk(3));
862     cout << "Tracker : set branch address TrkHough"<<endl;
863     };
864    
865     // Calorimeter
866     if(CAL1) {
867     t->SetBranchAddress("CaloLevel1", GetPointerToCalo(1));
868     cout << "Calorimeter : set branch address CaloLevel1"<<endl;
869     };
870     if(CAL2) {
871     t->SetBranchAddress("CaloLevel2", GetPointerToCalo(2));
872     cout << "Calorimeter : set branch address CaloLevel2"<<endl;
873     };
874    
875     // ToF
876     if(TOF) {
877     t->SetBranchAddress("ToFLevel2", GetPointerToToF());
878     cout << "ToF : set branch address ToFLevel2"<<endl;
879     };
880     // Trigger
881     if(TRG) {
882     t->SetBranchAddress("TrigLevel2", GetPointerToTrig());
883     cout << "Trigger : set branch address TrigLevel2"<<endl;
884     };
885     // S4
886     if(S4) {
887     t->SetBranchAddress("S4Level2", GetPointerToS4());
888     cout << "S4 : set branch address S4Level2"<<endl;
889     };
890     // Neutron Detector
891     if(ND) {
892     t->SetBranchAddress("NDLevel2", GetPointerToND());
893     cout << "NeutronD : set branch address NDLevel2"<<endl;
894     };
895     // Anticounters
896     if(AC) {
897     t->SetBranchAddress("AcLevel2", GetPointerToAc());
898     cout << "Anticounter : set branch address AcLevel2"<<endl;
899     };
900     // OrbitalInfo
901     if(ORB) {
902     t->SetBranchAddress("OrbitalInfo", GetPointerToOrb());
903     cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
904     };
905    
906     }
907 pam-fi 1.4 //--------------------------------------
908     //
909     //
910     //--------------------------------------
911     void *PamLevel2::GetPointerTo(const char* c ){
912     // cout << "objname "<< objname << endl;
913 pam-fi 1.6 TString objname = c;
914 pam-fi 1.8 if(!objname.CompareTo("TrkLevel1"))return &trk1_obj;
915     if(!objname.CompareTo("TrkLevel2"))return &trk2_obj;
916     if(!objname.CompareTo("TrkHough"))return &trkh_obj;
917 pam-fi 1.6
918     return NULL;
919 pam-fi 1.4 };
920     //--------------------------------------
921     //
922     //
923     //--------------------------------------
924     /**
925     * Get the Run tree chain from a list of files.
926     * @param fl Pointer to a TList of TSystemFiles
927     * @return Pointer to a TChain
928     */
929     TChain *PamLevel2::GetRunTree(TList *fl){
930    
931 pam-fi 1.6 TChain *R = new TChain("Run");
932    
933     // loop over files and create chains
934     TIter next(fl);
935     TSystemFile *questo = 0;
936     while ( (questo = (TSystemFile*) next()) ) {
937     TString name = questo->GetName();
938 pam-fi 1.4 // cout << "File: "<< name << endl;
939 pam-fi 1.6 if( CheckLevel2File(name) ){
940     R->Add(name);
941     };
942     }
943    
944     R->SetBranchAddress("RunInfo", GetPointerToRun());
945     cout << "Run : set branch address RunInfo"<<endl;
946 pam-fi 1.4
947 pam-fi 1.6 return R;
948 pam-fi 1.4
949     }
950     //--------------------------------------
951     //
952     //
953     //--------------------------------------
954     /**
955     * Get the Run tree from a file.
956     * @param f Pointer to a TFile
957     * @return Pointer to a TTree
958     */
959     TTree *PamLevel2::GetRunTree(TFile *f){
960    
961    
962 pam-fi 1.6 TTree *R = (TTree*)f->Get("Run");
963    
964     R->SetBranchAddress("RunInfo", GetPointerToRun());
965     cout << "Run : set branch address RunInfo"<<endl;
966 pam-fi 1.4
967 pam-fi 1.6 return R;
968 pam-fi 1.2
969     }
970     //--------------------------------------
971     //
972     //
973     //--------------------------------------
974     /**
975 pam-fi 1.8 * Set which trees shoul be analysed
976 pam-fi 1.2 * @param detlist TString containing the sequence of trees required
977     */
978     void PamLevel2::SetWhichTrees(TString detlist){
979    
980 pam-fi 1.6 if(detlist.Contains("+ALL", TString::kIgnoreCase)){
981 pam-fi 1.8 CAL1 = true;
982     CAL2 = true;
983     TRK2 = true;
984     TRK1 = false;
985     TRKh = false;
986 pam-fi 1.6 TRG = true;
987     TOF = true;
988     S4 = true;
989     ND = true;
990     AC = true;
991     ORB = true;
992     }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
993 pam-fi 1.8 CAL1 = false;
994     CAL2 = false;
995     TRK2 = false;
996     TRK1 = false;
997     TRKh = false;
998 pam-fi 1.6 TRG = false;
999     TOF = false;
1000     S4 = false;
1001     ND = false;
1002     AC = false;
1003     ORB = false;
1004     };
1005    
1006 pam-fi 1.8 // -------------------------------------------------------------------------
1007     if( detlist.Contains("CAL1", TString::kIgnoreCase) ){
1008     if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;
1009     if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;
1010     };
1011    
1012     if( detlist.Contains("CAL2", TString::kIgnoreCase)){
1013     if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;
1014     if ( detlist.Contains("+CAL2", TString::kIgnoreCase) )CAL2=true;
1015     };
1016    
1017     if( detlist.Contains("+CAL", TString::kIgnoreCase) && !CAL1 && !CAL2 )CAL2=true;
1018     if( detlist.Contains("-CAL", TString::kIgnoreCase) && CAL1 && CAL2 ){
1019     CAL2=false;
1020     CAL1=false;
1021     }
1022     // -------------------------------------------------------------------------
1023     if( detlist.Contains("TRK1", TString::kIgnoreCase) ){
1024     if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;
1025     if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;
1026     };
1027    
1028     if( detlist.Contains("TRK2", TString::kIgnoreCase)){
1029     if ( detlist.Contains("-TRK2", TString::kIgnoreCase) )TRK2=false;
1030     if ( detlist.Contains("+TRK2", TString::kIgnoreCase) )TRK2=true;
1031     };
1032    
1033     if( detlist.Contains("TRKh", TString::kIgnoreCase)){
1034     if ( detlist.Contains("-TRKh", TString::kIgnoreCase) )TRKh=false;
1035     if ( detlist.Contains("+TRKh", TString::kIgnoreCase) )TRKh=true;
1036     };
1037    
1038     if( detlist.Contains("+TRK", TString::kIgnoreCase) && !TRK1 && !TRK2 && !TRKh )TRK2=true;
1039     if( detlist.Contains("-TRK", TString::kIgnoreCase) && TRK1 && TRK2 && TRKh){
1040     TRK2=false;
1041     TRK1=false;
1042     TRKh=false;
1043     }
1044     // -------------------------------------------------------------------------
1045    
1046    
1047 pam-fi 1.6
1048 pam-fi 1.8 // if( detlist.Contains("-TRK", TString::kIgnoreCase) )TRK2 = false;
1049     // else if( detlist.Contains("+TRK", TString::kIgnoreCase) )TRK2 = true;
1050 pam-fi 1.6
1051 pam-fi 1.8 // if( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1 = false;
1052     // else if( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1 = true;
1053    
1054     // if( detlist.Contains("-TRKh", TString::kIgnoreCase) )TRKh = false;
1055     // else if( detlist.Contains("+TRKh", TString::kIgnoreCase) )TRKh = true;
1056 pam-fi 1.6
1057     if( detlist.Contains("-TRG", TString::kIgnoreCase) )TRG = false;
1058     else if( detlist.Contains("+TRG", TString::kIgnoreCase) )TRG = true;
1059    
1060     if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
1061     else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
1062    
1063     if( detlist.Contains("-S4", TString::kIgnoreCase) )S4 = false;
1064     else if( detlist.Contains("+S4", TString::kIgnoreCase) )S4 = true;
1065    
1066     if( detlist.Contains("-ND", TString::kIgnoreCase) )ND = false;
1067     else if( detlist.Contains("+ND", TString::kIgnoreCase) )ND = true;
1068    
1069     if( detlist.Contains("-AC", TString::kIgnoreCase) )AC = false;
1070     else if( detlist.Contains("+AC", TString::kIgnoreCase) )AC = true;
1071    
1072     if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;
1073     else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;
1074    
1075 pam-fi 1.2 };
1076     //--------------------------------------
1077     //
1078     //
1079     //--------------------------------------
1080     /**
1081 pam-fi 1.3 * Check if a file contains selected Pamela Level2 trees.
1082 pam-fi 1.2 * @param name File name
1083 pam-fi 1.4 * @return true if the file is ok.
1084 pam-fi 1.2 */
1085     Bool_t PamLevel2::CheckLevel2File(TString name){
1086    
1087 pam-fi 1.8 Bool_t CAL1__ok = false;
1088     Bool_t CAL2__ok = false;
1089     Bool_t TRK2__ok = false;
1090     Bool_t TRK1__ok = false;
1091     Bool_t TRKh__ok = false;
1092 pam-fi 1.7 Bool_t TRG__ok = false;
1093     Bool_t TOF__ok = false;
1094     Bool_t S4__ok = false;
1095     Bool_t ND__ok = false;
1096     Bool_t AC__ok = false;
1097     Bool_t ORB__ok = false;
1098 pam-fi 1.6
1099 pam-fi 1.7 Bool_t RUN__ok = false;
1100 pam-fi 1.6
1101 pam-fi 1.8
1102    
1103     cout << "Checking file: "<<name<<endl;
1104 pam-fi 1.6 TFile *f = new TFile(name.Data());
1105     if( !f || f->IsZombie() ){
1106     cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false;
1107     }
1108 pam-fi 1.7 // cout << "Get list of keys: "<<f<<endl;
1109 pam-fi 1.6 TList *lk = f->GetListOfKeys();
1110 pam-fi 1.8 // lk->Print();
1111 pam-fi 1.6 TIter next(lk);
1112     TKey *key =0;
1113 pam-fi 1.8
1114     Int_t nev = 0;
1115    
1116 pam-fi 1.6 while( (key = (TKey*)next()) ){
1117    
1118 pam-fi 1.7 // cout << key->GetName() << endl;
1119     // cout << " Get tree: " << f->Get(key->GetName())<<endl;
1120     // nev_previous = nev;
1121     // cout << " n.entries "<< nev <<endl;
1122     // if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){
1123     // nev = ((TTree*)f->Get(key->GetName()))->GetEntries();
1124     // cout << "File: "<< f->GetName() <<" discarded ---- "<< key->GetName() << " tree: n.entries does not match "<<nev<<" "<<nev_previous<< endl;
1125     // return false;
1126     // };
1127 pam-fi 1.6
1128     if( !strcmp(key->GetName(),"Run" ) )RUN__ok = true;
1129 pam-fi 1.8
1130     //=========================================================
1131     if( !strcmp(key->GetName(),"Trigger" ) ){
1132     TRG__ok = true;
1133     if(TRG){
1134     Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries();
1135     if( nev && nevt!=nev){
1136     cout << "File: "<< f->GetName() <<" discarded ---- Trigger tree has "<<nevt<<" events instead of "<<nev<< endl;
1137     return false;
1138     }
1139     nev=nevt;
1140     }
1141     }
1142     //=========================================================
1143     if( !strcmp(key->GetName(),"ToF" ) ){
1144     TOF__ok = true;
1145     if(TOF){
1146     Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries();
1147     if( nev && nevt!=nev){
1148     cout << "File: "<< f->GetName() <<" discarded ---- ToF tree has "<<nevt<<" events instead of "<<nev<< endl;
1149     return false;
1150     }
1151     nev=nevt;
1152     }
1153     }
1154     //=========================================================
1155     if( !strcmp(key->GetName(),"S4" ) ){
1156     S4__ok = true;
1157     if(S4){
1158     Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries();
1159     if( nev && nevt!=nev){
1160     cout << "File: "<< f->GetName() <<" discarded ---- S4 tree has "<<nevt<<" events instead of "<<nev<< endl;
1161     return false;
1162     }
1163     nev=nevt;
1164     }
1165     }
1166     //=========================================================
1167    
1168     if( !strcmp(key->GetName(),"NeutronD" ) ){
1169     ND__ok = true;
1170     if(ND){
1171     Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries();
1172     if( nev && nevt!=nev){
1173     cout << "File: "<< f->GetName() <<" discarded ---- NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl;
1174     return false;
1175     }
1176     nev=nevt;
1177     }
1178     }
1179     //=========================================================
1180     if( !strcmp(key->GetName(),"Anticounter") ){
1181     AC__ok = true;
1182     if(AC){
1183     Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries();
1184     if( nev && nevt!=nev){
1185     cout << "File: "<< f->GetName() <<" discarded ---- Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl;
1186     return false;
1187     }
1188     nev=nevt;
1189     }
1190     }
1191     //=========================================================
1192     if( !strcmp(key->GetName(),"OrbitalInfo") ){
1193     ORB__ok = true;
1194     if(ORB){
1195     Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries();
1196     if( nev && nevt!=nev){
1197     cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
1198     return false;
1199     }
1200     nev=nevt;
1201     }
1202     }
1203     //=========================================================
1204 pam-fi 1.6 if( !strcmp(key->GetName(),"Tracker" ) ){
1205     TTree *T = (TTree*)f->Get("Tracker");
1206 pam-fi 1.8 if(TRK1||TRK2||TRKh){
1207     Int_t nevt = T->GetEntries();
1208     if( nev && nevt!=nev){
1209     cout << "File: "<< f->GetName() <<" discarded ---- Tracker tree has "<<nevt<<" events instead of "<<nev<< endl;
1210     return false;
1211     }
1212     nev=nevt;
1213     }
1214 pam-fi 1.6 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
1215     TString name = T->GetListOfBranches()->At(i)->GetName();
1216 pam-fi 1.8 if( !name.CompareTo("TrkLevel1") )TRK1__ok=true;
1217     if( !name.CompareTo("TrkLevel2") )TRK2__ok=true;
1218     if( !name.CompareTo("TrkHough") )TRKh__ok=true;
1219     };
1220     T->Delete();
1221 pam-fi 1.2 };
1222 pam-fi 1.8 //=========================================================
1223     if( !strcmp(key->GetName(),"Calorimeter" ) ){
1224     TTree *T = (TTree*)f->Get("Calorimeter");
1225     if(CAL1||CAL2){
1226     Int_t nevt = T->GetEntries();
1227     if( nev && nevt!=nev){
1228     cout << "File: "<< f->GetName() <<" discarded ---- Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl;
1229     return false;
1230     }
1231     nev=nevt;
1232     }
1233     for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
1234     TString name = T->GetListOfBranches()->At(i)->GetName();
1235     if( !name.CompareTo("CaloLevel1") )CAL1__ok=true;
1236     if( !name.CompareTo("CaloLevel2") )CAL2__ok=true;
1237     };
1238     T->Delete();
1239     };
1240    
1241 pam-fi 1.6 };
1242    
1243 pam-fi 1.8
1244    
1245 pam-fi 1.6 if(!RUN__ok) {
1246 pam-fi 1.8 cout << "File: "<< f->GetName() <<" discarded ---- Missing RunInfo tree"<< endl;
1247     return false;
1248     };
1249    
1250     if(CAL1 && !CAL1__ok){
1251     cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel1 branch"<< endl;
1252     return false;
1253     };
1254     if(CAL2 && !CAL2__ok){
1255     cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel2 branch"<< endl;
1256     return false;
1257     };
1258     if(TRK2 && !TRK2__ok){
1259     cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel2 branch"<< endl;
1260     return false;
1261     };
1262     if(TRK1 && !TRK1__ok){
1263     cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel1 branch"<< endl;
1264     return false;
1265     };
1266     if(TRKh && !TRKh__ok){
1267     cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkHough branch"<< endl;
1268     return false;
1269 pam-fi 1.6 };
1270 pam-fi 1.8 if(ORB && !ORB__ok){
1271     cout << "File: "<< f->GetName() <<" discarded ---- Missing ORB tree"<< endl;
1272     return false;
1273 pam-fi 1.6 };
1274 pam-fi 1.8 if(AC && !AC__ok){
1275     cout << "File: "<< f->GetName() <<" discarded ---- Missing AC tree"<< endl;
1276     return false;
1277 pam-fi 1.6 };
1278     if(S4 && !S4__ok){
1279 pam-fi 1.8 cout << "File: "<< f->GetName() <<" discarded ---- Missing S4 tree"<< endl;
1280     return false;
1281 pam-fi 1.6 };
1282 pam-fi 1.8 if(TOF && !TOF__ok){
1283     cout << "File: "<< f->GetName() <<" discarded ---- Missing ToF tree"<< endl;
1284     return false;
1285 pam-fi 1.6 };
1286 pam-fi 1.8
1287     if(ND && !ND__ok){
1288     cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl;
1289     return false;
1290     };
1291     if(TRG && !TRG__ok){
1292     cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;
1293     return false;
1294     };
1295    
1296    
1297    
1298    
1299    
1300     lk->Delete();
1301     f->Close();
1302    
1303     return true;
1304 pam-fi 1.2
1305     };
1306    
1307    

  ViewVC Help
Powered by ViewVC 1.1.23