/[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.66 by pam-fi, Thu Dec 4 15:34:26 2008 UTC revision 1.95 by pam-ts, Wed Oct 15 08:51:51 2014 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() {
   
     Clear();  
   
     delete []    Ipltof;    
     delete []    Ipaddle;  
     delete []    Ipartof;  
     delete []    Xintof;    
     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;    
   
   
 };  
31    
32      Clear();
33      /* EM all these are in the stack not in the heap, so no need to delete by hand...
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    }
136    
137    
138  void GPamela::SetBranchAddress( TChain* fhBookTree ){  void GPamela::SetBranchAddress(TChain* fhBookTree) {
139    
140  //    cout << "fhBookTree "<<fhBookTree << endl;    //    cout << "fhBookTree "<<fhBookTree << endl;
141      // prepare tree    // prepare tree
142      fhBookTree->SetBranchAddress("Irun",&Irun);    fhBookTree->SetBranchAddress("Irun", &Irun);
143      fhBookTree->SetBranchAddress("Ievnt",&Ievnt);    fhBookTree->SetBranchAddress("Ievnt", &Ievnt);
144      fhBookTree->SetBranchAddress("Ipa",&Ipa);    fhBookTree->SetBranchAddress("Ipa", &Ipa);
145      fhBookTree->SetBranchAddress("X0",&X0);    fhBookTree->SetBranchAddress("X0", &X0);
146      fhBookTree->SetBranchAddress("Y0",&Y0);    fhBookTree->SetBranchAddress("Y0", &Y0);
147      fhBookTree->SetBranchAddress("Z0",&Z0);    fhBookTree->SetBranchAddress("Z0", &Z0);
148      fhBookTree->SetBranchAddress("Theta",&Theta);    fhBookTree->SetBranchAddress("Theta", &Theta);
149      fhBookTree->SetBranchAddress("Phi",&Phi);    fhBookTree->SetBranchAddress("Phi", &Phi);
150      fhBookTree->SetBranchAddress("P0",&P0);    fhBookTree->SetBranchAddress("P0", &P0);
151      fhBookTree->SetBranchAddress("Nthtof",&Nthtof);    fhBookTree->SetBranchAddress("Nthtof", &Nthtof);
152      fhBookTree->SetBranchAddress("Ipltof",Ipltof);    fhBookTree->SetBranchAddress("Ipltof", Ipltof);
153      fhBookTree->SetBranchAddress("Ipaddle",Ipaddle);    fhBookTree->SetBranchAddress("Ipaddle", Ipaddle);
154      fhBookTree->SetBranchAddress("Ipartof",Ipartof);    fhBookTree->SetBranchAddress("Ipartof", Ipartof);
155      fhBookTree->SetBranchAddress("Xintof",Xintof);    fhBookTree->SetBranchAddress("Xintof", Xintof);
156      fhBookTree->SetBranchAddress("Yintof",Yintof);    fhBookTree->SetBranchAddress("Yintof", Yintof);
157      fhBookTree->SetBranchAddress("Zintof",Zintof);    fhBookTree->SetBranchAddress("Zintof", Zintof);
158      fhBookTree->SetBranchAddress("Xouttof",Xouttof);    fhBookTree->SetBranchAddress("Xouttof", Xouttof);
159      fhBookTree->SetBranchAddress("Youttof",Youttof);    fhBookTree->SetBranchAddress("Youttof", Youttof);
160      fhBookTree->SetBranchAddress("Zouttof",Zouttof);    fhBookTree->SetBranchAddress("Zouttof", Zouttof);
161      fhBookTree->SetBranchAddress("Ereltof",Ereltof);    fhBookTree->SetBranchAddress("Ereltof", Ereltof);
162      fhBookTree->SetBranchAddress("Timetof",Timetof);    fhBookTree->SetBranchAddress("Timetof", Timetof);
163      fhBookTree->SetBranchAddress("Pathtof",Pathtof);    fhBookTree->SetBranchAddress("Pathtof", Pathtof);
164      fhBookTree->SetBranchAddress("P0tof",P0tof);    fhBookTree->SetBranchAddress("P0tof", P0tof);
165      fhBookTree->SetBranchAddress("Nthcat",&Nthcat);    fhBookTree->SetBranchAddress("Nthcat", &Nthcat);
166      fhBookTree->SetBranchAddress("Iparcat",Iparcat);    fhBookTree->SetBranchAddress("Iparcat", Iparcat);
167      fhBookTree->SetBranchAddress("Icat",Icat);    fhBookTree->SetBranchAddress("Icat", Icat);
168      fhBookTree->SetBranchAddress("Xincat",Xincat);    fhBookTree->SetBranchAddress("Xincat", Xincat);
169      fhBookTree->SetBranchAddress("Yincat",Yincat);    fhBookTree->SetBranchAddress("Yincat", Yincat);
170      fhBookTree->SetBranchAddress("Zincat",Zincat);    fhBookTree->SetBranchAddress("Zincat", Zincat);
171      fhBookTree->SetBranchAddress("Xoutcat",Xoutcat);    fhBookTree->SetBranchAddress("Xoutcat", Xoutcat);
172      fhBookTree->SetBranchAddress("Youtcat",Youtcat);    fhBookTree->SetBranchAddress("Youtcat", Youtcat);
173      fhBookTree->SetBranchAddress("Zoutcat",Zoutcat);    fhBookTree->SetBranchAddress("Zoutcat", Zoutcat);
174      fhBookTree->SetBranchAddress("Erelcat",Erelcat);    fhBookTree->SetBranchAddress("Erelcat", Erelcat);
175      fhBookTree->SetBranchAddress("Timecat",Timecat);    fhBookTree->SetBranchAddress("Timecat", Timecat);
176      fhBookTree->SetBranchAddress("Pathcat",Pathcat);    fhBookTree->SetBranchAddress("Pathcat", Pathcat);
177      fhBookTree->SetBranchAddress("P0cat",P0cat);    fhBookTree->SetBranchAddress("P0cat", P0cat);
178      fhBookTree->SetBranchAddress("Nthcas",&Nthcas);    fhBookTree->SetBranchAddress("Nthcas", &Nthcas);
179      fhBookTree->SetBranchAddress("Iparcas",Iparcas);    fhBookTree->SetBranchAddress("Iparcas", Iparcas);
180      fhBookTree->SetBranchAddress("Icas",Icas);    fhBookTree->SetBranchAddress("Icas", Icas);
181      fhBookTree->SetBranchAddress("Xincas",Xincas);    fhBookTree->SetBranchAddress("Xincas", Xincas);
182      fhBookTree->SetBranchAddress("Yincas",Yincas);    fhBookTree->SetBranchAddress("Yincas", Yincas);
183      fhBookTree->SetBranchAddress("Zincas",Zincas);    fhBookTree->SetBranchAddress("Zincas", Zincas);
184      fhBookTree->SetBranchAddress("Xoutcas",Xoutcas);    fhBookTree->SetBranchAddress("Xoutcas", Xoutcas);
185      fhBookTree->SetBranchAddress("Youtcas",Youtcas);    fhBookTree->SetBranchAddress("Youtcas", Youtcas);
186      fhBookTree->SetBranchAddress("Zoutcas",Zoutcas);    fhBookTree->SetBranchAddress("Zoutcas", Zoutcas);
187      fhBookTree->SetBranchAddress("Erelcas",Erelcas);    fhBookTree->SetBranchAddress("Erelcas", Erelcas);
188      fhBookTree->SetBranchAddress("Timecas",Timecas);    fhBookTree->SetBranchAddress("Timecas", Timecas);
189      fhBookTree->SetBranchAddress("Pathcas",Pathcas);    fhBookTree->SetBranchAddress("Pathcas", Pathcas);
190      fhBookTree->SetBranchAddress("P0cas",P0cas);    fhBookTree->SetBranchAddress("P0cas", P0cas);
191      fhBookTree->SetBranchAddress("Nthspe",&Nthspe);    fhBookTree->SetBranchAddress("Nthspe", &Nthspe);
192      fhBookTree->SetBranchAddress("Iparspe",Iparspe);    fhBookTree->SetBranchAddress("Iparspe", Iparspe);
193      fhBookTree->SetBranchAddress("Itrpb",Itrpb);    fhBookTree->SetBranchAddress("Itrpb", Itrpb);
194      fhBookTree->SetBranchAddress("Itrsl",Itrsl);    fhBookTree->SetBranchAddress("Itrsl", Itrsl);
195      fhBookTree->SetBranchAddress("Itspa",Itspa);    fhBookTree->SetBranchAddress("Itspa", Itspa);
196      fhBookTree->SetBranchAddress("Xinspe",Xinspe);    fhBookTree->SetBranchAddress("Xinspe", Xinspe);
197      fhBookTree->SetBranchAddress("Yinspe",Yinspe);    fhBookTree->SetBranchAddress("Yinspe", Yinspe);
198      fhBookTree->SetBranchAddress("Zinspe",Zinspe);    fhBookTree->SetBranchAddress("Zinspe", Zinspe);
199      fhBookTree->SetBranchAddress("Xoutspe",Xoutspe);    fhBookTree->SetBranchAddress("Xoutspe", Xoutspe);
200      fhBookTree->SetBranchAddress("Youtspe",Youtspe);    fhBookTree->SetBranchAddress("Youtspe", Youtspe);
201      fhBookTree->SetBranchAddress("Zoutspe",Zoutspe);    fhBookTree->SetBranchAddress("Zoutspe", Zoutspe);
202      fhBookTree->SetBranchAddress("Xavspe",Xavspe);    fhBookTree->SetBranchAddress("Xavspe", Xavspe);
203      fhBookTree->SetBranchAddress("Yavspe",Yavspe);    fhBookTree->SetBranchAddress("Yavspe", Yavspe);
204      fhBookTree->SetBranchAddress("Zavspe",Zavspe);    fhBookTree->SetBranchAddress("Zavspe", Zavspe);
205      fhBookTree->SetBranchAddress("Erelspe",Erelspe);    fhBookTree->SetBranchAddress("Erelspe", Erelspe);
206      fhBookTree->SetBranchAddress("Pathspe",Pathspe);    fhBookTree->SetBranchAddress("Pathspe", Pathspe);
207      fhBookTree->SetBranchAddress("P0spe",P0spe);    fhBookTree->SetBranchAddress("P0spe", P0spe);
208      fhBookTree->SetBranchAddress("Nxmult",Nxmult);    fhBookTree->SetBranchAddress("Nxmult", Nxmult);
209      fhBookTree->SetBranchAddress("Nymult",Nymult);    fhBookTree->SetBranchAddress("Nymult", Nymult);
210      fhBookTree->SetBranchAddress("Nstrpx",&Nstrpx);    fhBookTree->SetBranchAddress("Nstrpx", &Nstrpx);
211      fhBookTree->SetBranchAddress("Npstripx",Npstripx);    fhBookTree->SetBranchAddress("Npstripx", Npstripx);
212      fhBookTree->SetBranchAddress("Ntstripx",Ntstripx);    fhBookTree->SetBranchAddress("Ntstripx", Ntstripx);
213      fhBookTree->SetBranchAddress("Istripx",Istripx);    fhBookTree->SetBranchAddress("Istripx", Istripx);
214      fhBookTree->SetBranchAddress("Qstripx",Qstripx);    fhBookTree->SetBranchAddress("Qstripx", Qstripx);
215      fhBookTree->SetBranchAddress("Xstripx",Xstripx);    fhBookTree->SetBranchAddress("Xstripx", Xstripx);
216      fhBookTree->SetBranchAddress("Nstrpy",&Nstrpy);    fhBookTree->SetBranchAddress("Nstrpy", &Nstrpy);
217      fhBookTree->SetBranchAddress("Npstripy",Npstripy);    fhBookTree->SetBranchAddress("Npstripy", Npstripy);
218      fhBookTree->SetBranchAddress("Ntstripy",Ntstripy);    fhBookTree->SetBranchAddress("Ntstripy", Ntstripy);
219      fhBookTree->SetBranchAddress("Istripy",Istripy);    fhBookTree->SetBranchAddress("Istripy", Istripy);
220      fhBookTree->SetBranchAddress("Qstripy",Qstripy);    fhBookTree->SetBranchAddress("Qstripy", Qstripy);
221      fhBookTree->SetBranchAddress("Ystripy",Ystripy);    fhBookTree->SetBranchAddress("Ystripy", Ystripy);
222      fhBookTree->SetBranchAddress("Nthcali",&Nthcali);    fhBookTree->SetBranchAddress("Nthcali", &Nthcali);
223      fhBookTree->SetBranchAddress("Icaplane",Icaplane);    fhBookTree->SetBranchAddress("Icaplane", Icaplane);
224      fhBookTree->SetBranchAddress("Icastrip",Icastrip);    fhBookTree->SetBranchAddress("Icastrip", Icastrip);
225      fhBookTree->SetBranchAddress("Icamod",Icamod);    fhBookTree->SetBranchAddress("Icamod", Icamod);
226      fhBookTree->SetBranchAddress("Enestrip",Enestrip);    fhBookTree->SetBranchAddress("Enestrip", Enestrip);
227      fhBookTree->SetBranchAddress("Nthcal",&Nthcal);    fhBookTree->SetBranchAddress("Nthcal", &Nthcal);
228      fhBookTree->SetBranchAddress("Icapl",Icapl);    fhBookTree->SetBranchAddress("Icapl", Icapl);
229      fhBookTree->SetBranchAddress("Icasi",Icasi);    fhBookTree->SetBranchAddress("Icasi", Icasi);
230      fhBookTree->SetBranchAddress("Icast",Icast);    fhBookTree->SetBranchAddress("Icast", Icast);
231      fhBookTree->SetBranchAddress("Xincal",Xincal);    fhBookTree->SetBranchAddress("Xincal", Xincal);
232      fhBookTree->SetBranchAddress("Yincal",Yincal);    fhBookTree->SetBranchAddress("Yincal", Yincal);
233      fhBookTree->SetBranchAddress("Zincal",Zincal);    fhBookTree->SetBranchAddress("Zincal", Zincal);
234      fhBookTree->SetBranchAddress("Erelcal",Erelcal);    fhBookTree->SetBranchAddress("Erelcal", Erelcal);
235      fhBookTree->SetBranchAddress("Nthnd",&Nthnd);    fhBookTree->SetBranchAddress("Nthnd", &Nthnd);
236      fhBookTree->SetBranchAddress("Itubend",Itubend);    fhBookTree->SetBranchAddress("Itubend", Itubend);
237      fhBookTree->SetBranchAddress("Iparnd",Iparnd);    fhBookTree->SetBranchAddress("Iparnd", Iparnd);
238      fhBookTree->SetBranchAddress("Xinnd",Xinnd);    fhBookTree->SetBranchAddress("Xinnd", Xinnd);
239      fhBookTree->SetBranchAddress("Yinnd",Yinnd);    fhBookTree->SetBranchAddress("Yinnd", Yinnd);
240      fhBookTree->SetBranchAddress("Zinnd",Zinnd);    fhBookTree->SetBranchAddress("Zinnd", Zinnd);
241      fhBookTree->SetBranchAddress("Xoutnd",Xoutnd);    fhBookTree->SetBranchAddress("Xoutnd", Xoutnd);
242      fhBookTree->SetBranchAddress("Youtnd",Youtnd);    fhBookTree->SetBranchAddress("Youtnd", Youtnd);
243      fhBookTree->SetBranchAddress("Zoutnd",Zoutnd);    fhBookTree->SetBranchAddress("Zoutnd", Zoutnd);
244      fhBookTree->SetBranchAddress("Erelnd",Erelnd);    fhBookTree->SetBranchAddress("Erelnd", Erelnd);
245      fhBookTree->SetBranchAddress("Timend",Timend);    fhBookTree->SetBranchAddress("Timend", Timend);
246      fhBookTree->SetBranchAddress("Pathnd",Pathnd);    fhBookTree->SetBranchAddress("Pathnd", Pathnd);
247      fhBookTree->SetBranchAddress("P0nd",P0nd);    fhBookTree->SetBranchAddress("P0nd", P0nd);
248      fhBookTree->SetBranchAddress("Nthcard",&Nthcard);    fhBookTree->SetBranchAddress("Nthcard", &Nthcard);
249      fhBookTree->SetBranchAddress("Iparcard",Iparcard);    fhBookTree->SetBranchAddress("Iparcard", Iparcard);
250      fhBookTree->SetBranchAddress("Icard",Icard);    fhBookTree->SetBranchAddress("Icard", Icard);
251      fhBookTree->SetBranchAddress("Xincard",Xincard);    fhBookTree->SetBranchAddress("Xincard", Xincard);
252      fhBookTree->SetBranchAddress("Yincard",Yincard);    fhBookTree->SetBranchAddress("Yincard", Yincard);
253      fhBookTree->SetBranchAddress("Zincard",Zincard);    fhBookTree->SetBranchAddress("Zincard", Zincard);
254      fhBookTree->SetBranchAddress("Xoutcard",Xoutcard);    fhBookTree->SetBranchAddress("Xoutcard", Xoutcard);
255      fhBookTree->SetBranchAddress("Youtcard",Youtcard);    fhBookTree->SetBranchAddress("Youtcard", Youtcard);
256      fhBookTree->SetBranchAddress("Zoutcard",Zoutcard);    fhBookTree->SetBranchAddress("Zoutcard", Zoutcard);
257      fhBookTree->SetBranchAddress("Erelcard",Erelcard);    fhBookTree->SetBranchAddress("Erelcard", Erelcard);
258      fhBookTree->SetBranchAddress("Timecard",Timecard);    fhBookTree->SetBranchAddress("Timecard", Timecard);
259      fhBookTree->SetBranchAddress("Pathcard",Pathcard);    fhBookTree->SetBranchAddress("Pathcard", Pathcard);
260      fhBookTree->SetBranchAddress("P0card",P0card);    fhBookTree->SetBranchAddress("P0card", P0card);
261    
262  //    fhBookTree->SetBranchStatus("*",0);    //    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;    trk_ext_track = 0;
282      tof_track  = 0;    calo_track = 0;
283      orb_track  = 0;    tof_track = 0;
284      candeleteobj = 0;    orb_track = 0;
285      pscore = 0;    candeleteobj = 0;
286      iscore = 0;    pscore = 0;
287  };    iscore = 0;
288    }
289    ;
290  //--------------------------------------  //--------------------------------------
291  //  //
292  //  //
293  //--------------------------------------  //--------------------------------------
294  /**  /**
295   * Constructor   * Constructor
296   */   */
297  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o, OrbitalInfoTrkVar *r){  PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o, OrbitalInfoTrkVar *r) {
298    
299      trk_track  = 0;    trk_ext_track = 0;
300      calo_track = 0;    trk_track = 0;
301      tof_track  = 0;    calo_track = 0;
302      orb_track  = 0;    tof_track = 0;
303  //     if(t)trk_track  = new TrkTrack(*t);    orb_track = 0;
304  //     if(c)calo_track = new CaloTrkVar(*c);    //     if(t)trk_track  = new TrkTrack(*t);
305  //     if(o)tof_track  = new ToFTrkVar(*o);    //     if(c)calo_track = new CaloTrkVar(*c);
306      if(t)trk_track  = t;    //     if(o)tof_track  = new ToFTrkVar(*o);
307      if(c)calo_track = c;  //   if (t)
308      if(o)tof_track  = o;  //     trk_track = t;
309      if(r)orb_track  = r;  //   if (c)
310      candeleteobj = 0;  //     calo_track = c;
311    //   if (o)
312    //     tof_track = o;
313    //   if (r)
314    //     orb_track = r;
315    
316    //   candeleteobj = 0;
317    
318    
319      if (t){
320          trk_track = new TrkTrack(*t);
321          trk_ext_track = new ExtTrack(*t);//NB!! ha dimensione 6 invece che 8
322      }
323      if (c)
324        calo_track = new CaloTrkVar(*c);
325      if (o)
326        tof_track = new ToFTrkVar(*o);
327      if (r)
328        orb_track = new OrbitalInfoTrkVar(*r);
329      candeleteobj = 1;
330    
331  };  }
332  PamTrack::PamTrack(const PamTrack& track){  ;
333    /**
334     * Constructor
335     */
336    PamTrack::PamTrack(ExtTrack* t, CaloTrkVar* c, ToFTrkVar* o, OrbitalInfoTrkVar *r) {
337    
338      TrkTrack   *t = track.trk_track;    trk_ext_track = 0;
339      CaloTrkVar *c = track.calo_track;    trk_track = 0;
340      ToFTrkVar  *o = track.tof_track;    calo_track = 0;
341      OrbitalInfoTrkVar  *r = track.orb_track;    tof_track = 0;
342      orb_track = 0;
343      //     if(t)trk_track  = new TrkTrack(*t);
344      //     if(c)calo_track = new CaloTrkVar(*c);
345      //     if(o)tof_track  = new ToFTrkVar(*o);
346    //   if (t)
347    //     trk_track = t;
348    //   if (c)
349    //     calo_track = c;
350    //   if (o)
351    //     tof_track = o;
352    //   if (r)
353    //     orb_track = r;
354    
355    //   candeleteobj = 0;
356    
357    
358      if (t){
359    ////      trk_track = new TrkTrack(*t);//in this case TrkTrack object remains null
360          trk_ext_track = new ExtTrack(*t);
361      }
362      if (c)
363        calo_track = new CaloTrkVar(*c);
364      if (o)
365        tof_track = new ToFTrkVar(*o);
366      if (r)
367        orb_track = new OrbitalInfoTrkVar(*r);
368      candeleteobj = 1;
369      pscore = 0;
370      iscore = 0;
371    
     trk_track  = 0;  
     calo_track = 0;  
     tof_track  = 0;  
     orb_track  = 0;  
     if(t)trk_track  = new TrkTrack(*t);  
     if(c)calo_track = new CaloTrkVar(*c);  
     if(o)tof_track  = new ToFTrkVar(*o);  
     if(r)orb_track  = new OrbitalInfoTrkVar(*r);  
     candeleteobj = 1;  
       
372  }  }
373  void PamTrack::Clear(){  ;
374    PamTrack::PamTrack(const PamTrack& track) {
375    
376  //    cout << "PamTrack::Clear() "<<candeleteobj<<endl;    TrkTrack *t = track.trk_track;
377      if(candeleteobj){    CaloTrkVar *c = track.calo_track;
378          if(trk_track)  trk_track->TrkTrack::Clear();    ToFTrkVar *o = track.tof_track;
379          if(calo_track) calo_track->CaloTrkVar::Clear();//???    OrbitalInfoTrkVar *r = track.orb_track;
380          if(tof_track)  tof_track->ToFTrkVar::Clear();//???  
381          if(orb_track)  orb_track->OrbitalInfoTrkVar::Clear();//???    trk_track = 0;
382      }else{    calo_track = 0;
383          trk_track  = 0;    tof_track = 0;
384          calo_track = 0;    orb_track = 0;
385          tof_track  = 0;    if (t)
386          orb_track  = 0;      trk_track = new TrkTrack(*t);
387      }    if (c)
388      pscore = 0;      calo_track = new CaloTrkVar(*c);
389      iscore = 0;    if (o)
390        tof_track = new ToFTrkVar(*o);
391  }    if (r)
392  void PamTrack::Delete(){      orb_track = new OrbitalInfoTrkVar(*r);
393  //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;    candeleteobj = 1;
394      if(candeleteobj){    pscore = 0;
395          if(trk_track)  {    iscore = 0;
396              trk_track->TrkTrack::Clear();  
397              delete trk_track;  }
398          }  void PamTrack::Clear() {
399          if(calo_track){  
400              calo_track->CaloTrkVar::Clear();//???    //    cout << "PamTrack::Clear() "<<candeleteobj<<endl;
401              delete calo_track;    if (candeleteobj) {
402          }        
403          if(tof_track){      if (trk_ext_track)
404              tof_track->ToFTrkVar::Clear();//???        trk_ext_track->ExtTrack::Clear();
405              delete tof_track;      if (trk_track)
406          }        trk_track->TrkTrack::Clear();
407          if(orb_track){      if (calo_track)
408              orb_track->OrbitalInfoTrkVar::Clear();//???        calo_track->CaloTrkVar::Clear();//???
409              delete orb_track;      if (tof_track)
410          }        tof_track->ToFTrkVar::Clear();//???
411      }else{      if (orb_track)
412          Clear();        orb_track->OrbitalInfoTrkVar::Clear();//???
413      }
414      else {
415        trk_ext_track = 0;
416        trk_track = 0;
417        calo_track = 0;
418        tof_track = 0;
419        orb_track = 0;
420      }
421      pscore = 0;
422      iscore = 0;
423    
424    }
425    void PamTrack::Delete() {
426      //    cout << "PamTrack::Delete() "<<candeleteobj<<endl;
427      if (candeleteobj) {
428        if (trk_ext_track) {
429          trk_ext_track->ExtTrack::Clear();
430          delete trk_ext_track;
431        }
432        if (trk_track) {
433          trk_track->TrkTrack::Clear();
434          delete trk_track;
435        }
436        if (calo_track) {
437          calo_track->CaloTrkVar::Clear();//???
438          delete calo_track;
439        }
440        if (tof_track) {
441          tof_track->ToFTrkVar::Clear();//???
442          delete tof_track;
443        }
444        if (orb_track) {
445          orb_track->OrbitalInfoTrkVar::Clear();//???
446          delete orb_track;
447      }      }
448      }
449      else {
450        Clear();
451      }
452  }  }
453    
454    
455    
456    
457  //--------------------------------------  //--------------------------------------
458  //  //
459  //  //
460  //--------------------------------------  //--------------------------------------
461  /**  /**
462   * Default Constructor   * Default Constructor
463   */   */
464  PamLevel2::PamLevel2(){  PamLevel2::PamLevel2() {
465      Initialize();    Initialize();
466  };  }
467    
468    
469  /**  /**
470   * Constructor   * Constructor
471   * @param ddir Name of directory where level2 files are stored.   * @param ddir Name of directory where level2 files are stored.
472   * @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
473   * @param detlist Options to chose what to load.   * @param detlist Options to chose what to load.
474   * Possible options are:   * Possible options are:
475   *       +AUTO --> load all trees/branches in the input files   *       +AUTO --> load all trees/branches in the input files
476   *       +(-)ALL --> inlcude(exclude) all trees/branches   *       +(-)ALL --> inlcude(exclude) all trees/branches
477   *       +(-)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
478   *       +(-)TRK0 --> include(exclude) tracker level0 tree   *       +(-)TRK0 --> include(exclude) tracker level0 tree
479   *       +(-)GP --> include exclude GPAMELA output tree   *       +(-)GP --> include exclude GPAMELA output tree
480   * If no options are specified, the default is assumed. Default is:   * If no options are specified, the default is assumed. Default is:
481   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
482   */   */
483  PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){  PamLevel2::PamLevel2(TString ddir, TString llist, TString detlist) {
484      Initialize();    Initialize();
485      TList*  listf = GetListOfLevel2Files(ddir,list);    TList* listf = GetListOfLevel2Files(ddir, llist);
486      GetPamTree(listf,detlist);    if (listf)
487        GetPamTree(listf, detlist);
488      if (listf)
489      GetRunTree(listf);      GetRunTree(listf);
490  };    SetMaxShift(-1);
491    }
492    
493    
494    PamLevel2::PamLevel2(TString ddir, TList *llist, TString detlist) {
495      Initialize();
496      GetPamTree(llist, detlist);
497      GetRunTree(llist);
498      SetMaxShift(-1);
499    }
500    
501  /**  /**
502   * Constructor   * Constructor
503   * @param ddir Name of directory where level2 files are stored.   * @param ddir Name of directory where level2 files are stored.
504   * @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
505   * Default trees/branches are loaded. Default is:   * Default trees/branches are loaded. Default is:
506   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
507   */   */
508  PamLevel2::PamLevel2(TString ddir,TString list){  PamLevel2::PamLevel2(TString ddir, TString llist) {
509      Initialize();    Initialize();
510      TList*  listf = GetListOfLevel2Files(ddir,list);    TList* listf = GetListOfLevel2Files(ddir, llist);
511      GetPamTree(listf,"");    cout << "GetPamTree: "<<endl;
512      GetRunTree(listf);    GetPamTree(listf, "");
513  };    cout << "GetRunTree: "<<endl;
514      GetRunTree(listf);
515      SetMaxShift(-1);
516    }
517    
518    
519  void PamLevel2::Initialize(){  void PamLevel2::Initialize() {
           
     h0_obj    = 0;  
     trk0_obj  = 0;  
     calo0_obj  = 0;  
   
     trk2_obj  = 0;  
     trk1_obj  = 0;  
     trkh_obj  = 0;  
     calo1_obj = 0;  
     calo2_obj = 0;  
     tof_obj   = 0;  
     trig_obj  = 0;  
     s4_obj    = 0;  
     nd_obj    = 0;  
     ac_obj    = 0;  
     orb_obj   = 0;  
     gp_obj    = 0;  
   
     run_obj   = 0;//new GL_RUN();  
     soft_obj   = 0;// Emiliano  
     irun = -1LL;  
     irunt = -1LL;  
     runfirstentry = 0LL;  
     runlastentry = 0LL;  
   
     l0_file = NULL;  
     l0_tree = NULL;  
     iroot   = -1;  
     dbc     = 0;  
520    
521      prevshift = 0;    h0_obj = 0;
522      maxshift = 10; //EMILIANO    trk0_obj = 0;
523          calo0_obj = 0;
524      run_tree = NULL;  
525      run_tree_clone = NULL;    trk2_obj = 0;
526      sel_tree = NULL;    trk1_obj = 0;
527      sel_tree_clone = NULL;    trkh_obj = 0;
528          calo1_obj = 0;
529      irunentry = -1LL;    calo2_obj = 0;
530      pam_tree = NULL;    tof2_obj = 0;
531      for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;    trig_obj = 0;
532      s4_obj = 0;
533      totdltime[0] = 0LL;    nd_obj = 0;
534      totdltime[1] = 0LL;    ac_obj = 0;
535      totdltime[2] = 0LL;    orb2_obj = 0;
536      gp_obj = 0;
537      host = "mysql://localhost/pamelaprod";  
538      user = "anonymous";    extAlgFlag=0;
539      psw = "";  
540      const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");    trk_ext_obj     = 0;
541      const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");    trk_ext_nuc_obj = 0;
542      const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");    trk_nuc_obj     = 0;
543      if ( !pamdbhost ) pamdbhost = "";    
544      if ( !pamdbuser ) pamdbuser = "";    calo_ext_obj     = 0;
545      if ( !pamdbpsw ) pamdbpsw = "";    calo_ext_nuc_obj = 0;
546      if ( strcmp(pamdbhost,"") ) host = pamdbhost;    calo_nuc_obj     = 0;
547      if ( strcmp(pamdbuser,"") ) user = pamdbuser;    
548      if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;    tof_ext_obj     = 0;
549      tof_ext_nuc_obj = 0;
550      tof_nuc_obj     = 0;
551      
552      orb_ext_obj     = 0;
553      orb_ext_nuc_obj = 0;
554      orb_nuc_obj     = 0;
555    
556      trk2_nuc_obj  = 0;
557      calo2_nuc_obj = 0;
558      tof2_nuc_obj  = 0;
559      orb2_nuc_obj  = 0;
560    
561    
562      run_obj = 0;//new GL_RUN();
563      soft_obj = 0;// Emiliano
564      irun = -1LL;
565      irunt = -1LL;
566      totrunentry = 0LL;
567      totrunentrymax = 0LL;
568      totrunentrymin = 0LL;
569      runfirstentry = 0LL;
570      runlastentry = 0LL;
571      gltsync = 0; // Emiliano
572      fUpdateRunInfo = true; // Emiliano
573      fUseDBinRunInfo = true; // Emiliano
574      isSync = false; // by default assume that the level2 file(s) is(are) not sinchronized between L0/DB and L2, that is we miss some packets in L2 due to nested/DV-skipped events
575      il0entry = 0LL;
576      //  hasL0EE = true;
577    
578      l0_file = NULL;
579      l0_tree = NULL;
580      iroot = -1;
581      dbc = 0;
582    
583      prevshift = 0;
584      yprevshift = 0;
585      maxshift = 10; //EMILIANO now overridden by SetMaxShift(-1) called by constructors
586    
587      run_tree = NULL;
588      run_tree_clone = NULL;
589      sel_tree = NULL;
590      sel_tree_clone = NULL;
591    
592      irunentry = -1LL;
593      pam_tree = NULL;
594      for (Int_t i = 0; i < NCLONES; i++)
595        pam_tree_clone[i] = NULL;
596    
597      totdltime[0] = 0LL;
598      totdltime[1] = 0LL;
599      totdltime[2] = 0LL;
600    
601      host = "mysql://localhost/pamelaprod";
602      user = "anonymous";
603      psw = "";
604      const char *pamdbhost = gSystem->Getenv("PAM_DBHOST");
605      const char *pamdbuser = gSystem->Getenv("PAM_DBUSER");
606      const char *pamdbpsw = gSystem->Getenv("PAM_DBPSW");
607      if (!pamdbhost)
608        pamdbhost = "";
609      if (!pamdbuser)
610        pamdbuser = "";
611      if (!pamdbpsw)
612        pamdbpsw = "";
613      if (strcmp(pamdbhost, ""))
614        host = pamdbhost;
615      if (strcmp(pamdbuser, ""))
616        user = pamdbuser;
617      if (strcmp(pamdbpsw, ""))
618        psw = pamdbpsw;
619    
620      //    sorted_tracks = 0;//new TRefArray();
621    
622      CAL0 = false;
623      CAL1 = true;
624      CAL2 = true;
625      TRK2 = true;
626      TRK1 = false;
627      TRK0 = false;
628      TRKh = false;
629      TRG = true;
630      TOF = true;
631      TOF0 = false;
632      S4 = true;
633      ND = true;
634      AC = true;
635      ORB = true;
636      GP = false;
637    
638      EXT = false;
639      NUC = false;
640      trkAlg = "";//default tracking algorythm
641    
642      RUN = true;
643    
644      SELLI = -1;
645    
646      ISGP = false;
647    
648      DBG = false;
649    
650      tsorted = 0;
651      timage = 0;
652      text = 0 ;
653    
654      tsorted_nuc = 0;
655      timage_nuc = 0;
656      text_nuc = 0 ;
657    
658      howtosort = "+CAL+TOF";
659      //howtosort = "+TOF";
660      sortthr = 100.;
661    
662      issorted = false;
663      lastsorted = -1;
664      issorted_new = false;
665      lastsorted_new = -1;
666    
667        }
668    ;
669    /**
670     * Delete the event (act as Dtor)
671     */
672    void PamLevel2::Delete() {
673    
674  //    sorted_tracks = 0;//new TRefArray();    if (run_obj)
675            delete run_obj;
676      CAL0 = false;    if (soft_obj)
677      CAL1 = true;      delete soft_obj; //Emiliano
678      CAL2 = true;  
679      TRK2 = true;    //    cout << "void PamLevel2::Clear()"<<endl;
680      TRK1 = false;    if (h0_obj)
681      TRK0 = false;      delete h0_obj;
682      TRKh = false;    if (trk0_obj)
683      TRG  = true;      delete trk0_obj;
684      TOF  = true;    if (calo0_obj)
685      TOF0 = false;      delete calo0_obj;
686      S4   = true;    if (trk1_obj)
687      ND   = true;      delete trk1_obj;
688      AC   = true;    if (trk2_obj)
689      ORB  = true;          delete trk2_obj;
690      GP   = false;    if (trkh_obj)
691        delete trkh_obj;
692      if (calo1_obj)
693        delete calo1_obj;
694      if (calo2_obj)
695        delete calo2_obj;
696      if (tof2_obj)
697        delete tof2_obj;
698      if (trig_obj)
699        delete trig_obj;
700      if (s4_obj)
701        delete s4_obj;
702      if (nd_obj)
703        delete nd_obj;
704      if (ac_obj)
705        delete ac_obj;
706      if (orb2_obj)
707        delete orb2_obj;
708      if (gp_obj)
709        delete gp_obj;
710    
711      if(trk_nuc_obj)trk_nuc_obj->Delete();
712      if(trk_ext_obj)trk_ext_obj->Delete();
713      if(trk_ext_nuc_obj)trk_ext_nuc_obj->Delete();
714    
715      if(calo_nuc_obj)calo_nuc_obj->Delete();
716      if(calo_ext_obj)calo_ext_obj->Delete();
717      if(calo_ext_nuc_obj)calo_ext_nuc_obj->Delete();
718    
719      if(tof_nuc_obj)tof_nuc_obj->Delete();
720      if(tof_ext_obj)tof_ext_obj->Delete();
721      if(tof_ext_nuc_obj)tof_ext_nuc_obj->Delete();
722    
723      if(orb_nuc_obj)orb_nuc_obj->Delete();
724      if(orb_ext_obj)orb_ext_obj->Delete();
725      if(orb_ext_nuc_obj)orb_ext_nuc_obj->Delete();
726    
727    
728      if(trk2_nuc_obj)trk2_nuc_obj->Delete();;
729      if( calo2_nuc_obj)calo2_nuc_obj->Delete();;
730      if(tof2_nuc_obj)tof2_nuc_obj->Delete();;
731      if(orb2_nuc_obj)orb2_nuc_obj->Delete();;
732      
733    
     RUN  = true;  
734    
735      SELLI = -1;    if (tsorted) {
736        tsorted->Delete();
737        delete tsorted;
738      }
739      if (timage) {
740        timage->Delete();
741        delete timage;
742      }
743      if (text) {
744        text->Delete();
745        delete text;
746      }
747      if (tsorted_nuc) {
748        tsorted_nuc->Delete();
749        delete tsorted_nuc;
750      }
751      if (timage_nuc) {
752        timage_nuc->Delete();
753        delete timage_nuc;
754      }
755      if (text_nuc) {
756        text_nuc->Delete();
757        delete text_nuc;
758      }
759    
     ISGP = false;  
760    
     DBG = false;  
761    
762      tsorted=0;    if (dbc) {
763      timage=0;      dbc->Close();
764            delete dbc;
765      howtosort = "+CAL+TOF";      dbc=0;
766      //howtosort = "+TOF";    }
767      sortthr = 100.;  
768      if (gltsync)
769        delete gltsync;
770    
771      if (l0_file)
772        l0_file->Close();
773      //    if(pam_tree)pam_tree->Delete();;
774    
775  };    if (pam_tree) {
776  /**      //
777   * Delete the event (act as Dtor)      // 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...
778   */      //
779  void PamLevel2::Delete(){      TList *temp = pam_tree->GetListOfFriends();
780                TList *contents = new TList; // create chain friend list
781      if(run_obj)delete run_obj;      contents->SetOwner();
782      if(soft_obj)delete soft_obj; //Emiliano      TIter next(temp);
783        TChain *questo = 0;
784        while ((questo = (TChain*) next())) {
785          TString name = questo->GetName();
786          contents->Add((TChain*) gROOT->FindObject(name.Data()));// add object to the list
787        };
788        //
789        // deleting the main chain
790        //
791        pam_tree->Delete();
792        //
793        // deleting the friends...
794        //
795        TIter next2(contents);
796        TChain *questa = 0;
797        while ( (questa = (TChain*)next2()) ) {
798          TString name = questa->GetName();
799          questa->Delete();
800          questa = NULL;
801        };
802        //
803      };
804      pam_tree = NULL;
805    
806  //    cout << "void PamLevel2::Clear()"<<endl;    if (run_tree)
807      if(h0_obj)   delete h0_obj;      run_tree->Delete();;
808      if(trk0_obj) delete trk0_obj;          if (sel_tree)
809      if(calo0_obj) delete calo0_obj;          sel_tree->Delete();;
810      if(trk1_obj) delete trk1_obj;        
811      if(trk2_obj) delete trk2_obj;    // The following lines are commented out since they may generate a double delete error
812      if(trkh_obj) delete trkh_obj;    // if the file containing the clone trees is closed. This is because the file owns the
813      if(calo1_obj)delete calo1_obj;    // clone trees which are written into it, so it will delete them when it is closed; if
814      if(calo2_obj)delete calo2_obj;    // also PamLevel2 will try to delete these trees, a double delete error will be generated
815      if(tof_obj)  delete tof_obj;    // when exiting from analysis program. (Nicola 28/11/2011)
816      if(trig_obj) delete trig_obj;  
817      if(s4_obj)   delete s4_obj;    /*for (Int_t i = 0; i < NCLONES; i++)
818      if(nd_obj)   delete nd_obj;      if (pam_tree_clone[i])
819      if(ac_obj)   delete ac_obj;        pam_tree_clone[i]->Delete();;
820      if(orb_obj)  delete orb_obj;    if (run_tree_clone)
821      if(gp_obj)   delete gp_obj;      run_tree_clone->Delete();;
822          if (sel_tree_clone)
823      if(tsorted){      sel_tree_clone->Delete();;*/
         tsorted->Delete();  
         delete tsorted;  
     }  
     if(timage){  
         timage->Delete();  
         delete timage;  
     }  
824    
825      if(dbc){    if (irunoffset)
826          dbc->Close();      delete[] irunoffset;
         delete dbc;  
     }  
       
     if(l0_file)l0_file->Close();  
     //    if(pam_tree)pam_tree->Delete();;  
827    
     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;  
828    
829      if(run_tree)run_tree->Delete();;    Initialize();
     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;  
830    
831  };  }
832    ;
833    
834  /**  /**
835   * Clear the event (NB! does not deallocate objects)   * Clear the event (NB! does not deallocate objects)
836   */   */
837  void PamLevel2::Clear(){  void PamLevel2::Clear() {
           
 //    cout << "void PamLevel2::Clear()"<<endl;  
838    
839  //    //    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();  
840    
841      if(tsorted){    //
842          tsorted->Delete();    // 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
843      }    // want to load them for each event even if they are the same...
844      if(timage){    //
845          timage->Delete();    //    if(run_obj)delete run_obj;
846      }    //    if(run_obj) run_obj->Clear();  // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead
847  };    //    if(soft_obj) soft_obj->Clear();
848    
849      if (h0_obj)
850        h0_obj->Clear();
851      //    if(trk0_obj) trk0_obj->Clear();
852      if (trk1_obj)
853        trk1_obj->Clear();
854      if (trk2_obj)
855        trk2_obj->Clear();
856      if (trkh_obj)
857        trkh_obj->Clear();
858      if (calo0_obj)
859        calo0_obj->Clear();
860      if (calo1_obj)
861        calo1_obj->Clear();
862      if (calo2_obj)
863        calo2_obj->Clear();
864      if (tof2_obj)
865        tof2_obj->Clear();
866      if (trig_obj)
867        trig_obj->Clear();
868      if (s4_obj)
869        s4_obj->Clear();
870      if (nd_obj)
871        nd_obj->Clear();
872      if (ac_obj)
873        ac_obj->Clear();
874      if (orb2_obj)
875        orb2_obj->Clear();
876      if (gp_obj)
877        gp_obj->Clear();
878    
879      //    if(sorted_tracks)sorted_tracks->Clear();
880      //    sorted_tracks.Clear();
881    
882      if(trk_nuc_obj)trk_nuc_obj->Clear();
883      if(trk_ext_obj)trk_ext_obj->Clear();
884      if(trk_ext_nuc_obj)trk_ext_nuc_obj->Clear();
885    
886      if(calo_nuc_obj)calo_nuc_obj->Clear();
887      if(calo_ext_obj)calo_ext_obj->Clear();
888      if(calo_ext_nuc_obj)calo_ext_nuc_obj->Clear();
889    
890      if(tof_nuc_obj)tof_nuc_obj->Clear();
891      if(tof_ext_obj)tof_ext_obj->Clear();
892      if(tof_ext_nuc_obj)tof_ext_nuc_obj->Clear();
893    
894      if(orb_nuc_obj)orb_nuc_obj->Clear();
895      if(orb_ext_obj)orb_ext_obj->Clear();
896      if(orb_ext_nuc_obj)orb_ext_nuc_obj->Clear();
897    
898      if(trk2_nuc_obj)trk2_nuc_obj->Clear();;
899      if( calo2_nuc_obj)calo2_nuc_obj->Clear();;
900      if(tof2_nuc_obj)tof2_nuc_obj->Clear();;
901      if(orb2_nuc_obj)orb2_nuc_obj->Clear();;
902    
903      if (tsorted)tsorted->Delete();
904      if (timage)timage->Delete();
905      if (text) text->Delete();
906    
907      if (tsorted_nuc)tsorted_nuc->Delete();
908      if (timage_nuc)timage_nuc->Delete();
909      if (text_nuc) text_nuc->Delete();
910    }
911    ;
912    
913  void PamLevel2::Reset(){  void PamLevel2::Reset() {
914      //
915      // First of all clear everything
916      //
917      Clear();
918      //
919      // close and reset chains and pointers
920      //
921      if (pam_tree) {
922      //      //
923      // First of all clear everything      // 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...
     //  
     Clear();  
924      //      //
925      // close and reset chains and pointers      TList *temp = pam_tree->GetListOfFriends();
926      //          TList *contents = new TList; // create chain friend list
927      if ( pam_tree ){      contents->SetOwner();
928          //      TIter next(temp);
929          // 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;
930          //      while ((questo = (TChain*) next())) {
931          TList *temp = pam_tree->GetListOfFriends();        TString name = questo->GetName();
932          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;  
         };  
         //  
933      };      };
     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;  
934      //      //
935      h0_obj    = 0;      // deleting the main chain
     trk0_obj  = 0;  
     calo0_obj  = 0;  
936      //      //
937      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;  
938      //      //
939      // Reset run pointers      // deleting the friends...
940      //      //
941      run_obj   = 0;//new GL_RUN();      TIter next2(contents);
942      soft_obj   = 0;// Emiliano      TChain *questa = 0;
943      irun = -1;      while ( (questa = (TChain*) next2()) ) {
944      irunt = -1;        TString name = questa->GetName();
945      runfirstentry = 0ULL;        questa->Delete();
946      runlastentry = 0ULL;            questa = NULL;
947      //      };
     totdltime[0] = 0LL;  
     totdltime[1] = 0LL;  
     totdltime[2] = 0LL;  
948      //      //
949  };    };
950      pam_tree = NULL;
951      //
952      if (run_tree)
953        run_tree->Delete();;
954      run_tree = NULL;
955      if (sel_tree)
956        sel_tree->Delete();;
957      sel_tree = NULL;
958      //
959      // Close file
960      //
961      if (l0_file)
962        l0_file->Close("R");
963      l0_file = NULL;
964      //
965      h0_obj = 0;
966      trk0_obj = 0;
967      calo0_obj = 0;
968      //
969      trk2_obj = 0;
970      trk1_obj = 0;
971      trkh_obj = 0;
972      calo1_obj = 0;
973      calo2_obj = 0;
974      tof2_obj = 0;
975      trig_obj = 0;
976      s4_obj = 0;
977      nd_obj = 0;
978      ac_obj = 0;
979      orb2_obj = 0;
980      gp_obj = 0;
981    
982      trk_ext_obj     = 0;
983      trk_ext_nuc_obj = 0;
984      trk_nuc_obj     = 0;
985      
986      calo_ext_obj     = 0;
987      calo_ext_nuc_obj = 0;
988      calo_nuc_obj     = 0;
989      
990      tof_ext_obj     = 0;
991      tof_ext_nuc_obj = 0;
992      tof_nuc_obj     = 0;
993      
994      orb_ext_obj     = 0;
995      orb_ext_nuc_obj = 0;
996      orb_nuc_obj     = 0;
997    
998      trk2_nuc_obj  = 0;
999      calo2_nuc_obj = 0;
1000      tof2_nuc_obj  = 0;
1001      orb2_nuc_obj  = 0;
1002    
1003      trk2_nuc_obj  = 0;
1004      calo2_nuc_obj = 0;
1005      tof2_nuc_obj  = 0;
1006      orb2_nuc_obj  = 0;
1007      //
1008      // Reset run pointers
1009      //
1010      run_obj = 0;//new GL_RUN();
1011      soft_obj = 0;// Emiliano
1012      irun = -1;
1013      irunt = -1;
1014      totrunentry = 0LL;
1015      totrunentrymax = 0LL;
1016      totrunentrymin = 0LL;
1017      runfirstentry = 0ULL;
1018      runlastentry = 0ULL;
1019      prevabstime = 0ULL;
1020      prevpktnum = 0;
1021      abstime = 0ULL;
1022      pktnum = 0;
1023      isFragment = false;
1024      //
1025      totdltime[0] = 0LL;
1026      totdltime[1] = 0LL;
1027      totdltime[2] = 0LL;
1028      //
1029    }
1030    ;
1031    
1032  Bool_t PamLevel2::IsGood(){  Bool_t PamLevel2::IsGood(Bool_t strict) {
1033      Bool_t goodev=true;    Bool_t goodev = true;
1034      if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false;    //
1035      if(calo2_obj && calo2_obj->good != 1) goodev = false;    if (calo2_obj && !calo2_obj->IsGood(strict))
1036      if(tof_obj && tof_obj->unpackError != 0) goodev = false;        goodev = false;
1037      if(trig_obj && trig_obj->unpackError != 0) goodev = false;    //
1038      if(s4_obj && s4_obj->unpackError != 0) goodev = false;      if (strict) {
1039      if(nd_obj && nd_obj->unpackError != 0) goodev = false;        if (trk2_obj && trk2_obj->UnpackError() != 0)
1040      if(ac_obj && ac_obj->unpackError != 255) goodev = false;          goodev = false;
1041      //  if(orb_obj)        if (tof2_obj && tof2_obj->unpackError != 0)
1042      return goodev;        goodev = false;
1043  };      if (trig_obj && trig_obj->unpackError != 0)
1044          goodev = false;
1045        if (s4_obj && s4_obj->unpackError != 0)
1046          goodev = false;
1047        if (nd_obj && nd_obj->unpackError != 0)
1048          goodev = false;
1049        if (ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0] >> 2) & 1) || ((ac_obj->status[1] >> 2) & 1)))
1050          goodev = false;
1051        //  if(orb2_obj)
1052      }
1053      else {
1054        if (nd_obj && nd_obj->unpackError != 0)
1055          goodev = false;
1056        if (ac_obj && (ac_obj->unpackError != 0 || ((ac_obj->status[0] >> 2) & 1) || ((ac_obj->status[1] >> 2) & 1)))
1057          goodev = false;
1058      };
1059      return (goodev);
1060    }
1061    ;
1062    
1063    void PamLevel2::SkipRunInfoUpdate(){
1064      printf("\n\n ******** WARNING ******** \n Skip DB connections, DO NOT USE PamLevel2::GetRunInfo() method! \n\n");
1065      fUpdateRunInfo = false;
1066      this->SetSELLI(2);
1067      printf(" ===============> W A R N I N G <================ \n");
1068      printf(" in case PamLevel2::CreateCloneTrees() will be called \n");
1069      printf(" it will be reverted to PadmeAmidala level2 structure , i.e. NO SELECTIONLIST WILL BE CREATED IN THE NEW LEVEL2 FILE! \n\n");
1070      if ( run_tree_clone ){
1071        printf(" ===============> W A R N I N G <================ \n");
1072        printf(" PamLevel2::SkipRunIndoUpdate or PamLevel2::NoDBconnections() has been called together with PamLevel2::CreateCloneTrees() \n");
1073        printf(" TO AVOID CRASHES call PamLevel2::CreateCloneTrees() after PamLevel2::SkipRunIndoUpdate or PamLevel2::NoDBconnections() \n");    
1074      };
1075    }
1076    
1077    void PamLevel2::SetMaxShift(Int_t sh){
1078      if ( sh >=  0 ){
1079        printf("PamLevel2::SetMaxShift(Int_t) --WARNING-- the default is optimized by checking the level2 file\n it is strongly suggested to let PamLevel2 choose the max shift!\n");
1080        maxshift = sh;
1081      } else {
1082        ULong64_t nev = GetEntries();
1083        ULong64_t runnev = 0ULL;
1084        for (Int_t r=0; r< run_tree->GetEntries();r++){
1085          run_tree->GetEntry(r);//update runinfo
1086          runnev += GetRunInfo()->NEVENTS;
1087        }
1088        maxshift = (Int_t)(runnev-nev) + 10; // +10 just to be conservative
1089        if ( (runnev-nev) == 0 ) isSync = true;
1090        if (DBG) printf("PamLevel2::SetMaxShift(Int_t_) - sh negative %i - nev is %lld runnnev is %lld so maxshift set to %i \n",sh,nev,runnev,maxshift);
1091        //    printf("PamLevel2::SetMaxShift(Int_t_) - sh negative %i - nev is %lld runnnev is %lld so maxshift set to %i \n",sh,nev,runnev,maxshift); // TOGLITOGLI
1092      }
1093    }
1094    
1095  //--------------------------------------  //--------------------------------------
1096  //  //
1097  //  //
1098  //--------------------------------------  //--------------------------------------
1099  void *PamLevel2::GetPointerTo(const char* c ){  void *PamLevel2::GetPointerTo(const char* c) {
1100    
1101      TString objname = c;    TString objname = c;
1102    
1103      if(!objname.CompareTo("TrkLevel1"))  {    if (!objname.CompareTo("TrkLevel1")) {
1104          if(!trk1_obj){      if (!trk1_obj) {
1105              trk1_obj  = new TrkLevel1();        trk1_obj = new TrkLevel1();
1106              trk1_obj->Set();        trk1_obj->Set();
1107          }      }
1108          return &trk1_obj;      return &trk1_obj;
1109      };    };
1110      if(!objname.CompareTo("TrkLevel2"))  {    if (!objname.CompareTo("TrkLevel2")) {
1111          if(!trk2_obj){        if (!trk2_obj) {
1112              trk2_obj  = new TrkLevel2();        trk2_obj = new TrkLevel2();
1113              trk2_obj->Set();        trk2_obj->Set();
1114          }      }
1115          return &trk2_obj;      return &trk2_obj;
1116      };    };
1117      if(!objname.CompareTo("TrkHough"))   {    if (!objname.CompareTo("TrkHough")) {
1118          if(!trkh_obj)  {      if (!trkh_obj) {
1119              trkh_obj  = new TrkHough();        trkh_obj = new TrkHough();
1120              trkh_obj->Set();        trkh_obj->Set();
1121          }      }
1122          return &trkh_obj;      return &trkh_obj;
1123      };    };
1124      if(!objname.CompareTo("CaloLevel1")) {    if (!objname.CompareTo("CaloLevel1")) {
1125          if(!calo1_obj) calo1_obj = new CaloLevel1();      if (!calo1_obj)
1126          return &calo1_obj;        calo1_obj = new CaloLevel1();
1127      };      return &calo1_obj;
1128      if(!objname.CompareTo("CaloLevel2")) {    };
1129          if(!calo2_obj){    if (!objname.CompareTo("CaloLevel2")) {
1130              calo2_obj = new CaloLevel2();      if (!calo2_obj) {
1131              calo2_obj->Set();        calo2_obj = new CaloLevel2();
1132          };        calo2_obj->Set();
1133          return &calo2_obj;      };
1134      };      return &calo2_obj;
1135      if(!objname.CompareTo("ToFLevel2"))  {    };
1136          if(!tof_obj){    if (!objname.CompareTo("ToFLevel2")) {
1137              tof_obj   = new ToFLevel2();      if (!tof2_obj) {
1138              tof_obj->Set();        tof2_obj = new ToFLevel2();
1139          }        tof2_obj->Set();
1140          return &tof_obj;      }
1141      };      return &tof2_obj;
1142      if(!objname.CompareTo("TrigLevel2")) {    };
1143          if(!trig_obj)  trig_obj  = new TrigLevel2();    if (!objname.CompareTo("TrigLevel2")) {
1144          return &trig_obj;      if (!trig_obj)
1145      };        trig_obj = new TrigLevel2();
1146      if(!objname.CompareTo("S4Level2"))   {      return &trig_obj;
1147          if(!s4_obj)    s4_obj    = new S4Level2();    };
1148          return &s4_obj;    if (!objname.CompareTo("S4Level2")) {
1149      };      if (!s4_obj)
1150      if(!objname.CompareTo("NDLevel2"))   {        s4_obj = new S4Level2();
1151          if(!nd_obj)    nd_obj    = new NDLevel2();      return &s4_obj;
1152          return &nd_obj;    };
1153      };    if (!objname.CompareTo("NDLevel2")) {
1154      if(!objname.CompareTo("AcLevel2"))   {      if (!nd_obj)
1155          if(!ac_obj)    ac_obj    = new AcLevel2();        nd_obj = new NDLevel2();
1156          return &ac_obj;      return &nd_obj;
1157      };    };
1158      if(!objname.CompareTo("OrbitalInfo")){    if (!objname.CompareTo("AcLevel2")) {
1159          if(!orb_obj)   orb_obj   = new OrbitalInfo();      if (!ac_obj)
1160          return &orb_obj;        ac_obj = new AcLevel2();
1161      };      return &ac_obj;
1162      if(!objname.CompareTo("GPamela")){    };
1163          if(!gp_obj)   gp_obj   = new GPamela();    if (!objname.CompareTo("OrbitalInfo")) {
1164          return &gp_obj;      if (!orb2_obj) {
1165      };        orb2_obj = new OrbitalInfo();
1166              orb2_obj->Set();
1167      if(!objname.CompareTo("RunInfo"))return &run_obj;      }
1168        return &orb2_obj;
1169      };
1170      //     if(!objname.CompareTo("OrbitalInfo")){
1171      //    if(!orb2_obj)   orb2_obj   = new OrbitalInfo();
1172      //    return &orb2_obj;
1173      //     };
1174      if (!objname.CompareTo("GPamela")) {
1175        if (!gp_obj)
1176          gp_obj = new GPamela();
1177        return &gp_obj;
1178      };
1179    
1180      if(!objname.CompareTo("SoftInfo"))return &soft_obj; // Emiliano    if (!objname.CompareTo("RunInfo"))
1181        return &run_obj;
1182    
1183      return NULL;    if (!objname.CompareTo("SoftInfo"))
1184  };      return &soft_obj; // Emiliano
1185    
1186      return NULL;
1187    }
1188    ;
1189  //--------------------------------------  //--------------------------------------
1190  //  //
1191  //  //
1192  //--------------------------------------  //--------------------------------------
1193  /**  /**
1194   * Retrieves the calorimeter track matching the seqno-th tracker stored track.   * Retrieves the calorimeter track matching the seqno-th tracker stored track.
1195   * (If seqno = -1 retrieves the self-trigger calorimeter track)   * (If seqno = -1 retrieves the self-trigger calorimeter track)
1196   */   */
1197  CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){  CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno) {
       
     if( !calo2_obj )return 0;  
1198    
1199      if( calo2_obj->CaloLevel2::ntrk()==0 ){    if (!calo2_obj)
1200          cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;      return 0;
1201          return NULL;  
1202      };    if (calo2_obj->CaloLevel2::ntrk() == 0) {
1203            cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo " << seqno
1204      CaloTrkVar *c = 0;          << " but no Calorimeter tracks are stored" << endl;
1205      Int_t it_calo=0;      return NULL;
1206          };
1207      do{  
1208          c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);    CaloTrkVar *c = 0;
1209          it_calo++;    Int_t it_calo = 0;
1210      } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());      
1211          do {
1212      if(!c || seqno != c->trkseqno){      c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo);
1213          c = 0;      it_calo++;
1214          if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;    } while (c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk());
1215      };  
1216      return c;    if (!c || seqno != c->trkseqno) {
1217            c = 0;
1218  };      if (seqno != -1)
1219          cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo " << seqno
1220              << " does not match Calorimeter stored tracks" << endl;
1221      };
1222      return c;
1223    
1224    }
1225    ;
1226  //--------------------------------------  //--------------------------------------
1227  //  //
1228  //  //
1229  //--------------------------------------  //--------------------------------------
1230  /**  /**
1231   * Retrieves the ToF track matching the seqno-th tracker stored track.   * Retrieves the ToF track matching the seqno-th tracker stored track.
1232   * (If seqno = -1 retrieves the tracker-independent tof track)   * (If seqno = -1 retrieves the tracker-independent tof track)
1233   */   */
1234  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){  ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno) {
1235            
1236      if( !tof_obj )return 0;    if (!tof2_obj)
1237        return 0;
1238      if( tof_obj->ToFLevel2::ntrk()==0 ){  
1239          cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;    if (tof2_obj->ToFLevel2::ntrk() == 0) {
1240          return NULL;      cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo " << seqno << " but no ToF tracks are stored"
1241      };          << endl;
1242            return NULL;
1243      ToFTrkVar *c = 0;    };
1244      Int_t it_tof=0;  
1245          ToFTrkVar *c = 0;
1246      do{    Int_t it_tof = 0;
1247          c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof);  
1248          it_tof++;    do {
1249      } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk());      c = tof2_obj->ToFLevel2::GetToFTrkVar(it_tof);
1250            it_tof++;
1251      if(!c || seqno != c->trkseqno){    } while (c && seqno != c->trkseqno && it_tof < tof2_obj->ToFLevel2::ntrk());
1252          c = 0;  
1253          if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;    if (!c || seqno != c->trkseqno) {
1254      };      c = 0;
1255      return c;      if (seqno != -1)
1256              cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo " << seqno
1257  };            << " does not match ToF stored tracks" << endl;
1258      };
1259      return c;
1260    
1261    }
1262    ;
1263    
1264  //--------------------------------------  //--------------------------------------
1265  //  //
1266  //  //
1267  //--------------------------------------  //--------------------------------------
1268  /**  /**
1269   * Retrieves the OrbitalInfo track matching the seqno-th tracker stored track.   * Retrieves the OrbitalInfo track matching the seqno-th tracker stored track.
1270   * (If seqno = -1 retrieves the tracker-independent tof related track)   * (If seqno = -1 retrieves the tracker-independent tof related track)
1271   */   */
1272  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno){  OrbitalInfoTrkVar *PamLevel2::GetOrbitalInfoStoredTrack(int seqno) {
1273            
1274      if( !orb_obj )return 0;    if (!orb2_obj)
1275        return 0;
1276      if( orb_obj->OrbitalInfo::ntrk()==0 ){  
1277          cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no OrbitalInfo tracks are stored"<<endl;    if (orb2_obj->OrbitalInfo::ntrk() == 0) {
1278          return NULL;      //       // TRICK BEGIN
1279      };      //       OrbitalInfoTrkVar  *r = new OrbitalInfoTrkVar(); // TEMPORARY TRICK
1280            //       Int_t nn = 0;
1281      OrbitalInfoTrkVar *c = 0;      //       TClonesArray &tor = *orb2_obj->OrbitalInfoTrk;
1282      Int_t it_tof=0;      //       for(Int_t nt=0; nt < tof2_obj->ToFLevel2::ntrk(); nt++){
1283            //  //
1284      do{      //  ToFTrkVar *ptt = tof2_obj->ToFLevel2::GetToFTrkVar(nt);
1285          c = orb_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);      //  if ( ptt->trkseqno != -1  ){
1286          it_tof++;      //    //
1287      } while( c && seqno != c->trkseqno && it_tof < orb_obj->OrbitalInfo::ntrk());            //    r->trkseqno = ptt->trkseqno;
1288            //    //
1289      if(!c || seqno != c->trkseqno){      //    r->Eij = 0;
1290          c = 0;      //    //
1291          if(seqno!=-1)cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match OrbitalInfo stored tracks"<<endl;      //    r->Sij = 0;
1292      };      //    //
1293      return c;      //    r->pitch = -1000.;
1294            //    //
1295  };      //    r->cutoff = -1000.;
1296        //    //
1297        //    new(tor[nn]) OrbitalInfoTrkVar(*r);
1298        //    nn++;
1299        //    //
1300        //    r->Clear();
1301        //    //
1302        //  };
1303        //       };
1304        //       delete r;
1305        //       OrbitalInfoTrkVar *c = 0;
1306        //       c = orb2_obj->OrbitalInfo::GetOrbitalInfoTrkVar(0);
1307        //       return c;
1308        //       //TRICK END
1309        cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo " << seqno
1310            << " but no OrbitalInfo tracks are stored" << endl;
1311        return NULL;
1312      };
1313    
1314      OrbitalInfoTrkVar *c = 0;
1315      Int_t it_tof = 0;
1316    
1317      do {
1318        c = orb2_obj->OrbitalInfo::GetOrbitalInfoTrkVar(it_tof);
1319        it_tof++;
1320      } while (c && seqno != c->trkseqno && it_tof < orb2_obj->OrbitalInfo::ntrk());
1321    
1322      if (!c || seqno != c->trkseqno) {
1323        c = 0;
1324        if (seqno != -1)
1325          cout << "PamLevel2::GetOrbitalInfoStoredTrack(int) : requested tracker SeqNo " << seqno
1326              << " does not match OrbitalInfo stored tracks" << endl;
1327      };
1328      return c;
1329    
1330    }
1331    ;
1332    
1333  //--------------------------------------  //--------------------------------------
1334  //  //
1335  //  //
1336  //--------------------------------------  //--------------------------------------
1337  /**  /**
1338   * 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.
1339   */   */
1340  PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){  PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t) {
       
     cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl;  
     cout <<"(if you use it, remember to delete the PamTrack object)"<<endl;  
1341    
1342      CaloTrkVar *c = 0;    cout << "PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** " << endl;
1343      ToFTrkVar  *o = 0;    cout << "(if you use it, remember to delete the PamTrack object)" << endl;
1344      OrbitalInfoTrkVar  *r = 0;  
1345          CaloTrkVar *c = 0;
1346      if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());    ToFTrkVar *o = 0;
1347      if(TOF) o = GetToFStoredTrack(t->GetSeqNo());    OrbitalInfoTrkVar *r = 0;
1348      if(ORB) r = GetOrbitalInfoStoredTrack(t->GetSeqNo());  
1349          if (CAL2)
1350  //    if(t && c && o)track = new PamTrack(t,c,o);      c = GetCaloStoredTrack(t->GetSeqNo());
1351      PamTrack *track = new PamTrack(t,c,o,r);    if (TOF)
1352            o = GetToFStoredTrack(t->GetSeqNo());
1353      return track;    if (ORB)
1354        r = GetOrbitalInfoStoredTrack(t->GetSeqNo());
1355  };  
1356      //    if(t && c && o)track = new PamTrack(t,c,o);
1357      PamTrack *track = new PamTrack(t, c, o, r);
1358    
1359      return track;
1360    
1361    }
1362    ;
1363  //--------------------------------------  //--------------------------------------
1364  //  //
1365  //  //
1366  //--------------------------------------  //--------------------------------------
1367  /**  /**
1368   * Retrieves the it-th stored track.   * Retrieves the it-th stored track.
1369   * It override TrkLevel2::GetTrack(int it).   * It override TrkLevel2::GetTrack(int it).
1370   * @param itrk Track number, ranging from 0 to GetNTracks().   * @param itrk Track number, ranging from 0 to GetNTracks().
1371   */   */
1372    
1373  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){  PamTrack* PamLevel2::GetStoredTrack(Int_t itrk) {
1374        
1375      cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl;    cout << "PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** " << endl;
1376      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
1377      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)"
1378      PamTrack *track = 0;        << endl;
1379          cout << "(if you use it, remember to delete the PamTrack object)" << endl;
1380      if( itrk >=0 && itrk < trk2_obj->TrkLevel2::ntrk() ){    PamTrack *track = 0;
1381            
1382          TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk);    if (itrk >= 0 && itrk < trk2_obj->TrkLevel2::ntrk()) {
1383          track = GetPamTrackAlong(t);  
1384                TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk);
1385                track = GetPamTrackAlong(t);
1386    
1387      }
1388      else {
1389        cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo " << itrk << " does not exist (GetNTracks() = "
1390            << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
1391      };
1392    
1393      return track;
1394    
     }else{  
         cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;  
     };  
       
     return track;  
       
1395  }  }
1396  //--------------------------------------  //--------------------------------------
1397  //  //
# Line 972  PamTrack* PamLevel2::GetStoredTrack(Int_ Line 1399  PamTrack* PamLevel2::GetStoredTrack(Int_
1399  /**  /**
1400   * Sort physical (tracker) tracks. Left here as backward compatibility method.   * Sort physical (tracker) tracks. Left here as backward compatibility method.
1401   **/   **/
1402  void PamLevel2::SortTracks(TString how){  void PamLevel2::SortTracks(TString how) {
1403      printf(" WARNING! obsolete, use SortTracks() and SetSortingMethod(TString) instead! \n Setting sorting method to %s \n",how.Data());    printf(
1404      howtosort = how;          " WARNING! obsolete, use SortTracks() and SetSortingMethod(TString) instead! \n Setting sorting method to %s \n",
1405      SortTracks();        how.Data());
1406  };    howtosort = how;
1407      SortTracks();
1408    }
1409    ;
1410    
1411  //  //
1412  //--------------------------------------  //--------------------------------------
# Line 984  void PamLevel2::SortTracks(TString how){ Line 1414  void PamLevel2::SortTracks(TString how){
1414   * Sort physical (tracker) tracks.   * Sort physical (tracker) tracks.
1415   * @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...).
1416   * Sorting cryteria:   * Sorting cryteria:
1417   * TRK: lower chi**2   * TRK: lower chi**2
1418   * CAL: lower Y spatial residual on the first calorimeter plane   * CAL: lower Y spatial residual on the first calorimeter plane
1419   * 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).
1420   * S1: (ask Emiliano)   * S1: (ask Emiliano)
1421   * S2: (ask Emiliano)   * S2: (ask Emiliano)
1422   * S3: (ask Emiliano)   * S3: (ask Emiliano)
1423   * GP: more GP hits   * GP: more GP hits
1424   * The default sorting cryterium is "TOF+CAL".   * The default sorting cryterium is "TOF+CAL".
1425   *   *
1426   * 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).
1427   */   */
1428  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();  
1429    
1430      // create TCloneArrays to store tracks and its images    //Check if the current event has already been sorted
1431      if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks());    if (issorted && lastsorted == GetReadEntry()) {
1432        return;
1433      }
1434      //Reset the sort flags, just in case something will go wrong...
1435      issorted = false;
1436      lastsorted = -1;
1437    
1438      TString how = howtosort;
1439    
1440      //  cout <<" PamLevel2::SortTracks(TString how) "<<endl;
1441      if (!trk2_obj) {
1442        cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!";
1443        return;
1444      };
1445      //Save current Object count
1446      Int_t ObjectNumber = TProcessID::GetObjectCount();
1447    
1448      // create TCloneArrays to store tracks and its images
1449      if (!tsorted)
1450        tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1451      tsorted->Delete();
1452      TClonesArray &ttsorted = *tsorted;
1453    
1454      if (!timage)
1455        timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1456      timage->Delete();
1457      TClonesArray &ttimage = *timage;
1458    
1459    
1460    
1461      //--------------------------------------------------
1462      // retrieve sorting method
1463      //--------------------------------------------------
1464      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
1465      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
1466      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
1467      Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
1468      Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
1469      Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
1470      Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
1471    
1472      if (use_TOF) {
1473        use_S1 = true;
1474        use_S2 = true;
1475        use_S3 = true;
1476      };
1477      if (!CAL2 && use_CAL)
1478        use_CAL = false;
1479      if (!TOF) {
1480        use_TOF = false;
1481        use_S1 = false;
1482        use_S2 = false;
1483        use_S3 = false;
1484      }
1485      if (!GP) {
1486        use_GP = false;
1487      }
1488    
1489      if (!TRK2) {
1490        cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
1491        return;
1492      };
1493    
1494      //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
1495    
1496    
1497      //--------------------------------------------------
1498      // loop over "physical" tracks sorted by the tracker
1499      //--------------------------------------------------
1500      for (Int_t i = 0; i < trk2_obj->TrkLevel2::GetNTracks(); i++) {
1501    
1502        TrkTrack *ts = 0;
1503        CaloTrkVar *cs = 0;
1504        ToFTrkVar *os = 0;
1505        OrbitalInfoTrkVar *rs = 0;
1506    
1507        // get tracker tracks
1508        TrkTrack *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker
1509        CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo());
1510        ToFTrkVar *op = GetToFStoredTrack(tp->GetSeqNo());
1511        OrbitalInfoTrkVar *rp = GetOrbitalInfoStoredTrack(tp->GetSeqNo());
1512    
1513        TrkTrack *ti = 0; //tracker (image)
1514        CaloTrkVar *ci = 0;
1515        ToFTrkVar *oi = 0;
1516        OrbitalInfoTrkVar *ri = 0;
1517        //  cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
1518        // if track has an image, check image selection
1519    
1520        Int_t tp_score = 0; //main track sorted by the tracker
1521        Int_t ti_score = 0; //image track
1522        Int_t totp_score = 0; //main track sorted by the tracker
1523        Int_t toti_score = 0; //image track
1524    
1525        if (tp->HasImage()) {
1526    
1527          ti = trk2_obj->TrkLevel2::GetTrackImage(i); //tracker (image)
1528          ci = GetCaloStoredTrack(ti->GetSeqNo());
1529          oi = GetToFStoredTrack(ti->GetSeqNo());
1530          ri = GetOrbitalInfoStoredTrack(ti->GetSeqNo());
1531    
1532          //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
1533    
1534          //assign starting scores
1535          tp_score = 0; //main track sorted by the tracker
1536          ti_score = 0; //image track
1537    
1538          // -----------------------------------------------------------------------------------------
1539          // *****************************************************************************************
1540          // -----------------------------------------------------------------------------------------
1541          // calorimeter check
1542          // -----------------------------------------------------------------------------------------
1543          if (use_CAL && !calo2_obj) {
1544            cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but CaloLevel2 not loaded !!!";
1545            return;
1546          };
1547          if (use_CAL && !cp && ci) {
1548            ti_score++;
1549            toti_score++;
1550          };
1551          if (use_CAL && cp && !ci) {
1552            tp_score++;
1553            totp_score++;
1554          };
1555          if (use_CAL && cp && ci && true) {
1556    
1557            if (cp->npresh > ci->npresh && true) {
1558              tp_score++;
1559              totp_score++;
1560            };
1561            if (cp->npresh < ci->npresh && true) {
1562              ti_score++;
1563              toti_score++;
1564            };
1565    
1566            //      cout << "CALO "<<tp_score<<ti_score<<endl;
1567    
1568          };
1569          // -----------------------------------------------------------------------------------------
1570          // *****************************************************************************************
1571          // -----------------------------------------------------------------------------------------
1572          // TOF check
1573          // -----------------------------------------------------------------------------------------
1574          // check the number of hit pmts along the track
1575          // on S12 S21 and S32, where paddles are parallel to Y axis
1576          if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof2_obj) {
1577            cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";
1578            return;
1579          };
1580          //
1581          if ((use_TOF || use_S1 || use_S2 || use_S3) && !op && oi) {
1582            ti_score++;
1583            toti_score++;
1584          };
1585          if ((use_TOF || use_S1 || use_S2 || use_S3) && op && !oi) {
1586            tp_score++;
1587            totp_score++;
1588          };
1589          if ((use_TOF || use_S1 || use_S2 || use_S3) && op && oi) {
1590            //
1591            Float_t sen = 0.;
1592            for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1593              Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1594              if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
1595                sen += (op->dedx).At(ih);
1596            };
1597            for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1598              Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1599              if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
1600                sen += (oi->dedx).At(ih);
1601            };
1602            //
1603            if (sen >= sortthr && false) { // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
1604              //printf(" IS A NUCLEUS! en = %f \n",sen);
1605              //
1606              // is a nucleus use a different algorithm
1607              //
1608              Int_t nz = 6;
1609              Float_t zin[6]; // << define TOF z-coordinates
1610              for (Int_t ip = 0; ip < nz; ip++)
1611                zin[ip] = tof2_obj->ToFLevel2::GetZTOF(tof2_obj->ToFLevel2::GetToFPlaneID(ip)); // << read ToF plane z-coordinates
1612              Trajectory *tr = new Trajectory(nz, zin);
1613              //
1614              Int_t nphit_p = 0;
1615              Int_t nphit_i = 0;
1616              Float_t enhit_p = 0.;
1617              Float_t enhit_i = 0.;
1618              //
1619              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1620                Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1621                if (pl == 1 || pl == 2 || pl == 5) {
1622                  nphit_p++;
1623                  enhit_p += (op->dedx).At(ih);
1624                };
1625              };
1626              //
1627              tp->DoTrack2(tr);
1628              //
1629              if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
1630                for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1631                  Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1632                  if (pl == 0) {
1633                    nphit_p++;
1634                    enhit_p += (op->dedx).At(ih);
1635                  };
1636                };
1637              };
1638              if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
1639                for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1640                  Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1641                  if (pl == 3) {
1642                    nphit_p++;
1643                    enhit_p += (op->dedx).At(ih);
1644                  };
1645                };
1646              };
1647              if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
1648                for (Int_t ih = 0; ih < op->npmtadc; ih++) {
1649                  Int_t pl = tof2_obj->GetPlaneIndex((op->pmtadc).At(ih));
1650                  if (pl == 4) {
1651                    nphit_p++;
1652                    enhit_p += (op->dedx).At(ih);
1653                  };
1654                };
1655              };
1656    
1657              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1658                Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1659                if (pl == 1 || pl == 2 || pl == 5) {
1660                  nphit_i++;
1661                  enhit_i += (op->dedx).At(ih);
1662                };
1663              };
1664              //
1665              ti->DoTrack2(tr);
1666              //
1667              if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
1668                for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1669                  Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1670                  if (pl == 0) {
1671                    nphit_i++;
1672                    enhit_i += (op->dedx).At(ih);
1673                  };
1674                };
1675              };
1676              if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
1677                for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1678                  Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1679                  if (pl == 3) {
1680                    nphit_i++;
1681                    enhit_i += (op->dedx).At(ih);
1682                  };
1683                };
1684              };
1685              if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
1686                for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
1687                  Int_t pl = tof2_obj->GetPlaneIndex((oi->pmtadc).At(ih));
1688                  if (pl == 4) {
1689                    nphit_i++;
1690                    enhit_i += (op->dedx).At(ih);
1691                  };
1692                };
1693              };
1694    
1695              if ((use_TOF || use_S1 || use_S2 || use_S3) && (nphit_p + nphit_i) != 0 && true) {
1696    
1697                //      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);
1698                //      printf(" score p %i score i %i \n",tp_score,ti_score);
1699                //            if( enhit_p > enhit_i ) tp_score++;
1700                //            if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
1701                if (nphit_p > nphit_i)
1702                  tp_score++;
1703                if (nphit_p < nphit_i)
1704                  ti_score++;
1705                if (nphit_p == nphit_i) {
1706                  if (enhit_p > enhit_i)
1707                    tp_score++;
1708                  else
1709                    ti_score++;
1710                };
1711                //      printf(" dopo score p %i score i %i \n",tp_score,ti_score);
1712              };
1713              delete tr;
1714              //
1715            }
1716            else {
1717              // -------------
1718              // NOT a NUCLEUS
1719              // -------------
1720              //printf(" NOT a NUCLEUS! en = %f \n",sen);
1721    
1722              Int_t nphit_p = 0;
1723              Int_t nphit_i = 0;
1724    
1725              /*                            cout << "track: npmtadc "<< op->npmtadc << endl;
1726               cout << "track: npmttdc "<< op->npmttdc << endl;
1727               cout << "image: npmtadc "<< oi->npmtadc << endl;
1728               cout << "image: npmttdc "<< oi->npmttdc << endl;*/
1729    
1730              //      for (Int_t ih=0; ih < op->npmtadc; ih++){
1731              //        Int_t pl = tof2_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
1732              //        if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
1733              //      };
1734    
1735              //      for (Int_t ih=0; ih < oi->npmtadc; ih++){
1736              //        Int_t pl = tof2_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
1737              //        if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
1738              //      };
1739              // --- modified to count tdc signals (more efficient?)
1740              // --- and to implement check on tdcflag
1741              for (Int_t ih = 0; ih < op->npmttdc; ih++) {
1742                Int_t pl = tof2_obj->GetPlaneIndex((op->pmttdc).At(ih));
1743                //      if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
1744                if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
1745                    || (use_S3 && (pl == 4 || pl == 5))) {
1746                  if ((op->tdcflag).At(ih) == 0)
1747                    nphit_p++;
1748                };
1749              };
1750    
1751              for (Int_t ih = 0; ih < oi->npmttdc; ih++) {
1752                Int_t pl = tof2_obj->GetPlaneIndex((oi->pmttdc).At(ih));
1753                //      if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;
1754                if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
1755                    || (use_S3 && (pl == 4 || pl == 5))) {
1756                  if ((oi->tdcflag).At(ih) == 0)
1757                    nphit_i++;
1758                };
1759              };
1760    
1761              if ((nphit_p + nphit_i) != 0 && true) {
1762    
1763                if (nphit_p != nphit_i) {
1764                  totp_score += nphit_p;
1765                  toti_score += nphit_i;
1766                  tp_score += nphit_p;
1767                  ti_score += nphit_i;
1768                };
1769                //      if     ( nphit_p > nphit_i) tp_score+=nphit_p;
1770                //      else if( nphit_p < nphit_i) ti_score+=nphit_i;
1771                //      else ;//niente
1772              };
1773            };
1774            //      cout << "TOF "<<tp_score<<ti_score<<endl;
1775          };
1776    
1777          //      if(tp_score == ti_score) use_TRK = true;
1778    
1779    
1780          // -----------------------------------------------------------------------------------------
1781          // *****************************************************************************************
1782          // -----------------------------------------------------------------------------------------
1783          // tracker check
1784          // -----------------------------------------------------------------------------------------
1785          // chi**2 difference is not always large enough to distinguish among
1786          // the real track and its image.
1787          // Tracker check will be applied always when calorimeter and tof information is ambiguous.
1788          // *** MODIFIED ON AUGUST 2007 ***
1789          if (use_TRK) {
1790            //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
1791            //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
1792    
1793            // CHECK 1 : number of points along X
1794            if (tp->GetNX() >= ti->GetNX()) {
1795              tp_score++;
1796              totp_score++;
1797            };
1798            if (tp->GetNX() <= ti->GetNX()) {
1799              ti_score++;
1800              toti_score++;
1801            };
1802            // CHECK 2 : number of points along Y
1803            if (tp->GetNY() >= ti->GetNY()) {
1804              tp_score++;
1805              totp_score++;
1806            };
1807            if (tp->GetNY() <= ti->GetNY()) {
1808              ti_score++;
1809              toti_score++;
1810            };
1811    
1812            //      cout << "TRK "<<tp_score<<ti_score<<endl;
1813          };
1814    
1815          // -----------------------------------------------------------------------------------------
1816          // *****************************************************************************************
1817          // -----------------------------------------------------------------------------------------
1818          // GPamela check
1819          // -----------------------------------------------------------------------------------------
1820    
1821          //---------------------------------------------------
1822          // count the number of GP hits
1823          //---------------------------------------------------
1824          if (use_GP) {
1825            int ngphits_p = 0;
1826            int ngphits_i = 0;
1827            float toll = 0.02; //200 micron
1828            for (int ih = 0; ih < GetGPamela()->Nthspe; ih++) {
1829              int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
1830              if (tp && tp->YGood(ip) && fabs(tp->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
1831                ngphits_p++;
1832              if (ti && ti->YGood(ip) && fabs(ti->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
1833                ngphits_i++;
1834            }
1835            if (ngphits_p > ngphits_i && true) {
1836              tp_score++;
1837              totp_score++;
1838            }
1839            if (ngphits_p < ngphits_i && true) {
1840              ti_score++;
1841              toti_score++;
1842            }
1843          }
1844    
1845          // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1846          // the winner is....
1847          // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1848          if (tp_score > ti_score) {
1849    
1850          }
1851          else if (tp_score < ti_score) {
1852    
1853            ts = ti;//its image!!
1854            cs = ci;
1855            os = oi;
1856            rs = ri;
1857            Int_t totis = toti_score;
1858    
1859            ti = tp;//its image!!
1860            ci = cp;
1861            oi = op;
1862            ri = rp;
1863    
1864            tp = ts;//its image!!
1865            cp = cs;
1866            op = os;
1867            rp = rs;
1868    
1869            toti_score = totp_score;
1870            totp_score = totis;
1871    
1872          }
1873          else {
1874    
1875            //      cout << "Warning - track image ambiguity not solved" << endl;
1876    
1877          };
1878    
1879        }
1880        else {
1881          totp_score = 1;
1882          toti_score = 0;
1883    
1884          //            ts = tp;
1885          //            cs = cp;
1886          //            os = op;
1887        };
1888    
1889        //  cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
1890        //  sorted_tracks->Add(ts);//save the track in the sorted array
1891        //  sorted_tracks.Add(ts);//save the track in the sorted array
1892        //  sorted_tracks.Add(tp);//save the track in the sorted array
1893        //  cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
1894        //  cout<<"o "<<tp<<endl;
1895        //  cout<<"o "<<cp<<endl;
1896        //  cout<<"o "<<op<<endl;
1897    
1898        new (ttsorted[i]) PamTrack(tp, cp, op, rp);
1899        new (ttimage[i]) PamTrack(ti, ci, oi, ri);
1900    
1901        ((PamTrack*) (ttsorted[i]))->SetPScore(totp_score);
1902        ((PamTrack*) (ttsorted[i]))->SetIScore(toti_score);
1903        ((PamTrack*) (ttimage[i]))->SetPScore(totp_score);
1904        ((PamTrack*) (ttimage[i]))->SetIScore(toti_score);
1905      };
1906    
1907      if (tsorted->GetEntries() != trk2_obj->GetNTracks()) {
1908        cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() " << tsorted->GetEntries()
1909            << " != trk2_obj->GetNTracks() = " << trk2_obj->GetNTracks() << endl;
1910      tsorted->Delete();      tsorted->Delete();
1911      TClonesArray &ttsorted = *tsorted;      tsorted = 0;
   
     if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks());  
1912      timage->Delete();      timage->Delete();
1913      TClonesArray &ttimage = *timage;      timage = 0;
1914      }
1915    
1916      //Restore Object count
1917      //To save space in the table keeping track of all referenced objects
1918      //We reset the object count to what it was at the beginning of the event.
1919      TProcessID::SetObjectCount(ObjectNumber);
1920    
1921      //Everything went fine so the current event can be tagged as sorted
1922      issorted = true;
1923      lastsorted = GetReadEntry();
1924    
1925    }
1926    ;
1927    //
1928    //--------------------------------------
1929    /**
1930     * Sort physical (tracker) tracks.
1931     * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...).
1932     * Sorting cryteria:
1933     * TRK: lower chi**2
1934     * CAL: lower Y spatial residual on the first calorimeter plane
1935     * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis).
1936     * S1: (ask Emiliano)
1937     * S2: (ask Emiliano)
1938     * S3: (ask Emiliano)
1939     * GP: more GP hits
1940     * The default sorting cryterium is "TOF+CAL".
1941     *
1942     * 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).
1943     *
1944     * New version, with handling of extended tracks and nuclei tracks.
1945     */
1946    void PamLevel2::SortTracksNew() {
1947    
1948      //--------------------------------------------------    //--------------------------------------------------
1949      // retrieve sorting method    //Check if the current event has already been sorted
1950      //--------------------------------------------------    //--------------------------------------------------
1951      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);    if (issorted_new && lastsorted_new == GetReadEntry()) {
1952      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);        return; //already done for this event
1953      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;  
     }  
1954    
     if( !TRK2 ){  
         cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;  
         return;  
     };  
1955    
1956      //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;  //  cout << "SORT" << endl;
     
1957    
1958      //--------------------------------------------------    //Reset the sort flags, just in case something will go wrong...
1959      // loop over "physical" tracks sorted by the tracker    issorted_new = false;
1960      //--------------------------------------------------    lastsorted_new = -1;
     for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){  
           
         TrkTrack   *ts = 0;  
         CaloTrkVar *cs = 0;  
         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  
1961    
1962          if(tp->HasImage()){    //--------------------------------------------------
1963                  // set input variables
1964              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;  
1965    
1966              //assign starting scores    TString how = howtosort;
1967              tp_score = 0;  //main track sorted by the tracker    //Save current Object count
1968              ti_score = 0;  //image track    Int_t ObjectNumber = TProcessID::GetObjectCount();
               
             // -----------------------------------------------------------------------------------------  
             // *****************************************************************************************  
             // -----------------------------------------------------------------------------------------  
             // 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){  
1969    
                   
                 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);  
                             };  
                         };  
                     };            
1970    
                   
                     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);  
1971    
                     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++ ;  
                 };  
1972    
1973                  //      cout << "TRK "<<tp_score<<ti_score<<endl;    TrkLevel2  * trk2 ;
1974              };    CaloLevel2 * calo2;
1975                  ToFLevel2  * tof2  ;
1976      OrbitalInfo  * orb2 ;
1977      
1978      TClonesArray * trkext ;
1979      TClonesArray * caloext;
1980      TClonesArray * tofext ;
1981      TClonesArray * orbext ;
1982    
             // -----------------------------------------------------------------------------------------  
             // *****************************************************************************************  
             // -----------------------------------------------------------------------------------------  
             // 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++ ;                    
                 }  
             }  
1983    
1984    //   cout << "trk2_obj" << trk2_obj<< endl;
1985    //   cout << "trk2_nuc_obj" << trk2_nuc_obj<< endl;
1986    //   cout << " trk_ext_obj "<<trk_ext_obj<< endl;
1987    //   cout << " trk_ext_nuc_obj "<<trk_ext_nuc_obj<< endl;
1988    
1989      //-----------------------------------------------------------
1990      // create/reset TCloneArrays to store tracks and their images
1991      //-----------------------------------------------------------
1992      
1993      // main tracks from standard alg
1994      if (!tsorted)
1995          tsorted = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
1996      tsorted->Delete();
1997      // track images from standard alg
1998      if (!timage)
1999          timage = new TClonesArray("PamTrack", trk2_obj->GetNTracks());
2000      timage->Delete();
2001      // tracks from extended algorythm
2002      if(EXT && !text)
2003          text = new TClonesArray("PamTrack",trk_ext_obj->GetEntries());
2004      if(text)text->Delete();
2005    
2006      //-----------------------------------------------------------
2007      // create/reset TCloneArrays to store tracks and their images
2008      //-----------------------------------------------------------
2009      if(NUC){
2010      // main tracks from standard alg
2011          if (!tsorted_nuc)
2012              tsorted_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2013          tsorted_nuc->Delete();
2014          // track images from standard alg
2015          if (!timage_nuc)
2016              timage_nuc = new TClonesArray("PamTrack", trk2_nuc_obj->GetNTracks());
2017          timage_nuc->Delete();
2018          // tracks from extended algorythm
2019          if(EXT && !text_nuc)
2020              text_nuc = new TClonesArray("PamTrack",trk_ext_nuc_obj->GetEntries());
2021          if(text_nuc)text_nuc->Delete();
2022      }
2023      //--------------------------------------------------
2024      // retrieve sorting method
2025      //--------------------------------------------------
2026      Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
2027      Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
2028      Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
2029      Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase);
2030      Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase);
2031      Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase);
2032      Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase);
2033    
2034      if (use_TOF) {
2035        use_S1 = true;
2036        use_S2 = true;
2037        use_S3 = true;
2038      };
2039      if (!CAL2 && use_CAL)
2040        use_CAL = false;
2041      if (!TOF) {
2042        use_TOF = false;
2043        use_S1 = false;
2044        use_S2 = false;
2045        use_S3 = false;
2046      }
2047      if (!GP) {
2048        use_GP = false;
2049      }
2050    
2051      if (!TRK2) {
2052        cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
2053        return;
2054      };
2055    
2056    
2057      ///////////////////////////////////////////////////////////////////////////////////
2058      //
2059      //   sort tracks and fill PamTrack arrays
2060      //
2061      ///////////////////////////////////////////////////////////////////////////////////
2062      for(int doit=0; doit<2; doit++){
2063    
2064    //       cout << "doit "<<doit<<endl;
2065    
2066    
2067          if(doit == 0){
2068    
2069              trk2  = trk2_obj;
2070              calo2 = calo2_obj;
2071              tof2  = tof2_obj;
2072              orb2  = orb2_obj;
2073          
2074              trkext = trk_ext_obj;
2075              caloext = calo_ext_obj;
2076              tofext = tof_ext_obj;
2077              orbext = orb_ext_obj;
2078        
2079          
2080          
2081          
2082    
2083              // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*        }else if (doit == 1){
             // 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;  
2084    
2085                  toti_score = totp_score;            if(!NUC)break;
                 totp_score = totis;  
2086    
2087                          
2088              }else {            trk2  = trk2_nuc_obj;
2089              calo2 = calo2_nuc_obj;
2090              tof2  = tof2_nuc_obj;
2091              orb2  = orb2_nuc_obj;
2092          
2093              trkext = trk_ext_nuc_obj;
2094              caloext = calo_ext_nuc_obj;
2095              tofext = tof_ext_nuc_obj;
2096              orbext = orb_ext_nuc_obj;
2097          
2098          
2099          
2100    
2101  //      cout << "Warning - track image ambiguity not solved" << endl;        }
2102    
2103              };  //       cout << "trk2" << trk2<<endl;
2104                //       cout << "calo2" << calo2<<endl;
2105          }else{  //       cout << "tof2" << tof2<<endl;
2106              totp_score = 1;  //       cout << "orb2" << orb2<<endl;
2107              toti_score = 0;  //       cout << "trkext" <<trkext <<endl;
2108    //       cout << "tofext" << tofext<<endl;
2109    //       cout << "caloext" << caloext<<endl;
2110    //       cout << "orbext" << orbext<<endl;
2111    
2112          TClonesArray &ttext    = (doit==0 ? *text : *text_nuc);
2113          TClonesArray &ttimage  = (doit==0 ? *timage : *timage_nuc);
2114          TClonesArray &ttsorted = (doit==0 ? *tsorted : *tsorted_nuc);
2115      
2116    //       cout << "tsorted + timage "<<doit<<endl;
2117    
2118          //--------------------------------------------------
2119          // loop over "physical" tracks sorted by the tracker
2120          //--------------------------------------------------
2121          for (Int_t i = 0; i < trk2->TrkLevel2::GetNTracks(); i++) {
2122    
2123              TrkTrack *ts = 0;
2124              CaloTrkVar *cs = 0;
2125              ToFTrkVar *os = 0;
2126              OrbitalInfoTrkVar *rs = 0;
2127    
2128              // get tracker tracks
2129              TrkTrack *tp = trk2->GetTrack(i); //tracker
2130              CaloTrkVar *cp = calo2->GetCaloStoredTrack(tp->GetSeqNo());
2131              ToFTrkVar *op = tof2->GetToFStoredTrack(tp->GetSeqNo());
2132              OrbitalInfoTrkVar *rp = orb2->GetOrbitalInfoStoredTrack(tp->GetSeqNo());
2133    
2134              TrkTrack *ti = 0; //tracker (image)
2135              CaloTrkVar *ci = 0;
2136              ToFTrkVar *oi = 0;
2137              OrbitalInfoTrkVar *ri = 0;
2138              //    cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
2139              // if track has an image, check image selection
2140    
2141              Int_t tp_score = 0; //main track sorted by the tracker
2142              Int_t ti_score = 0; //image track
2143              Int_t totp_score = 0; //main track sorted by the tracker
2144              Int_t toti_score = 0; //image track
2145    
2146              if (tp->HasImage()) {
2147    
2148                  ti = trk2->GetTrackImage(i); //tracker (image)
2149                  ci = calo2->GetCaloStoredTrack(ti->GetSeqNo());
2150                  oi = tof2->GetToFStoredTrack(ti->GetSeqNo());
2151                  ri = orb2->GetOrbitalInfoStoredTrack(ti->GetSeqNo());
2152    
2153                  //            cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
2154    
2155                  //assign starting scores
2156                  tp_score = 0; //main track sorted by the tracker
2157                  ti_score = 0; //image track
2158    
2159                  // -----------------------------------------------------------------------------------------
2160                  // *****************************************************************************************
2161                  // -----------------------------------------------------------------------------------------
2162                  // calorimeter check
2163                  // -----------------------------------------------------------------------------------------
2164                  if (use_CAL && !calo2) {
2165                      cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but CaloLevel2 not loaded !!!";
2166                      return;
2167                  };
2168                  if (use_CAL && !cp && ci) {
2169                      ti_score++;
2170                      toti_score++;
2171                  };
2172                  if (use_CAL && cp && !ci) {
2173                      tp_score++;
2174                      totp_score++;
2175                  };
2176                  if (use_CAL && cp && ci && true) {
2177    
2178                      if (cp->npresh > ci->npresh && true) {
2179                          tp_score++;
2180                          totp_score++;
2181                      };
2182                      if (cp->npresh < ci->npresh && true) {
2183                          ti_score++;
2184                          toti_score++;
2185                      };
2186    
2187                      //    cout << "CALO "<<tp_score<<ti_score<<endl;
2188    
2189                  };
2190                  // -----------------------------------------------------------------------------------------
2191                  // *****************************************************************************************
2192                  // -----------------------------------------------------------------------------------------
2193                  // TOF check
2194                  // -----------------------------------------------------------------------------------------
2195                  // check the number of hit pmts along the track
2196                  // on S12 S21 and S32, where paddles are parallel to Y axis
2197                  if ((use_TOF || use_S1 || use_S2 || use_S3) && !tof2) {
2198                      cout << "void PamLevel2::SortTracks(): howtosort= " << how << " but ToFLevel2 not loaded !!!";
2199                      return;
2200                  };
2201                  //
2202                  if ((use_TOF || use_S1 || use_S2 || use_S3) && !op && oi) {
2203                      ti_score++;
2204                      toti_score++;
2205                  };
2206                  if ((use_TOF || use_S1 || use_S2 || use_S3) && op && !oi) {
2207                      tp_score++;
2208                      totp_score++;
2209                  };
2210                  if ((use_TOF || use_S1 || use_S2 || use_S3) && op && oi) {
2211                      //
2212                      Float_t sen = 0.;
2213                      for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2214                          Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2215                          if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
2216                              sen += (op->dedx).At(ih);
2217                      };
2218                      for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2219                          Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2220                          if (pl == 2 || pl == 3 || pl == 4 || pl == 5)
2221                              sen += (oi->dedx).At(ih);
2222                      };
2223                      //
2224                      if (sen >= sortthr && false) { // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!)
2225                          //printf(" IS A NUCLEUS! en = %f \n",sen);
2226                          //
2227                          // is a nucleus use a different algorithm
2228                          //
2229                          Int_t nz = 6;
2230                          Float_t zin[6]; // << define TOF z-coordinates
2231                          for (Int_t ip = 0; ip < nz; ip++)
2232                              zin[ip] = tof2->GetZTOF(tof2->GetToFPlaneID(ip)); // << read ToF plane z-coordinates
2233                          Trajectory *tr = new Trajectory(nz, zin);
2234                          //
2235                          Int_t nphit_p = 0;
2236                          Int_t nphit_i = 0;
2237                          Float_t enhit_p = 0.;
2238                          Float_t enhit_i = 0.;
2239                          //
2240                          for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2241                              Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2242                              if (pl == 1 || pl == 2 || pl == 5) {
2243                                  nphit_p++;
2244                                  enhit_p += (op->dedx).At(ih);
2245                              };
2246                          };
2247                          //
2248                          tp->DoTrack2(tr);
2249                          //
2250                          if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
2251                              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2252                                  Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2253                                  if (pl == 0) {
2254                                      nphit_p++;
2255                                      enhit_p += (op->dedx).At(ih);
2256                                  };
2257                              };
2258                          };
2259                          if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
2260                              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2261                                  Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2262                                  if (pl == 3) {
2263                                      nphit_p++;
2264                                      enhit_p += (op->dedx).At(ih);
2265                                  };
2266                              };
2267                          };
2268                          if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
2269                              for (Int_t ih = 0; ih < op->npmtadc; ih++) {
2270                                  Int_t pl = tof2->GetPlaneIndex((op->pmtadc).At(ih));
2271                                  if (pl == 4) {
2272                                      nphit_p++;
2273                                      enhit_p += (op->dedx).At(ih);
2274                                  };
2275                              };
2276                          };
2277    
2278                          for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2279                              Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2280                              if (pl == 1 || pl == 2 || pl == 5) {
2281                                  nphit_i++;
2282                                  enhit_i += (op->dedx).At(ih);
2283                              };
2284                          };
2285                          //
2286                          ti->DoTrack2(tr);
2287                          //
2288                          if (fabs(tr->y[0] - oi->ytofpos[0]) < 2.) {
2289                              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2290                                  Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2291                                  if (pl == 0) {
2292                                      nphit_i++;
2293                                      enhit_i += (op->dedx).At(ih);
2294                                  };
2295                              };
2296                          };
2297                          if (fabs(tr->y[3] - oi->ytofpos[1]) < 2.) {
2298                              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2299                                  Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2300                                  if (pl == 3) {
2301                                      nphit_i++;
2302                                      enhit_i += (op->dedx).At(ih);
2303                                  };
2304                              };
2305                          };
2306                          if (fabs(tr->y[4] - oi->ytofpos[2]) < 2.) {
2307                              for (Int_t ih = 0; ih < oi->npmtadc; ih++) {
2308                                  Int_t pl = tof2->GetPlaneIndex((oi->pmtadc).At(ih));
2309                                  if (pl == 4) {
2310                                      nphit_i++;
2311                                      enhit_i += (op->dedx).At(ih);
2312                                  };
2313                              };
2314                          };
2315    
2316                          if ((use_TOF || use_S1 || use_S2 || use_S3) && (nphit_p + nphit_i) != 0 && true) {
2317    
2318                              //        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);
2319                              //        printf(" score p %i score i %i \n",tp_score,ti_score);
2320                              //              if( enhit_p > enhit_i ) tp_score++;
2321                              //              if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++;
2322                              if (nphit_p > nphit_i)
2323                                  tp_score++;
2324                              if (nphit_p < nphit_i)
2325                                  ti_score++;
2326                              if (nphit_p == nphit_i) {
2327                                  if (enhit_p > enhit_i)
2328                                      tp_score++;
2329                                  else
2330                                      ti_score++;
2331                              };
2332                              //        printf(" dopo score p %i score i %i \n",tp_score,ti_score);
2333                          };
2334                          delete tr;
2335                          //
2336                      }
2337                      else {
2338                          // -------------
2339                          // NOT a NUCLEUS
2340                          // -------------
2341                          //printf(" NOT a NUCLEUS! en = %f \n",sen);
2342    
2343                          Int_t nphit_p = 0;
2344                          Int_t nphit_i = 0;
2345    
2346                          /*                                cout << "track: npmtadc "<< op->npmtadc << endl;
2347                            cout << "track: npmttdc "<< op->npmttdc << endl;
2348                            cout << "image: npmtadc "<< oi->npmtadc << endl;
2349                            cout << "image: npmttdc "<< oi->npmttdc << endl;*/
2350    
2351                          //          for (Int_t ih=0; ih < op->npmtadc; ih++){
2352                          //            Int_t pl = tof2_obj->GetPlaneIndex( (op->pmtadc).At(ih) );
2353                          //            if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
2354                          //          };
2355    
2356                          //          for (Int_t ih=0; ih < oi->npmtadc; ih++){
2357                          //            Int_t pl = tof2_obj->GetPlaneIndex( (oi->pmtadc).At(ih) );
2358                          //            if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
2359                          //          };
2360                          // --- modified to count tdc signals (more efficient?)
2361                          // --- and to implement check on tdcflag
2362                          for (Int_t ih = 0; ih < op->npmttdc; ih++) {
2363                              Int_t pl = tof2->GetPlaneIndex((op->pmttdc).At(ih));
2364                              //        if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++;
2365                              if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
2366                                  || (use_S3 && (pl == 4 || pl == 5))) {
2367                                  if ((op->tdcflag).At(ih) == 0)
2368                                      nphit_p++;
2369                              };
2370                          };
2371    
2372                          for (Int_t ih = 0; ih < oi->npmttdc; ih++) {
2373                              Int_t pl = tof2->GetPlaneIndex((oi->pmttdc).At(ih));
2374                              //        if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++;
2375                              if ((use_S1 && (pl == 0 || pl == 1)) || (use_S2 && (pl == 2 || pl == 3))
2376                                  || (use_S3 && (pl == 4 || pl == 5))) {
2377                                  if ((oi->tdcflag).At(ih) == 0)
2378                                      nphit_i++;
2379                              };
2380                          };
2381    
2382                          if ((nphit_p + nphit_i) != 0 && true) {
2383    
2384                              if (nphit_p != nphit_i) {
2385                                  totp_score += nphit_p;
2386                                  toti_score += nphit_i;
2387                                  tp_score += nphit_p;
2388                                  ti_score += nphit_i;
2389                              };
2390                              //        if     ( nphit_p > nphit_i) tp_score+=nphit_p;
2391                              //        else if( nphit_p < nphit_i) ti_score+=nphit_i;
2392                              //        else ;//niente
2393                          };
2394                      };
2395                      //    cout << "TOF "<<tp_score<<ti_score<<endl;
2396                  };
2397    
2398                  //      if(tp_score == ti_score) use_TRK = true;
2399    
2400    
2401                  // -----------------------------------------------------------------------------------------
2402                  // *****************************************************************************************
2403                  // -----------------------------------------------------------------------------------------
2404                  // tracker check
2405                  // -----------------------------------------------------------------------------------------
2406                  // chi**2 difference is not always large enough to distinguish among
2407                  // the real track and its image.
2408                  // Tracker check will be applied always when calorimeter and tof information is ambiguous.
2409                  // *** MODIFIED ON AUGUST 2007 ***
2410                  if (use_TRK) {
2411                      //    if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
2412                      //    else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
2413    
2414                      // CHECK 1 : number of points along X
2415                      if (tp->GetNX() >= ti->GetNX()) {
2416                          tp_score++;
2417                          totp_score++;
2418                      };
2419                      if (tp->GetNX() <= ti->GetNX()) {
2420                          ti_score++;
2421                          toti_score++;
2422                      };
2423                      // CHECK 2 : number of points along Y
2424                      if (tp->GetNY() >= ti->GetNY()) {
2425                          tp_score++;
2426                          totp_score++;
2427                      };
2428                      if (tp->GetNY() <= ti->GetNY()) {
2429                          ti_score++;
2430                          toti_score++;
2431                      };
2432    
2433                      //    cout << "TRK "<<tp_score<<ti_score<<endl;
2434                  };
2435    
2436                  // -----------------------------------------------------------------------------------------
2437                  // *****************************************************************************************
2438                  // -----------------------------------------------------------------------------------------
2439                  // GPamela check
2440                  // -----------------------------------------------------------------------------------------
2441    
2442                  //---------------------------------------------------
2443                  // count the number of GP hits
2444                  //---------------------------------------------------
2445                  if (use_GP) {
2446                      int ngphits_p = 0;
2447                      int ngphits_i = 0;
2448                      float toll = 0.02; //200 micron
2449                      for (int ih = 0; ih < GetGPamela()->Nthspe; ih++) {
2450                          int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1;
2451                          if (tp && tp->YGood(ip) && fabs(tp->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
2452                              ngphits_p++;
2453                          if (ti && ti->YGood(ip) && fabs(ti->ym[ip] - GetGPamela()->Yavspe[ih]) < toll && true)
2454                              ngphits_i++;
2455                      }
2456                      if (ngphits_p > ngphits_i && true) {
2457                          tp_score++;
2458                          totp_score++;
2459                      }
2460                      if (ngphits_p < ngphits_i && true) {
2461                          ti_score++;
2462                          toti_score++;
2463                      }
2464                  }
2465    
2466                  // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2467                  // the winner is....
2468                  // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2469                  if (tp_score > ti_score) {
2470    
2471                  }
2472                  else if (tp_score < ti_score) {
2473    
2474                      ts = ti;//its image!!
2475                      cs = ci;
2476                      os = oi;
2477                      rs = ri;
2478                      Int_t totis = toti_score;
2479    
2480                      ti = tp;//its image!!
2481                      ci = cp;
2482                      oi = op;
2483                      ri = rp;
2484    
2485                      tp = ts;//its image!!
2486                      cp = cs;
2487                      op = os;
2488                      rp = rs;
2489    
2490                      toti_score = totp_score;
2491                      totp_score = totis;
2492    
2493                  }
2494                  else {
2495    
2496                      //    cout << "Warning - track image ambiguity not solved" << endl;
2497    
2498                  };
2499    
2500              }
2501              else {
2502                  totp_score = 1;
2503                  toti_score = 0;
2504    
2505                  //            ts = tp;
2506                  //            cs = cp;
2507                  //            os = op;
2508              };
2509    
2510              //    cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
2511              //    sorted_tracks->Add(ts);//save the track in the sorted array
2512              //    sorted_tracks.Add(ts);//save the track in the sorted array
2513              //    sorted_tracks.Add(tp);//save the track in the sorted array
2514              //    cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
2515              //    cout<<"o "<<tp<<endl;
2516              //    cout<<"o "<<cp<<endl;
2517              //    cout<<"o "<<op<<endl;
2518    
2519              new (ttsorted[i]) PamTrack(tp, cp, op, rp);
2520              new (ttimage[i]) PamTrack(ti, ci, oi, ri);
2521    
2522              ((PamTrack*) (ttsorted[i]))->SetPScore(totp_score);
2523              ((PamTrack*) (ttsorted[i]))->SetIScore(toti_score);
2524              ((PamTrack*) (ttimage[i]))->SetPScore(totp_score);
2525              ((PamTrack*) (ttimage[i]))->SetIScore(toti_score);
2526          };
2527    
2528    
2529    
2530    
2531    
2532    //   if (tsorted->GetEntries() != trk2->GetNTracks()) {
2533    //     cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() " << tsorted->GetEntries()
2534    //         << " != trk2->GetNTracks() = " << trk2->GetNTracks() << endl;
2535    //     tsorted->Delete();
2536    //     tsorted = 0;
2537    //     timage->Delete();
2538    //     timage = 0;
2539    //   }
2540    
2541    
2542    //       cout << "text "<<doit<<endl;
2543    
2544    
2545          //--------------------------------------------------
2546          // fill array with extended tracks (this is easy...)
2547          //--------------------------------------------------
2548          if(EXT){
2549              for(int it=0; it<trkext->GetEntries(); it++){
2550                  
2551                  new (ttext[it]) PamTrack((ExtTrack*)(*trkext)[it], (CaloTrkVar*)(*caloext)[it], (ToFTrkVar*)(*tofext)[it], (OrbitalInfoTrkVar*)(*orbext)[it]);
2552                  
2553              }
2554          }
2555                
             //      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);  
     };  
2556    
     if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){  
         cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl;  
         tsorted->Delete(); tsorted=0;  
         timage->Delete(); timage=0;      
     }  
2557    
2558      //Restore Object count    };
2559      //To save space in the table keeping track of all referenced objects  
2560      //We reset the object count to what it was at the beginning of the event.  
2561      TProcessID::SetObjectCount(ObjectNumber);    //Restore Object count
2562          //To save space in the table keeping track of all referenced objects
2563      //We reset the object count to what it was at the beginning of the event.
2564      TProcessID::SetObjectCount(ObjectNumber);
2565    
2566      //Everything went fine so the current event can be tagged as sorted
2567      issorted_new = true;
2568      lastsorted_new = GetReadEntry();
2569    
2570    //   cout << " tsorted "<< tsorted << " "<<(tsorted ? tsorted->GetEntries() : 0)<<endl;
2571    //   cout << " timage  "<< timage  << " "<<(timage  ? timage->GetEntries() : 0)<<endl;
2572    //   cout << " text    "<< text    << " "<<(text    ? text->GetEntries() : 0)<<endl;
2573    
2574    
2575  };  };
2576  //--------------------------------------  //--------------------------------------
2577  //  //
# Line 1496  void PamLevel2::SortTracks(){ Line 2580  void PamLevel2::SortTracks(){
2580  /**  /**
2581   * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.   * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.
2582   * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.   * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.
2583   */   /*
2584    
2585  // TRefArray *PamLevel2::GetTracks(){  // TRefArray *PamLevel2::GetTracks(){
2586    
2587  // //  *-*-*-*-*-*-*-*-*-*-*-*-*  // //  *-*-*-*-*-*-*-*-*-*-*-*-*
# Line 1505  void PamLevel2::SortTracks(){ Line 2590  void PamLevel2::SortTracks(){
2590    
2591  // //   return  sorted_tracks;  // //   return  sorted_tracks;
2592  //     return &sorted_tracks;  //     return &sorted_tracks;
2593        
2594  //  };  //  };
 TClonesArray *PamLevel2::GetTracks(){  
2595    
 //  *-*-*-*-*-*-*-*-*-*-*-*-*  
     SortTracks();  
 //  *-*-*-*-*-*-*-*-*-*-*-*-*  
2596    
     return tsorted;  
       
 };  
2597  //--------------------------------------  //--------------------------------------
2598  //  //
2599  //  //
2600  //--------------------------------------  //--------------------------------------
2601  /**  /**
2602   * Retrieves the it-th Pamela "physical" track.   * Retrieves the it-th Pamela "physical" track.
2603   * It override TrkLevel2::GetTrack(int it).   * It override TrkLevel2::GetTrack(int it).
2604   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
2605   */   */
2606  PamTrack *PamLevel2::GetTrack(int it){  PamTrack *PamLevel2::GetTrack(int it) {
2607    
2608  //    if(!trk2_obj) return 0;    PamTrack *track = NULL;
           
 // //  *-*-*-*+-*-*-*-*-*-*-*-*-*  
 //     SortTracks("+CAL+TOF");  
 // //  *-*-*-*-*-*-*-*-*-*-*-*-*  
 // //    if(!sorted_tracks)return 0;  
 //     if(sorted_tracks.IsEmpty())return 0;  
2609    
2610  //     PamTrack *track = 0;    //  *-*-*-*-*-*-*-*-*-*-*-*-*
2611          SortTracks();
2612  //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() && it<sorted_tracks.GetEntriesFast() ){        //  *-*-*-*-*-*-*-*-*-*-*-*-*
2613  //      TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);    if (!tsorted)
2614  //      track = GetPamTrackAlong(t);      return track;
2615  //     }else{    if (!tsorted->GetEntries())
2616  //      cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;      return track;
2617  //     };  
2618        
2619  //     return track;    if (it >= 0 && it < trk2_obj->TrkLevel2::GetNTracks()) {
2620        track = (PamTrack*)((*tsorted)[it]);
2621      }
2622      else {
2623        cout << "PamLevel2::GetTrack(int) : tracker track SeqNo " << it << " does not exist (GetNTracks() = "
2624            << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
2625      };
2626    
2627      return track;
2628    
2629  //    cout << "PamLevel2::GetTrack(int it) "<<endl;  };
2630  //  *-*-*-*-*-*-*-*-*-*-*-*-*  
2631      SortTracks();  //PamTrack *PamLevel2::GetTrack(int it) { return GetTrack(it,trkAlg); };
2632  //  *-*-*-*-*-*-*-*-*-*-*-*-*  
2633      if(!tsorted)return 0;  /**
2634      if(!tsorted->GetEntries())return 0;   * Retrieves the it-th Pamela "physical" track.
2635     * It override TrkLevel2::GetTrack(int it).
2636     * @param it Track number, ranging from 0 to GetNTracks().
2637     * @param alg Algorythm, see SetTrakingAlgorythm(char *alg) for explanation.
2638     */
2639    PamTrack *PamLevel2::GetTrack(int it, char* alg) {
2640    
2641      PamTrack *track = 0;      TString s(alg);
2642        if(!s.CompareTo("") ||!s.CompareTo("STD") )return GetTrack(it); //old algorythm
2643    
2644    
2645        SortTracksNew();
2646        // >> fill tsorted, timage and text
2647    
2648        if ( ( !s.Contains("EXTF", TString::kIgnoreCase) || !EXT )){ //not forced exteded-alg requested (or exteded-data missing)
2649    
2650            if( s.Contains("NUC")){
2651                if(
2652                    tsorted_nuc &&
2653                    it < tsorted_nuc->GetEntries() &&                             //enough tracks found
2654                    it >= 0 &&                                                //valid index
2655                    true) return (PamTrack*)((*tsorted_nuc)[it]);                 //ok return the track
2656            }else{
2657                if(
2658                    tsorted &&
2659                    it < tsorted->GetEntries() &&                             //enough tracks found
2660                    it >= 0 &&                                                //valid index
2661                    true )return (PamTrack*)((*tsorted)[it]);                 //ok return the track
2662            }
2663    
2664        }
2665            
2666      if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks()){  
2667  //      TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it);      /////////////////////////////////////////////////////////////////////////
2668  //      track = GetPamTrackAlong(t);      /// if requested get track from extended algorythm output
2669          TClonesArray &t = *(tsorted);      /////////////////////////////////////////////////////////////////////////
2670          track = (PamTrack*)t[it];      
2671        if(s.Contains("EXT", TString::kIgnoreCase) && EXT){//if exteded-alg requested
2672                    
2673      }else{          if(s.Contains("NUC")){
2674          cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;              if(
2675                    text_nuc &&
2676                    it < text_nuc->GetEntries() &&                             //enough tracks found
2677                    it >= 0 &&                                                //valid index
2678                    true) return (PamTrack*)((*text_nuc)[it]);
2679            }else{
2680                if(
2681                    text &&
2682                    it < text->GetEntries() &&                             //enough tracks found
2683                    it >= 0 &&                                                //valid index
2684                    true) return (PamTrack*)((*text)[it]);
2685            }
2686    
2687      };      };
2688            
     return track;  
2689            
2690  };      
2691        return NULL;
2692    
2693    }
2694    ;
2695    TClonesArray *PamLevel2::GetTracks() {
2696    
2697      //  *-*-*-*-*-*-*-*-*-*-*-*-*
2698      SortTracks();
2699      //  *-*-*-*-*-*-*-*-*-*-*-*-*
2700    
2701      return tsorted;
2702    
2703    }
2704    ;
2705    Int_t  PamLevel2::GetNTracks(char* alg) {
2706    
2707    
2708    //    cout << " trk_nuc_obj->GetEntries() "<<trk_nuc_obj->GetEntries()<<" trk2_nuc_obj->GetNTracks() "<<trk2_nuc_obj->GetNTracks()<<endl;
2709    
2710        TString s(alg);
2711    
2712        if(!s.CompareTo("") || !s.CompareTo("STD"))return trk2_obj->TrkLevel2::GetNTracks(); //standard algorythm
2713            
2714        if(s.Contains("EXTF", TString::kIgnoreCase) && EXT){
2715            if(s.Contains("NUC", TString::kIgnoreCase) && NUC)return trk_ext_nuc_obj->GetEntries();//ok
2716            return trk_ext_obj->GetEntries();//ok
2717        }
2718        if( s.Contains("EXT", TString::kIgnoreCase) && EXT) {
2719            if(s.Contains("NUC", TString::kIgnoreCase) && NUC)
2720                return (trk2_nuc_obj->TrkLevel2::GetNTracks() ?  trk2_nuc_obj->TrkLevel2::GetNTracks() :  trk_ext_nuc_obj->GetEntries() );  
2721            return (trk2_obj->TrkLevel2::GetNTracks() ?  trk2_obj->TrkLevel2::GetNTracks() :  trk_ext_obj->GetEntries() );
2722        }
2723        if(s.Contains("NUC", TString::kIgnoreCase) && NUC )
2724            return trk2_nuc_obj->TrkLevel2::GetNTracks();
2725        
2726        return 0;
2727    
2728    }
2729    
2730    
2731  //--------------------------------------  //--------------------------------------
2732  //  //
2733  //  //
2734  //--------------------------------------  //--------------------------------------
2735  /**  /**
2736   * 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().
2737   * @param it Track number, ranging from 0 to GetNTracks().   * @param it Track number, ranging from 0 to GetNTracks().
2738   */   */
2739  PamTrack *PamLevel2::GetTrackImage(int it){  PamTrack *PamLevel2::GetTrackImage(int it) {
2740    
2741  //  *-*-*-*-*-*-*-*-*-*-*-*-*    //  *-*-*-*-*-*-*-*-*-*-*-*-*
2742      SortTracks();    SortTracks();
2743  //  *-*-*-*-*-*-*-*-*-*-*-*-*    //  *-*-*-*-*-*-*-*-*-*-*-*-*
2744      if(!timage)return 0;    if (!timage)
2745      if(!timage->GetEntries())return 0;      return 0;
2746          if (!timage->GetEntries())
2747      PamTrack *image = 0;      return 0;
2748        
2749      if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){    PamTrack *image = 0;
2750          TClonesArray &t = *(tsorted);  
2751          PamTrack *temp = (PamTrack*)t[it];    if (it >= 0 && it < trk2_obj->TrkLevel2::GetNTracks()) {
2752          if( temp->GetTrkTrack()->HasImage() ){      TClonesArray &t = *(tsorted);
2753              TClonesArray &t = *(timage);      PamTrack *temp = (PamTrack*) t[it];
2754              image = (PamTrack*)t[it];      if (temp->GetTrkTrack()->HasImage()) {
2755          TClonesArray & t = *(timage);
2756          image = (PamTrack*) t[it];
2757        }
2758        else {
2759          //            cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
2760        };
2761      }
2762      else {
2763        cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo " << it << " does not exist (GetNTracks() = "
2764            << trk2_obj->TrkLevel2::GetNTracks() << ")" << endl;
2765      };
2766    
2767      return image;
2768    }
2769    /**
2770     * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().
2771     * @param it Track number, ranging from 0 to GetNTracks().
2772     * @param alg Algorythm, see SetTrakingAlgorythm(char *alg) for explanation.
2773     */
2774    PamTrack *PamLevel2::GetTrackImage(int it, char* alg) {
2775    
2776        TString s(alg);
2777        if(!s.CompareTo("") || !s.CompareTo("STD"))return GetTrack(it); //old algorythm
2778    
2779    
2780        SortTracksNew();
2781        // >> fill tsorted, timage and text
2782    
2783        if ( ( !s.Contains("EXTF", TString::kIgnoreCase) || !EXT )){ //not forced exteded-alg requested (or exteded-data missing)
2784    
2785            if( s.Contains("NUC")){
2786                if(
2787                    tsorted_nuc &&
2788                    it < tsorted_nuc->GetEntries() &&                             //enough tracks found
2789                    it >= 0 &&                                                //valid index
2790                    true){
2791                    TClonesArray &t = *(tsorted_nuc);
2792                    PamTrack *temp = (PamTrack*) t[it];
2793                    if (temp->GetTrkTrack()->HasImage()) {
2794                        return (PamTrack*)((*timage_nuc)[it]);                 //ok return the track
2795                    }
2796                    
2797                }
2798          }else{          }else{
2799  //          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;              if(
2800          };                  tsorted &&
2801      }else{                  it < tsorted->GetEntries() &&                             //enough tracks found
2802          cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl;                  it >= 0 &&                                                //valid index
2803      };                  true ){
2804                        TClonesArray &t = *(tsorted);
2805      return image;                  PamTrack *temp = (PamTrack*) t[it];
2806                    if (temp->GetTrkTrack()->HasImage()) {              
2807                        return (PamTrack*)((*timage)[it]);                 //ok return the track
2808                    }
2809                }
2810            }
2811    
2812        }
2813          
2814        return NULL;
2815    
2816  }  }
2817    ;
2818    
2819  //--------------------------------------  //--------------------------------------
2820  //  //
# Line 1613  PamTrack *PamLevel2::GetTrackImage(int i Line 2826  PamTrack *PamLevel2::GetTrackImage(int i
2826   * @param detlist String to select trees to be included   * @param detlist String to select trees to be included
2827   * @return Pointer to a TTree   * @return Pointer to a TTree
2828   */   */
2829  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){  TTree *PamLevel2::GetPamTree(TFile *f, TString detlist) {
2830    
2831      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {    if (detlist.Contains("+AUTO", TString::kIgnoreCase)) {
2832          cout << "+AUTO"<<endl;      cout << "+AUTO" << endl;
2833          GetWhichTrees(f);      GetWhichTrees(f);
2834      };    };
2835      SetWhichTrees(detlist);    SetWhichTrees(detlist);
2836    
2837      if ( pam_tree ){    if (pam_tree) {
2838          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 ");
2839          return pam_tree;      return pam_tree;
2840      };    };
2841      //    //
2842    
2843      cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;    cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte " << endl;
2844    
2845  //    SetWhichTrees(detlist);    //    SetWhichTrees(detlist);
2846    
2847      TTree *Trout =0;    TTree *Trout = 0;
2848    
2849      TString fname = f->GetName();    TString fname = f->GetName();
2850      if(!CheckLevel2File(fname))return NULL;    if (!CheckLevel2File(fname))
2851        return NULL;
2852    
2853  //    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)cout<<">>> Found selection-list <<<"<<endl;  
   
     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;  
     };  
2854    
2855      // ToF        cout << "GetPamTree(TFile*,TString): detector list --> ";
2856      TTree *O = (TTree*)f->Get("ToF");    if (TRK1)
2857      if(O && TOF) {      cout << "TRK1 ";
2858          O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));    if (TRK2)
2859          cout << "ToF          : set branch address ToFLevel2"<<endl;      cout << "TRK2 ";
2860          if(!Trout)Trout=O;    if (TRKh)
2861          else Trout->AddFriend(O);      cout << "TRKH ";
2862      }else{    if (CAL1)
2863          cout << "ToF         : missing tree"<<endl;      cout << "CAL1 ";
2864      };    if (CAL2)
2865      // Trigger      cout << "CAL2 ";
2866      TTree *R = (TTree*)f->Get("Trigger");    if (TOF)
2867      if(R && TRG) {      cout << "TOF ";
2868          R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));    if (TRG)
2869          cout << "Trigger      : set branch address TrigLevel2"<<endl;      cout << "TRG ";
2870          if(!Trout)Trout=R;    if (AC)
2871          else Trout->AddFriend(R);      cout << "AC ";
2872      }else{    if (ND)
2873          cout << "Trigger      : missing tree"<<endl;      cout << "ND ";
2874      };    if (S4)
2875      // S4      cout << "S4 ";
2876      TTree *S = (TTree*)f->Get("S4");    if (ORB)
2877      if(S && S4) {      cout << "ORB ";
2878          S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));    if (GP)
2879          cout << "S4           : set branch address S4Level2"<<endl;      cout << "GP ";
2880          if(!Trout)Trout=S;    cout << endl;
2881          else Trout->AddFriend(S);    if (SELLI && SELLI != 2)
2882      }else{      cout << ">>> Found selection-list <<<" << endl; //EMILIANO
2883          cout << "S4           : missing tree"<<endl;  
2884      };    f->cd();
2885      // Neutron Detector  
2886      TTree *N = (TTree*)f->Get("NeutronD");    // Tracker
2887      if(N && ND) {    TTree *T = (TTree*) f->Get("Tracker");
2888          N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));    if (T && (TRK2 || TRK1 || TRKh)) {
2889          cout << "NeutronD     : set branch address NDLevel2"<<endl;      if (TRK2)
2890          if(!Trout)Trout=N;        T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
2891          else Trout->AddFriend(N);      //  else    T->SetBranchStatus("TrkLevel2",0,found);
2892      }else{      if (TRK2)
2893          cout << "NeutronD     : missing tree"<<endl;        cout << "Tracker      : set branch address TrkLevel2" << endl;
2894      };      if (TRK1)
2895      // Anticounters        T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
2896      TTree *A = (TTree*)f->Get("Anticounter");      //  else    T->SetBranchStatus("TrkLevel1",0,found);
2897      if(A && AC) {      if (TRK1)
2898          A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));        cout << "Tracker      : set branch address TrkLevel1" << endl;
2899          cout << "Anticounter  : set branch address AcLevel2"<<endl;      if (TRKh)
2900          if(!Trout)Trout=A;        T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
2901          else Trout->AddFriend(A);      //  else    T->SetBranchStatus("TrkHough",0,found);
2902      }else{      if (TRKh)
2903          cout << "Anticounter  : missing tree"<<endl;        cout << "Tracker      : set branch address TrkHough" << endl;
2904      };      if (!Trout)
2905      // Orbital Info        Trout = T;
2906      TTree *B = (TTree*)f->Get("OrbitalInfo");      else
2907      if(B && ORB) {          Trout->AddFriend(T);
2908          B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));    }
2909          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;    else {
2910          if(!Trout)Trout=B;      cout << "Tracker      : missing tree" << endl;
2911          else Trout->AddFriend(B);    };
2912      }else{    // Calorimeter
2913          cout << "OrbitalInfo  : missing tree"<<endl;    TTree *C = (TTree*) f->Get("Calorimeter");
2914      };    if (C && (CAL2 || CAL1)) {
2915        if (CAL2)
2916          C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
2917        //  else    C->SetBranchStatus("CaloLevel2",0,found);
2918        if (CAL2)
2919          cout << "Calorimeter  : set branch address CaloLevel2" << endl;
2920        if (CAL1)
2921          C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
2922        //  else    C->SetBranchStatus("CaloLevel1",0,found);
2923        if (CAL1)
2924          cout << "Calorimeter  : set branch address CaloLevel1" << endl;
2925        if (!Trout)
2926          Trout = C;
2927        else
2928          Trout->AddFriend(C);
2929      }
2930      else {
2931        cout << "Calorimeter  : missing tree" << endl;
2932      };
2933    
2934      // ToF
2935      TTree *O = (TTree*) f->Get("ToF");
2936      if (O && TOF) {
2937        O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
2938        cout << "ToF          : set branch address ToFLevel2" << endl;
2939        if (!Trout)
2940          Trout = O;
2941        else
2942          Trout->AddFriend(O);
2943      }
2944      else {
2945        cout << "ToF         : missing tree" << endl;
2946      };
2947      // Trigger
2948      TTree *R = (TTree*) f->Get("Trigger");
2949      if (R && TRG) {
2950        R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
2951        cout << "Trigger      : set branch address TrigLevel2" << endl;
2952        if (!Trout)
2953          Trout = R;
2954        else
2955          Trout->AddFriend(R);
2956      }
2957      else {
2958        cout << "Trigger      : missing tree" << endl;
2959      };
2960      // S4
2961      TTree *S = (TTree*) f->Get("S4");
2962      if (S && S4) {
2963        S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
2964        cout << "S4           : set branch address S4Level2" << endl;
2965        if (!Trout)
2966          Trout = S;
2967        else
2968          Trout->AddFriend(S);
2969      }
2970      else {
2971        cout << "S4           : missing tree" << endl;
2972      };
2973      // Neutron Detector
2974      TTree *N = (TTree*) f->Get("NeutronD");
2975      if (N && ND) {
2976        N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
2977        cout << "NeutronD     : set branch address NDLevel2" << endl;
2978        if (!Trout)
2979          Trout = N;
2980        else
2981          Trout->AddFriend(N);
2982      }
2983      else {
2984        cout << "NeutronD     : missing tree" << endl;
2985      };
2986      // Anticounters
2987      TTree *A = (TTree*) f->Get("Anticounter");
2988      if (A && AC) {
2989        A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
2990        cout << "Anticounter  : set branch address AcLevel2" << endl;
2991        if (!Trout)
2992          Trout = A;
2993        else
2994          Trout->AddFriend(A);
2995      }
2996      else {
2997        cout << "Anticounter  : missing tree" << endl;
2998      };
2999      // Orbital Info
3000      TTree *B = (TTree*) f->Get("OrbitalInfo");
3001      if (B && ORB) {
3002        B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
3003        cout << "OrbitalInfo  : set branch address OrbitalInfo" << endl;
3004        if (!Trout)
3005          Trout = B;
3006        else
3007          Trout->AddFriend(B);
3008      }
3009      else {
3010        cout << "OrbitalInfo  : missing tree" << endl;
3011      };
3012    
3013      // GPamela
3014      TTree *G = (TTree*) f->Get("h20");
3015      if (G && GP) {
3016        if (!gp_obj)
3017          gp_obj = new GPamela();
3018        //      ------------------------------------
3019        //      ATTENZIONE!!!
3020        //      non so per quale arcano motivo,
3021        //      per l'albero di gpamela il branch address lo devo settare
3022        //      DOPO aver fatto friend
3023        //      FGRRRVZZZZUTSALKJMSLKJ!!!
3024        //      ------------------------------------
3025        //  gp_obj->SetBranchAddress(G); //ho dovuto fare in maniera diversa dagli altri
3026        //  cout << "h20          : set branch address GPamela "<<endl;
3027        if (!Trout)
3028          Trout = G;
3029        else
3030          Trout->AddFriend(G);
3031      }
3032      else {
3033        //  cout << "h20          : missing tree"<<endl;
3034      };
3035    
3036      TTree *L = (TTree*) f->Get("SelectionList");
3037      if (L && SELLI == 1) {
3038        cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemented!!!!" << endl;
3039        sel_tree = 0;
3040      }
3041      else {
3042        cout << "SelectionList  : missing tree" << endl;
3043      };
3044    
3045      cout << endl << " Number of entries: " << Trout->GetEntries() << endl << endl;
3046    
3047      //      ------------------------------------
3048      //      ATTENZIONE!!!
3049      //      non so per quale arcano motivo,
3050      //      per l'albero di gpamela il branch address lo devo settare
3051      //      DOPO aver fatto friend
3052      //      FGRRRVZZZZUTSALKJMSLKJ!!!
3053      //      ------------------------------------
3054      if (G && GP) {
3055        gp_obj->SetBranchAddress(Trout); //ho dovuto fare in maniera diversa dagli altri
3056        cout << "h20          : set branch address GPamela " << endl;
3057      }
3058      else {
3059        cout << "h20          : missing tree" << endl;
3060      };
3061    
3062      // GPamela    pam_tree = (TChain*) Trout;
     TTree *G = (TTree*)f->Get("h20");  
     if(G && GP) {  
         if(!gp_obj)gp_obj=new GPamela();  
 //      ------------------------------------  
 //      ATTENZIONE!!!  
 //      non so per quale arcano motivo,  
 //      per l'albero di gpamela il branch address lo devo settare  
 //      DOPO aver fatto friend  
 //      FGRRRVZZZZUTSALKJMSLKJ!!!  
 //      ------------------------------------  
 //      gp_obj->SetBranchAddress(G); //ho dovuto fare in maniera diversa dagli altri  
 //      cout << "h20          : set branch address GPamela "<<endl;  
         if(!Trout)Trout=G;  
         else Trout->AddFriend(G);  
     }else{  
 //      cout << "h20          : missing tree"<<endl;  
     };  
3063    
3064      return Trout;
3065    
     TTree *L = (TTree*)f->Get("SelectionList");  
     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;  
   
 //      ------------------------------------  
 //      ATTENZIONE!!!  
 //      non so per quale arcano motivo,  
 //      per l'albero di gpamela il branch address lo devo settare  
 //      DOPO aver fatto friend  
 //      FGRRRVZZZZUTSALKJMSLKJ!!!  
 //      ------------------------------------  
     if(G && GP) {        
         gp_obj->SetBranchAddress(Trout); //ho dovuto fare in maniera diversa dagli altri  
         cout << "h20          : set branch address GPamela "<<endl;  
     }else{  
         cout << "h20          : missing tree"<<endl;  
     };  
   
     pam_tree = (TChain*)Trout;  
       
     return Trout;  
       
3066  }  }
3067  //--------------------------------------  //--------------------------------------
3068  //  //
# Line 1809  TTree *PamLevel2::GetPamTree(TFile *f, T Line 3075  TTree *PamLevel2::GetPamTree(TFile *f, T
3075   * @return Pointer to a TList of TSystemFiles   * @return Pointer to a TList of TSystemFiles
3076   * 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.
3077   */   */
3078  TList*  PamLevel2::GetListOfLevel2Files(TString ddir, TString flisttxt = ""){  TList* PamLevel2::GetListOfLevel2Files(TString ddir, TString flisttxt = "") {
3079            
3080      TString wdir = gSystem->WorkingDirectory();    TString wdir = gSystem->WorkingDirectory();
3081        
3082      //    if(ddir=="")ddir = wdir;    if (ddir != "") {
3083  //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);      cout << "Level2 data directory : " << ddir << endl;
3084      if ( ddir != ""){    }
3085          cout << "Level2 data directory : "<<  ddir << endl;    else {
3086      } else {      cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory "
3087          cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory " << endl;          << endl;
3088      };    };
3089      TList *contents  = new TList; // create output list    TList *contents = new TList; // create output list
3090      contents->SetOwner();    contents->SetOwner();
3091        
3092  //    char *fullpath;    // --------------------------------------
3093  //    const char *fullpath;    // case 1 : input file/file-list provided
3094          // --------------------------------------
3095      // if no input file list is given:      if (flisttxt != "") {
3096      if ( flisttxt != "" ){  
3097                // --------------------------------------
3098  //      if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){              // a list of files given as input
3099  //      if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){      // --------------------------------------
3100  //          cout <<"File "<<flisttxt<<" not found"<<endl;      if (!flisttxt.EndsWith(".root")) {
3101  //          return 0;  
3102  //      }              TString dir = gSystem->DirName(flisttxt);
3103  //      flisttxt = fullpath;        //            cout << " List directory "<<dir<<endl;
3104          if ( !flisttxt.EndsWith(".root") ){        if (dir == "." || dir == "")
3105            flisttxt = gSystem->ConcatFileName(wdir.Data(), gSystem->BaseName(flisttxt));
3106              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));        //                flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
3107    
3108              if( !gSystem->ChangeDirectory(ddir) ){        if (!gSystem->ChangeDirectory(ddir)) {
3109                  cout << "Cannot change directory : "<<ddir<<endl;          cout << "Cannot change directory : " << ddir << endl;
3110                  return 0;          return 0;
3111              }        }
3112            
3113              cout <<"Input file list : " << flisttxt <<endl;        cout << "Input file list : " << flisttxt << endl;
3114              ifstream in;        ifstream in;
3115              in.open(flisttxt, ios::in); //open input file list        in.open(flisttxt, ios::in); //open input file list
3116              if(!in.good()){        if (!in.good()) {
3117                  cout <<" ERROR opening the file "<<endl;          cout << " TList*  PamLevel2::GetListOfLevel2Files(TString, TString) --> ERROR opening the file " << endl;
3118                  gSystem->ChangeDirectory(wdir); // back to the working directory          gSystem->ChangeDirectory(wdir); // back to the working directory
3119                  return 0;          return 0;
3120              }          }
3121              int line=0;        int line = 0;
3122              while (1) {        // ...........................
3123                  TString file;        // loop over file-list records
3124                  in >> file;        // ...........................
3125                  if (!in.good()) break;        while (1) {
3126                  line++;          TString file;
3127  //          cout <<"(1) " << file << endl;          in >> file;
3128                  if(file.IsNull()){          if (!in.good())
3129                      cout << "-- list interrupted at line "<<line <<endl;            break;
3130                      break;          line++;
3131                  }          cout << "(*) " << file << endl;
3132                  if(file.Contains("#"))file = file(0,file.First("#"));          if (file.IsNull()) {
3133  //          cout <<"(2) " << file << endl;            cout << "-- list interrupted at line " << line << endl;
3134  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){            break;
3135  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){          }
3136                  if( file.EndsWith(".root") ){          if (file.Contains("#"))
3137                      TString filedir;            file = file(0, file.First("#"));
3138                      if (ddir != ""){          //
3139                          filedir = ddir; // take the input dir          // take only root files
3140                      } else {          //
3141                          gSystem->ChangeDirectory(wdir); // back to the working directory          if (file.EndsWith(".root")) {
3142                          filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir            TString filedir;
3143                      };            cout << ddir << endl;
3144                      char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));            if ( ddir != "" ) {
3145                      contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list              filedir = ddir; // take the input dir
3146                      delete fullpath;            }
3147                  }            else {
3148  //          }else{              gSystem->ChangeDirectory(wdir); // back to the working directory
3149  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;              filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir
3150  //          };            };
3151              };            filedir.Append("/");
3152              in.close();            //          char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir), gSystem->BaseName(file));
3153          } else {            char *fullpath = gSystem->ConcatFileName(filedir.Data(), gSystem->BaseName(file));
3154              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));            contents->Add(new TSystemFile(fullpath, gSystem->DirName(fullpath)));// add file to the list
3155              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));            cout << fullpath << endl;
3156              contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list            delete fullpath;
3157              delete fullpath;          }
3158          };                //          }else{
3159      }else{          //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
3160                    //          };
3161          cout << "No input file list given."<<endl;        };
3162          cout << "Check for existing root files."<<endl;        in.close();
3163  //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;        // --------------------------------------
3164          if ( ddir == "" ){        // a single root file given as input
3165              ddir = wdir;        // --------------------------------------
3166              cout << "Level2 data directory : "<<  ddir << endl;      }
3167          };      else {
3168          if (flisttxt.Contains("#"))
3169          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);          flisttxt = flisttxt(0, flisttxt.First("#"));
3170          TList *temp = datadir->GetListOfFiles();        char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt), gSystem->BaseName(flisttxt));
3171  //              temp->Print();        contents->Add(new TSystemFile(fullpath, gSystem->DirName(fullpath)));// add file to the list
3172  //              cout << "*************************************" << endl;        delete fullpath;
3173                };
3174          TIter next(temp);      // ---------------------------------------------------------------------------------
3175          TSystemFile *questo = 0;      // case 2 : no input file/file-list provided --> read all files insede the directory
3176                // ---------------------------------------------------------------------------------
3177              }
3178          while ( (questo = (TSystemFile*) next()) ) {    else {
3179              TString name =  questo-> GetName();  
3180              if( name.EndsWith(".root") ){      cout << "No input file list given." << endl;
3181  //              const char *fullpath = gSystem->FindFile(ddir,name);      cout << "Check for existing root files." << endl;
3182  //              char *fullpath;      //          cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
3183  //              gSystem->IsFileInIncludePath(name,&fullpath);      if (ddir == "") {
3184                  char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(name));        ddir = wdir;
3185                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));        cout << "Level2 data directory : " << ddir << endl;
3186                  delete fullpath;      };
3187              };  
3188          }      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir), ddir);
3189          delete temp;      TList *temp = datadir->GetListOfFiles();
3190          delete datadir;      if (!temp)
3191                  return 0;
3192      };      //          temp->Print();
3193      gSystem->ChangeDirectory(wdir); // back to the working directory      //          cout << "*************************************" << endl;
3194  //      cout << endl << "Selected files:" << endl;  
3195  //      contents->Print();      TIter next(temp);
3196      cout << contents->GetEntries()<<" files \n";      TSystemFile *questo = 0;
3197  //      cout << endl;  
3198  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;      while ((questo = (TSystemFile*) next())) {
3199      return contents;        TString name = questo-> GetName();
3200  };        if (name.EndsWith(".root")) {
3201            //              const char *fullpath = gSystem->FindFile(ddir,name);
3202            //              char *fullpath;
3203            //              gSystem->IsFileInIncludePath(name,&fullpath);
3204            char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir), gSystem->BaseName(name));
3205            contents->Add(new TSystemFile(fullpath, gSystem->DirName(fullpath)));
3206            delete fullpath;
3207          };
3208        }
3209        delete temp;
3210        delete datadir;
3211    
3212      };
3213      gSystem->ChangeDirectory(wdir); // back to the working directory
3214      //    cout << endl << "Selected files:" << endl;
3215      //    contents->Print();
3216      cout << contents->GetEntries() << " files \n";
3217      //    cout << endl;
3218      //    cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;
3219      return contents;
3220    }
3221    ;
3222  //--------------------------------------  //--------------------------------------
3223  //  //
3224  //  //
3225  //--------------------------------------  //--------------------------------------
3226  /**  /**
3227   * Get the Pamela detector chains from a list of files and make them friends.   * Get the Pamela detector chains from a list of files and make them friends.
3228   * @param fl Pointer to a TList of TSystemFiles   * @param fl Pointer to a TList of TSystemFiles
3229   * @param detlist String to select trees to be included   * @param detlist String to select trees to be included
3230   * @return Pointer to a TChain   * @return Pointer to a TChain
3231   */   */
3232  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){  TChain *PamLevel2::GetPamTree(TList *fl, TString detlist) {
3233      //    //
3234      //    //
3235      //    //
3236      if ( pam_tree ){    if (pam_tree) {
3237          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 ");
3238          return pam_tree;      return pam_tree;
3239      };    };
3240      //    //
3241        
3242      TChain *Trout =0;    TChain *Trout = 0;
3243    
3244      // -------------------------------------------    // -------------------------------------------
3245      // set flags to include/exclude trees/branches    // set flags to include/exclude trees/branches
3246      // -------------------------------------------    // -------------------------------------------
3247      if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) {    if (detlist.Contains("+AUTO", TString::kIgnoreCase)) {
3248          if( fl->GetEntries()>0 ){      if (fl->GetEntries() > 0) {
3249              cout << "+AUTO"<<endl;        cout << "+AUTO" << endl;
3250              TFile *fprimo = new TFile( fl->At(0)->GetName() );        TFile *fprimo = new TFile(fl->At(0)->GetName());
3251              GetWhichTrees(fprimo);        GetWhichTrees(fprimo);
3252              fprimo->Close();// AAAAARGGGGGHHHHH!!!!!!! non commentare questa riga, altrimenti si incasina il TChain        fprimo->Close();// AAAAARGGGGGHHHHH!!!!!!! non commentare questa riga, altrimenti si incasina il TChain
3253              fprimo->Delete();        fprimo->Delete();
3254          }      }
3255      };    };
3256      SetWhichTrees(detlist);        SetWhichTrees(detlist);
3257    
3258      // -------------------------------------------
3259      // -------------------------------------------    // build chains
3260      // build chains    // -------------------------------------------
3261      // -------------------------------------------    TChain *T = 0;
3262      TChain *T = 0;          TChain *C = 0;
3263      TChain *C = 0;    TChain *O = 0;
3264      TChain *O = 0;    TChain *R = 0;
3265      TChain *R = 0;    TChain *S = 0;
3266      TChain *S = 0;    TChain *N = 0;
3267      TChain *N = 0;    TChain *A = 0;
3268      TChain *A = 0;    TChain *B = 0;
3269      TChain *B = 0;    TChain *G = 0;
3270      TChain *G = 0;  
3271      TChain *L = 0;
3272      TChain *L = 0;  
3273          if (TRK2 || TRK1 || TRKh)
3274      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          T = new TChain("Tracker");
3275      if(CAL2||CAL1)       C = new TChain("Calorimeter");    if (CAL2 || CAL1)
3276      if(TOF)              O = new TChain("ToF");      C = new TChain("Calorimeter");
3277      if(TRG)              R = new TChain("Trigger");    if (TOF)
3278      if(S4)               S = new TChain("S4");      O = new TChain("ToF");
3279      if(ND)               N = new TChain("NeutronD");    if (TRG)
3280      if(AC)               A = new TChain("Anticounter");      R = new TChain("Trigger");
3281      if(ORB)              B = new TChain("OrbitalInfo");    if (S4)
3282      if(GP)               G = new TChain("h20");      S = new TChain("S4");
3283      L = new TChain("SelectionList");    if (ND)
3284            N = new TChain("NeutronD");
3285      // loop over files and create chains            if (AC)
3286      TIter next(fl);      A = new TChain("Anticounter");
3287      TSystemFile *questo = 0;    if (ORB)
3288      while ( (questo = (TSystemFile*) next()) ) {      B = new TChain("OrbitalInfo");
3289          TString name =  questo->GetName();    if (GP)
3290          cout << "File: "<< name << endl;      G = new TChain("h20");
3291          if( CheckLevel2File(name) ){    L = new TChain("SelectionList");
3292              if(TRK2||TRK1||TRKh) T->Add(name);  
3293              if(CAL1||CAL2)       C->Add(name);    // loop over files and create chains
3294              if(TOF)              O->Add(name);    TIter next(fl);
3295              if(TRG)              R->Add(name);    TSystemFile *questo = 0;
3296              if(S4)               S->Add(name);    while ((questo = (TSystemFile*) next())) {
3297              if(ND)               N->Add(name);      TString name = questo->GetName();
3298              if(AC)               A->Add(name);      cout << "File: " << name << endl;
3299              if(ORB)              B->Add(name);      if (CheckLevel2File(name)) {
3300              if(GP)               G->Add(name);        if (TRK2 || TRK1 || TRKh)
3301              if(SELLI==1)         L->Add(name);          T->Add(name);
3302          };        if (CAL1 || CAL2)
3303      };          C->Add(name);
3304              if (TOF)
3305      cout << "done chains\n";          O->Add(name);
3306      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;        if (TRG)
3307            R->Add(name);
3308          if (S4)
3309      // -------------------------------------------          S->Add(name);
3310      // make friends        if (ND)
3311      // -------------------------------------------          N->Add(name);
3312          if (AC)
3313  // Tracker          A->Add(name);
3314      cout << "Friends: "<<endl;        if (ORB)
3315      if(T && (TRK2||TRK1||TRKh)) {          B->Add(name);
3316          if(!Trout)Trout=T;        if (GP)
3317          else Trout->AddFriend("Tracker");          G->Add(name);
3318  //      cout << "+Tacker"<<endl;        if (SELLI == 1)
3319      };          L->Add(name);
3320      // Calorimeter       };
3321      if(C && (CAL2||CAL1)) {    };
3322          if(!Trout)Trout=C;  
3323          else Trout->AddFriend("Calorimeter");    cout << "done data-tree chains  "<<  T->GetNtrees() <<" \n";
3324  //      cout << "+Calorimeter"<<endl;    cout << "----------------------------------------------------" << endl;
3325      };  
3326      // ToF        // -------------------------------------------
3327      if(O && TOF) {    // make friends
3328          if(!Trout)Trout=O;    // -------------------------------------------
3329          else Trout->AddFriend("ToF");  
3330  //      cout << "+ToF"<<endl;    // Tracker
3331      };    cout << "Friends: " << endl;
3332      // Trigger    if (T && (TRK2 || TRK1 || TRKh)) {
3333      if(R && TRG) {      if (!Trout)
3334          if(!Trout)Trout=O;        Trout = T;
3335          else Trout->AddFriend("Trigger");      else
3336  //      cout << "+Trigger"<<endl;        Trout->AddFriend("Tracker");
3337      };      //  cout << "+Tacker"<<endl;
3338      // S4    };
3339      if(S && S4) {    // Calorimeter
3340          if(!Trout)Trout=O;    if (C && (CAL2 || CAL1)) {
3341          else Trout->AddFriend("S4");      if (!Trout)
3342  //      cout << "+S4"<<endl;        Trout = C;
3343      };      else
3344      // Neutron Detector        Trout->AddFriend("Calorimeter");
3345      if(N && ND) {      //  cout << "+Calorimeter"<<endl;
3346          if(!Trout)Trout=O;    };
3347          else Trout->AddFriend("NeutronD");    // ToF
3348  //      cout << "+NeutronD"<<endl;    if (O && TOF) {
3349      };      if (!Trout)
3350      // Anticounters        Trout = O;
3351      if(A && AC) {      else
3352          if(!Trout)Trout=O;        Trout->AddFriend("ToF");
3353          else Trout->AddFriend("Anticounter");      //  cout << "+ToF"<<endl;
3354  //      cout << "+Anticounter"<<endl;    };
3355      };    // Trigger
3356      // Orbital Info    if (R && TRG) {
3357      if(B && ORB) {      if (!Trout)
3358          if(!Trout)Trout=O;        Trout = O;
3359          else Trout->AddFriend("OrbitalInfo");      else
3360  //      cout << "+OrbitalInfo"<<endl;        Trout->AddFriend("Trigger");
3361      };      //  cout << "+Trigger"<<endl;
3362      // GPamela    };
3363      if(G && GP) {    // S4
3364          if(!Trout)Trout=G;    if (S && S4) {
3365          else Trout->AddFriend("h20");      if (!Trout)
3366  //      cout << "+h20"<<endl;        Trout = O;
3367      };      else
3368          Trout->AddFriend("S4");
3369  //  =====================================      //  cout << "+S4"<<endl;
3370  //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND    };
3371  //  =====================================    // Neutron Detector
3372      SetBranchAddress(Trout);    if (N && ND) {
3373        if (!Trout)
3374          Trout = O;
3375  //  ------------------------------------      else
3376  //  finally handle selection trees...        Trout->AddFriend("NeutronD");
3377  //  (it is not friend of pamela tree)      //  cout << "+NeutronD"<<endl;
3378  //  ------------------------------------    };
3379      // Anticounters
3380      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;    if (A && AC) {
3381        if (!Trout)
3382      // Selection List        Trout = O;
3383      if(L && SELLI==1) {      else
3384          cout<<">>> Found selection-list <<<"<<endl;        Trout->AddFriend("Anticounter");
3385  //      L->SetBranchAddress("RunEntry",&irun);      //  cout << "+Anticounter"<<endl;
3386          L->SetBranchAddress("RunEntry",&irunt);//NEWNEW    };
3387          cout << "SelectionList: set branch address RunEntry"<<endl;    // Orbital Info
3388          L->SetBranchAddress("EventEntry",&irunentry);    if (B && ORB) {
3389          cout << "SelectionList: set branch address EventEntry"<<endl;      if (!Trout)
3390          sel_tree = L;        Trout = O;
3391  //      if(!Trout)Trout=O;      else
3392  //      else Trout->AddFriend("SelectionList");        Trout->AddFriend("OrbitalInfo");
3393          cout << "+SelectionList"<<endl;      //  cout << "+OrbitalInfo"<<endl;
3394          cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;    };
3395      }else{    // GPamela
3396  //      cout << "SelectionList  : missing tree"<<endl;    if (G && GP) {
3397          if(L)L->Delete();      if (!Trout)
3398      };        Trout = G;
3399        else
3400          Trout->AddFriend("h20");
3401        //  cout << "+h20"<<endl;
3402      };
3403    
3404      //  =====================================
3405      //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND
3406      //  =====================================
3407      if( Trout->GetNtrees() )SetBranchAddress(Trout);
3408    
3409      //  ------------------------------------
3410      //  finally handle selection trees...
3411      //  (it is not friend of pamela tree)
3412      //  ------------------------------------
3413    
3414      cout << "----------------------------------------------------" << endl;
3415    
3416      // Selection List
3417      if (L && SELLI == 1) {
3418        cout << ">>> Found selection-list <<<" << endl;
3419        //  L->SetBranchAddress("RunEntry",&irun);
3420        L->SetBranchAddress("RunEntry", &irunt);//NEWNEW
3421        cout << "SelectionList: set branch address RunEntry" << endl;
3422        L->SetBranchAddress("EventEntry", &irunentry);
3423        cout << "SelectionList: set branch address EventEntry" << endl;
3424        /*    if ( L->GetBranch("L0EventEntry") ){
3425          hasL0EE = true;
3426          L->SetBranchAddress("L0EventEntry", &il0entry);
3427          cout << "SelectionList: set branch address L0EventEntry" << endl;
3428        } else {
3429          hasL0EE = false; // backward compatibility with old preselected files...
3430          }*/
3431        sel_tree = L;
3432        //          if(!Trout)Trout=O;
3433        //          else Trout->AddFriend("SelectionList");
3434        cout << "+SelectionList" << endl;
3435        cout << "----------------------------------------------------" << endl;
3436      }
3437      else {
3438        //  cout << "SelectionList  : missing tree"<<endl;
3439        if (L)
3440          L->Delete();
3441      };
3442    
3443      //  --------------------------------------------
3444      //  return the pamela chain with all the friends
3445      //  --------------------------------------------
3446    
3447  //  --------------------------------------------    pam_tree = Trout;
 //  return the pamela chain with all the friends  
 //  --------------------------------------------  
3448    
3449      pam_tree = Trout;    return Trout;
       
     return Trout;  
3450  }  }
3451    
   
   
3452  //--------------------------------------  //--------------------------------------
3453  //  //
3454  //  //
# Line 2128  TChain *PamLevel2::GetPamTree(TList *fl, Line 3456  TChain *PamLevel2::GetPamTree(TList *fl,
3456  /**  /**
3457   * Set branch addresses for Pamela friend trees   * Set branch addresses for Pamela friend trees
3458   */   */
3459  void PamLevel2::SetBranchAddress(TTree *t){  void PamLevel2::SetBranchAddress(TTree *t) {
3460    
3461      TRK2    = TRK2 & t->GetBranchStatus("TrkLevel2");  //   TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
3462      TRK1    = TRK1 & t->GetBranchStatus("TrkLevel1");  //   TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
3463      TRKh    = TRKh & t->GetBranchStatus("TrkHough");  //   TRKh = TRKh & t->GetBranchStatus("TrkHough");
3464      CAL2    = CAL2 & t->GetBranchStatus("CaloLevel2");  //   CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
3465      CAL1    = CAL1 & t->GetBranchStatus("CaloLevel1");  //   CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
3466      TOF    = TOF & t->GetBranchStatus("ToFLevel2");  //   TOF = TOF & t->GetBranchStatus("ToFLevel2");
3467      TRG    = TRG & t->GetBranchStatus("TrigLevel2");  //   TRG = TRG & t->GetBranchStatus("TrigLevel2");
3468      S4     = S4  & t->GetBranchStatus("S4Level2");  //   S4 = S4 & t->GetBranchStatus("S4Level2");
3469      ND     = ND  & t->GetBranchStatus("NDLevel2");  //   ND = ND & t->GetBranchStatus("NDLevel2");
3470      AC     = AC  & t->GetBranchStatus("AcLevel2");  //   AC = AC & t->GetBranchStatus("AcLevel2");
3471      ORB    = ORB & t->GetBranchStatus("OrbitalInfo");  //   ORB = ORB & t->GetBranchStatus("OrbitalInfo");
3472      GP     = GP  & t->GetBranchStatus("h20");  //   GP = GP & t->GetBranchStatus("h20");
3473    
3474    
3475      // Tracker    // Tracker
3476      if(TRK1) {    if (TRK1) {
3477          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel2"));      t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel2"));
3478          cout << "Tracker      : set branch address TrkLevel1"<<endl;      cout << "Tracker      : set branch address TrkLevel1" << endl;
3479      };    };
3480      if(TRK2) {    if (TRK2) {
3481          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));
3482          cout << "Tracker      : set branch address TrkLevel2"<<endl;      cout << "Tracker      : set branch address TrkLevel2" << endl;
3483      };      NUC = t->GetBranchStatus("TrackNuclei");
3484      if(TRKh) {      EXT = t->GetBranchStatus("RecoveredTrack") && (NUC ? t->GetBranchStatus("RecoveredTrackNuclei"): true );    
3485          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));    };
3486          cout << "Tracker      : set branch address TrkHough"<<endl;    if (TRKh) {
3487      };      t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
3488            cout << "Tracker      : set branch address TrkHough" << endl;
3489      // Calorimeter    };
3490      if(CAL1) {  
3491          t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));    // Calorimeter
3492          cout << "Calorimeter  : set branch address CaloLevel1"<<endl;    if (CAL1) {
3493      };      t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
3494      if(CAL2) {      cout << "Calorimeter  : set branch address CaloLevel1" << endl;
3495          t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));    };
3496          cout << "Calorimeter  : set branch address CaloLevel2"<<endl;    if (CAL2) {
3497      };      t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
3498            cout << "Calorimeter  : set branch address CaloLevel2" << endl;
3499      // ToF        };
3500      if(TOF) {  
3501          t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));    // ToF
3502          cout << "ToF          : set branch address ToFLevel2"<<endl;    if (TOF) {
3503      };      t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
3504      // Trigger      cout << "ToF          : set branch address ToFLevel2" << endl;
3505      if(TRG) {    };
3506          t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));    // Trigger
3507          cout << "Trigger      : set branch address TrigLevel2"<<endl;    if (TRG) {
3508      };      t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
3509      // S4      cout << "Trigger      : set branch address TrigLevel2" << endl;
3510      if(S4) {    };
3511          t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));    // S4
3512          cout << "S4           : set branch address S4Level2"<<endl;    if (S4) {
3513      };      t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
3514      // Neutron Detector      cout << "S4           : set branch address S4Level2" << endl;
3515      if(ND) {    };
3516          t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));    // Neutron Detector
3517          cout << "NeutronD     : set branch address NDLevel2"<<endl;    if (ND) {
3518      };      t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
3519      // Anticounters      cout << "NeutronD     : set branch address NDLevel2" << endl;
3520      if(AC) {    };
3521          t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));    // Anticounters
3522          cout << "Anticounter  : set branch address AcLevel2"<<endl;    if (AC) {
3523      };      t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
3524      // OrbitalInfo      cout << "Anticounter  : set branch address AcLevel2" << endl;
3525      if(ORB) {    };
3526          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));    // OrbitalInfo
3527          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;    if (ORB) {
3528      };      t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
3529      // GPamela      cout << "OrbitalInfo  : set branch address OrbitalInfo" << endl;
3530      if(GP) {    };
3531  //      GetPointerTo("GPamela");    // GPamela
3532          if(!gp_obj)gp_obj = new GPamela();    if (GP) {
3533  //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri      //  GetPointerTo("GPamela");
3534  // //   t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));      if (!gp_obj)
3535          if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));        gp_obj = new GPamela();
3536          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
3537        // //       t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
3538        if (SELLI)
3539          t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
3540        else
3541          gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
3542    
3543        cout << "h20          : set branch address GPamela " << endl;
3544      };
3545      if(NUC){
3546          
3547          cout << "Found nuclei-track branches" << endl;
3548    
3549          cout << "h20          : set branch address GPamela "<<endl;        if( !trk_nuc_obj )trk_nuc_obj = new TClonesArray("TrkTrack");
3550      };        if( !calo_nuc_obj)calo_nuc_obj= new TClonesArray("CaloTrkVar");
3551              if( !tof_nuc_obj)tof_nuc_obj= new TClonesArray("ToFTrkVar");
3552          if( !orb_nuc_obj)orb_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3553          if (TRK2)t->                          SetBranchAddress("TrackNuclei",&trk_nuc_obj);
3554          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("TrackNuclei",&calo_nuc_obj);
3555          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("TrackNuclei",&tof_nuc_obj);
3556          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("TrackNuclei",&orb_nuc_obj);
3557    
3558          ///copy the vector content inside a "fake" object (all aother info are missing)    
3559    
3560          if( !trk2_nuc_obj )trk2_nuc_obj =  new TrkLevel2();
3561          if( !calo2_nuc_obj )calo2_nuc_obj =  new CaloLevel2();
3562          if( !tof2_nuc_obj )tof2_nuc_obj =  new ToFLevel2();
3563          if( !orb2_nuc_obj )orb2_nuc_obj =  new OrbitalInfo();
3564    //       *(trk2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*trk_nuc_obj);
3565    //       *(calo2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*calo_nuc_obj);
3566    //       *(tof2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*tof_nuc_obj);
3567    //       *(orb2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*orb_nuc_obj);
3568    
3569          trk2_nuc_obj->SetTrackArray(  trk_nuc_obj  );
3570          calo2_nuc_obj->SetTrackArray( calo_nuc_obj );
3571          tof2_nuc_obj->SetTrackArray(  tof_nuc_obj  );
3572          orb2_nuc_obj->SetTrackArray(  orb_nuc_obj  );
3573    
3574          
3575      }    
3576    
3577      if(EXT){
3578          
3579          cout << "Found extended tracking algorythm branches" << endl;
3580    
3581          if( !trk_ext_obj )trk_ext_obj = new TClonesArray("ExtTrack");
3582          if( !calo_ext_obj)calo_ext_obj= new TClonesArray("CaloTrkVar");
3583          if( !tof_ext_obj)tof_ext_obj= new TClonesArray("ToFTrkVar");
3584          if( !orb_ext_obj)orb_ext_obj= new TClonesArray("OrbitalInfoTrkVar");
3585          
3586          if (TRK2)t->                          SetBranchAddress("RecoveredTrack",&trk_ext_obj);
3587          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrack",&calo_ext_obj);
3588          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrack",&tof_ext_obj);
3589          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrack",&orb_ext_obj);
3590    
3591        
3592          if(NUC){
3593              if( !trk_ext_nuc_obj )trk_ext_nuc_obj = new TClonesArray("ExtTrack");
3594              if( !calo_ext_nuc_obj)calo_ext_nuc_obj= new TClonesArray("CaloTrkVar");
3595              if( !tof_ext_nuc_obj)tof_ext_nuc_obj= new TClonesArray("ToFTrkVar");
3596              if( !orb_ext_nuc_obj)orb_ext_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3597              if (TRK2)t->                          SetBranchAddress("RecoveredTrackNuclei",&trk_ext_nuc_obj);
3598              if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrackNuclei",&calo_ext_nuc_obj);
3599              if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrackNuclei",&tof_ext_nuc_obj);
3600              if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrackNuclei",&orb_ext_nuc_obj);
3601          }
3602      }    
3603  }  }
3604  /**  /**
3605   * Set branch addresses for Pamela friend trees   * Set branch addresses for Pamela friend trees
3606   */   */
3607  void PamLevel2::SetBranchAddress(TChain *t){  void PamLevel2::SetBranchAddress(TChain *t) {
3608    
3609  //     TRK2    = TRK2 & t->GetBranchStatus("TrkLevel2");    //     TRK2    = TRK2 & t->GetBranchStatus("TrkLevel2");
3610  //     TRK1    = TRK1 & t->GetBranchStatus("TrkLevel1");    //     TRK1    = TRK1 & t->GetBranchStatus("TrkLevel1");
3611  //     TRKh    = TRKh & t->GetBranchStatus("TrkHough");    //     TRKh    = TRKh & t->GetBranchStatus("TrkHough");
3612  //     CAL1    = CAL1 & t->GetBranchStatus("CaloLevel1");    //     CAL1    = CAL1 & t->GetBranchStatus("CaloLevel1");
3613  //     CAL2    = CAL2 & t->GetBranchStatus("CaloLevel2");    //     CAL2    = CAL2 & t->GetBranchStatus("CaloLevel2");
3614  //     TOF    = TOF & t->GetBranchStatus("ToFLevel2");    //     TOF    = TOF & t->GetBranchStatus("ToFLevel2");
3615  //     TRG    = TRG & t->GetBranchStatus("TrigLevel2");    //     TRG    = TRG & t->GetBranchStatus("TrigLevel2");
3616  //     S4     = S4  & t->GetBranchStatus("S4Level2");    //     S4     = S4  & t->GetBranchStatus("S4Level2");
3617  //     ND     = ND  & t->GetBranchStatus("NDLevel2");    //     ND     = ND  & t->GetBranchStatus("NDLevel2");
3618  //     AC     = AC  & t->GetBranchStatus("AcLevel2");    //     AC     = AC  & t->GetBranchStatus("AcLevel2");
3619  //     ORB    = ORB & t->GetBranchStatus("OrbitalInfo");    //     ORB    = ORB & t->GetBranchStatus("OrbitalInfo");
3620  //    GP     = GP & t->GetBranchStatus("h20");    //    GP     = GP & t->GetBranchStatus("h20");
3621    
3622      // Tracker    // Tracker
3623      if(TRK2) {    if (TRK2) {
3624          t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));      t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
3625          cout << "Tracker      : set branch address TrkLevel2"<<endl;      cout << "Tracker      : set branch address TrkLevel2" << endl;
3626      };      NUC = t->GetBranchStatus("TrackNuclei");
3627      if(TRK1) {      EXT = t->GetBranchStatus("RecoveredTrack") && (NUC ? t->GetBranchStatus("RecoveredTrackNuclei"): true );
3628          t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));    };
3629          cout << "Tracker      : set branch address TrkLevel1"<<endl;    if (TRK1) {
3630      };      t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
3631      if(TRKh) {      cout << "Tracker      : set branch address TrkLevel1" << endl;
3632          t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));    };
3633          cout << "Tracker      : set branch address TrkHough"<<endl;    if (TRKh) {
3634      };      t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
3635            cout << "Tracker      : set branch address TrkHough" << endl;
3636      // Calorimeter    };
3637      if(CAL2) {  
3638          t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));    // Calorimeter
3639          cout << "Calorimeter  : set branch address CaloLevel2"<<endl;    if (CAL2) {
3640      };        t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
3641      if(CAL1) {      cout << "Calorimeter  : set branch address CaloLevel2" << endl;    
3642          t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));    };
3643          cout << "Calorimeter  : set branch address CaloLevel1"<<endl;    if (CAL1) {
3644      };      t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
3645            cout << "Calorimeter  : set branch address CaloLevel1" << endl;
3646      // ToF        };
3647      if(TOF) {  
3648          t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));    // ToF
3649          cout << "ToF          : set branch address ToFLevel2"<<endl;    if (TOF) {
3650      };      t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
3651      // Trigger      cout << "ToF          : set branch address ToFLevel2" << endl;
3652      if(TRG) {    };
3653          t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));    // Trigger
3654          cout << "Trigger      : set branch address TrigLevel2"<<endl;    if (TRG) {
3655      };      t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
3656      // S4      cout << "Trigger      : set branch address TrigLevel2" << endl;
3657      if(S4) {    };
3658          t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));    // S4
3659          cout << "S4           : set branch address S4Level2"<<endl;    if (S4) {
3660      };      t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
3661      // Neutron Detector      cout << "S4           : set branch address S4Level2" << endl;
3662      if(ND) {    };
3663          t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));    // Neutron Detector
3664          cout << "NeutronD     : set branch address NDLevel2"<<endl;    if (ND) {
3665      };      t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
3666      // Anticounters      cout << "NeutronD     : set branch address NDLevel2" << endl;
3667      if(AC) {    };
3668          t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));    // Anticounters
3669          cout << "Anticounter  : set branch address AcLevel2"<<endl;    if (AC) {
3670      };      t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
3671      // OrbitalInfo      cout << "Anticounter  : set branch address AcLevel2" << endl;
3672      if(ORB) {    };
3673          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));    // OrbitalInfo
3674          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;    if (ORB) {
3675      };      t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
3676      // GPamela      cout << "OrbitalInfo  : set branch address OrbitalInfo" << endl;
3677  //    cout <<"GP "<<GP<<endl;    };
3678      if(GP) {    // GPamela
3679  //      GetPointerTo("GPamela");    //    cout <<"GP "<<GP<<endl;
3680          if(!gp_obj)gp_obj = new GPamela();    if (GP) {
3681          if(SELLI) t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));      //  GetPointerTo("GPamela");
3682          else      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri      if (!gp_obj)
3683  //      gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri        gp_obj = new GPamela();
3684          cout << "h20          : set branch address GPamela "<<endl;      if (SELLI)
3685      };        t->SetBranchAddress("GPamela", GetPointerTo("GPamela"));
3686      // SelectionList      else
3687  //     if(SELLI==1){        gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
3688  //      t->SetBranchAddress("RunEntry",&irunt);//NEWNEW      //  gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri
3689  //      cout << "SelectionList: set branch address RunEntry"<<endl;      cout << "h20          : set branch address GPamela " << endl;
3690  //      t->SetBranchAddress("EventEntry",&irunentry);    };
3691  //      cout << "SelectionList: set branch address EventEntry"<<endl;    // SelectionList
3692              //     if(SELLI==1){
3693  //     }    //    t->SetBranchAddress("RunEntry",&irunt);//NEWNEW
3694      //    cout << "SelectionList: set branch address RunEntry"<<endl;
3695      //    t->SetBranchAddress("EventEntry",&irunentry);
3696      //    cout << "SelectionList: set branch address EventEntry"<<endl;
3697    
3698      //     }
3699      if(NUC){
3700          
3701          cout << "Found nuclei-track branches" << endl;
3702    
3703          if( !trk_nuc_obj )trk_nuc_obj = new TClonesArray("TrkTrack");
3704          if( !calo_nuc_obj)calo_nuc_obj= new TClonesArray("CaloTrkVar");
3705          if( !tof_nuc_obj)tof_nuc_obj= new TClonesArray("ToFTrkVar");
3706          if( !orb_nuc_obj)orb_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3707          if (TRK2)t->                          SetBranchAddress("TrackNuclei",&trk_nuc_obj);
3708          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("TrackNuclei",&calo_nuc_obj);
3709          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("TrackNuclei",&tof_nuc_obj);
3710          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("TrackNuclei",&orb_nuc_obj);
3711          
3712          ///copy the vector content inside a "fake" object (all aother info are missing)    
3713    
3714          if( !trk2_nuc_obj )trk2_nuc_obj =  new TrkLevel2();
3715          if( !calo2_nuc_obj )calo2_nuc_obj =  new CaloLevel2();
3716          if( !tof2_nuc_obj )tof2_nuc_obj =  new ToFLevel2();
3717          if( !orb2_nuc_obj )orb2_nuc_obj =  new OrbitalInfo();
3718    
3719    //       *(trk2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*trk_nuc_obj);
3720    //       *(calo2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*calo_nuc_obj);
3721    //       *(tof2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*tof_nuc_obj);
3722    //       *(orb2_nuc_obj->GetPointerToTrackArray()) = new TClonesArray(*orb_nuc_obj);
3723          trk2_nuc_obj->SetTrackArray(  trk_nuc_obj  );
3724          calo2_nuc_obj->SetTrackArray( calo_nuc_obj );
3725          tof2_nuc_obj->SetTrackArray(  tof_nuc_obj  );
3726          orb2_nuc_obj->SetTrackArray(  orb_nuc_obj  );
3727    
3728      }    
3729      if(EXT){
3730          
3731          cout << "Found extended tracking algorythm branches" << endl;
3732    
3733          t->SetBranchAddress("extAlgFlag",&extAlgFlag);
3734    
3735          if( !trk_ext_obj )trk_ext_obj = new TClonesArray("ExtTrack");
3736          if( !calo_ext_obj)calo_ext_obj= new TClonesArray("CaloTrkVar");
3737          if( !tof_ext_obj)tof_ext_obj= new TClonesArray("ToFTrkVar");
3738          if( !orb_ext_obj)orb_ext_obj= new TClonesArray("OrbitalInfoTrkVar");
3739          
3740          if (TRK2)t->                          SetBranchAddress("RecoveredTrack",&trk_ext_obj);
3741          if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrack",&calo_ext_obj);
3742          if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrack",&tof_ext_obj);
3743          if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrack",&orb_ext_obj);
3744          
3745          if(NUC){
3746              if( !trk_ext_nuc_obj )trk_ext_nuc_obj = new TClonesArray("ExtTrack");
3747              if( !calo_ext_nuc_obj)calo_ext_nuc_obj= new TClonesArray("CaloTrkVar");
3748              if( !tof_ext_nuc_obj)tof_ext_nuc_obj= new TClonesArray("ToFTrkVar");
3749              if( !orb_ext_nuc_obj)orb_ext_nuc_obj= new TClonesArray("OrbitalInfoTrkVar");
3750              if (TRK2)t->                          SetBranchAddress("RecoveredTrackNuclei",&trk_ext_nuc_obj);
3751              if (CAL2)t->GetFriend("Calorimeter")->SetBranchAddress("RecoveredTrackNuclei",&calo_ext_nuc_obj);
3752              if (TOF )t->GetFriend("ToF")->        SetBranchAddress("RecoveredTrackNuclei",&tof_ext_nuc_obj);
3753              if (ORB )t->GetFriend("OrbitalInfo")->SetBranchAddress("RecoveredTrackNuclei",&orb_ext_nuc_obj);
3754          }
3755      }    
3756      
3757  }  }
3758    
3759    /**
3760     * Set the tracking algorythm
3761     * @param alg String to choose the track.
3762     * "" --> take the output of the standard tracking algorythm
3763     * "STD" --> take the output of the standard tracking algorythm
3764     * "NUC" --> take the output of the standard tracking algorythm for nuclei cluster selection
3765     * "EXT" --> in case the standard tracking algorythm has not found any track, take the output of the extended one
3766     * "EXTF" --> force the extended tracking algorythm
3767     * "NUCEXT" --> as "EXT", but for nuclei
3768     * "NUCEXTF" --> as "EXTF", but for nuclei
3769     */
3770    void PamLevel2::SetTrakingAlgorythm(char *alg){
3771    
3772    
3773        TString s(alg);
3774        if(s.Contains("NUC", TString::kIgnoreCase) && !NUC)
3775            cout << "Warning! NUC algorythm requested, but branches are missing"<<endl;
3776        if(s.Contains("EXT", TString::kIgnoreCase) && !EXT)
3777            cout << "Warning! EXT algorythm requested, but branches are missing"<<endl;;
3778                
3779        trkAlg = alg;
3780    
3781    };
3782    char* PamLevel2::GetTrakingAlgorythm(){
3783    
3784    
3785        cout<<endl<<" Implemented tracking algorythm: ";
3786        cout<<endl<<"  \"\" or \"STD\"  --> take the output of the standard tracking algorythm";
3787        cout<<endl<<"  \"NUC\"      --> take the output of the standard tracking algorythm for nuclei cluster selection";
3788        cout<<endl<<"  \"EXT\"      --> in case the standard tracking algorythm has not found any track,";
3789        cout<<endl<<"                 take the output of the extended one";
3790        cout<<endl<<"  \"EXTF\"     --> force the extended tracking algorythm";
3791        cout<<endl<<"  \"NUCEXT\"   --> as \"EXT\", but for nuclei ";
3792        cout<<endl<<"  \"NUCEXTF\"  --> as \"EXTF\", but for nuclei";
3793    
3794        cout<<endl;
3795        cout<<" <<Currently set algorythm>> "<<trkAlg<<endl;
3796        cout<<endl;
3797    
3798        return trkAlg;
3799    };
3800    
3801    
3802    
3803  //--------------------------------------  //--------------------------------------
3804  //  //
# Line 2311  void PamLevel2::SetBranchAddress(TChain Line 3806  void PamLevel2::SetBranchAddress(TChain
3806  //--------------------------------------  //--------------------------------------
3807  /**  /**
3808   * Get the Run tree chain from a list of files.   * Get the Run tree chain from a list of files.
3809   * @param fl Pointer to a TList of TSystemFiles   * @param fl Pointer to a TList of TSystemFiles
3810   * @return Pointer to a TChain   * @return Pointer to a TChain
3811   */   */
3812  TChain *PamLevel2::GetRunTree(TList *fl){  TChain *PamLevel2::GetRunTree(TList *fl) {
3813      //    //
3814      //    //
3815      //    //
3816      if ( run_tree ){    if (run_tree) {
3817          printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");      printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n ");
3818          return run_tree;      return run_tree;
3819      };      };
3820      //    //
3821    
3822    
3823      TChain *R = new TChain("Run");
3824    
3825      // loop over files and create chains
3826      TIter next(fl);
3827      TSystemFile *questo = 0;
3828      while ((questo = (TSystemFile*) next())) {
3829        TString name = questo->GetName();
3830        //          cout << "File: "<< name << endl;
3831        if (CheckLevel2File(name)) {
3832          R->Add(name);
3833        };
3834      }
3835    
3836      cout << "done run chain  "<<  R->GetNtrees() <<" \n";
3837    
3838    
3839      if (RUN && R->GetNtrees()) {
3840    
3841        R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
3842        cout << "Run         : set branch address RunInfo" << endl;
3843        R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
3844        cout << "Software    : set branch address SoftInfo" << endl; // Emiliano
3845    
3846        irunoffset = new int[R->GetNtrees()];
3847        if (DBG) {
3848          cout << "----------------------------------------------------" << endl;
3849          cout << "irun\t | ";
3850          cout << "tree\t |";
3851          //        cout << "offset\t |";
3852          cout << "RUN\t";
3853          cout << "FRAG\t";
3854          cout << "NEVENTS\t";
3855          cout << "absolute time\t\t\t";
3856          cout << "on-board time";
3857          cout << endl;
3858        }
3859        for (Int_t ii = 0; ii < R->GetEntries(); ii++) {
3860          R->GetEntry(ii);
3861          if (DBG) {
3862            cout << ii << "\t | ";
3863            cout << R->GetTreeNumber() << "\t |";
3864            //          cout << R->GetChainOffset()<< "\t |";
3865            cout << GetRunInfo()->ID << "\t";
3866            cout << GetRunInfo()->ID_RUN_FRAG << "\t";
3867            cout << GetRunInfo()->NEVENTS << "\t";
3868            cout << GetRunInfo()->RUNHEADER_TIME << " <---> " << GetRunInfo()->RUNTRAILER_TIME << "\t";
3869            cout << GetRunInfo()->RUNHEADER_OBT << " <---> " << GetRunInfo()->RUNTRAILER_OBT << "\t";
3870            cout << endl;
3871          }
3872          irunoffset[R->GetTreeNumber()] = R->GetChainOffset();
3873        }
3874        cout << "N.run = " << R->GetEntries() << endl;
3875        cout << "----------------------------------------------------" << endl;
3876    
3877      }
3878    //   else {
3879    //     delete R;
3880    //     R = 0;
3881    //   }
3882    
3883      run_tree = R;
3884    
3885      TChain *R = new TChain("Run");    return R;
       
     // loop over files and create chains          
     TIter next(fl);  
     TSystemFile *questo = 0;  
     while ( (questo = (TSystemFile*) next()) ) {  
         TString name =  questo->GetName();  
 //              cout << "File: "<< name << endl;  
         if( CheckLevel2File(name) ){  
             R->Add(name);  
         };  
     }  
       
   
     if(RUN && R->GetNtrees()){  
       
         R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));  
         cout << "Run         : set branch address RunInfo"<<endl;  
         R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano  
         cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano  
   
         irunoffset = new int[R->GetNtrees()];  
         if(DBG){  
             cout << "----------------------------------------------------"<<endl;  
             cout << "irun\t | ";  
             cout << "tree\t |";  
 //      cout << "offset\t |";  
             cout << "RUN\t";  
             cout << "FRAG\t";  
             cout << "NEVENTS\t";  
             cout << "absolute time\t\t\t";  
             cout << "on-board time";  
             cout<<endl;  
         }  
         for (Int_t ii=0; ii<R->GetEntries(); ii++){  
             R->GetEntry(ii);  
             if(DBG){  
                 cout << ii<< "\t | ";  
                 cout << R->GetTreeNumber()<< "\t |";  
 //          cout << R->GetChainOffset()<< "\t |";  
                 cout <<GetRunInfo()->ID<<"\t";  
                 cout <<GetRunInfo()->ID_RUN_FRAG<<"\t";  
                 cout <<GetRunInfo()->NEVENTS<< "\t";  
                 cout <<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME <<"\t";  
                 cout <<GetRunInfo()->RUNHEADER_OBT<<" <---> "<<GetRunInfo()->RUNTRAILER_OBT<<"\t";  
                 cout <<endl;  
             }  
             irunoffset[R->GetTreeNumber()]=R->GetChainOffset();  
         }  
         cout << "N.run = "<<R->GetEntries()<<endl;  
         cout << "----------------------------------------------------"<<endl;  
3886    
   
     }else{  
         delete R;  
         R=0;  
     }  
       
   
     run_tree = R;  
   
     return R;  
       
3887  }  }
3888  //--------------------------------------  //--------------------------------------
3889  //  //
# Line 2395  TChain *PamLevel2::GetRunTree(TList *fl) Line 3891  TChain *PamLevel2::GetRunTree(TList *fl)
3891  //--------------------------------------  //--------------------------------------
3892  /**  /**
3893   * Get the Run tree  from a file.   * Get the Run tree  from a file.
3894   * @param f Pointer to a TFile   * @param f Pointer to a TFile
3895   * @return Pointer to a TTree   * @return Pointer to a TTree
3896   */   */
3897  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f) {
3898      if ( run_tree ){    if (run_tree) {
3899          printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");      printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n ");
3900          return run_tree;      return run_tree;
3901      };    };
           
3902    
3903      cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;    cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte " << endl;
3904    
3905      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  
3906    
3907      }    if (T) {
3908        T->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
3909        cout << "Run         : set branch address RunInfo" << endl;
3910        T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
3911        cout << "Software    : set branch address SoftInfo" << endl; // Emiliano
3912    
3913      run_tree = (TChain*)T;    }
3914    
3915      return T;    run_tree = (TChain*) T;
       
 }  
 /**  
  * Update the runinfo informations (to be used to have Run infos event by event basis)  
  * @param run Pointer to the chain/tree which contains run infos  
  * @return true if a new run has been read, false if it is still the same run  
  */  
 Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){  
     //  
     // check if we have already called once GetEntry, if not call it  
     //  
     cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- ATTENZIONE --- NON E` MANTENUTA!!!!!!!.... "<<endl;  
     if(!run){  
         cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree "<<endl;  
         return(false);    
     }  
     if ( run->GetEntries() <= 0 ) return(false);  
     //  
     
     //  Int_t oldrun = irun;  
     Long64_t oldrun = irun;  
   
     // --------------------------------------  
     // if it is a full file (not preselected)  
     // --------------------------------------  
     if(SELLI==0){  
3916    
3917          //    return T;
         // 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);  
         }  
3918    
3919          ULong64_t abstime = 0;  }
         if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime;  
3920    
3921    Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) {
3922    
3923          //    if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - inside\n");
         // 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);      
     };  
     // ----------------------------------------------------  
     // if it is a preselected file (there is SelectionList)  
     // NBNB - the event tree MUST be read first  
     // ----------------------------------------------------  
     if(SELLI==1){        
         sel_tree->GetEntry(iev);  
 //      cout << irun << " "<< irunentry << endl;  
         if(irun != oldrun){  
             run->GetEntry(irun);  
             cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;  
             prevshift = 0;  
             return true;  
         }  
         return false;  
     }  
3924    
3925      if (!run_tree) {
3926        cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded" << endl;
3927      return false;      return false;
3928      //    }
3929  };    if (run_tree->GetEntries() <= 0) {
3930        cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty" << endl;
3931  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){      return (false);
3932      }
3933      if(!run_tree){  
3934          cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded"<<endl;  
3935          return false;    Int_t oldrun = irun; // store current run index
3936      }  
3937      if ( run_tree->GetEntries() <= 0 ) {    // -----------------------------------------------------------------------
3938          cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty"<<endl;    // the first time the routine is called, set run search from the beginning
3939          return(false);    // -----------------------------------------------------------------------
3940      }  
3941        if (irun < 0) {
3942      Int_t oldrun = irun; // store current run index      irun = 0LL;
3943        irunt = 0LL;
3944        totrunentry = 0LL;
3945        totrunentrymin = 0LL;
3946        totrunentrymax = 0LL;
3947        irunentry = 0LL;
3948        il0entry = 0LL;
3949        prevshift = 0;
3950        yprevshift = 0;
3951        prevabstime = 0;
3952        prevpktnum = 0;
3953        abstime = 0ULL;
3954        pktnum = 0;
3955        isFragment = false;
3956        run_tree->GetEntry(irun);
3957        if (!GetOrbitalInfo())
3958          cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated " << endl;
3959        if ( fUseDBinRunInfo ){
3960          if (gltsync)
3961            delete gltsync; //Emiliano
3962          if (!dbc || (dbc && !dbc->IsConnected()))
3963            SetDBConnection(); //Emiliano
3964          gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); //Emiliano // the "false" means not to use level0 file (not necessary here)
3965          if (dbc){
3966            dbc->Close();// Emiliano
3967            delete dbc;
3968            dbc=0;
3969          }
3970        }
3971      }
3972      // ---------------------------------------------------------------
3973      // retrieve OBT and absolute time of the event
3974      // ---------------------------------------------------------------
3975      Long64_t obt = 0LL; // Emiliano, Long64_t GL_TIMESYNC::DBobt(UInt_t obt) since depending on the situation OBT is lowered or boosted
3976      prevabstime = abstime;
3977      prevpktnum = pktnum;
3978      if (GetOrbitalInfo()) {
3979        abstime = GetOrbitalInfo()->absTime;
3980        if ( fUseDBinRunInfo ) obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano
3981        pktnum = GetOrbitalInfo()->pkt_num; // Emiliano
3982      }
3983      else {
3984        abstime = GetRunInfo()->RUNHEADER_TIME;
3985        if ( fUseDBinRunInfo ) obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano
3986        pktnum = GetRunInfo()->RUNHEADER_PKT; // Emiliano
3987      }
3988    
3989      if (DBG){
3990        printf("0abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
3991        printf("0        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
3992        printf("0        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
3993        if ( fUseDBinRunInfo ) printf("0        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
3994        printf("0        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
3995        printf("0        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);
3996      }
3997    
3998      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
3999      // if it is a full file (not preselected)
4000      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
4001      if (SELLI == 0 || SELLI == 2) { // Emiliano
4002    
     // -----------------------------------------------------------------------  
     // the first time the routine is called, set run search from the beginning  
     // -----------------------------------------------------------------------  
   
     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;  
     };        
4003      // ---------------------------------------------------------------      // ---------------------------------------------------------------
4004      // retrieve OBT and absolute time of the event      // increment dead and live-time counters
4005        // (only when reading a file not preselected)
4006      // ---------------------------------------------------------------      // ---------------------------------------------------------------
4007      ULong64_t abstime = 0LL;      if (SELLI == 0) {
4008      ULong64_t obt     = 0LL;        if (GetTrigLevel2()) {
4009      if( GetOrbitalInfo() ){          totdltime[0] += GetTrigLevel2()->dltime[0];
4010          abstime = GetOrbitalInfo()->absTime;          totdltime[1] += GetTrigLevel2()->dltime[1];
4011          obt     = GetOrbitalInfo()->OBT;        }
4012      }else{        totdltime[2]++;
         abstime = GetRunInfo()->RUNHEADER_TIME;  
         obt     = GetRunInfo()->RUNHEADER_OBT;  
4013      }      }
       
   
     // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-  
     // if it is a full file (not preselected)  
     // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-  
     if(SELLI==0){  
   
         // ---------------------------------------------------------------  
         // 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  
4014    
4015        //
4016        bool a = true;
4017        bool b = true;
4018        if ( fUseDBinRunInfo ){
4019          a = false;    
4020          b = false;
4021          if ( obt < gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) ) a = true;
4022          if ( obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ) b = true;
4023        }
4024        if ( iev < totrunentrymin || iev > totrunentrymax // entry is outside run limits
4025             || iev == 0 // or it is the first entry
4026             || (!isSync && (
4027                             (abstime <= GetRunInfo()->RUNHEADER_TIME && a ) // or it is outside obt limits (and abstime limits for security reasons)
4028                             || (abstime >= GetRunInfo()->RUNTRAILER_TIME && b ) ))// or it is outside obt limits (and abstime limits for security reasons)
4029             ){ // check on abstime and obt needed to handle nested+DV_skipped packets
4030          
4031          // check for a new run (ma prima il primo!)
4032          if (DBG){
4033            printf("1abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4034            printf("1        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4035            printf("1        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4036            if ( fUseDBinRunInfo ) printf("1        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4037            printf("1        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4038            printf("1        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);
4039          }
4040          //        printf("1abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4041          //        printf("1        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4042          //        printf("1        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4043          //        printf("1        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4044          //        printf("1        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4045          //        printf("1        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);//TOGLITOGLI
4046    
4047          totrunentry = 0LL;
4048          runfirstentry = 0LL;
4049          for (Int_t r=0; r< run_tree->GetEntries();r++){
4050            // -------------------------------------------------------------------
4051            // save the index of the first entry of the run, relative to pam_tree,
4052            // and read a new run
4053            // -------------------------------------------------------------------
4054            run_tree->GetEntry(r);//update runinfo
4055            if ( r > 0 ){
4056              totrunentrymin = totrunentrymax+1;
4057            } else {
4058              totrunentrymin = 0LL;
4059            }
4060            totrunentry += GetRunInfo()->NEVENTS;
4061            totrunentrymax = totrunentry - 1 - prevshift; // prevshift is needed to handle nested+DV_skipped packets
4062            irun = r;        
4063            if ( fUseDBinRunInfo ){
4064              a = false;    
4065              b = false;
4066              if ( obt < gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) ) a = true;
4067              if ( obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ) b = true;
4068            }
4069            if ( (iev >= totrunentrymin && iev <= totrunentrymax) || // entry is inside run limits
4070                 ( !isSync &&
4071                   ( abstime >= GetRunInfo()->RUNHEADER_TIME  && a // or it is inside obt limits (and abstime limits for security reasons)
4072                     && abstime <= GetRunInfo()->RUNTRAILER_TIME && b))  // or it is inside obt limits (and abstime limits for security reasons)
4073                 ){ // check on abstime and obt needed to handle nested+DV_skipped packets
4074              if ( totrunentrymin > iev ){ // there is a shift (nested+DV_skipped packets)
4075                if ( !isSync ){
4076                  if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - unconsistent iev - nevents, probable DBL0-L2 async\n");
4077                  if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);
4078                  //              printf("PamLevel2::UpdateRunInfo(Long64_t) - unconsistent iev - nevents, probable DBL0-L2 async\n");
4079                  //              printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI
4080                  prevshift += (totrunentrymin-iev); // add the new shift to total shift
4081                  totrunentrymin -= (totrunentrymin-iev); // shift run position min
4082                  totrunentrymax -= (totrunentrymin-iev); // shift run position max
4083                  if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);
4084                  //              printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI
4085                } else {
4086                  printf(" PamLevel2::UpdateRunInfo(Long64_t) ERROR! sync file but unconsistent totrunetrymin %lld and iev %lld!!! \n",totrunentrymin,iev);
4087                  cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
4088                  cout << "\nFor bug reporting instructions, please see for example:\n";
4089                  cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
4090                  cout << "  " << endl;
4091                }
4092              }
4093              runfirstentry = totrunentrymin; // first entry of the run in the level2
4094              
4095    
4096              //
4097              if ( fUseDBinRunInfo ){
4098                if (gltsync)
4099                  delete gltsync; // Emiliano
4100                if (!dbc || (dbc && !dbc->IsConnected()))
4101                  SetDBConnection(); //Emiliano
4102                gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano
4103                TrkParams::Set(GetRunInfo(), dbc);
4104                if (dbc){
4105                  dbc->Close(); // Emiliano
4106                  delete dbc;
4107                  dbc=0;
4108                }          
4109                if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano
4110                  cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun
4111                       << "  has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;
4112                  cout
4113                    << "                                                            (NB!! in this case some events could be assigned to a wrong run)"
4114                    << endl;
4115                }
4116              }
4117              //
4118              if (DBG) printf(" found \n");
4119              //          printf(" found \n");//TOGLITOGLI
4120              //
4121              break;
4122            }
4123          } // loop over run
4124          
4125          // --------------------------------------
4126          // if there was no need to update the run
4127          // ---> exit with FALSE
4128          // --------------------------------------
4129          if (irun == oldrun){
4130            if (DBG) printf(" no new run \n");
4131            //        printf(" no new run \n");//TOGLITOGLI
4132            return (false);
4133          }      
4134          // --------------------------------------
4135          // ... otherwise
4136          // ---> exit with TRUE
4137          // --------------------------------------
4138    
4139          if (SELLI != 2) {
4140            /// decrement counters since this event belongs to a new run
4141            if (GetTrigLevel2()) {
4142              totdltime[0] -= GetTrigLevel2()->dltime[0];//live-time
4143              totdltime[1] -= GetTrigLevel2()->dltime[1];//dead-time
4144            }
4145            totdltime[2]--; //event counter
4146            if (DBG) {
4147              cout << endl;
4148              cout << "n.events     : " << totdltime[2] << endl;
4149              cout << "RUN LIVE-TIME: " << totdltime[0] * 0.16 << " ms" << endl;
4150              cout << "RUN DEAD-TIME: " << totdltime[1] * 0.01 << " ms" << endl;
4151            }
4152            // add an entry
4153            if (run_tree_clone && totdltime[2] > 0)
4154              if (run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
4155                run_tree_clone->GetBranch("DeadLiveTime")->Fill();
4156            // reset counters
4157            if ( totdltime[2] > 0 ){
4158              if (GetTrigLevel2()) {
4159                totdltime[0] = GetTrigLevel2()->dltime[0];//live-time
4160                totdltime[1] = 0; //dead-time
4161              }
4162              totdltime[2] = 1; //event counter
4163            }
4164          }
4165    
4166          if (DBG){
4167            cout << endl << " ))))) UPDATE RUN INFO (((((  @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun
4168                 << endl;        
4169            printf("2abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4170            printf("2        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4171            printf("2        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4172            if ( fUseDBinRunInfo ) printf("2        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4173            printf("2        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4174            printf("2        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);
4175          }
4176          //        printf("2abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
4177          //        printf("2        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
4178          //        printf("2        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
4179          //        printf("2        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
4180          //        printf("2        bo irunentry %lld prevshift %lld irun %lld  \n",irunentry,prevshift,irun);
4181          //        printf("2        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);//TOGLITOGLI
4182    
4183          return (true);
4184        } // need for run upgrade
4185        if (DBG) printf("return false\n");
4186        return (false);
4187      }// SELLI = 0 SELLI = 2
4188      
4189      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
4190      // if it is a preselected file (there is SelectionList)
4191      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
4192      // irun  = run entry relative to the chain
4193      // irunt = run entry relative to the tree
4194      if (SELLI == 1) {
4195        sel_tree->GetEntry(iev);// read irunt from SelectionList
4196        irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
4197        if (irun != oldrun) {
4198          if (irun < run_tree->GetEntries())
4199            run_tree->GetEntry(irun);
4200          // check if the time is ok (with merged files it is not...)
4201          // if not loop over run and look for the proper entry
4202          bool SECONDO_GIRO = false;
4203          //            Long64_t irun_start   = irun;
4204          int offset_start = irunoffset[sel_tree->GetTreeNumber()];
4205          while (((!(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s)
4206              abstime <= GetRunInfo()->RUNTRAILER_TIME)
4207          //                        ||
4208          //                        !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
4209          //                          obt <= GetRunInfo()->RUNTRAILER_OBT)
4210          ) || GetRunInfo()->NEVENTS == 0)
4211          //                && irun < run_tree->GetEntries()
4212          ) {
4213    
4214            if (DBG) {
4215              cout << " (test) ";
4216              cout << " tree " << sel_tree->GetTreeNumber();
4217              cout << " irunt " << irunt;
4218              cout << " offset " << irunoffset[sel_tree->GetTreeNumber()];
4219              cout << " abs " << abstime;
4220              cout << " >> " << GetRunInfo()->RUNHEADER_TIME << " " << GetRunInfo()->RUNTRAILER_TIME;
4221              cout << " obt " << obt;
4222              cout << " >> " << GetRunInfo()->RUNHEADER_OBT << " " << GetRunInfo()->RUNTRAILER_OBT;
4223              cout << " *** JUMP RUN *** irun " << irun;
4224              cout << endl;
4225            }
4226            //              irun++;
4227            irunoffset[sel_tree->GetTreeNumber()]++;
4228            irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
4229            if (irun == run_tree->GetEntries() && SECONDO_GIRO) {
4230              //            if(irun == irun_start ){
4231              cout << " ...grrrvzzkhhhajsdkj!!!! " << endl;
4232              irunoffset[sel_tree->GetTreeNumber()] = offset_start;
4233              return false;
4234            }
4235            if (irun >= run_tree->GetEntries() || irun < 0) {
4236              cout << "irun = " << irun << " >>  search from the beginning... <<" << endl;
4237              SECONDO_GIRO = true;
4238              irun = 0;
4239              irunoffset[sel_tree->GetTreeNumber()] = -irunt;
4240            }
4241            run_tree->GetEntry(irun);
4242          }
4243    
4244          if (DBG) {
4245            cout << " (test) ";
4246            cout << " tree " << sel_tree->GetTreeNumber();
4247            cout << " irunt " << irunt;
4248            cout << " offset " << irunoffset[sel_tree->GetTreeNumber()];
4249            cout << " abs " << abstime;
4250            cout << " >> " << GetRunInfo()->RUNHEADER_TIME << " " << GetRunInfo()->RUNTRAILER_TIME;
4251            cout << " obt " << obt;
4252            cout << " >> " << GetRunInfo()->RUNHEADER_OBT << " " << GetRunInfo()->RUNTRAILER_OBT;
4253          }
4254          if (DBG)
4255            cout << endl;
4256          if (DBG)
4257            cout << endl << " ))))) UPDATE RUN INFO (((((  @iev " << iev << " run " << GetRunInfo()->ID << " (run-entry "
4258                << irun << ")" << endl;
4259          // ----------------------------------------------------
4260          // update the tracker parameters
4261          // (non ho trovato nessun altro modo sicuro di farlo...)
4262          // ----------------------------------------------------
4263          if ( fUseDBinRunInfo ){
4264            if (!dbc || (dbc && !dbc->IsConnected()))
4265              SetDBConnection();
4266            TrkParams::Set(GetRunInfo(), dbc);
4267            if (dbc){
4268              dbc->Close();
4269              delete dbc;
4270              dbc=0;
4271            }
4272          }
4273          //            cout << endl;
4274          prevshift = 0;
4275          yprevshift = 0;
4276          return true;
4277        }
4278        return false;
4279      }
4280    
4281          // ------------------------------------------------------    return false;
4282          // loop over runs to find the one that contains the event    //
4283          // ------------------------------------------------------  }
         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 >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)  
                   obt <= GetRunInfo()->RUNTRAILER_OBT)            
                 ||  
                 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(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  
                     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  
                     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(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){  
                 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;                
         }  
   
         return(true);      
     };  
     // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-  
     // if it is a preselected file (there is SelectionList)  
     // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-  
     // irun  = run entry relative to the chain  
     // irunt = run entry relative to the tree  
     if(SELLI==1){        
         sel_tree->GetEntry(iev);// read irunt from SelectionList  
         irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW  
         if(irun != oldrun ){  
             if( irun < run_tree->GetEntries() )run_tree->GetEntry(irun);  
             // check if the time is ok (with merged files it is not...)  
             // if not loop over run and look for the proper entry  
             bool SECONDO_GIRO=false;  
             //      Long64_t irun_start   = irun;  
             int      offset_start = irunoffset[sel_tree->GetTreeNumber()];  
             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)  
                         )  
                     || GetRunInfo()->NEVENTS==0  
                     )  
 //              && irun < run_tree->GetEntries()  
                 ){  
   
                 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;  
                     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);  
             }  
   
4284    
4285              if(DBG){  /**
4286                  cout << " (test) ";   * Update the runinfo informations (to be used to have Run infos event by event basis)
4287                  cout << " tree "<<sel_tree->GetTreeNumber();   * @param run Pointer to the chain/tree which contains run infos
4288                  cout << " irunt "<<irunt;   * @return true if a new run has been read, false if it is still the same run
4289                  cout << " offset "<<irunoffset[sel_tree->GetTreeNumber()];   */
4290                  cout << " abs "<<abstime;  Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) {
4291                  cout <<" >> "<<GetRunInfo()->RUNHEADER_TIME<<" "<<GetRunInfo()->RUNTRAILER_TIME;    return (UpdateRunInfo(iev));
4292                  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;  
     }  
4293    
     return false;  
     //  
 };  
4294  /**  /**
4295   * 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)
4296   * @param run Pointer to the chain/tree which contains run infos   * @param run Pointer to the chain/tree which contains run infos
4297   * @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
4298   */   */
4299  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev) {
4300      return(UpdateRunInfo((TChain*)run,iev));    return (UpdateRunInfo((TChain*) run, iev));
4301  };  }
4302    
4303    
4304  //--------------------------------------  //--------------------------------------
4305  //  //
# Line 2868  Bool_t PamLevel2::UpdateRunInfo(TTree *r Line 4307  Bool_t PamLevel2::UpdateRunInfo(TTree *r
4307  //--------------------------------------  //--------------------------------------
4308  /**  /**
4309   * Set which trees shoul be analysed   * Set which trees shoul be analysed
4310   * @param detlist TString containing the sequence of trees required   * @param detlist TString containing the sequence of trees required
4311   */   */
4312  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist) {
       
 //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){  
     if( detlist.Contains("+ALL", TString::kIgnoreCase)){  
4313    
4314          cout << " ======================================================== "<<endl;    //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
4315          cout << "                       (( WARNING ))                      "<<endl;    if (detlist.Contains("+ALL", TString::kIgnoreCase)) {
         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;  
     };  
4316    
4317      if( detlist.Contains("CAL0", TString::kIgnoreCase) ){      cout << " ======================================================== " << endl;
4318          if ( detlist.Contains("-CAL0", TString::kIgnoreCase) )CAL0=false;      cout << "                       (( WARNING ))                      " << endl;
4319          if ( detlist.Contains("+CAL0", TString::kIgnoreCase) )CAL0=true;      cout << " The meaning of the option +ALL has changed!!             " << endl;
4320      };      cout << " Now it includes really all (level0+level1+level2+gpamela)" << endl;
4321                cout << " and the file is discarded if it does not contain         " << endl;
4322      if( detlist.Contains("CAL2", TString::kIgnoreCase)){      cout << " all trees or  if level0 files are not available!!        " << endl;
4323          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;      cout << " ======================================================== " << endl;
         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;  
     };  
4324    
4325      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){      CAL0 = true;
4326          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;      CAL1 = true;
4327          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;      CAL2 = true;
4328      };      TRK2 = true;
4329                TRK1 = true;
4330      if( detlist.Contains("TRK2", TString::kIgnoreCase)){      TRKh = true;
4331          if ( detlist.Contains("-TRK2", TString::kIgnoreCase) )TRK2=false;      TRK0 = true;
4332          if ( detlist.Contains("+TRK2", TString::kIgnoreCase) )TRK2=true;      TRG = true;
4333      };      TOF = true;
4334        TOF0 = true;
4335        S4 = true;
4336        ND = true;
4337        AC = true;
4338        ORB = true;
4339        GP = true;
4340      }
4341      else if (detlist.Contains("-ALL", TString::kIgnoreCase)) {
4342        CAL0 = false;
4343        CAL1 = false;
4344        CAL2 = false;
4345        TRK2 = false;
4346        TRK1 = false;
4347        TRKh = false;
4348        TRK0 = false;
4349        TRG = false;
4350        TOF = false;
4351        TOF0 = false;
4352        S4 = false;
4353        ND = false;
4354        AC = false;
4355        ORB = false;
4356        GP = false;
4357      };
4358    
4359      //  -------------------------------------------------------------------------
4360      if (detlist.Contains("CAL1", TString::kIgnoreCase)) {
4361        if (detlist.Contains("-CAL1", TString::kIgnoreCase))
4362          CAL1 = false;
4363        if (detlist.Contains("+CAL1", TString::kIgnoreCase))
4364          CAL1 = true;
4365      };
4366    
4367      if (detlist.Contains("CAL0", TString::kIgnoreCase)) {
4368        if (detlist.Contains("-CAL0", TString::kIgnoreCase))
4369          CAL0 = false;
4370        if (detlist.Contains("+CAL0", TString::kIgnoreCase))
4371          CAL0 = true;
4372      };
4373    
4374      if (detlist.Contains("CAL2", TString::kIgnoreCase)) {
4375        if (detlist.Contains("-CAL2", TString::kIgnoreCase))
4376          CAL2 = false;
4377        if (detlist.Contains("+CAL2", TString::kIgnoreCase))
4378          CAL2 = true;
4379      };
4380    
4381      if( detlist.Contains("TRKh", TString::kIgnoreCase)){    if (detlist.Contains("+CAL", TString::kIgnoreCase) && !CAL1 && !CAL2)
4382          if ( detlist.Contains("-TRKh", TString::kIgnoreCase) )TRKh=false;      CAL2 = true;
4383          if ( detlist.Contains("+TRKh", TString::kIgnoreCase) )TRKh=true;    if (detlist.Contains("-CAL", TString::kIgnoreCase) && CAL1 && CAL2) {
4384      };      CAL2 = false;
4385                CAL1 = false;
4386      if( detlist.Contains("+TRK", TString::kIgnoreCase) && !TRK1 && !TRK2 && !TRKh )TRK2=true;    }
4387      if( detlist.Contains("-TRK", TString::kIgnoreCase) && TRK1 && TRK2 && TRKh){    //  -------------------------------------------------------------------------
4388          TRK2=false;    if (detlist.Contains("TRK0", TString::kIgnoreCase)) {
4389          TRK1=false;      if (detlist.Contains("-TRK0", TString::kIgnoreCase))
4390          TRKh=false;        TRK0 = false;
4391      }      if (detlist.Contains("+TRK0", TString::kIgnoreCase))
4392  //  -------------------------------------------------------------------------        TRK0 = true;
4393          };
4394      if( detlist.Contains("-TRG", TString::kIgnoreCase) )TRG = false;  
4395      else if( detlist.Contains("+TRG", TString::kIgnoreCase) )TRG = true;    if (detlist.Contains("TRK1", TString::kIgnoreCase)) {
4396            if (detlist.Contains("-TRK1", TString::kIgnoreCase))
4397      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;        TRK1 = false;
4398      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;      if (detlist.Contains("+TRK1", TString::kIgnoreCase))
4399          TRK1 = true;
4400      };
4401    
4402      if (detlist.Contains("TRK2", TString::kIgnoreCase)) {
4403        if (detlist.Contains("-TRK2", TString::kIgnoreCase))
4404          TRK2 = false;
4405        if (detlist.Contains("+TRK2", TString::kIgnoreCase))
4406          TRK2 = true;
4407      };
4408    
4409      if (detlist.Contains("TRKh", TString::kIgnoreCase)) {
4410        if (detlist.Contains("-TRKh", TString::kIgnoreCase))
4411          TRKh = false;
4412        if (detlist.Contains("+TRKh", TString::kIgnoreCase))
4413          TRKh = true;
4414      };
4415    
4416      if( detlist.Contains("-TOF0", TString::kIgnoreCase) )TOF0 = false;    if (detlist.Contains("+TRK", TString::kIgnoreCase) && !TRK1 && !TRK2 && !TRKh)
4417      else if( detlist.Contains("+TOF0", TString::kIgnoreCase) )TOF0 = true;      TRK2 = true;
4418          if (detlist.Contains("-TRK", TString::kIgnoreCase) && TRK1 && TRK2 && TRKh) {
4419      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;      TRK2 = false;
4420      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;      TRK1 = false;
4421            TRKh = false;
4422      if( detlist.Contains("-ND",  TString::kIgnoreCase) )ND  = false;    }
4423      else if( detlist.Contains("+ND",  TString::kIgnoreCase) )ND  = true;    //  -------------------------------------------------------------------------
       
     if( detlist.Contains("-AC",  TString::kIgnoreCase) )AC  = false;  
     else if( detlist.Contains("+AC",  TString::kIgnoreCase) )AC  = true;  
       
     if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;  
     else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;  
4424    
4425      if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false;    if (detlist.Contains("-TRG", TString::kIgnoreCase))
4426      else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true;      TRG = false;
4427      else if (detlist.Contains("+TRG", TString::kIgnoreCase))
4428        TRG = true;
4429    
4430      if (detlist.Contains("-TOF", TString::kIgnoreCase))
4431        TOF = false;
4432      else if (detlist.Contains("+TOF", TString::kIgnoreCase))
4433        TOF = true;
4434    
4435      cout<< "tree/branch list from input --> ";    if (detlist.Contains("-TOF0", TString::kIgnoreCase))
4436      if(TRK0)cout<<"TRK0 ";      TOF0 = false;
4437      if(TRK1)cout<<"TRK1 ";    else if (detlist.Contains("+TOF0", TString::kIgnoreCase))
4438      if(TRK2)cout<<"TRK2 ";      TOF0 = true;
4439      if(TRKh)cout<<"TRKH ";  
4440      if(CAL0)cout<<"CAL0 ";    if (detlist.Contains("-S4", TString::kIgnoreCase))
4441      if(CAL1)cout<<"CAL1 ";      S4 = false;
4442      if(CAL2)cout<<"CAL2 ";    else if (detlist.Contains("+S4", TString::kIgnoreCase))
4443      if(TOF)cout<<"TOF ";      S4 = true;
4444      if(TRG)cout<<"TRG ";  
4445      if(AC)cout<<"AC ";    if (detlist.Contains("-ND", TString::kIgnoreCase))
4446      if(ND)cout<<"ND ";      ND = false;
4447      if(S4)cout<<"S4 ";    else if (detlist.Contains("+ND", TString::kIgnoreCase))
4448      if(ORB)cout<<"ORB ";      ND = true;
4449      if(GP)cout<<"GP ";  
4450      cout << endl;    if (detlist.Contains("-AC", TString::kIgnoreCase))
4451  //     cout<< "Set detector list --> ";      AC = false;
4452  //     if(TRK1)cout<<"TRK1 ";    else if (detlist.Contains("+AC", TString::kIgnoreCase))
4453  //     if(TRK2)cout<<"TRK2 ";      AC = true;
4454  //     if(TRKh)cout<<"TRKH ";  
4455  //     if(CAL1)cout<<"CAL1 ";    if (detlist.Contains("-ORB", TString::kIgnoreCase))
4456  //     if(CAL2)cout<<"CAL2 ";      ORB = false;
4457  //     if(TOF0)cout<<"TOF0 ";    else if (detlist.Contains("+ORB", TString::kIgnoreCase))
4458  //     if(TOF)cout<<"TOF ";      ORB = true;
4459  //     if(TRG)cout<<"TRG ";  
4460  //     if(AC)cout<<"AC ";    if (detlist.Contains("-GP", TString::kIgnoreCase))
4461  //     if(ND)cout<<"ND ";      GP = false;
4462  //     if(S4)cout<<"S4 ";    else if (detlist.Contains("+GP", TString::kIgnoreCase))
4463  //     if(ORB)cout<<"ORB ";      GP = true;
4464  //     cout << endl;  
4465          cout << "tree/branch list from input --> ";
4466  };    if (TRK0)
4467        cout << "TRK0 ";
4468      if (TRK1)
4469        cout << "TRK1 ";
4470      if (TRK2)
4471        cout << "TRK2 ";
4472      if (TRKh)
4473        cout << "TRKH ";
4474      if (CAL0)
4475        cout << "CAL0 ";
4476      if (CAL1)
4477        cout << "CAL1 ";
4478      if (CAL2)
4479        cout << "CAL2 ";
4480      if (TOF)
4481        cout << "TOF ";
4482      if (TRG)
4483        cout << "TRG ";
4484      if (AC)
4485        cout << "AC ";
4486      if (ND)
4487        cout << "ND ";
4488      if (S4)
4489        cout << "S4 ";
4490      if (ORB)
4491        cout << "ORB ";
4492      if (GP)
4493        cout << "GP ";
4494      cout << endl;
4495      //     cout<< "Set detector list --> ";
4496      //     if(TRK1)cout<<"TRK1 ";
4497      //     if(TRK2)cout<<"TRK2 ";
4498      //     if(TRKh)cout<<"TRKH ";
4499      //     if(CAL1)cout<<"CAL1 ";
4500      //     if(CAL2)cout<<"CAL2 ";
4501      //     if(TOF0)cout<<"TOF0 ";
4502      //     if(TOF)cout<<"TOF ";
4503      //     if(TRG)cout<<"TRG ";
4504      //     if(AC)cout<<"AC ";
4505      //     if(ND)cout<<"ND ";
4506      //     if(S4)cout<<"S4 ";
4507      //     if(ORB)cout<<"ORB ";
4508      //     cout << endl;
4509    
4510    }
4511    ;
4512    
4513  /**  /**
4514   * Set tree/branch detector flags from the content of a tree   * Set tree/branch detector flags from the content of a tree
4515   */   */
4516  void  PamLevel2::GetWhichTrees(TFile* f){  void PamLevel2::GetWhichTrees(TFile* f) {
       
   
   
 //    cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;  
     // -----------  
     // 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();  
     TIter next(lk);  
     TKey *key =0;  
4517    
4518      Int_t nev = 0;    //    cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
4519      // -----------
4520      // reset flags
4521      // -----------
4522      CAL1 = false;
4523      CAL2 = false;
4524      TRK2 = false;
4525      TRK1 = false;
4526      TRKh = false;
4527      TRG = false;
4528      TOF = false;
4529      S4 = false;
4530      ND = false;
4531      AC = false;
4532      ORB = false;
4533      GP = false;
4534    
4535      RUN = false;
4536    
4537      //    cout << "Checking file: "<<f->GetName()<<endl;
4538      if (!f || f->IsZombie()) {
4539        cout << "File: " << f->GetName() << " Non valid root file" << endl;
4540        return;
4541      }
4542    
4543      TList *lk = f->GetListOfKeys();
4544      if (!lk)
4545        return;
4546      TIter next(lk);
4547      TKey *key = 0;
4548    
4549      Int_t nev = 0;
4550    
4551      while ((key = (TKey*) next())) {
4552    
4553        if (!strcmp(key->GetName(), "Run"))
4554          RUN = true;
4555    
4556        //=========================================================
4557        if (!strcmp(key->GetName(), "Trigger")) {
4558          TRG = true;
4559          Int_t nevt = ((TTree*) f->Get("Trigger"))->GetEntries();
4560          if (nev && nevt != nev) {
4561            cout << "File: " << f->GetName() << " Trigger tree has " << nevt << " events instead of " << nev << endl;
4562            TRG = false;
4563          }
4564          else
4565            nev = nevt;
4566        }
4567        //=========================================================
4568        if (!strcmp(key->GetName(), "ToF")) {
4569          TOF = true;
4570          Int_t nevt = ((TTree*) f->Get("ToF"))->GetEntries();
4571          if (nev && nevt != nev) {
4572            cout << "File: " << f->GetName() << "     ToF tree has " << nevt << " events instead of " << nev << endl;
4573            TOF = false;
4574          }
4575          else
4576            nev = nevt;
4577        }
4578        //=========================================================
4579        if (!strcmp(key->GetName(), "S4")) {
4580          S4 = true;
4581          Int_t nevt = ((TTree*) f->Get("S4"))->GetEntries();
4582          if (nev && nevt != nev) {
4583            cout << "File: " << f->GetName() << "      S4 tree has " << nevt << " events instead of " << nev << endl;
4584            S4 = false;
4585          }
4586          else
4587            nev = nevt;
4588        }
4589        //=========================================================
4590    
4591        if (!strcmp(key->GetName(), "NeutronD")) {
4592          ND = true;
4593          Int_t nevt = ((TTree*) f->Get("NeutronD"))->GetEntries();
4594          if (nev && nevt != nev) {
4595            cout << "File: " << f->GetName() << "NeutronD tree has " << nevt << " events instead of " << nev << endl;
4596            ND = false;
4597          }
4598          else
4599            nev = nevt;
4600        }
4601        //=========================================================
4602        if (!strcmp(key->GetName(), "Anticounter")) {
4603          AC = true;
4604          Int_t nevt = ((TTree*) f->Get("Anticounter"))->GetEntries();
4605          if (nev && nevt != nev) {
4606            cout << "File: " << f->GetName() << " Anticounter tree has " << nevt << " events instead of " << nev << endl;
4607            AC = false;
4608          }
4609          else
4610            nev = nevt;
4611        }
4612        //=========================================================
4613        if (!strcmp(key->GetName(), "OrbitalInfo")) {
4614          ORB = true;
4615          Int_t nevt = ((TTree*) f->Get("OrbitalInfo"))->GetEntries();
4616          if (nev && nevt != nev) {
4617            cout << "File: " << f->GetName() << " OrbitalInfo tree has " << nevt << " events instead of " << nev << endl;
4618            ORB = false;
4619          }
4620          else
4621            nev = nevt;
4622        }
4623        //=========================================================
4624        if (!strcmp(key->GetName(), "Tracker")) {
4625          TTree *T = (TTree*) f->Get("Tracker");
4626          for (Int_t i = 0; i < T->GetListOfBranches()->GetEntries(); i++) {
4627            TString name = T->GetListOfBranches()->At(i)->GetName();
4628            if (!name.CompareTo("TrkLevel1"))
4629              TRK1 = true;
4630            if (!name.CompareTo("TrkLevel2"))
4631              TRK2 = true;
4632            if (!name.CompareTo("TrkHough"))
4633              TRKh = true;
4634          };
4635          Int_t nevt = T->GetEntries();
4636          if (nev && nevt != nev) {
4637            cout << "File: " << f->GetName() << " Tracker tree has " << nevt << " events instead of " << nev << endl;
4638            TRK1 = false;
4639            TRK2 = false;
4640            TRKh = false;
4641          }
4642          else
4643            nev = nevt;
4644          //            T->Delete();
4645        };
4646        //=========================================================
4647        if (!strcmp(key->GetName(), "Calorimeter")) {
4648          TTree *T = (TTree*) f->Get("Calorimeter");
4649          for (Int_t i = 0; i < T->GetListOfBranches()->GetEntries(); i++) {
4650            TString name = T->GetListOfBranches()->At(i)->GetName();
4651            if (!name.CompareTo("CaloLevel1"))
4652              CAL1 = true;
4653            if (!name.CompareTo("CaloLevel2"))
4654              CAL2 = true;
4655          };
4656          Int_t nevt = T->GetEntries();
4657          if (nev && nevt != nev) {
4658            cout << "File: " << f->GetName() << "  Calorimeter tree has " << nevt << " events instead of " << nev << endl;
4659            CAL1 = false;
4660            CAL2 = false;
4661          }
4662          else
4663            nev = nevt;
4664          //            T->Delete();
4665        };
4666        //=========================================================
4667        if (!strcmp(key->GetName(), "h20")) {
4668          GP = true;
4669          Int_t nevt = ((TTree*) f->Get("h20"))->GetEntries();
4670          if (nev && nevt != nev) {
4671            cout << "File: " << f->GetName() << " h20 tree has " << nevt << " events instead of " << nev << endl;
4672            GP = false;
4673          }
4674          else
4675            nev = nevt;
4676        }
4677    
4678      };
4679    
4680      //    delete lk;
4681    
4682      cout << "tree/branch list from file  --> ";
4683      if (TRK1)
4684        cout << "TRK1 ";
4685      if (TRK2)
4686        cout << "TRK2 ";
4687      if (TRKh)
4688        cout << "TRKH ";
4689      if (CAL1)
4690        cout << "CAL1 ";
4691      if (CAL2)
4692        cout << "CAL2 ";
4693      if (TOF)
4694        cout << "TOF ";
4695      if (TRG)
4696        cout << "TRG ";
4697      if (AC)
4698        cout << "AC ";
4699      if (ND)
4700        cout << "ND ";
4701      if (S4)
4702        cout << "S4 ";
4703      if (ORB)
4704        cout << "ORB ";
4705      if (GP)
4706        cout << "GP ";
4707      cout << endl;
4708    
4709      while( (key = (TKey*)next()) ){    return;
           
         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;  
         }  
   
     };  
       
 //    delete lk;  
   
     cout<< "tree/branch list from file  --> ";  
     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 ;  
           
 };  
4710    
4711    }
4712    ;
4713    
4714  //--------------------------------------  //--------------------------------------
4715  //  //
# Line 3198  void  PamLevel2::GetWhichTrees(TFile* f) Line 4720  void  PamLevel2::GetWhichTrees(TFile* f)
4720   * @param name File name   * @param name File name
4721   * @return true if the file is ok.   * @return true if the file is ok.
4722   */   */
4723  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;  
             }  
         }  
         //=========================================================    
4724    
4725          if( !strcmp(key->GetName(),"NeutronD"   ) ){    Bool_t CAL1__ok = false;
4726              ND__ok = true;    Bool_t CAL2__ok = false;
4727              if(ND){    Bool_t TRK2__ok = false;
4728                  Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries();    Bool_t TRK1__ok = false;
4729                  if( nev && nevt!=nev){    Bool_t TRKh__ok = false;
4730                      cout << "File: "<< f->GetName() <<" discarded ---- NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl;    Bool_t TRG__ok = false;
4731                      return false;    Bool_t TOF__ok = false;
4732                  }    Bool_t S4__ok = false;
4733                  nev=nevt;    Bool_t ND__ok = false;
4734              }    Bool_t AC__ok = false;
4735          }          Bool_t ORB__ok = false;
4736          //=========================================================      Bool_t GP__ok = false;
4737          if( !strcmp(key->GetName(),"Anticounter") ){  
4738              AC__ok = true;    Bool_t RUN__ok = false;
4739              if(AC){  
4740                  Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries();    Bool_t SELLI__ok = false;
4741                  if( nev && nevt!=nev){  
4742                      cout << "File: "<< f->GetName() <<" discarded ---- Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl;    //    cout << "Checking file: "<<name<<endl;
4743                      return false;    TFile *f = new TFile(name.Data());
4744                  }    if (!f || f->IsZombie()) {
4745                  nev=nevt;      cout << "File: " << f->GetName() << " discarded ---- Non valid root file" << endl;
4746              }      return false;
4747          }    }
4748          //=========================================================      //    cout << "Get list of keys: "<<f<<endl;
4749          if( !strcmp(key->GetName(),"OrbitalInfo") ){    TList *lk = f->GetListOfKeys();
4750              ORB__ok = true;    //    lk->Print();
4751              if(ORB){    TIter next(lk);
4752                  Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries();    TKey *key = 0;
4753                  if( nev && nevt!=nev){  
4754                      cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;    Int_t nev = 0;
4755                      return false;  
4756                  }    while ((key = (TKey*) next())) {
4757                  nev=nevt;  
4758              }      //  cout << key->GetName() << endl;
4759          }      //  cout << key->GetName() << ""<<key->GetClassName()<<endl;
4760          //=========================================================        //          cout << " Get tree: " << f->Get(key->GetName())<<endl;
4761          if( !strcmp(key->GetName(),"Tracker"    ) ){      //  nev_previous = nev;
4762              TTree *T = (TTree*)f->Get("Tracker");      //  cout << " n.entries  "<< nev <<endl;
4763              if(TRK1||TRK2||TRKh){      //  if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){
4764                  Int_t nevt = T->GetEntries();      //      nev = ((TTree*)f->Get(key->GetName()))->GetEntries();
4765                  if( nev && nevt!=nev){      //      cout << "File: "<< f->GetName() <<" discarded ---- "<< key->GetName() << " tree: n.entries does not match "<<nev<<" "<<nev_previous<< endl;
4766                      cout << "File: "<< f->GetName() <<" discarded ---- Tracker tree has "<<nevt<<" events instead of "<<nev<< endl;      //      return false;
4767                      return false;      //  };
4768                  }  
4769                  nev=nevt;      //=========================================================
4770              }      // check if the file
4771              for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){  
4772                  TString name = T->GetListOfBranches()->At(i)->GetName();  
4773                  if( !name.CompareTo("TrkLevel1") )TRK1__ok=true;      if (!strcmp(key->GetName(), "Run"))
4774                  if( !name.CompareTo("TrkLevel2") )TRK2__ok=true;        RUN__ok = true;
4775                  if( !name.CompareTo("TrkHough") )TRKh__ok=true;  
4776              };            //=========================================================
4777              T->Delete();      if (!strcmp(key->GetName(), "SelectionList")) {
4778          };        SELLI__ok = true;
4779          //=========================================================          if (SELLI == 1) {
4780          if( !strcmp(key->GetName(),"Calorimeter"    ) ){          Int_t nevt = ((TTree*) f->Get("SelectionList"))->GetEntries();
4781              TTree *T = (TTree*)f->Get("Calorimeter");          if (nev && nevt != nev) {
4782              if(CAL1||CAL2){            cout << "File: " << f->GetName() << " discarded ---- SelectionList tree has " << nevt
4783                  Int_t nevt = T->GetEntries();                << " events instead of " << nev << endl;
4784                  if( nev && nevt!=nev){            return false;
4785                      cout << "File: "<< f->GetName() <<" discarded ---- Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl;          }
4786                      return false;          nev = nevt;
4787                  }        }
4788                  nev=nevt;      }
4789              }  
4790              for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){      //=========================================================
4791                  TString name = T->GetListOfBranches()->At(i)->GetName();      if (!strcmp(key->GetName(), "Trigger")) {
4792                  if( !name.CompareTo("CaloLevel1") )CAL1__ok=true;        TRG__ok = true;
4793                  if( !name.CompareTo("CaloLevel2") )CAL2__ok=true;        if (TRG) {
4794              };              Int_t nevt = ((TTree*) f->Get("Trigger"))->GetEntries();
4795              T->Delete();          if (nev && nevt != nev) {
4796          };                  cout << "File: " << f->GetName() << " discarded ---- Trigger tree has " << nevt << " events instead of "
4797          //=========================================================                    << nev << endl;
4798          if( !strcmp(key->GetName(),"h20") ){            return false;
4799              ISGP = true;              }
4800              GP__ok = true;          nev = nevt;
4801              if(GP){        }
4802                  Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();      }
4803                  if( nev && nevt!=nev){      //=========================================================
4804                      cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;      if (!strcmp(key->GetName(), "ToF")) {
4805                      return false;        TOF__ok = true;
4806                  }        if (TOF) {
4807                  nev=nevt;          Int_t nevt = ((TTree*) f->Get("ToF"))->GetEntries();
4808              }          if (nev && nevt != nev) {
4809          }            cout << "File: " << f->GetName() << " discarded ---- ToF tree has " << nevt << " events instead of " << nev
4810                  << endl;
4811              return false;
4812            }
4813            nev = nevt;
4814          }
4815        }
4816        //=========================================================
4817        if (!strcmp(key->GetName(), "S4")) {
4818          S4__ok = true;
4819          if (S4) {
4820            Int_t nevt = ((TTree*) f->Get("S4"))->GetEntries();
4821            if (nev && nevt != nev) {
4822              cout << "File: " << f->GetName() << " discarded ---- S4 tree has " << nevt << " events instead of " << nev
4823                  << endl;
4824              return false;
4825            }
4826            nev = nevt;
4827          }
4828        }
4829        //=========================================================
4830    
4831        if (!strcmp(key->GetName(), "NeutronD")) {
4832          ND__ok = true;
4833          if (ND) {
4834            Int_t nevt = ((TTree*) f->Get("NeutronD"))->GetEntries();
4835            if (nev && nevt != nev) {
4836              cout << "File: " << f->GetName() << " discarded ---- NeutronD tree has " << nevt << " events instead of "
4837                  << nev << endl;
4838              return false;
4839            }
4840            nev = nevt;
4841          }
4842        }
4843        //=========================================================
4844        if (!strcmp(key->GetName(), "Anticounter")) {
4845          AC__ok = true;
4846          if (AC) {
4847            Int_t nevt = ((TTree*) f->Get("Anticounter"))->GetEntries();
4848            if (nev && nevt != nev) {
4849              cout << "File: " << f->GetName() << " discarded ---- Anticounter tree has " << nevt << " events instead of "
4850                  << nev << endl;
4851              return false;
4852            }
4853            nev = nevt;
4854          }
4855        }
4856        //=========================================================
4857        if (!strcmp(key->GetName(), "OrbitalInfo")) {
4858          ORB__ok = true;
4859          if (ORB) {
4860            Int_t nevt = ((TTree*) f->Get("OrbitalInfo"))->GetEntries();
4861            if (nev && nevt != nev) {
4862              cout << "File: " << f->GetName() << " discarded ---- OrbitalInfo tree has " << nevt << " events instead of "
4863                  << nev << endl;
4864              return false;
4865            }
4866            nev = nevt;
4867          }
4868        }
4869        //=========================================================
4870        if (!strcmp(key->GetName(), "Tracker")) {
4871          TTree *T = (TTree*) f->Get("Tracker");
4872          if (TRK1 || TRK2 || TRKh) {
4873            Int_t nevt = T->GetEntries();
4874            if (nev && nevt != nev) {
4875              cout << "File: " << f->GetName() << " discarded ---- Tracker tree has " << nevt << " events instead of "
4876                  << nev << endl;
4877              return false;
4878            }
4879            nev = nevt;
4880          }
4881          for (Int_t i = 0; i < T->GetListOfBranches()->GetEntries(); i++) {
4882            TString name = T->GetListOfBranches()->At(i)->GetName();
4883            if (!name.CompareTo("TrkLevel1"))
4884              TRK1__ok = true;
4885            if (!name.CompareTo("TrkLevel2"))
4886              TRK2__ok = true;
4887            if (!name.CompareTo("TrkHough"))
4888              TRKh__ok = true;
4889          };
4890          T->Delete();
4891        };
4892        //=========================================================
4893        if (!strcmp(key->GetName(), "Calorimeter")) {
4894          TTree *T = (TTree*) f->Get("Calorimeter");
4895          if (CAL1 || CAL2) {
4896            Int_t nevt = T->GetEntries();
4897            if (nev && nevt != nev) {
4898              cout << "File: " << f->GetName() << " discarded ---- Calorimeter tree has " << nevt << " events instead of "
4899                  << nev << endl;
4900              return false;
4901            }
4902            nev = nevt;
4903          }
4904          for (Int_t i = 0; i < T->GetListOfBranches()->GetEntries(); i++) {
4905            TString name = T->GetListOfBranches()->At(i)->GetName();
4906            if (!name.CompareTo("CaloLevel1"))
4907              CAL1__ok = true;
4908            if (!name.CompareTo("CaloLevel2"))
4909              CAL2__ok = true;
4910          };
4911          T->Delete();
4912        };
4913        //=========================================================
4914        if (!strcmp(key->GetName(), "h20")) {
4915          ISGP = true;
4916          GP__ok = true;
4917          if (GP) {
4918            Int_t nevt = ((TTree*) f->Get("h20"))->GetEntries();
4919            if (nev && nevt != nev) {
4920              cout << "File: " << f->GetName() << " discarded ---- h20 tree has " << nevt << " events instead of " << nev
4921                  << endl;
4922              return false;
4923            }
4924            nev = nevt;
4925          }
4926        }
4927    
4928      };
4929    
4930      if (SELLI == -1)
4931        SELLI = (Int_t) SELLI__ok;
4932      if (SELLI == 0 && SELLI__ok) {
4933        cout << "File: " << f->GetName() << " discarded ---- found SelectionList (it is not a full-event file)" << endl;
4934        return false;
4935      }
4936      if (SELLI == 1 && !SELLI__ok) {
4937        cout << "File: " << f->GetName() << " discarded ---- SelectionList missing" << endl;
4938        return false;
4939      }
4940    
4941      };    //    cout << "SELLI "<<SELLI<<endl;
4942    
4943      if( SELLI==-1 )SELLI = (Int_t)SELLI__ok;    //     cout<< "CheckLevel2File(TString): detector list --> ";
4944      if( SELLI==0 && SELLI__ok ){    //     if(TRK1__ok)cout<<"TRK1 ";
4945          cout << "File: "<< f->GetName() <<" discarded ---- found SelectionList (it is not a full-event file)" << endl;    //     if(TRK2__ok)cout<<"TRK2 ";
4946          return false;      //     if(TRKh__ok)cout<<"TRKH ";
4947      }    //     if(CAL1__ok)cout<<"CAL1 ";
4948      if( SELLI==1 && !SELLI__ok ){    //     if(CAL2__ok)cout<<"CAL2 ";
4949          cout << "File: "<< f->GetName() <<" discarded ---- SelectionList missing" << endl;    //     if(TOF__ok)cout<<"TOF ";
4950          return false;    //     if(TRG__ok)cout<<"TRG ";
4951      }    //     if(AC__ok)cout<<"AC ";
4952          //     if(ND__ok)cout<<"ND ";
4953  //    cout << "SELLI "<<SELLI<<endl;    //     if(S4__ok)cout<<"S4 ";
4954      //     if(ORB__ok)cout<<"ORB ";
4955      //     cout << endl;
4956    
4957    
4958      if (TRK2 && TRK1__ok)
4959        TRK1 = 1;
4960      // ----------------------------------------------------------------------------
4961      // NOTA
4962      // se c'e` il level1, lo devo necessarimente leggere.
4963      // infatti (non ho capito perche`) i cluster vengono letti e allocati in memoria
4964      // comunque, ma non vengono disallocati da PamLevel2::Clear()
4965      // ----------------------------------------------------------------------------
4966    
4967    
4968      if (!RUN__ok) {
4969        cout << "File: " << f->GetName() << " *WARNING* ---- Missing RunInfo tree (NB: RUN infos will not be updated)"
4970            << endl;
4971        RUN = false;
4972      };
4973    
4974  //     cout<< "CheckLevel2File(TString): detector list --> ";    if (CAL1 && !CAL1__ok) {
4975  //     if(TRK1__ok)cout<<"TRK1 ";      cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel1 branch" << endl;
4976  //     if(TRK2__ok)cout<<"TRK2 ";      return false;
4977  //     if(TRKh__ok)cout<<"TRKH ";    };
4978  //     if(CAL1__ok)cout<<"CAL1 ";    if (CAL2 && !CAL2__ok) {
4979  //     if(CAL2__ok)cout<<"CAL2 ";      cout << "File: " << f->GetName() << " discarded ---- Missing CaloLevel2 branch" << endl;
4980  //     if(TOF__ok)cout<<"TOF ";      return false;
4981  //     if(TRG__ok)cout<<"TRG ";    };
4982  //     if(AC__ok)cout<<"AC ";    if (TRK2 && !TRK2__ok) {
4983  //     if(ND__ok)cout<<"ND ";      cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel2 branch" << endl;
4984  //     if(S4__ok)cout<<"S4 ";      return false;
4985  //     if(ORB__ok)cout<<"ORB ";    };
4986  //     cout << endl;    if (TRK1 && !TRK1__ok) {
4987        cout << "File: " << f->GetName() << " discarded ---- Missing TrkLevel1 branch" << endl;
4988        return false;
4989      if(TRK2 && TRK1__ok)TRK1=1;    };
4990  // ----------------------------------------------------------------------------    if (TRKh && !TRKh__ok) {
4991  // NOTA      cout << "File: " << f->GetName() << " discarded ---- Missing TrkHough branch" << endl;
4992  // se c'e` il level1, lo devo necessarimente leggere.      return false;
4993  // infatti (non ho capito perche`) i cluster vengono letti e allocati in memoria    };
4994  // comunque, ma non vengono disallocati da PamLevel2::Clear()    if (ORB && !ORB__ok) {
4995  // ----------------------------------------------------------------------------      cout << "File: " << f->GetName() << " discarded ---- Missing ORB tree" << endl;
4996        return false;
4997      };
4998      if(!RUN__ok) {    if (AC && !AC__ok) {
4999          cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree (NB: RUN infos will not be updated)"<< endl;      cout << "File: " << f->GetName() << " discarded ---- Missing AC tree" << endl;
5000          RUN = false;      return false;
5001      };    };
5002      if (S4 && !S4__ok) {
5003        cout << "File: " << f->GetName() << " discarded ---- Missing S4 tree" << endl;
5004        return false;
5005      };
5006      if (TOF && !TOF__ok) {
5007        cout << "File: " << f->GetName() << " discarded ---- Missing ToF tree" << endl;
5008        return false;
5009      };
5010    
5011      if(CAL1 && !CAL1__ok){    if (ND && !ND__ok) {
5012          cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel1 branch"<< endl;      cout << "File: " << f->GetName() << " discarded ---- Missing ND tree" << endl;
5013          return false;      return false;
5014      };    };
5015      if(CAL2 && !CAL2__ok){    if (TRG && !TRG__ok) {
5016          cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel2 branch"<< endl;      cout << "File: " << f->GetName() << " discarded ---- Missing Trigger tree" << endl;
5017          return false;      return false;
5018      };    };
5019      if(TRK2 && !TRK2__ok){    if (GP && !GP__ok) {
5020          cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel2 branch"<< endl;      cout << "File: " << f->GetName() << " discarded ---- Missing h20 tree" << endl;
5021          return false;      return false;
5022      };    };
     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;  
     };  
5023    
5024      if(ND && !ND__ok){    //    lk->Delete();
5025          cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl;    //    delete lk;
5026          return false;    f->Close();
5027      };  
5028      if(TRG && !TRG__ok){    //     cout<< "CheckLevel2File(TString): detector list --> ";
5029          cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;    //     if(TRK1)cout<<"TRK1 ";
5030          return false;    //     if(TRK2)cout<<"TRK2 ";
5031      };    //     if(TRKh)cout<<"TRKH ";
5032      if(GP && !GP__ok){    //     if(CAL1)cout<<"CAL1 ";
5033          cout << "File: "<< f->GetName() <<" discarded ---- Missing h20 tree"<< endl;    //     if(CAL2)cout<<"CAL2 ";
5034          return false;    //     if(TOF)cout<<"TOF ";
5035      };    //     if(TRG)cout<<"TRG ";
5036          //     if(AC)cout<<"AC ";
5037      //     if(ND)cout<<"ND ";
5038      //     if(S4)cout<<"S4 ";
5039      //     if(ORB)cout<<"ORB ";
5040      //     if(GP)cout<<"GP ";
5041      //     cout << endl;
5042    
5043  //    lk->Delete();    return true;
 //    delete lk;  
     f->Close();  
   
 //     cout<< "CheckLevel2File(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;  
         
     return true;  
           
 };  
5044    
5045    }
5046    ;
5047    
5048  /**  /**
5049   * Create clone-trees   * Create clone-trees
5050   */   */
5051  void PamLevel2::CreateCloneTrees0( TChain *fChain, TFile *ofile ){  void PamLevel2::CreateCloneTrees0(TChain *fChain, TFile *ofile) {
5052    
5053      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5054      cout << "Create clones of PAMELA trees "<<endl;    cout << "Create clones of PAMELA trees " << endl;
5055        
5056      Int_t i=0;    Int_t i = 0;
5057      pam_tree_clone[i] = fChain->GetTree()->CloneTree(0);    pam_tree_clone[i] = fChain->GetTree()->CloneTree(0);
5058      TString name =  pam_tree_clone[i]->GetName();    TString name = pam_tree_clone[i]->GetName();
5059      name.Append("_clone");
5060      //    pam_tree_clone[i]->SetName(name.Data());
5061      cout << pam_tree_clone[i]->GetName() << endl;
5062      i++;
5063    
5064      TList *li = fChain->GetListOfFriends();
5065      TIter next(li);
5066      TFriendElement* T_friend = 0;
5067      ofile->cd();
5068      while ((T_friend = (TFriendElement*) next())) {
5069        //  cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;
5070        //  cout<<T_friend->GetTree()->GetName()<< endl;
5071        pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0);
5072        pam_tree_clone[i]->SetAutoSave(1000000);
5073        name = pam_tree_clone[i]->GetName();
5074      name.Append("_clone");      name.Append("_clone");
5075  //    pam_tree_clone[i]->SetName(name.Data());      //  pam_tree_clone[i]->SetName(name.Data());
5076      cout << pam_tree_clone[i]->GetName() <<endl;      cout << pam_tree_clone[i]->GetName() << endl;
5077      i++;      i++;
5078      }
5079    
5080      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;  
5081    
5082      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5083    
5084  }  }
5085    
5086  /**  /**
5087   * Create clone-trees   * Create clone-trees
5088   */   */
5089  void PamLevel2::CreateCloneTrees(TFile *ofile){  void PamLevel2::CreateCloneTrees(TFile *ofile) {
5090    
5091      //  if the pointer is null, create a default file
5092      if (!run_tree)
5093        return;
5094    
5095      if (!ofile) {
5096        cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root " << endl;
5097        ofile = new TFile("clone-tree.root", "recreate");
5098      }
5099    
5100      ofile->cd();
5101    
5102      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5103      cout << "Create new PAMELA trees " << endl;
5104    
5105      run_tree_clone = new TTree("Run", "PAMELA Level2 data from the GL_RUN table ");
5106      run_tree_clone->Branch("RunInfo", "GL_RUN", GetPointerTo("RunInfo"));
5107      cout << "Run          : branch RunInfo" << endl;
5108      run_tree_clone->Branch("SoftInfo", "SoftInfo", GetPointerTo("SoftInfo"));
5109      cout << "Run          : branch SoftInfo" << endl;
5110      // ------------------
5111      // replicate run tree
5112      // ------------------
5113      //    cout << "----------------------------------------------------"<<endl;
5114      //    cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl;
5115      for (Int_t i = 0; i < run_tree->GetEntries(); i++) {
5116        run_tree->GetEntry(i);
5117        //  cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl;
5118        run_tree_clone->Fill();
5119      }
5120      cout << "----------------------------------------------------" << endl;
5121    
5122      // ------------------------------------
5123      // add branch with dead and live times
5124      // ------------------------------------
5125      if (SELLI != 2) { // EMILIANO
5126        run_tree_clone->Branch("DeadLiveTime", totdltime, "dltime[3]/l");
5127        cout << "Run          : branch DeadLiveTime" << endl;
5128    
5129        sel_tree_clone = new TTree("SelectionList", "List of selected events ");
5130        //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L");
5131        sel_tree_clone->Branch("RunEntry", &irunt, "runentry/L");//NEWNEW
5132        sel_tree_clone->Branch("EventEntry", &irunentry, "eventry/L");
5133        //    if ( hasL0EE ) sel_tree_clone->Branch("L0EventEntry", &il0entry, "l0eventry/L");
5134      };
5135    
5136      Int_t i = 0;
5137      if (TRK1 || TRK2 || TRKh) {
5138        pam_tree_clone[i] = new TTree("Tracker", "PAMELA tracker level2 data ");
5139        if (TRK1) {
5140          pam_tree_clone[i]->Branch("TrkLevel1", "TrkLevel1", GetPointerTo("TrkLevel1"));
5141          pam_tree_clone[i]->BranchRef();
5142          cout << "Tracker      : branch TrkLevel1" << endl;
5143          //            cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;
5144        };
5145        if (TRK2) {
5146          pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2", GetPointerTo("TrkLevel2"));
5147          cout << "Tracker      : branch TrkLevel2" << endl;
5148        };
5149        if (TRKh) {
5150          pam_tree_clone[i]->Branch("TrkHough", "TrkHough", GetPointerTo("TrkHough"));
5151          cout << "Tracker      : branch TrkHough" << endl;
5152        };
5153        if(NUC){
5154            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&trk_nuc_obj);
5155            cout << "Tracker      : branch TrackNuclei" << endl;    
5156        }
5157        if(EXT){
5158            pam_tree_clone[i]->Branch("extAlgFlag",&extAlgFlag,"extAlgFlag/I");
5159            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&trk_ext_obj);
5160            cout << "Tracker      : branch RecoveredTrack" << endl;
5161            if(NUC){
5162                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&trk_ext_nuc_obj);
5163                cout << "Tracker      : branch RecoveredTrackNuclei" << endl;                  
5164            }
5165        }
5166    
5167  //  if the pointer is null, create a default file      i++;
5168      if(!run_tree)return;    }
5169    
5170      if(!ofile){    // Calorimeter
5171          cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl;    if (CAL1 || CAL2) {
5172          ofile = new TFile("clone-tree.root","recreate");      pam_tree_clone[i] = new TTree("Calorimeter", "PAMELA calorimeter level2 data ");
5173        if (CAL1) {
5174          pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
5175          cout << "Calorimeter  : branch CaloLevel1" << endl;
5176        };
5177        if (CAL2) {
5178          pam_tree_clone[i]->Branch("CaloLevel2", "CaloLevel2", GetPointerTo("CaloLevel2"));
5179          cout << "Calorimeter  : branch CaloLevel2" << endl;
5180        };
5181        if(NUC){
5182            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&calo_nuc_obj);
5183            cout << "Calorimeter  : branch TrackNuclei" << endl;    
5184        }
5185        if(EXT){
5186            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&calo_ext_obj);
5187            cout << "Calorimeter  : branch RecoveredTrack" << endl;
5188            if(NUC){
5189                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&calo_ext_nuc_obj);
5190                cout << "Calorimeter  : branch RecoveredTrackNuclei" << endl;                  
5191            }
5192      }      }
5193        i++;
5194      }
5195    
5196      ofile->cd();    // ToF
5197      if (TOF) {
5198      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      pam_tree_clone[i] = new TTree("ToF", "PAMELA ToF level2 data ");
5199      cout << "Create new PAMELA trees "<<endl;      pam_tree_clone[i]->Branch("ToFLevel2", "ToFLevel2", GetPointerTo("ToFLevel2"));
5200                cout << "ToF          : branch ToFLevel2" << endl;
5201        if(NUC){
5202            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&tof_nuc_obj);
5203            cout << "ToF          : branch TrackNuclei" << endl;    
5204        }
5205        if(EXT){
5206            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&tof_ext_obj);
5207            cout << "ToF          : branch RecoveredTrack" << endl;
5208            if(NUC){
5209                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&tof_ext_nuc_obj);
5210                cout << "ToF          : branch RecoveredTrackNuclei" << endl;                  
5211            }
5212        }
5213        i++;
5214      };
5215      // Trigger
5216      if (TRG) {
5217        pam_tree_clone[i] = new TTree("Trigger", "PAMELA trigger level2 data ");
5218        pam_tree_clone[i]->Branch("TrigLevel2", "TrigLevel2", GetPointerTo("TrigLevel2"));
5219        cout << "Trigger      : branch TrigLevel2" << endl;
5220        i++;
5221      };
5222      // S4
5223      if (S4) {
5224        pam_tree_clone[i] = new TTree("S4", "PAMELA S4 level2 data ");
5225        pam_tree_clone[i]->Branch("S4Level2", "S4Level2", GetPointerTo("S4Level2"));
5226        cout << "S4           : branch S4Level2" << endl;
5227        i++;
5228      };
5229      // Neutron Detector
5230      if (ND) {
5231        pam_tree_clone[i] = new TTree("NeutronD", "PAMELA neutron detector level2 data ");
5232        pam_tree_clone[i]->Branch("NDLevel2", "NDLevel2", GetPointerTo("NDLevel2"));
5233        cout << "NeutronD     : branch NDLevel2" << endl;
5234        i++;
5235      };
5236      // Anticounters
5237      if (AC) {
5238        pam_tree_clone[i] = new TTree("Anticounter", "PAMELA anticounter detector level2 data ");
5239        pam_tree_clone[i]->Branch("AcLevel2", "AcLevel2", GetPointerTo("AcLevel2"));
5240        cout << "Anticounter  : branch AcLevel2" << endl;
5241        i++;
5242      };
5243      // OrbitalInfo
5244      if (ORB) {
5245        pam_tree_clone[i] = new TTree("OrbitalInfo", "PAMELA orbital info  ");
5246        pam_tree_clone[i]->Branch("OrbitalInfo", "OrbitalInfo", GetPointerTo("OrbitalInfo"));
5247        cout << "OrbitalInfo  : branch OrbitalInfo" << endl;
5248        if(NUC){
5249            pam_tree_clone[i]->Branch("TrackNuclei","TClonesArray",&orb_nuc_obj);
5250            cout << "OrbitalInfo  : branch TrackNuclei" << endl;    
5251        }
5252        if(EXT){
5253            pam_tree_clone[i]->Branch("RecoveredTrack","TClonesArray",&orb_ext_obj);
5254            cout << "OrbitalInfo  : branch RecoveredTrack" << endl;
5255            if(NUC){
5256                pam_tree_clone[i]->Branch("RecoveredTrackNuclei","TClonesArray",&orb_ext_nuc_obj);
5257                cout << "OrbitalInfo  : branch RecoveredTrackNuclei" << endl;                  
5258            }
5259        }
5260        i++;
5261      };
5262      // GPamela
5263      if (GP) {
5264        pam_tree_clone[i] = new TTree("h20", "GPAMELA info ");
5265        pam_tree_clone[i]->Branch("GPamela", "GPamela", GetPointerTo("GPamela"), 32000, 1);//split
5266        cout << "GPamela  : branch GPamela" << endl;
5267        i++;
5268      };
5269    
     run_tree_clone = new TTree("Run","PAMELA Level2 data from the GL_RUN table ");  
     run_tree_clone->Branch("RunInfo","GL_RUN",GetPointerTo("RunInfo"));  
     cout << "Run          : branch RunInfo"<<endl;  
     run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));  
     cout << "Run          : branch SoftInfo"<<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  
     // ------------------------------------  
     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");  
       
5270    
5271      Int_t i=0;    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
     if(TRK1||TRK2||TRKh){  
         pam_tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");  
         if(TRK1) {  
             pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));  
             pam_tree_clone[i]->BranchRef();  
             cout << "Tracker      : branch TrkLevel1"<<endl;  
 //          cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;  
         };  
         if(TRK2) {  
             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++;  
     };  
     // Neutron Detector  
     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 oribital 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","PAMELA oribital info  ");    
         pam_tree_clone[i]->Branch("GPamela","GPamela", GetPointerTo("GPamela"),32000,1);//split  
         cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;  
         i++;  
     };  
     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
5272    
5273  }  }
5274    
   
5275  /**  /**
5276   * Fill tree (created with CreateCloneTrees)   * Fill tree (created with CreateCloneTrees)
5277   *   *
5278   */   */
5279  //void PamLevel2::FillNewPamTree(TTree *T){  //void PamLevel2::FillNewPamTree(TTree *T){
5280  void PamLevel2::FillCloneTrees(){  void PamLevel2::FillCloneTrees() {
       
 //    cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;  
5281    
5282      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();      
5283    
5284  }    for (Int_t i = 0; i < NCLONES; i++) {
5285        if (pam_tree_clone[i])
5286          pam_tree_clone[i]->Fill();
5287      }
5288      if (sel_tree_clone)
5289        sel_tree_clone->Fill();
5290    
5291    }
5292    
5293  TTree* PamLevel2::GetCloneTree(TString name){  TTree* PamLevel2::GetCloneTree(TString name) {
5294    
5295      for(Int_t i=0; i<NCLONES; i++){        for (Int_t i = 0; i < NCLONES; i++) {
5296          if(pam_tree_clone[i]){      if (pam_tree_clone[i]) {
5297              TString na = pam_tree_clone[i]->GetName();        TString na = pam_tree_clone[i]->GetName();
5298              if(!name.CompareTo(na))return pam_tree_clone[i];        if (!name.CompareTo(na))
5299          };          return pam_tree_clone[i];
5300      }      };
5301      if(run_tree_clone){    }
5302          TString na = run_tree_clone->GetName();    if (run_tree_clone) {
5303          if(!name.CompareTo(na))return run_tree_clone;      TString na = run_tree_clone->GetName();
5304      }      if (!name.CompareTo(na))
5305      if(sel_tree_clone){        return run_tree_clone;
5306          TString na = sel_tree_clone->GetName();    }
5307          if(!name.CompareTo(na))return sel_tree_clone;    if (sel_tree_clone) {
5308      }      TString na = sel_tree_clone->GetName();
5309      return NULL;      if (!name.CompareTo(na))
5310          return sel_tree_clone;
5311      }
5312      return NULL;
5313    
5314  }  }
5315  void PamLevel2::WriteCloneTrees(){  void PamLevel2::WriteCloneTrees() {
5316      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;    cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5317      cout << "Write clones of PAMELA trees "<<endl;    cout << "Write clones of PAMELA trees " << endl;
5318      cout << run_tree_clone->GetName()<<endl;      cout << run_tree_clone->GetName() << endl;
5319      if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())    if (SELLI != 2) {// Emiliano
5320          run_tree_clone->GetBranch("DeadLiveTime")->Fill();      if (run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
5321      run_tree_clone->Write();        run_tree_clone->GetBranch("DeadLiveTime")->Fill();
5322      cout << sel_tree_clone->GetName()<<endl;        };
5323      run_tree_clone->Write();
5324      if (SELLI != 2) { //Emiliano
5325        cout << sel_tree_clone->GetName() << endl;
5326      sel_tree_clone->Write();      sel_tree_clone->Write();
5327      for(Int_t i=0; i<NCLONES; i++){        };
5328          if(pam_tree_clone[i]){    for (Int_t i = 0; i < NCLONES; i++) {
5329              cout << pam_tree_clone[i]->GetName()<<endl;      if (pam_tree_clone[i]) {
5330              pam_tree_clone[i]->Write();        cout << pam_tree_clone[i]->GetName() << endl;
5331          };        pam_tree_clone[i]->Write();
5332      }      };
5333      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;    }
5334      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl;
5335    
5336  }  }
5337    
5338  /**  /**
5339   * 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.
5340   */   */
5341  //Int_t PamLevel2::GetEntry(Int_t iee){  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;  
     }  
   
   
     //  
     // 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...  
     //  
     //    if(!run_tree ){  
     //  cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl;  
     //  return 0;  
     //    }  
   
     Long64_t ii=0;  
     //-------------------------------  
     ii = iee;  
     if( !pam_tree->GetEntry(ii) ){        
         cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<<endl;  
         return 0;  
     }  
5342    
5343      //    if (!pam_tree) {
5344      // ... 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.      cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded" << endl;
5345      // 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      return 0;
5346      // a problem if you don't check the return code of getentry.    }
5347      //  
5348      if(!RUN || !run_tree ){    //
5349          if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1?    // 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...
5350              cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;    //
5351              return 0;    //    if(!run_tree ){
5352          }  else {    //    cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl;
5353              return 1; //cosi` se non c'e` run esce qua...    //    return 0;
5354          }    //    }
5355      }  
5356      //-------------------------------
5357      if (!pam_tree->GetEntry(iee)) {
5358        cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree" << endl;
5359        return 0;
5360      }
5361      //
5362      // ... 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.
5363      // 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
5364      // a problem if you don't check the return code of getentry.
5365      //
5366      if (!RUN || !run_tree) {
5367        if (TRK0 || CAL0 || TOF0 || RUN) { //forse cosi` va bene per tornare 1?
5368          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded" << endl;
5369          return 0;
5370        }
5371        else {
5372          return 1; //cosi` se non c'e` run esce qua...
5373        }
5374      }
5375    
5376      //-------------------------------
5377      //
5378      if ( fUpdateRunInfo ) UpdateRunInfo(iee); // Emiliano
5379      if (SELLI == 0 || SELLI == 2) irunentry = iee - runfirstentry;
5380    
5381      //-------------------------------    return 1;
     ii = iee;  
 //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii);  
 //    Bool_t UPDATED = UpdateRunInfo(ii);  
     UpdateRunInfo(ii);  
     if(SELLI==0)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;  
5382    
5383  }  }
5384    
5385  TrkLevel0    *PamLevel2::GetTrkLevel0(){  TrkLevel0 *PamLevel2::GetTrkLevel0() {
5386      if( !TRK0 )return NULL;    if (!TRK0)
5387      if( !GetYodaEntry( ) ){      return NULL;
5388          cout << " Int_t PamLevel2::GetTrkLevel0() -- ERROR -- error reading level0 tree"<<endl;    if (!GetYodaEntry()) {
5389          return 0;      cout << " Int_t PamLevel2::GetTrkLevel0() -- ERROR -- error reading level0 tree" << endl;
5390      }      return 0;
5391      return trk0_obj;    }
5392  };    return trk0_obj;
5393  CaloLevel0    *PamLevel2::GetCaloLevel0(){  }
5394      if( !CAL0 )return NULL;  ;
5395      if( !GetYodaEntry( ) ){  CaloLevel0 *PamLevel2::GetCaloLevel0() {
5396          cout << " Int_t PamLevel2::GetCaloLevel0() -- ERROR -- error reading level0 tree"<<endl;    if (!CAL0)
5397          return 0;      return NULL;
5398      }    if (!GetYodaEntry()) {
5399      return calo0_obj;      cout << " Int_t PamLevel2::GetCaloLevel0() -- ERROR -- error reading level0 tree" << endl;
5400  };      return 0;
5401      }
5402      return calo0_obj;
5403    }
5404    ;
5405    
5406  /**  /**
5407   * 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 3830  CaloLevel0    *PamLevel2::GetCaloLevel0( Line 5409  CaloLevel0    *PamLevel2::GetCaloLevel0(
5409   * @return Pointer to the tree   * @return Pointer to the tree
5410   */   */
5411    
5412    TTree* PamLevel2::GetYodaTree() {
5413    
5414  TTree* PamLevel2::GetYodaTree( ){    //    cout << "TTree* PamLevel2::GetYodaTree( )"<<endl;
5415          //===================================
5416  //    cout << "TTree* PamLevel2::GetYodaTree( )"<<endl;    // check if iroot has changed
5417      //===================================    //===================================
5418      // check if iroot has changed    if (irun < 0) {
5419      //===================================      cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = " << irun << endl;
5420      if( irun<0 ){      if (DBG) cout << "In order to use this method you have to first load the RunInfo tree "<<endl;
5421          cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = "<<irun<<endl;      return NULL;
5422  //      cout << "In order to use this method you have to first load the RunInfo tree "<<endl;    }
5423          return NULL;    Int_t irootnew = GetRunInfo()->ID_ROOT_L0;
5424      }        if (DBG){
5425      Int_t irootnew = run_obj->ID_ROOT_L0;      cout << "iroot    "<<iroot<<endl;
5426  //      cout << "iroot    "<<iroot<<endl;      cout << "irootnew "<<irootnew<<endl;
5427  //      cout << "irootnew "<<irootnew<<endl;    }
5428    
5429      //===================================
5430      // load the level0 file
5431      // (if not already loaded)
5432      //===================================
5433      if (iroot != irootnew || !l0_tree) {
5434        iroot = irootnew;
5435      //===================================      //===================================
5436      // load the level0 file      // open the DB connection
5437      // (if not already loaded)      // (if not already opened)
5438      //===================================      //===================================
5439      if( iroot != irootnew || !l0_tree){      if (!dbc || (dbc && !dbc->IsConnected()))
5440          iroot = irootnew;        SetDBConnection();
5441          //===================================      GL_ROOT glroot = GL_ROOT();
5442          // open the DB connection      if (glroot.Query_GL_ROOT(iroot, dbc)) {
5443          // (if not already opened)        cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = " << iroot << " does not exists"
5444          //===================================            << endl;
5445          if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();        return NULL;
5446          GL_ROOT glroot = GL_ROOT();      };
5447          if( glroot.Query_GL_ROOT(iroot,dbc) ){      TString filename = glroot.PATH + glroot.NAME;
5448              cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;      if (l0_file) {
5449              return NULL;        l0_file->Close();
5450          };        l0_file->Delete();
5451          TString filename = glroot.PATH + glroot.NAME;      }
5452          if(l0_file){      cout << "Opening LEVEL0 file: " << filename << endl;
5453              l0_file->Close();      FileStat_t t;
5454              l0_file->Delete();      if (gSystem->GetPathInfo(filename.Data(), t)) {
5455          }        cout << " PamLevel2::GetYodaTree() -- ERROR opening file " << endl;
5456          cout << "Opening LEVEL0 file: "<< filename << endl;        return NULL;
5457          FileStat_t t;      }
5458          if( gSystem->GetPathInfo(filename.Data(),t) ){      l0_file = new TFile(filename);
5459              cout << " PamLevel2::GetYodaTree() -- ERROR opening file "<<endl;      if (!l0_file)
5460              return NULL;        return NULL;
5461          }      l0_tree = (TTree*) l0_file->Get("Physics");
5462          l0_file = new TFile(filename);      if (!h0_obj)
5463          if( !l0_file )return NULL;        h0_obj = new EventHeader();
5464          l0_tree = (TTree*)l0_file->Get("Physics");      l0_tree->SetBranchAddress("Header", &h0_obj);
5465          if(!h0_obj)h0_obj = new EventHeader();      yprevshift = 0; // yes, yprevshift is the shift in the level0, prevshift is the shift in the level2
5466          l0_tree->SetBranchAddress("Header" ,&h0_obj);      //---------------------------------------------------
5467          prevshift = 0;      // TRACKER:
5468          //---------------------------------------------------      if (TRK0) {
5469          // TRACKER:        if (!trk0_obj) {
5470          if(TRK0){          trk0_obj = new TrkLevel0();
5471              if(!trk0_obj){          trk0_obj->Set();
5472                  trk0_obj = new TrkLevel0();        };
5473                  trk0_obj->Set();        l0_tree->SetBranchAddress("Tracker", trk0_obj->GetPointerToTrackerEvent());
             };  
             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;  
         }  
   
         dbc->Close(); // EMILIANO, do not leave open connections, open only when needed  
   
   
     };  
   
 //     if(!dbc || (dbc && !dbc->IsConnected())){  
 //      cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;  
 //     }  
   
     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  
5474      }      }
5475        //--------------------------------------------------
5476        // CALORIMETER:
5477  //    cout << l0_tree << endl;      if (CAL0) {
5478      return l0_tree;        if (!calo0_obj) {
5479            calo0_obj = new CaloLevel0();
5480            calo0_obj->Set();
5481          };
5482          l0_tree->SetBranchAddress("Calorimeter", calo0_obj->GetPointerToCalorimeterEvent());
5483        }
5484        //---------------------------------------------------
5485        // TOF:
5486        if (TOF0) {
5487          cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented " << endl;
5488        }
5489    
5490        dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
5491        delete dbc;
5492        dbc=0;
5493    
5494      };
5495    
5496      if (TRK0) {
5497        if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection();
5498        TrkParams::SetCalib(run_obj, dbc);
5499        TrkParams::LoadCalib();
5500        if (!TrkParams::CalibIsLoaded()) {
5501          cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded" << endl;
5502        };
5503        if(dbc){
5504          dbc->Close(); // EMILIANO, do not leave open connections, open only when needed
5505          delete dbc;
5506          dbc=0;
5507        };
5508      }
5509      return l0_tree;
5510  }  }
5511    
5512  /**  /**
5513   * 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.
5514   */   */
5515  Int_t PamLevel2::GetYodaEntry(){  Int_t PamLevel2::GetYodaEntry() {
5516    
5517  //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;    Long64_t iev = this->GetReadEntry();
5518      if(!GetYodaTree())return 0;  
5519          // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
5520      // patch    // if it is a full file (not preselected)
5521      if( irunentry < 0){    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
5522  //      cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;    //  if (SELLI == 0 || SELLI == 2 || !hasL0EE) {
5523          irunentry=0LL;  
5524        if (!GetYodaTree()){
5525          printf(" PamLevel2::GetYodaEntry() : ERROR no level0 file loaded!\n");
5526          return 0;
5527        }
5528    
5529        if (irunentry < 0) {
5530          if (DBG) cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
5531          //      cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl; // TOGLITOGLI
5532          irunentry = 0LL;
5533      }      }
5534      //  ---------------------------------      //  ---------------------------------
5535      //  if file is NOT a preselected file      //  if file is NOT a preselected file
5536      //  ---------------------------------      //  ---------------------------------
5537      Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM);      Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM); // prevshift already included in irunentry
5538  //     cout << " irunentry "<<irunentry<<endl;  
5539  //     cout << " EV_FROM "<<run_obj->EV_FROM<<endl;      if (DBG){
5540  //     cout << " quellagiusta = irunentry + EV_FROM "<< quellagiusta << endl;        cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
5541          cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
5542  //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;        cout << " time "<< abstime << endl;
5543  //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;      }
5544  //     cout << " time "<< abstime << endl;  
5545  //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;      ULong64_t obt = 0;
5546            ULong64_t pktn = 0;
5547      ULong64_t obt     = 0;      if (GetOrbitalInfo()) {
5548      ULong64_t pktn    = 0;        obt = GetOrbitalInfo()->OBT;
5549      if( GetOrbitalInfo() ){        pktn = GetOrbitalInfo()->pkt_num;
         obt     = GetOrbitalInfo()->OBT;  
         pktn    = GetOrbitalInfo()->pkt_num;  
5550      }      }
5551    
5552      if( !GetOrbitalInfo() && !ISGP){      if (!GetOrbitalInfo() && !ISGP) {
5553          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;        cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo " << endl;
5554          return 0;        return 0;
5555      }      }
5556      if( obt==0 && pktn==0 && !ISGP ){      if (obt == 0 && pktn == 0 && !ISGP) {
5557          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl;        cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? " << endl;
5558          return 0;        return 0;
5559      }      }
5560    
5561      // ---------------------------------------------------------------------      // ---------------------------------------------------------------------
# Line 3986  Int_t PamLevel2::GetYodaEntry(){ Line 5569  Int_t PamLevel2::GetYodaEntry(){
5569      // of the OBT and pkt-number. In case of mismatch, the level0 entry number      // of the OBT and pkt-number. In case of mismatch, the level0 entry number
5570      // is shift forward until when the packets match.      // is shift forward until when the packets match.
5571      // ---------------------------------------------------------------------      // ---------------------------------------------------------------------
5572      Int_t answer = 0;      Long64_t shift = 0LL;
5573      Int_t shift =0;      Long64_t answer = quellagiusta + shift + yprevshift;
5574      //    printf(" siamo qui %i %i \n",shift,prevshift);      Int_t readl0 = 0;
5575      //    Int_t maxshift = 50; // EMILIANO      readl0 = l0_tree->GetEntry(answer); // prevshift already included in irunentry
5576      do{  
5577          if(shift>0){          if (DBG){
5578  <<<<<<< PamLevel2.cpp        printf(" siamo qui shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
5579              if(DBG)cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;      }
5580              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;  
5581              if(DBG)cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;  
5582  =======      if (ISGP) {
5583              cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;        obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO
5584              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;        pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO
5585              if(DBG)cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl;      }
5586  >>>>>>> 1.65  
5587          }      while ( (obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta + (Long64_t) shift) < GetYodaTree()->GetEntries() && shift < maxshift ){
5588          answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift);        if ( isSync && shift == 0LL ){
5589          shift++;          printf(" PamLevel2::GetYodaEntry() ERROR! sync file but the level0 entry not found in place!!! \n");
5590          if( !GetEventHeader() ){          cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5591              cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;          cout << "\nFor bug reporting instructions, please see for example:\n";
5592              return 0;          cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5593          }          cout << "  " << endl;
5594          }
5595          if(ISGP){        if (shift > 0) {
5596              obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO          if (DBG) cout << " PKTNUM  L2 --- " << pktn << " --- L0 --- " << GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
5597              pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO          if (DBG)
5598          }            cout << "         RUN: ID " << GetRunInfo()->ID << " ID_ROOT_L0 " << run_obj->ID_ROOT_L0 << " ID_RUN_FRAG "
5599                   << GetRunInfo()->ID_RUN_FRAG << " EV_FROM " << GetRunInfo()->EV_FROM << endl;
5600  //      cout << "PKTNUM "<<shift<<" ==  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl;          if (DBG)
5601  //      cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl;            cout << "         L2 <--> L0 mismatch ( irun " << irun << " irunentry " << irunentry << " shift " << shift
5602  //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;                 << " prevshift " << prevshift << " )" << endl;
5603  //      cout << " obt "<< obt << endl;        }
5604  //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;        answer = quellagiusta +  shift+ yprevshift;
5605  //      cout << " pktn "<< pktn << endl;        readl0 = l0_tree->GetEntry(answer);
5606  //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;        //      printf(" inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5607  //      printf(" IDRUN %u \n",GetRunInfo()->ID);  
5608  //        if (!GetEventHeader()) {
5609          if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader " << endl;
5610              prevshift = 0;          return 0;
5611              shift = -1;        }
5612          };  
5613          //
5614      }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) ||        if (yprevshift != 0 && (quellagiusta + (Long64_t) shift) == GetYodaTree()->GetEntries()) {
5615                pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())       )          if (DBG) printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
5616              && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift);          //        printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5617            yprevshift = 0LL;
5618      if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) {          shift = -1LL;
5619          cout << " Big trouble here, no such event in Level0 data! (NB maxshift set to "<<maxshift<<" )" <<endl;        };
5620          return 0;      
5621      }        shift++;
5622  //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;      }
5623  //    return GetYodaTree()->GetEntry(quellagiusta);                                    
5624      if ( shift > 1 ) prevshift += (shift-1);  
5625            if ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) ){
5626      return answer;        if ( isSync ){
5627                printf(" PamLevel2::GetYodaEntry() ERROR! sync file but the level0 entry not found AT ALL!!! \n");
5628            cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5629            cout << "\nFor bug reporting instructions, please see for example:\n";
5630            cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5631            cout << "  " << endl;
5632          }
5633          cout << "Int_t PamLevel2::GetYodaEntry() -- WARNING -- " << endl;
5634          cout << " Big trouble here, no such event in Level0 data! (NB maxshift set to " << maxshift << " )" << endl;    
5635          cout << " Nested and/or DarthVader skipped packets in fragmented run? checking and trying to fix " <<endl;
5636          // query the DB for runs containing the event, loop over LEVEL0 files which could contain the level0 event and try to find it
5637          // ma nel mezzo del cammin per ogni run che pesco devo vedere la posizione relativa di iev rispetto al runheader nel livello2 per andare a cercare nel posto giusto
5638          // connect to db
5639          if (!dbc || (dbc && !dbc->IsConnected())) SetDBConnection(); //Emiliano
5640          //
5641          if (GetOrbitalInfo()){
5642            abstime = GetOrbitalInfo()->absTime;
5643          } else {
5644            printf(" PamLevel2::GetYodaEntry() ERROR! no OrbitalInfo, cannot get the absolute time for event \n");
5645            return 0;
5646          }
5647          // query DB looking for runs containing the processed event
5648          TSQLResult *pResult;
5649          TSQLRow *Row = NULL;
5650          TString myquery = Form("select ID,NEVENTS from GL_RUN where RUNHEADER_TIME<=%lld and RUNTRAILER_TIME>=%lld;",abstime,abstime);
5651          if ( DBG ) printf(" query is %s \n",myquery.Data());
5652          //      printf(" query is %s \n",myquery.Data());// TOGLITOGLI
5653          pResult = dbc->Query(myquery.Data());    
5654          if (!pResult->GetRowCount()){
5655            printf(" PamLevel2::GetYodaEntry() ERROR! event is not included in any run!!! \n");
5656            cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5657            cout << "\nFor bug reporting instructions, please see for example:\n";
5658            cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5659            cout << "  " << endl;
5660            return 0;
5661          }
5662          if ( pResult->GetRowCount() == 1 ){
5663            if (DBG) printf(" PamLevel2::GetYodaEntry() - WARNING - YodaEntry not found but only one run containing the event, it should not happen \n");
5664            //        printf(" PamLevel2::GetYodaEntry() - WARNING - YodaEntry not found but only one run containing the event, it should not happen \n");//TOGLITOGLI
5665          }
5666          for( Int_t ru=0; ru < pResult->GetRowCount(); ru++){ // loop over runs containing the event
5667            if (Row) delete Row;
5668            Row = pResult->Next();  
5669            if( Row == NULL ) break;
5670            UInt_t idrun = (UInt_t)atoll(Row->GetField(0));
5671            UInt_t nev = (UInt_t)atoll(Row->GetField(1));
5672            if (DBG) printf(" inside loop over runs: ru %i idrun %i nev %i \n",ru,idrun,nev);
5673            //        printf(" inside loop over runs: ru %i idrun %i nev %i \n",ru,idrun,nev);//TOGLITOGLI
5674    
5675            // now look for this run in the level2 file, it must be present! code is taken from updateruninfo of course
5676            Bool_t rfound = false;
5677            totrunentry = 0LL;
5678            runfirstentry = 0LL;
5679            for (Int_t r=0; r< run_tree->GetEntries();r++){
5680              run_tree->GetEntry(r);//update runinfo
5681              if ( r > 0 ){
5682                totrunentrymin = totrunentrymax+1;
5683              } else {
5684                totrunentrymin = 0LL;
5685              }
5686              totrunentry += GetRunInfo()->NEVENTS;
5687              totrunentrymax = totrunentry - 1 - prevshift; // prevshift is needed to handle nested+DV_skipped packets
5688              irun = r;        
5689    
5690              if (idrun == GetRunInfo()->ID){
5691                if ( totrunentrymin > iev ){ // there is a shift (nested+DV_skipped packets)
5692                  if (DBG) printf("PamLevel2::GetYodaEntry - unconsistent iev - nevents, probable DBL0-L2 async\n");
5693                  if (DBG) printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);
5694                  //              printf("PamLevel2::GetYodaEntry - unconsistent iev - nevents, probable DBL0-L2 async\n");
5695                  //              printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI
5696                  prevshift += (totrunentrymin-iev); // add the new shift to total shift
5697                  totrunentrymin -= (totrunentrymin-iev); // shift run position min
5698                  totrunentrymax -= (totrunentrymin-iev); // shift run position max
5699                  if (DBG) printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);
5700                  //              printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI
5701                }
5702                runfirstentry = totrunentrymin; // first entry of the run in the level2
5703              
5704    
5705                //
5706                if (gltsync)
5707                  delete gltsync; // Emiliano
5708                if (!dbc || (dbc && !dbc->IsConnected()))
5709                  SetDBConnection(); //Emiliano
5710                gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano
5711                if (dbc){
5712                  dbc->Close(); // Emiliano
5713                  delete dbc;
5714                  dbc=0;
5715                }          
5716                if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano
5717                  cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun
5718                       << "  has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;
5719                  cout
5720                    << "                                                            (NB!! in this case some events could be assigned to a wrong run)"
5721                    << endl;
5722                }
5723                //
5724                if (DBG) printf(" found \n");
5725                //            printf(" found \n");//TOGLITOGLI
5726                rfound = true;
5727                //
5728                break;
5729              }
5730            } // loop over run
5731            if ( !rfound ){
5732              printf(" PamLevel2::GetYodaEntry() ERROR! run is not present in the level2 file!!! \n");
5733              cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5734              cout << "\nFor bug reporting instructions, please see for example:\n";
5735              cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5736              cout << "  " << endl;        
5737              return 0;
5738            }
5739    
5740            // here we got the first run and we can check if it contains the level0 event
5741            if (!GetYodaTree()){
5742              printf(" PamLevel2::GetYodaEntry() : ERROR no level0 file loaded!\n");
5743              return 0;
5744            }      
5745    
5746            // get the current run entry
5747            irunentry = iev - runfirstentry;
5748            if (irunentry < 0) {
5749              if (DBG) cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl;
5750              //          cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl; // TOGLITOGLI
5751              irunentry = 0LL;
5752            }
5753            //  ---------------------------------
5754            //  if file is NOT a preselected file
5755            //  ---------------------------------
5756            quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM); // prevshift already included in irunentry
5757          
5758            if (DBG){
5759              cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
5760              cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
5761              cout << " time "<< abstime << endl;
5762            }
5763            //        cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
5764            //        cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
5765            //        cout << " time "<< abstime << endl; // TOGLITOGLI
5766          
5767            shift = 0;
5768            answer = quellagiusta + shift + yprevshift; // prevshift already included in irunentry
5769            readl0 = l0_tree->GetEntry(answer); // prevshift already included in irunentry
5770    
5771            if (DBG){
5772              printf(" siamo qua shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
5773            }
5774            //        printf(" siamo qua shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5775          
5776            while ( (obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta + (Long64_t) shift) < GetYodaTree()->GetEntries() && shift < maxshift ){
5777              if (shift > 0) {
5778                if (DBG) cout << " PKTNUM  L2 --- " << pktn << " --- L0 --- " << GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
5779                if (DBG)
5780                  cout << "         RUN: ID " << GetRunInfo()->ID << " ID_ROOT_L0 " << run_obj->ID_ROOT_L0 << " ID_RUN_FRAG "
5781                       << GetRunInfo()->ID_RUN_FRAG << " EV_FROM " << GetRunInfo()->EV_FROM << endl;
5782                if (DBG)
5783                  cout << "         L2 <--> L0 mismatch ( irun " << irun << " irunentry " << irunentry << " shift " << shift
5784                       << " prevshift " << prevshift << " )" << endl;
5785              }
5786              answer = quellagiusta +  shift+ yprevshift;
5787              readl0 = l0_tree->GetEntry(answer);
5788              //          printf(" inside inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5789            
5790              if (!GetEventHeader()) {
5791                cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader " << endl;
5792                return 0;
5793              }
5794              //
5795              if (yprevshift != 0 && (quellagiusta + (Long64_t) shift) == GetYodaTree()->GetEntries()) {
5796                if (DBG) printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);
5797                //            printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI
5798                yprevshift = 0;
5799                shift = -1;
5800              };
5801            
5802              shift++;
5803            }
5804          
5805            if ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) ){
5806              //still not the good run... continue with the nex one!
5807              printf("still not the good run... continue with the nex one!\n");
5808            } else {
5809              if (DBG) cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
5810              //          cout << "LA ENTRY GIUSTA E`: "<<answer<<" (spero...)"<<endl;//TOGLITOGLI
5811              if (shift > 1) yprevshift = (shift - 1);
5812              if (Row) delete Row;
5813              delete pResult;  
5814              if (dbc){
5815                dbc->Close(); // Emiliano
5816                delete dbc;
5817                dbc=0;
5818              }    
5819              il0entry = answer;
5820              return readl0;
5821            }
5822            // perhaps it is all
5823          }// loop over runs containing the event
5824          if (Row) delete Row;
5825          delete pResult;  
5826          if (dbc){
5827            dbc->Close(); // Emiliano
5828            delete dbc;
5829            dbc=0;
5830          }          
5831          // arriving here it means no run found, cannot be! error!
5832          printf(" PamLevel2::GetYodaEntry() ERROR! run is not present in the level0 files!!! \n");
5833          cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5834          cout << "\nFor bug reporting instructions, please see for example:\n";
5835          cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5836          cout << "  " << endl;        
5837          return 0;
5838        } else {
5839          if (DBG) cout << "=> LA ENTRY GIUSTA E`: "<<answer<<" (spero...)"<<endl;
5840          //    cout << "=> LA ENTRY GIUSTA E`: "<<answer<<" (spero...)"<<endl;
5841          //    printf("obt %lld (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) %i  pktn %lld (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter() %i \n",obt,(UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()), pktn, (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) );
5842          if (shift > 1) yprevshift = (shift - 1);
5843          il0entry = answer;
5844          return readl0;
5845        }
5846    
5847        /*  } // if selli 0 || 2
5848      if ( SELLI == 1 && hasL0EE ){
5849        sel_tree->GetEntry(iev);  
5850        Long64_t answer = il0entry;
5851        Int_t readl0 = 0;
5852        readl0 = l0_tree->GetEntry(answer);
5853        return readl0;
5854        }*/
5855      printf(" PamLevel2::GetYodaEntry() ERROR! \n");
5856      cout << " Entry not found! OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl;
5857      cout << "\nFor bug reporting instructions, please see for example:\n";
5858      cout << "     <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n";
5859      cout << "  " << endl;
5860      return 0;
5861  }  }
5862    
5863  /**  /**
5864   * \Brief Set DB connection   * \Brief Set DB connection
5865   */   */
5866  Bool_t PamLevel2::SetDBConnection(){  Bool_t PamLevel2::SetDBConnection() {
5867    
5868  //    cout << "PamLevel2::SetDBConnection()" << endl;    //    cout << "PamLevel2::SetDBConnection()" << endl;
5869      if(DBG){    if (DBG) {
5870          cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;      cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
5871          cout<<"Connecting to DB"<<endl;      cout << "Connecting to DB" << endl;
5872          cout<<"HOST "<<host<<endl;      cout << "HOST " << host << endl;
5873          cout<<"USER "<<user<<endl;      cout << "USER " << user << endl;
5874          cout<<"PSW  "<<psw<<endl;      cout << "PSW  " << psw << endl;
5875      }    }
5876      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());    Bool_t notconn = true;
5877      if( !dbc )return false;    Int_t trials = 0;
5878      if( !dbc->IsConnected() )return false;        while ( notconn && trials < 10 ){
5879      stringstream myquery;  // EMILIANO      //    gSystem->Sleep(500);
5880      myquery.str("");  // EMILIANO      dbc = TSQLServer::Connect(host.Data(), user.Data(), psw.Data());
5881      myquery << "SET time_zone='+0:00'";  // EMILIANO      //dbc->Connect(host.Data(), user.Data(), psw.Data());
5882      dbc->Query(myquery.str().c_str());  // EMILIANO      if ( dbc ) notconn = false;
5883      if(DBG)cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;      if (DBG) printf("<%i> test connection...\n ",trials);
5884      return true;      if (!dbc){
5885          if (DBG) printf(" :( failed, no pointer \n");
5886          notconn = true;
5887          //      return false;
5888        };
5889        if (dbc && !dbc->IsConnected()){
5890          if (DBG) printf(" :( failed, no connection \n");
5891          notconn = true;
5892          //      return false;
5893        };
5894        trials++;
5895      };
5896      if ( notconn ) return false;
5897      //
5898      if (DBG) printf("=connected!\n");
5899      stringstream myquery; // EMILIANO
5900      myquery.str(""); // EMILIANO
5901      myquery << "SET time_zone='+0:00'"; // EMILIANO
5902      dbc->Query(myquery.str().c_str()); // EMILIANO
5903      if ( DBG ) printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
5904      return true;
5905    
5906  }  }
5907    
# Line 4073  Bool_t PamLevel2::SetDBConnection(){ Line 5910  Bool_t PamLevel2::SetDBConnection(){
5910   * @param cname name of the chain to be added   * @param cname name of the chain to be added
5911   */   */
5912    
5913  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;  
     }  
5914    
5915      if (!GetPamTree()) {
5916        cout << " TChain* PamLevel2::AddFriend(TString cname) --- a pamela tree must be created first" << endl;
5917        return NULL;
5918      }
5919    
5920      TChain *c = new TChain( cname.Data() );    TChain *c = new TChain(cname.Data());
5921    
5922      TIter next( GetPamTree()->GetListOfFiles() );    TIter next(GetPamTree()->GetListOfFiles());
5923      Int_t nf = 0;    Int_t nf = 0;
5924      TChainElement* element = 0;        TChainElement* element = 0;
5925      while ((element = (TChainElement*) next())) {          while ((element = (TChainElement*) next())) {
5926          c->Add(element->GetTitle());      c->Add(element->GetTitle());
5927          nf++;      nf++;
5928      }    }
5929    
5930      GetPamTree()->AddFriend(cname.Data());    GetPamTree()->AddFriend(cname.Data());
5931    
5932      cout << "external chain created and added to pamela friends :"<<cname<<endl;    cout << "external chain created and added to pamela friends :" << cname << endl;
5933      cout << "n.files "<<nf<<endl;    cout << "n.files " << nf << endl;
       
5934    
5935      return c;        return c;
5936    
5937  }  }
5938    
5939    /**
5940     * Returns the current read entry. This method simply returns the result of the call to
5941     * pam_tree->GetReadEntry(), so it is entirely handled by ROOT.
5942     */
5943    Long64_t PamLevel2::GetReadEntry() {
5944      return pam_tree->GetReadEntry();
5945    }
5946    
5947    /**
5948     * Sets the sorting method. If the new method is different from the previous, the issorted
5949     * flag is set to false, forcing a new sort the next time GetTrack is called.
5950     * @see GetTrack
5951     */
5952    void PamLevel2::SetSortingMethod(TString how) {
5953      if (howtosort != how) {
5954        issorted = false;
5955        issorted_new = false;
5956      }
5957      howtosort = how;
5958    }

Legend:
Removed from v.1.66  
changed lines
  Added in v.1.95

  ViewVC Help
Powered by ViewVC 1.1.23