24 |
tof_track = this->ToFTrkVar::GetToFTrkVar(); |
tof_track = this->ToFTrkVar::GetToFTrkVar(); |
25 |
if(t) *trk_track = *t; |
if(t) *trk_track = *t; |
26 |
if(c) *calo_track = *c; |
if(c) *calo_track = *c; |
27 |
if(o) *tof_track = *o; |
if(o) *tof_track = *o; |
28 |
}; |
}; |
29 |
|
|
30 |
//-------------------------------------- |
//-------------------------------------- |
35 |
* Constructor |
* Constructor |
36 |
*/ |
*/ |
37 |
PamLevel2::PamLevel2(){ |
PamLevel2::PamLevel2(){ |
38 |
trk_obj = this->TrkLevel2::GetTrkLevel2(); |
|
39 |
calo_obj = this->CaloLevel2::GetCaloLevel2(); |
trk1_obj = this->TrkLevel1::GetTrkLevel1(); |
40 |
tof_obj = this->ToFLevel2::GetToFLevel2(); |
trk2_obj = this->TrkLevel2::GetTrkLevel2(); |
41 |
trig_obj = this->TrigLevel2::GetTrigLevel2(); |
trkh_obj = this->TrkHough::GetTrkHough(); |
42 |
s4_obj = this->S4Level2::GetS4Level2(); |
calo1_obj = this->CaloLevel1::GetCaloLevel1(); |
43 |
nd_obj = this->NDLevel2::GetNDLevel2(); |
calo2_obj = this->CaloLevel2::GetCaloLevel2(); |
44 |
ac_obj = this->AcLevel2::GetAcLevel2(); |
tof_obj = this->ToFLevel2::GetToFLevel2(); |
45 |
|
trig_obj = this->TrigLevel2::GetTrigLevel2(); |
46 |
|
s4_obj = this->S4Level2::GetS4Level2(); |
47 |
|
nd_obj = this->NDLevel2::GetNDLevel2(); |
48 |
|
ac_obj = this->AcLevel2::GetAcLevel2(); |
49 |
|
orb_obj = this->OrbitalInfo::GetOrbitalInfo(); |
50 |
|
|
51 |
|
run_obj = new GL_RUN(); |
52 |
|
|
53 |
|
sorted_tracks = new TRefArray(); |
54 |
|
|
55 |
|
CAL2 = true; |
56 |
|
TRK2 = true; |
57 |
|
TRK1 = false; |
58 |
|
TRKh = false; |
59 |
|
TRG = true; |
60 |
|
TOF = true; |
61 |
|
S4 = true; |
62 |
|
ND = true; |
63 |
|
AC = true; |
64 |
|
ORB = true; |
65 |
|
|
66 |
|
|
67 |
|
}; |
68 |
|
/** |
69 |
|
* Destructor |
70 |
|
*/ |
71 |
|
PamLevel2::~PamLevel2(){ |
72 |
|
|
73 |
|
TrkLevel1::Clear(); |
74 |
|
|
75 |
|
TrkLevel2::Clear(); |
76 |
|
CaloLevel2::Clear(); |
77 |
|
ToFLevel2::Clear(); |
78 |
|
TrigLevel2::Clear(); |
79 |
|
S4Level2::Clear(); |
80 |
|
NDLevel2::Clear(); |
81 |
|
AcLevel2::Clear(); |
82 |
|
OrbitalInfo::Clear(); |
83 |
|
|
84 |
|
delete run_obj; |
85 |
|
|
86 |
|
// delete sorted_tracks; |
87 |
|
sorted_tracks->Delete(); // clean the reference array |
88 |
|
|
89 |
|
|
90 |
|
}; |
91 |
|
/** |
92 |
|
* Clear the event |
93 |
|
*/ |
94 |
|
void PamLevel2::Clear(){ |
95 |
|
|
96 |
|
TrkLevel1::Clear(); |
97 |
|
|
98 |
|
TrkLevel2::Clear(); |
99 |
|
CaloLevel2::Clear(); |
100 |
|
ToFLevel2::Clear(); |
101 |
|
TrigLevel2::Clear(); |
102 |
|
S4Level2::Clear(); |
103 |
|
NDLevel2::Clear(); |
104 |
|
AcLevel2::Clear(); |
105 |
|
OrbitalInfo::Clear(); |
106 |
|
|
107 |
|
sorted_tracks->Delete(); // clean the reference array |
108 |
|
|
109 |
}; |
}; |
110 |
|
|
111 |
|
|
112 |
|
//-------------------------------------- |
113 |
|
// |
114 |
|
// |
115 |
|
//-------------------------------------- |
116 |
|
/** |
117 |
|
* Retrieves the calorimeter track matching the seqno-th tracker stored track. |
118 |
|
* (If seqno = -1 retrieves the self-trigger calorimeter track) |
119 |
|
*/ |
120 |
|
CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){ |
121 |
|
|
122 |
|
if( CaloLevel2::ntrk()==0 ){ |
123 |
|
cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl; |
124 |
|
return NULL; |
125 |
|
}; |
126 |
|
|
127 |
|
CaloTrkVar *c = 0; |
128 |
|
Int_t it_calo=0; |
129 |
|
|
130 |
|
do{ |
131 |
|
c = CaloLevel2::GetCaloTrkVar(it_calo); |
132 |
|
it_calo++; |
133 |
|
} while( c && seqno != c->trkseqno && it_calo < CaloLevel2::ntrk()); |
134 |
|
|
135 |
|
if(!c || seqno != c->trkseqno){ |
136 |
|
c = 0; |
137 |
|
if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl; |
138 |
|
}; |
139 |
|
return c; |
140 |
|
|
141 |
|
}; |
142 |
|
//-------------------------------------- |
143 |
|
// |
144 |
|
// |
145 |
|
//-------------------------------------- |
146 |
|
/** |
147 |
|
* Retrieves the ToF track matching the seqno-th tracker stored track. |
148 |
|
* (If seqno = -1 retrieves the tracker-independent tof track) |
149 |
|
*/ |
150 |
|
ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){ |
151 |
|
|
152 |
|
if( ToFLevel2::ntrk()==0 ){ |
153 |
|
cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl; |
154 |
|
return NULL; |
155 |
|
}; |
156 |
|
|
157 |
|
ToFTrkVar *c = 0; |
158 |
|
Int_t it_tof=0; |
159 |
|
|
160 |
|
do{ |
161 |
|
c = ToFLevel2::GetToFTrkVar(it_tof); |
162 |
|
it_tof++; |
163 |
|
} while( c && seqno != c->trkseqno && it_tof < ToFLevel2::ntrk()); |
164 |
|
|
165 |
|
if(!c || seqno != c->trkseqno){ |
166 |
|
c = 0; |
167 |
|
if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl; |
168 |
|
}; |
169 |
|
return c; |
170 |
|
|
171 |
|
}; |
172 |
|
|
173 |
|
//-------------------------------------- |
174 |
|
// |
175 |
|
// |
176 |
|
//-------------------------------------- |
177 |
|
/** |
178 |
|
* Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information. |
179 |
|
*/ |
180 |
|
PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){ |
181 |
|
|
182 |
|
CaloTrkVar *c = 0; |
183 |
|
ToFTrkVar *o = 0; |
184 |
|
|
185 |
|
if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo()); |
186 |
|
if(TOF) o = GetToFStoredTrack(t->GetSeqNo()); |
187 |
|
|
188 |
|
// if(t && c && o)track = new PamTrack(t,c,o); |
189 |
|
PamTrack *track = new PamTrack(t,c,o); |
190 |
|
|
191 |
|
return track; |
192 |
|
|
193 |
|
}; |
194 |
//-------------------------------------- |
//-------------------------------------- |
195 |
// |
// |
196 |
// |
// |
203 |
|
|
204 |
PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){ |
PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){ |
205 |
|
|
206 |
// retrieve itrk-th tracker stored track |
PamTrack *track = 0; |
207 |
TrkTrack *t = 0; |
|
208 |
CaloTrkVar *c = 0; |
if( itrk >=0 && itrk < TrkLevel2::ntrk() ){ |
209 |
ToFTrkVar *o = 0; |
|
210 |
|
TrkTrack *t = TrkLevel2::GetStoredTrack(itrk); |
211 |
if( itrk >=0 && itrk < TrkLevel2::ntrk() ){ |
track = GetPamTrackAlong(t); |
212 |
t = TrkLevel2::GetStoredTrack(itrk); |
|
213 |
c = CaloLevel2::GetCaloTrkVar(t->GetSeqNo()); |
}else{ |
214 |
o = ToFLevel2::GetToFTrkVar(t->GetSeqNo()); |
cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl; |
215 |
}; |
}; |
|
// retrieve related ToF-track |
|
216 |
|
|
|
// hence create a "PamTrack" object |
|
|
PamTrack *track = 0; |
|
|
if(t && c && o)track = new PamTrack(t,c,o); |
|
217 |
return track; |
return track; |
218 |
|
|
219 |
} |
} |
222 |
// |
// |
223 |
//-------------------------------------- |
//-------------------------------------- |
224 |
/** |
/** |
225 |
* Sort physical (tracker) tracks and stores them in a TObjectArray (of TrkTrack objects). |
* Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is PamLevel2::sorted_tracks. |
226 |
* The total number of physical tracks is given by GetNTracks() and the it-th physical track can be retrieved by means of the method GetTrack(int it). |
* @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...). |
227 |
* This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2. |
* Sorting cryteria: |
228 |
* PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information. |
* TRK: lower chi**2 |
229 |
|
* CAL: lower Y spatial residual on the first calorimeter plane |
230 |
|
* TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis). |
231 |
|
* The default sorting cryterium is "TOF+CAL". |
232 |
|
* |
233 |
|
* 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). |
234 |
*/ |
*/ |
235 |
TClonesArray *PamLevel2::GetTracks(){ |
void PamLevel2::SortTracks(TString how){ |
|
|
|
|
// define new array for sorted tracker tracks |
|
|
TClonesArray *aa = new TClonesArray("TrkTrack"); |
|
|
TClonesArray &sorted = *aa; |
|
236 |
|
|
237 |
|
//Save current Object count |
238 |
|
Int_t ObjectNumber = TProcessID::GetObjectCount(); |
239 |
|
|
240 |
|
sorted_tracks->Delete(); //temporaneo??? |
241 |
|
|
242 |
// loop over the tracks sorted by the tracker |
// loop over the tracks sorted by the tracker |
243 |
|
Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase); |
244 |
|
Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase); |
245 |
|
Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase); |
246 |
|
|
247 |
|
if( !CAL2 && use_CAL) use_CAL = false; |
248 |
|
if( !TOF && use_TOF) use_TOF = false; |
249 |
|
|
250 |
|
if( !TRK2 ){ |
251 |
|
cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl; |
252 |
|
return; |
253 |
|
}; |
254 |
|
|
255 |
for(Int_t i=0; i < TrkLevel2::GetNTracks(); i++){ |
for(Int_t i=0; i < TrkLevel2::GetNTracks(); i++){ |
256 |
|
|
257 |
TrkTrack *ts=0; |
TrkTrack *ts = 0; |
258 |
|
|
259 |
// get tracker tracks |
// get tracker tracks |
260 |
TrkTrack *tp = TrkLevel2::GetTrack(i); //tracker |
TrkTrack *tp = TrkLevel2::GetTrack(i); //tracker |
261 |
CaloTrkVar *cp = CaloLevel2::GetCaloTrkVar(tp->GetSeqNo()); //calorimeter |
CaloTrkVar *cp = 0; |
262 |
ToFTrkVar *op = ToFLevel2::GetToFTrkVar(tp->GetSeqNo()); //tof |
ToFTrkVar *op = 0; |
263 |
|
|
264 |
// if track has an image, check image selection |
// if track has an image, check image selection |
265 |
if(tp->HasImage()){ |
if(tp->HasImage()){ |
266 |
|
|
267 |
TrkTrack *ti = TrkLevel2::GetTrackImage(i); //tracker (image) |
TrkTrack *ti = TrkLevel2::GetTrackImage(i); //tracker (image) |
268 |
CaloTrkVar *ci = CaloLevel2::GetCaloTrkVar(ti->GetSeqNo());//calorimeter (image) |
CaloTrkVar *ci = 0; |
269 |
ToFTrkVar *oi = ToFLevel2::GetToFTrkVar(ti->GetSeqNo()); //tof (image) |
ToFTrkVar *oi = 0; |
270 |
|
|
271 |
//assign starting scores |
//assign starting scores |
272 |
Int_t tp_score = 1; |
Int_t tp_score = 0; //main track sorted by the tracker |
273 |
Int_t ti_score = 0; |
Int_t ti_score = 0; //image track |
274 |
|
|
275 |
// ------------------------ |
// ------------------------ |
276 |
// calorimeter check |
// calorimeter check |
277 |
// ------------------------ |
// ------------------------ |
278 |
|
// check the Y spatial residual on the first calorimeter plane |
279 |
|
// (cut on calorimeter variables from Emiliano) |
280 |
if( |
if( |
281 |
npcfit[1] > 3 && //no. of fit planes on Y view |
use_CAL && |
282 |
// varcfit[1] < 50.&& //fit variance on Y view |
npcfit[1] > 15 && //no. of fit planes on Y view |
283 |
true){ |
varcfit[1] < 1000. && //fit variance on Y view |
284 |
|
true){ |
285 |
Float_t resy_p = cp->tbar[0][1] - cbar[0][1];if(resy_p < 0)resy_p= - resy_p; |
|
286 |
Float_t resy_i = ci->tbar[0][1] - cbar[0][1];if(resy_i < 0)resy_i= - resy_i; |
cp = GetCaloStoredTrack(tp->GetSeqNo()); |
287 |
|
ci = GetCaloStoredTrack(ti->GetSeqNo()); |
288 |
|
|
289 |
|
Float_t resy_p = cp->tbar[0][1] - cbar[0][1]; if(resy_p < 0)resy_p= - resy_p; |
290 |
|
Float_t resy_i = ci->tbar[0][1] - cbar[0][1]; if(resy_i < 0)resy_i= - resy_i; |
291 |
|
|
292 |
if(resy_p <= resy_i) tp_score++; |
if(resy_p <= resy_i) tp_score++; |
293 |
else ti_score++; |
else ti_score++; |
294 |
}; |
}; |
295 |
// ------------------------ |
// ------------------------ |
296 |
// TOF check |
// TOF check |
297 |
// ------------------------ |
// ------------------------ |
298 |
|
// check the number of hit pmts along the track |
299 |
|
// on S12 S21 and S32, where paddles are parallel to Y axis |
300 |
|
if( use_TOF ){ |
301 |
|
|
302 |
|
Int_t nphit_p =0; |
303 |
|
Int_t nphit_i =0; |
304 |
|
|
305 |
|
op = GetToFStoredTrack(tp->GetSeqNo()); |
306 |
|
oi = GetToFStoredTrack(ti->GetSeqNo()); |
307 |
|
|
308 |
|
/* cout << "track: npmtadc "<< op->npmtadc << endl; |
309 |
|
cout << "track: npmttdc "<< op->npmttdc << endl; |
310 |
|
cout << "image: npmtadc "<< oi->npmtadc << endl; |
311 |
|
cout << "image: npmttdc "<< oi->npmttdc << endl;*/ |
312 |
|
|
313 |
|
for (Int_t ih=0; ih < op->npmtadc; ih++){ |
314 |
|
Int_t pl = GetPlaneIndex( (op->pmtadc).At(ih) ); |
315 |
|
if(pl == 1 || pl == 2 || pl == 5)nphit_p++; |
316 |
|
}; |
317 |
|
|
318 |
|
for (Int_t ih=0; ih < oi->npmtadc; ih++){ |
319 |
|
Int_t pl = GetPlaneIndex( (oi->pmtadc).At(ih) ); |
320 |
|
if(pl == 1 || pl == 2 || pl == 5)nphit_i++; |
321 |
|
}; |
322 |
|
|
323 |
|
if( |
324 |
|
use_TOF && |
325 |
|
(nphit_p+nphit_i) !=0 && |
326 |
|
true){ |
327 |
|
|
328 |
|
if( nphit_p >= nphit_i) tp_score++; |
329 |
|
else ti_score++; |
330 |
|
}; |
331 |
|
}; |
332 |
|
if(tp_score == ti_score) use_TRK = true; |
333 |
|
// ------------------------ |
334 |
|
// tracker check |
335 |
|
// ------------------------ |
336 |
|
// chi**2 difference is not always large enough to distinguish among |
337 |
|
// the real track and its image. |
338 |
|
// Tracker check will be applied always when calorimeter and tof information is ambiguous. |
339 |
|
if(use_TRK){ |
340 |
|
if( tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ; |
341 |
|
else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ; |
342 |
|
}; |
343 |
|
|
344 |
// ------------------------ |
// ------------------------ |
345 |
// the winner is.... |
// the winner is.... |
346 |
// ------------------------ |
// ------------------------ |
347 |
if(tp_score > ti_score) ts = tp;//the track sorted by the tracker!! |
if (tp_score > ti_score) ts = tp;//the track sorted by the tracker!! |
348 |
else ts = ti;//its image!! |
else if (tp_score < ti_score) ts = ti;//its image!! |
349 |
|
else { |
350 |
|
ts = tp; |
351 |
|
// cout << "Warning - track image ambiguity not solved" << endl; |
352 |
|
// cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl; |
353 |
|
}; |
354 |
|
|
355 |
}else{ |
}else{ |
356 |
ts = tp; |
ts = tp; |
357 |
}; |
}; |
358 |
|
|
359 |
new(sorted[i]) TrkTrack(*ts); //save the track in the sorted array |
// cout <<" SortTracks() "<<i<<" -- "<<ts<<endl; |
360 |
|
sorted_tracks->Add(ts);//save the track in the sorted array |
361 |
|
// cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl; |
362 |
|
|
363 |
}; |
}; |
364 |
|
//Restore Object count |
365 |
return aa; |
//To save space in the table keeping track of all referenced objects |
366 |
|
//we assume that our events do not address each other. We reset the |
367 |
|
//object count to what it was at the beginning of the event. |
368 |
|
TProcessID::SetObjectCount(ObjectNumber); |
369 |
|
|
370 |
}; |
}; |
371 |
//-------------------------------------- |
//-------------------------------------- |
372 |
// |
// |
373 |
// |
// |
374 |
//-------------------------------------- |
//-------------------------------------- |
375 |
/** |
/** |
376 |
|
* This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2. |
377 |
|
* PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information. |
378 |
|
*/ |
379 |
|
TRefArray *PamLevel2::GetTracks(){ |
380 |
|
|
381 |
|
// *-*-*-*-*-*-*-*-*-*-*-*-* |
382 |
|
SortTracks("+CAL+TOF"); |
383 |
|
// *-*-*-*-*-*-*-*-*-*-*-*-* |
384 |
|
|
385 |
|
return sorted_tracks; |
386 |
|
}; |
387 |
|
//-------------------------------------- |
388 |
|
// |
389 |
|
// |
390 |
|
//-------------------------------------- |
391 |
|
/** |
392 |
* Retrieves the it-th Pamela "physical" track. |
* Retrieves the it-th Pamela "physical" track. |
393 |
* It override TrkLevel2::GetTrack(int it). |
* It override TrkLevel2::GetTrack(int it). |
394 |
* @param it Track number, ranging from 0 to GetNTracks(). |
* @param it Track number, ranging from 0 to GetNTracks(). |
395 |
*/ |
*/ |
396 |
PamTrack *PamLevel2::GetTrack(int it){ |
PamTrack *PamLevel2::GetTrack(int it){ |
397 |
|
|
398 |
TClonesArray *aa = this->GetTracks(); |
// *-*-*-*-*-*-*-*-*-*-*-*-* |
399 |
TClonesArray &sorted = *aa; |
SortTracks("+CAL+TOF"); |
400 |
|
// *-*-*-*-*-*-*-*-*-*-*-*-* |
|
TrkTrack *t = 0; |
|
|
CaloTrkVar *c = 0; |
|
|
ToFTrkVar *o = 0; |
|
|
|
|
|
if( it >=0 && it < TrkLevel2::GetNTracks() ){ |
|
|
t = (TrkTrack*)sorted[it]; |
|
|
c = CaloLevel2::GetCaloTrkVar(t->GetSeqNo()); |
|
|
o = ToFLevel2::GetToFTrkVar(t->GetSeqNo()); |
|
|
}; |
|
401 |
|
|
|
// hence create a "PamTrack" object |
|
402 |
PamTrack *track = 0; |
PamTrack *track = 0; |
403 |
if(t && c && o)track = new PamTrack(t,c,o); |
|
404 |
|
if( it >=0 && it < TrkLevel2::GetNTracks() && it<sorted_tracks->GetEntriesFast() ){ |
405 |
|
TrkTrack *t = (TrkTrack*)sorted_tracks->At(it); |
406 |
|
track = GetPamTrackAlong(t); |
407 |
|
}else{ |
408 |
|
cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl; |
409 |
|
}; |
410 |
|
|
411 |
return track; |
return track; |
412 |
|
|
413 |
}; |
}; |
414 |
|
|
415 |
//-------------------------------------- |
//-------------------------------------- |
416 |
// |
// |
417 |
// |
// |
418 |
//-------------------------------------- |
//-------------------------------------- |
419 |
/** |
/** |
420 |
* Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::GetTracks(). |
* Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks(). |
421 |
* @param it Track number, ranging from 0 to GetNTracks(). |
* @param it Track number, ranging from 0 to GetNTracks(). |
422 |
*/ |
*/ |
423 |
PamTrack *PamLevel2::GetTrackImage(int it){ |
PamTrack *PamLevel2::GetTrackImage(int it){ |
424 |
|
|
425 |
TClonesArray *aa = this->GetTracks(); |
// *-*-*-*-*-*-*-*-*-*-*-*-* |
426 |
TClonesArray &sorted = *aa; |
SortTracks("+CAL+TOF"); |
427 |
|
// *-*-*-*-*-*-*-*-*-*-*-*-* |
428 |
TrkTrack *t = 0; |
|
429 |
CaloTrkVar *c = 0; |
PamTrack *image = 0; |
430 |
ToFTrkVar *o = 0; |
|
|
|
|
431 |
if( it >=0 && it < TrkLevel2::GetNTracks() ){ |
if( it >=0 && it < TrkLevel2::GetNTracks() ){ |
432 |
TrkTrack *temp = (TrkTrack*)sorted[it]; |
TrkTrack *temp = (TrkTrack*)sorted_tracks->At(it); |
433 |
if( temp->HasImage() ){ |
if( temp->HasImage() ){ |
434 |
t = TrkLevel2::GetStoredTrack(temp->GetImageSeqNo()); |
TrkTrack *t = TrkLevel2::GetStoredTrack(temp->GetImageSeqNo()); |
435 |
c = CaloLevel2::GetCaloTrkVar(temp->GetImageSeqNo()); |
image = GetPamTrackAlong(t); |
436 |
o = ToFLevel2::GetToFTrkVar(temp->GetImageSeqNo()); |
}else{ |
437 |
|
cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl; |
438 |
}; |
}; |
439 |
|
}else{ |
440 |
|
cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl; |
441 |
}; |
}; |
442 |
|
|
|
// hence create a "PamTrack" object |
|
|
PamTrack *image = 0; |
|
|
if(t && c && o)image = new PamTrack(t,c,o); |
|
443 |
return image; |
return image; |
|
|
|
444 |
} |
} |
445 |
|
|
446 |
//-------------------------------------- |
//-------------------------------------- |
448 |
// |
// |
449 |
//-------------------------------------- |
//-------------------------------------- |
450 |
/** |
/** |
451 |
* Get the Pamela detector trees and make them friends. |
* Get the Pamela detector trees in a single file and make them friends. |
452 |
|
* @param f TFile pointer |
453 |
|
* @param detlist String to select trees to be included |
454 |
|
* @return Pointer to a TTree |
455 |
*/ |
*/ |
456 |
TTree *PamLevel2::LoadPamTrees(TFile *f){ |
TTree *PamLevel2::GetPamTree(TFile *f, TString detlist="+ALL"){ |
457 |
|
|
458 |
TTree *Tout =0; |
// cout << "WARNING!!! -- obsolete method -- \n"; |
459 |
|
// cout << "better use TChain *PamLevel2::GetPamTree(TList*, TString) \n"; |
460 |
|
|
461 |
|
TTree *Trout =0; |
462 |
|
|
463 |
// Tracker |
SetWhichTrees(detlist); |
464 |
|
// Tracker |
465 |
TTree *T = (TTree*)f->Get("Tracker"); |
TTree *T = (TTree*)f->Get("Tracker"); |
466 |
if(T) { |
if(T && (TRK2||TRK1||TRKh)) { |
467 |
T->SetBranchAddress("TrkLevel2", GetPointerToTrk()); |
if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerToTrk(2)); |
468 |
cout << "Tracker : set branch address TrkLevel2"<<endl; |
if(TRK2)cout << "Tracker : set branch address TrkLevel2"<<endl; |
469 |
if(!Tout)Tout=T; |
if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerToTrk(1)); |
470 |
|
if(TRK1)cout << "Tracker : set branch address TrkLevel1"<<endl; |
471 |
|
// if(TRKh)T->SetBranchAddress("TrkHough", GetPointerToTrk(3)); |
472 |
|
// if(TRKh)cout << "Tracker : set branch address TrkHough"<<endl; |
473 |
|
Trout=T; |
474 |
}else{ |
}else{ |
475 |
cout << "Tracker : missing tree"<<endl; |
cout << "Tracker : missing tree"<<endl; |
476 |
}; |
}; |
477 |
// Calorimeter |
// Calorimeter |
478 |
TTree *C = (TTree*)f->Get("Calorimeter"); |
TTree *C = (TTree*)f->Get("Calorimeter"); |
479 |
if(C) { |
if(C && CAL2) { |
480 |
C->SetBranchAddress("CaloLevel2", GetPointerToCalo()); |
C->SetBranchAddress("CaloLevel2", GetPointerToCalo()); |
481 |
cout << "Calorimeter : set branch address CaloLevel2"<<endl; |
cout << "Calorimeter : set branch address CaloLevel2"<<endl; |
482 |
if(!Tout)Tout=C; |
if(!Trout)Trout=C; |
483 |
else Tout->AddFriend(C); |
else Trout->AddFriend(C); |
484 |
}else{ |
}else{ |
485 |
cout << "Calorimeter : missing tree"<<endl; |
cout << "Calorimeter : missing tree"<<endl; |
486 |
}; |
}; |
487 |
// ToF |
// ToF |
488 |
TTree *O = (TTree*)f->Get("ToF"); |
TTree *O = (TTree*)f->Get("ToF"); |
489 |
if(O) { |
if(O && TOF) { |
490 |
O->SetBranchAddress("ToFLevel2", GetPointerToToF()); |
O->SetBranchAddress("ToFLevel2", GetPointerToToF()); |
491 |
cout << "ToF : set branch address ToFLevel2"<<endl; |
cout << "ToF : set branch address ToFLevel2"<<endl; |
492 |
if(!Tout)Tout=O; |
if(!Trout)Trout=O; |
493 |
else Tout->AddFriend(O); |
else Trout->AddFriend(O); |
494 |
}else{ |
}else{ |
495 |
cout << "ToF : missing tree"<<endl; |
cout << "ToF : missing tree"<<endl; |
496 |
}; |
}; |
497 |
// Trigger |
// Trigger |
498 |
TTree *R = (TTree*)f->Get("Trigger"); |
TTree *R = (TTree*)f->Get("Trigger"); |
499 |
if(R) { |
if(R && TRG) { |
500 |
R->SetBranchAddress("TrigLevel2", GetPointerToTrig()); |
R->SetBranchAddress("TrigLevel2", GetPointerToTrig()); |
501 |
cout << "Trigger : set branch address TrigLevel2"<<endl; |
cout << "Trigger : set branch address TrigLevel2"<<endl; |
502 |
if(!Tout)Tout=O; |
if(!Trout)Trout=O; |
503 |
else Tout->AddFriend(R); |
else Trout->AddFriend(R); |
504 |
}else{ |
}else{ |
505 |
cout << "Trigger : missing tree"<<endl; |
cout << "Trigger : missing tree"<<endl; |
506 |
}; |
}; |
507 |
// S4 |
// S4 |
508 |
TTree *S = (TTree*)f->Get("S4"); |
TTree *S = (TTree*)f->Get("S4"); |
509 |
if(S) { |
if(S && S4) { |
510 |
S->SetBranchAddress("S4Level2", GetPointerToS4()); |
S->SetBranchAddress("S4Level2", GetPointerToS4()); |
511 |
cout << "S4 : set branch address S4Level2"<<endl; |
cout << "S4 : set branch address S4Level2"<<endl; |
512 |
if(!Tout)Tout=O; |
if(!Trout)Trout=O; |
513 |
else Tout->AddFriend(S); |
else Trout->AddFriend(S); |
514 |
}else{ |
}else{ |
515 |
cout << "S4 : missing tree"<<endl; |
cout << "S4 : missing tree"<<endl; |
516 |
}; |
}; |
517 |
// Neutron Detector |
// Neutron Detector |
518 |
TTree *N = (TTree*)f->Get("NeutronD"); |
TTree *N = (TTree*)f->Get("NeutronD"); |
519 |
if(N) { |
if(N && ND) { |
520 |
N->SetBranchAddress("NDLevel2", GetPointerToND()); |
N->SetBranchAddress("NDLevel2", GetPointerToND()); |
521 |
cout << "NeutronD : set branch address NDLevel2"<<endl; |
cout << "NeutronD : set branch address NDLevel2"<<endl; |
522 |
if(!Tout)Tout=O; |
if(!Trout)Trout=O; |
523 |
else Tout->AddFriend(N); |
else Trout->AddFriend(N); |
524 |
}else{ |
}else{ |
525 |
cout << "NeutronD : missing tree"<<endl; |
cout << "NeutronD : missing tree"<<endl; |
526 |
}; |
}; |
527 |
// Anticounters |
// Anticounters |
528 |
TTree *A = (TTree*)f->Get("Anticounter"); |
TTree *A = (TTree*)f->Get("Anticounter"); |
529 |
if(A) { |
if(A && AC) { |
530 |
A->SetBranchAddress("AcLevel2", GetPointerToAc()); |
A->SetBranchAddress("AcLevel2", GetPointerToAc()); |
531 |
cout << "Anticounter : set branch address AcLevel2"<<endl; |
cout << "Anticounter : set branch address AcLevel2"<<endl; |
532 |
if(!Tout)Tout=O; |
if(!Trout)Trout=O; |
533 |
else Tout->AddFriend(A); |
else Trout->AddFriend(A); |
534 |
}else{ |
}else{ |
535 |
cout << "Anticounter : missing tree"<<endl; |
cout << "Anticounter : missing tree"<<endl; |
536 |
}; |
}; |
537 |
|
// Orbital Info |
538 |
|
TTree *B = (TTree*)f->Get("OrbitalInfo"); |
539 |
|
if(B && ORB) { |
540 |
|
B->SetBranchAddress("OrbitalInfo", GetPointerToOrb()); |
541 |
|
cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl; |
542 |
|
if(!Trout)Trout=O; |
543 |
|
else Trout->AddFriend(B); |
544 |
|
}else{ |
545 |
|
cout << "OrbitalInfo : missing tree"<<endl; |
546 |
|
}; |
547 |
|
|
548 |
|
cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl; |
549 |
|
|
550 |
|
return Trout; |
551 |
|
|
552 |
|
} |
553 |
|
//-------------------------------------- |
554 |
|
// |
555 |
|
// |
556 |
|
//-------------------------------------- |
557 |
|
/** |
558 |
|
* Get list of Level2 files. |
559 |
|
* @param ddir Level2 data directory. |
560 |
|
* @param flisttxt Name of txt file containing file list. |
561 |
|
* @return Pointer to a TList of TSystemFiles |
562 |
|
* If no input file list is given , all the Level2 files inside the directory are processed. |
563 |
|
*/ |
564 |
|
TList* PamLevel2::GetListOfLevel2Files(TString ddir, TString flisttxt = ""){ |
565 |
|
|
566 |
|
TString wdir = gSystem->WorkingDirectory(); |
567 |
|
|
568 |
|
if(ddir=="")ddir = wdir; |
569 |
|
// TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir); |
570 |
|
cout << "Level2 data directory : "<< ddir << endl; |
571 |
|
|
572 |
|
TList *contents = new TList; // create output list |
573 |
|
contents->SetOwner(); |
574 |
|
|
575 |
|
char *fullpath; |
576 |
|
|
577 |
|
// if no input file list is given: |
578 |
|
if ( flisttxt != "" ){ |
579 |
|
|
580 |
|
if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) )return 0; |
581 |
|
|
582 |
|
// flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt)); |
583 |
|
flisttxt = fullpath; |
584 |
|
|
585 |
|
if( !gSystem->ChangeDirectory(ddir) )return 0; |
586 |
|
|
587 |
|
cout <<"Input file list : " << flisttxt <<endl; |
588 |
|
ifstream in; |
589 |
|
in.open(flisttxt, ios::in); //open input file list |
590 |
|
while (1) { |
591 |
|
TString file; |
592 |
|
in >> file; |
593 |
|
if (!in.good()) break; |
594 |
|
// cout <<"(1) " << file << endl; |
595 |
|
if(file.Contains("#"))file = file(0,file.First("#")); |
596 |
|
// cout <<"(2) " << file << endl; |
597 |
|
|
598 |
|
if( gSystem->IsFileInIncludePath(file,&fullpath) ){ |
599 |
|
|
600 |
|
contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list |
601 |
|
|
602 |
|
}else{ |
603 |
|
if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl; |
604 |
|
}; |
605 |
|
}; |
606 |
|
in.close(); |
607 |
|
|
608 |
|
}else{ |
609 |
|
|
610 |
|
cout << "No input file list given."<<endl; |
611 |
|
cout << "Check for existing root files."<<endl; |
612 |
|
// cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl; |
613 |
|
|
614 |
|
TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir); |
615 |
|
TList *temp = datadir->GetListOfFiles(); |
616 |
|
// temp->Print(); |
617 |
|
// cout << "*************************************" << endl; |
618 |
|
|
619 |
|
TIter next(temp); |
620 |
|
TSystemFile *questo = 0; |
621 |
|
|
622 |
|
|
623 |
|
while ( (questo = (TSystemFile*) next()) ) { |
624 |
|
TString name = questo-> GetName(); |
625 |
|
if( name.EndsWith(".root") ){ |
626 |
|
char *fullpath; |
627 |
|
gSystem->IsFileInIncludePath(name,&fullpath); |
628 |
|
contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath))); |
629 |
|
}; |
630 |
|
} |
631 |
|
delete temp; |
632 |
|
delete datadir; |
633 |
|
|
634 |
|
}; |
635 |
|
gSystem->ChangeDirectory(wdir); // back to the working directory |
636 |
|
// cout << endl << "Selected files:" << endl; |
637 |
|
// contents->Print(); |
638 |
|
cout << contents->GetEntries()<<" files selected\n"; |
639 |
|
// cout << endl; |
640 |
|
// cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl; |
641 |
|
return contents; |
642 |
|
}; |
643 |
|
//-------------------------------------- |
644 |
|
// |
645 |
|
// |
646 |
|
//-------------------------------------- |
647 |
|
/** |
648 |
|
* Get the Pamela detector chains from a list of files and make them friends. |
649 |
|
* @param fl Pointer to a TList of TSystemFiles |
650 |
|
* @param detlist String to select trees to be included |
651 |
|
* @return Pointer to a TChain |
652 |
|
*/ |
653 |
|
TChain *PamLevel2::GetPamTree(TList *fl, TString detlist="+ALL"){ |
654 |
|
|
655 |
|
// TChain *Tout=0; |
656 |
|
// if(Tout)Tout->Delete(); |
657 |
|
// Tout = NULL; |
658 |
|
|
659 |
|
TChain *Tout =0; |
660 |
|
|
661 |
|
SetWhichTrees(detlist); |
662 |
|
|
663 |
|
TChain *T = 0; |
664 |
|
TChain *C = 0; |
665 |
|
TChain *O = 0; |
666 |
|
TChain *R = 0; |
667 |
|
TChain *S = 0; |
668 |
|
TChain *N = 0; |
669 |
|
TChain *A = 0; |
670 |
|
TChain *B = 0; |
671 |
|
|
672 |
|
if(TRK2||TRK1||TRKh) T = new TChain("Tracker"); |
673 |
|
if(CAL2||CAL1) C = new TChain("Calorimeter"); |
674 |
|
if(TOF) O = new TChain("ToF"); |
675 |
|
if(TRG) R = new TChain("Trigger"); |
676 |
|
if(S4) S = new TChain("S4"); |
677 |
|
if(ND) N = new TChain("NeutronD"); |
678 |
|
if(AC) A = new TChain("Anticounter"); |
679 |
|
if(ORB) B = new TChain("OrbitalInfo"); |
680 |
|
|
681 |
|
// loop over files and create chains |
682 |
|
TIter next(fl); |
683 |
|
TSystemFile *questo = 0; |
684 |
|
while ( (questo = (TSystemFile*) next()) ) { |
685 |
|
TString name = questo->GetName(); |
686 |
|
// cout << "File: "<< name << endl; |
687 |
|
if( CheckLevel2File(name) ){ |
688 |
|
if(TRK2||TRK1||TRKh) T->Add(name); |
689 |
|
if(CAL1||CAL2) C->Add(name); |
690 |
|
if(TOF) O->Add(name); |
691 |
|
if(TRG) R->Add(name); |
692 |
|
if(S4) S->Add(name); |
693 |
|
if(ND) N->Add(name); |
694 |
|
if(AC) A->Add(name); |
695 |
|
if(ORB) B->Add(name); |
696 |
|
}; |
697 |
|
} |
698 |
|
|
699 |
|
cout << "done chain \n"; |
700 |
|
|
701 |
|
// Tracker |
702 |
|
if(TRK2||TRK1||TRKh)if(!Tout)Tout=T; |
703 |
|
// Calorimeter |
704 |
|
if(CAL2||CAL1) { |
705 |
|
if(!Tout)Tout=C; |
706 |
|
else Tout->AddFriend("Calorimeter"); |
707 |
|
}; |
708 |
|
// ToF |
709 |
|
if(TOF) { |
710 |
|
if(!Tout)Tout=O; |
711 |
|
else Tout->AddFriend("ToF"); |
712 |
|
}; |
713 |
|
// Trigger |
714 |
|
if(TRG) { |
715 |
|
if(!Tout)Tout=O; |
716 |
|
else Tout->AddFriend("Trigger"); |
717 |
|
}; |
718 |
|
// S4 |
719 |
|
if(S4) { |
720 |
|
if(!Tout)Tout=O; |
721 |
|
else Tout->AddFriend("S4"); |
722 |
|
}; |
723 |
|
// Neutron Detector |
724 |
|
if(ND) { |
725 |
|
if(!Tout)Tout=O; |
726 |
|
else Tout->AddFriend("NeutronD"); |
727 |
|
}; |
728 |
|
// Anticounters |
729 |
|
if(AC) { |
730 |
|
if(!Tout)Tout=O; |
731 |
|
else Tout->AddFriend("Anticounter"); |
732 |
|
}; |
733 |
|
// OrbitalInfo |
734 |
|
if(ORB) { |
735 |
|
if(!Tout)Tout=O; |
736 |
|
else Tout->AddFriend("OrbitalInfo"); |
737 |
|
}; |
738 |
|
|
739 |
|
// cout<<endl<<" Number of entries: "<<Tout->GetEntries()<<endl<<endl; |
740 |
|
|
741 |
|
// if( Tout->GetEntries() )PamLevel2::SetBranchAddress(); |
742 |
|
if( Tout->GetEntries() )PamLevel2::SetBranchAddress( Tout ); |
743 |
|
|
744 |
return Tout; |
return Tout; |
745 |
|
} |
746 |
|
|
747 |
|
|
748 |
|
|
749 |
|
//-------------------------------------- |
750 |
|
// |
751 |
|
// |
752 |
|
//-------------------------------------- |
753 |
|
/** |
754 |
|
* Set branch addresses for Pamela friend trees |
755 |
|
*/ |
756 |
|
void PamLevel2::SetBranchAddress(TTree *t){ |
757 |
|
|
758 |
|
|
759 |
|
|
760 |
|
TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2"); |
761 |
|
TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1"); |
762 |
|
TRKh = TRKh & t->GetBranchStatus("TrkHough"); |
763 |
|
CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2"); |
764 |
|
CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1"); |
765 |
|
TOF = TOF & t->GetBranchStatus("ToFLevel2"); |
766 |
|
TRG = TRG & t->GetBranchStatus("TrigLevel2"); |
767 |
|
S4 = S4 & t->GetBranchStatus("S4Level2"); |
768 |
|
ND = ND & t->GetBranchStatus("NDLevel2"); |
769 |
|
AC = AC & t->GetBranchStatus("AcLevel2"); |
770 |
|
ORB = ORB & t->GetBranchStatus("OrbitalInfo"); |
771 |
|
|
772 |
|
|
773 |
|
// Tracker |
774 |
|
if(TRK1) { |
775 |
|
t->SetBranchAddress("TrkLevel1", GetPointerToTrk(1)); |
776 |
|
cout << "Tracker : set branch address TrkLevel1"<<endl; |
777 |
|
}; |
778 |
|
if(TRK2) { |
779 |
|
t->SetBranchAddress("TrkLevel2", GetPointerToTrk(2)); |
780 |
|
cout << "Tracker : set branch address TrkLevel2"<<endl; |
781 |
|
}; |
782 |
|
if(TRKh) { |
783 |
|
t->SetBranchAddress("TrkHough", GetPointerToTrk(3)); |
784 |
|
cout << "Tracker : set branch address TrkHough"<<endl; |
785 |
|
}; |
786 |
|
|
787 |
|
// Calorimeter |
788 |
|
if(CAL1) { |
789 |
|
t->SetBranchAddress("CaloLevel1", GetPointerToCalo(1)); |
790 |
|
cout << "Calorimeter : set branch address CaloLevel1"<<endl; |
791 |
|
}; |
792 |
|
if(CAL2) { |
793 |
|
t->SetBranchAddress("CaloLevel2", GetPointerToCalo(2)); |
794 |
|
cout << "Calorimeter : set branch address CaloLevel2"<<endl; |
795 |
|
}; |
796 |
|
|
797 |
|
// ToF |
798 |
|
if(TOF) { |
799 |
|
t->SetBranchAddress("ToFLevel2", GetPointerToToF()); |
800 |
|
cout << "ToF : set branch address ToFLevel2"<<endl; |
801 |
|
}; |
802 |
|
// Trigger |
803 |
|
if(TRG) { |
804 |
|
t->SetBranchAddress("TrigLevel2", GetPointerToTrig()); |
805 |
|
cout << "Trigger : set branch address TrigLevel2"<<endl; |
806 |
|
}; |
807 |
|
// S4 |
808 |
|
if(S4) { |
809 |
|
t->SetBranchAddress("S4Level2", GetPointerToS4()); |
810 |
|
cout << "S4 : set branch address S4Level2"<<endl; |
811 |
|
}; |
812 |
|
// Neutron Detector |
813 |
|
if(ND) { |
814 |
|
t->SetBranchAddress("NDLevel2", GetPointerToND()); |
815 |
|
cout << "NeutronD : set branch address NDLevel2"<<endl; |
816 |
|
}; |
817 |
|
// Anticounters |
818 |
|
if(AC) { |
819 |
|
t->SetBranchAddress("AcLevel2", GetPointerToAc()); |
820 |
|
cout << "Anticounter : set branch address AcLevel2"<<endl; |
821 |
|
}; |
822 |
|
// OrbitalInfo |
823 |
|
if(ORB) { |
824 |
|
t->SetBranchAddress("OrbitalInfo", GetPointerToOrb()); |
825 |
|
cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl; |
826 |
|
}; |
827 |
|
|
828 |
|
} |
829 |
|
/** |
830 |
|
* Set branch addresses for Pamela friend trees |
831 |
|
*/ |
832 |
|
void PamLevel2::SetBranchAddress(TChain *t){ |
833 |
|
|
834 |
|
|
835 |
|
|
836 |
|
|
837 |
|
TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2"); |
838 |
|
TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1"); |
839 |
|
TRKh = TRKh & t->GetBranchStatus("TrkHough"); |
840 |
|
CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1"); |
841 |
|
CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2"); |
842 |
|
TOF = TOF & t->GetBranchStatus("ToFLevel2"); |
843 |
|
TRG = TRG & t->GetBranchStatus("TrigLevel2"); |
844 |
|
S4 = S4 & t->GetBranchStatus("S4Level2"); |
845 |
|
ND = ND & t->GetBranchStatus("NDLevel2"); |
846 |
|
AC = AC & t->GetBranchStatus("AcLevel2"); |
847 |
|
ORB = ORB & t->GetBranchStatus("OrbitalInfo"); |
848 |
|
|
849 |
|
|
850 |
|
|
851 |
|
// Tracker |
852 |
|
if(TRK1) { |
853 |
|
t->SetBranchAddress("TrkLevel1", GetPointerToTrk(1)); |
854 |
|
cout << "Tracker : set branch address TrkLevel1"<<endl; |
855 |
|
}; |
856 |
|
if(TRK2) { |
857 |
|
t->SetBranchAddress("TrkLevel2", GetPointerToTrk(2)); |
858 |
|
cout << "Tracker : set branch address TrkLevel2"<<endl; |
859 |
|
}; |
860 |
|
if(TRKh) { |
861 |
|
t->SetBranchAddress("TrkHough", GetPointerToTrk(3)); |
862 |
|
cout << "Tracker : set branch address TrkHough"<<endl; |
863 |
|
}; |
864 |
|
|
865 |
|
// Calorimeter |
866 |
|
if(CAL1) { |
867 |
|
t->SetBranchAddress("CaloLevel1", GetPointerToCalo(1)); |
868 |
|
cout << "Calorimeter : set branch address CaloLevel1"<<endl; |
869 |
|
}; |
870 |
|
if(CAL2) { |
871 |
|
t->SetBranchAddress("CaloLevel2", GetPointerToCalo(2)); |
872 |
|
cout << "Calorimeter : set branch address CaloLevel2"<<endl; |
873 |
|
}; |
874 |
|
|
875 |
|
// ToF |
876 |
|
if(TOF) { |
877 |
|
t->SetBranchAddress("ToFLevel2", GetPointerToToF()); |
878 |
|
cout << "ToF : set branch address ToFLevel2"<<endl; |
879 |
|
}; |
880 |
|
// Trigger |
881 |
|
if(TRG) { |
882 |
|
t->SetBranchAddress("TrigLevel2", GetPointerToTrig()); |
883 |
|
cout << "Trigger : set branch address TrigLevel2"<<endl; |
884 |
|
}; |
885 |
|
// S4 |
886 |
|
if(S4) { |
887 |
|
t->SetBranchAddress("S4Level2", GetPointerToS4()); |
888 |
|
cout << "S4 : set branch address S4Level2"<<endl; |
889 |
|
}; |
890 |
|
// Neutron Detector |
891 |
|
if(ND) { |
892 |
|
t->SetBranchAddress("NDLevel2", GetPointerToND()); |
893 |
|
cout << "NeutronD : set branch address NDLevel2"<<endl; |
894 |
|
}; |
895 |
|
// Anticounters |
896 |
|
if(AC) { |
897 |
|
t->SetBranchAddress("AcLevel2", GetPointerToAc()); |
898 |
|
cout << "Anticounter : set branch address AcLevel2"<<endl; |
899 |
|
}; |
900 |
|
// OrbitalInfo |
901 |
|
if(ORB) { |
902 |
|
t->SetBranchAddress("OrbitalInfo", GetPointerToOrb()); |
903 |
|
cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl; |
904 |
|
}; |
905 |
|
|
906 |
|
} |
907 |
|
//-------------------------------------- |
908 |
|
// |
909 |
|
// |
910 |
|
//-------------------------------------- |
911 |
|
void *PamLevel2::GetPointerTo(const char* c ){ |
912 |
|
// cout << "objname "<< objname << endl; |
913 |
|
TString objname = c; |
914 |
|
if(!objname.CompareTo("TrkLevel1"))return &trk1_obj; |
915 |
|
if(!objname.CompareTo("TrkLevel2"))return &trk2_obj; |
916 |
|
if(!objname.CompareTo("TrkHough"))return &trkh_obj; |
917 |
|
|
918 |
|
return NULL; |
919 |
|
}; |
920 |
|
//-------------------------------------- |
921 |
|
// |
922 |
|
// |
923 |
|
//-------------------------------------- |
924 |
|
/** |
925 |
|
* Get the Run tree chain from a list of files. |
926 |
|
* @param fl Pointer to a TList of TSystemFiles |
927 |
|
* @return Pointer to a TChain |
928 |
|
*/ |
929 |
|
TChain *PamLevel2::GetRunTree(TList *fl){ |
930 |
|
|
931 |
|
TChain *R = new TChain("Run"); |
932 |
|
|
933 |
|
// loop over files and create chains |
934 |
|
TIter next(fl); |
935 |
|
TSystemFile *questo = 0; |
936 |
|
while ( (questo = (TSystemFile*) next()) ) { |
937 |
|
TString name = questo->GetName(); |
938 |
|
// cout << "File: "<< name << endl; |
939 |
|
if( CheckLevel2File(name) ){ |
940 |
|
R->Add(name); |
941 |
|
}; |
942 |
|
} |
943 |
|
|
944 |
|
R->SetBranchAddress("RunInfo", GetPointerToRun()); |
945 |
|
cout << "Run : set branch address RunInfo"<<endl; |
946 |
|
|
947 |
|
return R; |
948 |
|
|
949 |
} |
} |
950 |
|
//-------------------------------------- |
951 |
|
// |
952 |
|
// |
953 |
|
//-------------------------------------- |
954 |
|
/** |
955 |
|
* Get the Run tree from a file. |
956 |
|
* @param f Pointer to a TFile |
957 |
|
* @return Pointer to a TTree |
958 |
|
*/ |
959 |
|
TTree *PamLevel2::GetRunTree(TFile *f){ |
960 |
|
|
961 |
|
|
962 |
|
TTree *R = (TTree*)f->Get("Run"); |
963 |
|
|
964 |
|
R->SetBranchAddress("RunInfo", GetPointerToRun()); |
965 |
|
cout << "Run : set branch address RunInfo"<<endl; |
966 |
|
|
967 |
|
return R; |
968 |
|
|
969 |
|
} |
970 |
|
//-------------------------------------- |
971 |
|
// |
972 |
|
// |
973 |
|
//-------------------------------------- |
974 |
|
/** |
975 |
|
* Set which trees shoul be analysed |
976 |
|
* @param detlist TString containing the sequence of trees required |
977 |
|
*/ |
978 |
|
void PamLevel2::SetWhichTrees(TString detlist){ |
979 |
|
|
980 |
|
if(detlist.Contains("+ALL", TString::kIgnoreCase)){ |
981 |
|
CAL1 = true; |
982 |
|
CAL2 = true; |
983 |
|
TRK2 = true; |
984 |
|
TRK1 = false; |
985 |
|
TRKh = false; |
986 |
|
TRG = true; |
987 |
|
TOF = true; |
988 |
|
S4 = true; |
989 |
|
ND = true; |
990 |
|
AC = true; |
991 |
|
ORB = true; |
992 |
|
}else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){ |
993 |
|
CAL1 = false; |
994 |
|
CAL2 = false; |
995 |
|
TRK2 = false; |
996 |
|
TRK1 = false; |
997 |
|
TRKh = false; |
998 |
|
TRG = false; |
999 |
|
TOF = false; |
1000 |
|
S4 = false; |
1001 |
|
ND = false; |
1002 |
|
AC = false; |
1003 |
|
ORB = false; |
1004 |
|
}; |
1005 |
|
|
1006 |
|
// ------------------------------------------------------------------------- |
1007 |
|
if( detlist.Contains("CAL1", TString::kIgnoreCase) ){ |
1008 |
|
if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false; |
1009 |
|
if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true; |
1010 |
|
}; |
1011 |
|
|
1012 |
|
if( detlist.Contains("CAL2", TString::kIgnoreCase)){ |
1013 |
|
if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false; |
1014 |
|
if ( detlist.Contains("+CAL2", TString::kIgnoreCase) )CAL2=true; |
1015 |
|
}; |
1016 |
|
|
1017 |
|
if( detlist.Contains("+CAL", TString::kIgnoreCase) && !CAL1 && !CAL2 )CAL2=true; |
1018 |
|
if( detlist.Contains("-CAL", TString::kIgnoreCase) && CAL1 && CAL2 ){ |
1019 |
|
CAL2=false; |
1020 |
|
CAL1=false; |
1021 |
|
} |
1022 |
|
// ------------------------------------------------------------------------- |
1023 |
|
if( detlist.Contains("TRK1", TString::kIgnoreCase) ){ |
1024 |
|
if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false; |
1025 |
|
if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true; |
1026 |
|
}; |
1027 |
|
|
1028 |
|
if( detlist.Contains("TRK2", TString::kIgnoreCase)){ |
1029 |
|
if ( detlist.Contains("-TRK2", TString::kIgnoreCase) )TRK2=false; |
1030 |
|
if ( detlist.Contains("+TRK2", TString::kIgnoreCase) )TRK2=true; |
1031 |
|
}; |
1032 |
|
|
1033 |
|
if( detlist.Contains("TRKh", TString::kIgnoreCase)){ |
1034 |
|
if ( detlist.Contains("-TRKh", TString::kIgnoreCase) )TRKh=false; |
1035 |
|
if ( detlist.Contains("+TRKh", TString::kIgnoreCase) )TRKh=true; |
1036 |
|
}; |
1037 |
|
|
1038 |
|
if( detlist.Contains("+TRK", TString::kIgnoreCase) && !TRK1 && !TRK2 && !TRKh )TRK2=true; |
1039 |
|
if( detlist.Contains("-TRK", TString::kIgnoreCase) && TRK1 && TRK2 && TRKh){ |
1040 |
|
TRK2=false; |
1041 |
|
TRK1=false; |
1042 |
|
TRKh=false; |
1043 |
|
} |
1044 |
|
// ------------------------------------------------------------------------- |
1045 |
|
|
1046 |
|
|
1047 |
|
|
1048 |
|
// if( detlist.Contains("-TRK", TString::kIgnoreCase) )TRK2 = false; |
1049 |
|
// else if( detlist.Contains("+TRK", TString::kIgnoreCase) )TRK2 = true; |
1050 |
|
|
1051 |
|
// if( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1 = false; |
1052 |
|
// else if( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1 = true; |
1053 |
|
|
1054 |
|
// if( detlist.Contains("-TRKh", TString::kIgnoreCase) )TRKh = false; |
1055 |
|
// else if( detlist.Contains("+TRKh", TString::kIgnoreCase) )TRKh = true; |
1056 |
|
|
1057 |
|
if( detlist.Contains("-TRG", TString::kIgnoreCase) )TRG = false; |
1058 |
|
else if( detlist.Contains("+TRG", TString::kIgnoreCase) )TRG = true; |
1059 |
|
|
1060 |
|
if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false; |
1061 |
|
else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true; |
1062 |
|
|
1063 |
|
if( detlist.Contains("-S4", TString::kIgnoreCase) )S4 = false; |
1064 |
|
else if( detlist.Contains("+S4", TString::kIgnoreCase) )S4 = true; |
1065 |
|
|
1066 |
|
if( detlist.Contains("-ND", TString::kIgnoreCase) )ND = false; |
1067 |
|
else if( detlist.Contains("+ND", TString::kIgnoreCase) )ND = true; |
1068 |
|
|
1069 |
|
if( detlist.Contains("-AC", TString::kIgnoreCase) )AC = false; |
1070 |
|
else if( detlist.Contains("+AC", TString::kIgnoreCase) )AC = true; |
1071 |
|
|
1072 |
|
if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false; |
1073 |
|
else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true; |
1074 |
|
|
1075 |
|
}; |
1076 |
|
//-------------------------------------- |
1077 |
|
// |
1078 |
|
// |
1079 |
|
//-------------------------------------- |
1080 |
|
/** |
1081 |
|
* Check if a file contains selected Pamela Level2 trees. |
1082 |
|
* @param name File name |
1083 |
|
* @return true if the file is ok. |
1084 |
|
*/ |
1085 |
|
Bool_t PamLevel2::CheckLevel2File(TString name){ |
1086 |
|
|
1087 |
|
Bool_t CAL1__ok = false; |
1088 |
|
Bool_t CAL2__ok = false; |
1089 |
|
Bool_t TRK2__ok = false; |
1090 |
|
Bool_t TRK1__ok = false; |
1091 |
|
Bool_t TRKh__ok = false; |
1092 |
|
Bool_t TRG__ok = false; |
1093 |
|
Bool_t TOF__ok = false; |
1094 |
|
Bool_t S4__ok = false; |
1095 |
|
Bool_t ND__ok = false; |
1096 |
|
Bool_t AC__ok = false; |
1097 |
|
Bool_t ORB__ok = false; |
1098 |
|
|
1099 |
|
Bool_t RUN__ok = false; |
1100 |
|
|
1101 |
|
|
1102 |
|
|
1103 |
|
cout << "Checking file: "<<name<<endl; |
1104 |
|
TFile *f = new TFile(name.Data()); |
1105 |
|
if( !f || f->IsZombie() ){ |
1106 |
|
cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false; |
1107 |
|
} |
1108 |
|
// cout << "Get list of keys: "<<f<<endl; |
1109 |
|
TList *lk = f->GetListOfKeys(); |
1110 |
|
// lk->Print(); |
1111 |
|
TIter next(lk); |
1112 |
|
TKey *key =0; |
1113 |
|
|
1114 |
|
Int_t nev = 0; |
1115 |
|
|
1116 |
|
while( (key = (TKey*)next()) ){ |
1117 |
|
|
1118 |
|
// cout << key->GetName() << endl; |
1119 |
|
// cout << " Get tree: " << f->Get(key->GetName())<<endl; |
1120 |
|
// nev_previous = nev; |
1121 |
|
// cout << " n.entries "<< nev <<endl; |
1122 |
|
// if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){ |
1123 |
|
// nev = ((TTree*)f->Get(key->GetName()))->GetEntries(); |
1124 |
|
// cout << "File: "<< f->GetName() <<" discarded ---- "<< key->GetName() << " tree: n.entries does not match "<<nev<<" "<<nev_previous<< endl; |
1125 |
|
// return false; |
1126 |
|
// }; |
1127 |
|
|
1128 |
|
if( !strcmp(key->GetName(),"Run" ) )RUN__ok = true; |
1129 |
|
|
1130 |
|
//========================================================= |
1131 |
|
if( !strcmp(key->GetName(),"Trigger" ) ){ |
1132 |
|
TRG__ok = true; |
1133 |
|
if(TRG){ |
1134 |
|
Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries(); |
1135 |
|
if( nev && nevt!=nev){ |
1136 |
|
cout << "File: "<< f->GetName() <<" discarded ---- Trigger tree has "<<nevt<<" events instead of "<<nev<< endl; |
1137 |
|
return false; |
1138 |
|
} |
1139 |
|
nev=nevt; |
1140 |
|
} |
1141 |
|
} |
1142 |
|
//========================================================= |
1143 |
|
if( !strcmp(key->GetName(),"ToF" ) ){ |
1144 |
|
TOF__ok = true; |
1145 |
|
if(TOF){ |
1146 |
|
Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries(); |
1147 |
|
if( nev && nevt!=nev){ |
1148 |
|
cout << "File: "<< f->GetName() <<" discarded ---- ToF tree has "<<nevt<<" events instead of "<<nev<< endl; |
1149 |
|
return false; |
1150 |
|
} |
1151 |
|
nev=nevt; |
1152 |
|
} |
1153 |
|
} |
1154 |
|
//========================================================= |
1155 |
|
if( !strcmp(key->GetName(),"S4" ) ){ |
1156 |
|
S4__ok = true; |
1157 |
|
if(S4){ |
1158 |
|
Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries(); |
1159 |
|
if( nev && nevt!=nev){ |
1160 |
|
cout << "File: "<< f->GetName() <<" discarded ---- S4 tree has "<<nevt<<" events instead of "<<nev<< endl; |
1161 |
|
return false; |
1162 |
|
} |
1163 |
|
nev=nevt; |
1164 |
|
} |
1165 |
|
} |
1166 |
|
//========================================================= |
1167 |
|
|
1168 |
|
if( !strcmp(key->GetName(),"NeutronD" ) ){ |
1169 |
|
ND__ok = true; |
1170 |
|
if(ND){ |
1171 |
|
Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries(); |
1172 |
|
if( nev && nevt!=nev){ |
1173 |
|
cout << "File: "<< f->GetName() <<" discarded ---- NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl; |
1174 |
|
return false; |
1175 |
|
} |
1176 |
|
nev=nevt; |
1177 |
|
} |
1178 |
|
} |
1179 |
|
//========================================================= |
1180 |
|
if( !strcmp(key->GetName(),"Anticounter") ){ |
1181 |
|
AC__ok = true; |
1182 |
|
if(AC){ |
1183 |
|
Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries(); |
1184 |
|
if( nev && nevt!=nev){ |
1185 |
|
cout << "File: "<< f->GetName() <<" discarded ---- Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl; |
1186 |
|
return false; |
1187 |
|
} |
1188 |
|
nev=nevt; |
1189 |
|
} |
1190 |
|
} |
1191 |
|
//========================================================= |
1192 |
|
if( !strcmp(key->GetName(),"OrbitalInfo") ){ |
1193 |
|
ORB__ok = true; |
1194 |
|
if(ORB){ |
1195 |
|
Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries(); |
1196 |
|
if( nev && nevt!=nev){ |
1197 |
|
cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl; |
1198 |
|
return false; |
1199 |
|
} |
1200 |
|
nev=nevt; |
1201 |
|
} |
1202 |
|
} |
1203 |
|
//========================================================= |
1204 |
|
if( !strcmp(key->GetName(),"Tracker" ) ){ |
1205 |
|
TTree *T = (TTree*)f->Get("Tracker"); |
1206 |
|
if(TRK1||TRK2||TRKh){ |
1207 |
|
Int_t nevt = T->GetEntries(); |
1208 |
|
if( nev && nevt!=nev){ |
1209 |
|
cout << "File: "<< f->GetName() <<" discarded ---- Tracker tree has "<<nevt<<" events instead of "<<nev<< endl; |
1210 |
|
return false; |
1211 |
|
} |
1212 |
|
nev=nevt; |
1213 |
|
} |
1214 |
|
for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){ |
1215 |
|
TString name = T->GetListOfBranches()->At(i)->GetName(); |
1216 |
|
if( !name.CompareTo("TrkLevel1") )TRK1__ok=true; |
1217 |
|
if( !name.CompareTo("TrkLevel2") )TRK2__ok=true; |
1218 |
|
if( !name.CompareTo("TrkHough") )TRKh__ok=true; |
1219 |
|
}; |
1220 |
|
T->Delete(); |
1221 |
|
}; |
1222 |
|
//========================================================= |
1223 |
|
if( !strcmp(key->GetName(),"Calorimeter" ) ){ |
1224 |
|
TTree *T = (TTree*)f->Get("Calorimeter"); |
1225 |
|
if(CAL1||CAL2){ |
1226 |
|
Int_t nevt = T->GetEntries(); |
1227 |
|
if( nev && nevt!=nev){ |
1228 |
|
cout << "File: "<< f->GetName() <<" discarded ---- Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl; |
1229 |
|
return false; |
1230 |
|
} |
1231 |
|
nev=nevt; |
1232 |
|
} |
1233 |
|
for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){ |
1234 |
|
TString name = T->GetListOfBranches()->At(i)->GetName(); |
1235 |
|
if( !name.CompareTo("CaloLevel1") )CAL1__ok=true; |
1236 |
|
if( !name.CompareTo("CaloLevel2") )CAL2__ok=true; |
1237 |
|
}; |
1238 |
|
T->Delete(); |
1239 |
|
}; |
1240 |
|
|
1241 |
|
}; |
1242 |
|
|
1243 |
|
|
1244 |
|
|
1245 |
|
if(!RUN__ok) { |
1246 |
|
cout << "File: "<< f->GetName() <<" discarded ---- Missing RunInfo tree"<< endl; |
1247 |
|
return false; |
1248 |
|
}; |
1249 |
|
|
1250 |
|
if(CAL1 && !CAL1__ok){ |
1251 |
|
cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel1 branch"<< endl; |
1252 |
|
return false; |
1253 |
|
}; |
1254 |
|
if(CAL2 && !CAL2__ok){ |
1255 |
|
cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel2 branch"<< endl; |
1256 |
|
return false; |
1257 |
|
}; |
1258 |
|
if(TRK2 && !TRK2__ok){ |
1259 |
|
cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel2 branch"<< endl; |
1260 |
|
return false; |
1261 |
|
}; |
1262 |
|
if(TRK1 && !TRK1__ok){ |
1263 |
|
cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel1 branch"<< endl; |
1264 |
|
return false; |
1265 |
|
}; |
1266 |
|
if(TRKh && !TRKh__ok){ |
1267 |
|
cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkHough branch"<< endl; |
1268 |
|
return false; |
1269 |
|
}; |
1270 |
|
if(ORB && !ORB__ok){ |
1271 |
|
cout << "File: "<< f->GetName() <<" discarded ---- Missing ORB tree"<< endl; |
1272 |
|
return false; |
1273 |
|
}; |
1274 |
|
if(AC && !AC__ok){ |
1275 |
|
cout << "File: "<< f->GetName() <<" discarded ---- Missing AC tree"<< endl; |
1276 |
|
return false; |
1277 |
|
}; |
1278 |
|
if(S4 && !S4__ok){ |
1279 |
|
cout << "File: "<< f->GetName() <<" discarded ---- Missing S4 tree"<< endl; |
1280 |
|
return false; |
1281 |
|
}; |
1282 |
|
if(TOF && !TOF__ok){ |
1283 |
|
cout << "File: "<< f->GetName() <<" discarded ---- Missing ToF tree"<< endl; |
1284 |
|
return false; |
1285 |
|
}; |
1286 |
|
|
1287 |
|
if(ND && !ND__ok){ |
1288 |
|
cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl; |
1289 |
|
return false; |
1290 |
|
}; |
1291 |
|
if(TRG && !TRG__ok){ |
1292 |
|
cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl; |
1293 |
|
return false; |
1294 |
|
}; |
1295 |
|
|
1296 |
|
|
1297 |
|
|
1298 |
|
|
1299 |
|
|
1300 |
|
lk->Delete(); |
1301 |
|
f->Close(); |
1302 |
|
|
1303 |
|
return true; |
1304 |
|
|
1305 |
|
}; |
1306 |
|
|
1307 |
|
|