--- PamelaLevel2/src/PamLevel2.cpp 2006/09/29 10:02:30 1.4 +++ PamelaLevel2/src/PamLevel2.cpp 2006/10/27 11:33:19 1.7 @@ -37,54 +37,54 @@ PamLevel2::PamLevel2(){ trk_l1_obj = this->TrkLevel1::GetTrkLevel1(); - trk_obj = this->TrkLevel2::GetTrkLevel2(); - calo_obj = this->CaloLevel2::GetCaloLevel2(); + trk_obj = this->TrkLevel2::GetTrkLevel2(); + calo_obj = this->CaloLevel2::GetCaloLevel2(); tof_obj = this->ToFLevel2::GetToFLevel2(); trig_obj = this->TrigLevel2::GetTrigLevel2(); s4_obj = this->S4Level2::GetS4Level2(); nd_obj = this->NDLevel2::GetNDLevel2(); ac_obj = this->AcLevel2::GetAcLevel2(); - orb_obj = this->OrbitalInfo::GetOrbitalInfo(); + orb_obj = this->OrbitalInfo::GetOrbitalInfo(); - run_obj = new GL_RUN(); - - sorted_tracks = new TRefArray(); - - CAL = true; - TRK = true; - TRG = true; - TOF = true; - S4 = true; - ND = true; - AC = true; - ORB = true; - - TRK_L1 = false; - - Tout = NULL; + run_obj = new GL_RUN(); + + sorted_tracks = new TRefArray(); + + CAL = true; + TRK = true; + TRG = true; + TOF = true; + S4 = true; + ND = true; + AC = true; + ORB = true; + + TRK_L1 = false; + + Tout = NULL; }; /** * Destructor */ PamLevel2::~PamLevel2(){ - TrkLevel1::Clear(); - - TrkLevel2::Clear(); - CaloLevel2::Clear(); - ToFLevel2::Clear(); - TrigLevel2::Clear(); - S4Level2::Clear(); - NDLevel2::Clear(); - AcLevel2::Clear(); - OrbitalInfo::Clear(); - - delete run_obj; - + TrkLevel1::Clear(); + + TrkLevel2::Clear(); + CaloLevel2::Clear(); + ToFLevel2::Clear(); + TrigLevel2::Clear(); + S4Level2::Clear(); + NDLevel2::Clear(); + AcLevel2::Clear(); + OrbitalInfo::Clear(); + + delete run_obj; + // delete sorted_tracks; - sorted_tracks->Delete(); // clean the reference array + sorted_tracks->Delete(); // clean the reference array - if(Tout)Tout->Delete(); // delete loaded tree from memory + if(Tout)Tout->Delete(); // delete loaded tree from memory }; /** @@ -92,19 +92,19 @@ */ void PamLevel2::Clear(){ - TrkLevel1::Clear(); - - TrkLevel2::Clear(); - CaloLevel2::Clear(); - ToFLevel2::Clear(); - TrigLevel2::Clear(); - S4Level2::Clear(); - NDLevel2::Clear(); - AcLevel2::Clear(); - OrbitalInfo::Clear(); - - sorted_tracks->Delete(); // clean the reference array + TrkLevel1::Clear(); + TrkLevel2::Clear(); + CaloLevel2::Clear(); + ToFLevel2::Clear(); + TrigLevel2::Clear(); + S4Level2::Clear(); + NDLevel2::Clear(); + AcLevel2::Clear(); + OrbitalInfo::Clear(); + + sorted_tracks->Delete(); // clean the reference array + }; @@ -118,25 +118,25 @@ */ CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){ - if( CaloLevel2::ntrk()==0 ){ - cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<trkseqno && it_calo < CaloLevel2::ntrk()); - - if(seqno != c->trkseqno){ - c = 0; - if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<trkseqno && it_calo < CaloLevel2::ntrk()); + + if(!c || seqno != c->trkseqno){ + c = 0; + if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<trkseqno && it_tof < ToFLevel2::ntrk()); - - if(seqno != c->trkseqno){ - c = 0; - if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<trkseqno && it_tof < ToFLevel2::ntrk()); + + if(!c || seqno != c->trkseqno){ + c = 0; + if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<GetSeqNo()); - o = GetToFStoredTrack(t->GetSeqNo()); - + CaloTrkVar *c = 0; + ToFTrkVar *o = 0; + + if(CAL) c = GetCaloStoredTrack(t->GetSeqNo()); + if(TOF) o = GetToFStoredTrack(t->GetSeqNo()); + // if(t && c && o)track = new PamTrack(t,c,o); - PamTrack *track = new PamTrack(t,c,o); - - return track; + PamTrack *track = new PamTrack(t,c,o); + + return track; }; //-------------------------------------- @@ -202,19 +202,19 @@ PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){ - PamTrack *track = 0; - - if( itrk >=0 && itrk < TrkLevel2::ntrk() ){ - - TrkTrack *t = TrkLevel2::GetStoredTrack(itrk); - track = GetPamTrackAlong(t); + PamTrack *track = 0; + + if( itrk >=0 && itrk < TrkLevel2::ntrk() ){ - }else{ - cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<Delete(); //temporaneo??? + Int_t ObjectNumber = TProcessID::GetObjectCount(); + + sorted_tracks->Delete(); //temporaneo??? // loop over the tracks sorted by the tracker - Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase); - Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase); - Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase); + Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase); + Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase); + Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase); + + if( !CAL && use_CAL) use_CAL = false; + if( !TOF && use_TOF) use_TOF = false; + + if( !TRK ){ + cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl; + return; + }; + + for(Int_t i=0; i < TrkLevel2::GetNTracks(); i++){ + TrkTrack *ts = 0; - for(Int_t i=0; i < TrkLevel2::GetNTracks(); i++){ - - TrkTrack *ts = 0; - // get tracker tracks - TrkTrack *tp = TrkLevel2::GetTrack(i); //tracker - CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo()); - ToFTrkVar *op = GetToFStoredTrack(tp->GetSeqNo()); - + TrkTrack *tp = TrkLevel2::GetTrack(i); //tracker +// CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo()); +// ToFTrkVar *op = GetToFStoredTrack(tp->GetSeqNo()); + CaloTrkVar *cp = 0; + ToFTrkVar *op = 0; + // if track has an image, check image selection - if(tp->HasImage()){ - - TrkTrack *ti = TrkLevel2::GetTrackImage(i); //tracker (image) - CaloTrkVar *ci = GetCaloStoredTrack(ti->GetSeqNo()); - ToFTrkVar *oi = GetToFStoredTrack(ti->GetSeqNo()); - + if(tp->HasImage()){ + + TrkTrack *ti = TrkLevel2::GetTrackImage(i); //tracker (image) +// CaloTrkVar *ci = GetCaloStoredTrack(ti->GetSeqNo()); +// ToFTrkVar *oi = GetToFStoredTrack(ti->GetSeqNo()); + CaloTrkVar *ci = 0; + ToFTrkVar *oi = 0; + //assign starting scores - Int_t tp_score = 0; //main track sorted by the tracker - Int_t ti_score = 0; //image track - + Int_t tp_score = 0; //main track sorted by the tracker + Int_t ti_score = 0; //image track + // ------------------------ // calorimeter check // ------------------------ - // check the Y spatial residual on the first calorimeter plane - // (cut on calorimeter variables from Emiliano) - if( - use_CAL && - npcfit[1] > 15 && //no. of fit planes on Y view - varcfit[1] < 1000. && //fit variance on Y view - true){ - - Float_t resy_p = cp->tbar[0][1] - cbar[0][1]; if(resy_p < 0)resy_p= - resy_p; - Float_t resy_i = ci->tbar[0][1] - cbar[0][1]; if(resy_i < 0)resy_i= - resy_i; - - if(resy_p <= resy_i) tp_score++; - else ti_score++; - }; + // check the Y spatial residual on the first calorimeter plane + // (cut on calorimeter variables from Emiliano) + if( + use_CAL && + npcfit[1] > 15 && //no. of fit planes on Y view + varcfit[1] < 1000. && //fit variance on Y view + true){ + + cp = GetCaloStoredTrack(tp->GetSeqNo()); + ci = GetCaloStoredTrack(ti->GetSeqNo()); + + Float_t resy_p = cp->tbar[0][1] - cbar[0][1]; if(resy_p < 0)resy_p= - resy_p; + Float_t resy_i = ci->tbar[0][1] - cbar[0][1]; if(resy_i < 0)resy_i= - resy_i; + + if(resy_p <= resy_i) tp_score++; + else ti_score++; + }; // ------------------------ // TOF check // ------------------------ - // check the number of hit pmts along the track - // on S12 S21 and S32, where paddles are parallel to Y axis - Int_t nphit_p =0; - Int_t nphit_i =0; - - for (Int_t ih=0; ih < op->npmtadc; ih++){ - Int_t pl = GetPlaneIndex( (op->pmtadc).At(ih) ); - if(pl == 1 || pl == 2 || pl == 5)nphit_p++; - }; - - for (Int_t ih=0; ih < oi->npmtadc; ih++){ - Int_t pl = GetPlaneIndex( (oi->pmtadc).At(ih) ); - if(pl == 1 || pl == 2 || pl == 5)nphit_i++; - }; - - if( - use_TOF && - (nphit_p+nphit_i) !=0 && - true){ - - if( nphit_p >= nphit_i) tp_score++; - else ti_score++; - }; - - if(tp_score == ti_score) use_TRK = true; - // ------------------------ + // check the number of hit pmts along the track + // on S12 S21 and S32, where paddles are parallel to Y axis + if( use_TOF ){ + + Int_t nphit_p =0; + Int_t nphit_i =0; + + op = GetToFStoredTrack(tp->GetSeqNo()); + oi = GetToFStoredTrack(ti->GetSeqNo()); + +/* cout << "track: npmtadc "<< op->npmtadc << endl; + cout << "track: npmttdc "<< op->npmttdc << endl; + cout << "image: npmtadc "<< oi->npmtadc << endl; + cout << "image: npmttdc "<< oi->npmttdc << endl;*/ + + for (Int_t ih=0; ih < op->npmtadc; ih++){ + Int_t pl = GetPlaneIndex( (op->pmtadc).At(ih) ); + if(pl == 1 || pl == 2 || pl == 5)nphit_p++; + }; + + for (Int_t ih=0; ih < oi->npmtadc; ih++){ + Int_t pl = GetPlaneIndex( (oi->pmtadc).At(ih) ); + if(pl == 1 || pl == 2 || pl == 5)nphit_i++; + }; + + if( + use_TOF && + (nphit_p+nphit_i) !=0 && + true){ + + if( nphit_p >= nphit_i) tp_score++; + else ti_score++; + }; + }; + if(tp_score == ti_score) use_TRK = true; + // ------------------------ // tracker check // ------------------------ - // chi**2 difference is not always large enough to distinguish among - // the real track and its image. - // Tracker check will be applied always when calorimeter and tof information is ambiguous. - if(use_TRK){ - if( tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ; - else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ; - }; - + // chi**2 difference is not always large enough to distinguish among + // the real track and its image. + // Tracker check will be applied always when calorimeter and tof information is ambiguous. + if(use_TRK){ + if( tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ; + else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ; + }; + // ------------------------ // the winner is.... // ------------------------ - if (tp_score > ti_score) ts = tp;//the track sorted by the tracker!! - else if (tp_score < ti_score) ts = ti;//its image!! - else { - ts = tp; + if (tp_score > ti_score) ts = tp;//the track sorted by the tracker!! + else if (tp_score < ti_score) ts = ti;//its image!! + else { + ts = tp; // cout << "Warning - track image ambiguity not solved" << endl; // cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl; - }; - - }else{ - ts = tp; - }; - + }; + + }else{ + ts = tp; + }; + // cout <<" SortTracks() "<Add(ts);//save the track in the sorted array + sorted_tracks->Add(ts);//save the track in the sorted array // cout << "SortTracks:: sorted_tracks->Add(it) "<=0 && it < TrkLevel2::GetNTracks() ){ - TrkTrack *t = (TrkTrack*)sorted_tracks->At(it); -// cout << "GetTrack(int it):: sorted_tracks->At(it) "<=0 && it < TrkLevel2::GetNTracks() && itGetEntriesFast() ){ + TrkTrack *t = (TrkTrack*)sorted_tracks->At(it); + track = GetPamTrackAlong(t); + }else{ + cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<Get("Tracker"); if(T && TRK) { - if(TRK_L1){ - T->SetBranchAddress("TrkLevel1", GetPointerToTrk(1)); - cout << "Tracker : set branch address TrkLevel1"<SetBranchAddress("TrkLevel2", GetPointerToTrk(2)); - cout << "Tracker : set branch address TrkLevel2"<SetBranchAddress("TrkLevel1", GetPointerToTrk(1)); + cout << "Tracker : set branch address TrkLevel1"<SetBranchAddress("TrkLevel2", GetPointerToTrk(2)); + cout << "Tracker : set branch address TrkLevel2"<GetEntries()<Get("Tracker"); - if(T && TRK) { - T->SetBranchAddress("TrkLevel2", GetPointerToTrk()); - cout << "Tracker : set branch address TrkLevel2"<Get("Calorimeter"); - if(C && CAL) { - C->SetBranchAddress("CaloLevel2", GetPointerToCalo()); - cout << "Calorimeter : set branch address CaloLevel2"<AddFriend(C); - }else{ - cout << "Calorimeter : missing tree"<Get("ToF"); - if(O && TOF) { - O->SetBranchAddress("ToFLevel2", GetPointerToToF()); - cout << "ToF : set branch address ToFLevel2"<AddFriend(O); - }else{ - cout << "ToF : missing tree"<Get("Trigger"); - if(R && TRG) { - R->SetBranchAddress("TrigLevel2", GetPointerToTrig()); - cout << "Trigger : set branch address TrigLevel2"<AddFriend(R); - }else{ - cout << "Trigger : missing tree"<Get("S4"); - if(S && S4) { - S->SetBranchAddress("S4Level2", GetPointerToS4()); - cout << "S4 : set branch address S4Level2"<AddFriend(S); - }else{ - cout << "S4 : missing tree"<Get("NeutronD"); - if(N && ND) { - N->SetBranchAddress("NDLevel2", GetPointerToND()); - cout << "NeutronD : set branch address NDLevel2"<AddFriend(N); - }else{ - cout << "NeutronD : missing tree"<Get("Anticounter"); - if(A && AC) { - A->SetBranchAddress("AcLevel2", GetPointerToAc()); - cout << "Anticounter : set branch address AcLevel2"<AddFriend(A); - }else{ - cout << "Anticounter : missing tree"<Get("OrbitalInfo"); - if(B && ORB) { - B->SetBranchAddress("OrbitalInfo", GetPointerToOrb()); - cout << "OrbitalInfo : set branch address OrbitalInfo"<AddFriend(B); - }else{ - cout << "OrbitalInfo : missing tree"<WorkingDirectory(); - - if(ddir=="")ddir = wdir; + TString wdir = gSystem->WorkingDirectory(); + + if(ddir=="")ddir = wdir; // TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir); - cout << "Level2 data directory : "<< endl << ddir << endl; - - TList *contents = new TList; // create output list - contents->SetOwner(); + cout << "Level2 data directory : "<< ddir << endl; + + TList *contents = new TList; // create output list + contents->SetOwner(); + + char *fullpath; + + // if no input file list is given: + if ( flisttxt != "" ){ + + if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) )return 0; - char *fullpath; - - // if no input file list is given: - if ( flisttxt != "" ){ - - if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) )return 0; - // flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt)); - flisttxt = fullpath; - - if( !gSystem->ChangeDirectory(ddir) )return 0; + flisttxt = fullpath; - cout <<"Input file list : "<< endl << flisttxt <> file; - if (!in.good()) break; - if( gSystem->IsFileInIncludePath(file,&fullpath) ){ + if( !gSystem->ChangeDirectory(ddir) )return 0; + + cout <<"Input file list : " << flisttxt <> file; + if (!in.good()) break; + if( gSystem->IsFileInIncludePath(file,&fullpath) ){ // contents->Add(new TSystemDirectory(fullpath,ddir)); // add file to the list // contents->Add(new TSystemFile(fullpath,ddir)); // add file to the list - contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list - }else{ - cout << "warning! --- File "<Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list + }else{ + cout << "warning! --- File "<WorkingDirectory()<< endl; - - TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir); - TList *temp = datadir->GetListOfFiles(); + + TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir); + TList *temp = datadir->GetListOfFiles(); // temp->Print(); // cout << "*************************************" << endl; - - TIter next(temp); - TSystemFile *questo = 0; - - - while ( (questo = (TSystemFile*) next()) ) { - TString name = questo-> GetName(); - if( name.EndsWith(".root") ){ - char *fullpath; - gSystem->IsFileInIncludePath(name,&fullpath); - contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath))); - }; - } - delete temp; - delete datadir; - }; - gSystem->ChangeDirectory(wdir); // back to the working directory - cout << endl << "Selected files:" << endl; - contents->Print(); - cout << endl; + TIter next(temp); + TSystemFile *questo = 0; + + + while ( (questo = (TSystemFile*) next()) ) { + TString name = questo-> GetName(); + if( name.EndsWith(".root") ){ + char *fullpath; + gSystem->IsFileInIncludePath(name,&fullpath); + contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath))); + }; + } + delete temp; + delete datadir; + + }; + gSystem->ChangeDirectory(wdir); // back to the working directory +// cout << endl << "Selected files:" << endl; +// contents->Print(); + cout << contents->GetEntries()<<" files selected\n"; +// cout << endl; // cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl; - return contents; + return contents; }; //-------------------------------------- // @@ -720,157 +651,92 @@ TChain *PamLevel2::GetPamTree(TList *fl, TString detlist="+ALL"){ // TChain *Tout=0; - if(Tout)Tout->Delete(); - Tout = NULL; - - SetWhichTrees(detlist); - - TChain *T = 0; - TChain *C = 0; - TChain *O = 0; - TChain *R = 0; - TChain *S = 0; - TChain *N = 0; - TChain *A = 0; - TChain *B = 0; - - if(TRK) T = new TChain("Tracker"); - if(CAL) C = new TChain("Calorimeter"); - if(TOF) O = new TChain("ToF"); - if(TRG) R = new TChain("Trigger"); - if(S4) S = new TChain("S4"); - if(ND) N = new TChain("NeutronD"); - if(AC) A = new TChain("Anticounter"); - if(ORB) B = new TChain("OrbitalInfo"); - - // loop over files and create chains - TIter next(fl); - TSystemFile *questo = 0; - while ( (questo = (TSystemFile*) next()) ) { - TString name = questo->GetName(); + if(Tout)Tout->Delete(); + Tout = NULL; + + SetWhichTrees(detlist); + + TChain *T = 0; + TChain *C = 0; + TChain *O = 0; + TChain *R = 0; + TChain *S = 0; + TChain *N = 0; + TChain *A = 0; + TChain *B = 0; + + if(TRK) T = new TChain("Tracker"); + if(CAL) C = new TChain("Calorimeter"); + if(TOF) O = new TChain("ToF"); + if(TRG) R = new TChain("Trigger"); + if(S4) S = new TChain("S4"); + if(ND) N = new TChain("NeutronD"); + if(AC) A = new TChain("Anticounter"); + if(ORB) B = new TChain("OrbitalInfo"); + + // loop over files and create chains + TIter next(fl); + TSystemFile *questo = 0; + while ( (questo = (TSystemFile*) next()) ) { + TString name = questo->GetName(); // cout << "File: "<< name << endl; - if( CheckLevel2File(name) ){ - if(TRK) T->Add(name); - if(CAL) C->Add(name); - if(TOF) O->Add(name); - if(TRG) R->Add(name); - if(S4) S->Add(name); - if(ND) N->Add(name); - if(AC) A->Add(name); - if(ORB) B->Add(name); - }; - } - -/* // Tracker - if(TRK) { - if(TRK_L1){ - T->SetBranchAddress("TrkLevel1", GetPointerToTrk(1)); - cout << "Tracker : set branch address TrkLevel1"<SetBranchAddress("TrkLevel2", GetPointerToTrk(2)); - cout << "Tracker : set branch address TrkLevel2"<SetBranchAddress("CaloLevel2", GetPointerToCalo()); - cout << "Calorimeter : set branch address CaloLevel2"<AddFriend("Calorimeter"); - }; - - // ToF - if(TOF) { - O->SetBranchAddress("ToFLevel2", GetPointerToToF()); - cout << "ToF : set branch address ToFLevel2"<AddFriend("ToF"); - }; - // Trigger - if(TRG) { - R->SetBranchAddress("TrigLevel2", GetPointerToTrig()); - cout << "Trigger : set branch address TrigLevel2"<AddFriend("Trigger"); - }; - // S4 - if(S4) { - S->SetBranchAddress("S4Level2", GetPointerToS4()); - cout << "S4 : set branch address S4Level2"<AddFriend("S4"); - }; - // Neutron Detector - if(ND) { - N->SetBranchAddress("NDLevel2", GetPointerToND()); - cout << "NeutronD : set branch address NDLevel2"<AddFriend("NeutronD"); - }; - // Anticounters - if(AC) { - A->SetBranchAddress("AcLevel2", GetPointerToAc()); - cout << "Anticounter : set branch address AcLevel2"<AddFriend("Anticounter"); - }; - // OrbitalInfo - if(ORB) { - B->SetBranchAddress("OrbitalInfo", GetPointerToOrb()); - cout << "OrbitalInfo : set branch address OrbitalInfo"<AddFriend("OrbitalInfo"); + if( CheckLevel2File(name) ){ + if(TRK) T->Add(name); + if(CAL) C->Add(name); + if(TOF) O->Add(name); + if(TRG) R->Add(name); + if(S4) S->Add(name); + if(ND) N->Add(name); + if(AC) A->Add(name); + if(ORB) B->Add(name); }; + } - cout<GetEntries()<AddFriend("Calorimeter"); - }; - + cout << "done chain \n"; + + // Tracker + if(TRK) if(!Tout)Tout=T; + // Calorimeter + if(CAL) { + if(!Tout)Tout=C; + else Tout->AddFriend("Calorimeter"); + }; // ToF - if(TOF) { - if(!Tout)Tout=O; - else Tout->AddFriend("ToF"); - }; + if(TOF) { + if(!Tout)Tout=O; + else Tout->AddFriend("ToF"); + }; // Trigger - if(TRG) { - if(!Tout)Tout=O; - else Tout->AddFriend("Trigger"); - }; + if(TRG) { + if(!Tout)Tout=O; + else Tout->AddFriend("Trigger"); + }; // S4 - if(S4) { - if(!Tout)Tout=O; - else Tout->AddFriend("S4"); - }; + if(S4) { + if(!Tout)Tout=O; + else Tout->AddFriend("S4"); + }; // Neutron Detector - if(ND) { - if(!Tout)Tout=O; - else Tout->AddFriend("NeutronD"); - }; + if(ND) { + if(!Tout)Tout=O; + else Tout->AddFriend("NeutronD"); + }; // Anticounters - if(AC) { - if(!Tout)Tout=O; - else Tout->AddFriend("Anticounter"); - }; + if(AC) { + if(!Tout)Tout=O; + else Tout->AddFriend("Anticounter"); + }; // OrbitalInfo - if(ORB) { - if(!Tout)Tout=O; - else Tout->AddFriend("OrbitalInfo"); - }; - - cout<GetEntries()<AddFriend("OrbitalInfo"); + }; + +// cout<GetEntries()<GetEntries() )PamLevel2::SetBranchAddress(); + + return Tout; } //-------------------------------------- // @@ -881,52 +747,52 @@ */ void PamLevel2::SetBranchAddress(){ // Tracker - if(TRK) { - if(TRK_L1){ - Tout->SetBranchAddress("TrkLevel1", GetPointerToTrk(1)); - cout << "Tracker : set branch address TrkLevel1"<SetBranchAddress("TrkLevel2", GetPointerToTrk(2)); - cout << "Tracker : set branch address TrkLevel2"<SetBranchAddress("CaloLevel2", GetPointerToCalo()); - cout << "Calorimeter : set branch address CaloLevel2"<SetBranchAddress("TrkLevel1", GetPointerToTrk(1)); + cout << "Tracker : set branch address TrkLevel1"<SetBranchAddress("TrkLevel2", GetPointerToTrk(2)); + cout << "Tracker : set branch address TrkLevel2"<SetBranchAddress("CaloLevel2", GetPointerToCalo()); + cout << "Calorimeter : set branch address CaloLevel2"<SetBranchAddress("ToFLevel2", GetPointerToToF()); - cout << "ToF : set branch address ToFLevel2"<SetBranchAddress("ToFLevel2", GetPointerToToF()); + cout << "ToF : set branch address ToFLevel2"<SetBranchAddress("TrigLevel2", GetPointerToTrig()); - cout << "Trigger : set branch address TrigLevel2"<SetBranchAddress("TrigLevel2", GetPointerToTrig()); + cout << "Trigger : set branch address TrigLevel2"<SetBranchAddress("S4Level2", GetPointerToS4()); - cout << "S4 : set branch address S4Level2"<SetBranchAddress("S4Level2", GetPointerToS4()); + cout << "S4 : set branch address S4Level2"<SetBranchAddress("NDLevel2", GetPointerToND()); - cout << "NeutronD : set branch address NDLevel2"<SetBranchAddress("NDLevel2", GetPointerToND()); + cout << "NeutronD : set branch address NDLevel2"<SetBranchAddress("AcLevel2", GetPointerToAc()); - cout << "Anticounter : set branch address AcLevel2"<SetBranchAddress("AcLevel2", GetPointerToAc()); + cout << "Anticounter : set branch address AcLevel2"<SetBranchAddress("OrbitalInfo", GetPointerToOrb()); - cout << "OrbitalInfo : set branch address OrbitalInfo"<SetBranchAddress("OrbitalInfo", GetPointerToOrb()); + cout << "OrbitalInfo : set branch address OrbitalInfo"<GetName(); + TChain *R = new TChain("Run"); + + // loop over files and create chains + TIter next(fl); + TSystemFile *questo = 0; + while ( (questo = (TSystemFile*) next()) ) { + TString name = questo->GetName(); // cout << "File: "<< name << endl; - if( CheckLevel2File(name) ){ - R->Add(name); - }; - } - - R->SetBranchAddress("RunInfo", GetPointerToRun()); - cout << "Run : set branch address RunInfo"<Add(name); + }; + } + + R->SetBranchAddress("RunInfo", GetPointerToRun()); + cout << "Run : set branch address RunInfo"<Get("Run"); - - R->SetBranchAddress("RunInfo", GetPointerToRun()); - cout << "Run : set branch address RunInfo"<Get("Run"); - return R; + R->SetBranchAddress("RunInfo", GetPointerToRun()); + cout << "Run : set branch address RunInfo"<GetListOfKeys(); -// lk->Print(); - TIter next(lk); - TKey *key =0; - while( (key = (TKey*)next()) ){ -// cout << key->GetName() << endl; - if( !strcmp(key->GetName(),"Calorimeter") )CAL__ok = true; -// if( !strcmp(key->GetName(),"Tracker" ) )TRK__ok = true; - if( !strcmp(key->GetName(),"Trigger" ) )TRG__ok = true; - if( !strcmp(key->GetName(),"ToF" ) )TOF__ok = true; - if( !strcmp(key->GetName(),"S4" ) )S4__ok = true; - if( !strcmp(key->GetName(),"NeutronD" ) )ND__ok = true; - if( !strcmp(key->GetName(),"Anticounter") )AC__ok = true; - if( !strcmp(key->GetName(),"OrbitalInfo") )ORB__ok = true; - if( !strcmp(key->GetName(),"Run" ) )RUN__ok = true; - - if( !strcmp(key->GetName(),"Tracker" ) ){ - TRK__ok = true; - TTree *T = (TTree*)f->Get("Tracker"); - for(Int_t i=0; iGetListOfBranches()->GetEntries(); i++){ - TString name = T->GetListOfBranches()->At(i)->GetName(); - if( !name.CompareTo("TrkLevel1") )TRK_L1__ok=true; - }; - }; - - }; - - lk->Delete(); - f->Close(); - - Bool_t FLAG = true; - if(!RUN__ok) { - cout << "File: "<< f->GetName() <<" discarded ---- Missing RunInfo tree"<< endl; - FLAG = false; - }; - if(CAL && !CAL__ok){ - cout << "File: "<< f->GetName() <<" discarded ---- Missing Calorimeter tree"<< endl; - FLAG = false; - }; - if(TRK && !TRK__ok){ - cout << "File: "<< f->GetName() <<" discarded ---- Missing Tracker tree"<< endl; - FLAG = false; - }; - if(TRK_L1 && !TRK_L1__ok){ - cout << "File: "<< f->GetName() <<" discarded ---- Missing Tracker Level1 Branch"<< endl; - FLAG = false; - }; - if(TRG && !TRG__ok){ - cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl; - FLAG = false; - }; - if(TOF && !TOF__ok){ - cout << "File: "<< f->GetName() <<" discarded ---- Missing ToF tree"<< endl; - FLAG = false; - }; - if(S4 && !S4__ok){ - cout << "File: "<< f->GetName() <<" discarded ---- Missing S4 tree"<< endl; - FLAG = false; - }; - if(ND && !ND__ok){ - cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl; - FLAG = false; - }; - if(AC && !AC__ok){ - cout << "File: "<< f->GetName() <<" discarded ---- Missing AC tree"<< endl; - FLAG = false; - }; - if(ORB && !ORB__ok){ - cout << "File: "<< f->GetName() <<" discarded ---- Missing ORB tree"<< endl; - FLAG = false; + Bool_t CAL__ok = false; + Bool_t TRK__ok = false; + Bool_t TRK_L1__ok = false; + Bool_t TRG__ok = false; + Bool_t TOF__ok = false; + Bool_t S4__ok = false; + Bool_t ND__ok = false; + Bool_t AC__ok = false; + Bool_t ORB__ok = false; + + Bool_t RUN__ok = false; + +// cout << "Checking file: "<IsZombie() ){ + cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false; + } +// cout << "Get list of keys: "<GetListOfKeys(); + lk->Print(); + TIter next(lk); + TKey *key =0; + Int_t nev =0; + Int_t nev_previous =0; + while( (key = (TKey*)next()) ){ + +// cout << key->GetName() << endl; +// cout << " Get tree: " << f->Get(key->GetName())<GetClassName()=="TTree" && nev_previous && nev != nev_previous ){ +// nev = ((TTree*)f->Get(key->GetName()))->GetEntries(); +// cout << "File: "<< f->GetName() <<" discarded ---- "<< key->GetName() << " tree: n.entries does not match "<GetName(),"Calorimeter") )CAL__ok = true; + if( !strcmp(key->GetName(),"Trigger" ) )TRG__ok = true; + if( !strcmp(key->GetName(),"ToF" ) )TOF__ok = true; + if( !strcmp(key->GetName(),"S4" ) )S4__ok = true; + if( !strcmp(key->GetName(),"NeutronD" ) )ND__ok = true; + if( !strcmp(key->GetName(),"Anticounter") )AC__ok = true; + if( !strcmp(key->GetName(),"OrbitalInfo") )ORB__ok = true; + if( !strcmp(key->GetName(),"Run" ) )RUN__ok = true; + if( !strcmp(key->GetName(),"Tracker" ) ){ + TRK__ok = true; + TTree *T = (TTree*)f->Get("Tracker"); + for(Int_t i=0; iGetListOfBranches()->GetEntries(); i++){ + TString name = T->GetListOfBranches()->At(i)->GetName(); + if( !name.CompareTo("TrkLevel1") )TRK_L1__ok=true; + }; }; - return FLAG; + }; + + lk->Delete(); + f->Close(); + + Bool_t FLAG = true; + if(!RUN__ok) { + cout << "File: "<< f->GetName() <<" discarded ---- Missing RunInfo tree"<< endl; return false; +// FLAG = false; + }; + if(CAL && !CAL__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing Calorimeter tree"<< endl; return false; +// FLAG = false; + }; + if(TRK && !TRK__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing Tracker tree"<< endl; return false; +// FLAG = false; + }; + if(TRK_L1 && !TRK_L1__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing Tracker Level1 Branch"<< endl; return false; +// FLAG = false; + }; + if(TRG && !TRG__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl; return false; +// FLAG = false; + }; + if(TOF && !TOF__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing ToF tree"<< endl; return false; +// FLAG = false; + }; + if(S4 && !S4__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing S4 tree"<< endl; return false; +// FLAG = false; + }; + if(ND && !ND__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl; return false; +// FLAG = false; + }; + if(AC && !AC__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing AC tree"<< endl; return false; +// FLAG = false; + }; + if(ORB && !ORB__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing ORB tree"<< endl; return false; +// FLAG = false; + }; + + return FLAG; };