/[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.48 by mocchiut, Wed Sep 12 09:51:57 2007 UTC revision 1.62 by pam-fi, Mon Sep 29 10:20:26 2008 UTC
# Line 1  Line 1 
1  #include <PamLevel2.h>  #include <PamLevel2.h>
2    
3    
4    
5    /////////////////////////////////////////////////////////////////////////////
6    /////////////////////////////////////////////////////////////////////////////
7    /////////////////////////////////////////////////////////////////////////////
8    /////////////////////////////////////////////////////////////////////////////
9    
10    void GPamela::Clear(){
11        Irun   = 0;
12        Ievnt  = 0;
13        Ipa    = 0;
14        X0     = 0.;
15        Y0     = 0.;
16        Z0     = 0.;
17        Theta  = 0.;
18        Phi    = 0.;
19        P0     = 0.;
20        Nthtof  = 0;
21        Nthcat  = 0;
22        Nthcas  = 0;
23        Nthspe  = 0;
24        Nstrpx  = 0;
25        Nstrpy  = 0;
26        Nthcali = 0;
27        Nthcal  = 0;
28        Nthnd   = 0;
29        Nthcard = 0;
30    }
31    
32    void GPamela::Delete(){
33    
34        Clear();
35    
36        delete []    Ipltof;  
37        delete []    Ipaddle;
38        delete []    Ipartof;
39        delete []    Xintof;  
40        delete []    Yintof;  
41        delete []    Zintof;  
42        delete []    Xouttof;
43        delete []    Youttof;
44        delete []    Zouttof;
45        delete []    Ereltof;
46        delete []    Timetof;
47        delete []    Pathtof;
48        delete []    P0tof;  
49        delete []    Iparcat;
50        delete []    Icat;  
51        delete []    Xincat;  
52        delete []    Yincat;  
53        delete []    Zincat;  
54        delete []    Xoutcat;
55        delete []    Youtcat;
56        delete []    Zoutcat;
57        delete []    Erelcat;
58        delete []    Timecat;
59        delete []    Pathcat;
60        delete []    P0cat;  
61        delete []    Iparcas;
62        delete []    Icas;  
63        delete []    Xincas;  
64        delete []    Yincas;  
65        delete []    Zincas;  
66        delete []    Xoutcas;
67        delete []    Youtcas;
68        delete []    Zoutcas;
69        delete []    Erelcas;
70        delete []    Timecas;
71        delete []    Pathcas;
72        delete []    P0cas;  
73        delete []    Iparspe;
74        delete []    Itrpb;  
75        delete []    Itrsl;  
76        delete []    Itspa;  
77        delete []    Xinspe;  
78        delete []    Yinspe;  
79        delete []    Zinspe;  
80        delete []    Xoutspe;
81        delete []    Youtspe;
82        delete []    Zoutspe;
83        delete []    Xavspe;  
84        delete []    Yavspe;  
85        delete []    Zavspe;  
86        delete []    Erelspe;
87        delete []    Pathspe;
88        delete []    P0spe;  
89        delete []    Nxmult;  
90        delete []    Nymult;  
91        delete []    Npstripx;
92        delete []    Ntstripx;
93        delete []    Istripx;
94        delete []    Qstripx;
95        delete []    Xstripx;
96        delete []    Npstripy;
97        delete []    Ntstripy;
98        delete []    Istripy;
99        delete []    Qstripy;
100        delete []    Ystripy;
101        delete []    Icaplane;
102        delete []    Icastrip;
103        delete []    Icamod;  
104        delete []    Enestrip;
105        delete []    Icapl;  
106        delete []    Icasi;  
107        delete []    Icast;  
108        delete []    Xincal;  
109        delete []    Yincal;  
110        delete []    Zincal;  
111        delete []    Erelcal;
112        delete []    Itubend;
113        delete []    Iparnd;  
114        delete []    Xinnd;  
115        delete []    Yinnd;  
116        delete []    Zinnd;  
117        delete []    Xoutnd;  
118        delete []    Youtnd;  
119        delete []    Zoutnd;  
120        delete []    Erelnd;  
121        delete []    Timend;  
122        delete []    Pathnd;  
123        delete []    P0nd;  
124        delete []    Iparcard;
125        delete []    Icard;  
126        delete []    Xincard;
127        delete []    Yincard;
128        delete []    Zincard;
129        delete []    Xoutcard;
130        delete []    Youtcard;
131        delete []    Zoutcard;
132        delete []    Erelcard;
133        delete []    Timecard;
134        delete []    Pathcard;
135        delete []    P0card;  
136    
137    
138    };
139    
140    
141    
142    void GPamela::SetBranchAddress( TChain* fhBookTree ){
143    
144    //    cout << "fhBookTree "<<fhBookTree << endl;
145        // prepare tree
146        fhBookTree->SetBranchAddress("Irun",&Irun);
147        fhBookTree->SetBranchAddress("Ievnt",&Ievnt);
148        fhBookTree->SetBranchAddress("Ipa",&Ipa);
149        fhBookTree->SetBranchAddress("X0",&X0);
150        fhBookTree->SetBranchAddress("Y0",&Y0);
151        fhBookTree->SetBranchAddress("Z0",&Z0);
152        fhBookTree->SetBranchAddress("Theta",&Theta);
153        fhBookTree->SetBranchAddress("Phi",&Phi);
154        fhBookTree->SetBranchAddress("P0",&P0);
155        fhBookTree->SetBranchAddress("Nthtof",&Nthtof);
156        fhBookTree->SetBranchAddress("Ipltof",Ipltof);
157        fhBookTree->SetBranchAddress("Ipaddle",Ipaddle);
158        fhBookTree->SetBranchAddress("Ipartof",Ipartof);
159        fhBookTree->SetBranchAddress("Xintof",Xintof);
160        fhBookTree->SetBranchAddress("Yintof",Yintof);
161        fhBookTree->SetBranchAddress("Zintof",Zintof);
162        fhBookTree->SetBranchAddress("Xouttof",Xouttof);
163        fhBookTree->SetBranchAddress("Youttof",Youttof);
164        fhBookTree->SetBranchAddress("Zouttof",Zouttof);
165        fhBookTree->SetBranchAddress("Ereltof",Ereltof);
166        fhBookTree->SetBranchAddress("Timetof",Timetof);
167        fhBookTree->SetBranchAddress("Pathtof",Pathtof);
168        fhBookTree->SetBranchAddress("P0tof",P0tof);
169        fhBookTree->SetBranchAddress("Nthcat",&Nthcat);
170        fhBookTree->SetBranchAddress("Iparcat",Iparcat);
171        fhBookTree->SetBranchAddress("Icat",Icat);
172        fhBookTree->SetBranchAddress("Xincat",Xincat);
173        fhBookTree->SetBranchAddress("Yincat",Yincat);
174        fhBookTree->SetBranchAddress("Zincat",Zincat);
175        fhBookTree->SetBranchAddress("Xoutcat",Xoutcat);
176        fhBookTree->SetBranchAddress("Youtcat",Youtcat);
177        fhBookTree->SetBranchAddress("Zoutcat",Zoutcat);
178        fhBookTree->SetBranchAddress("Erelcat",Erelcat);
179        fhBookTree->SetBranchAddress("Timecat",Timecat);
180        fhBookTree->SetBranchAddress("Pathcat",Pathcat);
181        fhBookTree->SetBranchAddress("P0cat",P0cat);
182        fhBookTree->SetBranchAddress("Nthcas",&Nthcas);
183        fhBookTree->SetBranchAddress("Iparcas",Iparcas);
184        fhBookTree->SetBranchAddress("Icas",Icas);
185        fhBookTree->SetBranchAddress("Xincas",Xincas);
186        fhBookTree->SetBranchAddress("Yincas",Yincas);
187        fhBookTree->SetBranchAddress("Zincas",Zincas);
188        fhBookTree->SetBranchAddress("Xoutcas",Xoutcas);
189        fhBookTree->SetBranchAddress("Youtcas",Youtcas);
190        fhBookTree->SetBranchAddress("Zoutcas",Zoutcas);
191        fhBookTree->SetBranchAddress("Erelcas",Erelcas);
192        fhBookTree->SetBranchAddress("Timecas",Timecas);
193        fhBookTree->SetBranchAddress("Pathcas",Pathcas);
194        fhBookTree->SetBranchAddress("P0cas",P0cas);
195        fhBookTree->SetBranchAddress("Nthspe",&Nthspe);
196        fhBookTree->SetBranchAddress("Iparspe",Iparspe);
197        fhBookTree->SetBranchAddress("Itrpb",Itrpb);
198        fhBookTree->SetBranchAddress("Itrsl",Itrsl);
199        fhBookTree->SetBranchAddress("Itspa",Itspa);
200        fhBookTree->SetBranchAddress("Xinspe",Xinspe);
201        fhBookTree->SetBranchAddress("Yinspe",Yinspe);
202        fhBookTree->SetBranchAddress("Zinspe",Zinspe);
203        fhBookTree->SetBranchAddress("Xoutspe",Xoutspe);
204        fhBookTree->SetBranchAddress("Youtspe",Youtspe);
205        fhBookTree->SetBranchAddress("Zoutspe",Zoutspe);
206        fhBookTree->SetBranchAddress("Xavspe",Xavspe);
207        fhBookTree->SetBranchAddress("Yavspe",Yavspe);
208        fhBookTree->SetBranchAddress("Zavspe",Zavspe);
209        fhBookTree->SetBranchAddress("Erelspe",Erelspe);
210        fhBookTree->SetBranchAddress("Pathspe",Pathspe);
211        fhBookTree->SetBranchAddress("P0spe",P0spe);
212        fhBookTree->SetBranchAddress("Nxmult",Nxmult);
213        fhBookTree->SetBranchAddress("Nymult",Nymult);
214        fhBookTree->SetBranchAddress("Nstrpx",&Nstrpx);
215        fhBookTree->SetBranchAddress("Npstripx",Npstripx);
216        fhBookTree->SetBranchAddress("Ntstripx",Ntstripx);
217        fhBookTree->SetBranchAddress("Istripx",Istripx);
218        fhBookTree->SetBranchAddress("Qstripx",Qstripx);
219        fhBookTree->SetBranchAddress("Xstripx",Xstripx);
220        fhBookTree->SetBranchAddress("Nstrpy",&Nstrpy);
221        fhBookTree->SetBranchAddress("Npstripy",Npstripy);
222        fhBookTree->SetBranchAddress("Ntstripy",Ntstripy);
223        fhBookTree->SetBranchAddress("Istripy",Istripy);
224        fhBookTree->SetBranchAddress("Qstripy",Qstripy);
225        fhBookTree->SetBranchAddress("Ystripy",Ystripy);
226        fhBookTree->SetBranchAddress("Nthcali",&Nthcali);
227        fhBookTree->SetBranchAddress("Icaplane",Icaplane);
228        fhBookTree->SetBranchAddress("Icastrip",Icastrip);
229        fhBookTree->SetBranchAddress("Icamod",Icamod);
230        fhBookTree->SetBranchAddress("Enestrip",Enestrip);
231        fhBookTree->SetBranchAddress("Nthcal",&Nthcal);
232        fhBookTree->SetBranchAddress("Icapl",Icapl);
233        fhBookTree->SetBranchAddress("Icasi",Icasi);
234        fhBookTree->SetBranchAddress("Icast",Icast);
235        fhBookTree->SetBranchAddress("Xincal",Xincal);
236        fhBookTree->SetBranchAddress("Yincal",Yincal);
237        fhBookTree->SetBranchAddress("Zincal",Zincal);
238        fhBookTree->SetBranchAddress("Erelcal",Erelcal);
239        fhBookTree->SetBranchAddress("Nthnd",&Nthnd);
240        fhBookTree->SetBranchAddress("Itubend",Itubend);
241        fhBookTree->SetBranchAddress("Iparnd",Iparnd);
242        fhBookTree->SetBranchAddress("Xinnd",Xinnd);
243        fhBookTree->SetBranchAddress("Yinnd",Yinnd);
244        fhBookTree->SetBranchAddress("Zinnd",Zinnd);
245        fhBookTree->SetBranchAddress("Xoutnd",Xoutnd);
246        fhBookTree->SetBranchAddress("Youtnd",Youtnd);
247        fhBookTree->SetBranchAddress("Zoutnd",Zoutnd);
248        fhBookTree->SetBranchAddress("Erelnd",Erelnd);
249        fhBookTree->SetBranchAddress("Timend",Timend);
250        fhBookTree->SetBranchAddress("Pathnd",Pathnd);
251        fhBookTree->SetBranchAddress("P0nd",P0nd);
252        fhBookTree->SetBranchAddress("Nthcard",&Nthcard);
253        fhBookTree->SetBranchAddress("Iparcard",Iparcard);
254        fhBookTree->SetBranchAddress("Icard",Icard);
255        fhBookTree->SetBranchAddress("Xincard",Xincard);
256        fhBookTree->SetBranchAddress("Yincard",Yincard);
257        fhBookTree->SetBranchAddress("Zincard",Zincard);
258        fhBookTree->SetBranchAddress("Xoutcard",Xoutcard);
259        fhBookTree->SetBranchAddress("Youtcard",Youtcard);
260        fhBookTree->SetBranchAddress("Zoutcard",Zoutcard);
261        fhBookTree->SetBranchAddress("Erelcard",Erelcard);
262        fhBookTree->SetBranchAddress("Timecard",Timecard);
263        fhBookTree->SetBranchAddress("Pathcard",Pathcard);
264        fhBookTree->SetBranchAddress("P0card",P0card);
265    
266    //    fhBookTree->SetBranchStatus("*",0);
267    
268    }
269    
270    ClassImp(GPamela);
271    
272    /////////////////////////////////////////////////////////////////////////////
273    /////////////////////////////////////////////////////////////////////////////
274    /////////////////////////////////////////////////////////////////////////////
275    /////////////////////////////////////////////////////////////////////////////
276  //--------------------------------------  //--------------------------------------
277  //  //
278  //  //
# Line 93  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);      TList*  listf = GetListOfLevel2Files(ddir,list);
390    GetRunTree(GetListOfLevel2Files(ddir,list));      GetPamTree(listf,detlist);
391        GetRunTree(listf);
392  };  };
393    
394  /**  /**
395   * Constructor with given dir and list   * Constructor
396     * @param ddir Name of directory where level2 files are stored.
397     * @param list Name of an ascii file containing the list of file names
398     * Default trees/branches are loaded. Default is:
399     * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
400   */   */
401  PamLevel2::PamLevel2(TString ddir,TString list){  PamLevel2::PamLevel2(TString ddir,TString list){
402    Initialize();      Initialize();
403    GetPamTree(GetListOfLevel2Files(ddir,list),"");      TList*  listf = GetListOfLevel2Files(ddir,list);
404    GetRunTree(GetListOfLevel2Files(ddir,list));      GetPamTree(listf,"");
405        GetRunTree(listf);
406  };  };
407    
408    
# Line 132  void PamLevel2::Initialize(){ Line 423  void PamLevel2::Initialize(){
423      nd_obj    = 0;      nd_obj    = 0;
424      ac_obj    = 0;      ac_obj    = 0;
425      orb_obj   = 0;      orb_obj   = 0;
426        gp_obj    = 0;
427    
428      run_obj   = 0;//new GL_RUN();      run_obj   = 0;//new GL_RUN();
429      soft_obj   = 0;// Emiliano      soft_obj   = 0;// Emiliano
430      irun = -1LL;      irun = -1LL;
431        irunt = -1LL;
432      runfirstentry = 0LL;      runfirstentry = 0LL;
433      runlastentry = 0LL;      runlastentry = 0LL;
434    
# Line 145  void PamLevel2::Initialize(){ Line 438  void PamLevel2::Initialize(){
438      dbc     = 0;      dbc     = 0;
439    
440      prevshift = 0;      prevshift = 0;
441        maxshift = 10; //EMILIANO
442            
443      run_tree = NULL;      run_tree = NULL;
444      run_tree_clone = NULL;      run_tree_clone = NULL;
# Line 157  void PamLevel2::Initialize(){ Line 451  void PamLevel2::Initialize(){
451    
452      totdltime[0] = 0LL;      totdltime[0] = 0LL;
453      totdltime[1] = 0LL;      totdltime[1] = 0LL;
454        totdltime[2] = 0LL;
455    
456      host = "mysql://localhost/pamelaprod";      host = "mysql://localhost/pamelaprod";
457      user = "anonymous";      user = "anonymous";
# Line 180  void PamLevel2::Initialize(){ Line 475  void PamLevel2::Initialize(){
475      CAL2 = true;      CAL2 = true;
476      TRK2 = true;      TRK2 = true;
477      TRK1 = false;      TRK1 = false;
478      TRKh = false;      TRK0 = false;
479      TRKh = false;      TRKh = false;
480      TRG  = true;      TRG  = true;
481      TOF  = true;      TOF  = true;
# Line 188  void PamLevel2::Initialize(){ Line 483  void PamLevel2::Initialize(){
483      S4   = true;      S4   = true;
484      ND   = true;      ND   = true;
485      AC   = true;      AC   = true;
486      ORB  = true;      ORB  = true;    
487            GP   = false;
488    
489      RUN  = true;      RUN  = true;
490    
491      SELLI = -1;      SELLI = -1;
492    
493      ISGP = false;      ISGP = false;
494    
495        DBG = false;
496    
497      tsorted=0;      tsorted=0;
498      timage=0;      timage=0;
499            
# Line 227  void PamLevel2::Delete(){ Line 525  void PamLevel2::Delete(){
525      if(nd_obj)   delete nd_obj;      if(nd_obj)   delete nd_obj;
526      if(ac_obj)   delete ac_obj;      if(ac_obj)   delete ac_obj;
527      if(orb_obj)  delete orb_obj;      if(orb_obj)  delete orb_obj;
528        if(gp_obj)   delete gp_obj;
529            
530      if(tsorted){      if(tsorted){
531          tsorted->Delete();          tsorted->Delete();
# Line 245  void PamLevel2::Delete(){ Line 544  void PamLevel2::Delete(){
544      if(l0_file)l0_file->Close();      if(l0_file)l0_file->Close();
545      //    if(pam_tree)pam_tree->Delete();;      //    if(pam_tree)pam_tree->Delete();;
546    
547    if ( pam_tree ){      if ( pam_tree ){
548      //          //
549      // 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...
550      //          //
551      TList *temp = pam_tree->GetListOfFriends();          TList *temp = pam_tree->GetListOfFriends();
552      TList *contents  = new TList; // create chain friend list          TList *contents  = new TList; // create chain friend list
553      contents->SetOwner();          contents->SetOwner();
554      TIter next(temp);          TIter next(temp);
555      TChain *questo = 0;          TChain *questo = 0;
556      while ( (questo = (TChain*) next()) ){          while ( (questo = (TChain*) next()) ){
557        TString name =  questo->GetName();              TString name =  questo->GetName();
558        contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list              contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
559      };          };
560      //          //
561      // deleting the main chain          // deleting the main chain
562      //          //
563      pam_tree->Delete();          pam_tree->Delete();
564      //          //
565      // deleting the friends...          // deleting the friends...
566      //          //
567      TIter next2(contents);          TIter next2(contents);
568      TChain *questa = 0;          TChain *questa = 0;
569      while ( questa = (TChain*)next2() ){          while ( questa = (TChain*)next2() ){
570        TString name =  questa->GetName();              TString name =  questa->GetName();
571        questa->Delete();                    questa->Delete();      
572        questa=NULL;              questa=NULL;
573            };
574            //
575      };      };
576      //      pam_tree = NULL;
   };  
   pam_tree = NULL;  
577    
578      if(run_tree)run_tree->Delete();;      if(run_tree)run_tree->Delete();;
579      if(sel_tree)sel_tree->Delete();;      if(sel_tree)sel_tree->Delete();;
# Line 282  void PamLevel2::Delete(){ Line 581  void PamLevel2::Delete(){
581      if(run_tree_clone)run_tree_clone->Delete();;      if(run_tree_clone)run_tree_clone->Delete();;
582      if(sel_tree_clone)sel_tree_clone->Delete();;      if(sel_tree_clone)sel_tree_clone->Delete();;
583            
584        if(irunoffset) delete [] irunoffset;
585    
586  };  };
587    
# Line 314  void PamLevel2::Clear(){ Line 614  void PamLevel2::Clear(){
614      if(nd_obj)   nd_obj->Clear();      if(nd_obj)   nd_obj->Clear();
615      if(ac_obj)   ac_obj->Clear();      if(ac_obj)   ac_obj->Clear();
616      if(orb_obj)  orb_obj->Clear();      if(orb_obj)  orb_obj->Clear();
617        if(gp_obj)   gp_obj->Clear();
618            
619  //    if(sorted_tracks)sorted_tracks->Clear();  //    if(sorted_tracks)sorted_tracks->Clear();
620  //    sorted_tracks.Clear();  //    sorted_tracks.Clear();
# Line 327  void PamLevel2::Clear(){ Line 628  void PamLevel2::Clear(){
628  };  };
629    
630  void PamLevel2::Reset(){  void PamLevel2::Reset(){
   //  
   // First of all clear everything  
   //  
   Clear();  
   //  
   // close and reset chains and pointers  
   //      
   if ( pam_tree ){  
631      //      //
632      // 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
633        //
634        Clear();
635        //
636        // close and reset chains and pointers
637        //    
638        if ( pam_tree ){
639            //
640            // 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...
641            //
642            TList *temp = pam_tree->GetListOfFriends();
643            TList *contents  = new TList; // create chain friend list
644            contents->SetOwner();
645            TIter next(temp);
646            TChain *questo = 0;
647            while ( (questo = (TChain*) next()) ){
648                TString name =  questo->GetName();
649                contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list
650            };
651            //
652            // deleting the main chain
653            //
654            pam_tree->Delete();
655            //
656            // deleting the friends...
657            //
658            TIter next2(contents);
659            TChain *questa = 0;
660            while ( questa = (TChain*)next2() ){
661                TString name =  questa->GetName();
662                questa->Delete();      
663                questa=NULL;
664            };
665            //
666        };
667        pam_tree = NULL;
668        //
669        if(run_tree)run_tree->Delete();;
670        run_tree = NULL;
671        if(sel_tree)sel_tree->Delete();;
672        sel_tree = NULL;
673        //
674        // Close file
675        //
676        if(l0_file)l0_file->Close("R");
677        l0_file = NULL;
678        //
679        h0_obj    = 0;
680        trk0_obj  = 0;
681        calo0_obj  = 0;
682        //
683        trk2_obj  = 0;
684        trk1_obj  = 0;
685        trkh_obj  = 0;
686        calo1_obj = 0;
687        calo2_obj = 0;
688        tof_obj   = 0;
689        trig_obj  = 0;
690        s4_obj    = 0;
691        nd_obj    = 0;
692        ac_obj    = 0;
693        orb_obj   = 0;
694        gp_obj    = 0;
695        //
696        // Reset run pointers
697        //
698        run_obj   = 0;//new GL_RUN();
699        soft_obj   = 0;// Emiliano
700        irun = -1;
701        irunt = -1;
702        runfirstentry = 0ULL;
703        runlastentry = 0ULL;    
704        //
705        totdltime[0] = 0LL;
706        totdltime[1] = 0LL;
707        totdltime[2] = 0LL;
708      //      //
     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;      
   //  
   totdltime[0] = 0LL;  
   totdltime[1] = 0LL;  
   //  
709  };  };
710    
711  Bool_t PamLevel2::IsGood(){  Bool_t PamLevel2::IsGood(){
712    Bool_t goodev=true;      Bool_t goodev=true;
713    //  if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;      //  if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;
714    if(calo2_obj && calo2_obj->good != 1) goodev = false;      if(calo2_obj && calo2_obj->good != 1) goodev = false;
715    if(tof_obj && tof_obj->unpackError != 0) goodev = false;        if(tof_obj && tof_obj->unpackError != 0) goodev = false;  
716    if(trig_obj && trig_obj->unpackError != 0) goodev = false;      if(trig_obj && trig_obj->unpackError != 0) goodev = false;
717    if(s4_obj && s4_obj->unpackError != 0) goodev = false;        if(s4_obj && s4_obj->unpackError != 0) goodev = false;  
718    if(nd_obj && nd_obj->unpackError != 0) goodev = false;        if(nd_obj && nd_obj->unpackError != 0) goodev = false;  
719    if(ac_obj && ac_obj->unpackError != 255) goodev = false;        if(ac_obj && ac_obj->unpackError != 255) goodev = false;  
720      //  if(orb_obj)        //  if(orb_obj)  
721    return goodev;      return goodev;
722  };  };
723    
724  //--------------------------------------  //--------------------------------------
# Line 481  void *PamLevel2::GetPointerTo(const char Line 785  void *PamLevel2::GetPointerTo(const char
785          if(!orb_obj)   orb_obj   = new OrbitalInfo();          if(!orb_obj)   orb_obj   = new OrbitalInfo();
786          return &orb_obj;          return &orb_obj;
787      };      };
788        if(!objname.CompareTo("GPamela")){
789            if(!gp_obj)   gp_obj   = new GPamela();
790            return &gp_obj;
791        };
792            
793      if(!objname.CompareTo("RunInfo"))return &run_obj;      if(!objname.CompareTo("RunInfo"))return &run_obj;
794    
# Line 496  void *PamLevel2::GetPointerTo(const char Line 804  void *PamLevel2::GetPointerTo(const char
804   * Retrieves the calorimeter track matching the seqno-th tracker stored track.   * Retrieves the calorimeter track matching the seqno-th tracker stored track.
805   * (If seqno = -1 retrieves the self-trigger calorimeter track)   * (If seqno = -1 retrieves the self-trigger calorimeter track)
806   */   */
807   CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){  CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
808            
809       if( !calo2_obj )return 0;      if( !calo2_obj )return 0;
810    
811       if( calo2_obj->CaloLevel2::ntrk()==0 ){      if( calo2_obj->CaloLevel2::ntrk()==0 ){
812           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;
813           return NULL;          return NULL;
814       };      };
815            
816       CaloTrkVar *c = 0;      CaloTrkVar *c = 0;
817       Int_t it_calo=0;      Int_t it_calo=0;
818            
819       do{      do{
820           c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);          c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
821           it_calo++;          it_calo++;
822       } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());          } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());    
823            
824       if(!c || seqno != c->trkseqno){      if(!c || seqno != c->trkseqno){
825           c = 0;          c = 0;
826           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;
827       };      };
828       return c;      return c;
829            
830   };  };
831  //--------------------------------------  //--------------------------------------
832   //  //
833   //  //
834  //--------------------------------------  //--------------------------------------
835  /**  /**
836    * Retrieves the ToF track matching the seqno-th tracker stored track.   * Retrieves the ToF track matching the seqno-th tracker stored track.
837    * (If seqno = -1 retrieves the tracker-independent tof track)   * (If seqno = -1 retrieves the tracker-independent tof track)
838   */   */
839   ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
840                    
841       if( !tof_obj )return 0;      if( !tof_obj )return 0;
842    
843       if( tof_obj->ToFLevel2::ntrk()==0 ){      if( tof_obj->ToFLevel2::ntrk()==0 ){
844           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;
845           return NULL;          return NULL;
846       };      };
847            
848       ToFTrkVar *c = 0;      ToFTrkVar *c = 0;
849       Int_t it_tof=0;      Int_t it_tof=0;
850            
851       do{      do{
852           c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);          c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);
853           it_tof++;          it_tof++;
854       } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());              } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());
855            
856       if(!c || seqno != c->trkseqno){      if(!c || seqno != c->trkseqno){
857           c = 0;          c = 0;
858           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;
859       };      };
860       return c;      return c;
861            
862   };  };
863    
864  //--------------------------------------  //--------------------------------------
865   //  //
866   //  //
867  //--------------------------------------  //--------------------------------------
868  /**  /**
869   * 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.
870   */   */
871   PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){  PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
872            
873       cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;      cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;
874       cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;      cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;
875    
876       CaloTrkVar *c = 0;      CaloTrkVar *c = 0;
877       ToFTrkVar  *o = 0;      ToFTrkVar  *o = 0;
878            
879       if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());      if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());
880       if(TOF) o = GetToFStoredTrack(t->GetSeqNo());      if(TOF) o = GetToFStoredTrack(t->GetSeqNo());
881            
882  //    if(t && c && o)track = new PamTrack(t,c,o);  //    if(t && c && o)track = new PamTrack(t,c,o);
883       PamTrack *track = new PamTrack(t,c,o);      PamTrack *track = new PamTrack(t,c,o);
884            
885       return track;      return track;
886    
887   };  };
888  //--------------------------------------  //--------------------------------------
889  //  //
890  //  //
# Line 612  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 920  PamTrack* PamLevel2::GetStoredTrack(Int_
920  //  //
921    
922  /**  /**
923   * 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.
924   **/   **/
925  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(TString how){
926    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());
927    howtosort = how;        howtosort = how;  
928    SortTracks();      SortTracks();
929  };  };
930    
931  //  //
932  //--------------------------------------  //--------------------------------------
933  /**  /**
934   * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is  PamLevel2::sorted_tracks.   * Sort physical (tracker) tracks.
935   * @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...).
936   * Sorting cryteria:   * Sorting cryteria:
937   * TRK: lower chi**2   * TRK: lower chi**2
938   * CAL: lower Y spatial residual on the first calorimeter plane   * CAL: lower Y spatial residual on the first calorimeter plane
939   * 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).
940     * S1: (ask Emiliano)
941     * S2: (ask Emiliano)
942     * S3: (ask Emiliano)
943     * GP: more GP hits
944   * The default sorting cryterium is "TOF+CAL".   * The default sorting cryterium is "TOF+CAL".
945   *   *
946   * 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).
947   */   */
948  void PamLevel2::SortTracks(){  void PamLevel2::SortTracks(){
949    TString how = howtosort;      TString how = howtosort;
950    
951        //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;
952        if( !trk2_obj ){
953            cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";
954            return;
955        };
956        //Save current Object count
957        Int_t ObjectNumber = TProcessID::GetObjectCount();
958    
959    //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;      // create TCloneArrays to store tracks and its images
960    if( !trk2_obj ){      if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
961      cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";      tsorted->Delete();
962      return;      TClonesArray &ttsorted = *tsorted;
963    };  
964    //    cout << "call SortTracs() "<<endl;      if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());
965    //Save current Object count      timage->Delete();
966    Int_t ObjectNumber = TProcessID::GetObjectCount();      TClonesArray &ttimage = *timage;
   
   //    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;  
967    
968    
969    
970    //--------------------------------------------------      //--------------------------------------------------
971    // retrieve sorting method      // retrieve sorting method
972    //--------------------------------------------------      //--------------------------------------------------
973    Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
974    Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
975    Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
976    Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);      Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
977    Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);      Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
978    Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);      Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
979        Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
980        
981    if ( use_TOF ){      if ( use_TOF ){
982      use_S1 = true;          use_S1 = true;
983      use_S2 = true;          use_S2 = true;
984      use_S3 = true;          use_S3 = true;
985    };      };
986    if( !CAL2 &&  use_CAL) use_CAL = false;      if( !CAL2 &&  use_CAL) use_CAL = false;
987    if( !TOF ){      if( !TOF ){
988      use_TOF = false;          use_TOF = false;
989      use_S1  = false;          use_S1  = false;
990      use_S2  = false;          use_S2  = false;
991      use_S3  = false;          use_S3  = false;
992    }      }
993        if( !GP ){
994    if( !TRK2 ){          use_GP  = false;
995      //  cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;      }
     return;  
   };  
996    
997    //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;      if( !TRK2 ){
998            cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
999            return;
1000        };
1001    
1002        //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
1003        
1004    
1005    //--------------------------------------------------      //--------------------------------------------------
1006    // loop over "physical" tracks sorted by the tracker      // loop over "physical" tracks sorted by the tracker
1007    //--------------------------------------------------      //--------------------------------------------------
1008    for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){      for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){
1009                    
1010      TrkTrack   *ts = 0;          TrkTrack   *ts = 0;
1011      CaloTrkVar *cs = 0;          CaloTrkVar *cs = 0;
1012      ToFTrkVar  *os = 0;          ToFTrkVar  *os = 0;
1013                    
1014      // get tracker tracks          // get tracker tracks
1015      TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker          TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
1016      CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());          CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
1017      ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());          ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());
1018    
1019      TrkTrack   *ti = 0; //tracker (image)          TrkTrack   *ti = 0; //tracker (image)
1020      CaloTrkVar *ci = 0;          CaloTrkVar *ci = 0;
1021      ToFTrkVar  *oi = 0;          ToFTrkVar  *oi = 0;
1022      //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;          //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
1023      // if track has an image, check image selection          // if track has an image, check image selection
1024    
1025      Int_t tp_score = 0;  //main track sorted by the tracker          Int_t tp_score = 0;  //main track sorted by the tracker
1026      Int_t ti_score = 0;  //image track          Int_t ti_score = 0;  //image track
1027      Int_t totp_score = 0;  //main track sorted by the tracker          Int_t totp_score = 0;  //main track sorted by the tracker
1028      Int_t toti_score = 0;  //image track          Int_t toti_score = 0;  //image track
1029    
1030      if(tp->HasImage()){          if(tp->HasImage()){
1031                            
1032        ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)              ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)
1033        ci = GetCaloStoredTrack(ti->GetSeqNo());              ci = GetCaloStoredTrack(ti->GetSeqNo());
1034        oi = GetToFStoredTrack(ti->GetSeqNo());              oi = GetToFStoredTrack(ti->GetSeqNo());
1035                            
1036        //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;              //      cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
1037    
1038        //assign starting scores              //assign starting scores
1039        tp_score = 0;  //main track sorted by the tracker              tp_score = 0;  //main track sorted by the tracker
1040        ti_score = 0;  //image track              ti_score = 0;  //image track
1041                            
1042        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1043        // calorimeter check              // *****************************************************************************************
1044        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1045        // check the Y spatial residual on the first calorimeter plane              // calorimeter check
1046        // (cut on calorimeter variables from Emiliano)              // -----------------------------------------------------------------------------------------
1047        if( use_CAL && !calo2_obj ){              if( use_CAL && !calo2_obj ){
1048          cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";                  cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";
1049          return;                  return;
       };  
       if( use_CAL && !cp &&  ci ){  
         ti_score++;  
         toti_score++;  
       };  
       if( use_CAL &&  cp && !ci ){  
         tp_score++;  
         totp_score++;  
       };  
       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++;  
           totp_score++;  
         };  
         if( cp->npresh < ci->npresh){  
           ti_score++;  
           toti_score++;  
         };  
   
         //      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 || use_S1 || use_S2 || use_S3 ) && !tof_obj ){  
         cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";  
         return;  
       };  
       //  
       if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !op && oi ){  
         ti_score++;  
         toti_score++;  
       };  
       if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && !oi ){  
         tp_score++;  
         totp_score++;  
       };  
       if( (use_TOF || use_S1 || use_S2 || use_S3 ) && 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 && false){ // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)  
           //printf(" IS A NUCLEUS! en = %f \n",sen);  
           //  
           // is a nucleus use a different algorithm  
           //  
           Int_t nz = 6; Float_t zin[6];                                          // << define TOF z-coordinates  
           for(Int_t ip=0; ip<nz; ip++)  
             zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip));     // << read ToF plane z-coordinates  
           Trajectory *tr = new Trajectory(nz,zin);  
           //  
           Int_t nphit_p =0;  
           Int_t nphit_i =0;  
           Float_t enhit_p = 0.;  
           Float_t enhit_i = 0.;  
           //  
           for (Int_t ih=0; ih < op->npmtadc; ih++){  
             Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  
             if(pl == 1 || pl == 2 || pl == 5){  
               nphit_p++;  
               enhit_p += (op->dedx).At(ih);  
             };  
           };  
           //  
           tp->DoTrack2(tr);  
           //  
           if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){  
             for (Int_t ih=0; ih < op->npmtadc; ih++){  
               Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  
               if(pl == 0){  
                 nphit_p++;  
                 enhit_p += (op->dedx).At(ih);  
               };  
1050              };              };
1051            };              if( use_CAL && !cp &&  ci ){
1052            if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){                  ti_score++;
1053              for (Int_t ih=0; ih < op->npmtadc; ih++){                  toti_score++;
               Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  
               if(pl == 3){  
                 nphit_p++;  
                 enhit_p += (op->dedx).At(ih);  
               };  
1054              };              };
1055            };              if( use_CAL &&  cp && !ci ){
1056            if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){                  tp_score++;
1057              for (Int_t ih=0; ih < op->npmtadc; ih++){                  totp_score++;
               Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  
               if(pl == 4){  
                 nphit_p++;  
                 enhit_p += (op->dedx).At(ih);  
               };  
1058              };              };
1059            };              if(
1060                    use_CAL            &&
1061                    cp && ci &&
1062                    true){
1063    
1064                    
1065                    if(
1066                        cp->npresh > ci->npresh &&
1067                        true){
1068                        tp_score++;
1069                        totp_score++;
1070                    };
1071                    if(
1072                        cp->npresh < ci->npresh &&
1073                        true){
1074                        ti_score++;
1075                        toti_score++;
1076                    };
1077    
1078                    //      cout << "CALO "<<tp_score<<ti_score<<endl;
1079    
           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);  
1080              };              };
1081            };              // -----------------------------------------------------------------------------------------
1082            //              // *****************************************************************************************
1083            ti->DoTrack2(tr);              // -----------------------------------------------------------------------------------------
1084            //              // TOF check
1085            if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){              // -----------------------------------------------------------------------------------------
1086              for (Int_t ih=0; ih < oi->npmtadc; ih++){              // check the number of hit pmts along the track
1087                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );              // on S12 S21 and S32, where paddles are parallel to Y axis
1088                if(pl == 0){              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !tof_obj ){
1089                  nphit_i++;                  cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!";
1090                  enhit_i += (op->dedx).At(ih);                  return;
               };  
1091              };              };
1092            };              //
1093            if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !op && oi ){
1094              for (Int_t ih=0; ih < oi->npmtadc; ih++){                  ti_score++;
1095                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );                  toti_score++;
               if(pl == 3){  
                 nphit_i++;  
                 enhit_i += (op->dedx).At(ih);  
               };  
1096              };              };
1097            };              if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && !oi ){
1098            if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){                  tp_score++;
1099              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);  
               };  
1100              };              };
1101            };                          if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && oi ){
1102                    //
1103                    Float_t sen = 0.;
1104                    for (Int_t ih=0; ih < op->npmtadc; ih++){
1105                        Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1106                        if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih);
1107                    };
1108                    for (Int_t ih=0; ih < oi->npmtadc; ih++){
1109                        Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1110                        if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih);
1111                    };
1112                    //
1113                    if (  sen >= sortthr && false){ // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
1114                        //printf(" IS A NUCLEUS! en = %f \n",sen);
1115                        //
1116                        // is a nucleus use a different algorithm
1117                        //
1118                        Int_t nz = 6; Float_t zin[6];                                          // << define TOF z-coordinates
1119                        for(Int_t ip=0; ip<nz; ip++)
1120                            zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip));     // << read ToF plane z-coordinates
1121                        Trajectory *tr = new Trajectory(nz,zin);
1122                        //
1123                        Int_t nphit_p =0;
1124                        Int_t nphit_i =0;
1125                        Float_t enhit_p = 0.;
1126                        Float_t enhit_i = 0.;
1127                        //
1128                        for (Int_t ih=0; ih < op->npmtadc; ih++){
1129                            Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1130                            if(pl == 1 || pl == 2 || pl == 5){
1131                                nphit_p++;
1132                                enhit_p += (op->dedx).At(ih);
1133                            };
1134                        };
1135                        //
1136                        tp->DoTrack2(tr);
1137                        //
1138                        if ( fabs(tr->y[0]-oi->ytofpos[0]) < 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 == 0){
1142                                    nphit_p++;
1143                                    enhit_p += (op->dedx).At(ih);
1144                                };
1145                            };
1146                        };
1147                        if ( fabs(tr->y[3]-oi->ytofpos[1]) < 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 == 3){
1151                                    nphit_p++;
1152                                    enhit_p += (op->dedx).At(ih);
1153                                };
1154                            };
1155                        };
1156                        if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1157                            for (Int_t ih=0; ih < op->npmtadc; ih++){
1158                                Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1159                                if(pl == 4){
1160                                    nphit_p++;
1161                                    enhit_p += (op->dedx).At(ih);
1162                                };
1163                            };
1164                        };
1165    
1166                        for (Int_t ih=0; ih < oi->npmtadc; ih++){
1167                            Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1168                            if(pl == 1 || pl == 2 || pl == 5){
1169                                nphit_i++;  
1170                                enhit_i += (op->dedx).At(ih);
1171                            };
1172                        };
1173                        //
1174                        ti->DoTrack2(tr);
1175                        //
1176                        if ( fabs(tr->y[0]-oi->ytofpos[0]) < 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 == 0){
1180                                    nphit_i++;
1181                                    enhit_i += (op->dedx).At(ih);
1182                                };
1183                            };
1184                        };
1185                        if ( fabs(tr->y[3]-oi->ytofpos[1]) < 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 == 3){
1189                                    nphit_i++;
1190                                    enhit_i += (op->dedx).At(ih);
1191                                };
1192                            };
1193                        };
1194                        if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){
1195                            for (Int_t ih=0; ih < oi->npmtadc; ih++){
1196                                Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1197                                if(pl == 4){
1198                                    nphit_i++;
1199                                    enhit_i += (op->dedx).At(ih);
1200                                };
1201                            };
1202                        };          
1203    
1204                                    
1205            if(                      if(
1206               (use_TOF || use_S1 || use_S2 || use_S3)            &&                          (use_TOF || use_S1 || use_S2 || use_S3)            &&
1207               (nphit_p+nphit_i) !=0 &&                            (nphit_p+nphit_i) !=0 &&        
1208               true){                          true){
1209                                            
1210              //      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);
1211              //      printf(" score p %i score i %i \n",tp_score,ti_score);                          //          printf(" score p %i score i %i \n",tp_score,ti_score);
1212              //            if( enhit_p > enhit_i ) tp_score++;                          //                if( enhit_p > enhit_i ) tp_score++;
1213              //            if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;                          //                if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
1214              if ( nphit_p > nphit_i ) tp_score++;                          if ( nphit_p > nphit_i ) tp_score++;
1215              if ( nphit_p < nphit_i ) ti_score++;                          if ( nphit_p < nphit_i ) ti_score++;
1216              if ( nphit_p == nphit_i ){                          if ( nphit_p == nphit_i ){
1217                if ( enhit_p > enhit_i ) tp_score++;                              if ( enhit_p > enhit_i ) tp_score++;
1218                else ti_score++;                              else ti_score++;
1219              };                          };
1220              //      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);
1221            };                      };
1222            delete tr;                      delete tr;
1223            //                      //
1224          } else {                  } else {
1225            //                      // -------------
1226            // NOT a NUCLEUS                      // NOT a NUCLEUS
1227            //                      // -------------
1228            //printf(" NOT a NUCLEUS! en = %f \n",sen);                      //printf(" NOT a NUCLEUS! en = %f \n",sen);
1229    
1230            Int_t nphit_p =0;                      Int_t nphit_p =0;
1231            Int_t nphit_i =0;                      Int_t nphit_i =0;
1232                                    
1233                                    
1234            /*                            cout << "track: npmtadc "<< op->npmtadc << endl;                      /*                          cout << "track: npmtadc "<< op->npmtadc << endl;
1235              cout << "track: npmttdc "<< op->npmttdc << endl;                                                  cout << "track: npmttdc "<< op->npmttdc << endl;
1236              cout << "image: npmtadc "<< oi->npmtadc << endl;                                                  cout << "image: npmtadc "<< oi->npmtadc << endl;
1237              cout << "image: npmttdc "<< oi->npmttdc << endl;*/                                                  cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1238                                    
1239  //        for (Int_t ih=0; ih < op->npmtadc; ih++){  //        for (Int_t ih=0; ih < op->npmtadc; ih++){
1240  //          Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
# Line 937  void PamLevel2::SortTracks(){ Line 1245  void PamLevel2::SortTracks(){
1245  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1246  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;  //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1247  //        };  //        };
1248            // --- modified to count tdc signals (more efficient?)                      // --- modified to count tdc signals (more efficient?)
1249            // --- and to implement check on tdcflag                      // --- and to implement check on tdcflag
1250            for (Int_t ih=0; ih < op->npmttdc; ih++){                      for (Int_t ih=0; ih < op->npmttdc; ih++){
1251              Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );                          Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );
1252  //          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++;
1253              if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){                          if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){
1254                if( (op->tdcflag).At(ih)==0 )nphit_p++;                              if( (op->tdcflag).At(ih)==0 )nphit_p++;
1255              };                          };
1256            };                      };
1257                                    
1258            for (Int_t ih=0; ih < oi->npmttdc; ih++){                      for (Int_t ih=0; ih < oi->npmttdc; ih++){
1259              Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );                          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );
1260  //          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++;  
1261              if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){                          if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){
1262                if( (oi->tdcflag).At(ih)==0 )nphit_i++;                                if( (oi->tdcflag).At(ih)==0 )nphit_i++;    
1263              };                          };
1264            };                      };
1265                                    
1266            if(                      if(
1267               (nphit_p+nphit_i) !=0 &&                            (nphit_p+nphit_i) !=0 &&        
1268               true){                          true){
1269                                            
1270              if ( nphit_p != nphit_i ){                          if ( nphit_p != nphit_i ){
1271                totp_score += nphit_p;                              totp_score += nphit_p;
1272                toti_score += nphit_i;                              toti_score += nphit_i;
1273                tp_score+=nphit_p;                              tp_score+=nphit_p;
1274                ti_score+=nphit_i;                              ti_score+=nphit_i;
1275                            };
1276                            //          if     ( nphit_p > nphit_i) tp_score+=nphit_p;
1277                            //          else if( nphit_p < nphit_i) ti_score+=nphit_i;
1278                            //          else ;//niente
1279                        };
1280                    };
1281                    //      cout << "TOF "<<tp_score<<ti_score<<endl;
1282              };              };
             //      if     ( nphit_p > nphit_i) tp_score+=nphit_p;  
             //      else if( nphit_p < nphit_i) ti_score+=nphit_i;  
             //      else ;//niente  
           };  
         };  
         //      cout << "TOF "<<tp_score<<ti_score<<endl;  
       };  
1283    
1284    
1285  //      if(tp_score == ti_score) use_TRK = true;  //      if(tp_score == ti_score) use_TRK = true;
1286    
1287    
1288        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1289        // tracker check              // *****************************************************************************************
1290        // -----------------------------------------------------------------------------------------              // -----------------------------------------------------------------------------------------
1291        // chi**2 difference is not always large enough to distinguish among              // tracker check
1292        // the real track and its image.              // -----------------------------------------------------------------------------------------
1293        // Tracker check will be applied always when calorimeter and tof information is ambiguous.              // chi**2 difference is not always large enough to distinguish among
1294        // *** MODIFIED ON AUGUST 2007 ***              // the real track and its image.
1295        if(use_TRK){              // Tracker check will be applied always when calorimeter and tof information is ambiguous.
1296                // *** MODIFIED ON AUGUST 2007 ***
1297                if(use_TRK){
1298  //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;  //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
1299  //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;  //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
1300    
1301            // CHECK 1 : number of points along X                    // CHECK 1 : number of points along X  
1302          if ( tp->GetNX() >= ti->GetNX() ){                  if ( tp->GetNX() >= ti->GetNX() ){
1303            tp_score++ ;                      tp_score++ ;
1304            totp_score++ ;                      totp_score++ ;
1305          };                  };
1306          if ( tp->GetNX() <= ti->GetNX() ){                  if ( tp->GetNX() <= ti->GetNX() ){
1307            ti_score++ ;                      ti_score++ ;
1308            toti_score++ ;                      toti_score++ ;
1309          };                  };
1310            // CHECK 2 : number of points along Y                    // CHECK 2 : number of points along Y  
1311          if ( tp->GetNY() >= ti->GetNY() ){                  if ( tp->GetNY() >= ti->GetNY() ){
1312            tp_score++ ;                      tp_score++ ;
1313            totp_score++ ;                      totp_score++ ;
1314          };                  };
1315          if ( tp->GetNY() <= ti->GetNY() ){                  if ( tp->GetNY() <= ti->GetNY() ){
1316            ti_score++ ;                      ti_score++ ;
1317            toti_score++ ;                      toti_score++ ;
1318          };                  };
           // CHECK 3 : chi**2 along X    
 //        if(      tp->GetChi2X() > 0 && (tp->GetChi2X() < ti->GetChi2X() || ti->GetChi2X() <=0) ) tp_score++ ;  
 //        if(      ti->GetChi2X() > 0 && (ti->GetChi2X() < tp->GetChi2X() || tp->GetChi2X() <=0) ) ti_score++ ;  
           // CHECK 4 : chi**2 along Y    
 //        if(      tp->GetChi2Y() > 0 && (tp->GetChi2Y() < ti->GetChi2Y() || ti->GetChi2Y() <=0) ) tp_score++ ;  
 //        if(      ti->GetChi2Y() > 0 && (ti->GetChi2Y() < tp->GetChi2Y() || tp->GetChi2Y() <=0) ) ti_score++ ;  
           // CHECK 5 : total chi**2    
 //        if(      tp->chi2 > 0 && (tp->chi2 < ti->chi2 || ti->chi2 <=0) ) tp_score++ ;  
 //        if(      ti->chi2 > 0 && (ti->chi2 < tp->chi2 || tp->chi2 <=0) ) ti_score++ ;  
1319    
1320          //      cout << "TRK "<<tp_score<<ti_score<<endl;                  //      cout << "TRK "<<tp_score<<ti_score<<endl;
1321        };              };
1322                            
1323    
1324                // -----------------------------------------------------------------------------------------
1325                // *****************************************************************************************
1326                // -----------------------------------------------------------------------------------------
1327                // GPamela check
1328                // -----------------------------------------------------------------------------------------
1329                
1330                //---------------------------------------------------
1331                // count the number of GP hits
1332                //---------------------------------------------------
1333                if(use_GP){
1334                    int ngphits_p=0;
1335                    int ngphits_i=0;
1336                    float toll = 0.02; //200 micron
1337                    for(int ih=0; ih<GetGPamela()->Nthspe; ih++){
1338                        int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
1339                        if(
1340                            tp &&
1341                            tp->YGood(ip) &&
1342                            fabs(tp->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1343                            true) ngphits_p++;
1344                        if( ti &&
1345                            ti->YGood(ip) &&
1346                            fabs(ti->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&
1347                            true) ngphits_i++;
1348                    }
1349                    if(
1350                        ngphits_p > ngphits_i &&
1351                        true){
1352                        tp_score++ ;
1353                        totp_score++ ;                  
1354                    }
1355                    if(
1356                        ngphits_p < ngphits_i &&
1357                        true){
1358                        ti_score++ ;
1359                        toti_score++ ;                  
1360                    }
1361                }
1362    
1363    
1364        // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*              // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1365        // the winner is....              // the winner is....
1366        // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*              // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1367        if      (tp_score > ti_score) {              if      (tp_score > ti_score) {
1368                    
1369    
1370        }else if (tp_score < ti_score) {              }else if (tp_score < ti_score) {
1371    
1372    
1373          ts = ti;//its image!!                  ts = ti;//its image!!
1374          cs = ci;                  cs = ci;
1375          os = oi;                  os = oi;
1376          Int_t totis = toti_score;                  Int_t totis = toti_score;
1377    
1378          ti = tp;//its image!!                  ti = tp;//its image!!
1379          ci = cp;                  ci = cp;
1380          oi = op;                  oi = op;
1381    
1382          tp = ts;//its image!!                  tp = ts;//its image!!
1383          cp = cs;                  cp = cs;
1384          op = os;                  op = os;
1385    
1386          toti_score = totp_score;                  toti_score = totp_score;
1387          totp_score = totis;                  totp_score = totis;
1388    
1389                                    
1390        }else {              }else {
1391    
1392  //      cout << "Warning - track image ambiguity not solved" << endl;  //      cout << "Warning - track image ambiguity not solved" << endl;
1393    
1394        };              };
1395                            
1396      }else{          }else{
1397        totp_score = 1;              totp_score = 1;
1398        toti_score = 0;              toti_score = 0;
1399                
1400        //            ts = tp;              //      ts = tp;
1401        //            cs = cp;              //      cs = cp;
1402        //            os = op;              //      os = op;
1403      };          };
1404                    
1405      //  cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;          //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
1406      //  sorted_tracks->Add(ts);//save the track in the sorted array          //      sorted_tracks->Add(ts);//save the track in the sorted array
1407      //  sorted_tracks.Add(ts);//save the track in the sorted array          //      sorted_tracks.Add(ts);//save the track in the sorted array
1408      //  sorted_tracks.Add(tp);//save the track in the sorted array          //      sorted_tracks.Add(tp);//save the track in the sorted array
1409      //  cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;          //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
1410      //  cout<<"o "<<tp<<endl;          //      cout<<"o "<<tp<<endl;
1411      //  cout<<"o "<<cp<<endl;          //      cout<<"o "<<cp<<endl;
1412      //  cout<<"o "<<op<<endl;          //      cout<<"o "<<op<<endl;
1413    
1414      new(ttsorted[i]) PamTrack(tp,cp,op);          new(ttsorted[i]) PamTrack(tp,cp,op);
1415      new(ttimage[i])  PamTrack(ti,ci,oi);          new(ttimage[i])  PamTrack(ti,ci,oi);
1416    
1417      ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);          ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);
1418      ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);          ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);
1419      ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);          ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);
1420      ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);          ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);
1421    };      };
1422    
1423    if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){      if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){
1424      cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;          cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;
1425      tsorted->Delete(); tsorted=0;          tsorted->Delete(); tsorted=0;
1426      timage->Delete(); timage=0;          timage->Delete(); timage=0;    
1427    }      }
1428    
1429    //Restore Object count      //Restore Object count
1430    //To save space in the table keeping track of all referenced objects      //To save space in the table keeping track of all referenced objects
1431    //We reset the object count to what it was at the beginning of the event.      //We reset the object count to what it was at the beginning of the event.
1432    TProcessID::SetObjectCount(ObjectNumber);      TProcessID::SetObjectCount(ObjectNumber);
1433            
1434  };  };
1435  //--------------------------------------  //--------------------------------------
# Line 1118  TClonesArray *PamLevel2::GetTracks(){ Line 1458  TClonesArray *PamLevel2::GetTracks(){
1458    
1459      return tsorted;      return tsorted;
1460            
1461   };  };
1462  //--------------------------------------  //--------------------------------------
1463   //  //
1464   //  //
1465  //--------------------------------------  //--------------------------------------
1466  /**  /**
1467   * Retrieves the it-th Pamela "physical" track.   * Retrieves the it-th Pamela "physical" track.
# Line 1182  PamTrack *PamLevel2::GetTrack(int it){ Line 1522  PamTrack *PamLevel2::GetTrack(int it){
1522   */   */
1523  PamTrack *PamLevel2::GetTrackImage(int it){  PamTrack *PamLevel2::GetTrackImage(int it){
1524    
 //     if(!trk2_obj) return 0;  
   
 // //  *-*-*-*-*-*-*-*-*-*-*-*-*  
 //     SortTracks("+CAL+TOF");  
 // //  *-*-*-*-*-*-*-*-*-*-*-*-*  
 // //    if(!sorted_tracks)return 0;  
 //     if(sorted_tracks.IsEmpty())return 0;  
       
 //     PamTrack *image = 0;  
       
 //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){  
 //      TrkTrack *temp = (TrkTrack*)sorted_tracks.At(it);  
 //      if( temp->HasImage() ){  
 //          TrkTrack   *t = trk2_obj->TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());  
 //          image = GetPamTrackAlong(t);  
 //      }else{  
 //          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;  
 //      };  
 //     }else{  
 //      cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;  
 //     };  
       
 //     return image;  
   
   
1525  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
1526      SortTracks();      SortTracks();
1527  //  *-*-*-*-*-*-*-*-*-*-*-*-*  //  *-*-*-*-*-*-*-*-*-*-*-*-*
# Line 1243  PamTrack *PamLevel2::GetTrackImage(int i Line 1558  PamTrack *PamLevel2::GetTrackImage(int i
1558   */   */
1559  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){
1560    
1561  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {
1562  //     else                    GetWhichTrees(f);          cout << "+AUTO"<<endl;
1563    if ( pam_tree ){          GetWhichTrees(f);
1564      printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");      };
1565      return pam_tree;      SetWhichTrees(detlist);
1566    };  
1567    //      if ( pam_tree ){
1568            printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");
1569            return pam_tree;
1570        };
1571        //
1572    
1573      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
1574    
1575      SetWhichTrees(detlist);  //    SetWhichTrees(detlist);
1576    
1577      TTree *Trout =0;      TTree *Trout =0;
1578    
# Line 1274  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1593  TTree *PamLevel2::GetPamTree(TFile *f, T
1593      if(ND)cout<<"ND ";      if(ND)cout<<"ND ";
1594      if(S4)cout<<"S4 ";      if(S4)cout<<"S4 ";
1595      if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
1596        if(GP)cout<<"GP ";
1597      cout << endl;      cout << endl;
1598      if(SELLI)cout<<">>> Found selection-list <<<"<<endl;      if(SELLI)cout<<">>> Found selection-list <<<"<<endl;
1599    
# Line 1372  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1692  TTree *PamLevel2::GetPamTree(TFile *f, T
1692          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
1693      };      };
1694    
1695        // GPamela
1696        TTree *G = (TTree*)f->Get("h20");
1697        if(G && GP) {
1698            if(!gp_obj)gp_obj=new GPamela();
1699    //      ------------------------------------
1700    //      ATTENZIONE!!!
1701    //      non so per quale arcano motivo,
1702    //      per l'albero di gpamela il branch address lo devo settare
1703    //      DOPO aver fatto friend
1704    //      FGRRRVZZZZUTSALKJMSLKJ!!!
1705    //      ------------------------------------
1706    //      gp_obj->SetBranchAddress(G); //ho dovuto fare in maniera diversa dagli altri
1707    //      cout << "h20          : set branch address GPamela "<<endl;
1708            if(!Trout)Trout=G;
1709            else Trout->AddFriend(G);
1710        }else{
1711    //      cout << "h20          : missing tree"<<endl;
1712        };
1713    
1714    
1715      TTree *L = (TTree*)f->Get("SelectionList");      TTree *L = (TTree*)f->Get("SelectionList");
1716      if(L && SELLI==1) {      if(L && SELLI==1) {
1717  //      L->SetBranchAddress("RunEntry",&irun);          cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemented!!!!"<<endl;
 //      cout << "SelectionList: set branch address RunEntry"<<endl;  
 //      L->SetBranchAddress("EventEntry",&irunentry);  
 //      cout << "SelectionList: set branch address EventEntry"<<endl;  
 //      if(!Trout)Trout=O;  
 //      else Trout->AddFriend("SelectionList");  
         cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemente!!!!"<<endl;  
1718          sel_tree = 0;          sel_tree = 0;
1719      }else{      }else{
1720          cout << "SelectionList  : missing tree"<<endl;          cout << "SelectionList  : missing tree"<<endl;
# Line 1388  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1722  TTree *PamLevel2::GetPamTree(TFile *f, T
1722            
1723      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1724    
1725    //      ------------------------------------
1726    //      ATTENZIONE!!!
1727    //      non so per quale arcano motivo,
1728    //      per l'albero di gpamela il branch address lo devo settare
1729    //      DOPO aver fatto friend
1730    //      FGRRRVZZZZUTSALKJMSLKJ!!!
1731    //      ------------------------------------
1732        if(G && GP) {      
1733            gp_obj->SetBranchAddress(Trout); //ho dovuto fare in maniera diversa dagli altri
1734            cout << "h20          : set branch address GPamela "<<endl;
1735        }else{
1736            cout << "h20          : missing tree"<<endl;
1737        };
1738    
1739      pam_tree = (TChain*)Trout;      pam_tree = (TChain*)Trout;
1740            
1741      return Trout;      return Trout;
# Line 1411  TList*  PamLevel2::GetListOfLevel2Files( Line 1759  TList*  PamLevel2::GetListOfLevel2Files(
1759      //    if(ddir=="")ddir = wdir;      //    if(ddir=="")ddir = wdir;
1760  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1761      if ( ddir != ""){      if ( ddir != ""){
1762        cout << "Level2 data directory : "<<  ddir << endl;          cout << "Level2 data directory : "<<  ddir << endl;
1763      } else {      } else {
1764        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;
1765      };      };
1766      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
1767      contents->SetOwner();      contents->SetOwner();
# Line 1430  TList*  PamLevel2::GetListOfLevel2Files( Line 1778  TList*  PamLevel2::GetListOfLevel2Files(
1778  //          return 0;  //          return 0;
1779  //      }        //      }      
1780  //      flisttxt = fullpath;  //      flisttxt = fullpath;
1781        if ( !flisttxt.EndsWith(".root") ){          if ( !flisttxt.EndsWith(".root") ){
1782    
1783          flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1784    
1785          if( !gSystem->ChangeDirectory(ddir) ){              if( !gSystem->ChangeDirectory(ddir) ){
1786              cout << "Cannot change directory : "<<ddir<<endl;                  cout << "Cannot change directory : "<<ddir<<endl;
1787              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;  
1788              }              }
1789              if(file.Contains("#"))file = file(0,file.First("#"));          
1790                cout <<"Input file list : " << flisttxt <<endl;
1791                ifstream in;
1792                in.open(flisttxt, ios::in); //open input file list
1793                if(!in.good()){
1794                    cout <<" ERROR opening the file "<<endl;
1795                    gSystem->ChangeDirectory(wdir); // back to the working directory
1796                    return 0;
1797                }  
1798                int line=0;
1799                while (1) {
1800                    TString file;
1801                    in >> file;
1802                    if (!in.good()) break;
1803                    line++;
1804    //          cout <<"(1) " << file << endl;
1805                    if(file.IsNull()){
1806                        cout << "-- list interrupted at line "<<line <<endl;
1807                        break;
1808                    }
1809                    if(file.Contains("#"))file = file(0,file.First("#"));
1810  //          cout <<"(2) " << file << endl;  //          cout <<"(2) " << file << endl;
1811  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1812  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
1813              if( file.EndsWith(".root") ){                  if( file.EndsWith(".root") ){
1814                TString filedir;                      TString filedir;
1815                if (ddir != ""){                      if (ddir != ""){
1816                  filedir = ddir; // take the input dir                          filedir = ddir; // take the input dir
1817                } else {                      } else {
1818                  gSystem->ChangeDirectory(wdir); // back to the working directory                          gSystem->ChangeDirectory(wdir); // back to the working directory
1819                  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
1820                };                      };
1821                  char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));                      char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));
1822                  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
1823                  delete fullpath;                      delete fullpath;
1824              }                  }
1825  //          }else{  //          }else{
1826  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1827  //          };  //          };
1828          };              };
1829          in.close();              in.close();
1830        } else {          } else {
1831            if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));
1832            char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1833            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
1834            delete fullpath;              delete fullpath;
1835        };                  };      
1836      }else{      }else{
1837                    
1838          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
1839          cout << "Check for existing root files."<<endl;          cout << "Check for existing root files."<<endl;
1840  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
1841          if ( ddir == "" ){          if ( ddir == "" ){
1842            ddir = wdir;              ddir = wdir;
1843            cout << "Level2 data directory : "<<  ddir << endl;              cout << "Level2 data directory : "<<  ddir << endl;
1844          };          };
1845    
1846          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
# Line 1538  TList*  PamLevel2::GetListOfLevel2Files( Line 1886  TList*  PamLevel2::GetListOfLevel2Files(
1886   * @return Pointer to a TChain   * @return Pointer to a TChain
1887   */   */
1888  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){
1889    //      //
1890    //      //
1891    //      //
1892    if ( pam_tree ){      if ( pam_tree ){
1893      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 ");
1894      return pam_tree;          return pam_tree;
1895    };      };
1896    //      //
1897            
1898      TChain *Trout =0;      TChain *Trout =0;
1899    
1900  //    if( !detlist.IsNull() )SetWhichTrees(detlist);      // -------------------------------------------
1901      SetWhichTrees(detlist);      // set flags to include/exclude trees/branches
1902            // -------------------------------------------
1903      cout<< "GetPamTree(TList*,TString): input detector list --> ";      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {
1904      if(TRK1)cout<<"TRK1 ";          if( fl->GetEntries()>0 ){
1905      if(TRK2)cout<<"TRK2 ";              cout << "+AUTO"<<endl;
1906      if(TRKh)cout<<"TRKH ";              TFile *fprimo = new TFile( fl->At(0)->GetName() );
1907      if(CAL1)cout<<"CAL1 ";              GetWhichTrees(fprimo);
1908      if(CAL2)cout<<"CAL2 ";              fprimo->Close();// AAAAARGGGGGHHHHH!!!!!!! non commentare questa riga, altrimenti si incasina il TChain
1909      if(TOF)cout<<"TOF ";              fprimo->Delete();
1910      if(TRG)cout<<"TRG ";          }
1911      if(AC)cout<<"AC ";      };
1912      if(ND)cout<<"ND ";      SetWhichTrees(detlist);    
1913      if(S4)cout<<"S4 ";  
1914      if(ORB)cout<<"ORB ";  
1915      cout << endl;      // -------------------------------------------
1916        // build chains
1917       TChain *T = 0;          // -------------------------------------------
1918       TChain *C = 0;      TChain *T = 0;      
1919       TChain *O = 0;      TChain *C = 0;
1920       TChain *R = 0;      TChain *O = 0;
1921       TChain *S = 0;      TChain *R = 0;
1922       TChain *N = 0;      TChain *S = 0;
1923       TChain *A = 0;      TChain *N = 0;
1924       TChain *B = 0;      TChain *A = 0;
1925        TChain *B = 0;
1926        TChain *G = 0;
1927    
1928       TChain *L = 0;      TChain *L = 0;
1929            
1930      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
1931      if(CAL2||CAL1)       C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
# Line 1585  TChain *PamLevel2::GetPamTree(TList *fl, Line 1935  TChain *PamLevel2::GetPamTree(TList *fl,
1935      if(ND)               N = new TChain("NeutronD");      if(ND)               N = new TChain("NeutronD");
1936      if(AC)               A = new TChain("Anticounter");      if(AC)               A = new TChain("Anticounter");
1937      if(ORB)              B = new TChain("OrbitalInfo");      if(ORB)              B = new TChain("OrbitalInfo");
1938       L = new TChain("SelectionList");      if(GP)               G = new TChain("h20");
1939        L = new TChain("SelectionList");
1940            
1941      // loop over files and create chains              // loop over files and create chains        
1942      TIter next(fl);      TIter next(fl);
# Line 1602  TChain *PamLevel2::GetPamTree(TList *fl, Line 1953  TChain *PamLevel2::GetPamTree(TList *fl,
1953              if(ND)               N->Add(name);              if(ND)               N->Add(name);
1954              if(AC)               A->Add(name);              if(AC)               A->Add(name);
1955              if(ORB)              B->Add(name);              if(ORB)              B->Add(name);
1956                if(GP)               G->Add(name);
1957              if(SELLI==1)         L->Add(name);              if(SELLI==1)         L->Add(name);
1958          };          };
1959      };      };
1960            
1961      cout << "done chain \n";      cout << "done chains\n";
1962      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1963    
1964  //    UInt_t *found=0;  
1965        // -------------------------------------------
1966        // make friends
1967        // -------------------------------------------
1968    
1969  // Tracker  // Tracker
1970        cout << "Friends: "<<endl;
1971      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
         if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));  
 //      else    T->SetBranchStatus("TrkLevel2",0,found);  
         if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;  
         if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));  
 //      else    T->SetBranchStatus("TrkLevel1",0,found);  
         if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;  
         if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));  
 //      else    T->SetBranchStatus("TrkHough",0,found);  
         if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;  
1972          if(!Trout)Trout=T;          if(!Trout)Trout=T;
1973          else Trout->AddFriend("Tracker");          else Trout->AddFriend("Tracker");
1974      }else{  //      cout << "+Tacker"<<endl;
         cout << "Tracker      : missing tree"<<endl;  
1975      };      };
1976      // Calorimeter      // Calorimeter
1977      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
         if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));  
 //      else    C->SetBranchStatus("CaloLevel2",0,found);  
         if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;  
         if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));  
 //      else    C->SetBranchStatus("CaloLevel1",0,found);  
         if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;  
1978          if(!Trout)Trout=C;          if(!Trout)Trout=C;
1979          else Trout->AddFriend("Calorimeter");          else Trout->AddFriend("Calorimeter");
1980      }else{  //      cout << "+Calorimeter"<<endl;
         cout << "Calorimeter  : missing tree"<<endl;  
1981      };      };
1982      // ToF          // ToF    
1983      if(O && TOF) {      if(O && TOF) {
         O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));  
         cout << "ToF          : set branch address ToFLevel2"<<endl;  
1984          if(!Trout)Trout=O;          if(!Trout)Trout=O;
1985          else Trout->AddFriend("ToF");          else Trout->AddFriend("ToF");
1986      }else{  //      cout << "+ToF"<<endl;
         cout << "ToF         : missing tree"<<endl;  
1987      };      };
1988      // Trigger      // Trigger
1989      if(R && TRG) {      if(R && TRG) {
         R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));  
         cout << "Trigger      : set branch address TrigLevel2"<<endl;  
1990          if(!Trout)Trout=O;          if(!Trout)Trout=O;
1991          else Trout->AddFriend("Trigger");          else Trout->AddFriend("Trigger");
1992      }else{  //      cout << "+Trigger"<<endl;
         cout << "Trigger      : missing tree"<<endl;  
1993      };      };
1994      // S4      // S4
1995      if(S && S4) {      if(S && S4) {
         S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));  
         cout << "S4           : set branch address S4Level2"<<endl;  
1996          if(!Trout)Trout=O;          if(!Trout)Trout=O;
1997          else Trout->AddFriend("S4");          else Trout->AddFriend("S4");
1998      }else{  //      cout << "+S4"<<endl;
         cout << "S4           : missing tree"<<endl;  
1999      };      };
2000      // Neutron Detector      // Neutron Detector
2001      if(N && ND) {      if(N && ND) {
         N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));  
         cout << "NeutronD     : set branch address NDLevel2"<<endl;  
2002          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2003          else Trout->AddFriend("NeutronD");          else Trout->AddFriend("NeutronD");
2004      }else{  //      cout << "+NeutronD"<<endl;
         cout << "NeutronD     : missing tree"<<endl;  
2005      };      };
2006      // Anticounters      // Anticounters
2007      if(A && AC) {      if(A && AC) {
         A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));  
         cout << "Anticounter  : set branch address AcLevel2"<<endl;  
2008          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2009          else Trout->AddFriend("Anticounter");          else Trout->AddFriend("Anticounter");
2010      }else{  //      cout << "+Anticounter"<<endl;
         cout << "Anticounter  : missing tree"<<endl;  
2011      };      };
2012      // Orbital Info      // Orbital Info
2013      if(B && ORB) {      if(B && ORB) {
         B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));  
         cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;  
2014          if(!Trout)Trout=O;          if(!Trout)Trout=O;
2015          else Trout->AddFriend("OrbitalInfo");          else Trout->AddFriend("OrbitalInfo");
2016      }else{  //      cout << "+OrbitalInfo"<<endl;
         cout << "OrbitalInfo  : missing tree"<<endl;  
2017      };      };
2018        // GPamela
2019        if(G && GP) {
2020            if(!Trout)Trout=G;
2021            else Trout->AddFriend("h20");
2022    //      cout << "+h20"<<endl;
2023        };
2024    
2025    //  =====================================
2026    //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND
2027    //  =====================================
2028        SetBranchAddress(Trout);
2029    
2030    
2031    //  ------------------------------------
2032    //  finally handle selection trees...
2033    //  (it is not friend of pamela tree)
2034    //  ------------------------------------
2035    
2036      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2037    
2038      // Selection List      // Selection List
2039      if(L && SELLI==1) {      if(L && SELLI==1) {
2040          cout<<">>> Found selection-list <<<"<<endl;          cout<<">>> Found selection-list <<<"<<endl;
2041          L->SetBranchAddress("RunEntry",&irun);  //      L->SetBranchAddress("RunEntry",&irun);
2042            L->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2043          cout << "SelectionList: set branch address RunEntry"<<endl;          cout << "SelectionList: set branch address RunEntry"<<endl;
2044          L->SetBranchAddress("EventEntry",&irunentry);          L->SetBranchAddress("EventEntry",&irunentry);
2045          cout << "SelectionList: set branch address EventEntry"<<endl;          cout << "SelectionList: set branch address EventEntry"<<endl;
2046          sel_tree = L;          sel_tree = L;
2047  //      if(!Trout)Trout=O;  //      if(!Trout)Trout=O;
2048  //      else Trout->AddFriend("SelectionList");  //      else Trout->AddFriend("SelectionList");
2049          cout << "----------------------------------------------------" <<endl;          cout << "+SelectionList"<<endl;
2050            cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2051      }else{      }else{
2052  //      cout << "SelectionList  : missing tree"<<endl;  //      cout << "SelectionList  : missing tree"<<endl;
2053          if(L)L->Delete();          if(L)L->Delete();
2054      };      };
       
 //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;  
2055    
2056      pam_tree = Trout;  //  --------------------------------------------
2057    //  return the pamela chain with all the friends
2058    //  --------------------------------------------
2059    
2060        pam_tree = Trout;
2061        
2062      return Trout;      return Trout;
2063  }  }
2064    
# Line 1740  void PamLevel2::SetBranchAddress(TTree * Line 2084  void PamLevel2::SetBranchAddress(TTree *
2084      ND     = ND  & t->GetBranchStatus("NDLevel2");      ND     = ND  & t->GetBranchStatus("NDLevel2");
2085      AC     = AC  & t->GetBranchStatus("AcLevel2");      AC     = AC  & t->GetBranchStatus("AcLevel2");
2086      ORB    = ORB & t->GetBranchStatus("OrbitalInfo");      ORB    = ORB & t->GetBranchStatus("OrbitalInfo");
2087        GP     = GP  & t->GetBranchStatus("h20");
2088    
2089    
2090      // Tracker      // Tracker
# Line 1796  void PamLevel2::SetBranchAddress(TTree * Line 2141  void PamLevel2::SetBranchAddress(TTree *
2141          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
2142          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
2143      };      };
2144      // SelectionList      // GPamela
2145      if(SELLI==1) {      if(GP) {
2146          t->SetBranchAddress("RunEntry", &irun);  //      GetPointerTo("GPamela");
2147          cout << "SelectionList: set branch address RunEntry"<<endl;          if(!gp_obj)gp_obj = new GPamela();
2148          t->SetBranchAddress("EventEntry", &irunentry);  //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2149          cout << "SelectionList: set branch address EventEntry"<<endl;  // //   t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2150            if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2151            else      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2152    
2153            cout << "h20          : set branch address GPamela "<<endl;
2154      };      };
2155            
2156  }  }
# Line 1810  void PamLevel2::SetBranchAddress(TTree * Line 2159  void PamLevel2::SetBranchAddress(TTree *
2159   */   */
2160  void PamLevel2::SetBranchAddress(TChain *t){  void PamLevel2::SetBranchAddress(TChain *t){
2161    
2162      TRK2    = TRK2 & t->GetBranchStatus("TrkLevel2");  //     TRK2    = TRK2 & t->GetBranchStatus("TrkLevel2");
2163      TRK1    = TRK1 & t->GetBranchStatus("TrkLevel1");  //     TRK1    = TRK1 & t->GetBranchStatus("TrkLevel1");
2164      TRKh    = TRKh & t->GetBranchStatus("TrkHough");  //     TRKh    = TRKh & t->GetBranchStatus("TrkHough");
2165      CAL1    = CAL1 & t->GetBranchStatus("CaloLevel1");  //     CAL1    = CAL1 & t->GetBranchStatus("CaloLevel1");
2166      CAL2    = CAL2 & t->GetBranchStatus("CaloLevel2");  //     CAL2    = CAL2 & t->GetBranchStatus("CaloLevel2");
2167      TOF    = TOF & t->GetBranchStatus("ToFLevel2");  //     TOF    = TOF & t->GetBranchStatus("ToFLevel2");
2168      TRG    = TRG & t->GetBranchStatus("TrigLevel2");  //     TRG    = TRG & t->GetBranchStatus("TrigLevel2");
2169      S4     = S4  & t->GetBranchStatus("S4Level2");  //     S4     = S4  & t->GetBranchStatus("S4Level2");
2170      ND     = ND  & t->GetBranchStatus("NDLevel2");  //     ND     = ND  & t->GetBranchStatus("NDLevel2");
2171      AC     = AC  & t->GetBranchStatus("AcLevel2");  //     AC     = AC  & t->GetBranchStatus("AcLevel2");
2172      ORB    = ORB & t->GetBranchStatus("OrbitalInfo");  //     ORB    = ORB & t->GetBranchStatus("OrbitalInfo");
2173    //    GP     = GP & t->GetBranchStatus("h20");
2174    
2175      // Tracker      // Tracker
2176       if(TRK2) {      if(TRK2) {
2177          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
2178          cout << "Tracker      : set branch address TrkLevel2"<<endl;          cout << "Tracker      : set branch address TrkLevel2"<<endl;
2179      };      };
# Line 1831  void PamLevel2::SetBranchAddress(TChain Line 2181  void PamLevel2::SetBranchAddress(TChain
2181          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
2182          cout << "Tracker      : set branch address TrkLevel1"<<endl;          cout << "Tracker      : set branch address TrkLevel1"<<endl;
2183      };      };
2184       if(TRKh) {      if(TRKh) {
2185          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
2186          cout << "Tracker      : set branch address TrkHough"<<endl;          cout << "Tracker      : set branch address TrkHough"<<endl;
2187       };      };
2188            
2189      // Calorimeter      // Calorimeter
2190      if(CAL2) {      if(CAL2) {
# Line 1876  void PamLevel2::SetBranchAddress(TChain Line 2226  void PamLevel2::SetBranchAddress(TChain
2226          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
2227          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
2228      };      };
2229      // SelectionList      // GPamela
2230      if(SELLI==1) {  //    cout <<"GP "<<GP<<endl;
2231          t->SetBranchAddress("RunEntry", &irun);      if(GP) {
2232          cout << "SelectionList: set branch address RunEntry"<<endl;  //      GetPointerTo("GPamela");
2233          t->SetBranchAddress("EventEntry", &irunentry);          if(!gp_obj)gp_obj = new GPamela();
2234          cout << "SelectionList: set branch address EventEntry"<<endl;          if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2235            else      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2236    //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2237            cout << "h20          : set branch address GPamela "<<endl;
2238      };      };
2239            // SelectionList
2240    //     if(SELLI==1){
2241    //      t->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2242    //      cout << "SelectionList: set branch address RunEntry"<<endl;
2243    //      t->SetBranchAddress("EventEntry",&irunentry);
2244    //      cout << "SelectionList: set branch address EventEntry"<<endl;
2245            
2246    //     }
2247    
2248  }  }
2249    
2250    
# Line 1897  void PamLevel2::SetBranchAddress(TChain Line 2258  void PamLevel2::SetBranchAddress(TChain
2258   * @return Pointer to a TChain   * @return Pointer to a TChain
2259   */   */
2260  TChain *PamLevel2::GetRunTree(TList *fl){  TChain *PamLevel2::GetRunTree(TList *fl){
2261    //      //
2262    //      //
2263    //      //
2264    if ( run_tree ){      if ( run_tree ){
2265      printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");          printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
2266      return run_tree;          return run_tree;
2267    };          };  
2268    //      //
2269    TChain *R = new TChain("Run");  
2270    
2271        TChain *R = new TChain("Run");
2272            
2273      // loop over files and create chains              // loop over files and create chains        
2274      TIter next(fl);      TIter next(fl);
# Line 1917  TChain *PamLevel2::GetRunTree(TList *fl) Line 2280  TChain *PamLevel2::GetRunTree(TList *fl)
2280              R->Add(name);              R->Add(name);
2281          };          };
2282      }      }
2283        
2284    
2285      if(R->GetNtrees()){      if(RUN && R->GetNtrees()){
2286            
2287          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
2288          cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
2289          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2290          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
2291    
2292            irunoffset = new int[R->GetNtrees()];
2293            if(DBG){
2294                cout << "----------------------------------------------------"<<endl;
2295                cout << "irun\t | ";
2296                cout << "tree\t |";
2297    //      cout << "offset\t |";
2298                cout << "RUN\t";
2299                cout << "FRAG\t";
2300                cout << "NEVENTS\t";
2301                cout << "absolute time\t\t\t";
2302                cout << "on-board time";
2303                cout<<endl;
2304            }
2305            for (Int_t ii=0; ii<R->GetEntries(); ii++){
2306                R->GetEntry(ii);
2307                if(DBG){
2308                    cout << ii<< "\t | ";
2309                    cout << R->GetTreeNumber()<< "\t |";
2310    //          cout << R->GetChainOffset()<< "\t |";
2311                    cout <<GetRunInfo()->ID<<"\t";
2312                    cout <<GetRunInfo()->ID_RUN_FRAG<<"\t";
2313                    cout <<GetRunInfo()->NEVENTS<< "\t";
2314                    cout <<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME <<"\t";
2315                    cout <<GetRunInfo()->RUNHEADER_OBT<<" <---> "<<GetRunInfo()->RUNTRAILER_OBT<<"\t";
2316                    cout <<endl;
2317                }
2318                irunoffset[R->GetTreeNumber()]=R->GetChainOffset();
2319            }
2320            cout << "N.run = "<<R->GetEntries()<<endl;
2321            cout << "----------------------------------------------------"<<endl;
2322    
2323    
2324      }else{      }else{
2325          delete R;          delete R;
2326          R=0;          R=0;
2327      }      }
2328        
2329    
2330      run_tree = R;      run_tree = R;
2331    
# Line 1944  TChain *PamLevel2::GetRunTree(TList *fl) Line 2342  TChain *PamLevel2::GetRunTree(TList *fl)
2342   * @return Pointer to a TTree   * @return Pointer to a TTree
2343   */   */
2344  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f){
2345    if ( run_tree ){      if ( run_tree ){
2346      printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");          printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
2347      return run_tree;          return run_tree;
2348    };      };
2349                    
2350    
2351      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
# Line 1959  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2357  TTree *PamLevel2::GetRunTree(TFile *f){
2357          cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
2358          T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2359          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
2360    
2361      }      }
2362    
2363      run_tree = (TChain*)T;      run_tree = (TChain*)T;
# Line 1972  TTree *PamLevel2::GetRunTree(TFile *f){ Line 2371  TTree *PamLevel2::GetRunTree(TFile *f){
2371   * @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
2372   */   */
2373  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){
2374    //      //
2375    // check if we have already called once GetEntry, if not call it      // check if we have already called once GetEntry, if not call it
2376    //      //
2377      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;
2378      if(!run){      if(!run){
2379            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;
2380            return(false);                  return(false);  
2381      }      }
2382      if ( run->GetEntries() <= 0 ) return(false);      if ( run->GetEntries() <= 0 ) return(false);
2383    //      //
2384        
2385    //  Int_t oldrun = irun;      //  Int_t oldrun = irun;
2386    Long64_t oldrun = irun;      Long64_t oldrun = irun;
2387    
2388        // --------------------------------------
2389        // if it is a full file (not preselected)
2390        // --------------------------------------
2391        if(SELLI==0){
2392    
2393            //
2394            // the absolute time is necessary to relate the event with the run
2395            //
2396            if( !GetOrbitalInfo() && !ISGP){
2397                cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
2398                return(false);
2399            }
2400    
2401    // --------------------------------------          ULong64_t abstime = 0;
2402    // if it is a full file (not preselected)          if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;
2403    // --------------------------------------  
2404    if(SELLI==0){  
2405            //
2406        //          // the first time the routine is called, set run search from the beginning
2407        // the absolute time is necessary to relate the event with the run          //
2408        //          if ( irun < 0LL ){
2409        if( !GetOrbitalInfo() && !ISGP){              irun = 0LL;
2410            cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;              run->GetEntry(irun);
2411            return(false);              runfirstentry = 0LL;
2412        }              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2413                if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
       ULong64_t abstime = 0;  
       if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;  
   
   
       //  
       // the first time the routine is called, set run search from the beginning  
       //  
       if ( irun < 0LL ){  
           irun = 0LL;  
           run->GetEntry(irun);  
           runfirstentry = 0LL;  
           runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);  
           if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;  
2414                        
2415            if( ISGP && run->GetEntries()!=1 ){              if( ISGP && run->GetEntries()!=1 ){
2416                cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl;                  cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl;
2417                cout << "** WARNING ** run will not be updated"<<endl;                  cout << "** WARNING ** run will not be updated"<<endl;
2418            }              }
2419    
2420        };                };      
2421        //          //
2422        if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO          if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2423        //          //
2424        if ( irun == run->GetEntries()-1LL &&          if ( irun == run->GetEntries()-1LL &&
2425             !(abstime >= GetRunInfo()->RUNHEADER_TIME &&               !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2426               abstime <= GetRunInfo()->RUNTRAILER_TIME)                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
2427              ){              ){
2428           irun = -1LL;              irun = -1LL;
2429           runfirstentry = 0LL;              irunt = -1LL;
2430           runlastentry = -1LL;              runfirstentry = 0LL;
2431         };              runlastentry = -1LL;
2432        // modificato il controllo sull'aggiornamento del run, per evitare problemi          };
2433        // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)          // modificato il controllo sull'aggiornamento del run, per evitare problemi
2434        //          // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
2435        bool fromfirst = true;          //
2436        //          bool fromfirst = true;
2437        while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){          //
2438            while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){
2439  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){  //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
2440            irun++;              irun++;
2441            run->GetEntry(irun);              run->GetEntry(irun);
2442            runfirstentry = runlastentry;              runfirstentry = runlastentry;
2443            if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;              if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;
2444            runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);              runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2445  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;  //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2446  //        cout << "runfirstentry "<<runfirstentry<<endl;  //        cout << "runfirstentry "<<runfirstentry<<endl;
2447            //      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)));
2448            //      printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);              //    printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);
2449            //      printf(" IDRUN %u \n",GetRunInfo()->ID);              //    printf(" IDRUN %u \n",GetRunInfo()->ID);
2450            //              //
2451  //        prevshift = 0;  //        prevshift = 0;
2452            //              //
2453            if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){              if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){
2454                printf(" resetting irun  (it should NOT happen!!!)\n");                  printf(" resetting irun  (it should NOT happen!!!)\n");
2455                fromfirst = false;                  fromfirst = false;
2456                irun = 0;                  irun = 0;
2457                run->GetEntry(irun);                  run->GetEntry(irun);
2458                runfirstentry = 0ULL;                  runfirstentry = 0ULL;
2459                runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);                  runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2460                if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;                  if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;
2461            };              };
2462            //              //
2463        };          };
2464        //          //
2465        if (          if (
2466             !(abstime >= GetRunInfo()->RUNHEADER_TIME &&              !(abstime >= GetRunInfo()->RUNHEADER_TIME &&
2467               abstime <= GetRunInfo()->RUNTRAILER_TIME)                abstime <= GetRunInfo()->RUNTRAILER_TIME)
2468            ) {              ) {
2469          printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n",abstime);              printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n",abstime);
2470            return false;              return false;
2471        }          }
2472        //          //
2473        if ( irun == oldrun || irun >= run->GetEntries() ) return(false);          if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
2474        //          //
2475        //  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);
2476        //          //
2477        prevshift = 0;          prevshift = 0;
2478        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;          cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2479  //      cout << "runfirstentry "<<runfirstentry<<endl;  //      cout << "runfirstentry "<<runfirstentry<<endl;
2480        return(true);              return(true);    
2481    };      };
2482    // ----------------------------------------------------      // ----------------------------------------------------
2483    // if it is a preselected file (there is SelectionList)      // if it is a preselected file (there is SelectionList)
2484    // NBNB - the event tree MUST be read first      // NBNB - the event tree MUST be read first
2485    // ----------------------------------------------------      // ----------------------------------------------------
2486    if(SELLI==1){            if(SELLI==1){      
2487        sel_tree->GetEntry(iev);          sel_tree->GetEntry(iev);
2488  //      cout << irun << " "<< irunentry << endl;  //      cout << irun << " "<< irunentry << endl;
2489        if(irun != oldrun){          if(irun != oldrun){
2490            run->GetEntry(irun);              run->GetEntry(irun);
2491            cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;              cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2492            prevshift = 0;              prevshift = 0;
2493            return true;              return true;
2494        }          }
2495        return false;          return false;
2496    }      }
2497    
2498    return false;      return false;
2499    //      //
2500  };  };
2501    
2502  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){
# Line 2112  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2512  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2512        
2513      Int_t oldrun = irun; // store current run index      Int_t oldrun = irun; // store current run index
2514    
2515        // -----------------------------------------------------------------------
2516        // the first time the routine is called, set run search from the beginning
2517        // -----------------------------------------------------------------------
2518    
2519        if ( irun < 0 ){
2520            irun = 0LL;
2521            irunt = 0LL;
2522            irunentry = 0;
2523            prevshift = 0;
2524            run_tree->GetEntry(irun);
2525            if( !GetOrbitalInfo() )cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated "<<endl;
2526        };      
2527        // ---------------------------------------------------------------
2528        // retrieve OBT and absolute time of the event
2529        // ---------------------------------------------------------------
2530        ULong64_t abstime = 0LL;
2531        ULong64_t obt     = 0LL;
2532        if( GetOrbitalInfo() ){
2533            abstime = GetOrbitalInfo()->absTime;
2534            obt     = GetOrbitalInfo()->OBT;
2535        }else{
2536            abstime = GetRunInfo()->RUNHEADER_TIME;
2537            obt     = GetRunInfo()->RUNHEADER_OBT;
2538        }
2539        
2540    
2541      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2542      // if it is a full file (not preselected)      // if it is a full file (not preselected)
2543      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2544      if(SELLI==0){      if(SELLI==0){
2545    
2546          // ---------------------------------------------------------------          // ---------------------------------------------------------------
2547          // increment dead and live-time counters          // increment dead and live-time counters
2548          // ---------------------------------------------------------------          // (only when reading a file not preselected)
         if( GetTrigLevel2() ){  
             totdltime[0]+=GetTrigLevel2()->dltime[0];  
             totdltime[1]+=GetTrigLevel2()->dltime[1];  
         }  
         totdltime[2]++;  
   
 //      cout << setw(10)<<totdltime[0]<<setw(10)<<totdltime[1]<<setw(10)<<totdltime[2]<<endl;  
   
         // ---------------------------------------------------------------  
         // retrieve OBT and absolute time of the event  
         // ---------------------------------------------------------------  
         ULong64_t abstime = 0;  
         ULong64_t obt     = 0;  
         if( GetOrbitalInfo() ){  
             abstime = GetOrbitalInfo()->absTime;  
             obt     = GetOrbitalInfo()->OBT;  
         }  
2549          // ---------------------------------------------------------------          // ---------------------------------------------------------------
2550          // the absolute time is necessary to relate the event with the run          if(SELLI==0){
2551          // ---------------------------------------------------------------              if( GetTrigLevel2() ){
2552          if( !GetOrbitalInfo() && !ISGP ){                  totdltime[0]+=GetTrigLevel2()->dltime[0];
2553              cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;                  totdltime[1]+=GetTrigLevel2()->dltime[1];
             return(false);  
         }  
         
         // -----------------------------------------------------------------------  
         // the first time the routine is called, set run search from the beginning  
         // -----------------------------------------------------------------------  
         if ( irun < 0 ){  
             irun = 0LL;  
             irunentry = 0;  
             prevshift = 0;  
             run_tree->GetEntry(irun);  
   
             if( ISGP && run_tree->GetEntries()!=1 ){  
                 cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl;  
                 cout << "** WARNING ** run will not be updated"<<endl;  
2554              }              }
2555          };                    totdltime[2]++;
   
         // -----------------------------------------------------------------------  
         // if it is simulation, assigh abstime by hand (temporaneo!!!)  
         // -----------------------------------------------------------------------  
         if(ISGP){  
             abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO  
             obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO  
2556          }          }
2557    
2558          //          //
2559          bool fromfirst = true; // first loop over runs          bool fromfirst = true; // first loop over runs
2560    
 //      Bool_t hasfrag = false;  
 //      if( GetRunInfo()->ID_RUN_FRAG!=0 && GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID)hasfrag=true;  
 //      ULong64_t fragid = GetRunInfo()->ID_RUN_FRAG;  
2561    
2562          // ------------------------------------------------------          // ------------------------------------------------------
2563          // loop over runs to find the one that contains the event          // loop over runs to find the one that contains the event
2564          // ------------------------------------------------------          // ------------------------------------------------------
2565          while (          while (
2566              (              (
2567                  (  //              (
2568                      !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)  //                  !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2569                        abstime <= GetRunInfo()->RUNTRAILER_TIME) &&  //                    abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
2570                      !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)  //                  !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2571                        obt <= GetRunInfo()->RUNTRAILER_OBT)  //                    obt <= GetRunInfo()->RUNTRAILER_OBT)
2572                      )  //                  )
2573                  || GetRunInfo()->NEVENTS==0                  
2574                  || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift)                  !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2575                      abstime <= GetRunInfo()->RUNTRAILER_TIME)
2576                    ||
2577                    !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2578                      obt <= GetRunInfo()->RUNTRAILER_OBT)          
2579                    ||
2580                    GetRunInfo()->NEVENTS==0
2581    //              || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento
2582                    ||
2583                    !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)
2584                  )                  )
2585                  && irun < run_tree->GetEntries() ){              && irun < run_tree->GetEntries() ){
   
2586    
2587    
2588    //          if( !(abstime >= GetRunInfo()->RUNHEADER_TIME &&abstime <= GetRunInfo()->RUNTRAILER_TIME)  )cout << "ABS TIME "<<abstime << " " <<GetRunInfo()->RUNTRAILER_TIME <<endl;
2589    //          if( !(obt >= GetRunInfo()->RUNHEADER_OBT && obt <= GetRunInfo()->RUNTRAILER_OBT) )cout << "OBT TIME "<< obt <<" "<< GetRunInfo()->RUNTRAILER_OBT << endl;
2590    //          if( GetRunInfo()->NEVENTS==0  )cout <<"GetRunInfo()->NEVENTS==0 "<<endl;
2591    //          if( !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) ) cout << "irunentry > "<<GetRunInfo()->NEVENTS-1-prevshift << endl;
2592                // - - - - - - - - - - - - -
2593                // irunentry = position of current entry, relative to the run
2594                // prevshift = shift needed to synchronize l0 and l2 data (nested events)
2595                // - - - - - - - - - - - - -
2596    
2597              // -----------------------------------------              // -----------------------------------------
2598              // store dead and live-time of previous run              // store dead and live-time of previous run
2599              // -----------------------------------------              // -----------------------------------------
2600    //          if(SELLI==0){
2601              if(fromfirst){              if(fromfirst){
2602                  if(oldrun==irun){                  if(oldrun==irun){
2603                      /// decrement counters                      /// decrement counters
# Line 2225  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2627  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2627                  }                  }
2628                  totdltime[2]=1;                             //event counter                  totdltime[2]=1;                             //event counter
2629              }              }
2630    //          }
2631    
2632                irun++;        
             irun++;  
2633              // ------------------------------------              // ------------------------------------
2634              // if the end of run tree is reached...              // if the end of run tree is reached...
2635              // ------------------------------------              // ------------------------------------
# Line 2255  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2657  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2657              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;              if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;
2658              irunentry = 0;              irunentry = 0;
2659              prevshift = 0;                        prevshift = 0;          
2660              run_tree->GetEntry(irun);                    run_tree->GetEntry(irun);//update runinfo
2661                irunt = irun - irunoffset[run_tree->GetTreeNumber()];
2662              if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){              if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){
2663                  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;
2664                  cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl;                  cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl;
# Line 2277  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2680  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2680          // --------------------------------------          // --------------------------------------
2681    
2682    
   
 //      // -----------------------------------------  
 //      // store dead and live-time of previous run  
 //      // -----------------------------------------  
 //      // --------------------------------------------------------------  
 //      // if the run is empty, fill the dead-live time branch with zeros  
 //      // --------------------------------------------------------------  
 //      /// if some runs have been jumped, fill with zeros  
 //      if(irun-oldrun>1){  
 //          ULong64_t  temp[3];  
 //          temp[0]=totdltime[0];  
 //          temp[1]=totdltime[1];  
 //          temp[2]=totdltime[2];  
 //          for(int i=oldrun+1; i<irun; irun++){  
 //              totdltime[0]=0;  
 //              totdltime[1]=0;  
 //              totdltime[2]=0;  
 //              cout << " ** JUMPED RUN **"<<endl;  
 //              if(run_tree_clone)  
 //                  if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())  
 //                      run_tree_clone->GetBranch("DeadLiveTime")->Fill();  
 //          }  
 //          totdltime[0]=temp[0];  
 //          totdltime[1]=temp[1];  
 //          totdltime[2]=temp[2];  
 //      }  
 //      /// decrement counters  
 //      if( GetTrigLevel2() ){  
 //          totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time  
 //          totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time  
 //      }  
 //      totdltime[2]--;                              //event counter  
 //      /// add an entry  
 //      if(irun>0 ){  
 //          cout << endl;  
 //          cout << "n.events     : "<<totdltime[2]<<endl;  
 //          cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;  
 //          cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;        
 //          if(run_tree_clone)  
 //              if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())  
 //                  run_tree_clone->GetBranch("DeadLiveTime")->Fill();  
 //      }  
 //      /// reset counters  
 //      if( GetTrigLevel2() ){  
 //          totdltime[0]=GetTrigLevel2()->dltime[0];//live-time  
 //          totdltime[1]=0;                         //dead-time  
 //      }  
 //      totdltime[2]=1;                             //event counter  
           
   
2683          // --------------------------------------          // --------------------------------------
2684          // ---> exit with TRUE          // ---> exit with TRUE
2685          // --------------------------------------          // --------------------------------------
# Line 2348  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2701  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2701      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2702      // if it is a preselected file (there is SelectionList)      // if it is a preselected file (there is SelectionList)
2703      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2704        // irun  = run entry relative to the chain
2705        // irunt = run entry relative to the tree
2706      if(SELLI==1){            if(SELLI==1){      
2707          sel_tree->GetEntry(iev);          sel_tree->GetEntry(iev);// read irunt from SelectionList
2708          if(irun != oldrun){          irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
2709              run_tree->GetEntry(irun);          if(irun != oldrun ){
2710              cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;              if( irun < run_tree->GetEntries() )run_tree->GetEntry(irun);
2711                // check if the time is ok (with merged files it is not...)
2712                // if not loop over run and look for the proper entry
2713                bool SECONDO_GIRO=false;
2714                Long64_t irun_start   = irun;
2715                int      offset_start = irunoffset[sel_tree->GetTreeNumber()];
2716                while (
2717                    (
2718                        (
2719                            !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2720                              abstime <= GetRunInfo()->RUNTRAILER_TIME)
2721    //                      ||
2722    //                      !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2723    //                        obt <= GetRunInfo()->RUNTRAILER_OBT)
2724                            )
2725                        || GetRunInfo()->NEVENTS==0
2726                        )
2727    //              && irun < run_tree->GetEntries()
2728                    ){
2729    
2730                    if(DBG){
2731                        cout << " (test) ";
2732                        cout << " tree "<<sel_tree->GetTreeNumber();
2733                        cout << " irunt "<<irunt;
2734                        cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2735                        cout << " abs "<<abstime;
2736                        cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2737                        cout << " obt "<<obt;
2738                        cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2739                        cout << " *** JUMP RUN *** irun "<<irun;
2740    //              if(!SECONDO_GIRO)cout << " (don't worry)";
2741    //              else             cout << " (start worring...)";
2742                        cout << endl;
2743                    }
2744    //              irun++;
2745                    irunoffset[sel_tree->GetTreeNumber()]++;
2746                    irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW          
2747                    if(irun == run_tree->GetEntries() && SECONDO_GIRO){
2748    //              if(irun == irun_start ){
2749                        cout << " ...grrrvzzkhhhajsdkj!!!! "<<endl;
2750                        irunoffset[sel_tree->GetTreeNumber()] = offset_start;
2751                        return false;
2752                    }
2753                    if( irun >= run_tree->GetEntries() || irun < 0){
2754                        cout << "irun = "<<irun<<" >>  search from the beginning... <<"<<endl;
2755                        SECONDO_GIRO=true;
2756                        irun=0;
2757                        irunoffset[sel_tree->GetTreeNumber()]=-irunt;
2758                    }
2759                    run_tree->GetEntry(irun);
2760                }
2761    
2762    
2763                if(DBG){
2764                    cout << " (test) ";
2765                    cout << " tree "<<sel_tree->GetTreeNumber();
2766                    cout << " irunt "<<irunt;
2767                    cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];
2768                    cout << " abs "<<abstime;
2769                    cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;
2770                    cout << " obt "<<obt;
2771                    cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;
2772                }
2773                cout << endl;
2774                cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" (run-entry "<<irun<<")"<<endl;
2775    //          cout << endl;
2776              prevshift = 0;              prevshift = 0;
2777              return true;              return true;
2778          }          }
# Line 2368  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2788  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2788   * @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
2789   */   */
2790  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){
2791    return(UpdateRunInfo((TChain*)run,iev));      return(UpdateRunInfo((TChain*)run,iev));
2792  };  };
2793    
2794  //--------------------------------------  //--------------------------------------
# Line 2378  Bool_t PamLevel2::UpdateRunInfo(TTree *r Line 2798  Bool_t PamLevel2::UpdateRunInfo(TTree *r
2798  /**  /**
2799   * Set which trees shoul be analysed   * Set which trees shoul be analysed
2800   * @param detlist TString containing the sequence of trees required   * @param detlist TString containing the sequence of trees required
2801  */   */
2802  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist){
2803                
2804      if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){  //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
2805          CAL0 = false;      if( detlist.Contains("+ALL", TString::kIgnoreCase)){
2806    
2807            cout << " ======================================================== "<<endl;
2808            cout << "                       (( WARNING ))                      "<<endl;
2809            cout << " The meaning of the option +ALL has changed!!             "<<endl;
2810            cout << " Now it includes really all (level0+level1+level2+gpamela)"<<endl;
2811            cout << " and the file is discarded if it does not contain         "<<endl;
2812            cout << " all trees or  if level0 files are not available!!        "<<endl;
2813            cout << " ======================================================== "<<endl;
2814                
2815            CAL0 = true;
2816          CAL1 = true;          CAL1 = true;
2817          CAL2 = true;          CAL2 = true;
2818          TRK2 = true;          TRK2 = true;
2819          TRK1 = false;          TRK1 = true;
2820          TRKh = false;          TRKh = true;
2821          TRK0 = false;          TRK0 = true;
2822          TRG = true;          TRG = true;
2823          TOF = true;          TOF = true;
2824          TOF0 = false;          TOF0 = true;
2825          S4  = true;          S4  = true;
2826          ND  = true;          ND  = true;
2827          AC  = true;          AC  = true;
2828          ORB = true;          ORB = true;
2829            GP  = true;
2830      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
2831          CAL0 = false;          CAL0 = false;
2832          CAL1 = false;          CAL1 = false;
# Line 2411  void PamLevel2::SetWhichTrees(TString de Line 2842  void PamLevel2::SetWhichTrees(TString de
2842          ND  = false;          ND  = false;
2843          AC  = false;          AC  = false;
2844          ORB = false;          ORB = false;
2845            GP  = false;
2846      };      };
2847            
2848  //  -------------------------------------------------------------------------  //  -------------------------------------------------------------------------
# Line 2484  void PamLevel2::SetWhichTrees(TString de Line 2916  void PamLevel2::SetWhichTrees(TString de
2916      if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;      if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;
2917      else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;      else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;
2918    
2919        if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false;
2920        else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true;
2921    
2922        cout<< "tree/branch list from input --> ";
2923        if(TRK0)cout<<"TRK0 ";
2924        if(TRK1)cout<<"TRK1 ";
2925        if(TRK2)cout<<"TRK2 ";
2926        if(TRKh)cout<<"TRKH ";
2927        if(CAL0)cout<<"CAL0 ";
2928        if(CAL1)cout<<"CAL1 ";
2929        if(CAL2)cout<<"CAL2 ";
2930        if(TOF)cout<<"TOF ";
2931        if(TRG)cout<<"TRG ";
2932        if(AC)cout<<"AC ";
2933        if(ND)cout<<"ND ";
2934        if(S4)cout<<"S4 ";
2935        if(ORB)cout<<"ORB ";
2936        if(GP)cout<<"GP ";
2937        cout << endl;
2938  //     cout<< "Set detector list --> ";  //     cout<< "Set detector list --> ";
2939  //     if(TRK1)cout<<"TRK1 ";  //     if(TRK1)cout<<"TRK1 ";
2940  //     if(TRK2)cout<<"TRK2 ";  //     if(TRK2)cout<<"TRK2 ";
2941  //     if(TRKh)cout<<"TRKH ";  //     if(TRKh)cout<<"TRKH ";
2942  //     if(CAL1)cout<<"CAL1 ";  //     if(CAL1)cout<<"CAL1 ";
2943  //     if(CAL2)cout<<"CAL2 ";  //     if(CAL2)cout<<"CAL2 ";
2944    //     if(TOF0)cout<<"TOF0 ";
2945  //     if(TOF)cout<<"TOF ";  //     if(TOF)cout<<"TOF ";
2946  //     if(TRG)cout<<"TRG ";  //     if(TRG)cout<<"TRG ";
2947  //     if(AC)cout<<"AC ";  //     if(AC)cout<<"AC ";
# Line 2508  void  PamLevel2::GetWhichTrees(TFile* f) Line 2960  void  PamLevel2::GetWhichTrees(TFile* f)
2960            
2961    
2962    
2963      cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;  //    cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
2964      // -----------      // -----------
2965      // reset flags      // reset flags
2966      // -----------      // -----------
# Line 2523  void  PamLevel2::GetWhichTrees(TFile* f) Line 2975  void  PamLevel2::GetWhichTrees(TFile* f)
2975      ND     = false;          ND     = false;    
2976      AC     = false;          AC     = false;    
2977      ORB    = false;          ORB    = false;    
2978        GP     = false;    
2979            
2980      RUN    = false;      RUN    = false;
2981                    
2982      cout << "Checking file: "<<f->GetName()<<endl;  //    cout << "Checking file: "<<f->GetName()<<endl;
2983      if( !f || f->IsZombie() ){      if( !f || f->IsZombie() ){
2984          cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;          cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;
2985          return;          return;
# Line 2613  void  PamLevel2::GetWhichTrees(TFile* f) Line 3066  void  PamLevel2::GetWhichTrees(TFile* f)
3066                  TRK2 = false;                  TRK2 = false;
3067                  TRKh = false;                  TRKh = false;
3068              }else nev=nevt;              }else nev=nevt;
3069              T->Delete();  //          T->Delete();
3070          };          };
3071          //=========================================================            //=========================================================  
3072          if( !strcmp(key->GetName(),"Calorimeter"    ) ){          if( !strcmp(key->GetName(),"Calorimeter"    ) ){
# Line 2629  void  PamLevel2::GetWhichTrees(TFile* f) Line 3082  void  PamLevel2::GetWhichTrees(TFile* f)
3082                  CAL1 = false;                  CAL1 = false;
3083                  CAL2 = false;                  CAL2 = false;
3084              }else nev=nevt;              }else nev=nevt;
3085              T->Delete();  //          T->Delete();
3086          };                };      
3087            //=========================================================  
3088            if( !strcmp(key->GetName(),"h20") ){
3089                GP = true;
3090                Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();
3091                if( nev && nevt!=nev){
3092                    cout << "File: "<< f->GetName() <<" h20 tree has "<<nevt<<" events instead of "<<nev<< endl;
3093                    GP = false;
3094                }else nev=nevt;
3095            }
3096    
3097      };      };
3098            
3099      delete lk;  //    delete lk;
3100    
3101  //     cout<< "Get detector list from input file --> ";      cout<< "tree/branch list from file  --> ";
3102  //     if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
3103  //     if(TRK2)cout<<"TRK2 ";      if(TRK2)cout<<"TRK2 ";
3104  //     if(TRKh)cout<<"TRKH ";      if(TRKh)cout<<"TRKH ";
3105  //     if(CAL1)cout<<"CAL1 ";      if(CAL1)cout<<"CAL1 ";
3106  //     if(CAL2)cout<<"CAL2 ";      if(CAL2)cout<<"CAL2 ";
3107  //     if(TOF)cout<<"TOF ";      if(TOF)cout<<"TOF ";
3108  //     if(TRG)cout<<"TRG ";      if(TRG)cout<<"TRG ";
3109  //     if(AC)cout<<"AC ";      if(AC)cout<<"AC ";
3110  //     if(ND)cout<<"ND ";      if(ND)cout<<"ND ";
3111  //     if(S4)cout<<"S4 ";      if(S4)cout<<"S4 ";
3112  //     if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
3113  //     cout << endl;      if(GP)cout<<"GP ";
3114        cout << endl;
3115                
3116      return ;      return ;
3117                    
# Line 2677  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3140  Bool_t  PamLevel2::CheckLevel2File(TStri
3140      Bool_t ND__ok     = false;          Bool_t ND__ok     = false;    
3141      Bool_t AC__ok     = false;          Bool_t AC__ok     = false;    
3142      Bool_t ORB__ok    = false;          Bool_t ORB__ok    = false;    
3143        Bool_t GP__ok     = false;    
3144            
3145      Bool_t RUN__ok    = false;      Bool_t RUN__ok    = false;
3146            
3147      Bool_t SELLI__ok  = false;      Bool_t SELLI__ok  = false;
3148    
3149      cout << "Checking file: "<<name<<endl;  //    cout << "Checking file: "<<name<<endl;
3150      TFile *f = new TFile(name.Data());      TFile *f = new TFile(name.Data());
3151      if( !f || f->IsZombie() ){      if( !f || f->IsZombie() ){
3152          cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false;          cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false;
# Line 2708  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3172  Bool_t  PamLevel2::CheckLevel2File(TStri
3172  //          return false;  //          return false;
3173  //      };  //      };
3174    
3175            //=========================================================    
3176            // check if the file
3177            
3178    
3179          if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;                if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;      
3180    
# Line 2834  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3301  Bool_t  PamLevel2::CheckLevel2File(TStri
3301              };                  };    
3302              T->Delete();              T->Delete();
3303          };                };      
3304            //=========================================================    
3305            if( !strcmp(key->GetName(),"h20") ){
3306                ISGP = true;    
3307                GP__ok = true;
3308                if(GP){
3309                    Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();
3310                    if( nev && nevt!=nev){
3311                        cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
3312                        return false;
3313                    }
3314                    nev=nevt;
3315                }
3316            }
3317    
3318      };      };
3319    
# Line 2874  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3354  Bool_t  PamLevel2::CheckLevel2File(TStri
3354    
3355    
3356      if(!RUN__ok) {      if(!RUN__ok) {
3357          cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree"<< endl;          cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree (NB: RUN infos will not be updated)"<< endl;
3358  //      return false;          RUN = false;
3359      };      };
3360    
3361      if(CAL1 && !CAL1__ok){      if(CAL1 && !CAL1__ok){
# Line 2923  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3403  Bool_t  PamLevel2::CheckLevel2File(TStri
3403          cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;          cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;
3404          return false;          return false;
3405      };      };
3406        if(GP && !GP__ok){
3407            cout << "File: "<< f->GetName() <<" discarded ---- Missing h20 tree"<< endl;
3408            return false;
3409        };
3410            
3411    
3412  //    lk->Delete();  //    lk->Delete();
# Line 2941  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3425  Bool_t  PamLevel2::CheckLevel2File(TStri
3425  //     if(ND)cout<<"ND ";  //     if(ND)cout<<"ND ";
3426  //     if(S4)cout<<"S4 ";  //     if(S4)cout<<"S4 ";
3427  //     if(ORB)cout<<"ORB ";  //     if(ORB)cout<<"ORB ";
3428    //     if(GP)cout<<"GP ";
3429  //     cout << endl;  //     cout << endl;
3430                
3431      return true;      return true;
# Line 2993  void PamLevel2::CreateCloneTrees(TFile * Line 3478  void PamLevel2::CreateCloneTrees(TFile *
3478    
3479    
3480  //  if the pointer is null, create a default file  //  if the pointer is null, create a default file
3481        if(!run_tree)return;
3482    
3483      if(!ofile){      if(!ofile){
3484          cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;          cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;
# Line 3013  void PamLevel2::CreateCloneTrees(TFile * Line 3499  void PamLevel2::CreateCloneTrees(TFile *
3499      // ------------------      // ------------------
3500      // replicate run tree      // replicate run tree
3501      // ------------------      // ------------------
3502      cout << "----------------------------------------------------"<<endl;  //    cout << "----------------------------------------------------"<<endl;
3503      cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;  //    cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
3504      for (Int_t i=0; i<run_tree->GetEntries(); i++){      for (Int_t i=0; i<run_tree->GetEntries(); i++){
3505          run_tree->GetEntry(i);          run_tree->GetEntry(i);
3506          cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;  //      cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;
3507          run_tree_clone->Fill();          run_tree_clone->Fill();
3508      }      }
3509      cout << "----------------------------------------------------"<<endl;      cout << "----------------------------------------------------"<<endl;
# Line 3030  void PamLevel2::CreateCloneTrees(TFile * Line 3516  void PamLevel2::CreateCloneTrees(TFile *
3516    
3517    
3518      sel_tree_clone = new TTree("SelectionList","List of selected events ");      sel_tree_clone = new TTree("SelectionList","List of selected events ");
3519      sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");  //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
3520        sel_tree_clone->Branch("RunEntry",&irunt,"runentry/L");//NEWNEW
3521      sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");      sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");
3522            
3523    
# Line 3110  void PamLevel2::CreateCloneTrees(TFile * Line 3597  void PamLevel2::CreateCloneTrees(TFile *
3597          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
3598          i++;          i++;
3599      };      };
3600        // GPamela
3601        if(GP) {
3602            pam_tree_clone[i] = new TTree("h20","PAMELA oribital info  ");  
3603            pam_tree_clone[i]->Branch("GPamela","GPamela", GetPointerTo("GPamela"),32000,1);//split
3604            cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
3605            i++;
3606        };
3607      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
3608    
3609  }  }
# Line 3200  Int_t PamLevel2::GetEntry(Long64_t iee){ Line 3694  Int_t PamLevel2::GetEntry(Long64_t iee){
3694          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;
3695          return 0;          return 0;
3696      }      }
3697    
3698      //      //
3699      // ... 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.
3700      // 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
3701      // a problem if you don't check the return code of getentry.      // a problem if you don't check the return code of getentry.
3702      //      //
3703      if(!run_tree ){      if(!RUN || !run_tree ){
3704          if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?          if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?
3705              cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;              cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
3706              return 0;              return 0;
# Line 3290  TTree* PamLevel2::GetYodaTree( ){ Line 3785  TTree* PamLevel2::GetYodaTree( ){
3785          // open the DB connection          // open the DB connection
3786          // (if not already opened)          // (if not already opened)
3787          //===================================          //===================================
3788          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;  
         }  
3789          GL_ROOT glroot = GL_ROOT();          GL_ROOT glroot = GL_ROOT();
3790          if( glroot.Query_GL_ROOT(iroot,dbc) ){          if( glroot.Query_GL_ROOT(iroot,dbc) ){
3791              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 3351  TTree* PamLevel2::GetYodaTree( ){ Line 3833  TTree* PamLevel2::GetYodaTree( ){
3833              cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;              cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
3834          }          }
3835    
3836            dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
3837    
3838    
3839      };      };
3840    
3841      if(!dbc || (dbc && !dbc->IsConnected())){  //     if(!dbc || (dbc && !dbc->IsConnected())){
3842          cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;  //      cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;
3843      }  //     }
3844    
3845      if ( TRK0 ){      if ( TRK0 ){
3846          TrkParams::Load(6);          TrkParams::Load(6);
3847          if( !TrkParams::IsLoaded(6) ){          if( !TrkParams::IsLoaded(6) ){
3848              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;
3849          };          };
3850            if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
3851          TrkParams::SetCalib(run_obj,dbc);          TrkParams::SetCalib(run_obj,dbc);
3852          TrkParams::LoadCalib( );          TrkParams::LoadCalib( );
3853          if( !TrkParams::CalibIsLoaded() ){          if( !TrkParams::CalibIsLoaded() ){
3854              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;              cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;
3855          };          };
3856            dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
3857      }      }
3858    
3859    
3860  //    cout << l0_tree << endl;  //    cout << l0_tree << endl;
       
3861      return l0_tree;      return l0_tree;
3862    
3863  }  }
# Line 3431  Int_t PamLevel2::GetYodaEntry(){ Line 3918  Int_t PamLevel2::GetYodaEntry(){
3918      Int_t answer = 0;      Int_t answer = 0;
3919      Int_t shift =0;      Int_t shift =0;
3920      //    printf(" siamo qui %i %i \n",shift,prevshift);      //    printf(" siamo qui %i %i \n",shift,prevshift);
3921      Int_t maxshift = 10;      //    Int_t maxshift = 50; // EMILIANO
3922      do{      do{
3923          if(shift>0){              if(shift>0){    
3924              cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;              cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
# Line 3460  Int_t PamLevel2::GetYodaEntry(){ Line 3947  Int_t PamLevel2::GetYodaEntry(){
3947  //      printf(" IDRUN %u \n",GetRunInfo()->ID);  //      printf(" IDRUN %u \n",GetRunInfo()->ID);
3948  //  //
3949          if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){          if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){
3950            prevshift = 0;              prevshift = 0;
3951            shift = -1;              shift = -1;
3952          };          };
3953    
3954      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||
# Line 3484  Int_t PamLevel2::GetYodaEntry(){ Line 3971  Int_t PamLevel2::GetYodaEntry(){
3971   */   */
3972  Bool_t PamLevel2::SetDBConnection(){  Bool_t PamLevel2::SetDBConnection(){
3973    
3974      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;      if(DBG){
3975      cout<<"Connecting to DB"<<endl;          cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3976      cout<<"HOST "<<host<<endl;          cout<<"Connecting to DB"<<endl;
3977      cout<<"USER "<<user<<endl;          cout<<"HOST "<<host<<endl;
3978      cout<<"PSW  "<<psw<<endl;          cout<<"USER "<<user<<endl;
3979            cout<<"PSW  "<<psw<<endl;
3980        }
3981      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
3982      if( !dbc )return false;      if( !dbc )return false;
3983      if( !dbc->IsConnected() )return false;          if( !dbc->IsConnected() )return false;    
3984      cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;      stringstream myquery;  // EMILIANO
3985        myquery.str("");  // EMILIANO
3986        myquery << "SET time_zone='+0:00'";  // EMILIANO
3987        dbc->Query(myquery.str().c_str());  // EMILIANO
3988        if(DBG)cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
3989      return true;      return true;
3990    
3991  }  }
# Line 3529  TChain* PamLevel2::AddFriend(TString cna Line 4022  TChain* PamLevel2::AddFriend(TString cna
4022      return c;          return c;    
4023    
4024  }  }
4025    
4026    

Legend:
Removed from v.1.48  
changed lines
  Added in v.1.62

  ViewVC Help
Powered by ViewVC 1.1.23