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

Diff of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.11 by pam-fi, Mon Dec 11 17:49:03 2006 UTC revision 1.53 by pam-fi, Wed Nov 7 10:39:37 2007 UTC
# Line 1  Line 1 
1  #include <PamLevel2.h>  #include <PamLevel2.h>
2    
3    
4    
5    /////////////////////////////////////////////////////////////////////////////
6    /////////////////////////////////////////////////////////////////////////////
7    /////////////////////////////////////////////////////////////////////////////
8    /////////////////////////////////////////////////////////////////////////////
9    
10    void GPamela::Clear(){
11        Irun   = 0;
12        Ievnt  = 0;
13        Ipa    = 0;
14        X0     = 0.;
15        Y0     = 0.;
16        Z0     = 0.;
17        Theta  = 0.;
18        Phi    = 0.;
19        P0     = 0.;
20        Nthtof  = 0;
21        Nthcat  = 0;
22        Nthcas  = 0;
23        Nthspe  = 0;
24        Nstrpx  = 0;
25        Nstrpy  = 0;
26        Nthcali = 0;
27        Nthcal  = 0;
28        Nthnd   = 0;
29        Nthcard = 0;
30    }
31    
32    void GPamela::Delete(){
33    
34        Clear();
35    
36        delete []    Ipltof;  
37        delete []    Ipaddle;
38        delete []    Ipartof;
39        delete []    Xintof;  
40        delete []    Yintof;  
41        delete []    Zintof;  
42        delete []    Xouttof;
43        delete []    Youttof;
44        delete []    Zouttof;
45        delete []    Ereltof;
46        delete []    Timetof;
47        delete []    Pathtof;
48        delete []    P0tof;  
49        delete []    Iparcat;
50        delete []    Icat;  
51        delete []    Xincat;  
52        delete []    Yincat;  
53        delete []    Zincat;  
54        delete []    Xoutcat;
55        delete []    Youtcat;
56        delete []    Zoutcat;
57        delete []    Erelcat;
58        delete []    Timecat;
59        delete []    Pathcat;
60        delete []    P0cat;  
61        delete []    Iparcas;
62        delete []    Icas;  
63        delete []    Xincas;  
64        delete []    Yincas;  
65        delete []    Zincas;  
66        delete []    Xoutcas;
67        delete []    Youtcas;
68        delete []    Zoutcas;
69        delete []    Erelcas;
70        delete []    Timecas;
71        delete []    Pathcas;
72        delete []    P0cas;  
73        delete []    Iparspe;
74        delete []    Itrpb;  
75        delete []    Itrsl;  
76        delete []    Itspa;  
77        delete []    Xinspe;  
78        delete []    Yinspe;  
79        delete []    Zinspe;  
80        delete []    Xoutspe;
81        delete []    Youtspe;
82        delete []    Zoutspe;
83        delete []    Xavspe;  
84        delete []    Yavspe;  
85        delete []    Zavspe;  
86        delete []    Erelspe;
87        delete []    Pathspe;
88        delete []    P0spe;  
89        delete []    Nxmult;  
90        delete []    Nymult;  
91        delete []    Npstripx;
92        delete []    Ntstripx;
93        delete []    Istripx;
94        delete []    Qstripx;
95        delete []    Xstripx;
96        delete []    Npstripy;
97        delete []    Ntstripy;
98        delete []    Istripy;
99        delete []    Qstripy;
100        delete []    Ystripy;
101        delete []    Icaplane;
102        delete []    Icastrip;
103        delete []    Icamod;  
104        delete []    Enestrip;
105        delete []    Icapl;  
106        delete []    Icasi;  
107        delete []    Icast;  
108        delete []    Xincal;  
109        delete []    Yincal;  
110        delete []    Zincal;  
111        delete []    Erelcal;
112        delete []    Itubend;
113        delete []    Iparnd;  
114        delete []    Xinnd;  
115        delete []    Yinnd;  
116        delete []    Zinnd;  
117        delete []    Xoutnd;  
118        delete []    Youtnd;  
119        delete []    Zoutnd;  
120        delete []    Erelnd;  
121        delete []    Timend;  
122        delete []    Pathnd;  
123        delete []    P0nd;  
124        delete []    Iparcard;
125        delete []    Icard;  
126        delete []    Xincard;
127        delete []    Yincard;
128        delete []    Zincard;
129        delete []    Xoutcard;
130        delete []    Youtcard;
131        delete []    Zoutcard;
132        delete []    Erelcard;
133        delete []    Timecard;
134        delete []    Pathcard;
135        delete []    P0card;  
136    
137    
138    };
139    
140    
141    
142    void GPamela::SetBranchAddress( TChain* fhBookTree ){
143    
144    //    cout << "fhBookTree "<<fhBookTree << endl;
145        // prepare tree
146        fhBookTree->SetBranchAddress("Irun",&Irun);
147        fhBookTree->SetBranchAddress("Ievnt",&Ievnt);
148        fhBookTree->SetBranchAddress("Ipa",&Ipa);
149        fhBookTree->SetBranchAddress("X0",&X0);
150        fhBookTree->SetBranchAddress("Y0",&Y0);
151        fhBookTree->SetBranchAddress("Z0",&Z0);
152        fhBookTree->SetBranchAddress("Theta",&Theta);
153        fhBookTree->SetBranchAddress("Phi",&Phi);
154        fhBookTree->SetBranchAddress("P0",&P0);
155        fhBookTree->SetBranchAddress("Nthtof",&Nthtof);
156        fhBookTree->SetBranchAddress("Ipltof",Ipltof);
157        fhBookTree->SetBranchAddress("Ipaddle",Ipaddle);
158        fhBookTree->SetBranchAddress("Ipartof",Ipartof);
159        fhBookTree->SetBranchAddress("Xintof",Xintof);
160        fhBookTree->SetBranchAddress("Yintof",Yintof);
161        fhBookTree->SetBranchAddress("Zintof",Zintof);
162        fhBookTree->SetBranchAddress("Xouttof",Xouttof);
163        fhBookTree->SetBranchAddress("Youttof",Youttof);
164        fhBookTree->SetBranchAddress("Zouttof",Zouttof);
165        fhBookTree->SetBranchAddress("Ereltof",Ereltof);
166        fhBookTree->SetBranchAddress("Timetof",Timetof);
167        fhBookTree->SetBranchAddress("Pathtof",Pathtof);
168        fhBookTree->SetBranchAddress("P0tof",P0tof);
169        fhBookTree->SetBranchAddress("Nthcat",&Nthcat);
170        fhBookTree->SetBranchAddress("Iparcat",Iparcat);
171        fhBookTree->SetBranchAddress("Icat",Icat);
172        fhBookTree->SetBranchAddress("Xincat",Xincat);
173        fhBookTree->SetBranchAddress("Yincat",Yincat);
174        fhBookTree->SetBranchAddress("Zincat",Zincat);
175        fhBookTree->SetBranchAddress("Xoutcat",Xoutcat);
176        fhBookTree->SetBranchAddress("Youtcat",Youtcat);
177        fhBookTree->SetBranchAddress("Zoutcat",Zoutcat);
178        fhBookTree->SetBranchAddress("Erelcat",Erelcat);
179        fhBookTree->SetBranchAddress("Timecat",Timecat);
180        fhBookTree->SetBranchAddress("Pathcat",Pathcat);
181        fhBookTree->SetBranchAddress("P0cat",P0cat);
182        fhBookTree->SetBranchAddress("Nthcas",&Nthcas);
183        fhBookTree->SetBranchAddress("Iparcas",Iparcas);
184        fhBookTree->SetBranchAddress("Icas",Icas);
185        fhBookTree->SetBranchAddress("Xincas",Xincas);
186        fhBookTree->SetBranchAddress("Yincas",Yincas);
187        fhBookTree->SetBranchAddress("Zincas",Zincas);
188        fhBookTree->SetBranchAddress("Xoutcas",Xoutcas);
189        fhBookTree->SetBranchAddress("Youtcas",Youtcas);
190        fhBookTree->SetBranchAddress("Zoutcas",Zoutcas);
191        fhBookTree->SetBranchAddress("Erelcas",Erelcas);
192        fhBookTree->SetBranchAddress("Timecas",Timecas);
193        fhBookTree->SetBranchAddress("Pathcas",Pathcas);
194        fhBookTree->SetBranchAddress("P0cas",P0cas);
195        fhBookTree->SetBranchAddress("Nthspe",&Nthspe);
196        fhBookTree->SetBranchAddress("Iparspe",Iparspe);
197        fhBookTree->SetBranchAddress("Itrpb",Itrpb);
198        fhBookTree->SetBranchAddress("Itrsl",Itrsl);
199        fhBookTree->SetBranchAddress("Itspa",Itspa);
200        fhBookTree->SetBranchAddress("Xinspe",Xinspe);
201        fhBookTree->SetBranchAddress("Yinspe",Yinspe);
202        fhBookTree->SetBranchAddress("Zinspe",Zinspe);
203        fhBookTree->SetBranchAddress("Xoutspe",Xoutspe);
204        fhBookTree->SetBranchAddress("Youtspe",Youtspe);
205        fhBookTree->SetBranchAddress("Zoutspe",Zoutspe);
206        fhBookTree->SetBranchAddress("Xavspe",Xavspe);
207        fhBookTree->SetBranchAddress("Yavspe",Yavspe);
208        fhBookTree->SetBranchAddress("Zavspe",Zavspe);
209        fhBookTree->SetBranchAddress("Erelspe",Erelspe);
210        fhBookTree->SetBranchAddress("Pathspe",Pathspe);
211        fhBookTree->SetBranchAddress("P0spe",P0spe);
212        fhBookTree->SetBranchAddress("Nxmult",Nxmult);
213        fhBookTree->SetBranchAddress("Nymult",Nymult);
214        fhBookTree->SetBranchAddress("Nstrpx",&Nstrpx);
215        fhBookTree->SetBranchAddress("Npstripx",Npstripx);
216        fhBookTree->SetBranchAddress("Ntstripx",Ntstripx);
217        fhBookTree->SetBranchAddress("Istripx",Istripx);
218        fhBookTree->SetBranchAddress("Qstripx",Qstripx);
219        fhBookTree->SetBranchAddress("Xstripx",Xstripx);
220        fhBookTree->SetBranchAddress("Nstrpy",&Nstrpy);
221        fhBookTree->SetBranchAddress("Npstripy",Npstripy);
222        fhBookTree->SetBranchAddress("Ntstripy",Ntstripy);
223        fhBookTree->SetBranchAddress("Istripy",Istripy);
224        fhBookTree->SetBranchAddress("Qstripy",Qstripy);
225        fhBookTree->SetBranchAddress("Ystripy",Ystripy);
226        fhBookTree->SetBranchAddress("Nthcali",&Nthcali);
227        fhBookTree->SetBranchAddress("Icaplane",Icaplane);
228        fhBookTree->SetBranchAddress("Icastrip",Icastrip);
229        fhBookTree->SetBranchAddress("Icamod",Icamod);
230        fhBookTree->SetBranchAddress("Enestrip",Enestrip);
231        fhBookTree->SetBranchAddress("Nthcal",&Nthcal);
232        fhBookTree->SetBranchAddress("Icapl",Icapl);
233        fhBookTree->SetBranchAddress("Icasi",Icasi);
234        fhBookTree->SetBranchAddress("Icast",Icast);
235        fhBookTree->SetBranchAddress("Xincal",Xincal);
236        fhBookTree->SetBranchAddress("Yincal",Yincal);
237        fhBookTree->SetBranchAddress("Zincal",Zincal);
238        fhBookTree->SetBranchAddress("Erelcal",Erelcal);
239        fhBookTree->SetBranchAddress("Nthnd",&Nthnd);
240        fhBookTree->SetBranchAddress("Itubend",Itubend);
241        fhBookTree->SetBranchAddress("Iparnd",Iparnd);
242        fhBookTree->SetBranchAddress("Xinnd",Xinnd);
243        fhBookTree->SetBranchAddress("Yinnd",Yinnd);
244        fhBookTree->SetBranchAddress("Zinnd",Zinnd);
245        fhBookTree->SetBranchAddress("Xoutnd",Xoutnd);
246        fhBookTree->SetBranchAddress("Youtnd",Youtnd);
247        fhBookTree->SetBranchAddress("Zoutnd",Zoutnd);
248        fhBookTree->SetBranchAddress("Erelnd",Erelnd);
249        fhBookTree->SetBranchAddress("Timend",Timend);
250        fhBookTree->SetBranchAddress("Pathnd",Pathnd);
251        fhBookTree->SetBranchAddress("P0nd",P0nd);
252        fhBookTree->SetBranchAddress("Nthcard",&Nthcard);
253        fhBookTree->SetBranchAddress("Iparcard",Iparcard);
254        fhBookTree->SetBranchAddress("Icard",Icard);
255        fhBookTree->SetBranchAddress("Xincard",Xincard);
256        fhBookTree->SetBranchAddress("Yincard",Yincard);
257        fhBookTree->SetBranchAddress("Zincard",Zincard);
258        fhBookTree->SetBranchAddress("Xoutcard",Xoutcard);
259        fhBookTree->SetBranchAddress("Youtcard",Youtcard);
260        fhBookTree->SetBranchAddress("Zoutcard",Zoutcard);
261        fhBookTree->SetBranchAddress("Erelcard",Erelcard);
262        fhBookTree->SetBranchAddress("Timecard",Timecard);
263        fhBookTree->SetBranchAddress("Pathcard",Pathcard);
264        fhBookTree->SetBranchAddress("P0card",P0card);
265    
266    //    fhBookTree->SetBranchStatus("*",0);
267    
268    }
269    
270    ClassImp(GPamela);
271    
272    /////////////////////////////////////////////////////////////////////////////
273    /////////////////////////////////////////////////////////////////////////////
274    /////////////////////////////////////////////////////////////////////////////
275    /////////////////////////////////////////////////////////////////////////////
276  //--------------------------------------  //--------------------------------------
277  //  //
278  //  //
# Line 7  Line 281 
281   * Default constructor   * Default constructor
282   */   */
283  PamTrack::PamTrack(){  PamTrack::PamTrack(){
284      trk_track  = this->TrkTrack::GetTrkTrack();      trk_track  = 0;
285      calo_track = this->CaloTrkVar::GetCaloTrkVar();      calo_track = 0;
286      tof_track  = this->ToFTrkVar::GetToFTrkVar();      tof_track  = 0;
287        candeleteobj = 0;
288        pscore = 0;
289        iscore = 0;
290  };  };
291  //--------------------------------------  //--------------------------------------
292  //  //
# Line 19  PamTrack::PamTrack(){ Line 296  PamTrack::PamTrack(){
296   * Constructor   * Constructor
297   */   */
298  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o){  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o){
299      trk_track  = this->TrkTrack::GetTrkTrack();  
300      calo_track = this->CaloTrkVar::GetCaloTrkVar();      trk_track  = 0;
301      tof_track  = this->ToFTrkVar::GetToFTrkVar();      calo_track = 0;
302      if(t) *trk_track  = *t;      tof_track  = 0;
303      if(c) *calo_track = *c;  //     if(t)trk_track  = new TrkTrack(*t);
304      if(o) *tof_track  = *o;      //     if(c)calo_track = new CaloTrkVar(*c);
305    //     if(o)tof_track  = new ToFTrkVar(*o);
306        if(t)trk_track  = t;
307        if(c)calo_track = c;
308        if(o)tof_track  = o;
309        candeleteobj = 0;
310    
311  };  };
312    PamTrack::PamTrack(const PamTrack& track){
313    
314        TrkTrack   *t = track.trk_track;
315        CaloTrkVar *c = track.calo_track;
316        ToFTrkVar  *o = track.tof_track;
317    
318        trk_track  = 0;
319        calo_track = 0;
320        tof_track  = 0;
321        if(t)trk_track  = new TrkTrack(*t);
322        if(c)calo_track = new CaloTrkVar(*c);
323        if(o)tof_track  = new ToFTrkVar(*o);
324        candeleteobj = 1;
325        
326    }
327    void PamTrack::Clear(){
328    
329    //    cout << "PamTrack::Clear() "<<candeleteobj<<endl;
330        if(candeleteobj){
331            if(trk_track)  trk_track->TrkTrack::Clear();
332            if(calo_track) calo_track->CaloTrkVar::Clear();//???
333            if(tof_track)  tof_track->ToFTrkVar::Clear();//???
334        }else{
335            trk_track  = 0;
336            calo_track = 0;
337            tof_track  = 0;
338        }
339        pscore = 0;
340        iscore = 0;
341    
342    }
343    void PamTrack::Delete(){
344    //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;
345        if(candeleteobj){
346            if(trk_track)  {
347                trk_track->TrkTrack::Clear();
348                delete trk_track;
349            }
350            if(calo_track){
351                calo_track->CaloTrkVar::Clear();//???
352                delete calo_track;
353            }
354            if(tof_track){
355                tof_track->ToFTrkVar::Clear();//???
356                delete tof_track;
357            }
358        }else{
359            Clear();
360        }
361    }
362  //--------------------------------------  //--------------------------------------
363  //  //
364  //  //
365  //--------------------------------------  //--------------------------------------
366  /**  /**
367   * Constructor   * Default Constructor
368   */   */
369  PamLevel2::PamLevel2(){  PamLevel2::PamLevel2(){
370      Initialize();
371    };
372    
373    /**
374     * Constructor
375     * @param ddir Name of directory where level2 files are stored.
376     * @param list Name of an ascii file containing the list of file names
377     * @param detlist Options to chose what to load.
378     * Possible options are:
379     *       +AUTO --> load all trees/branches in the input files
380     *       +(-)ALL --> inlcude(exclude) all trees/branches
381     *       +(-)TRK1+(-)TRK2+(-)CAL1+(-)CAL2+(-)TOF+(-)TRG+(-)ND+(-)S4+(-)ORB+(-)AC --> inlcude(exclude) trees and branches
382     *       +(-)TRK0 --> include(exclude) tracker level0 tree
383     *       +(-)GP --> include exclude GPAMELA output tree
384     * If no options are specified, the default is assumed. Default is:
385     * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
386     */
387    PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){
388      Initialize();
389      GetPamTree(GetListOfLevel2Files(ddir,list),detlist);
390      GetRunTree(GetListOfLevel2Files(ddir,list));
391    };
392    
393    /**
394     * Constructor
395     * @param ddir Name of directory where level2 files are stored.
396     * @param list Name of an ascii file containing the list of file names
397     * Default trees/branches are loaded. Default is:
398     * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
399     */
400    PamLevel2::PamLevel2(TString ddir,TString list){
401      Initialize();
402      GetPamTree(GetListOfLevel2Files(ddir,list),"");
403      GetRunTree(GetListOfLevel2Files(ddir,list));
404    };
405    
406    
407    void PamLevel2::Initialize(){
408                    
409      trk2_obj  = TrkLevel2::GetTrkLevel2();      h0_obj    = 0;
410      trk1_obj  = TrkLevel1::GetTrkLevel1();      trk0_obj  = 0;
411      trkh_obj  = TrkHough::GetTrkHough();      calo0_obj  = 0;
412      calo1_obj = CaloLevel1::GetCaloLevel1();  
413      calo2_obj = CaloLevel2::GetCaloLevel2();      trk2_obj  = 0;
414      tof_obj   = ToFLevel2::GetToFLevel2();      trk1_obj  = 0;
415      trig_obj  = TrigLevel2::GetTrigLevel2();      trkh_obj  = 0;
416      s4_obj    = S4Level2::GetS4Level2();      calo1_obj = 0;
417      nd_obj    = NDLevel2::GetNDLevel2();      calo2_obj = 0;
418      ac_obj    = AcLevel2::GetAcLevel2();      tof_obj   = 0;
419      orb_obj   = OrbitalInfo::GetOrbitalInfo();      trig_obj  = 0;
420        s4_obj    = 0;
421      run_obj   = new GL_RUN();      nd_obj    = 0;
422            ac_obj    = 0;
423  //     trk1_clone  = 0;      orb_obj   = 0;
424  //     trk2_clone  = 0;      gp_obj    = 0;
425  //     trkh_clone  = 0;  
426  //     calo1_clone = 0;      run_obj   = 0;//new GL_RUN();
427  //     calo2_clone = 0;      soft_obj   = 0;// Emiliano
428  //     tof_clone   = 0;      irun = -1LL;
429  //     trig_clone  = 0;      runfirstentry = 0LL;
430  //     s4_clone    = 0;      runlastentry = 0LL;
431  //     nd_clone    = 0;  
432  //     ac_clone    = 0;      l0_file = NULL;
433  //     orb_clone   = 0;      l0_tree = NULL;
434        iroot   = -1;
435  //     T_clone  = 0;      dbc     = 0;
436  //     C_clone  = 0;  
437  //     O_clone  = 0;      prevshift = 0;
438  //     R_clone  = 0;      maxshift = 10; //EMILIANO
439  //     S_clone  = 0;      
440  //     N_clone  = 0;      run_tree = NULL;
441  //     A_clone  = 0;      run_tree_clone = NULL;
442  //     B_clone  = 0;      sel_tree = NULL;
443        sel_tree_clone = NULL;
444        
445        irunentry = -1LL;
446        pam_tree = NULL;
447        for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;
448    
449        totdltime[0] = 0LL;
450        totdltime[1] = 0LL;
451    
452        host = "mysql://localhost/pamelaprod";
453        user = "anonymous";
454        psw = "";
455        const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
456        const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
457        const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
458        if ( !pamdbhost ) pamdbhost = "";
459        if ( !pamdbuser ) pamdbuser = "";
460        if ( !pamdbpsw ) pamdbpsw = "";
461        if ( strcmp(pamdbhost,"") ) host = pamdbhost;
462        if ( strcmp(pamdbuser,"") ) user = pamdbuser;
463        if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
464    
465      for(Int_t i=0; i<8; i++ )tree_clone[i]=NULL;      
466    
467      sorted_tracks = new TRefArray();  //    sorted_tracks = 0;//new TRefArray();
468            
469        CAL0 = false;
470      CAL1 = true;      CAL1 = true;
471      CAL2 = true;      CAL2 = true;
472      TRK2 = true;      TRK2 = true;
473      TRK1 = false;      TRK1 = false;
474        TRK0 = false;
475      TRKh = false;      TRKh = false;
476      TRG = true;      TRG  = true;
477      TOF = true;      TOF  = true;
478      S4  = true;      TOF0 = false;
479      ND  = true;      S4   = true;
480      AC  = true;      ND   = true;
481      ORB = true;      AC   = true;
482            ORB  = true;    
483        GP   = false;
484    
485        RUN  = true;
486    
487        SELLI = -1;
488    
489        ISGP = false;
490    
491        tsorted=0;
492        timage=0;
493        
494        howtosort = "+CAL+TOF";
495        //howtosort = "+TOF";
496        sortthr = 100.;
497    
498  };  };
499  /**  /**
500   * Destructor   * Delete the event (act as Dtor)
501   */   */
502  PamLevel2::~PamLevel2(){                  void PamLevel2::Delete(){
503      delete run_obj;          
504      Clear();      if(run_obj)delete run_obj;
505        if(soft_obj)delete soft_obj; //Emiliano
506    
507    //    cout << "void PamLevel2::Clear()"<<endl;
508        if(h0_obj)   delete h0_obj;
509        if(trk0_obj) delete trk0_obj;      
510        if(calo0_obj) delete calo0_obj;    
511        if(trk1_obj) delete trk1_obj;      
512        if(trk2_obj) delete trk2_obj;
513        if(trkh_obj) delete trkh_obj;
514        if(calo1_obj)delete calo1_obj;
515        if(calo2_obj)delete calo2_obj;
516        if(tof_obj)  delete tof_obj;
517        if(trig_obj) delete trig_obj;
518        if(s4_obj)   delete s4_obj;
519        if(nd_obj)   delete nd_obj;
520        if(ac_obj)   delete ac_obj;
521        if(orb_obj)  delete orb_obj;
522        if(gp_obj)   delete gp_obj;
523        
524        if(tsorted){
525            tsorted->Delete();
526            delete tsorted;
527        }
528        if(timage){
529            timage->Delete();
530            delete timage;
531        }
532    
533        if(dbc){
534            dbc->Close();
535            delete dbc;
536        }
537        
538        if(l0_file)l0_file->Close();
539        //    if(pam_tree)pam_tree->Delete();;
540    
541      if ( pam_tree ){
542        //
543        // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault...
544        //
545        TList *temp = pam_tree->GetListOfFriends();
546        TList *contents  = new TList; // create chain friend list
547        contents->SetOwner();
548        TIter next(temp);
549        TChain *questo = 0;
550        while ( (questo = (TChain*) next()) ){
551          TString name =  questo->GetName();
552          contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
553        };
554        //
555        // deleting the main chain
556        //
557        pam_tree->Delete();
558        //
559        // deleting the friends...
560        //
561        TIter next2(contents);
562        TChain *questa = 0;
563        while ( questa = (TChain*)next2() ){
564          TString name =  questa->GetName();
565          questa->Delete();      
566          questa=NULL;
567        };
568        //
569      };
570      pam_tree = NULL;
571    
572        if(run_tree)run_tree->Delete();;
573        if(sel_tree)sel_tree->Delete();;
574        for(Int_t i=0; i<NCLONES; i++ )if(pam_tree_clone[i])pam_tree_clone[i]->Delete();;
575        if(run_tree_clone)run_tree_clone->Delete();;
576        if(sel_tree_clone)sel_tree_clone->Delete();;
577        
578    
579  };  };
580    
581  /**  /**
582   * Clear the event   * Clear the event (NB! does not deallocate objects)
583   */   */
584  void PamLevel2::Clear(){  void PamLevel2::Clear(){
585                    
586      TrkLevel1::Clear();  //    cout << "void PamLevel2::Clear()"<<endl;
587            
588      TrkLevel2::Clear();  //
589      CaloLevel2::Clear();  // This method is called once for every entry but RunInfo and SoftInfo do not change until the next run so we cannot clear them here unless we don't
590      ToFLevel2::Clear();  // want to load them for each event even if they are the same...
591      TrigLevel2::Clear();  //
592      S4Level2::Clear();  //    if(run_obj)delete run_obj;
593      NDLevel2::Clear();  //    if(run_obj) run_obj->Clear();  // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead
594      AcLevel2::Clear();  //    if(soft_obj) soft_obj->Clear();
595      OrbitalInfo::Clear();  
596        if(h0_obj)   h0_obj->Clear();      
597  //     if(trk1_clone)trk1_clone->Clear();  //    if(trk0_obj) trk0_obj->Clear();  
598  //     if(trk2_clone)trk2_clone->Clear();      if(trk1_obj) trk1_obj->Clear();    
599  //     if(trkh_clone)trkh_clone->Clear();      if(trk2_obj) trk2_obj->Clear();
600  //     if(calo1_clone)calo1_clone->Clear();      if(trkh_obj) trkh_obj->Clear();
601  //     if(calo2_clone)calo2_clone->Clear();      if(calo0_obj) calo0_obj->Clear();  
602  //     if(tof_clone)tof_clone->Clear();      if(calo1_obj)calo1_obj->Clear();
603  //     if(trig_clone)trig_clone->Clear();      if(calo2_obj)calo2_obj->Clear();
604  //     if(s4_clone)s4_clone->Clear();      if(tof_obj)  tof_obj->Clear();
605  //     if(nd_clone)nd_clone->Clear();      if(trig_obj) trig_obj->Clear();
606  //     if(ac_clone)ac_clone->Clear();      if(s4_obj)   s4_obj->Clear();
607  //     if(orb_clone)orb_clone->Clear();      if(nd_obj)   nd_obj->Clear();
608            if(ac_obj)   ac_obj->Clear();
609      sorted_tracks->Delete(); // clean the reference array      if(orb_obj)  orb_obj->Clear();
610        if(gp_obj)   gp_obj->Clear();
611            
612    //    if(sorted_tracks)sorted_tracks->Clear();
613    //    sorted_tracks.Clear();
614    
615        if(tsorted){
616            tsorted->Delete();
617        }
618        if(timage){
619            timage->Delete();
620        }
621    };
622    
623    void PamLevel2::Reset(){
624      //
625      // First of all clear everything
626      //
627      Clear();
628      //
629      // close and reset chains and pointers
630      //    
631      if ( pam_tree ){
632        //
633        // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault...
634        //
635        TList *temp = pam_tree->GetListOfFriends();
636        TList *contents  = new TList; // create chain friend list
637        contents->SetOwner();
638        TIter next(temp);
639        TChain *questo = 0;
640        while ( (questo = (TChain*) next()) ){
641          TString name =  questo->GetName();
642          contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
643        };
644        //
645        // deleting the main chain
646        //
647        pam_tree->Delete();
648        //
649        // deleting the friends...
650        //
651        TIter next2(contents);
652        TChain *questa = 0;
653        while ( questa = (TChain*)next2() ){
654          TString name =  questa->GetName();
655          questa->Delete();      
656          questa=NULL;
657        };
658        //
659      };
660      pam_tree = NULL;
661      //
662      if(run_tree)run_tree->Delete();;
663      run_tree = NULL;
664      if(sel_tree)sel_tree->Delete();;
665      sel_tree = NULL;
666      //
667      // Close file
668      //
669      if(l0_file)l0_file->Close("R");
670      l0_file = NULL;
671      //
672      h0_obj    = 0;
673      trk0_obj  = 0;
674      calo0_obj  = 0;
675      //
676      trk2_obj  = 0;
677      trk1_obj  = 0;
678      trkh_obj  = 0;
679      calo1_obj = 0;
680      calo2_obj = 0;
681      tof_obj   = 0;
682      trig_obj  = 0;
683      s4_obj    = 0;
684      nd_obj    = 0;
685      ac_obj    = 0;
686      orb_obj   = 0;
687      gp_obj    = 0;
688      //
689      // Reset run pointers
690      //
691      run_obj   = 0;//new GL_RUN();
692      soft_obj   = 0;// Emiliano
693      irun = -1;
694      runfirstentry = 0ULL;
695      runlastentry = 0ULL;    
696      //
697      totdltime[0] = 0LL;
698      totdltime[1] = 0LL;
699      //
700  };  };
701    
702    Bool_t PamLevel2::IsGood(){
703      Bool_t goodev=true;
704      //  if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;
705      if(calo2_obj && calo2_obj->good != 1) goodev = false;
706      if(tof_obj && tof_obj->unpackError != 0) goodev = false;  
707      if(trig_obj && trig_obj->unpackError != 0) goodev = false;
708      if(s4_obj && s4_obj->unpackError != 0) goodev = false;  
709      if(nd_obj && nd_obj->unpackError != 0) goodev = false;  
710      if(ac_obj && ac_obj->unpackError != 255) goodev = false;  
711        //  if(orb_obj)  
712      return goodev;
713    };
714    
715  //--------------------------------------  //--------------------------------------
716  //  //
# Line 136  void PamLevel2::Clear(){ Line 719  void PamLevel2::Clear(){
719  void *PamLevel2::GetPointerTo(const char* c ){  void *PamLevel2::GetPointerTo(const char* c ){
720    
721      TString objname = c;      TString objname = c;
722      if(!objname.CompareTo("TrkLevel1"))return &trk1_obj;  
723      if(!objname.CompareTo("TrkLevel2"))return &trk2_obj;      if(!objname.CompareTo("TrkLevel1"))  {
724      if(!objname.CompareTo("TrkHough"))return &trkh_obj;          if(!trk1_obj){
725      if(!objname.CompareTo("CaloLevel1"))return &calo1_obj;              trk1_obj  = new TrkLevel1();
726      if(!objname.CompareTo("CaloLevel2"))return &calo2_obj;              trk1_obj->Set();
727      if(!objname.CompareTo("ToFLevel2"))return &tof_obj;          }
728      if(!objname.CompareTo("TrigLevel2"))return &trig_obj;          return &trk1_obj;
729      if(!objname.CompareTo("S4Level2"))return &s4_obj;      };
730      if(!objname.CompareTo("NDLevel2"))return &nd_obj;      if(!objname.CompareTo("TrkLevel2"))  {
731      if(!objname.CompareTo("AcLevel2"))return &ac_obj;          if(!trk2_obj){  
732      if(!objname.CompareTo("OrbitalInfo"))return &orb_obj;              trk2_obj  = new TrkLevel2();
733                trk2_obj->Set();
734            }
735            return &trk2_obj;
736        };
737        if(!objname.CompareTo("TrkHough"))   {
738            if(!trkh_obj)  trkh_obj  = new TrkHough();
739            return &trkh_obj;
740        };
741        if(!objname.CompareTo("CaloLevel1")) {
742            if(!calo1_obj) calo1_obj = new CaloLevel1();
743            return &calo1_obj;
744        };
745        if(!objname.CompareTo("CaloLevel2")) {
746            if(!calo2_obj){
747                calo2_obj = new CaloLevel2();
748                calo2_obj->Set();
749            };
750            return &calo2_obj;
751        };
752        if(!objname.CompareTo("ToFLevel2"))  {
753            if(!tof_obj){
754                tof_obj   = new ToFLevel2();
755                tof_obj->Set();
756            }
757            return &tof_obj;
758        };
759        if(!objname.CompareTo("TrigLevel2")) {
760            if(!trig_obj)  trig_obj  = new TrigLevel2();
761            return &trig_obj;
762        };
763        if(!objname.CompareTo("S4Level2"))   {
764            if(!s4_obj)    s4_obj    = new S4Level2();
765            return &s4_obj;
766        };
767        if(!objname.CompareTo("NDLevel2"))   {
768            if(!nd_obj)    nd_obj    = new NDLevel2();
769            return &nd_obj;
770        };
771        if(!objname.CompareTo("AcLevel2"))   {
772            if(!ac_obj)    ac_obj    = new AcLevel2();
773            return &ac_obj;
774        };
775        if(!objname.CompareTo("OrbitalInfo")){
776            if(!orb_obj)   orb_obj   = new OrbitalInfo();
777            return &orb_obj;
778        };
779        if(!objname.CompareTo("GPamela")){
780            if(!gp_obj)   gp_obj   = new GPamela();
781            return &gp_obj;
782        };
783        
784      if(!objname.CompareTo("RunInfo"))return &run_obj;      if(!objname.CompareTo("RunInfo"))return &run_obj;
785    
786        if(!objname.CompareTo("SoftInfo"))return &soft_obj; // Emiliano
787    
788      return NULL;      return NULL;
789  };  };
790  //--------------------------------------  //--------------------------------------
# Line 159  void *PamLevel2::GetPointerTo(const char Line 796  void *PamLevel2::GetPointerTo(const char
796   * (If seqno = -1 retrieves the self-trigger calorimeter track)   * (If seqno = -1 retrieves the self-trigger calorimeter track)
797   */   */
798   CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){   CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
799                
800       if( CaloLevel2::ntrk()==0 ){       if( !calo2_obj )return 0;
801    
802         if( calo2_obj->CaloLevel2::ntrk()==0 ){
803           cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;           cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;
804           return NULL;           return NULL;
805       };       };
# Line 169  void *PamLevel2::GetPointerTo(const char Line 808  void *PamLevel2::GetPointerTo(const char
808       Int_t it_calo=0;       Int_t it_calo=0;
809            
810       do{       do{
811           c = CaloLevel2::GetCaloTrkVar(it_calo);           c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
812           it_calo++;           it_calo++;
813       } while( c && seqno != c->trkseqno && it_calo < CaloLevel2::ntrk());             } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());    
814            
815       if(!c || seqno != c->trkseqno){       if(!c || seqno != c->trkseqno){
816           c = 0;           c = 0;
# Line 190  void *PamLevel2::GetPointerTo(const char Line 829  void *PamLevel2::GetPointerTo(const char
829   */   */
830   ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){   ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
831                    
832       if( ToFLevel2::ntrk()==0 ){       if( !tof_obj )return 0;
833    
834         if( tof_obj->ToFLevel2::ntrk()==0 ){
835           cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;           cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;
836           return NULL;           return NULL;
837       };       };
# Line 199  void *PamLevel2::GetPointerTo(const char Line 840  void *PamLevel2::GetPointerTo(const char
840       Int_t it_tof=0;       Int_t it_tof=0;
841            
842       do{       do{
843           c = ToFLevel2::GetToFTrkVar(it_tof);           c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);
844           it_tof++;           it_tof++;
845       } while( c && seqno != c->trkseqno && it_tof < ToFLevel2::ntrk());       } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());        
846            
847       if(!c || seqno != c->trkseqno){       if(!c || seqno != c->trkseqno){
848           c = 0;           c = 0;
# Line 219  void *PamLevel2::GetPointerTo(const char Line 860  void *PamLevel2::GetPointerTo(const char
860   * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.   * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.
861   */   */
862   PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){   PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
863                
864         cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;
865         cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
866    
867       CaloTrkVar *c = 0;       CaloTrkVar *c = 0;
868       ToFTrkVar  *o = 0;       ToFTrkVar  *o = 0;
869            
# Line 244  void *PamLevel2::GetPointerTo(const char Line 888  void *PamLevel2::GetPointerTo(const char
888    
889  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
890            
891        cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;
892        cout <<"for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack)"<<endl;
893        cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
894      PamTrack *track = 0;      PamTrack *track = 0;
895            
896      if( itrk >=0 && itrk < TrkLevel2::ntrk() ){      if( itrk >=0 && itrk < trk2_obj->TrkLevel2::ntrk() ){
897                    
898          TrkTrack *t = TrkLevel2::GetStoredTrack(itrk);          TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk);
899          track = GetPamTrackAlong(t);          track = GetPamTrackAlong(t);
900                    
901            
902    
903      }else{      }else{
904          cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;          cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
905      };      };
906            
907      return track;      return track;
# Line 260  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 909  PamTrack* PamLevel2::GetStoredTrack(Int_
909  }  }
910  //--------------------------------------  //--------------------------------------
911  //  //
912    
913    /**
914     * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is  PamLevel2::sorted_tracks. Left here as backward compatibility method.
915     **/
916    void PamLevel2::SortTracks(TString how){
917      printf(" WARNING! obsolete, use SortTracks() and SetSortingMethod(TString) instead! \n Setting sorting method to %s \n",how.Data());
918      howtosort = how;  
919      SortTracks();
920    };
921    
922  //  //
923  //--------------------------------------  //--------------------------------------
924  /**  /**
# Line 273  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 932  PamTrack* PamLevel2::GetStoredTrack(Int_
932   *   *
933   * 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).   * 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).
934   */   */
935  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(){
936      TString how = howtosort;
937    
938  //    cout << "call SortTracs() "<<endl;    //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;
939      if( !trk2_obj ){
940        cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";
941        return;
942      };
943      //    cout << "call SortTracs() "<<endl;
944    //Save current Object count    //Save current Object count
945      Int_t ObjectNumber = TProcessID::GetObjectCount();    Int_t ObjectNumber = TProcessID::GetObjectCount();
946    
947  //    cout << "ObjectNumber  "<<ObjectNumber <<endl;    //    cout << "ObjectNumber  "<<ObjectNumber <<endl;
       
     sorted_tracks->Delete(); //temporaneo???  
           
     // loop over the tracks sorted by the tracker  
     Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);  
     Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);  
     Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);  
       
     if( !CAL2 &&  use_CAL) use_CAL = false;  
     if( !TOF &&  use_TOF) use_TOF = false;  
       
     if( !TRK2 ){  
 //      cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;  
         return;  
     };  
948    
949      //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;    //     if(!sorted_tracks)sorted_tracks = new TRefArray();
950          //     sorted_tracks->Clear();
951      for(Int_t i=0; i < TrkLevel2::GetNTracks(); i++){    //    sorted_tracks.Clear();
952            
953          TrkTrack *ts = 0;    if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
954              tsorted->Delete();
955          // get tracker tracks    TClonesArray &ttsorted = *tsorted;
956          TrkTrack   *tp = TrkLevel2::GetTrack(i);                    //tracker    if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
957          CaloTrkVar *cp = 0;    timage->Delete();
958          ToFTrkVar  *op = 0;    TClonesArray &ttimage = *timage;
959    
960    
961    
962      //--------------------------------------------------
963      // retrieve sorting method
964      //--------------------------------------------------
965      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
966      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
967      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
968      Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
969      Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
970      Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
971      
972      if ( use_TOF ){
973        use_S1 = true;
974        use_S2 = true;
975        use_S3 = true;
976      };
977      if( !CAL2 &&  use_CAL) use_CAL = false;
978      if( !TOF ){
979        use_TOF = false;
980        use_S1  = false;
981        use_S2  = false;
982        use_S3  = false;
983      }
984    
985      if( !TRK2 ){
986        //  cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
987        return;
988      };
989    
990      //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
991      
992    
993      //--------------------------------------------------
994      // loop over "physical" tracks sorted by the tracker
995      //--------------------------------------------------
996      for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
997            
998        TrkTrack   *ts = 0;
999        CaloTrkVar *cs = 0;
1000        ToFTrkVar  *os = 0;
1001            
1002        // get tracker tracks
1003        TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
1004        CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
1005        ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
1006    
1007        TrkTrack   *ti = 0; //tracker (image)
1008        CaloTrkVar *ci = 0;
1009        ToFTrkVar  *oi = 0;
1010        //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
1011        // if track has an image, check image selection
1012    
1013        Int_t tp_score = 0;  //main track sorted by the tracker
1014        Int_t ti_score = 0;  //image track
1015        Int_t totp_score = 0;  //main track sorted by the tracker
1016        Int_t toti_score = 0;  //image track
1017    
1018  //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;      if(tp->HasImage()){
         // if track has an image, check image selection  
         if(tp->HasImage()){  
1019                            
1020              TrkTrack   *ti = TrkLevel2::GetTrackImage(i);              //tracker (image)        ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)
1021              CaloTrkVar *ci = 0;        ci = GetCaloStoredTrack(ti->GetSeqNo());
1022              ToFTrkVar  *oi = 0;        oi = GetToFStoredTrack(ti->GetSeqNo());
1023                            
1024  //          cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;        //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
1025    
1026              //assign starting scores        //assign starting scores
1027              Int_t tp_score = 0;  //main track sorted by the tracker        tp_score = 0;  //main track sorted by the tracker
1028              Int_t ti_score = 0;  //image track        ti_score = 0;  //image track
1029                            
1030              // ------------------------        // -----------------------------------------------------------------------------------------
1031              // calorimeter check        // calorimeter check
1032              // ------------------------        // -----------------------------------------------------------------------------------------
1033              // check the Y spatial residual on the first calorimeter plane        // check the Y spatial residual on the first calorimeter plane
1034              // (cut on calorimeter variables from Emiliano)        // (cut on calorimeter variables from Emiliano)
1035              if(        if( use_CAL && !calo2_obj ){
1036                  use_CAL            &&          cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";
1037                  npcfit[1] > 15     &&   //no. of fit planes on Y view          return;
1038                  varcfit[1] < 1000. &&  //fit variance on Y view        };
1039                  true){        if( use_CAL && !cp &&  ci ){
1040            ti_score++;
1041            toti_score++;
1042          };
1043          if( use_CAL &&  cp && !ci ){
1044            tp_score++;
1045            totp_score++;
1046          };
1047          if(
1048             use_CAL            &&
1049    //       calo2_obj->npcfit[1] > 5     &&   //no. of fit planes on Y view
1050    //       calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view
1051             cp && ci &&
1052             true){
1053    
                 cp = GetCaloStoredTrack(tp->GetSeqNo());  
                 ci = GetCaloStoredTrack(ti->GetSeqNo());  
1054                                    
1055                  Float_t resy_p = cp->tbar[0][1] - cbar[0][1]; if(resy_p < 0)resy_p= - resy_p;  //      Float_t resy_p = cp->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_p < 0)resy_p= - resy_p;
1056                  Float_t resy_i = ci->tbar[0][1] - cbar[0][1]; if(resy_i < 0)resy_i= - resy_i;  //      Float_t resy_i = ci->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_i < 0)resy_i= - resy_i;
1057                                    
1058                  if(resy_p <= resy_i) tp_score++;  //      if(resy_p <= resy_i) tp_score++;
1059                  else                 ti_score++;  //      else                 ti_score++;
1060            
1061    
1062            if( cp->npresh > ci->npresh){
1063              tp_score++;
1064              totp_score++;
1065            };
1066            if( cp->npresh < ci->npresh){
1067              ti_score++;
1068              toti_score++;
1069            };
1070    
1071            //      cout << "CALO "<<tp_score<<ti_score<<endl;
1072    
1073  //              cout << "CALO "<<tp_score<<ti_score<<endl;        };
1074          // -----------------------------------------------------------------------------------------
1075          // TOF check
1076          // -----------------------------------------------------------------------------------------
1077          // check the number of hit pmts along the track
1078          // on S12 S21 and S32, where paddles are parallel to Y axis
1079          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !tof_obj ){
1080            cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";
1081            return;
1082          };
1083          //
1084          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !op && oi ){
1085            ti_score++;
1086            toti_score++;
1087          };
1088          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && !oi ){
1089            tp_score++;
1090            totp_score++;
1091          };
1092          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && oi ){
1093            //
1094            Float_t sen = 0.;
1095            for (Int_t ih=0; ih < op->npmtadc; ih++){
1096              Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1097              if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih);
1098            };
1099            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1100              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1101              if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);
1102            };
1103            //
1104            if (  sen >= sortthr && false){ // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
1105              //printf(" IS A NUCLEUS! en = %f \n",sen);
1106              //
1107              // is a nucleus use a different algorithm
1108              //
1109              Int_t nz = 6; Float_t zin[6];                                          // << define TOF z-coordinates
1110              for(Int_t ip=0; ip<nz; ip++)
1111                zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip));     // << read ToF plane z-coordinates
1112              Trajectory *tr = new Trajectory(nz,zin);
1113              //
1114              Int_t nphit_p =0;
1115              Int_t nphit_i =0;
1116              Float_t enhit_p = 0.;
1117              Float_t enhit_i = 0.;
1118              //
1119              for (Int_t ih=0; ih < op->npmtadc; ih++){
1120                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1121                if(pl == 1 || pl == 2 || pl == 5){
1122                  nphit_p++;
1123                  enhit_p += (op->dedx).At(ih);
1124                };
1125              };
1126              //
1127              tp->DoTrack2(tr);
1128              //
1129              if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1130                for (Int_t ih=0; ih < op->npmtadc; ih++){
1131                  Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1132                  if(pl == 0){
1133                    nphit_p++;
1134                    enhit_p += (op->dedx).At(ih);
1135                  };
1136                };
1137              };
1138              if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1139                for (Int_t ih=0; ih < op->npmtadc; ih++){
1140                  Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1141                  if(pl == 3){
1142                    nphit_p++;
1143                    enhit_p += (op->dedx).At(ih);
1144                  };
1145                };
1146              };
1147              if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1148                for (Int_t ih=0; ih < op->npmtadc; ih++){
1149                  Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1150                  if(pl == 4){
1151                    nphit_p++;
1152                    enhit_p += (op->dedx).At(ih);
1153                  };
1154                };
1155              };
1156    
1157              for (Int_t ih=0; ih < oi->npmtadc; ih++){
1158                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1159                if(pl == 1 || pl == 2 || pl == 5){
1160                  nphit_i++;        
1161                  enhit_i += (op->dedx).At(ih);
1162                };
1163              };
1164              //
1165              ti->DoTrack2(tr);
1166              //
1167              if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1168                for (Int_t ih=0; ih < oi->npmtadc; ih++){
1169                  Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1170                  if(pl == 0){
1171                    nphit_i++;
1172                    enhit_i += (op->dedx).At(ih);
1173                  };
1174                };
1175              };
1176              if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1177                for (Int_t ih=0; ih < oi->npmtadc; ih++){
1178                  Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1179                  if(pl == 3){
1180                    nphit_i++;
1181                    enhit_i += (op->dedx).At(ih);
1182                  };
1183              };              };
1184              // ------------------------            };
1185              // TOF check            if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1186              // ------------------------                  for (Int_t ih=0; ih < oi->npmtadc; ih++){
1187              // check the number of hit pmts along the track                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1188              // on S12 S21 and S32, where paddles are parallel to Y axis                if(pl == 4){
1189              if( use_TOF ){                  nphit_i++;
1190                    enhit_i += (op->dedx).At(ih);
1191                  };
1192                };
1193              };            
1194    
1195                                    
1196                  Int_t nphit_p =0;            if(
1197                  Int_t nphit_i =0;               (use_TOF || use_S1 || use_S2 || use_S3)            &&
1198                 (nphit_p+nphit_i) !=0 &&  
1199                 true){
1200                        
1201                //      printf(" seqno %i nphit_p %i nphit_i %i enhit_p %f enhit_i %f \n",trk2_obj->TrkLevel2::GetSeqNo(i),nphit_p,nphit_i,enhit_p,enhit_i);
1202                //      printf(" score p %i score i %i \n",tp_score,ti_score);
1203                //            if( enhit_p > enhit_i ) tp_score++;
1204                //            if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
1205                if ( nphit_p > nphit_i ) tp_score++;
1206                if ( nphit_p < nphit_i ) ti_score++;
1207                if ( nphit_p == nphit_i ){
1208                  if ( enhit_p > enhit_i ) tp_score++;
1209                  else ti_score++;
1210                };
1211                //      printf(" dopo score p %i score i %i \n",tp_score,ti_score);
1212              };
1213              delete tr;
1214              //
1215            } else {
1216              //
1217              // NOT a NUCLEUS
1218              //
1219              //printf(" NOT a NUCLEUS! en = %f \n",sen);
1220    
1221              Int_t nphit_p =0;
1222              Int_t nphit_i =0;
1223                                    
                 op = GetToFStoredTrack(tp->GetSeqNo());  
                 oi = GetToFStoredTrack(ti->GetSeqNo());  
1224                                    
1225  /*                              cout << "track: npmtadc "<< op->npmtadc << endl;            /*                            cout << "track: npmtadc "<< op->npmtadc << endl;
1226                                  cout << "track: npmttdc "<< op->npmttdc << endl;              cout << "track: npmttdc "<< op->npmttdc << endl;
1227                                  cout << "image: npmtadc "<< oi->npmtadc << endl;              cout << "image: npmtadc "<< oi->npmtadc << endl;
1228                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/              cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1229                                    
1230                  for (Int_t ih=0; ih < op->npmtadc; ih++){  //        for (Int_t ih=0; ih < op->npmtadc; ih++){
1231                      Int_t pl = GetPlaneIndex( (op->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1232                      if(pl == 1 || pl == 2 || pl == 5)nphit_p++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
1233                  };  //        };
1234                                    
1235                  for (Int_t ih=0; ih < oi->npmtadc; ih++){  //        for (Int_t ih=0; ih < oi->npmtadc; ih++){
1236                      Int_t pl = GetPlaneIndex( (oi->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1237                      if(pl == 1 || pl == 2 || pl == 5)nphit_i++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1238                  };  //        };
1239              // --- modified to count tdc signals (more efficient?)
1240              // --- and to implement check on tdcflag
1241              for (Int_t ih=0; ih < op->npmttdc; ih++){
1242                Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );
1243    //          if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
1244                if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){
1245                  if( (op->tdcflag).At(ih)==0 )nphit_p++;
1246                };
1247              };
1248                                    
1249                  if(            for (Int_t ih=0; ih < oi->npmttdc; ih++){
1250                      use_TOF            &&              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );
1251                      (nphit_p+nphit_i) !=0 &&      //          if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;  
1252                      true){              if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){
1253                                      if( (oi->tdcflag).At(ih)==0 )nphit_i++;  
                     if( nphit_p >= nphit_i) tp_score++;  
                     else ti_score++;  
                 };  
 //              cout << "TOF "<<tp_score<<ti_score<<endl;  
1254              };              };
1255              if(tp_score == ti_score) use_TRK = true;            };
1256              // ------------------------                  
1257              // tracker check            if(
1258              // ------------------------               (nphit_p+nphit_i) !=0 &&  
1259              // chi**2 difference is not always large enough to distinguish among               true){
1260              // the real track and its image.                      
1261              // Tracker check will be applied always when calorimeter and tof information is ambiguous.              if ( nphit_p != nphit_i ){
1262              if(use_TRK){                totp_score += nphit_p;
1263                  if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;                toti_score += nphit_i;
1264                  else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;                tp_score+=nphit_p;
1265  //              cout << "TRK "<<tp_score<<ti_score<<endl;                ti_score+=nphit_i;
1266              };              };
1267                //      if     ( nphit_p > nphit_i) tp_score+=nphit_p;
1268                //      else if( nphit_p < nphit_i) ti_score+=nphit_i;
1269                //      else ;//niente
1270              };
1271            };
1272            //      cout << "TOF "<<tp_score<<ti_score<<endl;
1273          };
1274    
1275    
1276    //      if(tp_score == ti_score) use_TRK = true;
1277    
1278    
1279          // -----------------------------------------------------------------------------------------
1280          // tracker check
1281          // -----------------------------------------------------------------------------------------
1282          // chi**2 difference is not always large enough to distinguish among
1283          // the real track and its image.
1284          // Tracker check will be applied always when calorimeter and tof information is ambiguous.
1285          // *** MODIFIED ON AUGUST 2007 ***
1286          if(use_TRK){
1287    //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
1288    //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
1289    
1290              // CHECK 1 : number of points along X  
1291            if ( tp->GetNX() >= ti->GetNX() ){
1292              tp_score++ ;
1293              totp_score++ ;
1294            };
1295            if ( tp->GetNX() <= ti->GetNX() ){
1296              ti_score++ ;
1297              toti_score++ ;
1298            };
1299              // CHECK 2 : number of points along Y  
1300            if ( tp->GetNY() >= ti->GetNY() ){
1301              tp_score++ ;
1302              totp_score++ ;
1303            };
1304            if ( tp->GetNY() <= ti->GetNY() ){
1305              ti_score++ ;
1306              toti_score++ ;
1307            };
1308              // CHECK 3 : chi**2 along X  
1309    //        if(      tp->GetChi2X() > 0 && (tp->GetChi2X() < ti->GetChi2X() || ti->GetChi2X() <=0) ) tp_score++ ;
1310    //        if(      ti->GetChi2X() > 0 && (ti->GetChi2X() < tp->GetChi2X() || tp->GetChi2X() <=0) ) ti_score++ ;
1311              // CHECK 4 : chi**2 along Y  
1312    //        if(      tp->GetChi2Y() > 0 && (tp->GetChi2Y() < ti->GetChi2Y() || ti->GetChi2Y() <=0) ) tp_score++ ;
1313    //        if(      ti->GetChi2Y() > 0 && (ti->GetChi2Y() < tp->GetChi2Y() || tp->GetChi2Y() <=0) ) ti_score++ ;
1314              // CHECK 5 : total chi**2  
1315    //        if(      tp->chi2 > 0 && (tp->chi2 < ti->chi2 || ti->chi2 <=0) ) tp_score++ ;
1316    //        if(      ti->chi2 > 0 && (ti->chi2 < tp->chi2 || tp->chi2 <=0) ) ti_score++ ;
1317    
1318            //      cout << "TRK "<<tp_score<<ti_score<<endl;
1319          };
1320                            
1321              // ------------------------  
1322              // the winner is....  
1323              // ------------------------            // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1324              if      (tp_score > ti_score) ts = tp;//the track sorted by the tracker!!        // the winner is....
1325              else if (tp_score < ti_score) ts = ti;//its image!!        // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1326              else {        if      (tp_score > ti_score) {
1327                  ts = tp;          
1328  //                              cout << "Warning - track image ambiguity not solved" << endl;  
1329  //                              cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;        }else if (tp_score < ti_score) {
1330              };  
1331    
1332            ts = ti;//its image!!
1333            cs = ci;
1334            os = oi;
1335            Int_t totis = toti_score;
1336    
1337            ti = tp;//its image!!
1338            ci = cp;
1339            oi = op;
1340    
1341            tp = ts;//its image!!
1342            cp = cs;
1343            op = os;
1344    
1345            toti_score = totp_score;
1346            totp_score = totis;
1347    
1348                    
1349          }else {
1350    
1351    //      cout << "Warning - track image ambiguity not solved" << endl;
1352    
1353          };
1354                            
1355          }else{      }else{
1356              ts = tp;        totp_score = 1;
1357          };        toti_score = 0;
1358                  
1359  //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;        //            ts = tp;
1360          sorted_tracks->Add(ts);//save the track in the sorted array        //            cs = cp;
1361  //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;        //            os = op;
1362                };
1363      };          
1364      //Restore Object count      //  cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
1365      //To save space in the table keeping track of all referenced objects      //  sorted_tracks->Add(ts);//save the track in the sorted array
1366      //we assume that our events do not address each other. We reset the      //  sorted_tracks.Add(ts);//save the track in the sorted array
1367      //object count to what it was at the beginning of the event.      //  sorted_tracks.Add(tp);//save the track in the sorted array
1368      TProcessID::SetObjectCount(ObjectNumber);      //  cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
1369        //  cout<<"o "<<tp<<endl;
1370        //  cout<<"o "<<cp<<endl;
1371        //  cout<<"o "<<op<<endl;
1372    
1373        new(ttsorted[i]) PamTrack(tp,cp,op);
1374        new(ttimage[i])  PamTrack(ti,ci,oi);
1375    
1376        ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);
1377        ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);
1378        ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);
1379        ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);
1380      };
1381    
1382      if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
1383        cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;
1384        tsorted->Delete(); tsorted=0;
1385        timage->Delete(); timage=0;
1386      }
1387    
1388      //Restore Object count
1389      //To save space in the table keeping track of all referenced objects
1390      //We reset the object count to what it was at the beginning of the event.
1391      TProcessID::SetObjectCount(ObjectNumber);
1392            
1393  };  };
1394  //--------------------------------------  //--------------------------------------
# Line 430  void PamLevel2::SortTracks(TString how){ Line 1399  void PamLevel2::SortTracks(TString how){
1399   * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.   * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.
1400   * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.   * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.
1401   */   */
1402  TRefArray *PamLevel2::GetTracks(){  // TRefArray *PamLevel2::GetTracks(){
1403    
1404    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
1405    //     SortTracks("+CAL+TOF");
1406    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
1407    
1408    // //   return  sorted_tracks;
1409    //     return &sorted_tracks;
1410        
1411    //  };
1412    TClonesArray *PamLevel2::GetTracks(){
1413    
1414  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1415      SortTracks("+CAL+TOF");      SortTracks();
1416  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1417    
1418      return sorted_tracks;      return tsorted;
1419        
1420   };   };
1421  //--------------------------------------  //--------------------------------------
1422   //   //
# Line 448  TRefArray *PamLevel2::GetTracks(){ Line 1428  TRefArray *PamLevel2::GetTracks(){
1428   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
1429   */   */
1430  PamTrack *PamLevel2::GetTrack(int it){  PamTrack *PamLevel2::GetTrack(int it){
1431    
1432    //    if(!trk2_obj) return 0;
1433                    
1434    // //  *-*-*-*+-*-*-*-*-*-*-*-*-*
1435    //     SortTracks("+CAL+TOF");
1436    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
1437    // //    if(!sorted_tracks)return 0;
1438    //     if(sorted_tracks.IsEmpty())return 0;
1439    
1440    //     PamTrack *track = 0;
1441        
1442    //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() && it<sorted_tracks.GetEntriesFast() ){    
1443    //      TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);
1444    //      track = GetPamTrackAlong(t);
1445    //     }else{
1446    //      cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
1447    //     };
1448        
1449    //     return track;
1450    
1451    //    cout << "PamLevel2::GetTrack(int it) "<<endl;
1452  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1453      SortTracks("+CAL+TOF");      SortTracks();
1454  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1455            if(!tsorted)return 0;
1456        if(!tsorted->GetEntries())return 0;
1457    
1458      PamTrack *track = 0;      PamTrack *track = 0;
1459            
1460      if( it >=0 && it < TrkLevel2::GetNTracks() && it<sorted_tracks->GetEntriesFast() ){      if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks()){
1461          TrkTrack   *t = (TrkTrack*)sorted_tracks->At(it);  //      TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);
1462          track = GetPamTrackAlong(t);  //      track = GetPamTrackAlong(t);
1463            TClonesArray &t = *(tsorted);
1464            track = (PamTrack*)t[it];
1465            
1466      }else{      }else{
1467          cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;          cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
1468      };      };
1469            
1470      return track;      return track;
# Line 476  PamTrack *PamLevel2::GetTrack(int it){ Line 1481  PamTrack *PamLevel2::GetTrack(int it){
1481   */   */
1482  PamTrack *PamLevel2::GetTrackImage(int it){  PamTrack *PamLevel2::GetTrackImage(int it){
1483    
1484    //     if(!trk2_obj) return 0;
1485    
1486    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
1487    //     SortTracks("+CAL+TOF");
1488    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
1489    // //    if(!sorted_tracks)return 0;
1490    //     if(sorted_tracks.IsEmpty())return 0;
1491        
1492    //     PamTrack *image = 0;
1493        
1494    //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){
1495    //      TrkTrack *temp = (TrkTrack*)sorted_tracks.At(it);
1496    //      if( temp->HasImage() ){
1497    //          TrkTrack   *t = trk2_obj->TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());
1498    //          image = GetPamTrackAlong(t);
1499    //      }else{
1500    //          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
1501    //      };
1502    //     }else{
1503    //      cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
1504    //     };
1505        
1506    //     return image;
1507    
1508    
1509  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1510      SortTracks("+CAL+TOF");      SortTracks();
1511  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1512        if(!timage)return 0;
1513        if(!timage->GetEntries())return 0;
1514            
1515      PamTrack *image = 0;      PamTrack *image = 0;
1516            
1517      if( it >=0 && it < TrkLevel2::GetNTracks() ){      if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){
1518          TrkTrack *temp = (TrkTrack*)sorted_tracks->At(it);          TClonesArray &t = *(tsorted);
1519          if( temp->HasImage() ){          PamTrack *temp = (PamTrack*)t[it];
1520              TrkTrack   *t = TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());          if( temp->GetTrkTrack()->HasImage() ){
1521              image = GetPamTrackAlong(t);              TClonesArray &t = *(timage);
1522                image = (PamTrack*)t[it];
1523          }else{          }else{
1524              cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;  //          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
1525          };          };
1526      }else{      }else{
1527          cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;          cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
1528      };      };
1529            
1530      return image;      return image;
# Line 509  PamTrack *PamLevel2::GetTrackImage(int i Line 1542  PamTrack *PamLevel2::GetTrackImage(int i
1542   */   */
1543  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){
1544    
1545      if( !detlist.IsNull() ) SetWhichTrees(detlist);      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {
1546      else                    GetWhichTrees(f);          cout << "+AUTO"<<endl;
1547            GetWhichTrees(f);
1548        };
1549        SetWhichTrees(detlist);
1550    
1551        if ( pam_tree ){
1552            printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");
1553            return pam_tree;
1554        };
1555      //
1556    
1557        cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
1558    
1559    //    SetWhichTrees(detlist);
1560    
1561      TTree *Trout =0;      TTree *Trout =0;
1562    
1563      TString fname = f->GetName();      TString fname = f->GetName();
1564      if(!CheckLevel2File(fname))return NULL;      if(!CheckLevel2File(fname))return NULL;
1565    
1566      UInt_t *found=0;      //    UInt_t *found=0;    
1567    
1568        cout<< "GetPamTree(TFile*,TString): detector list --> ";
1569        if(TRK1)cout<<"TRK1 ";
1570        if(TRK2)cout<<"TRK2 ";
1571        if(TRKh)cout<<"TRKH ";
1572        if(CAL1)cout<<"CAL1 ";
1573        if(CAL2)cout<<"CAL2 ";
1574        if(TOF)cout<<"TOF ";
1575        if(TRG)cout<<"TRG ";
1576        if(AC)cout<<"AC ";
1577        if(ND)cout<<"ND ";
1578        if(S4)cout<<"S4 ";
1579        if(ORB)cout<<"ORB ";
1580        if(GP)cout<<"GP ";
1581        cout << endl;
1582        if(SELLI)cout<<">>> Found selection-list <<<"<<endl;
1583    
1584        f->cd();
1585    
1586  // Tracker  // Tracker
1587      TTree *T = (TTree*)f->Get("Tracker");      TTree *T = (TTree*)f->Get("Tracker");
1588      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
1589          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1590          else    T->SetBranchStatus("TrkLevel2",0,found);  //      else    T->SetBranchStatus("TrkLevel2",0,found);
1591          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
1592          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1593          else    T->SetBranchStatus("TrkLevel1",0,found);  //      else    T->SetBranchStatus("TrkLevel1",0,found);
1594          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
1595          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1596          else    T->SetBranchStatus("TrkHough",0,found);  //      else    T->SetBranchStatus("TrkHough",0,found);
1597          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
1598          if(!Trout)Trout=T;          if(!Trout)Trout=T;
1599          else Trout->AddFriend(T);          else Trout->AddFriend(T);
# Line 540  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1604  TTree *PamLevel2::GetPamTree(TFile *f, T
1604      TTree *C = (TTree*)f->Get("Calorimeter");      TTree *C = (TTree*)f->Get("Calorimeter");
1605      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
1606          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1607          else    C->SetBranchStatus("CaloLevel2",0,found);  //      else    C->SetBranchStatus("CaloLevel2",0,found);
1608          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
1609          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1610          else    C->SetBranchStatus("CaloLevel1",0,found);  //      else    C->SetBranchStatus("CaloLevel1",0,found);
1611          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
1612          if(!Trout)Trout=C;          if(!Trout)Trout=C;
1613          else Trout->AddFriend(C);          else Trout->AddFriend(C);
1614      }else{      }else{
1615          cout << "Calorimeter  : missing tree"<<endl;          cout << "Calorimeter  : missing tree"<<endl;
1616      };      };
1617    
1618      // ToF          // ToF    
1619      TTree *O = (TTree*)f->Get("ToF");      TTree *O = (TTree*)f->Get("ToF");
1620      if(O && TOF) {      if(O && TOF) {
# Line 565  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1630  TTree *PamLevel2::GetPamTree(TFile *f, T
1630      if(R && TRG) {      if(R && TRG) {
1631          R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));          R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1632          cout << "Trigger      : set branch address TrigLevel2"<<endl;          cout << "Trigger      : set branch address TrigLevel2"<<endl;
1633          if(!Trout)Trout=O;          if(!Trout)Trout=R;
1634          else Trout->AddFriend(R);          else Trout->AddFriend(R);
1635      }else{      }else{
1636          cout << "Trigger      : missing tree"<<endl;          cout << "Trigger      : missing tree"<<endl;
# Line 575  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1640  TTree *PamLevel2::GetPamTree(TFile *f, T
1640      if(S && S4) {      if(S && S4) {
1641          S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));          S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1642          cout << "S4           : set branch address S4Level2"<<endl;          cout << "S4           : set branch address S4Level2"<<endl;
1643          if(!Trout)Trout=O;          if(!Trout)Trout=S;
1644          else Trout->AddFriend(S);          else Trout->AddFriend(S);
1645      }else{      }else{
1646          cout << "S4           : missing tree"<<endl;          cout << "S4           : missing tree"<<endl;
# Line 585  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1650  TTree *PamLevel2::GetPamTree(TFile *f, T
1650      if(N && ND) {      if(N && ND) {
1651          N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));          N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1652          cout << "NeutronD     : set branch address NDLevel2"<<endl;          cout << "NeutronD     : set branch address NDLevel2"<<endl;
1653          if(!Trout)Trout=O;          if(!Trout)Trout=N;
1654          else Trout->AddFriend(N);          else Trout->AddFriend(N);
1655      }else{      }else{
1656          cout << "NeutronD     : missing tree"<<endl;          cout << "NeutronD     : missing tree"<<endl;
# Line 595  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1660  TTree *PamLevel2::GetPamTree(TFile *f, T
1660      if(A && AC) {      if(A && AC) {
1661          A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));          A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1662          cout << "Anticounter  : set branch address AcLevel2"<<endl;          cout << "Anticounter  : set branch address AcLevel2"<<endl;
1663          if(!Trout)Trout=O;          if(!Trout)Trout=A;
1664          else Trout->AddFriend(A);          else Trout->AddFriend(A);
1665      }else{      }else{
1666          cout << "Anticounter  : missing tree"<<endl;          cout << "Anticounter  : missing tree"<<endl;
# Line 605  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1670  TTree *PamLevel2::GetPamTree(TFile *f, T
1670      if(B && ORB) {      if(B && ORB) {
1671          B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1672          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1673          if(!Trout)Trout=O;          if(!Trout)Trout=B;
1674          else Trout->AddFriend(B);          else Trout->AddFriend(B);
1675      }else{      }else{
1676          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
1677      };      };
1678    
1679        // GPamela
1680        TTree *G = (TTree*)f->Get("h20");
1681        if(G && GP) {
1682            if(!gp_obj)gp_obj=new GPamela();
1683    //      ------------------------------------
1684    //      ATTENZIONE!!!
1685    //      non so per quale arcano motivo,
1686    //      per l'albero di gpamela il branch address lo devo settare
1687    //      DOPO aver fatto friend
1688    //      FGRRRVZZZZUTSALKJMSLKJ!!!
1689    //      ------------------------------------
1690    //      gp_obj->SetBranchAddress(G); //ho dovuto fare in maniera diversa dagli altri
1691    //      cout << "h20          : set branch address GPamela "<<endl;
1692            if(!Trout)Trout=G;
1693            else Trout->AddFriend(G);
1694        }else{
1695    //      cout << "h20          : missing tree"<<endl;
1696        };
1697    
1698    
1699        TTree *L = (TTree*)f->Get("SelectionList");
1700        if(L && SELLI==1) {
1701    //      L->SetBranchAddress("RunEntry",&irun);
1702    //      cout << "SelectionList: set branch address RunEntry"<<endl;
1703    //      L->SetBranchAddress("EventEntry",&irunentry);
1704    //      cout << "SelectionList: set branch address EventEntry"<<endl;
1705    //      if(!Trout)Trout=O;
1706    //      else Trout->AddFriend("SelectionList");
1707            cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemente!!!!"<<endl;
1708            sel_tree = 0;
1709        }else{
1710            cout << "SelectionList  : missing tree"<<endl;
1711        };
1712            
1713      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1714    
1715    //      ------------------------------------
1716    //      ATTENZIONE!!!
1717    //      non so per quale arcano motivo,
1718    //      per l'albero di gpamela il branch address lo devo settare
1719    //      DOPO aver fatto friend
1720    //      FGRRRVZZZZUTSALKJMSLKJ!!!
1721    //      ------------------------------------
1722        if(G && GP) {      
1723            gp_obj->SetBranchAddress(Trout); //ho dovuto fare in maniera diversa dagli altri
1724            cout << "h20          : set branch address GPamela "<<endl;
1725        }else{
1726            cout << "h20          : missing tree"<<endl;
1727        };
1728    
1729        pam_tree = (TChain*)Trout;
1730            
1731      return Trout;      return Trout;
1732            
# Line 631  TList*  PamLevel2::GetListOfLevel2Files( Line 1746  TList*  PamLevel2::GetListOfLevel2Files(
1746                    
1747      TString wdir = gSystem->WorkingDirectory();      TString wdir = gSystem->WorkingDirectory();
1748            
1749      if(ddir=="")ddir = wdir;      //    if(ddir=="")ddir = wdir;
1750  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1751      cout << "Level2 data directory : "<<  ddir << endl;      if ( ddir != ""){
1752              cout << "Level2 data directory : "<<  ddir << endl;
1753        } else {
1754          cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory " << endl;
1755        };
1756      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
1757      contents->SetOwner();      contents->SetOwner();
1758            
1759      char *fullpath;  //    char *fullpath;
1760    //    const char *fullpath;
1761            
1762      // if no input file list is given:        // if no input file list is given:  
1763      if ( flisttxt != "" ){      if ( flisttxt != "" ){
1764                    
1765          if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){  //      if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){        
1766              cout <<"File "<<flisttxt<<" not found"<<endl;  //      if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){
1767              return 0;  //          cout <<"File "<<flisttxt<<" not found"<<endl;
1768          }        //          return 0;
1769  //              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));  //      }      
1770          flisttxt = fullpath;  //      flisttxt = fullpath;
1771                  if ( !flisttxt.EndsWith(".root") ){
1772    
1773            flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1774    
1775          if( !gSystem->ChangeDirectory(ddir) ){          if( !gSystem->ChangeDirectory(ddir) ){
1776              cout << "Cannot change directory : "<<ddir<<endl;              cout << "Cannot change directory : "<<ddir<<endl;
1777              return 0;              return 0;
# Line 658  TList*  PamLevel2::GetListOfLevel2Files( Line 1780  TList*  PamLevel2::GetListOfLevel2Files(
1780          cout <<"Input file list : " << flisttxt <<endl;          cout <<"Input file list : " << flisttxt <<endl;
1781          ifstream in;          ifstream in;
1782          in.open(flisttxt, ios::in); //open input file list          in.open(flisttxt, ios::in); //open input file list
1783            if(!in.good()){
1784                cout <<" ERROR opening the file "<<endl;
1785                gSystem->ChangeDirectory(wdir); // back to the working directory
1786                return 0;
1787            }      
1788          int line=0;          int line=0;
1789          while (1) {          while (1) {
1790              TString file;              TString file;
# Line 671  TList*  PamLevel2::GetListOfLevel2Files( Line 1798  TList*  PamLevel2::GetListOfLevel2Files(
1798              }              }
1799              if(file.Contains("#"))file = file(0,file.First("#"));              if(file.Contains("#"))file = file(0,file.First("#"));
1800  //          cout <<"(2) " << file << endl;  //          cout <<"(2) " << file << endl;
1801              if( gSystem->IsFileInIncludePath(file,&fullpath) ){  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1802    //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
1803                if( file.EndsWith(".root") ){
1804                  TString filedir;
1805                  if (ddir != ""){
1806                    filedir = ddir; // take the input dir
1807                  } else {
1808                    gSystem->ChangeDirectory(wdir); // back to the working directory
1809                    filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir
1810                  };
1811                    char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));
1812                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1813                    delete fullpath;
1814              }else{              }
1815    //          }else{
1816  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1817              };  //          };
1818          };          };
1819          in.close();          in.close();
1820                  } else {
1821              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));
1822              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1823              contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1824              delete fullpath;
1825          };        
1826      }else{      }else{
1827                    
1828          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
1829          cout << "Check for existing root files."<<endl;          cout << "Check for existing root files."<<endl;
1830  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
1831                    if ( ddir == "" ){
1832              ddir = wdir;
1833              cout << "Level2 data directory : "<<  ddir << endl;
1834            };
1835    
1836          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1837          TList *temp = datadir->GetListOfFiles();          TList *temp = datadir->GetListOfFiles();
1838  //              temp->Print();  //              temp->Print();
# Line 699  TList*  PamLevel2::GetListOfLevel2Files( Line 1845  TList*  PamLevel2::GetListOfLevel2Files(
1845          while ( (questo = (TSystemFile*) next()) ) {          while ( (questo = (TSystemFile*) next()) ) {
1846              TString name =  questo-> GetName();              TString name =  questo-> GetName();
1847              if( name.EndsWith(".root") ){              if( name.EndsWith(".root") ){
1848                  char *fullpath;  //              const char *fullpath = gSystem->FindFile(ddir,name);
1849                  gSystem->IsFileInIncludePath(name,&fullpath);  //              char *fullpath;
1850    //              gSystem->IsFileInIncludePath(name,&fullpath);
1851                    char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(name));
1852                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));
1853                    delete fullpath;
1854              };              };
1855          }          }
1856          delete temp;          delete temp;
# Line 711  TList*  PamLevel2::GetListOfLevel2Files( Line 1860  TList*  PamLevel2::GetListOfLevel2Files(
1860      gSystem->ChangeDirectory(wdir); // back to the working directory      gSystem->ChangeDirectory(wdir); // back to the working directory
1861  //      cout << endl << "Selected files:" << endl;  //      cout << endl << "Selected files:" << endl;
1862  //      contents->Print();  //      contents->Print();
1863      cout << contents->GetEntries()<<" files selected\n";      cout << contents->GetEntries()<<" files \n";
1864  //      cout << endl;  //      cout << endl;
1865  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;
1866      return contents;      return contents;
# Line 727  TList*  PamLevel2::GetListOfLevel2Files( Line 1876  TList*  PamLevel2::GetListOfLevel2Files(
1876   * @return Pointer to a TChain   * @return Pointer to a TChain
1877   */   */
1878  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){
1879        //
1880        //
1881        //
1882        if ( pam_tree ){
1883            printf("WARNING: TChain *PamLevel2::GetPamTree(TList *fl, TString detlist) -- pam_tree already exists!\n ");
1884            return pam_tree;
1885        };
1886        //
1887            
1888      TChain *Trout =0;      TChain *Trout =0;
1889    
     if( !detlist.IsNull() )SetWhichTrees(detlist);  
       
1890            
1891      TChain *T = 0;            if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {
1892      TChain *C = 0;          if( fl->GetEntries()>0 ){
1893      TChain *O = 0;              cout << "+AUTO"<<endl;
1894      TChain *R = 0;              TFile *fprimo = new TFile( fl->At(0)->GetName() );
1895      TChain *S = 0;              GetWhichTrees(fprimo);
1896      TChain *N = 0;              fprimo->Delete();
1897      TChain *A = 0;          }
1898      TChain *B = 0;      };
1899        SetWhichTrees(detlist);    
1900    
1901    
1902    
1903    //    if( !detlist.IsNull() )SetWhichTrees(detlist);
1904    //    
1905         TChain *T = 0;    
1906         TChain *C = 0;
1907         TChain *O = 0;
1908         TChain *R = 0;
1909         TChain *S = 0;
1910         TChain *N = 0;
1911         TChain *A = 0;
1912         TChain *B = 0;
1913         TChain *G = 0;
1914    
1915         TChain *L = 0;
1916            
1917      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
1918      if(CAL2||CAL1)       C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
# Line 750  TChain *PamLevel2::GetPamTree(TList *fl, Line 1922  TChain *PamLevel2::GetPamTree(TList *fl,
1922      if(ND)               N = new TChain("NeutronD");      if(ND)               N = new TChain("NeutronD");
1923      if(AC)               A = new TChain("Anticounter");      if(AC)               A = new TChain("Anticounter");
1924      if(ORB)              B = new TChain("OrbitalInfo");      if(ORB)              B = new TChain("OrbitalInfo");
1925        if(GP)               G = new TChain("h20");
1926        L = new TChain("SelectionList");
1927            
1928      // loop over files and create chains              // loop over files and create chains        
1929      TIter next(fl);      TIter next(fl);
1930      TSystemFile *questo = 0;      TSystemFile *questo = 0;
1931      while ( (questo = (TSystemFile*) next()) ) {      while ( (questo = (TSystemFile*) next()) ) {
1932          TString name =  questo->GetName();          TString name =  questo->GetName();
1933  //      cout << "File: "<< name << endl;          cout << "File: "<< name << endl;
1934          if( CheckLevel2File(name) ){          if( CheckLevel2File(name) ){
1935              if(TRK2||TRK1||TRKh) T->Add(name);              if(TRK2||TRK1||TRKh) T->Add(name);
1936              if(CAL1||CAL2)       C->Add(name);              if(CAL1||CAL2)       C->Add(name);
# Line 766  TChain *PamLevel2::GetPamTree(TList *fl, Line 1940  TChain *PamLevel2::GetPamTree(TList *fl,
1940              if(ND)               N->Add(name);              if(ND)               N->Add(name);
1941              if(AC)               A->Add(name);              if(AC)               A->Add(name);
1942              if(ORB)              B->Add(name);              if(ORB)              B->Add(name);
1943                if(GP)               G->Add(name);
1944                if(SELLI==1)         L->Add(name);
1945          };          };
1946      }      };
1947            
1948      cout << "done chain \n";      cout << "done chain \n";
1949        cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1950    
1951      UInt_t *found=0;  //    UInt_t *found=0;
1952  // Tracker  // Tracker
1953      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
1954          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));  //      if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1955          else    T->SetBranchStatus("TrkLevel2",0,found);  //      if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
1956          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;  //      if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1957          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));  //      if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
1958          else    T->SetBranchStatus("TrkLevel1",0,found);  //      if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1959          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;  //      if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
         if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));  
         else    T->SetBranchStatus("TrkHough",0,found);  
         if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;  
1960          if(!Trout)Trout=T;          if(!Trout)Trout=T;
1961          else Trout->AddFriend("Tracker");          else Trout->AddFriend("Tracker");
1962      }else{      }else{
1963          cout << "Tracker      : missing tree"<<endl;  //        cout << "Tracker      : missing tree"<<endl;
1964      };      };
1965      // Calorimeter      // Calorimeter
1966      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
1967          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));  //        if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1968          else    C->SetBranchStatus("CaloLevel2",0,found);  //        if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
1969          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;  //        if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1970          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));  //        if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
         else    C->SetBranchStatus("CaloLevel1",0,found);  
         if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;  
1971          if(!Trout)Trout=C;          if(!Trout)Trout=C;
1972          else Trout->AddFriend("Calorimeter");          else Trout->AddFriend("Calorimeter");
1973      }else{      }else{
1974          cout << "Calorimeter  : missing tree"<<endl;  //        cout << "Calorimeter  : missing tree"<<endl;
1975      };      };
1976      // ToF          // ToF    
1977      if(O && TOF) {      if(O && TOF) {
1978          O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));  //        O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
1979          cout << "ToF          : set branch address ToFLevel2"<<endl;  //        cout << "ToF          : set branch address ToFLevel2"<<endl;
1980          if(!Trout)Trout=O;          if(!Trout)Trout=O;
1981          else Trout->AddFriend("ToF");          else Trout->AddFriend("ToF");
1982      }else{      }else{
1983          cout << "ToF         : missing tree"<<endl;  //        cout << "ToF         : missing tree"<<endl;
1984      };      };
1985      // Trigger      // Trigger
1986      if(R && TRG) {      if(R && TRG) {
1987          R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));  //        R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1988          cout << "Trigger      : set branch address TrigLevel2"<<endl;  //        cout << "Trigger      : set branch address TrigLevel2"<<endl;
1989          if(!Trout)Trout=O;          if(!Trout)Trout=O;
1990          else Trout->AddFriend("Trigger");          else Trout->AddFriend("Trigger");
1991      }else{      }else{
1992          cout << "Trigger      : missing tree"<<endl;  //        cout << "Trigger      : missing tree"<<endl;
1993      };      };
1994      // S4      // S4
1995      if(S && S4) {      if(S && S4) {
1996          S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));  //        S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1997          cout << "S4           : set branch address S4Level2"<<endl;  //        cout << "S4           : set branch address S4Level2"<<endl;
1998          if(!Trout)Trout=O;          if(!Trout)Trout=O;
1999          else Trout->AddFriend("S4");          else Trout->AddFriend("S4");
2000      }else{      }else{
2001          cout << "S4           : missing tree"<<endl;  //        cout << "S4           : missing tree"<<endl;
2002      };      };
2003      // Neutron Detector      // Neutron Detector
2004      if(N && ND) {      if(N && ND) {
2005          N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));  //        N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
2006          cout << "NeutronD     : set branch address NDLevel2"<<endl;  //        cout << "NeutronD     : set branch address NDLevel2"<<endl;
2007          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2008          else Trout->AddFriend("NeutronD");          else Trout->AddFriend("NeutronD");
2009      }else{      }else{
2010          cout << "NeutronD     : missing tree"<<endl;  //        cout << "NeutronD     : missing tree"<<endl;
2011      };      };
2012      // Anticounters      // Anticounters
2013      if(A && AC) {      if(A && AC) {
2014          A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));  //        A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
2015          cout << "Anticounter  : set branch address AcLevel2"<<endl;  //        cout << "Anticounter  : set branch address AcLevel2"<<endl;
2016          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2017          else Trout->AddFriend("Anticounter");          else Trout->AddFriend("Anticounter");
2018      }else{      }else{
2019          cout << "Anticounter  : missing tree"<<endl;  //        cout << "Anticounter  : missing tree"<<endl;
2020      };      };
2021      // Orbital Info      // Orbital Info
2022      if(B && ORB) {      if(B && ORB) {
2023          B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));  //      B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
2024          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;  //      cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
2025          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2026          else Trout->AddFriend("OrbitalInfo");          else Trout->AddFriend("OrbitalInfo");
2027      }else{      }else{
2028          cout << "OrbitalInfo  : missing tree"<<endl;  //      cout << "OrbitalInfo  : missing tree"<<endl;
2029        };
2030        // GPamela
2031        if(G && GP) {
2032            if(!gp_obj)gp_obj = new GPamela();
2033    //      ------------------------------------
2034    //      ATTENZIONE!!!
2035    //      non so per quale arcano motivo,
2036    //      per l'albero di gpamela il branch address lo devo settare
2037    //      DOPO aver fatto friend
2038    //      FGRRRVZZZZUTSALKJMSLKJ!!!
2039    //      ------------------------------------
2040    //      gp_obj->SetBranchAddress(G); //ho dovuto fare in maniera diversa dagli altri
2041    //      cout << "h20          : set branch address GPamela "<<endl;
2042            if(!Trout)Trout=G;
2043            else Trout->AddFriend("h20");
2044        }else{
2045    //      cout << "h20          : missing tree"<<endl;
2046        };
2047    
2048    //  =====================================
2049    //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND
2050    //  =====================================
2051        SetBranchAddress(Trout);
2052    
2053        cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2054    
2055        // Selection List
2056        if(L && SELLI==1) {
2057            cout<<">>> Found selection-list <<<"<<endl;
2058            L->SetBranchAddress("RunEntry",&irun);
2059            cout << "SelectionList: set branch address RunEntry"<<endl;
2060            L->SetBranchAddress("EventEntry",&irunentry);
2061            cout << "SelectionList: set branch address EventEntry"<<endl;
2062            sel_tree = L;
2063    //      if(!Trout)Trout=O;
2064    //      else Trout->AddFriend("SelectionList");
2065            cout << "----------------------------------------------------" <<endl;
2066        }else{
2067    //      cout << "SelectionList  : missing tree"<<endl;
2068            if(L)L->Delete();
2069      };      };
2070            
2071  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
2072    
2073        //      ------------------------------------
2074  //     // Tracker  //      ATTENZIONE!!!
2075  //     if(TRK2||TRK1||TRKh){  //      non so per quale arcano motivo,
2076  //      if(!Tout)Tout=T;  //      per l'albero di gpamela il branch address lo devo settare
2077  //      else Tout->AddFriend("Tracker");  //      DOPO aver fatto friend
2078  //     }  //      FGRRRVZZZZUTSALKJMSLKJ!!!
2079  //     // Calorimeter  //      ------------------------------------
2080  //     if(CAL2||CAL1) {          //     cout << G << " --- "<<GP <<endl;
2081  //      if(!Tout)Tout=C;  //     if(G && GP) {    
2082  //      else Tout->AddFriend("Calorimeter");  //      gp_obj->SetBranchAddress(Trout); //ho dovuto fare in maniera diversa dagli altri
2083  //     };  //      cout << "h20          : set branch address GPamela "<<endl;
2084  //     // ToF      //     }else{
2085  //     if(TOF) {  //      cout << "h20          : missing tree"<<endl;
 //      if(!Tout)Tout=O;  
 //      else Tout->AddFriend("ToF");  
 //     };  
 //     // Trigger  
 //     if(TRG) {  
 //      if(!Tout)Tout=R;  
 //      else Tout->AddFriend("Trigger");  
 //     };  
 //     // S4  
 //     if(S4) {  
 //      if(!Tout)Tout=S;  
 //      else Tout->AddFriend("S4");  
 //     };  
 //     // Neutron Detector  
 //     if(ND) {  
 //      if(!Tout)Tout=N;  
 //      else Tout->AddFriend("NeutronD");  
2086  //     };  //     };
2087  //     // Anticounters  
2088  //     if(AC) {  
2089  //      if(!Tout)Tout=A;      pam_tree = Trout;
 //      else Tout->AddFriend("Anticounter");  
 //     };  
 //     // OrbitalInfo  
 //     if(ORB) {  
 //      if(!Tout)Tout=B;  
 //      else Tout->AddFriend("OrbitalInfo");  
 //     };  
       
 //    cout<<endl<<" Number of entries: "<<Tout->GetEntries()<<endl<<endl;  
       
 //    if( Tout->GetEntries() )PamLevel2::SetBranchAddress( Tout );  
2090            
2091      return Trout;      return Trout;
2092  }  }
# Line 929  void PamLevel2::SetBranchAddress(TTree * Line 2113  void PamLevel2::SetBranchAddress(TTree *
2113      ND     = ND  & t->GetBranchStatus("NDLevel2");      ND     = ND  & t->GetBranchStatus("NDLevel2");
2114      AC     = AC  & t->GetBranchStatus("AcLevel2");      AC     = AC  & t->GetBranchStatus("AcLevel2");
2115      ORB    = ORB & t->GetBranchStatus("OrbitalInfo");      ORB    = ORB & t->GetBranchStatus("OrbitalInfo");
2116        GP     = GP  & t->GetBranchStatus("h20");
2117    
2118    
2119      // Tracker      // Tracker
# Line 985  void PamLevel2::SetBranchAddress(TTree * Line 2170  void PamLevel2::SetBranchAddress(TTree *
2170          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
2171          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
2172      };      };
2173        // GPamela
2174        if(GP) {
2175    //      GetPointerTo("GPamela");
2176            if(!gp_obj)gp_obj = new GPamela();
2177            gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2178            cout << "h20          : set branch address GPamela "<<endl;
2179        };
2180        // SelectionList
2181        if(SELLI==1) {
2182            t->SetBranchAddress("RunEntry", &irun);
2183            cout << "SelectionList: set branch address RunEntry"<<endl;
2184            t->SetBranchAddress("EventEntry", &irunentry);
2185            cout << "SelectionList: set branch address EventEntry"<<endl;
2186        };
2187            
2188  }  }
2189  /**  /**
# Line 992  void PamLevel2::SetBranchAddress(TTree * Line 2191  void PamLevel2::SetBranchAddress(TTree *
2191   */   */
2192  void PamLevel2::SetBranchAddress(TChain *t){  void PamLevel2::SetBranchAddress(TChain *t){
2193    
2194      TRK2    = TRK2 & t->GetBranchStatus("TrkLevel2");  //     TRK2    = TRK2 & t->GetBranchStatus("TrkLevel2");
2195      TRK1    = TRK1 & t->GetBranchStatus("TrkLevel1");  //     TRK1    = TRK1 & t->GetBranchStatus("TrkLevel1");
2196      TRKh    = TRKh & t->GetBranchStatus("TrkHough");  //     TRKh    = TRKh & t->GetBranchStatus("TrkHough");
2197      CAL1    = CAL1 & t->GetBranchStatus("CaloLevel1");  //     CAL1    = CAL1 & t->GetBranchStatus("CaloLevel1");
2198      CAL2    = CAL2 & t->GetBranchStatus("CaloLevel2");  //     CAL2    = CAL2 & t->GetBranchStatus("CaloLevel2");
2199      TOF    = TOF & t->GetBranchStatus("ToFLevel2");  //     TOF    = TOF & t->GetBranchStatus("ToFLevel2");
2200      TRG    = TRG & t->GetBranchStatus("TrigLevel2");  //     TRG    = TRG & t->GetBranchStatus("TrigLevel2");
2201      S4     = S4  & t->GetBranchStatus("S4Level2");  //     S4     = S4  & t->GetBranchStatus("S4Level2");
2202      ND     = ND  & t->GetBranchStatus("NDLevel2");  //     ND     = ND  & t->GetBranchStatus("NDLevel2");
2203      AC     = AC  & t->GetBranchStatus("AcLevel2");  //     AC     = AC  & t->GetBranchStatus("AcLevel2");
2204      ORB    = ORB & t->GetBranchStatus("OrbitalInfo");  //     ORB    = ORB & t->GetBranchStatus("OrbitalInfo");
2205    //    GP     = GP & t->GetBranchStatus("h20");
2206    
2207      // Tracker      // Tracker
2208       if(TRK2) {       if(TRK2) {
# Line 1058  void PamLevel2::SetBranchAddress(TChain Line 2258  void PamLevel2::SetBranchAddress(TChain
2258          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
2259          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
2260      };      };
2261        // GPamela
2262    //    cout <<"GP "<<GP<<endl;
2263        if(GP) {
2264    //      GetPointerTo("GPamela");
2265            if(!gp_obj)gp_obj = new GPamela();
2266            gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2267            cout << "h20          : set branch address GPamela "<<endl;
2268        };
2269        // SelectionList
2270        if(SELLI==1) {
2271            t->SetBranchAddress("RunEntry", &irun);
2272            cout << "SelectionList: set branch address RunEntry"<<endl;
2273            t->SetBranchAddress("EventEntry", &irunentry);
2274            cout << "SelectionList: set branch address EventEntry"<<endl;
2275        };
2276            
2277  }  }
2278    
# Line 1072  void PamLevel2::SetBranchAddress(TChain Line 2287  void PamLevel2::SetBranchAddress(TChain
2287   * @return Pointer to a TChain   * @return Pointer to a TChain
2288   */   */
2289  TChain *PamLevel2::GetRunTree(TList *fl){  TChain *PamLevel2::GetRunTree(TList *fl){
2290              //
2291      TChain *R = new TChain("Run");    //
2292      //
2293      if ( run_tree ){
2294        printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
2295        return run_tree;
2296      };    
2297      //
2298      TChain *R = new TChain("Run");
2299            
2300      // loop over files and create chains              // loop over files and create chains        
2301      TIter next(fl);      TIter next(fl);
# Line 1085  TChain *PamLevel2::GetRunTree(TList *fl) Line 2307  TChain *PamLevel2::GetRunTree(TList *fl)
2307              R->Add(name);              R->Add(name);
2308          };          };
2309      }      }
2310        
2311      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));      if(R->GetNtrees()){
2312      cout << "Run         : set branch address RunInfo"<<endl;      
2313                R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
2314      return R;          cout << "Run         : set branch address RunInfo"<<endl;
2315                R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2316  }          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
2317  //--------------------------------------      }else{
2318  //          delete R;
2319  //          R=0;
2320  //--------------------------------------      }
2321    
2322        run_tree = R;
2323    
2324        return R;
2325        
2326    }
2327    //--------------------------------------
2328    //
2329    //
2330    //--------------------------------------
2331    /**
2332     * Get the Run tree  from a file.
2333     * @param f Pointer to a TFile
2334     * @return Pointer to a TTree
2335     */
2336    TTree *PamLevel2::GetRunTree(TFile *f){
2337      if ( run_tree ){
2338        printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
2339        return run_tree;
2340      };
2341            
2342    
2343        cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
2344    
2345        TTree *T = (TTree*)f->Get("Run");
2346        
2347        if(T){
2348            T->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
2349            cout << "Run         : set branch address RunInfo"<<endl;
2350            T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2351            cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
2352        }
2353    
2354        run_tree = (TChain*)T;
2355    
2356        return T;
2357        
2358    }
2359    /**
2360     * Update the runinfo informations (to be used to have Run infos event by event basis)
2361     * @param run Pointer to the chain/tree which contains run infos
2362     * @return true if a new run has been read, false if it is still the same run
2363     */
2364    Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){
2365      //
2366      // check if we have already called once GetEntry, if not call it
2367      //
2368        cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- ATTENZIONE --- NON E` MANTENUTA!!!!!!!.... "<<endl;
2369        if(!run){
2370              cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree "<<endl;
2371              return(false);        
2372        }
2373        if ( run->GetEntries() <= 0 ) return(false);
2374      //
2375      
2376      //  Int_t oldrun = irun;
2377      Long64_t oldrun = irun;
2378    
2379      // --------------------------------------
2380      // if it is a full file (not preselected)
2381      // --------------------------------------
2382      if(SELLI==0){
2383    
2384          //
2385          // the absolute time is necessary to relate the event with the run
2386          //
2387          if( !GetOrbitalInfo() && !ISGP){
2388              cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2389              return(false);
2390          }
2391    
2392          ULong64_t abstime = 0;
2393          if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;
2394    
2395    
2396          //
2397          // the first time the routine is called, set run search from the beginning
2398          //
2399          if ( irun < 0LL ){
2400              irun = 0LL;
2401              run->GetEntry(irun);
2402              runfirstentry = 0LL;
2403              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2404              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2405              
2406              if( ISGP && run->GetEntries()!=1 ){
2407                  cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl;
2408                  cout << "** WARNING ** run will not be updated"<<endl;
2409              }
2410    
2411          };      
2412          //
2413          if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2414          //
2415          if ( irun == run->GetEntries()-1LL &&
2416               !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2417                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2418                ){
2419             irun = -1LL;
2420             runfirstentry = 0LL;
2421             runlastentry = -1LL;
2422           };
2423          // modificato il controllo sull'aggiornamento del run, per evitare problemi
2424          // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
2425          //
2426          bool fromfirst = true;
2427          //
2428          while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){
2429    //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
2430              irun++;
2431              run->GetEntry(irun);
2432              runfirstentry = runlastentry;
2433              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;
2434              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2435    //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2436    //        cout << "runfirstentry "<<runfirstentry<<endl;
2437              //      printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
2438              //      printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);
2439              //      printf(" IDRUN %u \n",GetRunInfo()->ID);
2440              //
2441    //        prevshift = 0;
2442              //
2443              if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){
2444                  printf(" resetting irun  (it should NOT happen!!!)\n");
2445                  fromfirst = false;
2446                  irun = 0;
2447                  run->GetEntry(irun);
2448                  runfirstentry = 0ULL;
2449                  runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2450                  if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2451              };
2452              //
2453          };
2454          //
2455          if (
2456               !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2457                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2458              ) {
2459            printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n",abstime);
2460              return false;
2461          }
2462          //
2463          if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
2464          //
2465          //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
2466          //
2467          prevshift = 0;
2468          cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2469    //      cout << "runfirstentry "<<runfirstentry<<endl;
2470          return(true);    
2471      };
2472      // ----------------------------------------------------
2473      // if it is a preselected file (there is SelectionList)
2474      // NBNB - the event tree MUST be read first
2475      // ----------------------------------------------------
2476      if(SELLI==1){      
2477          sel_tree->GetEntry(iev);
2478    //      cout << irun << " "<< irunentry << endl;
2479          if(irun != oldrun){
2480              run->GetEntry(irun);
2481              cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2482              prevshift = 0;
2483              return true;
2484          }
2485          return false;
2486      }
2487    
2488      return false;
2489      //
2490    };
2491    
2492    Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){
2493    
2494        if(!run_tree){
2495            cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded"<<endl;
2496            return false;
2497        }
2498        if ( run_tree->GetEntries() <= 0 ) {
2499            cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty"<<endl;
2500            return(false);
2501        }
2502      
2503        Int_t oldrun = irun; // store current run index
2504    
2505        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2506        // if it is a full file (not preselected)
2507        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2508        if(SELLI==0){
2509    
2510            // ---------------------------------------------------------------
2511            // increment dead and live-time counters
2512            // ---------------------------------------------------------------
2513            if( GetTrigLevel2() ){
2514                totdltime[0]+=GetTrigLevel2()->dltime[0];
2515                totdltime[1]+=GetTrigLevel2()->dltime[1];
2516            }
2517            totdltime[2]++;
2518    
2519    //      cout << setw(10)<<totdltime[0]<<setw(10)<<totdltime[1]<<setw(10)<<totdltime[2]<<endl;
2520    
2521            // ---------------------------------------------------------------
2522            // retrieve OBT and absolute time of the event
2523            // ---------------------------------------------------------------
2524            ULong64_t abstime = 0;
2525            ULong64_t obt     = 0;
2526            if( GetOrbitalInfo() ){
2527                abstime = GetOrbitalInfo()->absTime;
2528                obt     = GetOrbitalInfo()->OBT;
2529            }
2530            // ---------------------------------------------------------------
2531            // the absolute time is necessary to relate the event with the run
2532            // ---------------------------------------------------------------
2533            if( !GetOrbitalInfo() && !ISGP ){
2534                cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2535                return(false);
2536            }
2537          
2538            // -----------------------------------------------------------------------
2539            // the first time the routine is called, set run search from the beginning
2540            // -----------------------------------------------------------------------
2541            if ( irun < 0 ){
2542                irun = 0LL;
2543                irunentry = 0;
2544                prevshift = 0;
2545                run_tree->GetEntry(irun);
2546    
2547                if( ISGP && run_tree->GetEntries()!=1 ){
2548                    cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl;
2549                    cout << "** WARNING ** run will not be updated"<<endl;
2550                }
2551            };      
2552    
2553            // -----------------------------------------------------------------------
2554            // if it is simulation, assign abstime by hand (temporaneo!!!)
2555            // -----------------------------------------------------------------------
2556            if(ISGP){
2557                abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2558                obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO
2559            }
2560            //
2561            bool fromfirst = true; // first loop over runs
2562    
2563    //      Bool_t hasfrag = false;
2564    //      if( GetRunInfo()->ID_RUN_FRAG!=0 && GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID)hasfrag=true;
2565    //      ULong64_t fragid = GetRunInfo()->ID_RUN_FRAG;
2566    
2567            // ------------------------------------------------------
2568            // loop over runs to find the one that contains the event
2569            // ------------------------------------------------------
2570            while (
2571                (
2572                    (
2573                        !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2574                          abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
2575                        !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2576                          obt <= GetRunInfo()->RUNTRAILER_OBT)
2577                        )
2578                    || GetRunInfo()->NEVENTS==0
2579    //              || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento
2580                    || !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)
2581                    )
2582                    && irun < run_tree->GetEntries() ){
2583    
2584                // - - - - - - - - - - - - -
2585                // irunentry = position of current entry, relative to the run
2586                // prevshift = shift needed to synchronize l0 and l2 data (nested events)
2587                // - - - - - - - - - - - - -
2588    
2589                // -----------------------------------------
2590                // store dead and live-time of previous run
2591                // -----------------------------------------
2592                if(fromfirst){
2593                    if(oldrun==irun){
2594                        /// decrement counters
2595                        if( GetTrigLevel2()){
2596                            totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time
2597                            totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time
2598                        }
2599                        totdltime[2]--;                              //event counter
2600                        cout << endl;
2601                        cout << "n.events     : "<<totdltime[2]<<endl;
2602                        cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;
2603                        cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;      
2604                    }else{
2605                        totdltime[0]=0;//live-time
2606                        totdltime[1]=0;//dead-time
2607                        totdltime[2]=0;                             //event counter
2608                        cout << " *** JUMP RUN *** irun "<<irun<<endl;
2609                    }
2610                    /// add an entry
2611                    if(run_tree_clone)
2612                        if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2613                            run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2614                    /// reset counters
2615                    if( GetTrigLevel2() ){
2616                        totdltime[0]=GetTrigLevel2()->dltime[0];//live-time
2617                        totdltime[1]=0;                         //dead-time
2618                    }
2619                    totdltime[2]=1;                             //event counter
2620                }
2621    
2622    
2623                irun++;
2624                // ------------------------------------
2625                // if the end of run tree is reached...
2626                // ------------------------------------
2627                if( irun == run_tree->GetEntries() ){
2628                    if(!fromfirst){
2629                        // -----------------------------------------------------
2630                        // if it happened already once and the run was not found
2631                        // ---> exit with error
2632                        // -----------------------------------------------------
2633                        cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- event entry #"<<iev<<" does not belong to any run (should not happen)" <<endl;
2634                        return false;
2635                    }
2636                    // -----------------------------------------
2637                    // ...otherwise repeat search from beginning
2638                    // -----------------------------------------
2639                    cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- reached end of run tree. searchin again from beginning " <<endl;
2640                    fromfirst = false;
2641                    irun = 0LL;
2642                    runfirstentry = 0LL;
2643                }
2644                // -------------------------------------------------------------------
2645                // save the index of the first entry of the run, relative to pam_tree,
2646                // and read a new run
2647                // -------------------------------------------------------------------
2648                if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;
2649                irunentry = 0;
2650                prevshift = 0;          
2651                run_tree->GetEntry(irun);      
2652                if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){
2653                    cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<"  has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl;
2654                    cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl;
2655                }
2656    //          if(hasfrag &&  fragid != GetRunInfo()->ID){
2657    //              cout << "... where is the next fragment ??"<<endl;
2658    //          }
2659            };
2660    
2661    
2662            // --------------------------------------
2663            // if there was no need to update the run
2664            // ---> exit with FALSE
2665            // --------------------------------------
2666            if ( irun == oldrun ) return(false);
2667    
2668            // --------------------------------------
2669            // ... otherwise
2670            // --------------------------------------
2671    
2672    
2673    
2674    //      // -----------------------------------------
2675    //      // store dead and live-time of previous run
2676    //      // -----------------------------------------
2677    //      // --------------------------------------------------------------
2678    //      // if the run is empty, fill the dead-live time branch with zeros
2679    //      // --------------------------------------------------------------
2680    //      /// if some runs have been jumped, fill with zeros
2681    //      if(irun-oldrun>1){
2682    //          ULong64_t  temp[3];
2683    //          temp[0]=totdltime[0];
2684    //          temp[1]=totdltime[1];
2685    //          temp[2]=totdltime[2];
2686    //          for(int i=oldrun+1; i<irun; irun++){
2687    //              totdltime[0]=0;
2688    //              totdltime[1]=0;
2689    //              totdltime[2]=0;
2690    //              cout << " ** JUMPED RUN **"<<endl;
2691    //              if(run_tree_clone)
2692    //                  if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2693    //                      run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2694    //          }
2695    //          totdltime[0]=temp[0];
2696    //          totdltime[1]=temp[1];
2697    //          totdltime[2]=temp[2];
2698    //      }
2699    //      /// decrement counters
2700    //      if( GetTrigLevel2() ){
2701    //          totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time
2702    //          totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time
2703    //      }
2704    //      totdltime[2]--;                              //event counter
2705    //      /// add an entry
2706    //      if(irun>0 ){
2707    //          cout << endl;
2708    //          cout << "n.events     : "<<totdltime[2]<<endl;
2709    //          cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;
2710    //          cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;      
2711    //          if(run_tree_clone)
2712    //              if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2713    //                  run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2714    //      }
2715    //      /// reset counters
2716    //      if( GetTrigLevel2() ){
2717    //          totdltime[0]=GetTrigLevel2()->dltime[0];//live-time
2718    //          totdltime[1]=0;                         //dead-time
2719    //      }
2720    //      totdltime[2]=1;                             //event counter
2721            
2722    
2723            // --------------------------------------
2724            // ---> exit with TRUE
2725            // --------------------------------------
2726            cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2727            // ----------------------------------------------------
2728            // then check if the run has a fragment
2729            // in this case we have to switch to the next fragment
2730            // when the end of the first fragment is reached
2731            // ----------------------------------------------------
2732            if(
2733                GetRunInfo()->ID_RUN_FRAG != 0 &&
2734    //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&
2735                true ){
2736                cout << "* fragment *"<<endl;              
2737            }
2738    
2739            return(true);    
2740        };
2741        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2742        // if it is a preselected file (there is SelectionList)
2743        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2744        if(SELLI==1){      
2745            sel_tree->GetEntry(iev);
2746            if(irun != oldrun){
2747                run_tree->GetEntry(irun);
2748                cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2749                prevshift = 0;
2750                return true;
2751            }
2752            return false;
2753        }
2754    
2755        return false;
2756        //
2757    };
2758  /**  /**
2759   * Get the Run tree  from a file.   * Update the runinfo informations (to be used to have Run infos event by event basis)
2760   * @param f Pointer to a TFile   * @param run Pointer to the chain/tree which contains run infos
2761   * @return Pointer to a TTree   * @return true if a new run has been read, false if it is still the same run
2762   */   */
2763  TTree *PamLevel2::GetRunTree(TFile *f){  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){
2764      return(UpdateRunInfo((TChain*)run,iev));
2765    };
2766    
     TTree *R = (TTree*)f->Get("Run");  
       
     R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));  
     cout << "Run         : set branch address RunInfo"<<endl;  
       
     return R;  
       
 }  
2767  //--------------------------------------  //--------------------------------------
2768  //  //
2769  //  //
# Line 1121  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2773  TTree *PamLevel2::GetRunTree(TFile *f){
2773   * @param detlist TString containing the sequence of trees required   * @param detlist TString containing the sequence of trees required
2774  */  */
2775  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist){
2776                
2777      if(detlist.Contains("+ALL", TString::kIgnoreCase)){  //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
2778        if( detlist.Contains("+ALL", TString::kIgnoreCase)){
2779    
2780            cout << " ======================================================== "<<endl;
2781            cout << "                       (( WARNING ))                      "<< endl;
2782            cout << " The meaning of the option +ALL has changed!!             "<<endl;
2783            cout << " Now it includes really all (level0+level1+level2+gpamela)"<<endl;
2784            cout << " and the file is discarded if it does not contain all     "<<endl;
2785            cout << " trees or level0 files are not available!!                "<<endl;
2786            cout << " ======================================================== "<<endl;
2787                
2788            CAL0 = true;
2789          CAL1 = true;          CAL1 = true;
2790          CAL2 = true;          CAL2 = true;
2791          TRK2 = true;          TRK2 = true;
2792          TRK1 = false;          TRK1 = true;
2793          TRKh = false;          TRKh = true;
2794            TRK0 = true;
2795          TRG = true;          TRG = true;
2796          TOF = true;          TOF = true;
2797            TOF0 = true;
2798          S4  = true;          S4  = true;
2799          ND  = true;          ND  = true;
2800          AC  = true;          AC  = true;
2801          ORB = true;          ORB = true;
2802            GP  = true;
2803      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
2804            CAL0 = false;
2805          CAL1 = false;          CAL1 = false;
2806          CAL2 = false;          CAL2 = false;
2807          TRK2 = false;          TRK2 = false;
2808          TRK1 = false;          TRK1 = false;
2809          TRKh = false;          TRKh = false;
2810            TRK0 = false;
2811          TRG = false;          TRG = false;
2812          TOF = false;          TOF = false;
2813            TOF0 = false;
2814          S4  = false;          S4  = false;
2815          ND  = false;          ND  = false;
2816          AC  = false;          AC  = false;
2817          ORB = false;          ORB = false;
2818            GP  = false;
2819      };      };
2820            
2821  //  -------------------------------------------------------------------------  //  -------------------------------------------------------------------------
# Line 1153  void PamLevel2::SetWhichTrees(TString de Line 2823  void PamLevel2::SetWhichTrees(TString de
2823          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;
2824          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;
2825      };      };
2826    
2827        if( detlist.Contains("CAL0", TString::kIgnoreCase) ){
2828            if ( detlist.Contains("-CAL0", TString::kIgnoreCase) )CAL0=false;
2829            if ( detlist.Contains("+CAL0", TString::kIgnoreCase) )CAL0=true;
2830        };
2831                    
2832      if( detlist.Contains("CAL2", TString::kIgnoreCase)){      if( detlist.Contains("CAL2", TString::kIgnoreCase)){
2833          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;
# Line 1165  void PamLevel2::SetWhichTrees(TString de Line 2840  void PamLevel2::SetWhichTrees(TString de
2840          CAL1=false;          CAL1=false;
2841      }      }
2842  //  -------------------------------------------------------------------------  //  -------------------------------------------------------------------------
2843        if( detlist.Contains("TRK0", TString::kIgnoreCase) ){
2844            if ( detlist.Contains("-TRK0", TString::kIgnoreCase) )TRK0=false;
2845            if ( detlist.Contains("+TRK0", TString::kIgnoreCase) )TRK0=true;
2846        };
2847    
2848      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){
2849          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;
2850          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;
# Line 1193  void PamLevel2::SetWhichTrees(TString de Line 2873  void PamLevel2::SetWhichTrees(TString de
2873            
2874      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
2875      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
2876    
2877        if( detlist.Contains("-TOF0", TString::kIgnoreCase) )TOF0 = false;
2878        else if( detlist.Contains("+TOF0", TString::kIgnoreCase) )TOF0 = true;
2879            
2880      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;
2881      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;
# Line 1206  void PamLevel2::SetWhichTrees(TString de Line 2889  void PamLevel2::SetWhichTrees(TString de
2889      if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;      if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;
2890      else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;      else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;
2891    
2892      cout<< "Set detector list --> ";      if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false;
2893        else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true;
2894    
2895        cout<< "Set detector list from input --> ";
2896        if(TRK0)cout<<"TRK0 ";
2897      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
2898      if(TRK2)cout<<"TRK2 ";      if(TRK2)cout<<"TRK2 ";
2899      if(TRKh)cout<<"TRKH ";      if(TRKh)cout<<"TRKH ";
2900        if(CAL0)cout<<"CAL0 ";
2901      if(CAL1)cout<<"CAL1 ";      if(CAL1)cout<<"CAL1 ";
2902      if(CAL2)cout<<"CAL2 ";      if(CAL2)cout<<"CAL2 ";
2903      if(TOF)cout<<"TOF ";      if(TOF)cout<<"TOF ";
# Line 1218  void PamLevel2::SetWhichTrees(TString de Line 2906  void PamLevel2::SetWhichTrees(TString de
2906      if(ND)cout<<"ND ";      if(ND)cout<<"ND ";
2907      if(S4)cout<<"S4 ";      if(S4)cout<<"S4 ";
2908      if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
2909        if(GP)cout<<"GP ";
2910      cout << endl;      cout << endl;
2911    //     cout<< "Set detector list --> ";
2912    //     if(TRK1)cout<<"TRK1 ";
2913    //     if(TRK2)cout<<"TRK2 ";
2914    //     if(TRKh)cout<<"TRKH ";
2915    //     if(CAL1)cout<<"CAL1 ";
2916    //     if(CAL2)cout<<"CAL2 ";
2917    //     if(TOF0)cout<<"TOF0 ";
2918    //     if(TOF)cout<<"TOF ";
2919    //     if(TRG)cout<<"TRG ";
2920    //     if(AC)cout<<"AC ";
2921    //     if(ND)cout<<"ND ";
2922    //     if(S4)cout<<"S4 ";
2923    //     if(ORB)cout<<"ORB ";
2924    //     cout << endl;
2925            
2926  };  };
2927    
# Line 1227  void PamLevel2::SetWhichTrees(TString de Line 2930  void PamLevel2::SetWhichTrees(TString de
2930   * Set tree/branch detector flags from the content of a tree   * Set tree/branch detector flags from the content of a tree
2931   */   */
2932  void  PamLevel2::GetWhichTrees(TFile* f){  void  PamLevel2::GetWhichTrees(TFile* f){
2933                
2934    
2935    
2936    //    cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
2937      // -----------      // -----------
2938      // reset flags      // reset flags
2939      // -----------      // -----------
2940      Bool_t CAL1   = false;          CAL1   = false;    
2941      Bool_t CAL2   = false;          CAL2   = false;    
2942      Bool_t TRK2   = false;          TRK2   = false;    
2943      Bool_t TRK1   = false;          TRK1   = false;    
2944      Bool_t TRKh   = false;          TRKh   = false;    
2945      Bool_t TRG    = false;          TRG    = false;    
2946      Bool_t TOF    = false;          TOF    = false;    
2947      Bool_t S4     = false;          S4     = false;    
2948      Bool_t ND     = false;          ND     = false;    
2949      Bool_t AC     = false;          AC     = false;    
2950      Bool_t ORB    = false;          ORB    = false;    
2951        GP     = false;    
2952            
2953      Bool_t RUN    = false;      RUN    = false;
2954                    
2955      cout << "Checking file: "<<f->GetName()<<endl;      cout << "Checking file: "<<f->GetName()<<endl;
2956      if( !f || f->IsZombie() ){      if( !f || f->IsZombie() ){
# Line 1333  void  PamLevel2::GetWhichTrees(TFile* f) Line 3039  void  PamLevel2::GetWhichTrees(TFile* f)
3039                  TRK2 = false;                  TRK2 = false;
3040                  TRKh = false;                  TRKh = false;
3041              }else nev=nevt;              }else nev=nevt;
3042              T->Delete();  //          T->Delete();
3043          };          };
3044          //=========================================================            //=========================================================  
3045          if( !strcmp(key->GetName(),"Calorimeter"    ) ){          if( !strcmp(key->GetName(),"Calorimeter"    ) ){
# Line 1349  void  PamLevel2::GetWhichTrees(TFile* f) Line 3055  void  PamLevel2::GetWhichTrees(TFile* f)
3055                  CAL1 = false;                  CAL1 = false;
3056                  CAL2 = false;                  CAL2 = false;
3057              }else nev=nevt;              }else nev=nevt;
3058              T->Delete();  //          T->Delete();
3059          };                };      
3060            //=========================================================  
3061            if( !strcmp(key->GetName(),"h20") ){
3062                GP = true;
3063                Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();
3064                if( nev && nevt!=nev){
3065                    cout << "File: "<< f->GetName() <<" h20 tree has "<<nevt<<" events instead of "<<nev<< endl;
3066                    GP = false;
3067                }else nev=nevt;
3068            }
3069    
3070      };      };
3071            
3072      lk->Delete();  //    delete lk;
3073    
3074        cout<< "Get detector list from input file --> ";
3075        if(TRK1)cout<<"TRK1 ";
3076        if(TRK2)cout<<"TRK2 ";
3077        if(TRKh)cout<<"TRKH ";
3078        if(CAL1)cout<<"CAL1 ";
3079        if(CAL2)cout<<"CAL2 ";
3080        if(TOF)cout<<"TOF ";
3081        if(TRG)cout<<"TRG ";
3082        if(AC)cout<<"AC ";
3083        if(ND)cout<<"ND ";
3084        if(S4)cout<<"S4 ";
3085        if(ORB)cout<<"ORB ";
3086        if(GP)cout<<"GP ";
3087        cout << endl;
3088                
3089      return ;      return ;
3090                    
# Line 1383  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3113  Bool_t  PamLevel2::CheckLevel2File(TStri
3113      Bool_t ND__ok     = false;          Bool_t ND__ok     = false;    
3114      Bool_t AC__ok     = false;          Bool_t AC__ok     = false;    
3115      Bool_t ORB__ok    = false;          Bool_t ORB__ok    = false;    
3116        Bool_t GP__ok     = false;    
3117            
3118      Bool_t RUN__ok    = false;      Bool_t RUN__ok    = false;
3119            
3120            Bool_t SELLI__ok  = false;
3121    
3122      cout << "Checking file: "<<name<<endl;      cout << "Checking file: "<<name<<endl;
3123      TFile *f = new TFile(name.Data());      TFile *f = new TFile(name.Data());
# Line 1404  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3135  Bool_t  PamLevel2::CheckLevel2File(TStri
3135      while( (key = (TKey*)next()) ){      while( (key = (TKey*)next()) ){
3136                    
3137  //      cout << key->GetName() << endl;  //      cout << key->GetName() << endl;
3138  //      cout << " Get tree: " << f->Get(key->GetName())<<endl;  //      cout << key->GetName() << ""<<key->GetClassName()<<endl;
3139    //              cout << " Get tree: " << f->Get(key->GetName())<<endl;
3140  //      nev_previous = nev;  //      nev_previous = nev;
3141  //      cout << " n.entries  "<< nev <<endl;  //      cout << " n.entries  "<< nev <<endl;
3142  //      if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){  //      if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){
# Line 1413  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3145  Bool_t  PamLevel2::CheckLevel2File(TStri
3145  //          return false;  //          return false;
3146  //      };  //      };
3147    
3148            //=========================================================    
3149            // check if the file
3150            
3151    
3152          if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;                if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;      
3153    
3154          //=========================================================              //=========================================================    
3155            if( !strcmp(key->GetName(),"SelectionList"    ) ){
3156                SELLI__ok = true;
3157                if(SELLI==1){
3158                    Int_t nevt = ((TTree*)f->Get("SelectionList"))->GetEntries();
3159                    if( nev && nevt!=nev){
3160                        cout << "File: "<< f->GetName() <<" discarded ---- SelectionList tree has "<<nevt<<" events instead of "<<nev<< endl;
3161                        return false;
3162                    }
3163                    nev=nevt;
3164                }
3165            }
3166    
3167            //=========================================================    
3168          if( !strcmp(key->GetName(),"Trigger"    ) ){          if( !strcmp(key->GetName(),"Trigger"    ) ){
3169              TRG__ok = true;              TRG__ok = true;
3170              if(TRG){              if(TRG){
# Line 1525  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3274  Bool_t  PamLevel2::CheckLevel2File(TStri
3274              };                  };    
3275              T->Delete();              T->Delete();
3276          };                };      
3277            //=========================================================    
3278            if( !strcmp(key->GetName(),"h20") ){
3279                ISGP = true;    
3280                GP__ok = true;
3281                if(GP){
3282                    Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();
3283                    if( nev && nevt!=nev){
3284                        cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
3285                        return false;
3286                    }
3287                    nev=nevt;
3288                }
3289            }
3290    
3291      };      };
3292    
3293        if( SELLI==-1 )SELLI = (Int_t)SELLI__ok;
3294        if( SELLI==0 && SELLI__ok ){
3295            cout << "File: "<< f->GetName() <<" discarded ---- found SelectionList (it is not a full-event file)" << endl;
3296            return false;  
3297        }
3298        if( SELLI==1 && !SELLI__ok ){
3299            cout << "File: "<< f->GetName() <<" discarded ---- SelectionList missing" << endl;
3300            return false;
3301        }
3302            
3303    //    cout << "SELLI "<<SELLI<<endl;
3304    
3305    //     cout<< "CheckLevel2File(TString): detector list --> ";
3306    //     if(TRK1__ok)cout<<"TRK1 ";
3307    //     if(TRK2__ok)cout<<"TRK2 ";
3308    //     if(TRKh__ok)cout<<"TRKH ";
3309    //     if(CAL1__ok)cout<<"CAL1 ";
3310    //     if(CAL2__ok)cout<<"CAL2 ";
3311    //     if(TOF__ok)cout<<"TOF ";
3312    //     if(TRG__ok)cout<<"TRG ";
3313    //     if(AC__ok)cout<<"AC ";
3314    //     if(ND__ok)cout<<"ND ";
3315    //     if(S4__ok)cout<<"S4 ";
3316    //     if(ORB__ok)cout<<"ORB ";
3317    //     cout << endl;
3318    
3319    
3320        if(TRK2 && TRK1__ok)TRK1=1;
3321    // ----------------------------------------------------------------------------
3322    // NOTA
3323    // se c'e` il level1, lo devo necessarimente leggere.
3324    // infatti (non ho capito perche`) i cluster vengono letti e allocati in memoria
3325    // comunque, ma non vengono disallocati da PamLevel2::Clear()
3326    // ----------------------------------------------------------------------------
3327    
3328    
3329      if(!RUN__ok) {      if(!RUN__ok) {
# Line 1572  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3368  Bool_t  PamLevel2::CheckLevel2File(TStri
3368          return false;          return false;
3369      };      };
3370    
3371          if(ND && !ND__ok){      if(ND && !ND__ok){
3372              cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl;          cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl;
3373              return false;          return false;
3374          };      };
3375          if(TRG && !TRG__ok){      if(TRG && !TRG__ok){
3376              cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;          cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;
3377              return false;          return false;
3378          };      };
3379        if(GP && !GP__ok){
3380            cout << "File: "<< f->GetName() <<" discarded ---- Missing h20 tree"<< endl;
3381            return false;
3382        };
3383        
3384    
3385      lk->Delete();  //    lk->Delete();
3386    //    delete lk;
3387      f->Close();      f->Close();
3388    
3389    //     cout<< "CheckLevel2File(TString): detector list --> ";
3390    //     if(TRK1)cout<<"TRK1 ";
3391    //     if(TRK2)cout<<"TRK2 ";
3392    //     if(TRKh)cout<<"TRKH ";
3393    //     if(CAL1)cout<<"CAL1 ";
3394    //     if(CAL2)cout<<"CAL2 ";
3395    //     if(TOF)cout<<"TOF ";
3396    //     if(TRG)cout<<"TRG ";
3397    //     if(AC)cout<<"AC ";
3398    //     if(ND)cout<<"ND ";
3399    //     if(S4)cout<<"S4 ";
3400    //     if(ORB)cout<<"ORB ";
3401    //     if(GP)cout<<"GP ";
3402    //     cout << endl;
3403                
3404      return true;      return true;
3405                    
# Line 1602  void PamLevel2::CreateCloneTrees0( TChai Line 3415  void PamLevel2::CreateCloneTrees0( TChai
3415      cout << "Create clones of PAMELA trees "<<endl;      cout << "Create clones of PAMELA trees "<<endl;
3416            
3417      Int_t i=0;      Int_t i=0;
3418      tree_clone[i] = fChain->GetTree()->CloneTree(0);      pam_tree_clone[i] = fChain->GetTree()->CloneTree(0);
3419      TString name =  tree_clone[i]->GetName();      TString name =  pam_tree_clone[i]->GetName();
3420      name.Append("_clone");      name.Append("_clone");
3421  //    tree_clone[i]->SetName(name.Data());  //    pam_tree_clone[i]->SetName(name.Data());
3422      cout << tree_clone[i]->GetName() <<endl;      cout << pam_tree_clone[i]->GetName() <<endl;
3423      i++;      i++;
3424    
3425      TList *li = fChain->GetListOfFriends();      TList *li = fChain->GetListOfFriends();
# Line 1616  void PamLevel2::CreateCloneTrees0( TChai Line 3429  void PamLevel2::CreateCloneTrees0( TChai
3429      while( (T_friend = (TFriendElement*)next()) ){      while( (T_friend = (TFriendElement*)next()) ){
3430  //      cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;  //      cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;
3431  //      cout<<T_friend->GetTree()->GetName()<< endl;  //      cout<<T_friend->GetTree()->GetName()<< endl;
3432          tree_clone[i] = T_friend->GetTree()->CloneTree(0);          pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0);
3433          tree_clone[i]->SetAutoSave(1000000);          pam_tree_clone[i]->SetAutoSave(1000000);
3434          name =  tree_clone[i]->GetName();          name =  pam_tree_clone[i]->GetName();
3435          name.Append("_clone");          name.Append("_clone");
3436  //      tree_clone[i]->SetName(name.Data());  //      pam_tree_clone[i]->SetName(name.Data());
3437          cout << tree_clone[i]->GetName() << endl;          cout << pam_tree_clone[i]->GetName() << endl;
3438          i++;          i++;
3439      }      }
3440        
3441        delete li;
3442    
3443      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3444    
# Line 1634  void PamLevel2::CreateCloneTrees0( TChai Line 3449  void PamLevel2::CreateCloneTrees0( TChai
3449   */   */
3450  void PamLevel2::CreateCloneTrees(TFile *ofile){  void PamLevel2::CreateCloneTrees(TFile *ofile){
3451    
3452    
3453    //  if the pointer is null, create a default file
3454    
3455        if(!ofile){
3456            cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;
3457            ofile = new TFile("clone-tree.root","recreate");
3458        }
3459    
3460      ofile->cd();      ofile->cd();
3461    
3462      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3463      cout << "Create new PAMELA trees "<<endl;      cout << "Create new PAMELA trees "<<endl;
3464                    
     Int_t i=0;  
3465    
3466        run_tree_clone = new TTree("Run","PAMELA Level2 data from the GL_RUN table ");
3467        run_tree_clone->Branch("RunInfo","GL_RUN",GetPointerTo("RunInfo"));
3468        cout << "Run          : branch RunInfo"<<endl;
3469        run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));
3470        cout << "Run          : branch SoftInfo"<<endl;
3471        // ------------------
3472        // replicate run tree
3473        // ------------------
3474        cout << "----------------------------------------------------"<<endl;
3475        cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
3476        for (Int_t i=0; i<run_tree->GetEntries(); i++){
3477            run_tree->GetEntry(i);
3478            cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;
3479            run_tree_clone->Fill();
3480        }
3481        cout << "----------------------------------------------------"<<endl;
3482    
3483        // ------------------------------------
3484        // add branch with dead and live times
3485        // ------------------------------------
3486        run_tree_clone->Branch("DeadLiveTime",totdltime,"dltime[3]/l");
3487        cout << "Run          : branch DeadLiveTime"<<endl;
3488    
3489    
3490        sel_tree_clone = new TTree("SelectionList","List of selected events ");
3491        sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
3492        sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");
3493        
3494    
3495        Int_t i=0;
3496      if(TRK1||TRK2||TRKh){      if(TRK1||TRK2||TRKh){
3497          tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");              pam_tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");
3498          if(TRK1) {          if(TRK1) {
3499              tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));              pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
3500              tree_clone[i]->BranchRef();              pam_tree_clone[i]->BranchRef();
3501              cout << "Tracker      : branch TrkLevel1"<<endl;              cout << "Tracker      : branch TrkLevel1"<<endl;
3502    //          cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;
3503          };          };
3504          if(TRK2) {          if(TRK2) {
3505              tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));              pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
3506              cout << "Tracker      : branch TrkLevel2"<<endl;                      cout << "Tracker      : branch TrkLevel2"<<endl;        
3507          };          };
3508          if(TRKh) {          if(TRKh) {
3509              tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));              pam_tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));
3510              cout << "Tracker      : branch TrkHough"<<endl;              cout << "Tracker      : branch TrkHough"<<endl;
3511          };          };
3512          i++;          i++;
# Line 1661  void PamLevel2::CreateCloneTrees(TFile * Line 3514  void PamLevel2::CreateCloneTrees(TFile *
3514    
3515      // Calorimeter      // Calorimeter
3516      if(CAL1||CAL2){      if(CAL1||CAL2){
3517          tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");              pam_tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");
3518          if(CAL1) {          if(CAL1) {
3519              tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));              pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
3520              cout << "Calorimeter  : branch CaloLevel1"<<endl;              cout << "Calorimeter  : branch CaloLevel1"<<endl;
3521          };          };
3522          if(CAL2) {          if(CAL2) {
3523              tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));              pam_tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));
3524              cout << "Calorimeter  : branch CaloLevel2"<<endl;              cout << "Calorimeter  : branch CaloLevel2"<<endl;
3525          };          };
3526          i++;          i++;
# Line 1675  void PamLevel2::CreateCloneTrees(TFile * Line 3528  void PamLevel2::CreateCloneTrees(TFile *
3528    
3529      // ToF          // ToF    
3530      if(TOF) {      if(TOF) {
3531          tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");              pam_tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");
3532          tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));          pam_tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));
3533          cout << "ToF          : branch ToFLevel2"<<endl;          cout << "ToF          : branch ToFLevel2"<<endl;
3534          i++;          i++;
3535      };      };
3536      // Trigger      // Trigger
3537      if(TRG) {      if(TRG) {
3538          tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");              pam_tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");
3539          tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));          pam_tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));
3540          cout << "Trigger      : branch TrigLevel2"<<endl;          cout << "Trigger      : branch TrigLevel2"<<endl;
3541          i++;          i++;
3542      };      };
3543      // S4      // S4
3544      if(S4) {      if(S4) {
3545          tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");                pam_tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");  
3546          tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));          pam_tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));
3547          cout << "S4           : branch S4Level2"<<endl;          cout << "S4           : branch S4Level2"<<endl;
3548          i++;          i++;
3549      };      };
3550      // Neutron Detector      // Neutron Detector
3551      if(ND) {      if(ND) {
3552          tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");            pam_tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");      
3553          tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));          pam_tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));
3554          cout << "NeutronD     : branch NDLevel2"<<endl;          cout << "NeutronD     : branch NDLevel2"<<endl;
3555          i++;          i++;
3556      };      };
3557      // Anticounters      // Anticounters
3558      if(AC) {      if(AC) {
3559          tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");              pam_tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");        
3560          tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));          pam_tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));
3561          cout << "Anticounter  : branch AcLevel2"<<endl;          cout << "Anticounter  : branch AcLevel2"<<endl;
3562          i++;          i++;
3563      };      };
3564      // OrbitalInfo      // OrbitalInfo
3565      if(ORB) {      if(ORB) {
3566          tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");                pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");  
3567          tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));          pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));
3568            cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
3569            i++;
3570        };
3571        // GPamela
3572        if(GP) {
3573            pam_tree_clone[i] = new TTree("h20","PAMELA oribital info  ");  
3574            pam_tree_clone[i]->Branch("GPamela","GPamela", GetPointerTo("GPamela"),32000,1);//split
3575          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
3576          i++;          i++;
3577      };      };
# Line 1719  void PamLevel2::CreateCloneTrees(TFile * Line 3579  void PamLevel2::CreateCloneTrees(TFile *
3579    
3580  }  }
3581    
 // /**  
 //  * Create clone-trees  
 //  */  
 // void PamLevel2::CreateCloneTrees(){  
   
 //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
 //     cout << "Create new PAMELA trees "<<endl;  
           
 //     if(TRK1||TRK2||TRKh){  
 //      T_clone = new TTree("Tracker_clone","PAMELA tracker level2 data ");      
 //      if(TRK1) {  
 //          trk1_clone = new TrkLevel1();  
 //          T_clone->Branch("TrkLevel1","TrkLevel1", &trk1_clone);  
 //          T_clone->BranchRef();  
 //          cout << "Tracker      : branch TrkLevel1"<<endl;  
 //      };  
 //      if(TRK2) {  
 //          trk2_clone = new TrkLevel2();  
 //          T_clone->Branch("TrkLevel2", "TrkLevel2",&trk2_clone);  
 //          cout << "Tracker      : branch TrkLevel2"<<endl;          
 //      };  
 //      if(TRKh) {  
 //          trkh_clone = new TrkHough();  
 //          T_clone->Branch("TrkHough","TrkHough", &trkh_clone);  
 //          cout << "Tracker      : branch TrkHough"<<endl;  
 //      };  
 //      cout << hex << T_clone << dec << endl;  
 //     }  
   
 //     // Calorimeter  
 //     if(CAL1||CAL2){  
 //      C_clone = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");      
 //      if(CAL1) {  
 //          calo1_clone = new CaloLevel1();  
 //          C_clone->Branch("CaloLevel1", "CaloLevel1", &calo1_clone);  
 //          cout << "Calorimeter  : branch CaloLevel1"<<endl;  
 //      };  
 //      if(CAL2) {  
 //          calo2_clone = new CaloLevel2();  
 //          C_clone->Branch("CaloLevel2","CaloLevel2", &calo2_clone);  
 //          cout << "Calorimeter  : branch CaloLevel2"<<endl;  
 //      };  
 //     }      
   
 //     // ToF      
 //     if(TOF) {  
 //      O_clone = new TTree("ToF_clone","PAMELA ToF level2 data ");      
 //      tof_clone = new ToFLevel2();  
 //      O_clone->Branch("ToFLevel2","ToFLevel2", &tof_clone);  
 //      cout << "ToF          : branch ToFLevel2"<<endl;  
 //     };  
 //     // Trigger  
 //     if(TRG) {  
 //      R_clone = new TTree("Trigger_clone","PAMELA trigger level2 data ");      
 //      trig_clone = new TrigLevel2();  
 //      R_clone->Branch("TrigLevel2","TrigLevel2", &trig_clone);  
 //      cout << "Trigger      : branch TrigLevel2"<<endl;  
 //     };  
 //     // S4  
 //     if(S4) {  
 //      S_clone = new TTree("S4_clone","PAMELA S4 level2 data ");        
 //      s4_clone = new S4Level2();  
 //      S_clone->Branch("S4Level2","S4Level2", &s4_clone);  
 //      cout << "S4           : branch S4Level2"<<endl;  
 //     };  
 //     // Neutron Detector  
 //     if(ND) {  
 //      N_clone = new TTree("NeutronD_clone","PAMELA neutron detector level2 data ");    
 //      nd_clone = new NDLevel2();  
 //      N_clone->Branch("NDLevel2","NDLevel2", &nd_clone);  
 //      cout << "NeutronD     : branch NDLevel2"<<endl;  
 //     };  
 //     // Anticounters  
 //     if(AC) {  
 //      A_clone = new TTree("Anticounter_clone","PAMELA anticounter detector level2 data ");      
 //      ac_clone = new AcLevel2();  
 //      A_clone->Branch("AcLevel2","AcLevel2", &ac_clone);  
 //      cout << "Anticounter  : branch AcLevel2"<<endl;  
 //     };  
 //     // OrbitalInfo  
 //     if(ORB) {  
 //      B_clone = new TTree("OrbitalInfo_clone","PAMELA oribital info  ");        
 //      orb_clone = new OrbitalInfo();  
 //      B_clone->Branch("OrbitalInfo","OrbitalInfo", &orb_clone);  
 //      cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;  
 //     };  
 //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
   
 // }  
3582    
3583  /**  /**
3584   * Fill tree (created with CreateCloneTrees)   * Fill tree (created with CreateCloneTrees)
# Line 1815  void PamLevel2::CreateCloneTrees(TFile * Line 3586  void PamLevel2::CreateCloneTrees(TFile *
3586   */   */
3587  //void PamLevel2::FillNewPamTree(TTree *T){  //void PamLevel2::FillNewPamTree(TTree *T){
3588  void PamLevel2::FillCloneTrees(){  void PamLevel2::FillCloneTrees(){
3589                
3590  // //  --------------------------------------  //    cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;
 // //  copy the event  
 // //  --------------------------------------  
 //     if(trk1_clone)  *trk1_clone = *trk1_obj;  
 //     if(trk2_clone){  
 //      trk2_clone->Clear();  
 //      trk2_obj->Copy(*trk2_clone);  
 // //   *trk2_clone = *trk2_obj;  
 //     }  
 //     if(trkh_clone)  *trkh_clone = *trkh_obj;  
 //     if(calo1_clone){  
 // //   *calo1_clone = *calo1_obj;  
 //      calo1_clone->Clear();  
 //      calo1_obj->Copy(*calo1_clone);  
 //     }  
 //     if(calo2_clone){  
 // //   *calo2_clone = *calo2_obj;  
 //      calo2_clone->Clear();  
 //      calo2_obj->Copy(*calo2_clone);  
 //     }  
 //     if(tof_clone)   *tof_clone  = *tof_obj;  
 //     if(trig_clone)  *trig_clone = *trig_obj;  
 //     if(s4_clone)    *s4_clone   = *s4_obj;  
 //     if(nd_clone)    *nd_clone   = *nd_obj;  
 //     if(ac_clone)    *ac_clone   = *ac_obj;  
 //     if(orb_clone)   *orb_clone  = *orb_obj;  
   
 //     if(T_clone)T_clone->Fill();  
 //     if(C_clone)C_clone->Fill();  
 //     if(O_clone)O_clone->Fill();  
 //     if(R_clone)R_clone->Fill();  
 //     if(S_clone)S_clone->Fill();  
 //     if(N_clone)N_clone->Fill();  
 //     if(A_clone)A_clone->Fill();  
 //     if(O_clone)O_clone->Fill();  
3591    
3592      for(Int_t i=0; i<8; i++){      for(Int_t i=0; i<NCLONES; i++){
3593          if(tree_clone[i])tree_clone[i]->Fill();          if(pam_tree_clone[i])pam_tree_clone[i]->Fill();
3594      }      }
3595        if(sel_tree_clone)sel_tree_clone->Fill();    
3596    
3597  }  }
3598    
3599    
3600  TTree* PamLevel2::GetCloneTree(TString name){  TTree* PamLevel2::GetCloneTree(TString name){
3601    
3602      for(Int_t i=0; i<8; i++){        for(Int_t i=0; i<NCLONES; i++){    
3603          if(tree_clone[i]){          if(pam_tree_clone[i]){
3604              TString na = tree_clone[i]->GetName();              TString na = pam_tree_clone[i]->GetName();
3605              if(!name.CompareTo(na))return tree_clone[i];              if(!name.CompareTo(na))return pam_tree_clone[i];
3606          };          };
3607      }      }
3608        if(run_tree_clone){
3609            TString na = run_tree_clone->GetName();
3610            if(!name.CompareTo(na))return run_tree_clone;
3611        }
3612        if(sel_tree_clone){
3613            TString na = sel_tree_clone->GetName();
3614            if(!name.CompareTo(na))return sel_tree_clone;
3615        }
3616      return NULL;      return NULL;
3617    
3618  }  }
3619  void PamLevel2::WriteCloneTrees(){  void PamLevel2::WriteCloneTrees(){
3620      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3621      cout << "Write clones of PAMELA trees "<<endl;      cout << "Write clones of PAMELA trees "<<endl;
3622      for(Int_t i=0; i<8; i++){        cout << run_tree_clone->GetName()<<endl;  
3623          if(tree_clone[i]){      if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
3624              cout << tree_clone[i]->GetName()<<endl;          run_tree_clone->GetBranch("DeadLiveTime")->Fill();
3625              tree_clone[i]->Write();      run_tree_clone->Write();
3626        cout << sel_tree_clone->GetName()<<endl;    
3627        sel_tree_clone->Write();
3628        for(Int_t i=0; i<NCLONES; i++){    
3629            if(pam_tree_clone[i]){
3630                cout << pam_tree_clone[i]->GetName()<<endl;
3631                pam_tree_clone[i]->Write();
3632          };          };
3633      }      }
3634      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
# Line 1883  void PamLevel2::WriteCloneTrees(){ Line 3636  void PamLevel2::WriteCloneTrees(){
3636  }  }
3637    
3638  /**  /**
3639   * Create a new (empty) Pamela trees   * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.
3640     */
3641    //Int_t PamLevel2::GetEntry(Int_t iee){
3642    Int_t PamLevel2::GetEntry(Long64_t iee){
3643        
3644    //     cout << "-------------------------------------"<<endl;
3645    //     cout << "Int_t PamLevel2::GetEntry("<<iee<<")"<<endl;
3646    
3647        if(!pam_tree){
3648            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded"<<endl;
3649            return 0;
3650        }
3651    
3652    
3653        //
3654        // This is a sort of bug: if you don't have the run tree you don't want to exit here you want to have loaded the event anyway...
3655        //
3656        //    if(!run_tree ){
3657        //  cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl;
3658        //  return 0;
3659        //    }
3660    
3661        Long64_t ii=0;
3662        //-------------------------------
3663        ii = iee;
3664        if( !pam_tree->GetEntry(ii) ){      
3665            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<<endl;
3666            return 0;
3667        }
3668    
3669    //    cout << " gp_obj->P0 "<<gp_obj->P0<<endl;
3670        //
3671        // ... that's way I put it here. Notice that nothing change in the code (is backward compatible) since in any case you return with 0.
3672        // in theory one would like to return 1 if run is not loaded but now I don't have the will to add that 2 lines of code and it is not
3673        // a problem if you don't check the return code of getentry.
3674        //
3675        if(!run_tree ){
3676            if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?
3677                cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
3678                return 0;
3679            }  else {
3680                return 1; //cosi` se non c'e` run esce qua...
3681            }
3682        }
3683    
3684        //-------------------------------
3685        ii = iee;
3686    //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
3687    //    Bool_t UPDATED = UpdateRunInfo(ii);
3688        UpdateRunInfo(ii);
3689        if(SELLI==0)irunentry = iee-runfirstentry;
3690    //    if(UPDATED && run_tree_clone)run_tree_clone->Fill();
3691      
3692    //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
3693    
3694    //     cout << "irunentry     "<<irunentry << endl;
3695    //     cout << "runfirstentry "<<runfirstentry << endl;
3696    //     cout << "nevents       "<<GetRunInfo()->NEVENTS<< endl;
3697    
3698    //     if( TRK0 || CAL0 || TOF0 ){
3699    //      if( !GetYodaEntry( ) ){
3700    //          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl;
3701    //          return 0;
3702    //      }
3703    //     }
3704    
3705    
3706        return 1;
3707    
3708    }
3709    
3710    TrkLevel0    *PamLevel2::GetTrkLevel0(){
3711        if( !TRK0 )return NULL;
3712        if( !GetYodaEntry( ) ){
3713            cout << " Int_t PamLevel2::GetTrkLevel0() -- ERROR -- error reading level0 tree"<<endl;
3714            return 0;
3715        }
3716        return trk0_obj;
3717    };
3718    CaloLevel0    *PamLevel2::GetCaloLevel0(){
3719        if( !CAL0 )return NULL;
3720        if( !GetYodaEntry( ) ){
3721            cout << " Int_t PamLevel2::GetCaloLevel0() -- ERROR -- error reading level0 tree"<<endl;
3722            return 0;
3723        }
3724        return calo0_obj;
3725    };
3726    
3727    
3728    /**
3729     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
3730     * Given the run ID (...), if needed it query the DB and load the proper file.
3731     * @return Pointer to the tree
3732   */   */
 // TTree* PamLevel2::GetNewPamTree(){  
3733    
 //     if(tree_clone)return tree_clone;  
3734    
3735  //     TTree *Tout = 0;  TTree* PamLevel2::GetYodaTree( ){
3736        
3737    //    cout << "TTree* PamLevel2::GetYodaTree( )"<<endl;
3738        //===================================
3739        // check if iroot has changed
3740        //===================================
3741        if( irun<0 ){
3742            cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = "<<irun<<endl;
3743    //      cout << "In order to use this method you have to first load the RunInfo tree "<<endl;
3744            return NULL;
3745        }    
3746        Int_t irootnew = run_obj->ID_ROOT_L0;
3747    //      cout << "iroot    "<<iroot<<endl;
3748    //      cout << "irootnew "<<irootnew<<endl;
3749    
3750        //===================================
3751        // load the level0 file
3752        // (if not already loaded)
3753        //===================================
3754        if( iroot != irootnew || !l0_tree){
3755            iroot = irootnew;
3756            //===================================
3757            // open the DB connection
3758            // (if not already opened)
3759            //===================================
3760            if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
3761            GL_ROOT glroot = GL_ROOT();
3762            if( glroot.Query_GL_ROOT(iroot,dbc) ){
3763                cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;
3764                return NULL;
3765            };
3766            TString filename = glroot.PATH + glroot.NAME;
3767            if(l0_file){
3768                l0_file->Close();
3769                l0_file->Delete();
3770            }
3771            cout << "Opening LEVEL0 file: "<< filename << endl;
3772            FileStat_t t;
3773            if( gSystem->GetPathInfo(filename.Data(),t) ){
3774                cout << " PamLevel2::GetYodaTree() -- ERROR opening file "<<endl;
3775                return NULL;
3776            }
3777            l0_file = new TFile(filename);
3778            if( !l0_file )return NULL;
3779            l0_tree = (TTree*)l0_file->Get("Physics");
3780            if(!h0_obj)h0_obj = new EventHeader();
3781            l0_tree->SetBranchAddress("Header" ,&h0_obj);
3782            prevshift = 0;
3783            //---------------------------------------------------
3784            // TRACKER:
3785            if(TRK0){
3786                if(!trk0_obj){
3787                    trk0_obj = new TrkLevel0();
3788                    trk0_obj->Set();
3789                };
3790                l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());
3791            }
3792            //--------------------------------------------------
3793            // CALORIMETER:
3794            if(CAL0){
3795                if(!calo0_obj){
3796                    calo0_obj = new CaloLevel0();
3797                    calo0_obj->Set();
3798                };
3799                l0_tree->SetBranchAddress("Calorimeter" ,calo0_obj->GetPointerToCalorimeterEvent());
3800                //      cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;
3801            }
3802            //---------------------------------------------------
3803            // TOF:
3804            if(TOF0){
3805                cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
3806            }
3807    
3808    //      dbc->Close();
3809    
3810    
3811        };
3812    
3813    //     if(!dbc || (dbc && !dbc->IsConnected())){
3814    //      cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;
3815    //     }
3816    
3817        if ( TRK0 ){
3818            TrkParams::Load(6);
3819            if( !TrkParams::IsLoaded(6) ){
3820                cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;
3821            };
3822            if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
3823            TrkParams::SetCalib(run_obj,dbc);
3824            TrkParams::LoadCalib( );
3825            if( !TrkParams::CalibIsLoaded() ){
3826                cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;
3827            };
3828        }
3829    
3830    
3831    //    cout << l0_tree << endl;
3832        return l0_tree;
3833    
3834    }
3835    
3836    /**
3837     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
3838     */
3839    Int_t PamLevel2::GetYodaEntry(){
3840    
3841    //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;
3842        if(!GetYodaTree())return 0;
3843            
3844  //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      // patch
3845  //     cout << "Create new PAMELA trees "<<endl;      if( irunentry < 0){
3846    //      cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
3847            irunentry=0LL;
3848        }
3849        //  ---------------------------------
3850        //  if file is NOT a preselected file
3851        //  ---------------------------------
3852        Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM);
3853    //     cout << " irunentry "<<irunentry<<endl;
3854    //     cout << " EV_FROM "<<run_obj->EV_FROM<<endl;
3855    //     cout << " quellagiusta = irunentry + EV_FROM "<< quellagiusta << endl;
3856    
3857    //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
3858    //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
3859    //     cout << " time "<< abstime << endl;
3860    //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;
3861        
3862        ULong64_t obt     = 0;
3863        ULong64_t pktn    = 0;
3864        if( GetOrbitalInfo() ){
3865            obt     = GetOrbitalInfo()->OBT;
3866            pktn    = GetOrbitalInfo()->pkt_num;
3867        }
3868    
3869        if( !GetOrbitalInfo() && !ISGP){
3870            cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;
3871            return 0;
3872        }
3873        if( obt==0 && pktn==0 && !ISGP ){
3874            cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl;
3875            return 0;
3876        }
3877    
3878        // ---------------------------------------------------------------------
3879        // ATTENTION!!!
3880        // If data are not pre-processed with cleaner, the level0 tree may contain
3881        // spurious nested physics packets.
3882        // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries
3883        // while level2 tree DOES NOT!!
3884        // This means that "quellagiusta" in these cases is not correct.
3885        // In order to retrieve the correct level0 event, I implemented a check
3886        // of the OBT and pkt-number. In case of mismatch, the level0 entry number
3887        // is shift forward until when the packets match.
3888        // ---------------------------------------------------------------------
3889        Int_t answer = 0;
3890        Int_t shift =0;
3891        //    printf(" siamo qui %i %i \n",shift,prevshift);
3892        //    Int_t maxshift = 50; // EMILIANO
3893        do{
3894            if(shift>0){    
3895                cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
3896                cout << "         RUN: ID "<< GetRunInfo()->ID << " ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<" ID_RUN_FRAG "<<GetRunInfo()->ID_RUN_FRAG << " EV_FROM "<<GetRunInfo()->EV_FROM  <<endl;
3897                cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;
3898            }
3899            answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);
3900            shift++;
3901            if( !GetEventHeader() ){
3902                cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;
3903                return 0;
3904            }
3905    
3906            if(ISGP){
3907                obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO
3908                pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO
3909            }
3910    
3911    //      cout << "PKTNUM "<<shift<<" ==  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
3912    //      cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;
3913    //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;
3914    //      cout << " obt "<< obt << endl;
3915    //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;
3916    //      cout << " pktn "<< pktn << endl;
3917    //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
3918    //      printf(" IDRUN %u \n",GetRunInfo()->ID);
3919    //
3920            if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){
3921              prevshift = 0;
3922              shift = -1;
3923            };
3924    
3925        }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||
3926                  pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())       )
3927                && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);
3928    
3929        if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {
3930            cout << " Big trouble here, no such event in Level0 data! " <<endl;
3931            return 0;
3932        }
3933    //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
3934    //    return GetYodaTree()->GetEntry(quellagiusta);
3935        if ( shift > 1 ) prevshift += (shift-1);
3936            
3937        return answer;
3938            
3939  //     if(TRK1||TRK2||TRKh){  }
3940  //      TTree *T = new TTree("Tracker_clone","PAMELA tracker level2 data ");      /**
3941  //      if(TRK1) {   * \Brief Set DB connection
3942  //          trk1_clone = new TrkLevel1();   */
3943  //          T->Branch("TrkLevel1","TrkLevel1", &trk1_clone);  Bool_t PamLevel2::SetDBConnection(){
 //          T->BranchRef();  
 //          cout << "Tracker      : branch TrkLevel1"<<endl;  
 //      };  
 //      if(TRK2) {  
 //          trk2_clone = new TrkLevel2();  
 //          T->Branch("TrkLevel2", "TrkLevel2",&trk2_clone);  
 //          cout << "Tracker      : branch TrkLevel2"<<endl;          
 //      };  
 //      if(TRKh) {  
 //          trkh_clone = new TrkHough();  
 //          T->Branch("TrkHough","TrkHough", &trkh_clone);  
 //          cout << "Tracker      : branch TrkHough"<<endl;  
 //      };  
 //      if(!Tout)Tout=T;  
 //      else Tout->AddFriend("Tracker_clone");  
 //     }  
3944    
3945  //     // Calorimeter      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3946  //     if(CAL1||CAL2){      cout<<"Connecting to DB"<<endl;
3947  //      TTree *C = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");          cout<<"HOST "<<host<<endl;
3948  //      if(CAL1) {      cout<<"USER "<<user<<endl;
3949  //          calo1_clone = new CaloLevel1();      cout<<"PSW  "<<psw<<endl;
3950  //          C->Branch("CaloLevel1", "CaloLevel1", &calo1_clone);      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
3951  //          cout << "Calorimeter  : branch CaloLevel1"<<endl;      if( !dbc )return false;
3952  //      };      if( !dbc->IsConnected() )return false;    
3953  //      if(CAL2) {      stringstream myquery;  // EMILIANO
3954  //          calo2_clone = new CaloLevel2();      myquery.str("");  // EMILIANO
3955  //          C->Branch("CaloLevel2","CaloLevel2", &calo2_clone);      myquery << "SET time_zone='+0:00'";  // EMILIANO
3956  //          cout << "Calorimeter  : branch CaloLevel2"<<endl;      dbc->Query(myquery.str().c_str());  // EMILIANO
3957  //      };      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3958  //      if(!Tout)Tout=C;      return true;
 //      else Tout->AddFriend("Calorimeter_clone");  
 //     }      
   
 //     // ToF      
 //     if(TOF) {  
 //      TTree *O = new TTree("ToF_clone","PAMELA ToF level2 data ");      
 //      tof_clone = new ToFLevel2();  
 //      O->Branch("ToFLevel2","ToFLevel2", &tof_clone);  
 //      cout << "ToF          : branch ToFLevel2"<<endl;  
 //      if(!Tout)Tout=O;  
 //      else Tout->AddFriend("ToF_clone");  
 //     };  
 //     // Trigger  
 //     if(TRG) {  
 //      TTree *R = new TTree("Trigger_clone","PAMELA trigger level2 data ");      
 //      trig_clone = new TrigLevel2();  
 //      R->Branch("TrigLevel2","TrigLevel2", &trig_clone);  
 //      cout << "Trigger      : branch TrigLevel2"<<endl;  
 //      if(!Tout)Tout=R;  
 //      else Tout->AddFriend("Trigger_clone");  
 //     };  
 //     // S4  
 //     if(S4) {  
 //      TTree *S = new TTree("S4_clone","PAMELA S4 level2 data ");        
 //      s4_clone = new S4Level2();  
 //      S->Branch("S4Level2","S4Level2", &s4_clone);  
 //      cout << "S4           : branch S4Level2"<<endl;  
 //      if(!Tout)Tout=S;  
 //      else Tout->AddFriend("S4_clone");  
 //     };  
 //     // Neutron Detector  
 //     if(ND) {  
 //      TTree *N = new TTree("NeutronD_clone","PAMELA neutron detector level2 data ");    
 //      nd_clone = new NDLevel2();  
 //      N->Branch("NDLevel2","NDLevel2", &nd_clone);  
 //      cout << "NeutronD     : branch NDLevel2"<<endl;  
 //      if(!Tout)Tout=N;  
 //      else Tout->AddFriend("NeutronD_clone");  
 //     };  
 //     // Anticounters  
 //     if(AC) {  
 //      TTree *A = new TTree("Anticounter_clone","PAMELA anticounter detector level2 data ");    
 //      ac_clone = new AcLevel2();  
 //      A->Branch("AcLevel2","AcLevel2", &ac_clone);  
 //      cout << "Anticounter  : branch AcLevel2"<<endl;  
 //      if(!Tout)Tout=A;  
 //      else Tout->AddFriend("Anticounter_clone");  
 //     };  
 //     // OrbitalInfo  
 //     if(ORB) {  
 //      TTree *B = new TTree("OrbitalInfo_clone","PAMELA oribital info  ");      
 //      orb_clone = new OrbitalInfo();  
 //      B->Branch("OrbitalInfo","OrbitalInfo", &orb_clone);  
 //      cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;  
 //      if(!Tout)Tout=B;  
 //      else Tout->AddFriend("OrbitalInfo_clone");  
 //     };  
 //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
3959    
3960  //     tree_clone = Tout;  }
 //     tree_clone->SetDirectory(0);  
3961    
3962  //     return Tout;  /**
3963  // }   * \Brief Add a friend to the pamela chain.
3964  // /**   * @param cname name of the chain to be added
3965  //  * Fill a tree (created with GetNewPamTree)   */
3966  //  *  
3967  //  */  TChain* PamLevel2::AddFriend(TString cname){
3968  // //void PamLevel2::FillNewPamTree(TTree *T){  
3969  // void PamLevel2::FillNewPamTree(){      if(!GetPamTree()){
3970                    cout << " TChain* PamLevel2::AddFriend(TString cname) --- a pamela tree must be created first"<<endl;
3971            return NULL;
3972        }
3973    
3974    
3975        TChain *c = new TChain( cname.Data() );
3976    
3977        TIter next( GetPamTree()->GetListOfFiles() );
3978        Int_t nf = 0;
3979        TChainElement* element = 0;    
3980        while ((element = (TChainElement*) next())) {      
3981            c->Add(element->GetTitle());
3982            nf++;
3983        }
3984    
3985        GetPamTree()->AddFriend(cname.Data());
3986    
3987        cout << "external chain created and added to pamela friends :"<<cname<<endl;
3988        cout << "n.files "<<nf<<endl;
3989        
3990    
3991        return c;    
3992    
3993    }
3994    
 //     if(trk1_clone)  *trk1_clone = *trk1_obj;  
 //     if(trk2_clone){  
 //      trk2_clone->Clear();  
 //      trk2_obj->Copy(*trk2_clone);  
 // //   *trk2_clone = *trk2_obj;  
 //     }  
 //     if(trkh_clone)  *trkh_clone = *trkh_obj;  
 //     if(calo1_clone){  
 // //   *calo1_clone = *calo1_obj;  
 //      calo1_clone->Clear();  
 //      calo1_obj->Copy(*calo1_clone);  
 //     }  
 //     if(calo2_clone){  
 // //   *calo2_clone = *calo2_obj;  
 //      calo2_clone->Clear();  
 //      calo2_obj->Copy(*calo2_clone);  
 //     }  
 //     if(tof_clone)   *tof_clone  = *tof_obj;  
 //     if(trig_clone)  *trig_clone = *trig_obj;  
 //     if(s4_clone)    *s4_clone   = *s4_obj;  
 //     if(nd_clone)    *nd_clone   = *nd_obj;  
 //     if(ac_clone)    *ac_clone   = *ac_obj;  
 //     if(orb_clone)   *orb_clone  = *orb_obj;  
   
 //     TTree *T = tree_clone;  
   
 //     T->Fill(); //fill main tree  
 // //    cout<<T->IsA()->GetName()<<" "<<T->GetName()<<endl;  
 //     TList *li = T->GetListOfFriends();  
 //     TIter next(li);  
 //     TFriendElement* T_friend=0;  
 //     while( (T_friend = (TFriendElement*)next()) ){  
 // //   cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;  
 //      T_friend->GetTree()->Fill();//fill friends  
 //     }  
3995    
 // }  

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.53

  ViewVC Help
Powered by ViewVC 1.1.23