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

Annotation of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.23