/[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.80 by pam-fi, Wed Mar 25 14:42:36 2009 UTC revision 1.81 by pam-fi, Wed Apr 1 09:25:04 2009 UTC
# Line 1  Line 1 
1  #include <PamLevel2.h>  #include <PamLevel2.h>
2    
   
   
3  /////////////////////////////////////////////////////////////////////////////  /////////////////////////////////////////////////////////////////////////////
4  /////////////////////////////////////////////////////////////////////////////  /////////////////////////////////////////////////////////////////////////////
5  /////////////////////////////////////////////////////////////////////////////  /////////////////////////////////////////////////////////////////////////////
6  /////////////////////////////////////////////////////////////////////////////  /////////////////////////////////////////////////////////////////////////////
7    
8  void GPamela::Clear(){  void GPamela::Clear() {
9      Irun   = 0;    Irun = 0;
10      Ievnt  = 0;    Ievnt = 0;
11      Ipa    = 0;    Ipa = 0;
12      X0     = 0.;    X0 = 0.;
13      Y0     = 0.;    Y0 = 0.;
14      Z0     = 0.;    Z0 = 0.;
15      Theta  = 0.;    Theta = 0.;
16      Phi    = 0.;    Phi = 0.;
17      P0     = 0.;    P0 = 0.;
18      Nthtof  = 0;    Nthtof = 0;
19      Nthcat  = 0;    Nthcat = 0;
20      Nthcas  = 0;    Nthcas = 0;
21      Nthspe  = 0;    Nthspe = 0;
22      Nstrpx  = 0;    Nstrpx = 0;
23      Nstrpy  = 0;    Nstrpy = 0;
24      Nthcali = 0;    Nthcali = 0;
25      Nthcal  = 0;    Nthcal = 0;
26      Nthnd   = 0;    Nthnd = 0;
27      Nthcard = 0;    Nthcard = 0;
28  }  }
29    
30  void GPamela::Delete(){  void GPamela::Delete() {
31    
32      Clear();    Clear();
33    
34      delete[] Ipltof;
35      delete[] Ipaddle;
36      delete[] Ipartof;
37      delete[] Xintof;
38      delete[] Yintof;
39      delete[] Zintof;
40      delete[] Xouttof;
41      delete[] Youttof;
42      delete[] Zouttof;
43      delete[] Ereltof;
44      delete[] Timetof;
45      delete[] Pathtof;
46      delete[] P0tof;
47      delete[] Iparcat;
48      delete[] Icat;
49      delete[] Xincat;
50      delete[] Yincat;
51      delete[] Zincat;
52      delete[] Xoutcat;
53      delete[] Youtcat;
54      delete[] Zoutcat;
55      delete[] Erelcat;
56      delete[] Timecat;
57      delete[] Pathcat;
58      delete[] P0cat;
59      delete[] Iparcas;
60      delete[] Icas;
61      delete[] Xincas;
62      delete[] Yincas;
63      delete[] Zincas;
64      delete[] Xoutcas;
65      delete[] Youtcas;
66      delete[] Zoutcas;
67      delete[] Erelcas;
68      delete[] Timecas;
69      delete[] Pathcas;
70      delete[] P0cas;
71      delete[] Iparspe;
72      delete[] Itrpb;
73      delete[] Itrsl;
74      delete[] Itspa;
75      delete[] Xinspe;
76      delete[] Yinspe;
77      delete[] Zinspe;
78      delete[] Xoutspe;
79      delete[] Youtspe;
80      delete[] Zoutspe;
81      delete[] Xavspe;
82      delete[] Yavspe;
83      delete[] Zavspe;
84      delete[] Erelspe;
85      delete[] Pathspe;
86      delete[] P0spe;
87      delete[] Nxmult;
88      delete[] Nymult;
89      delete[] Npstripx;
90      delete[] Ntstripx;
91      delete[] Istripx;
92      delete[] Qstripx;
93      delete[] Xstripx;
94      delete[] Npstripy;
95      delete[] Ntstripy;
96      delete[] Istripy;
97      delete[] Qstripy;
98      delete[] Ystripy;
99      delete[] Icaplane;
100      delete[] Icastrip;
101      delete[] Icamod;
102      delete[] Enestrip;
103      delete[] Icapl;
104      delete[] Icasi;
105      delete[] Icast;
106      delete[] Xincal;
107      delete[] Yincal;
108      delete[] Zincal;
109      delete[] Erelcal;
110      delete[] Itubend;
111      delete[] Iparnd;
112      delete[] Xinnd;
113      delete[] Yinnd;
114      delete[] Zinnd;
115      delete[] Xoutnd;
116      delete[] Youtnd;
117      delete[] Zoutnd;
118      delete[] Erelnd;
119      delete[] Timend;
120      delete[] Pathnd;
121      delete[] P0nd;
122      delete[] Iparcard;
123      delete[] Icard;
124      delete[] Xincard;
125      delete[] Yincard;
126      delete[] Zincard;
127      delete[] Xoutcard;
128      delete[] Youtcard;
129      delete[] Zoutcard;
130      delete[] Erelcard;
131      delete[] Timecard;
132      delete[] Pathcard;
133      delete[] P0card;
134    
135      delete []    Ipltof;    }
136      delete []    Ipaddle;  ;
137      delete []    Ipartof;  
138      delete []    Xintof;    void GPamela::SetBranchAddress(TChain* fhBookTree) {
     delete []    Yintof;    
     delete []    Zintof;    
     delete []    Xouttof;  
     delete []    Youttof;  
     delete []    Zouttof;  
     delete []    Ereltof;  
     delete []    Timetof;  
     delete []    Pathtof;  
     delete []    P0tof;    
     delete []    Iparcat;  
     delete []    Icat;    
     delete []    Xincat;    
     delete []    Yincat;    
     delete []    Zincat;    
     delete []    Xoutcat;  
     delete []    Youtcat;  
     delete []    Zoutcat;  
     delete []    Erelcat;  
     delete []    Timecat;  
     delete []    Pathcat;  
     delete []    P0cat;    
     delete []    Iparcas;  
     delete []    Icas;    
     delete []    Xincas;    
     delete []    Yincas;    
     delete []    Zincas;    
     delete []    Xoutcas;  
     delete []    Youtcas;  
     delete []    Zoutcas;  
     delete []    Erelcas;  
     delete []    Timecas;  
     delete []    Pathcas;  
     delete []    P0cas;    
     delete []    Iparspe;  
     delete []    Itrpb;    
     delete []    Itrsl;    
     delete []    Itspa;    
     delete []    Xinspe;    
     delete []    Yinspe;    
     delete []    Zinspe;    
     delete []    Xoutspe;  
     delete []    Youtspe;  
     delete []    Zoutspe;  
     delete []    Xavspe;    
     delete []    Yavspe;    
     delete []    Zavspe;    
     delete []    Erelspe;  
     delete []    Pathspe;  
     delete []    P0spe;    
     delete []    Nxmult;    
     delete []    Nymult;    
     delete []    Npstripx;  
     delete []    Ntstripx;  
     delete []    Istripx;  
     delete []    Qstripx;  
     delete []    Xstripx;  
     delete []    Npstripy;  
     delete []    Ntstripy;  
     delete []    Istripy;  
     delete []    Qstripy;  
     delete []    Ystripy;  
     delete []    Icaplane;  
     delete []    Icastrip;  
     delete []    Icamod;    
     delete []    Enestrip;  
     delete []    Icapl;    
     delete []    Icasi;    
     delete []    Icast;    
     delete []    Xincal;    
     delete []    Yincal;    
     delete []    Zincal;    
     delete []    Erelcal;  
     delete []    Itubend;  
     delete []    Iparnd;    
     delete []    Xinnd;    
     delete []    Yinnd;    
     delete []    Zinnd;    
     delete []    Xoutnd;    
     delete []    Youtnd;    
     delete []    Zoutnd;    
     delete []    Erelnd;    
     delete []    Timend;    
     delete []    Pathnd;    
     delete []    P0nd;    
     delete []    Iparcard;  
     delete []    Icard;    
     delete []    Xincard;  
     delete []    Yincard;  
     delete []    Zincard;  
     delete []    Xoutcard;  
     delete []    Youtcard;  
     delete []    Zoutcard;  
     delete []    Erelcard;  
     delete []    Timecard;  
     delete []    Pathcard;  
     delete []    P0card;    
   
   
 };  
   
   
   
 void GPamela::SetBranchAddress( TChain* fhBookTree ){  
   
 //    cout << "fhBookTree "<<fhBookTree << endl;  
     // prepare tree  
     fhBookTree->SetBranchAddress("Irun",&Irun);  
     fhBookTree->SetBranchAddress("Ievnt",&Ievnt);  
     fhBookTree->SetBranchAddress("Ipa",&Ipa);  
     fhBookTree->SetBranchAddress("X0",&X0);  
     fhBookTree->SetBranchAddress("Y0",&Y0);  
     fhBookTree->SetBranchAddress("Z0",&Z0);  
     fhBookTree->SetBranchAddress("Theta",&Theta);  
     fhBookTree->SetBranchAddress("Phi",&Phi);  
     fhBookTree->SetBranchAddress("P0",&P0);  
     fhBookTree->SetBranchAddress("Nthtof",&Nthtof);  
     fhBookTree->SetBranchAddress("Ipltof",Ipltof);  
     fhBookTree->SetBranchAddress("Ipaddle",Ipaddle);  
     fhBookTree->SetBranchAddress("Ipartof",Ipartof);  
     fhBookTree->SetBranchAddress("Xintof",Xintof);  
     fhBookTree->SetBranchAddress("Yintof",Yintof);  
     fhBookTree->SetBranchAddress("Zintof",Zintof);  
     fhBookTree->SetBranchAddress("Xouttof",Xouttof);  
     fhBookTree->SetBranchAddress("Youttof",Youttof);  
     fhBookTree->SetBranchAddress("Zouttof",Zouttof);  
     fhBookTree->SetBranchAddress("Ereltof",Ereltof);  
     fhBookTree->SetBranchAddress("Timetof",Timetof);  
     fhBookTree->SetBranchAddress("Pathtof",Pathtof);  
     fhBookTree->SetBranchAddress("P0tof",P0tof);  
     fhBookTree->SetBranchAddress("Nthcat",&Nthcat);  
     fhBookTree->SetBranchAddress("Iparcat",Iparcat);  
     fhBookTree->SetBranchAddress("Icat",Icat);  
     fhBookTree->SetBranchAddress("Xincat",Xincat);  
     fhBookTree->SetBranchAddress("Yincat",Yincat);  
     fhBookTree->SetBranchAddress("Zincat",Zincat);  
     fhBookTree->SetBranchAddress("Xoutcat",Xoutcat);  
     fhBookTree->SetBranchAddress("Youtcat",Youtcat);  
     fhBookTree->SetBranchAddress("Zoutcat",Zoutcat);  
     fhBookTree->SetBranchAddress("Erelcat",Erelcat);  
     fhBookTree->SetBranchAddress("Timecat",Timecat);  
     fhBookTree->SetBranchAddress("Pathcat",Pathcat);  
     fhBookTree->SetBranchAddress("P0cat",P0cat);  
     fhBookTree->SetBranchAddress("Nthcas",&Nthcas);  
     fhBookTree->SetBranchAddress("Iparcas",Iparcas);  
     fhBookTree->SetBranchAddress("Icas",Icas);  
     fhBookTree->SetBranchAddress("Xincas",Xincas);  
     fhBookTree->SetBranchAddress("Yincas",Yincas);  
     fhBookTree->SetBranchAddress("Zincas",Zincas);  
     fhBookTree->SetBranchAddress("Xoutcas",Xoutcas);  
     fhBookTree->SetBranchAddress("Youtcas",Youtcas);  
     fhBookTree->SetBranchAddress("Zoutcas",Zoutcas);  
     fhBookTree->SetBranchAddress("Erelcas",Erelcas);  
     fhBookTree->SetBranchAddress("Timecas",Timecas);  
     fhBookTree->SetBranchAddress("Pathcas",Pathcas);  
     fhBookTree->SetBranchAddress("P0cas",P0cas);  
     fhBookTree->SetBranchAddress("Nthspe",&Nthspe);  
     fhBookTree->SetBranchAddress("Iparspe",Iparspe);  
     fhBookTree->SetBranchAddress("Itrpb",Itrpb);  
     fhBookTree->SetBranchAddress("Itrsl",Itrsl);  
     fhBookTree->SetBranchAddress("Itspa",Itspa);  
     fhBookTree->SetBranchAddress("Xinspe",Xinspe);  
     fhBookTree->SetBranchAddress("Yinspe",Yinspe);  
     fhBookTree->SetBranchAddress("Zinspe",Zinspe);  
     fhBookTree->SetBranchAddress("Xoutspe",Xoutspe);  
     fhBookTree->SetBranchAddress("Youtspe",Youtspe);  
     fhBookTree->SetBranchAddress("Zoutspe",Zoutspe);  
     fhBookTree->SetBranchAddress("Xavspe",Xavspe);  
     fhBookTree->SetBranchAddress("Yavspe",Yavspe);  
     fhBookTree->SetBranchAddress("Zavspe",Zavspe);  
     fhBookTree->SetBranchAddress("Erelspe",Erelspe);  
     fhBookTree->SetBranchAddress("Pathspe",Pathspe);  
     fhBookTree->SetBranchAddress("P0spe",P0spe);  
     fhBookTree->SetBranchAddress("Nxmult",Nxmult);  
     fhBookTree->SetBranchAddress("Nymult",Nymult);  
     fhBookTree->SetBranchAddress("Nstrpx",&Nstrpx);  
     fhBookTree->SetBranchAddress("Npstripx",Npstripx);  
     fhBookTree->SetBranchAddress("Ntstripx",Ntstripx);  
     fhBookTree->SetBranchAddress("Istripx",Istripx);  
     fhBookTree->SetBranchAddress("Qstripx",Qstripx);  
     fhBookTree->SetBranchAddress("Xstripx",Xstripx);  
     fhBookTree->SetBranchAddress("Nstrpy",&Nstrpy);  
     fhBookTree->SetBranchAddress("Npstripy",Npstripy);  
     fhBookTree->SetBranchAddress("Ntstripy",Ntstripy);  
     fhBookTree->SetBranchAddress("Istripy",Istripy);  
     fhBookTree->SetBranchAddress("Qstripy",Qstripy);  
     fhBookTree->SetBranchAddress("Ystripy",Ystripy);  
     fhBookTree->SetBranchAddress("Nthcali",&Nthcali);  
     fhBookTree->SetBranchAddress("Icaplane",Icaplane);  
     fhBookTree->SetBranchAddress("Icastrip",Icastrip);  
     fhBookTree->SetBranchAddress("Icamod",Icamod);  
     fhBookTree->SetBranchAddress("Enestrip",Enestrip);  
     fhBookTree->SetBranchAddress("Nthcal",&Nthcal);  
     fhBookTree->SetBranchAddress("Icapl",Icapl);  
     fhBookTree->SetBranchAddress("Icasi",Icasi);  
     fhBookTree->SetBranchAddress("Icast",Icast);  
     fhBookTree->SetBranchAddress("Xincal",Xincal);  
     fhBookTree->SetBranchAddress("Yincal",Yincal);  
     fhBookTree->SetBranchAddress("Zincal",Zincal);  
     fhBookTree->SetBranchAddress("Erelcal",Erelcal);  
     fhBookTree->SetBranchAddress("Nthnd",&Nthnd);  
     fhBookTree->SetBranchAddress("Itubend",Itubend);  
     fhBookTree->SetBranchAddress("Iparnd",Iparnd);  
     fhBookTree->SetBranchAddress("Xinnd",Xinnd);  
     fhBookTree->SetBranchAddress("Yinnd",Yinnd);  
     fhBookTree->SetBranchAddress("Zinnd",Zinnd);  
     fhBookTree->SetBranchAddress("Xoutnd",Xoutnd);  
     fhBookTree->SetBranchAddress("Youtnd",Youtnd);  
     fhBookTree->SetBranchAddress("Zoutnd",Zoutnd);  
     fhBookTree->SetBranchAddress("Erelnd",Erelnd);  
     fhBookTree->SetBranchAddress("Timend",Timend);  
     fhBookTree->SetBranchAddress("Pathnd",Pathnd);  
     fhBookTree->SetBranchAddress("P0nd",P0nd);  
     fhBookTree->SetBranchAddress("Nthcard",&Nthcard);  
     fhBookTree->SetBranchAddress("Iparcard",Iparcard);  
     fhBookTree->SetBranchAddress("Icard",Icard);  
     fhBookTree->SetBranchAddress("Xincard",Xincard);  
     fhBookTree->SetBranchAddress("Yincard",Yincard);  
     fhBookTree->SetBranchAddress("Zincard",Zincard);  
     fhBookTree->SetBranchAddress("Xoutcard",Xoutcard);  
     fhBookTree->SetBranchAddress("Youtcard",Youtcard);  
     fhBookTree->SetBranchAddress("Zoutcard",Zoutcard);  
     fhBookTree->SetBranchAddress("Erelcard",Erelcard);  
     fhBookTree->SetBranchAddress("Timecard",Timecard);  
     fhBookTree->SetBranchAddress("Pathcard",Pathcard);  
     fhBookTree->SetBranchAddress("P0card",P0card);  
139    
140  //    fhBookTree->SetBranchStatus("*",0);    //    cout << "fhBookTree "<<fhBookTree << endl;
141      // prepare tree
142      fhBookTree->SetBranchAddress("Irun", &Irun);
143      fhBookTree->SetBranchAddress("Ievnt", &Ievnt);
144      fhBookTree->SetBranchAddress("Ipa", &Ipa);
145      fhBookTree->SetBranchAddress("X0", &X0);
146      fhBookTree->SetBranchAddress("Y0", &Y0);
147      fhBookTree->SetBranchAddress("Z0", &Z0);
148      fhBookTree->SetBranchAddress("Theta", &Theta);
149      fhBookTree->SetBranchAddress("Phi", &Phi);
150      fhBookTree->SetBranchAddress("P0", &P0);
151      fhBookTree->SetBranchAddress("Nthtof", &Nthtof);
152      fhBookTree->SetBranchAddress("Ipltof", Ipltof);
153      fhBookTree->SetBranchAddress("Ipaddle", Ipaddle);
154      fhBookTree->SetBranchAddress("Ipartof", Ipartof);
155      fhBookTree->SetBranchAddress("Xintof", Xintof);
156      fhBookTree->SetBranchAddress("Yintof", Yintof);
157      fhBookTree->SetBranchAddress("Zintof", Zintof);
158      fhBookTree->SetBranchAddress("Xouttof", Xouttof);
159      fhBookTree->SetBranchAddress("Youttof", Youttof);
160      fhBookTree->SetBranchAddress("Zouttof", Zouttof);
161      fhBookTree->SetBranchAddress("Ereltof", Ereltof);
162      fhBookTree->SetBranchAddress("Timetof", Timetof);
163      fhBookTree->SetBranchAddress("Pathtof", Pathtof);
164      fhBookTree->SetBranchAddress("P0tof", P0tof);
165      fhBookTree->SetBranchAddress("Nthcat", &Nthcat);
166      fhBookTree->SetBranchAddress("Iparcat", Iparcat);
167      fhBookTree->SetBranchAddress("Icat", Icat);
168      fhBookTree->SetBranchAddress("Xincat", Xincat);
169      fhBookTree->SetBranchAddress("Yincat", Yincat);
170      fhBookTree->SetBranchAddress("Zincat", Zincat);
171      fhBookTree->SetBranchAddress("Xoutcat", Xoutcat);
172      fhBookTree->SetBranchAddress("Youtcat", Youtcat);
173      fhBookTree->SetBranchAddress("Zoutcat", Zoutcat);
174      fhBookTree->SetBranchAddress("Erelcat", Erelcat);
175      fhBookTree->SetBranchAddress("Timecat", Timecat);
176      fhBookTree->SetBranchAddress("Pathcat", Pathcat);
177      fhBookTree->SetBranchAddress("P0cat", P0cat);
178      fhBookTree->SetBranchAddress("Nthcas", &Nthcas);
179      fhBookTree->SetBranchAddress("Iparcas", Iparcas);
180      fhBookTree->SetBranchAddress("Icas", Icas);
181      fhBookTree->SetBranchAddress("Xincas", Xincas);
182      fhBookTree->SetBranchAddress("Yincas", Yincas);
183      fhBookTree->SetBranchAddress("Zincas", Zincas);
184      fhBookTree->SetBranchAddress("Xoutcas", Xoutcas);
185      fhBookTree->SetBranchAddress("Youtcas", Youtcas);
186      fhBookTree->SetBranchAddress("Zoutcas", Zoutcas);
187      fhBookTree->SetBranchAddress("Erelcas", Erelcas);
188      fhBookTree->SetBranchAddress("Timecas", Timecas);
189      fhBookTree->SetBranchAddress("Pathcas", Pathcas);
190      fhBookTree->SetBranchAddress("P0cas", P0cas);
191      fhBookTree->SetBranchAddress("Nthspe", &Nthspe);
192      fhBookTree->SetBranchAddress("Iparspe", Iparspe);
193      fhBookTree->SetBranchAddress("Itrpb", Itrpb);
194      fhBookTree->SetBranchAddress("Itrsl", Itrsl);
195      fhBookTree->SetBranchAddress("Itspa", Itspa);
196      fhBookTree->SetBranchAddress("Xinspe", Xinspe);
197      fhBookTree->SetBranchAddress("Yinspe", Yinspe);
198      fhBookTree->SetBranchAddress("Zinspe", Zinspe);
199      fhBookTree->SetBranchAddress("Xoutspe", Xoutspe);
200      fhBookTree->SetBranchAddress("Youtspe", Youtspe);
201      fhBookTree->SetBranchAddress("Zoutspe", Zoutspe);
202      fhBookTree->SetBranchAddress("Xavspe", Xavspe);
203      fhBookTree->SetBranchAddress("Yavspe", Yavspe);
204      fhBookTree->SetBranchAddress("Zavspe", Zavspe);
205      fhBookTree->SetBranchAddress("Erelspe", Erelspe);
206      fhBookTree->SetBranchAddress("Pathspe", Pathspe);
207      fhBookTree->SetBranchAddress("P0spe", P0spe);
208      fhBookTree->SetBranchAddress("Nxmult", Nxmult);
209      fhBookTree->SetBranchAddress("Nymult", Nymult);
210      fhBookTree->SetBranchAddress("Nstrpx", &Nstrpx);
211      fhBookTree->SetBranchAddress("Npstripx", Npstripx);
212      fhBookTree->SetBranchAddress("Ntstripx", Ntstripx);
213      fhBookTree->SetBranchAddress("Istripx", Istripx);
214      fhBookTree->SetBranchAddress("Qstripx", Qstripx);
215      fhBookTree->SetBranchAddress("Xstripx", Xstripx);
216      fhBookTree->SetBranchAddress("Nstrpy", &Nstrpy);
217      fhBookTree->SetBranchAddress("Npstripy", Npstripy);
218      fhBookTree->SetBranchAddress("Ntstripy", Ntstripy);
219      fhBookTree->SetBranchAddress("Istripy", Istripy);
220      fhBookTree->SetBranchAddress("Qstripy", Qstripy);
221      fhBookTree->SetBranchAddress("Ystripy", Ystripy);
222      fhBookTree->SetBranchAddress("Nthcali", &Nthcali);
223      fhBookTree->SetBranchAddress("Icaplane", Icaplane);
224      fhBookTree->SetBranchAddress("Icastrip", Icastrip);
225      fhBookTree->SetBranchAddress("Icamod", Icamod);
226      fhBookTree->SetBranchAddress("Enestrip", Enestrip);
227      fhBookTree->SetBranchAddress("Nthcal", &Nthcal);
228      fhBookTree->SetBranchAddress("Icapl", Icapl);
229      fhBookTree->SetBranchAddress("Icasi", Icasi);
230      fhBookTree->SetBranchAddress("Icast", Icast);
231      fhBookTree->SetBranchAddress("Xincal", Xincal);
232      fhBookTree->SetBranchAddress("Yincal", Yincal);
233      fhBookTree->SetBranchAddress("Zincal", Zincal);
234      fhBookTree->SetBranchAddress("Erelcal", Erelcal);
235      fhBookTree->SetBranchAddress("Nthnd", &Nthnd);
236      fhBookTree->SetBranchAddress("Itubend", Itubend);
237      fhBookTree->SetBranchAddress("Iparnd", Iparnd);
238      fhBookTree->SetBranchAddress("Xinnd", Xinnd);
239      fhBookTree->SetBranchAddress("Yinnd", Yinnd);
240      fhBookTree->SetBranchAddress("Zinnd", Zinnd);
241      fhBookTree->SetBranchAddress("Xoutnd", Xoutnd);
242      fhBookTree->SetBranchAddress("Youtnd", Youtnd);
243      fhBookTree->SetBranchAddress("Zoutnd", Zoutnd);
244      fhBookTree->SetBranchAddress("Erelnd", Erelnd);
245      fhBookTree->SetBranchAddress("Timend", Timend);
246      fhBookTree->SetBranchAddress("Pathnd", Pathnd);
247      fhBookTree->SetBranchAddress("P0nd", P0nd);
248      fhBookTree->SetBranchAddress("Nthcard", &Nthcard);
249      fhBookTree->SetBranchAddress("Iparcard", Iparcard);
250      fhBookTree->SetBranchAddress("Icard", Icard);
251      fhBookTree->SetBranchAddress("Xincard", Xincard);
252      fhBookTree->SetBranchAddress("Yincard", Yincard);
253      fhBookTree->SetBranchAddress("Zincard", Zincard);
254      fhBookTree->SetBranchAddress("Xoutcard", Xoutcard);
255      fhBookTree->SetBranchAddress("Youtcard", Youtcard);
256      fhBookTree->SetBranchAddress("Zoutcard", Zoutcard);
257      fhBookTree->SetBranchAddress("Erelcard", Erelcard);
258      fhBookTree->SetBranchAddress("Timecard", Timecard);
259      fhBookTree->SetBranchAddress("Pathcard", Pathcard);
260      fhBookTree->SetBranchAddress("P0card", P0card);
261    
262      //    fhBookTree->SetBranchStatus("*",0);
263    
264  }  }
265    
266  ClassImp(GPamela);  ClassImp( GPamela);
267    
268  /////////////////////////////////////////////////////////////////////////////  /////////////////////////////////////////////////////////////////////////////
269  /////////////////////////////////////////////////////////////////////////////  /////////////////////////////////////////////////////////////////////////////
# Line 278  ClassImp(GPamela); Line 274  ClassImp(GPamela);
274  //  //
275  //--------------------------------------  //--------------------------------------
276  /**  /**
277   * Default constructor   * Default constructor
278   */   */
279  PamTrack::PamTrack(){  PamTrack::PamTrack() {
280      trk_track  = 0;    trk_track = 0;
281      calo_track = 0;    calo_track = 0;
282      tof_track  = 0;    tof_track = 0;
283      orb_track  = 0;    orb_track = 0;
284      candeleteobj = 0;    candeleteobj = 0;
285      pscore = 0;    pscore = 0;
286      iscore = 0;    iscore = 0;
287  };  }
288    ;
289  //--------------------------------------  //--------------------------------------
290  //  //
291  //  //
292  //--------------------------------------  //--------------------------------------
293  /**  /**
294   * Constructor   * Constructor
295   */   */
296  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o, OrbitalInfoTrkVar *r){  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o, OrbitalInfoTrkVar *r) {
297    
298      trk_track  = 0;    trk_track = 0;
299      calo_track = 0;    calo_track = 0;
300      tof_track  = 0;    tof_track = 0;
301      orb_track  = 0;    orb_track = 0;
302  //     if(t)trk_track  = new TrkTrack(*t);    //     if(t)trk_track  = new TrkTrack(*t);
303  //     if(c)calo_track = new CaloTrkVar(*c);    //     if(c)calo_track = new CaloTrkVar(*c);
304  //     if(o)tof_track  = new ToFTrkVar(*o);    //     if(o)tof_track  = new ToFTrkVar(*o);
305      if(t)trk_track  = t;    if (t)
306      if(c)calo_track = c;      trk_track = t;
307      if(o)tof_track  = o;    if (c)
308      if(r) orb_track  = r;      calo_track = c;
309      if (o)
310     candeleteobj = 0;      tof_track = o;
311      if (r)
312  };      orb_track = r;
313  PamTrack::PamTrack(const PamTrack& track){  
314      candeleteobj = 0;
315      TrkTrack   *t = track.trk_track;  
316      CaloTrkVar *c = track.calo_track;  }
317      ToFTrkVar  *o = track.tof_track;  ;
318      OrbitalInfoTrkVar  *r = track.orb_track;  PamTrack::PamTrack(const PamTrack& track) {
319    
320      TrkTrack *t = track.trk_track;
321      CaloTrkVar *c = track.calo_track;
322      ToFTrkVar *o = track.tof_track;
323      OrbitalInfoTrkVar *r = track.orb_track;
324    
325      trk_track = 0;
326      calo_track = 0;
327      tof_track = 0;
328      orb_track = 0;
329      if (t)
330        trk_track = new TrkTrack(*t);
331      if (c)
332        calo_track = new CaloTrkVar(*c);
333      if (o)
334        tof_track = new ToFTrkVar(*o);
335      if (r)
336        orb_track = new OrbitalInfoTrkVar(*r);
337      candeleteobj = 1;
338    
339    }
340    void PamTrack::Clear() {
341    
342      trk_track  = 0;    //    cout << "PamTrack::Clear() "<<candeleteobj<<endl;
343      if (candeleteobj) {
344        if (trk_track)
345          trk_track->TrkTrack::Clear();
346        if (calo_track)
347          calo_track->CaloTrkVar::Clear();//???
348        if (tof_track)
349          tof_track->ToFTrkVar::Clear();//???
350        if (orb_track)
351          orb_track->OrbitalInfoTrkVar::Clear();//???
352      }
353      else {
354        trk_track = 0;
355      calo_track = 0;      calo_track = 0;
356      tof_track  = 0;      tof_track = 0;
357      orb_track  = 0;      orb_track = 0;
358      if(t)trk_track  = new TrkTrack(*t);    }
359      if(c)calo_track = new CaloTrkVar(*c);    pscore = 0;
360      if(o)tof_track  = new ToFTrkVar(*o);    iscore = 0;
361      if(r)orb_track  = new OrbitalInfoTrkVar(*r);  
362      candeleteobj = 1;  }
363        void PamTrack::Delete() {
364  }    //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;
365  void PamTrack::Clear(){    if (candeleteobj) {
366        if (trk_track) {
367  //    cout << "PamTrack::Clear() "<<candeleteobj<<endl;        trk_track->TrkTrack::Clear();
368      if(candeleteobj){        delete trk_track;
369          if(trk_track)  trk_track->TrkTrack::Clear();      }
370          if(calo_track) calo_track->CaloTrkVar::Clear();//???      if (calo_track) {
371          if(tof_track)  tof_track->ToFTrkVar::Clear();//???        calo_track->CaloTrkVar::Clear();//???
372          if(orb_track)  orb_track->OrbitalInfoTrkVar::Clear();//???        delete calo_track;
373      }else{      }
374          trk_track  = 0;      if (tof_track) {
375          calo_track = 0;        tof_track->ToFTrkVar::Clear();//???
376          tof_track  = 0;        delete tof_track;
377          orb_track  = 0;      }
378      }      if (orb_track) {
379      pscore = 0;        orb_track->OrbitalInfoTrkVar::Clear();//???
380      iscore = 0;        delete orb_track;
   
 }  
 void PamTrack::Delete(){  
 //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;  
     if(candeleteobj){  
         if(trk_track)  {  
             trk_track->TrkTrack::Clear();  
             delete trk_track;  
         }  
         if(calo_track){  
             calo_track->CaloTrkVar::Clear();//???  
             delete calo_track;  
         }  
         if(tof_track){  
             tof_track->ToFTrkVar::Clear();//???  
             delete tof_track;  
         }  
         if(orb_track){  
             orb_track->OrbitalInfoTrkVar::Clear();//???  
             delete orb_track;  
         }  
     }else{  
         Clear();  
381      }      }
382      }
383      else {
384        Clear();
385      }
386  }  }
387  //--------------------------------------  //--------------------------------------
388  //  //
389  //  //
390  //--------------------------------------  //--------------------------------------
391  /**  /**
392   * Default Constructor   * Default Constructor
393   */   */
394  PamLevel2::PamLevel2(){  PamLevel2::PamLevel2() {
395      Initialize();    Initialize();
396  };  }
397    ;
398    
399  /**  /**
400   * Constructor   * Constructor
401   * @param ddir Name of directory where level2 files are stored.   * @param ddir Name of directory where level2 files are stored.
402   * @param list Name of an ascii file containing the list of file names   * @param list Name of an ascii file containing the list of file names
403   * @param detlist Options to chose what to load.   * @param detlist Options to chose what to load.
404   * Possible options are:   * Possible options are:
405   *       +AUTO --> load all trees/branches in the input files   *       +AUTO --> load all trees/branches in the input files
406   *       +(-)ALL --> inlcude(exclude) all trees/branches   *       +(-)ALL --> inlcude(exclude) all trees/branches
407   *       +(-)TRK1+(-)TRK2+(-)CAL1+(-)CAL2+(-)TOF+(-)TRG+(-)ND+(-)S4+(-)ORB+(-)AC --> inlcude(exclude) trees and branches   *       +(-)TRK1+(-)TRK2+(-)CAL1+(-)CAL2+(-)TOF+(-)TRG+(-)ND+(-)S4+(-)ORB+(-)AC --> inlcude(exclude) trees and branches
408   *       +(-)TRK0 --> include(exclude) tracker level0 tree   *       +(-)TRK0 --> include(exclude) tracker level0 tree
409   *       +(-)GP --> include exclude GPAMELA output tree   *       +(-)GP --> include exclude GPAMELA output tree
410   * If no options are specified, the default is assumed. Default is:   * If no options are specified, the default is assumed. Default is:
411   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
412   */   */
413  PamLevel2::PamLevel2(TString ddir,TString llist,TString detlist){  PamLevel2::PamLevel2(TString ddir, TString llist, TString detlist) {
414      Initialize();    Initialize();
415      TList*  listf = GetListOfLevel2Files(ddir,llist);    TList* listf = GetListOfLevel2Files(ddir, llist);
416      if(listf)GetPamTree(listf,detlist);    if (listf)
417      if(listf)GetRunTree(listf);      GetPamTree(listf, detlist);
418  };    if (listf)
419        GetRunTree(listf);
420  PamLevel2::PamLevel2(TString ddir,TList *llist,TString detlist){  }
421      Initialize();  ;
422      GetPamTree(llist,detlist);  
423      GetRunTree(llist);  PamLevel2::PamLevel2(TString ddir, TList *llist, TString detlist) {
424  };    Initialize();
425      GetPamTree(llist, detlist);
426      GetRunTree(llist);
427    }
428    ;
429  /**  /**
430   * Constructor   * Constructor
431   * @param ddir Name of directory where level2 files are stored.   * @param ddir Name of directory where level2 files are stored.
432   * @param list Name of an ascii file containing the list of file names   * @param list Name of an ascii file containing the list of file names
433   * Default trees/branches are loaded. Default is:   * Default trees/branches are loaded. Default is:
434   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
435   */   */
436  PamLevel2::PamLevel2(TString ddir,TString llist){  PamLevel2::PamLevel2(TString ddir, TString llist) {
437      Initialize();    Initialize();
438      TList*  listf = GetListOfLevel2Files(ddir,llist);    TList* listf = GetListOfLevel2Files(ddir, llist);
439      GetPamTree(listf,"");    GetPamTree(listf, "");
440      GetRunTree(listf);    GetRunTree(listf);
441  };  }
442    ;
443    
444    void PamLevel2::Initialize() {
445    
446  void PamLevel2::Initialize(){    h0_obj = 0;
447              trk0_obj = 0;
448      h0_obj    = 0;    calo0_obj = 0;
449      trk0_obj  = 0;  
450      calo0_obj  = 0;    trk2_obj = 0;
451      trk1_obj = 0;
452      trk2_obj  = 0;    trkh_obj = 0;
453      trk1_obj  = 0;    calo1_obj = 0;
454      trkh_obj  = 0;    calo2_obj = 0;
455      calo1_obj = 0;    tof_obj = 0;
456      calo2_obj = 0;    trig_obj = 0;
457      tof_obj   = 0;    s4_obj = 0;
458      trig_obj  = 0;    nd_obj = 0;
459      s4_obj    = 0;    ac_obj = 0;
460      nd_obj    = 0;    orb_obj = 0;
461      ac_obj    = 0;    gp_obj = 0;
462      orb_obj   = 0;  
463      gp_obj    = 0;    run_obj = 0;//new GL_RUN();
464      soft_obj = 0;// Emiliano
465      run_obj   = 0;//new GL_RUN();    irun = -1LL;
466      soft_obj   = 0;// Emiliano    irunt = -1LL;
467      irun = -1LL;    runfirstentry = 0LL;
468      irunt = -1LL;    runlastentry = 0LL;
469      runfirstentry = 0LL;    gltsync = 0; // Emiliano
470      runlastentry = 0LL;  
471      gltsync = 0; // Emiliano    l0_file = NULL;
472      l0_tree = NULL;
473      l0_file = NULL;    iroot = -1;
474      l0_tree = NULL;    dbc = 0;
475      iroot   = -1;  
476      dbc     = 0;    prevshift = 0;
477      maxshift = 10; //EMILIANO
478    
479      run_tree = NULL;
480      run_tree_clone = NULL;
481      sel_tree = NULL;
482      sel_tree_clone = NULL;
483    
484      irunentry = -1LL;
485      pam_tree = NULL;
486      for (Int_t i = 0; i < NCLONES; i++)
487        pam_tree_clone[i] = NULL;
488    
489      totdltime[0] = 0LL;
490      totdltime[1] = 0LL;
491      totdltime[2] = 0LL;
492    
493      host = "mysql://localhost/pamelaprod";
494      user = "anonymous";
495      psw = "";
496      const char *pamdbhost = gSystem->Getenv("PAM_DBHOST");
497      const char *pamdbuser = gSystem->Getenv("PAM_DBUSER");
498      const char *pamdbpsw = gSystem->Getenv("PAM_DBPSW");
499      if (!pamdbhost)
500        pamdbhost = "";
501      if (!pamdbuser)
502        pamdbuser = "";
503      if (!pamdbpsw)
504        pamdbpsw = "";
505      if (strcmp(pamdbhost, ""))
506        host = pamdbhost;
507      if (strcmp(pamdbuser, ""))
508        user = pamdbuser;
509      if (strcmp(pamdbpsw, ""))
510        psw = pamdbpsw;
511    
512      //    sorted_tracks = 0;//new TRefArray();
513    
514      CAL0 = false;
515      CAL1 = true;
516      CAL2 = true;
517      TRK2 = true;
518      TRK1 = false;
519      TRK0 = false;
520      TRKh = false;
521      TRG = true;
522      TOF = true;
523      TOF0 = false;
524      S4 = true;
525      ND = true;
526      AC = true;
527      ORB = true;
528      GP = false;
529    
530      RUN = true;
531    
532      SELLI = -1;
533    
534      ISGP = false;
535    
536      DBG = false;
537    
538      tsorted = 0;
539      timage = 0;
540    
541      howtosort = "+CAL+TOF";
542      //howtosort = "+TOF";
543      sortthr = 100.;
544    
545      prevshift = 0;    issorted = false;
546      maxshift = 10; //EMILIANO    lastsorted = -1;
547        
548      run_tree = NULL;  }
549      run_tree_clone = NULL;  ;
550      sel_tree = NULL;  /**
551      sel_tree_clone = NULL;   * Delete the event (act as Dtor)
552         */
553      irunentry = -1LL;  void PamLevel2::Delete() {
     pam_tree = NULL;  
     for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;  
   
     totdltime[0] = 0LL;  
     totdltime[1] = 0LL;  
     totdltime[2] = 0LL;  
   
     host = "mysql://localhost/pamelaprod";  
     user = "anonymous";  
     psw = "";  
     const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");  
     const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");  
     const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");  
     if ( !pamdbhost ) pamdbhost = "";  
     if ( !pamdbuser ) pamdbuser = "";  
     if ( !pamdbpsw ) pamdbpsw = "";  
     if ( strcmp(pamdbhost,"") ) host = pamdbhost;  
     if ( strcmp(pamdbuser,"") ) user = pamdbuser;  
     if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;  
554    
555          if (run_obj)
556        delete run_obj;
557      if (soft_obj)
558        delete soft_obj; //Emiliano
559    
560      //    cout << "void PamLevel2::Clear()"<<endl;
561      if (h0_obj)
562        delete h0_obj;
563      if (trk0_obj)
564        delete trk0_obj;
565      if (calo0_obj)
566        delete calo0_obj;
567      if (trk1_obj)
568        delete trk1_obj;
569      if (trk2_obj)
570        delete trk2_obj;
571      if (trkh_obj)
572        delete trkh_obj;
573      if (calo1_obj)
574        delete calo1_obj;
575      if (calo2_obj)
576        delete calo2_obj;
577      if (tof_obj)
578        delete tof_obj;
579      if (trig_obj)
580        delete trig_obj;
581      if (s4_obj)
582        delete s4_obj;
583      if (nd_obj)
584        delete nd_obj;
585      if (ac_obj)
586        delete ac_obj;
587      if (orb_obj)
588        delete orb_obj;
589      if (gp_obj)
590        delete gp_obj;
591    
592  //    sorted_tracks = 0;//new TRefArray();    if (tsorted) {
593            tsorted->Delete();
594      CAL0 = false;      delete tsorted;
595      CAL1 = true;    }
596      CAL2 = true;    if (timage) {
597      TRK2 = true;      timage->Delete();
598      TRK1 = false;      delete timage;
599      TRK0 = false;    }
     TRKh = false;  
     TRG  = true;  
     TOF  = true;  
     TOF0 = false;  
     S4   = true;  
     ND   = true;  
     AC   = true;  
     ORB  = true;      
     GP   = false;  
600    
601      RUN  = true;    if (dbc) {
602        dbc->Close();
603        delete dbc;
604      }
605    
606      if (gltsync)
607        delete gltsync;
608    
609      if (l0_file)
610        l0_file->Close();
611      //    if(pam_tree)pam_tree->Delete();;
612    
613      SELLI = -1;    if (pam_tree) {
614        //
615        // 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...
616        //
617        TList *temp = pam_tree->GetListOfFriends();
618        TList *contents = new TList; // create chain friend list
619        contents->SetOwner();
620        TIter next(temp);
621        TChain *questo = 0;
622        while ((questo = (TChain*) next())) {
623          TString name = questo->GetName();
624          contents->Add((TChain*) gROOT->FindObject(name.Data()));// add object to the list
625        };
626        //
627        // deleting the main chain
628        //
629        pam_tree->Delete();
630        //
631        // deleting the friends...
632        //
633        TIter next2(contents);
634        TChain *questa = 0;
635        while (questa = (TChain*) next2()) {
636          TString name = questa->GetName();
637          questa->Delete();
638          questa = NULL;
639        };
640        //
641      };
642      pam_tree = NULL;
643    
644      ISGP = false;    if (run_tree)
645        run_tree->Delete();;
646      if (sel_tree)
647        sel_tree->Delete();;
648      for (Int_t i = 0; i < NCLONES; i++)
649        if (pam_tree_clone[i])
650          pam_tree_clone[i]->Delete();;
651      if (run_tree_clone)
652        run_tree_clone->Delete();;
653      if (sel_tree_clone)
654        sel_tree_clone->Delete();;
655    
656      DBG = false;    if (irunoffset)
657        delete[] irunoffset;
658    
659      tsorted=0;  }
660      timage=0;  ;
       
     howtosort = "+CAL+TOF";  
     //howtosort = "+TOF";  
     sortthr = 100.;  
661    
 };  
662  /**  /**
663   * Delete the event (act as Dtor)   * Clear the event (NB! does not deallocate objects)
664   */   */
665  void PamLevel2::Delete(){  void PamLevel2::Clear() {
           
     if(run_obj)delete run_obj;  
     if(soft_obj)delete soft_obj; //Emiliano  
   
 //    cout << "void PamLevel2::Clear()"<<endl;  
     if(h0_obj)   delete h0_obj;  
     if(trk0_obj) delete trk0_obj;        
     if(calo0_obj) delete calo0_obj;      
     if(trk1_obj) delete trk1_obj;        
     if(trk2_obj) delete trk2_obj;  
     if(trkh_obj) delete trkh_obj;  
     if(calo1_obj)delete calo1_obj;  
     if(calo2_obj)delete calo2_obj;  
     if(tof_obj)  delete tof_obj;  
     if(trig_obj) delete trig_obj;  
     if(s4_obj)   delete s4_obj;  
     if(nd_obj)   delete nd_obj;  
     if(ac_obj)   delete ac_obj;  
     if(orb_obj)  delete orb_obj;  
     if(gp_obj)   delete gp_obj;  
       
     if(tsorted){  
         tsorted->Delete();  
         delete tsorted;  
     }  
     if(timage){  
         timage->Delete();  
         delete timage;  
     }  
   
     if(dbc){  
         dbc->Close();  
         delete dbc;  
     }  
   
     if ( gltsync ) delete gltsync;  
       
     if(l0_file)l0_file->Close();  
     //    if(pam_tree)pam_tree->Delete();;  
   
     if ( pam_tree ){  
         //  
         // 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...  
         //  
         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;  
666    
667      if(run_tree)run_tree->Delete();;    //    cout << "void PamLevel2::Clear()"<<endl;
     if(sel_tree)sel_tree->Delete();;  
     for(Int_t i=0; i<NCLONES; i++ )if(pam_tree_clone[i])pam_tree_clone[i]->Delete();;  
     if(run_tree_clone)run_tree_clone->Delete();;  
     if(sel_tree_clone)sel_tree_clone->Delete();;  
       
     if(irunoffset) delete [] irunoffset;  
668    
669  };    //
670      // This method is called once for every entry but RunInfo and SoftInfo do not change until the next run so we cannot clear them here unless we don't
671      // want to load them for each event even if they are the same...
672      //
673      //    if(run_obj)delete run_obj;
674      //    if(run_obj) run_obj->Clear();  // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead
675      //    if(soft_obj) soft_obj->Clear();
676    
677      if (h0_obj)
678        h0_obj->Clear();
679      //    if(trk0_obj) trk0_obj->Clear();
680      if (trk1_obj)
681        trk1_obj->Clear();
682      if (trk2_obj)
683        trk2_obj->Clear();
684      if (trkh_obj)
685        trkh_obj->Clear();
686      if (calo0_obj)
687        calo0_obj->Clear();
688      if (calo1_obj)
689        calo1_obj->Clear();
690      if (calo2_obj)
691        calo2_obj->Clear();
692      if (tof_obj)
693        tof_obj->Clear();
694      if (trig_obj)
695        trig_obj->Clear();
696      if (s4_obj)
697        s4_obj->Clear();
698      if (nd_obj)
699        nd_obj->Clear();
700      if (ac_obj)
701        ac_obj->Clear();
702      if (orb_obj)
703        orb_obj->Clear();
704      if (gp_obj)
705        gp_obj->Clear();
706    
707  /**    //    if(sorted_tracks)sorted_tracks->Clear();
708   * Clear the event (NB! does not deallocate objects)    //    sorted_tracks.Clear();
  */  
 void PamLevel2::Clear(){  
           
 //    cout << "void PamLevel2::Clear()"<<endl;  
   
 //  
 // This method is called once for every entry but RunInfo and SoftInfo do not change until the next run so we cannot clear them here unless we don't  
 // want to load them for each event even if they are the same...  
 //  
 //    if(run_obj)delete run_obj;  
 //    if(run_obj) run_obj->Clear();  // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead  
 //    if(soft_obj) soft_obj->Clear();  
   
     if(h0_obj)   h0_obj->Clear();        
 //    if(trk0_obj) trk0_obj->Clear();    
     if(trk1_obj) trk1_obj->Clear();      
     if(trk2_obj) trk2_obj->Clear();  
     if(trkh_obj) trkh_obj->Clear();  
     if(calo0_obj) calo0_obj->Clear();    
     if(calo1_obj)calo1_obj->Clear();  
     if(calo2_obj)calo2_obj->Clear();  
     if(tof_obj)  tof_obj->Clear();  
     if(trig_obj) trig_obj->Clear();  
     if(s4_obj)   s4_obj->Clear();  
     if(nd_obj)   nd_obj->Clear();  
     if(ac_obj)   ac_obj->Clear();  
     if(orb_obj)  orb_obj->Clear();  
     if(gp_obj)   gp_obj->Clear();  
       
 //    if(sorted_tracks)sorted_tracks->Clear();  
 //    sorted_tracks.Clear();  
   
     if(tsorted){  
         tsorted->Delete();  
     }  
     if(timage){  
         timage->Delete();  
     }  
 };  
709    
710  void PamLevel2::Reset(){    if (tsorted) {
711      //      tsorted->Delete();
712      // First of all clear everything    }
713      if (timage) {
714        timage->Delete();
715      }
716    }
717    ;
718    
719    void PamLevel2::Reset() {
720      //
721      // First of all clear everything
722      //
723      Clear();
724      //
725      // close and reset chains and pointers
726      //
727      if (pam_tree) {
728      //      //
729      Clear();      // 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...
730      //      //
731      // close and reset chains and pointers      TList *temp = pam_tree->GetListOfFriends();
732      //          TList *contents = new TList; // create chain friend list
733      if ( pam_tree ){      contents->SetOwner();
734          //      TIter next(temp);
735          // 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...      TChain *questo = 0;
736          //      while ((questo = (TChain*) next())) {
737          TList *temp = pam_tree->GetListOfFriends();        TString name = questo->GetName();
738          TList *contents  = new TList; // create chain friend list        contents->Add((TChain*) gROOT->FindObject(name.Data()));// add object to the 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;  
         };  
         //  
739      };      };
     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;  
740      //      //
741      h0_obj    = 0;      // deleting the main chain
     trk0_obj  = 0;  
     calo0_obj  = 0;  
742      //      //
743      trk2_obj  = 0;      pam_tree->Delete();
     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;  
     gp_obj    = 0;  
744      //      //
745      // Reset run pointers      // deleting the friends...
746      //      //
747      run_obj   = 0;//new GL_RUN();      TIter next2(contents);
748      soft_obj   = 0;// Emiliano      TChain *questa = 0;
749      irun = -1;      while (questa = (TChain*) next2()) {
750      irunt = -1;        TString name = questa->GetName();
751      runfirstentry = 0ULL;        questa->Delete();
752      runlastentry = 0ULL;            questa = NULL;
753      //      };
     totdltime[0] = 0LL;  
     totdltime[1] = 0LL;  
     totdltime[2] = 0LL;  
754      //      //
755  };    };
756      pam_tree = NULL;
757      //
758      if (run_tree)
759        run_tree->Delete();;
760      run_tree = NULL;
761      if (sel_tree)
762        sel_tree->Delete();;
763      sel_tree = NULL;
764      //
765      // Close file
766      //
767      if (l0_file)
768        l0_file->Close("R");
769      l0_file = NULL;
770      //
771      h0_obj = 0;
772      trk0_obj = 0;
773      calo0_obj = 0;
774      //
775      trk2_obj = 0;
776      trk1_obj = 0;
777      trkh_obj = 0;
778      calo1_obj = 0;
779      calo2_obj = 0;
780      tof_obj = 0;
781      trig_obj = 0;
782      s4_obj = 0;
783      nd_obj = 0;
784      ac_obj = 0;
785      orb_obj = 0;
786      gp_obj = 0;
787      //
788      // Reset run pointers
789      //
790      run_obj = 0;//new GL_RUN();
791      soft_obj = 0;// Emiliano
792      irun = -1;
793      irunt = -1;
794      runfirstentry = 0ULL;
795      runlastentry = 0ULL;
796      //
797      totdltime[0] = 0LL;
798      totdltime[1] = 0LL;
799      totdltime[2] = 0LL;
800      //
801    }
802    ;
803    
804  Bool_t PamLevel2::IsGood(Bool_t strict){  Bool_t PamLevel2::IsGood(Bool_t strict) {
805    Bool_t goodev=true;    Bool_t goodev = true;
806    //    //
807    if(calo2_obj && !calo2_obj->IsGood(strict) ) goodev = false;    if (calo2_obj && !calo2_obj->IsGood(strict))
808        goodev = false;
809    //    //
810    if ( strict ){    if (strict) {
811      if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;      if (trk2_obj && trk2_obj->UnpackError() != 0)
812      if(tof_obj && tof_obj->unpackError != 0) goodev = false;          goodev = false;
813      if(trig_obj && trig_obj->unpackError != 0) goodev = false;      if (tof_obj && tof_obj->unpackError != 0)
814      if(s4_obj && s4_obj->unpackError != 0) goodev = false;          goodev = false;
815      if(nd_obj && nd_obj->unpackError != 0) goodev = false;        if (trig_obj && trig_obj->unpackError != 0)
816      if(ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0]>>2)&1) || ((ac_obj->status[1]>>2)&1)) ) goodev = false;              goodev = false;
817      //  if(orb_obj)        if (s4_obj && s4_obj->unpackError != 0)
818    } else {        goodev = false;
819      if(nd_obj && nd_obj->unpackError != 0) goodev = false;        if (nd_obj && nd_obj->unpackError != 0)
820      if(ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0]>>2)&1) || ((ac_obj->status[1]>>2)&1)) ) goodev = false;              goodev = false;
821        if (ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0] >> 2) & 1) || ((ac_obj->status[1] >> 2) & 1)))
822          goodev = false;
823        //  if(orb_obj)
824      }
825      else {
826        if (nd_obj && nd_obj->unpackError != 0)
827          goodev = false;
828        if (ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0] >> 2) & 1) || ((ac_obj->status[1] >> 2) & 1)))
829          goodev = false;
830    };    };
831    return(goodev);    return (goodev);
832  };  }
833    ;
834    
835  //--------------------------------------  //--------------------------------------
836  //  //
837  //  //
838  //--------------------------------------  //--------------------------------------
839  void *PamLevel2::GetPointerTo(const char* c ){  void *PamLevel2::GetPointerTo(const char* c) {
840    
841      TString objname = c;    TString objname = c;
842    
843      if(!objname.CompareTo("TrkLevel1"))  {    if (!objname.CompareTo("TrkLevel1")) {
844          if(!trk1_obj){      if (!trk1_obj) {
845              trk1_obj  = new TrkLevel1();        trk1_obj = new TrkLevel1();
846              trk1_obj->Set();        trk1_obj->Set();
847          }      }
848          return &trk1_obj;      return &trk1_obj;
849      };    };
850      if(!objname.CompareTo("TrkLevel2"))  {    if (!objname.CompareTo("TrkLevel2")) {
851          if(!trk2_obj){        if (!trk2_obj) {
852              trk2_obj  = new TrkLevel2();        trk2_obj = new TrkLevel2();
853              trk2_obj->Set();        trk2_obj->Set();
854          }      }
855          return &trk2_obj;      return &trk2_obj;
856      };    };
857      if(!objname.CompareTo("TrkHough"))   {    if (!objname.CompareTo("TrkHough")) {
858          if(!trkh_obj)  {      if (!trkh_obj) {
859              trkh_obj  = new TrkHough();        trkh_obj = new TrkHough();
860              trkh_obj->Set();        trkh_obj->Set();
861          }      }
862          return &trkh_obj;      return &trkh_obj;
863      };    };
864      if(!objname.CompareTo("CaloLevel1")) {    if (!objname.CompareTo("CaloLevel1")) {
865          if(!calo1_obj) calo1_obj = new CaloLevel1();      if (!calo1_obj)
866          return &calo1_obj;        calo1_obj = new CaloLevel1();
867      };      return &calo1_obj;
868      if(!objname.CompareTo("CaloLevel2")) {    };
869          if(!calo2_obj){    if (!objname.CompareTo("CaloLevel2")) {
870              calo2_obj = new CaloLevel2();      if (!calo2_obj) {
871              calo2_obj->Set();        calo2_obj = new CaloLevel2();
872          };        calo2_obj->Set();
         return &calo2_obj;  
     };  
     if(!objname.CompareTo("ToFLevel2"))  {  
         if(!tof_obj){  
             tof_obj   = new ToFLevel2();  
             tof_obj->Set();  
         }  
         return &tof_obj;  
     };  
     if(!objname.CompareTo("TrigLevel2")) {  
         if(!trig_obj)  trig_obj  = new TrigLevel2();  
         return &trig_obj;  
     };  
     if(!objname.CompareTo("S4Level2"))   {  
         if(!s4_obj)    s4_obj    = new S4Level2();  
         return &s4_obj;  
     };  
     if(!objname.CompareTo("NDLevel2"))   {  
         if(!nd_obj)    nd_obj    = new NDLevel2();  
         return &nd_obj;  
     };  
     if(!objname.CompareTo("AcLevel2"))   {  
         if(!ac_obj)    ac_obj    = new AcLevel2();  
         return &ac_obj;  
     };  
     if(!objname.CompareTo("OrbitalInfo"))  {  
         if(!orb_obj){  
             orb_obj   = new OrbitalInfo();  
             orb_obj->Set();  
         }  
         return &orb_obj;  
     };  
 //     if(!objname.CompareTo("OrbitalInfo")){  
 //      if(!orb_obj)   orb_obj   = new OrbitalInfo();  
 //      return &orb_obj;  
 //     };  
     if(!objname.CompareTo("GPamela")){  
         if(!gp_obj)   gp_obj   = new GPamela();  
         return &gp_obj;  
873      };      };
874            return &calo2_obj;
875      if(!objname.CompareTo("RunInfo"))return &run_obj;    };
876      if (!objname.CompareTo("ToFLevel2")) {
877        if (!tof_obj) {
878          tof_obj = new ToFLevel2();
879          tof_obj->Set();
880        }
881        return &tof_obj;
882      };
883      if (!objname.CompareTo("TrigLevel2")) {
884        if (!trig_obj)
885          trig_obj = new TrigLevel2();
886        return &trig_obj;
887      };
888      if (!objname.CompareTo("S4Level2")) {
889        if (!s4_obj)
890          s4_obj = new S4Level2();
891        return &s4_obj;
892      };
893      if (!objname.CompareTo("NDLevel2")) {
894        if (!nd_obj)
895          nd_obj = new NDLevel2();
896        return &nd_obj;
897      };
898      if (!objname.CompareTo("AcLevel2")) {
899        if (!ac_obj)
900          ac_obj = new AcLevel2();
901        return &ac_obj;
902      };
903      if (!objname.CompareTo("OrbitalInfo")) {
904        if (!orb_obj) {
905          orb_obj = new OrbitalInfo();
906          orb_obj->Set();
907        }
908        return &orb_obj;
909      };
910      //     if(!objname.CompareTo("OrbitalInfo")){
911      //    if(!orb_obj)   orb_obj   = new OrbitalInfo();
912      //    return &orb_obj;
913      //     };
914      if (!objname.CompareTo("GPamela")) {
915        if (!gp_obj)
916          gp_obj = new GPamela();
917        return &gp_obj;
918      };
919    
920      if(!objname.CompareTo("SoftInfo"))return &soft_obj; // Emiliano    if (!objname.CompareTo("RunInfo"))
921        return &run_obj;
922    
923      return NULL;    if (!objname.CompareTo("SoftInfo"))
924  };      return &soft_obj; // Emiliano
925    
926      return NULL;
927    }
928    ;
929  //--------------------------------------  //--------------------------------------
930  //  //
931  //  //
932  //--------------------------------------  //--------------------------------------
933  /**  /**
934   * Retrieves the calorimeter track matching the seqno-th tracker stored track.   * Retrieves the calorimeter track matching the seqno-th tracker stored track.
935   * (If seqno = -1 retrieves the self-trigger calorimeter track)   * (If seqno = -1 retrieves the self-trigger calorimeter track)
936   */   */
937  CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){  CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno) {
938        
939      if( !calo2_obj )return 0;    if (!calo2_obj)
940        return 0;
941      if( calo2_obj->CaloLevel2::ntrk()==0 ){  
942          cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;    if (calo2_obj->CaloLevel2::ntrk() == 0) {
943          return NULL;      cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo " << seqno
944      };          << " but no Calorimeter tracks are stored" << endl;
945            return NULL;
946      CaloTrkVar *c = 0;    };
947      Int_t it_calo=0;  
948          CaloTrkVar *c = 0;
949      do{    Int_t it_calo = 0;
950          c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);  
951          it_calo++;    do {
952      } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());          c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
953            it_calo++;
954      if(!c || seqno != c->trkseqno){    } while (c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());
955          c = 0;  
956          if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;    if (!c || seqno != c->trkseqno) {
957      };      c = 0;
958      return c;      if (seqno != -1)
959              cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo " << seqno
960  };            << " does not match Calorimeter stored tracks" << endl;
961      };
962      return c;
963    
964    }
965    ;
966  //--------------------------------------  //--------------------------------------
967  //  //
968  //  //
969  //--------------------------------------  //--------------------------------------
970  /**  /**
971   * Retrieves the ToF track matching the seqno-th tracker stored track.   * Retrieves the ToF track matching the seqno-th tracker stored track.
972   * (If seqno = -1 retrieves the tracker-independent tof track)   * (If seqno = -1 retrieves the tracker-independent tof track)
973   */   */
974  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno) {
975            
976      if( !tof_obj )return 0;    if (!tof_obj)
977        return 0;
978      if( tof_obj->ToFLevel2::ntrk()==0 ){  
979          cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;    if (tof_obj->ToFLevel2::ntrk() == 0) {
980          return NULL;      cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo " << seqno << " but no ToF tracks are stored"
981      };          << endl;
982            return NULL;
983      ToFTrkVar *c = 0;    };
984      Int_t it_tof=0;  
985          ToFTrkVar *c = 0;
986      do{    Int_t it_tof = 0;
987          c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);  
988          it_tof++;    do {
989      } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());      c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);
990            it_tof++;
991      if(!c || seqno != c->trkseqno){    } while (c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());
992          c = 0;  
993          if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;    if (!c || seqno != c->trkseqno) {
994      };      c = 0;
995      return c;      if (seqno != -1)
996              cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo " << seqno
997  };            << " does not match ToF stored tracks" << endl;
998      };
999      return c;
1000    
1001    }
1002    ;
1003    
1004  //--------------------------------------  //--------------------------------------
1005  //  //
1006  //  //
1007  //--------------------------------------  //--------------------------------------
1008  /**  /**
1009   * Retrieves the OrbitalInfo track matching the seqno-th tracker stored track.   * Retrieves the OrbitalInfo track matching the seqno-th tracker stored track.
1010   * (If seqno = -1 retrieves the tracker-independent tof related track)   * (If seqno = -1 retrieves the tracker-independent tof related track)
1011   */   */
1012  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno){  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno) {
1013            
1014      if( !orb_obj )return 0;    if (!orb_obj)
1015        return 0;
1016    
1017      if( orb_obj->OrbitalInfo::ntrk()==0 ){    if (orb_obj->OrbitalInfo::ntrk() == 0) {
1018  //       // TRICK BEGIN      //       // TRICK BEGIN
1019  //       OrbitalInfoTrkVar  *r = new OrbitalInfoTrkVar(); // TEMPORARY TRICK      //       OrbitalInfoTrkVar  *r = new OrbitalInfoTrkVar(); // TEMPORARY TRICK
1020  //       Int_t nn = 0;      //       Int_t nn = 0;
1021  //       TClonesArray &tor = *orb_obj->OrbitalInfoTrk;      //       TClonesArray &tor = *orb_obj->OrbitalInfoTrk;
1022  //       for(Int_t nt=0; nt < tof_obj->ToFLevel2::ntrk(); nt++){        //       for(Int_t nt=0; nt < tof_obj->ToFLevel2::ntrk(); nt++){
1023  //      //      //  //
1024  //      ToFTrkVar *ptt = tof_obj->ToFLevel2::GetToFTrkVar(nt);      //  ToFTrkVar *ptt = tof_obj->ToFLevel2::GetToFTrkVar(nt);
1025  //      if ( ptt->trkseqno != -1  ){      //  if ( ptt->trkseqno != -1  ){
1026  //        //      //    //
1027  //        r->trkseqno = ptt->trkseqno;      //    r->trkseqno = ptt->trkseqno;
1028  //        //      //    //
1029  //        r->Eij = 0;        //    r->Eij = 0;
1030  //        //      //    //
1031  //        r->Sij = 0;      //    r->Sij = 0;
1032  //        //              //    //
1033  //        r->pitch = -1000.;      //    r->pitch = -1000.;
1034  //        //      //    //
1035  //        r->cutoff = -1000.;      //    r->cutoff = -1000.;
1036  //        //      //    //
1037  //        new(tor[nn]) OrbitalInfoTrkVar(*r);      //    new(tor[nn]) OrbitalInfoTrkVar(*r);
1038  //        nn++;      //    nn++;
1039  //        //      //    //
1040  //        r->Clear();      //    r->Clear();
1041  //        //      //    //
1042  //      };      //  };
1043  //       };      //       };
1044  //       delete r;      //       delete r;
1045  //       OrbitalInfoTrkVar *c = 0;      //       OrbitalInfoTrkVar *c = 0;
1046  //       c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(0);      //       c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(0);
1047  //       return c;      //       return c;
1048  //       //TRICK END      //       //TRICK END
1049        cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no OrbitalInfo tracks are stored"<<endl;      cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo " << seqno
1050        return NULL;          << " but no OrbitalInfo tracks are stored" << endl;
1051      };      return NULL;
1052          };
1053      OrbitalInfoTrkVar *c = 0;  
1054      Int_t it_tof=0;    OrbitalInfoTrkVar *c = 0;
1055          Int_t it_tof = 0;
1056      do{  
1057          c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);    do {
1058          it_tof++;      c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);
1059      } while( c && seqno != c->trkseqno && it_tof < orb_obj->OrbitalInfo::ntrk());            it_tof++;
1060          } while (c && seqno != c->trkseqno && it_tof < orb_obj->OrbitalInfo::ntrk());
1061      if(!c || seqno != c->trkseqno){  
1062          c = 0;    if (!c || seqno != c->trkseqno) {
1063          if(seqno!=-1)cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match OrbitalInfo stored tracks"<<endl;      c = 0;
1064      };      if (seqno != -1)
1065      return c;        cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo " << seqno
1066                  << " does not match OrbitalInfo stored tracks" << endl;
1067  };    };
1068      return c;
1069    
1070    }
1071    ;
1072    
1073  //--------------------------------------  //--------------------------------------
1074  //  //
1075  //  //
1076  //--------------------------------------  //--------------------------------------
1077  /**  /**
1078   * Give the pamela track associated to a tracker track, retrieving related calorimeter, orbitalinfo and tof track information.   * Give the pamela track associated to a tracker track, retrieving related calorimeter, orbitalinfo and tof track information.
1079   */   */
1080  PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){  PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t) {
1081        
1082      cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;    cout << "PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** " << endl;
1083      cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;    cout << "(if you use it, remember to delete the PamTrack object)" << endl;
1084    
1085      CaloTrkVar *c = 0;    CaloTrkVar *c = 0;
1086      ToFTrkVar  *o = 0;    ToFTrkVar *o = 0;
1087      OrbitalInfoTrkVar  *r = 0;    OrbitalInfoTrkVar *r = 0;
1088        
1089      if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());    if (CAL2)
1090      if(TOF) o = GetToFStoredTrack(t->GetSeqNo());      c = GetCaloStoredTrack(t->GetSeqNo());
1091      if(ORB) r = GetOrbitalInfoStoredTrack(t->GetSeqNo());    if (TOF)
1092            o = GetToFStoredTrack(t->GetSeqNo());
1093  //    if(t && c && o)track = new PamTrack(t,c,o);    if (ORB)
1094      PamTrack *track = new PamTrack(t,c,o,r);      r = GetOrbitalInfoStoredTrack(t->GetSeqNo());
1095        
1096      return track;    //    if(t && c && o)track = new PamTrack(t,c,o);
1097      PamTrack *track = new PamTrack(t, c, o, r);
1098  };  
1099      return track;
1100    
1101    }
1102    ;
1103  //--------------------------------------  //--------------------------------------
1104  //  //
1105  //  //
1106  //--------------------------------------  //--------------------------------------
1107  /**  /**
1108   * Retrieves the it-th stored track.   * Retrieves the it-th stored track.
1109   * It override TrkLevel2::GetTrack(int it).   * It override TrkLevel2::GetTrack(int it).
1110   * @param itrk Track number, ranging from 0 to GetNTracks().   * @param itrk Track number, ranging from 0 to GetNTracks().
1111   */   */
1112    
1113  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk) {
1114        
1115      cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;    cout << "PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** " << endl;
1116      cout <<"for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack) OrbitalInfo::GetOrbitalInfoTrkVar(Int_t notrack)"<<endl;    cout
1117      cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;        << "for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack) OrbitalInfo::GetOrbitalInfoTrkVar(Int_t notrack)"
1118      PamTrack *track = 0;        << endl;
1119          cout << "(if you use it, remember to delete the PamTrack object)" << endl;
1120      if( itrk >=0 && itrk < trk2_obj->TrkLevel2::ntrk() ){    PamTrack *track = 0;
1121            
1122          TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk);    if (itrk >= 0 && itrk < trk2_obj->TrkLevel2::ntrk()) {
1123          track = GetPamTrackAlong(t);  
1124                TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk);
1125                track = GetPamTrackAlong(t);
1126    
1127      }
1128      else {
1129        cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo " << itrk << " does not exist (GetNTracks() = "
1130            << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
1131      };
1132    
1133      return track;
1134    
     }else{  
         cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;  
     };  
       
     return track;  
       
1135  }  }
1136  //--------------------------------------  //--------------------------------------
1137  //  //
# Line 1027  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 1139  PamTrack* PamLevel2::GetStoredTrack(Int_
1139  /**  /**
1140   * Sort physical (tracker) tracks. Left here as backward compatibility method.   * Sort physical (tracker) tracks. Left here as backward compatibility method.
1141   **/   **/
1142  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(TString how) {
1143      printf(" WARNING! obsolete, use SortTracks() and SetSortingMethod(TString) instead! \n Setting sorting method to %s \n",how.Data());    printf(
1144      howtosort = how;          " WARNING! obsolete, use SortTracks() and SetSortingMethod(TString) instead! \n Setting sorting method to %s \n",
1145      SortTracks();        how.Data());
1146  };    howtosort = how;
1147      SortTracks();
1148    }
1149    ;
1150    
1151  //  //
1152  //--------------------------------------  //--------------------------------------
# Line 1039  void PamLevel2::SortTracks(TString how){ Line 1154  void PamLevel2::SortTracks(TString how){
1154   * Sort physical (tracker) tracks.   * Sort physical (tracker) tracks.
1155   * @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...).
1156   * Sorting cryteria:   * Sorting cryteria:
1157   * TRK: lower chi**2   * TRK: lower chi**2
1158   * CAL: lower Y spatial residual on the first calorimeter plane   * CAL: lower Y spatial residual on the first calorimeter plane
1159   * 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).
1160   * S1: (ask Emiliano)   * S1: (ask Emiliano)
1161   * S2: (ask Emiliano)   * S2: (ask Emiliano)
1162   * S3: (ask Emiliano)   * S3: (ask Emiliano)
1163   * GP: more GP hits   * GP: more GP hits
1164   * The default sorting cryterium is "TOF+CAL".   * The default sorting cryterium is "TOF+CAL".
1165   *   *
1166   * 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).
1167   */   */
1168  void PamLevel2::SortTracks(){  void PamLevel2::SortTracks() {
     TString how = howtosort;  
   
     //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;  
     if( !trk2_obj ){  
         cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";  
         return;  
     };  
     //Save current Object count  
     Int_t ObjectNumber = TProcessID::GetObjectCount();  
   
     // create TCloneArrays to store tracks and its images  
     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;  
1169    
1170      //Check if the current event has already been sorted
1171      if (issorted && lastsorted == GetReadEntry()) {
1172        return;
1173      }
1174      //Reset the sort flags, just in case something will go wrong...
1175      issorted = false;
1176      lastsorted = -1;
1177    
1178      TString how = howtosort;
1179    
1180      //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;
1181      if (!trk2_obj) {
1182        cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";
1183        return;
1184      };
1185      //Save current Object count
1186      Int_t ObjectNumber = TProcessID::GetObjectCount();
1187    
1188      // create TCloneArrays to store tracks and its images
1189      if (!tsorted)
1190        tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1191      tsorted->Delete();
1192      TClonesArray &ttsorted = *tsorted;
1193    
1194      if (!timage)
1195        timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1196      timage->Delete();
1197      TClonesArray &ttimage = *timage;
1198    
1199      //--------------------------------------------------
1200      // retrieve sorting method
1201      //--------------------------------------------------
1202      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
1203      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
1204      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
1205      Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
1206      Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
1207      Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
1208      Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
1209    
1210      if (use_TOF) {
1211        use_S1 = true;
1212        use_S2 = true;
1213        use_S3 = true;
1214      };
1215      if (!CAL2 && use_CAL)
1216        use_CAL = false;
1217      if (!TOF) {
1218        use_TOF = false;
1219        use_S1 = false;
1220        use_S2 = false;
1221        use_S3 = false;
1222      }
1223      if (!GP) {
1224        use_GP = false;
1225      }
1226    
1227      if (!TRK2) {
1228        cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
1229        return;
1230      };
1231    
1232      //--------------------------------------------------    //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
     // retrieve sorting method  
     //--------------------------------------------------  
     Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);  
     Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);  
     Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);  
     Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);  
     Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);  
     Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);  
     Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);  
     
     if ( use_TOF ){  
         use_S1 = true;  
         use_S2 = true;  
         use_S3 = true;  
     };  
     if( !CAL2 &&  use_CAL) use_CAL = false;  
     if( !TOF ){  
         use_TOF = false;  
         use_S1  = false;  
         use_S2  = false;  
         use_S3  = false;  
     }  
     if( !GP ){  
         use_GP  = false;  
     }  
1233    
     if( !TRK2 ){  
         cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;  
         return;  
     };  
1234    
1235      //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;    //--------------------------------------------------
1236        // loop over "physical" tracks sorted by the tracker
1237      //--------------------------------------------------
1238      for (Int_t i = 0; i < trk2_obj->TrkLevel2::GetNTracks(); i++) {
1239    
1240        TrkTrack *ts = 0;
1241        CaloTrkVar *cs = 0;
1242        ToFTrkVar *os = 0;
1243        OrbitalInfoTrkVar *rs = 0;
1244    
1245        // get tracker tracks
1246        TrkTrack *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
1247        CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
1248        ToFTrkVar *op = GetToFStoredTrack(tp->GetSeqNo());
1249        OrbitalInfoTrkVar *rp = GetOrbitalInfoStoredTrack(tp->GetSeqNo());
1250    
1251        TrkTrack *ti = 0; //tracker (image)
1252        CaloTrkVar *ci = 0;
1253        ToFTrkVar *oi = 0;
1254        OrbitalInfoTrkVar *ri = 0;
1255        //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
1256        // if track has an image, check image selection
1257    
1258        Int_t tp_score = 0; //main track sorted by the tracker
1259        Int_t ti_score = 0; //image track
1260        Int_t totp_score = 0; //main track sorted by the tracker
1261        Int_t toti_score = 0; //image track
1262    
1263        if (tp->HasImage()) {
1264    
1265          ti = trk2_obj->TrkLevel2::GetTrackImage(i); //tracker (image)
1266          ci = GetCaloStoredTrack(ti->GetSeqNo());
1267          oi = GetToFStoredTrack(ti->GetSeqNo());
1268          ri = GetOrbitalInfoStoredTrack(ti->GetSeqNo());
1269    
1270          //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
1271    
1272          //assign starting scores
1273          tp_score = 0; //main track sorted by the tracker
1274          ti_score = 0; //image track
1275    
1276          // -----------------------------------------------------------------------------------------
1277          // *****************************************************************************************
1278          // -----------------------------------------------------------------------------------------
1279          // calorimeter check
1280          // -----------------------------------------------------------------------------------------
1281          if (use_CAL && !calo2_obj) {
1282            cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but CaloLevel2 not loaded !!!";
1283            return;
1284          };
1285          if (use_CAL && !cp && ci) {
1286            ti_score++;
1287            toti_score++;
1288          };
1289          if (use_CAL && cp && !ci) {
1290            tp_score++;
1291            totp_score++;
1292          };
1293          if (use_CAL && cp && ci && true) {
1294    
1295            if (cp->npresh > ci->npresh && true) {
1296              tp_score++;
1297              totp_score++;
1298            };
1299            if (cp->npresh < ci->npresh && true) {
1300              ti_score++;
1301              toti_score++;
1302            };
1303    
1304            //      cout << "CALO "<<tp_score<<ti_score<<endl;
1305    
1306          };
1307          // -----------------------------------------------------------------------------------------
1308          // *****************************************************************************************
1309          // -----------------------------------------------------------------------------------------
1310          // TOF check
1311          // -----------------------------------------------------------------------------------------
1312          // check the number of hit pmts along the track
1313          // on S12 S21 and S32, where paddles are parallel to Y axis
1314          if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof_obj) {
1315            cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";
1316            return;
1317          };
1318          //
1319          if ((use_TOF || use_S1 || use_S2 || use_S3) && !op && oi) {
1320            ti_score++;
1321            toti_score++;
1322          };
1323          if ((use_TOF || use_S1 || use_S2 || use_S3) && op && !oi) {
1324            tp_score++;
1325            totp_score++;
1326          };
1327          if ((use_TOF || use_S1 || use_S2 || use_S3) && op && oi) {
1328            //
1329            Float_t sen = 0.;
1330            for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1331              Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));
1332              if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
1333                sen += (op->dedx).At(ih);
1334            };
1335            for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1336              Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1337              if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
1338                sen += (oi->dedx).At(ih);
1339            };
1340            //
1341            if (sen >= sortthr && false) { // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
1342              //printf(" IS A NUCLEUS! en = %f \n",sen);
1343              //
1344              // is a nucleus use a different algorithm
1345              //
1346              Int_t nz = 6;
1347              Float_t zin[6]; // << define TOF z-coordinates
1348              for (Int_t ip = 0; ip < nz; ip++)
1349                zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip)); // << read ToF plane z-coordinates
1350              Trajectory *tr = new Trajectory(nz, zin);
1351              //
1352              Int_t nphit_p = 0;
1353              Int_t nphit_i = 0;
1354              Float_t enhit_p = 0.;
1355              Float_t enhit_i = 0.;
1356              //
1357              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1358                Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));
1359                if (pl == 1 || pl == 2 || pl == 5) {
1360                  nphit_p++;
1361                  enhit_p += (op->dedx).At(ih);
1362                };
1363              };
1364              //
1365              tp->DoTrack2(tr);
1366              //
1367              if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
1368                for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1369                  Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));
1370                  if (pl == 0) {
1371                    nphit_p++;
1372                    enhit_p += (op->dedx).At(ih);
1373                  };
1374                };
1375              };
1376              if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
1377                for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1378                  Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));
1379                  if (pl == 3) {
1380                    nphit_p++;
1381                    enhit_p += (op->dedx).At(ih);
1382                  };
1383                };
1384              };
1385              if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
1386                for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1387                  Int_t pl = tof_obj->GetPlaneIndex((op->pmtadc).At(ih));
1388                  if (pl == 4) {
1389                    nphit_p++;
1390                    enhit_p += (op->dedx).At(ih);
1391                  };
1392                };
1393              };
1394    
1395              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1396                Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1397                if (pl == 1 || pl == 2 || pl == 5) {
1398                  nphit_i++;
1399                  enhit_i += (op->dedx).At(ih);
1400                };
1401              };
1402              //
1403              ti->DoTrack2(tr);
1404              //
1405              if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
1406                for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1407                  Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1408                  if (pl == 0) {
1409                    nphit_i++;
1410                    enhit_i += (op->dedx).At(ih);
1411                  };
1412                };
1413              };
1414              if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
1415                for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1416                  Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1417                  if (pl == 3) {
1418                    nphit_i++;
1419                    enhit_i += (op->dedx).At(ih);
1420                  };
1421                };
1422              };
1423              if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
1424                for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1425                  Int_t pl = tof_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1426                  if (pl == 4) {
1427                    nphit_i++;
1428                    enhit_i += (op->dedx).At(ih);
1429                  };
1430                };
1431              };
1432    
1433              if ((use_TOF || use_S1 || use_S2 || use_S3) && (nphit_p + nphit_i) != 0 && true) {
1434    
1435                //      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);
1436                //      printf(" score p %i score i %i \n",tp_score,ti_score);
1437                //            if( enhit_p > enhit_i ) tp_score++;
1438                //            if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
1439                if (nphit_p > nphit_i)
1440                  tp_score++;
1441                if (nphit_p < nphit_i)
1442                  ti_score++;
1443                if (nphit_p == nphit_i) {
1444                  if (enhit_p > enhit_i)
1445                    tp_score++;
1446                  else
1447                    ti_score++;
1448                };
1449                //      printf(" dopo score p %i score i %i \n",tp_score,ti_score);
1450              };
1451              delete tr;
1452              //
1453            }
1454            else {
1455              // -------------
1456              // NOT a NUCLEUS
1457              // -------------
1458              //printf(" NOT a NUCLEUS! en = %f \n",sen);
1459    
1460              Int_t nphit_p = 0;
1461              Int_t nphit_i = 0;
1462    
1463              /*                            cout << "track: npmtadc "<< op->npmtadc << endl;
1464               cout << "track: npmttdc "<< op->npmttdc << endl;
1465               cout << "image: npmtadc "<< oi->npmtadc << endl;
1466               cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1467    
1468              //      for (Int_t ih=0; ih < op->npmtadc; ih++){
1469              //        Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1470              //        if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
1471              //      };
1472    
1473              //      for (Int_t ih=0; ih < oi->npmtadc; ih++){
1474              //        Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1475              //        if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1476              //      };
1477              // --- modified to count tdc signals (more efficient?)
1478              // --- and to implement check on tdcflag
1479              for (Int_t ih = 0; ih < op->npmttdc; ih++) {
1480                Int_t pl = tof_obj->GetPlaneIndex((op->pmttdc).At(ih));
1481                //      if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
1482                if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
1483                    || (use_S3 && (pl == 4 || pl == 5))) {
1484                  if ((op->tdcflag).At(ih) == 0)
1485                    nphit_p++;
1486                };
1487              };
1488    
1489              for (Int_t ih = 0; ih < oi->npmttdc; ih++) {
1490                Int_t pl = tof_obj->GetPlaneIndex((oi->pmttdc).At(ih));
1491                //      if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;
1492                if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
1493                    || (use_S3 && (pl == 4 || pl == 5))) {
1494                  if ((oi->tdcflag).At(ih) == 0)
1495                    nphit_i++;
1496                };
1497              };
1498    
1499              if ((nphit_p + nphit_i) != 0 && true) {
1500    
1501                if (nphit_p != nphit_i) {
1502                  totp_score += nphit_p;
1503                  toti_score += nphit_i;
1504                  tp_score += nphit_p;
1505                  ti_score += nphit_i;
1506                };
1507                //      if     ( nphit_p > nphit_i) tp_score+=nphit_p;
1508                //      else if( nphit_p < nphit_i) ti_score+=nphit_i;
1509                //      else ;//niente
1510              };
1511            };
1512            //      cout << "TOF "<<tp_score<<ti_score<<endl;
1513          };
1514    
1515          //      if(tp_score == ti_score) use_TRK = true;
1516    
1517    
1518          // -----------------------------------------------------------------------------------------
1519          // *****************************************************************************************
1520          // -----------------------------------------------------------------------------------------
1521          // tracker check
1522          // -----------------------------------------------------------------------------------------
1523          // chi**2 difference is not always large enough to distinguish among
1524          // the real track and its image.
1525          // Tracker check will be applied always when calorimeter and tof information is ambiguous.
1526          // *** MODIFIED ON AUGUST 2007 ***
1527          if (use_TRK) {
1528            //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
1529            //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
1530    
1531            // CHECK 1 : number of points along X
1532            if (tp->GetNX() >= ti->GetNX()) {
1533              tp_score++;
1534              totp_score++;
1535            };
1536            if (tp->GetNX() <= ti->GetNX()) {
1537              ti_score++;
1538              toti_score++;
1539            };
1540            // CHECK 2 : number of points along Y
1541            if (tp->GetNY() >= ti->GetNY()) {
1542              tp_score++;
1543              totp_score++;
1544            };
1545            if (tp->GetNY() <= ti->GetNY()) {
1546              ti_score++;
1547              toti_score++;
1548            };
1549    
1550            //      cout << "TRK "<<tp_score<<ti_score<<endl;
1551          };
1552    
1553          // -----------------------------------------------------------------------------------------
1554          // *****************************************************************************************
1555          // -----------------------------------------------------------------------------------------
1556          // GPamela check
1557          // -----------------------------------------------------------------------------------------
1558    
1559          //---------------------------------------------------
1560          // count the number of GP hits
1561          //---------------------------------------------------
1562          if (use_GP) {
1563            int ngphits_p = 0;
1564            int ngphits_i = 0;
1565            float toll = 0.02; //200 micron
1566            for (int ih = 0; ih < GetGPamela()->Nthspe; ih++) {
1567              int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
1568              if (tp && tp->YGood(ip) && fabs(tp->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
1569                ngphits_p++;
1570              if (ti && ti->YGood(ip) && fabs(ti->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
1571                ngphits_i++;
1572            }
1573            if (ngphits_p > ngphits_i && true) {
1574              tp_score++;
1575              totp_score++;
1576            }
1577            if (ngphits_p < ngphits_i && true) {
1578              ti_score++;
1579              toti_score++;
1580            }
1581          }
1582    
1583          // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1584          // the winner is....
1585          // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1586          if (tp_score > ti_score) {
1587    
1588          }
1589          else if (tp_score < ti_score) {
1590    
1591            ts = ti;//its image!!
1592            cs = ci;
1593            os = oi;
1594            rs = ri;
1595            Int_t totis = toti_score;
1596    
1597            ti = tp;//its image!!
1598            ci = cp;
1599            oi = op;
1600            ri = rp;
1601    
1602            tp = ts;//its image!!
1603            cp = cs;
1604            op = os;
1605            rp = rs;
1606    
1607            toti_score = totp_score;
1608            totp_score = totis;
1609    
1610          }
1611          else {
1612    
1613            //      cout << "Warning - track image ambiguity not solved" << endl;
1614    
1615          };
1616    
1617        }
1618        else {
1619          totp_score = 1;
1620          toti_score = 0;
1621    
1622          //            ts = tp;
1623          //            cs = cp;
1624          //            os = op;
1625        };
1626    
1627        //  cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
1628        //  sorted_tracks->Add(ts);//save the track in the sorted array
1629        //  sorted_tracks.Add(ts);//save the track in the sorted array
1630        //  sorted_tracks.Add(tp);//save the track in the sorted array
1631        //  cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
1632        //  cout<<"o "<<tp<<endl;
1633        //  cout<<"o "<<cp<<endl;
1634        //  cout<<"o "<<op<<endl;
1635    
1636        new (ttsorted[i]) PamTrack(tp, cp, op, rp);
1637        new (ttimage[i]) PamTrack(ti, ci, oi, ri);
1638    
1639        ((PamTrack*) (ttsorted[i]))->SetPScore(totp_score);
1640        ((PamTrack*) (ttsorted[i]))->SetIScore(toti_score);
1641        ((PamTrack*) (ttimage[i]))->SetPScore(totp_score);
1642        ((PamTrack*) (ttimage[i]))->SetIScore(toti_score);
1643      };
1644    
1645      //--------------------------------------------------    if (tsorted->GetEntries() != trk2_obj->GetNTracks()) {
1646      // loop over "physical" tracks sorted by the tracker      cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() " << tsorted->GetEntries()
1647      //--------------------------------------------------          << " != trk2_obj->GetNTracks() = " << trk2_obj->GetNTracks() << endl;
1648      for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){      tsorted->Delete();
1649                tsorted = 0;
1650          TrkTrack   *ts = 0;      timage->Delete();
1651          CaloTrkVar *cs = 0;      timage = 0;
1652          ToFTrkVar  *os = 0;    }
         OrbitalInfoTrkVar  *rs = 0;  
           
         // get tracker tracks  
         TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker  
         CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());  
         ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo());  
         OrbitalInfoTrkVar  *rp = GetOrbitalInfoStoredTrack(tp->GetSeqNo());  
   
         TrkTrack   *ti = 0; //tracker (image)  
         CaloTrkVar *ci = 0;  
         ToFTrkVar  *oi = 0;  
         OrbitalInfoTrkVar  *ri = 0;  
         //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;  
         // if track has an image, check image selection  
   
         Int_t tp_score = 0;  //main track sorted by the tracker  
         Int_t ti_score = 0;  //image track  
         Int_t totp_score = 0;  //main track sorted by the tracker  
         Int_t toti_score = 0;  //image track  
   
         if(tp->HasImage()){  
               
             ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image)  
             ci = GetCaloStoredTrack(ti->GetSeqNo());  
             oi = GetToFStoredTrack(ti->GetSeqNo());  
             ri = GetOrbitalInfoStoredTrack(ti->GetSeqNo());  
               
             //      cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;  
   
             //assign starting scores  
             tp_score = 0;  //main track sorted by the tracker  
             ti_score = 0;  //image track  
               
             // -----------------------------------------------------------------------------------------  
             // *****************************************************************************************  
             // -----------------------------------------------------------------------------------------  
             // calorimeter check  
             // -----------------------------------------------------------------------------------------  
             if( use_CAL && !calo2_obj ){  
                 cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!";  
                 return;  
             };  
             if( use_CAL && !cp &&  ci ){  
                 ti_score++;  
                 toti_score++;  
             };  
             if( use_CAL &&  cp && !ci ){  
                 tp_score++;  
                 totp_score++;  
             };  
             if(  
                 use_CAL            &&  
                 cp && ci &&  
                 true){  
   
                   
                 if(  
                     cp->npresh > ci->npresh &&  
                     true){  
                     tp_score++;  
                     totp_score++;  
                 };  
                 if(  
                     cp->npresh < ci->npresh &&  
                     true){  
                     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);  
                             };  
                         };  
                     };  
                     if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){  
                         for (Int_t ih=0; ih < op->npmtadc; ih++){  
                             Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  
                             if(pl == 3){  
                                 nphit_p++;  
                                 enhit_p += (op->dedx).At(ih);  
                             };  
                         };  
                     };  
                     if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){  
                         for (Int_t ih=0; ih < op->npmtadc; ih++){  
                             Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) );  
                             if(pl == 4){  
                                 nphit_p++;  
                                 enhit_p += (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 == 1 || pl == 2 || pl == 5){  
                             nphit_i++;    
                             enhit_i += (op->dedx).At(ih);  
                         };  
                     };  
                     //  
                     ti->DoTrack2(tr);  
                     //  
                     if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){  
                         for (Int_t ih=0; ih < oi->npmtadc; ih++){  
                             Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  
                             if(pl == 0){  
                                 nphit_i++;  
                                 enhit_i += (op->dedx).At(ih);  
                             };  
                         };  
                     };  
                     if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){  
                         for (Int_t ih=0; ih < oi->npmtadc; ih++){  
                             Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  
                             if(pl == 3){  
                                 nphit_i++;  
                                 enhit_i += (op->dedx).At(ih);  
                             };  
                         };  
                     };  
                     if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){  
                         for (Int_t ih=0; ih < oi->npmtadc; ih++){  
                             Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );  
                             if(pl == 4){  
                                 nphit_i++;  
                                 enhit_i += (op->dedx).At(ih);  
                             };  
                         };  
                     };            
   
                   
                     if(  
                         (use_TOF || use_S1 || use_S2 || use_S3)            &&  
                         (nphit_p+nphit_i) !=0 &&          
                         true){  
                       
                         //          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(" score p %i score i %i \n",tp_score,ti_score);  
                         //                if( enhit_p > enhit_i ) tp_score++;  
                         //                if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;  
                         if ( nphit_p > nphit_i ) tp_score++;  
                         if ( nphit_p < nphit_i ) ti_score++;  
                         if ( nphit_p == nphit_i ){  
                             if ( enhit_p > enhit_i ) tp_score++;  
                             else ti_score++;  
                         };  
                         //          printf(" dopo score p %i score i %i \n",tp_score,ti_score);  
                     };  
                     delete tr;  
                     //  
                 } else {  
                     // -------------  
                     // NOT a NUCLEUS  
                     // -------------  
                     //printf(" NOT a NUCLEUS! en = %f \n",sen);  
   
                     Int_t nphit_p =0;  
                     Int_t nphit_i =0;  
                   
                   
                     /*                          cout << "track: npmtadc "<< op->npmtadc << endl;  
                                                 cout << "track: npmttdc "<< op->npmttdc << endl;  
                                                 cout << "image: npmtadc "<< oi->npmtadc << endl;  
                                                 cout << "image: npmttdc "<< oi->npmttdc << endl;*/  
                   
 //        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++;  
 //        };  
                   
 //        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++;  
 //        };  
                     // --- modified to count tdc signals (more efficient?)  
                     // --- and to implement check on tdcflag  
                     for (Int_t ih=0; ih < op->npmttdc; ih++){  
                         Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) );  
 //          if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;  
                         if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){  
                             if( (op->tdcflag).At(ih)==0 )nphit_p++;  
                         };  
                     };  
                   
                     for (Int_t ih=0; ih < oi->npmttdc; ih++){  
                         Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) );  
 //          if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;    
                         if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){  
                             if( (oi->tdcflag).At(ih)==0 )nphit_i++;      
                         };  
                     };  
                   
                     if(  
                         (nphit_p+nphit_i) !=0 &&          
                         true){  
                       
                         if ( nphit_p != nphit_i ){  
                             totp_score += nphit_p;  
                             toti_score += nphit_i;  
                             tp_score+=nphit_p;  
                             ti_score+=nphit_i;  
                         };  
                         //          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;  
             };  
   
   
 //      if(tp_score == ti_score) use_TRK = true;  
   
   
             // -----------------------------------------------------------------------------------------  
             // *****************************************************************************************  
             // -----------------------------------------------------------------------------------------  
             // tracker check  
             // -----------------------------------------------------------------------------------------  
             // chi**2 difference is not always large enough to distinguish among  
             // the real track and its image.  
             // Tracker check will be applied always when calorimeter and tof information is ambiguous.  
             // *** MODIFIED ON AUGUST 2007 ***  
             if(use_TRK){  
 //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;  
 //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;  
   
                 // CHECK 1 : number of points along X    
                 if ( tp->GetNX() >= ti->GetNX() ){  
                     tp_score++ ;  
                     totp_score++ ;  
                 };  
                 if ( tp->GetNX() <= ti->GetNX() ){  
                     ti_score++ ;  
                     toti_score++ ;  
                 };  
                 // CHECK 2 : number of points along Y    
                 if ( tp->GetNY() >= ti->GetNY() ){  
                     tp_score++ ;  
                     totp_score++ ;  
                 };  
                 if ( tp->GetNY() <= ti->GetNY() ){  
                     ti_score++ ;  
                     toti_score++ ;  
                 };  
   
                 //      cout << "TRK "<<tp_score<<ti_score<<endl;  
             };  
               
   
             // -----------------------------------------------------------------------------------------  
             // *****************************************************************************************  
             // -----------------------------------------------------------------------------------------  
             // GPamela check  
             // -----------------------------------------------------------------------------------------  
               
             //---------------------------------------------------  
             // count the number of GP hits  
             //---------------------------------------------------  
             if(use_GP){  
                 int ngphits_p=0;  
                 int ngphits_i=0;  
                 float toll = 0.02; //200 micron  
                 for(int ih=0; ih<GetGPamela()->Nthspe; ih++){  
                     int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;  
                     if(  
                         tp &&  
                         tp->YGood(ip) &&  
                         fabs(tp->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&  
                         true) ngphits_p++;  
                     if( ti &&  
                         ti->YGood(ip) &&  
                         fabs(ti->ym[ip]- GetGPamela()->Yavspe[ih])<toll &&  
                         true) ngphits_i++;  
                 }  
                 if(  
                     ngphits_p > ngphits_i &&  
                     true){  
                     tp_score++ ;  
                     totp_score++ ;                    
                 }  
                 if(  
                     ngphits_p < ngphits_i &&  
                     true){  
                     ti_score++ ;  
                     toti_score++ ;                    
                 }  
             }  
   
   
             // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*  
             // the winner is....  
             // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*  
             if      (tp_score > ti_score) {  
           
   
             }else if (tp_score < ti_score) {  
   
   
                 ts = ti;//its image!!  
                 cs = ci;  
                 os = oi;  
                 rs = ri;  
                 Int_t totis = toti_score;  
   
                 ti = tp;//its image!!  
                 ci = cp;  
                 oi = op;  
                 ri = rp;  
   
                 tp = ts;//its image!!  
                 cp = cs;  
                 op = os;  
                 rp = rs;  
   
                 toti_score = totp_score;  
                 totp_score = totis;  
   
                   
             }else {  
   
 //      cout << "Warning - track image ambiguity not solved" << endl;  
   
             };  
               
         }else{  
             totp_score = 1;  
             toti_score = 0;  
         
             //      ts = tp;  
             //      cs = cp;  
             //      os = op;  
         };  
           
         //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;  
         //      sorted_tracks->Add(ts);//save the track in the sorted array  
         //      sorted_tracks.Add(ts);//save the track in the sorted array  
         //      sorted_tracks.Add(tp);//save the track in the sorted array  
         //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;  
         //      cout<<"o "<<tp<<endl;  
         //      cout<<"o "<<cp<<endl;  
         //      cout<<"o "<<op<<endl;  
   
         new(ttsorted[i]) PamTrack(tp,cp,op,rp);  
         new(ttimage[i])  PamTrack(ti,ci,oi,ri);  
   
         ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score);  
         ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score);  
         ((PamTrack*)(ttimage[i]))->SetPScore(totp_score);  
         ((PamTrack*)(ttimage[i]))->SetIScore(toti_score);  
     };  
1653    
1654      if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){    //Restore Object count
1655          cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;    //To save space in the table keeping track of all referenced objects
1656          tsorted->Delete(); tsorted=0;    //We reset the object count to what it was at the beginning of the event.
1657          timage->Delete(); timage=0;        TProcessID::SetObjectCount(ObjectNumber);
1658      }  
1659      //Everything went fine so the current event can be tagged as sorted
1660      issorted = true;
1661      lastsorted = GetReadEntry();
1662    
1663      //Restore Object count  }
1664      //To save space in the table keeping track of all referenced objects  ;
     //We reset the object count to what it was at the beginning of the event.  
     TProcessID::SetObjectCount(ObjectNumber);  
       
 };  
1665  //--------------------------------------  //--------------------------------------
1666  //  //
1667  //  //
# Line 1560  void PamLevel2::SortTracks(){ Line 1678  void PamLevel2::SortTracks(){
1678    
1679  // //   return  sorted_tracks;  // //   return  sorted_tracks;
1680  //     return &sorted_tracks;  //     return &sorted_tracks;
1681        
1682  //  };  //  };
1683  TClonesArray *PamLevel2::GetTracks(){  TClonesArray *PamLevel2::GetTracks() {
1684    
1685      //  *-*-*-*-*-*-*-*-*-*-*-*-*
1686      SortTracks();
1687      //  *-*-*-*-*-*-*-*-*-*-*-*-*
1688    
1689      return tsorted;
1690    
1691  //  *-*-*-*-*-*-*-*-*-*-*-*-*  }
1692      SortTracks();  ;
 //  *-*-*-*-*-*-*-*-*-*-*-*-*  
   
     return tsorted;  
       
 };  
1693  //--------------------------------------  //--------------------------------------
1694  //  //
1695  //  //
1696  //--------------------------------------  //--------------------------------------
1697  /**  /**
1698   * Retrieves the it-th Pamela "physical" track.   * Retrieves the it-th Pamela "physical" track.
1699   * It override TrkLevel2::GetTrack(int it).   * It override TrkLevel2::GetTrack(int it).
1700   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
1701   */   */
1702  PamTrack *PamLevel2::GetTrack(int it){  PamTrack *PamLevel2::GetTrack(int it) {
1703    
1704  //    if(!trk2_obj) return 0;    //    if(!trk2_obj) return 0;
           
 // //  *-*-*-*+-*-*-*-*-*-*-*-*-*  
 //     SortTracks("+CAL+TOF");  
 // //  *-*-*-*-*-*-*-*-*-*-*-*-*  
 // //    if(!sorted_tracks)return 0;  
 //     if(sorted_tracks.IsEmpty())return 0;  
1705    
1706  //     PamTrack *track = 0;    // //  *-*-*-*+-*-*-*-*-*-*-*-*-*
1707          //     SortTracks("+CAL+TOF");
1708  //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() && it<sorted_tracks.GetEntriesFast() ){        // //  *-*-*-*-*-*-*-*-*-*-*-*-*
1709  //      TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);    // //    if(!sorted_tracks)return 0;
1710  //      track = GetPamTrackAlong(t);    //     if(sorted_tracks.IsEmpty())return 0;
1711  //     }else{  
1712  //      cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;    //     PamTrack *track = 0;
1713  //     };  
1714          //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() && it<sorted_tracks.GetEntriesFast() ){
1715  //     return track;    //    TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);
1716      //    track = GetPamTrackAlong(t);
1717  //    cout << "PamLevel2::GetTrack(int it) "<<endl;    //     }else{
1718  //  *-*-*-*-*-*-*-*-*-*-*-*-*    //    cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;
1719      SortTracks();    //     };
1720  //  *-*-*-*-*-*-*-*-*-*-*-*-*  
1721      if(!tsorted)return 0;    //     return track;
1722      if(!tsorted->GetEntries())return 0;  
1723      //    cout << "PamLevel2::GetTrack(int it) "<<endl;
1724      PamTrack *track = 0;    //  *-*-*-*-*-*-*-*-*-*-*-*-*
1725          SortTracks();
1726      if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks()){    //  *-*-*-*-*-*-*-*-*-*-*-*-*
1727  //      TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);    if (!tsorted)
1728  //      track = GetPamTrackAlong(t);      return 0;
1729          TClonesArray &t = *(tsorted);    if (!tsorted->GetEntries())
1730          track = (PamTrack*)t[it];      return 0;
1731            
1732      }else{    PamTrack *track = 0;
1733          cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;  
1734      };    if (it >= 0 && it < trk2_obj->TrkLevel2::GetNTracks()) {
1735            //  TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);
1736      return track;      //  track = GetPamTrackAlong(t);
1737            //TClonesArray &t = *(tsorted);
1738  };      //track = (PamTrack*)t[it];
1739        track = (PamTrack*)((*tsorted)[it]);
1740      }
1741      else {
1742        cout << "PamLevel2::GetTrack(int) : tracker track SeqNo " << it << " does not exist (GetNTracks() = "
1743            << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
1744      };
1745    
1746      return track;
1747    
1748    }
1749    ;
1750    
1751  //--------------------------------------  //--------------------------------------
1752  //  //
1753  //  //
1754  //--------------------------------------  //--------------------------------------
1755  /**  /**
1756   * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().   * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().
1757   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
1758   */   */
1759  PamTrack *PamLevel2::GetTrackImage(int it){  PamTrack *PamLevel2::GetTrackImage(int it) {
1760    
1761  //  *-*-*-*-*-*-*-*-*-*-*-*-*    //  *-*-*-*-*-*-*-*-*-*-*-*-*
1762      SortTracks();    SortTracks();
1763  //  *-*-*-*-*-*-*-*-*-*-*-*-*    //  *-*-*-*-*-*-*-*-*-*-*-*-*
1764      if(!timage)return 0;    if (!timage)
1765      if(!timage->GetEntries())return 0;      return 0;
1766          if (!timage->GetEntries())
1767      PamTrack *image = 0;      return 0;
1768        
1769      if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){    PamTrack *image = 0;
1770          TClonesArray &t = *(tsorted);  
1771          PamTrack *temp = (PamTrack*)t[it];    if (it >= 0 && it < trk2_obj->TrkLevel2::GetNTracks()) {
1772          if( temp->GetTrkTrack()->HasImage() ){      TClonesArray &t = *(tsorted);
1773              TClonesArray &t = *(timage);      PamTrack *temp = (PamTrack*) t[it];
1774              image = (PamTrack*)t[it];      if (temp->GetTrkTrack()->HasImage()) {
1775          }else{        TClonesArray & t = *(timage);
1776  //          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;        image = (PamTrack*) t[it];
1777          };      }
1778      }else{      else {
1779          cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;        //            cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
1780      };      };
1781          }
1782      return image;    else {
1783        cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo " << it << " does not exist (GetNTracks() = "
1784            << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
1785      };
1786    
1787      return image;
1788  }  }
1789    
1790  //--------------------------------------  //--------------------------------------
# Line 1668  PamTrack *PamLevel2::GetTrackImage(int i Line 1797  PamTrack *PamLevel2::GetTrackImage(int i
1797   * @param detlist String to select trees to be included   * @param detlist String to select trees to be included
1798   * @return Pointer to a TTree   * @return Pointer to a TTree
1799   */   */
1800  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist) {
1801    
1802      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {    if (detlist.Contains("+AUTO", TString::kIgnoreCase)) {
1803          cout << "+AUTO"<<endl;      cout << "+AUTO" << endl;
1804          GetWhichTrees(f);      GetWhichTrees(f);
1805      };    };
1806      SetWhichTrees(detlist);    SetWhichTrees(detlist);
1807    
1808      if ( pam_tree ){    if (pam_tree) {
1809          printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");      printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n ");
1810          return pam_tree;      return pam_tree;
1811      };    };
1812      //    //
1813    
1814      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;    cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte " << endl;
1815    
1816  //    SetWhichTrees(detlist);    //    SetWhichTrees(detlist);
1817    
1818      TTree *Trout =0;    TTree *Trout = 0;
1819    
1820      TString fname = f->GetName();    TString fname = f->GetName();
1821      if(!CheckLevel2File(fname))return NULL;    if (!CheckLevel2File(fname))
1822        return NULL;
1823    
1824  //    UInt_t *found=0;        //    UInt_t *found=0;
   
     cout<< "GetPamTree(TFile*,TString): detector list --> ";  
     if(TRK1)cout<<"TRK1 ";  
     if(TRK2)cout<<"TRK2 ";  
     if(TRKh)cout<<"TRKH ";  
     if(CAL1)cout<<"CAL1 ";  
     if(CAL2)cout<<"CAL2 ";  
     if(TOF)cout<<"TOF ";  
     if(TRG)cout<<"TRG ";  
     if(AC)cout<<"AC ";  
     if(ND)cout<<"ND ";  
     if(S4)cout<<"S4 ";  
     if(ORB)cout<<"ORB ";  
     if(GP)cout<<"GP ";  
     cout << endl;  
     if(SELLI && SELLI!=2)cout<<">>> Found selection-list <<<"<<endl; //EMILIANO  
   
     f->cd();  
   
 // Tracker  
     TTree *T = (TTree*)f->Get("Tracker");  
     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;  
         if(!Trout)Trout=T;  
         else Trout->AddFriend(T);  
     }else{  
         cout << "Tracker      : missing tree"<<endl;  
     };  
     // Calorimeter  
     TTree *C = (TTree*)f->Get("Calorimeter");  
     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;  
         if(!Trout)Trout=C;  
         else Trout->AddFriend(C);  
     }else{  
         cout << "Calorimeter  : missing tree"<<endl;  
     };  
1825    
1826      // ToF        cout << "GetPamTree(TFile*,TString): detector list --> ";
1827      TTree *O = (TTree*)f->Get("ToF");    if (TRK1)
1828      if(O && TOF) {      cout << "TRK1 ";
1829          O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));    if (TRK2)
1830          cout << "ToF          : set branch address ToFLevel2"<<endl;      cout << "TRK2 ";
1831          if(!Trout)Trout=O;    if (TRKh)
1832          else Trout->AddFriend(O);      cout << "TRKH ";
1833      }else{    if (CAL1)
1834          cout << "ToF         : missing tree"<<endl;      cout << "CAL1 ";
1835      };    if (CAL2)
1836      // Trigger      cout << "CAL2 ";
1837      TTree *R = (TTree*)f->Get("Trigger");    if (TOF)
1838      if(R && TRG) {      cout << "TOF ";
1839          R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));    if (TRG)
1840          cout << "Trigger      : set branch address TrigLevel2"<<endl;      cout << "TRG ";
1841          if(!Trout)Trout=R;    if (AC)
1842          else Trout->AddFriend(R);      cout << "AC ";
1843      }else{    if (ND)
1844          cout << "Trigger      : missing tree"<<endl;      cout << "ND ";
1845      };    if (S4)
1846      // S4      cout << "S4 ";
1847      TTree *S = (TTree*)f->Get("S4");    if (ORB)
1848      if(S && S4) {      cout << "ORB ";
1849          S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));    if (GP)
1850          cout << "S4           : set branch address S4Level2"<<endl;      cout << "GP ";
1851          if(!Trout)Trout=S;    cout << endl;
1852          else Trout->AddFriend(S);    if (SELLI && SELLI != 2)
1853      }else{      cout << ">>> Found selection-list <<<" << endl; //EMILIANO
1854          cout << "S4           : missing tree"<<endl;  
1855      };    f->cd();
1856      // Neutron Detector  
1857      TTree *N = (TTree*)f->Get("NeutronD");    // Tracker
1858      if(N && ND) {    TTree *T = (TTree*) f->Get("Tracker");
1859          N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));    if (T && (TRK2 || TRK1 || TRKh)) {
1860          cout << "NeutronD     : set branch address NDLevel2"<<endl;      if (TRK2)
1861          if(!Trout)Trout=N;        T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1862          else Trout->AddFriend(N);      //  else    T->SetBranchStatus("TrkLevel2",0,found);
1863      }else{      if (TRK2)
1864          cout << "NeutronD     : missing tree"<<endl;        cout << "Tracker      : set branch address TrkLevel2" << endl;
1865      };      if (TRK1)
1866      // Anticounters        T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1867      TTree *A = (TTree*)f->Get("Anticounter");      //  else    T->SetBranchStatus("TrkLevel1",0,found);
1868      if(A && AC) {      if (TRK1)
1869          A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));        cout << "Tracker      : set branch address TrkLevel1" << endl;
1870          cout << "Anticounter  : set branch address AcLevel2"<<endl;      if (TRKh)
1871          if(!Trout)Trout=A;        T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1872          else Trout->AddFriend(A);      //  else    T->SetBranchStatus("TrkHough",0,found);
1873      }else{      if (TRKh)
1874          cout << "Anticounter  : missing tree"<<endl;        cout << "Tracker      : set branch address TrkHough" << endl;
1875      };      if (!Trout)
1876      // Orbital Info        Trout = T;
1877      TTree *B = (TTree*)f->Get("OrbitalInfo");      else
1878      if(B && ORB) {        Trout->AddFriend(T);
1879          B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));    }
1880          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;    else {
1881          if(!Trout)Trout=B;      cout << "Tracker      : missing tree" << endl;
1882          else Trout->AddFriend(B);    };
1883      }else{    // Calorimeter
1884          cout << "OrbitalInfo  : missing tree"<<endl;    TTree *C = (TTree*) f->Get("Calorimeter");
1885      };    if (C && (CAL2 || CAL1)) {
1886        if (CAL2)
1887          C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1888        //  else    C->SetBranchStatus("CaloLevel2",0,found);
1889        if (CAL2)
1890          cout << "Calorimeter  : set branch address CaloLevel2" << endl;
1891        if (CAL1)
1892          C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1893        //  else    C->SetBranchStatus("CaloLevel1",0,found);
1894        if (CAL1)
1895          cout << "Calorimeter  : set branch address CaloLevel1" << endl;
1896        if (!Trout)
1897          Trout = C;
1898        else
1899          Trout->AddFriend(C);
1900      }
1901      else {
1902        cout << "Calorimeter  : missing tree" << endl;
1903      };
1904    
1905      // GPamela    // ToF
1906      TTree *G = (TTree*)f->Get("h20");    TTree *O = (TTree*) f->Get("ToF");
1907      if(G && GP) {    if (O && TOF) {
1908          if(!gp_obj)gp_obj=new GPamela();      O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
1909  //      ------------------------------------      cout << "ToF          : set branch address ToFLevel2" << endl;
1910  //      ATTENZIONE!!!      if (!Trout)
1911  //      non so per quale arcano motivo,        Trout = O;
1912  //      per l'albero di gpamela il branch address lo devo settare      else
1913  //      DOPO aver fatto friend        Trout->AddFriend(O);
1914  //      FGRRRVZZZZUTSALKJMSLKJ!!!    }
1915  //      ------------------------------------    else {
1916  //      gp_obj->SetBranchAddress(G); //ho dovuto fare in maniera diversa dagli altri      cout << "ToF         : missing tree" << endl;
1917  //      cout << "h20          : set branch address GPamela "<<endl;    };
1918          if(!Trout)Trout=G;    // Trigger
1919          else Trout->AddFriend(G);    TTree *R = (TTree*) f->Get("Trigger");
1920      }else{    if (R && TRG) {
1921  //      cout << "h20          : missing tree"<<endl;      R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1922      };      cout << "Trigger      : set branch address TrigLevel2" << endl;
1923        if (!Trout)
1924          Trout = R;
1925        else
1926          Trout->AddFriend(R);
1927      }
1928      else {
1929        cout << "Trigger      : missing tree" << endl;
1930      };
1931      // S4
1932      TTree *S = (TTree*) f->Get("S4");
1933      if (S && S4) {
1934        S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1935        cout << "S4           : set branch address S4Level2" << endl;
1936        if (!Trout)
1937          Trout = S;
1938        else
1939          Trout->AddFriend(S);
1940      }
1941      else {
1942        cout << "S4           : missing tree" << endl;
1943      };
1944      // Neutron Detector
1945      TTree *N = (TTree*) f->Get("NeutronD");
1946      if (N && ND) {
1947        N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1948        cout << "NeutronD     : set branch address NDLevel2" << endl;
1949        if (!Trout)
1950          Trout = N;
1951        else
1952          Trout->AddFriend(N);
1953      }
1954      else {
1955        cout << "NeutronD     : missing tree" << endl;
1956      };
1957      // Anticounters
1958      TTree *A = (TTree*) f->Get("Anticounter");
1959      if (A && AC) {
1960        A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1961        cout << "Anticounter  : set branch address AcLevel2" << endl;
1962        if (!Trout)
1963          Trout = A;
1964        else
1965          Trout->AddFriend(A);
1966      }
1967      else {
1968        cout << "Anticounter  : missing tree" << endl;
1969      };
1970      // Orbital Info
1971      TTree *B = (TTree*) f->Get("OrbitalInfo");
1972      if (B && ORB) {
1973        B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1974        cout << "OrbitalInfo  : set branch address OrbitalInfo" << endl;
1975        if (!Trout)
1976          Trout = B;
1977        else
1978          Trout->AddFriend(B);
1979      }
1980      else {
1981        cout << "OrbitalInfo  : missing tree" << endl;
1982      };
1983    
1984      // GPamela
1985      TTree *G = (TTree*) f->Get("h20");
1986      if (G && GP) {
1987        if (!gp_obj)
1988          gp_obj = new GPamela();
1989        //      ------------------------------------
1990        //      ATTENZIONE!!!
1991        //      non so per quale arcano motivo,
1992        //      per l'albero di gpamela il branch address lo devo settare
1993        //      DOPO aver fatto friend
1994        //      FGRRRVZZZZUTSALKJMSLKJ!!!
1995        //      ------------------------------------
1996        //  gp_obj->SetBranchAddress(G); //ho dovuto fare in maniera diversa dagli altri
1997        //  cout << "h20          : set branch address GPamela "<<endl;
1998        if (!Trout)
1999          Trout = G;
2000        else
2001          Trout->AddFriend(G);
2002      }
2003      else {
2004        //  cout << "h20          : missing tree"<<endl;
2005      };
2006    
2007      TTree *L = (TTree*) f->Get("SelectionList");
2008      if (L && SELLI == 1) {
2009        cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemented!!!!" << endl;
2010        sel_tree = 0;
2011      }
2012      else {
2013        cout << "SelectionList  : missing tree" << endl;
2014      };
2015    
2016      TTree *L = (TTree*)f->Get("SelectionList");    cout << endl << " Number of entries: " << Trout->GetEntries() << endl << endl;
     if(L && SELLI==1) {  
         cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemented!!!!"<<endl;  
         sel_tree = 0;  
     }else{  
         cout << "SelectionList  : missing tree"<<endl;  
     };  
       
     cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;  
2017    
2018  //      ------------------------------------    //      ------------------------------------
2019  //      ATTENZIONE!!!    //      ATTENZIONE!!!
2020  //      non so per quale arcano motivo,    //      non so per quale arcano motivo,
2021  //      per l'albero di gpamela il branch address lo devo settare    //      per l'albero di gpamela il branch address lo devo settare
2022  //      DOPO aver fatto friend    //      DOPO aver fatto friend
2023  //      FGRRRVZZZZUTSALKJMSLKJ!!!    //      FGRRRVZZZZUTSALKJMSLKJ!!!
2024  //      ------------------------------------    //      ------------------------------------
2025      if(G && GP) {          if (G && GP) {
2026          gp_obj->SetBranchAddress(Trout); //ho dovuto fare in maniera diversa dagli altri      gp_obj->SetBranchAddress(Trout); //ho dovuto fare in maniera diversa dagli altri
2027          cout << "h20          : set branch address GPamela "<<endl;      cout << "h20          : set branch address GPamela " << endl;
2028      }else{    }
2029          cout << "h20          : missing tree"<<endl;    else {
2030      };      cout << "h20          : missing tree" << endl;
2031      };
2032    
2033      pam_tree = (TChain*) Trout;
2034    
2035      return Trout;
2036    
     pam_tree = (TChain*)Trout;  
       
     return Trout;  
       
2037  }  }
2038  //--------------------------------------  //--------------------------------------
2039  //  //
# Line 1864  TTree *PamLevel2::GetPamTree(TFile *f, T Line 2046  TTree *PamLevel2::GetPamTree(TFile *f, T
2046   * @return Pointer to a TList of TSystemFiles   * @return Pointer to a TList of TSystemFiles
2047   * If no input file list is given , all the Level2 files inside the directory are processed.   * If no input file list is given , all the Level2 files inside the directory are processed.
2048   */   */
2049  TList*  PamLevel2::GetListOfLevel2Files(TString ddir, TString flisttxt = ""){  TList* PamLevel2::GetListOfLevel2Files(TString ddir, TString flisttxt = "") {
2050            
2051      TString wdir = gSystem->WorkingDirectory();    TString wdir = gSystem->WorkingDirectory();
2052    
2053      if ( ddir != ""){    if (ddir != "") {
2054          cout << "Level2 data directory : "<<  ddir << endl;      cout << "Level2 data directory : " << ddir << endl;
2055      } else {    }
2056          cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory " << endl;    else {
2057      };      cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory "
2058      TList *contents  = new TList; // create output list          << endl;
2059      contents->SetOwner();    };
2060          TList *contents = new TList; // create output list
2061      contents->SetOwner();
2062    
2063      // --------------------------------------
2064      // case 1 : input file/file-list provided
2065      // --------------------------------------
2066      if (flisttxt != "") {
2067    
2068      // --------------------------------------      // --------------------------------------
2069      // case 1 : input file/file-list provided      // a list of files given as input
2070      // --------------------------------------      // --------------------------------------
2071      if ( flisttxt != "" ){      if (!flisttxt.EndsWith(".root")) {
2072            
2073          // --------------------------------------        TString dir = gSystem->DirName(flisttxt);
2074          // a list of files given as input        //            cout << " List directory "<<dir<<endl;
2075          // --------------------------------------        if (dir == "." || dir == "")
2076          if ( !flisttxt.EndsWith(".root") ){          flisttxt = gSystem->ConcatFileName(wdir.Data(), gSystem->BaseName(flisttxt));
2077          //                flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
2078              TString dir = gSystem->DirName(flisttxt);  
2079  //          cout << " List directory "<<dir<<endl;        if (!gSystem->ChangeDirectory(ddir)) {
2080              if(dir == "." || dir == "")          cout << "Cannot change directory : " << ddir << endl;
2081                  flisttxt = gSystem->ConcatFileName(wdir.Data(),gSystem->BaseName(flisttxt));          return 0;
2082  //              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));        }
2083    
2084              if( !gSystem->ChangeDirectory(ddir) ){        cout << "Input file list : " << flisttxt << endl;
2085                  cout << "Cannot change directory : "<<ddir<<endl;        ifstream in;
2086                  return 0;        in.open(flisttxt, ios::in); //open input file list
2087              }        if (!in.good()) {
2088                    cout << " TList*  PamLevel2::GetListOfLevel2Files(TString, TString) --> ERROR opening the file " << endl;
2089              cout <<"Input file list : " << flisttxt <<endl;          gSystem->ChangeDirectory(wdir); // back to the working directory
2090              ifstream in;          return 0;
2091              in.open(flisttxt, ios::in); //open input file list        }
2092              if(!in.good()){        int line = 0;
2093                  cout <<" TList*  PamLevel2::GetListOfLevel2Files(TString, TString) --> ERROR opening the file "<<endl;        // ...........................
2094                  gSystem->ChangeDirectory(wdir); // back to the working directory        // loop over file-list records
2095                  return 0;        // ...........................
2096              }          while (1) {
2097              int line=0;          TString file;
2098              // ...........................          in >> file;
2099              // loop over file-list records          if (!in.good())
2100              // ...........................            break;
2101              while (1) {          line++;
2102                  TString file;          cout << "(*) " << file << endl;
2103                  in >> file;          if (file.IsNull()) {
2104                  if (!in.good()) break;            cout << "-- list interrupted at line " << line << endl;
2105                  line++;            break;
2106                  cout <<"(*) " << file << endl;          }
2107                  if(file.IsNull()){          if (file.Contains("#"))
2108                      cout << "-- list interrupted at line "<<line <<endl;            file = file(0, file.First("#"));
2109                      break;          //
2110                  }          // take only root files
2111                  if(file.Contains("#"))file = file(0,file.First("#"));          //
2112                  //          if (file.EndsWith(".root")) {
2113                  // take only root files            TString filedir;
2114                  //            cout << ddir << endl;
2115                  if( file.EndsWith(".root") ){            if (ddir != "") {
2116                      TString filedir;              filedir = ddir; // take the input dir
2117                      cout << ddir << endl;            }
2118                      if (ddir != ""){            else {
2119                          filedir = ddir; // take the input dir              gSystem->ChangeDirectory(wdir); // back to the working directory
2120                      } else {              filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir
2121                          gSystem->ChangeDirectory(wdir); // back to the working directory            };
2122                          filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir            filedir.Append("/");
2123                      };            char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir), gSystem->BaseName(file));
2124                      filedir.Append("/");            contents->Add(new TSystemFile(fullpath, gSystem->DirName(fullpath)));// add file to the list
2125                      char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));            cout << fullpath << endl;
2126                      contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list            delete fullpath;
2127                      cout << fullpath << endl;          }
2128                      delete fullpath;          //          }else{
2129                  }          //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
2130  //          }else{          //          };
2131  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;        };
2132  //          };        in.close();
2133              };        // --------------------------------------
2134              in.close();        // a single root file given as input
2135          // --------------------------------------        // --------------------------------------
2136          // a single root file given as input      }
2137          // --------------------------------------      else {
2138          } else {        if (flisttxt.Contains("#"))
2139              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));          flisttxt = flisttxt(0, flisttxt.First("#"));
2140              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));        char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt), gSystem->BaseName(flisttxt));
2141              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
2142              delete fullpath;        delete fullpath;
2143          };            };
2144      // ---------------------------------------------------------------------------------      // ---------------------------------------------------------------------------------
2145      // case 2 : no input file/file-list provided --> read all files insede the directory      // case 2 : no input file/file-list provided --> read all files insede the directory
2146      // ---------------------------------------------------------------------------------      // ---------------------------------------------------------------------------------
2147      }else{    }
2148              else {
2149          cout << "No input file list given."<<endl;  
2150          cout << "Check for existing root files."<<endl;      cout << "No input file list given." << endl;
2151  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;      cout << "Check for existing root files." << endl;
2152          if ( ddir == "" ){      //          cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
2153              ddir = wdir;      if (ddir == "") {
2154              cout << "Level2 data directory : "<<  ddir << endl;        ddir = wdir;
2155          };        cout << "Level2 data directory : " << ddir << endl;
   
         TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);  
         TList *temp = datadir->GetListOfFiles();  
         if(!temp)return 0;  
 //              temp->Print();  
 //              cout << "*************************************" << endl;  
           
         TIter next(temp);  
         TSystemFile *questo = 0;  
           
           
         while ( (questo = (TSystemFile*) next()) ) {  
             TString name =  questo-> GetName();  
             if( name.EndsWith(".root") ){  
 //              const char *fullpath = gSystem->FindFile(ddir,name);  
 //              char *fullpath;  
 //              gSystem->IsFileInIncludePath(name,&fullpath);  
                 char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(name));  
                 contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));  
                 delete fullpath;  
             };  
         }  
         delete temp;  
         delete datadir;  
           
2156      };      };
2157      gSystem->ChangeDirectory(wdir); // back to the working directory  
2158  //      cout << endl << "Selected files:" << endl;      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir), ddir);
2159  //      contents->Print();      TList *temp = datadir->GetListOfFiles();
2160      cout << contents->GetEntries()<<" files \n";      if (!temp)
2161  //      cout << endl;        return 0;
2162  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;      //          temp->Print();
2163      return contents;      //          cout << "*************************************" << endl;
2164  };  
2165  //--------------------------------------      TIter next(temp);
2166  //      TSystemFile *questo = 0;
2167  //  
2168  //--------------------------------------      while ((questo = (TSystemFile*) next())) {
2169  /**        TString name = questo-> GetName();
2170   * Get the Pamela detector chains from a list of files and make them friends.        if (name.EndsWith(".root")) {
2171   * @param fl Pointer to a TList of TSystemFiles          //              const char *fullpath = gSystem->FindFile(ddir,name);
2172   * @param detlist String to select trees to be included          //              char *fullpath;
2173            //              gSystem->IsFileInIncludePath(name,&fullpath);
2174            char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir), gSystem->BaseName(name));
2175            contents->Add(new TSystemFile(fullpath, gSystem->DirName(fullpath)));
2176            delete fullpath;
2177          };
2178        }
2179        delete temp;
2180        delete datadir;
2181    
2182      };
2183      gSystem->ChangeDirectory(wdir); // back to the working directory
2184      //    cout << endl << "Selected files:" << endl;
2185      //    contents->Print();
2186      cout << contents->GetEntries() << " files \n";
2187      //    cout << endl;
2188      //    cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;
2189      return contents;
2190    }
2191    ;
2192    //--------------------------------------
2193    //
2194    //
2195    //--------------------------------------
2196    /**
2197     * Get the Pamela detector chains from a list of files and make them friends.
2198     * @param fl Pointer to a TList of TSystemFiles
2199     * @param detlist String to select trees to be included
2200   * @return Pointer to a TChain   * @return Pointer to a TChain
2201   */   */
2202  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist) {
2203      //    //
2204      //    //
2205      //    //
2206      if ( pam_tree ){    if (pam_tree) {
2207          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 ");
2208          return pam_tree;      return pam_tree;
2209      };    };
2210      //    //
       
     TChain *Trout =0;  
2211    
2212      // -------------------------------------------    TChain *Trout = 0;
     // set flags to include/exclude trees/branches  
     // -------------------------------------------  
     if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {  
         if( fl->GetEntries()>0 ){  
             cout << "+AUTO"<<endl;  
             TFile *fprimo = new TFile( fl->At(0)->GetName() );  
             GetWhichTrees(fprimo);  
             fprimo->Close();// AAAAARGGGGGHHHHH!!!!!!! non commentare questa riga, altrimenti si incasina il TChain  
             fprimo->Delete();  
         }  
     };  
     SetWhichTrees(detlist);      
2213    
2214      // -------------------------------------------
2215      // set flags to include/exclude trees/branches
2216      // -------------------------------------------
2217      if (detlist.Contains("+AUTO", TString::kIgnoreCase)) {
2218        if (fl->GetEntries() > 0) {
2219          cout << "+AUTO" << endl;
2220          TFile *fprimo = new TFile(fl->At(0)->GetName());
2221          GetWhichTrees(fprimo);
2222          fprimo->Close();// AAAAARGGGGGHHHHH!!!!!!! non commentare questa riga, altrimenti si incasina il TChain
2223          fprimo->Delete();
2224        }
2225      };
2226      SetWhichTrees(detlist);
2227    
2228      // -------------------------------------------    // -------------------------------------------
2229      // build chains    // build chains
2230      // -------------------------------------------    // -------------------------------------------
2231      TChain *T = 0;          TChain *T = 0;
2232      TChain *C = 0;    TChain *C = 0;
2233      TChain *O = 0;    TChain *O = 0;
2234      TChain *R = 0;    TChain *R = 0;
2235      TChain *S = 0;    TChain *S = 0;
2236      TChain *N = 0;    TChain *N = 0;
2237      TChain *A = 0;    TChain *A = 0;
2238      TChain *B = 0;    TChain *B = 0;
2239      TChain *G = 0;    TChain *G = 0;
2240    
2241      TChain *L = 0;    TChain *L = 0;
2242        
2243      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");        if (TRK2 || TRK1 || TRKh)
2244      if(CAL2||CAL1)       C = new TChain("Calorimeter");      T = new TChain("Tracker");
2245      if(TOF)              O = new TChain("ToF");    if (CAL2 || CAL1)
2246      if(TRG)              R = new TChain("Trigger");      C = new TChain("Calorimeter");
2247      if(S4)               S = new TChain("S4");    if (TOF)
2248      if(ND)               N = new TChain("NeutronD");      O = new TChain("ToF");
2249      if(AC)               A = new TChain("Anticounter");    if (TRG)
2250      if(ORB)              B = new TChain("OrbitalInfo");      R = new TChain("Trigger");
2251      if(GP)               G = new TChain("h20");    if (S4)
2252      L = new TChain("SelectionList");      S = new TChain("S4");
2253          if (ND)
2254      // loop over files and create chains              N = new TChain("NeutronD");
2255      TIter next(fl);    if (AC)
2256      TSystemFile *questo = 0;      A = new TChain("Anticounter");
2257      while ( (questo = (TSystemFile*) next()) ) {    if (ORB)
2258          TString name =  questo->GetName();      B = new TChain("OrbitalInfo");
2259          cout << "File: "<< name << endl;    if (GP)
2260          if( CheckLevel2File(name) ){      G = new TChain("h20");
2261              if(TRK2||TRK1||TRKh) T->Add(name);    L = new TChain("SelectionList");
2262              if(CAL1||CAL2)       C->Add(name);  
2263              if(TOF)              O->Add(name);    // loop over files and create chains
2264              if(TRG)              R->Add(name);    TIter next(fl);
2265              if(S4)               S->Add(name);    TSystemFile *questo = 0;
2266              if(ND)               N->Add(name);    while ((questo = (TSystemFile*) next())) {
2267              if(AC)               A->Add(name);      TString name = questo->GetName();
2268              if(ORB)              B->Add(name);      cout << "File: " << name << endl;
2269              if(GP)               G->Add(name);      if (CheckLevel2File(name)) {
2270              if(SELLI==1)         L->Add(name);        if (TRK2 || TRK1 || TRKh)
2271          };          T->Add(name);
2272          if (CAL1 || CAL2)
2273            C->Add(name);
2274          if (TOF)
2275            O->Add(name);
2276          if (TRG)
2277            R->Add(name);
2278          if (S4)
2279            S->Add(name);
2280          if (ND)
2281            N->Add(name);
2282          if (AC)
2283            A->Add(name);
2284          if (ORB)
2285            B->Add(name);
2286          if (GP)
2287            G->Add(name);
2288          if (SELLI == 1)
2289            L->Add(name);
2290      };      };
2291          };
     cout << "done chains\n";  
     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
2292    
2293      cout << "done chains\n";
2294      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
2295    
2296      // -------------------------------------------    // -------------------------------------------
2297      // make friends    // make friends
2298      // -------------------------------------------    // -------------------------------------------
2299    
2300  // Tracker    // Tracker
2301      cout << "Friends: "<<endl;    cout << "Friends: " << endl;
2302      if(T && (TRK2||TRK1||TRKh)) {    if (T && (TRK2 || TRK1 || TRKh)) {
2303          if(!Trout)Trout=T;      if (!Trout)
2304          else Trout->AddFriend("Tracker");        Trout = T;
2305  //      cout << "+Tacker"<<endl;      else
2306      };        Trout->AddFriend("Tracker");
2307      // Calorimeter      //  cout << "+Tacker"<<endl;
2308      if(C && (CAL2||CAL1)) {    };
2309          if(!Trout)Trout=C;    // Calorimeter
2310          else Trout->AddFriend("Calorimeter");    if (C && (CAL2 || CAL1)) {
2311  //      cout << "+Calorimeter"<<endl;      if (!Trout)
2312      };        Trout = C;
2313      // ToF          else
2314      if(O && TOF) {        Trout->AddFriend("Calorimeter");
2315          if(!Trout)Trout=O;      //  cout << "+Calorimeter"<<endl;
2316          else Trout->AddFriend("ToF");    };
2317  //      cout << "+ToF"<<endl;    // ToF
2318      };    if (O && TOF) {
2319      // Trigger      if (!Trout)
2320      if(R && TRG) {        Trout = O;
2321          if(!Trout)Trout=O;      else
2322          else Trout->AddFriend("Trigger");        Trout->AddFriend("ToF");
2323  //      cout << "+Trigger"<<endl;      //  cout << "+ToF"<<endl;
2324      };    };
2325      // S4    // Trigger
2326      if(S && S4) {    if (R && TRG) {
2327          if(!Trout)Trout=O;      if (!Trout)
2328          else Trout->AddFriend("S4");        Trout = O;
2329  //      cout << "+S4"<<endl;      else
2330      };        Trout->AddFriend("Trigger");
2331      // Neutron Detector      //  cout << "+Trigger"<<endl;
2332      if(N && ND) {    };
2333          if(!Trout)Trout=O;    // S4
2334          else Trout->AddFriend("NeutronD");    if (S && S4) {
2335  //      cout << "+NeutronD"<<endl;      if (!Trout)
2336      };        Trout = O;
2337      // Anticounters      else
2338      if(A && AC) {        Trout->AddFriend("S4");
2339          if(!Trout)Trout=O;      //  cout << "+S4"<<endl;
2340          else Trout->AddFriend("Anticounter");    };
2341  //      cout << "+Anticounter"<<endl;    // Neutron Detector
2342      };    if (N && ND) {
2343      // Orbital Info      if (!Trout)
2344      if(B && ORB) {        Trout = O;
2345          if(!Trout)Trout=O;      else
2346          else Trout->AddFriend("OrbitalInfo");        Trout->AddFriend("NeutronD");
2347  //      cout << "+OrbitalInfo"<<endl;      //  cout << "+NeutronD"<<endl;
2348      };    };
2349      // GPamela    // Anticounters
2350      if(G && GP) {    if (A && AC) {
2351          if(!Trout)Trout=G;      if (!Trout)
2352          else Trout->AddFriend("h20");        Trout = O;
2353  //      cout << "+h20"<<endl;      else
2354      };        Trout->AddFriend("Anticounter");
2355        //  cout << "+Anticounter"<<endl;
2356      };
2357      // Orbital Info
2358      if (B && ORB) {
2359        if (!Trout)
2360          Trout = O;
2361        else
2362          Trout->AddFriend("OrbitalInfo");
2363        //  cout << "+OrbitalInfo"<<endl;
2364      };
2365      // GPamela
2366      if (G && GP) {
2367        if (!Trout)
2368          Trout = G;
2369        else
2370          Trout->AddFriend("h20");
2371        //  cout << "+h20"<<endl;
2372      };
2373    
2374  //  =====================================    //  =====================================
2375  //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND    //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND
2376  //  =====================================    //  =====================================
2377      SetBranchAddress(Trout);    SetBranchAddress(Trout);
2378    
2379      //  ------------------------------------
2380  //  ------------------------------------    //  finally handle selection trees...
2381  //  finally handle selection trees...    //  (it is not friend of pamela tree)
2382  //  (it is not friend of pamela tree)    //  ------------------------------------
2383  //  ------------------------------------  
2384      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
2385      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
2386      // Selection List
2387      // Selection List    if (L && SELLI == 1) {
2388      if(L && SELLI==1) {      cout << ">>> Found selection-list <<<" << endl;
2389          cout<<">>> Found selection-list <<<"<<endl;      //  L->SetBranchAddress("RunEntry",&irun);
2390  //      L->SetBranchAddress("RunEntry",&irun);      L->SetBranchAddress("RunEntry", &irunt);//NEWNEW
2391          L->SetBranchAddress("RunEntry",&irunt);//NEWNEW      cout << "SelectionList: set branch address RunEntry" << endl;
2392          cout << "SelectionList: set branch address RunEntry"<<endl;      L->SetBranchAddress("EventEntry", &irunentry);
2393          L->SetBranchAddress("EventEntry",&irunentry);      cout << "SelectionList: set branch address EventEntry" << endl;
2394          cout << "SelectionList: set branch address EventEntry"<<endl;      sel_tree = L;
2395          sel_tree = L;      //          if(!Trout)Trout=O;
2396  //      if(!Trout)Trout=O;      //          else Trout->AddFriend("SelectionList");
2397  //      else Trout->AddFriend("SelectionList");      cout << "+SelectionList" << endl;
2398          cout << "+SelectionList"<<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
2399          cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;    }
2400      }else{    else {
2401  //      cout << "SelectionList  : missing tree"<<endl;      //  cout << "SelectionList  : missing tree"<<endl;
2402          if(L)L->Delete();      if (L)
2403      };        L->Delete();
2404      };
2405    
2406  //  --------------------------------------------    //  --------------------------------------------
2407  //  return the pamela chain with all the friends    //  return the pamela chain with all the friends
2408  //  --------------------------------------------    //  --------------------------------------------
   
     pam_tree = Trout;  
       
     return Trout;  
 }  
2409    
2410      pam_tree = Trout;
2411    
2412      return Trout;
2413    }
2414    
2415  //--------------------------------------  //--------------------------------------
2416  //  //
# Line 2194  TChain *PamLevel2::GetPamTree(TList *fl, Line 2419  TChain *PamLevel2::GetPamTree(TList *fl,
2419  /**  /**
2420   * Set branch addresses for Pamela friend trees   * Set branch addresses for Pamela friend trees
2421   */   */
2422  void PamLevel2::SetBranchAddress(TTree *t){  void PamLevel2::SetBranchAddress(TTree *t) {
2423    
2424      TRK2    = TRK2 & t->GetBranchStatus("TrkLevel2");    TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
2425      TRK1    = TRK1 & t->GetBranchStatus("TrkLevel1");    TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
2426      TRKh    = TRKh & t->GetBranchStatus("TrkHough");    TRKh = TRKh & t->GetBranchStatus("TrkHough");
2427      CAL2    = CAL2 & t->GetBranchStatus("CaloLevel2");    CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
2428      CAL1    = CAL1 & t->GetBranchStatus("CaloLevel1");    CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
2429      TOF    = TOF & t->GetBranchStatus("ToFLevel2");    TOF = TOF & t->GetBranchStatus("ToFLevel2");
2430      TRG    = TRG & t->GetBranchStatus("TrigLevel2");    TRG = TRG & t->GetBranchStatus("TrigLevel2");
2431      S4     = S4  & t->GetBranchStatus("S4Level2");    S4 = S4 & t->GetBranchStatus("S4Level2");
2432      ND     = ND  & t->GetBranchStatus("NDLevel2");    ND = ND & t->GetBranchStatus("NDLevel2");
2433      AC     = AC  & t->GetBranchStatus("AcLevel2");    AC = AC & t->GetBranchStatus("AcLevel2");
2434      ORB    = ORB & t->GetBranchStatus("OrbitalInfo");    ORB = ORB & t->GetBranchStatus("OrbitalInfo");
2435      GP     = GP  & t->GetBranchStatus("h20");    GP = GP & t->GetBranchStatus("h20");
2436    
2437      // Tracker
2438      // Tracker    if (TRK1) {
2439      if(TRK1) {      t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel2"));
2440          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel2"));      cout << "Tracker      : set branch address TrkLevel1" << endl;
2441          cout << "Tracker      : set branch address TrkLevel1"<<endl;    };
2442      };    if (TRK2) {
2443      if(TRK2) {      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));
2444          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));      cout << "Tracker      : set branch address TrkLevel2" << endl;
2445          cout << "Tracker      : set branch address TrkLevel2"<<endl;    };
2446      };    if (TRKh) {
2447      if(TRKh) {      t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
2448          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));      cout << "Tracker      : set branch address TrkHough" << endl;
2449          cout << "Tracker      : set branch address TrkHough"<<endl;    };
2450      };  
2451          // Calorimeter
2452      // Calorimeter    if (CAL1) {
2453      if(CAL1) {      t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
2454          t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));      cout << "Calorimeter  : set branch address CaloLevel1" << endl;
2455          cout << "Calorimeter  : set branch address CaloLevel1"<<endl;    };
2456      };    if (CAL2) {
2457      if(CAL2) {      t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
2458          t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));      cout << "Calorimeter  : set branch address CaloLevel2" << endl;
2459          cout << "Calorimeter  : set branch address CaloLevel2"<<endl;    };
2460      };  
2461          // ToF
2462      // ToF        if (TOF) {
2463      if(TOF) {      t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
2464          t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));      cout << "ToF          : set branch address ToFLevel2" << endl;
2465          cout << "ToF          : set branch address ToFLevel2"<<endl;    };
2466      };    // Trigger
2467      // Trigger    if (TRG) {
2468      if(TRG) {      t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
2469          t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));      cout << "Trigger      : set branch address TrigLevel2" << endl;
2470          cout << "Trigger      : set branch address TrigLevel2"<<endl;    };
2471      };    // S4
2472      // S4    if (S4) {
2473      if(S4) {      t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
2474          t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));      cout << "S4           : set branch address S4Level2" << endl;
2475          cout << "S4           : set branch address S4Level2"<<endl;    };
2476      };    // Neutron Detector
2477      // Neutron Detector    if (ND) {
2478      if(ND) {      t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
2479          t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));      cout << "NeutronD     : set branch address NDLevel2" << endl;
2480          cout << "NeutronD     : set branch address NDLevel2"<<endl;    };
2481      };    // Anticounters
2482      // Anticounters    if (AC) {
2483      if(AC) {      t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
2484          t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));      cout << "Anticounter  : set branch address AcLevel2" << endl;
2485          cout << "Anticounter  : set branch address AcLevel2"<<endl;    };
2486      };    // OrbitalInfo
2487      // OrbitalInfo    if (ORB) {
2488      if(ORB) {      t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
2489          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));      cout << "OrbitalInfo  : set branch address OrbitalInfo" << endl;
2490          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;    };
2491      };    // GPamela
2492      // GPamela    if (GP) {
2493      if(GP) {      //  GetPointerTo("GPamela");
2494  //      GetPointerTo("GPamela");      if (!gp_obj)
2495          if(!gp_obj)gp_obj = new GPamela();        gp_obj = new GPamela();
2496  //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri      //  gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2497  // //   t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));      // //       t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2498          if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));      if (SELLI)
2499          else      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri        t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2500        else
2501          gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2502    
2503        cout << "h20          : set branch address GPamela " << endl;
2504      };
2505    
         cout << "h20          : set branch address GPamela "<<endl;  
     };  
       
2506  }  }
2507  /**  /**
2508   * Set branch addresses for Pamela friend trees   * Set branch addresses for Pamela friend trees
2509   */   */
2510  void PamLevel2::SetBranchAddress(TChain *t){  void PamLevel2::SetBranchAddress(TChain *t) {
2511    
2512  //     TRK2    = TRK2 & t->GetBranchStatus("TrkLevel2");    //     TRK2    = TRK2 & t->GetBranchStatus("TrkLevel2");
2513  //     TRK1    = TRK1 & t->GetBranchStatus("TrkLevel1");    //     TRK1    = TRK1 & t->GetBranchStatus("TrkLevel1");
2514  //     TRKh    = TRKh & t->GetBranchStatus("TrkHough");    //     TRKh    = TRKh & t->GetBranchStatus("TrkHough");
2515  //     CAL1    = CAL1 & t->GetBranchStatus("CaloLevel1");    //     CAL1    = CAL1 & t->GetBranchStatus("CaloLevel1");
2516  //     CAL2    = CAL2 & t->GetBranchStatus("CaloLevel2");    //     CAL2    = CAL2 & t->GetBranchStatus("CaloLevel2");
2517  //     TOF    = TOF & t->GetBranchStatus("ToFLevel2");    //     TOF    = TOF & t->GetBranchStatus("ToFLevel2");
2518  //     TRG    = TRG & t->GetBranchStatus("TrigLevel2");    //     TRG    = TRG & t->GetBranchStatus("TrigLevel2");
2519  //     S4     = S4  & t->GetBranchStatus("S4Level2");    //     S4     = S4  & t->GetBranchStatus("S4Level2");
2520  //     ND     = ND  & t->GetBranchStatus("NDLevel2");    //     ND     = ND  & t->GetBranchStatus("NDLevel2");
2521  //     AC     = AC  & t->GetBranchStatus("AcLevel2");    //     AC     = AC  & t->GetBranchStatus("AcLevel2");
2522  //     ORB    = ORB & t->GetBranchStatus("OrbitalInfo");    //     ORB    = ORB & t->GetBranchStatus("OrbitalInfo");
2523  //    GP     = GP & t->GetBranchStatus("h20");    //    GP     = GP & t->GetBranchStatus("h20");
2524    
2525      // Tracker    // Tracker
2526      if(TRK2) {    if (TRK2) {
2527          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
2528          cout << "Tracker      : set branch address TrkLevel2"<<endl;      cout << "Tracker      : set branch address TrkLevel2" << endl;
2529      };    };
2530      if(TRK1) {    if (TRK1) {
2531          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));      t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
2532          cout << "Tracker      : set branch address TrkLevel1"<<endl;      cout << "Tracker      : set branch address TrkLevel1" << endl;
2533      };    };
2534      if(TRKh) {    if (TRKh) {
2535          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));      t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
2536          cout << "Tracker      : set branch address TrkHough"<<endl;      cout << "Tracker      : set branch address TrkHough" << endl;
2537      };    };
       
     // Calorimeter  
     if(CAL2) {  
         t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));  
         cout << "Calorimeter  : set branch address CaloLevel2"<<endl;  
     };    
     if(CAL1) {  
         t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));  
         cout << "Calorimeter  : set branch address CaloLevel1"<<endl;  
     };  
       
     // ToF      
     if(TOF) {  
         t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));  
         cout << "ToF          : set branch address ToFLevel2"<<endl;  
     };  
     // Trigger  
     if(TRG) {  
         t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));  
         cout << "Trigger      : set branch address TrigLevel2"<<endl;  
     };  
     // S4  
     if(S4) {  
         t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));  
         cout << "S4           : set branch address S4Level2"<<endl;  
     };  
     // Neutron Detector  
     if(ND) {  
         t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));  
         cout << "NeutronD     : set branch address NDLevel2"<<endl;  
     };  
     // Anticounters  
     if(AC) {  
         t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));  
         cout << "Anticounter  : set branch address AcLevel2"<<endl;  
     };  
     // OrbitalInfo  
     if(ORB) {  
         t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));  
         cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;  
     };  
     // GPamela  
 //    cout <<"GP "<<GP<<endl;  
     if(GP) {  
 //      GetPointerTo("GPamela");  
         if(!gp_obj)gp_obj = new GPamela();  
         if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));  
         else      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri  
 //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri  
         cout << "h20          : set branch address GPamela "<<endl;  
     };  
     // SelectionList  
 //     if(SELLI==1){  
 //      t->SetBranchAddress("RunEntry",&irunt);//NEWNEW  
 //      cout << "SelectionList: set branch address RunEntry"<<endl;  
 //      t->SetBranchAddress("EventEntry",&irunentry);  
 //      cout << "SelectionList: set branch address EventEntry"<<endl;  
           
 //     }  
2538    
2539  }    // Calorimeter
2540      if (CAL2) {
2541        t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
2542        cout << "Calorimeter  : set branch address CaloLevel2" << endl;
2543      };
2544      if (CAL1) {
2545        t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
2546        cout << "Calorimeter  : set branch address CaloLevel1" << endl;
2547      };
2548    
2549      // ToF
2550      if (TOF) {
2551        t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
2552        cout << "ToF          : set branch address ToFLevel2" << endl;
2553      };
2554      // Trigger
2555      if (TRG) {
2556        t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
2557        cout << "Trigger      : set branch address TrigLevel2" << endl;
2558      };
2559      // S4
2560      if (S4) {
2561        t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
2562        cout << "S4           : set branch address S4Level2" << endl;
2563      };
2564      // Neutron Detector
2565      if (ND) {
2566        t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
2567        cout << "NeutronD     : set branch address NDLevel2" << endl;
2568      };
2569      // Anticounters
2570      if (AC) {
2571        t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
2572        cout << "Anticounter  : set branch address AcLevel2" << endl;
2573      };
2574      // OrbitalInfo
2575      if (ORB) {
2576        t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
2577        cout << "OrbitalInfo  : set branch address OrbitalInfo" << endl;
2578      };
2579      // GPamela
2580      //    cout <<"GP "<<GP<<endl;
2581      if (GP) {
2582        //  GetPointerTo("GPamela");
2583        if (!gp_obj)
2584          gp_obj = new GPamela();
2585        if (SELLI)
2586          t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
2587        else
2588          gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2589        //  gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
2590        cout << "h20          : set branch address GPamela " << endl;
2591      };
2592      // SelectionList
2593      //     if(SELLI==1){
2594      //    t->SetBranchAddress("RunEntry",&irunt);//NEWNEW
2595      //    cout << "SelectionList: set branch address RunEntry"<<endl;
2596      //    t->SetBranchAddress("EventEntry",&irunentry);
2597      //    cout << "SelectionList: set branch address EventEntry"<<endl;
2598    
2599      //     }
2600    
2601    }
2602    
2603  //--------------------------------------  //--------------------------------------
2604  //  //
# Line 2377  void PamLevel2::SetBranchAddress(TChain Line 2606  void PamLevel2::SetBranchAddress(TChain
2606  //--------------------------------------  //--------------------------------------
2607  /**  /**
2608   * Get the Run tree chain from a list of files.   * Get the Run tree chain from a list of files.
2609   * @param fl Pointer to a TList of TSystemFiles   * @param fl Pointer to a TList of TSystemFiles
2610   * @return Pointer to a TChain   * @return Pointer to a TChain
2611   */   */
2612  TChain *PamLevel2::GetRunTree(TList *fl){  TChain *PamLevel2::GetRunTree(TList *fl) {
2613      //    //
2614      //    //
2615      //    //
2616      if ( run_tree ){    if (run_tree) {
2617          printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");      printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
2618          return run_tree;      return run_tree;
2619      };      };
2620      //    //
2621    
2622    
2623      TChain *R = new TChain("Run");    TChain *R = new TChain("Run");
2624        
2625      // loop over files and create chains            // loop over files and create chains
2626      TIter next(fl);    TIter next(fl);
2627      TSystemFile *questo = 0;    TSystemFile *questo = 0;
2628      while ( (questo = (TSystemFile*) next()) ) {    while ((questo = (TSystemFile*) next())) {
2629          TString name =  questo->GetName();      TString name = questo->GetName();
2630  //              cout << "File: "<< name << endl;      //          cout << "File: "<< name << endl;
2631          if( CheckLevel2File(name) ){      if (CheckLevel2File(name)) {
2632              R->Add(name);        R->Add(name);
2633          };      };
2634      }    }
2635        
2636      if (RUN && R->GetNtrees()) {
2637      if(RUN && R->GetNtrees()){  
2638            R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
2639          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));      cout << "Run         : set branch address RunInfo" << endl;
2640          cout << "Run         : set branch address RunInfo"<<endl;      R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2641          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano      cout << "Software    : set branch address SoftInfo" << endl; // Emiliano
2642          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano  
2643        irunoffset = new int[R->GetNtrees()];
2644          irunoffset = new int[R->GetNtrees()];      if (DBG) {
2645          if(DBG){        cout << "----------------------------------------------------" << endl;
2646              cout << "----------------------------------------------------"<<endl;        cout << "irun\t | ";
2647              cout << "irun\t | ";        cout << "tree\t |";
2648              cout << "tree\t |";        //        cout << "offset\t |";
2649  //      cout << "offset\t |";        cout << "RUN\t";
2650              cout << "RUN\t";        cout << "FRAG\t";
2651              cout << "FRAG\t";        cout << "NEVENTS\t";
2652              cout << "NEVENTS\t";        cout << "absolute time\t\t\t";
2653              cout << "absolute time\t\t\t";        cout << "on-board time";
2654              cout << "on-board time";        cout << endl;
2655              cout<<endl;      }
2656          }      for (Int_t ii = 0; ii < R->GetEntries(); ii++) {
2657          for (Int_t ii=0; ii<R->GetEntries(); ii++){        R->GetEntry(ii);
2658              R->GetEntry(ii);        if (DBG) {
2659              if(DBG){          cout << ii << "\t | ";
2660                  cout << ii<< "\t | ";          cout << R->GetTreeNumber() << "\t |";
2661                  cout << R->GetTreeNumber()<< "\t |";          //          cout << R->GetChainOffset()<< "\t |";
2662  //          cout << R->GetChainOffset()<< "\t |";          cout << GetRunInfo()->ID << "\t";
2663                  cout <<GetRunInfo()->ID<<"\t";          cout << GetRunInfo()->ID_RUN_FRAG << "\t";
2664                  cout <<GetRunInfo()->ID_RUN_FRAG<<"\t";          cout << GetRunInfo()->NEVENTS << "\t";
2665                  cout <<GetRunInfo()->NEVENTS<< "\t";          cout << GetRunInfo()->RUNHEADER_TIME << " <---> " << GetRunInfo()->RUNTRAILER_TIME << "\t";
2666                  cout <<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME <<"\t";          cout << GetRunInfo()->RUNHEADER_OBT << " <---> " << GetRunInfo()->RUNTRAILER_OBT << "\t";
2667                  cout <<GetRunInfo()->RUNHEADER_OBT<<" <---> "<<GetRunInfo()->RUNTRAILER_OBT<<"\t";          cout << endl;
2668                  cout <<endl;        }
2669              }        irunoffset[R->GetTreeNumber()] = R->GetChainOffset();
2670              irunoffset[R->GetTreeNumber()]=R->GetChainOffset();      }
2671          }      cout << "N.run = " << R->GetEntries() << endl;
2672          cout << "N.run = "<<R->GetEntries()<<endl;      cout << "----------------------------------------------------" << endl;
2673          cout << "----------------------------------------------------"<<endl;  
2674      }
2675      else {
2676      }else{      delete R;
2677          delete R;      R = 0;
2678          R=0;    }
     }  
       
2679    
2680      run_tree = R;    run_tree = R;
2681    
2682      return R;
2683    
     return R;  
       
2684  }  }
2685  //--------------------------------------  //--------------------------------------
2686  //  //
# Line 2461  TChain *PamLevel2::GetRunTree(TList *fl) Line 2688  TChain *PamLevel2::GetRunTree(TList *fl)
2688  //--------------------------------------  //--------------------------------------
2689  /**  /**
2690   * Get the Run tree  from a file.   * Get the Run tree  from a file.
2691   * @param f Pointer to a TFile   * @param f Pointer to a TFile
2692   * @return Pointer to a TTree   * @return Pointer to a TTree
2693   */   */
2694  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f) {
2695      if ( run_tree ){    if (run_tree) {
2696          printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");      printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
2697          return run_tree;      return run_tree;
2698      };    };
           
2699    
2700      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;    cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte " << endl;
2701    
2702      TTree *T = (TTree*)f->Get("Run");    TTree *T = (TTree*) f->Get("Run");
       
     if(T){  
         T->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));  
         cout << "Run         : set branch address RunInfo"<<endl;  
         T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano  
         cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano  
2703    
2704      }    if (T) {
2705        T->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
2706        cout << "Run         : set branch address RunInfo" << endl;
2707        T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
2708        cout << "Software    : set branch address SoftInfo" << endl; // Emiliano
2709    
2710      }
2711    
2712      run_tree = (TChain*) T;
2713    
2714      run_tree = (TChain*)T;    return T;
2715    
     return T;  
       
2716  }  }
2717  /**  /**
2718   * Update the runinfo informations (to be used to have Run infos event by event basis)   * Update the runinfo informations (to be used to have Run infos event by event basis)
2719   * @param run Pointer to the chain/tree which contains run infos   * @param run Pointer to the chain/tree which contains run infos
2720   * @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
2721   */   */
2722  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) {
2723      //
2724      // check if we have already called once GetEntry, if not call it
2725      //
2726      cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- ATTENZIONE --- NON E` MANTENUTA!!!!!!!.... "
2727          << endl;
2728      if (!run) {
2729        cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree " << endl;
2730        return (false);
2731      }
2732      if (run->GetEntries() <= 0)
2733        return (false);
2734      //
2735    
2736      //  Int_t oldrun = irun;
2737      Long64_t oldrun = irun;
2738    
2739      // --------------------------------------
2740      // if it is a full file (not preselected)
2741      // --------------------------------------
2742      if (SELLI == 0) {
2743    
2744      //      //
2745      // check if we have already called once GetEntry, if not call it      // the absolute time is necessary to relate the event with the run
2746      //      //
2747      cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- ATTENZIONE --- NON E` MANTENUTA!!!!!!!.... "<<endl;      if (!GetOrbitalInfo() && !ISGP) {
2748      if(!run){        cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo " << endl;
2749          cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree "<<endl;        return (false);
         return(false);    
2750      }      }
     if ( run->GetEntries() <= 0 ) return(false);  
     //  
     
     //  Int_t oldrun = irun;  
     Long64_t oldrun = irun;  
2751    
2752      // --------------------------------------      ULong64_t abstime = 0;
2753      // if it is a full file (not preselected)      if (GetOrbitalInfo())
2754      // --------------------------------------        abstime = GetOrbitalInfo()->absTime;
2755      if(SELLI==0){  
2756        //
2757        // the first time the routine is called, set run search from the beginning
2758        //
2759        if (irun < 0LL) {
2760          irun = 0LL;
2761          run->GetEntry(irun);
2762          runfirstentry = 0LL;
2763          runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2764          if ((Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL)
2765            runlastentry -= 1LL;
2766    
2767          if (ISGP && run->GetEntries() != 1) {
2768            cout << "** WARNING ** simulated files are assumed to have 1 single run, not " << run->GetEntries() << endl;
2769            cout << "** WARNING ** run will not be updated" << endl;
2770          }
2771    
         //  
         // the absolute time is necessary to relate the event with the run  
         //  
         if( !GetOrbitalInfo() && !ISGP){  
             cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;  
             return(false);  
         }  
   
         ULong64_t abstime = 0;  
         if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;  
   
   
         //  
         // the first time the routine is called, set run search from the beginning  
         //  
         if ( irun < 0LL ){  
             irun = 0LL;  
             run->GetEntry(irun);  
             runfirstentry = 0LL;  
             runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);  
             if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;  
             
             if( ISGP && run->GetEntries()!=1 ){  
                 cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl;  
                 cout << "** WARNING ** run will not be updated"<<endl;  
             }  
   
         };        
         //  
         if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO  
         //  
         if ( irun == run->GetEntries()-1LL &&  
              !(abstime >= GetRunInfo()->RUNHEADER_TIME &&  
                abstime <= GetRunInfo()->RUNTRAILER_TIME)  
             ){  
             irun = -1LL;  
             irunt = -1LL;  
             runfirstentry = 0LL;  
             runlastentry = -1LL;  
         };  
         // modificato il controllo sull'aggiornamento del run, per evitare problemi  
         // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)  
         //  
         bool fromfirst = true;  
         //  
         while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){  
 //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){  
             irun++;  
             run->GetEntry(irun);  
             runfirstentry = runlastentry;  
             if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL;  
             runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);  
 //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;  
 //        cout << "runfirstentry "<<runfirstentry<<endl;  
             //    printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));  
             //    printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);  
             //    printf(" IDRUN %u \n",GetRunInfo()->ID);  
             //  
 //        prevshift = 0;  
             //  
             if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){  
                 printf(" resetting irun  (it should NOT happen!!!)\n");  
                 fromfirst = false;  
                 irun = 0;  
                 run->GetEntry(irun);  
                 runfirstentry = 0ULL;  
                 runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);  
                 if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL;  
             };  
             //  
         };  
         //  
         if (  
             !(abstime >= GetRunInfo()->RUNHEADER_TIME &&  
               abstime <= GetRunInfo()->RUNTRAILER_TIME)  
             ) {  
             printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n",abstime);  
             return false;  
         }  
         //  
         if ( irun == oldrun || irun >= run->GetEntries() ) return(false);  
         //  
         //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);  
         //  
         prevshift = 0;  
         cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;  
 //      cout << "runfirstentry "<<runfirstentry<<endl;  
         return(true);      
2772      };      };
2773      // ----------------------------------------------------      //
2774      // if it is a preselected file (there is SelectionList)      if (ISGP)
2775      // NBNB - the event tree MUST be read first        abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2776      // ----------------------------------------------------      //
2777      if(SELLI==1){            if (irun == run->GetEntries() - 1LL && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime
2778          sel_tree->GetEntry(iev);          <= GetRunInfo()->RUNTRAILER_TIME)) {
2779  //      cout << irun << " "<< irunentry << endl;        irun = -1LL;
2780          if(irun != oldrun){        irunt = -1LL;
2781              run->GetEntry(irun);        runfirstentry = 0LL;
2782              cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;        runlastentry = -1LL;
2783              prevshift = 0;      };
2784              return true;      // modificato il controllo sull'aggiornamento del run, per evitare problemi
2785          }      // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
2786          return false;      //
2787        bool fromfirst = true;
2788        //
2789        while (!(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun
2790            < run->GetEntries() - 1LL) {
2791          //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
2792          irun++;
2793          run->GetEntry(irun);
2794          runfirstentry = runlastentry;
2795          if ((Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL)
2796            runfirstentry += 1LL;
2797          runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2798          //          cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2799          //          cout << "runfirstentry "<<runfirstentry<<endl;
2800          //          printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
2801          //          printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);
2802          //          printf(" IDRUN %u \n",GetRunInfo()->ID);
2803          //
2804          //          prevshift = 0;
2805          //
2806          if (irun == (Long64_t)(run->GetEntries() - 1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME
2807              && abstime <= GetRunInfo()->RUNTRAILER_TIME)) {
2808            printf(" resetting irun  (it should NOT happen!!!)\n");
2809            fromfirst = false;
2810            irun = 0;
2811            run->GetEntry(irun);
2812            runfirstentry = 0ULL;
2813            runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS);
2814            if ((Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL)
2815              runlastentry -= 1LL;
2816          };
2817          //
2818        };
2819        //
2820        if (!(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)) {
2821          printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n", abstime);
2822          return false;
2823      }      }
   
     return false;  
2824      //      //
2825  };      if (irun == oldrun || irun >= run->GetEntries())
2826          return (false);
2827        //
2828        //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
2829        //
2830        prevshift = 0;
2831        cout << " ))))) UPDATE RUN INFO (((((  @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun << endl;
2832        //      cout << "runfirstentry "<<runfirstentry<<endl;
2833        return (true);
2834      };
2835      // ----------------------------------------------------
2836      // if it is a preselected file (there is SelectionList)
2837      // NBNB - the event tree MUST be read first
2838      // ----------------------------------------------------
2839      if (SELLI == 1) {
2840        sel_tree->GetEntry(iev);
2841        //      cout << irun << " "<< irunentry << endl;
2842        if (irun != oldrun) {
2843          run->GetEntry(irun);
2844          cout << " ))))) UPDATE RUN INFO (((((  @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun << endl;
2845          prevshift = 0;
2846          return true;
2847        }
2848        return false;
2849      }
2850    
2851  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){    return false;
2852      //
2853    }
2854    ;
2855    
2856      if(!run_tree){  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) {
         cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded"<<endl;  
         return false;  
     }  
     if ( run_tree->GetEntries() <= 0 ) {  
         cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty"<<endl;  
         return(false);  
     }  
     
     Int_t oldrun = irun; // store current run index  
2857    
2858      // -----------------------------------------------------------------------    if (!run_tree) {
2859      // the first time the routine is called, set run search from the beginning      cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded" << endl;
2860      // -----------------------------------------------------------------------      return false;
2861      }
2862      if (run_tree->GetEntries() <= 0) {
2863        cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty" << endl;
2864        return (false);
2865      }
2866    
2867      Int_t oldrun = irun; // store current run index
2868    
2869      // -----------------------------------------------------------------------
2870      // the first time the routine is called, set run search from the beginning
2871      // -----------------------------------------------------------------------
2872    
2873      if (irun < 0) {
2874        irun = 0LL;
2875        irunt = 0LL;
2876        irunentry = 0;
2877        prevshift = 0;
2878        run_tree->GetEntry(irun);
2879        if (!GetOrbitalInfo())
2880          cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated " << endl;
2881        if (gltsync)
2882          delete gltsync; //Emiliano
2883        if (!dbc || (dbc && !dbc->IsConnected()))
2884          SetDBConnection(); //Emiliano
2885        gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); //Emiliano // the "false" means not to use level0 file (not necessary here)
2886        if (dbc)
2887          dbc->Close();// Emiliano
2888      };
2889      // ---------------------------------------------------------------
2890      // retrieve OBT and absolute time of the event
2891      // ---------------------------------------------------------------
2892      ULong64_t abstime = 0LL;
2893      //    ULong64_t obt     = 0LL; // Emiliano
2894      Long64_t obt = 0LL; // Emiliano, Long64_t GL_TIMESYNC::DBobt(UInt_t obt) since depending on the situation OBT is lowered or boosted
2895      if (GetOrbitalInfo()) {
2896        abstime = GetOrbitalInfo()->absTime;
2897        obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano
2898      }
2899      else {
2900        abstime = GetRunInfo()->RUNHEADER_TIME;
2901        obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano
2902      }
2903    
2904      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2905      // if it is a full file (not preselected)
2906      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
2907      if (SELLI == 0 || SELLI == 2) { // Emiliano
2908    
     if ( irun < 0 ){  
         irun = 0LL;  
         irunt = 0LL;  
         irunentry = 0;  
         prevshift = 0;  
         run_tree->GetEntry(irun);  
         if( !GetOrbitalInfo() )cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated "<<endl;  
         if ( gltsync ) delete gltsync; //Emiliano  
         if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection(); //Emiliano  
         gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0,"ID",dbc,false); //Emiliano // the "false" means not to use level0 file (not necessary here)  
         if ( dbc ) dbc->Close();// Emiliano  
     };        
2909      // ---------------------------------------------------------------      // ---------------------------------------------------------------
2910      // retrieve OBT and absolute time of the event      // increment dead and live-time counters
2911        // (only when reading a file not preselected)
2912      // ---------------------------------------------------------------      // ---------------------------------------------------------------
2913      ULong64_t abstime = 0LL;      if (SELLI == 0) {
2914      //    ULong64_t obt     = 0LL; // Emiliano        if (GetTrigLevel2()) {
2915      Long64_t obt     = 0LL; // Emiliano, Long64_t GL_TIMESYNC::DBobt(UInt_t obt) since depending on the situation OBT is lowered or boosted          totdltime[0] += GetTrigLevel2()->dltime[0];
2916      if( GetOrbitalInfo() ){          totdltime[1] += GetTrigLevel2()->dltime[1];
2917          abstime = GetOrbitalInfo()->absTime;        }
2918          obt     = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano        totdltime[2]++;
2919      }else{      }
2920          abstime = GetRunInfo()->RUNHEADER_TIME;  
2921          obt     = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano      //
2922      }      bool fromfirst = true; // first loop over runs
2923        
   
     // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-  
     // if it is a full file (not preselected)  
     // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-  
     if(SELLI==0 || SELLI==2){ // Emiliano  
   
         // ---------------------------------------------------------------  
         // increment dead and live-time counters  
         // (only when reading a file not preselected)  
         // ---------------------------------------------------------------  
         if(SELLI==0){  
             if( GetTrigLevel2() ){  
                 totdltime[0]+=GetTrigLevel2()->dltime[0];  
                 totdltime[1]+=GetTrigLevel2()->dltime[1];  
             }  
             totdltime[2]++;  
         }  
   
         //  
         bool fromfirst = true; // first loop over runs  
   
   
         // ------------------------------------------------------  
         // loop over runs to find the one that contains the event  
         // ------------------------------------------------------  
         while (  
             (  
 //              (  
 //                  !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)  
 //                    abstime <= GetRunInfo()->RUNTRAILER_TIME) &&  
 //                  !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)  
 //                    obt <= GetRunInfo()->RUNTRAILER_OBT)  
 //                  )  
                   
                 !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)  
                   abstime <= GetRunInfo()->RUNTRAILER_TIME)  
                 ||  
                 !(obt >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) &&         // additional check on OBT (ms) // Emiliano  
                   obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT))           // Emiliano  
                 ||  
                 GetRunInfo()->NEVENTS==0  
 //              || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento  
                 ||  
                 !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift)  
                 )  
             && irun < run_tree->GetEntries() ){  
   
   
 //          if( !(abstime >= GetRunInfo()->RUNHEADER_TIME &&abstime <= GetRunInfo()->RUNTRAILER_TIME)  )cout << "ABS TIME "<<abstime << " " <<GetRunInfo()->RUNTRAILER_TIME <<endl;  
 //          if( !(obt >= GetRunInfo()->RUNHEADER_OBT && obt <= GetRunInfo()->RUNTRAILER_OBT) )cout << "OBT TIME "<< obt <<" "<< GetRunInfo()->RUNTRAILER_OBT << endl;  
 //          if( GetRunInfo()->NEVENTS==0  )cout <<"GetRunInfo()->NEVENTS==0 "<<endl;  
 //          if( !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) ) cout << "irunentry > "<<GetRunInfo()->NEVENTS-1-prevshift << endl;  
             // - - - - - - - - - - - - -  
             // irunentry = position of current entry, relative to the run  
             // prevshift = shift needed to synchronize l0 and l2 data (nested events)  
             // - - - - - - - - - - - - -  
   
             // -----------------------------------------  
             // store dead and live-time of previous run  
             // -----------------------------------------  
 //          if(SELLI==0){  
           if(SELLI!=2){  
             if(fromfirst){  
                 if(oldrun==irun){  
                     /// decrement counters  
                     if( GetTrigLevel2()){  
                         totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time  
                         totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time  
                     }  
                     totdltime[2]--;                              //event counter  
                     if(DBG){  
                         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;            
                     }  
                 }else{  
                     totdltime[0]=0;//live-time  
                     totdltime[1]=0;//dead-time  
                     totdltime[2]=0;                             //event counter  
                     if(DBG)cout << " *** JUMP RUN *** irun "<<irun<<endl;  
                 }  
                 /// add an entry  
                 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  
             }  
           }  
           //        }  
   
             irun++;          
             // ------------------------------------  
             // if the end of run tree is reached...  
             // ------------------------------------  
             if( irun == run_tree->GetEntries() ){  
                 if(!fromfirst){  
                     // -----------------------------------------------------  
                     // if it happened already once and the run was not found  
                     // ---> exit with error  
                     // -----------------------------------------------------  
                     cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- event entry #"<<iev<<" does not belong to any run (should not happen)" <<endl;  
                     return false;  
                 }  
                 // -----------------------------------------  
                 // ...otherwise repeat search from beginning  
                 // -----------------------------------------  
                 cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- reached end of run tree. searchin again from beginning " <<endl;  
                 fromfirst = false;  
                 irun = 0LL;  
                 runfirstentry = 0LL;  
             }  
             // -------------------------------------------------------------------  
             // save the index of the first entry of the run, relative to pam_tree,  
             // and read a new run  
             // -------------------------------------------------------------------  
             if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift;  
             irunentry = 0;  
             prevshift = 0;            
             run_tree->GetEntry(irun);//update runinfo  
             irunt = irun - irunoffset[run_tree->GetTreeNumber()];  
             if ( gltsync ) delete gltsync; // Emiliano  
             if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection(); //Emiliano  
             gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0,"ID",dbc,false); // Emiliano  
             if ( dbc ) dbc->Close(); // Emiliano  
             if(gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT)>gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ){ // Emiliano  
                 cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<"  has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl;  
                 cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl;  
             }  
 //          if(hasfrag &&  fragid != GetRunInfo()->ID){  
 //              cout << "... where is the next fragment ??"<<endl;  
 //          }  
         };  
   
   
         // --------------------------------------  
         // if there was no need to update the run  
         // ---> exit with FALSE  
         // --------------------------------------  
         if ( irun == oldrun ) return(false);  
   
         // --------------------------------------  
         // ... otherwise  
         // --------------------------------------  
   
   
         // --------------------------------------  
         // ---> exit with TRUE  
         // --------------------------------------  
         if(DBG)cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;  
         // ----------------------------------------------------  
         // update the tracker parameters  
         // (non ho trovato nessun altro modo sicuro di farlo...)  
         // ----------------------------------------------------  
         if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection();  
         TrkParams::Set(GetRunInfo() ,dbc);  
         if(dbc)dbc->Close();  
   
         // ----------------------------------------------------  
         // then check if the run has a fragment  
         // in this case we have to switch to the next fragment  
         // when the end of the first fragment is reached  
         // ----------------------------------------------------  
         if(  
             GetRunInfo()->ID_RUN_FRAG != 0 &&  
 //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&  
             DBG &&  
             true ){  
             cout << "* fragment *"<<endl;                
         }  
2924    
2925          return(true);          // ------------------------------------------------------
2926        // loop over runs to find the one that contains the event
2927        // ------------------------------------------------------
2928        while ((
2929        //          (
2930        //              !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
2931        //                abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
2932        //              !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
2933        //                obt <= GetRunInfo()->RUNTRAILER_OBT)
2934        //              )
2935    
2936        !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s)
2937            abstime <= GetRunInfo()->RUNTRAILER_TIME) || !(obt >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) && // additional check on OBT (ms) // Emiliano
2938            obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) // Emiliano
2939            || GetRunInfo()->NEVENTS == 0
2940        //          || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento
2941            || !(irunentry <= GetRunInfo()->NEVENTS - 1 - prevshift)) && irun < run_tree->GetEntries()) {
2942    
2943          //            if( !(abstime >= GetRunInfo()->RUNHEADER_TIME &&abstime <= GetRunInfo()->RUNTRAILER_TIME)  )cout << "ABS TIME "<<abstime << " " <<GetRunInfo()->RUNTRAILER_TIME <<endl;
2944          //            if( !(obt >= GetRunInfo()->RUNHEADER_OBT && obt <= GetRunInfo()->RUNTRAILER_OBT) )cout << "OBT TIME "<< obt <<" "<< GetRunInfo()->RUNTRAILER_OBT << endl;
2945          //            if( GetRunInfo()->NEVENTS==0  )cout <<"GetRunInfo()->NEVENTS==0 "<<endl;
2946          //            if( !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) ) cout << "irunentry > "<<GetRunInfo()->NEVENTS-1-prevshift << endl;
2947          // - - - - - - - - - - - - -
2948          // irunentry = position of current entry, relative to the run
2949          // prevshift = shift needed to synchronize l0 and l2 data (nested events)
2950          // - - - - - - - - - - - - -
2951    
2952          // -----------------------------------------
2953          // store dead and live-time of previous run
2954          // -----------------------------------------
2955          //            if(SELLI==0){
2956          if (SELLI != 2) {
2957            if (fromfirst) {
2958              if (oldrun == irun) {
2959                /// decrement counters
2960                if (GetTrigLevel2()) {
2961                  totdltime[0] -= GetTrigLevel2()->dltime[0];//live-time
2962                  totdltime[1] -= GetTrigLevel2()->dltime[1];//dead-time
2963                }
2964                totdltime[2]--; //event counter
2965                if (DBG) {
2966                  cout << endl;
2967                  cout << "n.events     : " << totdltime[2] << endl;
2968                  cout << "RUN LIVE-TIME: " << totdltime[0] * 0.16 << " ms" << endl;
2969                  cout << "RUN DEAD-TIME: " << totdltime[1] * 0.01 << " ms" << endl;
2970                }
2971              }
2972              else {
2973                totdltime[0] = 0;//live-time
2974                totdltime[1] = 0;//dead-time
2975                totdltime[2] = 0; //event counter
2976                if (DBG)
2977                  cout << " *** JUMP RUN *** irun " << irun << endl;
2978              }
2979              /// add an entry
2980              if (run_tree_clone)
2981                if (run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
2982                  run_tree_clone->GetBranch("DeadLiveTime")->Fill();
2983              /// reset counters
2984              if (GetTrigLevel2()) {
2985                totdltime[0] = GetTrigLevel2()->dltime[0];//live-time
2986                totdltime[1] = 0; //dead-time
2987              }
2988              totdltime[2] = 1; //event counter
2989            }
2990          }
2991          //            }
2992    
2993          irun++;
2994          // ------------------------------------
2995          // if the end of run tree is reached...
2996          // ------------------------------------
2997          if (irun == run_tree->GetEntries()) {
2998            if (!fromfirst) {
2999              // -----------------------------------------------------
3000              // if it happened already once and the run was not found
3001              // ---> exit with error
3002              // -----------------------------------------------------
3003              cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- event entry #" << iev
3004                  << " does not belong to any run (should not happen)" << endl;
3005              return false;
3006            }
3007            // -----------------------------------------
3008            // ...otherwise repeat search from beginning
3009            // -----------------------------------------
3010            cout
3011                << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- reached end of run tree. searchin again from beginning "
3012                << endl;
3013            fromfirst = false;
3014            irun = 0LL;
3015            runfirstentry = 0LL;
3016          }
3017          // -------------------------------------------------------------------
3018          // save the index of the first entry of the run, relative to pam_tree,
3019          // and read a new run
3020          // -------------------------------------------------------------------
3021          if (irun > 0)
3022            runfirstentry += (GetRunInfo()->NEVENTS) - prevshift;
3023          irunentry = 0;
3024          prevshift = 0;
3025          run_tree->GetEntry(irun);//update runinfo
3026          irunt = irun - irunoffset[run_tree->GetTreeNumber()];
3027          if (gltsync)
3028            delete gltsync; // Emiliano
3029          if (!dbc || (dbc && !dbc->IsConnected()))
3030            SetDBConnection(); //Emiliano
3031          gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano
3032          if (dbc)
3033            dbc->Close(); // Emiliano
3034          if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano
3035            cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun
3036                << "  has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;
3037            cout
3038                << "                                                            (NB!! in this case some events are assigned to a wrong run)"
3039                << endl;
3040          }
3041          //            if(hasfrag &&  fragid != GetRunInfo()->ID){
3042          //                cout << "... where is the next fragment ??"<<endl;
3043          //            }
3044      };      };
3045      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-  
3046      // if it is a preselected file (there is SelectionList)      // --------------------------------------
3047      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-      // if there was no need to update the run
3048      // irun  = run entry relative to the chain      // ---> exit with FALSE
3049      // irunt = run entry relative to the tree      // --------------------------------------
3050      if(SELLI==1){            if (irun == oldrun)
3051          sel_tree->GetEntry(iev);// read irunt from SelectionList        return (false);
3052          irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW  
3053          if(irun != oldrun ){      // --------------------------------------
3054              if( irun < run_tree->GetEntries() )run_tree->GetEntry(irun);      // ... otherwise
3055              // check if the time is ok (with merged files it is not...)      // --------------------------------------
3056              // if not loop over run and look for the proper entry  
3057              bool SECONDO_GIRO=false;  
3058              //      Long64_t irun_start   = irun;      // --------------------------------------
3059              int      offset_start = irunoffset[sel_tree->GetTreeNumber()];      // ---> exit with TRUE
3060              while (      // --------------------------------------
3061                  (      if (DBG)
3062                      (        cout << endl << " ))))) UPDATE RUN INFO (((((  @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun
3063                          !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)            << endl;
3064                            abstime <= GetRunInfo()->RUNTRAILER_TIME)      // ----------------------------------------------------
3065  //                      ||      // update the tracker parameters
3066  //                      !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)      // (non ho trovato nessun altro modo sicuro di farlo...)
3067  //                        obt <= GetRunInfo()->RUNTRAILER_OBT)      // ----------------------------------------------------
3068                          )      if (!dbc || (dbc && !dbc->IsConnected()))
3069                      || GetRunInfo()->NEVENTS==0        SetDBConnection();
3070                      )      TrkParams::Set(GetRunInfo(), dbc);
3071  //              && irun < run_tree->GetEntries()      if (dbc)
3072                  ){        dbc->Close();
3073    
3074                  if(DBG){      // ----------------------------------------------------
3075                      cout << " (test) ";      // then check if the run has a fragment
3076                      cout << " tree "<<sel_tree->GetTreeNumber();      // in this case we have to switch to the next fragment
3077                      cout << " irunt "<<irunt;      // when the end of the first fragment is reached
3078                      cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];      // ----------------------------------------------------
3079                      cout << " abs "<<abstime;      if (GetRunInfo()->ID_RUN_FRAG != 0 &&
3080                      cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;      //      GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID &&
3081                      cout << " obt "<<obt;          DBG && true) {
3082                      cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;        cout << "* fragment *" << endl;
                     cout << " *** JUMP RUN *** irun "<<irun;  
                     cout << endl;  
                 }  
 //              irun++;  
                 irunoffset[sel_tree->GetTreeNumber()]++;  
                 irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW            
                 if(irun == run_tree->GetEntries() && SECONDO_GIRO){  
 //              if(irun == irun_start ){  
                     cout << " ...grrrvzzkhhhajsdkj!!!! "<<endl;  
                     irunoffset[sel_tree->GetTreeNumber()] = offset_start;  
                     return false;  
                 }  
                 if( irun >= run_tree->GetEntries() || irun < 0){  
                     cout << "irun = "<<irun<<" >>  search from the beginning... <<"<<endl;  
                     SECONDO_GIRO=true;  
                     irun=0;  
                     irunoffset[sel_tree->GetTreeNumber()]=-irunt;  
                 }  
                 run_tree->GetEntry(irun);  
             }  
   
   
             if(DBG){  
                 cout << " (test) ";  
                 cout << " tree "<<sel_tree->GetTreeNumber();  
                 cout << " irunt "<<irunt;  
                 cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];  
                 cout << " abs "<<abstime;  
                 cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;  
                 cout << " obt "<<obt;  
                 cout <<" >> "<<GetRunInfo()->RUNHEADER_OBT<<" "<<GetRunInfo()->RUNTRAILER_OBT;  
             }  
             if(DBG)cout << endl;  
             if(DBG)cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" (run-entry "<<irun<<")"<<endl;  
             // ----------------------------------------------------  
             // update the tracker parameters  
             // (non ho trovato nessun altro modo sicuro di farlo...)  
             // ----------------------------------------------------  
             if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection();  
             TrkParams::Set(GetRunInfo() ,dbc);  
             if(dbc)dbc->Close();  
 //          cout << endl;  
             prevshift = 0;  
             return true;  
         }  
         return false;  
3083      }      }
3084    
3085        return (true);
3086      };
3087      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
3088      // if it is a preselected file (there is SelectionList)
3089      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
3090      // irun  = run entry relative to the chain
3091      // irunt = run entry relative to the tree
3092      if (SELLI == 1) {
3093        sel_tree->GetEntry(iev);// read irunt from SelectionList
3094        irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
3095        if (irun != oldrun) {
3096          if (irun < run_tree->GetEntries())
3097            run_tree->GetEntry(irun);
3098          // check if the time is ok (with merged files it is not...)
3099          // if not loop over run and look for the proper entry
3100          bool SECONDO_GIRO = false;
3101          //            Long64_t irun_start   = irun;
3102          int offset_start = irunoffset[sel_tree->GetTreeNumber()];
3103          while (((!(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s)
3104              abstime <= GetRunInfo()->RUNTRAILER_TIME)
3105          //                        ||
3106          //                        !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
3107          //                          obt <= GetRunInfo()->RUNTRAILER_OBT)
3108          ) || GetRunInfo()->NEVENTS == 0)
3109          //                && irun < run_tree->GetEntries()
3110          ) {
3111    
3112            if (DBG) {
3113              cout << " (test) ";
3114              cout << " tree " << sel_tree->GetTreeNumber();
3115              cout << " irunt " << irunt;
3116              cout << " offset " << irunoffset[sel_tree->GetTreeNumber()];
3117              cout << " abs " << abstime;
3118              cout << " >> " << GetRunInfo()->RUNHEADER_TIME << " " << GetRunInfo()->RUNTRAILER_TIME;
3119              cout << " obt " << obt;
3120              cout << " >> " << GetRunInfo()->RUNHEADER_OBT << " " << GetRunInfo()->RUNTRAILER_OBT;
3121              cout << " *** JUMP RUN *** irun " << irun;
3122              cout << endl;
3123            }
3124            //              irun++;
3125            irunoffset[sel_tree->GetTreeNumber()]++;
3126            irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
3127            if (irun == run_tree->GetEntries() && SECONDO_GIRO) {
3128              //            if(irun == irun_start ){
3129              cout << " ...grrrvzzkhhhajsdkj!!!! " << endl;
3130              irunoffset[sel_tree->GetTreeNumber()] = offset_start;
3131              return false;
3132            }
3133            if (irun >= run_tree->GetEntries() || irun < 0) {
3134              cout << "irun = " << irun << " >>  search from the beginning... <<" << endl;
3135              SECONDO_GIRO = true;
3136              irun = 0;
3137              irunoffset[sel_tree->GetTreeNumber()] = -irunt;
3138            }
3139            run_tree->GetEntry(irun);
3140          }
3141    
3142          if (DBG) {
3143            cout << " (test) ";
3144            cout << " tree " << sel_tree->GetTreeNumber();
3145            cout << " irunt " << irunt;
3146            cout << " offset " << irunoffset[sel_tree->GetTreeNumber()];
3147            cout << " abs " << abstime;
3148            cout << " >> " << GetRunInfo()->RUNHEADER_TIME << " " << GetRunInfo()->RUNTRAILER_TIME;
3149            cout << " obt " << obt;
3150            cout << " >> " << GetRunInfo()->RUNHEADER_OBT << " " << GetRunInfo()->RUNTRAILER_OBT;
3151          }
3152          if (DBG)
3153            cout << endl;
3154          if (DBG)
3155            cout << endl << " ))))) UPDATE RUN INFO (((((  @iev " << iev << " run " << GetRunInfo()->ID << " (run-entry "
3156                << irun << ")" << endl;
3157          // ----------------------------------------------------
3158          // update the tracker parameters
3159          // (non ho trovato nessun altro modo sicuro di farlo...)
3160          // ----------------------------------------------------
3161          if (!dbc || (dbc && !dbc->IsConnected()))
3162            SetDBConnection();
3163          TrkParams::Set(GetRunInfo(), dbc);
3164          if (dbc)
3165            dbc->Close();
3166          //            cout << endl;
3167          prevshift = 0;
3168          return true;
3169        }
3170      return false;      return false;
3171      //    }
3172  };  
3173      return false;
3174      //
3175    }
3176    ;
3177  /**  /**
3178   * Update the runinfo informations (to be used to have Run infos event by event basis)   * Update the runinfo informations (to be used to have Run infos event by event basis)
3179   * @param run Pointer to the chain/tree which contains run infos   * @param run Pointer to the chain/tree which contains run infos
3180   * @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
3181   */   */
3182  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev) {
3183      return(UpdateRunInfo((TChain*)run,iev));    return (UpdateRunInfo((TChain*) run, iev));
3184  };  }
3185    ;
3186    
3187  //--------------------------------------  //--------------------------------------
3188  //  //
# Line 2947  Bool_t PamLevel2::UpdateRunInfo(TTree *r Line 3190  Bool_t PamLevel2::UpdateRunInfo(TTree *r
3190  //--------------------------------------  //--------------------------------------
3191  /**  /**
3192   * Set which trees shoul be analysed   * Set which trees shoul be analysed
3193   * @param detlist TString containing the sequence of trees required   * @param detlist TString containing the sequence of trees required
3194   */   */
3195  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist) {
       
 //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){  
     if( detlist.Contains("+ALL", TString::kIgnoreCase)){  
   
         cout << " ======================================================== "<<endl;  
         cout << "                       (( WARNING ))                      "<<endl;  
         cout << " The meaning of the option +ALL has changed!!             "<<endl;  
         cout << " Now it includes really all (level0+level1+level2+gpamela)"<<endl;  
         cout << " and the file is discarded if it does not contain         "<<endl;  
         cout << " all trees or  if level0 files are not available!!        "<<endl;  
         cout << " ======================================================== "<<endl;  
               
         CAL0 = true;  
         CAL1 = true;  
         CAL2 = true;  
         TRK2 = true;  
         TRK1 = true;  
         TRKh = true;  
         TRK0 = true;  
         TRG = true;  
         TOF = true;  
         TOF0 = true;  
         S4  = true;  
         ND  = true;  
         AC  = true;  
         ORB = true;  
         GP  = true;  
     }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){  
         CAL0 = false;  
         CAL1 = false;  
         CAL2 = false;  
         TRK2 = false;  
         TRK1 = false;  
         TRKh = false;  
         TRK0 = false;  
         TRG = false;  
         TOF = false;  
         TOF0 = false;  
         S4  = false;  
         ND  = false;  
         AC  = false;  
         ORB = false;  
         GP  = false;  
     };  
       
 //  -------------------------------------------------------------------------  
     if( detlist.Contains("CAL1", TString::kIgnoreCase) ){  
         if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;  
         if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;  
     };  
3196    
3197      if( detlist.Contains("CAL0", TString::kIgnoreCase) ){    //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
3198          if ( detlist.Contains("-CAL0", TString::kIgnoreCase) )CAL0=false;    if (detlist.Contains("+ALL", TString::kIgnoreCase)) {
         if ( detlist.Contains("+CAL0", TString::kIgnoreCase) )CAL0=true;  
     };  
           
     if( detlist.Contains("CAL2", TString::kIgnoreCase)){  
         if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;  
         if ( detlist.Contains("+CAL2", TString::kIgnoreCase) )CAL2=true;  
     };  
           
     if( detlist.Contains("+CAL", TString::kIgnoreCase) && !CAL1 && !CAL2 )CAL2=true;  
     if( detlist.Contains("-CAL", TString::kIgnoreCase) && CAL1 && CAL2 ){  
         CAL2=false;  
         CAL1=false;  
     }  
 //  -------------------------------------------------------------------------  
     if( detlist.Contains("TRK0", TString::kIgnoreCase) ){  
         if ( detlist.Contains("-TRK0", TString::kIgnoreCase) )TRK0=false;  
         if ( detlist.Contains("+TRK0", TString::kIgnoreCase) )TRK0=true;  
     };  
3199    
3200      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){      cout << " ======================================================== " << endl;
3201          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;      cout << "                       (( WARNING ))                      " << endl;
3202          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;      cout << " The meaning of the option +ALL has changed!!             " << endl;
3203      };      cout << " Now it includes really all (level0+level1+level2+gpamela)" << endl;
3204                cout << " and the file is discarded if it does not contain         " << endl;
3205      if( detlist.Contains("TRK2", TString::kIgnoreCase)){      cout << " all trees or  if level0 files are not available!!        " << endl;
3206          if ( detlist.Contains("-TRK2", TString::kIgnoreCase) )TRK2=false;      cout << " ======================================================== " << endl;
         if ( detlist.Contains("+TRK2", TString::kIgnoreCase) )TRK2=true;  
     };  
3207    
3208      if( detlist.Contains("TRKh", TString::kIgnoreCase)){      CAL0 = true;
3209          if ( detlist.Contains("-TRKh", TString::kIgnoreCase) )TRKh=false;      CAL1 = true;
3210          if ( detlist.Contains("+TRKh", TString::kIgnoreCase) )TRKh=true;      CAL2 = true;
3211      };      TRK2 = true;
3212                TRK1 = true;
3213      if( detlist.Contains("+TRK", TString::kIgnoreCase) && !TRK1 && !TRK2 && !TRKh )TRK2=true;      TRKh = true;
3214      if( detlist.Contains("-TRK", TString::kIgnoreCase) && TRK1 && TRK2 && TRKh){      TRK0 = true;
3215          TRK2=false;      TRG = true;
3216          TRK1=false;      TOF = true;
3217          TRKh=false;      TOF0 = true;
3218      }      S4 = true;
3219  //  -------------------------------------------------------------------------      ND = true;
3220            AC = true;
3221      if( detlist.Contains("-TRG", TString::kIgnoreCase) )TRG = false;      ORB = true;
3222      else if( detlist.Contains("+TRG", TString::kIgnoreCase) )TRG = true;      GP = true;
3223          }
3224      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;    else if (detlist.Contains("-ALL", TString::kIgnoreCase)) {
3225      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;      CAL0 = false;
3226        CAL1 = false;
3227      if( detlist.Contains("-TOF0", TString::kIgnoreCase) )TOF0 = false;      CAL2 = false;
3228      else if( detlist.Contains("+TOF0", TString::kIgnoreCase) )TOF0 = true;      TRK2 = false;
3229            TRK1 = false;
3230      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;      TRKh = false;
3231      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;      TRK0 = false;
3232            TRG = false;
3233      if( detlist.Contains("-ND",  TString::kIgnoreCase) )ND  = false;      TOF = false;
3234      else if( detlist.Contains("+ND",  TString::kIgnoreCase) )ND  = true;      TOF0 = false;
3235            S4 = false;
3236      if( detlist.Contains("-AC",  TString::kIgnoreCase) )AC  = false;      ND = false;
3237      else if( detlist.Contains("+AC",  TString::kIgnoreCase) )AC  = true;      AC = false;
3238            ORB = false;
3239      if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;      GP = false;
3240      else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;    };
3241    
3242      if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false;    //  -------------------------------------------------------------------------
3243      else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true;    if (detlist.Contains("CAL1", TString::kIgnoreCase)) {
3244        if (detlist.Contains("-CAL1", TString::kIgnoreCase))
3245      cout<< "tree/branch list from input --> ";        CAL1 = false;
3246      if(TRK0)cout<<"TRK0 ";      if (detlist.Contains("+CAL1", TString::kIgnoreCase))
3247      if(TRK1)cout<<"TRK1 ";        CAL1 = true;
3248      if(TRK2)cout<<"TRK2 ";    };
3249      if(TRKh)cout<<"TRKH ";  
3250      if(CAL0)cout<<"CAL0 ";    if (detlist.Contains("CAL0", TString::kIgnoreCase)) {
3251      if(CAL1)cout<<"CAL1 ";      if (detlist.Contains("-CAL0", TString::kIgnoreCase))
3252      if(CAL2)cout<<"CAL2 ";        CAL0 = false;
3253      if(TOF)cout<<"TOF ";      if (detlist.Contains("+CAL0", TString::kIgnoreCase))
3254      if(TRG)cout<<"TRG ";        CAL0 = true;
3255      if(AC)cout<<"AC ";    };
3256      if(ND)cout<<"ND ";  
3257      if(S4)cout<<"S4 ";    if (detlist.Contains("CAL2", TString::kIgnoreCase)) {
3258      if(ORB)cout<<"ORB ";      if (detlist.Contains("-CAL2", TString::kIgnoreCase))
3259      if(GP)cout<<"GP ";        CAL2 = false;
3260      cout << endl;      if (detlist.Contains("+CAL2", TString::kIgnoreCase))
3261  //     cout<< "Set detector list --> ";        CAL2 = true;
3262  //     if(TRK1)cout<<"TRK1 ";    };
3263  //     if(TRK2)cout<<"TRK2 ";  
3264  //     if(TRKh)cout<<"TRKH ";    if (detlist.Contains("+CAL", TString::kIgnoreCase) && !CAL1 && !CAL2)
3265  //     if(CAL1)cout<<"CAL1 ";      CAL2 = true;
3266  //     if(CAL2)cout<<"CAL2 ";    if (detlist.Contains("-CAL", TString::kIgnoreCase) && CAL1 && CAL2) {
3267  //     if(TOF0)cout<<"TOF0 ";      CAL2 = false;
3268  //     if(TOF)cout<<"TOF ";      CAL1 = false;
3269  //     if(TRG)cout<<"TRG ";    }
3270  //     if(AC)cout<<"AC ";    //  -------------------------------------------------------------------------
3271  //     if(ND)cout<<"ND ";    if (detlist.Contains("TRK0", TString::kIgnoreCase)) {
3272  //     if(S4)cout<<"S4 ";      if (detlist.Contains("-TRK0", TString::kIgnoreCase))
3273  //     if(ORB)cout<<"ORB ";        TRK0 = false;
3274  //     cout << endl;      if (detlist.Contains("+TRK0", TString::kIgnoreCase))
3275              TRK0 = true;
3276  };    };
3277    
3278      if (detlist.Contains("TRK1", TString::kIgnoreCase)) {
3279        if (detlist.Contains("-TRK1", TString::kIgnoreCase))
3280          TRK1 = false;
3281        if (detlist.Contains("+TRK1", TString::kIgnoreCase))
3282          TRK1 = true;
3283      };
3284    
3285      if (detlist.Contains("TRK2", TString::kIgnoreCase)) {
3286        if (detlist.Contains("-TRK2", TString::kIgnoreCase))
3287          TRK2 = false;
3288        if (detlist.Contains("+TRK2", TString::kIgnoreCase))
3289          TRK2 = true;
3290      };
3291    
3292      if (detlist.Contains("TRKh", TString::kIgnoreCase)) {
3293        if (detlist.Contains("-TRKh", TString::kIgnoreCase))
3294          TRKh = false;
3295        if (detlist.Contains("+TRKh", TString::kIgnoreCase))
3296          TRKh = true;
3297      };
3298    
3299      if (detlist.Contains("+TRK", TString::kIgnoreCase) && !TRK1 && !TRK2 && !TRKh)
3300        TRK2 = true;
3301      if (detlist.Contains("-TRK", TString::kIgnoreCase) && TRK1 && TRK2 && TRKh) {
3302        TRK2 = false;
3303        TRK1 = false;
3304        TRKh = false;
3305      }
3306      //  -------------------------------------------------------------------------
3307    
3308      if (detlist.Contains("-TRG", TString::kIgnoreCase))
3309        TRG = false;
3310      else if (detlist.Contains("+TRG", TString::kIgnoreCase))
3311        TRG = true;
3312    
3313      if (detlist.Contains("-TOF", TString::kIgnoreCase))
3314        TOF = false;
3315      else if (detlist.Contains("+TOF", TString::kIgnoreCase))
3316        TOF = true;
3317    
3318      if (detlist.Contains("-TOF0", TString::kIgnoreCase))
3319        TOF0 = false;
3320      else if (detlist.Contains("+TOF0", TString::kIgnoreCase))
3321        TOF0 = true;
3322    
3323      if (detlist.Contains("-S4", TString::kIgnoreCase))
3324        S4 = false;
3325      else if (detlist.Contains("+S4", TString::kIgnoreCase))
3326        S4 = true;
3327    
3328      if (detlist.Contains("-ND", TString::kIgnoreCase))
3329        ND = false;
3330      else if (detlist.Contains("+ND", TString::kIgnoreCase))
3331        ND = true;
3332    
3333      if (detlist.Contains("-AC", TString::kIgnoreCase))
3334        AC = false;
3335      else if (detlist.Contains("+AC", TString::kIgnoreCase))
3336        AC = true;
3337    
3338      if (detlist.Contains("-ORB", TString::kIgnoreCase))
3339        ORB = false;
3340      else if (detlist.Contains("+ORB", TString::kIgnoreCase))
3341        ORB = true;
3342    
3343      if (detlist.Contains("-GP", TString::kIgnoreCase))
3344        GP = false;
3345      else if (detlist.Contains("+GP", TString::kIgnoreCase))
3346        GP = true;
3347    
3348      cout << "tree/branch list from input --> ";
3349      if (TRK0)
3350        cout << "TRK0 ";
3351      if (TRK1)
3352        cout << "TRK1 ";
3353      if (TRK2)
3354        cout << "TRK2 ";
3355      if (TRKh)
3356        cout << "TRKH ";
3357      if (CAL0)
3358        cout << "CAL0 ";
3359      if (CAL1)
3360        cout << "CAL1 ";
3361      if (CAL2)
3362        cout << "CAL2 ";
3363      if (TOF)
3364        cout << "TOF ";
3365      if (TRG)
3366        cout << "TRG ";
3367      if (AC)
3368        cout << "AC ";
3369      if (ND)
3370        cout << "ND ";
3371      if (S4)
3372        cout << "S4 ";
3373      if (ORB)
3374        cout << "ORB ";
3375      if (GP)
3376        cout << "GP ";
3377      cout << endl;
3378      //     cout<< "Set detector list --> ";
3379      //     if(TRK1)cout<<"TRK1 ";
3380      //     if(TRK2)cout<<"TRK2 ";
3381      //     if(TRKh)cout<<"TRKH ";
3382      //     if(CAL1)cout<<"CAL1 ";
3383      //     if(CAL2)cout<<"CAL2 ";
3384      //     if(TOF0)cout<<"TOF0 ";
3385      //     if(TOF)cout<<"TOF ";
3386      //     if(TRG)cout<<"TRG ";
3387      //     if(AC)cout<<"AC ";
3388      //     if(ND)cout<<"ND ";
3389      //     if(S4)cout<<"S4 ";
3390      //     if(ORB)cout<<"ORB ";
3391      //     cout << endl;
3392    
3393    }
3394    ;
3395    
3396  /**  /**
3397   * Set tree/branch detector flags from the content of a tree   * Set tree/branch detector flags from the content of a tree
3398   */   */
3399  void  PamLevel2::GetWhichTrees(TFile* f){  void PamLevel2::GetWhichTrees(TFile* f) {
3400        
3401      //    cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
3402      // -----------
3403      // reset flags
3404      // -----------
3405      CAL1 = false;
3406      CAL2 = false;
3407      TRK2 = false;
3408      TRK1 = false;
3409      TRKh = false;
3410      TRG = false;
3411      TOF = false;
3412      S4 = false;
3413      ND = false;
3414      AC = false;
3415      ORB = false;
3416      GP = false;
3417    
3418      RUN = false;
3419    
3420      //    cout << "Checking file: "<<f->GetName()<<endl;
3421      if (!f || f->IsZombie()) {
3422        cout << "File: " << f->GetName() << " Non valid root file" << endl;
3423        return;
3424      }
3425    
3426      TList *lk = f->GetListOfKeys();
3427      if (!lk)
3428        return;
3429      TIter next(lk);
3430      TKey *key = 0;
3431    
3432      Int_t nev = 0;
3433    
3434      while ((key = (TKey*) next())) {
3435    
3436        if (!strcmp(key->GetName(), "Run"))
3437          RUN = true;
3438    
3439        //=========================================================
3440        if (!strcmp(key->GetName(), "Trigger")) {
3441          TRG = true;
3442          Int_t nevt = ((TTree*) f->Get("Trigger"))->GetEntries();
3443          if (nev && nevt != nev) {
3444            cout << "File: " << f->GetName() << " Trigger tree has " << nevt << " events instead of " << nev << endl;
3445            TRG = false;
3446          }
3447          else
3448            nev = nevt;
3449        }
3450        //=========================================================
3451        if (!strcmp(key->GetName(), "ToF")) {
3452          TOF = true;
3453          Int_t nevt = ((TTree*) f->Get("ToF"))->GetEntries();
3454          if (nev && nevt != nev) {
3455            cout << "File: " << f->GetName() << "     ToF tree has " << nevt << " events instead of " << nev << endl;
3456            TOF = false;
3457          }
3458          else
3459            nev = nevt;
3460        }
3461        //=========================================================
3462        if (!strcmp(key->GetName(), "S4")) {
3463          S4 = true;
3464          Int_t nevt = ((TTree*) f->Get("S4"))->GetEntries();
3465          if (nev && nevt != nev) {
3466            cout << "File: " << f->GetName() << "      S4 tree has " << nevt << " events instead of " << nev << endl;
3467            S4 = false;
3468          }
3469          else
3470            nev = nevt;
3471        }
3472        //=========================================================
3473    
3474        if (!strcmp(key->GetName(), "NeutronD")) {
3475          ND = true;
3476          Int_t nevt = ((TTree*) f->Get("NeutronD"))->GetEntries();
3477          if (nev && nevt != nev) {
3478            cout << "File: " << f->GetName() << "NeutronD tree has " << nevt << " events instead of " << nev << endl;
3479            ND = false;
3480          }
3481          else
3482            nev = nevt;
3483        }
3484        //=========================================================
3485        if (!strcmp(key->GetName(), "Anticounter")) {
3486          AC = true;
3487          Int_t nevt = ((TTree*) f->Get("Anticounter"))->GetEntries();
3488          if (nev && nevt != nev) {
3489            cout << "File: " << f->GetName() << " Anticounter tree has " << nevt << " events instead of " << nev << endl;
3490            AC = false;
3491          }
3492          else
3493            nev = nevt;
3494        }
3495        //=========================================================
3496        if (!strcmp(key->GetName(), "OrbitalInfo")) {
3497          ORB = true;
3498          Int_t nevt = ((TTree*) f->Get("OrbitalInfo"))->GetEntries();
3499          if (nev && nevt != nev) {
3500            cout << "File: " << f->GetName() << " OrbitalInfo tree has " << nevt << " events instead of " << nev << endl;
3501            ORB = false;
3502          }
3503          else
3504            nev = nevt;
3505        }
3506        //=========================================================
3507        if (!strcmp(key->GetName(), "Tracker")) {
3508          TTree *T = (TTree*) f->Get("Tracker");
3509          for (Int_t i = 0; i < T->GetListOfBranches()->GetEntries(); i++) {
3510            TString name = T->GetListOfBranches()->At(i)->GetName();
3511            if (!name.CompareTo("TrkLevel1"))
3512              TRK1 = true;
3513            if (!name.CompareTo("TrkLevel2"))
3514              TRK2 = true;
3515            if (!name.CompareTo("TrkHough"))
3516              TRKh = true;
3517          };
3518          Int_t nevt = T->GetEntries();
3519          if (nev && nevt != nev) {
3520            cout << "File: " << f->GetName() << " Tracker tree has " << nevt << " events instead of " << nev << endl;
3521            TRK1 = false;
3522            TRK2 = false;
3523            TRKh = false;
3524          }
3525          else
3526            nev = nevt;
3527          //            T->Delete();
3528        };
3529        //=========================================================
3530        if (!strcmp(key->GetName(), "Calorimeter")) {
3531          TTree *T = (TTree*) f->Get("Calorimeter");
3532          for (Int_t i = 0; i < T->GetListOfBranches()->GetEntries(); i++) {
3533            TString name = T->GetListOfBranches()->At(i)->GetName();
3534            if (!name.CompareTo("CaloLevel1"))
3535              CAL1 = true;
3536            if (!name.CompareTo("CaloLevel2"))
3537              CAL2 = true;
3538          };
3539          Int_t nevt = T->GetEntries();
3540          if (nev && nevt != nev) {
3541            cout << "File: " << f->GetName() << "  Calorimeter tree has " << nevt << " events instead of " << nev << endl;
3542            CAL1 = false;
3543            CAL2 = false;
3544          }
3545          else
3546            nev = nevt;
3547          //            T->Delete();
3548        };
3549        //=========================================================
3550        if (!strcmp(key->GetName(), "h20")) {
3551          GP = true;
3552          Int_t nevt = ((TTree*) f->Get("h20"))->GetEntries();
3553          if (nev && nevt != nev) {
3554            cout << "File: " << f->GetName() << " h20 tree has " << nevt << " events instead of " << nev << endl;
3555            GP = false;
3556          }
3557          else
3558            nev = nevt;
3559        }
3560    
3561      };
3562    
3563  //    cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;    //    delete lk;
     // -----------  
     // reset flags  
     // -----------  
     CAL1   = false;      
     CAL2   = false;      
     TRK2   = false;      
     TRK1   = false;      
     TRKh   = false;      
     TRG    = false;      
     TOF    = false;      
     S4     = false;      
     ND     = false;      
     AC     = false;      
     ORB    = false;      
     GP     = false;      
       
     RUN    = false;  
           
 //    cout << "Checking file: "<<f->GetName()<<endl;  
     if( !f || f->IsZombie() ){  
         cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;  
         return;  
     }  
   
     TList *lk = f->GetListOfKeys();  
     if(!lk)return;  
     TIter next(lk);  
     TKey *key =0;  
   
     Int_t nev = 0;  
   
     while( (key = (TKey*)next()) ){  
           
         if( !strcmp(key->GetName(),"Run"        ) )RUN = true;  
   
         //=========================================================      
         if( !strcmp(key->GetName(),"Trigger"    ) ){  
             TRG = true;  
             Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries();  
             if( nev && nevt!=nev){  
                 cout << "File: "<< f->GetName() <<" Trigger tree has "<<nevt<<" events instead of "<<nev<< endl;  
                 TRG = false;  
             }else nev=nevt;  
         }  
         //=========================================================      
         if( !strcmp(key->GetName(),"ToF"        ) ){  
             TOF = true;  
             Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries();  
             if( nev && nevt!=nev){  
                 cout << "File: "<< f->GetName() <<"     ToF tree has "<<nevt<<" events instead of "<<nev<< endl;  
                 TOF = false;  
             }else nev=nevt;  
         }  
         //=========================================================    
         if( !strcmp(key->GetName(),"S4"         ) ){  
             S4 = true;  
             Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries();  
             if( nev && nevt!=nev){  
                 cout << "File: "<< f->GetName() <<"      S4 tree has "<<nevt<<" events instead of "<<nev<< endl;  
                 S4 = false;  
             }else nev=nevt;  
         }  
         //=========================================================    
   
         if( !strcmp(key->GetName(),"NeutronD"   ) ){  
             ND = true;  
             Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries();  
             if( nev && nevt!=nev){  
                 cout << "File: "<< f->GetName() <<"NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl;  
                 ND =false;  
             }else nev=nevt;  
         }        
         //=========================================================    
         if( !strcmp(key->GetName(),"Anticounter") ){  
             AC = true;  
             Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries();  
             if( nev && nevt!=nev){  
                 cout << "File: "<< f->GetName() <<" Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl;  
                 AC =false;  
             }else nev=nevt;  
         }  
         //=========================================================    
         if( !strcmp(key->GetName(),"OrbitalInfo") ){  
             ORB = true;  
             Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries();  
             if( nev && nevt!=nev){  
                 cout << "File: "<< f->GetName() <<" OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;  
                 ORB = false;  
             }else nev=nevt;  
         }  
         //=========================================================    
         if( !strcmp(key->GetName(),"Tracker"    ) ){  
             TTree *T = (TTree*)f->Get("Tracker");  
             for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){  
                 TString name = T->GetListOfBranches()->At(i)->GetName();  
                 if( !name.CompareTo("TrkLevel1") )TRK1=true;  
                 if( !name.CompareTo("TrkLevel2") )TRK2=true;  
                 if( !name.CompareTo("TrkHough") )TRKh=true;  
             };        
             Int_t nevt = T->GetEntries();  
             if( nev && nevt!=nev){  
                 cout << "File: "<< f->GetName() <<" Tracker tree has "<<nevt<<" events instead of "<<nev<< endl;  
                 TRK1 = false;  
                 TRK2 = false;  
                 TRKh = false;  
             }else nev=nevt;  
 //          T->Delete();  
         };  
         //=========================================================    
         if( !strcmp(key->GetName(),"Calorimeter"    ) ){  
             TTree *T = (TTree*)f->Get("Calorimeter");  
             for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){  
                 TString name = T->GetListOfBranches()->At(i)->GetName();  
                 if( !name.CompareTo("CaloLevel1") )CAL1=true;  
                 if( !name.CompareTo("CaloLevel2") )CAL2=true;  
             };      
             Int_t nevt = T->GetEntries();  
             if( nev && nevt!=nev){  
                 cout << "File: "<< f->GetName() <<"  Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl;  
                 CAL1 = false;  
                 CAL2 = false;  
             }else nev=nevt;  
 //          T->Delete();  
         };        
         //=========================================================    
         if( !strcmp(key->GetName(),"h20") ){  
             GP = true;  
             Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();  
             if( nev && nevt!=nev){  
                 cout << "File: "<< f->GetName() <<" h20 tree has "<<nevt<<" events instead of "<<nev<< endl;  
                 GP = false;  
             }else nev=nevt;  
         }  
3564    
3565      };    cout << "tree/branch list from file  --> ";
3566          if (TRK1)
3567  //    delete lk;      cout << "TRK1 ";
3568      if (TRK2)
3569        cout << "TRK2 ";
3570      if (TRKh)
3571        cout << "TRKH ";
3572      if (CAL1)
3573        cout << "CAL1 ";
3574      if (CAL2)
3575        cout << "CAL2 ";
3576      if (TOF)
3577        cout << "TOF ";
3578      if (TRG)
3579        cout << "TRG ";
3580      if (AC)
3581        cout << "AC ";
3582      if (ND)
3583        cout << "ND ";
3584      if (S4)
3585        cout << "S4 ";
3586      if (ORB)
3587        cout << "ORB ";
3588      if (GP)
3589        cout << "GP ";
3590      cout << endl;
3591    
3592      cout<< "tree/branch list from file  --> ";    return;
     if(TRK1)cout<<"TRK1 ";  
     if(TRK2)cout<<"TRK2 ";  
     if(TRKh)cout<<"TRKH ";  
     if(CAL1)cout<<"CAL1 ";  
     if(CAL2)cout<<"CAL2 ";  
     if(TOF)cout<<"TOF ";  
     if(TRG)cout<<"TRG ";  
     if(AC)cout<<"AC ";  
     if(ND)cout<<"ND ";  
     if(S4)cout<<"S4 ";  
     if(ORB)cout<<"ORB ";  
     if(GP)cout<<"GP ";  
     cout << endl;  
         
     return ;  
           
 };  
3593    
3594    }
3595    ;
3596    
3597  //--------------------------------------  //--------------------------------------
3598  //  //
# Line 3278  void  PamLevel2::GetWhichTrees(TFile* f) Line 3603  void  PamLevel2::GetWhichTrees(TFile* f)
3603   * @param name File name   * @param name File name
3604   * @return true if the file is ok.   * @return true if the file is ok.
3605   */   */
3606  Bool_t  PamLevel2::CheckLevel2File(TString name){  Bool_t PamLevel2::CheckLevel2File(TString name) {
           
     Bool_t CAL1__ok   = false;      
     Bool_t CAL2__ok   = false;      
     Bool_t TRK2__ok   = false;      
     Bool_t TRK1__ok   = false;      
     Bool_t TRKh__ok   = false;      
     Bool_t TRG__ok    = false;      
     Bool_t TOF__ok    = false;      
     Bool_t S4__ok     = false;      
     Bool_t ND__ok     = false;      
     Bool_t AC__ok     = false;      
     Bool_t ORB__ok    = false;      
     Bool_t GP__ok     = false;      
       
     Bool_t RUN__ok    = false;  
       
     Bool_t SELLI__ok  = false;  
   
 //    cout << "Checking file: "<<name<<endl;  
     TFile *f = new TFile(name.Data());  
     if( !f || f->IsZombie() ){  
         cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false;  
     }  
 //    cout << "Get list of keys: "<<f<<endl;  
     TList *lk = f->GetListOfKeys();  
 //    lk->Print();  
     TIter next(lk);  
     TKey *key =0;  
   
     Int_t nev = 0;  
   
     while( (key = (TKey*)next()) ){  
           
 //      cout << key->GetName() << endl;  
 //      cout << key->GetName() << ""<<key->GetClassName()<<endl;  
 //              cout << " Get tree: " << f->Get(key->GetName())<<endl;  
 //      nev_previous = nev;  
 //      cout << " n.entries  "<< nev <<endl;  
 //      if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){  
 //          nev = ((TTree*)f->Get(key->GetName()))->GetEntries();  
 //          cout << "File: "<< f->GetName() <<" discarded ---- "<< key->GetName() << " tree: n.entries does not match "<<nev<<" "<<nev_previous<< endl;  
 //          return false;  
 //      };  
   
         //=========================================================      
         // check if the file  
           
   
         if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;        
   
         //=========================================================      
         if( !strcmp(key->GetName(),"SelectionList"    ) ){  
             SELLI__ok = true;  
             if(SELLI==1){  
                 Int_t nevt = ((TTree*)f->Get("SelectionList"))->GetEntries();  
                 if( nev && nevt!=nev){  
                     cout << "File: "<< f->GetName() <<" discarded ---- SelectionList tree has "<<nevt<<" events instead of "<<nev<< endl;  
                     return false;  
                 }  
                 nev=nevt;  
             }  
         }  
   
         //=========================================================      
         if( !strcmp(key->GetName(),"Trigger"    ) ){  
             TRG__ok = true;  
             if(TRG){  
                 Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries();  
                 if( nev && nevt!=nev){  
                     cout << "File: "<< f->GetName() <<" discarded ---- Trigger tree has "<<nevt<<" events instead of "<<nev<< endl;  
                     return false;  
                 }  
                 nev=nevt;  
             }  
         }  
         //=========================================================      
         if( !strcmp(key->GetName(),"ToF"        ) ){  
             TOF__ok = true;  
             if(TOF){  
                 Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries();  
                 if( nev && nevt!=nev){  
                     cout << "File: "<< f->GetName() <<" discarded ---- ToF tree has "<<nevt<<" events instead of "<<nev<< endl;  
                     return false;  
                 }  
                 nev=nevt;  
             }  
         }  
         //=========================================================    
         if( !strcmp(key->GetName(),"S4"         ) ){  
             S4__ok = true;  
             if(S4){  
                 Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries();  
                 if( nev && nevt!=nev){  
                     cout << "File: "<< f->GetName() <<" discarded ---- S4 tree has "<<nevt<<" events instead of "<<nev<< endl;  
                     return false;  
                 }  
                 nev=nevt;  
             }  
         }  
         //=========================================================    
   
         if( !strcmp(key->GetName(),"NeutronD"   ) ){  
             ND__ok = true;  
             if(ND){  
                 Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries();  
                 if( nev && nevt!=nev){  
                     cout << "File: "<< f->GetName() <<" discarded ---- NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl;  
                     return false;  
                 }  
                 nev=nevt;  
             }  
         }        
         //=========================================================    
         if( !strcmp(key->GetName(),"Anticounter") ){  
             AC__ok = true;  
             if(AC){  
                 Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries();  
                 if( nev && nevt!=nev){  
                     cout << "File: "<< f->GetName() <<" discarded ---- Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl;  
                     return false;  
                 }  
                 nev=nevt;  
             }  
         }  
         //=========================================================    
         if( !strcmp(key->GetName(),"OrbitalInfo") ){  
             ORB__ok = true;  
             if(ORB){  
                 Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries();  
                 if( nev && nevt!=nev){  
                     cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;  
                     return false;  
                 }  
                 nev=nevt;  
             }  
         }  
         //=========================================================    
         if( !strcmp(key->GetName(),"Tracker"    ) ){  
             TTree *T = (TTree*)f->Get("Tracker");  
             if(TRK1||TRK2||TRKh){  
                 Int_t nevt = T->GetEntries();  
                 if( nev && nevt!=nev){  
                     cout << "File: "<< f->GetName() <<" discarded ---- Tracker tree has "<<nevt<<" events instead of "<<nev<< endl;  
                     return false;  
                 }  
                 nev=nevt;  
             }  
             for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){  
                 TString name = T->GetListOfBranches()->At(i)->GetName();  
                 if( !name.CompareTo("TrkLevel1") )TRK1__ok=true;  
                 if( !name.CompareTo("TrkLevel2") )TRK2__ok=true;  
                 if( !name.CompareTo("TrkHough") )TRKh__ok=true;  
             };        
             T->Delete();  
         };  
         //=========================================================    
         if( !strcmp(key->GetName(),"Calorimeter"    ) ){  
             TTree *T = (TTree*)f->Get("Calorimeter");  
             if(CAL1||CAL2){  
                 Int_t nevt = T->GetEntries();  
                 if( nev && nevt!=nev){  
                     cout << "File: "<< f->GetName() <<" discarded ---- Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl;  
                     return false;  
                 }  
                 nev=nevt;  
             }  
             for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){  
                 TString name = T->GetListOfBranches()->At(i)->GetName();  
                 if( !name.CompareTo("CaloLevel1") )CAL1__ok=true;  
                 if( !name.CompareTo("CaloLevel2") )CAL2__ok=true;  
             };      
             T->Delete();  
         };        
         //=========================================================      
         if( !strcmp(key->GetName(),"h20") ){  
             ISGP = true;      
             GP__ok = true;  
             if(GP){  
                 Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();  
                 if( nev && nevt!=nev){  
                     cout << "File: "<< f->GetName() <<" discarded ---- h20 tree has "<<nevt<<" events instead of "<<nev<< endl;  
                     return false;  
                 }  
                 nev=nevt;  
             }  
         }  
3607    
3608      };    Bool_t CAL1__ok = false;
3609      Bool_t CAL2__ok = false;
3610      Bool_t TRK2__ok = false;
3611      Bool_t TRK1__ok = false;
3612      Bool_t TRKh__ok = false;
3613      Bool_t TRG__ok = false;
3614      Bool_t TOF__ok = false;
3615      Bool_t S4__ok = false;
3616      Bool_t ND__ok = false;
3617      Bool_t AC__ok = false;
3618      Bool_t ORB__ok = false;
3619      Bool_t GP__ok = false;
3620    
3621      Bool_t RUN__ok = false;
3622    
3623      Bool_t SELLI__ok = false;
3624    
3625      //    cout << "Checking file: "<<name<<endl;
3626      TFile *f = new TFile(name.Data());
3627      if (!f || f->IsZombie()) {
3628        cout << "File: " << f->GetName() << " discarded ---- Non valid root file" << endl;
3629        return false;
3630      }
3631      //    cout << "Get list of keys: "<<f<<endl;
3632      TList *lk = f->GetListOfKeys();
3633      //    lk->Print();
3634      TIter next(lk);
3635      TKey *key = 0;
3636    
3637      Int_t nev = 0;
3638    
3639      while ((key = (TKey*) next())) {
3640    
3641        //  cout << key->GetName() << endl;
3642        //  cout << key->GetName() << ""<<key->GetClassName()<<endl;
3643        //          cout << " Get tree: " << f->Get(key->GetName())<<endl;
3644        //  nev_previous = nev;
3645        //  cout << " n.entries  "<< nev <<endl;
3646        //  if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){
3647        //      nev = ((TTree*)f->Get(key->GetName()))->GetEntries();
3648        //      cout << "File: "<< f->GetName() <<" discarded ---- "<< key->GetName() << " tree: n.entries does not match "<<nev<<" "<<nev_previous<< endl;
3649        //      return false;
3650        //  };
3651    
3652        //=========================================================
3653        // check if the file
3654    
3655    
3656        if (!strcmp(key->GetName(), "Run"))
3657          RUN__ok = true;
3658    
3659        //=========================================================
3660        if (!strcmp(key->GetName(), "SelectionList")) {
3661          SELLI__ok = true;
3662          if (SELLI == 1) {
3663            Int_t nevt = ((TTree*) f->Get("SelectionList"))->GetEntries();
3664            if (nev && nevt != nev) {
3665              cout << "File: " << f->GetName() << " discarded ---- SelectionList tree has " << nevt
3666                  << " events instead of " << nev << endl;
3667              return false;
3668            }
3669            nev = nevt;
3670          }
3671        }
3672    
3673        //=========================================================
3674        if (!strcmp(key->GetName(), "Trigger")) {
3675          TRG__ok = true;
3676          if (TRG) {
3677            Int_t nevt = ((TTree*) f->Get("Trigger"))->GetEntries();
3678            if (nev && nevt != nev) {
3679              cout << "File: " << f->GetName() << " discarded ---- Trigger tree has " << nevt << " events instead of "
3680                  << nev << endl;
3681              return false;
3682            }
3683            nev = nevt;
3684          }
3685        }
3686        //=========================================================
3687        if (!strcmp(key->GetName(), "ToF")) {
3688          TOF__ok = true;
3689          if (TOF) {
3690            Int_t nevt = ((TTree*) f->Get("ToF"))->GetEntries();
3691            if (nev && nevt != nev) {
3692              cout << "File: " << f->GetName() << " discarded ---- ToF tree has " << nevt << " events instead of " << nev
3693                  << endl;
3694              return false;
3695            }
3696            nev = nevt;
3697          }
3698        }
3699        //=========================================================
3700        if (!strcmp(key->GetName(), "S4")) {
3701          S4__ok = true;
3702          if (S4) {
3703            Int_t nevt = ((TTree*) f->Get("S4"))->GetEntries();
3704            if (nev && nevt != nev) {
3705              cout << "File: " << f->GetName() << " discarded ---- S4 tree has " << nevt << " events instead of " << nev
3706                  << endl;
3707              return false;
3708            }
3709            nev = nevt;
3710          }
3711        }
3712        //=========================================================
3713    
3714        if (!strcmp(key->GetName(), "NeutronD")) {
3715          ND__ok = true;
3716          if (ND) {
3717            Int_t nevt = ((TTree*) f->Get("NeutronD"))->GetEntries();
3718            if (nev && nevt != nev) {
3719              cout << "File: " << f->GetName() << " discarded ---- NeutronD tree has " << nevt << " events instead of "
3720                  << nev << endl;
3721              return false;
3722            }
3723            nev = nevt;
3724          }
3725        }
3726        //=========================================================
3727        if (!strcmp(key->GetName(), "Anticounter")) {
3728          AC__ok = true;
3729          if (AC) {
3730            Int_t nevt = ((TTree*) f->Get("Anticounter"))->GetEntries();
3731            if (nev && nevt != nev) {
3732              cout << "File: " << f->GetName() << " discarded ---- Anticounter tree has " << nevt << " events instead of "
3733                  << nev << endl;
3734              return false;
3735            }
3736            nev = nevt;
3737          }
3738        }
3739        //=========================================================
3740        if (!strcmp(key->GetName(), "OrbitalInfo")) {
3741          ORB__ok = true;
3742          if (ORB) {
3743            Int_t nevt = ((TTree*) f->Get("OrbitalInfo"))->GetEntries();
3744            if (nev && nevt != nev) {
3745              cout << "File: " << f->GetName() << " discarded ---- OrbitalInfo tree has " << nevt << " events instead of "
3746                  << nev << endl;
3747              return false;
3748            }
3749            nev = nevt;
3750          }
3751        }
3752        //=========================================================
3753        if (!strcmp(key->GetName(), "Tracker")) {
3754          TTree *T = (TTree*) f->Get("Tracker");
3755          if (TRK1 || TRK2 || TRKh) {
3756            Int_t nevt = T->GetEntries();
3757            if (nev && nevt != nev) {
3758              cout << "File: " << f->GetName() << " discarded ---- Tracker tree has " << nevt << " events instead of "
3759                  << nev << endl;
3760              return false;
3761            }
3762            nev = nevt;
3763          }
3764          for (Int_t i = 0; i < T->GetListOfBranches()->GetEntries(); i++) {
3765            TString name = T->GetListOfBranches()->At(i)->GetName();
3766            if (!name.CompareTo("TrkLevel1"))
3767              TRK1__ok = true;
3768            if (!name.CompareTo("TrkLevel2"))
3769              TRK2__ok = true;
3770            if (!name.CompareTo("TrkHough"))
3771              TRKh__ok = true;
3772          };
3773          T->Delete();
3774        };
3775        //=========================================================
3776        if (!strcmp(key->GetName(), "Calorimeter")) {
3777          TTree *T = (TTree*) f->Get("Calorimeter");
3778          if (CAL1 || CAL2) {
3779            Int_t nevt = T->GetEntries();
3780            if (nev && nevt != nev) {
3781              cout << "File: " << f->GetName() << " discarded ---- Calorimeter tree has " << nevt << " events instead of "
3782                  << nev << endl;
3783              return false;
3784            }
3785            nev = nevt;
3786          }
3787          for (Int_t i = 0; i < T->GetListOfBranches()->GetEntries(); i++) {
3788            TString name = T->GetListOfBranches()->At(i)->GetName();
3789            if (!name.CompareTo("CaloLevel1"))
3790              CAL1__ok = true;
3791            if (!name.CompareTo("CaloLevel2"))
3792              CAL2__ok = true;
3793          };
3794          T->Delete();
3795        };
3796        //=========================================================
3797        if (!strcmp(key->GetName(), "h20")) {
3798          ISGP = true;
3799          GP__ok = true;
3800          if (GP) {
3801            Int_t nevt = ((TTree*) f->Get("h20"))->GetEntries();
3802            if (nev && nevt != nev) {
3803              cout << "File: " << f->GetName() << " discarded ---- h20 tree has " << nevt << " events instead of " << nev
3804                  << endl;
3805              return false;
3806            }
3807            nev = nevt;
3808          }
3809        }
3810    
3811      if( SELLI==-1 )SELLI = (Int_t)SELLI__ok;    };
     if( SELLI==0 && SELLI__ok ){  
         cout << "File: "<< f->GetName() <<" discarded ---- found SelectionList (it is not a full-event file)" << endl;  
         return false;    
     }  
     if( SELLI==1 && !SELLI__ok ){  
         cout << "File: "<< f->GetName() <<" discarded ---- SelectionList missing" << endl;  
         return false;  
     }  
       
 //    cout << "SELLI "<<SELLI<<endl;  
   
 //     cout<< "CheckLevel2File(TString): detector list --> ";  
 //     if(TRK1__ok)cout<<"TRK1 ";  
 //     if(TRK2__ok)cout<<"TRK2 ";  
 //     if(TRKh__ok)cout<<"TRKH ";  
 //     if(CAL1__ok)cout<<"CAL1 ";  
 //     if(CAL2__ok)cout<<"CAL2 ";  
 //     if(TOF__ok)cout<<"TOF ";  
 //     if(TRG__ok)cout<<"TRG ";  
 //     if(AC__ok)cout<<"AC ";  
 //     if(ND__ok)cout<<"ND ";  
 //     if(S4__ok)cout<<"S4 ";  
 //     if(ORB__ok)cout<<"ORB ";  
 //     cout << endl;  
   
   
     if(TRK2 && TRK1__ok)TRK1=1;  
 // ----------------------------------------------------------------------------  
 // NOTA  
 // se c'e` il level1, lo devo necessarimente leggere.  
 // infatti (non ho capito perche`) i cluster vengono letti e allocati in memoria  
 // comunque, ma non vengono disallocati da PamLevel2::Clear()  
 // ----------------------------------------------------------------------------  
   
   
     if(!RUN__ok) {  
         cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree (NB: RUN infos will not be updated)"<< endl;  
         RUN = false;  
     };  
3812    
3813      if(CAL1 && !CAL1__ok){    if (SELLI == -1)
3814          cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel1 branch"<< endl;      SELLI = (Int_t) SELLI__ok;
3815          return false;    if (SELLI == 0 && SELLI__ok) {
3816      };      cout << "File: " << f->GetName() << " discarded ---- found SelectionList (it is not a full-event file)" << endl;
3817      if(CAL2 && !CAL2__ok){      return false;
3818          cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel2 branch"<< endl;    }
3819          return false;    if (SELLI == 1 && !SELLI__ok) {
3820      };      cout << "File: " << f->GetName() << " discarded ---- SelectionList missing" << endl;
3821      if(TRK2 && !TRK2__ok){      return false;
3822          cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel2 branch"<< endl;    }
         return false;  
     };  
     if(TRK1 && !TRK1__ok){  
         cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel1 branch"<< endl;  
         return false;  
     };  
     if(TRKh && !TRKh__ok){  
         cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkHough branch"<< endl;  
         return false;  
     };  
     if(ORB && !ORB__ok){  
         cout << "File: "<< f->GetName() <<" discarded ---- Missing ORB tree"<< endl;  
         return false;  
     };  
     if(AC && !AC__ok){  
         cout << "File: "<< f->GetName() <<" discarded ---- Missing AC tree"<< endl;  
         return false;  
     };  
     if(S4 && !S4__ok){  
         cout << "File: "<< f->GetName() <<" discarded ---- Missing S4 tree"<< endl;  
         return false;  
     };  
     if(TOF && !TOF__ok){  
         cout << "File: "<< f->GetName() <<" discarded ---- Missing ToF tree"<< endl;  
         return false;  
     };  
3823    
3824      if(ND && !ND__ok){    //    cout << "SELLI "<<SELLI<<endl;
         cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl;  
         return false;  
     };  
     if(TRG && !TRG__ok){  
         cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;  
         return false;  
     };  
     if(GP && !GP__ok){  
         cout << "File: "<< f->GetName() <<" discarded ---- Missing h20 tree"<< endl;  
         return false;  
     };  
       
3825    
3826  //    lk->Delete();    //     cout<< "CheckLevel2File(TString): detector list --> ";
3827  //    delete lk;    //     if(TRK1__ok)cout<<"TRK1 ";
3828      f->Close();    //     if(TRK2__ok)cout<<"TRK2 ";
3829      //     if(TRKh__ok)cout<<"TRKH ";
3830  //     cout<< "CheckLevel2File(TString): detector list --> ";    //     if(CAL1__ok)cout<<"CAL1 ";
3831  //     if(TRK1)cout<<"TRK1 ";    //     if(CAL2__ok)cout<<"CAL2 ";
3832  //     if(TRK2)cout<<"TRK2 ";    //     if(TOF__ok)cout<<"TOF ";
3833  //     if(TRKh)cout<<"TRKH ";    //     if(TRG__ok)cout<<"TRG ";
3834  //     if(CAL1)cout<<"CAL1 ";    //     if(AC__ok)cout<<"AC ";
3835  //     if(CAL2)cout<<"CAL2 ";    //     if(ND__ok)cout<<"ND ";
3836  //     if(TOF)cout<<"TOF ";    //     if(S4__ok)cout<<"S4 ";
3837  //     if(TRG)cout<<"TRG ";    //     if(ORB__ok)cout<<"ORB ";
3838  //     if(AC)cout<<"AC ";    //     cout << endl;
3839  //     if(ND)cout<<"ND ";  
3840  //     if(S4)cout<<"S4 ";  
3841  //     if(ORB)cout<<"ORB ";    if (TRK2 && TRK1__ok)
3842  //     if(GP)cout<<"GP ";      TRK1 = 1;
3843  //     cout << endl;    // ----------------------------------------------------------------------------
3844            // NOTA
3845      return true;    // se c'e` il level1, lo devo necessarimente leggere.
3846              // infatti (non ho capito perche`) i cluster vengono letti e allocati in memoria
3847  };    // comunque, ma non vengono disallocati da PamLevel2::Clear()
3848      // ----------------------------------------------------------------------------
3849    
3850    
3851      if (!RUN__ok) {
3852        cout << "File: " << f->GetName() << " *WARNING* ---- Missing RunInfo tree (NB: RUN infos will not be updated)"
3853            << endl;
3854        RUN = false;
3855      };
3856    
3857      if (CAL1 && !CAL1__ok) {
3858        cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel1 branch" << endl;
3859        return false;
3860      };
3861      if (CAL2 && !CAL2__ok) {
3862        cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel2 branch" << endl;
3863        return false;
3864      };
3865      if (TRK2 && !TRK2__ok) {
3866        cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel2 branch" << endl;
3867        return false;
3868      };
3869      if (TRK1 && !TRK1__ok) {
3870        cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel1 branch" << endl;
3871        return false;
3872      };
3873      if (TRKh && !TRKh__ok) {
3874        cout << "File: " << f->GetName() << " discarded ---- Missing TrkHough branch" << endl;
3875        return false;
3876      };
3877      if (ORB && !ORB__ok) {
3878        cout << "File: " << f->GetName() << " discarded ---- Missing ORB tree" << endl;
3879        return false;
3880      };
3881      if (AC && !AC__ok) {
3882        cout << "File: " << f->GetName() << " discarded ---- Missing AC tree" << endl;
3883        return false;
3884      };
3885      if (S4 && !S4__ok) {
3886        cout << "File: " << f->GetName() << " discarded ---- Missing S4 tree" << endl;
3887        return false;
3888      };
3889      if (TOF && !TOF__ok) {
3890        cout << "File: " << f->GetName() << " discarded ---- Missing ToF tree" << endl;
3891        return false;
3892      };
3893    
3894      if (ND && !ND__ok) {
3895        cout << "File: " << f->GetName() << " discarded ---- Missing ND tree" << endl;
3896        return false;
3897      };
3898      if (TRG && !TRG__ok) {
3899        cout << "File: " << f->GetName() << " discarded ---- Missing Trigger tree" << endl;
3900        return false;
3901      };
3902      if (GP && !GP__ok) {
3903        cout << "File: " << f->GetName() << " discarded ---- Missing h20 tree" << endl;
3904        return false;
3905      };
3906    
3907      //    lk->Delete();
3908      //    delete lk;
3909      f->Close();
3910    
3911      //     cout<< "CheckLevel2File(TString): detector list --> ";
3912      //     if(TRK1)cout<<"TRK1 ";
3913      //     if(TRK2)cout<<"TRK2 ";
3914      //     if(TRKh)cout<<"TRKH ";
3915      //     if(CAL1)cout<<"CAL1 ";
3916      //     if(CAL2)cout<<"CAL2 ";
3917      //     if(TOF)cout<<"TOF ";
3918      //     if(TRG)cout<<"TRG ";
3919      //     if(AC)cout<<"AC ";
3920      //     if(ND)cout<<"ND ";
3921      //     if(S4)cout<<"S4 ";
3922      //     if(ORB)cout<<"ORB ";
3923      //     if(GP)cout<<"GP ";
3924      //     cout << endl;
3925    
3926      return true;
3927    
3928    }
3929    ;
3930    
3931  /**  /**
3932   * Create clone-trees   * Create clone-trees
3933   */   */
3934  void PamLevel2::CreateCloneTrees0( TChain *fChain, TFile *ofile ){  void PamLevel2::CreateCloneTrees0(TChain *fChain, TFile *ofile) {
3935    
3936      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
3937      cout << "Create clones of PAMELA trees " << endl;
3938    
3939      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;    Int_t i = 0;
3940      cout << "Create clones of PAMELA trees "<<endl;    pam_tree_clone[i] = fChain->GetTree()->CloneTree(0);
3941          TString name = pam_tree_clone[i]->GetName();
3942      Int_t i=0;    name.Append("_clone");
3943      pam_tree_clone[i] = fChain->GetTree()->CloneTree(0);    //    pam_tree_clone[i]->SetName(name.Data());
3944      TString name =  pam_tree_clone[i]->GetName();    cout << pam_tree_clone[i]->GetName() << endl;
3945      i++;
3946    
3947      TList *li = fChain->GetListOfFriends();
3948      TIter next(li);
3949      TFriendElement* T_friend = 0;
3950      ofile->cd();
3951      while ((T_friend = (TFriendElement*) next())) {
3952        //  cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;
3953        //  cout<<T_friend->GetTree()->GetName()<< endl;
3954        pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0);
3955        pam_tree_clone[i]->SetAutoSave(1000000);
3956        name = pam_tree_clone[i]->GetName();
3957      name.Append("_clone");      name.Append("_clone");
3958  //    pam_tree_clone[i]->SetName(name.Data());      //  pam_tree_clone[i]->SetName(name.Data());
3959      cout << pam_tree_clone[i]->GetName() <<endl;      cout << pam_tree_clone[i]->GetName() << endl;
3960      i++;      i++;
3961      }
3962    
3963      TList *li = fChain->GetListOfFriends();    delete li;
     TIter next(li);  
     TFriendElement* T_friend=0;  
     ofile->cd();  
     while( (T_friend = (TFriendElement*)next()) ){  
 //      cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;  
 //      cout<<T_friend->GetTree()->GetName()<< endl;  
         pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0);  
         pam_tree_clone[i]->SetAutoSave(1000000);  
         name =  pam_tree_clone[i]->GetName();  
         name.Append("_clone");  
 //      pam_tree_clone[i]->SetName(name.Data());  
         cout << pam_tree_clone[i]->GetName() << endl;  
         i++;  
     }  
       
     delete li;  
3964    
3965      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
3966    
3967  }  }
3968    
3969  /**  /**
3970   * Create clone-trees   * Create clone-trees
3971   */   */
3972  void PamLevel2::CreateCloneTrees(TFile *ofile){  void PamLevel2::CreateCloneTrees(TFile *ofile) {
   
3973    
3974  //  if the pointer is null, create a default file    //  if the pointer is null, create a default file
3975      if(!run_tree)return;    if (!run_tree)
3976        return;
3977    
3978      if (!ofile) {
3979        cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root " << endl;
3980        ofile = new TFile("clone-tree.root", "recreate");
3981      }
3982    
3983      ofile->cd();
3984    
3985      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
3986      cout << "Create new PAMELA trees " << endl;
3987    
3988      run_tree_clone = new TTree("Run", "PAMELA Level2 data from the GL_RUN table ");
3989      run_tree_clone->Branch("RunInfo", "GL_RUN", GetPointerTo("RunInfo"));
3990      cout << "Run          : branch RunInfo" << endl;
3991      run_tree_clone->Branch("SoftInfo", "SoftInfo", GetPointerTo("SoftInfo"));
3992      cout << "Run          : branch SoftInfo" << endl;
3993      // ------------------
3994      // replicate run tree
3995      // ------------------
3996      //    cout << "----------------------------------------------------"<<endl;
3997      //    cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
3998      for (Int_t i = 0; i < run_tree->GetEntries(); i++) {
3999        run_tree->GetEntry(i);
4000        //  cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;
4001        run_tree_clone->Fill();
4002      }
4003      cout << "----------------------------------------------------" << endl;
4004    
4005      // ------------------------------------
4006      // add branch with dead and live times
4007      // ------------------------------------
4008      if (SELLI != 2) { // EMILIANO
4009        run_tree_clone->Branch("DeadLiveTime", totdltime, "dltime[3]/l");
4010        cout << "Run          : branch DeadLiveTime" << endl;
4011    
4012        sel_tree_clone = new TTree("SelectionList", "List of selected events ");
4013        //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
4014        sel_tree_clone->Branch("RunEntry", &irunt, "runentry/L");//NEWNEW
4015        sel_tree_clone->Branch("EventEntry", &irunentry, "eventry/L");
4016      };
4017    
4018      if(!ofile){    Int_t i = 0;
4019          cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;    if (TRK1 || TRK2 || TRKh) {
4020          ofile = new TFile("clone-tree.root","recreate");      pam_tree_clone[i] = new TTree("Tracker", "PAMELA tracker level2 data ");
4021      }      if (TRK1) {
4022          pam_tree_clone[i]->Branch("TrkLevel1", "TrkLevel1", GetPointerTo("TrkLevel1"));
4023      ofile->cd();        pam_tree_clone[i]->BranchRef();
4024          cout << "Tracker      : branch TrkLevel1" << endl;
4025      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;        //            cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;
4026      cout << "Create new PAMELA trees "<<endl;      };
4027                if (TRK2) {
4028          pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2", GetPointerTo("TrkLevel2"));
4029      run_tree_clone = new TTree("Run","PAMELA Level2 data from the GL_RUN table ");        cout << "Tracker      : branch TrkLevel2" << endl;
4030      run_tree_clone->Branch("RunInfo","GL_RUN",GetPointerTo("RunInfo"));      };
4031      cout << "Run          : branch RunInfo"<<endl;      if (TRKh) {
4032      run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));        pam_tree_clone[i]->Branch("TrkHough", "TrkHough", GetPointerTo("TrkHough"));
4033      cout << "Run          : branch SoftInfo"<<endl;        cout << "Tracker      : branch TrkHough" << endl;
     // ------------------  
     // replicate run tree  
     // ------------------  
 //    cout << "----------------------------------------------------"<<endl;  
 //    cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;  
     for (Int_t i=0; i<run_tree->GetEntries(); i++){  
         run_tree->GetEntry(i);  
 //      cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;  
         run_tree_clone->Fill();  
     }  
     cout << "----------------------------------------------------"<<endl;  
   
     // ------------------------------------  
     // add branch with dead and live times  
     // ------------------------------------  
     if ( SELLI != 2 ){ // EMILIANO  
       run_tree_clone->Branch("DeadLiveTime",totdltime,"dltime[3]/l");  
       cout << "Run          : branch DeadLiveTime"<<endl;  
   
   
       sel_tree_clone = new TTree("SelectionList","List of selected events ");  
       //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");  
       sel_tree_clone->Branch("RunEntry",&irunt,"runentry/L");//NEWNEW  
       sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L");  
4034      };      };
4035        i++;
4036      }
4037    
4038      Int_t i=0;    // Calorimeter
4039      if(TRK1||TRK2||TRKh){    if (CAL1 || CAL2) {
4040          pam_tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");      pam_tree_clone[i] = new TTree("Calorimeter", "PAMELA calorimeter level2 data ");
4041          if(TRK1) {      if (CAL1) {
4042              pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));        pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
4043              pam_tree_clone[i]->BranchRef();        cout << "Calorimeter  : branch CaloLevel1" << endl;
4044              cout << "Tracker      : branch TrkLevel1"<<endl;      };
4045  //          cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;      if (CAL2) {
4046          };        pam_tree_clone[i]->Branch("CaloLevel2", "CaloLevel2", GetPointerTo("CaloLevel2"));
4047          if(TRK2) {        cout << "Calorimeter  : branch CaloLevel2" << endl;
             pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));  
             cout << "Tracker      : branch TrkLevel2"<<endl;          
         };  
         if(TRKh) {  
             pam_tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));  
             cout << "Tracker      : branch TrkHough"<<endl;  
         };  
         i++;  
     }  
   
     // Calorimeter  
     if(CAL1||CAL2){  
         pam_tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");  
         if(CAL1) {  
             pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));  
             cout << "Calorimeter  : branch CaloLevel1"<<endl;  
         };  
         if(CAL2) {  
             pam_tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));  
             cout << "Calorimeter  : branch CaloLevel2"<<endl;  
         };  
         i++;  
     }      
   
     // ToF      
     if(TOF) {  
         pam_tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");  
         pam_tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));  
         cout << "ToF          : branch ToFLevel2"<<endl;  
         i++;  
     };  
     // Trigger  
     if(TRG) {  
         pam_tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");  
         pam_tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));  
         cout << "Trigger      : branch TrigLevel2"<<endl;  
         i++;  
     };  
     // S4  
     if(S4) {  
         pam_tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");    
         pam_tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));  
         cout << "S4           : branch S4Level2"<<endl;  
         i++;  
4048      };      };
4049      // Neutron Detector      i++;
4050      if(ND) {    }
         pam_tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");        
         pam_tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));  
         cout << "NeutronD     : branch NDLevel2"<<endl;  
         i++;  
     };  
     // Anticounters  
     if(AC) {  
         pam_tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");          
         pam_tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));  
         cout << "Anticounter  : branch AcLevel2"<<endl;  
         i++;  
     };  
     // OrbitalInfo  
     if(ORB) {  
         pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA orbital info  ");    
         pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));  
         cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;  
         i++;  
     };  
     // GPamela  
     if(GP) {  
         pam_tree_clone[i] = new TTree("h20","GPAMELA info ");    
         pam_tree_clone[i]->Branch("GPamela","GPamela", GetPointerTo("GPamela"),32000,1);//split  
         cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;  
         i++;  
     };  
     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
4051    
4052  }    // ToF
4053      if (TOF) {
4054        pam_tree_clone[i] = new TTree("ToF", "PAMELA ToF level2 data ");
4055        pam_tree_clone[i]->Branch("ToFLevel2", "ToFLevel2", GetPointerTo("ToFLevel2"));
4056        cout << "ToF          : branch ToFLevel2" << endl;
4057        i++;
4058      };
4059      // Trigger
4060      if (TRG) {
4061        pam_tree_clone[i] = new TTree("Trigger", "PAMELA trigger level2 data ");
4062        pam_tree_clone[i]->Branch("TrigLevel2", "TrigLevel2", GetPointerTo("TrigLevel2"));
4063        cout << "Trigger      : branch TrigLevel2" << endl;
4064        i++;
4065      };
4066      // S4
4067      if (S4) {
4068        pam_tree_clone[i] = new TTree("S4", "PAMELA S4 level2 data ");
4069        pam_tree_clone[i]->Branch("S4Level2", "S4Level2", GetPointerTo("S4Level2"));
4070        cout << "S4           : branch S4Level2" << endl;
4071        i++;
4072      };
4073      // Neutron Detector
4074      if (ND) {
4075        pam_tree_clone[i] = new TTree("NeutronD", "PAMELA neutron detector level2 data ");
4076        pam_tree_clone[i]->Branch("NDLevel2", "NDLevel2", GetPointerTo("NDLevel2"));
4077        cout << "NeutronD     : branch NDLevel2" << endl;
4078        i++;
4079      };
4080      // Anticounters
4081      if (AC) {
4082        pam_tree_clone[i] = new TTree("Anticounter", "PAMELA anticounter detector level2 data ");
4083        pam_tree_clone[i]->Branch("AcLevel2", "AcLevel2", GetPointerTo("AcLevel2"));
4084        cout << "Anticounter  : branch AcLevel2" << endl;
4085        i++;
4086      };
4087      // OrbitalInfo
4088      if (ORB) {
4089        pam_tree_clone[i] = new TTree("OrbitalInfo", "PAMELA orbital info  ");
4090        pam_tree_clone[i]->Branch("OrbitalInfo", "OrbitalInfo", GetPointerTo("OrbitalInfo"));
4091        cout << "OrbitalInfo  : branch OrbitalInfo" << endl;
4092        i++;
4093      };
4094      // GPamela
4095      if (GP) {
4096        pam_tree_clone[i] = new TTree("h20", "GPAMELA info ");
4097        pam_tree_clone[i]->Branch("GPamela", "GPamela", GetPointerTo("GPamela"), 32000, 1);//split
4098        cout << "OrbitalInfo  : branch OrbitalInfo" << endl;
4099        i++;
4100      };
4101      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
4102    
4103    }
4104    
4105  /**  /**
4106   * Fill tree (created with CreateCloneTrees)   * Fill tree (created with CreateCloneTrees)
4107   *   *
4108   */   */
4109  //void PamLevel2::FillNewPamTree(TTree *T){  //void PamLevel2::FillNewPamTree(TTree *T){
4110  void PamLevel2::FillCloneTrees(){  void PamLevel2::FillCloneTrees() {
       
 //    cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;  
4111    
4112      for(Int_t i=0; i<NCLONES; i++){    //    cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;
         if(pam_tree_clone[i])pam_tree_clone[i]->Fill();  
     }  
     if(sel_tree_clone)sel_tree_clone->Fill();      
4113    
4114  }    for (Int_t i = 0; i < NCLONES; i++) {
4115        if (pam_tree_clone[i])
4116          pam_tree_clone[i]->Fill();
4117      }
4118      if (sel_tree_clone)
4119        sel_tree_clone->Fill();
4120    
4121    }
4122    
4123  TTree* PamLevel2::GetCloneTree(TString name){  TTree* PamLevel2::GetCloneTree(TString name) {
4124    
4125      for(Int_t i=0; i<NCLONES; i++){        for (Int_t i = 0; i < NCLONES; i++) {
4126          if(pam_tree_clone[i]){      if (pam_tree_clone[i]) {
4127              TString na = pam_tree_clone[i]->GetName();        TString na = pam_tree_clone[i]->GetName();
4128              if(!name.CompareTo(na))return pam_tree_clone[i];        if (!name.CompareTo(na))
4129          };          return pam_tree_clone[i];
4130      }      };
4131      if(run_tree_clone){    }
4132          TString na = run_tree_clone->GetName();    if (run_tree_clone) {
4133          if(!name.CompareTo(na))return run_tree_clone;      TString na = run_tree_clone->GetName();
4134      }      if (!name.CompareTo(na))
4135      if(sel_tree_clone){        return run_tree_clone;
4136          TString na = sel_tree_clone->GetName();    }
4137          if(!name.CompareTo(na))return sel_tree_clone;    if (sel_tree_clone) {
4138      }      TString na = sel_tree_clone->GetName();
4139      return NULL;      if (!name.CompareTo(na))
4140          return sel_tree_clone;
4141      }
4142      return NULL;
4143    
4144  }  }
4145  void PamLevel2::WriteCloneTrees(){  void PamLevel2::WriteCloneTrees() {
4146      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
4147      cout << "Write clones of PAMELA trees "<<endl;    cout << "Write clones of PAMELA trees " << endl;
4148      cout << run_tree_clone->GetName()<<endl;      cout << run_tree_clone->GetName() << endl;
4149      if ( SELLI != 2){// Emiliano    if (SELLI != 2) {// Emiliano
4150        if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())      if (run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
4151          run_tree_clone->GetBranch("DeadLiveTime")->Fill();        run_tree_clone->GetBranch("DeadLiveTime")->Fill();
4152      };    };
4153      run_tree_clone->Write();    run_tree_clone->Write();
4154      if ( SELLI != 2){ //Emiliano    if (SELLI != 2) { //Emiliano
4155        cout << sel_tree_clone->GetName()<<endl;          cout << sel_tree_clone->GetName() << endl;
4156        sel_tree_clone->Write();      sel_tree_clone->Write();
4157      };
4158      for (Int_t i = 0; i < NCLONES; i++) {
4159        if (pam_tree_clone[i]) {
4160          cout << pam_tree_clone[i]->GetName() << endl;
4161          pam_tree_clone[i]->Write();
4162      };      };
4163      for(Int_t i=0; i<NCLONES; i++){        }
4164          if(pam_tree_clone[i]){    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
             cout << pam_tree_clone[i]->GetName()<<endl;  
             pam_tree_clone[i]->Write();  
         };  
     }  
     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
4165    
4166  }  }
4167    
# Line 3824  void PamLevel2::WriteCloneTrees(){ Line 4169  void PamLevel2::WriteCloneTrees(){
4169   * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.   * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.
4170   */   */
4171  //Int_t PamLevel2::GetEntry(Int_t iee){  //Int_t PamLevel2::GetEntry(Int_t iee){
4172  Int_t PamLevel2::GetEntry(Long64_t iee){  Int_t PamLevel2::GetEntry(Long64_t iee) {
       
 //     cout << "-------------------------------------"<<endl;  
 //     cout << "Int_t PamLevel2::GetEntry("<<iee<<")"<<endl;  
   
     if(!pam_tree){  
         cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded"<<endl;  
         return 0;  
     }  
4173    
4174      //     cout << "-------------------------------------"<<endl;
4175      //     cout << "Int_t PamLevel2::GetEntry("<<iee<<")"<<endl;
4176    
4177      //    if (!pam_tree) {
4178      // This is a sort of bug: if you don't have the run tree you don't want to exit here you want to have loaded the event anyway...      cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded" << endl;
4179      //      return 0;
4180      //    if(!run_tree ){    }
4181      //  cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl;  
4182      //  return 0;    //
4183      //    }    // This is a sort of bug: if you don't have the run tree you don't want to exit here you want to have loaded the event anyway...
4184      //
4185      Long64_t ii=0;    //    if(!run_tree ){
4186      //-------------------------------    //    cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl;
4187      ii = iee;    //    return 0;
4188      if( !pam_tree->GetEntry(ii) ){          //    }
4189        cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<<endl;  
4190      Long64_t ii = 0;
4191      //-------------------------------
4192      ii = iee;
4193      if (!pam_tree->GetEntry(ii)) {
4194        cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree" << endl;
4195        return 0;
4196      }
4197      //
4198      // ... 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.
4199      // 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
4200      // a problem if you don't check the return code of getentry.
4201      //
4202      if (!RUN || !run_tree) {
4203        if (TRK0 || CAL0 || TOF0 || RUN) { //forse cosi` va bene per tornare 1?
4204          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded" << endl;
4205        return 0;        return 0;
4206      }      }
4207      //      else {
4208      // ... 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.        return 1; //cosi` se non c'e` run esce qua...
4209      // 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      }
4210      // a problem if you don't check the return code of getentry.    }
     //  
     if(!RUN || !run_tree ){  
         if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?  
             cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;  
             return 0;  
         }  else {  
             return 1; //cosi` se non c'e` run esce qua...  
         }  
     }  
   
     //-------------------------------  
     ii = iee;  
 //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);  
 //    Bool_t UPDATED = UpdateRunInfo(ii);  
     UpdateRunInfo(ii);  
     if(SELLI==0||SELLI==2)irunentry = iee-runfirstentry;  
 //    if(UPDATED && run_tree_clone)run_tree_clone->Fill();  
     
 //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;  
   
 //     cout << "irunentry     "<<irunentry << endl;  
 //     cout << "runfirstentry "<<runfirstentry << endl;  
 //     cout << "nevents       "<<GetRunInfo()->NEVENTS<< endl;  
   
 //     if( TRK0 || CAL0 || TOF0 ){  
 //      if( !GetYodaEntry( ) ){  
 //          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl;  
 //          return 0;  
 //      }  
 //     }  
   
   
     return 1;  
4211    
4212  }    //-------------------------------
4213      ii = iee;
4214      //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
4215      //    Bool_t UPDATED = UpdateRunInfo(ii);
4216      UpdateRunInfo(ii);
4217      if (SELLI == 0 || SELLI == 2)
4218        irunentry = iee - runfirstentry;
4219      //    if(UPDATED && run_tree_clone)run_tree_clone->Fill();
4220    
4221      //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
4222    
4223      //     cout << "irunentry     "<<irunentry << endl;
4224      //     cout << "runfirstentry "<<runfirstentry << endl;
4225      //     cout << "nevents       "<<GetRunInfo()->NEVENTS<< endl;
4226    
4227      //     if( TRK0 || CAL0 || TOF0 ){
4228      //    if( !GetYodaEntry( ) ){
4229      //        cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl;
4230      //        return 0;
4231      //    }
4232      //     }
4233    
 TrkLevel0    *PamLevel2::GetTrkLevel0(){  
     if( !TRK0 )return NULL;  
     if( !GetYodaEntry( ) ){  
         cout << " Int_t PamLevel2::GetTrkLevel0() -- ERROR -- error reading level0 tree"<<endl;  
         return 0;  
     }  
     return trk0_obj;  
 };  
 CaloLevel0    *PamLevel2::GetCaloLevel0(){  
     if( !CAL0 )return NULL;  
     if( !GetYodaEntry( ) ){  
         cout << " Int_t PamLevel2::GetCaloLevel0() -- ERROR -- error reading level0 tree"<<endl;  
         return 0;  
     }  
     return calo0_obj;  
 };  
4234    
4235      return 1;
4236    
4237    }
4238    
4239    TrkLevel0 *PamLevel2::GetTrkLevel0() {
4240      if (!TRK0)
4241        return NULL;
4242      if (!GetYodaEntry()) {
4243        cout << " Int_t PamLevel2::GetTrkLevel0() -- ERROR -- error reading level0 tree" << endl;
4244        return 0;
4245      }
4246      return trk0_obj;
4247    }
4248    ;
4249    CaloLevel0 *PamLevel2::GetCaloLevel0() {
4250      if (!CAL0)
4251        return NULL;
4252      if (!GetYodaEntry()) {
4253        cout << " Int_t PamLevel2::GetCaloLevel0() -- ERROR -- error reading level0 tree" << endl;
4254        return 0;
4255      }
4256      return calo0_obj;
4257    }
4258    ;
4259    
4260  /**  /**
4261   * Method to retrieve the level0 tree (YODA tree) that contains the current event.   * Method to retrieve the level0 tree (YODA tree) that contains the current event.
# Line 3914  CaloLevel0    *PamLevel2::GetCaloLevel0( Line 4263  CaloLevel0    *PamLevel2::GetCaloLevel0(
4263   * @return Pointer to the tree   * @return Pointer to the tree
4264   */   */
4265    
4266    TTree* PamLevel2::GetYodaTree() {
4267    
4268  TTree* PamLevel2::GetYodaTree( ){    //    cout << "TTree* PamLevel2::GetYodaTree( )"<<endl;
4269          //===================================
4270  //    cout << "TTree* PamLevel2::GetYodaTree( )"<<endl;    // check if iroot has changed
4271      //===================================
4272      if (irun < 0) {
4273        cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = " << irun << endl;
4274        //  cout << "In order to use this method you have to first load the RunInfo tree "<<endl;
4275        return NULL;
4276      }
4277      Int_t irootnew = run_obj->ID_ROOT_L0;
4278      //      cout << "iroot    "<<iroot<<endl;
4279      //      cout << "irootnew "<<irootnew<<endl;
4280    
4281      //===================================
4282      // load the level0 file
4283      // (if not already loaded)
4284      //===================================
4285      if (iroot != irootnew || !l0_tree) {
4286        iroot = irootnew;
4287      //===================================      //===================================
4288      // check if iroot has changed      // open the DB connection
4289        // (if not already opened)
4290      //===================================      //===================================
4291      if( irun<0 ){      if (!dbc || (dbc && !dbc->IsConnected()))
4292          cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = "<<irun<<endl;        SetDBConnection();
4293  //      cout << "In order to use this method you have to first load the RunInfo tree "<<endl;      GL_ROOT glroot = GL_ROOT();
4294          return NULL;      if (glroot.Query_GL_ROOT(iroot, dbc)) {
4295      }            cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = " << iroot << " does not exists"
4296      Int_t irootnew = run_obj->ID_ROOT_L0;            << endl;
4297  //      cout << "iroot    "<<iroot<<endl;        return NULL;
4298  //      cout << "irootnew "<<irootnew<<endl;      };
4299        TString filename = glroot.PATH + glroot.NAME;
4300        if (l0_file) {
4301          l0_file->Close();
4302          l0_file->Delete();
4303        }
4304        cout << "Opening LEVEL0 file: " << filename << endl;
4305        FileStat_t t;
4306        if (gSystem->GetPathInfo(filename.Data(), t)) {
4307          cout << " PamLevel2::GetYodaTree() -- ERROR opening file " << endl;
4308          return NULL;
4309        }
4310        l0_file = new TFile(filename);
4311        if (!l0_file)
4312          return NULL;
4313        l0_tree = (TTree*) l0_file->Get("Physics");
4314        if (!h0_obj)
4315          h0_obj = new EventHeader();
4316        l0_tree->SetBranchAddress("Header", &h0_obj);
4317        prevshift = 0;
4318        //---------------------------------------------------
4319        // TRACKER:
4320        if (TRK0) {
4321          if (!trk0_obj) {
4322            trk0_obj = new TrkLevel0();
4323            trk0_obj->Set();
4324          };
4325          l0_tree->SetBranchAddress("Tracker", trk0_obj->GetPointerToTrackerEvent());
4326        }
4327        //--------------------------------------------------
4328        // CALORIMETER:
4329        if (CAL0) {
4330          if (!calo0_obj) {
4331            calo0_obj = new CaloLevel0();
4332            calo0_obj->Set();
4333          };
4334          l0_tree->SetBranchAddress("Calorimeter", calo0_obj->GetPointerToCalorimeterEvent());
4335          //            cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;
4336        }
4337        //---------------------------------------------------
4338        // TOF:
4339        if (TOF0) {
4340          cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented " << endl;
4341        }
4342    
4343      //===================================      dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
     // load the level0 file  
     // (if not already loaded)  
     //===================================  
     if( iroot != irootnew || !l0_tree){  
         iroot = irootnew;  
         //===================================  
         // open the DB connection  
         // (if not already opened)  
         //===================================  
         if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();  
         GL_ROOT glroot = GL_ROOT();  
         if( glroot.Query_GL_ROOT(iroot,dbc) ){  
             cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;  
             return NULL;  
         };  
         TString filename = glroot.PATH + glroot.NAME;  
         if(l0_file){  
             l0_file->Close();  
             l0_file->Delete();  
         }  
         cout << "Opening LEVEL0 file: "<< filename << endl;  
         FileStat_t t;  
         if( gSystem->GetPathInfo(filename.Data(),t) ){  
             cout << " PamLevel2::GetYodaTree() -- ERROR opening file "<<endl;  
             return NULL;  
         }  
         l0_file = new TFile(filename);  
         if( !l0_file )return NULL;  
         l0_tree = (TTree*)l0_file->Get("Physics");  
         if(!h0_obj)h0_obj = new EventHeader();  
         l0_tree->SetBranchAddress("Header" ,&h0_obj);  
         prevshift = 0;  
         //---------------------------------------------------  
         // TRACKER:  
         if(TRK0){  
             if(!trk0_obj){  
                 trk0_obj = new TrkLevel0();  
                 trk0_obj->Set();  
             };  
             l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());  
         }  
         //--------------------------------------------------  
         // CALORIMETER:  
         if(CAL0){  
             if(!calo0_obj){  
                 calo0_obj = new CaloLevel0();  
                 calo0_obj->Set();  
             };  
             l0_tree->SetBranchAddress("Calorimeter" ,calo0_obj->GetPointerToCalorimeterEvent());  
             //      cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;  
         }  
         //---------------------------------------------------  
         // TOF:  
         if(TOF0){  
             cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;  
         }  
4344    
         dbc->Close(); // EMILIANO, do not leave open connections, open only when needed  
4345    
4346      };
4347    
4348      //     if(!dbc || (dbc && !dbc->IsConnected())){
4349      //    cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;
4350      //     }
4351    
4352      if (TRK0) {
4353        //  TrkParams::Load(6);
4354        //  if( !TrkParams::IsLoaded(6) ){
4355        //      cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;
4356        //  };
4357        //  if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
4358        TrkParams::SetCalib(run_obj, dbc);
4359        TrkParams::LoadCalib();
4360        if (!TrkParams::CalibIsLoaded()) {
4361          cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded" << endl;
4362      };      };
4363        //  if(dbc)dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
4364      }
4365    
4366  //     if(!dbc || (dbc && !dbc->IsConnected())){    //    cout << l0_tree << endl;
4367  //      cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;    return l0_tree;
 //     }  
   
     if ( TRK0 ){  
 //      TrkParams::Load(6);  
 //      if( !TrkParams::IsLoaded(6) ){  
 //          cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl;  
 //      };  
 //      if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();  
         TrkParams::SetCalib(run_obj,dbc);  
         TrkParams::LoadCalib( );  
         if( !TrkParams::CalibIsLoaded() ){  
             cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl;  
         };  
 //      if(dbc)dbc->Close(); // EMILIANO, do not leave open connections, open only when needed  
     }  
   
   
 //    cout << l0_tree << endl;  
     return l0_tree;  
4368    
4369  }  }
4370    
4371  /**  /**
4372   * Method to retrieve the level0 tree (YODA tree) that contains the current event.   * Method to retrieve the level0 tree (YODA tree) that contains the current event.
4373   */   */
4374  Int_t PamLevel2::GetYodaEntry(){  Int_t PamLevel2::GetYodaEntry() {
4375    
4376      //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;
4377      if (!GetYodaTree())
4378        return 0;
4379    
4380      // patch
4381      if (irunentry < 0) {
4382        //  cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
4383        irunentry = 0LL;
4384      }
4385      //  ---------------------------------
4386      //  if file is NOT a preselected file
4387      //  ---------------------------------
4388      Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM);
4389      //     cout << " irunentry "<<irunentry<<endl;
4390      //     cout << " EV_FROM "<<run_obj->EV_FROM<<endl;
4391      //     cout << " quellagiusta = irunentry + EV_FROM "<< quellagiusta << endl;
4392    
4393      //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
4394      //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
4395      //     cout << " time "<< abstime << endl;
4396      //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;
4397    
4398      ULong64_t obt = 0;
4399      ULong64_t pktn = 0;
4400      if (GetOrbitalInfo()) {
4401        obt = GetOrbitalInfo()->OBT;
4402        pktn = GetOrbitalInfo()->pkt_num;
4403      }
4404    
4405      if (!GetOrbitalInfo() && !ISGP) {
4406        cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo " << endl;
4407        return 0;
4408      }
4409      if (obt == 0 && pktn == 0 && !ISGP) {
4410        cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? " << endl;
4411        return 0;
4412      }
4413    
4414      // ---------------------------------------------------------------------
4415      // ATTENTION!!!
4416      // If data are not pre-processed with cleaner, the level0 tree may contain
4417      // spurious nested physics packets.
4418      // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries
4419      // while level2 tree DOES NOT!!
4420      // This means that "quellagiusta" in these cases is not correct.
4421      // In order to retrieve the correct level0 event, I implemented a check
4422      // of the OBT and pkt-number. In case of mismatch, the level0 entry number
4423      // is shift forward until when the packets match.
4424      // ---------------------------------------------------------------------
4425      Int_t answer = 0;
4426      Int_t shift = 0;
4427      //    printf(" siamo qui %i %i \n",shift,prevshift);
4428      //    Int_t maxshift = 50; // EMILIANO
4429      do {
4430        if (shift > 0) {
4431          cout << " PKTNUM  L2 --- " << pktn << " --- L0 --- " << GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
4432          if (DBG)
4433            cout << "         RUN: ID " << GetRunInfo()->ID << " ID_ROOT_L0 " << run_obj->ID_ROOT_L0 << " ID_RUN_FRAG "
4434                << GetRunInfo()->ID_RUN_FRAG << " EV_FROM " << GetRunInfo()->EV_FROM << endl;
4435          if (DBG)
4436            cout << "         L2 <--> L0 mismatch ( irun " << irun << " irunentry " << irunentry << " shift " << shift
4437                << " prevshift " << prevshift << " )" << endl;
4438        }
4439        answer = l0_tree->GetEntry(quellagiusta + (Long64_t) shift + (Long64_t) prevshift);
4440        shift++;
4441        if (!GetEventHeader()) {
4442          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader " << endl;
4443          return 0;
4444        }
4445    
4446        if (ISGP) {
4447          obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO
4448          pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO
4449        }
4450    
4451        //  cout << "PKTNUM "<<shift<<" ==  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;
4452        //  cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;
4453        //  if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;
4454        //  cout << " obt "<< obt << endl;
4455        //  cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;
4456        //  cout << " pktn "<< pktn << endl;
4457        //  cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
4458        //  printf(" IDRUN %u \n",GetRunInfo()->ID);
4459        //
4460        if (prevshift != 0 && (quellagiusta + (Long64_t) shift) == GetYodaTree()->GetEntries()) {
4461          prevshift = 0;
4462          shift = -1;
4463        };
4464    
4465      } while ((obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(
4466          GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta + (Long64_t) shift)
4467          < GetYodaTree()->GetEntries() && shift < maxshift);
4468    
4469      if ((quellagiusta + (Long64_t) shift + (Long64_t) prevshift) > GetYodaTree()->GetEntries() || shift == maxshift) {
4470        cout << " Big trouble here, no such event in Level0 data! (NB maxshift set to " << maxshift << " )" << endl;
4471        return 0;
4472      }
4473      //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
4474      //    return GetYodaTree()->GetEntry(quellagiusta);
4475      if (shift > 1)
4476        prevshift += (shift - 1);
4477    
4478      return answer;
4479    
 //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;  
     if(!GetYodaTree())return 0;  
       
     // patch  
     if( irunentry < 0){  
 //      cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;  
         irunentry=0LL;  
     }  
     //  ---------------------------------  
     //  if file is NOT a preselected file  
     //  ---------------------------------  
     Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM);  
 //     cout << " irunentry "<<irunentry<<endl;  
 //     cout << " EV_FROM "<<run_obj->EV_FROM<<endl;  
 //     cout << " quellagiusta = irunentry + EV_FROM "<< quellagiusta << endl;  
   
 //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;  
 //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;  
 //     cout << " time "<< abstime << endl;  
 //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;  
       
     ULong64_t obt     = 0;  
     ULong64_t pktn    = 0;  
     if( GetOrbitalInfo() ){  
         obt     = GetOrbitalInfo()->OBT;  
         pktn    = GetOrbitalInfo()->pkt_num;  
     }  
   
     if( !GetOrbitalInfo() && !ISGP){  
         cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;  
         return 0;  
     }  
     if( obt==0 && pktn==0 && !ISGP ){  
         cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl;  
         return 0;  
     }  
   
     // ---------------------------------------------------------------------  
     // ATTENTION!!!  
     // If data are not pre-processed with cleaner, the level0 tree may contain  
     // spurious nested physics packets.  
     // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries  
     // while level2 tree DOES NOT!!  
     // This means that "quellagiusta" in these cases is not correct.  
     // In order to retrieve the correct level0 event, I implemented a check  
     // of the OBT and pkt-number. In case of mismatch, the level0 entry number  
     // is shift forward until when the packets match.  
     // ---------------------------------------------------------------------  
     Int_t answer = 0;  
     Int_t shift =0;  
     //    printf(" siamo qui %i %i \n",shift,prevshift);  
     //    Int_t maxshift = 50; // EMILIANO  
     do{  
         if(shift>0){      
             cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;  
             if(DBG)cout << "         RUN: ID "<< GetRunInfo()->ID << " ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<" ID_RUN_FRAG "<<GetRunInfo()->ID_RUN_FRAG << " EV_FROM "<<GetRunInfo()->EV_FROM  <<endl;  
             if(DBG)cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;  
         }  
         answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);  
         shift++;  
         if( !GetEventHeader() ){  
             cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;  
             return 0;  
         }  
   
         if(ISGP){  
             obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO  
             pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO  
         }  
   
 //      cout << "PKTNUM "<<shift<<" ==  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;  
 //      cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;  
 //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;  
 //      cout << " obt "<< obt << endl;  
 //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;  
 //      cout << " pktn "<< pktn << endl;  
 //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;  
 //      printf(" IDRUN %u \n",GetRunInfo()->ID);  
 //  
         if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){  
             prevshift = 0;  
             shift = -1;  
         };  
   
     }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||  
               pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())       )  
             && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);  
   
     if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {  
         cout << " Big trouble here, no such event in Level0 data! (NB maxshift set to "<<maxshift<<" )" <<endl;  
         return 0;  
     }  
 //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;  
 //    return GetYodaTree()->GetEntry(quellagiusta);  
     if ( shift > 1 ) prevshift += (shift-1);  
       
     return answer;  
       
4480  }  }
4481  /**  /**
4482   * \Brief Set DB connection   * \Brief Set DB connection
4483   */   */
4484  Bool_t PamLevel2::SetDBConnection(){  Bool_t PamLevel2::SetDBConnection() {
4485    
4486  //    cout << "PamLevel2::SetDBConnection()" << endl;    //    cout << "PamLevel2::SetDBConnection()" << endl;
4487      if(DBG){    if (DBG) {
4488          cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;      cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
4489          cout<<"Connecting to DB"<<endl;      cout << "Connecting to DB" << endl;
4490          cout<<"HOST "<<host<<endl;      cout << "HOST " << host << endl;
4491          cout<<"USER "<<user<<endl;      cout << "USER " << user << endl;
4492          cout<<"PSW  "<<psw<<endl;      cout << "PSW  " << psw << endl;
4493      }    }
4494      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());    dbc = TSQLServer::Connect(host.Data(), user.Data(), psw.Data());
4495      if( !dbc )return false;    if (!dbc)
4496      if( !dbc->IsConnected() )return false;          return false;
4497      stringstream myquery;  // EMILIANO    if (!dbc->IsConnected())
4498      myquery.str("");  // EMILIANO      return false;
4499      myquery << "SET time_zone='+0:00'";  // EMILIANO    stringstream myquery; // EMILIANO
4500      dbc->Query(myquery.str().c_str());  // EMILIANO    myquery.str(""); // EMILIANO
4501      if(DBG)cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;    myquery << "SET time_zone='+0:00'"; // EMILIANO
4502      return true;    dbc->Query(myquery.str().c_str()); // EMILIANO
4503      if (DBG)
4504        cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
4505      return true;
4506    
4507  }  }
4508    
# Line 4151  Bool_t PamLevel2::SetDBConnection(){ Line 4511  Bool_t PamLevel2::SetDBConnection(){
4511   * @param cname name of the chain to be added   * @param cname name of the chain to be added
4512   */   */
4513    
4514  TChain* PamLevel2::AddFriend(TString cname){  TChain* PamLevel2::AddFriend(TString cname) {
   
     if(!GetPamTree()){  
         cout << " TChain* PamLevel2::AddFriend(TString cname) --- a pamela tree must be created first"<<endl;  
         return NULL;  
     }  
4515    
4516      if (!GetPamTree()) {
4517        cout << " TChain* PamLevel2::AddFriend(TString cname) --- a pamela tree must be created first" << endl;
4518        return NULL;
4519      }
4520    
4521      TChain *c = new TChain( cname.Data() );    TChain *c = new TChain(cname.Data());
4522    
4523      TIter next( GetPamTree()->GetListOfFiles() );    TIter next(GetPamTree()->GetListOfFiles());
4524      Int_t nf = 0;    Int_t nf = 0;
4525      TChainElement* element = 0;        TChainElement* element = 0;
4526      while ((element = (TChainElement*) next())) {          while ((element = (TChainElement*) next())) {
4527          c->Add(element->GetTitle());      c->Add(element->GetTitle());
4528          nf++;      nf++;
4529      }    }
4530    
4531      GetPamTree()->AddFriend(cname.Data());    GetPamTree()->AddFriend(cname.Data());
4532    
4533      cout << "external chain created and added to pamela friends :"<<cname<<endl;    cout << "external chain created and added to pamela friends :" << cname << endl;
4534      cout << "n.files "<<nf<<endl;    cout << "n.files " << nf << endl;
       
4535    
4536      return c;        return c;
4537    
4538  }  }
4539    
4540    /**
4541     * Returns the current read entry. This method simply returns the result of the call to
4542     * pam_tree->GetReadEntry(), so it is entirely handled by ROOT.
4543     */
4544    Long64_t PamLevel2::GetReadEntry() {
4545      return pam_tree->GetReadEntry();
4546    }
4547    
4548    /**
4549     * Sets the sorting method. If the new method is different from the previous, the issorted
4550     * flag is set to false, forcing a new sort the next time GetTrack is called.
4551     * @see GetTrack
4552     */
4553    void PamLevel2::SetSortingMethod(TString how) {
4554      if (howtosort != how) {
4555        issorted = false;
4556      }
4557      howtosort = how;
4558    }

Legend:
Removed from v.1.80  
changed lines
  Added in v.1.81

  ViewVC Help
Powered by ViewVC 1.1.23