/[PAMELA software]/PamelaLevel2/src/PamLevel2.cpp
ViewVC logotype

Contents of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (show annotations) (download)
Mon Dec 11 17:49:03 2006 UTC (18 years, 2 months ago) by pam-fi
Branch: MAIN
Changes since 1.10: +410 -196 lines
*** empty log message ***

1 #include <PamLevel2.h>
2 //--------------------------------------
3 //
4 //
5 //--------------------------------------
6 /**
7 * Default constructor
8 */
9 PamTrack::PamTrack(){
10 trk_track = this->TrkTrack::GetTrkTrack();
11 calo_track = this->CaloTrkVar::GetCaloTrkVar();
12 tof_track = this->ToFTrkVar::GetToFTrkVar();
13 };
14 //--------------------------------------
15 //
16 //
17 //--------------------------------------
18 /**
19 * Constructor
20 */
21 PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o){
22 trk_track = this->TrkTrack::GetTrkTrack();
23 calo_track = this->CaloTrkVar::GetCaloTrkVar();
24 tof_track = this->ToFTrkVar::GetToFTrkVar();
25 if(t) *trk_track = *t;
26 if(c) *calo_track = *c;
27 if(o) *tof_track = *o;
28 };
29
30 //--------------------------------------
31 //
32 //
33 //--------------------------------------
34 /**
35 * Constructor
36 */
37 PamLevel2::PamLevel2(){
38
39 trk2_obj = TrkLevel2::GetTrkLevel2();
40 trk1_obj = TrkLevel1::GetTrkLevel1();
41 trkh_obj = TrkHough::GetTrkHough();
42 calo1_obj = CaloLevel1::GetCaloLevel1();
43 calo2_obj = CaloLevel2::GetCaloLevel2();
44 tof_obj = ToFLevel2::GetToFLevel2();
45 trig_obj = TrigLevel2::GetTrigLevel2();
46 s4_obj = S4Level2::GetS4Level2();
47 nd_obj = NDLevel2::GetNDLevel2();
48 ac_obj = AcLevel2::GetAcLevel2();
49 orb_obj = OrbitalInfo::GetOrbitalInfo();
50
51 run_obj = new GL_RUN();
52
53 // trk1_clone = 0;
54 // trk2_clone = 0;
55 // trkh_clone = 0;
56 // calo1_clone = 0;
57 // calo2_clone = 0;
58 // tof_clone = 0;
59 // trig_clone = 0;
60 // s4_clone = 0;
61 // nd_clone = 0;
62 // ac_clone = 0;
63 // orb_clone = 0;
64
65 // T_clone = 0;
66 // C_clone = 0;
67 // O_clone = 0;
68 // R_clone = 0;
69 // S_clone = 0;
70 // N_clone = 0;
71 // A_clone = 0;
72 // B_clone = 0;
73
74 for(Int_t i=0; i<8; i++ )tree_clone[i]=NULL;
75
76 sorted_tracks = new TRefArray();
77
78 CAL1 = true;
79 CAL2 = true;
80 TRK2 = true;
81 TRK1 = false;
82 TRKh = false;
83 TRG = true;
84 TOF = true;
85 S4 = true;
86 ND = true;
87 AC = true;
88 ORB = true;
89
90
91 };
92 /**
93 * Destructor
94 */
95 PamLevel2::~PamLevel2(){
96 delete run_obj;
97 Clear();
98 };
99 /**
100 * Clear the event
101 */
102 void PamLevel2::Clear(){
103
104 TrkLevel1::Clear();
105
106 TrkLevel2::Clear();
107 CaloLevel2::Clear();
108 ToFLevel2::Clear();
109 TrigLevel2::Clear();
110 S4Level2::Clear();
111 NDLevel2::Clear();
112 AcLevel2::Clear();
113 OrbitalInfo::Clear();
114
115 // if(trk1_clone)trk1_clone->Clear();
116 // if(trk2_clone)trk2_clone->Clear();
117 // if(trkh_clone)trkh_clone->Clear();
118 // if(calo1_clone)calo1_clone->Clear();
119 // if(calo2_clone)calo2_clone->Clear();
120 // if(tof_clone)tof_clone->Clear();
121 // if(trig_clone)trig_clone->Clear();
122 // if(s4_clone)s4_clone->Clear();
123 // if(nd_clone)nd_clone->Clear();
124 // if(ac_clone)ac_clone->Clear();
125 // if(orb_clone)orb_clone->Clear();
126
127 sorted_tracks->Delete(); // clean the reference array
128
129 };
130
131
132 //--------------------------------------
133 //
134 //
135 //--------------------------------------
136 void *PamLevel2::GetPointerTo(const char* c ){
137
138 TString objname = c;
139 if(!objname.CompareTo("TrkLevel1"))return &trk1_obj;
140 if(!objname.CompareTo("TrkLevel2"))return &trk2_obj;
141 if(!objname.CompareTo("TrkHough"))return &trkh_obj;
142 if(!objname.CompareTo("CaloLevel1"))return &calo1_obj;
143 if(!objname.CompareTo("CaloLevel2"))return &calo2_obj;
144 if(!objname.CompareTo("ToFLevel2"))return &tof_obj;
145 if(!objname.CompareTo("TrigLevel2"))return &trig_obj;
146 if(!objname.CompareTo("S4Level2"))return &s4_obj;
147 if(!objname.CompareTo("NDLevel2"))return &nd_obj;
148 if(!objname.CompareTo("AcLevel2"))return &ac_obj;
149 if(!objname.CompareTo("OrbitalInfo"))return &orb_obj;
150 if(!objname.CompareTo("RunInfo"))return &run_obj;
151 return NULL;
152 };
153 //--------------------------------------
154 //
155 //
156 //--------------------------------------
157 /**
158 * Retrieves the calorimeter track matching the seqno-th tracker stored track.
159 * (If seqno = -1 retrieves the self-trigger calorimeter track)
160 */
161 CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){
162
163 if( CaloLevel2::ntrk()==0 ){
164 cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl;
165 return NULL;
166 };
167
168 CaloTrkVar *c = 0;
169 Int_t it_calo=0;
170
171 do{
172 c = CaloLevel2::GetCaloTrkVar(it_calo);
173 it_calo++;
174 } while( c && seqno != c->trkseqno && it_calo < CaloLevel2::ntrk());
175
176 if(!c || seqno != c->trkseqno){
177 c = 0;
178 if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl;
179 };
180 return c;
181
182 };
183 //--------------------------------------
184 //
185 //
186 //--------------------------------------
187 /**
188 * Retrieves the ToF track matching the seqno-th tracker stored track.
189 * (If seqno = -1 retrieves the tracker-independent tof track)
190 */
191 ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){
192
193 if( ToFLevel2::ntrk()==0 ){
194 cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl;
195 return NULL;
196 };
197
198 ToFTrkVar *c = 0;
199 Int_t it_tof=0;
200
201 do{
202 c = ToFLevel2::GetToFTrkVar(it_tof);
203 it_tof++;
204 } while( c && seqno != c->trkseqno && it_tof < ToFLevel2::ntrk());
205
206 if(!c || seqno != c->trkseqno){
207 c = 0;
208 if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl;
209 };
210 return c;
211
212 };
213
214 //--------------------------------------
215 //
216 //
217 //--------------------------------------
218 /**
219 * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information.
220 */
221 PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){
222
223 CaloTrkVar *c = 0;
224 ToFTrkVar *o = 0;
225
226 if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo());
227 if(TOF) o = GetToFStoredTrack(t->GetSeqNo());
228
229 // if(t && c && o)track = new PamTrack(t,c,o);
230 PamTrack *track = new PamTrack(t,c,o);
231
232 return track;
233
234 };
235 //--------------------------------------
236 //
237 //
238 //--------------------------------------
239 /**
240 * Retrieves the it-th stored track.
241 * It override TrkLevel2::GetTrack(int it).
242 * @param itrk Track number, ranging from 0 to GetNTracks().
243 */
244
245 PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){
246
247 PamTrack *track = 0;
248
249 if( itrk >=0 && itrk < TrkLevel2::ntrk() ){
250
251 TrkTrack *t = TrkLevel2::GetStoredTrack(itrk);
252 track = GetPamTrackAlong(t);
253
254 }else{
255 cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;
256 };
257
258 return track;
259
260 }
261 //--------------------------------------
262 //
263 //
264 //--------------------------------------
265 /**
266 * Sort physical (tracker) tracks and stores them in the TRefArray (of TrkTrack objects) which pointer is PamLevel2::sorted_tracks.
267 * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...).
268 * Sorting cryteria:
269 * TRK: lower chi**2
270 * CAL: lower Y spatial residual on the first calorimeter plane
271 * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis).
272 * The default sorting cryterium is "TOF+CAL".
273 *
274 * 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).
275 */
276 void PamLevel2::SortTracks(TString how){
277
278 // cout << "call SortTracs() "<<endl;
279 //Save current Object count
280 Int_t ObjectNumber = TProcessID::GetObjectCount();
281
282 // cout << "ObjectNumber "<<ObjectNumber <<endl;
283
284 sorted_tracks->Delete(); //temporaneo???
285
286 // loop over the tracks sorted by the tracker
287 Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase);
288 Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase);
289 Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase);
290
291 if( !CAL2 && use_CAL) use_CAL = false;
292 if( !TOF && use_TOF) use_TOF = false;
293
294 if( !TRK2 ){
295 // cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl;
296 return;
297 };
298
299 // cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl;
300
301 for(Int_t i=0; i < TrkLevel2::GetNTracks(); i++){
302
303 TrkTrack *ts = 0;
304
305 // get tracker tracks
306 TrkTrack *tp = TrkLevel2::GetTrack(i); //tracker
307 CaloTrkVar *cp = 0;
308 ToFTrkVar *op = 0;
309
310 // cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl;
311 // if track has an image, check image selection
312 if(tp->HasImage()){
313
314 TrkTrack *ti = TrkLevel2::GetTrackImage(i); //tracker (image)
315 CaloTrkVar *ci = 0;
316 ToFTrkVar *oi = 0;
317
318 // cout << "its image "<<i << " "<<hex<< ti <<dec<< endl;
319
320 //assign starting scores
321 Int_t tp_score = 0; //main track sorted by the tracker
322 Int_t ti_score = 0; //image track
323
324 // ------------------------
325 // calorimeter check
326 // ------------------------
327 // check the Y spatial residual on the first calorimeter plane
328 // (cut on calorimeter variables from Emiliano)
329 if(
330 use_CAL &&
331 npcfit[1] > 15 && //no. of fit planes on Y view
332 varcfit[1] < 1000. && //fit variance on Y view
333 true){
334
335 cp = GetCaloStoredTrack(tp->GetSeqNo());
336 ci = GetCaloStoredTrack(ti->GetSeqNo());
337
338 Float_t resy_p = cp->tbar[0][1] - cbar[0][1]; if(resy_p < 0)resy_p= - resy_p;
339 Float_t resy_i = ci->tbar[0][1] - cbar[0][1]; if(resy_i < 0)resy_i= - resy_i;
340
341 if(resy_p <= resy_i) tp_score++;
342 else ti_score++;
343
344 // cout << "CALO "<<tp_score<<ti_score<<endl;
345
346 };
347 // ------------------------
348 // TOF check
349 // ------------------------
350 // check the number of hit pmts along the track
351 // on S12 S21 and S32, where paddles are parallel to Y axis
352 if( use_TOF ){
353
354 Int_t nphit_p =0;
355 Int_t nphit_i =0;
356
357 op = GetToFStoredTrack(tp->GetSeqNo());
358 oi = GetToFStoredTrack(ti->GetSeqNo());
359
360 /* cout << "track: npmtadc "<< op->npmtadc << endl;
361 cout << "track: npmttdc "<< op->npmttdc << endl;
362 cout << "image: npmtadc "<< oi->npmtadc << endl;
363 cout << "image: npmttdc "<< oi->npmttdc << endl;*/
364
365 for (Int_t ih=0; ih < op->npmtadc; ih++){
366 Int_t pl = GetPlaneIndex( (op->pmtadc).At(ih) );
367 if(pl == 1 || pl == 2 || pl == 5)nphit_p++;
368 };
369
370 for (Int_t ih=0; ih < oi->npmtadc; ih++){
371 Int_t pl = GetPlaneIndex( (oi->pmtadc).At(ih) );
372 if(pl == 1 || pl == 2 || pl == 5)nphit_i++;
373 };
374
375 if(
376 use_TOF &&
377 (nphit_p+nphit_i) !=0 &&
378 true){
379
380 if( nphit_p >= nphit_i) tp_score++;
381 else ti_score++;
382 };
383 // cout << "TOF "<<tp_score<<ti_score<<endl;
384 };
385 if(tp_score == ti_score) use_TRK = true;
386 // ------------------------
387 // tracker check
388 // ------------------------
389 // chi**2 difference is not always large enough to distinguish among
390 // the real track and its image.
391 // Tracker check will be applied always when calorimeter and tof information is ambiguous.
392 if(use_TRK){
393 if( tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ;
394 else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ;
395 // cout << "TRK "<<tp_score<<ti_score<<endl;
396 };
397
398 // ------------------------
399 // the winner is....
400 // ------------------------
401 if (tp_score > ti_score) ts = tp;//the track sorted by the tracker!!
402 else if (tp_score < ti_score) ts = ti;//its image!!
403 else {
404 ts = tp;
405 // cout << "Warning - track image ambiguity not solved" << endl;
406 // cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl;
407 };
408
409 }else{
410 ts = tp;
411 };
412
413 // cout <<" SortTracks() "<<i<<" -- "<<ts<<endl;
414 sorted_tracks->Add(ts);//save the track in the sorted array
415 // cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl;
416
417 };
418 //Restore Object count
419 //To save space in the table keeping track of all referenced objects
420 //we assume that our events do not address each other. We reset the
421 //object count to what it was at the beginning of the event.
422 TProcessID::SetObjectCount(ObjectNumber);
423
424 };
425 //--------------------------------------
426 //
427 //
428 //--------------------------------------
429 /**
430 * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2.
431 * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information.
432 */
433 TRefArray *PamLevel2::GetTracks(){
434
435 // *-*-*-*-*-*-*-*-*-*-*-*-*
436 SortTracks("+CAL+TOF");
437 // *-*-*-*-*-*-*-*-*-*-*-*-*
438
439 return sorted_tracks;
440 };
441 //--------------------------------------
442 //
443 //
444 //--------------------------------------
445 /**
446 * Retrieves the it-th Pamela "physical" track.
447 * It override TrkLevel2::GetTrack(int it).
448 * @param it Track number, ranging from 0 to GetNTracks().
449 */
450 PamTrack *PamLevel2::GetTrack(int it){
451
452 // *-*-*-*-*-*-*-*-*-*-*-*-*
453 SortTracks("+CAL+TOF");
454 // *-*-*-*-*-*-*-*-*-*-*-*-*
455
456 PamTrack *track = 0;
457
458 if( it >=0 && it < TrkLevel2::GetNTracks() && it<sorted_tracks->GetEntriesFast() ){
459 TrkTrack *t = (TrkTrack*)sorted_tracks->At(it);
460 track = GetPamTrackAlong(t);
461 }else{
462 cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;
463 };
464
465 return track;
466
467 };
468
469 //--------------------------------------
470 //
471 //
472 //--------------------------------------
473 /**
474 * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks().
475 * @param it Track number, ranging from 0 to GetNTracks().
476 */
477 PamTrack *PamLevel2::GetTrackImage(int it){
478
479 // *-*-*-*-*-*-*-*-*-*-*-*-*
480 SortTracks("+CAL+TOF");
481 // *-*-*-*-*-*-*-*-*-*-*-*-*
482
483 PamTrack *image = 0;
484
485 if( it >=0 && it < TrkLevel2::GetNTracks() ){
486 TrkTrack *temp = (TrkTrack*)sorted_tracks->At(it);
487 if( temp->HasImage() ){
488 TrkTrack *t = TrkLevel2::GetStoredTrack(temp->GetImageSeqNo());
489 image = GetPamTrackAlong(t);
490 }else{
491 cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl;
492 };
493 }else{
494 cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<TrkLevel2::GetNTracks()<<")"<<endl;
495 };
496
497 return image;
498 }
499
500 //--------------------------------------
501 //
502 //
503 //--------------------------------------
504 /**
505 * Get the Pamela detector trees in a single file and make them friends.
506 * @param f TFile pointer
507 * @param detlist String to select trees to be included
508 * @return Pointer to a TTree
509 */
510 TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){
511
512 if( !detlist.IsNull() ) SetWhichTrees(detlist);
513 else GetWhichTrees(f);
514
515 TTree *Trout =0;
516
517 TString fname = f->GetName();
518 if(!CheckLevel2File(fname))return NULL;
519
520 UInt_t *found=0;
521
522 // Tracker
523 TTree *T = (TTree*)f->Get("Tracker");
524 if(T && (TRK2||TRK1||TRKh)) {
525 if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
526 else T->SetBranchStatus("TrkLevel2",0,found);
527 if(TRK2)cout << "Tracker : set branch address TrkLevel2"<<endl;
528 if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
529 else T->SetBranchStatus("TrkLevel1",0,found);
530 if(TRK1)cout << "Tracker : set branch address TrkLevel1"<<endl;
531 if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
532 else T->SetBranchStatus("TrkHough",0,found);
533 if(TRKh)cout << "Tracker : set branch address TrkHough"<<endl;
534 if(!Trout)Trout=T;
535 else Trout->AddFriend(T);
536 }else{
537 cout << "Tracker : missing tree"<<endl;
538 };
539 // Calorimeter
540 TTree *C = (TTree*)f->Get("Calorimeter");
541 if(C && (CAL2||CAL1)) {
542 if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
543 else C->SetBranchStatus("CaloLevel2",0,found);
544 if(CAL2)cout << "Calorimeter : set branch address CaloLevel2"<<endl;
545 if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
546 else C->SetBranchStatus("CaloLevel1",0,found);
547 if(CAL1)cout << "Calorimeter : set branch address CaloLevel1"<<endl;
548 if(!Trout)Trout=C;
549 else Trout->AddFriend(C);
550 }else{
551 cout << "Calorimeter : missing tree"<<endl;
552 };
553 // ToF
554 TTree *O = (TTree*)f->Get("ToF");
555 if(O && TOF) {
556 O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
557 cout << "ToF : set branch address ToFLevel2"<<endl;
558 if(!Trout)Trout=O;
559 else Trout->AddFriend(O);
560 }else{
561 cout << "ToF : missing tree"<<endl;
562 };
563 // Trigger
564 TTree *R = (TTree*)f->Get("Trigger");
565 if(R && TRG) {
566 R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
567 cout << "Trigger : set branch address TrigLevel2"<<endl;
568 if(!Trout)Trout=O;
569 else Trout->AddFriend(R);
570 }else{
571 cout << "Trigger : missing tree"<<endl;
572 };
573 // S4
574 TTree *S = (TTree*)f->Get("S4");
575 if(S && S4) {
576 S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
577 cout << "S4 : set branch address S4Level2"<<endl;
578 if(!Trout)Trout=O;
579 else Trout->AddFriend(S);
580 }else{
581 cout << "S4 : missing tree"<<endl;
582 };
583 // Neutron Detector
584 TTree *N = (TTree*)f->Get("NeutronD");
585 if(N && ND) {
586 N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
587 cout << "NeutronD : set branch address NDLevel2"<<endl;
588 if(!Trout)Trout=O;
589 else Trout->AddFriend(N);
590 }else{
591 cout << "NeutronD : missing tree"<<endl;
592 };
593 // Anticounters
594 TTree *A = (TTree*)f->Get("Anticounter");
595 if(A && AC) {
596 A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
597 cout << "Anticounter : set branch address AcLevel2"<<endl;
598 if(!Trout)Trout=O;
599 else Trout->AddFriend(A);
600 }else{
601 cout << "Anticounter : missing tree"<<endl;
602 };
603 // Orbital Info
604 TTree *B = (TTree*)f->Get("OrbitalInfo");
605 if(B && ORB) {
606 B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
607 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
608 if(!Trout)Trout=O;
609 else Trout->AddFriend(B);
610 }else{
611 cout << "OrbitalInfo : missing tree"<<endl;
612 };
613
614 cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
615
616 return Trout;
617
618 }
619 //--------------------------------------
620 //
621 //
622 //--------------------------------------
623 /**
624 * Get list of Level2 files.
625 * @param ddir Level2 data directory.
626 * @param flisttxt Name of txt file containing file list.
627 * @return Pointer to a TList of TSystemFiles
628 * If no input file list is given , all the Level2 files inside the directory are processed.
629 */
630 TList* PamLevel2::GetListOfLevel2Files(TString ddir, TString flisttxt = ""){
631
632 TString wdir = gSystem->WorkingDirectory();
633
634 if(ddir=="")ddir = wdir;
635 // TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
636 cout << "Level2 data directory : "<< ddir << endl;
637
638 TList *contents = new TList; // create output list
639 contents->SetOwner();
640
641 char *fullpath;
642
643 // if no input file list is given:
644 if ( flisttxt != "" ){
645
646 if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){
647 cout <<"File "<<flisttxt<<" not found"<<endl;
648 return 0;
649 }
650 // flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
651 flisttxt = fullpath;
652
653 if( !gSystem->ChangeDirectory(ddir) ){
654 cout << "Cannot change directory : "<<ddir<<endl;
655 return 0;
656 }
657
658 cout <<"Input file list : " << flisttxt <<endl;
659 ifstream in;
660 in.open(flisttxt, ios::in); //open input file list
661 int line=0;
662 while (1) {
663 TString file;
664 in >> file;
665 if (!in.good()) break;
666 line++;
667 // cout <<"(1) " << file << endl;
668 if(file.IsNull()){
669 cout << "-- list interrupted at line "<<line <<endl;
670 break;
671 }
672 if(file.Contains("#"))file = file(0,file.First("#"));
673 // cout <<"(2) " << file << endl;
674 if( gSystem->IsFileInIncludePath(file,&fullpath) ){
675
676 contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
677
678 }else{
679 // if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
680 };
681 };
682 in.close();
683
684 }else{
685
686 cout << "No input file list given."<<endl;
687 cout << "Check for existing root files."<<endl;
688 // cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl;
689
690 TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
691 TList *temp = datadir->GetListOfFiles();
692 // temp->Print();
693 // cout << "*************************************" << endl;
694
695 TIter next(temp);
696 TSystemFile *questo = 0;
697
698
699 while ( (questo = (TSystemFile*) next()) ) {
700 TString name = questo-> GetName();
701 if( name.EndsWith(".root") ){
702 char *fullpath;
703 gSystem->IsFileInIncludePath(name,&fullpath);
704 contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));
705 };
706 }
707 delete temp;
708 delete datadir;
709
710 };
711 gSystem->ChangeDirectory(wdir); // back to the working directory
712 // cout << endl << "Selected files:" << endl;
713 // contents->Print();
714 cout << contents->GetEntries()<<" files selected\n";
715 // cout << endl;
716 // cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;
717 return contents;
718 };
719 //--------------------------------------
720 //
721 //
722 //--------------------------------------
723 /**
724 * Get the Pamela detector chains from a list of files and make them friends.
725 * @param fl Pointer to a TList of TSystemFiles
726 * @param detlist String to select trees to be included
727 * @return Pointer to a TChain
728 */
729 TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){
730
731 TChain *Trout =0;
732
733 if( !detlist.IsNull() )SetWhichTrees(detlist);
734
735
736 TChain *T = 0;
737 TChain *C = 0;
738 TChain *O = 0;
739 TChain *R = 0;
740 TChain *S = 0;
741 TChain *N = 0;
742 TChain *A = 0;
743 TChain *B = 0;
744
745 if(TRK2||TRK1||TRKh) T = new TChain("Tracker");
746 if(CAL2||CAL1) C = new TChain("Calorimeter");
747 if(TOF) O = new TChain("ToF");
748 if(TRG) R = new TChain("Trigger");
749 if(S4) S = new TChain("S4");
750 if(ND) N = new TChain("NeutronD");
751 if(AC) A = new TChain("Anticounter");
752 if(ORB) B = new TChain("OrbitalInfo");
753
754 // loop over files and create chains
755 TIter next(fl);
756 TSystemFile *questo = 0;
757 while ( (questo = (TSystemFile*) next()) ) {
758 TString name = questo->GetName();
759 // cout << "File: "<< name << endl;
760 if( CheckLevel2File(name) ){
761 if(TRK2||TRK1||TRKh) T->Add(name);
762 if(CAL1||CAL2) C->Add(name);
763 if(TOF) O->Add(name);
764 if(TRG) R->Add(name);
765 if(S4) S->Add(name);
766 if(ND) N->Add(name);
767 if(AC) A->Add(name);
768 if(ORB) B->Add(name);
769 };
770 }
771
772 cout << "done chain \n";
773
774 UInt_t *found=0;
775 // Tracker
776 if(T && (TRK2||TRK1||TRKh)) {
777 if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
778 else T->SetBranchStatus("TrkLevel2",0,found);
779 if(TRK2)cout << "Tracker : set branch address TrkLevel2"<<endl;
780 if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
781 else T->SetBranchStatus("TrkLevel1",0,found);
782 if(TRK1)cout << "Tracker : set branch address TrkLevel1"<<endl;
783 if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
784 else T->SetBranchStatus("TrkHough",0,found);
785 if(TRKh)cout << "Tracker : set branch address TrkHough"<<endl;
786 if(!Trout)Trout=T;
787 else Trout->AddFriend("Tracker");
788 }else{
789 cout << "Tracker : missing tree"<<endl;
790 };
791 // Calorimeter
792 if(C && (CAL2||CAL1)) {
793 if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
794 else C->SetBranchStatus("CaloLevel2",0,found);
795 if(CAL2)cout << "Calorimeter : set branch address CaloLevel2"<<endl;
796 if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
797 else C->SetBranchStatus("CaloLevel1",0,found);
798 if(CAL1)cout << "Calorimeter : set branch address CaloLevel1"<<endl;
799 if(!Trout)Trout=C;
800 else Trout->AddFriend("Calorimeter");
801 }else{
802 cout << "Calorimeter : missing tree"<<endl;
803 };
804 // ToF
805 if(O && TOF) {
806 O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
807 cout << "ToF : set branch address ToFLevel2"<<endl;
808 if(!Trout)Trout=O;
809 else Trout->AddFriend("ToF");
810 }else{
811 cout << "ToF : missing tree"<<endl;
812 };
813 // Trigger
814 if(R && TRG) {
815 R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
816 cout << "Trigger : set branch address TrigLevel2"<<endl;
817 if(!Trout)Trout=O;
818 else Trout->AddFriend("Trigger");
819 }else{
820 cout << "Trigger : missing tree"<<endl;
821 };
822 // S4
823 if(S && S4) {
824 S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
825 cout << "S4 : set branch address S4Level2"<<endl;
826 if(!Trout)Trout=O;
827 else Trout->AddFriend("S4");
828 }else{
829 cout << "S4 : missing tree"<<endl;
830 };
831 // Neutron Detector
832 if(N && ND) {
833 N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
834 cout << "NeutronD : set branch address NDLevel2"<<endl;
835 if(!Trout)Trout=O;
836 else Trout->AddFriend("NeutronD");
837 }else{
838 cout << "NeutronD : missing tree"<<endl;
839 };
840 // Anticounters
841 if(A && AC) {
842 A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
843 cout << "Anticounter : set branch address AcLevel2"<<endl;
844 if(!Trout)Trout=O;
845 else Trout->AddFriend("Anticounter");
846 }else{
847 cout << "Anticounter : missing tree"<<endl;
848 };
849 // Orbital Info
850 if(B && ORB) {
851 B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
852 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
853 if(!Trout)Trout=O;
854 else Trout->AddFriend("OrbitalInfo");
855 }else{
856 cout << "OrbitalInfo : missing tree"<<endl;
857 };
858
859 // cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
860
861
862 // // Tracker
863 // if(TRK2||TRK1||TRKh){
864 // if(!Tout)Tout=T;
865 // else Tout->AddFriend("Tracker");
866 // }
867 // // Calorimeter
868 // if(CAL2||CAL1) {
869 // if(!Tout)Tout=C;
870 // else Tout->AddFriend("Calorimeter");
871 // };
872 // // ToF
873 // if(TOF) {
874 // if(!Tout)Tout=O;
875 // else Tout->AddFriend("ToF");
876 // };
877 // // Trigger
878 // if(TRG) {
879 // if(!Tout)Tout=R;
880 // else Tout->AddFriend("Trigger");
881 // };
882 // // S4
883 // if(S4) {
884 // if(!Tout)Tout=S;
885 // else Tout->AddFriend("S4");
886 // };
887 // // Neutron Detector
888 // if(ND) {
889 // if(!Tout)Tout=N;
890 // else Tout->AddFriend("NeutronD");
891 // };
892 // // Anticounters
893 // if(AC) {
894 // if(!Tout)Tout=A;
895 // else Tout->AddFriend("Anticounter");
896 // };
897 // // OrbitalInfo
898 // if(ORB) {
899 // if(!Tout)Tout=B;
900 // else Tout->AddFriend("OrbitalInfo");
901 // };
902
903 // cout<<endl<<" Number of entries: "<<Tout->GetEntries()<<endl<<endl;
904
905 // if( Tout->GetEntries() )PamLevel2::SetBranchAddress( Tout );
906
907 return Trout;
908 }
909
910
911
912 //--------------------------------------
913 //
914 //
915 //--------------------------------------
916 /**
917 * Set branch addresses for Pamela friend trees
918 */
919 void PamLevel2::SetBranchAddress(TTree *t){
920
921 TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
922 TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
923 TRKh = TRKh & t->GetBranchStatus("TrkHough");
924 CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
925 CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
926 TOF = TOF & t->GetBranchStatus("ToFLevel2");
927 TRG = TRG & t->GetBranchStatus("TrigLevel2");
928 S4 = S4 & t->GetBranchStatus("S4Level2");
929 ND = ND & t->GetBranchStatus("NDLevel2");
930 AC = AC & t->GetBranchStatus("AcLevel2");
931 ORB = ORB & t->GetBranchStatus("OrbitalInfo");
932
933
934 // Tracker
935 if(TRK1) {
936 t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel2"));
937 cout << "Tracker : set branch address TrkLevel1"<<endl;
938 };
939 if(TRK2) {
940 t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1"));
941 cout << "Tracker : set branch address TrkLevel2"<<endl;
942 };
943 if(TRKh) {
944 t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
945 cout << "Tracker : set branch address TrkHough"<<endl;
946 };
947
948 // Calorimeter
949 if(CAL1) {
950 t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
951 cout << "Calorimeter : set branch address CaloLevel1"<<endl;
952 };
953 if(CAL2) {
954 t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
955 cout << "Calorimeter : set branch address CaloLevel2"<<endl;
956 };
957
958 // ToF
959 if(TOF) {
960 t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
961 cout << "ToF : set branch address ToFLevel2"<<endl;
962 };
963 // Trigger
964 if(TRG) {
965 t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
966 cout << "Trigger : set branch address TrigLevel2"<<endl;
967 };
968 // S4
969 if(S4) {
970 t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
971 cout << "S4 : set branch address S4Level2"<<endl;
972 };
973 // Neutron Detector
974 if(ND) {
975 t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
976 cout << "NeutronD : set branch address NDLevel2"<<endl;
977 };
978 // Anticounters
979 if(AC) {
980 t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
981 cout << "Anticounter : set branch address AcLevel2"<<endl;
982 };
983 // OrbitalInfo
984 if(ORB) {
985 t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
986 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
987 };
988
989 }
990 /**
991 * Set branch addresses for Pamela friend trees
992 */
993 void PamLevel2::SetBranchAddress(TChain *t){
994
995 TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2");
996 TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1");
997 TRKh = TRKh & t->GetBranchStatus("TrkHough");
998 CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1");
999 CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2");
1000 TOF = TOF & t->GetBranchStatus("ToFLevel2");
1001 TRG = TRG & t->GetBranchStatus("TrigLevel2");
1002 S4 = S4 & t->GetBranchStatus("S4Level2");
1003 ND = ND & t->GetBranchStatus("NDLevel2");
1004 AC = AC & t->GetBranchStatus("AcLevel2");
1005 ORB = ORB & t->GetBranchStatus("OrbitalInfo");
1006
1007 // Tracker
1008 if(TRK2) {
1009 t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1010 cout << "Tracker : set branch address TrkLevel2"<<endl;
1011 };
1012 if(TRK1) {
1013 t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1014 cout << "Tracker : set branch address TrkLevel1"<<endl;
1015 };
1016 if(TRKh) {
1017 t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1018 cout << "Tracker : set branch address TrkHough"<<endl;
1019 };
1020
1021 // Calorimeter
1022 if(CAL2) {
1023 t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1024 cout << "Calorimeter : set branch address CaloLevel2"<<endl;
1025 };
1026 if(CAL1) {
1027 t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1028 cout << "Calorimeter : set branch address CaloLevel1"<<endl;
1029 };
1030
1031 // ToF
1032 if(TOF) {
1033 t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2"));
1034 cout << "ToF : set branch address ToFLevel2"<<endl;
1035 };
1036 // Trigger
1037 if(TRG) {
1038 t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2"));
1039 cout << "Trigger : set branch address TrigLevel2"<<endl;
1040 };
1041 // S4
1042 if(S4) {
1043 t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2"));
1044 cout << "S4 : set branch address S4Level2"<<endl;
1045 };
1046 // Neutron Detector
1047 if(ND) {
1048 t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2"));
1049 cout << "NeutronD : set branch address NDLevel2"<<endl;
1050 };
1051 // Anticounters
1052 if(AC) {
1053 t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2"));
1054 cout << "Anticounter : set branch address AcLevel2"<<endl;
1055 };
1056 // OrbitalInfo
1057 if(ORB) {
1058 t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1059 cout << "OrbitalInfo : set branch address OrbitalInfo"<<endl;
1060 };
1061
1062 }
1063
1064
1065 //--------------------------------------
1066 //
1067 //
1068 //--------------------------------------
1069 /**
1070 * Get the Run tree chain from a list of files.
1071 * @param fl Pointer to a TList of TSystemFiles
1072 * @return Pointer to a TChain
1073 */
1074 TChain *PamLevel2::GetRunTree(TList *fl){
1075
1076 TChain *R = new TChain("Run");
1077
1078 // loop over files and create chains
1079 TIter next(fl);
1080 TSystemFile *questo = 0;
1081 while ( (questo = (TSystemFile*) next()) ) {
1082 TString name = questo->GetName();
1083 // cout << "File: "<< name << endl;
1084 if( CheckLevel2File(name) ){
1085 R->Add(name);
1086 };
1087 }
1088
1089 R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1090 cout << "Run : set branch address RunInfo"<<endl;
1091
1092 return R;
1093
1094 }
1095 //--------------------------------------
1096 //
1097 //
1098 //--------------------------------------
1099 /**
1100 * Get the Run tree from a file.
1101 * @param f Pointer to a TFile
1102 * @return Pointer to a TTree
1103 */
1104 TTree *PamLevel2::GetRunTree(TFile *f){
1105
1106
1107 TTree *R = (TTree*)f->Get("Run");
1108
1109 R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1110 cout << "Run : set branch address RunInfo"<<endl;
1111
1112 return R;
1113
1114 }
1115 //--------------------------------------
1116 //
1117 //
1118 //--------------------------------------
1119 /**
1120 * Set which trees shoul be analysed
1121 * @param detlist TString containing the sequence of trees required
1122 */
1123 void PamLevel2::SetWhichTrees(TString detlist){
1124
1125 if(detlist.Contains("+ALL", TString::kIgnoreCase)){
1126 CAL1 = true;
1127 CAL2 = true;
1128 TRK2 = true;
1129 TRK1 = false;
1130 TRKh = false;
1131 TRG = true;
1132 TOF = true;
1133 S4 = true;
1134 ND = true;
1135 AC = true;
1136 ORB = true;
1137 }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
1138 CAL1 = false;
1139 CAL2 = false;
1140 TRK2 = false;
1141 TRK1 = false;
1142 TRKh = false;
1143 TRG = false;
1144 TOF = false;
1145 S4 = false;
1146 ND = false;
1147 AC = false;
1148 ORB = false;
1149 };
1150
1151 // -------------------------------------------------------------------------
1152 if( detlist.Contains("CAL1", TString::kIgnoreCase) ){
1153 if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;
1154 if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;
1155 };
1156
1157 if( detlist.Contains("CAL2", TString::kIgnoreCase)){
1158 if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;
1159 if ( detlist.Contains("+CAL2", TString::kIgnoreCase) )CAL2=true;
1160 };
1161
1162 if( detlist.Contains("+CAL", TString::kIgnoreCase) && !CAL1 && !CAL2 )CAL2=true;
1163 if( detlist.Contains("-CAL", TString::kIgnoreCase) && CAL1 && CAL2 ){
1164 CAL2=false;
1165 CAL1=false;
1166 }
1167 // -------------------------------------------------------------------------
1168 if( detlist.Contains("TRK1", TString::kIgnoreCase) ){
1169 if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;
1170 if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;
1171 };
1172
1173 if( detlist.Contains("TRK2", TString::kIgnoreCase)){
1174 if ( detlist.Contains("-TRK2", TString::kIgnoreCase) )TRK2=false;
1175 if ( detlist.Contains("+TRK2", TString::kIgnoreCase) )TRK2=true;
1176 };
1177
1178 if( detlist.Contains("TRKh", TString::kIgnoreCase)){
1179 if ( detlist.Contains("-TRKh", TString::kIgnoreCase) )TRKh=false;
1180 if ( detlist.Contains("+TRKh", TString::kIgnoreCase) )TRKh=true;
1181 };
1182
1183 if( detlist.Contains("+TRK", TString::kIgnoreCase) && !TRK1 && !TRK2 && !TRKh )TRK2=true;
1184 if( detlist.Contains("-TRK", TString::kIgnoreCase) && TRK1 && TRK2 && TRKh){
1185 TRK2=false;
1186 TRK1=false;
1187 TRKh=false;
1188 }
1189 // -------------------------------------------------------------------------
1190
1191 if( detlist.Contains("-TRG", TString::kIgnoreCase) )TRG = false;
1192 else if( detlist.Contains("+TRG", TString::kIgnoreCase) )TRG = true;
1193
1194 if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
1195 else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
1196
1197 if( detlist.Contains("-S4", TString::kIgnoreCase) )S4 = false;
1198 else if( detlist.Contains("+S4", TString::kIgnoreCase) )S4 = true;
1199
1200 if( detlist.Contains("-ND", TString::kIgnoreCase) )ND = false;
1201 else if( detlist.Contains("+ND", TString::kIgnoreCase) )ND = true;
1202
1203 if( detlist.Contains("-AC", TString::kIgnoreCase) )AC = false;
1204 else if( detlist.Contains("+AC", TString::kIgnoreCase) )AC = true;
1205
1206 if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false;
1207 else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true;
1208
1209 cout<< "Set detector list --> ";
1210 if(TRK1)cout<<"TRK1 ";
1211 if(TRK2)cout<<"TRK2 ";
1212 if(TRKh)cout<<"TRKH ";
1213 if(CAL1)cout<<"CAL1 ";
1214 if(CAL2)cout<<"CAL2 ";
1215 if(TOF)cout<<"TOF ";
1216 if(TRG)cout<<"TRG ";
1217 if(AC)cout<<"AC ";
1218 if(ND)cout<<"ND ";
1219 if(S4)cout<<"S4 ";
1220 if(ORB)cout<<"ORB ";
1221 cout << endl;
1222
1223 };
1224
1225
1226 /**
1227 * Set tree/branch detector flags from the content of a tree
1228 */
1229 void PamLevel2::GetWhichTrees(TFile* f){
1230
1231
1232 // -----------
1233 // reset flags
1234 // -----------
1235 Bool_t CAL1 = false;
1236 Bool_t CAL2 = false;
1237 Bool_t TRK2 = false;
1238 Bool_t TRK1 = false;
1239 Bool_t TRKh = false;
1240 Bool_t TRG = false;
1241 Bool_t TOF = false;
1242 Bool_t S4 = false;
1243 Bool_t ND = false;
1244 Bool_t AC = false;
1245 Bool_t ORB = false;
1246
1247 Bool_t RUN = false;
1248
1249 cout << "Checking file: "<<f->GetName()<<endl;
1250 if( !f || f->IsZombie() ){
1251 cout << "File: "<< f->GetName() <<" Non valid root file"<< endl;
1252 return;
1253 }
1254
1255 TList *lk = f->GetListOfKeys();
1256 TIter next(lk);
1257 TKey *key =0;
1258
1259 Int_t nev = 0;
1260
1261 while( (key = (TKey*)next()) ){
1262
1263 if( !strcmp(key->GetName(),"Run" ) )RUN = true;
1264
1265 //=========================================================
1266 if( !strcmp(key->GetName(),"Trigger" ) ){
1267 TRG = true;
1268 Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries();
1269 if( nev && nevt!=nev){
1270 cout << "File: "<< f->GetName() <<" Trigger tree has "<<nevt<<" events instead of "<<nev<< endl;
1271 TRG = false;
1272 }else nev=nevt;
1273 }
1274 //=========================================================
1275 if( !strcmp(key->GetName(),"ToF" ) ){
1276 TOF = true;
1277 Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries();
1278 if( nev && nevt!=nev){
1279 cout << "File: "<< f->GetName() <<" ToF tree has "<<nevt<<" events instead of "<<nev<< endl;
1280 TOF = false;
1281 }else nev=nevt;
1282 }
1283 //=========================================================
1284 if( !strcmp(key->GetName(),"S4" ) ){
1285 S4 = true;
1286 Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries();
1287 if( nev && nevt!=nev){
1288 cout << "File: "<< f->GetName() <<" S4 tree has "<<nevt<<" events instead of "<<nev<< endl;
1289 S4 = false;
1290 }else nev=nevt;
1291 }
1292 //=========================================================
1293
1294 if( !strcmp(key->GetName(),"NeutronD" ) ){
1295 ND = true;
1296 Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries();
1297 if( nev && nevt!=nev){
1298 cout << "File: "<< f->GetName() <<"NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl;
1299 ND =false;
1300 }else nev=nevt;
1301 }
1302 //=========================================================
1303 if( !strcmp(key->GetName(),"Anticounter") ){
1304 AC = true;
1305 Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries();
1306 if( nev && nevt!=nev){
1307 cout << "File: "<< f->GetName() <<" Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl;
1308 AC =false;
1309 }else nev=nevt;
1310 }
1311 //=========================================================
1312 if( !strcmp(key->GetName(),"OrbitalInfo") ){
1313 ORB = true;
1314 Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries();
1315 if( nev && nevt!=nev){
1316 cout << "File: "<< f->GetName() <<" OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
1317 ORB = false;
1318 }else nev=nevt;
1319 }
1320 //=========================================================
1321 if( !strcmp(key->GetName(),"Tracker" ) ){
1322 TTree *T = (TTree*)f->Get("Tracker");
1323 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
1324 TString name = T->GetListOfBranches()->At(i)->GetName();
1325 if( !name.CompareTo("TrkLevel1") )TRK1=true;
1326 if( !name.CompareTo("TrkLevel2") )TRK2=true;
1327 if( !name.CompareTo("TrkHough") )TRKh=true;
1328 };
1329 Int_t nevt = T->GetEntries();
1330 if( nev && nevt!=nev){
1331 cout << "File: "<< f->GetName() <<" Tracker tree has "<<nevt<<" events instead of "<<nev<< endl;
1332 TRK1 = false;
1333 TRK2 = false;
1334 TRKh = false;
1335 }else nev=nevt;
1336 T->Delete();
1337 };
1338 //=========================================================
1339 if( !strcmp(key->GetName(),"Calorimeter" ) ){
1340 TTree *T = (TTree*)f->Get("Calorimeter");
1341 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
1342 TString name = T->GetListOfBranches()->At(i)->GetName();
1343 if( !name.CompareTo("CaloLevel1") )CAL1=true;
1344 if( !name.CompareTo("CaloLevel2") )CAL2=true;
1345 };
1346 Int_t nevt = T->GetEntries();
1347 if( nev && nevt!=nev){
1348 cout << "File: "<< f->GetName() <<" Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl;
1349 CAL1 = false;
1350 CAL2 = false;
1351 }else nev=nevt;
1352 T->Delete();
1353 };
1354
1355 };
1356
1357 lk->Delete();
1358
1359 return ;
1360
1361 };
1362
1363
1364 //--------------------------------------
1365 //
1366 //
1367 //--------------------------------------
1368 /**
1369 * Check if a file contains selected Pamela Level2 trees.
1370 * @param name File name
1371 * @return true if the file is ok.
1372 */
1373 Bool_t PamLevel2::CheckLevel2File(TString name){
1374
1375 Bool_t CAL1__ok = false;
1376 Bool_t CAL2__ok = false;
1377 Bool_t TRK2__ok = false;
1378 Bool_t TRK1__ok = false;
1379 Bool_t TRKh__ok = false;
1380 Bool_t TRG__ok = false;
1381 Bool_t TOF__ok = false;
1382 Bool_t S4__ok = false;
1383 Bool_t ND__ok = false;
1384 Bool_t AC__ok = false;
1385 Bool_t ORB__ok = false;
1386
1387 Bool_t RUN__ok = false;
1388
1389
1390
1391 cout << "Checking file: "<<name<<endl;
1392 TFile *f = new TFile(name.Data());
1393 if( !f || f->IsZombie() ){
1394 cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false;
1395 }
1396 // cout << "Get list of keys: "<<f<<endl;
1397 TList *lk = f->GetListOfKeys();
1398 // lk->Print();
1399 TIter next(lk);
1400 TKey *key =0;
1401
1402 Int_t nev = 0;
1403
1404 while( (key = (TKey*)next()) ){
1405
1406 // cout << key->GetName() << endl;
1407 // cout << " Get tree: " << f->Get(key->GetName())<<endl;
1408 // nev_previous = nev;
1409 // cout << " n.entries "<< nev <<endl;
1410 // if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){
1411 // nev = ((TTree*)f->Get(key->GetName()))->GetEntries();
1412 // cout << "File: "<< f->GetName() <<" discarded ---- "<< key->GetName() << " tree: n.entries does not match "<<nev<<" "<<nev_previous<< endl;
1413 // return false;
1414 // };
1415
1416 if( !strcmp(key->GetName(),"Run" ) )RUN__ok = true;
1417
1418 //=========================================================
1419 if( !strcmp(key->GetName(),"Trigger" ) ){
1420 TRG__ok = true;
1421 if(TRG){
1422 Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries();
1423 if( nev && nevt!=nev){
1424 cout << "File: "<< f->GetName() <<" discarded ---- Trigger tree has "<<nevt<<" events instead of "<<nev<< endl;
1425 return false;
1426 }
1427 nev=nevt;
1428 }
1429 }
1430 //=========================================================
1431 if( !strcmp(key->GetName(),"ToF" ) ){
1432 TOF__ok = true;
1433 if(TOF){
1434 Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries();
1435 if( nev && nevt!=nev){
1436 cout << "File: "<< f->GetName() <<" discarded ---- ToF tree has "<<nevt<<" events instead of "<<nev<< endl;
1437 return false;
1438 }
1439 nev=nevt;
1440 }
1441 }
1442 //=========================================================
1443 if( !strcmp(key->GetName(),"S4" ) ){
1444 S4__ok = true;
1445 if(S4){
1446 Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries();
1447 if( nev && nevt!=nev){
1448 cout << "File: "<< f->GetName() <<" discarded ---- S4 tree has "<<nevt<<" events instead of "<<nev<< endl;
1449 return false;
1450 }
1451 nev=nevt;
1452 }
1453 }
1454 //=========================================================
1455
1456 if( !strcmp(key->GetName(),"NeutronD" ) ){
1457 ND__ok = true;
1458 if(ND){
1459 Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries();
1460 if( nev && nevt!=nev){
1461 cout << "File: "<< f->GetName() <<" discarded ---- NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl;
1462 return false;
1463 }
1464 nev=nevt;
1465 }
1466 }
1467 //=========================================================
1468 if( !strcmp(key->GetName(),"Anticounter") ){
1469 AC__ok = true;
1470 if(AC){
1471 Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries();
1472 if( nev && nevt!=nev){
1473 cout << "File: "<< f->GetName() <<" discarded ---- Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl;
1474 return false;
1475 }
1476 nev=nevt;
1477 }
1478 }
1479 //=========================================================
1480 if( !strcmp(key->GetName(),"OrbitalInfo") ){
1481 ORB__ok = true;
1482 if(ORB){
1483 Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries();
1484 if( nev && nevt!=nev){
1485 cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;
1486 return false;
1487 }
1488 nev=nevt;
1489 }
1490 }
1491 //=========================================================
1492 if( !strcmp(key->GetName(),"Tracker" ) ){
1493 TTree *T = (TTree*)f->Get("Tracker");
1494 if(TRK1||TRK2||TRKh){
1495 Int_t nevt = T->GetEntries();
1496 if( nev && nevt!=nev){
1497 cout << "File: "<< f->GetName() <<" discarded ---- Tracker tree has "<<nevt<<" events instead of "<<nev<< endl;
1498 return false;
1499 }
1500 nev=nevt;
1501 }
1502 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
1503 TString name = T->GetListOfBranches()->At(i)->GetName();
1504 if( !name.CompareTo("TrkLevel1") )TRK1__ok=true;
1505 if( !name.CompareTo("TrkLevel2") )TRK2__ok=true;
1506 if( !name.CompareTo("TrkHough") )TRKh__ok=true;
1507 };
1508 T->Delete();
1509 };
1510 //=========================================================
1511 if( !strcmp(key->GetName(),"Calorimeter" ) ){
1512 TTree *T = (TTree*)f->Get("Calorimeter");
1513 if(CAL1||CAL2){
1514 Int_t nevt = T->GetEntries();
1515 if( nev && nevt!=nev){
1516 cout << "File: "<< f->GetName() <<" discarded ---- Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl;
1517 return false;
1518 }
1519 nev=nevt;
1520 }
1521 for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){
1522 TString name = T->GetListOfBranches()->At(i)->GetName();
1523 if( !name.CompareTo("CaloLevel1") )CAL1__ok=true;
1524 if( !name.CompareTo("CaloLevel2") )CAL2__ok=true;
1525 };
1526 T->Delete();
1527 };
1528
1529 };
1530
1531
1532
1533 if(!RUN__ok) {
1534 cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree"<< endl;
1535 // return false;
1536 };
1537
1538 if(CAL1 && !CAL1__ok){
1539 cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel1 branch"<< endl;
1540 return false;
1541 };
1542 if(CAL2 && !CAL2__ok){
1543 cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel2 branch"<< endl;
1544 return false;
1545 };
1546 if(TRK2 && !TRK2__ok){
1547 cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel2 branch"<< endl;
1548 return false;
1549 };
1550 if(TRK1 && !TRK1__ok){
1551 cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel1 branch"<< endl;
1552 return false;
1553 };
1554 if(TRKh && !TRKh__ok){
1555 cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkHough branch"<< endl;
1556 return false;
1557 };
1558 if(ORB && !ORB__ok){
1559 cout << "File: "<< f->GetName() <<" discarded ---- Missing ORB tree"<< endl;
1560 return false;
1561 };
1562 if(AC && !AC__ok){
1563 cout << "File: "<< f->GetName() <<" discarded ---- Missing AC tree"<< endl;
1564 return false;
1565 };
1566 if(S4 && !S4__ok){
1567 cout << "File: "<< f->GetName() <<" discarded ---- Missing S4 tree"<< endl;
1568 return false;
1569 };
1570 if(TOF && !TOF__ok){
1571 cout << "File: "<< f->GetName() <<" discarded ---- Missing ToF tree"<< endl;
1572 return false;
1573 };
1574
1575 if(ND && !ND__ok){
1576 cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl;
1577 return false;
1578 };
1579 if(TRG && !TRG__ok){
1580 cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl;
1581 return false;
1582 };
1583
1584
1585
1586
1587
1588 lk->Delete();
1589 f->Close();
1590
1591 return true;
1592
1593 };
1594
1595
1596 /**
1597 * Create clone-trees
1598 */
1599 void PamLevel2::CreateCloneTrees0( TChain *fChain, TFile *ofile ){
1600
1601 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1602 cout << "Create clones of PAMELA trees "<<endl;
1603
1604 Int_t i=0;
1605 tree_clone[i] = fChain->GetTree()->CloneTree(0);
1606 TString name = tree_clone[i]->GetName();
1607 name.Append("_clone");
1608 // tree_clone[i]->SetName(name.Data());
1609 cout << tree_clone[i]->GetName() <<endl;
1610 i++;
1611
1612 TList *li = fChain->GetListOfFriends();
1613 TIter next(li);
1614 TFriendElement* T_friend=0;
1615 ofile->cd();
1616 while( (T_friend = (TFriendElement*)next()) ){
1617 // cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;
1618 // cout<<T_friend->GetTree()->GetName()<< endl;
1619 tree_clone[i] = T_friend->GetTree()->CloneTree(0);
1620 tree_clone[i]->SetAutoSave(1000000);
1621 name = tree_clone[i]->GetName();
1622 name.Append("_clone");
1623 // tree_clone[i]->SetName(name.Data());
1624 cout << tree_clone[i]->GetName() << endl;
1625 i++;
1626 }
1627
1628 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1629
1630 }
1631
1632 /**
1633 * Create clone-trees
1634 */
1635 void PamLevel2::CreateCloneTrees(TFile *ofile){
1636
1637 ofile->cd();
1638
1639 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1640 cout << "Create new PAMELA trees "<<endl;
1641
1642 Int_t i=0;
1643
1644 if(TRK1||TRK2||TRKh){
1645 tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");
1646 if(TRK1) {
1647 tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
1648 tree_clone[i]->BranchRef();
1649 cout << "Tracker : branch TrkLevel1"<<endl;
1650 };
1651 if(TRK2) {
1652 tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
1653 cout << "Tracker : branch TrkLevel2"<<endl;
1654 };
1655 if(TRKh) {
1656 tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));
1657 cout << "Tracker : branch TrkHough"<<endl;
1658 };
1659 i++;
1660 }
1661
1662 // Calorimeter
1663 if(CAL1||CAL2){
1664 tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");
1665 if(CAL1) {
1666 tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
1667 cout << "Calorimeter : branch CaloLevel1"<<endl;
1668 };
1669 if(CAL2) {
1670 tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));
1671 cout << "Calorimeter : branch CaloLevel2"<<endl;
1672 };
1673 i++;
1674 }
1675
1676 // ToF
1677 if(TOF) {
1678 tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");
1679 tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));
1680 cout << "ToF : branch ToFLevel2"<<endl;
1681 i++;
1682 };
1683 // Trigger
1684 if(TRG) {
1685 tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");
1686 tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));
1687 cout << "Trigger : branch TrigLevel2"<<endl;
1688 i++;
1689 };
1690 // S4
1691 if(S4) {
1692 tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");
1693 tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));
1694 cout << "S4 : branch S4Level2"<<endl;
1695 i++;
1696 };
1697 // Neutron Detector
1698 if(ND) {
1699 tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");
1700 tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));
1701 cout << "NeutronD : branch NDLevel2"<<endl;
1702 i++;
1703 };
1704 // Anticounters
1705 if(AC) {
1706 tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");
1707 tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));
1708 cout << "Anticounter : branch AcLevel2"<<endl;
1709 i++;
1710 };
1711 // OrbitalInfo
1712 if(ORB) {
1713 tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info ");
1714 tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));
1715 cout << "OrbitalInfo : branch OrbitalInfo"<<endl;
1716 i++;
1717 };
1718 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1719
1720 }
1721
1722 // /**
1723 // * Create clone-trees
1724 // */
1725 // void PamLevel2::CreateCloneTrees(){
1726
1727 // cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1728 // cout << "Create new PAMELA trees "<<endl;
1729
1730 // if(TRK1||TRK2||TRKh){
1731 // T_clone = new TTree("Tracker_clone","PAMELA tracker level2 data ");
1732 // if(TRK1) {
1733 // trk1_clone = new TrkLevel1();
1734 // T_clone->Branch("TrkLevel1","TrkLevel1", &trk1_clone);
1735 // T_clone->BranchRef();
1736 // cout << "Tracker : branch TrkLevel1"<<endl;
1737 // };
1738 // if(TRK2) {
1739 // trk2_clone = new TrkLevel2();
1740 // T_clone->Branch("TrkLevel2", "TrkLevel2",&trk2_clone);
1741 // cout << "Tracker : branch TrkLevel2"<<endl;
1742 // };
1743 // if(TRKh) {
1744 // trkh_clone = new TrkHough();
1745 // T_clone->Branch("TrkHough","TrkHough", &trkh_clone);
1746 // cout << "Tracker : branch TrkHough"<<endl;
1747 // };
1748 // cout << hex << T_clone << dec << endl;
1749 // }
1750
1751 // // Calorimeter
1752 // if(CAL1||CAL2){
1753 // C_clone = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");
1754 // if(CAL1) {
1755 // calo1_clone = new CaloLevel1();
1756 // C_clone->Branch("CaloLevel1", "CaloLevel1", &calo1_clone);
1757 // cout << "Calorimeter : branch CaloLevel1"<<endl;
1758 // };
1759 // if(CAL2) {
1760 // calo2_clone = new CaloLevel2();
1761 // C_clone->Branch("CaloLevel2","CaloLevel2", &calo2_clone);
1762 // cout << "Calorimeter : branch CaloLevel2"<<endl;
1763 // };
1764 // }
1765
1766 // // ToF
1767 // if(TOF) {
1768 // O_clone = new TTree("ToF_clone","PAMELA ToF level2 data ");
1769 // tof_clone = new ToFLevel2();
1770 // O_clone->Branch("ToFLevel2","ToFLevel2", &tof_clone);
1771 // cout << "ToF : branch ToFLevel2"<<endl;
1772 // };
1773 // // Trigger
1774 // if(TRG) {
1775 // R_clone = new TTree("Trigger_clone","PAMELA trigger level2 data ");
1776 // trig_clone = new TrigLevel2();
1777 // R_clone->Branch("TrigLevel2","TrigLevel2", &trig_clone);
1778 // cout << "Trigger : branch TrigLevel2"<<endl;
1779 // };
1780 // // S4
1781 // if(S4) {
1782 // S_clone = new TTree("S4_clone","PAMELA S4 level2 data ");
1783 // s4_clone = new S4Level2();
1784 // S_clone->Branch("S4Level2","S4Level2", &s4_clone);
1785 // cout << "S4 : branch S4Level2"<<endl;
1786 // };
1787 // // Neutron Detector
1788 // if(ND) {
1789 // N_clone = new TTree("NeutronD_clone","PAMELA neutron detector level2 data ");
1790 // nd_clone = new NDLevel2();
1791 // N_clone->Branch("NDLevel2","NDLevel2", &nd_clone);
1792 // cout << "NeutronD : branch NDLevel2"<<endl;
1793 // };
1794 // // Anticounters
1795 // if(AC) {
1796 // A_clone = new TTree("Anticounter_clone","PAMELA anticounter detector level2 data ");
1797 // ac_clone = new AcLevel2();
1798 // A_clone->Branch("AcLevel2","AcLevel2", &ac_clone);
1799 // cout << "Anticounter : branch AcLevel2"<<endl;
1800 // };
1801 // // OrbitalInfo
1802 // if(ORB) {
1803 // B_clone = new TTree("OrbitalInfo_clone","PAMELA oribital info ");
1804 // orb_clone = new OrbitalInfo();
1805 // B_clone->Branch("OrbitalInfo","OrbitalInfo", &orb_clone);
1806 // cout << "OrbitalInfo : branch OrbitalInfo"<<endl;
1807 // };
1808 // cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1809
1810 // }
1811
1812 /**
1813 * Fill tree (created with CreateCloneTrees)
1814 *
1815 */
1816 //void PamLevel2::FillNewPamTree(TTree *T){
1817 void PamLevel2::FillCloneTrees(){
1818
1819 // // --------------------------------------
1820 // // copy the event
1821 // // --------------------------------------
1822 // if(trk1_clone) *trk1_clone = *trk1_obj;
1823 // if(trk2_clone){
1824 // trk2_clone->Clear();
1825 // trk2_obj->Copy(*trk2_clone);
1826 // // *trk2_clone = *trk2_obj;
1827 // }
1828 // if(trkh_clone) *trkh_clone = *trkh_obj;
1829 // if(calo1_clone){
1830 // // *calo1_clone = *calo1_obj;
1831 // calo1_clone->Clear();
1832 // calo1_obj->Copy(*calo1_clone);
1833 // }
1834 // if(calo2_clone){
1835 // // *calo2_clone = *calo2_obj;
1836 // calo2_clone->Clear();
1837 // calo2_obj->Copy(*calo2_clone);
1838 // }
1839 // if(tof_clone) *tof_clone = *tof_obj;
1840 // if(trig_clone) *trig_clone = *trig_obj;
1841 // if(s4_clone) *s4_clone = *s4_obj;
1842 // if(nd_clone) *nd_clone = *nd_obj;
1843 // if(ac_clone) *ac_clone = *ac_obj;
1844 // if(orb_clone) *orb_clone = *orb_obj;
1845
1846 // if(T_clone)T_clone->Fill();
1847 // if(C_clone)C_clone->Fill();
1848 // if(O_clone)O_clone->Fill();
1849 // if(R_clone)R_clone->Fill();
1850 // if(S_clone)S_clone->Fill();
1851 // if(N_clone)N_clone->Fill();
1852 // if(A_clone)A_clone->Fill();
1853 // if(O_clone)O_clone->Fill();
1854
1855 for(Int_t i=0; i<8; i++){
1856 if(tree_clone[i])tree_clone[i]->Fill();
1857 }
1858 }
1859
1860
1861 TTree* PamLevel2::GetCloneTree(TString name){
1862
1863 for(Int_t i=0; i<8; i++){
1864 if(tree_clone[i]){
1865 TString na = tree_clone[i]->GetName();
1866 if(!name.CompareTo(na))return tree_clone[i];
1867 };
1868 }
1869 return NULL;
1870
1871 }
1872 void PamLevel2::WriteCloneTrees(){
1873 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1874 cout << "Write clones of PAMELA trees "<<endl;
1875 for(Int_t i=0; i<8; i++){
1876 if(tree_clone[i]){
1877 cout << tree_clone[i]->GetName()<<endl;
1878 tree_clone[i]->Write();
1879 };
1880 }
1881 cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1882
1883 }
1884
1885 /**
1886 * Create a new (empty) Pamela trees
1887 */
1888 // TTree* PamLevel2::GetNewPamTree(){
1889
1890 // if(tree_clone)return tree_clone;
1891
1892 // TTree *Tout = 0;
1893
1894 // cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1895 // cout << "Create new PAMELA trees "<<endl;
1896
1897
1898 // if(TRK1||TRK2||TRKh){
1899 // TTree *T = new TTree("Tracker_clone","PAMELA tracker level2 data ");
1900 // if(TRK1) {
1901 // trk1_clone = new TrkLevel1();
1902 // T->Branch("TrkLevel1","TrkLevel1", &trk1_clone);
1903 // T->BranchRef();
1904 // cout << "Tracker : branch TrkLevel1"<<endl;
1905 // };
1906 // if(TRK2) {
1907 // trk2_clone = new TrkLevel2();
1908 // T->Branch("TrkLevel2", "TrkLevel2",&trk2_clone);
1909 // cout << "Tracker : branch TrkLevel2"<<endl;
1910 // };
1911 // if(TRKh) {
1912 // trkh_clone = new TrkHough();
1913 // T->Branch("TrkHough","TrkHough", &trkh_clone);
1914 // cout << "Tracker : branch TrkHough"<<endl;
1915 // };
1916 // if(!Tout)Tout=T;
1917 // else Tout->AddFriend("Tracker_clone");
1918 // }
1919
1920 // // Calorimeter
1921 // if(CAL1||CAL2){
1922 // TTree *C = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");
1923 // if(CAL1) {
1924 // calo1_clone = new CaloLevel1();
1925 // C->Branch("CaloLevel1", "CaloLevel1", &calo1_clone);
1926 // cout << "Calorimeter : branch CaloLevel1"<<endl;
1927 // };
1928 // if(CAL2) {
1929 // calo2_clone = new CaloLevel2();
1930 // C->Branch("CaloLevel2","CaloLevel2", &calo2_clone);
1931 // cout << "Calorimeter : branch CaloLevel2"<<endl;
1932 // };
1933 // if(!Tout)Tout=C;
1934 // else Tout->AddFriend("Calorimeter_clone");
1935 // }
1936
1937 // // ToF
1938 // if(TOF) {
1939 // TTree *O = new TTree("ToF_clone","PAMELA ToF level2 data ");
1940 // tof_clone = new ToFLevel2();
1941 // O->Branch("ToFLevel2","ToFLevel2", &tof_clone);
1942 // cout << "ToF : branch ToFLevel2"<<endl;
1943 // if(!Tout)Tout=O;
1944 // else Tout->AddFriend("ToF_clone");
1945 // };
1946 // // Trigger
1947 // if(TRG) {
1948 // TTree *R = new TTree("Trigger_clone","PAMELA trigger level2 data ");
1949 // trig_clone = new TrigLevel2();
1950 // R->Branch("TrigLevel2","TrigLevel2", &trig_clone);
1951 // cout << "Trigger : branch TrigLevel2"<<endl;
1952 // if(!Tout)Tout=R;
1953 // else Tout->AddFriend("Trigger_clone");
1954 // };
1955 // // S4
1956 // if(S4) {
1957 // TTree *S = new TTree("S4_clone","PAMELA S4 level2 data ");
1958 // s4_clone = new S4Level2();
1959 // S->Branch("S4Level2","S4Level2", &s4_clone);
1960 // cout << "S4 : branch S4Level2"<<endl;
1961 // if(!Tout)Tout=S;
1962 // else Tout->AddFriend("S4_clone");
1963 // };
1964 // // Neutron Detector
1965 // if(ND) {
1966 // TTree *N = new TTree("NeutronD_clone","PAMELA neutron detector level2 data ");
1967 // nd_clone = new NDLevel2();
1968 // N->Branch("NDLevel2","NDLevel2", &nd_clone);
1969 // cout << "NeutronD : branch NDLevel2"<<endl;
1970 // if(!Tout)Tout=N;
1971 // else Tout->AddFriend("NeutronD_clone");
1972 // };
1973 // // Anticounters
1974 // if(AC) {
1975 // TTree *A = new TTree("Anticounter_clone","PAMELA anticounter detector level2 data ");
1976 // ac_clone = new AcLevel2();
1977 // A->Branch("AcLevel2","AcLevel2", &ac_clone);
1978 // cout << "Anticounter : branch AcLevel2"<<endl;
1979 // if(!Tout)Tout=A;
1980 // else Tout->AddFriend("Anticounter_clone");
1981 // };
1982 // // OrbitalInfo
1983 // if(ORB) {
1984 // TTree *B = new TTree("OrbitalInfo_clone","PAMELA oribital info ");
1985 // orb_clone = new OrbitalInfo();
1986 // B->Branch("OrbitalInfo","OrbitalInfo", &orb_clone);
1987 // cout << "OrbitalInfo : branch OrbitalInfo"<<endl;
1988 // if(!Tout)Tout=B;
1989 // else Tout->AddFriend("OrbitalInfo_clone");
1990 // };
1991 // cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
1992
1993 // tree_clone = Tout;
1994 // tree_clone->SetDirectory(0);
1995
1996 // return Tout;
1997 // }
1998 // /**
1999 // * Fill a tree (created with GetNewPamTree)
2000 // *
2001 // */
2002 // //void PamLevel2::FillNewPamTree(TTree *T){
2003 // void PamLevel2::FillNewPamTree(){
2004
2005
2006 // if(trk1_clone) *trk1_clone = *trk1_obj;
2007 // if(trk2_clone){
2008 // trk2_clone->Clear();
2009 // trk2_obj->Copy(*trk2_clone);
2010 // // *trk2_clone = *trk2_obj;
2011 // }
2012 // if(trkh_clone) *trkh_clone = *trkh_obj;
2013 // if(calo1_clone){
2014 // // *calo1_clone = *calo1_obj;
2015 // calo1_clone->Clear();
2016 // calo1_obj->Copy(*calo1_clone);
2017 // }
2018 // if(calo2_clone){
2019 // // *calo2_clone = *calo2_obj;
2020 // calo2_clone->Clear();
2021 // calo2_obj->Copy(*calo2_clone);
2022 // }
2023 // if(tof_clone) *tof_clone = *tof_obj;
2024 // if(trig_clone) *trig_clone = *trig_obj;
2025 // if(s4_clone) *s4_clone = *s4_obj;
2026 // if(nd_clone) *nd_clone = *nd_obj;
2027 // if(ac_clone) *ac_clone = *ac_obj;
2028 // if(orb_clone) *orb_clone = *orb_obj;
2029
2030 // TTree *T = tree_clone;
2031
2032 // T->Fill(); //fill main tree
2033 // // cout<<T->IsA()->GetName()<<" "<<T->GetName()<<endl;
2034 // TList *li = T->GetListOfFriends();
2035 // TIter next(li);
2036 // TFriendElement* T_friend=0;
2037 // while( (T_friend = (TFriendElement*)next()) ){
2038 // // cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;
2039 // T_friend->GetTree()->Fill();//fill friends
2040 // }
2041
2042 // }

  ViewVC Help
Powered by ViewVC 1.1.23