/[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.43 by pam-fi, Fri Aug 17 16:57:12 2007 UTC revision 1.70 by mocchiut, Wed Dec 10 11:56:35 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 10  PamTrack::PamTrack(){ Line 284  PamTrack::PamTrack(){
284      trk_track  = 0;      trk_track  = 0;
285      calo_track = 0;      calo_track = 0;
286      tof_track  = 0;      tof_track  = 0;
287        orb_track  = 0;
288      candeleteobj = 0;      candeleteobj = 0;
289        pscore = 0;
290        iscore = 0;
291  };  };
292  //--------------------------------------  //--------------------------------------
293  //  //
# Line 19  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    
301      trk_track  = 0;      trk_track  = 0;
302      calo_track = 0;      calo_track = 0;
303      tof_track  = 0;      tof_track  = 0;
304        orb_track  = 0;
305  //     if(t)trk_track  = new TrkTrack(*t);  //     if(t)trk_track  = new TrkTrack(*t);
306  //     if(c)calo_track = new CaloTrkVar(*c);  //     if(c)calo_track = new CaloTrkVar(*c);
307  //     if(o)tof_track  = new ToFTrkVar(*o);  //     if(o)tof_track  = new ToFTrkVar(*o);
308      if(t)trk_track  = t;      if(t)trk_track  = t;
309      if(c)calo_track = c;      if(c)calo_track = c;
310      if(o)tof_track  = o;      if(o)tof_track  = o;
311        if(r)orb_track  = r;
312      candeleteobj = 0;      candeleteobj = 0;
313    
314  };  };
# Line 38  PamTrack::PamTrack(const PamTrack& track Line 317  PamTrack::PamTrack(const PamTrack& track
317      TrkTrack   *t = track.trk_track;      TrkTrack   *t = track.trk_track;
318      CaloTrkVar *c = track.calo_track;      CaloTrkVar *c = track.calo_track;
319      ToFTrkVar  *o = track.tof_track;      ToFTrkVar  *o = track.tof_track;
320        OrbitalInfoTrkVar  *r = track.orb_track;
321    
322      trk_track  = 0;      trk_track  = 0;
323      calo_track = 0;      calo_track = 0;
324      tof_track  = 0;      tof_track  = 0;
325        orb_track  = 0;
326      if(t)trk_track  = new TrkTrack(*t);      if(t)trk_track  = new TrkTrack(*t);
327      if(c)calo_track = new CaloTrkVar(*c);      if(c)calo_track = new CaloTrkVar(*c);
328      if(o)tof_track  = new ToFTrkVar(*o);      if(o)tof_track  = new ToFTrkVar(*o);
329        if(r)orb_track  = new OrbitalInfoTrkVar(*r);
330      candeleteobj = 1;      candeleteobj = 1;
331            
332  }  }
# Line 55  void PamTrack::Clear(){ Line 337  void PamTrack::Clear(){
337          if(trk_track)  trk_track->TrkTrack::Clear();          if(trk_track)  trk_track->TrkTrack::Clear();
338          if(calo_track) calo_track->CaloTrkVar::Clear();//???          if(calo_track) calo_track->CaloTrkVar::Clear();//???
339          if(tof_track)  tof_track->ToFTrkVar::Clear();//???          if(tof_track)  tof_track->ToFTrkVar::Clear();//???
340            if(orb_track)  orb_track->OrbitalInfoTrkVar::Clear();//???
341      }else{      }else{
342          trk_track  = 0;          trk_track  = 0;
343          calo_track = 0;          calo_track = 0;
344          tof_track  = 0;          tof_track  = 0;
345            orb_track  = 0;
346      }      }
347        pscore = 0;
348        iscore = 0;
349    
350  }  }
351  void PamTrack::Delete(){  void PamTrack::Delete(){
352  //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;  //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;
# Line 76  void PamTrack::Delete(){ Line 363  void PamTrack::Delete(){
363              tof_track->ToFTrkVar::Clear();//???              tof_track->ToFTrkVar::Clear();//???
364              delete tof_track;              delete tof_track;
365          }          }
366            if(orb_track){
367                orb_track->OrbitalInfoTrkVar::Clear();//???
368                delete orb_track;
369            }
370      }else{      }else{
371          Clear();          Clear();
372      }      }
# Line 88  void PamTrack::Delete(){ Line 379  void PamTrack::Delete(){
379   * Default Constructor   * Default Constructor
380   */   */
381  PamLevel2::PamLevel2(){  PamLevel2::PamLevel2(){
382    Initialize();      Initialize();
383  };  };
384    
385  /**  /**
386   * Constructor with given dir, list and detectors   * Constructor
387     * @param ddir Name of directory where level2 files are stored.
388     * @param list Name of an ascii file containing the list of file names
389     * @param detlist Options to chose what to load.
390     * Possible options are:
391     *       +AUTO --> load all trees/branches in the input files
392     *       +(-)ALL --> inlcude(exclude) all trees/branches
393     *       +(-)TRK1+(-)TRK2+(-)CAL1+(-)CAL2+(-)TOF+(-)TRG+(-)ND+(-)S4+(-)ORB+(-)AC --> inlcude(exclude) trees and branches
394     *       +(-)TRK0 --> include(exclude) tracker level0 tree
395     *       +(-)GP --> include exclude GPAMELA output tree
396     * If no options are specified, the default is assumed. Default is:
397     * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
398   */   */
399  PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){  PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){
400    Initialize();      Initialize();
401    GetPamTree(GetListOfLevel2Files(ddir,list),detlist);      TList*  listf = GetListOfLevel2Files(ddir,list);
402    GetRunTree(GetListOfLevel2Files(ddir,list));      GetPamTree(listf,detlist);
403        GetRunTree(listf);
404  };  };
405    
406    PamLevel2::PamLevel2(TString ddir,TList *list,TString detlist){
407        Initialize();
408        GetPamTree(list,detlist);
409        GetRunTree(list);
410    };
411  /**  /**
412   * Constructor with given dir and list   * Constructor
413     * @param ddir Name of directory where level2 files are stored.
414     * @param list Name of an ascii file containing the list of file names
415     * Default trees/branches are loaded. Default is:
416     * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
417   */   */
418  PamLevel2::PamLevel2(TString ddir,TString list){  PamLevel2::PamLevel2(TString ddir,TString list){
419    Initialize();      Initialize();
420    GetPamTree(GetListOfLevel2Files(ddir,list),"");      TList*  listf = GetListOfLevel2Files(ddir,list);
421    GetRunTree(GetListOfLevel2Files(ddir,list));      GetPamTree(listf,"");
422        GetRunTree(listf);
423  };  };
424    
425    
# Line 127  void PamLevel2::Initialize(){ Line 440  void PamLevel2::Initialize(){
440      nd_obj    = 0;      nd_obj    = 0;
441      ac_obj    = 0;      ac_obj    = 0;
442      orb_obj   = 0;      orb_obj   = 0;
443        gp_obj    = 0;
444    
445      run_obj   = 0;//new GL_RUN();      run_obj   = 0;//new GL_RUN();
446      soft_obj   = 0;// Emiliano      soft_obj   = 0;// Emiliano
447      irun = -1LL;      irun = -1LL;
448        irunt = -1LL;
449      runfirstentry = 0LL;      runfirstentry = 0LL;
450      runlastentry = 0LL;      runlastentry = 0LL;
451    
# Line 140  void PamLevel2::Initialize(){ Line 455  void PamLevel2::Initialize(){
455      dbc     = 0;      dbc     = 0;
456    
457      prevshift = 0;      prevshift = 0;
458        maxshift = 10; //EMILIANO
459            
460      run_tree = NULL;      run_tree = NULL;
461      run_tree_clone = NULL;      run_tree_clone = NULL;
# Line 150  void PamLevel2::Initialize(){ Line 466  void PamLevel2::Initialize(){
466      pam_tree = NULL;      pam_tree = NULL;
467      for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;      for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;
468    
469        totdltime[0] = 0LL;
470        totdltime[1] = 0LL;
471        totdltime[2] = 0LL;
472    
473      host = "mysql://localhost/pamelaprod";      host = "mysql://localhost/pamelaprod";
474      user = "anonymous";      user = "anonymous";
475      psw = "";      psw = "";
# Line 172  void PamLevel2::Initialize(){ Line 492  void PamLevel2::Initialize(){
492      CAL2 = true;      CAL2 = true;
493      TRK2 = true;      TRK2 = true;
494      TRK1 = false;      TRK1 = false;
495      TRKh = false;      TRK0 = false;
496      TRKh = false;      TRKh = false;
497      TRG  = true;      TRG  = true;
498      TOF  = true;      TOF  = true;
# Line 180  void PamLevel2::Initialize(){ Line 500  void PamLevel2::Initialize(){
500      S4   = true;      S4   = true;
501      ND   = true;      ND   = true;
502      AC   = true;      AC   = true;
503      ORB  = true;      ORB  = true;    
504            GP   = false;
505    
506      RUN  = true;      RUN  = true;
507    
508      SELLI = -1;      SELLI = -1;
509    
510      ISGP = false;      ISGP = false;
511    
512        DBG = false;
513    
514      tsorted=0;      tsorted=0;
515      timage=0;      timage=0;
516            
# Line 219  void PamLevel2::Delete(){ Line 542  void PamLevel2::Delete(){
542      if(nd_obj)   delete nd_obj;      if(nd_obj)   delete nd_obj;
543      if(ac_obj)   delete ac_obj;      if(ac_obj)   delete ac_obj;
544      if(orb_obj)  delete orb_obj;      if(orb_obj)  delete orb_obj;
545        if(gp_obj)   delete gp_obj;
546            
547      if(tsorted){      if(tsorted){
548          tsorted->Delete();          tsorted->Delete();
# Line 237  void PamLevel2::Delete(){ Line 561  void PamLevel2::Delete(){
561      if(l0_file)l0_file->Close();      if(l0_file)l0_file->Close();
562      //    if(pam_tree)pam_tree->Delete();;      //    if(pam_tree)pam_tree->Delete();;
563    
564    if ( pam_tree ){      if ( pam_tree ){
565      //          //
566      // 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...          // 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...
567      //          //
568      TList *temp = pam_tree->GetListOfFriends();          TList *temp = pam_tree->GetListOfFriends();
569      TList *contents  = new TList; // create chain friend list          TList *contents  = new TList; // create chain friend list
570      contents->SetOwner();          contents->SetOwner();
571      TIter next(temp);          TIter next(temp);
572      TChain *questo = 0;          TChain *questo = 0;
573      while ( (questo = (TChain*) next()) ){          while ( (questo = (TChain*) next()) ){
574        TString name =  questo->GetName();              TString name =  questo->GetName();
575        contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list              contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
576      };          };
577      //          //
578      // deleting the main chain          // deleting the main chain
579      //          //
580      pam_tree->Delete();          pam_tree->Delete();
581      //          //
582      // deleting the friends...          // deleting the friends...
583      //          //
584      TIter next2(contents);          TIter next2(contents);
585      TChain *questa = 0;          TChain *questa = 0;
586      while ( questa = (TChain*)next2() ){          while ( questa = (TChain*)next2() ){
587        TString name =  questa->GetName();              TString name =  questa->GetName();
588        questa->Delete();                    questa->Delete();      
589        questa=NULL;              questa=NULL;
590            };
591            //
592      };      };
593      //      pam_tree = NULL;
   };  
   pam_tree = NULL;  
594    
595      if(run_tree)run_tree->Delete();;      if(run_tree)run_tree->Delete();;
596      if(sel_tree)sel_tree->Delete();;      if(sel_tree)sel_tree->Delete();;
# Line 274  void PamLevel2::Delete(){ Line 598  void PamLevel2::Delete(){
598      if(run_tree_clone)run_tree_clone->Delete();;      if(run_tree_clone)run_tree_clone->Delete();;
599      if(sel_tree_clone)sel_tree_clone->Delete();;      if(sel_tree_clone)sel_tree_clone->Delete();;
600            
601        if(irunoffset) delete [] irunoffset;
602    
603  };  };
604    
# Line 306  void PamLevel2::Clear(){ Line 631  void PamLevel2::Clear(){
631      if(nd_obj)   nd_obj->Clear();      if(nd_obj)   nd_obj->Clear();
632      if(ac_obj)   ac_obj->Clear();      if(ac_obj)   ac_obj->Clear();
633      if(orb_obj)  orb_obj->Clear();      if(orb_obj)  orb_obj->Clear();
634        if(gp_obj)   gp_obj->Clear();
635            
636  //    if(sorted_tracks)sorted_tracks->Clear();  //    if(sorted_tracks)sorted_tracks->Clear();
637  //    sorted_tracks.Clear();  //    sorted_tracks.Clear();
# Line 319  void PamLevel2::Clear(){ Line 645  void PamLevel2::Clear(){
645  };  };
646    
647  void PamLevel2::Reset(){  void PamLevel2::Reset(){
   //  
   // First of all clear everything  
   //  
   Clear();  
   //  
   // close and reset chains and pointers  
   //      
   if ( pam_tree ){  
648      //      //
649      // 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...      // First of all clear everything
650      //      //
651      TList *temp = pam_tree->GetListOfFriends();      Clear();
652      TList *contents  = new TList; // create chain friend list      //
653      contents->SetOwner();      // close and reset chains and pointers
654      TIter next(temp);      //    
655      TChain *questo = 0;      if ( pam_tree ){
656      while ( (questo = (TChain*) next()) ){          //
657        TString name =  questo->GetName();          // 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...
658        contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list          //
659            TList *temp = pam_tree->GetListOfFriends();
660            TList *contents  = new TList; // create chain friend list
661            contents->SetOwner();
662            TIter next(temp);
663            TChain *questo = 0;
664            while ( (questo = (TChain*) next()) ){
665                TString name =  questo->GetName();
666                contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
667            };
668            //
669            // deleting the main chain
670            //
671            pam_tree->Delete();
672            //
673            // deleting the friends...
674            //
675            TIter next2(contents);
676            TChain *questa = 0;
677            while ( questa = (TChain*)next2() ){
678                TString name =  questa->GetName();
679                questa->Delete();      
680                questa=NULL;
681            };
682            //
683      };      };
684        pam_tree = NULL;
685      //      //
686      // deleting the main chain      if(run_tree)run_tree->Delete();;
687        run_tree = NULL;
688        if(sel_tree)sel_tree->Delete();;
689        sel_tree = NULL;
690      //      //
691      pam_tree->Delete();      // Close file
692      //      //
693      // deleting the friends...      if(l0_file)l0_file->Close("R");
694        l0_file = NULL;
695      //      //
696      TIter next2(contents);      h0_obj    = 0;
697      TChain *questa = 0;      trk0_obj  = 0;
698      while ( questa = (TChain*)next2() ){      calo0_obj  = 0;
699        TString name =  questa->GetName();      //
700        questa->Delete();            trk2_obj  = 0;
701        questa=NULL;      trk1_obj  = 0;
702      };      trkh_obj  = 0;
703        calo1_obj = 0;
704        calo2_obj = 0;
705        tof_obj   = 0;
706        trig_obj  = 0;
707        s4_obj    = 0;
708        nd_obj    = 0;
709        ac_obj    = 0;
710        orb_obj   = 0;
711        gp_obj    = 0;
712        //
713        // Reset run pointers
714        //
715        run_obj   = 0;//new GL_RUN();
716        soft_obj   = 0;// Emiliano
717        irun = -1;
718        irunt = -1;
719        runfirstentry = 0ULL;
720        runlastentry = 0ULL;    
721        //
722        totdltime[0] = 0LL;
723        totdltime[1] = 0LL;
724        totdltime[2] = 0LL;
725      //      //
   };  
   pam_tree = NULL;  
   //  
   if(run_tree)run_tree->Delete();;  
   run_tree = NULL;  
   if(sel_tree)sel_tree->Delete();;  
   sel_tree = NULL;  
   //  
   // Close file  
   //  
   if(l0_file)l0_file->Close("R");  
   l0_file = NULL;  
   //  
   h0_obj    = 0;  
   trk0_obj  = 0;  
   calo0_obj  = 0;  
   //  
   trk2_obj  = 0;  
   trk1_obj  = 0;  
   trkh_obj  = 0;  
   calo1_obj = 0;  
   calo2_obj = 0;  
   tof_obj   = 0;  
   trig_obj  = 0;  
   s4_obj    = 0;  
   nd_obj    = 0;  
   ac_obj    = 0;  
   orb_obj   = 0;  
   //  
   // Reset run pointers  
   //  
   run_obj   = 0;//new GL_RUN();  
   soft_obj   = 0;// Emiliano  
   irun = -1;  
   runfirstentry = 0ULL;  
   runlastentry = 0ULL;      
   //  
726  };  };
727    
728  Bool_t PamLevel2::IsGood(){  Bool_t PamLevel2::IsGood(Bool_t strict){
729    Bool_t goodev=true;    Bool_t goodev=true;
730    //  if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;    //
731    if(calo2_obj && calo2_obj->good != 1) goodev = false;    if(calo2_obj && !calo2_obj->IsGood(strict) ) goodev = false;
732    if(tof_obj && tof_obj->unpackError != 0) goodev = false;      //
733    if(trig_obj && trig_obj->unpackError != 0) goodev = false;    if ( strict ){
734    if(s4_obj && s4_obj->unpackError != 0) goodev = false;        if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;
735    if(nd_obj && nd_obj->unpackError != 0) goodev = false;        if(tof_obj && tof_obj->unpackError != 0) goodev = false;  
736    if(ac_obj && ac_obj->unpackError != 255) goodev = false;        if(trig_obj && trig_obj->unpackError != 0) goodev = false;
737        if(s4_obj && s4_obj->unpackError != 0) goodev = false;  
738        if(nd_obj && nd_obj->unpackError != 0) goodev = false;  
739        if(ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0]>>3)&1) || ((ac_obj->status[0]>>3)&1)) ) goodev = false;      
740      //  if(orb_obj)        //  if(orb_obj)  
741    return goodev;    } else {
742        if(nd_obj && nd_obj->unpackError != 0) goodev = false;  
743        if(ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0]>>3)&1) || ((ac_obj->status[0]>>3)&1)) ) goodev = false;      
744      };
745      return(goodev);
746  };  };
747    
748  //--------------------------------------  //--------------------------------------
# Line 429  void *PamLevel2::GetPointerTo(const char Line 768  void *PamLevel2::GetPointerTo(const char
768          return &trk2_obj;          return &trk2_obj;
769      };      };
770      if(!objname.CompareTo("TrkHough"))   {      if(!objname.CompareTo("TrkHough"))   {
771          if(!trkh_obj)  trkh_obj  = new TrkHough();          if(!trkh_obj)  {
772                trkh_obj  = new TrkHough();
773                trkh_obj->Set();
774            }
775          return &trkh_obj;          return &trkh_obj;
776      };      };
777      if(!objname.CompareTo("CaloLevel1")) {      if(!objname.CompareTo("CaloLevel1")) {
# Line 470  void *PamLevel2::GetPointerTo(const char Line 812  void *PamLevel2::GetPointerTo(const char
812          if(!orb_obj)   orb_obj   = new OrbitalInfo();          if(!orb_obj)   orb_obj   = new OrbitalInfo();
813          return &orb_obj;          return &orb_obj;
814      };      };
815        if(!objname.CompareTo("GPamela")){
816            if(!gp_obj)   gp_obj   = new GPamela();
817            return &gp_obj;
818        };
819            
820      if(!objname.CompareTo("RunInfo"))return &run_obj;      if(!objname.CompareTo("RunInfo"))return &run_obj;
821    
# Line 485  void *PamLevel2::GetPointerTo(const char Line 831  void *PamLevel2::GetPointerTo(const char
831   * Retrieves the calorimeter track matching the seqno-th tracker stored track.   * Retrieves the calorimeter track matching the seqno-th tracker stored track.
832   * (If seqno = -1 retrieves the self-trigger calorimeter track)   * (If seqno = -1 retrieves the self-trigger calorimeter track)
833   */   */
834   CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){  CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
835            
836       if( !calo2_obj )return 0;      if( !calo2_obj )return 0;
837    
838       if( calo2_obj->CaloLevel2::ntrk()==0 ){      if( calo2_obj->CaloLevel2::ntrk()==0 ){
839           cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;          cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;
840           return NULL;          return NULL;
841       };      };
842            
843       CaloTrkVar *c = 0;      CaloTrkVar *c = 0;
844       Int_t it_calo=0;      Int_t it_calo=0;
845            
846       do{      do{
847           c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);          c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
848           it_calo++;          it_calo++;
849       } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());          } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());    
850            
851       if(!c || seqno != c->trkseqno){      if(!c || seqno != c->trkseqno){
852           c = 0;          c = 0;
853           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;
854       };      };
855       return c;      return c;
856            
857   };  };
858  //--------------------------------------  //--------------------------------------
859   //  //
860   //  //
861  //--------------------------------------  //--------------------------------------
862  /**  /**
863    * Retrieves the ToF track matching the seqno-th tracker stored track.   * Retrieves the ToF track matching the seqno-th tracker stored track.
864    * (If seqno = -1 retrieves the tracker-independent tof track)   * (If seqno = -1 retrieves the tracker-independent tof track)
865   */   */
866   ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
867                    
868       if( !tof_obj )return 0;      if( !tof_obj )return 0;
869    
870       if( tof_obj->ToFLevel2::ntrk()==0 ){      if( tof_obj->ToFLevel2::ntrk()==0 ){
871           cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;          cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;
872           return NULL;          return NULL;
873       };      };
874            
875       ToFTrkVar *c = 0;      ToFTrkVar *c = 0;
876       Int_t it_tof=0;      Int_t it_tof=0;
877            
878       do{      do{
879           c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);          c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);
880           it_tof++;          it_tof++;
881       } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());              } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());
882            
883       if(!c || seqno != c->trkseqno){      if(!c || seqno != c->trkseqno){
884           c = 0;          c = 0;
885           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;
886       };      };
887       return c;      return c;
888            
889   };  };
890    
891  //--------------------------------------  //--------------------------------------
892   //  //
893   //  //
894  //--------------------------------------  //--------------------------------------
895  /**  /**
896   * 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.
897     * (If seqno = -1 retrieves the tracker-independent tof related track)
898   */   */
899   PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno){
900            
901        if( !orb_obj )return 0;
902    
903        if( orb_obj->OrbitalInfo::ntrk()==0 ){
904            cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no OrbitalInfo tracks are stored"<<endl;
905            return NULL;
906        };
907        
908        OrbitalInfoTrkVar *c = 0;
909        Int_t it_tof=0;
910            
911       cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;      do{
912       cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;          c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);
913            it_tof++;
914        } while( c && seqno != c->trkseqno && it_tof < orb_obj->OrbitalInfo::ntrk());      
915        
916        if(!c || seqno != c->trkseqno){
917            c = 0;
918            if(seqno!=-1)cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match OrbitalInfo stored tracks"<<endl;
919        };
920        return c;
921        
922    };
923    
924       CaloTrkVar *c = 0;  //--------------------------------------
925       ToFTrkVar  *o = 0;  //
926    //
927    //--------------------------------------
928    /**
929     * Give the pamela track associated to a tracker track, retrieving related calorimeter, orbitalinfo and tof track information.
930     */
931    PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
932            
933       if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());      cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;
934       if(TOF) o = GetToFStoredTrack(t->GetSeqNo());      cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
935    
936        CaloTrkVar *c = 0;
937        ToFTrkVar  *o = 0;
938        OrbitalInfoTrkVar  *r = 0;
939        
940        if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());
941        if(TOF) o = GetToFStoredTrack(t->GetSeqNo());
942        if(ORB) r = GetOrbitalInfoStoredTrack(t->GetSeqNo());
943            
944  //    if(t && c && o)track = new PamTrack(t,c,o);  //    if(t && c && o)track = new PamTrack(t,c,o);
945       PamTrack *track = new PamTrack(t,c,o);      PamTrack *track = new PamTrack(t,c,o,r);
946            
947       return track;      return track;
948    
949   };  };
950  //--------------------------------------  //--------------------------------------
951  //  //
952  //  //
# Line 579  void *PamLevel2::GetPointerTo(const char Line 960  void *PamLevel2::GetPointerTo(const char
960  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
961            
962      cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;      cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;
963      cout <<"for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack)"<<endl;      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;
964      cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;      cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
965      PamTrack *track = 0;      PamTrack *track = 0;
966            
# Line 601  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 982  PamTrack* PamLevel2::GetStoredTrack(Int_
982  //  //
983    
984  /**  /**
985   * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is  PamLevel2::sorted_tracks. Left here as backward compatibility method.   * Sort physical (tracker) tracks. Left here as backward compatibility method.
986   **/   **/
987  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(TString how){
988    printf(" WARNING! obsolete, use SortTracks() and SetSortingMethod(TString) instead! \n Setting sorting method to %s \n",how.Data());      printf(" WARNING! obsolete, use SortTracks() and SetSortingMethod(TString) instead! \n Setting sorting method to %s \n",how.Data());
989    howtosort = how;        howtosort = how;  
990    SortTracks();      SortTracks();
991  };  };
992    
993  //  //
994  //--------------------------------------  //--------------------------------------
995  /**  /**
996   * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is  PamLevel2::sorted_tracks.   * Sort physical (tracker) tracks.
997   * @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...).
998   * Sorting cryteria:   * Sorting cryteria:
999   * TRK: lower chi**2   * TRK: lower chi**2
1000   * CAL: lower Y spatial residual on the first calorimeter plane   * CAL: lower Y spatial residual on the first calorimeter plane
1001   * 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).
1002     * S1: (ask Emiliano)
1003     * S2: (ask Emiliano)
1004     * S3: (ask Emiliano)
1005     * GP: more GP hits
1006   * The default sorting cryterium is "TOF+CAL".   * The default sorting cryterium is "TOF+CAL".
1007   *   *
1008   * 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).
1009   */   */
1010  void PamLevel2::SortTracks(){  void PamLevel2::SortTracks(){
1011    TString how = howtosort;      TString how = howtosort;
1012    
1013    //    cout <<" PamLevel2::SortTracks(TString how) "<<endl;      //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;
1014    if( !trk2_obj ){      if( !trk2_obj ){
1015      cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";          cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";
1016      return;          return;
1017    };      };
1018    //    cout << "call SortTracs() "<<endl;      //Save current Object count
1019    //Save current Object count      Int_t ObjectNumber = TProcessID::GetObjectCount();
   Int_t ObjectNumber = TProcessID::GetObjectCount();  
   
   //    cout << "ObjectNumber  "<<ObjectNumber <<endl;  
   
   //     if(!sorted_tracks)sorted_tracks = new TRefArray();  
   //     sorted_tracks->Clear();  
   //    sorted_tracks.Clear();  
   
   if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());  
   tsorted->Delete();  
   TClonesArray &ttsorted = *tsorted;  
   if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());  
   timage->Delete();  
   TClonesArray &ttimage = *timage;  
1020    
1021        // create TCloneArrays to store tracks and its images
1022        if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
1023        tsorted->Delete();
1024        TClonesArray &ttsorted = *tsorted;
1025    
1026        if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
1027        timage->Delete();
1028        TClonesArray &ttimage = *timage;
1029    
1030    
   //--------------------------------------------------  
   // retrieve sorting method  
   //--------------------------------------------------  
   Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);  
   Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);  
   Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);  
       
   if( !CAL2 &&  use_CAL) use_CAL = false;  
   if( !TOF &&  use_TOF) use_TOF = false;  
       
   if( !TRK2 ){  
     //  cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;  
     return;  
   };  
1031    
1032    //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;      //--------------------------------------------------
1033        // retrieve sorting method
1034        //--------------------------------------------------
1035        Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
1036        Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
1037        Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
1038        Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
1039        Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
1040        Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
1041        Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
1042        
1043        if ( use_TOF ){
1044            use_S1 = true;
1045            use_S2 = true;
1046            use_S3 = true;
1047        };
1048        if( !CAL2 &&  use_CAL) use_CAL = false;
1049        if( !TOF ){
1050            use_TOF = false;
1051            use_S1  = false;
1052            use_S2  = false;
1053            use_S3  = false;
1054        }
1055        if( !GP ){
1056            use_GP  = false;
1057        }
1058    
1059    //--------------------------------------------------      if( !TRK2 ){
1060    // loop over "physical" tracks sorted by the tracker          cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
   //--------------------------------------------------  
   for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){  
           
     TrkTrack   *ts = 0;  
     CaloTrkVar *cs = 0;  
     ToFTrkVar  *os = 0;  
           
     // get tracker tracks  
     TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker  
     CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());  
     ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());  
   
     TrkTrack   *ti = 0; //tracker (image)  
     CaloTrkVar *ci = 0;  
     ToFTrkVar  *oi = 0;  
     //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;  
     // if track has an image, check image selection  
     if(tp->HasImage()){  
               
       ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)  
       ci = GetCaloStoredTrack(ti->GetSeqNo());  
       oi = GetToFStoredTrack(ti->GetSeqNo());  
               
       //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;  
   
       //assign starting scores  
       Int_t tp_score = 0;  //main track sorted by the tracker  
       Int_t ti_score = 0;  //image track  
               
       // -----------------------------------------------------------------------------------------  
       // calorimeter check  
       // -----------------------------------------------------------------------------------------  
       // check the Y spatial residual on the first calorimeter plane  
       // (cut on calorimeter variables from Emiliano)  
       if( use_CAL && !calo2_obj ){  
         cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";  
1061          return;          return;
1062        };      };
       if(  
          use_CAL            &&  
 //       calo2_obj->npcfit[1] > 5     &&   //no. of fit planes on Y view  
 //       calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view  
          cp && ci &&  
          true){  
1063    
1064                        //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
1065  //      Float_t resy_p = cp->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_p < 0)resy_p= - resy_p;    
1066  //      Float_t resy_i = ci->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_i < 0)resy_i= - resy_i;  
1067                        //--------------------------------------------------
1068  //      if(resy_p <= resy_i) tp_score++;      // loop over "physical" tracks sorted by the tracker
1069  //      else                 ti_score++;      //--------------------------------------------------
1070        for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
1071                    
1072            TrkTrack   *ts = 0;
1073            CaloTrkVar *cs = 0;
1074            ToFTrkVar  *os = 0;
1075            OrbitalInfoTrkVar  *rs = 0;
1076            
1077            // get tracker tracks
1078            TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
1079            CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
1080            ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
1081            OrbitalInfoTrkVar  *rp = GetOrbitalInfoStoredTrack(tp->GetSeqNo());
1082    
1083            TrkTrack   *ti = 0; //tracker (image)
1084            CaloTrkVar *ci = 0;
1085            ToFTrkVar  *oi = 0;
1086            OrbitalInfoTrkVar  *ri = 0;
1087            //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
1088            // if track has an image, check image selection
1089    
1090            Int_t tp_score = 0;  //main track sorted by the tracker
1091            Int_t ti_score = 0;  //image track
1092            Int_t totp_score = 0;  //main track sorted by the tracker
1093            Int_t toti_score = 0;  //image track
1094    
1095            if( cp->npresh > ci->npresh) tp_score++;          if(tp->HasImage()){
1096            if( cp->npresh < ci->npresh) ti_score++;              
1097            else ;//niente              ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)
1098                ci = GetCaloStoredTrack(ti->GetSeqNo());
1099          //      cout << "CALO "<<tp_score<<ti_score<<endl;              oi = GetToFStoredTrack(ti->GetSeqNo());
1100                ri = GetOrbitalInfoStoredTrack(ti->GetSeqNo());
1101        };              
1102        // -----------------------------------------------------------------------------------------              //      cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
1103        // TOF check  
1104        // -----------------------------------------------------------------------------------------              //assign starting scores
1105        // check the number of hit pmts along the track              tp_score = 0;  //main track sorted by the tracker
1106        // on S12 S21 and S32, where paddles are parallel to Y axis              ti_score = 0;  //image track
1107        if( use_TOF && !tof_obj ){              
1108          cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";              // -----------------------------------------------------------------------------------------
1109          return;              // *****************************************************************************************
1110        };              // -----------------------------------------------------------------------------------------
1111        if( use_TOF && op && oi ){              // calorimeter check
1112                                // -----------------------------------------------------------------------------------------
1113          //              if( use_CAL && !calo2_obj ){
1114          Float_t sen = 0.;                  cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";
1115          for (Int_t ih=0; ih < op->npmtadc; ih++){                  return;
           Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  
           if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih);  
         };  
         for (Int_t ih=0; ih < oi->npmtadc; ih++){  
           Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  
           if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);  
         };  
         //  
         if (  sen >= sortthr ){  
           //printf(" IS A NUCLEUS! en = %f \n",sen);  
           //  
           // is a nucleus use a different algorithm  
           //  
           Int_t nz = 6; Float_t zin[6];                                          // << define TOF z-coordinates  
           for(Int_t ip=0; ip<nz; ip++)  
             zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip));     // << read ToF plane z-coordinates  
           Trajectory *tr = new Trajectory(nz,zin);  
           //  
           Int_t nphit_p =0;  
           Int_t nphit_i =0;  
           Float_t enhit_p = 0.;  
           Float_t enhit_i = 0.;  
           //  
           for (Int_t ih=0; ih < op->npmtadc; ih++){  
             Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  
             if(pl == 1 || pl == 2 || pl == 5){  
               nphit_p++;  
               enhit_p += (op->dedx).At(ih);  
             };  
           };  
           //  
           tp->DoTrack2(tr);  
           //  
           if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){  
             for (Int_t ih=0; ih < op->npmtadc; ih++){  
               Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  
               if(pl == 0){  
                 nphit_p++;  
                 enhit_p += (op->dedx).At(ih);  
               };  
1116              };              };
1117            };              if( use_CAL && !cp &&  ci ){
1118            if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){                  ti_score++;
1119              for (Int_t ih=0; ih < op->npmtadc; ih++){                  toti_score++;
               Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  
               if(pl == 3){  
                 nphit_p++;  
                 enhit_p += (op->dedx).At(ih);  
               };  
1120              };              };
1121            };              if( use_CAL &&  cp && !ci ){
1122            if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){                  tp_score++;
1123              for (Int_t ih=0; ih < op->npmtadc; ih++){                  totp_score++;
               Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  
               if(pl == 4){  
                 nphit_p++;  
                 enhit_p += (op->dedx).At(ih);  
               };  
1124              };              };
1125            };              if(
1126                    use_CAL            &&
1127                    cp && ci &&
1128                    true){
1129    
1130                    
1131                    if(
1132                        cp->npresh > ci->npresh &&
1133                        true){
1134                        tp_score++;
1135                        totp_score++;
1136                    };
1137                    if(
1138                        cp->npresh < ci->npresh &&
1139                        true){
1140                        ti_score++;
1141                        toti_score++;
1142                    };
1143    
1144                    //      cout << "CALO "<<tp_score<<ti_score<<endl;
1145    
           for (Int_t ih=0; ih < oi->npmtadc; ih++){  
             Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  
             if(pl == 1 || pl == 2 || pl == 5){  
               nphit_i++;          
               enhit_i += (op->dedx).At(ih);  
1146              };              };
1147            };              // -----------------------------------------------------------------------------------------
1148            //              // *****************************************************************************************
1149            ti->DoTrack2(tr);              // -----------------------------------------------------------------------------------------
1150            //              // TOF check
1151            if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){              // -----------------------------------------------------------------------------------------
1152              for (Int_t ih=0; ih < oi->npmtadc; ih++){              // check the number of hit pmts along the track
1153                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );              // on S12 S21 and S32, where paddles are parallel to Y axis
1154                if(pl == 0){              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !tof_obj ){
1155                  nphit_i++;                  cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";
1156                  enhit_i += (op->dedx).At(ih);                  return;
               };  
1157              };              };
1158            };              //
1159            if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !op && oi ){
1160              for (Int_t ih=0; ih < oi->npmtadc; ih++){                  ti_score++;
1161                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );                  toti_score++;
               if(pl == 3){  
                 nphit_i++;  
                 enhit_i += (op->dedx).At(ih);  
               };  
1162              };              };
1163            };              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && !oi ){
1164            if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){                  tp_score++;
1165              for (Int_t ih=0; ih < oi->npmtadc; ih++){                  totp_score++;
               Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  
               if(pl == 4){  
                 nphit_i++;  
                 enhit_i += (op->dedx).At(ih);  
               };  
1166              };              };
1167            };                          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && oi ){
1168                    //
1169                    Float_t sen = 0.;
1170                    for (Int_t ih=0; ih < op->npmtadc; ih++){
1171                        Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1172                        if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih);
1173                    };
1174                    for (Int_t ih=0; ih < oi->npmtadc; ih++){
1175                        Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1176                        if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);
1177                    };
1178                    //
1179                    if (  sen >= sortthr && false){ // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
1180                        //printf(" IS A NUCLEUS! en = %f \n",sen);
1181                        //
1182                        // is a nucleus use a different algorithm
1183                        //
1184                        Int_t nz = 6; Float_t zin[6];                                          // << define TOF z-coordinates
1185                        for(Int_t ip=0; ip<nz; ip++)
1186                            zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip));     // << read ToF plane z-coordinates
1187                        Trajectory *tr = new Trajectory(nz,zin);
1188                        //
1189                        Int_t nphit_p =0;
1190                        Int_t nphit_i =0;
1191                        Float_t enhit_p = 0.;
1192                        Float_t enhit_i = 0.;
1193                        //
1194                        for (Int_t ih=0; ih < op->npmtadc; ih++){
1195                            Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1196                            if(pl == 1 || pl == 2 || pl == 5){
1197                                nphit_p++;
1198                                enhit_p += (op->dedx).At(ih);
1199                            };
1200                        };
1201                        //
1202                        tp->DoTrack2(tr);
1203                        //
1204                        if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1205                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1206                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1207                                if(pl == 0){
1208                                    nphit_p++;
1209                                    enhit_p += (op->dedx).At(ih);
1210                                };
1211                            };
1212                        };
1213                        if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1214                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1215                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1216                                if(pl == 3){
1217                                    nphit_p++;
1218                                    enhit_p += (op->dedx).At(ih);
1219                                };
1220                            };
1221                        };
1222                        if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1223                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1224                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1225                                if(pl == 4){
1226                                    nphit_p++;
1227                                    enhit_p += (op->dedx).At(ih);
1228                                };
1229                            };
1230                        };
1231    
1232                        for (Int_t ih=0; ih < oi->npmtadc; ih++){
1233                            Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1234                            if(pl == 1 || pl == 2 || pl == 5){
1235                                nphit_i++;  
1236                                enhit_i += (op->dedx).At(ih);
1237                            };
1238                        };
1239                        //
1240                        ti->DoTrack2(tr);
1241                        //
1242                        if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1243                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1244                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1245                                if(pl == 0){
1246                                    nphit_i++;
1247                                    enhit_i += (op->dedx).At(ih);
1248                                };
1249                            };
1250                        };
1251                        if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1252                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1253                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1254                                if(pl == 3){
1255                                    nphit_i++;
1256                                    enhit_i += (op->dedx).At(ih);
1257                                };
1258                            };
1259                        };
1260                        if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1261                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1262                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1263                                if(pl == 4){
1264                                    nphit_i++;
1265                                    enhit_i += (op->dedx).At(ih);
1266                                };
1267                            };
1268                        };          
1269    
1270                                    
1271            if(                      if(
1272               use_TOF            &&                          (use_TOF || use_S1 || use_S2 || use_S3)            &&
1273               (nphit_p+nphit_i) !=0 &&                            (nphit_p+nphit_i) !=0 &&        
1274               true){                          true){
1275                                            
1276              //      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);                          //          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);
1277              //      printf(" score p %i score i %i \n",tp_score,ti_score);                          //          printf(" score p %i score i %i \n",tp_score,ti_score);
1278              //            if( enhit_p > enhit_i ) tp_score++;                          //                if( enhit_p > enhit_i ) tp_score++;
1279              //            if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;                          //                if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
1280              if ( nphit_p > nphit_i ) tp_score++;                          if ( nphit_p > nphit_i ) tp_score++;
1281              if ( nphit_p < nphit_i ) ti_score++;                          if ( nphit_p < nphit_i ) ti_score++;
1282              if ( nphit_p == nphit_i ){                          if ( nphit_p == nphit_i ){
1283                if ( enhit_p > enhit_i ) tp_score++;                              if ( enhit_p > enhit_i ) tp_score++;
1284                else ti_score++;                              else ti_score++;
1285              };                          };
1286              //      printf(" dopo score p %i score i %i \n",tp_score,ti_score);                          //          printf(" dopo score p %i score i %i \n",tp_score,ti_score);
1287            };                      };
1288            delete tr;                      delete tr;
1289            //                      //
1290          } else {                  } else {
1291            //                      // -------------
1292            // NOT a NUCLEUS                      // NOT a NUCLEUS
1293            //                      // -------------
1294            //printf(" NOT a NUCLEUS! en = %f \n",sen);                      //printf(" NOT a NUCLEUS! en = %f \n",sen);
1295    
1296            Int_t nphit_p =0;                      Int_t nphit_p =0;
1297            Int_t nphit_i =0;                      Int_t nphit_i =0;
1298                                    
1299                                    
1300            /*                            cout << "track: npmtadc "<< op->npmtadc << endl;                      /*                          cout << "track: npmtadc "<< op->npmtadc << endl;
1301              cout << "track: npmttdc "<< op->npmttdc << endl;                                                  cout << "track: npmttdc "<< op->npmttdc << endl;
1302              cout << "image: npmtadc "<< oi->npmtadc << endl;                                                  cout << "image: npmtadc "<< oi->npmtadc << endl;
1303              cout << "image: npmttdc "<< oi->npmttdc << endl;*/                                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1304                                    
1305  //        for (Int_t ih=0; ih < op->npmtadc; ih++){  //        for (Int_t ih=0; ih < op->npmtadc; ih++){
1306  //          Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
# Line 886  void PamLevel2::SortTracks(){ Line 1311  void PamLevel2::SortTracks(){
1311  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1312  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1313  //        };  //        };
1314            // --- modified to count tdc signals (more efficient?)                      // --- modified to count tdc signals (more efficient?)
1315            // --- and to implement check on tdcflag                      // --- and to implement check on tdcflag
1316            for (Int_t ih=0; ih < op->npmttdc; ih++){                      for (Int_t ih=0; ih < op->npmttdc; ih++){
1317              Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );                          Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );
1318  //          if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;  //          if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
1319              if( (op->tdcflag).At(ih)==0 )nphit_p++;                          if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){
1320            };                              if( (op->tdcflag).At(ih)==0 )nphit_p++;
1321                            };
1322                        };
1323                                    
1324            for (Int_t ih=0; ih < oi->npmttdc; ih++){                      for (Int_t ih=0; ih < oi->npmttdc; ih++){
1325              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );                          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );
1326  //          if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;    //          if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;  
1327              if( (oi->tdcflag).At(ih)==0 )nphit_i++;                              if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){
1328            };                              if( (oi->tdcflag).At(ih)==0 )nphit_i++;    
1329                            };
1330                        };
1331                                    
1332            if(                      if(
1333               (nphit_p+nphit_i) !=0 &&                            (nphit_p+nphit_i) !=0 &&        
1334               true){                          true){
1335                                            
1336              if     ( nphit_p > nphit_i) tp_score++;                          if ( nphit_p != nphit_i ){
1337              else if( nphit_p < nphit_i) ti_score++;                              totp_score += nphit_p;
1338              else ;//niente                              toti_score += nphit_i;
1339            };                              tp_score+=nphit_p;
1340          };                              ti_score+=nphit_i;
1341          //      cout << "TOF "<<tp_score<<ti_score<<endl;                          };
1342        };                          //          if     ( nphit_p > nphit_i) tp_score+=nphit_p;
1343                            //          else if( nphit_p < nphit_i) ti_score+=nphit_i;
1344                            //          else ;//niente
1345                        };
1346                    };
1347                    //      cout << "TOF "<<tp_score<<ti_score<<endl;
1348                };
1349    
1350    
1351  //      if(tp_score == ti_score) use_TRK = true;  //      if(tp_score == ti_score) use_TRK = true;
1352    
1353    
1354        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1355        // tracker check              // *****************************************************************************************
1356        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1357        // chi**2 difference is not always large enough to distinguish among              // tracker check
1358        // the real track and its image.              // -----------------------------------------------------------------------------------------
1359        // Tracker check will be applied always when calorimeter and tof information is ambiguous.              // chi**2 difference is not always large enough to distinguish among
1360        // *** MODIFIED ON AUGUST 2007 ***              // the real track and its image.
1361        if(use_TRK){              // Tracker check will be applied always when calorimeter and tof information is ambiguous.
1362                // *** MODIFIED ON AUGUST 2007 ***
1363                if(use_TRK){
1364  //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;  //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
1365  //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;  //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
1366    
1367            // CHECK 1 : number of points along X                    // CHECK 1 : number of points along X  
1368            if ( tp->GetNX() >= ti->GetNX() )tp_score++ ;                  if ( tp->GetNX() >= ti->GetNX() ){
1369            if ( tp->GetNX() <= ti->GetNX() )ti_score++ ;                      tp_score++ ;
1370            // CHECK 2 : number of points along Y                        totp_score++ ;
1371            if ( tp->GetNY() >= ti->GetNY() )tp_score++ ;                  };
1372            if ( tp->GetNY() <= ti->GetNY() )ti_score++ ;                  if ( tp->GetNX() <= ti->GetNX() ){
1373            // CHECK 3 : chi**2 along X                        ti_score++ ;
1374  //        if(      tp->GetChi2X() > 0 && (tp->GetChi2X() < ti->GetChi2X() || ti->GetChi2X() <=0) ) tp_score++ ;                      toti_score++ ;
1375  //        if(      ti->GetChi2X() > 0 && (ti->GetChi2X() < tp->GetChi2X() || tp->GetChi2X() <=0) ) ti_score++ ;                  };
1376            // CHECK 4 : chi**2 along Y                    // CHECK 2 : number of points along Y  
1377  //        if(      tp->GetChi2Y() > 0 && (tp->GetChi2Y() < ti->GetChi2Y() || ti->GetChi2Y() <=0) ) tp_score++ ;                  if ( tp->GetNY() >= ti->GetNY() ){
1378  //        if(      ti->GetChi2Y() > 0 && (ti->GetChi2Y() < tp->GetChi2Y() || tp->GetChi2Y() <=0) ) ti_score++ ;                      tp_score++ ;
1379            // CHECK 5 : total chi**2                        totp_score++ ;
1380  //        if(      tp->chi2 > 0 && (tp->chi2 < ti->chi2 || ti->chi2 <=0) ) tp_score++ ;                  };
1381  //        if(      ti->chi2 > 0 && (ti->chi2 < tp->chi2 || tp->chi2 <=0) ) ti_score++ ;                  if ( tp->GetNY() <= ti->GetNY() ){
1382                        ti_score++ ;
1383                        toti_score++ ;
1384                    };
1385    
1386                    //      cout << "TRK "<<tp_score<<ti_score<<endl;
1387                };
1388                
1389    
1390          //      cout << "TRK "<<tp_score<<ti_score<<endl;              // -----------------------------------------------------------------------------------------
1391        };              // *****************************************************************************************
1392                // -----------------------------------------------------------------------------------------
1393                // GPamela check
1394                // -----------------------------------------------------------------------------------------
1395                            
1396                //---------------------------------------------------
1397                // count the number of GP hits
1398                //---------------------------------------------------
1399                if(use_GP){
1400                    int ngphits_p=0;
1401                    int ngphits_i=0;
1402                    float toll = 0.02; //200 micron
1403                    for(int ih=0; ih<GetGPamela()->Nthspe; ih++){
1404                        int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
1405                        if(
1406                            tp &&
1407                            tp->YGood(ip) &&
1408                            fabs(tp->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1409                            true) ngphits_p++;
1410                        if( ti &&
1411                            ti->YGood(ip) &&
1412                            fabs(ti->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1413                            true) ngphits_i++;
1414                    }
1415                    if(
1416                        ngphits_p > ngphits_i &&
1417                        true){
1418                        tp_score++ ;
1419                        totp_score++ ;                  
1420                    }
1421                    if(
1422                        ngphits_p < ngphits_i &&
1423                        true){
1424                        ti_score++ ;
1425                        toti_score++ ;                  
1426                    }
1427                }
1428    
1429    
1430        // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*              // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1431        // the winner is....              // the winner is....
1432        // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*              // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1433        if      (tp_score > ti_score) {              if      (tp_score > ti_score) {
1434                    
1435    
1436        }else if (tp_score < ti_score) {              }else if (tp_score < ti_score) {
   
1437    
         ts = ti;//its image!!  
         cs = ci;  
         os = oi;  
1438    
1439          ti = tp;//its image!!                  ts = ti;//its image!!
1440          ci = cp;                  cs = ci;
1441          oi = op;                  os = oi;
1442                    rs = ri;
1443                    Int_t totis = toti_score;
1444    
1445                    ti = tp;//its image!!
1446                    ci = cp;
1447                    oi = op;
1448                    ri = rp;
1449    
1450                    tp = ts;//its image!!
1451                    cp = cs;
1452                    op = os;
1453                    rp = rs;
1454    
1455          tp = ts;//its image!!                  toti_score = totp_score;
1456          cp = cs;                  totp_score = totis;
         op = os;  
1457    
1458                                    
1459        }else {              }else {
1460    
1461  //      cout << "Warning - track image ambiguity not solved" << endl;  //      cout << "Warning - track image ambiguity not solved" << endl;
1462    
1463        };              };
1464                            
1465      }else{          }else{
1466        //            ts = tp;              totp_score = 1;
1467        //            cs = cp;              toti_score = 0;
1468        //            os = op;        
1469      };              //      ts = tp;
1470                //      cs = cp;
1471                //      os = op;
1472            };
1473                    
1474      //  cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;          //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
1475      //  sorted_tracks->Add(ts);//save the track in the sorted array          //      sorted_tracks->Add(ts);//save the track in the sorted array
1476      //  sorted_tracks.Add(ts);//save the track in the sorted array          //      sorted_tracks.Add(ts);//save the track in the sorted array
1477      //  sorted_tracks.Add(tp);//save the track in the sorted array          //      sorted_tracks.Add(tp);//save the track in the sorted array
1478      //  cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;          //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
1479      //  cout<<"o "<<tp<<endl;          //      cout<<"o "<<tp<<endl;
1480      //  cout<<"o "<<cp<<endl;          //      cout<<"o "<<cp<<endl;
1481      //  cout<<"o "<<op<<endl;          //      cout<<"o "<<op<<endl;
1482      new(ttsorted[i]) PamTrack(tp,cp,op);  
1483      new(ttimage[i])  PamTrack(ti,ci,oi);          new(ttsorted[i]) PamTrack(tp,cp,op,rp);
1484    };          new(ttimage[i])  PamTrack(ti,ci,oi,ri);
1485    
1486    if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){          ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);
1487      cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;          ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);
1488      tsorted->Delete(); tsorted=0;          ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);
1489      timage->Delete(); timage=0;          ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);
1490    }      };
1491    
1492    //Restore Object count      if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
1493    //To save space in the table keeping track of all referenced objects          cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;
1494    //We reset the object count to what it was at the beginning of the event.          tsorted->Delete(); tsorted=0;
1495    TProcessID::SetObjectCount(ObjectNumber);          timage->Delete(); timage=0;    
1496        }
1497    
1498        //Restore Object count
1499        //To save space in the table keeping track of all referenced objects
1500        //We reset the object count to what it was at the beginning of the event.
1501        TProcessID::SetObjectCount(ObjectNumber);
1502            
1503  };  };
1504  //--------------------------------------  //--------------------------------------
# Line 1032  TClonesArray *PamLevel2::GetTracks(){ Line 1527  TClonesArray *PamLevel2::GetTracks(){
1527    
1528      return tsorted;      return tsorted;
1529            
1530   };  };
1531  //--------------------------------------  //--------------------------------------
1532   //  //
1533   //  //
1534  //--------------------------------------  //--------------------------------------
1535  /**  /**
1536   * Retrieves the it-th Pamela "physical" track.   * Retrieves the it-th Pamela "physical" track.
# Line 1096  PamTrack *PamLevel2::GetTrack(int it){ Line 1591  PamTrack *PamLevel2::GetTrack(int it){
1591   */   */
1592  PamTrack *PamLevel2::GetTrackImage(int it){  PamTrack *PamLevel2::GetTrackImage(int it){
1593    
 //     if(!trk2_obj) return 0;  
   
 // //  *-*-*-*-*-*-*-*-*-*-*-*-*  
 //     SortTracks("+CAL+TOF");  
 // //  *-*-*-*-*-*-*-*-*-*-*-*-*  
 // //    if(!sorted_tracks)return 0;  
 //     if(sorted_tracks.IsEmpty())return 0;  
       
 //     PamTrack *image = 0;  
       
 //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){  
 //      TrkTrack *temp = (TrkTrack*)sorted_tracks.At(it);  
 //      if( temp->HasImage() ){  
 //          TrkTrack   *t = trk2_obj->TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());  
 //          image = GetPamTrackAlong(t);  
 //      }else{  
 //          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;  
 //      };  
 //     }else{  
 //      cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;  
 //     };  
       
 //     return image;  
   
   
1594  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1595      SortTracks();      SortTracks();
1596  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
# Line 1157  PamTrack *PamLevel2::GetTrackImage(int i Line 1627  PamTrack *PamLevel2::GetTrackImage(int i
1627   */   */
1628  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){
1629    
1630  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {
1631  //     else                    GetWhichTrees(f);          cout << "+AUTO"<<endl;
1632    if ( pam_tree ){          GetWhichTrees(f);
1633      printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");      };
1634      return pam_tree;      SetWhichTrees(detlist);
1635    };  
1636    //      if ( pam_tree ){
1637            printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");
1638            return pam_tree;
1639        };
1640        //
1641    
1642      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
1643    
1644      SetWhichTrees(detlist);  //    SetWhichTrees(detlist);
1645    
1646      TTree *Trout =0;      TTree *Trout =0;
1647    
# Line 1188  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1662  TTree *PamLevel2::GetPamTree(TFile *f, T
1662      if(ND)cout<<"ND ";      if(ND)cout<<"ND ";
1663      if(S4)cout<<"S4 ";      if(S4)cout<<"S4 ";
1664      if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
1665        if(GP)cout<<"GP ";
1666      cout << endl;      cout << endl;
1667      if(SELLI)cout<<">>> Found selection-list <<<"<<endl;      if(SELLI)cout<<">>> Found selection-list <<<"<<endl;
1668    
# Line 1286  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1761  TTree *PamLevel2::GetPamTree(TFile *f, T
1761          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
1762      };      };
1763    
1764        // GPamela
1765        TTree *G = (TTree*)f->Get("h20");
1766        if(G && GP) {
1767            if(!gp_obj)gp_obj=new GPamela();
1768    //      ------------------------------------
1769    //      ATTENZIONE!!!
1770    //      non so per quale arcano motivo,
1771    //      per l'albero di gpamela il branch address lo devo settare
1772    //      DOPO aver fatto friend
1773    //      FGRRRVZZZZUTSALKJMSLKJ!!!
1774    //      ------------------------------------
1775    //      gp_obj->SetBranchAddress(G); //ho dovuto fare in maniera diversa dagli altri
1776    //      cout << "h20          : set branch address GPamela "<<endl;
1777            if(!Trout)Trout=G;
1778            else Trout->AddFriend(G);
1779        }else{
1780    //      cout << "h20          : missing tree"<<endl;
1781        };
1782    
1783    
1784      TTree *L = (TTree*)f->Get("SelectionList");      TTree *L = (TTree*)f->Get("SelectionList");
1785      if(L && SELLI==1) {      if(L && SELLI==1) {
1786  //      L->SetBranchAddress("RunEntry",&irun);          cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemented!!!!"<<endl;
 //      cout << "SelectionList: set branch address RunEntry"<<endl;  
 //      L->SetBranchAddress("EventEntry",&irunentry);  
 //      cout << "SelectionList: set branch address EventEntry"<<endl;  
 //      if(!Trout)Trout=O;  
 //      else Trout->AddFriend("SelectionList");  
         cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemente!!!!"<<endl;  
1787          sel_tree = 0;          sel_tree = 0;
1788      }else{      }else{
1789          cout << "SelectionList  : missing tree"<<endl;          cout << "SelectionList  : missing tree"<<endl;
# Line 1302  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1791  TTree *PamLevel2::GetPamTree(TFile *f, T
1791            
1792      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1793    
1794    //      ------------------------------------
1795    //      ATTENZIONE!!!
1796    //      non so per quale arcano motivo,
1797    //      per l'albero di gpamela il branch address lo devo settare
1798    //      DOPO aver fatto friend
1799    //      FGRRRVZZZZUTSALKJMSLKJ!!!
1800    //      ------------------------------------
1801        if(G && GP) {      
1802            gp_obj->SetBranchAddress(Trout); //ho dovuto fare in maniera diversa dagli altri
1803            cout << "h20          : set branch address GPamela "<<endl;
1804        }else{
1805            cout << "h20          : missing tree"<<endl;
1806        };
1807    
1808      pam_tree = (TChain*)Trout;      pam_tree = (TChain*)Trout;
1809            
1810      return Trout;      return Trout;
# Line 1325  TList*  PamLevel2::GetListOfLevel2Files( Line 1828  TList*  PamLevel2::GetListOfLevel2Files(
1828      //    if(ddir=="")ddir = wdir;      //    if(ddir=="")ddir = wdir;
1829  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1830      if ( ddir != ""){      if ( ddir != ""){
1831        cout << "Level2 data directory : "<<  ddir << endl;          cout << "Level2 data directory : "<<  ddir << endl;
1832      } else {      } else {
1833        cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory " << endl;          cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory " << endl;
1834      };      };
1835      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
1836      contents->SetOwner();      contents->SetOwner();
# Line 1344  TList*  PamLevel2::GetListOfLevel2Files( Line 1847  TList*  PamLevel2::GetListOfLevel2Files(
1847  //          return 0;  //          return 0;
1848  //      }        //      }      
1849  //      flisttxt = fullpath;  //      flisttxt = fullpath;
1850        if ( !flisttxt.EndsWith(".root") ){          if ( !flisttxt.EndsWith(".root") ){
1851    
1852          flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1853    
1854          if( !gSystem->ChangeDirectory(ddir) ){              if( !gSystem->ChangeDirectory(ddir) ){
1855              cout << "Cannot change directory : "<<ddir<<endl;                  cout << "Cannot change directory : "<<ddir<<endl;
1856              return 0;                  return 0;
         }  
           
         cout <<"Input file list : " << flisttxt <<endl;  
         ifstream in;  
         in.open(flisttxt, ios::in); //open input file list  
         if(!in.good()){  
             cout <<" ERROR opening the file "<<endl;  
             gSystem->ChangeDirectory(wdir); // back to the working directory  
             return 0;  
         }        
         int line=0;  
         while (1) {  
             TString file;  
             in >> file;  
             if (!in.good()) break;  
             line++;  
 //          cout <<"(1) " << file << endl;  
             if(file.IsNull()){  
                 cout << "-- list interrupted at line "<<line <<endl;  
                 break;  
1857              }              }
1858              if(file.Contains("#"))file = file(0,file.First("#"));          
1859                cout <<"Input file list : " << flisttxt <<endl;
1860                ifstream in;
1861                in.open(flisttxt, ios::in); //open input file list
1862                if(!in.good()){
1863                    cout <<" ERROR opening the file "<<endl;
1864                    gSystem->ChangeDirectory(wdir); // back to the working directory
1865                    return 0;
1866                }  
1867                int line=0;
1868                while (1) {
1869                    TString file;
1870                    in >> file;
1871                    if (!in.good()) break;
1872                    line++;
1873    //          cout <<"(1) " << file << endl;
1874                    if(file.IsNull()){
1875                        cout << "-- list interrupted at line "<<line <<endl;
1876                        break;
1877                    }
1878                    if(file.Contains("#"))file = file(0,file.First("#"));
1879  //          cout <<"(2) " << file << endl;  //          cout <<"(2) " << file << endl;
1880  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1881  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
1882              if( file.EndsWith(".root") ){                  if( file.EndsWith(".root") ){
1883                TString filedir;                      TString filedir;
1884                if (ddir != ""){                      if (ddir != ""){
1885                  filedir = ddir; // take the input dir                          filedir = ddir; // take the input dir
1886                } else {                      } else {
1887                  gSystem->ChangeDirectory(wdir); // back to the working directory                          gSystem->ChangeDirectory(wdir); // back to the working directory
1888                  filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir                          filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir
1889                };                      };
1890                  char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));                      char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));
1891                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list                      contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1892                  delete fullpath;                      delete fullpath;
1893              }                  }
1894  //          }else{  //          }else{
1895  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1896  //          };  //          };
1897          };              };
1898          in.close();              in.close();
1899        } else {          } else {
1900            if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));
1901            char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1902            contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list              contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1903            delete fullpath;              delete fullpath;
1904        };                  };      
1905      }else{      }else{
1906                    
1907          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
1908          cout << "Check for existing root files."<<endl;          cout << "Check for existing root files."<<endl;
1909  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
1910          if ( ddir == "" ){          if ( ddir == "" ){
1911            ddir = wdir;              ddir = wdir;
1912            cout << "Level2 data directory : "<<  ddir << endl;              cout << "Level2 data directory : "<<  ddir << endl;
1913          };          };
1914    
1915          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
# Line 1452  TList*  PamLevel2::GetListOfLevel2Files( Line 1955  TList*  PamLevel2::GetListOfLevel2Files(
1955   * @return Pointer to a TChain   * @return Pointer to a TChain
1956   */   */
1957  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){
1958    //      //
1959    //      //
1960    //      //
1961    if ( pam_tree ){      if ( pam_tree ){
1962      printf("WARNING: TChain *PamLevel2::GetPamTree(TList *fl, TString detlist) -- pam_tree already exists!\n ");          printf("WARNING: TChain *PamLevel2::GetPamTree(TList *fl, TString detlist) -- pam_tree already exists!\n ");
1963      return pam_tree;          return pam_tree;
1964    };      };
1965    //      //
1966            
1967      TChain *Trout =0;      TChain *Trout =0;
1968    
1969  //    if( !detlist.IsNull() )SetWhichTrees(detlist);      // -------------------------------------------
1970      SetWhichTrees(detlist);      // set flags to include/exclude trees/branches
1971            // -------------------------------------------
1972      cout<< "GetPamTree(TList*,TString): input detector list --> ";      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {
1973      if(TRK1)cout<<"TRK1 ";          if( fl->GetEntries()>0 ){
1974      if(TRK2)cout<<"TRK2 ";              cout << "+AUTO"<<endl;
1975      if(TRKh)cout<<"TRKH ";              TFile *fprimo = new TFile( fl->At(0)->GetName() );
1976      if(CAL1)cout<<"CAL1 ";              GetWhichTrees(fprimo);
1977      if(CAL2)cout<<"CAL2 ";              fprimo->Close();// AAAAARGGGGGHHHHH!!!!!!! non commentare questa riga, altrimenti si incasina il TChain
1978      if(TOF)cout<<"TOF ";              fprimo->Delete();
1979      if(TRG)cout<<"TRG ";          }
1980      if(AC)cout<<"AC ";      };
1981      if(ND)cout<<"ND ";      SetWhichTrees(detlist);    
1982      if(S4)cout<<"S4 ";  
     if(ORB)cout<<"ORB ";  
     cout << endl;  
1983    
1984       TChain *T = 0;          // -------------------------------------------
1985       TChain *C = 0;      // build chains
1986       TChain *O = 0;      // -------------------------------------------
1987       TChain *R = 0;      TChain *T = 0;      
1988       TChain *S = 0;      TChain *C = 0;
1989       TChain *N = 0;      TChain *O = 0;
1990       TChain *A = 0;      TChain *R = 0;
1991       TChain *B = 0;      TChain *S = 0;
1992        TChain *N = 0;
1993        TChain *A = 0;
1994        TChain *B = 0;
1995        TChain *G = 0;
1996    
1997       TChain *L = 0;      TChain *L = 0;
1998            
1999      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
2000      if(CAL2||CAL1)       C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
# Line 1499  TChain *PamLevel2::GetPamTree(TList *fl, Line 2004  TChain *PamLevel2::GetPamTree(TList *fl,
2004      if(ND)               N = new TChain("NeutronD");      if(ND)               N = new TChain("NeutronD");
2005      if(AC)               A = new TChain("Anticounter");      if(AC)               A = new TChain("Anticounter");
2006      if(ORB)              B = new TChain("OrbitalInfo");      if(ORB)              B = new TChain("OrbitalInfo");
2007       L = new TChain("SelectionList");      if(GP)               G = new TChain("h20");
2008        L = new TChain("SelectionList");
2009            
2010      // loop over files and create chains              // loop over files and create chains        
2011      TIter next(fl);      TIter next(fl);
# Line 1516  TChain *PamLevel2::GetPamTree(TList *fl, Line 2022  TChain *PamLevel2::GetPamTree(TList *fl,
2022              if(ND)               N->Add(name);              if(ND)               N->Add(name);
2023              if(AC)               A->Add(name);              if(AC)               A->Add(name);
2024              if(ORB)              B->Add(name);              if(ORB)              B->Add(name);
2025                if(GP)               G->Add(name);
2026              if(SELLI==1)         L->Add(name);              if(SELLI==1)         L->Add(name);
2027          };          };
2028      };      };
2029            
2030      cout << "done chain \n";      cout << "done chains\n";
2031      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2032    
2033  //    UInt_t *found=0;  
2034        // -------------------------------------------
2035        // make friends
2036        // -------------------------------------------
2037    
2038  // Tracker  // Tracker
2039        cout << "Friends: "<<endl;
2040      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
         if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));  
 //      else    T->SetBranchStatus("TrkLevel2",0,found);  
         if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;  
         if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));  
 //      else    T->SetBranchStatus("TrkLevel1",0,found);  
         if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;  
         if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));  
 //      else    T->SetBranchStatus("TrkHough",0,found);  
         if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;  
2041          if(!Trout)Trout=T;          if(!Trout)Trout=T;
2042          else Trout->AddFriend("Tracker");          else Trout->AddFriend("Tracker");
2043      }else{  //      cout << "+Tacker"<<endl;
         cout << "Tracker      : missing tree"<<endl;  
2044      };      };
2045      // Calorimeter      // Calorimeter
2046      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
         if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));  
 //      else    C->SetBranchStatus("CaloLevel2",0,found);  
         if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;  
         if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));  
 //      else    C->SetBranchStatus("CaloLevel1",0,found);  
         if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;  
2047          if(!Trout)Trout=C;          if(!Trout)Trout=C;
2048          else Trout->AddFriend("Calorimeter");          else Trout->AddFriend("Calorimeter");
2049      }else{  //      cout << "+Calorimeter"<<endl;
         cout << "Calorimeter  : missing tree"<<endl;  
2050      };      };
2051      // ToF          // ToF    
2052      if(O && TOF) {      if(O && TOF) {
         O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));  
         cout << "ToF          : set branch address ToFLevel2"<<endl;  
2053          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2054          else Trout->AddFriend("ToF");          else Trout->AddFriend("ToF");
2055      }else{  //      cout << "+ToF"<<endl;
         cout << "ToF         : missing tree"<<endl;  
2056      };      };
2057      // Trigger      // Trigger
2058      if(R && TRG) {      if(R && TRG) {
         R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));  
         cout << "Trigger      : set branch address TrigLevel2"<<endl;  
2059          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2060          else Trout->AddFriend("Trigger");          else Trout->AddFriend("Trigger");
2061      }else{  //      cout << "+Trigger"<<endl;
         cout << "Trigger      : missing tree"<<endl;  
2062      };      };
2063      // S4      // S4
2064      if(S && S4) {      if(S && S4) {
         S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));  
         cout << "S4           : set branch address S4Level2"<<endl;  
2065          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2066          else Trout->AddFriend("S4");          else Trout->AddFriend("S4");
2067      }else{  //      cout << "+S4"<<endl;
         cout << "S4           : missing tree"<<endl;  
2068      };      };
2069      // Neutron Detector      // Neutron Detector
2070      if(N && ND) {      if(N && ND) {
         N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));  
         cout << "NeutronD     : set branch address NDLevel2"<<endl;  
2071          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2072          else Trout->AddFriend("NeutronD");          else Trout->AddFriend("NeutronD");
2073      }else{  //      cout << "+NeutronD"<<endl;
         cout << "NeutronD     : missing tree"<<endl;  
2074      };      };
2075      // Anticounters      // Anticounters
2076      if(A && AC) {      if(A && AC) {
         A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));  
         cout << "Anticounter  : set branch address AcLevel2"<<endl;  
2077          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2078          else Trout->AddFriend("Anticounter");          else Trout->AddFriend("Anticounter");
2079      }else{  //      cout << "+Anticounter"<<endl;
         cout << "Anticounter  : missing tree"<<endl;  
2080      };      };
2081      // Orbital Info      // Orbital Info
2082      if(B && ORB) {      if(B && ORB) {
         B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));  
         cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;  
2083          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2084          else Trout->AddFriend("OrbitalInfo");          else Trout->AddFriend("OrbitalInfo");
2085      }else{  //      cout << "+OrbitalInfo"<<endl;
2086          cout << "OrbitalInfo  : missing tree"<<endl;      };
2087        // GPamela
2088        if(G && GP) {
2089            if(!Trout)Trout=G;
2090            else Trout->AddFriend("h20");
2091    //      cout << "+h20"<<endl;
2092      };      };
2093    
2094    //  =====================================
2095    //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND
2096    //  =====================================
2097        SetBranchAddress(Trout);
2098    
2099    
2100    //  ------------------------------------
2101    //  finally handle selection trees...
2102    //  (it is not friend of pamela tree)
2103    //  ------------------------------------
2104    
2105      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2106    
2107      // Selection List      // Selection List
2108      if(L && SELLI==1) {      if(L && SELLI==1) {
2109          cout<<">>> Found selection-list <<<"<<endl;          cout<<">>> Found selection-list <<<"<<endl;
2110          L->SetBranchAddress("RunEntry",&irun);  //      L->SetBranchAddress("RunEntry",&irun);
2111            L->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2112          cout << "SelectionList: set branch address RunEntry"<<endl;          cout << "SelectionList: set branch address RunEntry"<<endl;
2113          L->SetBranchAddress("EventEntry",&irunentry);          L->SetBranchAddress("EventEntry",&irunentry);
2114          cout << "SelectionList: set branch address EventEntry"<<endl;          cout << "SelectionList: set branch address EventEntry"<<endl;
2115          sel_tree = L;          sel_tree = L;
2116  //      if(!Trout)Trout=O;  //      if(!Trout)Trout=O;
2117  //      else Trout->AddFriend("SelectionList");  //      else Trout->AddFriend("SelectionList");
2118          cout << "----------------------------------------------------" <<endl;          cout << "+SelectionList"<<endl;
2119            cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2120      }else{      }else{
2121  //      cout << "SelectionList  : missing tree"<<endl;  //      cout << "SelectionList  : missing tree"<<endl;
2122          if(L)L->Delete();          if(L)L->Delete();
2123      };      };
2124        
2125  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;  //  --------------------------------------------
2126    //  return the pamela chain with all the friends
2127    //  --------------------------------------------
2128    
2129      pam_tree = Trout;      pam_tree = Trout;
2130        
2131      return Trout;      return Trout;
2132  }  }
2133    
# Line 1654  void PamLevel2::SetBranchAddress(TTree * Line 2153  void PamLevel2::SetBranchAddress(TTree *
2153      ND     = ND  & t->GetBranchStatus("NDLevel2");      ND     = ND  & t->GetBranchStatus("NDLevel2");
2154      AC     = AC  & t->GetBranchStatus("AcLevel2");      AC     = AC  & t->GetBranchStatus("AcLevel2");
2155      ORB    = ORB & t->GetBranchStatus("OrbitalInfo");      ORB    = ORB & t->GetBranchStatus("OrbitalInfo");
2156        GP     = GP  & t->GetBranchStatus("h20");
2157    
2158    
2159      // Tracker      // Tracker
# Line 1710  void PamLevel2::SetBranchAddress(TTree * Line 2210  void PamLevel2::SetBranchAddress(TTree *
2210          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
2211          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
2212      };      };
2213      // SelectionList      // GPamela
2214      if(SELLI==1) {      if(GP) {
2215          t->SetBranchAddress("RunEntry", &irun);  //      GetPointerTo("GPamela");
2216          cout << "SelectionList: set branch address RunEntry"<<endl;          if(!gp_obj)gp_obj = new GPamela();
2217          t->SetBranchAddress("EventEntry", &irunentry);  //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2218          cout << "SelectionList: set branch address EventEntry"<<endl;  // //   t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2219            if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2220            else      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2221    
2222            cout << "h20          : set branch address GPamela "<<endl;
2223      };      };
2224            
2225  }  }
# Line 1724  void PamLevel2::SetBranchAddress(TTree * Line 2228  void PamLevel2::SetBranchAddress(TTree *
2228   */   */
2229  void PamLevel2::SetBranchAddress(TChain *t){  void PamLevel2::SetBranchAddress(TChain *t){
2230    
2231      TRK2    = TRK2 & t->GetBranchStatus("TrkLevel2");  //     TRK2    = TRK2 & t->GetBranchStatus("TrkLevel2");
2232      TRK1    = TRK1 & t->GetBranchStatus("TrkLevel1");  //     TRK1    = TRK1 & t->GetBranchStatus("TrkLevel1");
2233      TRKh    = TRKh & t->GetBranchStatus("TrkHough");  //     TRKh    = TRKh & t->GetBranchStatus("TrkHough");
2234      CAL1    = CAL1 & t->GetBranchStatus("CaloLevel1");  //     CAL1    = CAL1 & t->GetBranchStatus("CaloLevel1");
2235      CAL2    = CAL2 & t->GetBranchStatus("CaloLevel2");  //     CAL2    = CAL2 & t->GetBranchStatus("CaloLevel2");
2236      TOF    = TOF & t->GetBranchStatus("ToFLevel2");  //     TOF    = TOF & t->GetBranchStatus("ToFLevel2");
2237      TRG    = TRG & t->GetBranchStatus("TrigLevel2");  //     TRG    = TRG & t->GetBranchStatus("TrigLevel2");
2238      S4     = S4  & t->GetBranchStatus("S4Level2");  //     S4     = S4  & t->GetBranchStatus("S4Level2");
2239      ND     = ND  & t->GetBranchStatus("NDLevel2");  //     ND     = ND  & t->GetBranchStatus("NDLevel2");
2240      AC     = AC  & t->GetBranchStatus("AcLevel2");  //     AC     = AC  & t->GetBranchStatus("AcLevel2");
2241      ORB    = ORB & t->GetBranchStatus("OrbitalInfo");  //     ORB    = ORB & t->GetBranchStatus("OrbitalInfo");
2242    //    GP     = GP & t->GetBranchStatus("h20");
2243    
2244      // Tracker      // Tracker
2245       if(TRK2) {      if(TRK2) {
2246          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
2247          cout << "Tracker      : set branch address TrkLevel2"<<endl;          cout << "Tracker      : set branch address TrkLevel2"<<endl;
2248      };      };
# Line 1745  void PamLevel2::SetBranchAddress(TChain Line 2250  void PamLevel2::SetBranchAddress(TChain
2250          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
2251          cout << "Tracker      : set branch address TrkLevel1"<<endl;          cout << "Tracker      : set branch address TrkLevel1"<<endl;
2252      };      };
2253       if(TRKh) {      if(TRKh) {
2254          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
2255          cout << "Tracker      : set branch address TrkHough"<<endl;          cout << "Tracker      : set branch address TrkHough"<<endl;
2256       };      };
2257            
2258      // Calorimeter      // Calorimeter
2259      if(CAL2) {      if(CAL2) {
# Line 1790  void PamLevel2::SetBranchAddress(TChain Line 2295  void PamLevel2::SetBranchAddress(TChain
2295          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
2296          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
2297      };      };
2298      // SelectionList      // GPamela
2299      if(SELLI==1) {  //    cout <<"GP "<<GP<<endl;
2300          t->SetBranchAddress("RunEntry", &irun);      if(GP) {
2301          cout << "SelectionList: set branch address RunEntry"<<endl;  //      GetPointerTo("GPamela");
2302          t->SetBranchAddress("EventEntry", &irunentry);          if(!gp_obj)gp_obj = new GPamela();
2303          cout << "SelectionList: set branch address EventEntry"<<endl;          if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2304            else      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2305    //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2306            cout << "h20          : set branch address GPamela "<<endl;
2307      };      };
2308            // SelectionList
2309    //     if(SELLI==1){
2310    //      t->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2311    //      cout << "SelectionList: set branch address RunEntry"<<endl;
2312    //      t->SetBranchAddress("EventEntry",&irunentry);
2313    //      cout << "SelectionList: set branch address EventEntry"<<endl;
2314            
2315    //     }
2316    
2317  }  }
2318    
2319    
# Line 1811  void PamLevel2::SetBranchAddress(TChain Line 2327  void PamLevel2::SetBranchAddress(TChain
2327   * @return Pointer to a TChain   * @return Pointer to a TChain
2328   */   */
2329  TChain *PamLevel2::GetRunTree(TList *fl){  TChain *PamLevel2::GetRunTree(TList *fl){
2330    //      //
2331    //      //
2332    //      //
2333    if ( run_tree ){      if ( run_tree ){
2334      printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");          printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
2335      return run_tree;          return run_tree;
2336    };          };  
2337    //      //
2338    TChain *R = new TChain("Run");  
2339    
2340        TChain *R = new TChain("Run");
2341            
2342      // loop over files and create chains              // loop over files and create chains        
2343      TIter next(fl);      TIter next(fl);
# Line 1831  TChain *PamLevel2::GetRunTree(TList *fl) Line 2349  TChain *PamLevel2::GetRunTree(TList *fl)
2349              R->Add(name);              R->Add(name);
2350          };          };
2351      }      }
2352        
2353    
2354      if(R->GetNtrees()){      if(RUN && R->GetNtrees()){
2355            
2356          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
2357          cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
2358          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2359          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
2360    
2361            irunoffset = new int[R->GetNtrees()];
2362            if(DBG){
2363                cout << "----------------------------------------------------"<<endl;
2364                cout << "irun\t | ";
2365                cout << "tree\t |";
2366    //      cout << "offset\t |";
2367                cout << "RUN\t";
2368                cout << "FRAG\t";
2369                cout << "NEVENTS\t";
2370                cout << "absolute time\t\t\t";
2371                cout << "on-board time";
2372                cout<<endl;
2373            }
2374            for (Int_t ii=0; ii<R->GetEntries(); ii++){
2375                R->GetEntry(ii);
2376                if(DBG){
2377                    cout << ii<< "\t | ";
2378                    cout << R->GetTreeNumber()<< "\t |";
2379    //          cout << R->GetChainOffset()<< "\t |";
2380                    cout <<GetRunInfo()->ID<<"\t";
2381                    cout <<GetRunInfo()->ID_RUN_FRAG<<"\t";
2382                    cout <<GetRunInfo()->NEVENTS<< "\t";
2383                    cout <<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME <<"\t";
2384                    cout <<GetRunInfo()->RUNHEADER_OBT<<" <---> "<<GetRunInfo()->RUNTRAILER_OBT<<"\t";
2385                    cout <<endl;
2386                }
2387                irunoffset[R->GetTreeNumber()]=R->GetChainOffset();
2388            }
2389            cout << "N.run = "<<R->GetEntries()<<endl;
2390            cout << "----------------------------------------------------"<<endl;
2391    
2392    
2393      }else{      }else{
2394          delete R;          delete R;
2395          R=0;          R=0;
2396      }      }
2397        
2398    
2399      run_tree = R;      run_tree = R;
2400    
# Line 1858  TChain *PamLevel2::GetRunTree(TList *fl) Line 2411  TChain *PamLevel2::GetRunTree(TList *fl)
2411   * @return Pointer to a TTree   * @return Pointer to a TTree
2412   */   */
2413  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f){
2414    if ( run_tree ){      if ( run_tree ){
2415      printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");          printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
2416      return run_tree;          return run_tree;
2417    };      };
2418                    
2419    
2420      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
# Line 1873  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2426  TTree *PamLevel2::GetRunTree(TFile *f){
2426          cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
2427          T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2428          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
2429    
2430      }      }
2431    
2432      run_tree = (TChain*)T;      run_tree = (TChain*)T;
# Line 1886  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2440  TTree *PamLevel2::GetRunTree(TFile *f){
2440   * @return true if a new run has been read, false if it is still the same run   * @return true if a new run has been read, false if it is still the same run
2441   */   */
2442  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){
2443    //      //
2444    // check if we have already called once GetEntry, if not call it      // check if we have already called once GetEntry, if not call it
2445    //      //
2446      cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- NON FUNZIONA BENISSIMO.... "<<endl;      cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- ATTENZIONE --- NON E` MANTENUTA!!!!!!!.... "<<endl;
2447      if(!run){      if(!run){
2448            cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree "<<endl;          cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree "<<endl;
2449            return(false);                  return(false);  
2450      }      }
2451      if ( run->GetEntries() <= 0 ) return(false);      if ( run->GetEntries() <= 0 ) return(false);
2452    //      //
2453        
2454    //  Int_t oldrun = irun;      //  Int_t oldrun = irun;
2455    Long64_t oldrun = irun;      Long64_t oldrun = irun;
2456    
2457        // --------------------------------------
2458        // if it is a full file (not preselected)
2459        // --------------------------------------
2460        if(SELLI==0){
2461    
2462            //
2463            // the absolute time is necessary to relate the event with the run
2464            //
2465            if( !GetOrbitalInfo() && !ISGP){
2466                cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2467                return(false);
2468            }
2469    
2470            ULong64_t abstime = 0;
2471            if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;
2472    
2473    // --------------------------------------  
2474    // if it is a full file (not preselected)          //
2475    // --------------------------------------          // the first time the routine is called, set run search from the beginning
2476    if(SELLI==0){          //
2477            if ( irun < 0LL ){
2478        //              irun = 0LL;
2479        // the absolute time is necessary to relate the event with the run              run->GetEntry(irun);
2480        //              runfirstentry = 0LL;
2481        if( !GetOrbitalInfo() && !ISGP){              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2482            cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
           return(false);  
       }  
   
       ULong64_t abstime = 0;  
       if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;  
   
   
       //  
       // the first time the routine is called, set run search from the beginning  
       //  
       if ( irun < 0LL ){  
           irun = 0LL;  
           run->GetEntry(irun);  
           runfirstentry = 0LL;  
           runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);  
           if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;  
2483                        
2484            if( ISGP && run->GetEntries()!=1 ){              if( ISGP && run->GetEntries()!=1 ){
2485                cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl;                  cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl;
2486                cout << "** WARNING ** run will not be updated"<<endl;                  cout << "** WARNING ** run will not be updated"<<endl;
2487            }              }
2488    
2489        };                };      
2490        //          //
2491        if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO          if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2492        //          //
2493        if ( irun == run->GetEntries()-1LL &&          if ( irun == run->GetEntries()-1LL &&
2494             !(abstime >= GetRunInfo()->RUNHEADER_TIME &&               !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2495               abstime <= GetRunInfo()->RUNTRAILER_TIME)                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2496              ){              ){
2497           irun = -1LL;              irun = -1LL;
2498           runfirstentry = 0LL;              irunt = -1LL;
2499           runlastentry = -1LL;              runfirstentry = 0LL;
2500         };              runlastentry = -1LL;
2501        // modificato il controllo sull'aggiornamento del run, per evitare problemi          };
2502        // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)          // modificato il controllo sull'aggiornamento del run, per evitare problemi
2503        //          // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
2504        bool fromfirst = true;          //
2505        //          bool fromfirst = true;
2506        while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){          //
2507            while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){
2508  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
2509            irun++;              irun++;
2510            run->GetEntry(irun);              run->GetEntry(irun);
2511            runfirstentry = runlastentry;              runfirstentry = runlastentry;
2512            if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;
2513            runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2514  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2515  //        cout << "runfirstentry "<<runfirstentry<<endl;  //        cout << "runfirstentry "<<runfirstentry<<endl;
2516            //      printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));              //    printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
2517            //      printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);              //    printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);
2518            //      printf(" IDRUN %u \n",GetRunInfo()->ID);              //    printf(" IDRUN %u \n",GetRunInfo()->ID);
2519            //              //
2520  //        prevshift = 0;  //        prevshift = 0;
2521            //              //
2522            if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){              if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){
2523                printf(" resetting irun  (it should NOT happen!!!)\n");                  printf(" resetting irun  (it should NOT happen!!!)\n");
2524                fromfirst = false;                  fromfirst = false;
2525                irun = 0;                  irun = 0;
2526                run->GetEntry(irun);                  run->GetEntry(irun);
2527                runfirstentry = 0ULL;                  runfirstentry = 0ULL;
2528                runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);                  runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2529                if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;                  if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2530            };              };
2531            //              //
2532        };          };
2533        //          //
2534        if (          if (
2535             !(abstime >= GetRunInfo()->RUNHEADER_TIME &&              !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2536               abstime <= GetRunInfo()->RUNTRAILER_TIME)                abstime <= GetRunInfo()->RUNTRAILER_TIME)
2537            ) {              ) {
2538            printf(" Something very wrong here: cannot find RUN containing absolute time %u \n",abstime);              printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n",abstime);
2539            return false;              return false;
2540        }          }
2541        //          //
2542        if ( irun == oldrun || irun >= run->GetEntries() ) return(false);          if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
2543        //          //
2544        //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);          //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
2545        //          //
2546        prevshift = 0;          prevshift = 0;
2547        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;          cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2548  //      cout << "runfirstentry "<<runfirstentry<<endl;  //      cout << "runfirstentry "<<runfirstentry<<endl;
2549        return(true);              return(true);    
2550    };      };
2551    // ----------------------------------------------------      // ----------------------------------------------------
2552    // if it is a preselected file (there is SelectionList)      // if it is a preselected file (there is SelectionList)
2553    // NBNB - the event tree MUST be read first      // NBNB - the event tree MUST be read first
2554    // ----------------------------------------------------      // ----------------------------------------------------
2555    if(SELLI==1){            if(SELLI==1){      
2556        sel_tree->GetEntry(iev);          sel_tree->GetEntry(iev);
2557  //      cout << irun << " "<< irunentry << endl;  //      cout << irun << " "<< irunentry << endl;
2558        if(irun != oldrun){          if(irun != oldrun){
2559            run->GetEntry(irun);              run->GetEntry(irun);
2560            cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;              cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2561            prevshift = 0;              prevshift = 0;
2562            return true;              return true;
2563        }          }
2564        return false;          return false;
2565    }      }
2566    
2567    return false;      return false;
2568    //      //
2569  };  };
2570    
2571  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){
# Line 2026  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2581  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2581        
2582      Int_t oldrun = irun; // store current run index      Int_t oldrun = irun; // store current run index
2583    
2584        // -----------------------------------------------------------------------
2585        // the first time the routine is called, set run search from the beginning
2586        // -----------------------------------------------------------------------
2587    
2588        if ( irun < 0 ){
2589            irun = 0LL;
2590            irunt = 0LL;
2591            irunentry = 0;
2592            prevshift = 0;
2593            run_tree->GetEntry(irun);
2594            if( !GetOrbitalInfo() )cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated "<<endl;
2595        };      
2596        // ---------------------------------------------------------------
2597        // retrieve OBT and absolute time of the event
2598        // ---------------------------------------------------------------
2599        ULong64_t abstime = 0LL;
2600        ULong64_t obt     = 0LL;
2601        if( GetOrbitalInfo() ){
2602            abstime = GetOrbitalInfo()->absTime;
2603            obt     = GetOrbitalInfo()->OBT;
2604        }else{
2605            abstime = GetRunInfo()->RUNHEADER_TIME;
2606            obt     = GetRunInfo()->RUNHEADER_OBT;
2607        }
2608        
2609    
2610      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2611      // if it is a full file (not preselected)      // if it is a full file (not preselected)
2612      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2613      if(SELLI==0){      if(SELLI==0){
2614    
         ULong64_t abstime = 0;  
         ULong64_t obt     = 0;  
         if( GetOrbitalInfo() ){  
             abstime = GetOrbitalInfo()->absTime;  
             obt     = GetOrbitalInfo()->OBT;  
         }  
2615          // ---------------------------------------------------------------          // ---------------------------------------------------------------
2616          // the absolute time is necessary to relate the event with the run          // increment dead and live-time counters
2617            // (only when reading a file not preselected)
2618          // ---------------------------------------------------------------          // ---------------------------------------------------------------
2619          if( !GetOrbitalInfo() && !ISGP ){          if(SELLI==0){
2620              cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;              if( GetTrigLevel2() ){
2621              return(false);                  totdltime[0]+=GetTrigLevel2()->dltime[0];
2622          }                  totdltime[1]+=GetTrigLevel2()->dltime[1];
         
         // -----------------------------------------------------------------------  
         // the first time the routine is called, set run search from the beginning  
         // -----------------------------------------------------------------------  
         if ( irun < 0 ){  
             irun = 0LL;  
             irunentry = 0;  
             prevshift = 0;  
             run_tree->GetEntry(irun);  
   
             if( ISGP && run_tree->GetEntries()!=1 ){  
                 cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl;  
                 cout << "** WARNING ** run will not be updated"<<endl;  
2623              }              }
2624          };                    totdltime[2]++;
   
         // -----------------------------------------------------------------------  
         // if it is simulation, assigh abstime by end (temporaneo!!!)  
         // -----------------------------------------------------------------------  
         if(ISGP){  
             abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO  
             obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO  
2625          }          }
2626    
2627          //          //
2628          bool fromfirst = true; // first loop over runs          bool fromfirst = true; // first loop over runs
2629    
 //      Bool_t hasfrag = false;  
 //      if( GetRunInfo()->ID_RUN_FRAG!=0 && GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID)hasfrag=true;  
 //      ULong64_t fragid = GetRunInfo()->ID_RUN_FRAG;  
2630    
2631          // ------------------------------------------------------          // ------------------------------------------------------
2632          // loop over runs to find the one that contains the event          // loop over runs to find the one that contains the event
2633          // ------------------------------------------------------          // ------------------------------------------------------
2634          while (          while (
2635              (              (
2636                  (  //              (
2637                      !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)  //                  !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2638                        abstime <= GetRunInfo()->RUNTRAILER_TIME) &&  //                    abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
2639                      !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)  //                  !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2640                        obt <= GetRunInfo()->RUNTRAILER_OBT)  //                    obt <= GetRunInfo()->RUNTRAILER_OBT)
2641                      )  //                  )
2642                  || GetRunInfo()->NEVENTS==0                  
2643                  || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift)                  !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2644                      abstime <= GetRunInfo()->RUNTRAILER_TIME)
2645                    ||
2646                    !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2647                      obt <= GetRunInfo()->RUNTRAILER_OBT)          
2648                    ||
2649                    GetRunInfo()->NEVENTS==0
2650    //              || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento
2651                    ||
2652                    !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)
2653                  )                  )
2654                  && irun < run_tree->GetEntries() ){              && irun < run_tree->GetEntries() ){
2655    
2656              irun++;  
2657    //          if( !(abstime >= GetRunInfo()->RUNHEADER_TIME &&abstime <= GetRunInfo()->RUNTRAILER_TIME)  )cout << "ABS TIME "<<abstime << " " <<GetRunInfo()->RUNTRAILER_TIME <<endl;
2658    //          if( !(obt >= GetRunInfo()->RUNHEADER_OBT && obt <= GetRunInfo()->RUNTRAILER_OBT) )cout << "OBT TIME "<< obt <<" "<< GetRunInfo()->RUNTRAILER_OBT << endl;
2659    //          if( GetRunInfo()->NEVENTS==0  )cout <<"GetRunInfo()->NEVENTS==0 "<<endl;
2660    //          if( !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) ) cout << "irunentry > "<<GetRunInfo()->NEVENTS-1-prevshift << endl;
2661                // - - - - - - - - - - - - -
2662                // irunentry = position of current entry, relative to the run
2663                // prevshift = shift needed to synchronize l0 and l2 data (nested events)
2664                // - - - - - - - - - - - - -
2665    
2666                // -----------------------------------------
2667                // store dead and live-time of previous run
2668                // -----------------------------------------
2669    //          if(SELLI==0){
2670                if(fromfirst){
2671                    if(oldrun==irun){
2672                        /// decrement counters
2673                        if( GetTrigLevel2()){
2674                            totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time
2675                            totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time
2676                        }
2677                        totdltime[2]--;                              //event counter
2678                        cout << endl;
2679                        cout << "n.events     : "<<totdltime[2]<<endl;
2680                        cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;
2681                        cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;      
2682                    }else{
2683                        totdltime[0]=0;//live-time
2684                        totdltime[1]=0;//dead-time
2685                        totdltime[2]=0;                             //event counter
2686                        cout << " *** JUMP RUN *** irun "<<irun<<endl;
2687                    }
2688                    /// add an entry
2689                    if(run_tree_clone)
2690                        if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2691                            run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2692                    /// reset counters
2693                    if( GetTrigLevel2() ){
2694                        totdltime[0]=GetTrigLevel2()->dltime[0];//live-time
2695                        totdltime[1]=0;                         //dead-time
2696                    }
2697                    totdltime[2]=1;                             //event counter
2698                }
2699    //          }
2700    
2701                irun++;        
2702              // ------------------------------------              // ------------------------------------
2703              // if the end of run tree is reached...              // if the end of run tree is reached...
2704              // ------------------------------------              // ------------------------------------
# Line 2117  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2725  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2725              // -------------------------------------------------------------------              // -------------------------------------------------------------------
2726              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;
2727              irunentry = 0;              irunentry = 0;
2728              prevshift = 0;              prevshift = 0;          
2729              run_tree->GetEntry(irun);                    run_tree->GetEntry(irun);//update runinfo
2730                irunt = irun - irunoffset[run_tree->GetTreeNumber()];
2731              if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){              if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){
2732                  cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<"  has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl;                  cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<"  has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl;
2733                  cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl;                  cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl;
# Line 2137  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2746  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2746    
2747          // --------------------------------------          // --------------------------------------
2748          // ... otherwise          // ... otherwise
2749            // --------------------------------------
2750    
2751    
2752            // --------------------------------------
2753          // ---> exit with TRUE          // ---> exit with TRUE
2754          // --------------------------------------          // --------------------------------------
2755          cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;          if(DBG)cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2756            // ----------------------------------------------------
2757            // update the tracker parameters
2758            // (non ho trovato nessun altro modo sicuro di farlo...)
2759            // ----------------------------------------------------
2760            if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection();
2761            TrkParams::Set(GetRunInfo() ,dbc);
2762            if(dbc)dbc->Close();
2763    
2764          // ----------------------------------------------------          // ----------------------------------------------------
2765          // then check if the run has a fragment          // then check if the run has a fragment
2766          // in this case we have to switch to the next fragment          // in this case we have to switch to the next fragment
# Line 2148  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2769  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2769          if(          if(
2770              GetRunInfo()->ID_RUN_FRAG != 0 &&              GetRunInfo()->ID_RUN_FRAG != 0 &&
2771  //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&  //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&
2772                DBG &&
2773              true ){              true ){
2774              cout << "* fragment *"<<endl;                            cout << "* fragment *"<<endl;              
2775          }          }
2776            
2777          return(true);              return(true);    
2778      };      };
2779      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2780      // if it is a preselected file (there is SelectionList)      // if it is a preselected file (there is SelectionList)
2781      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2782        // irun  = run entry relative to the chain
2783        // irunt = run entry relative to the tree
2784      if(SELLI==1){            if(SELLI==1){      
2785          sel_tree->GetEntry(iev);          sel_tree->GetEntry(iev);// read irunt from SelectionList
2786          if(irun != oldrun){          irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
2787              run_tree->GetEntry(irun);          if(irun != oldrun ){
2788              cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;              if( irun < run_tree->GetEntries() )run_tree->GetEntry(irun);
2789                // check if the time is ok (with merged files it is not...)
2790                // if not loop over run and look for the proper entry
2791                bool SECONDO_GIRO=false;
2792                //      Long64_t irun_start   = irun;
2793                int      offset_start = irunoffset[sel_tree->GetTreeNumber()];
2794                while (
2795                    (
2796                        (
2797                            !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2798                              abstime <= GetRunInfo()->RUNTRAILER_TIME)
2799    //                      ||
2800    //                      !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2801    //                        obt <= GetRunInfo()->RUNTRAILER_OBT)
2802                            )
2803                        || GetRunInfo()->NEVENTS==0
2804                        )
2805    //              && irun < run_tree->GetEntries()
2806                    ){
2807    
2808                    if(DBG){
2809                        cout << " (test) ";
2810                        cout << " tree "<<sel_tree->GetTreeNumber();
2811                        cout << " irunt "<<irunt;
2812                        cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2813                        cout << " abs "<<abstime;
2814                        cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2815                        cout << " obt "<<obt;
2816                        cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2817                        cout << " *** JUMP RUN *** irun "<<irun;
2818                        cout << endl;
2819                    }
2820    //              irun++;
2821                    irunoffset[sel_tree->GetTreeNumber()]++;
2822                    irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW          
2823                    if(irun == run_tree->GetEntries() && SECONDO_GIRO){
2824    //              if(irun == irun_start ){
2825                        cout << " ...grrrvzzkhhhajsdkj!!!! "<<endl;
2826                        irunoffset[sel_tree->GetTreeNumber()] = offset_start;
2827                        return false;
2828                    }
2829                    if( irun >= run_tree->GetEntries() || irun < 0){
2830                        cout << "irun = "<<irun<<" >>  search from the beginning... <<"<<endl;
2831                        SECONDO_GIRO=true;
2832                        irun=0;
2833                        irunoffset[sel_tree->GetTreeNumber()]=-irunt;
2834                    }
2835                    run_tree->GetEntry(irun);
2836                }
2837    
2838    
2839                if(DBG){
2840                    cout << " (test) ";
2841                    cout << " tree "<<sel_tree->GetTreeNumber();
2842                    cout << " irunt "<<irunt;
2843                    cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2844                    cout << " abs "<<abstime;
2845                    cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2846                    cout << " obt "<<obt;
2847                    cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2848                }
2849                if(DBG)cout << endl;
2850                if(DBG)cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" (run-entry "<<irun<<")"<<endl;
2851                // ----------------------------------------------------
2852                // update the tracker parameters
2853                // (non ho trovato nessun altro modo sicuro di farlo...)
2854                // ----------------------------------------------------
2855                if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection();
2856                TrkParams::Set(GetRunInfo() ,dbc);
2857                if(dbc)dbc->Close();
2858    //          cout << endl;
2859              prevshift = 0;              prevshift = 0;
2860              return true;              return true;
2861          }          }
# Line 2177  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2871  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2871   * @return true if a new run has been read, false if it is still the same run   * @return true if a new run has been read, false if it is still the same run
2872   */   */
2873  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){
2874    return(UpdateRunInfo((TChain*)run,iev));      return(UpdateRunInfo((TChain*)run,iev));
2875  };  };
2876    
2877  //--------------------------------------  //--------------------------------------
# Line 2187  Bool_t PamLevel2::UpdateRunInfo(TTree *r Line 2881  Bool_t PamLevel2::UpdateRunInfo(TTree *r
2881  /**  /**
2882   * Set which trees shoul be analysed   * Set which trees shoul be analysed
2883   * @param detlist TString containing the sequence of trees required   * @param detlist TString containing the sequence of trees required
2884  */   */
2885  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist){
2886                
2887      if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){  //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
2888          CAL0 = false;      if( detlist.Contains("+ALL", TString::kIgnoreCase)){
2889    
2890            cout << " ======================================================== "<<endl;
2891            cout << "                       (( WARNING ))                      "<<endl;
2892            cout << " The meaning of the option +ALL has changed!!             "<<endl;
2893            cout << " Now it includes really all (level0+level1+level2+gpamela)"<<endl;
2894            cout << " and the file is discarded if it does not contain         "<<endl;
2895            cout << " all trees or  if level0 files are not available!!        "<<endl;
2896            cout << " ======================================================== "<<endl;
2897                
2898            CAL0 = true;
2899          CAL1 = true;          CAL1 = true;
2900          CAL2 = true;          CAL2 = true;
2901          TRK2 = true;          TRK2 = true;
2902          TRK1 = false;          TRK1 = true;
2903          TRKh = false;          TRKh = true;
2904          TRK0 = false;          TRK0 = true;
2905          TRG = true;          TRG = true;
2906          TOF = true;          TOF = true;
2907          TOF0 = false;          TOF0 = true;
2908          S4  = true;          S4  = true;
2909          ND  = true;          ND  = true;
2910          AC  = true;          AC  = true;
2911          ORB = true;          ORB = true;
2912            GP  = true;
2913      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
2914          CAL0 = false;          CAL0 = false;
2915          CAL1 = false;          CAL1 = false;
# Line 2220  void PamLevel2::SetWhichTrees(TString de Line 2925  void PamLevel2::SetWhichTrees(TString de
2925          ND  = false;          ND  = false;
2926          AC  = false;          AC  = false;
2927          ORB = false;          ORB = false;
2928            GP  = false;
2929      };      };
2930            
2931  //  -------------------------------------------------------------------------  //  -------------------------------------------------------------------------
# Line 2293  void PamLevel2::SetWhichTrees(TString de Line 2999  void PamLevel2::SetWhichTrees(TString de
2999      if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;      if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;
3000      else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;      else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;
3001    
3002        if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false;
3003        else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true;
3004    
3005        cout<< "tree/branch list from input --> ";
3006        if(TRK0)cout<<"TRK0 ";
3007        if(TRK1)cout<<"TRK1 ";
3008        if(TRK2)cout<<"TRK2 ";
3009        if(TRKh)cout<<"TRKH ";
3010        if(CAL0)cout<<"CAL0 ";
3011        if(CAL1)cout<<"CAL1 ";
3012        if(CAL2)cout<<"CAL2 ";
3013        if(TOF)cout<<"TOF ";
3014        if(TRG)cout<<"TRG ";
3015        if(AC)cout<<"AC ";
3016        if(ND)cout<<"ND ";
3017        if(S4)cout<<"S4 ";
3018        if(ORB)cout<<"ORB ";
3019        if(GP)cout<<"GP ";
3020        cout << endl;
3021  //     cout<< "Set detector list --> ";  //     cout<< "Set detector list --> ";
3022  //     if(TRK1)cout<<"TRK1 ";  //     if(TRK1)cout<<"TRK1 ";
3023  //     if(TRK2)cout<<"TRK2 ";  //     if(TRK2)cout<<"TRK2 ";
3024  //     if(TRKh)cout<<"TRKH ";  //     if(TRKh)cout<<"TRKH ";
3025  //     if(CAL1)cout<<"CAL1 ";  //     if(CAL1)cout<<"CAL1 ";
3026  //     if(CAL2)cout<<"CAL2 ";  //     if(CAL2)cout<<"CAL2 ";
3027    //     if(TOF0)cout<<"TOF0 ";
3028  //     if(TOF)cout<<"TOF ";  //     if(TOF)cout<<"TOF ";
3029  //     if(TRG)cout<<"TRG ";  //     if(TRG)cout<<"TRG ";
3030  //     if(AC)cout<<"AC ";  //     if(AC)cout<<"AC ";
# Line 2317  void  PamLevel2::GetWhichTrees(TFile* f) Line 3043  void  PamLevel2::GetWhichTrees(TFile* f)
3043            
3044    
3045    
3046      cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;  //    cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
3047      // -----------      // -----------
3048      // reset flags      // reset flags
3049      // -----------      // -----------
# Line 2332  void  PamLevel2::GetWhichTrees(TFile* f) Line 3058  void  PamLevel2::GetWhichTrees(TFile* f)
3058      ND     = false;          ND     = false;    
3059      AC     = false;          AC     = false;    
3060      ORB    = false;          ORB    = false;    
3061        GP     = false;    
3062            
3063      RUN    = false;      RUN    = false;
3064                    
3065      cout << "Checking file: "<<f->GetName()<<endl;  //    cout << "Checking file: "<<f->GetName()<<endl;
3066      if( !f || f->IsZombie() ){      if( !f || f->IsZombie() ){
3067          cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;          cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;
3068          return;          return;
# Line 2422  void  PamLevel2::GetWhichTrees(TFile* f) Line 3149  void  PamLevel2::GetWhichTrees(TFile* f)
3149                  TRK2 = false;                  TRK2 = false;
3150                  TRKh = false;                  TRKh = false;
3151              }else nev=nevt;              }else nev=nevt;
3152              T->Delete();  //          T->Delete();
3153          };          };
3154          //=========================================================            //=========================================================  
3155          if( !strcmp(key->GetName(),"Calorimeter"    ) ){          if( !strcmp(key->GetName(),"Calorimeter"    ) ){
# Line 2438  void  PamLevel2::GetWhichTrees(TFile* f) Line 3165  void  PamLevel2::GetWhichTrees(TFile* f)
3165                  CAL1 = false;                  CAL1 = false;
3166                  CAL2 = false;                  CAL2 = false;
3167              }else nev=nevt;              }else nev=nevt;
3168              T->Delete();  //          T->Delete();
3169          };                };      
3170            //=========================================================  
3171            if( !strcmp(key->GetName(),"h20") ){
3172                GP = true;
3173                Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();
3174                if( nev && nevt!=nev){
3175                    cout << "File: "<< f->GetName() <<" h20 tree has "<<nevt<<" events instead of "<<nev<< endl;
3176                    GP = false;
3177                }else nev=nevt;
3178            }
3179    
3180      };      };
3181            
3182      delete lk;  //    delete lk;
3183    
3184  //     cout<< "Get detector list from input file --> ";      cout<< "tree/branch list from file  --> ";
3185  //     if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
3186  //     if(TRK2)cout<<"TRK2 ";      if(TRK2)cout<<"TRK2 ";
3187  //     if(TRKh)cout<<"TRKH ";      if(TRKh)cout<<"TRKH ";
3188  //     if(CAL1)cout<<"CAL1 ";      if(CAL1)cout<<"CAL1 ";
3189  //     if(CAL2)cout<<"CAL2 ";      if(CAL2)cout<<"CAL2 ";
3190  //     if(TOF)cout<<"TOF ";      if(TOF)cout<<"TOF ";
3191  //     if(TRG)cout<<"TRG ";      if(TRG)cout<<"TRG ";
3192  //     if(AC)cout<<"AC ";      if(AC)cout<<"AC ";
3193  //     if(ND)cout<<"ND ";      if(ND)cout<<"ND ";
3194  //     if(S4)cout<<"S4 ";      if(S4)cout<<"S4 ";
3195  //     if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
3196  //     cout << endl;      if(GP)cout<<"GP ";
3197        cout << endl;
3198                
3199      return ;      return ;
3200                    
# Line 2486  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3223  Bool_t  PamLevel2::CheckLevel2File(TStri
3223      Bool_t ND__ok     = false;          Bool_t ND__ok     = false;    
3224      Bool_t AC__ok     = false;          Bool_t AC__ok     = false;    
3225      Bool_t ORB__ok    = false;          Bool_t ORB__ok    = false;    
3226        Bool_t GP__ok     = false;    
3227            
3228      Bool_t RUN__ok    = false;      Bool_t RUN__ok    = false;
3229            
3230      Bool_t SELLI__ok  = false;      Bool_t SELLI__ok  = false;
3231    
3232      cout << "Checking file: "<<name<<endl;  //    cout << "Checking file: "<<name<<endl;
3233      TFile *f = new TFile(name.Data());      TFile *f = new TFile(name.Data());
3234      if( !f || f->IsZombie() ){      if( !f || f->IsZombie() ){
3235          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 2517  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3255  Bool_t  PamLevel2::CheckLevel2File(TStri
3255  //          return false;  //          return false;
3256  //      };  //      };
3257    
3258            //=========================================================    
3259            // check if the file
3260            
3261    
3262          if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;                if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;      
3263    
# Line 2643  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3384  Bool_t  PamLevel2::CheckLevel2File(TStri
3384              };                  };    
3385              T->Delete();              T->Delete();
3386          };                };      
3387            //=========================================================    
3388            if( !strcmp(key->GetName(),"h20") ){
3389                ISGP = true;    
3390                GP__ok = true;
3391                if(GP){
3392                    Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();
3393                    if( nev && nevt!=nev){
3394                        cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
3395                        return false;
3396                    }
3397                    nev=nevt;
3398                }
3399            }
3400    
3401      };      };
3402    
# Line 2683  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3437  Bool_t  PamLevel2::CheckLevel2File(TStri
3437    
3438    
3439      if(!RUN__ok) {      if(!RUN__ok) {
3440          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;
3441  //      return false;          RUN = false;
3442      };      };
3443    
3444      if(CAL1 && !CAL1__ok){      if(CAL1 && !CAL1__ok){
# Line 2732  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3486  Bool_t  PamLevel2::CheckLevel2File(TStri
3486          cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;          cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;
3487          return false;          return false;
3488      };      };
3489        if(GP && !GP__ok){
3490            cout << "File: "<< f->GetName() <<" discarded ---- Missing h20 tree"<< endl;
3491            return false;
3492        };
3493            
3494    
3495  //    lk->Delete();  //    lk->Delete();
# Line 2750  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3508  Bool_t  PamLevel2::CheckLevel2File(TStri
3508  //     if(ND)cout<<"ND ";  //     if(ND)cout<<"ND ";
3509  //     if(S4)cout<<"S4 ";  //     if(S4)cout<<"S4 ";
3510  //     if(ORB)cout<<"ORB ";  //     if(ORB)cout<<"ORB ";
3511    //     if(GP)cout<<"GP ";
3512  //     cout << endl;  //     cout << endl;
3513                
3514      return true;      return true;
# Line 2802  void PamLevel2::CreateCloneTrees(TFile * Line 3561  void PamLevel2::CreateCloneTrees(TFile *
3561    
3562    
3563  //  if the pointer is null, create a default file  //  if the pointer is null, create a default file
3564        if(!run_tree)return;
3565    
3566      if(!ofile){      if(!ofile){
3567          cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;          cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;
# Line 2822  void PamLevel2::CreateCloneTrees(TFile * Line 3582  void PamLevel2::CreateCloneTrees(TFile *
3582      // ------------------      // ------------------
3583      // replicate run tree      // replicate run tree
3584      // ------------------      // ------------------
3585      cout << "----------------------------------------------------"<<endl;  //    cout << "----------------------------------------------------"<<endl;
3586      cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;  //    cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
3587      for (Int_t i=0; i<run_tree->GetEntries(); i++){      for (Int_t i=0; i<run_tree->GetEntries(); i++){
3588          run_tree->GetEntry(i);          run_tree->GetEntry(i);
3589          cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;  //      cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;
3590          run_tree_clone->Fill();          run_tree_clone->Fill();
3591      }      }
3592      cout << "----------------------------------------------------"<<endl;      cout << "----------------------------------------------------"<<endl;
3593    
3594        // ------------------------------------
3595        // add branch with dead and live times
3596        // ------------------------------------
3597        run_tree_clone->Branch("DeadLiveTime",totdltime,"dltime[3]/l");
3598        cout << "Run          : branch DeadLiveTime"<<endl;
3599    
3600    
3601      sel_tree_clone = new TTree("SelectionList","List of selected events ");      sel_tree_clone = new TTree("SelectionList","List of selected events ");
3602      sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");  //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
3603        sel_tree_clone->Branch("RunEntry",&irunt,"runentry/L");//NEWNEW
3604      sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");      sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");
3605            
3606    
# Line 2913  void PamLevel2::CreateCloneTrees(TFile * Line 3680  void PamLevel2::CreateCloneTrees(TFile *
3680          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
3681          i++;          i++;
3682      };      };
3683        // GPamela
3684        if(GP) {
3685            pam_tree_clone[i] = new TTree("h20","PAMELA oribital info  ");  
3686            pam_tree_clone[i]->Branch("GPamela","GPamela", GetPointerTo("GPamela"),32000,1);//split
3687            cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
3688            i++;
3689        };
3690      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3691    
3692  }  }
# Line 2957  TTree* PamLevel2::GetCloneTree(TString n Line 3731  TTree* PamLevel2::GetCloneTree(TString n
3731  void PamLevel2::WriteCloneTrees(){  void PamLevel2::WriteCloneTrees(){
3732      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3733      cout << "Write clones of PAMELA trees "<<endl;      cout << "Write clones of PAMELA trees "<<endl;
3734      cout << run_tree_clone->GetName()<<endl;          cout << run_tree_clone->GetName()<<endl;  
3735        if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
3736            run_tree_clone->GetBranch("DeadLiveTime")->Fill();
3737      run_tree_clone->Write();      run_tree_clone->Write();
3738      cout << sel_tree_clone->GetName()<<endl;          cout << sel_tree_clone->GetName()<<endl;    
3739      sel_tree_clone->Write();      sel_tree_clone->Write();
# Line 3001  Int_t PamLevel2::GetEntry(Long64_t iee){ Line 3777  Int_t PamLevel2::GetEntry(Long64_t iee){
3777          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<<endl;          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<<endl;
3778          return 0;          return 0;
3779      }      }
3780    
3781      //      //
3782      // ... 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.      // ... 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.
3783      // 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      // 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
3784      // a problem if you don't check the return code of getentry.      // a problem if you don't check the return code of getentry.
3785      //      //
3786      if(!run_tree ){      if(!RUN || !run_tree ){
3787          if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?          if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?
3788              cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;              cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
3789              return 0;              return 0;
# Line 3091  TTree* PamLevel2::GetYodaTree( ){ Line 3868  TTree* PamLevel2::GetYodaTree( ){
3868          // open the DB connection          // open the DB connection
3869          // (if not already opened)          // (if not already opened)
3870          //===================================          //===================================
3871          if(!dbc || (dbc && !dbc->IsConnected())){          if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
             cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;  
             cout<<"Connecting to DB"<<endl;  
             cout<<"HOST "<<host<<endl;  
             cout<<"USER "<<user<<endl;  
             cout<<"PSW  "<<psw<<endl;  
             dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());  
             if( !dbc )return NULL;  
             if( !dbc->IsConnected() )return NULL;      
 //          cout<<"...done"<<endl;  
             cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;  
         }else{  
 //          cout<<"DB already connected"<<endl;  
         }  
3872          GL_ROOT glroot = GL_ROOT();          GL_ROOT glroot = GL_ROOT();
3873          if( glroot.Query_GL_ROOT(iroot,dbc) ){          if( glroot.Query_GL_ROOT(iroot,dbc) ){
3874              cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;              cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;
# Line 3152  TTree* PamLevel2::GetYodaTree( ){ Line 3916  TTree* PamLevel2::GetYodaTree( ){
3916              cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;              cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
3917          }          }
3918    
3919            dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
3920    
3921    
3922      };      };
3923    
3924      if(!dbc || (dbc && !dbc->IsConnected())){  //     if(!dbc || (dbc && !dbc->IsConnected())){
3925          cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;  //      cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;
3926      }  //     }
3927    
3928      if ( TRK0 ){      if ( TRK0 ){
3929          TrkParams::Load(6);  //      TrkParams::Load(6);
3930          if( !TrkParams::IsLoaded(6) ){  //      if( !TrkParams::IsLoaded(6) ){
3931              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;  //          cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;
3932          };  //      };
3933    //      if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
3934          TrkParams::SetCalib(run_obj,dbc);          TrkParams::SetCalib(run_obj,dbc);
3935          TrkParams::LoadCalib( );          TrkParams::LoadCalib( );
3936          if( !TrkParams::CalibIsLoaded() ){          if( !TrkParams::CalibIsLoaded() ){
3937              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;
3938          };          };
3939    //      if(dbc)dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
3940      }      }
3941    
3942    
3943  //    cout << l0_tree << endl;  //    cout << l0_tree << endl;
       
3944      return l0_tree;      return l0_tree;
3945    
3946  }  }
# Line 3232  Int_t PamLevel2::GetYodaEntry(){ Line 4001  Int_t PamLevel2::GetYodaEntry(){
4001      Int_t answer = 0;      Int_t answer = 0;
4002      Int_t shift =0;      Int_t shift =0;
4003      //    printf(" siamo qui %i %i \n",shift,prevshift);      //    printf(" siamo qui %i %i \n",shift,prevshift);
4004      Int_t maxshift = 10;      //    Int_t maxshift = 50; // EMILIANO
4005      do{      do{
4006          if(shift>0){              if(shift>0){    
4007              cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;              cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
4008              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;              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;
4009              cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;              if(DBG)cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;
4010          }          }
4011          answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);          answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);
4012          shift++;          shift++;
# Line 3261  Int_t PamLevel2::GetYodaEntry(){ Line 4030  Int_t PamLevel2::GetYodaEntry(){
4030  //      printf(" IDRUN %u \n",GetRunInfo()->ID);  //      printf(" IDRUN %u \n",GetRunInfo()->ID);
4031  //  //
4032          if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){          if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){
4033            prevshift = 0;              prevshift = 0;
4034            shift = -1;              shift = -1;
4035          };          };
4036    
4037      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||
# Line 3270  Int_t PamLevel2::GetYodaEntry(){ Line 4039  Int_t PamLevel2::GetYodaEntry(){
4039              && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);              && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);
4040    
4041      if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {      if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {
4042          cout << " Big trouble here, no such event in Level0 data! " <<endl;          cout << " Big trouble here, no such event in Level0 data! (NB maxshift set to "<<maxshift<<" )" <<endl;
4043          return 0;          return 0;
4044      }      }
4045  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
# Line 3285  Int_t PamLevel2::GetYodaEntry(){ Line 4054  Int_t PamLevel2::GetYodaEntry(){
4054   */   */
4055  Bool_t PamLevel2::SetDBConnection(){  Bool_t PamLevel2::SetDBConnection(){
4056    
4057      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;  //    cout << "PamLevel2::SetDBConnection()" << endl;
4058      cout<<"Connecting to DB"<<endl;      if(DBG){
4059      cout<<"HOST "<<host<<endl;          cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
4060      cout<<"USER "<<user<<endl;          cout<<"Connecting to DB"<<endl;
4061      cout<<"PSW  "<<psw<<endl;          cout<<"HOST "<<host<<endl;
4062            cout<<"USER "<<user<<endl;
4063            cout<<"PSW  "<<psw<<endl;
4064        }
4065      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
4066      if( !dbc )return false;      if( !dbc )return false;
4067      if( !dbc->IsConnected() )return false;          if( !dbc->IsConnected() )return false;    
4068      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;      stringstream myquery;  // EMILIANO
4069        myquery.str("");  // EMILIANO
4070        myquery << "SET time_zone='+0:00'";  // EMILIANO
4071        dbc->Query(myquery.str().c_str());  // EMILIANO
4072        if(DBG)cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
4073      return true;      return true;
4074    
4075  }  }
4076    
4077    /**
4078     * \Brief Add a friend to the pamela chain.
4079     * @param cname name of the chain to be added
4080     */
4081    
4082    TChain* PamLevel2::AddFriend(TString cname){
4083    
4084        if(!GetPamTree()){
4085            cout << " TChain* PamLevel2::AddFriend(TString cname) --- a pamela tree must be created first"<<endl;
4086            return NULL;
4087        }
4088    
4089    
4090        TChain *c = new TChain( cname.Data() );
4091    
4092        TIter next( GetPamTree()->GetListOfFiles() );
4093        Int_t nf = 0;
4094        TChainElement* element = 0;    
4095        while ((element = (TChainElement*) next())) {      
4096            c->Add(element->GetTitle());
4097            nf++;
4098        }
4099    
4100        GetPamTree()->AddFriend(cname.Data());
4101    
4102        cout << "external chain created and added to pamela friends :"<<cname<<endl;
4103        cout << "n.files "<<nf<<endl;
4104        
4105    
4106        return c;    
4107    
4108    }
4109    
4110    

Legend:
Removed from v.1.43  
changed lines
  Added in v.1.70

  ViewVC Help
Powered by ViewVC 1.1.23