/[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.42 by pam-fi, Tue Aug 7 15:37:12 2007 UTC revision 1.55 by pam-fi, Wed Nov 14 11:14:28 2007 UTC
# Line 1  Line 1 
1  #include <PamLevel2.h>  #include <PamLevel2.h>
2    
3    
4    
5    /////////////////////////////////////////////////////////////////////////////
6    /////////////////////////////////////////////////////////////////////////////
7    /////////////////////////////////////////////////////////////////////////////
8    /////////////////////////////////////////////////////////////////////////////
9    
10    void GPamela::Clear(){
11        Irun   = 0;
12        Ievnt  = 0;
13        Ipa    = 0;
14        X0     = 0.;
15        Y0     = 0.;
16        Z0     = 0.;
17        Theta  = 0.;
18        Phi    = 0.;
19        P0     = 0.;
20        Nthtof  = 0;
21        Nthcat  = 0;
22        Nthcas  = 0;
23        Nthspe  = 0;
24        Nstrpx  = 0;
25        Nstrpy  = 0;
26        Nthcali = 0;
27        Nthcal  = 0;
28        Nthnd   = 0;
29        Nthcard = 0;
30    }
31    
32    void GPamela::Delete(){
33    
34        Clear();
35    
36        delete []    Ipltof;  
37        delete []    Ipaddle;
38        delete []    Ipartof;
39        delete []    Xintof;  
40        delete []    Yintof;  
41        delete []    Zintof;  
42        delete []    Xouttof;
43        delete []    Youttof;
44        delete []    Zouttof;
45        delete []    Ereltof;
46        delete []    Timetof;
47        delete []    Pathtof;
48        delete []    P0tof;  
49        delete []    Iparcat;
50        delete []    Icat;  
51        delete []    Xincat;  
52        delete []    Yincat;  
53        delete []    Zincat;  
54        delete []    Xoutcat;
55        delete []    Youtcat;
56        delete []    Zoutcat;
57        delete []    Erelcat;
58        delete []    Timecat;
59        delete []    Pathcat;
60        delete []    P0cat;  
61        delete []    Iparcas;
62        delete []    Icas;  
63        delete []    Xincas;  
64        delete []    Yincas;  
65        delete []    Zincas;  
66        delete []    Xoutcas;
67        delete []    Youtcas;
68        delete []    Zoutcas;
69        delete []    Erelcas;
70        delete []    Timecas;
71        delete []    Pathcas;
72        delete []    P0cas;  
73        delete []    Iparspe;
74        delete []    Itrpb;  
75        delete []    Itrsl;  
76        delete []    Itspa;  
77        delete []    Xinspe;  
78        delete []    Yinspe;  
79        delete []    Zinspe;  
80        delete []    Xoutspe;
81        delete []    Youtspe;
82        delete []    Zoutspe;
83        delete []    Xavspe;  
84        delete []    Yavspe;  
85        delete []    Zavspe;  
86        delete []    Erelspe;
87        delete []    Pathspe;
88        delete []    P0spe;  
89        delete []    Nxmult;  
90        delete []    Nymult;  
91        delete []    Npstripx;
92        delete []    Ntstripx;
93        delete []    Istripx;
94        delete []    Qstripx;
95        delete []    Xstripx;
96        delete []    Npstripy;
97        delete []    Ntstripy;
98        delete []    Istripy;
99        delete []    Qstripy;
100        delete []    Ystripy;
101        delete []    Icaplane;
102        delete []    Icastrip;
103        delete []    Icamod;  
104        delete []    Enestrip;
105        delete []    Icapl;  
106        delete []    Icasi;  
107        delete []    Icast;  
108        delete []    Xincal;  
109        delete []    Yincal;  
110        delete []    Zincal;  
111        delete []    Erelcal;
112        delete []    Itubend;
113        delete []    Iparnd;  
114        delete []    Xinnd;  
115        delete []    Yinnd;  
116        delete []    Zinnd;  
117        delete []    Xoutnd;  
118        delete []    Youtnd;  
119        delete []    Zoutnd;  
120        delete []    Erelnd;  
121        delete []    Timend;  
122        delete []    Pathnd;  
123        delete []    P0nd;  
124        delete []    Iparcard;
125        delete []    Icard;  
126        delete []    Xincard;
127        delete []    Yincard;
128        delete []    Zincard;
129        delete []    Xoutcard;
130        delete []    Youtcard;
131        delete []    Zoutcard;
132        delete []    Erelcard;
133        delete []    Timecard;
134        delete []    Pathcard;
135        delete []    P0card;  
136    
137    
138    };
139    
140    
141    
142    void GPamela::SetBranchAddress( TChain* fhBookTree ){
143    
144    //    cout << "fhBookTree "<<fhBookTree << endl;
145        // prepare tree
146        fhBookTree->SetBranchAddress("Irun",&Irun);
147        fhBookTree->SetBranchAddress("Ievnt",&Ievnt);
148        fhBookTree->SetBranchAddress("Ipa",&Ipa);
149        fhBookTree->SetBranchAddress("X0",&X0);
150        fhBookTree->SetBranchAddress("Y0",&Y0);
151        fhBookTree->SetBranchAddress("Z0",&Z0);
152        fhBookTree->SetBranchAddress("Theta",&Theta);
153        fhBookTree->SetBranchAddress("Phi",&Phi);
154        fhBookTree->SetBranchAddress("P0",&P0);
155        fhBookTree->SetBranchAddress("Nthtof",&Nthtof);
156        fhBookTree->SetBranchAddress("Ipltof",Ipltof);
157        fhBookTree->SetBranchAddress("Ipaddle",Ipaddle);
158        fhBookTree->SetBranchAddress("Ipartof",Ipartof);
159        fhBookTree->SetBranchAddress("Xintof",Xintof);
160        fhBookTree->SetBranchAddress("Yintof",Yintof);
161        fhBookTree->SetBranchAddress("Zintof",Zintof);
162        fhBookTree->SetBranchAddress("Xouttof",Xouttof);
163        fhBookTree->SetBranchAddress("Youttof",Youttof);
164        fhBookTree->SetBranchAddress("Zouttof",Zouttof);
165        fhBookTree->SetBranchAddress("Ereltof",Ereltof);
166        fhBookTree->SetBranchAddress("Timetof",Timetof);
167        fhBookTree->SetBranchAddress("Pathtof",Pathtof);
168        fhBookTree->SetBranchAddress("P0tof",P0tof);
169        fhBookTree->SetBranchAddress("Nthcat",&Nthcat);
170        fhBookTree->SetBranchAddress("Iparcat",Iparcat);
171        fhBookTree->SetBranchAddress("Icat",Icat);
172        fhBookTree->SetBranchAddress("Xincat",Xincat);
173        fhBookTree->SetBranchAddress("Yincat",Yincat);
174        fhBookTree->SetBranchAddress("Zincat",Zincat);
175        fhBookTree->SetBranchAddress("Xoutcat",Xoutcat);
176        fhBookTree->SetBranchAddress("Youtcat",Youtcat);
177        fhBookTree->SetBranchAddress("Zoutcat",Zoutcat);
178        fhBookTree->SetBranchAddress("Erelcat",Erelcat);
179        fhBookTree->SetBranchAddress("Timecat",Timecat);
180        fhBookTree->SetBranchAddress("Pathcat",Pathcat);
181        fhBookTree->SetBranchAddress("P0cat",P0cat);
182        fhBookTree->SetBranchAddress("Nthcas",&Nthcas);
183        fhBookTree->SetBranchAddress("Iparcas",Iparcas);
184        fhBookTree->SetBranchAddress("Icas",Icas);
185        fhBookTree->SetBranchAddress("Xincas",Xincas);
186        fhBookTree->SetBranchAddress("Yincas",Yincas);
187        fhBookTree->SetBranchAddress("Zincas",Zincas);
188        fhBookTree->SetBranchAddress("Xoutcas",Xoutcas);
189        fhBookTree->SetBranchAddress("Youtcas",Youtcas);
190        fhBookTree->SetBranchAddress("Zoutcas",Zoutcas);
191        fhBookTree->SetBranchAddress("Erelcas",Erelcas);
192        fhBookTree->SetBranchAddress("Timecas",Timecas);
193        fhBookTree->SetBranchAddress("Pathcas",Pathcas);
194        fhBookTree->SetBranchAddress("P0cas",P0cas);
195        fhBookTree->SetBranchAddress("Nthspe",&Nthspe);
196        fhBookTree->SetBranchAddress("Iparspe",Iparspe);
197        fhBookTree->SetBranchAddress("Itrpb",Itrpb);
198        fhBookTree->SetBranchAddress("Itrsl",Itrsl);
199        fhBookTree->SetBranchAddress("Itspa",Itspa);
200        fhBookTree->SetBranchAddress("Xinspe",Xinspe);
201        fhBookTree->SetBranchAddress("Yinspe",Yinspe);
202        fhBookTree->SetBranchAddress("Zinspe",Zinspe);
203        fhBookTree->SetBranchAddress("Xoutspe",Xoutspe);
204        fhBookTree->SetBranchAddress("Youtspe",Youtspe);
205        fhBookTree->SetBranchAddress("Zoutspe",Zoutspe);
206        fhBookTree->SetBranchAddress("Xavspe",Xavspe);
207        fhBookTree->SetBranchAddress("Yavspe",Yavspe);
208        fhBookTree->SetBranchAddress("Zavspe",Zavspe);
209        fhBookTree->SetBranchAddress("Erelspe",Erelspe);
210        fhBookTree->SetBranchAddress("Pathspe",Pathspe);
211        fhBookTree->SetBranchAddress("P0spe",P0spe);
212        fhBookTree->SetBranchAddress("Nxmult",Nxmult);
213        fhBookTree->SetBranchAddress("Nymult",Nymult);
214        fhBookTree->SetBranchAddress("Nstrpx",&Nstrpx);
215        fhBookTree->SetBranchAddress("Npstripx",Npstripx);
216        fhBookTree->SetBranchAddress("Ntstripx",Ntstripx);
217        fhBookTree->SetBranchAddress("Istripx",Istripx);
218        fhBookTree->SetBranchAddress("Qstripx",Qstripx);
219        fhBookTree->SetBranchAddress("Xstripx",Xstripx);
220        fhBookTree->SetBranchAddress("Nstrpy",&Nstrpy);
221        fhBookTree->SetBranchAddress("Npstripy",Npstripy);
222        fhBookTree->SetBranchAddress("Ntstripy",Ntstripy);
223        fhBookTree->SetBranchAddress("Istripy",Istripy);
224        fhBookTree->SetBranchAddress("Qstripy",Qstripy);
225        fhBookTree->SetBranchAddress("Ystripy",Ystripy);
226        fhBookTree->SetBranchAddress("Nthcali",&Nthcali);
227        fhBookTree->SetBranchAddress("Icaplane",Icaplane);
228        fhBookTree->SetBranchAddress("Icastrip",Icastrip);
229        fhBookTree->SetBranchAddress("Icamod",Icamod);
230        fhBookTree->SetBranchAddress("Enestrip",Enestrip);
231        fhBookTree->SetBranchAddress("Nthcal",&Nthcal);
232        fhBookTree->SetBranchAddress("Icapl",Icapl);
233        fhBookTree->SetBranchAddress("Icasi",Icasi);
234        fhBookTree->SetBranchAddress("Icast",Icast);
235        fhBookTree->SetBranchAddress("Xincal",Xincal);
236        fhBookTree->SetBranchAddress("Yincal",Yincal);
237        fhBookTree->SetBranchAddress("Zincal",Zincal);
238        fhBookTree->SetBranchAddress("Erelcal",Erelcal);
239        fhBookTree->SetBranchAddress("Nthnd",&Nthnd);
240        fhBookTree->SetBranchAddress("Itubend",Itubend);
241        fhBookTree->SetBranchAddress("Iparnd",Iparnd);
242        fhBookTree->SetBranchAddress("Xinnd",Xinnd);
243        fhBookTree->SetBranchAddress("Yinnd",Yinnd);
244        fhBookTree->SetBranchAddress("Zinnd",Zinnd);
245        fhBookTree->SetBranchAddress("Xoutnd",Xoutnd);
246        fhBookTree->SetBranchAddress("Youtnd",Youtnd);
247        fhBookTree->SetBranchAddress("Zoutnd",Zoutnd);
248        fhBookTree->SetBranchAddress("Erelnd",Erelnd);
249        fhBookTree->SetBranchAddress("Timend",Timend);
250        fhBookTree->SetBranchAddress("Pathnd",Pathnd);
251        fhBookTree->SetBranchAddress("P0nd",P0nd);
252        fhBookTree->SetBranchAddress("Nthcard",&Nthcard);
253        fhBookTree->SetBranchAddress("Iparcard",Iparcard);
254        fhBookTree->SetBranchAddress("Icard",Icard);
255        fhBookTree->SetBranchAddress("Xincard",Xincard);
256        fhBookTree->SetBranchAddress("Yincard",Yincard);
257        fhBookTree->SetBranchAddress("Zincard",Zincard);
258        fhBookTree->SetBranchAddress("Xoutcard",Xoutcard);
259        fhBookTree->SetBranchAddress("Youtcard",Youtcard);
260        fhBookTree->SetBranchAddress("Zoutcard",Zoutcard);
261        fhBookTree->SetBranchAddress("Erelcard",Erelcard);
262        fhBookTree->SetBranchAddress("Timecard",Timecard);
263        fhBookTree->SetBranchAddress("Pathcard",Pathcard);
264        fhBookTree->SetBranchAddress("P0card",P0card);
265    
266    //    fhBookTree->SetBranchStatus("*",0);
267    
268    }
269    
270    ClassImp(GPamela);
271    
272    /////////////////////////////////////////////////////////////////////////////
273    /////////////////////////////////////////////////////////////////////////////
274    /////////////////////////////////////////////////////////////////////////////
275    /////////////////////////////////////////////////////////////////////////////
276  //--------------------------------------  //--------------------------------------
277  //  //
278  //  //
# Line 11  PamTrack::PamTrack(){ Line 285  PamTrack::PamTrack(){
285      calo_track = 0;      calo_track = 0;
286      tof_track  = 0;      tof_track  = 0;
287      candeleteobj = 0;      candeleteobj = 0;
288        pscore = 0;
289        iscore = 0;
290  };  };
291  //--------------------------------------  //--------------------------------------
292  //  //
# Line 60  void PamTrack::Clear(){ Line 336  void PamTrack::Clear(){
336          calo_track = 0;          calo_track = 0;
337          tof_track  = 0;          tof_track  = 0;
338      }      }
339        pscore = 0;
340        iscore = 0;
341    
342  }  }
343  void PamTrack::Delete(){  void PamTrack::Delete(){
344  //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;  //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;
# Line 88  void PamTrack::Delete(){ Line 367  void PamTrack::Delete(){
367   * Default Constructor   * Default Constructor
368   */   */
369  PamLevel2::PamLevel2(){  PamLevel2::PamLevel2(){
370    Initialize();      Initialize();
371  };  };
372    
373  /**  /**
374   * Constructor with given dir, list and detectors   * Constructor
375     * @param ddir Name of directory where level2 files are stored.
376     * @param list Name of an ascii file containing the list of file names
377     * @param detlist Options to chose what to load.
378     * Possible options are:
379     *       +AUTO --> load all trees/branches in the input files
380     *       +(-)ALL --> inlcude(exclude) all trees/branches
381     *       +(-)TRK1+(-)TRK2+(-)CAL1+(-)CAL2+(-)TOF+(-)TRG+(-)ND+(-)S4+(-)ORB+(-)AC --> inlcude(exclude) trees and branches
382     *       +(-)TRK0 --> include(exclude) tracker level0 tree
383     *       +(-)GP --> include exclude GPAMELA output tree
384     * If no options are specified, the default is assumed. Default is:
385     * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
386   */   */
387  PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){  PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){
388    Initialize();      Initialize();
389    GetPamTree(GetListOfLevel2Files(ddir,list),detlist);      GetPamTree(GetListOfLevel2Files(ddir,list),detlist);
390    GetRunTree(GetListOfLevel2Files(ddir,list));      GetRunTree(GetListOfLevel2Files(ddir,list));
391  };  };
392    
393  /**  /**
394   * Constructor with given dir and list   * Constructor
395     * @param ddir Name of directory where level2 files are stored.
396     * @param list Name of an ascii file containing the list of file names
397     * Default trees/branches are loaded. Default is:
398     * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
399   */   */
400  PamLevel2::PamLevel2(TString ddir,TString list){  PamLevel2::PamLevel2(TString ddir,TString list){
401    Initialize();      Initialize();
402    GetPamTree(GetListOfLevel2Files(ddir,list),"");      GetPamTree(GetListOfLevel2Files(ddir,list),"");
403    GetRunTree(GetListOfLevel2Files(ddir,list));      GetRunTree(GetListOfLevel2Files(ddir,list));
404  };  };
405    
406    
407  void PamLevel2::Initialize(){  void PamLevel2::Initialize(){
408                    
 //     trk2_obj  = TrkLevel2::GetTrkLevel2();  
 //     trk1_obj  = TrkLevel1::GetTrkLevel1();  
 //     trkh_obj  = TrkHough::GetTrkHough();  
 //     calo1_obj = CaloLevel1::GetCaloLevel1();  
 //     calo2_obj = CaloLevel2::GetCaloLevel2();  
 //     tof_obj   = ToFLevel2::GetToFLevel2();  
 //     trig_obj  = TrigLevel2::GetTrigLevel2();  
 //     s4_obj    = S4Level2::GetS4Level2();  
 //     nd_obj    = NDLevel2::GetNDLevel2();  
 //     ac_obj    = AcLevel2::GetAcLevel2();  
 //     orb_obj   = OrbitalInfo::GetOrbitalInfo();  
       
409      h0_obj    = 0;      h0_obj    = 0;
410      trk0_obj  = 0;      trk0_obj  = 0;
411      calo0_obj  = 0;      calo0_obj  = 0;
# Line 139  void PamLevel2::Initialize(){ Line 421  void PamLevel2::Initialize(){
421      nd_obj    = 0;      nd_obj    = 0;
422      ac_obj    = 0;      ac_obj    = 0;
423      orb_obj   = 0;      orb_obj   = 0;
424        gp_obj    = 0;
425    
426      run_obj   = 0;//new GL_RUN();      run_obj   = 0;//new GL_RUN();
427      soft_obj   = 0;// Emiliano      soft_obj   = 0;// Emiliano
# Line 152  void PamLevel2::Initialize(){ Line 435  void PamLevel2::Initialize(){
435      dbc     = 0;      dbc     = 0;
436    
437      prevshift = 0;      prevshift = 0;
438        maxshift = 10; //EMILIANO
439            
440      run_tree = NULL;      run_tree = NULL;
441      run_tree_clone = NULL;      run_tree_clone = NULL;
# Line 162  void PamLevel2::Initialize(){ Line 446  void PamLevel2::Initialize(){
446      pam_tree = NULL;      pam_tree = NULL;
447      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;
448    
449        totdltime[0] = 0LL;
450        totdltime[1] = 0LL;
451    
452      host = "mysql://localhost/pamelaprod";      host = "mysql://localhost/pamelaprod";
453      user = "anonymous";      user = "anonymous";
454      psw = "";      psw = "";
# Line 184  void PamLevel2::Initialize(){ Line 471  void PamLevel2::Initialize(){
471      CAL2 = true;      CAL2 = true;
472      TRK2 = true;      TRK2 = true;
473      TRK1 = false;      TRK1 = false;
474      TRKh = false;      TRK0 = false;
475      TRKh = false;      TRKh = false;
476      TRG  = true;      TRG  = true;
477      TOF  = true;      TOF  = true;
# Line 192  void PamLevel2::Initialize(){ Line 479  void PamLevel2::Initialize(){
479      S4   = true;      S4   = true;
480      ND   = true;      ND   = true;
481      AC   = true;      AC   = true;
482      ORB  = true;      ORB  = true;    
483            GP   = false;
484    
485      RUN  = true;      RUN  = true;
486    
487      SELLI = -1;      SELLI = -1;
488    
489        ISGP = false;
490    
491      tsorted=0;      tsorted=0;
492      timage=0;      timage=0;
493            
# Line 229  void PamLevel2::Delete(){ Line 519  void PamLevel2::Delete(){
519      if(nd_obj)   delete nd_obj;      if(nd_obj)   delete nd_obj;
520      if(ac_obj)   delete ac_obj;      if(ac_obj)   delete ac_obj;
521      if(orb_obj)  delete orb_obj;      if(orb_obj)  delete orb_obj;
522        if(gp_obj)   delete gp_obj;
523            
524      if(tsorted){      if(tsorted){
525          tsorted->Delete();          tsorted->Delete();
# Line 247  void PamLevel2::Delete(){ Line 538  void PamLevel2::Delete(){
538      if(l0_file)l0_file->Close();      if(l0_file)l0_file->Close();
539      //    if(pam_tree)pam_tree->Delete();;      //    if(pam_tree)pam_tree->Delete();;
540    
541    if ( pam_tree ){      if ( pam_tree ){
542      //          //
543      // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault...          // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault...
544      //          //
545      TList *temp = pam_tree->GetListOfFriends();          TList *temp = pam_tree->GetListOfFriends();
546      TList *contents  = new TList; // create chain friend list          TList *contents  = new TList; // create chain friend list
547      contents->SetOwner();          contents->SetOwner();
548      TIter next(temp);          TIter next(temp);
549      TChain *questo = 0;          TChain *questo = 0;
550      while ( (questo = (TChain*) next()) ){          while ( (questo = (TChain*) next()) ){
551        TString name =  questo->GetName();              TString name =  questo->GetName();
552        contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list              contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
553      };          };
554      //          //
555      // deleting the main chain          // deleting the main chain
556      //          //
557      pam_tree->Delete();          pam_tree->Delete();
558      //          //
559      // deleting the friends...          // deleting the friends...
560      //          //
561      TIter next2(contents);          TIter next2(contents);
562      TChain *questa = 0;          TChain *questa = 0;
563      while ( questa = (TChain*)next2() ){          while ( questa = (TChain*)next2() ){
564        TString name =  questa->GetName();              TString name =  questa->GetName();
565        questa->Delete();                    questa->Delete();      
566        questa=NULL;              questa=NULL;
567            };
568            //
569      };      };
570      //      pam_tree = NULL;
   };  
   pam_tree = NULL;  
571    
572      if(run_tree)run_tree->Delete();;      if(run_tree)run_tree->Delete();;
573      if(sel_tree)sel_tree->Delete();;      if(sel_tree)sel_tree->Delete();;
# Line 316  void PamLevel2::Clear(){ Line 607  void PamLevel2::Clear(){
607      if(nd_obj)   nd_obj->Clear();      if(nd_obj)   nd_obj->Clear();
608      if(ac_obj)   ac_obj->Clear();      if(ac_obj)   ac_obj->Clear();
609      if(orb_obj)  orb_obj->Clear();      if(orb_obj)  orb_obj->Clear();
610        if(gp_obj)   gp_obj->Clear();
611            
612  //    if(sorted_tracks)sorted_tracks->Clear();  //    if(sorted_tracks)sorted_tracks->Clear();
613  //    sorted_tracks.Clear();  //    sorted_tracks.Clear();
# Line 329  void PamLevel2::Clear(){ Line 621  void PamLevel2::Clear(){
621  };  };
622    
623  void PamLevel2::Reset(){  void PamLevel2::Reset(){
   //  
   // First of all clear everything  
   //  
   Clear();  
   //  
   // close and reset chains and pointers  
   //      
   if ( pam_tree ){  
624      //      //
625      // 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
626        //
627        Clear();
628        //
629        // close and reset chains and pointers
630        //    
631        if ( pam_tree ){
632            //
633            // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault...
634            //
635            TList *temp = pam_tree->GetListOfFriends();
636            TList *contents  = new TList; // create chain friend list
637            contents->SetOwner();
638            TIter next(temp);
639            TChain *questo = 0;
640            while ( (questo = (TChain*) next()) ){
641                TString name =  questo->GetName();
642                contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
643            };
644            //
645            // deleting the main chain
646            //
647            pam_tree->Delete();
648            //
649            // deleting the friends...
650            //
651            TIter next2(contents);
652            TChain *questa = 0;
653            while ( questa = (TChain*)next2() ){
654                TString name =  questa->GetName();
655                questa->Delete();      
656                questa=NULL;
657            };
658            //
659        };
660        pam_tree = NULL;
661        //
662        if(run_tree)run_tree->Delete();;
663        run_tree = NULL;
664        if(sel_tree)sel_tree->Delete();;
665        sel_tree = NULL;
666        //
667        // Close file
668        //
669        if(l0_file)l0_file->Close("R");
670        l0_file = NULL;
671        //
672        h0_obj    = 0;
673        trk0_obj  = 0;
674        calo0_obj  = 0;
675        //
676        trk2_obj  = 0;
677        trk1_obj  = 0;
678        trkh_obj  = 0;
679        calo1_obj = 0;
680        calo2_obj = 0;
681        tof_obj   = 0;
682        trig_obj  = 0;
683        s4_obj    = 0;
684        nd_obj    = 0;
685        ac_obj    = 0;
686        orb_obj   = 0;
687        gp_obj    = 0;
688        //
689        // Reset run pointers
690        //
691        run_obj   = 0;//new GL_RUN();
692        soft_obj   = 0;// Emiliano
693        irun = -1;
694        runfirstentry = 0ULL;
695        runlastentry = 0ULL;    
696        //
697        totdltime[0] = 0LL;
698        totdltime[1] = 0LL;
699      //      //
     TList *temp = pam_tree->GetListOfFriends();  
     TList *contents  = new TList; // create chain friend list  
     contents->SetOwner();  
     TIter next(temp);  
     TChain *questo = 0;  
     while ( (questo = (TChain*) next()) ){  
       TString name =  questo->GetName();  
       contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list  
     };  
     //  
     // deleting the main chain  
     //  
     pam_tree->Delete();  
     //  
     // deleting the friends...  
     //  
     TIter next2(contents);  
     TChain *questa = 0;  
     while ( questa = (TChain*)next2() ){  
       TString name =  questa->GetName();  
       questa->Delete();        
       questa=NULL;  
     };  
     //  
   };  
   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;      
   //  
700  };  };
701    
702  Bool_t PamLevel2::IsGood(){  Bool_t PamLevel2::IsGood(){
703    Bool_t goodev=true;      Bool_t goodev=true;
704    //  if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;      //  if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;
705    if(calo2_obj && calo2_obj->good != 1) goodev = false;      if(calo2_obj && calo2_obj->good != 1) goodev = false;
706    if(tof_obj && tof_obj->unpackError != 0) goodev = false;        if(tof_obj && tof_obj->unpackError != 0) goodev = false;  
707    if(trig_obj && trig_obj->unpackError != 0) goodev = false;      if(trig_obj && trig_obj->unpackError != 0) goodev = false;
708    if(s4_obj && s4_obj->unpackError != 0) goodev = false;        if(s4_obj && s4_obj->unpackError != 0) goodev = false;  
709    if(nd_obj && nd_obj->unpackError != 0) goodev = false;        if(nd_obj && nd_obj->unpackError != 0) goodev = false;  
710    if(ac_obj && ac_obj->unpackError != 255) goodev = false;        if(ac_obj && ac_obj->unpackError != 255) goodev = false;  
711      //  if(orb_obj)        //  if(orb_obj)  
712    return goodev;      return goodev;
713  };  };
714    
715  //--------------------------------------  //--------------------------------------
# Line 480  void *PamLevel2::GetPointerTo(const char Line 776  void *PamLevel2::GetPointerTo(const char
776          if(!orb_obj)   orb_obj   = new OrbitalInfo();          if(!orb_obj)   orb_obj   = new OrbitalInfo();
777          return &orb_obj;          return &orb_obj;
778      };      };
779        if(!objname.CompareTo("GPamela")){
780            if(!gp_obj)   gp_obj   = new GPamela();
781            return &gp_obj;
782        };
783            
784      if(!objname.CompareTo("RunInfo"))return &run_obj;      if(!objname.CompareTo("RunInfo"))return &run_obj;
785    
# Line 495  void *PamLevel2::GetPointerTo(const char Line 795  void *PamLevel2::GetPointerTo(const char
795   * Retrieves the calorimeter track matching the seqno-th tracker stored track.   * Retrieves the calorimeter track matching the seqno-th tracker stored track.
796   * (If seqno = -1 retrieves the self-trigger calorimeter track)   * (If seqno = -1 retrieves the self-trigger calorimeter track)
797   */   */
798   CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){  CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
799            
800       if( !calo2_obj )return 0;      if( !calo2_obj )return 0;
801    
802       if( calo2_obj->CaloLevel2::ntrk()==0 ){      if( calo2_obj->CaloLevel2::ntrk()==0 ){
803           cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;          cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;
804           return NULL;          return NULL;
805       };      };
806            
807       CaloTrkVar *c = 0;      CaloTrkVar *c = 0;
808       Int_t it_calo=0;      Int_t it_calo=0;
809            
810       do{      do{
811           c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);          c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
812           it_calo++;          it_calo++;
813       } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());          } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());    
814            
815       if(!c || seqno != c->trkseqno){      if(!c || seqno != c->trkseqno){
816           c = 0;          c = 0;
817           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;
818       };      };
819       return c;      return c;
820            
821   };  };
822  //--------------------------------------  //--------------------------------------
823   //  //
824   //  //
825  //--------------------------------------  //--------------------------------------
826  /**  /**
827    * Retrieves the ToF track matching the seqno-th tracker stored track.   * Retrieves the ToF track matching the seqno-th tracker stored track.
828    * (If seqno = -1 retrieves the tracker-independent tof track)   * (If seqno = -1 retrieves the tracker-independent tof track)
829   */   */
830   ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
831                    
832       if( !tof_obj )return 0;      if( !tof_obj )return 0;
833    
834       if( tof_obj->ToFLevel2::ntrk()==0 ){      if( tof_obj->ToFLevel2::ntrk()==0 ){
835           cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;          cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;
836           return NULL;          return NULL;
837       };      };
838            
839       ToFTrkVar *c = 0;      ToFTrkVar *c = 0;
840       Int_t it_tof=0;      Int_t it_tof=0;
841            
842       do{      do{
843           c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);          c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);
844           it_tof++;          it_tof++;
845       } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());              } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());
846            
847       if(!c || seqno != c->trkseqno){      if(!c || seqno != c->trkseqno){
848           c = 0;          c = 0;
849           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;
850       };      };
851       return c;      return c;
852            
853   };  };
854    
855  //--------------------------------------  //--------------------------------------
856   //  //
857   //  //
858  //--------------------------------------  //--------------------------------------
859  /**  /**
860   * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.   * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.
861   */   */
862   PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){  PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
863            
864       cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;      cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;
865       cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;      cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
866    
867       CaloTrkVar *c = 0;      CaloTrkVar *c = 0;
868       ToFTrkVar  *o = 0;      ToFTrkVar  *o = 0;
869            
870       if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());      if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());
871       if(TOF) o = GetToFStoredTrack(t->GetSeqNo());      if(TOF) o = GetToFStoredTrack(t->GetSeqNo());
872            
873  //    if(t && c && o)track = new PamTrack(t,c,o);  //    if(t && c && o)track = new PamTrack(t,c,o);
874       PamTrack *track = new PamTrack(t,c,o);      PamTrack *track = new PamTrack(t,c,o);
875            
876       return track;      return track;
877    
878   };  };
879  //--------------------------------------  //--------------------------------------
880  //  //
881  //  //
# Line 611  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 911  PamTrack* PamLevel2::GetStoredTrack(Int_
911  //  //
912    
913  /**  /**
914   * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is  PamLevel2::sorted_tracks. Left here as backward compatibility method.   * Sort physical (tracker) tracks. Left here as backward compatibility method.
915   **/   **/
916  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(TString how){
917    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());
918    howtosort = how;        howtosort = how;  
919    SortTracks();      SortTracks();
920  };  };
921    
922  //  //
923  //--------------------------------------  //--------------------------------------
924  /**  /**
925   * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is  PamLevel2::sorted_tracks.   * Sort physical (tracker) tracks.
926   * @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...).
927   * Sorting cryteria:   * Sorting cryteria:
928   * TRK: lower chi**2   * TRK: lower chi**2
929   * CAL: lower Y spatial residual on the first calorimeter plane   * CAL: lower Y spatial residual on the first calorimeter plane
930   * 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).
931     * S1: (ask Emiliano)
932     * S2: (ask Emiliano)
933     * S3: (ask Emiliano)
934     * GP: more GP hits
935   * The default sorting cryterium is "TOF+CAL".   * The default sorting cryterium is "TOF+CAL".
936   *   *
937   * 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).
938   */   */
939  void PamLevel2::SortTracks(){  void PamLevel2::SortTracks(){
940    TString how = howtosort;      TString how = howtosort;
941    
942    //    cout <<" PamLevel2::SortTracks(TString how) "<<endl;      //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;
943    if( !trk2_obj ){      if( !trk2_obj ){
944      cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";          cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";
945      return;          return;
946    };      };
947    //    cout << "call SortTracs() "<<endl;      //Save current Object count
948    //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;  
949    
950        // create TCloneArrays to store tracks and its images
951        if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
952        tsorted->Delete();
953        TClonesArray &ttsorted = *tsorted;
954    
955        if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
956        timage->Delete();
957        TClonesArray &ttimage = *timage;
958    
959    
   //--------------------------------------------------  
   // 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;  
   };  
960    
961    //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;      //--------------------------------------------------
962        // retrieve sorting method
963        //--------------------------------------------------
964        Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
965        Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
966        Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
967        Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
968        Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
969        Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
970        Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
971        
972        if ( use_TOF ){
973            use_S1 = true;
974            use_S2 = true;
975            use_S3 = true;
976        };
977        if( !CAL2 &&  use_CAL) use_CAL = false;
978        if( !TOF ){
979            use_TOF = false;
980            use_S1  = false;
981            use_S2  = false;
982            use_S3  = false;
983        }
984        if( !GP ){
985            use_GP  = false;
986        }
987    
988    //--------------------------------------------------      if( !TRK2 ){
989    // loop over "physical" tracks sorted by the tracker          cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
990    //--------------------------------------------------          return;
991    for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){      };
992            
993      TrkTrack   *ts = 0;      //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
994      CaloTrkVar *cs = 0;    
995      ToFTrkVar  *os = 0;  
996                //--------------------------------------------------
997      // get tracker tracks      // loop over "physical" tracks sorted by the tracker
998      TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker      //--------------------------------------------------
999      CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());      for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
1000      ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());          
1001            TrkTrack   *ts = 0;
1002      TrkTrack   *ti = 0; //tracker (image)          CaloTrkVar *cs = 0;
1003      CaloTrkVar *ci = 0;          ToFTrkVar  *os = 0;
1004      ToFTrkVar  *oi = 0;          
1005      //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;          // get tracker tracks
1006      // if track has an image, check image selection          TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
1007      if(tp->HasImage()){          CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
1008            ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
1009    
1010            TrkTrack   *ti = 0; //tracker (image)
1011            CaloTrkVar *ci = 0;
1012            ToFTrkVar  *oi = 0;
1013            //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
1014            // if track has an image, check image selection
1015    
1016            Int_t tp_score = 0;  //main track sorted by the tracker
1017            Int_t ti_score = 0;  //image track
1018            Int_t totp_score = 0;  //main track sorted by the tracker
1019            Int_t toti_score = 0;  //image track
1020    
1021            if(tp->HasImage()){
1022                            
1023        ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)              ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)
1024        ci = GetCaloStoredTrack(ti->GetSeqNo());              ci = GetCaloStoredTrack(ti->GetSeqNo());
1025        oi = GetToFStoredTrack(ti->GetSeqNo());              oi = GetToFStoredTrack(ti->GetSeqNo());
1026                            
1027        //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;              //      cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
1028    
1029        //assign starting scores              //assign starting scores
1030        Int_t tp_score = 0;  //main track sorted by the tracker              tp_score = 0;  //main track sorted by the tracker
1031        Int_t ti_score = 0;  //image track              ti_score = 0;  //image track
1032                            
1033        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1034        // calorimeter check              // *****************************************************************************************
1035        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1036        // check the Y spatial residual on the first calorimeter plane              // calorimeter check
1037        // (cut on calorimeter variables from Emiliano)              // -----------------------------------------------------------------------------------------
1038        if( use_CAL && !calo2_obj ){              if( use_CAL && !calo2_obj ){
1039          cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";                  cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";
1040          return;                  return;
       };  
       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){  
   
                   
 //      Float_t resy_p = cp->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_p < 0)resy_p= - resy_p;  
 //      Float_t resy_i = ci->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_i < 0)resy_i= - resy_i;  
                   
 //      if(resy_p <= resy_i) tp_score++;  
 //      else                 ti_score++;  
           
   
           if( cp->npresh > ci->npresh) tp_score++;  
           if( cp->npresh < ci->npresh) ti_score++;  
           else ;//niente  
   
         //      cout << "CALO "<<tp_score<<ti_score<<endl;  
   
       };  
       // -----------------------------------------------------------------------------------------  
       // TOF check  
       // -----------------------------------------------------------------------------------------  
       // check the number of hit pmts along the track  
       // on S12 S21 and S32, where paddles are parallel to Y axis  
       if( use_TOF && !tof_obj ){  
         cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";  
         return;  
       };  
       if( use_TOF && op && oi ){  
                   
         //  
         Float_t sen = 0.;  
         for (Int_t ih=0; ih < op->npmtadc; ih++){  
           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);  
1041              };              };
1042            };              if( use_CAL && !cp &&  ci ){
1043            //                  ti_score++;
1044            tp->DoTrack2(tr);                  toti_score++;
           //  
           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);  
               };  
1045              };              };
1046            };              if( use_CAL &&  cp && !ci ){
1047            if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){                  tp_score++;
1048              for (Int_t ih=0; ih < op->npmtadc; ih++){                  totp_score++;
               Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  
               if(pl == 3){  
                 nphit_p++;  
                 enhit_p += (op->dedx).At(ih);  
               };  
1049              };              };
1050            };              if(
1051            if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){                  use_CAL            &&
1052              for (Int_t ih=0; ih < op->npmtadc; ih++){                  cp && ci &&
1053                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );                  true){
1054                if(pl == 4){  
1055                  nphit_p++;                  
1056                  enhit_p += (op->dedx).At(ih);                  if(
1057                };                      cp->npresh > ci->npresh &&
1058              };                      true){
1059            };                      tp_score++;
1060                        totp_score++;
1061                    };
1062                    if(
1063                        cp->npresh < ci->npresh &&
1064                        true){
1065                        ti_score++;
1066                        toti_score++;
1067                    };
1068    
1069                    //      cout << "CALO "<<tp_score<<ti_score<<endl;
1070    
           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);  
1071              };              };
1072            };              // -----------------------------------------------------------------------------------------
1073            //              // *****************************************************************************************
1074            ti->DoTrack2(tr);              // -----------------------------------------------------------------------------------------
1075            //              // TOF check
1076            if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){              // -----------------------------------------------------------------------------------------
1077              for (Int_t ih=0; ih < oi->npmtadc; ih++){              // check the number of hit pmts along the track
1078                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );              // on S12 S21 and S32, where paddles are parallel to Y axis
1079                if(pl == 0){              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !tof_obj ){
1080                  nphit_i++;                  cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";
1081                  enhit_i += (op->dedx).At(ih);                  return;
               };  
1082              };              };
1083            };              //
1084            if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !op && oi ){
1085              for (Int_t ih=0; ih < oi->npmtadc; ih++){                  ti_score++;
1086                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );                  toti_score++;
               if(pl == 3){  
                 nphit_i++;  
                 enhit_i += (op->dedx).At(ih);  
               };  
1087              };              };
1088            };              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && !oi ){
1089            if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){                  tp_score++;
1090              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);  
               };  
1091              };              };
1092            };                          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && oi ){
1093                    //
1094                    Float_t sen = 0.;
1095                    for (Int_t ih=0; ih < op->npmtadc; ih++){
1096                        Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1097                        if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih);
1098                    };
1099                    for (Int_t ih=0; ih < oi->npmtadc; ih++){
1100                        Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1101                        if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);
1102                    };
1103                    //
1104                    if (  sen >= sortthr && false){ // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
1105                        //printf(" IS A NUCLEUS! en = %f \n",sen);
1106                        //
1107                        // is a nucleus use a different algorithm
1108                        //
1109                        Int_t nz = 6; Float_t zin[6];                                          // << define TOF z-coordinates
1110                        for(Int_t ip=0; ip<nz; ip++)
1111                            zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip));     // << read ToF plane z-coordinates
1112                        Trajectory *tr = new Trajectory(nz,zin);
1113                        //
1114                        Int_t nphit_p =0;
1115                        Int_t nphit_i =0;
1116                        Float_t enhit_p = 0.;
1117                        Float_t enhit_i = 0.;
1118                        //
1119                        for (Int_t ih=0; ih < op->npmtadc; ih++){
1120                            Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1121                            if(pl == 1 || pl == 2 || pl == 5){
1122                                nphit_p++;
1123                                enhit_p += (op->dedx).At(ih);
1124                            };
1125                        };
1126                        //
1127                        tp->DoTrack2(tr);
1128                        //
1129                        if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1130                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1131                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1132                                if(pl == 0){
1133                                    nphit_p++;
1134                                    enhit_p += (op->dedx).At(ih);
1135                                };
1136                            };
1137                        };
1138                        if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1139                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1140                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1141                                if(pl == 3){
1142                                    nphit_p++;
1143                                    enhit_p += (op->dedx).At(ih);
1144                                };
1145                            };
1146                        };
1147                        if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1148                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1149                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1150                                if(pl == 4){
1151                                    nphit_p++;
1152                                    enhit_p += (op->dedx).At(ih);
1153                                };
1154                            };
1155                        };
1156    
1157                        for (Int_t ih=0; ih < oi->npmtadc; ih++){
1158                            Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1159                            if(pl == 1 || pl == 2 || pl == 5){
1160                                nphit_i++;  
1161                                enhit_i += (op->dedx).At(ih);
1162                            };
1163                        };
1164                        //
1165                        ti->DoTrack2(tr);
1166                        //
1167                        if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){
1168                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1169                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1170                                if(pl == 0){
1171                                    nphit_i++;
1172                                    enhit_i += (op->dedx).At(ih);
1173                                };
1174                            };
1175                        };
1176                        if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){
1177                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1178                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1179                                if(pl == 3){
1180                                    nphit_i++;
1181                                    enhit_i += (op->dedx).At(ih);
1182                                };
1183                            };
1184                        };
1185                        if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1186                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1187                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1188                                if(pl == 4){
1189                                    nphit_i++;
1190                                    enhit_i += (op->dedx).At(ih);
1191                                };
1192                            };
1193                        };          
1194    
1195                                    
1196            if(                      if(
1197               use_TOF            &&                          (use_TOF || use_S1 || use_S2 || use_S3)            &&
1198               (nphit_p+nphit_i) !=0 &&                            (nphit_p+nphit_i) !=0 &&        
1199               true){                          true){
1200                                            
1201              //      printf(" seqno %i nphit_p %i nphit_i %i enhit_p %f enhit_i %f \n",trk2_obj->TrkLevel2::GetSeqNo(i),nphit_p,nphit_i,enhit_p,enhit_i);                          //          printf(" seqno %i nphit_p %i nphit_i %i enhit_p %f enhit_i %f \n",trk2_obj->TrkLevel2::GetSeqNo(i),nphit_p,nphit_i,enhit_p,enhit_i);
1202              //      printf(" score p %i score i %i \n",tp_score,ti_score);                          //          printf(" score p %i score i %i \n",tp_score,ti_score);
1203              //            if( enhit_p > enhit_i ) tp_score++;                          //                if( enhit_p > enhit_i ) tp_score++;
1204              //            if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;                          //                if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
1205              if ( nphit_p > nphit_i ) tp_score++;                          if ( nphit_p > nphit_i ) tp_score++;
1206              if ( nphit_p < nphit_i ) ti_score++;                          if ( nphit_p < nphit_i ) ti_score++;
1207              if ( nphit_p == nphit_i ){                          if ( nphit_p == nphit_i ){
1208                if ( enhit_p > enhit_i ) tp_score++;                              if ( enhit_p > enhit_i ) tp_score++;
1209                else ti_score++;                              else ti_score++;
1210              };                          };
1211              //      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);
1212            };                      };
1213            delete tr;                      delete tr;
1214            //                      //
1215          } else {                  } else {
1216            //                      // -------------
1217            // NOT a NUCLEUS                      // NOT a NUCLEUS
1218            //                      // -------------
1219            //printf(" NOT a NUCLEUS! en = %f \n",sen);                      //printf(" NOT a NUCLEUS! en = %f \n",sen);
1220    
1221            Int_t nphit_p =0;                      Int_t nphit_p =0;
1222            Int_t nphit_i =0;                      Int_t nphit_i =0;
1223                                    
1224                                    
1225            /*                            cout << "track: npmtadc "<< op->npmtadc << endl;                      /*                          cout << "track: npmtadc "<< op->npmtadc << endl;
1226              cout << "track: npmttdc "<< op->npmttdc << endl;                                                  cout << "track: npmttdc "<< op->npmttdc << endl;
1227              cout << "image: npmtadc "<< oi->npmtadc << endl;                                                  cout << "image: npmtadc "<< oi->npmtadc << endl;
1228              cout << "image: npmttdc "<< oi->npmttdc << endl;*/                                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1229                                    
1230  //        for (Int_t ih=0; ih < op->npmtadc; ih++){  //        for (Int_t ih=0; ih < op->npmtadc; ih++){
1231  //          Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
# Line 896  void PamLevel2::SortTracks(){ Line 1236  void PamLevel2::SortTracks(){
1236  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1237  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1238  //        };  //        };
1239            // --- modified to count tdc signals (more efficient?)                      // --- modified to count tdc signals (more efficient?)
1240            // --- and to implement check on tdcflag                      // --- and to implement check on tdcflag
1241            for (Int_t ih=0; ih < op->npmttdc; ih++){                      for (Int_t ih=0; ih < op->npmttdc; ih++){
1242              Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );                          Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );
1243  //          if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;  //          if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
1244              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 )) ){
1245            };                              if( (op->tdcflag).At(ih)==0 )nphit_p++;
1246                            };
1247                        };
1248                                    
1249            for (Int_t ih=0; ih < oi->npmttdc; ih++){                      for (Int_t ih=0; ih < oi->npmttdc; ih++){
1250              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );                          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );
1251  //          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++;  
1252              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 )) ){
1253            };                              if( (oi->tdcflag).At(ih)==0 )nphit_i++;    
1254                            };
1255                        };
1256                                    
1257            if(                      if(
1258               (nphit_p+nphit_i) !=0 &&                            (nphit_p+nphit_i) !=0 &&        
1259               true){                          true){
1260                                            
1261              if     ( nphit_p > nphit_i) tp_score++;                          if ( nphit_p != nphit_i ){
1262              else if( nphit_p < nphit_i) ti_score++;                              totp_score += nphit_p;
1263              else ;//niente                              toti_score += nphit_i;
1264            };                              tp_score+=nphit_p;
1265          };                              ti_score+=nphit_i;
1266          //      cout << "TOF "<<tp_score<<ti_score<<endl;                          };
1267        };                          //          if     ( nphit_p > nphit_i) tp_score+=nphit_p;
1268                            //          else if( nphit_p < nphit_i) ti_score+=nphit_i;
1269                            //          else ;//niente
1270                        };
1271                    };
1272                    //      cout << "TOF "<<tp_score<<ti_score<<endl;
1273                };
1274    
1275    
1276  //      if(tp_score == ti_score) use_TRK = true;  //      if(tp_score == ti_score) use_TRK = true;
1277    
1278    
1279        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1280        // tracker check              // *****************************************************************************************
1281        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1282        // chi**2 difference is not always large enough to distinguish among              // tracker check
1283        // the real track and its image.              // -----------------------------------------------------------------------------------------
1284        // Tracker check will be applied always when calorimeter and tof information is ambiguous.              // chi**2 difference is not always large enough to distinguish among
1285        // *** MODIFIED ON AUGUST 2007 ***              // the real track and its image.
1286        if(use_TRK){              // Tracker check will be applied always when calorimeter and tof information is ambiguous.
1287                // *** MODIFIED ON AUGUST 2007 ***
1288                if(use_TRK){
1289  //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;  //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
1290  //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;  //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
1291    
1292            // CHECK 1 : number of points along X                    // CHECK 1 : number of points along X  
1293            if ( tp->GetNX() >= ti->GetNX() )tp_score++ ;                  if ( tp->GetNX() >= ti->GetNX() ){
1294            if ( tp->GetNX() <= ti->GetNX() )ti_score++ ;                      tp_score++ ;
1295            // CHECK 2 : number of points along Y                        totp_score++ ;
1296            if ( tp->GetNY() >= ti->GetNY() )tp_score++ ;                  };
1297            if ( tp->GetNY() <= ti->GetNY() )ti_score++ ;                  if ( tp->GetNX() <= ti->GetNX() ){
1298            // CHECK 3 : chi**2 along X                        ti_score++ ;
1299  //        if(      tp->GetChi2X() > 0 && (tp->GetChi2X() < ti->GetChi2X() || ti->GetChi2X() <=0) ) tp_score++ ;                      toti_score++ ;
1300  //        if(      ti->GetChi2X() > 0 && (ti->GetChi2X() < tp->GetChi2X() || tp->GetChi2X() <=0) ) ti_score++ ;                  };
1301            // CHECK 4 : chi**2 along Y                    // CHECK 2 : number of points along Y  
1302  //        if(      tp->GetChi2Y() > 0 && (tp->GetChi2Y() < ti->GetChi2Y() || ti->GetChi2Y() <=0) ) tp_score++ ;                  if ( tp->GetNY() >= ti->GetNY() ){
1303  //        if(      ti->GetChi2Y() > 0 && (ti->GetChi2Y() < tp->GetChi2Y() || tp->GetChi2Y() <=0) ) ti_score++ ;                      tp_score++ ;
1304            // CHECK 5 : total chi**2                        totp_score++ ;
1305  //        if(      tp->chi2 > 0 && (tp->chi2 < ti->chi2 || ti->chi2 <=0) ) tp_score++ ;                  };
1306  //        if(      ti->chi2 > 0 && (ti->chi2 < tp->chi2 || tp->chi2 <=0) ) ti_score++ ;                  if ( tp->GetNY() <= ti->GetNY() ){
1307                        ti_score++ ;
1308                        toti_score++ ;
1309                    };
1310    
1311                    //      cout << "TRK "<<tp_score<<ti_score<<endl;
1312                };
1313                
1314    
1315          //      cout << "TRK "<<tp_score<<ti_score<<endl;              // -----------------------------------------------------------------------------------------
1316        };              // *****************************************************************************************
1317                // -----------------------------------------------------------------------------------------
1318                // GPamela check
1319                // -----------------------------------------------------------------------------------------
1320                            
1321                //---------------------------------------------------
1322                // count the number of GP hits
1323                //---------------------------------------------------
1324                if(use_GP){
1325                    int ngphits_p=0;
1326                    int ngphits_i=0;
1327                    float toll = 0.02; //200 micron
1328                    for(int ih=0; ih<GetGPamela()->Nthspe; ih++){
1329                        int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
1330                        if(
1331                            tp &&
1332                            tp->YGood(ip) &&
1333                            fabs(tp->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1334                            true) ngphits_p++;
1335                        if( ti &&
1336                            ti->YGood(ip) &&
1337                            fabs(ti->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1338                            true) ngphits_i++;
1339                    }
1340                    if(
1341                        ngphits_p > ngphits_i &&
1342                        true){
1343                        tp_score++ ;
1344                        totp_score++ ;                  
1345                    }
1346                    if(
1347                        ngphits_p < ngphits_i &&
1348                        true){
1349                        ti_score++ ;
1350                        toti_score++ ;                  
1351                    }
1352                }
1353    
1354    
1355        // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*              // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1356        // the winner is....              // the winner is....
1357        // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*              // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1358        if      (tp_score > ti_score) {              if      (tp_score > ti_score) {
1359                    
1360    
1361        }else if (tp_score < ti_score) {              }else if (tp_score < ti_score) {
1362    
1363    
1364                    ts = ti;//its image!!
1365                    cs = ci;
1366                    os = oi;
1367                    Int_t totis = toti_score;
1368    
1369          ts = ti;//its image!!                  ti = tp;//its image!!
1370          cs = ci;                  ci = cp;
1371          os = oi;                  oi = op;
1372    
1373          ti = tp;//its image!!                  tp = ts;//its image!!
1374          ci = cp;                  cp = cs;
1375          oi = op;                  op = os;
1376    
1377          tp = ts;//its image!!                  toti_score = totp_score;
1378          cp = cs;                  totp_score = totis;
         op = os;  
1379    
1380                                    
1381        }else {              }else {
1382    
1383  //      cout << "Warning - track image ambiguity not solved" << endl;  //      cout << "Warning - track image ambiguity not solved" << endl;
1384    
1385        };              };
1386                            
1387      }else{          }else{
1388        //            ts = tp;              totp_score = 1;
1389        //            cs = cp;              toti_score = 0;
1390        //            os = op;        
1391      };              //      ts = tp;
1392                        //      cs = cp;
1393      //  cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;              //      os = op;
1394      //  sorted_tracks->Add(ts);//save the track in the sorted array          };
1395      //  sorted_tracks.Add(ts);//save the track in the sorted array          
1396      //  sorted_tracks.Add(tp);//save the track in the sorted array          //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
1397      //  cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;          //      sorted_tracks->Add(ts);//save the track in the sorted array
1398      //  cout<<"o "<<tp<<endl;          //      sorted_tracks.Add(ts);//save the track in the sorted array
1399      //  cout<<"o "<<cp<<endl;          //      sorted_tracks.Add(tp);//save the track in the sorted array
1400      //  cout<<"o "<<op<<endl;          //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
1401      new(ttsorted[i]) PamTrack(tp,cp,op);          //      cout<<"o "<<tp<<endl;
1402      new(ttimage[i])  PamTrack(ti,ci,oi);          //      cout<<"o "<<cp<<endl;
1403    };          //      cout<<"o "<<op<<endl;
1404    
1405    if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){          new(ttsorted[i]) PamTrack(tp,cp,op);
1406      cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;          new(ttimage[i])  PamTrack(ti,ci,oi);
1407      tsorted->Delete(); tsorted=0;  
1408      timage->Delete(); timage=0;          ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);
1409    }          ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);
1410            ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);
1411    //Restore Object count          ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);
1412    //To save space in the table keeping track of all referenced objects      };
1413    //We reset the object count to what it was at the beginning of the event.  
1414    TProcessID::SetObjectCount(ObjectNumber);      if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
1415            cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;
1416            tsorted->Delete(); tsorted=0;
1417            timage->Delete(); timage=0;    
1418        }
1419    
1420        //Restore Object count
1421        //To save space in the table keeping track of all referenced objects
1422        //We reset the object count to what it was at the beginning of the event.
1423        TProcessID::SetObjectCount(ObjectNumber);
1424            
1425  };  };
1426  //--------------------------------------  //--------------------------------------
# Line 1042  TClonesArray *PamLevel2::GetTracks(){ Line 1449  TClonesArray *PamLevel2::GetTracks(){
1449    
1450      return tsorted;      return tsorted;
1451            
1452   };  };
1453  //--------------------------------------  //--------------------------------------
1454   //  //
1455   //  //
1456  //--------------------------------------  //--------------------------------------
1457  /**  /**
1458   * Retrieves the it-th Pamela "physical" track.   * Retrieves the it-th Pamela "physical" track.
# Line 1167  PamTrack *PamLevel2::GetTrackImage(int i Line 1574  PamTrack *PamLevel2::GetTrackImage(int i
1574   */   */
1575  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){
1576    
1577  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {
1578  //     else                    GetWhichTrees(f);          cout << "+AUTO"<<endl;
1579    if ( pam_tree ){          GetWhichTrees(f);
1580      printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");      };
1581      return pam_tree;      SetWhichTrees(detlist);
1582    };  
1583    //      if ( pam_tree ){
1584            printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");
1585            return pam_tree;
1586        };
1587        //
1588    
1589      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
1590    
1591      SetWhichTrees(detlist);  //    SetWhichTrees(detlist);
1592    
1593      TTree *Trout =0;      TTree *Trout =0;
1594    
# Line 1198  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1609  TTree *PamLevel2::GetPamTree(TFile *f, T
1609      if(ND)cout<<"ND ";      if(ND)cout<<"ND ";
1610      if(S4)cout<<"S4 ";      if(S4)cout<<"S4 ";
1611      if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
1612        if(GP)cout<<"GP ";
1613      cout << endl;      cout << endl;
1614      if(SELLI)cout<<">>> Found selection-list <<<"<<endl;      if(SELLI)cout<<">>> Found selection-list <<<"<<endl;
1615    
# Line 1296  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1708  TTree *PamLevel2::GetPamTree(TFile *f, T
1708          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
1709      };      };
1710    
1711        // GPamela
1712        TTree *G = (TTree*)f->Get("h20");
1713        if(G && GP) {
1714            if(!gp_obj)gp_obj=new GPamela();
1715    //      ------------------------------------
1716    //      ATTENZIONE!!!
1717    //      non so per quale arcano motivo,
1718    //      per l'albero di gpamela il branch address lo devo settare
1719    //      DOPO aver fatto friend
1720    //      FGRRRVZZZZUTSALKJMSLKJ!!!
1721    //      ------------------------------------
1722    //      gp_obj->SetBranchAddress(G); //ho dovuto fare in maniera diversa dagli altri
1723    //      cout << "h20          : set branch address GPamela "<<endl;
1724            if(!Trout)Trout=G;
1725            else Trout->AddFriend(G);
1726        }else{
1727    //      cout << "h20          : missing tree"<<endl;
1728        };
1729    
1730    
1731      TTree *L = (TTree*)f->Get("SelectionList");      TTree *L = (TTree*)f->Get("SelectionList");
1732      if(L && SELLI==1) {      if(L && SELLI==1) {
1733  //      L->SetBranchAddress("RunEntry",&irun);  //      L->SetBranchAddress("RunEntry",&irun);
# Line 1304  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1736  TTree *PamLevel2::GetPamTree(TFile *f, T
1736  //      cout << "SelectionList: set branch address EventEntry"<<endl;  //      cout << "SelectionList: set branch address EventEntry"<<endl;
1737  //      if(!Trout)Trout=O;  //      if(!Trout)Trout=O;
1738  //      else Trout->AddFriend("SelectionList");  //      else Trout->AddFriend("SelectionList");
1739          cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemente!!!!"<<endl;          cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemented!!!!"<<endl;
1740          sel_tree = 0;          sel_tree = 0;
1741      }else{      }else{
1742          cout << "SelectionList  : missing tree"<<endl;          cout << "SelectionList  : missing tree"<<endl;
# Line 1312  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1744  TTree *PamLevel2::GetPamTree(TFile *f, T
1744            
1745      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1746    
1747    //      ------------------------------------
1748    //      ATTENZIONE!!!
1749    //      non so per quale arcano motivo,
1750    //      per l'albero di gpamela il branch address lo devo settare
1751    //      DOPO aver fatto friend
1752    //      FGRRRVZZZZUTSALKJMSLKJ!!!
1753    //      ------------------------------------
1754        if(G && GP) {      
1755            gp_obj->SetBranchAddress(Trout); //ho dovuto fare in maniera diversa dagli altri
1756            cout << "h20          : set branch address GPamela "<<endl;
1757        }else{
1758            cout << "h20          : missing tree"<<endl;
1759        };
1760    
1761      pam_tree = (TChain*)Trout;      pam_tree = (TChain*)Trout;
1762            
1763      return Trout;      return Trout;
# Line 1335  TList*  PamLevel2::GetListOfLevel2Files( Line 1781  TList*  PamLevel2::GetListOfLevel2Files(
1781      //    if(ddir=="")ddir = wdir;      //    if(ddir=="")ddir = wdir;
1782  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1783      if ( ddir != ""){      if ( ddir != ""){
1784        cout << "Level2 data directory : "<<  ddir << endl;          cout << "Level2 data directory : "<<  ddir << endl;
1785      } else {      } else {
1786        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;
1787      };      };
1788      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
1789      contents->SetOwner();      contents->SetOwner();
# Line 1354  TList*  PamLevel2::GetListOfLevel2Files( Line 1800  TList*  PamLevel2::GetListOfLevel2Files(
1800  //          return 0;  //          return 0;
1801  //      }        //      }      
1802  //      flisttxt = fullpath;  //      flisttxt = fullpath;
1803        if ( !flisttxt.EndsWith(".root") ){          if ( !flisttxt.EndsWith(".root") ){
1804    
1805          flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1806    
1807          if( !gSystem->ChangeDirectory(ddir) ){              if( !gSystem->ChangeDirectory(ddir) ){
1808              cout << "Cannot change directory : "<<ddir<<endl;                  cout << "Cannot change directory : "<<ddir<<endl;
1809              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;  
1810              }              }
1811              if(file.Contains("#"))file = file(0,file.First("#"));          
1812                cout <<"Input file list : " << flisttxt <<endl;
1813                ifstream in;
1814                in.open(flisttxt, ios::in); //open input file list
1815                if(!in.good()){
1816                    cout <<" ERROR opening the file "<<endl;
1817                    gSystem->ChangeDirectory(wdir); // back to the working directory
1818                    return 0;
1819                }  
1820                int line=0;
1821                while (1) {
1822                    TString file;
1823                    in >> file;
1824                    if (!in.good()) break;
1825                    line++;
1826    //          cout <<"(1) " << file << endl;
1827                    if(file.IsNull()){
1828                        cout << "-- list interrupted at line "<<line <<endl;
1829                        break;
1830                    }
1831                    if(file.Contains("#"))file = file(0,file.First("#"));
1832  //          cout <<"(2) " << file << endl;  //          cout <<"(2) " << file << endl;
1833  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1834  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
1835              if( file.EndsWith(".root") ){                  if( file.EndsWith(".root") ){
1836                TString filedir;                      TString filedir;
1837                if (ddir != ""){                      if (ddir != ""){
1838                  filedir = ddir; // take the input dir                          filedir = ddir; // take the input dir
1839                } else {                      } else {
1840                  gSystem->ChangeDirectory(wdir); // back to the working directory                          gSystem->ChangeDirectory(wdir); // back to the working directory
1841                  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
1842                };                      };
1843                  char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));                      char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));
1844                  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
1845                  delete fullpath;                      delete fullpath;
1846              }                  }
1847  //          }else{  //          }else{
1848  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1849  //          };  //          };
1850          };              };
1851          in.close();              in.close();
1852        } else {          } else {
1853            if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));
1854            char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1855            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
1856            delete fullpath;              delete fullpath;
1857        };                  };      
1858      }else{      }else{
1859                    
1860          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
1861          cout << "Check for existing root files."<<endl;          cout << "Check for existing root files."<<endl;
1862  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
1863          if ( ddir == "" ){          if ( ddir == "" ){
1864            ddir = wdir;              ddir = wdir;
1865            cout << "Level2 data directory : "<<  ddir << endl;              cout << "Level2 data directory : "<<  ddir << endl;
1866          };          };
1867    
1868          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
# Line 1462  TList*  PamLevel2::GetListOfLevel2Files( Line 1908  TList*  PamLevel2::GetListOfLevel2Files(
1908   * @return Pointer to a TChain   * @return Pointer to a TChain
1909   */   */
1910  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){
1911    //      //
1912    //      //
1913    //      //
1914    if ( pam_tree ){      if ( pam_tree ){
1915      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 ");
1916      return pam_tree;          return pam_tree;
1917    };      };
1918    //      //
1919            
1920      TChain *Trout =0;      TChain *Trout =0;
1921    
 //    if( !detlist.IsNull() )SetWhichTrees(detlist);  
     SetWhichTrees(detlist);  
1922            
1923      cout<< "GetPamTree(TList*,TString): input detector list --> ";      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {
1924      if(TRK1)cout<<"TRK1 ";          if( fl->GetEntries()>0 ){
1925      if(TRK2)cout<<"TRK2 ";              cout << "+AUTO"<<endl;
1926      if(TRKh)cout<<"TRKH ";              TFile *fprimo = new TFile( fl->At(0)->GetName() );
1927      if(CAL1)cout<<"CAL1 ";              GetWhichTrees(fprimo);
1928      if(CAL2)cout<<"CAL2 ";              fprimo->Delete();
1929      if(TOF)cout<<"TOF ";          }
1930      if(TRG)cout<<"TRG ";      };
1931      if(AC)cout<<"AC ";      SetWhichTrees(detlist);    
1932      if(ND)cout<<"ND ";  
     if(S4)cout<<"S4 ";  
     if(ORB)cout<<"ORB ";  
     cout << endl;  
1933    
      TChain *T = 0;      
      TChain *C = 0;  
      TChain *O = 0;  
      TChain *R = 0;  
      TChain *S = 0;  
      TChain *N = 0;  
      TChain *A = 0;  
      TChain *B = 0;  
1934    
1935       TChain *L = 0;  //    if( !detlist.IsNull() )SetWhichTrees(detlist);
1936    //    
1937        TChain *T = 0;      
1938        TChain *C = 0;
1939        TChain *O = 0;
1940        TChain *R = 0;
1941        TChain *S = 0;
1942        TChain *N = 0;
1943        TChain *A = 0;
1944        TChain *B = 0;
1945        TChain *G = 0;
1946    
1947        TChain *L = 0;
1948            
1949      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
1950      if(CAL2||CAL1)       C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
# Line 1509  TChain *PamLevel2::GetPamTree(TList *fl, Line 1954  TChain *PamLevel2::GetPamTree(TList *fl,
1954      if(ND)               N = new TChain("NeutronD");      if(ND)               N = new TChain("NeutronD");
1955      if(AC)               A = new TChain("Anticounter");      if(AC)               A = new TChain("Anticounter");
1956      if(ORB)              B = new TChain("OrbitalInfo");      if(ORB)              B = new TChain("OrbitalInfo");
1957       L = new TChain("SelectionList");      if(GP)               G = new TChain("h20");
1958        L = new TChain("SelectionList");
1959            
1960      // loop over files and create chains              // loop over files and create chains        
1961      TIter next(fl);      TIter next(fl);
# Line 1526  TChain *PamLevel2::GetPamTree(TList *fl, Line 1972  TChain *PamLevel2::GetPamTree(TList *fl,
1972              if(ND)               N->Add(name);              if(ND)               N->Add(name);
1973              if(AC)               A->Add(name);              if(AC)               A->Add(name);
1974              if(ORB)              B->Add(name);              if(ORB)              B->Add(name);
1975                if(GP)               G->Add(name);
1976              if(SELLI==1)         L->Add(name);              if(SELLI==1)         L->Add(name);
1977          };          };
1978      };      };
# Line 1536  TChain *PamLevel2::GetPamTree(TList *fl, Line 1983  TChain *PamLevel2::GetPamTree(TList *fl,
1983  //    UInt_t *found=0;  //    UInt_t *found=0;
1984  // Tracker  // Tracker
1985      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
1986          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));  //      if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1987  //      else    T->SetBranchStatus("TrkLevel2",0,found);  //      if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
1988          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;  //      if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1989          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));  //      if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
1990  //      else    T->SetBranchStatus("TrkLevel1",0,found);  //      if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1991          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;  //      if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
         if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));  
 //      else    T->SetBranchStatus("TrkHough",0,found);  
         if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;  
1992          if(!Trout)Trout=T;          if(!Trout)Trout=T;
1993          else Trout->AddFriend("Tracker");          else Trout->AddFriend("Tracker");
1994      }else{      }else{
1995          cout << "Tracker      : missing tree"<<endl;  //        cout << "Tracker      : missing tree"<<endl;
1996      };      };
1997      // Calorimeter      // Calorimeter
1998      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
1999          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));  //        if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
2000  //      else    C->SetBranchStatus("CaloLevel2",0,found);  //        if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
2001          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;  //        if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
2002          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));  //        if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
 //      else    C->SetBranchStatus("CaloLevel1",0,found);  
         if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;  
2003          if(!Trout)Trout=C;          if(!Trout)Trout=C;
2004          else Trout->AddFriend("Calorimeter");          else Trout->AddFriend("Calorimeter");
2005      }else{      }else{
2006          cout << "Calorimeter  : missing tree"<<endl;  //        cout << "Calorimeter  : missing tree"<<endl;
2007      };      };
2008      // ToF          // ToF    
2009      if(O && TOF) {      if(O && TOF) {
2010          O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));  //        O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
2011          cout << "ToF          : set branch address ToFLevel2"<<endl;  //        cout << "ToF          : set branch address ToFLevel2"<<endl;
2012          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2013          else Trout->AddFriend("ToF");          else Trout->AddFriend("ToF");
2014      }else{      }else{
2015          cout << "ToF         : missing tree"<<endl;  //        cout << "ToF         : missing tree"<<endl;
2016      };      };
2017      // Trigger      // Trigger
2018      if(R && TRG) {      if(R && TRG) {
2019          R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));  //        R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
2020          cout << "Trigger      : set branch address TrigLevel2"<<endl;  //        cout << "Trigger      : set branch address TrigLevel2"<<endl;
2021          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2022          else Trout->AddFriend("Trigger");          else Trout->AddFriend("Trigger");
2023      }else{      }else{
2024          cout << "Trigger      : missing tree"<<endl;  //        cout << "Trigger      : missing tree"<<endl;
2025      };      };
2026      // S4      // S4
2027      if(S && S4) {      if(S && S4) {
2028          S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));  //        S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
2029          cout << "S4           : set branch address S4Level2"<<endl;  //        cout << "S4           : set branch address S4Level2"<<endl;
2030          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2031          else Trout->AddFriend("S4");          else Trout->AddFriend("S4");
2032      }else{      }else{
2033          cout << "S4           : missing tree"<<endl;  //        cout << "S4           : missing tree"<<endl;
2034      };      };
2035      // Neutron Detector      // Neutron Detector
2036      if(N && ND) {      if(N && ND) {
2037          N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));  //        N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
2038          cout << "NeutronD     : set branch address NDLevel2"<<endl;  //        cout << "NeutronD     : set branch address NDLevel2"<<endl;
2039          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2040          else Trout->AddFriend("NeutronD");          else Trout->AddFriend("NeutronD");
2041      }else{      }else{
2042          cout << "NeutronD     : missing tree"<<endl;  //        cout << "NeutronD     : missing tree"<<endl;
2043      };      };
2044      // Anticounters      // Anticounters
2045      if(A && AC) {      if(A && AC) {
2046          A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));  //        A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
2047          cout << "Anticounter  : set branch address AcLevel2"<<endl;  //        cout << "Anticounter  : set branch address AcLevel2"<<endl;
2048          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2049          else Trout->AddFriend("Anticounter");          else Trout->AddFriend("Anticounter");
2050      }else{      }else{
2051          cout << "Anticounter  : missing tree"<<endl;  //        cout << "Anticounter  : missing tree"<<endl;
2052      };      };
2053      // Orbital Info      // Orbital Info
2054      if(B && ORB) {      if(B && ORB) {
2055          B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));  //      B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
2056          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;  //      cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
2057          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2058          else Trout->AddFriend("OrbitalInfo");          else Trout->AddFriend("OrbitalInfo");
2059      }else{      }else{
2060          cout << "OrbitalInfo  : missing tree"<<endl;  //      cout << "OrbitalInfo  : missing tree"<<endl;
2061      };      };
2062        // GPamela
2063        if(G && GP) {
2064            if(!gp_obj)gp_obj = new GPamela();
2065    //      ------------------------------------
2066    //      ATTENZIONE!!!
2067    //      non so per quale arcano motivo,
2068    //      per l'albero di gpamela il branch address lo devo settare
2069    //      DOPO aver fatto friend
2070    //      FGRRRVZZZZUTSALKJMSLKJ!!!
2071    //      ------------------------------------
2072    //      gp_obj->SetBranchAddress(G); //ho dovuto fare in maniera diversa dagli altri
2073    //      cout << "h20          : set branch address GPamela "<<endl;
2074            if(!Trout)Trout=G;
2075            else Trout->AddFriend("h20");
2076        }else{
2077    //      cout << "h20          : missing tree"<<endl;
2078        };
2079    
2080    //  =====================================
2081    //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND
2082    //  =====================================
2083        SetBranchAddress(Trout);
2084    
2085      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2086    
2087      // Selection List      // Selection List
2088      if(L && SELLI==1) {      if(L && SELLI==1) {
2089          cout<<">>> Found selection-list <<<"<<endl;          cout<<">>> Found selection-list <<<"<<endl;
2090    //      L->SetBranchAddress("RunEntry",&irun);
2091          L->SetBranchAddress("RunEntry",&irun);          L->SetBranchAddress("RunEntry",&irun);
2092          cout << "SelectionList: set branch address RunEntry"<<endl;          cout << "SelectionList: set branch address RunEntry"<<endl;
2093          L->SetBranchAddress("EventEntry",&irunentry);          L->SetBranchAddress("EventEntry",&irunentry);
# Line 1637  TChain *PamLevel2::GetPamTree(TList *fl, Line 2103  TChain *PamLevel2::GetPamTree(TList *fl,
2103            
2104  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
2105    
2106      pam_tree = Trout;  //      ------------------------------------
2107    //      ATTENZIONE!!!
2108    //      non so per quale arcano motivo,
2109    //      per l'albero di gpamela il branch address lo devo settare
2110    //      DOPO aver fatto friend
2111    //      FGRRRVZZZZUTSALKJMSLKJ!!!
2112    //      ------------------------------------
2113    //     cout << G << " --- "<<GP <<endl;
2114    //     if(G && GP) {    
2115    //      gp_obj->SetBranchAddress(Trout); //ho dovuto fare in maniera diversa dagli altri
2116    //      cout << "h20          : set branch address GPamela "<<endl;
2117    //     }else{
2118    //      cout << "h20          : missing tree"<<endl;
2119    //     };
2120    
2121    
2122        pam_tree = Trout;
2123        
2124      return Trout;      return Trout;
2125  }  }
2126    
# Line 1664  void PamLevel2::SetBranchAddress(TTree * Line 2146  void PamLevel2::SetBranchAddress(TTree *
2146      ND     = ND  & t->GetBranchStatus("NDLevel2");      ND     = ND  & t->GetBranchStatus("NDLevel2");
2147      AC     = AC  & t->GetBranchStatus("AcLevel2");      AC     = AC  & t->GetBranchStatus("AcLevel2");
2148      ORB    = ORB & t->GetBranchStatus("OrbitalInfo");      ORB    = ORB & t->GetBranchStatus("OrbitalInfo");
2149        GP     = GP  & t->GetBranchStatus("h20");
2150    
2151    
2152      // Tracker      // Tracker
# Line 1720  void PamLevel2::SetBranchAddress(TTree * Line 2203  void PamLevel2::SetBranchAddress(TTree *
2203          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
2204          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
2205      };      };
2206        // GPamela
2207        if(GP) {
2208    //      GetPointerTo("GPamela");
2209            if(!gp_obj)gp_obj = new GPamela();
2210            gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2211            cout << "h20          : set branch address GPamela "<<endl;
2212        };
2213      // SelectionList      // SelectionList
2214      if(SELLI==1) {      if(SELLI==1) {
2215    //      t->SetBranchAddress("RunEntry", &irun);
2216          t->SetBranchAddress("RunEntry", &irun);          t->SetBranchAddress("RunEntry", &irun);
2217          cout << "SelectionList: set branch address RunEntry"<<endl;          cout << "SelectionList: set branch address RunEntry"<<endl;
2218          t->SetBranchAddress("EventEntry", &irunentry);          t->SetBranchAddress("EventEntry", &irunentry);
# Line 1734  void PamLevel2::SetBranchAddress(TTree * Line 2225  void PamLevel2::SetBranchAddress(TTree *
2225   */   */
2226  void PamLevel2::SetBranchAddress(TChain *t){  void PamLevel2::SetBranchAddress(TChain *t){
2227    
2228      TRK2    = TRK2 & t->GetBranchStatus("TrkLevel2");  //     TRK2    = TRK2 & t->GetBranchStatus("TrkLevel2");
2229      TRK1    = TRK1 & t->GetBranchStatus("TrkLevel1");  //     TRK1    = TRK1 & t->GetBranchStatus("TrkLevel1");
2230      TRKh    = TRKh & t->GetBranchStatus("TrkHough");  //     TRKh    = TRKh & t->GetBranchStatus("TrkHough");
2231      CAL1    = CAL1 & t->GetBranchStatus("CaloLevel1");  //     CAL1    = CAL1 & t->GetBranchStatus("CaloLevel1");
2232      CAL2    = CAL2 & t->GetBranchStatus("CaloLevel2");  //     CAL2    = CAL2 & t->GetBranchStatus("CaloLevel2");
2233      TOF    = TOF & t->GetBranchStatus("ToFLevel2");  //     TOF    = TOF & t->GetBranchStatus("ToFLevel2");
2234      TRG    = TRG & t->GetBranchStatus("TrigLevel2");  //     TRG    = TRG & t->GetBranchStatus("TrigLevel2");
2235      S4     = S4  & t->GetBranchStatus("S4Level2");  //     S4     = S4  & t->GetBranchStatus("S4Level2");
2236      ND     = ND  & t->GetBranchStatus("NDLevel2");  //     ND     = ND  & t->GetBranchStatus("NDLevel2");
2237      AC     = AC  & t->GetBranchStatus("AcLevel2");  //     AC     = AC  & t->GetBranchStatus("AcLevel2");
2238      ORB    = ORB & t->GetBranchStatus("OrbitalInfo");  //     ORB    = ORB & t->GetBranchStatus("OrbitalInfo");
2239    //    GP     = GP & t->GetBranchStatus("h20");
2240    
2241      // Tracker      // Tracker
2242       if(TRK2) {      if(TRK2) {
2243          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
2244          cout << "Tracker      : set branch address TrkLevel2"<<endl;          cout << "Tracker      : set branch address TrkLevel2"<<endl;
2245      };      };
# Line 1755  void PamLevel2::SetBranchAddress(TChain Line 2247  void PamLevel2::SetBranchAddress(TChain
2247          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
2248          cout << "Tracker      : set branch address TrkLevel1"<<endl;          cout << "Tracker      : set branch address TrkLevel1"<<endl;
2249      };      };
2250       if(TRKh) {      if(TRKh) {
2251          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
2252          cout << "Tracker      : set branch address TrkHough"<<endl;          cout << "Tracker      : set branch address TrkHough"<<endl;
2253       };      };
2254            
2255      // Calorimeter      // Calorimeter
2256      if(CAL2) {      if(CAL2) {
# Line 1800  void PamLevel2::SetBranchAddress(TChain Line 2292  void PamLevel2::SetBranchAddress(TChain
2292          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
2293          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
2294      };      };
2295        // GPamela
2296    //    cout <<"GP "<<GP<<endl;
2297        if(GP) {
2298    //      GetPointerTo("GPamela");
2299            if(!gp_obj)gp_obj = new GPamela();
2300            gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2301            cout << "h20          : set branch address GPamela "<<endl;
2302        };
2303      // SelectionList      // SelectionList
2304      if(SELLI==1) {      if(SELLI==1) {
2305    //      t->SetBranchAddress("RunEntry", &irun);
2306          t->SetBranchAddress("RunEntry", &irun);          t->SetBranchAddress("RunEntry", &irun);
2307          cout << "SelectionList: set branch address RunEntry"<<endl;          cout << "SelectionList: set branch address RunEntry"<<endl;
2308          t->SetBranchAddress("EventEntry", &irunentry);          t->SetBranchAddress("EventEntry", &irunentry);
# Line 1821  void PamLevel2::SetBranchAddress(TChain Line 2322  void PamLevel2::SetBranchAddress(TChain
2322   * @return Pointer to a TChain   * @return Pointer to a TChain
2323   */   */
2324  TChain *PamLevel2::GetRunTree(TList *fl){  TChain *PamLevel2::GetRunTree(TList *fl){
2325    //      //
2326    //      //
2327    //      //
2328    if ( run_tree ){      if ( run_tree ){
2329      printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");          printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
2330      return run_tree;          return run_tree;
2331    };          };  
2332    //      //
2333    TChain *R = new TChain("Run");      TChain *R = new TChain("Run");
2334            
2335      // loop over files and create chains              // loop over files and create chains        
2336      TIter next(fl);      TIter next(fl);
# Line 1868  TChain *PamLevel2::GetRunTree(TList *fl) Line 2369  TChain *PamLevel2::GetRunTree(TList *fl)
2369   * @return Pointer to a TTree   * @return Pointer to a TTree
2370   */   */
2371  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f){
2372    if ( run_tree ){      if ( run_tree ){
2373      printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");          printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
2374      return run_tree;          return run_tree;
2375    };      };
2376                    
2377    
2378      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
# Line 1896  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2397  TTree *PamLevel2::GetRunTree(TFile *f){
2397   * @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
2398   */   */
2399  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){
2400    //      //
2401    // check if we have already called once GetEntry, if not call it      // check if we have already called once GetEntry, if not call it
2402    //      //
2403      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;
2404      if(!run){      if(!run){
2405            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;
2406            return(false);                  return(false);  
2407      }      }
2408      if ( run->GetEntries() <= 0 ) return(false);      if ( run->GetEntries() <= 0 ) return(false);
2409    //      //
2410        
2411    //  Int_t oldrun = irun;      //  Int_t oldrun = irun;
2412    Long64_t oldrun = irun;      Long64_t oldrun = irun;
2413    
2414        // --------------------------------------
2415        // if it is a full file (not preselected)
2416        // --------------------------------------
2417        if(SELLI==0){
2418    
2419            //
2420            // the absolute time is necessary to relate the event with the run
2421            //
2422            if( !GetOrbitalInfo() && !ISGP){
2423                cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2424                return(false);
2425            }
2426    
2427            ULong64_t abstime = 0;
2428            if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;
2429    
2430    
2431            //
2432            // the first time the routine is called, set run search from the beginning
2433            //
2434            if ( irun < 0LL ){
2435                irun = 0LL;
2436                run->GetEntry(irun);
2437                runfirstentry = 0LL;
2438                runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2439                if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2440              
2441                if( ISGP && run->GetEntries()!=1 ){
2442                    cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl;
2443                    cout << "** WARNING ** run will not be updated"<<endl;
2444                }
2445    
2446    // --------------------------------------          };      
2447    // if it is a full file (not preselected)          //
2448    // --------------------------------------          if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2449    if(SELLI==0){          //
2450            if ( irun == run->GetEntries()-1LL &&
2451        //               !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2452        // the absolute time is necessary to relate the event with the run                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
       //  
       if( !GetOrbitalInfo() ){  
           cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;  
           return(false);  
       }  
   
       //  
       // 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;  
       };        
       //  
        if ( irun == run->GetEntries()-1LL &&  
            !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME &&  
              GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME)  
2453              ){              ){
2454           irun = -1LL;              irun = -1LL;
2455           runfirstentry = 0LL;              runfirstentry = 0LL;
2456           runlastentry = -1LL;              runlastentry = -1LL;
2457         };          };
2458        // modificato il controllo sull'aggiornamento del run, per evitare problemi          // modificato il controllo sull'aggiornamento del run, per evitare problemi
2459        // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)          // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
2460        //          //
2461        bool fromfirst = true;          bool fromfirst = true;
2462        //          //
2463        while ( !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME && GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){          while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){
2464  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
2465            irun++;              irun++;
2466            run->GetEntry(irun);              run->GetEntry(irun);
2467            runfirstentry = runlastentry;              runfirstentry = runlastentry;
2468            if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;
2469            runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2470  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2471  //        cout << "runfirstentry "<<runfirstentry<<endl;  //        cout << "runfirstentry "<<runfirstentry<<endl;
2472            //      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)));
2473            //      printf(" abstime %u trailertime %u \n",GetOrbitalInfo()->absTime,GetRunInfo()->RUNTRAILER_TIME);              //    printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);
2474            //      printf(" IDRUN %u \n",GetRunInfo()->ID);              //    printf(" IDRUN %u \n",GetRunInfo()->ID);
2475            //              //
2476  //        prevshift = 0;  //        prevshift = 0;
2477            //              //
2478            if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME && GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME)){              if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){
2479                printf(" resetting irun  (it should NOT happen!!!)\n");                  printf(" resetting irun  (it should NOT happen!!!)\n");
2480                fromfirst = false;                  fromfirst = false;
2481                irun = 0;                  irun = 0;
2482                run->GetEntry(irun);                  run->GetEntry(irun);
2483                runfirstentry = 0ULL;                  runfirstentry = 0ULL;
2484                runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);                  runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2485                if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;                  if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2486            };              };
2487            //              //
2488        };          };
2489        //          //
2490        if (          if (
2491             !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME &&              !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2492               GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME)                abstime <= GetRunInfo()->RUNTRAILER_TIME)
2493            ) {              ) {
2494            printf(" Something very wrong here: cannot find RUN containing absolute time %u \n",GetOrbitalInfo()->absTime);              printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n",abstime);
2495            return false;              return false;
2496        }          }
2497        //          //
2498        if ( irun == oldrun || irun >= run->GetEntries() ) return(false);          if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
2499        //          //
2500        //  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);
2501        //          //
2502        prevshift = 0;          prevshift = 0;
2503        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;          cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2504  //      cout << "runfirstentry "<<runfirstentry<<endl;  //      cout << "runfirstentry "<<runfirstentry<<endl;
2505        return(true);              return(true);    
2506    };      };
2507    // ----------------------------------------------------      // ----------------------------------------------------
2508    // if it is a preselected file (there is SelectionList)      // if it is a preselected file (there is SelectionList)
2509    // NBNB - the event tree MUST be read first      // NBNB - the event tree MUST be read first
2510    // ----------------------------------------------------      // ----------------------------------------------------
2511    if(SELLI==1){            if(SELLI==1){      
2512        sel_tree->GetEntry(iev);          sel_tree->GetEntry(iev);
2513  //      cout << irun << " "<< irunentry << endl;  //      cout << irun << " "<< irunentry << endl;
2514        if(irun != oldrun){          if(irun != oldrun){
2515            run->GetEntry(irun);              run->GetEntry(irun);
2516            cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;              cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2517            prevshift = 0;              prevshift = 0;
2518            return true;              return true;
2519        }          }
2520        return false;          return false;
2521    }      }
2522    
2523    return false;      return false;
2524    //      //
2525  };  };
2526    
2527  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){
# Line 2030  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2543  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2543      if(SELLI==0){      if(SELLI==0){
2544    
2545          // ---------------------------------------------------------------          // ---------------------------------------------------------------
2546            // increment dead and live-time counters
2547            // ---------------------------------------------------------------
2548            if( GetTrigLevel2() ){
2549                totdltime[0]+=GetTrigLevel2()->dltime[0];
2550                totdltime[1]+=GetTrigLevel2()->dltime[1];
2551            }
2552            totdltime[2]++;
2553    
2554    //      cout << setw(10)<<totdltime[0]<<setw(10)<<totdltime[1]<<setw(10)<<totdltime[2]<<endl;
2555    
2556            // ---------------------------------------------------------------
2557            // retrieve OBT and absolute time of the event
2558            // ---------------------------------------------------------------
2559            ULong64_t abstime = 0;
2560            ULong64_t obt     = 0;
2561            if( GetOrbitalInfo() ){
2562                abstime = GetOrbitalInfo()->absTime;
2563                obt     = GetOrbitalInfo()->OBT;
2564            }
2565            // ---------------------------------------------------------------
2566          // the absolute time is necessary to relate the event with the run          // the absolute time is necessary to relate the event with the run
2567          // ---------------------------------------------------------------          // ---------------------------------------------------------------
2568          if( !GetOrbitalInfo() ){          if( !GetOrbitalInfo() && !ISGP ){
2569              cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;              cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2570              return(false);              return(false);
2571          }          }
# Line 2045  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2578  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2578              irunentry = 0;              irunentry = 0;
2579              prevshift = 0;              prevshift = 0;
2580              run_tree->GetEntry(irun);              run_tree->GetEntry(irun);
2581    
2582                if( ISGP && run_tree->GetEntries()!=1 ){
2583                    cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl;
2584                    cout << "** WARNING ** run will not be updated"<<endl;
2585                }
2586          };                };      
2587    
2588            // -----------------------------------------------------------------------
2589            // if it is simulation, assign abstime by hand (temporaneo!!!)
2590            // -----------------------------------------------------------------------
2591            if(ISGP){
2592                abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2593                obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO
2594            }
2595          //          //
2596          bool fromfirst = true; // first loop over runs          bool fromfirst = true; // first loop over runs
2597    
# Line 2059  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2605  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2605          while (          while (
2606              (              (
2607                  (                  (
2608                      !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)                      !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2609                        GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME) &&                        abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
2610                      !(GetOrbitalInfo()->OBT >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)                      !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2611                        GetOrbitalInfo()->OBT <= GetRunInfo()->RUNTRAILER_OBT)                        obt <= GetRunInfo()->RUNTRAILER_OBT)
2612                      )                      )
2613                  || GetRunInfo()->NEVENTS==0                  || GetRunInfo()->NEVENTS==0
2614                  || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift)  //              || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento
2615                    || !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)
2616                  )                  )
2617                  && irun < run_tree->GetEntries() ){              && irun < run_tree->GetEntries() ){
2618    
2619                // - - - - - - - - - - - - -
2620                // irunentry = position of current entry, relative to the run
2621                // prevshift = shift needed to synchronize l0 and l2 data (nested events)
2622                // - - - - - - - - - - - - -
2623    
2624                // -----------------------------------------
2625                // store dead and live-time of previous run
2626                // -----------------------------------------
2627                if(fromfirst){
2628                    if(oldrun==irun){
2629                        /// decrement counters
2630                        if( GetTrigLevel2()){
2631                            totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time
2632                            totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time
2633                        }
2634                        totdltime[2]--;                              //event counter
2635                        cout << endl;
2636                        cout << "n.events     : "<<totdltime[2]<<endl;
2637                        cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;
2638                        cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;      
2639                    }else{
2640                        totdltime[0]=0;//live-time
2641                        totdltime[1]=0;//dead-time
2642                        totdltime[2]=0;                             //event counter
2643                        cout << " *** JUMP RUN *** irun "<<irun<<endl;
2644                    }
2645                    /// add an entry
2646                    if(run_tree_clone)
2647                        if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2648                            run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2649                    /// reset counters
2650                    if( GetTrigLevel2() ){
2651                        totdltime[0]=GetTrigLevel2()->dltime[0];//live-time
2652                        totdltime[1]=0;                         //dead-time
2653                    }
2654                    totdltime[2]=1;                             //event counter
2655                }
2656    
2657    
2658              irun++;              irun++;
2659              // ------------------------------------              // ------------------------------------
# Line 2096  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2682  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2682              // -------------------------------------------------------------------              // -------------------------------------------------------------------
2683              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;
2684              irunentry = 0;              irunentry = 0;
2685              prevshift = 0;              prevshift = 0;          
2686              run_tree->GetEntry(irun);                    run_tree->GetEntry(irun);      
2687              if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){              if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){
2688                  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;
# Line 2116  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2702  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2702    
2703          // --------------------------------------          // --------------------------------------
2704          // ... otherwise          // ... otherwise
2705            // --------------------------------------
2706    
2707    
2708    
2709    //      // -----------------------------------------
2710    //      // store dead and live-time of previous run
2711    //      // -----------------------------------------
2712    //      // --------------------------------------------------------------
2713    //      // if the run is empty, fill the dead-live time branch with zeros
2714    //      // --------------------------------------------------------------
2715    //      /// if some runs have been jumped, fill with zeros
2716    //      if(irun-oldrun>1){
2717    //          ULong64_t  temp[3];
2718    //          temp[0]=totdltime[0];
2719    //          temp[1]=totdltime[1];
2720    //          temp[2]=totdltime[2];
2721    //          for(int i=oldrun+1; i<irun; irun++){
2722    //              totdltime[0]=0;
2723    //              totdltime[1]=0;
2724    //              totdltime[2]=0;
2725    //              cout << " ** JUMPED RUN **"<<endl;
2726    //              if(run_tree_clone)
2727    //                  if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2728    //                      run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2729    //          }
2730    //          totdltime[0]=temp[0];
2731    //          totdltime[1]=temp[1];
2732    //          totdltime[2]=temp[2];
2733    //      }
2734    //      /// decrement counters
2735    //      if( GetTrigLevel2() ){
2736    //          totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time
2737    //          totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time
2738    //      }
2739    //      totdltime[2]--;                              //event counter
2740    //      /// add an entry
2741    //      if(irun>0 ){
2742    //          cout << endl;
2743    //          cout << "n.events     : "<<totdltime[2]<<endl;
2744    //          cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;
2745    //          cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;      
2746    //          if(run_tree_clone)
2747    //              if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2748    //                  run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2749    //      }
2750    //      /// reset counters
2751    //      if( GetTrigLevel2() ){
2752    //          totdltime[0]=GetTrigLevel2()->dltime[0];//live-time
2753    //          totdltime[1]=0;                         //dead-time
2754    //      }
2755    //      totdltime[2]=1;                             //event counter
2756            
2757    
2758            // --------------------------------------
2759          // ---> exit with TRUE          // ---> exit with TRUE
2760          // --------------------------------------          // --------------------------------------
2761          cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;          cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
# Line 2130  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2770  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2770              true ){              true ){
2771              cout << "* fragment *"<<endl;                            cout << "* fragment *"<<endl;              
2772          }          }
2773            
2774          return(true);              return(true);    
2775      };      };
2776      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# Line 2156  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2796  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2796   * @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
2797   */   */
2798  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){
2799    return(UpdateRunInfo((TChain*)run,iev));      return(UpdateRunInfo((TChain*)run,iev));
2800  };  };
2801    
2802  //--------------------------------------  //--------------------------------------
# Line 2166  Bool_t PamLevel2::UpdateRunInfo(TTree *r Line 2806  Bool_t PamLevel2::UpdateRunInfo(TTree *r
2806  /**  /**
2807   * Set which trees shoul be analysed   * Set which trees shoul be analysed
2808   * @param detlist TString containing the sequence of trees required   * @param detlist TString containing the sequence of trees required
2809  */   */
2810  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist){
2811                
2812      if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){  //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
2813          CAL0 = false;      if( detlist.Contains("+ALL", TString::kIgnoreCase)){
2814    
2815            cout << " ======================================================== "<<endl;
2816            cout << "                       (( WARNING ))                      "<< endl;
2817            cout << " The meaning of the option +ALL has changed!!             "<<endl;
2818            cout << " Now it includes really all (level0+level1+level2+gpamela)"<<endl;
2819            cout << " and the file is discarded if it does not contain all     "<<endl;
2820            cout << " trees or level0 files are not available!!                "<<endl;
2821            cout << " ======================================================== "<<endl;
2822                
2823            CAL0 = true;
2824          CAL1 = true;          CAL1 = true;
2825          CAL2 = true;          CAL2 = true;
2826          TRK2 = true;          TRK2 = true;
2827          TRK1 = false;          TRK1 = true;
2828          TRKh = false;          TRKh = true;
2829          TRK0 = false;          TRK0 = true;
2830          TRG = true;          TRG = true;
2831          TOF = true;          TOF = true;
2832          TOF0 = false;          TOF0 = true;
2833          S4  = true;          S4  = true;
2834          ND  = true;          ND  = true;
2835          AC  = true;          AC  = true;
2836          ORB = true;          ORB = true;
2837            GP  = true;
2838      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
2839          CAL0 = false;          CAL0 = false;
2840          CAL1 = false;          CAL1 = false;
# Line 2199  void PamLevel2::SetWhichTrees(TString de Line 2850  void PamLevel2::SetWhichTrees(TString de
2850          ND  = false;          ND  = false;
2851          AC  = false;          AC  = false;
2852          ORB = false;          ORB = false;
2853            GP  = false;
2854      };      };
2855            
2856  //  -------------------------------------------------------------------------  //  -------------------------------------------------------------------------
# Line 2272  void PamLevel2::SetWhichTrees(TString de Line 2924  void PamLevel2::SetWhichTrees(TString de
2924      if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;      if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;
2925      else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;      else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;
2926    
2927        if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false;
2928        else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true;
2929    
2930        cout<< "Set detector list from input --> ";
2931        if(TRK0)cout<<"TRK0 ";
2932        if(TRK1)cout<<"TRK1 ";
2933        if(TRK2)cout<<"TRK2 ";
2934        if(TRKh)cout<<"TRKH ";
2935        if(CAL0)cout<<"CAL0 ";
2936        if(CAL1)cout<<"CAL1 ";
2937        if(CAL2)cout<<"CAL2 ";
2938        if(TOF)cout<<"TOF ";
2939        if(TRG)cout<<"TRG ";
2940        if(AC)cout<<"AC ";
2941        if(ND)cout<<"ND ";
2942        if(S4)cout<<"S4 ";
2943        if(ORB)cout<<"ORB ";
2944        if(GP)cout<<"GP ";
2945        cout << endl;
2946  //     cout<< "Set detector list --> ";  //     cout<< "Set detector list --> ";
2947  //     if(TRK1)cout<<"TRK1 ";  //     if(TRK1)cout<<"TRK1 ";
2948  //     if(TRK2)cout<<"TRK2 ";  //     if(TRK2)cout<<"TRK2 ";
2949  //     if(TRKh)cout<<"TRKH ";  //     if(TRKh)cout<<"TRKH ";
2950  //     if(CAL1)cout<<"CAL1 ";  //     if(CAL1)cout<<"CAL1 ";
2951  //     if(CAL2)cout<<"CAL2 ";  //     if(CAL2)cout<<"CAL2 ";
2952    //     if(TOF0)cout<<"TOF0 ";
2953  //     if(TOF)cout<<"TOF ";  //     if(TOF)cout<<"TOF ";
2954  //     if(TRG)cout<<"TRG ";  //     if(TRG)cout<<"TRG ";
2955  //     if(AC)cout<<"AC ";  //     if(AC)cout<<"AC ";
# Line 2296  void  PamLevel2::GetWhichTrees(TFile* f) Line 2968  void  PamLevel2::GetWhichTrees(TFile* f)
2968            
2969    
2970    
2971      cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;  //    cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
2972      // -----------      // -----------
2973      // reset flags      // reset flags
2974      // -----------      // -----------
# Line 2311  void  PamLevel2::GetWhichTrees(TFile* f) Line 2983  void  PamLevel2::GetWhichTrees(TFile* f)
2983      ND     = false;          ND     = false;    
2984      AC     = false;          AC     = false;    
2985      ORB    = false;          ORB    = false;    
2986        GP     = false;    
2987            
2988      RUN    = false;      RUN    = false;
2989                    
# Line 2401  void  PamLevel2::GetWhichTrees(TFile* f) Line 3074  void  PamLevel2::GetWhichTrees(TFile* f)
3074                  TRK2 = false;                  TRK2 = false;
3075                  TRKh = false;                  TRKh = false;
3076              }else nev=nevt;              }else nev=nevt;
3077              T->Delete();  //          T->Delete();
3078          };          };
3079          //=========================================================            //=========================================================  
3080          if( !strcmp(key->GetName(),"Calorimeter"    ) ){          if( !strcmp(key->GetName(),"Calorimeter"    ) ){
# Line 2417  void  PamLevel2::GetWhichTrees(TFile* f) Line 3090  void  PamLevel2::GetWhichTrees(TFile* f)
3090                  CAL1 = false;                  CAL1 = false;
3091                  CAL2 = false;                  CAL2 = false;
3092              }else nev=nevt;              }else nev=nevt;
3093              T->Delete();  //          T->Delete();
3094          };                };      
3095            //=========================================================  
3096            if( !strcmp(key->GetName(),"h20") ){
3097                GP = true;
3098                Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();
3099                if( nev && nevt!=nev){
3100                    cout << "File: "<< f->GetName() <<" h20 tree has "<<nevt<<" events instead of "<<nev<< endl;
3101                    GP = false;
3102                }else nev=nevt;
3103            }
3104    
3105      };      };
3106            
3107      delete lk;  //    delete lk;
3108    
3109  //     cout<< "Get detector list from input file --> ";      cout<< "Get detector list from input file --> ";
3110  //     if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
3111  //     if(TRK2)cout<<"TRK2 ";      if(TRK2)cout<<"TRK2 ";
3112  //     if(TRKh)cout<<"TRKH ";      if(TRKh)cout<<"TRKH ";
3113  //     if(CAL1)cout<<"CAL1 ";      if(CAL1)cout<<"CAL1 ";
3114  //     if(CAL2)cout<<"CAL2 ";      if(CAL2)cout<<"CAL2 ";
3115  //     if(TOF)cout<<"TOF ";      if(TOF)cout<<"TOF ";
3116  //     if(TRG)cout<<"TRG ";      if(TRG)cout<<"TRG ";
3117  //     if(AC)cout<<"AC ";      if(AC)cout<<"AC ";
3118  //     if(ND)cout<<"ND ";      if(ND)cout<<"ND ";
3119  //     if(S4)cout<<"S4 ";      if(S4)cout<<"S4 ";
3120  //     if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
3121  //     cout << endl;      if(GP)cout<<"GP ";
3122        cout << endl;
3123                
3124      return ;      return ;
3125                    
# Line 2465  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3148  Bool_t  PamLevel2::CheckLevel2File(TStri
3148      Bool_t ND__ok     = false;          Bool_t ND__ok     = false;    
3149      Bool_t AC__ok     = false;          Bool_t AC__ok     = false;    
3150      Bool_t ORB__ok    = false;          Bool_t ORB__ok    = false;    
3151        Bool_t GP__ok     = false;    
3152            
3153      Bool_t RUN__ok    = false;      Bool_t RUN__ok    = false;
3154            
# Line 2496  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3180  Bool_t  PamLevel2::CheckLevel2File(TStri
3180  //          return false;  //          return false;
3181  //      };  //      };
3182    
3183            //=========================================================    
3184            // check if the file
3185            
3186    
3187          if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;                if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;      
3188    
# Line 2622  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3309  Bool_t  PamLevel2::CheckLevel2File(TStri
3309              };                  };    
3310              T->Delete();              T->Delete();
3311          };                };      
3312            //=========================================================    
3313            if( !strcmp(key->GetName(),"h20") ){
3314                ISGP = true;    
3315                GP__ok = true;
3316                if(GP){
3317                    Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();
3318                    if( nev && nevt!=nev){
3319                        cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
3320                        return false;
3321                    }
3322                    nev=nevt;
3323                }
3324            }
3325    
3326      };      };
3327    
# Line 2711  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3411  Bool_t  PamLevel2::CheckLevel2File(TStri
3411          cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;          cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;
3412          return false;          return false;
3413      };      };
3414        if(GP && !GP__ok){
3415            cout << "File: "<< f->GetName() <<" discarded ---- Missing h20 tree"<< endl;
3416            return false;
3417        };
3418            
3419    
3420  //    lk->Delete();  //    lk->Delete();
# Line 2729  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3433  Bool_t  PamLevel2::CheckLevel2File(TStri
3433  //     if(ND)cout<<"ND ";  //     if(ND)cout<<"ND ";
3434  //     if(S4)cout<<"S4 ";  //     if(S4)cout<<"S4 ";
3435  //     if(ORB)cout<<"ORB ";  //     if(ORB)cout<<"ORB ";
3436    //     if(GP)cout<<"GP ";
3437  //     cout << endl;  //     cout << endl;
3438                
3439      return true;      return true;
# Line 2810  void PamLevel2::CreateCloneTrees(TFile * Line 3515  void PamLevel2::CreateCloneTrees(TFile *
3515      }      }
3516      cout << "----------------------------------------------------"<<endl;      cout << "----------------------------------------------------"<<endl;
3517    
3518        // ------------------------------------
3519        // add branch with dead and live times
3520        // ------------------------------------
3521        run_tree_clone->Branch("DeadLiveTime",totdltime,"dltime[3]/l");
3522        cout << "Run          : branch DeadLiveTime"<<endl;
3523    
3524    
3525      sel_tree_clone = new TTree("SelectionList","List of selected events ");      sel_tree_clone = new TTree("SelectionList","List of selected events ");
3526    //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
3527      sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");      sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
3528      sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");      sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");
3529            
# Line 2892  void PamLevel2::CreateCloneTrees(TFile * Line 3604  void PamLevel2::CreateCloneTrees(TFile *
3604          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
3605          i++;          i++;
3606      };      };
3607        // GPamela
3608        if(GP) {
3609            pam_tree_clone[i] = new TTree("h20","PAMELA oribital info  ");  
3610            pam_tree_clone[i]->Branch("GPamela","GPamela", GetPointerTo("GPamela"),32000,1);//split
3611            cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
3612            i++;
3613        };
3614      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3615    
3616  }  }
# Line 2936  TTree* PamLevel2::GetCloneTree(TString n Line 3655  TTree* PamLevel2::GetCloneTree(TString n
3655  void PamLevel2::WriteCloneTrees(){  void PamLevel2::WriteCloneTrees(){
3656      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3657      cout << "Write clones of PAMELA trees "<<endl;      cout << "Write clones of PAMELA trees "<<endl;
3658      cout << run_tree_clone->GetName()<<endl;          cout << run_tree_clone->GetName()<<endl;  
3659        if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
3660            run_tree_clone->GetBranch("DeadLiveTime")->Fill();
3661      run_tree_clone->Write();      run_tree_clone->Write();
3662      cout << sel_tree_clone->GetName()<<endl;          cout << sel_tree_clone->GetName()<<endl;    
3663      sel_tree_clone->Write();      sel_tree_clone->Write();
# Line 2980  Int_t PamLevel2::GetEntry(Long64_t iee){ Line 3701  Int_t PamLevel2::GetEntry(Long64_t iee){
3701          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;
3702          return 0;          return 0;
3703      }      }
3704    
3705    //    cout << " gp_obj->P0 "<<gp_obj->P0<<endl;
3706      //      //
3707      // ... 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.
3708      // 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
# Line 3070  TTree* PamLevel2::GetYodaTree( ){ Line 3793  TTree* PamLevel2::GetYodaTree( ){
3793          // open the DB connection          // open the DB connection
3794          // (if not already opened)          // (if not already opened)
3795          //===================================          //===================================
3796          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;  
         }  
3797          GL_ROOT glroot = GL_ROOT();          GL_ROOT glroot = GL_ROOT();
3798          if( glroot.Query_GL_ROOT(iroot,dbc) ){          if( glroot.Query_GL_ROOT(iroot,dbc) ){
3799              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 3131  TTree* PamLevel2::GetYodaTree( ){ Line 3841  TTree* PamLevel2::GetYodaTree( ){
3841              cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;              cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
3842          }          }
3843    
3844            dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
3845    
3846    
3847      };      };
3848    
3849      if(!dbc || (dbc && !dbc->IsConnected())){  //     if(!dbc || (dbc && !dbc->IsConnected())){
3850          cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;  //      cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;
3851      }  //     }
3852    
3853      if ( TRK0 ){      if ( TRK0 ){
3854          TrkParams::Load(6);          TrkParams::Load(6);
3855          if( !TrkParams::IsLoaded(6) ){          if( !TrkParams::IsLoaded(6) ){
3856              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;
3857          };          };
3858            if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
3859          TrkParams::SetCalib(run_obj,dbc);          TrkParams::SetCalib(run_obj,dbc);
3860          TrkParams::LoadCalib( );          TrkParams::LoadCalib( );
3861          if( !TrkParams::CalibIsLoaded() ){          if( !TrkParams::CalibIsLoaded() ){
3862              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;
3863          };          };
3864            dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
3865      }      }
3866    
3867    
3868  //    cout << l0_tree << endl;  //    cout << l0_tree << endl;
       
3869      return l0_tree;      return l0_tree;
3870    
3871  }  }
# Line 3178  Int_t PamLevel2::GetYodaEntry(){ Line 3893  Int_t PamLevel2::GetYodaEntry(){
3893    
3894  //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;  //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
3895  //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;  //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
3896  //     cout << " time "<< GetOrbitalInfo()->absTime << endl;  //     cout << " time "<< abstime << endl;
3897  //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;  //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;
3898            
3899      if( !GetOrbitalInfo() ){      ULong64_t obt     = 0;
3900        ULong64_t pktn    = 0;
3901        if( GetOrbitalInfo() ){
3902            obt     = GetOrbitalInfo()->OBT;
3903            pktn    = GetOrbitalInfo()->pkt_num;
3904        }
3905    
3906        if( !GetOrbitalInfo() && !ISGP){
3907          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;
3908          return 0;          return 0;
3909      }      }
3910      if( GetOrbitalInfo()->OBT==0 && GetOrbitalInfo()->pkt_num==0 ){      if( obt==0 && pktn==0 && !ISGP ){
3911          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl;          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl;
3912          return 0;          return 0;
3913      }      }
# Line 3204  Int_t PamLevel2::GetYodaEntry(){ Line 3926  Int_t PamLevel2::GetYodaEntry(){
3926      Int_t answer = 0;      Int_t answer = 0;
3927      Int_t shift =0;      Int_t shift =0;
3928      //    printf(" siamo qui %i %i \n",shift,prevshift);      //    printf(" siamo qui %i %i \n",shift,prevshift);
3929      Int_t maxshift = 10;      //    Int_t maxshift = 50; // EMILIANO
3930      do{      do{
3931          if(shift>0){              if(shift>0){    
3932              cout << " PKTNUM  L2 --- "<< GetOrbitalInfo()->pkt_num << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;              cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
3933              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;              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;
3934              cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;              cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;
3935          }          }
# Line 3217  Int_t PamLevel2::GetYodaEntry(){ Line 3939  Int_t PamLevel2::GetYodaEntry(){
3939              cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;              cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;
3940              return 0;              return 0;
3941          }          }
3942  //      cout << "PKTNUM "<<shift<<" ==  L2 --- "<< GetOrbitalInfo()->pkt_num << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;  
3943  //      cout << " L2 --- "<< GetOrbitalInfo()->OBT << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;          if(ISGP){
3944                obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO
3945                pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO
3946            }
3947    
3948    //      cout << "PKTNUM "<<shift<<" ==  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
3949    //      cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;
3950  //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;  //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;
3951  //      cout << " GetOrbitalInfo()->OBT "<< GetOrbitalInfo()->OBT << endl;  //      cout << " obt "<< obt << endl;
3952  //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;  //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;
3953  //      cout << " GetOrbitalInfo()->pkt_num "<< GetOrbitalInfo()->pkt_num << endl;  //      cout << " pktn "<< pktn << endl;
3954  //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;  //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
3955  //      printf(" IDRUN %u \n",GetRunInfo()->ID);  //      printf(" IDRUN %u \n",GetRunInfo()->ID);
3956  //  //
3957          if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){          if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){
3958            prevshift = 0;              prevshift = 0;
3959            shift = -1;              shift = -1;
3960          };          };
3961    
3962      }while( ( GetOrbitalInfo()->OBT != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || GetOrbitalInfo()->pkt_num != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||
3963                  pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())       )
3964                && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);
3965    
3966      if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {      if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {
3967          cout << " Big trouble here, no such event in Level0 data! " <<endl;          cout << " Big trouble here, no such event in Level0 data! " <<endl;
# Line 3257  Bool_t PamLevel2::SetDBConnection(){ Line 3987  Bool_t PamLevel2::SetDBConnection(){
3987      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
3988      if( !dbc )return false;      if( !dbc )return false;
3989      if( !dbc->IsConnected() )return false;          if( !dbc->IsConnected() )return false;    
3990        stringstream myquery;  // EMILIANO
3991        myquery.str("");  // EMILIANO
3992        myquery << "SET time_zone='+0:00'";  // EMILIANO
3993        dbc->Query(myquery.str().c_str());  // EMILIANO
3994      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3995      return true;      return true;
3996    
3997  }  }
3998    
3999    /**
4000     * \Brief Add a friend to the pamela chain.
4001     * @param cname name of the chain to be added
4002     */
4003    
4004    TChain* PamLevel2::AddFriend(TString cname){
4005    
4006        if(!GetPamTree()){
4007            cout << " TChain* PamLevel2::AddFriend(TString cname) --- a pamela tree must be created first"<<endl;
4008            return NULL;
4009        }
4010    
4011    
4012        TChain *c = new TChain( cname.Data() );
4013    
4014        TIter next( GetPamTree()->GetListOfFiles() );
4015        Int_t nf = 0;
4016        TChainElement* element = 0;    
4017        while ((element = (TChainElement*) next())) {      
4018            c->Add(element->GetTitle());
4019            nf++;
4020        }
4021    
4022        GetPamTree()->AddFriend(cname.Data());
4023    
4024        cout << "external chain created and added to pamela friends :"<<cname<<endl;
4025        cout << "n.files "<<nf<<endl;
4026        
4027    
4028        return c;    
4029    
4030    }
4031    
4032    

Legend:
Removed from v.1.42  
changed lines
  Added in v.1.55

  ViewVC Help
Powered by ViewVC 1.1.23