/[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.10 by pam-fi, Wed Dec 6 11:07:35 2006 UTC revision 1.74 by mocchiut, Tue Dec 16 12:43:08 2008 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        orb_track  = 0;
288        candeleteobj = 0;
289        pscore = 0;
290        iscore = 0;
291  };  };
292  //--------------------------------------  //--------------------------------------
293  //  //
# Line 18  PamTrack::PamTrack(){ Line 296  PamTrack::PamTrack(){
296  /**  /**
297   * Constructor   * Constructor
298   */   */
299  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o){  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o, OrbitalInfoTrkVar *r){
300      trk_track  = this->TrkTrack::GetTrkTrack();  
301      calo_track = this->CaloTrkVar::GetCaloTrkVar();      trk_track  = 0;
302      tof_track  = this->ToFTrkVar::GetToFTrkVar();      calo_track = 0;
303      if(t) *trk_track  = *t;      tof_track  = 0;
304      if(c) *calo_track = *c;      orb_track  = 0;
305      if(o) *tof_track  = *o;      //     if(t)trk_track  = new TrkTrack(*t);
306    //     if(c)calo_track = new CaloTrkVar(*c);
307    //     if(o)tof_track  = new ToFTrkVar(*o);
308        if(t)trk_track  = t;
309        if(c)calo_track = c;
310        if(o)tof_track  = o;
311        if(r) orb_track  = r;
312    
313       candeleteobj = 0;
314    
315  };  };
316    PamTrack::PamTrack(const PamTrack& track){
317    
318        TrkTrack   *t = track.trk_track;
319        CaloTrkVar *c = track.calo_track;
320        ToFTrkVar  *o = track.tof_track;
321        OrbitalInfoTrkVar  *r = track.orb_track;
322    
323        trk_track  = 0;
324        calo_track = 0;
325        tof_track  = 0;
326        orb_track  = 0;
327        if(t)trk_track  = new TrkTrack(*t);
328        if(c)calo_track = new CaloTrkVar(*c);
329        if(o)tof_track  = new ToFTrkVar(*o);
330        if(r)orb_track  = new OrbitalInfoTrkVar(*r);
331        candeleteobj = 1;
332        
333    }
334    void PamTrack::Clear(){
335    
336    //    cout << "PamTrack::Clear() "<<candeleteobj<<endl;
337        if(candeleteobj){
338            if(trk_track)  trk_track->TrkTrack::Clear();
339            if(calo_track) calo_track->CaloTrkVar::Clear();//???
340            if(tof_track)  tof_track->ToFTrkVar::Clear();//???
341            if(orb_track)  orb_track->OrbitalInfoTrkVar::Clear();//???
342        }else{
343            trk_track  = 0;
344            calo_track = 0;
345            tof_track  = 0;
346            orb_track  = 0;
347        }
348        pscore = 0;
349        iscore = 0;
350    
351    }
352    void PamTrack::Delete(){
353    //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;
354        if(candeleteobj){
355            if(trk_track)  {
356                trk_track->TrkTrack::Clear();
357                delete trk_track;
358            }
359            if(calo_track){
360                calo_track->CaloTrkVar::Clear();//???
361                delete calo_track;
362            }
363            if(tof_track){
364                tof_track->ToFTrkVar::Clear();//???
365                delete tof_track;
366            }
367            if(orb_track){
368                orb_track->OrbitalInfoTrkVar::Clear();//???
369                delete orb_track;
370            }
371        }else{
372            Clear();
373        }
374    }
375  //--------------------------------------  //--------------------------------------
376  //  //
377  //  //
378  //--------------------------------------  //--------------------------------------
379  /**  /**
380   * Constructor   * Default Constructor
381   */   */
382  PamLevel2::PamLevel2(){  PamLevel2::PamLevel2(){
383        Initialize();
384    };
385    
386    /**
387     * Constructor
388     * @param ddir Name of directory where level2 files are stored.
389     * @param list Name of an ascii file containing the list of file names
390     * @param detlist Options to chose what to load.
391     * Possible options are:
392     *       +AUTO --> load all trees/branches in the input files
393     *       +(-)ALL --> inlcude(exclude) all trees/branches
394     *       +(-)TRK1+(-)TRK2+(-)CAL1+(-)CAL2+(-)TOF+(-)TRG+(-)ND+(-)S4+(-)ORB+(-)AC --> inlcude(exclude) trees and branches
395     *       +(-)TRK0 --> include(exclude) tracker level0 tree
396     *       +(-)GP --> include exclude GPAMELA output tree
397     * If no options are specified, the default is assumed. Default is:
398     * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
399     */
400    PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){
401        Initialize();
402        TList*  listf = GetListOfLevel2Files(ddir,list);
403        GetPamTree(listf,detlist);
404        GetRunTree(listf);
405    };
406    
407    PamLevel2::PamLevel2(TString ddir,TList *list,TString detlist){
408        Initialize();
409        GetPamTree(list,detlist);
410        GetRunTree(list);
411    };
412    /**
413     * Constructor
414     * @param ddir Name of directory where level2 files are stored.
415     * @param list Name of an ascii file containing the list of file names
416     * Default trees/branches are loaded. Default is:
417     * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
418     */
419    PamLevel2::PamLevel2(TString ddir,TString list){
420        Initialize();
421        TList*  listf = GetListOfLevel2Files(ddir,list);
422        GetPamTree(listf,"");
423        GetRunTree(listf);
424    };
425    
426    
427    void PamLevel2::Initialize(){
428                    
429      trk2_obj  = TrkLevel2::GetTrkLevel2();      h0_obj    = 0;
430      trk1_obj  = TrkLevel1::GetTrkLevel1();      trk0_obj  = 0;
431      trkh_obj  = TrkHough::GetTrkHough();      calo0_obj  = 0;
432      calo1_obj = CaloLevel1::GetCaloLevel1();  
433      calo2_obj = CaloLevel2::GetCaloLevel2();      trk2_obj  = 0;
434      tof_obj   = ToFLevel2::GetToFLevel2();      trk1_obj  = 0;
435      trig_obj  = TrigLevel2::GetTrigLevel2();      trkh_obj  = 0;
436      s4_obj    = S4Level2::GetS4Level2();      calo1_obj = 0;
437      nd_obj    = NDLevel2::GetNDLevel2();      calo2_obj = 0;
438      ac_obj    = AcLevel2::GetAcLevel2();      tof_obj   = 0;
439      orb_obj   = OrbitalInfo::GetOrbitalInfo();      trig_obj  = 0;
440        s4_obj    = 0;
441      run_obj   = new GL_RUN();      nd_obj    = 0;
442            ac_obj    = 0;
443  //     trk1_clone  = 0;      orb_obj   = 0;
444  //     trk2_clone  = 0;      gp_obj    = 0;
445  //     trkh_clone  = 0;  
446  //     calo1_clone = 0;      run_obj   = 0;//new GL_RUN();
447  //     calo2_clone = 0;      soft_obj   = 0;// Emiliano
448  //     tof_clone   = 0;      irun = -1LL;
449  //     trig_clone  = 0;      irunt = -1LL;
450  //     s4_clone    = 0;      runfirstentry = 0LL;
451  //     nd_clone    = 0;      runlastentry = 0LL;
452  //     ac_clone    = 0;      gltsync = 0; // Emiliano
453  //     orb_clone   = 0;  
454        l0_file = NULL;
455  //     T_clone  = 0;      l0_tree = NULL;
456  //     C_clone  = 0;      iroot   = -1;
457  //     O_clone  = 0;      dbc     = 0;
458  //     R_clone  = 0;  
459  //     S_clone  = 0;      prevshift = 0;
460  //     N_clone  = 0;      maxshift = 10; //EMILIANO
461  //     A_clone  = 0;      
462  //     B_clone  = 0;      run_tree = NULL;
463        run_tree_clone = NULL;
464        sel_tree = NULL;
465        sel_tree_clone = NULL;
466        
467        irunentry = -1LL;
468        pam_tree = NULL;
469        for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;
470    
471        totdltime[0] = 0LL;
472        totdltime[1] = 0LL;
473        totdltime[2] = 0LL;
474    
475        host = "mysql://localhost/pamelaprod";
476        user = "anonymous";
477        psw = "";
478        const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
479        const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
480        const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
481        if ( !pamdbhost ) pamdbhost = "";
482        if ( !pamdbuser ) pamdbuser = "";
483        if ( !pamdbpsw ) pamdbpsw = "";
484        if ( strcmp(pamdbhost,"") ) host = pamdbhost;
485        if ( strcmp(pamdbuser,"") ) user = pamdbuser;
486        if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
487    
488      for(Int_t i=0; i<8; i++ )tree_clone[i]=NULL;      
489    
490      sorted_tracks = new TRefArray();  //    sorted_tracks = 0;//new TRefArray();
491            
492        CAL0 = false;
493      CAL1 = true;      CAL1 = true;
494      CAL2 = true;      CAL2 = true;
495      TRK2 = true;      TRK2 = true;
496      TRK1 = false;      TRK1 = false;
497        TRK0 = false;
498      TRKh = false;      TRKh = false;
499      TRG = true;      TRG  = true;
500      TOF = true;      TOF  = true;
501      S4  = true;      TOF0 = false;
502      ND  = true;      S4   = true;
503      AC  = true;      ND   = true;
504      ORB = true;      AC   = true;
505        ORB  = true;    
506        GP   = false;
507    
508        RUN  = true;
509    
510        SELLI = -1;
511    
512        ISGP = false;
513    
514        DBG = false;
515    
516        tsorted=0;
517        timage=0;
518            
519        howtosort = "+CAL+TOF";
520        //howtosort = "+TOF";
521        sortthr = 100.;
522    
523  };  };
524  /**  /**
525   * Destructor   * Delete the event (act as Dtor)
526   */   */
527  PamLevel2::~PamLevel2(){                  void PamLevel2::Delete(){
528      delete run_obj;          
529      Clear();      if(run_obj)delete run_obj;
530        if(soft_obj)delete soft_obj; //Emiliano
531    
532    //    cout << "void PamLevel2::Clear()"<<endl;
533        if(h0_obj)   delete h0_obj;
534        if(trk0_obj) delete trk0_obj;      
535        if(calo0_obj) delete calo0_obj;    
536        if(trk1_obj) delete trk1_obj;      
537        if(trk2_obj) delete trk2_obj;
538        if(trkh_obj) delete trkh_obj;
539        if(calo1_obj)delete calo1_obj;
540        if(calo2_obj)delete calo2_obj;
541        if(tof_obj)  delete tof_obj;
542        if(trig_obj) delete trig_obj;
543        if(s4_obj)   delete s4_obj;
544        if(nd_obj)   delete nd_obj;
545        if(ac_obj)   delete ac_obj;
546        if(orb_obj)  delete orb_obj;
547        if(gp_obj)   delete gp_obj;
548        
549        if(tsorted){
550            tsorted->Delete();
551            delete tsorted;
552        }
553        if(timage){
554            timage->Delete();
555            delete timage;
556        }
557    
558        if(dbc){
559            dbc->Close();
560            delete dbc;
561        }
562    
563        if ( gltsync ) delete gltsync;
564        
565        if(l0_file)l0_file->Close();
566        //    if(pam_tree)pam_tree->Delete();;
567    
568        if ( pam_tree ){
569            //
570            // 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...
571            //
572            TList *temp = pam_tree->GetListOfFriends();
573            TList *contents  = new TList; // create chain friend list
574            contents->SetOwner();
575            TIter next(temp);
576            TChain *questo = 0;
577            while ( (questo = (TChain*) next()) ){
578                TString name =  questo->GetName();
579                contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
580            };
581            //
582            // deleting the main chain
583            //
584            pam_tree->Delete();
585            //
586            // deleting the friends...
587            //
588            TIter next2(contents);
589            TChain *questa = 0;
590            while ( questa = (TChain*)next2() ){
591                TString name =  questa->GetName();
592                questa->Delete();      
593                questa=NULL;
594            };
595            //
596        };
597        pam_tree = NULL;
598    
599        if(run_tree)run_tree->Delete();;
600        if(sel_tree)sel_tree->Delete();;
601        for(Int_t i=0; i<NCLONES; i++ )if(pam_tree_clone[i])pam_tree_clone[i]->Delete();;
602        if(run_tree_clone)run_tree_clone->Delete();;
603        if(sel_tree_clone)sel_tree_clone->Delete();;
604        
605        if(irunoffset) delete [] irunoffset;
606    
607  };  };
608    
609  /**  /**
610   * Clear the event   * Clear the event (NB! does not deallocate objects)
611   */   */
612  void PamLevel2::Clear(){  void PamLevel2::Clear(){
613                    
614      TrkLevel1::Clear();  //    cout << "void PamLevel2::Clear()"<<endl;
615            
616      TrkLevel2::Clear();  //
617      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
618      ToFLevel2::Clear();  // want to load them for each event even if they are the same...
619      TrigLevel2::Clear();  //
620      S4Level2::Clear();  //    if(run_obj)delete run_obj;
621      NDLevel2::Clear();  //    if(run_obj) run_obj->Clear();  // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead
622      AcLevel2::Clear();  //    if(soft_obj) soft_obj->Clear();
623      OrbitalInfo::Clear();  
624        if(h0_obj)   h0_obj->Clear();      
625  //     if(trk1_clone)trk1_clone->Clear();  //    if(trk0_obj) trk0_obj->Clear();  
626  //     if(trk2_clone)trk2_clone->Clear();      if(trk1_obj) trk1_obj->Clear();    
627  //     if(trkh_clone)trkh_clone->Clear();      if(trk2_obj) trk2_obj->Clear();
628  //     if(calo1_clone)calo1_clone->Clear();      if(trkh_obj) trkh_obj->Clear();
629  //     if(calo2_clone)calo2_clone->Clear();      if(calo0_obj) calo0_obj->Clear();  
630  //     if(tof_clone)tof_clone->Clear();      if(calo1_obj)calo1_obj->Clear();
631  //     if(trig_clone)trig_clone->Clear();      if(calo2_obj)calo2_obj->Clear();
632  //     if(s4_clone)s4_clone->Clear();      if(tof_obj)  tof_obj->Clear();
633  //     if(nd_clone)nd_clone->Clear();      if(trig_obj) trig_obj->Clear();
634  //     if(ac_clone)ac_clone->Clear();      if(s4_obj)   s4_obj->Clear();
635  //     if(orb_clone)orb_clone->Clear();      if(nd_obj)   nd_obj->Clear();
636            if(ac_obj)   ac_obj->Clear();
637      sorted_tracks->Delete(); // clean the reference array      if(orb_obj)  orb_obj->Clear();
638        if(gp_obj)   gp_obj->Clear();
639            
640    //    if(sorted_tracks)sorted_tracks->Clear();
641    //    sorted_tracks.Clear();
642    
643        if(tsorted){
644            tsorted->Delete();
645        }
646        if(timage){
647            timage->Delete();
648        }
649  };  };
650    
651    void PamLevel2::Reset(){
652        //
653        // First of all clear everything
654        //
655        Clear();
656        //
657        // close and reset chains and pointers
658        //    
659        if ( pam_tree ){
660            //
661            // 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...
662            //
663            TList *temp = pam_tree->GetListOfFriends();
664            TList *contents  = new TList; // create chain friend list
665            contents->SetOwner();
666            TIter next(temp);
667            TChain *questo = 0;
668            while ( (questo = (TChain*) next()) ){
669                TString name =  questo->GetName();
670                contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
671            };
672            //
673            // deleting the main chain
674            //
675            pam_tree->Delete();
676            //
677            // deleting the friends...
678            //
679            TIter next2(contents);
680            TChain *questa = 0;
681            while ( questa = (TChain*)next2() ){
682                TString name =  questa->GetName();
683                questa->Delete();      
684                questa=NULL;
685            };
686            //
687        };
688        pam_tree = NULL;
689        //
690        if(run_tree)run_tree->Delete();;
691        run_tree = NULL;
692        if(sel_tree)sel_tree->Delete();;
693        sel_tree = NULL;
694        //
695        // Close file
696        //
697        if(l0_file)l0_file->Close("R");
698        l0_file = NULL;
699        //
700        h0_obj    = 0;
701        trk0_obj  = 0;
702        calo0_obj  = 0;
703        //
704        trk2_obj  = 0;
705        trk1_obj  = 0;
706        trkh_obj  = 0;
707        calo1_obj = 0;
708        calo2_obj = 0;
709        tof_obj   = 0;
710        trig_obj  = 0;
711        s4_obj    = 0;
712        nd_obj    = 0;
713        ac_obj    = 0;
714        orb_obj   = 0;
715        gp_obj    = 0;
716        //
717        // Reset run pointers
718        //
719        run_obj   = 0;//new GL_RUN();
720        soft_obj   = 0;// Emiliano
721        irun = -1;
722        irunt = -1;
723        runfirstentry = 0ULL;
724        runlastentry = 0ULL;    
725        //
726        totdltime[0] = 0LL;
727        totdltime[1] = 0LL;
728        totdltime[2] = 0LL;
729        //
730    };
731    
732    Bool_t PamLevel2::IsGood(Bool_t strict){
733      Bool_t goodev=true;
734      //
735      if(calo2_obj && !calo2_obj->IsGood(strict) ) goodev = false;
736      //
737      if ( strict ){
738        if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;
739        if(tof_obj && tof_obj->unpackError != 0) goodev = false;  
740        if(trig_obj && trig_obj->unpackError != 0) goodev = false;
741        if(s4_obj && s4_obj->unpackError != 0) goodev = false;  
742        if(nd_obj && nd_obj->unpackError != 0) goodev = false;  
743        if(ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0]>>2)&1) || ((ac_obj->status[1]>>2)&1)) ) goodev = false;      
744        //  if(orb_obj)  
745      } else {
746        if(nd_obj && nd_obj->unpackError != 0) goodev = false;  
747        if(ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0]>>2)&1) || ((ac_obj->status[1]>>2)&1)) ) goodev = false;      
748      };
749      return(goodev);
750    };
751    
752  //--------------------------------------  //--------------------------------------
753  //  //
# Line 136  void PamLevel2::Clear(){ Line 756  void PamLevel2::Clear(){
756  void *PamLevel2::GetPointerTo(const char* c ){  void *PamLevel2::GetPointerTo(const char* c ){
757    
758      TString objname = c;      TString objname = c;
759      if(!objname.CompareTo("TrkLevel1"))return &trk1_obj;  
760      if(!objname.CompareTo("TrkLevel2"))return &trk2_obj;      if(!objname.CompareTo("TrkLevel1"))  {
761      if(!objname.CompareTo("TrkHough"))return &trkh_obj;          if(!trk1_obj){
762      if(!objname.CompareTo("CaloLevel1"))return &calo1_obj;              trk1_obj  = new TrkLevel1();
763      if(!objname.CompareTo("CaloLevel2"))return &calo2_obj;              trk1_obj->Set();
764      if(!objname.CompareTo("ToFLevel2"))return &tof_obj;          }
765      if(!objname.CompareTo("TrigLevel2"))return &trig_obj;          return &trk1_obj;
766      if(!objname.CompareTo("S4Level2"))return &s4_obj;      };
767      if(!objname.CompareTo("NDLevel2"))return &nd_obj;      if(!objname.CompareTo("TrkLevel2"))  {
768      if(!objname.CompareTo("AcLevel2"))return &ac_obj;          if(!trk2_obj){  
769      if(!objname.CompareTo("OrbitalInfo"))return &orb_obj;              trk2_obj  = new TrkLevel2();
770                trk2_obj->Set();
771            }
772            return &trk2_obj;
773        };
774        if(!objname.CompareTo("TrkHough"))   {
775            if(!trkh_obj)  {
776                trkh_obj  = new TrkHough();
777                trkh_obj->Set();
778            }
779            return &trkh_obj;
780        };
781        if(!objname.CompareTo("CaloLevel1")) {
782            if(!calo1_obj) calo1_obj = new CaloLevel1();
783            return &calo1_obj;
784        };
785        if(!objname.CompareTo("CaloLevel2")) {
786            if(!calo2_obj){
787                calo2_obj = new CaloLevel2();
788                calo2_obj->Set();
789            };
790            return &calo2_obj;
791        };
792        if(!objname.CompareTo("ToFLevel2"))  {
793            if(!tof_obj){
794                tof_obj   = new ToFLevel2();
795                tof_obj->Set();
796            }
797            return &tof_obj;
798        };
799        if(!objname.CompareTo("TrigLevel2")) {
800            if(!trig_obj)  trig_obj  = new TrigLevel2();
801            return &trig_obj;
802        };
803        if(!objname.CompareTo("S4Level2"))   {
804            if(!s4_obj)    s4_obj    = new S4Level2();
805            return &s4_obj;
806        };
807        if(!objname.CompareTo("NDLevel2"))   {
808            if(!nd_obj)    nd_obj    = new NDLevel2();
809            return &nd_obj;
810        };
811        if(!objname.CompareTo("AcLevel2"))   {
812            if(!ac_obj)    ac_obj    = new AcLevel2();
813            return &ac_obj;
814        };
815        if(!objname.CompareTo("OrbitalInfo"))  {
816            if(!orb_obj){
817                orb_obj   = new OrbitalInfo();
818                orb_obj->Set();
819            }
820            return &orb_obj;
821        };
822    //     if(!objname.CompareTo("OrbitalInfo")){
823    //      if(!orb_obj)   orb_obj   = new OrbitalInfo();
824    //      return &orb_obj;
825    //     };
826        if(!objname.CompareTo("GPamela")){
827            if(!gp_obj)   gp_obj   = new GPamela();
828            return &gp_obj;
829        };
830        
831      if(!objname.CompareTo("RunInfo"))return &run_obj;      if(!objname.CompareTo("RunInfo"))return &run_obj;
832    
833        if(!objname.CompareTo("SoftInfo"))return &soft_obj; // Emiliano
834    
835      return NULL;      return NULL;
836  };  };
837  //--------------------------------------  //--------------------------------------
# Line 158  void *PamLevel2::GetPointerTo(const char Line 842  void *PamLevel2::GetPointerTo(const char
842   * Retrieves the calorimeter track matching the seqno-th tracker stored track.   * Retrieves the calorimeter track matching the seqno-th tracker stored track.
843   * (If seqno = -1 retrieves the self-trigger calorimeter track)   * (If seqno = -1 retrieves the self-trigger calorimeter track)
844   */   */
845   CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){  CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
           
      if( CaloLevel2::ntrk()==0 ){  
          cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;  
          return NULL;  
      };  
846            
847       CaloTrkVar *c = 0;      if( !calo2_obj )return 0;
848       Int_t it_calo=0;  
849        if( calo2_obj->CaloLevel2::ntrk()==0 ){
850            cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;
851            return NULL;
852        };
853        
854        CaloTrkVar *c = 0;
855        Int_t it_calo=0;
856            
857       do{      do{
858           c = CaloLevel2::GetCaloTrkVar(it_calo);          c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
859           it_calo++;          it_calo++;
860       } while( c && seqno != c->trkseqno && it_calo < CaloLevel2::ntrk());            } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());    
861            
862       if(!c || seqno != c->trkseqno){      if(!c || seqno != c->trkseqno){
863           c = 0;          c = 0;
864           if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;          if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;
865       };      };
866       return c;      return c;
867            
868   };  };
869  //--------------------------------------  //--------------------------------------
870   //  //
871   //  //
872  //--------------------------------------  //--------------------------------------
873  /**  /**
874    * Retrieves the ToF track matching the seqno-th tracker stored track.   * Retrieves the ToF track matching the seqno-th tracker stored track.
875    * (If seqno = -1 retrieves the tracker-independent tof track)   * (If seqno = -1 retrieves the tracker-independent tof track)
876   */   */
877   ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
878                    
879       if( ToFLevel2::ntrk()==0 ){      if( !tof_obj )return 0;
880           cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;  
881           return NULL;      if( tof_obj->ToFLevel2::ntrk()==0 ){
882       };          cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;
883            return NULL;
884        };
885            
886       ToFTrkVar *c = 0;      ToFTrkVar *c = 0;
887       Int_t it_tof=0;      Int_t it_tof=0;
888            
889       do{      do{
890           c = ToFLevel2::GetToFTrkVar(it_tof);          c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);
891           it_tof++;          it_tof++;
892       } while( c && seqno != c->trkseqno && it_tof < ToFLevel2::ntrk());      } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());
893            
894       if(!c || seqno != c->trkseqno){      if(!c || seqno != c->trkseqno){
895           c = 0;          c = 0;
896           if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;          if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;
897       };      };
898       return c;      return c;
899            
900   };  };
901    
902  //--------------------------------------  //--------------------------------------
903   //  //
904   //  //
905  //--------------------------------------  //--------------------------------------
906  /**  /**
907   * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.   * Retrieves the OrbitalInfo track matching the seqno-th tracker stored track.
908     * (If seqno = -1 retrieves the tracker-independent tof related track)
909   */   */
910   PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno){
911                    
912       CaloTrkVar *c = 0;      if( !orb_obj )return 0;
913       ToFTrkVar  *o = 0;  
914    
915        if( orb_obj->OrbitalInfo::ntrk()==0 ){
916    //       // TRICK BEGIN
917    //       OrbitalInfoTrkVar  *r = new OrbitalInfoTrkVar(); // TEMPORARY TRICK
918    //       Int_t nn = 0;
919    //       TClonesArray &tor = *orb_obj->OrbitalInfoTrk;
920    //       for(Int_t nt=0; nt < tof_obj->ToFLevel2::ntrk(); nt++){  
921    //      //
922    //      ToFTrkVar *ptt = tof_obj->ToFLevel2::GetToFTrkVar(nt);
923    //      if ( ptt->trkseqno != -1  ){
924    //        //
925    //        r->trkseqno = ptt->trkseqno;
926    //        //
927    //        r->Eij = 0;  
928    //        //
929    //        r->Sij = 0;
930    //        //        
931    //        r->pitch = -1000.;
932    //        //
933    //        r->cutoff = -1000.;
934    //        //
935    //        new(tor[nn]) OrbitalInfoTrkVar(*r);
936    //        nn++;
937    //        //
938    //        r->Clear();
939    //        //
940    //      };
941    //       };
942    //       delete r;
943    //       OrbitalInfoTrkVar *c = 0;
944    //       c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(0);
945    //       return c;
946    //       //TRICK END
947          cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no OrbitalInfo tracks are stored"<<endl;
948          return NULL;
949        };
950        
951        OrbitalInfoTrkVar *c = 0;
952        Int_t it_tof=0;
953        
954        do{
955            c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);
956            it_tof++;
957        } while( c && seqno != c->trkseqno && it_tof < orb_obj->OrbitalInfo::ntrk());      
958            
959       if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());      if(!c || seqno != c->trkseqno){
960       if(TOF) o = GetToFStoredTrack(t->GetSeqNo());          c = 0;
961            if(seqno!=-1)cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match OrbitalInfo stored tracks"<<endl;
962        };
963        return c;
964        
965    };
966    
967    //--------------------------------------
968    //
969    //
970    //--------------------------------------
971    /**
972     * Give the pamela track associated to a tracker track, retrieving related calorimeter, orbitalinfo and tof track information.
973     */
974    PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
975        
976        cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;
977        cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
978    
979        CaloTrkVar *c = 0;
980        ToFTrkVar  *o = 0;
981        OrbitalInfoTrkVar  *r = 0;
982        
983        if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());
984        if(TOF) o = GetToFStoredTrack(t->GetSeqNo());
985        if(ORB) r = GetOrbitalInfoStoredTrack(t->GetSeqNo());
986            
987  //    if(t && c && o)track = new PamTrack(t,c,o);  //    if(t && c && o)track = new PamTrack(t,c,o);
988       PamTrack *track = new PamTrack(t,c,o);      PamTrack *track = new PamTrack(t,c,o,r);
989            
990       return track;      return track;
991    
992   };  };
993  //--------------------------------------  //--------------------------------------
994  //  //
995  //  //
# Line 244  void *PamLevel2::GetPointerTo(const char Line 1002  void *PamLevel2::GetPointerTo(const char
1002    
1003  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
1004            
1005        cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;
1006        cout <<"for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack) OrbitalInfo::GetOrbitalInfoTrkVar(Int_t notrack)"<<endl;
1007        cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
1008      PamTrack *track = 0;      PamTrack *track = 0;
1009            
1010      if( itrk >=0 && itrk < TrkLevel2::ntrk() ){      if( itrk >=0 && itrk < trk2_obj->TrkLevel2::ntrk() ){
1011                    
1012          TrkTrack *t = TrkLevel2::GetStoredTrack(itrk);          TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk);
1013          track = GetPamTrackAlong(t);          track = GetPamTrackAlong(t);
1014                    
1015            
1016    
1017      }else{      }else{
1018          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;
1019      };      };
1020            
1021      return track;      return track;
# Line 260  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 1023  PamTrack* PamLevel2::GetStoredTrack(Int_
1023  }  }
1024  //--------------------------------------  //--------------------------------------
1025  //  //
1026    
1027    /**
1028     * Sort physical (tracker) tracks. Left here as backward compatibility method.
1029     **/
1030    void PamLevel2::SortTracks(TString how){
1031        printf(" WARNING! obsolete, use SortTracks() and SetSortingMethod(TString) instead! \n Setting sorting method to %s \n",how.Data());
1032        howtosort = how;  
1033        SortTracks();
1034    };
1035    
1036  //  //
1037  //--------------------------------------  //--------------------------------------
1038  /**  /**
1039   * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is  PamLevel2::sorted_tracks.   * Sort physical (tracker) tracks.
1040   * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...).   * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...).
1041   * Sorting cryteria:   * Sorting cryteria:
1042   * TRK: lower chi**2   * TRK: lower chi**2
1043   * CAL: lower Y spatial residual on the first calorimeter plane   * CAL: lower Y spatial residual on the first calorimeter plane
1044   * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis).   * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis).
1045     * S1: (ask Emiliano)
1046     * S2: (ask Emiliano)
1047     * S3: (ask Emiliano)
1048     * GP: more GP hits
1049   * The default sorting cryterium is "TOF+CAL".   * The default sorting cryterium is "TOF+CAL".
1050   *   *
1051   * 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).
1052   */   */
1053  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(){
1054        TString how = howtosort;
1055    
1056  //    cout << "call SortTracs() "<<endl;      //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;
1057    //Save current Object count      if( !trk2_obj ){
1058            cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";
1059            return;
1060        };
1061        //Save current Object count
1062      Int_t ObjectNumber = TProcessID::GetObjectCount();      Int_t ObjectNumber = TProcessID::GetObjectCount();
1063    
1064  //    cout << "ObjectNumber  "<<ObjectNumber <<endl;      // create TCloneArrays to store tracks and its images
1065            if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
1066      sorted_tracks->Delete(); //temporaneo???      tsorted->Delete();
1067                TClonesArray &ttsorted = *tsorted;
1068      // loop over the tracks sorted by the tracker  
1069        if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
1070        timage->Delete();
1071        TClonesArray &ttimage = *timage;
1072    
1073    
1074    
1075        //--------------------------------------------------
1076        // retrieve sorting method
1077        //--------------------------------------------------
1078      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
1079      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
1080      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
1081            Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
1082        Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
1083        Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
1084        Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
1085      
1086        if ( use_TOF ){
1087            use_S1 = true;
1088            use_S2 = true;
1089            use_S3 = true;
1090        };
1091      if( !CAL2 &&  use_CAL) use_CAL = false;      if( !CAL2 &&  use_CAL) use_CAL = false;
1092      if( !TOF &&  use_TOF) use_TOF = false;      if( !TOF ){
1093                use_TOF = false;
1094            use_S1  = false;
1095            use_S2  = false;
1096            use_S3  = false;
1097        }
1098        if( !GP ){
1099            use_GP  = false;
1100        }
1101    
1102      if( !TRK2 ){      if( !TRK2 ){
1103  //      cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;          cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
1104          return;          return;
1105      };      };
1106    
1107      //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;      //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
1108          
1109      for(Int_t i=0; i < TrkLevel2::GetNTracks(); i++){  
1110        //--------------------------------------------------
1111        // loop over "physical" tracks sorted by the tracker
1112        //--------------------------------------------------
1113        for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
1114                    
1115          TrkTrack *ts = 0;          TrkTrack   *ts = 0;
1116            CaloTrkVar *cs = 0;
1117            ToFTrkVar  *os = 0;
1118            OrbitalInfoTrkVar  *rs = 0;
1119                    
1120          // get tracker tracks          // get tracker tracks
1121          TrkTrack   *tp = TrkLevel2::GetTrack(i);                    //tracker          TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
1122          CaloTrkVar *cp = 0;          CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
1123          ToFTrkVar  *op = 0;          ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
1124            OrbitalInfoTrkVar  *rp = GetOrbitalInfoStoredTrack(tp->GetSeqNo());
1125  //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;  
1126            TrkTrack   *ti = 0; //tracker (image)
1127            CaloTrkVar *ci = 0;
1128            ToFTrkVar  *oi = 0;
1129            OrbitalInfoTrkVar  *ri = 0;
1130            //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
1131          // if track has an image, check image selection          // if track has an image, check image selection
1132    
1133            Int_t tp_score = 0;  //main track sorted by the tracker
1134            Int_t ti_score = 0;  //image track
1135            Int_t totp_score = 0;  //main track sorted by the tracker
1136            Int_t toti_score = 0;  //image track
1137    
1138          if(tp->HasImage()){          if(tp->HasImage()){
1139                            
1140              TrkTrack   *ti = TrkLevel2::GetTrackImage(i);              //tracker (image)              ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)
1141              CaloTrkVar *ci = 0;              ci = GetCaloStoredTrack(ti->GetSeqNo());
1142              ToFTrkVar  *oi = 0;              oi = GetToFStoredTrack(ti->GetSeqNo());
1143                ri = GetOrbitalInfoStoredTrack(ti->GetSeqNo());
1144                            
1145  //          cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;              //      cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
1146    
1147              //assign starting scores              //assign starting scores
1148              Int_t tp_score = 0;  //main track sorted by the tracker              tp_score = 0;  //main track sorted by the tracker
1149              Int_t ti_score = 0;  //image track              ti_score = 0;  //image track
1150                            
1151              // ------------------------              // -----------------------------------------------------------------------------------------
1152                // *****************************************************************************************
1153                // -----------------------------------------------------------------------------------------
1154              // calorimeter check              // calorimeter check
1155              // ------------------------              // -----------------------------------------------------------------------------------------
1156              // check the Y spatial residual on the first calorimeter plane              if( use_CAL && !calo2_obj ){
1157              // (cut on calorimeter variables from Emiliano)                  cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";
1158                    return;
1159                };
1160                if( use_CAL && !cp &&  ci ){
1161                    ti_score++;
1162                    toti_score++;
1163                };
1164                if( use_CAL &&  cp && !ci ){
1165                    tp_score++;
1166                    totp_score++;
1167                };
1168              if(              if(
1169                  use_CAL            &&                  use_CAL            &&
1170                  npcfit[1] > 15     &&   //no. of fit planes on Y view                  cp && ci &&
                 varcfit[1] < 1000. &&  //fit variance on Y view  
1171                  true){                  true){
1172    
1173                  cp = GetCaloStoredTrack(tp->GetSeqNo());                  
1174                  ci = GetCaloStoredTrack(ti->GetSeqNo());                  if(
1175                                        cp->npresh > ci->npresh &&
1176                  Float_t resy_p = cp->tbar[0][1] - cbar[0][1]; if(resy_p < 0)resy_p= - resy_p;                      true){
1177                  Float_t resy_i = ci->tbar[0][1] - cbar[0][1]; if(resy_i < 0)resy_i= - resy_i;                      tp_score++;
1178                                        totp_score++;
1179                  if(resy_p <= resy_i) tp_score++;                  };
1180                  else                 ti_score++;                  if(
1181                        cp->npresh < ci->npresh &&
1182                        true){
1183                        ti_score++;
1184                        toti_score++;
1185                    };
1186    
1187  //              cout << "CALO "<<tp_score<<ti_score<<endl;                  //      cout << "CALO "<<tp_score<<ti_score<<endl;
1188    
1189              };              };
1190              // ------------------------              // -----------------------------------------------------------------------------------------
1191                // *****************************************************************************************
1192                // -----------------------------------------------------------------------------------------
1193              // TOF check              // TOF check
1194              // ------------------------                  // -----------------------------------------------------------------------------------------
1195              // check the number of hit pmts along the track              // check the number of hit pmts along the track
1196              // on S12 S21 and S32, where paddles are parallel to Y axis              // on S12 S21 and S32, where paddles are parallel to Y axis
1197              if( use_TOF ){              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !tof_obj ){
1198                    cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";
1199                    return;
1200                };
1201                //
1202                if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !op && oi ){
1203                    ti_score++;
1204                    toti_score++;
1205                };
1206                if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && !oi ){
1207                    tp_score++;
1208                    totp_score++;
1209                };
1210                if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && oi ){
1211                    //
1212                    Float_t sen = 0.;
1213                    for (Int_t ih=0; ih < op->npmtadc; ih++){
1214                        Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1215                        if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih);
1216                    };
1217                    for (Int_t ih=0; ih < oi->npmtadc; ih++){
1218                        Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1219                        if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);
1220                    };
1221                    //
1222                    if (  sen >= sortthr && false){ // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
1223                        //printf(" IS A NUCLEUS! en = %f \n",sen);
1224                        //
1225                        // is a nucleus use a different algorithm
1226                        //
1227                        Int_t nz = 6; Float_t zin[6];                                          // << define TOF z-coordinates
1228                        for(Int_t ip=0; ip<nz; ip++)
1229                            zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip));     // << read ToF plane z-coordinates
1230                        Trajectory *tr = new Trajectory(nz,zin);
1231                        //
1232                        Int_t nphit_p =0;
1233                        Int_t nphit_i =0;
1234                        Float_t enhit_p = 0.;
1235                        Float_t enhit_i = 0.;
1236                        //
1237                        for (Int_t ih=0; ih < op->npmtadc; ih++){
1238                            Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1239                            if(pl == 1 || pl == 2 || pl == 5){
1240                                nphit_p++;
1241                                enhit_p += (op->dedx).At(ih);
1242                            };
1243                        };
1244                        //
1245                        tp->DoTrack2(tr);
1246                        //
1247                        if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1248                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1249                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1250                                if(pl == 0){
1251                                    nphit_p++;
1252                                    enhit_p += (op->dedx).At(ih);
1253                                };
1254                            };
1255                        };
1256                        if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1257                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1258                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1259                                if(pl == 3){
1260                                    nphit_p++;
1261                                    enhit_p += (op->dedx).At(ih);
1262                                };
1263                            };
1264                        };
1265                        if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1266                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1267                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1268                                if(pl == 4){
1269                                    nphit_p++;
1270                                    enhit_p += (op->dedx).At(ih);
1271                                };
1272                            };
1273                        };
1274    
1275                        for (Int_t ih=0; ih < oi->npmtadc; ih++){
1276                            Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1277                            if(pl == 1 || pl == 2 || pl == 5){
1278                                nphit_i++;  
1279                                enhit_i += (op->dedx).At(ih);
1280                            };
1281                        };
1282                        //
1283                        ti->DoTrack2(tr);
1284                        //
1285                        if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1286                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1287                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1288                                if(pl == 0){
1289                                    nphit_i++;
1290                                    enhit_i += (op->dedx).At(ih);
1291                                };
1292                            };
1293                        };
1294                        if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1295                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1296                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1297                                if(pl == 3){
1298                                    nphit_i++;
1299                                    enhit_i += (op->dedx).At(ih);
1300                                };
1301                            };
1302                        };
1303                        if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1304                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1305                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1306                                if(pl == 4){
1307                                    nphit_i++;
1308                                    enhit_i += (op->dedx).At(ih);
1309                                };
1310                            };
1311                        };          
1312    
1313                                    
1314                  Int_t nphit_p =0;                      if(
1315                  Int_t nphit_i =0;                          (use_TOF || use_S1 || use_S2 || use_S3)            &&
1316                            (nphit_p+nphit_i) !=0 &&        
1317                            true){
1318                        
1319                            //          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);
1320                            //          printf(" score p %i score i %i \n",tp_score,ti_score);
1321                            //                if( enhit_p > enhit_i ) tp_score++;
1322                            //                if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
1323                            if ( nphit_p > nphit_i ) tp_score++;
1324                            if ( nphit_p < nphit_i ) ti_score++;
1325                            if ( nphit_p == nphit_i ){
1326                                if ( enhit_p > enhit_i ) tp_score++;
1327                                else ti_score++;
1328                            };
1329                            //          printf(" dopo score p %i score i %i \n",tp_score,ti_score);
1330                        };
1331                        delete tr;
1332                        //
1333                    } else {
1334                        // -------------
1335                        // NOT a NUCLEUS
1336                        // -------------
1337                        //printf(" NOT a NUCLEUS! en = %f \n",sen);
1338    
1339                        Int_t nphit_p =0;
1340                        Int_t nphit_i =0;
1341                                    
                 op = GetToFStoredTrack(tp->GetSeqNo());  
                 oi = GetToFStoredTrack(ti->GetSeqNo());  
1342                                    
1343  /*                              cout << "track: npmtadc "<< op->npmtadc << endl;                      /*                          cout << "track: npmtadc "<< op->npmtadc << endl;
1344                                  cout << "track: npmttdc "<< op->npmttdc << endl;                                                  cout << "track: npmttdc "<< op->npmttdc << endl;
1345                                  cout << "image: npmtadc "<< oi->npmtadc << endl;                                                  cout << "image: npmtadc "<< oi->npmtadc << endl;
1346                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/                                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1347                                    
1348                  for (Int_t ih=0; ih < op->npmtadc; ih++){  //        for (Int_t ih=0; ih < op->npmtadc; ih++){
1349                      Int_t pl = GetPlaneIndex( (op->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1350                      if(pl == 1 || pl == 2 || pl == 5)nphit_p++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
1351                  };  //        };
1352                                    
1353                  for (Int_t ih=0; ih < oi->npmtadc; ih++){  //        for (Int_t ih=0; ih < oi->npmtadc; ih++){
1354                      Int_t pl = GetPlaneIndex( (oi->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1355                      if(pl == 1 || pl == 2 || pl == 5)nphit_i++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1356                  };  //        };
1357                        // --- modified to count tdc signals (more efficient?)
1358                        // --- and to implement check on tdcflag
1359                        for (Int_t ih=0; ih < op->npmttdc; ih++){
1360                            Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );
1361    //          if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
1362                            if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){
1363                                if( (op->tdcflag).At(ih)==0 )nphit_p++;
1364                            };
1365                        };
1366                                    
1367                  if(                      for (Int_t ih=0; ih < oi->npmttdc; ih++){
1368                      use_TOF            &&                          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );
1369                      (nphit_p+nphit_i) !=0 &&      //          if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;  
1370                      true){                          if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){
1371                                if( (oi->tdcflag).At(ih)==0 )nphit_i++;    
1372                            };
1373                        };
1374                    
1375                        if(
1376                            (nphit_p+nphit_i) !=0 &&        
1377                            true){
1378                                            
1379                      if( nphit_p >= nphit_i) tp_score++;                          if ( nphit_p != nphit_i ){
1380                      else ti_score++;                              totp_score += nphit_p;
1381                                toti_score += nphit_i;
1382                                tp_score+=nphit_p;
1383                                ti_score+=nphit_i;
1384                            };
1385                            //          if     ( nphit_p > nphit_i) tp_score+=nphit_p;
1386                            //          else if( nphit_p < nphit_i) ti_score+=nphit_i;
1387                            //          else ;//niente
1388                        };
1389                  };                  };
1390  //              cout << "TOF "<<tp_score<<ti_score<<endl;                  //      cout << "TOF "<<tp_score<<ti_score<<endl;
1391              };              };
1392              if(tp_score == ti_score) use_TRK = true;  
1393              // ------------------------  
1394    //      if(tp_score == ti_score) use_TRK = true;
1395    
1396    
1397                // -----------------------------------------------------------------------------------------
1398                // *****************************************************************************************
1399                // -----------------------------------------------------------------------------------------
1400              // tracker check              // tracker check
1401              // ------------------------              // -----------------------------------------------------------------------------------------
1402              // chi**2 difference is not always large enough to distinguish among              // chi**2 difference is not always large enough to distinguish among
1403              // the real track and its image.              // the real track and its image.
1404              // Tracker check will be applied always when calorimeter and tof information is ambiguous.              // Tracker check will be applied always when calorimeter and tof information is ambiguous.
1405                // *** MODIFIED ON AUGUST 2007 ***
1406              if(use_TRK){              if(use_TRK){
1407                  if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;  //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
1408                  else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;  //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
1409  //              cout << "TRK "<<tp_score<<ti_score<<endl;  
1410                    // CHECK 1 : number of points along X  
1411                    if ( tp->GetNX() >= ti->GetNX() ){
1412                        tp_score++ ;
1413                        totp_score++ ;
1414                    };
1415                    if ( tp->GetNX() <= ti->GetNX() ){
1416                        ti_score++ ;
1417                        toti_score++ ;
1418                    };
1419                    // CHECK 2 : number of points along Y  
1420                    if ( tp->GetNY() >= ti->GetNY() ){
1421                        tp_score++ ;
1422                        totp_score++ ;
1423                    };
1424                    if ( tp->GetNY() <= ti->GetNY() ){
1425                        ti_score++ ;
1426                        toti_score++ ;
1427                    };
1428    
1429                    //      cout << "TRK "<<tp_score<<ti_score<<endl;
1430              };              };
1431                            
1432              // ------------------------  
1433                // -----------------------------------------------------------------------------------------
1434                // *****************************************************************************************
1435                // -----------------------------------------------------------------------------------------
1436                // GPamela check
1437                // -----------------------------------------------------------------------------------------
1438                
1439                //---------------------------------------------------
1440                // count the number of GP hits
1441                //---------------------------------------------------
1442                if(use_GP){
1443                    int ngphits_p=0;
1444                    int ngphits_i=0;
1445                    float toll = 0.02; //200 micron
1446                    for(int ih=0; ih<GetGPamela()->Nthspe; ih++){
1447                        int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
1448                        if(
1449                            tp &&
1450                            tp->YGood(ip) &&
1451                            fabs(tp->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1452                            true) ngphits_p++;
1453                        if( ti &&
1454                            ti->YGood(ip) &&
1455                            fabs(ti->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1456                            true) ngphits_i++;
1457                    }
1458                    if(
1459                        ngphits_p > ngphits_i &&
1460                        true){
1461                        tp_score++ ;
1462                        totp_score++ ;                  
1463                    }
1464                    if(
1465                        ngphits_p < ngphits_i &&
1466                        true){
1467                        ti_score++ ;
1468                        toti_score++ ;                  
1469                    }
1470                }
1471    
1472    
1473                // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1474              // the winner is....              // the winner is....
1475              // ------------------------                  // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1476              if      (tp_score > ti_score) ts = tp;//the track sorted by the tracker!!              if      (tp_score > ti_score) {
1477              else if (tp_score < ti_score) ts = ti;//its image!!          
1478              else {  
1479                  ts = tp;              }else if (tp_score < ti_score) {
1480  //                              cout << "Warning - track image ambiguity not solved" << endl;  
1481  //                              cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;  
1482                    ts = ti;//its image!!
1483                    cs = ci;
1484                    os = oi;
1485                    rs = ri;
1486                    Int_t totis = toti_score;
1487    
1488                    ti = tp;//its image!!
1489                    ci = cp;
1490                    oi = op;
1491                    ri = rp;
1492    
1493                    tp = ts;//its image!!
1494                    cp = cs;
1495                    op = os;
1496                    rp = rs;
1497    
1498                    toti_score = totp_score;
1499                    totp_score = totis;
1500    
1501                    
1502                }else {
1503    
1504    //      cout << "Warning - track image ambiguity not solved" << endl;
1505    
1506              };              };
1507                            
1508          }else{          }else{
1509              ts = tp;              totp_score = 1;
1510                toti_score = 0;
1511          
1512                //      ts = tp;
1513                //      cs = cp;
1514                //      os = op;
1515          };          };
1516                    
1517  //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;          //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
1518          sorted_tracks->Add(ts);//save the track in the sorted array          //      sorted_tracks->Add(ts);//save the track in the sorted array
1519  //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;          //      sorted_tracks.Add(ts);//save the track in the sorted array
1520                    //      sorted_tracks.Add(tp);//save the track in the sorted array
1521      };          //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
1522            //      cout<<"o "<<tp<<endl;
1523            //      cout<<"o "<<cp<<endl;
1524            //      cout<<"o "<<op<<endl;
1525    
1526            new(ttsorted[i]) PamTrack(tp,cp,op,rp);
1527            new(ttimage[i])  PamTrack(ti,ci,oi,ri);
1528    
1529            ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);
1530            ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);
1531            ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);
1532            ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);
1533        };
1534    
1535        if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
1536            cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;
1537            tsorted->Delete(); tsorted=0;
1538            timage->Delete(); timage=0;    
1539        }
1540    
1541      //Restore Object count      //Restore Object count
1542      //To save space in the table keeping track of all referenced objects      //To save space in the table keeping track of all referenced objects
1543      //we assume that our events do not address each other. We reset the      //We reset the object count to what it was at the beginning of the event.
     //object count to what it was at the beginning of the event.  
1544      TProcessID::SetObjectCount(ObjectNumber);      TProcessID::SetObjectCount(ObjectNumber);
1545            
1546  };  };
# Line 430  void PamLevel2::SortTracks(TString how){ Line 1552  void PamLevel2::SortTracks(TString how){
1552   * 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.
1553   * 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.
1554   */   */
1555  TRefArray *PamLevel2::GetTracks(){  // TRefArray *PamLevel2::GetTracks(){
1556    
1557    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
1558    //     SortTracks("+CAL+TOF");
1559    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
1560    
1561    // //   return  sorted_tracks;
1562    //     return &sorted_tracks;
1563        
1564    //  };
1565    TClonesArray *PamLevel2::GetTracks(){
1566    
1567  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1568      SortTracks("+CAL+TOF");      SortTracks();
1569  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1570    
1571      return sorted_tracks;      return tsorted;
1572   };      
1573    };
1574  //--------------------------------------  //--------------------------------------
1575   //  //
1576   //  //
1577  //--------------------------------------  //--------------------------------------
1578  /**  /**
1579   * Retrieves the it-th Pamela "physical" track.   * Retrieves the it-th Pamela "physical" track.
# Line 448  TRefArray *PamLevel2::GetTracks(){ Line 1581  TRefArray *PamLevel2::GetTracks(){
1581   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
1582   */   */
1583  PamTrack *PamLevel2::GetTrack(int it){  PamTrack *PamLevel2::GetTrack(int it){
1584    
1585    //    if(!trk2_obj) return 0;
1586                    
1587    // //  *-*-*-*+-*-*-*-*-*-*-*-*-*
1588    //     SortTracks("+CAL+TOF");
1589    // //  *-*-*-*-*-*-*-*-*-*-*-*-*
1590    // //    if(!sorted_tracks)return 0;
1591    //     if(sorted_tracks.IsEmpty())return 0;
1592    
1593    //     PamTrack *track = 0;
1594        
1595    //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() && it<sorted_tracks.GetEntriesFast() ){    
1596    //      TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);
1597    //      track = GetPamTrackAlong(t);
1598    //     }else{
1599    //      cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
1600    //     };
1601        
1602    //     return track;
1603    
1604    //    cout << "PamLevel2::GetTrack(int it) "<<endl;
1605  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1606      SortTracks("+CAL+TOF");      SortTracks();
1607  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1608            if(!tsorted)return 0;
1609        if(!tsorted->GetEntries())return 0;
1610    
1611      PamTrack *track = 0;      PamTrack *track = 0;
1612            
1613      if( it >=0 && it < TrkLevel2::GetNTracks() && it<sorted_tracks->GetEntriesFast() ){      if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks()){
1614          TrkTrack   *t = (TrkTrack*)sorted_tracks->At(it);  //      TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);
1615          track = GetPamTrackAlong(t);  //      track = GetPamTrackAlong(t);
1616            TClonesArray &t = *(tsorted);
1617            track = (PamTrack*)t[it];
1618            
1619      }else{      }else{
1620          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;
1621      };      };
1622            
1623      return track;      return track;
# Line 477  PamTrack *PamLevel2::GetTrack(int it){ Line 1635  PamTrack *PamLevel2::GetTrack(int it){
1635  PamTrack *PamLevel2::GetTrackImage(int it){  PamTrack *PamLevel2::GetTrackImage(int it){
1636    
1637  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1638      SortTracks("+CAL+TOF");      SortTracks();
1639  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1640        if(!timage)return 0;
1641        if(!timage->GetEntries())return 0;
1642            
1643      PamTrack *image = 0;      PamTrack *image = 0;
1644            
1645      if( it >=0 && it < TrkLevel2::GetNTracks() ){      if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){
1646          TrkTrack *temp = (TrkTrack*)sorted_tracks->At(it);          TClonesArray &t = *(tsorted);
1647          if( temp->HasImage() ){          PamTrack *temp = (PamTrack*)t[it];
1648              TrkTrack   *t = TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());          if( temp->GetTrkTrack()->HasImage() ){
1649              image = GetPamTrackAlong(t);              TClonesArray &t = *(timage);
1650                image = (PamTrack*)t[it];
1651          }else{          }else{
1652              cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;  //          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
1653          };          };
1654      }else{      }else{
1655          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;
1656      };      };
1657            
1658      return image;      return image;
# Line 507  PamTrack *PamLevel2::GetTrackImage(int i Line 1668  PamTrack *PamLevel2::GetTrackImage(int i
1668   * @param detlist String to select trees to be included   * @param detlist String to select trees to be included
1669   * @return Pointer to a TTree   * @return Pointer to a TTree
1670   */   */
1671  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist="+ALL"){  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){
   
 //      cout << "WARNING!!! -- obsolete method -- \n";  
 //      cout << "better use TChain *PamLevel2::GetPamTree(TList*, TString) \n";  
1672    
1673        if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {
1674            cout << "+AUTO"<<endl;
1675            GetWhichTrees(f);
1676        };
1677      SetWhichTrees(detlist);      SetWhichTrees(detlist);
     TTree *Trout =0;  
1678    
1679        if ( pam_tree ){
1680            printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");
1681            return pam_tree;
1682        };
1683        //
1684    
1685        cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
1686    
1687    //    SetWhichTrees(detlist);
1688    
1689        TTree *Trout =0;
1690    
1691      TString fname = f->GetName();      TString fname = f->GetName();
1692      if(!CheckLevel2File(fname))return NULL;      if(!CheckLevel2File(fname))return NULL;
1693    
1694        //    UInt_t *found=0;    
1695    
1696        cout<< "GetPamTree(TFile*,TString): detector list --> ";
1697        if(TRK1)cout<<"TRK1 ";
1698        if(TRK2)cout<<"TRK2 ";
1699        if(TRKh)cout<<"TRKH ";
1700        if(CAL1)cout<<"CAL1 ";
1701        if(CAL2)cout<<"CAL2 ";
1702        if(TOF)cout<<"TOF ";
1703        if(TRG)cout<<"TRG ";
1704        if(AC)cout<<"AC ";
1705        if(ND)cout<<"ND ";
1706        if(S4)cout<<"S4 ";
1707        if(ORB)cout<<"ORB ";
1708        if(GP)cout<<"GP ";
1709        cout << endl;
1710        if(SELLI && SELLI!=2)cout<<">>> Found selection-list <<<"<<endl; //EMILIANO
1711    
1712        f->cd();
1713    
1714  // Tracker  // Tracker
1715      TTree *T = (TTree*)f->Get("Tracker");      TTree *T = (TTree*)f->Get("Tracker");
1716      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
1717          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1718    //      else    T->SetBranchStatus("TrkLevel2",0,found);
1719          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
1720          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1721    //      else    T->SetBranchStatus("TrkLevel1",0,found);
1722          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
1723          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1724    //      else    T->SetBranchStatus("TrkHough",0,found);
1725          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
1726          if(!Trout)Trout=T;          if(!Trout)Trout=T;
1727          else Trout->AddFriend(T);          else Trout->AddFriend(T);
# Line 538  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1732  TTree *PamLevel2::GetPamTree(TFile *f, T
1732      TTree *C = (TTree*)f->Get("Calorimeter");      TTree *C = (TTree*)f->Get("Calorimeter");
1733      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
1734          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1735    //      else    C->SetBranchStatus("CaloLevel2",0,found);
1736          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
1737          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1738    //      else    C->SetBranchStatus("CaloLevel1",0,found);
1739          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
1740          if(!Trout)Trout=C;          if(!Trout)Trout=C;
1741          else Trout->AddFriend(C);          else Trout->AddFriend(C);
1742      }else{      }else{
1743          cout << "Calorimeter  : missing tree"<<endl;          cout << "Calorimeter  : missing tree"<<endl;
1744      };      };
1745    
1746      // ToF          // ToF    
1747      TTree *O = (TTree*)f->Get("ToF");      TTree *O = (TTree*)f->Get("ToF");
1748      if(O && TOF) {      if(O && TOF) {
# Line 561  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1758  TTree *PamLevel2::GetPamTree(TFile *f, T
1758      if(R && TRG) {      if(R && TRG) {
1759          R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));          R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1760          cout << "Trigger      : set branch address TrigLevel2"<<endl;          cout << "Trigger      : set branch address TrigLevel2"<<endl;
1761          if(!Trout)Trout=O;          if(!Trout)Trout=R;
1762          else Trout->AddFriend(R);          else Trout->AddFriend(R);
1763      }else{      }else{
1764          cout << "Trigger      : missing tree"<<endl;          cout << "Trigger      : missing tree"<<endl;
# Line 571  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1768  TTree *PamLevel2::GetPamTree(TFile *f, T
1768      if(S && S4) {      if(S && S4) {
1769          S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));          S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1770          cout << "S4           : set branch address S4Level2"<<endl;          cout << "S4           : set branch address S4Level2"<<endl;
1771          if(!Trout)Trout=O;          if(!Trout)Trout=S;
1772          else Trout->AddFriend(S);          else Trout->AddFriend(S);
1773      }else{      }else{
1774          cout << "S4           : missing tree"<<endl;          cout << "S4           : missing tree"<<endl;
# Line 581  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1778  TTree *PamLevel2::GetPamTree(TFile *f, T
1778      if(N && ND) {      if(N && ND) {
1779          N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));          N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1780          cout << "NeutronD     : set branch address NDLevel2"<<endl;          cout << "NeutronD     : set branch address NDLevel2"<<endl;
1781          if(!Trout)Trout=O;          if(!Trout)Trout=N;
1782          else Trout->AddFriend(N);          else Trout->AddFriend(N);
1783      }else{      }else{
1784          cout << "NeutronD     : missing tree"<<endl;          cout << "NeutronD     : missing tree"<<endl;
# Line 591  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1788  TTree *PamLevel2::GetPamTree(TFile *f, T
1788      if(A && AC) {      if(A && AC) {
1789          A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));          A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1790          cout << "Anticounter  : set branch address AcLevel2"<<endl;          cout << "Anticounter  : set branch address AcLevel2"<<endl;
1791          if(!Trout)Trout=O;          if(!Trout)Trout=A;
1792          else Trout->AddFriend(A);          else Trout->AddFriend(A);
1793      }else{      }else{
1794          cout << "Anticounter  : missing tree"<<endl;          cout << "Anticounter  : missing tree"<<endl;
1795      };      };
1796      // Orbital Info      // Orbital Info
1797          TTree *B = (TTree*)f->Get("OrbitalInfo");      TTree *B = (TTree*)f->Get("OrbitalInfo");
1798          if(B && ORB) {      if(B && ORB) {
1799                  B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1800                  cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1801                  if(!Trout)Trout=O;          if(!Trout)Trout=B;
1802                  else Trout->AddFriend(B);          else Trout->AddFriend(B);
1803          }else{      }else{
1804                  cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
1805          };      };
1806    
1807        // GPamela
1808        TTree *G = (TTree*)f->Get("h20");
1809        if(G && GP) {
1810            if(!gp_obj)gp_obj=new GPamela();
1811    //      ------------------------------------
1812    //      ATTENZIONE!!!
1813    //      non so per quale arcano motivo,
1814    //      per l'albero di gpamela il branch address lo devo settare
1815    //      DOPO aver fatto friend
1816    //      FGRRRVZZZZUTSALKJMSLKJ!!!
1817    //      ------------------------------------
1818    //      gp_obj->SetBranchAddress(G); //ho dovuto fare in maniera diversa dagli altri
1819    //      cout << "h20          : set branch address GPamela "<<endl;
1820            if(!Trout)Trout=G;
1821            else Trout->AddFriend(G);
1822        }else{
1823    //      cout << "h20          : missing tree"<<endl;
1824        };
1825    
1826    
1827        TTree *L = (TTree*)f->Get("SelectionList");
1828        if(L && SELLI==1) {
1829            cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemented!!!!"<<endl;
1830            sel_tree = 0;
1831        }else{
1832            cout << "SelectionList  : missing tree"<<endl;
1833        };
1834            
1835          cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1836                    
1837          return Trout;  //      ------------------------------------
1838    //      ATTENZIONE!!!
1839    //      non so per quale arcano motivo,
1840    //      per l'albero di gpamela il branch address lo devo settare
1841    //      DOPO aver fatto friend
1842    //      FGRRRVZZZZUTSALKJMSLKJ!!!
1843    //      ------------------------------------
1844        if(G && GP) {      
1845            gp_obj->SetBranchAddress(Trout); //ho dovuto fare in maniera diversa dagli altri
1846            cout << "h20          : set branch address GPamela "<<endl;
1847        }else{
1848            cout << "h20          : missing tree"<<endl;
1849        };
1850    
1851        pam_tree = (TChain*)Trout;
1852        
1853        return Trout;
1854            
1855  }  }
1856  //--------------------------------------  //--------------------------------------
# Line 627  TList*  PamLevel2::GetListOfLevel2Files( Line 1868  TList*  PamLevel2::GetListOfLevel2Files(
1868                    
1869      TString wdir = gSystem->WorkingDirectory();      TString wdir = gSystem->WorkingDirectory();
1870            
1871      if(ddir=="")ddir = wdir;      //    if(ddir=="")ddir = wdir;
1872  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1873      cout << "Level2 data directory : "<<  ddir << endl;      if ( ddir != ""){
1874                cout << "Level2 data directory : "<<  ddir << endl;
1875        } else {
1876            cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory " << endl;
1877        };
1878      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
1879      contents->SetOwner();      contents->SetOwner();
1880            
1881      char *fullpath;  //    char *fullpath;
1882    //    const char *fullpath;
1883            
1884      // if no input file list is given:        // if no input file list is given:  
1885      if ( flisttxt != "" ){      if ( flisttxt != "" ){
1886                    
1887          if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) )return 0;  //      if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){        
1888            //      if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){
1889  //              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));  //          cout <<"File "<<flisttxt<<" not found"<<endl;
1890          flisttxt = fullpath;  //          return 0;
1891            //      }      
1892          if( !gSystem->ChangeDirectory(ddir) )return 0;  //      flisttxt = fullpath;
1893            if ( !flisttxt.EndsWith(".root") ){
1894    
1895                flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1896    
1897                if( !gSystem->ChangeDirectory(ddir) ){
1898                    cout << "Cannot change directory : "<<ddir<<endl;
1899                    return 0;
1900                }
1901                    
1902          cout <<"Input file list : " << flisttxt <<endl;              cout <<"Input file list : " << flisttxt <<endl;
1903          ifstream in;              ifstream in;
1904          in.open(flisttxt, ios::in); //open input file list              in.open(flisttxt, ios::in); //open input file list
1905          int line=0;              if(!in.good()){
1906          while (1) {                  cout <<" ERROR opening the file "<<endl;
1907              TString file;                  gSystem->ChangeDirectory(wdir); // back to the working directory
1908              in >> file;                  return 0;
1909              if (!in.good()) break;              }  
1910              line++;              int line=0;
1911                while (1) {
1912                    TString file;
1913                    in >> file;
1914                    if (!in.good()) break;
1915                    line++;
1916  //          cout <<"(1) " << file << endl;  //          cout <<"(1) " << file << endl;
1917              if(file.IsNull()){                  if(file.IsNull()){
1918                  cout << "-- list interrupted at line "<<line <<endl;                      cout << "-- list interrupted at line "<<line <<endl;
1919                  break;                      break;
1920              }                  }
1921              if(file.Contains("#"))file = file(0,file.First("#"));                  if(file.Contains("#"))file = file(0,file.First("#"));
1922  //          cout <<"(2) " << file << endl;  //          cout <<"(2) " << file << endl;
1923              if( gSystem->IsFileInIncludePath(file,&fullpath) ){  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1924    //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
1925                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list                  if( file.EndsWith(".root") ){
1926                        TString filedir;
1927              }else{                      if (ddir != ""){
1928                            filedir = ddir; // take the input dir
1929                        } else {
1930                            gSystem->ChangeDirectory(wdir); // back to the working directory
1931                            filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir
1932                        };
1933                        char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));
1934                        contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1935                        delete fullpath;
1936                    }
1937    //          }else{
1938  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1939    //          };
1940              };              };
1941          };              in.close();
1942          in.close();          } else {
1943                        if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));
1944                char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1945                contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1946                delete fullpath;
1947            };      
1948      }else{      }else{
1949                    
1950          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
1951          cout << "Check for existing root files."<<endl;          cout << "Check for existing root files."<<endl;
1952  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
1953                    if ( ddir == "" ){
1954                ddir = wdir;
1955                cout << "Level2 data directory : "<<  ddir << endl;
1956            };
1957    
1958          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1959          TList *temp = datadir->GetListOfFiles();          TList *temp = datadir->GetListOfFiles();
1960  //              temp->Print();  //              temp->Print();
# Line 690  TList*  PamLevel2::GetListOfLevel2Files( Line 1967  TList*  PamLevel2::GetListOfLevel2Files(
1967          while ( (questo = (TSystemFile*) next()) ) {          while ( (questo = (TSystemFile*) next()) ) {
1968              TString name =  questo-> GetName();              TString name =  questo-> GetName();
1969              if( name.EndsWith(".root") ){              if( name.EndsWith(".root") ){
1970                  char *fullpath;  //              const char *fullpath = gSystem->FindFile(ddir,name);
1971                  gSystem->IsFileInIncludePath(name,&fullpath);  //              char *fullpath;
1972    //              gSystem->IsFileInIncludePath(name,&fullpath);
1973                    char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(name));
1974                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));
1975                    delete fullpath;
1976              };              };
1977          }          }
1978          delete temp;          delete temp;
# Line 702  TList*  PamLevel2::GetListOfLevel2Files( Line 1982  TList*  PamLevel2::GetListOfLevel2Files(
1982      gSystem->ChangeDirectory(wdir); // back to the working directory      gSystem->ChangeDirectory(wdir); // back to the working directory
1983  //      cout << endl << "Selected files:" << endl;  //      cout << endl << "Selected files:" << endl;
1984  //      contents->Print();  //      contents->Print();
1985      cout << contents->GetEntries()<<" files selected\n";      cout << contents->GetEntries()<<" files \n";
1986  //      cout << endl;  //      cout << endl;
1987  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;
1988      return contents;      return contents;
# Line 717  TList*  PamLevel2::GetListOfLevel2Files( Line 1997  TList*  PamLevel2::GetListOfLevel2Files(
1997   * @param detlist String to select trees to be included   * @param detlist String to select trees to be included
1998   * @return Pointer to a TChain   * @return Pointer to a TChain
1999   */   */
2000  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist="+ALL"){  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){
2001        //
2002        //
2003        //
2004        if ( pam_tree ){
2005            printf("WARNING: TChain *PamLevel2::GetPamTree(TList *fl, TString detlist) -- pam_tree already exists!\n ");
2006            return pam_tree;
2007        };
2008        //
2009        
2010        TChain *Trout =0;
2011    
2012        // -------------------------------------------
2013        // set flags to include/exclude trees/branches
2014        // -------------------------------------------
2015        if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {
2016            if( fl->GetEntries()>0 ){
2017                cout << "+AUTO"<<endl;
2018                TFile *fprimo = new TFile( fl->At(0)->GetName() );
2019                GetWhichTrees(fprimo);
2020                fprimo->Close();// AAAAARGGGGGHHHHH!!!!!!! non commentare questa riga, altrimenti si incasina il TChain
2021                fprimo->Delete();
2022            }
2023        };
2024        SetWhichTrees(detlist);    
2025    
 //      TChain *Tout=0;  
 //    if(Tout)Tout->Delete();  
 //    Tout = NULL;  
       
     TChain *Tout =0;  
2026    
2027      SetWhichTrees(detlist);      // -------------------------------------------
2028            // build chains
2029        // -------------------------------------------
2030      TChain *T = 0;            TChain *T = 0;      
2031      TChain *C = 0;      TChain *C = 0;
2032      TChain *O = 0;      TChain *O = 0;
# Line 735  TChain *PamLevel2::GetPamTree(TList *fl, Line 2035  TChain *PamLevel2::GetPamTree(TList *fl,
2035      TChain *N = 0;      TChain *N = 0;
2036      TChain *A = 0;      TChain *A = 0;
2037      TChain *B = 0;      TChain *B = 0;
2038        TChain *G = 0;
2039    
2040        TChain *L = 0;
2041            
2042      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
2043      if(CAL2||CAL1) C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
2044      if(TOF) O = new TChain("ToF");      if(TOF)              O = new TChain("ToF");
2045      if(TRG) R = new TChain("Trigger");      if(TRG)              R = new TChain("Trigger");
2046      if(S4)  S = new TChain("S4");      if(S4)               S = new TChain("S4");
2047      if(ND)  N = new TChain("NeutronD");      if(ND)               N = new TChain("NeutronD");
2048      if(AC)  A = new TChain("Anticounter");      if(AC)               A = new TChain("Anticounter");
2049      if(ORB) B = new TChain("OrbitalInfo");      if(ORB)              B = new TChain("OrbitalInfo");
2050        if(GP)               G = new TChain("h20");
2051        L = new TChain("SelectionList");
2052            
2053      // loop over files and create chains              // loop over files and create chains        
2054      TIter next(fl);      TIter next(fl);
2055      TSystemFile *questo = 0;      TSystemFile *questo = 0;
2056      while ( (questo = (TSystemFile*) next()) ) {      while ( (questo = (TSystemFile*) next()) ) {
2057          TString name =  questo->GetName();          TString name =  questo->GetName();
2058  //              cout << "File: "<< name << endl;          cout << "File: "<< name << endl;
2059          if( CheckLevel2File(name) ){          if( CheckLevel2File(name) ){
2060              if(TRK2||TRK1||TRKh) T->Add(name);              if(TRK2||TRK1||TRKh) T->Add(name);
2061              if(CAL1||CAL2) C->Add(name);              if(CAL1||CAL2)       C->Add(name);
2062              if(TOF) O->Add(name);              if(TOF)              O->Add(name);
2063              if(TRG) R->Add(name);              if(TRG)              R->Add(name);
2064              if(S4)  S->Add(name);              if(S4)               S->Add(name);
2065              if(ND)  N->Add(name);              if(ND)               N->Add(name);
2066              if(AC)  A->Add(name);              if(AC)               A->Add(name);
2067              if(ORB) B->Add(name);              if(ORB)              B->Add(name);
2068                if(GP)               G->Add(name);
2069                if(SELLI==1)         L->Add(name);
2070          };          };
2071      }      };
       
     cout << "done chain \n";  
2072            
2073        cout << "done chains\n";
2074        cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2075    
2076    
2077        // -------------------------------------------
2078        // make friends
2079        // -------------------------------------------
2080    
2081    // Tracker
2082        cout << "Friends: "<<endl;
2083        if(T && (TRK2||TRK1||TRKh)) {
2084            if(!Trout)Trout=T;
2085            else Trout->AddFriend("Tracker");
2086    //      cout << "+Tacker"<<endl;
2087        };
2088      // Calorimeter      // Calorimeter
2089      if(CAL2||CAL1) {                  if(C && (CAL2||CAL1)) {
2090          if(!Tout)Tout=C;          if(!Trout)Trout=C;
2091          else Tout->AddFriend("Calorimeter");          else Trout->AddFriend("Calorimeter");
2092    //      cout << "+Calorimeter"<<endl;
2093      };      };
2094      // ToF          // ToF    
2095      if(TOF) {      if(O && TOF) {
2096          if(!Tout)Tout=O;          if(!Trout)Trout=O;
2097          else Tout->AddFriend("ToF");          else Trout->AddFriend("ToF");
2098    //      cout << "+ToF"<<endl;
2099      };      };
     // Tracker  
     if(TRK2||TRK1||TRKh){  
         if(!Tout)Tout=T;  
         else Tout->AddFriend("Tracker");  
     }  
2100      // Trigger      // Trigger
2101      if(TRG) {      if(R && TRG) {
2102          if(!Tout)Tout=R;          if(!Trout)Trout=O;
2103          else Tout->AddFriend("Trigger");          else Trout->AddFriend("Trigger");
2104    //      cout << "+Trigger"<<endl;
2105      };      };
2106      // S4      // S4
2107      if(S4) {      if(S && S4) {
2108          if(!Tout)Tout=S;          if(!Trout)Trout=O;
2109          else Tout->AddFriend("S4");          else Trout->AddFriend("S4");
2110    //      cout << "+S4"<<endl;
2111      };      };
2112      // Neutron Detector      // Neutron Detector
2113      if(ND) {      if(N && ND) {
2114          if(!Tout)Tout=N;          if(!Trout)Trout=O;
2115          else Tout->AddFriend("NeutronD");          else Trout->AddFriend("NeutronD");
2116    //      cout << "+NeutronD"<<endl;
2117      };      };
2118      // Anticounters      // Anticounters
2119      if(AC) {      if(A && AC) {
2120          if(!Tout)Tout=A;          if(!Trout)Trout=O;
2121          else Tout->AddFriend("Anticounter");          else Trout->AddFriend("Anticounter");
2122    //      cout << "+Anticounter"<<endl;
2123      };      };
2124      // OrbitalInfo      // Orbital Info
2125      if(ORB) {      if(B && ORB) {
2126          if(!Tout)Tout=B;          if(!Trout)Trout=O;
2127          else Tout->AddFriend("OrbitalInfo");          else Trout->AddFriend("OrbitalInfo");
2128    //      cout << "+OrbitalInfo"<<endl;
2129        };
2130        // GPamela
2131        if(G && GP) {
2132            if(!Trout)Trout=G;
2133            else Trout->AddFriend("h20");
2134    //      cout << "+h20"<<endl;
2135        };
2136    
2137    //  =====================================
2138    //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND
2139    //  =====================================
2140        SetBranchAddress(Trout);
2141    
2142    
2143    //  ------------------------------------
2144    //  finally handle selection trees...
2145    //  (it is not friend of pamela tree)
2146    //  ------------------------------------
2147    
2148        cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2149    
2150        // Selection List
2151        if(L && SELLI==1) {
2152            cout<<">>> Found selection-list <<<"<<endl;
2153    //      L->SetBranchAddress("RunEntry",&irun);
2154            L->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2155            cout << "SelectionList: set branch address RunEntry"<<endl;
2156            L->SetBranchAddress("EventEntry",&irunentry);
2157            cout << "SelectionList: set branch address EventEntry"<<endl;
2158            sel_tree = L;
2159    //      if(!Trout)Trout=O;
2160    //      else Trout->AddFriend("SelectionList");
2161            cout << "+SelectionList"<<endl;
2162            cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2163        }else{
2164    //      cout << "SelectionList  : missing tree"<<endl;
2165            if(L)L->Delete();
2166      };      };
2167    
2168    //  --------------------------------------------
2169    //  return the pamela chain with all the friends
2170    //  --------------------------------------------
2171    
2172        pam_tree = Trout;
2173            
2174  //    cout<<endl<<" Number of entries: "<<Tout->GetEntries()<<endl<<endl;      return Trout;
       
 //    if( Tout->GetEntries() )PamLevel2::SetBranchAddress();  
     if( Tout->GetEntries() )PamLevel2::SetBranchAddress( Tout );  
       
     return Tout;  
2175  }  }
2176    
2177    
# Line 836  void PamLevel2::SetBranchAddress(TTree * Line 2196  void PamLevel2::SetBranchAddress(TTree *
2196      ND     = ND  & t->GetBranchStatus("NDLevel2");      ND     = ND  & t->GetBranchStatus("NDLevel2");
2197      AC     = AC  & t->GetBranchStatus("AcLevel2");      AC     = AC  & t->GetBranchStatus("AcLevel2");
2198      ORB    = ORB & t->GetBranchStatus("OrbitalInfo");      ORB    = ORB & t->GetBranchStatus("OrbitalInfo");
2199        GP     = GP  & t->GetBranchStatus("h20");
2200    
2201    
2202      // Tracker      // Tracker
# Line 892  void PamLevel2::SetBranchAddress(TTree * Line 2253  void PamLevel2::SetBranchAddress(TTree *
2253          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
2254          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
2255      };      };
2256        // GPamela
2257        if(GP) {
2258    //      GetPointerTo("GPamela");
2259            if(!gp_obj)gp_obj = new GPamela();
2260    //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2261    // //   t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2262            if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2263            else      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2264    
2265            cout << "h20          : set branch address GPamela "<<endl;
2266        };
2267            
2268  }  }
2269  /**  /**
# Line 899  void PamLevel2::SetBranchAddress(TTree * Line 2271  void PamLevel2::SetBranchAddress(TTree *
2271   */   */
2272  void PamLevel2::SetBranchAddress(TChain *t){  void PamLevel2::SetBranchAddress(TChain *t){
2273    
2274      TRK2    = TRK2 & t->GetBranchStatus("TrkLevel2");  //     TRK2    = TRK2 & t->GetBranchStatus("TrkLevel2");
2275      TRK1    = TRK1 & t->GetBranchStatus("TrkLevel1");  //     TRK1    = TRK1 & t->GetBranchStatus("TrkLevel1");
2276      TRKh    = TRKh & t->GetBranchStatus("TrkHough");  //     TRKh    = TRKh & t->GetBranchStatus("TrkHough");
2277      CAL1    = CAL1 & t->GetBranchStatus("CaloLevel1");  //     CAL1    = CAL1 & t->GetBranchStatus("CaloLevel1");
2278      CAL2    = CAL2 & t->GetBranchStatus("CaloLevel2");  //     CAL2    = CAL2 & t->GetBranchStatus("CaloLevel2");
2279      TOF    = TOF & t->GetBranchStatus("ToFLevel2");  //     TOF    = TOF & t->GetBranchStatus("ToFLevel2");
2280      TRG    = TRG & t->GetBranchStatus("TrigLevel2");  //     TRG    = TRG & t->GetBranchStatus("TrigLevel2");
2281      S4     = S4  & t->GetBranchStatus("S4Level2");  //     S4     = S4  & t->GetBranchStatus("S4Level2");
2282      ND     = ND  & t->GetBranchStatus("NDLevel2");  //     ND     = ND  & t->GetBranchStatus("NDLevel2");
2283      AC     = AC  & t->GetBranchStatus("AcLevel2");  //     AC     = AC  & t->GetBranchStatus("AcLevel2");
2284      ORB    = ORB & t->GetBranchStatus("OrbitalInfo");  //     ORB    = ORB & t->GetBranchStatus("OrbitalInfo");
2285    //    GP     = GP & t->GetBranchStatus("h20");
2286    
2287      // Tracker      // Tracker
2288       if(TRK2) {      if(TRK2) {
2289          t->SetBranchAddress("TrkLevel2", this->GetPointerTo("TrkLevel2"));          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
2290          cout << "Tracker      : set branch address TrkLevel2"<<endl;          cout << "Tracker      : set branch address TrkLevel2"<<endl;
2291      };      };
2292      if(TRK1) {      if(TRK1) {
2293          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
2294          cout << "Tracker      : set branch address TrkLevel1"<<endl;          cout << "Tracker      : set branch address TrkLevel1"<<endl;
2295      };      };
2296       if(TRKh) {      if(TRKh) {
2297          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
2298          cout << "Tracker      : set branch address TrkHough"<<endl;          cout << "Tracker      : set branch address TrkHough"<<endl;
2299       };      };
2300            
2301      // Calorimeter      // Calorimeter
2302      if(CAL2) {      if(CAL2) {
# Line 965  void PamLevel2::SetBranchAddress(TChain Line 2338  void PamLevel2::SetBranchAddress(TChain
2338          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
2339          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
2340      };      };
2341            // GPamela
2342    //    cout <<"GP "<<GP<<endl;
2343        if(GP) {
2344    //      GetPointerTo("GPamela");
2345            if(!gp_obj)gp_obj = new GPamela();
2346            if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2347            else      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2348    //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2349            cout << "h20          : set branch address GPamela "<<endl;
2350        };
2351        // SelectionList
2352    //     if(SELLI==1){
2353    //      t->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2354    //      cout << "SelectionList: set branch address RunEntry"<<endl;
2355    //      t->SetBranchAddress("EventEntry",&irunentry);
2356    //      cout << "SelectionList: set branch address EventEntry"<<endl;
2357            
2358    //     }
2359    
2360  }  }
2361    
 // void* PamLevel2::GetPointerToTrk()  {return &trk2_obj;};  
 // void* PamLevel2::GetPointerToTrk(int s){  
 //     switch (s) {  
 //     case 1:  return &trk1_obj;  
 //     case 2:  return &trk2_obj;  
 //     case 3:  return &trkh_obj;  
 //     default: return 0;  
 //     };  
 // };  
 // void* PamLevel2::GetPointerToCalo() {return &calo2_obj; };  
 // void*       GetPointerToCalo(int s){  
 //     switch (s) {  
 //     case 1:  return &calo1_obj;  
 //     case 2:  return &calo2_obj;  
 //     default: return 0;  
 //     };  
 // };  
 // void*       GetPointerToToF()  {return &tof_obj;  };  
 // void*       GetPointerTo("TrigLevel2") {return &trig_obj; };  
 // void*       GetPointerTo("S4Level2")   {return &s4_obj;   };  
 // void*       GetPointerTo("NDLevel2")   {return &nd_obj;   };  
 // void*       GetPointerTo("AcLevel2")   {return &ac_obj;   };  
 // void*       GetPointerTo("OrbitalInfo")  {return &orb_obj;  };  
 // void*       GetPointerTo("RunInfo")  {return &run_obj;  };  
2362    
2363  //--------------------------------------  //--------------------------------------
2364  //  //
# Line 1003  void PamLevel2::SetBranchAddress(TChain Line 2370  void PamLevel2::SetBranchAddress(TChain
2370   * @return Pointer to a TChain   * @return Pointer to a TChain
2371   */   */
2372  TChain *PamLevel2::GetRunTree(TList *fl){  TChain *PamLevel2::GetRunTree(TList *fl){
2373                //
2374        //
2375        //
2376        if ( run_tree ){
2377            printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
2378            return run_tree;
2379        };  
2380        //
2381    
2382    
2383      TChain *R = new TChain("Run");      TChain *R = new TChain("Run");
2384            
2385      // loop over files and create chains              // loop over files and create chains        
# Line 1017  TChain *PamLevel2::GetRunTree(TList *fl) Line 2393  TChain *PamLevel2::GetRunTree(TList *fl)
2393          };          };
2394      }      }
2395            
2396      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));  
2397      cout << "Run         : set branch address RunInfo"<<endl;      if(RUN && R->GetNtrees()){
2398        
2399            R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
2400            cout << "Run         : set branch address RunInfo"<<endl;
2401            R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2402            cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
2403    
2404            irunoffset = new int[R->GetNtrees()];
2405            if(DBG){
2406                cout << "----------------------------------------------------"<<endl;
2407                cout << "irun\t | ";
2408                cout << "tree\t |";
2409    //      cout << "offset\t |";
2410                cout << "RUN\t";
2411                cout << "FRAG\t";
2412                cout << "NEVENTS\t";
2413                cout << "absolute time\t\t\t";
2414                cout << "on-board time";
2415                cout<<endl;
2416            }
2417            for (Int_t ii=0; ii<R->GetEntries(); ii++){
2418                R->GetEntry(ii);
2419                if(DBG){
2420                    cout << ii<< "\t | ";
2421                    cout << R->GetTreeNumber()<< "\t |";
2422    //          cout << R->GetChainOffset()<< "\t |";
2423                    cout <<GetRunInfo()->ID<<"\t";
2424                    cout <<GetRunInfo()->ID_RUN_FRAG<<"\t";
2425                    cout <<GetRunInfo()->NEVENTS<< "\t";
2426                    cout <<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME <<"\t";
2427                    cout <<GetRunInfo()->RUNHEADER_OBT<<" <---> "<<GetRunInfo()->RUNTRAILER_OBT<<"\t";
2428                    cout <<endl;
2429                }
2430                irunoffset[R->GetTreeNumber()]=R->GetChainOffset();
2431            }
2432            cout << "N.run = "<<R->GetEntries()<<endl;
2433            cout << "----------------------------------------------------"<<endl;
2434    
2435    
2436        }else{
2437            delete R;
2438            R=0;
2439        }
2440            
2441    
2442        run_tree = R;
2443    
2444      return R;      return R;
2445            
2446  }  }
# Line 1033  TChain *PamLevel2::GetRunTree(TList *fl) Line 2454  TChain *PamLevel2::GetRunTree(TList *fl)
2454   * @return Pointer to a TTree   * @return Pointer to a TTree
2455   */   */
2456  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f){
2457        if ( run_tree ){
2458            printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
2459            return run_tree;
2460        };
2461            
2462    
2463        cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
2464    
2465      TTree *R = (TTree*)f->Get("Run");      TTree *T = (TTree*)f->Get("Run");
2466            
2467      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));      if(T){
2468      cout << "Run         : set branch address RunInfo"<<endl;          T->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
2469                cout << "Run         : set branch address RunInfo"<<endl;
2470      return R;          T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2471            cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
2472    
2473        }
2474    
2475        run_tree = (TChain*)T;
2476    
2477        return T;
2478            
2479  }  }
2480    /**
2481     * Update the runinfo informations (to be used to have Run infos event by event basis)
2482     * @param run Pointer to the chain/tree which contains run infos
2483     * @return true if a new run has been read, false if it is still the same run
2484     */
2485    Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){
2486        //
2487        // check if we have already called once GetEntry, if not call it
2488        //
2489        cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- ATTENZIONE --- NON E` MANTENUTA!!!!!!!.... "<<endl;
2490        if(!run){
2491            cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree "<<endl;
2492            return(false);  
2493        }
2494        if ( run->GetEntries() <= 0 ) return(false);
2495        //
2496      
2497        //  Int_t oldrun = irun;
2498        Long64_t oldrun = irun;
2499    
2500        // --------------------------------------
2501        // if it is a full file (not preselected)
2502        // --------------------------------------
2503        if(SELLI==0){
2504    
2505            //
2506            // the absolute time is necessary to relate the event with the run
2507            //
2508            if( !GetOrbitalInfo() && !ISGP){
2509                cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2510                return(false);
2511            }
2512    
2513            ULong64_t abstime = 0;
2514            if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;
2515    
2516    
2517            //
2518            // the first time the routine is called, set run search from the beginning
2519            //
2520            if ( irun < 0LL ){
2521                irun = 0LL;
2522                run->GetEntry(irun);
2523                runfirstentry = 0LL;
2524                runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2525                if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2526              
2527                if( ISGP && run->GetEntries()!=1 ){
2528                    cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl;
2529                    cout << "** WARNING ** run will not be updated"<<endl;
2530                }
2531    
2532            };      
2533            //
2534            if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2535            //
2536            if ( irun == run->GetEntries()-1LL &&
2537                 !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2538                   abstime <= GetRunInfo()->RUNTRAILER_TIME)
2539                ){
2540                irun = -1LL;
2541                irunt = -1LL;
2542                runfirstentry = 0LL;
2543                runlastentry = -1LL;
2544            };
2545            // modificato il controllo sull'aggiornamento del run, per evitare problemi
2546            // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
2547            //
2548            bool fromfirst = true;
2549            //
2550            while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){
2551    //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
2552                irun++;
2553                run->GetEntry(irun);
2554                runfirstentry = runlastentry;
2555                if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;
2556                runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2557    //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2558    //        cout << "runfirstentry "<<runfirstentry<<endl;
2559                //    printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
2560                //    printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);
2561                //    printf(" IDRUN %u \n",GetRunInfo()->ID);
2562                //
2563    //        prevshift = 0;
2564                //
2565                if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){
2566                    printf(" resetting irun  (it should NOT happen!!!)\n");
2567                    fromfirst = false;
2568                    irun = 0;
2569                    run->GetEntry(irun);
2570                    runfirstentry = 0ULL;
2571                    runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2572                    if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2573                };
2574                //
2575            };
2576            //
2577            if (
2578                !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2579                  abstime <= GetRunInfo()->RUNTRAILER_TIME)
2580                ) {
2581                printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n",abstime);
2582                return false;
2583            }
2584            //
2585            if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
2586            //
2587            //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
2588            //
2589            prevshift = 0;
2590            cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2591    //      cout << "runfirstentry "<<runfirstentry<<endl;
2592            return(true);    
2593        };
2594        // ----------------------------------------------------
2595        // if it is a preselected file (there is SelectionList)
2596        // NBNB - the event tree MUST be read first
2597        // ----------------------------------------------------
2598        if(SELLI==1){      
2599            sel_tree->GetEntry(iev);
2600    //      cout << irun << " "<< irunentry << endl;
2601            if(irun != oldrun){
2602                run->GetEntry(irun);
2603                cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2604                prevshift = 0;
2605                return true;
2606            }
2607            return false;
2608        }
2609    
2610        return false;
2611        //
2612    };
2613    
2614    Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){
2615    
2616        if(!run_tree){
2617            cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded"<<endl;
2618            return false;
2619        }
2620        if ( run_tree->GetEntries() <= 0 ) {
2621            cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty"<<endl;
2622            return(false);
2623        }
2624      
2625        Int_t oldrun = irun; // store current run index
2626    
2627        // -----------------------------------------------------------------------
2628        // the first time the routine is called, set run search from the beginning
2629        // -----------------------------------------------------------------------
2630    
2631        if ( irun < 0 ){
2632            irun = 0LL;
2633            irunt = 0LL;
2634            irunentry = 0;
2635            prevshift = 0;
2636            run_tree->GetEntry(irun);
2637            if( !GetOrbitalInfo() )cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated "<<endl;
2638            if ( gltsync ) delete gltsync; //Emiliano
2639            if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection(); //Emiliano
2640            gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0,"ID",dbc); //Emiliano
2641            if ( dbc ) dbc->Close();// Emiliano
2642        };      
2643        // ---------------------------------------------------------------
2644        // retrieve OBT and absolute time of the event
2645        // ---------------------------------------------------------------
2646        ULong64_t abstime = 0LL;
2647        //    ULong64_t obt     = 0LL; // Emiliano
2648        Long64_t obt     = 0LL; // Emiliano, Long64_t GL_TIMESYNC::DBobt(UInt_t obt) since depending on the situation OBT is lowered or boosted
2649        if( GetOrbitalInfo() ){
2650            abstime = GetOrbitalInfo()->absTime;
2651            obt     = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano
2652        }else{
2653            abstime = GetRunInfo()->RUNHEADER_TIME;
2654            obt     = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano
2655        }
2656        
2657    
2658        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2659        // if it is a full file (not preselected)
2660        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2661        if(SELLI==0 || SELLI==2){ // Emiliano
2662    
2663            // ---------------------------------------------------------------
2664            // increment dead and live-time counters
2665            // (only when reading a file not preselected)
2666            // ---------------------------------------------------------------
2667            if(SELLI==0){
2668                if( GetTrigLevel2() ){
2669                    totdltime[0]+=GetTrigLevel2()->dltime[0];
2670                    totdltime[1]+=GetTrigLevel2()->dltime[1];
2671                }
2672                totdltime[2]++;
2673            }
2674    
2675            //
2676            bool fromfirst = true; // first loop over runs
2677    
2678    
2679            // ------------------------------------------------------
2680            // loop over runs to find the one that contains the event
2681            // ------------------------------------------------------
2682            while (
2683                (
2684    //              (
2685    //                  !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2686    //                    abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
2687    //                  !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2688    //                    obt <= GetRunInfo()->RUNTRAILER_OBT)
2689    //                  )
2690                    
2691                    !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2692                      abstime <= GetRunInfo()->RUNTRAILER_TIME)
2693                    ||
2694                    !(obt >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) &&         // additional check on OBT (ms) // Emiliano
2695                      obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT))           // Emiliano
2696                    ||
2697                    GetRunInfo()->NEVENTS==0
2698    //              || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento
2699                    ||
2700                    !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)
2701                    )
2702                && irun < run_tree->GetEntries() ){
2703    
2704    
2705    //          if( !(abstime >= GetRunInfo()->RUNHEADER_TIME &&abstime <= GetRunInfo()->RUNTRAILER_TIME)  )cout << "ABS TIME "<<abstime << " " <<GetRunInfo()->RUNTRAILER_TIME <<endl;
2706    //          if( !(obt >= GetRunInfo()->RUNHEADER_OBT && obt <= GetRunInfo()->RUNTRAILER_OBT) )cout << "OBT TIME "<< obt <<" "<< GetRunInfo()->RUNTRAILER_OBT << endl;
2707    //          if( GetRunInfo()->NEVENTS==0  )cout <<"GetRunInfo()->NEVENTS==0 "<<endl;
2708    //          if( !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) ) cout << "irunentry > "<<GetRunInfo()->NEVENTS-1-prevshift << endl;
2709                // - - - - - - - - - - - - -
2710                // irunentry = position of current entry, relative to the run
2711                // prevshift = shift needed to synchronize l0 and l2 data (nested events)
2712                // - - - - - - - - - - - - -
2713    
2714                // -----------------------------------------
2715                // store dead and live-time of previous run
2716                // -----------------------------------------
2717    //          if(SELLI==0){
2718              if(SELLI!=2){
2719                if(fromfirst){
2720                    if(oldrun==irun){
2721                        /// decrement counters
2722                        if( GetTrigLevel2()){
2723                            totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time
2724                            totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time
2725                        }
2726                        totdltime[2]--;                              //event counter
2727                        cout << endl;
2728                        cout << "n.events     : "<<totdltime[2]<<endl;
2729                        cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;
2730                        cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;      
2731                    }else{
2732                        totdltime[0]=0;//live-time
2733                        totdltime[1]=0;//dead-time
2734                        totdltime[2]=0;                             //event counter
2735                        cout << " *** JUMP RUN *** irun "<<irun<<endl;
2736                    }
2737                    /// add an entry
2738                    if(run_tree_clone)
2739                        if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2740                            run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2741                    /// reset counters
2742                    if( GetTrigLevel2() ){
2743                        totdltime[0]=GetTrigLevel2()->dltime[0];//live-time
2744                        totdltime[1]=0;                         //dead-time
2745                    }
2746                    totdltime[2]=1;                             //event counter
2747                }
2748              }
2749              //        }
2750    
2751                irun++;        
2752                // ------------------------------------
2753                // if the end of run tree is reached...
2754                // ------------------------------------
2755                if( irun == run_tree->GetEntries() ){
2756                    if(!fromfirst){
2757                        // -----------------------------------------------------
2758                        // if it happened already once and the run was not found
2759                        // ---> exit with error
2760                        // -----------------------------------------------------
2761                        cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- event entry #"<<iev<<" does not belong to any run (should not happen)" <<endl;
2762                        return false;
2763                    }
2764                    // -----------------------------------------
2765                    // ...otherwise repeat search from beginning
2766                    // -----------------------------------------
2767                    cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- reached end of run tree. searchin again from beginning " <<endl;
2768                    fromfirst = false;
2769                    irun = 0LL;
2770                    runfirstentry = 0LL;
2771                }
2772                // -------------------------------------------------------------------
2773                // save the index of the first entry of the run, relative to pam_tree,
2774                // and read a new run
2775                // -------------------------------------------------------------------
2776                if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;
2777                irunentry = 0;
2778                prevshift = 0;          
2779                run_tree->GetEntry(irun);//update runinfo
2780                irunt = irun - irunoffset[run_tree->GetTreeNumber()];
2781                if ( gltsync ) delete gltsync; // Emiliano
2782                if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection(); //Emiliano
2783                gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0,"ID",dbc); // Emiliano
2784                if ( dbc ) dbc->Close(); // Emiliano
2785                if(gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT)>gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ){ // Emiliano
2786                    cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<"  has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl;
2787                    cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl;
2788                }
2789    //          if(hasfrag &&  fragid != GetRunInfo()->ID){
2790    //              cout << "... where is the next fragment ??"<<endl;
2791    //          }
2792            };
2793    
2794    
2795            // --------------------------------------
2796            // if there was no need to update the run
2797            // ---> exit with FALSE
2798            // --------------------------------------
2799            if ( irun == oldrun ) return(false);
2800    
2801            // --------------------------------------
2802            // ... otherwise
2803            // --------------------------------------
2804    
2805    
2806            // --------------------------------------
2807            // ---> exit with TRUE
2808            // --------------------------------------
2809            if(DBG)cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2810            // ----------------------------------------------------
2811            // update the tracker parameters
2812            // (non ho trovato nessun altro modo sicuro di farlo...)
2813            // ----------------------------------------------------
2814            if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection();
2815            TrkParams::Set(GetRunInfo() ,dbc);
2816            if(dbc)dbc->Close();
2817    
2818            // ----------------------------------------------------
2819            // then check if the run has a fragment
2820            // in this case we have to switch to the next fragment
2821            // when the end of the first fragment is reached
2822            // ----------------------------------------------------
2823            if(
2824                GetRunInfo()->ID_RUN_FRAG != 0 &&
2825    //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&
2826                DBG &&
2827                true ){
2828                cout << "* fragment *"<<endl;              
2829            }
2830    
2831            return(true);    
2832        };
2833        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2834        // if it is a preselected file (there is SelectionList)
2835        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2836        // irun  = run entry relative to the chain
2837        // irunt = run entry relative to the tree
2838        if(SELLI==1){      
2839            sel_tree->GetEntry(iev);// read irunt from SelectionList
2840            irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
2841            if(irun != oldrun ){
2842                if( irun < run_tree->GetEntries() )run_tree->GetEntry(irun);
2843                // check if the time is ok (with merged files it is not...)
2844                // if not loop over run and look for the proper entry
2845                bool SECONDO_GIRO=false;
2846                //      Long64_t irun_start   = irun;
2847                int      offset_start = irunoffset[sel_tree->GetTreeNumber()];
2848                while (
2849                    (
2850                        (
2851                            !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2852                              abstime <= GetRunInfo()->RUNTRAILER_TIME)
2853    //                      ||
2854    //                      !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2855    //                        obt <= GetRunInfo()->RUNTRAILER_OBT)
2856                            )
2857                        || GetRunInfo()->NEVENTS==0
2858                        )
2859    //              && irun < run_tree->GetEntries()
2860                    ){
2861    
2862                    if(DBG){
2863                        cout << " (test) ";
2864                        cout << " tree "<<sel_tree->GetTreeNumber();
2865                        cout << " irunt "<<irunt;
2866                        cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2867                        cout << " abs "<<abstime;
2868                        cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2869                        cout << " obt "<<obt;
2870                        cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2871                        cout << " *** JUMP RUN *** irun "<<irun;
2872                        cout << endl;
2873                    }
2874    //              irun++;
2875                    irunoffset[sel_tree->GetTreeNumber()]++;
2876                    irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW          
2877                    if(irun == run_tree->GetEntries() && SECONDO_GIRO){
2878    //              if(irun == irun_start ){
2879                        cout << " ...grrrvzzkhhhajsdkj!!!! "<<endl;
2880                        irunoffset[sel_tree->GetTreeNumber()] = offset_start;
2881                        return false;
2882                    }
2883                    if( irun >= run_tree->GetEntries() || irun < 0){
2884                        cout << "irun = "<<irun<<" >>  search from the beginning... <<"<<endl;
2885                        SECONDO_GIRO=true;
2886                        irun=0;
2887                        irunoffset[sel_tree->GetTreeNumber()]=-irunt;
2888                    }
2889                    run_tree->GetEntry(irun);
2890                }
2891    
2892    
2893                if(DBG){
2894                    cout << " (test) ";
2895                    cout << " tree "<<sel_tree->GetTreeNumber();
2896                    cout << " irunt "<<irunt;
2897                    cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2898                    cout << " abs "<<abstime;
2899                    cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2900                    cout << " obt "<<obt;
2901                    cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2902                }
2903                if(DBG)cout << endl;
2904                if(DBG)cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" (run-entry "<<irun<<")"<<endl;
2905                // ----------------------------------------------------
2906                // update the tracker parameters
2907                // (non ho trovato nessun altro modo sicuro di farlo...)
2908                // ----------------------------------------------------
2909                if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection();
2910                TrkParams::Set(GetRunInfo() ,dbc);
2911                if(dbc)dbc->Close();
2912    //          cout << endl;
2913                prevshift = 0;
2914                return true;
2915            }
2916            return false;
2917        }
2918    
2919        return false;
2920        //
2921    };
2922    /**
2923     * Update the runinfo informations (to be used to have Run infos event by event basis)
2924     * @param run Pointer to the chain/tree which contains run infos
2925     * @return true if a new run has been read, false if it is still the same run
2926     */
2927    Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){
2928        return(UpdateRunInfo((TChain*)run,iev));
2929    };
2930    
2931  //--------------------------------------  //--------------------------------------
2932  //  //
2933  //  //
# Line 1050  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2935  TTree *PamLevel2::GetRunTree(TFile *f){
2935  /**  /**
2936   * Set which trees shoul be analysed   * Set which trees shoul be analysed
2937   * @param detlist TString containing the sequence of trees required   * @param detlist TString containing the sequence of trees required
2938  */   */
2939  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist){
2940                
2941      if(detlist.Contains("+ALL", TString::kIgnoreCase)){  //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
2942        if( detlist.Contains("+ALL", TString::kIgnoreCase)){
2943    
2944            cout << " ======================================================== "<<endl;
2945            cout << "                       (( WARNING ))                      "<<endl;
2946            cout << " The meaning of the option +ALL has changed!!             "<<endl;
2947            cout << " Now it includes really all (level0+level1+level2+gpamela)"<<endl;
2948            cout << " and the file is discarded if it does not contain         "<<endl;
2949            cout << " all trees or  if level0 files are not available!!        "<<endl;
2950            cout << " ======================================================== "<<endl;
2951                
2952            CAL0 = true;
2953          CAL1 = true;          CAL1 = true;
2954          CAL2 = true;          CAL2 = true;
2955          TRK2 = true;          TRK2 = true;
2956          TRK1 = false;          TRK1 = true;
2957          TRKh = false;          TRKh = true;
2958            TRK0 = true;
2959          TRG = true;          TRG = true;
2960          TOF = true;          TOF = true;
2961            TOF0 = true;
2962          S4  = true;          S4  = true;
2963          ND  = true;          ND  = true;
2964          AC  = true;          AC  = true;
2965          ORB = true;          ORB = true;
2966            GP  = true;
2967      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
2968            CAL0 = false;
2969          CAL1 = false;          CAL1 = false;
2970          CAL2 = false;          CAL2 = false;
2971          TRK2 = false;          TRK2 = false;
2972          TRK1 = false;          TRK1 = false;
2973          TRKh = false;          TRKh = false;
2974            TRK0 = false;
2975          TRG = false;          TRG = false;
2976          TOF = false;          TOF = false;
2977            TOF0 = false;
2978          S4  = false;          S4  = false;
2979          ND  = false;          ND  = false;
2980          AC  = false;          AC  = false;
2981          ORB = false;          ORB = false;
2982            GP  = false;
2983      };      };
2984            
2985  //  -------------------------------------------------------------------------  //  -------------------------------------------------------------------------
# Line 1084  void PamLevel2::SetWhichTrees(TString de Line 2987  void PamLevel2::SetWhichTrees(TString de
2987          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;
2988          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;
2989      };      };
2990    
2991        if( detlist.Contains("CAL0", TString::kIgnoreCase) ){
2992            if ( detlist.Contains("-CAL0", TString::kIgnoreCase) )CAL0=false;
2993            if ( detlist.Contains("+CAL0", TString::kIgnoreCase) )CAL0=true;
2994        };
2995                    
2996      if( detlist.Contains("CAL2", TString::kIgnoreCase)){      if( detlist.Contains("CAL2", TString::kIgnoreCase)){
2997          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;
# Line 1096  void PamLevel2::SetWhichTrees(TString de Line 3004  void PamLevel2::SetWhichTrees(TString de
3004          CAL1=false;          CAL1=false;
3005      }      }
3006  //  -------------------------------------------------------------------------  //  -------------------------------------------------------------------------
3007        if( detlist.Contains("TRK0", TString::kIgnoreCase) ){
3008            if ( detlist.Contains("-TRK0", TString::kIgnoreCase) )TRK0=false;
3009            if ( detlist.Contains("+TRK0", TString::kIgnoreCase) )TRK0=true;
3010        };
3011    
3012      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){
3013          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;
3014          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;
# Line 1118  void PamLevel2::SetWhichTrees(TString de Line 3031  void PamLevel2::SetWhichTrees(TString de
3031          TRKh=false;          TRKh=false;
3032      }      }
3033  //  -------------------------------------------------------------------------  //  -------------------------------------------------------------------------
3034        
3035        if( detlist.Contains("-TRG", TString::kIgnoreCase) )TRG = false;
3036        else if( detlist.Contains("+TRG", TString::kIgnoreCase) )TRG = true;
3037        
3038        if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
3039        else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
3040    
3041        if( detlist.Contains("-TOF0", TString::kIgnoreCase) )TOF0 = false;
3042        else if( detlist.Contains("+TOF0", TString::kIgnoreCase) )TOF0 = true;
3043        
3044        if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;
3045        else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;
3046        
3047        if( detlist.Contains("-ND",  TString::kIgnoreCase) )ND  = false;
3048        else if( detlist.Contains("+ND",  TString::kIgnoreCase) )ND  = true;
3049        
3050        if( detlist.Contains("-AC",  TString::kIgnoreCase) )AC  = false;
3051        else if( detlist.Contains("+AC",  TString::kIgnoreCase) )AC  = true;
3052        
3053        if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;
3054        else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;
3055    
3056        if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false;
3057        else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true;
3058    
3059        cout<< "tree/branch list from input --> ";
3060        if(TRK0)cout<<"TRK0 ";
3061        if(TRK1)cout<<"TRK1 ";
3062        if(TRK2)cout<<"TRK2 ";
3063        if(TRKh)cout<<"TRKH ";
3064        if(CAL0)cout<<"CAL0 ";
3065        if(CAL1)cout<<"CAL1 ";
3066        if(CAL2)cout<<"CAL2 ";
3067        if(TOF)cout<<"TOF ";
3068        if(TRG)cout<<"TRG ";
3069        if(AC)cout<<"AC ";
3070        if(ND)cout<<"ND ";
3071        if(S4)cout<<"S4 ";
3072        if(ORB)cout<<"ORB ";
3073        if(GP)cout<<"GP ";
3074        cout << endl;
3075    //     cout<< "Set detector list --> ";
3076    //     if(TRK1)cout<<"TRK1 ";
3077    //     if(TRK2)cout<<"TRK2 ";
3078    //     if(TRKh)cout<<"TRKH ";
3079    //     if(CAL1)cout<<"CAL1 ";
3080    //     if(CAL2)cout<<"CAL2 ";
3081    //     if(TOF0)cout<<"TOF0 ";
3082    //     if(TOF)cout<<"TOF ";
3083    //     if(TRG)cout<<"TRG ";
3084    //     if(AC)cout<<"AC ";
3085    //     if(ND)cout<<"ND ";
3086    //     if(S4)cout<<"S4 ";
3087    //     if(ORB)cout<<"ORB ";
3088    //     cout << endl;
3089        
3090    };
3091    
3092    
3093    /**
3094     * Set tree/branch detector flags from the content of a tree
3095     */
3096    void  PamLevel2::GetWhichTrees(TFile* f){
3097        
3098    
3099    
3100    //    cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
3101        // -----------
3102        // reset flags
3103        // -----------
3104        CAL1   = false;    
3105        CAL2   = false;    
3106        TRK2   = false;    
3107        TRK1   = false;    
3108        TRKh   = false;    
3109        TRG    = false;    
3110        TOF    = false;    
3111        S4     = false;    
3112        ND     = false;    
3113        AC     = false;    
3114        ORB    = false;    
3115        GP     = false;    
3116        
3117        RUN    = false;
3118            
3119    //    cout << "Checking file: "<<f->GetName()<<endl;
3120        if( !f || f->IsZombie() ){
3121            cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;
3122            return;
3123        }
3124    
3125        TList *lk = f->GetListOfKeys();
3126        TIter next(lk);
3127        TKey *key =0;
3128    
3129        Int_t nev = 0;
3130    
3131        while( (key = (TKey*)next()) ){
3132            
3133            if( !strcmp(key->GetName(),"Run"        ) )RUN = true;
3134    
3135            //=========================================================    
3136            if( !strcmp(key->GetName(),"Trigger"    ) ){
3137                TRG = true;
3138                Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries();
3139                if( nev && nevt!=nev){
3140                    cout << "File: "<< f->GetName() <<" Trigger tree has "<<nevt<<" events instead of "<<nev<< endl;
3141                    TRG = false;
3142                }else nev=nevt;
3143            }
3144            //=========================================================    
3145            if( !strcmp(key->GetName(),"ToF"        ) ){
3146                TOF = true;
3147                Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries();
3148                if( nev && nevt!=nev){
3149                    cout << "File: "<< f->GetName() <<"     ToF tree has "<<nevt<<" events instead of "<<nev<< endl;
3150                    TOF = false;
3151                }else nev=nevt;
3152            }
3153            //=========================================================  
3154            if( !strcmp(key->GetName(),"S4"         ) ){
3155                S4 = true;
3156                Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries();
3157                if( nev && nevt!=nev){
3158                    cout << "File: "<< f->GetName() <<"      S4 tree has "<<nevt<<" events instead of "<<nev<< endl;
3159                    S4 = false;
3160                }else nev=nevt;
3161            }
3162            //=========================================================  
3163    
3164            if( !strcmp(key->GetName(),"NeutronD"   ) ){
3165                ND = true;
3166                Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries();
3167                if( nev && nevt!=nev){
3168                    cout << "File: "<< f->GetName() <<"NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl;
3169                    ND =false;
3170                }else nev=nevt;
3171            }      
3172            //=========================================================  
3173            if( !strcmp(key->GetName(),"Anticounter") ){
3174                AC = true;
3175                Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries();
3176                if( nev && nevt!=nev){
3177                    cout << "File: "<< f->GetName() <<" Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl;
3178                    AC =false;
3179                }else nev=nevt;
3180            }
3181            //=========================================================  
3182            if( !strcmp(key->GetName(),"OrbitalInfo") ){
3183                ORB = true;
3184                Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries();
3185                if( nev && nevt!=nev){
3186                    cout << "File: "<< f->GetName() <<" OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
3187                    ORB = false;
3188                }else nev=nevt;
3189            }
3190            //=========================================================  
3191            if( !strcmp(key->GetName(),"Tracker"    ) ){
3192                TTree *T = (TTree*)f->Get("Tracker");
3193                for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
3194                    TString name = T->GetListOfBranches()->At(i)->GetName();
3195                    if( !name.CompareTo("TrkLevel1") )TRK1=true;
3196                    if( !name.CompareTo("TrkLevel2") )TRK2=true;
3197                    if( !name.CompareTo("TrkHough") )TRKh=true;
3198                };      
3199                Int_t nevt = T->GetEntries();
3200                if( nev && nevt!=nev){
3201                    cout << "File: "<< f->GetName() <<" Tracker tree has "<<nevt<<" events instead of "<<nev<< endl;
3202                    TRK1 = false;
3203                    TRK2 = false;
3204                    TRKh = false;
3205                }else nev=nevt;
3206    //          T->Delete();
3207            };
3208            //=========================================================  
3209            if( !strcmp(key->GetName(),"Calorimeter"    ) ){
3210                TTree *T = (TTree*)f->Get("Calorimeter");
3211                for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
3212                    TString name = T->GetListOfBranches()->At(i)->GetName();
3213                    if( !name.CompareTo("CaloLevel1") )CAL1=true;
3214                    if( !name.CompareTo("CaloLevel2") )CAL2=true;
3215                };    
3216                Int_t nevt = T->GetEntries();
3217                if( nev && nevt!=nev){
3218                    cout << "File: "<< f->GetName() <<"  Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl;
3219                    CAL1 = false;
3220                    CAL2 = false;
3221                }else nev=nevt;
3222    //          T->Delete();
3223            };      
3224            //=========================================================  
3225            if( !strcmp(key->GetName(),"h20") ){
3226                GP = true;
3227                Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();
3228                if( nev && nevt!=nev){
3229                    cout << "File: "<< f->GetName() <<" h20 tree has "<<nevt<<" events instead of "<<nev<< endl;
3230                    GP = false;
3231                }else nev=nevt;
3232            }
3233    
3234        };
3235            
3236  //     if( detlist.Contains("-TRK", TString::kIgnoreCase) )TRK2 = false;  //    delete lk;
 //     else if( detlist.Contains("+TRK", TString::kIgnoreCase) )TRK2 = true;  
       
 //     if( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1 = false;  
 //     else if( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1 = true;  
3237    
3238  //     if( detlist.Contains("-TRKh", TString::kIgnoreCase) )TRKh = false;      cout<< "tree/branch list from file  --> ";
3239  //     else if( detlist.Contains("+TRKh", TString::kIgnoreCase) )TRKh = true;      if(TRK1)cout<<"TRK1 ";
3240            if(TRK2)cout<<"TRK2 ";
3241      if( detlist.Contains("-TRG", TString::kIgnoreCase) )TRG = false;      if(TRKh)cout<<"TRKH ";
3242      else if( detlist.Contains("+TRG", TString::kIgnoreCase) )TRG = true;      if(CAL1)cout<<"CAL1 ";
3243            if(CAL2)cout<<"CAL2 ";
3244      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;      if(TOF)cout<<"TOF ";
3245      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;      if(TRG)cout<<"TRG ";
3246            if(AC)cout<<"AC ";
3247      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;      if(ND)cout<<"ND ";
3248      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;      if(S4)cout<<"S4 ";
3249            if(ORB)cout<<"ORB ";
3250      if( detlist.Contains("-ND",  TString::kIgnoreCase) )ND  = false;      if(GP)cout<<"GP ";
3251      else if( detlist.Contains("+ND",  TString::kIgnoreCase) )ND  = true;      cout << endl;
3252              
3253      if( detlist.Contains("-AC",  TString::kIgnoreCase) )AC  = false;      return ;
3254      else if( detlist.Contains("+AC",  TString::kIgnoreCase) )AC  = true;          
       
     if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;  
     else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;  
       
3255  };  };
3256    
3257    
3258  //--------------------------------------  //--------------------------------------
3259  //  //
3260  //  //
# Line 1171  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3277  Bool_t  PamLevel2::CheckLevel2File(TStri
3277      Bool_t ND__ok     = false;          Bool_t ND__ok     = false;    
3278      Bool_t AC__ok     = false;          Bool_t AC__ok     = false;    
3279      Bool_t ORB__ok    = false;          Bool_t ORB__ok    = false;    
3280        Bool_t GP__ok     = false;    
3281            
3282      Bool_t RUN__ok    = false;      Bool_t RUN__ok    = false;
3283            
3284            Bool_t SELLI__ok  = false;
3285    
3286      cout << "Checking file: "<<name<<endl;  //    cout << "Checking file: "<<name<<endl;
3287      TFile *f = new TFile(name.Data());      TFile *f = new TFile(name.Data());
3288      if( !f || f->IsZombie() ){      if( !f || f->IsZombie() ){
3289          cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false;          cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false;
# Line 1192  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3299  Bool_t  PamLevel2::CheckLevel2File(TStri
3299      while( (key = (TKey*)next()) ){      while( (key = (TKey*)next()) ){
3300                    
3301  //      cout << key->GetName() << endl;  //      cout << key->GetName() << endl;
3302  //      cout << " Get tree: " << f->Get(key->GetName())<<endl;  //      cout << key->GetName() << ""<<key->GetClassName()<<endl;
3303    //              cout << " Get tree: " << f->Get(key->GetName())<<endl;
3304  //      nev_previous = nev;  //      nev_previous = nev;
3305  //      cout << " n.entries  "<< nev <<endl;  //      cout << " n.entries  "<< nev <<endl;
3306  //      if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){  //      if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){
# Line 1201  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3309  Bool_t  PamLevel2::CheckLevel2File(TStri
3309  //          return false;  //          return false;
3310  //      };  //      };
3311    
3312            //=========================================================    
3313            // check if the file
3314            
3315    
3316          if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;                if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;      
3317    
3318          //=========================================================              //=========================================================    
3319            if( !strcmp(key->GetName(),"SelectionList"    ) ){
3320                SELLI__ok = true;
3321                if(SELLI==1){
3322                    Int_t nevt = ((TTree*)f->Get("SelectionList"))->GetEntries();
3323                    if( nev && nevt!=nev){
3324                        cout << "File: "<< f->GetName() <<" discarded ---- SelectionList tree has "<<nevt<<" events instead of "<<nev<< endl;
3325                        return false;
3326                    }
3327                    nev=nevt;
3328                }
3329            }
3330    
3331            //=========================================================    
3332          if( !strcmp(key->GetName(),"Trigger"    ) ){          if( !strcmp(key->GetName(),"Trigger"    ) ){
3333              TRG__ok = true;              TRG__ok = true;
3334              if(TRG){              if(TRG){
# Line 1313  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3438  Bool_t  PamLevel2::CheckLevel2File(TStri
3438              };                  };    
3439              T->Delete();              T->Delete();
3440          };                };      
3441            //=========================================================    
3442            if( !strcmp(key->GetName(),"h20") ){
3443                ISGP = true;    
3444                GP__ok = true;
3445                if(GP){
3446                    Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();
3447                    if( nev && nevt!=nev){
3448                        cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
3449                        return false;
3450                    }
3451                    nev=nevt;
3452                }
3453            }
3454    
3455      };      };
3456    
3457        if( SELLI==-1 )SELLI = (Int_t)SELLI__ok;
3458        if( SELLI==0 && SELLI__ok ){
3459            cout << "File: "<< f->GetName() <<" discarded ---- found SelectionList (it is not a full-event file)" << endl;
3460            return false;  
3461        }
3462        if( SELLI==1 && !SELLI__ok ){
3463            cout << "File: "<< f->GetName() <<" discarded ---- SelectionList missing" << endl;
3464            return false;
3465        }
3466            
3467    //    cout << "SELLI "<<SELLI<<endl;
3468    
3469    //     cout<< "CheckLevel2File(TString): detector list --> ";
3470    //     if(TRK1__ok)cout<<"TRK1 ";
3471    //     if(TRK2__ok)cout<<"TRK2 ";
3472    //     if(TRKh__ok)cout<<"TRKH ";
3473    //     if(CAL1__ok)cout<<"CAL1 ";
3474    //     if(CAL2__ok)cout<<"CAL2 ";
3475    //     if(TOF__ok)cout<<"TOF ";
3476    //     if(TRG__ok)cout<<"TRG ";
3477    //     if(AC__ok)cout<<"AC ";
3478    //     if(ND__ok)cout<<"ND ";
3479    //     if(S4__ok)cout<<"S4 ";
3480    //     if(ORB__ok)cout<<"ORB ";
3481    //     cout << endl;
3482    
3483    
3484        if(TRK2 && TRK1__ok)TRK1=1;
3485    // ----------------------------------------------------------------------------
3486    // NOTA
3487    // se c'e` il level1, lo devo necessarimente leggere.
3488    // infatti (non ho capito perche`) i cluster vengono letti e allocati in memoria
3489    // comunque, ma non vengono disallocati da PamLevel2::Clear()
3490    // ----------------------------------------------------------------------------
3491    
3492    
3493      if(!RUN__ok) {      if(!RUN__ok) {
3494          cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree"<< endl;          cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree (NB: RUN infos will not be updated)"<< endl;
3495  //      return false;          RUN = false;
3496      };      };
3497    
3498      if(CAL1 && !CAL1__ok){      if(CAL1 && !CAL1__ok){
# Line 1360  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3532  Bool_t  PamLevel2::CheckLevel2File(TStri
3532          return false;          return false;
3533      };      };
3534    
3535          if(ND && !ND__ok){      if(ND && !ND__ok){
3536              cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl;          cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl;
3537              return false;          return false;
3538          };      };
3539          if(TRG && !TRG__ok){      if(TRG && !TRG__ok){
3540              cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;          cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;
3541              return false;          return false;
3542          };      };
3543        if(GP && !GP__ok){
3544            cout << "File: "<< f->GetName() <<" discarded ---- Missing h20 tree"<< endl;
3545            return false;
3546        };
3547        
3548    
3549      lk->Delete();  //    lk->Delete();
3550    //    delete lk;
3551      f->Close();      f->Close();
3552    
3553    //     cout<< "CheckLevel2File(TString): detector list --> ";
3554    //     if(TRK1)cout<<"TRK1 ";
3555    //     if(TRK2)cout<<"TRK2 ";
3556    //     if(TRKh)cout<<"TRKH ";
3557    //     if(CAL1)cout<<"CAL1 ";
3558    //     if(CAL2)cout<<"CAL2 ";
3559    //     if(TOF)cout<<"TOF ";
3560    //     if(TRG)cout<<"TRG ";
3561    //     if(AC)cout<<"AC ";
3562    //     if(ND)cout<<"ND ";
3563    //     if(S4)cout<<"S4 ";
3564    //     if(ORB)cout<<"ORB ";
3565    //     if(GP)cout<<"GP ";
3566    //     cout << endl;
3567                
3568      return true;      return true;
3569                    
# Line 1384  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3573  Bool_t  PamLevel2::CheckLevel2File(TStri
3573  /**  /**
3574   * Create clone-trees   * Create clone-trees
3575   */   */
3576  void PamLevel2::CreateCloneTrees( TChain *fChain ){  void PamLevel2::CreateCloneTrees0( TChain *fChain, TFile *ofile ){
3577    
3578      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3579      cout << "Create clones of PAMELA trees "<<endl;      cout << "Create clones of PAMELA trees "<<endl;
3580            
3581      Int_t i=0;      Int_t i=0;
3582      tree_clone[i] = fChain->GetTree()->CloneTree(0);      pam_tree_clone[i] = fChain->GetTree()->CloneTree(0);
3583      TString name =  tree_clone[i]->GetName();      TString name =  pam_tree_clone[i]->GetName();
3584      name.Append("_clone");      name.Append("_clone");
3585  //    tree_clone[i]->SetName(name.Data());  //    pam_tree_clone[i]->SetName(name.Data());
3586      cout << tree_clone[i]->GetName() <<endl;      cout << pam_tree_clone[i]->GetName() <<endl;
3587      i++;      i++;
3588    
3589      TList *li = fChain->GetListOfFriends();      TList *li = fChain->GetListOfFriends();
3590      TIter next(li);      TIter next(li);
3591      TFriendElement* T_friend=0;      TFriendElement* T_friend=0;
3592        ofile->cd();
3593      while( (T_friend = (TFriendElement*)next()) ){      while( (T_friend = (TFriendElement*)next()) ){
3594  //      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;
3595  //      cout<<T_friend->GetTree()->GetName()<< endl;  //      cout<<T_friend->GetTree()->GetName()<< endl;
3596          tree_clone[i] = T_friend->GetTree()->CloneTree(0);                pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0);
3597          name =  tree_clone[i]->GetName();          pam_tree_clone[i]->SetAutoSave(1000000);
3598            name =  pam_tree_clone[i]->GetName();
3599          name.Append("_clone");          name.Append("_clone");
3600  //      tree_clone[i]->SetName(name.Data());  //      pam_tree_clone[i]->SetName(name.Data());
3601          cout << tree_clone[i]->GetName() << endl;          cout << pam_tree_clone[i]->GetName() << endl;
3602          i++;          i++;
3603      }      }
3604        
3605        delete li;
3606    
3607      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3608    
3609  }  }
3610    
3611  // /**  /**
3612  //  * Create clone-trees   * Create clone-trees
3613  //  */   */
3614  // void PamLevel2::CreateCloneTrees(){  void PamLevel2::CreateCloneTrees(TFile *ofile){
3615    
3616    
3617    //  if the pointer is null, create a default file
3618        if(!run_tree)return;
3619    
3620        if(!ofile){
3621            cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;
3622            ofile = new TFile("clone-tree.root","recreate");
3623        }
3624    
3625        ofile->cd();
3626    
3627  //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3628  //     cout << "Create new PAMELA trees "<<endl;      cout << "Create new PAMELA trees "<<endl;
3629                    
 //     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", GetPointerTo("TrkLevel1"));  
 //          T_clone->BranchRef();  
 //          cout << "Tracker      : branch TrkLevel1"<<endl;  
 //      };  
 //      if(TRK2) {  
 //          trk2_clone = new TrkLevel2();  
 //          T_clone->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));  
 //          cout << "Tracker      : branch TrkLevel2"<<endl;          
 //      };  
 //      if(TRKh) {  
 //          trkh_clone = new TrkHough();  
 //          T_clone->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));  
 //          cout << "Tracker      : branch TrkHough"<<endl;  
 //      };  
 //      cout << hex << T_clone << dec << endl;  
 //     }  
3630    
3631  //     // Calorimeter      run_tree_clone = new TTree("Run","PAMELA Level2 data from the GL_RUN table ");
3632  //     if(CAL1||CAL2){      run_tree_clone->Branch("RunInfo","GL_RUN",GetPointerTo("RunInfo"));
3633  //      C_clone = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");          cout << "Run          : branch RunInfo"<<endl;
3634  //      if(CAL1) {      run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));
3635  //          calo1_clone = new CaloLevel1();      cout << "Run          : branch SoftInfo"<<endl;
3636  //          C_clone->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));      // ------------------
3637  //          cout << "Calorimeter  : branch CaloLevel1"<<endl;      // replicate run tree
3638  //      };      // ------------------
3639  //      if(CAL2) {  //    cout << "----------------------------------------------------"<<endl;
3640  //          calo2_clone = new CaloLevel2();  //    cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
3641  //          C_clone->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));      for (Int_t i=0; i<run_tree->GetEntries(); i++){
3642  //          cout << "Calorimeter  : branch CaloLevel2"<<endl;          run_tree->GetEntry(i);
3643  //      };  //      cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;
3644  //     }              run_tree_clone->Fill();
3645        }
3646        cout << "----------------------------------------------------"<<endl;
3647    
3648  //     // ToF          // ------------------------------------
3649  //     if(TOF) {      // add branch with dead and live times
3650  //      O_clone = new TTree("ToF_clone","PAMELA ToF level2 data ");          // ------------------------------------
3651  //      tof_clone = new ToFLevel2();      if ( SELLI != 2 ){ // EMILIANO
3652  //      O_clone->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));        run_tree_clone->Branch("DeadLiveTime",totdltime,"dltime[3]/l");
3653  //      cout << "ToF          : branch ToFLevel2"<<endl;        cout << "Run          : branch DeadLiveTime"<<endl;
 //     };  
 //     // Trigger  
 //     if(TRG) {  
 //      R_clone = new TTree("Trigger_clone","PAMELA trigger level2 data ");      
 //      trig_clone = new TrigLevel2();  
 //      R_clone->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));  
 //      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", GetPointerTo("S4Level2"));  
 //      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", GetPointerTo("NDLevel2"));  
 //      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", GetPointerTo("AcLevel2"));  
 //      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", GetPointerTo("OrbitalInfo"));  
 //      cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;  
 //     };  
 //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
3654    
 // }  
3655    
3656  // /**        sel_tree_clone = new TTree("SelectionList","List of selected events ");
3657  //  * Create clone-trees        //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
3658  //  */        sel_tree_clone->Branch("RunEntry",&irunt,"runentry/L");//NEWNEW
3659  // void PamLevel2::CreateCloneTrees(){        sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");
3660        };
3661    
3662  //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      Int_t i=0;
3663  //     cout << "Create new PAMELA trees "<<endl;      if(TRK1||TRK2||TRKh){
3664                    pam_tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");
3665  //     if(TRK1||TRK2||TRKh){          if(TRK1) {
3666  //      T_clone = new TTree("Tracker_clone","PAMELA tracker level2 data ");                  pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
3667  //      if(TRK1) {              pam_tree_clone[i]->BranchRef();
3668  //          trk1_clone = new TrkLevel1();              cout << "Tracker      : branch TrkLevel1"<<endl;
3669  //          T_clone->Branch("TrkLevel1","TrkLevel1", &trk1_clone);  //          cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;
3670  //          T_clone->BranchRef();          };
3671  //          cout << "Tracker      : branch TrkLevel1"<<endl;          if(TRK2) {
3672  //      };              pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
3673  //      if(TRK2) {              cout << "Tracker      : branch TrkLevel2"<<endl;        
3674  //          trk2_clone = new TrkLevel2();          };
3675  //          T_clone->Branch("TrkLevel2", "TrkLevel2",&trk2_clone);          if(TRKh) {
3676  //          cout << "Tracker      : branch TrkLevel2"<<endl;                      pam_tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));
3677  //      };              cout << "Tracker      : branch TrkHough"<<endl;
3678  //      if(TRKh) {          };
3679  //          trkh_clone = new TrkHough();          i++;
3680  //          T_clone->Branch("TrkHough","TrkHough", &trkh_clone);      }
 //          cout << "Tracker      : branch TrkHough"<<endl;  
 //      };  
 //      cout << hex << T_clone << dec << endl;  
 //     }  
3681    
3682  //     // Calorimeter      // Calorimeter
3683  //     if(CAL1||CAL2){      if(CAL1||CAL2){
3684  //      C_clone = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");              pam_tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");
3685  //      if(CAL1) {          if(CAL1) {
3686  //          calo1_clone = new CaloLevel1();              pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
3687  //          C_clone->Branch("CaloLevel1", "CaloLevel1", &calo1_clone);              cout << "Calorimeter  : branch CaloLevel1"<<endl;
3688  //          cout << "Calorimeter  : branch CaloLevel1"<<endl;          };
3689  //      };          if(CAL2) {
3690  //      if(CAL2) {              pam_tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));
3691  //          calo2_clone = new CaloLevel2();              cout << "Calorimeter  : branch CaloLevel2"<<endl;
3692  //          C_clone->Branch("CaloLevel2","CaloLevel2", &calo2_clone);          };
3693  //          cout << "Calorimeter  : branch CaloLevel2"<<endl;          i++;
3694  //      };      }    
 //     }      
3695    
3696  //     // ToF          // ToF    
3697  //     if(TOF) {      if(TOF) {
3698  //      O_clone = new TTree("ToF_clone","PAMELA ToF level2 data ");              pam_tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");
3699  //      tof_clone = new ToFLevel2();          pam_tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));
3700  //      O_clone->Branch("ToFLevel2","ToFLevel2", &tof_clone);          cout << "ToF          : branch ToFLevel2"<<endl;
3701  //      cout << "ToF          : branch ToFLevel2"<<endl;          i++;
3702  //     };      };
3703  //     // Trigger      // Trigger
3704  //     if(TRG) {      if(TRG) {
3705  //      R_clone = new TTree("Trigger_clone","PAMELA trigger level2 data ");              pam_tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");
3706  //      trig_clone = new TrigLevel2();          pam_tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));
3707  //      R_clone->Branch("TrigLevel2","TrigLevel2", &trig_clone);          cout << "Trigger      : branch TrigLevel2"<<endl;
3708  //      cout << "Trigger      : branch TrigLevel2"<<endl;          i++;
3709  //     };      };
3710  //     // S4      // S4
3711  //     if(S4) {      if(S4) {
3712  //      S_clone = new TTree("S4_clone","PAMELA S4 level2 data ");                pam_tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");  
3713  //      s4_clone = new S4Level2();          pam_tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));
3714  //      S_clone->Branch("S4Level2","S4Level2", &s4_clone);          cout << "S4           : branch S4Level2"<<endl;
3715  //      cout << "S4           : branch S4Level2"<<endl;          i++;
3716  //     };      };
3717  //     // Neutron Detector      // Neutron Detector
3718  //     if(ND) {      if(ND) {
3719  //      N_clone = new TTree("NeutronD_clone","PAMELA neutron detector level2 data ");            pam_tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");      
3720  //      nd_clone = new NDLevel2();          pam_tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));
3721  //      N_clone->Branch("NDLevel2","NDLevel2", &nd_clone);          cout << "NeutronD     : branch NDLevel2"<<endl;
3722  //      cout << "NeutronD     : branch NDLevel2"<<endl;          i++;
3723  //     };      };
3724  //     // Anticounters      // Anticounters
3725  //     if(AC) {      if(AC) {
3726  //      A_clone = new TTree("Anticounter_clone","PAMELA anticounter detector level2 data ");              pam_tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");        
3727  //      ac_clone = new AcLevel2();          pam_tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));
3728  //      A_clone->Branch("AcLevel2","AcLevel2", &ac_clone);          cout << "Anticounter  : branch AcLevel2"<<endl;
3729  //      cout << "Anticounter  : branch AcLevel2"<<endl;          i++;
3730  //     };      };
3731  //     // OrbitalInfo      // OrbitalInfo
3732  //     if(ORB) {      if(ORB) {
3733  //      B_clone = new TTree("OrbitalInfo_clone","PAMELA oribital info  ");                pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA orbital info  ");  
3734  //      orb_clone = new OrbitalInfo();          pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));
3735  //      B_clone->Branch("OrbitalInfo","OrbitalInfo", &orb_clone);          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
3736  //      cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;          i++;
3737  //     };      };
3738  //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      // GPamela
3739        if(GP) {
3740            pam_tree_clone[i] = new TTree("h20","PAMELA orbital info  ");  
3741            pam_tree_clone[i]->Branch("GPamela","GPamela", GetPointerTo("GPamela"),32000,1);//split
3742            cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
3743            i++;
3744        };
3745        cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3746    
3747    }
3748    
 // }  
3749    
3750  /**  /**
3751   * Fill tree (created with CreateCloneTrees)   * Fill tree (created with CreateCloneTrees)
# Line 1601  void PamLevel2::CreateCloneTrees( TChain Line 3753  void PamLevel2::CreateCloneTrees( TChain
3753   */   */
3754  //void PamLevel2::FillNewPamTree(TTree *T){  //void PamLevel2::FillNewPamTree(TTree *T){
3755  void PamLevel2::FillCloneTrees(){  void PamLevel2::FillCloneTrees(){
3756                
3757  // //  --------------------------------------  //    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();  
3758    
3759      for(Int_t i=0; i<8; i++){      for(Int_t i=0; i<NCLONES; i++){
3760          if(tree_clone[i])tree_clone[i]->Fill();          if(pam_tree_clone[i])pam_tree_clone[i]->Fill();
3761      }      }
3762        if(sel_tree_clone)sel_tree_clone->Fill();    
3763    
3764  }  }
3765    
3766    
3767  TTree* PamLevel2::GetCloneTree(TString name){  TTree* PamLevel2::GetCloneTree(TString name){
3768    
3769      for(Int_t i=0; i<8; i++){        for(Int_t i=0; i<NCLONES; i++){    
3770          if(tree_clone[i]){          if(pam_tree_clone[i]){
3771              TString na = tree_clone[i]->GetName();              TString na = pam_tree_clone[i]->GetName();
3772              if(!name.CompareTo(na))return tree_clone[i];              if(!name.CompareTo(na))return pam_tree_clone[i];
3773          };          };
3774      }      }
3775        if(run_tree_clone){
3776            TString na = run_tree_clone->GetName();
3777            if(!name.CompareTo(na))return run_tree_clone;
3778        }
3779        if(sel_tree_clone){
3780            TString na = sel_tree_clone->GetName();
3781            if(!name.CompareTo(na))return sel_tree_clone;
3782        }
3783      return NULL;      return NULL;
3784    
3785  }  }
3786  void PamLevel2::WriteCloneTrees(){  void PamLevel2::WriteCloneTrees(){
3787      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3788      cout << "Write clones of PAMELA trees "<<endl;      cout << "Write clones of PAMELA trees "<<endl;
3789      for(Int_t i=0; i<8; i++){        cout << run_tree_clone->GetName()<<endl;  
3790          if(tree_clone[i]){      if ( SELLI != 2){// Emiliano
3791              cout << tree_clone[i]->GetName()<<endl;        if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
3792              tree_clone[i]->Write();          run_tree_clone->GetBranch("DeadLiveTime")->Fill();
3793        };
3794        run_tree_clone->Write();
3795        if ( SELLI != 2){ //Emiliano
3796          cout << sel_tree_clone->GetName()<<endl;    
3797          sel_tree_clone->Write();
3798        };
3799        for(Int_t i=0; i<NCLONES; i++){    
3800            if(pam_tree_clone[i]){
3801                cout << pam_tree_clone[i]->GetName()<<endl;
3802                pam_tree_clone[i]->Write();
3803          };          };
3804      }      }
3805      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
# Line 1669  void PamLevel2::WriteCloneTrees(){ Line 3807  void PamLevel2::WriteCloneTrees(){
3807  }  }
3808    
3809  /**  /**
3810   * Create a new (empty) Pamela trees   * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.
3811   */   */
3812  // TTree* PamLevel2::GetNewPamTree(){  //Int_t PamLevel2::GetEntry(Int_t iee){
3813    Int_t PamLevel2::GetEntry(Long64_t iee){
3814        
3815    //     cout << "-------------------------------------"<<endl;
3816    //     cout << "Int_t PamLevel2::GetEntry("<<iee<<")"<<endl;
3817    
3818  //     if(tree_clone)return tree_clone;      if(!pam_tree){
3819            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded"<<endl;
3820            return 0;
3821        }
3822    
3823  //     TTree *Tout = 0;  
3824            //
3825  //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      // 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...
3826  //     cout << "Create new PAMELA trees "<<endl;      //
3827            //    if(!run_tree ){
3828        //  cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl;
3829        //  return 0;
3830        //    }
3831    
3832        Long64_t ii=0;
3833        //-------------------------------
3834        ii = iee;
3835        if( !pam_tree->GetEntry(ii) ){      
3836            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<<endl;
3837            return 0;
3838        }
3839    
3840        //
3841        // ... 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.
3842        // 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
3843        // a problem if you don't check the return code of getentry.
3844        //
3845        if(!RUN || !run_tree ){
3846            if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?
3847                cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
3848                return 0;
3849            }  else {
3850                return 1; //cosi` se non c'e` run esce qua...
3851            }
3852        }
3853    
3854        //-------------------------------
3855        ii = iee;
3856    //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
3857    //    Bool_t UPDATED = UpdateRunInfo(ii);
3858        UpdateRunInfo(ii);
3859        if(SELLI==0||SELLI==2)irunentry = iee-runfirstentry;
3860    //    if(UPDATED && run_tree_clone)run_tree_clone->Fill();
3861      
3862    //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
3863    
3864    //     cout << "irunentry     "<<irunentry << endl;
3865    //     cout << "runfirstentry "<<runfirstentry << endl;
3866    //     cout << "nevents       "<<GetRunInfo()->NEVENTS<< endl;
3867    
3868    //     if( TRK0 || CAL0 || TOF0 ){
3869    //      if( !GetYodaEntry( ) ){
3870    //          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl;
3871    //          return 0;
3872    //      }
3873    //     }
3874    
3875    
3876        return 1;
3877    
3878    }
3879    
3880    TrkLevel0    *PamLevel2::GetTrkLevel0(){
3881        if( !TRK0 )return NULL;
3882        if( !GetYodaEntry( ) ){
3883            cout << " Int_t PamLevel2::GetTrkLevel0() -- ERROR -- error reading level0 tree"<<endl;
3884            return 0;
3885        }
3886        return trk0_obj;
3887    };
3888    CaloLevel0    *PamLevel2::GetCaloLevel0(){
3889        if( !CAL0 )return NULL;
3890        if( !GetYodaEntry( ) ){
3891            cout << " Int_t PamLevel2::GetCaloLevel0() -- ERROR -- error reading level0 tree"<<endl;
3892            return 0;
3893        }
3894        return calo0_obj;
3895    };
3896    
3897    
3898    /**
3899     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
3900     * Given the run ID (...), if needed it query the DB and load the proper file.
3901     * @return Pointer to the tree
3902     */
3903    
3904    
3905    TTree* PamLevel2::GetYodaTree( ){
3906            
3907  //     if(TRK1||TRK2||TRKh){  //    cout << "TTree* PamLevel2::GetYodaTree( )"<<endl;
3908  //      TTree *T = new TTree("Tracker_clone","PAMELA tracker level2 data ");          //===================================
3909  //      if(TRK1) {      // check if iroot has changed
3910  //          trk1_clone = new TrkLevel1();      //===================================
3911  //          T->Branch("TrkLevel1","TrkLevel1", &trk1_clone);      if( irun<0 ){
3912  //          T->BranchRef();          cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = "<<irun<<endl;
3913  //          cout << "Tracker      : branch TrkLevel1"<<endl;  //      cout << "In order to use this method you have to first load the RunInfo tree "<<endl;
3914  //      };          return NULL;
3915  //      if(TRK2) {      }    
3916  //          trk2_clone = new TrkLevel2();      Int_t irootnew = run_obj->ID_ROOT_L0;
3917  //          T->Branch("TrkLevel2", "TrkLevel2",&trk2_clone);  //      cout << "iroot    "<<iroot<<endl;
3918  //          cout << "Tracker      : branch TrkLevel2"<<endl;          //      cout << "irootnew "<<irootnew<<endl;
3919  //      };  
3920  //      if(TRKh) {      //===================================
3921  //          trkh_clone = new TrkHough();      // load the level0 file
3922  //          T->Branch("TrkHough","TrkHough", &trkh_clone);      // (if not already loaded)
3923  //          cout << "Tracker      : branch TrkHough"<<endl;      //===================================
3924  //      };      if( iroot != irootnew || !l0_tree){
3925  //      if(!Tout)Tout=T;          iroot = irootnew;
3926  //      else Tout->AddFriend("Tracker_clone");          //===================================
3927            // open the DB connection
3928            // (if not already opened)
3929            //===================================
3930            if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
3931            GL_ROOT glroot = GL_ROOT();
3932            if( glroot.Query_GL_ROOT(iroot,dbc) ){
3933                cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;
3934                return NULL;
3935            };
3936            TString filename = glroot.PATH + glroot.NAME;
3937            if(l0_file){
3938                l0_file->Close();
3939                l0_file->Delete();
3940            }
3941            cout << "Opening LEVEL0 file: "<< filename << endl;
3942            FileStat_t t;
3943            if( gSystem->GetPathInfo(filename.Data(),t) ){
3944                cout << " PamLevel2::GetYodaTree() -- ERROR opening file "<<endl;
3945                return NULL;
3946            }
3947            l0_file = new TFile(filename);
3948            if( !l0_file )return NULL;
3949            l0_tree = (TTree*)l0_file->Get("Physics");
3950            if(!h0_obj)h0_obj = new EventHeader();
3951            l0_tree->SetBranchAddress("Header" ,&h0_obj);
3952            prevshift = 0;
3953            //---------------------------------------------------
3954            // TRACKER:
3955            if(TRK0){
3956                if(!trk0_obj){
3957                    trk0_obj = new TrkLevel0();
3958                    trk0_obj->Set();
3959                };
3960                l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());
3961            }
3962            //--------------------------------------------------
3963            // CALORIMETER:
3964            if(CAL0){
3965                if(!calo0_obj){
3966                    calo0_obj = new CaloLevel0();
3967                    calo0_obj->Set();
3968                };
3969                l0_tree->SetBranchAddress("Calorimeter" ,calo0_obj->GetPointerToCalorimeterEvent());
3970                //      cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;
3971            }
3972            //---------------------------------------------------
3973            // TOF:
3974            if(TOF0){
3975                cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
3976            }
3977    
3978            dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
3979    
3980    
3981        };
3982    
3983    //     if(!dbc || (dbc && !dbc->IsConnected())){
3984    //      cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;
3985  //     }  //     }
3986    
3987  //     // Calorimeter      if ( TRK0 ){
3988  //     if(CAL1||CAL2){  //      TrkParams::Load(6);
3989  //      TTree *C = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");      //      if( !TrkParams::IsLoaded(6) ){
3990  //      if(CAL1) {  //          cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;
 //          calo1_clone = new CaloLevel1();  
 //          C->Branch("CaloLevel1", "CaloLevel1", &calo1_clone);  
 //          cout << "Calorimeter  : branch CaloLevel1"<<endl;  
3991  //      };  //      };
3992  //      if(CAL2) {  //      if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
3993  //          calo2_clone = new CaloLevel2();          TrkParams::SetCalib(run_obj,dbc);
3994  //          C->Branch("CaloLevel2","CaloLevel2", &calo2_clone);          TrkParams::LoadCalib( );
3995  //          cout << "Calorimeter  : branch CaloLevel2"<<endl;          if( !TrkParams::CalibIsLoaded() ){
3996  //      };              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;
3997  //      if(!Tout)Tout=C;          };
3998  //      else Tout->AddFriend("Calorimeter_clone");  //      if(dbc)dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
3999  //     }          }
   
 //     // 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;  
4000    
 //     tree_clone = Tout;  
 //     tree_clone->SetDirectory(0);  
4001    
4002  //     return Tout;  //    cout << l0_tree << endl;
4003  // }      return l0_tree;
4004  // /**  
4005  //  * Fill a tree (created with GetNewPamTree)  }
4006  //  *  
4007  //  */  /**
4008  // //void PamLevel2::FillNewPamTree(TTree *T){   * Method to retrieve the level0 tree (YODA tree) that contains the current event.
4009  // void PamLevel2::FillNewPamTree(){   */
4010            Int_t PamLevel2::GetYodaEntry(){
4011    
4012    //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;
4013        if(!GetYodaTree())return 0;
4014        
4015        // patch
4016        if( irunentry < 0){
4017    //      cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
4018            irunentry=0LL;
4019        }
4020        //  ---------------------------------
4021        //  if file is NOT a preselected file
4022        //  ---------------------------------
4023        Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM);
4024    //     cout << " irunentry "<<irunentry<<endl;
4025    //     cout << " EV_FROM "<<run_obj->EV_FROM<<endl;
4026    //     cout << " quellagiusta = irunentry + EV_FROM "<< quellagiusta << endl;
4027    
4028    //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
4029    //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
4030    //     cout << " time "<< abstime << endl;
4031    //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;
4032        
4033        ULong64_t obt     = 0;
4034        ULong64_t pktn    = 0;
4035        if( GetOrbitalInfo() ){
4036            obt     = GetOrbitalInfo()->OBT;
4037            pktn    = GetOrbitalInfo()->pkt_num;
4038        }
4039    
4040        if( !GetOrbitalInfo() && !ISGP){
4041            cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;
4042            return 0;
4043        }
4044        if( obt==0 && pktn==0 && !ISGP ){
4045            cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl;
4046            return 0;
4047        }
4048    
4049        // ---------------------------------------------------------------------
4050        // ATTENTION!!!
4051        // If data are not pre-processed with cleaner, the level0 tree may contain
4052        // spurious nested physics packets.
4053        // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries
4054        // while level2 tree DOES NOT!!
4055        // This means that "quellagiusta" in these cases is not correct.
4056        // In order to retrieve the correct level0 event, I implemented a check
4057        // of the OBT and pkt-number. In case of mismatch, the level0 entry number
4058        // is shift forward until when the packets match.
4059        // ---------------------------------------------------------------------
4060        Int_t answer = 0;
4061        Int_t shift =0;
4062        //    printf(" siamo qui %i %i \n",shift,prevshift);
4063        //    Int_t maxshift = 50; // EMILIANO
4064        do{
4065            if(shift>0){    
4066                cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
4067                if(DBG)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;
4068                if(DBG)cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;
4069            }
4070            answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);
4071            shift++;
4072            if( !GetEventHeader() ){
4073                cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;
4074                return 0;
4075            }
4076    
4077            if(ISGP){
4078                obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO
4079                pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO
4080            }
4081    
4082    //      cout << "PKTNUM "<<shift<<" ==  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
4083    //      cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;
4084    //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;
4085    //      cout << " obt "<< obt << endl;
4086    //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;
4087    //      cout << " pktn "<< pktn << endl;
4088    //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
4089    //      printf(" IDRUN %u \n",GetRunInfo()->ID);
4090    //
4091            if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){
4092                prevshift = 0;
4093                shift = -1;
4094            };
4095    
4096        }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||
4097                  pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())       )
4098                && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);
4099    
4100        if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {
4101            cout << " Big trouble here, no such event in Level0 data! (NB maxshift set to "<<maxshift<<" )" <<endl;
4102            return 0;
4103        }
4104    //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
4105    //    return GetYodaTree()->GetEntry(quellagiusta);
4106        if ( shift > 1 ) prevshift += (shift-1);
4107        
4108        return answer;
4109        
4110    }
4111    /**
4112     * \Brief Set DB connection
4113     */
4114    Bool_t PamLevel2::SetDBConnection(){
4115    
4116    //    cout << "PamLevel2::SetDBConnection()" << endl;
4117        if(DBG){
4118            cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
4119            cout<<"Connecting to DB"<<endl;
4120            cout<<"HOST "<<host<<endl;
4121            cout<<"USER "<<user<<endl;
4122            cout<<"PSW  "<<psw<<endl;
4123        }
4124        dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
4125        if( !dbc )return false;
4126        if( !dbc->IsConnected() )return false;    
4127        stringstream myquery;  // EMILIANO
4128        myquery.str("");  // EMILIANO
4129        myquery << "SET time_zone='+0:00'";  // EMILIANO
4130        dbc->Query(myquery.str().c_str());  // EMILIANO
4131        if(DBG)cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
4132        return true;
4133    
4134    }
4135    
4136    /**
4137     * \Brief Add a friend to the pamela chain.
4138     * @param cname name of the chain to be added
4139     */
4140    
4141    TChain* PamLevel2::AddFriend(TString cname){
4142    
4143        if(!GetPamTree()){
4144            cout << " TChain* PamLevel2::AddFriend(TString cname) --- a pamela tree must be created first"<<endl;
4145            return NULL;
4146        }
4147    
4148    
4149        TChain *c = new TChain( cname.Data() );
4150    
4151        TIter next( GetPamTree()->GetListOfFiles() );
4152        Int_t nf = 0;
4153        TChainElement* element = 0;    
4154        while ((element = (TChainElement*) next())) {      
4155            c->Add(element->GetTitle());
4156            nf++;
4157        }
4158    
4159        GetPamTree()->AddFriend(cname.Data());
4160    
4161        cout << "external chain created and added to pamela friends :"<<cname<<endl;
4162        cout << "n.files "<<nf<<endl;
4163        
4164    
4165        return c;    
4166    
4167    }
4168    
 //     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  
 //     }  
4169    
 // }  

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.74

  ViewVC Help
Powered by ViewVC 1.1.23