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

Annotation of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Fri Aug 4 13:31:35 2006 UTC (18 years, 4 months ago) by pam-fi
Branch: MAIN
Changes since 1.1: +614 -77 lines
New methods to loop over files and some memory-leak bugs fixed

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     if(o) *tof_track = *o;
28     };
29    
30     //--------------------------------------
31     //
32     //
33     //--------------------------------------
34     /**
35     * Constructor
36     */
37     PamLevel2::PamLevel2(){
38 pam-fi 1.2
39 pam-fi 1.1 trk_obj = this->TrkLevel2::GetTrkLevel2();
40     calo_obj = this->CaloLevel2::GetCaloLevel2();
41     tof_obj = this->ToFLevel2::GetToFLevel2();
42     trig_obj = this->TrigLevel2::GetTrigLevel2();
43     s4_obj = this->S4Level2::GetS4Level2();
44     nd_obj = this->NDLevel2::GetNDLevel2();
45     ac_obj = this->AcLevel2::GetAcLevel2();
46 pam-fi 1.2 orb_obj = this->OrbitalInfo::GetOrbitalInfo();
47    
48     sorted_tracks = new TRefArray();
49    
50     CAL = true;
51     TRK = true;
52     TRG = true;
53     TOF = true;
54     S4 = true;
55     ND = true;
56     AC = true;
57     ORB = true;
58    
59     };
60     /**
61     * Destructor
62     */
63     PamLevel2::~PamLevel2(){
64    
65     delete sorted_tracks;
66    
67     };
68     /**
69     * Clear the event
70     */
71     void PamLevel2::Clear(){
72    
73     sorted_tracks->Delete();
74    
75 pam-fi 1.1 };
76 pam-fi 1.2
77    
78 pam-fi 1.1 //--------------------------------------
79     //
80     //
81     //--------------------------------------
82     /**
83     * Retrieves the it-th stored track.
84     * It override TrkLevel2::GetTrack(int it).
85     * @param itrk Track number, ranging from 0 to GetNTracks().
86     */
87    
88     PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
89    
90     TrkTrack *t = 0;
91     CaloTrkVar *c = 0;
92     ToFTrkVar *o = 0;
93    
94     if( itrk >=0 && itrk < TrkLevel2::ntrk() ){
95 pam-fi 1.2 t = TrkLevel2::GetStoredTrack(itrk);
96     /* c = CaloLevel2::GetCaloTrkVar(t->GetSeqNo());
97     o = ToFLevel2::GetToFTrkVar(t->GetSeqNo()); */
98     Int_t it_calo=0;
99     do{
100     c = CaloLevel2::GetCaloTrkVar(it_calo);
101     it_calo++;
102     } while(t->GetSeqNo() != c->trkseqno && it_calo < CaloLevel2::ntrk());
103     if( t->GetSeqNo() != c->trkseqno )cout << "PamLevel2::GetStoredTrack(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match Calorimeter SeqNo"<< c->trkseqno<<endl;
104    
105     Int_t it_tof=0;
106     do{
107     o = ToFLevel2::GetToFTrkVar(it_tof);
108     it_tof++;
109     } while(t->GetSeqNo() != o->trkseqno && it_tof < ToFLevel2::ntrk());
110     if( t->GetSeqNo() != o->trkseqno )cout << "PamLevel2::GetStoredTrack(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match ToF SeqNo "<< o->trkseqno <<endl;
111    
112     }else{
113     cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;
114     };
115    
116 pam-fi 1.1 // hence create a "PamTrack" object
117     PamTrack *track = 0;
118     if(t && c && o)track = new PamTrack(t,c,o);
119     return track;
120 pam-fi 1.2
121 pam-fi 1.1 }
122     //--------------------------------------
123     //
124     //
125     //--------------------------------------
126     /**
127     * Sort physical (tracker) tracks and stores them in a TObjectArray (of TrkTrack objects).
128     * The total number of physical tracks is given by GetNTracks() and the it-th physical track can be retrieved by means of the method GetTrack(int it).
129     */
130 pam-fi 1.2 void PamLevel2::SortTracks(){
131 pam-fi 1.1
132 pam-fi 1.2 sorted_tracks->Delete(); //temporaneo
133 pam-fi 1.1 // loop over the tracks sorted by the tracker
134 pam-fi 1.2 for(Int_t i=0; i < TrkLevel2::GetNTracks(); i++){
135 pam-fi 1.1
136 pam-fi 1.2 TrkTrack *ts = 0;
137 pam-fi 1.1
138     // get tracker tracks
139 pam-fi 1.2 TrkTrack *tp = TrkLevel2::GetTrack(i); //tracker
140     CaloTrkVar *cp = CaloLevel2::GetCaloTrkVar(tp->GetSeqNo()); //calorimeter
141     ToFTrkVar *op = ToFLevel2::GetToFTrkVar(tp->GetSeqNo()); //tof
142 pam-fi 1.1
143     // if track has an image, check image selection
144 pam-fi 1.2 if(tp->HasImage()){
145     TrkTrack *ti = TrkLevel2::GetTrackImage(i); //tracker (image)
146     CaloTrkVar *ci = CaloLevel2::GetCaloTrkVar(ti->GetSeqNo());//calorimeter (image)
147     ToFTrkVar *oi = ToFLevel2::GetToFTrkVar(ti->GetSeqNo()); //tof (image)
148 pam-fi 1.1
149     //assign starting scores
150 pam-fi 1.2 Int_t tp_score = 1; //"principal" track, sorted by the tracker
151     Int_t ti_score = 0; //image track
152 pam-fi 1.1 // ------------------------
153     // calorimeter check
154     // ------------------------
155 pam-fi 1.2 if(
156     npcfit[1] > 3 && //no. of fit planes on Y view
157 pam-fi 1.1 // varcfit[1] < 50.&& //fit variance on Y view
158 pam-fi 1.2 true){
159 pam-fi 1.1
160 pam-fi 1.2 Float_t resy_p = cp->tbar[0][1] - cbar[0][1];if(resy_p < 0)resy_p= - resy_p;
161     Float_t resy_i = ci->tbar[0][1] - cbar[0][1];if(resy_i < 0)resy_i= - resy_i;
162 pam-fi 1.1
163 pam-fi 1.2 if(resy_p <= resy_i) tp_score++;
164     else ti_score++;
165     };
166 pam-fi 1.1 // ------------------------
167     // TOF check
168     // ------------------------
169    
170     // ------------------------
171     // the winner is....
172     // ------------------------
173 pam-fi 1.2 if(tp_score > ti_score) ts = tp;//the track sorted by the tracker!!
174     else ts = ti;//its image!!
175 pam-fi 1.1
176 pam-fi 1.2 }else{
177     ts = tp;
178     };
179    
180     sorted_tracks->Add(ts);//save the track in the sorted array
181    
182 pam-fi 1.1 };
183    
184     };
185     //--------------------------------------
186     //
187     //
188     //--------------------------------------
189     /**
190 pam-fi 1.2 * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.
191     * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.
192     */
193     TRefArray *PamLevel2::GetTracks(){
194     // if(!sorted_tracks->GetEntries()) SortTracks();
195     SortTracks();
196     return sorted_tracks;
197     };
198     //--------------------------------------
199     //
200     //
201     //--------------------------------------
202     /**
203 pam-fi 1.1 * Retrieves the it-th Pamela "physical" track.
204     * It override TrkLevel2::GetTrack(int it).
205     * @param it Track number, ranging from 0 to GetNTracks().
206     */
207     PamTrack *PamLevel2::GetTrack(int it){
208    
209 pam-fi 1.2 SortTracks();
210    
211     TrkTrack *t = 0;
212     CaloTrkVar *c = 0;
213     ToFTrkVar *o = 0;
214    
215     if( it >=0 && it < TrkLevel2::GetNTracks() ){
216    
217     t = (TrkTrack*)sorted_tracks->At(it);
218    
219     Int_t it_calo=0;
220     do{
221     c = CaloLevel2::GetCaloTrkVar(it_calo);
222     it_calo++;
223     } while(t->GetSeqNo() != c->trkseqno && it_calo < CaloLevel2::ntrk());
224     if( t->GetSeqNo() != c->trkseqno )cout << "PamLevel2::GetTrack(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match Calorimeter SeqNo"<< c->trkseqno<<endl;
225    
226     Int_t it_tof=0;
227     do{
228     o = ToFLevel2::GetToFTrkVar(it_tof);
229     it_tof++;
230     } while(t->GetSeqNo() != o->trkseqno && it_tof < ToFLevel2::ntrk());
231     if( t->GetSeqNo() != o->trkseqno )cout << "PamLevel2::GetTrack(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match ToF SeqNo "<< o->trkseqno <<endl;
232    
233     }else{
234     cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;
235     };
236 pam-fi 1.1
237     // hence create a "PamTrack" object
238 pam-fi 1.2 PamTrack *track = 0;
239     if(t && c && o)track = new PamTrack(t,c,o);
240    
241     return track;
242 pam-fi 1.1
243     };
244     //--------------------------------------
245     //
246     //
247     //--------------------------------------
248     /**
249     * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::GetTracks().
250     * @param it Track number, ranging from 0 to GetNTracks().
251     */
252     PamTrack *PamLevel2::GetTrackImage(int it){
253    
254 pam-fi 1.2 // if(!sorted_tracks->GetEntries()) SortTracks();
255     SortTracks();
256    
257 pam-fi 1.1 TrkTrack *t = 0;
258     CaloTrkVar *c = 0;
259     ToFTrkVar *o = 0;
260    
261     if( it >=0 && it < TrkLevel2::GetNTracks() ){
262 pam-fi 1.2 TrkTrack *temp = (TrkTrack*)sorted_tracks->At(it);
263     if( temp->HasImage() ){
264    
265     t = TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());
266    
267     /* c = CaloLevel2::GetCaloTrkVar(temp->GetImageSeqNo());
268     o = ToFLevel2::GetToFTrkVar(temp->GetImageSeqNo());*/
269    
270     Int_t it_calo=0;
271     do{
272     c = CaloLevel2::GetCaloTrkVar(it_calo);
273     it_calo++;
274     } while(t->GetSeqNo() != c->trkseqno && it_calo < CaloLevel2::ntrk());
275     if( t->GetSeqNo() != c->trkseqno )cout << "PamLevel2::GetTrackImage(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match Calorimeter SeqNo"<< c->trkseqno<<endl;
276    
277     Int_t it_tof=0;
278     do{
279     o = ToFLevel2::GetToFTrkVar(it_tof);
280     it_tof++;
281     } while(t->GetSeqNo() != o->trkseqno && it_tof < ToFLevel2::ntrk());
282     if( t->GetSeqNo() != o->trkseqno )cout << "PamLevel2::GetTrackImage(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match ToF SeqNo "<< o->trkseqno <<endl;
283     }else{
284     cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
285     };
286     }else{
287     cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;
288 pam-fi 1.1 };
289    
290     // hence create a "PamTrack" object
291     PamTrack *image = 0;
292     if(t && c && o)image = new PamTrack(t,c,o);
293 pam-fi 1.2
294     return image;
295 pam-fi 1.1
296     }
297    
298     //--------------------------------------
299     //
300     //
301     //--------------------------------------
302     /**
303 pam-fi 1.2 * Get the Pamela detector trees in a single file and make them friends.
304     * @param f TFile pointer
305     * @param detlist String to select trees to be included
306     * @return Pointer to a TTree
307 pam-fi 1.1 */
308 pam-fi 1.2 TTree *PamLevel2::LoadPamTrees(TFile *f, TString detlist="+ALL"){
309 pam-fi 1.1
310     TTree *Tout =0;
311 pam-fi 1.2
312     SetWhichTrees(detlist);
313    
314 pam-fi 1.1 // Tracker
315     TTree *T = (TTree*)f->Get("Tracker");
316 pam-fi 1.2 if(T && TRK) {
317 pam-fi 1.1 T->SetBranchAddress("TrkLevel2", GetPointerToTrk());
318     cout << "Tracker : set branch address TrkLevel2"<<endl;
319     if(!Tout)Tout=T;
320     }else{
321     cout << "Tracker : missing tree"<<endl;
322     };
323     // Calorimeter
324     TTree *C = (TTree*)f->Get("Calorimeter");
325 pam-fi 1.2 if(C && CAL) {
326 pam-fi 1.1 C->SetBranchAddress("CaloLevel2", GetPointerToCalo());
327     cout << "Calorimeter : set branch address CaloLevel2"<<endl;
328     if(!Tout)Tout=C;
329     else Tout->AddFriend(C);
330     }else{
331     cout << "Calorimeter : missing tree"<<endl;
332     };
333     // ToF
334     TTree *O = (TTree*)f->Get("ToF");
335 pam-fi 1.2 if(O && TOF) {
336 pam-fi 1.1 O->SetBranchAddress("ToFLevel2", GetPointerToToF());
337     cout << "ToF : set branch address ToFLevel2"<<endl;
338     if(!Tout)Tout=O;
339     else Tout->AddFriend(O);
340     }else{
341     cout << "ToF : missing tree"<<endl;
342     };
343     // Trigger
344     TTree *R = (TTree*)f->Get("Trigger");
345 pam-fi 1.2 if(R && TRG) {
346 pam-fi 1.1 R->SetBranchAddress("TrigLevel2", GetPointerToTrig());
347     cout << "Trigger : set branch address TrigLevel2"<<endl;
348     if(!Tout)Tout=O;
349     else Tout->AddFriend(R);
350     }else{
351     cout << "Trigger : missing tree"<<endl;
352     };
353     // S4
354     TTree *S = (TTree*)f->Get("S4");
355 pam-fi 1.2 if(S && S4) {
356 pam-fi 1.1 S->SetBranchAddress("S4Level2", GetPointerToS4());
357     cout << "S4 : set branch address S4Level2"<<endl;
358     if(!Tout)Tout=O;
359     else Tout->AddFriend(S);
360     }else{
361     cout << "S4 : missing tree"<<endl;
362     };
363     // Neutron Detector
364     TTree *N = (TTree*)f->Get("NeutronD");
365 pam-fi 1.2 if(N && ND) {
366 pam-fi 1.1 N->SetBranchAddress("NDLevel2", GetPointerToND());
367     cout << "NeutronD : set branch address NDLevel2"<<endl;
368     if(!Tout)Tout=O;
369     else Tout->AddFriend(N);
370     }else{
371     cout << "NeutronD : missing tree"<<endl;
372     };
373     // Anticounters
374     TTree *A = (TTree*)f->Get("Anticounter");
375 pam-fi 1.2 if(A && AC) {
376 pam-fi 1.1 A->SetBranchAddress("AcLevel2", GetPointerToAc());
377     cout << "Anticounter : set branch address AcLevel2"<<endl;
378     if(!Tout)Tout=O;
379     else Tout->AddFriend(A);
380     }else{
381     cout << "Anticounter : missing tree"<<endl;
382     };
383 pam-fi 1.2 // Orbital Info
384     TTree *B = (TTree*)f->Get("OrbitalInfo");
385     if(B && ORB) {
386     B->SetBranchAddress("OrbitalInfo", GetPointerToOrb());
387     cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
388     if(!Tout)Tout=O;
389     else Tout->AddFriend(B);
390     }else{
391     cout << "OrbitalInfo : missing tree"<<endl;
392     };
393 pam-fi 1.1
394     return Tout;
395    
396     }
397 pam-fi 1.2 //--------------------------------------
398     //
399     //
400     //--------------------------------------
401     /**
402     * Get the Pamela detector trees in a single file and make them friends.
403     * @param f TFile pointer
404     * @return Pointer to a TTree
405     */
406     TTree *PamLevel2::LoadPamTrees(TFile *f){
407    
408     TTree *Tout =0;
409    
410     SetWhichTrees("+ALL");
411    
412     // Tracker
413     TTree *T = (TTree*)f->Get("Tracker");
414     if(T && TRK) {
415     T->SetBranchAddress("TrkLevel2", GetPointerToTrk());
416     cout << "Tracker : set branch address TrkLevel2"<<endl;
417     if(!Tout)Tout=T;
418     }else{
419     cout << "Tracker : missing tree"<<endl;
420     };
421     // Calorimeter
422     TTree *C = (TTree*)f->Get("Calorimeter");
423     if(C && CAL) {
424     C->SetBranchAddress("CaloLevel2", GetPointerToCalo());
425     cout << "Calorimeter : set branch address CaloLevel2"<<endl;
426     if(!Tout)Tout=C;
427     else Tout->AddFriend(C);
428     }else{
429     cout << "Calorimeter : missing tree"<<endl;
430     };
431     // ToF
432     TTree *O = (TTree*)f->Get("ToF");
433     if(O && TOF) {
434     O->SetBranchAddress("ToFLevel2", GetPointerToToF());
435     cout << "ToF : set branch address ToFLevel2"<<endl;
436     if(!Tout)Tout=O;
437     else Tout->AddFriend(O);
438     }else{
439     cout << "ToF : missing tree"<<endl;
440     };
441     // Trigger
442     TTree *R = (TTree*)f->Get("Trigger");
443     if(R && TRG) {
444     R->SetBranchAddress("TrigLevel2", GetPointerToTrig());
445     cout << "Trigger : set branch address TrigLevel2"<<endl;
446     if(!Tout)Tout=O;
447     else Tout->AddFriend(R);
448     }else{
449     cout << "Trigger : missing tree"<<endl;
450     };
451     // S4
452     TTree *S = (TTree*)f->Get("S4");
453     if(S && S4) {
454     S->SetBranchAddress("S4Level2", GetPointerToS4());
455     cout << "S4 : set branch address S4Level2"<<endl;
456     if(!Tout)Tout=O;
457     else Tout->AddFriend(S);
458     }else{
459     cout << "S4 : missing tree"<<endl;
460     };
461     // Neutron Detector
462     TTree *N = (TTree*)f->Get("NeutronD");
463     if(N && ND) {
464     N->SetBranchAddress("NDLevel2", GetPointerToND());
465     cout << "NeutronD : set branch address NDLevel2"<<endl;
466     if(!Tout)Tout=O;
467     else Tout->AddFriend(N);
468     }else{
469     cout << "NeutronD : missing tree"<<endl;
470     };
471     // Anticounters
472     TTree *A = (TTree*)f->Get("Anticounter");
473     if(A && AC) {
474     A->SetBranchAddress("AcLevel2", GetPointerToAc());
475     cout << "Anticounter : set branch address AcLevel2"<<endl;
476     if(!Tout)Tout=O;
477     else Tout->AddFriend(A);
478     }else{
479     cout << "Anticounter : missing tree"<<endl;
480     };
481     // Orbital Info
482     TTree *B = (TTree*)f->Get("OrbitalInfo");
483     if(B && ORB) {
484     B->SetBranchAddress("OrbitalInfo", GetPointerToOrb());
485     cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
486     if(!Tout)Tout=O;
487     else Tout->AddFriend(B);
488     }else{
489     cout << "OrbitalInfo : missing tree"<<endl;
490     };
491    
492     return Tout;
493    
494     }
495     //--------------------------------------
496     //
497     //
498     //--------------------------------------
499     /**
500     * Get list of Level2 files.
501     * @param ddir Level2 data directory.
502     * @param flisttxt Name of txt file containing file list.
503     * @return Pointer to a TList of TSystemFiles
504     * If no input file list is given , all the Level2 files inside the directory are processed.
505     */
506     TList* PamLevel2::GetListOfLevel2Files(TString ddir, TString flisttxt = ""){
507    
508     TString wdir = gSystem->WorkingDirectory();
509    
510     if(ddir=="")ddir = wdir;
511     TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
512     cout << "Level2 data directory : "<< endl << ddir << endl;
513    
514     TList *contents = new TList; // create output list
515     contents->SetOwner();
516    
517     // if no input file list is given:
518     if ( flisttxt != "" ){
519    
520     if( !gSystem->ChangeDirectory(ddir) )return 0;
521    
522     flisttxt = gSystem->ConcatFileName(wdir,gSystem->BaseName(flisttxt));
523    
524     cout <<"Input file list : "<< endl << flisttxt <<endl;
525     ifstream in;
526     in.open(flisttxt, ios::in);
527     while (1) {
528     TString file;
529     in >> file;
530     if (!in.good()) break;
531     char *fullpath;
532     if( gSystem->IsFileInIncludePath(file,&fullpath) ){
533     // contents->Add(new TSystemDirectory(fullpath,ddir)); // add file to the list
534     // contents->Add(new TSystemFile(fullpath,ddir)); // add file to the list
535     contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
536     }else{
537     cout << "warning! --- File "<<file<<" does not exists"<< endl;
538     };
539     };
540     in.close();
541    
542     }else{
543    
544     cout << "No input file list given."<<endl;
545     cout << "Check for existing root files."<<endl;
546     // cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
547    
548     TList *temp = datadir->GetListOfFiles();
549     // temp->Print();
550     // cout << "*************************************" << endl;
551    
552     TIter next(temp);
553     TSystemFile *questo = 0;
554    
555    
556     while ( (questo = (TSystemFile*) next()) ) {
557     TString name = questo-> GetName();
558     if( name.EndsWith(".root") ){
559     char *fullpath;
560     gSystem->IsFileInIncludePath(name,&fullpath);
561     contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));
562     };
563     }
564     delete temp;
565    
566     };
567     gSystem->ChangeDirectory(wdir);
568     cout << endl << "Selected files:" << endl;
569     contents->Print();
570     cout << endl;
571     // cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
572     return contents;
573     };
574     //--------------------------------------
575     //
576     //
577     //--------------------------------------
578     /**
579     * Get the Pamela detector chains from a list of files and make them friends.
580     * @param fl Pointer to a TList of TSystemFiles
581     * @param detlist String to select trees to be included
582     * @return Pointer to a TChain
583     */
584     TChain *PamLevel2::LoadPamTrees(TList *fl, TString detlist="+ALL"){
585    
586     TChain *Tout=0;
587    
588     SetWhichTrees(detlist);
589    
590     TChain *T = 0;
591     TChain *C = 0;
592     TChain *O = 0;
593     TChain *R = 0;
594     TChain *S = 0;
595     TChain *N = 0;
596     TChain *A = 0;
597     TChain *B = 0;
598    
599     if(TRK) T = new TChain("Tracker");
600     if(CAL) C = new TChain("Calorimeter");
601     if(TOF) O = new TChain("ToF");
602     if(TRG) R = new TChain("Trigger");
603     if(S4) S = new TChain("S4");
604     if(ND) N = new TChain("NeutronD");
605     if(AC) A = new TChain("Anticounter");
606     if(ORB) B = new TChain("OrbitalInfo");
607    
608     // loop over files and create chains
609     TIter next(fl);
610     TSystemFile *questo = 0;
611     while ( (questo = (TSystemFile*) next()) ) {
612     TString name = questo->GetName();
613     // cout << "File: "<< name << endl;
614     if( CheckLevel2File(name) ){
615     if(TRK) T->Add(name);
616     if(CAL) C->Add(name);
617     if(TOF) O->Add(name);
618     if(TRG) R->Add(name);
619     if(S4) S->Add(name);
620     if(ND) N->Add(name);
621     if(AC) A->Add(name);
622     if(ORB) B->Add(name);
623     };
624     }
625    
626     // Tracker
627     if(TRK) {
628     T->SetBranchAddress("TrkLevel2", GetPointerToTrk());
629     cout << "Tracker : set branch address TrkLevel2"<<endl;
630     if(!Tout)Tout=T;
631     };
632    
633     // Calorimeter
634     if(CAL) {
635     C->SetBranchAddress("CaloLevel2", GetPointerToCalo());
636     cout << "Calorimeter : set branch address CaloLevel2"<<endl;
637     if(!Tout)Tout=C;
638     else Tout->AddFriend("Calorimeter");
639     };
640    
641     // ToF
642     if(TOF) {
643     O->SetBranchAddress("ToFLevel2", GetPointerToToF());
644     cout << "ToF : set branch address ToFLevel2"<<endl;
645     if(!Tout)Tout=O;
646     else Tout->AddFriend("ToF");
647     };
648     // Trigger
649     if(TRG) {
650     R->SetBranchAddress("TrigLevel2", GetPointerToTrig());
651     cout << "Trigger : set branch address TrigLevel2"<<endl;
652     if(!Tout)Tout=O;
653     else Tout->AddFriend("Trigger");
654     };
655     // S4
656     if(S4) {
657     S->SetBranchAddress("S4Level2", GetPointerToS4());
658     cout << "S4 : set branch address S4Level2"<<endl;
659     if(!Tout)Tout=O;
660     else Tout->AddFriend("S4");
661     };
662     // Neutron Detector
663     if(ND) {
664     N->SetBranchAddress("NDLevel2", GetPointerToND());
665     cout << "NeutronD : set branch address NDLevel2"<<endl;
666     if(!Tout)Tout=O;
667     else Tout->AddFriend("NeutronD");
668     };
669     // Anticounters
670     if(AC) {
671     A->SetBranchAddress("AcLevel2", GetPointerToAc());
672     cout << "Anticounter : set branch address AcLevel2"<<endl;
673     if(!Tout)Tout=O;
674     else Tout->AddFriend("Anticounter");
675     };
676     // OrbitalInfo
677     if(ORB) {
678     B->SetBranchAddress("OrbitalInfo", GetPointerToOrb());
679     cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
680     if(!Tout)Tout=O;
681     else Tout->AddFriend("OrbitalInfo");
682     };
683    
684     return Tout;
685    
686     }
687     //--------------------------------------
688     //
689     //
690     //--------------------------------------
691     /**
692     * Set which trees should be analysed
693     * @param detlist TString containing the sequence of trees required
694     */
695     void PamLevel2::SetWhichTrees(TString detlist){
696    
697     if(detlist.Contains("+ALL", TString::kIgnoreCase)){
698     CAL = true;
699     TRK = true;
700     TRG = true;
701     TOF = true;
702     S4 = true;
703     ND = true;
704     AC = true;
705     ORB = true;
706     }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
707     CAL = false;
708     TRK = false;
709     TRG = false;
710     TOF = false;
711     S4 = false;
712     ND = false;
713     AC = false;
714     ORB = false;
715     };
716    
717     if( detlist.Contains("-CAL", TString::kIgnoreCase) )CAL = false;
718     else if( detlist.Contains("+CAL", TString::kIgnoreCase) )CAL = true;
719    
720     if( detlist.Contains("-TRK", TString::kIgnoreCase) )TRK = false;
721     else if( detlist.Contains("+TRK", TString::kIgnoreCase) )TRK = true;
722    
723     if( detlist.Contains("-TRG", TString::kIgnoreCase) )TRG = false;
724     else if( detlist.Contains("+TRG", TString::kIgnoreCase) )TRG = true;
725    
726     if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
727     else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
728    
729     if( detlist.Contains("-S4", TString::kIgnoreCase) )S4 = false;
730     else if( detlist.Contains("+S4", TString::kIgnoreCase) )S4 = true;
731    
732     if( detlist.Contains("-ND", TString::kIgnoreCase) )ND = false;
733     else if( detlist.Contains("+ND", TString::kIgnoreCase) )ND = true;
734    
735     if( detlist.Contains("-AC", TString::kIgnoreCase) )AC = false;
736     else if( detlist.Contains("+AC", TString::kIgnoreCase) )AC = true;
737    
738     if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;
739     else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;
740    
741     };
742     //--------------------------------------
743     //
744     //
745     //--------------------------------------
746     /**
747     * Check if a file contains required trees.
748     * @param name File name
749     * @return Pointer to a TChain
750     */
751     Bool_t PamLevel2::CheckLevel2File(TString name){
752    
753     Bool_t CAL__ok = false;
754     Bool_t TRK__ok = false;
755     Bool_t TRG__ok = false;
756     Bool_t TOF__ok = false;
757     Bool_t S4__ok = false;
758     Bool_t ND__ok = false;
759     Bool_t AC__ok = false;
760     Bool_t ORB__ok = false;
761    
762     Bool_t RUN__ok = false;
763    
764     TFile *f = new TFile(name.Data());
765     TList *lk = f->GetListOfKeys();
766     // lk->Print();
767     TIter next(lk);
768     TKey *key =0;
769     while( (key = (TKey*)next()) ){
770     // cout << key->GetName() << endl;
771     if( !strcmp(key->GetName(),"Calorimeter") )CAL__ok = true;
772     if( !strcmp(key->GetName(),"Tracker" ) )TRK__ok = true;
773     if( !strcmp(key->GetName(),"Trigger" ) )TRG__ok = true;
774     if( !strcmp(key->GetName(),"ToF" ) )TOF__ok = true;
775     if( !strcmp(key->GetName(),"S4" ) )S4__ok = true;
776     if( !strcmp(key->GetName(),"NeutronD" ) )ND__ok = true;
777     if( !strcmp(key->GetName(),"Anticounter") )AC__ok = true;
778     if( !strcmp(key->GetName(),"OrbitalInfo") )ORB__ok = true;
779     if( !strcmp(key->GetName(),"Run" ) )RUN__ok = true;
780     };
781    
782     lk->Delete();
783     f->Close();
784    
785     Bool_t FLAG = true;
786     if(!RUN__ok) {
787     cout << "File: "<< f->GetName() <<" discarded ---- Missing RunInfo tree"<< endl;
788     FLAG = false;
789     };
790     if(CAL && !CAL__ok){
791     cout << "File: "<< f->GetName() <<" discarded ---- Missing Calorimeter tree"<< endl;
792     FLAG = false;
793     };
794     if(TRK && !TRK__ok){
795     cout << "File: "<< f->GetName() <<" discarded ---- Missing Tracker tree"<< endl;
796     FLAG = false;
797     };
798     if(TRG && !TRG__ok){
799     cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;
800     FLAG = false;
801     };
802     if(TOF && !TOF__ok){
803     cout << "File: "<< f->GetName() <<" discarded ---- Missing ToF tree"<< endl;
804     FLAG = false;
805     };
806     if(S4 && !S4__ok){
807     cout << "File: "<< f->GetName() <<" discarded ---- Missing S4 tree"<< endl;
808     FLAG = false;
809     };
810     if(ND && !ND__ok){
811     cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl;
812     FLAG = false;
813     };
814     if(AC && !AC__ok){
815     cout << "File: "<< f->GetName() <<" discarded ---- Missing AC tree"<< endl;
816     FLAG = false;
817     };
818     if(ORB && !ORB__ok){
819     cout << "File: "<< f->GetName() <<" discarded ---- Missing ORB tree"<< endl;
820     FLAG = false;
821     };
822    
823     return FLAG;
824    
825     };
826    
827    

  ViewVC Help
Powered by ViewVC 1.1.23