--- PamelaLevel2/src/PamLevel2.cpp 2007/01/16 13:19:58 1.16 +++ PamelaLevel2/src/PamLevel2.cpp 2007/03/20 09:57:40 1.32 @@ -100,6 +100,11 @@ // nd_obj = NDLevel2::GetNDLevel2(); // ac_obj = AcLevel2::GetAcLevel2(); // orb_obj = OrbitalInfo::GetOrbitalInfo(); + + h0_obj = 0; + trk0_obj = 0; + calo0_obj = 0; + trk2_obj = 0; trk1_obj = 0; trkh_obj = 0; @@ -114,25 +119,62 @@ run_obj = 0;//new GL_RUN(); soft_obj = 0;// Emiliano - + irun = -1; + runfirstentry = 0ULL; + runlastentry = 0ULL; + + l0_file = NULL; + l0_tree = NULL; + iroot = -1; + dbc = 0; + + prevshift = 0; + + irun = -1; + run_tree = NULL; + run_tree_clone = NULL; + sel_tree = NULL; + sel_tree_clone = NULL; + + irunentry = -1; + pam_tree = NULL; + for(Int_t i=0; iGetenv("PAM_DBHOST"); + const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); + const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); + if ( !pamdbhost ) pamdbhost = ""; + if ( !pamdbuser ) pamdbuser = ""; + if ( !pamdbpsw ) pamdbpsw = ""; + if ( strcmp(pamdbhost,"") ) host = pamdbhost; + if ( strcmp(pamdbuser,"") ) user = pamdbuser; + if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; - for(Int_t i=0; i<8; i++ )tree_clone[i]=NULL; + // sorted_tracks = 0;//new TRefArray(); + CAL0 = false; CAL1 = true; CAL2 = true; TRK2 = true; TRK1 = false; TRKh = false; - TRG = true; - TOF = true; - S4 = true; - ND = true; - AC = true; - ORB = true; + TRKh = false; + TRG = true; + TOF = true; + TOF0 = false; + S4 = true; + ND = true; + AC = true; + ORB = true; - RUN = true; + RUN = true; + + SELLI = -1; tsorted=0; timage=0; @@ -147,6 +189,9 @@ if(soft_obj)delete soft_obj; //Emiliano // cout << "void PamLevel2::Clear()"<Delete(); delete timage; } + + if(dbc){ + dbc->Close(); + delete dbc; + } + + if(l0_file)l0_file->Close(); + if(pam_tree)pam_tree->Delete();; + if(run_tree)run_tree->Delete();; + if(sel_tree)sel_tree->Delete();; + for(Int_t i=0; iDelete();; + if(run_tree_clone)run_tree_clone->Delete();; + if(sel_tree_clone)sel_tree_clone->Delete();; + + }; /** @@ -177,10 +237,16 @@ // cout << "void PamLevel2::Clear()"<Clear(); // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead - if(soft_obj) soft_obj->Clear(); +// if(run_obj) run_obj->Clear(); // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead +// if(soft_obj) soft_obj->Clear(); + if(h0_obj) h0_obj->Clear(); + if(trk0_obj) trk0_obj->Clear(); + if(calo0_obj) calo0_obj->Clear(); if(trk1_obj) trk1_obj->Clear(); if(trk2_obj) trk2_obj->Clear(); if(trkh_obj) trkh_obj->Clear(); @@ -493,6 +559,7 @@ use_CAL && calo2_obj->npcfit[1] > 15 && //no. of fit planes on Y view calo2_obj->varcfit[1] < 1000. && //fit variance on Y view + cp && ci && true){ @@ -514,7 +581,7 @@ cout << "void PamLevel2::SortTracks(TString how): how= "<GetName(); if(!CheckLevel2File(fname))return NULL; - UInt_t *found=0; +// UInt_t *found=0; cout<< "GetPamTree(TFile*,TString): detector list --> "; if(TRK1)cout<<"TRK1 "; @@ -792,6 +862,7 @@ if(S4)cout<<"S4 "; if(ORB)cout<<"ORB "; cout << endl; + if(SELLI)cout<<">>> Found selection-list <<<"<cd(); @@ -799,13 +870,13 @@ TTree *T = (TTree*)f->Get("Tracker"); if(T && (TRK2||TRK1||TRKh)) { if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2")); - else T->SetBranchStatus("TrkLevel2",0,found); +// else T->SetBranchStatus("TrkLevel2",0,found); if(TRK2)cout << "Tracker : set branch address TrkLevel2"<SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1")); - else T->SetBranchStatus("TrkLevel1",0,found); +// else T->SetBranchStatus("TrkLevel1",0,found); if(TRK1)cout << "Tracker : set branch address TrkLevel1"<SetBranchAddress("TrkHough", GetPointerTo("TrkHough")); - else T->SetBranchStatus("TrkHough",0,found); +// else T->SetBranchStatus("TrkHough",0,found); if(TRKh)cout << "Tracker : set branch address TrkHough"<AddFriend(T); @@ -816,10 +887,10 @@ TTree *C = (TTree*)f->Get("Calorimeter"); if(C && (CAL2||CAL1)) { if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2")); - else C->SetBranchStatus("CaloLevel2",0,found); +// else C->SetBranchStatus("CaloLevel2",0,found); if(CAL2)cout << "Calorimeter : set branch address CaloLevel2"<SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1")); - else C->SetBranchStatus("CaloLevel1",0,found); +// else C->SetBranchStatus("CaloLevel1",0,found); if(CAL1)cout << "Calorimeter : set branch address CaloLevel1"<AddFriend(C); @@ -887,8 +958,24 @@ }else{ cout << "OrbitalInfo : missing tree"<Get("SelectionList"); + if(L && SELLI==1) { +// L->SetBranchAddress("RunEntry",&irun); +// cout << "SelectionList: set branch address RunEntry"<SetBranchAddress("EventEntry",&irunentry); +// cout << "SelectionList: set branch address EventEntry"<AddFriend("SelectionList"); + cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemente!!!!"<GetEntries()<SetOwner(); // char *fullpath; - const char *fullpath; +// const char *fullpath; // if no input file list is given: if ( flisttxt != "" ){ // if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){ - if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){ - cout <<"File "<ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt)); - flisttxt = fullpath; +// if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){ +// cout <<"File "<ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt)); if( !gSystem->ChangeDirectory(ddir) ){ cout << "Cannot change directory : "<ChangeDirectory(wdir); // back to the working directory + return 0; + } int line=0; while (1) { TString file; @@ -951,16 +1045,22 @@ if(file.Contains("#"))file = file(0,file.First("#")); // cout <<"(2) " << file << endl; // if( gSystem->IsFileInIncludePath(file,&fullpath) ){ - if( (fullpath = gSystem->FindFile(ddir,file)) ){ - +// if( (fullpath = gSystem->FindFile(ddir,file)) ){ + if( file.EndsWith(".root") ){ + char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(file)); contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list - - }else{ + delete fullpath; + } +// }else{ // if(file.Data()!="")cout << "File: "< missing "<< endl; - }; +// }; }; in.close(); - + } else { + char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt)); + contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list + delete fullpath; + }; }else{ cout << "No input file list given."< GetName(); if( name.EndsWith(".root") ){ - const char *fullpath = gSystem->FindFile(ddir,name); +// const char *fullpath = gSystem->FindFile(ddir,name); // char *fullpath; // gSystem->IsFileInIncludePath(name,&fullpath); + char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(name)); contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath))); + delete fullpath; }; } delete temp; @@ -992,7 +1094,7 @@ gSystem->ChangeDirectory(wdir); // back to the working directory // cout << endl << "Selected files:" << endl; // contents->Print(); - cout << contents->GetEntries()<<" files selected\n"; + cout << contents->GetEntries()<<" files \n"; // cout << endl; // cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl; return contents; @@ -1036,6 +1138,8 @@ TChain *N = 0; TChain *A = 0; TChain *B = 0; + + TChain *L = 0; if(TRK2||TRK1||TRKh) T = new TChain("Tracker"); if(CAL2||CAL1) C = new TChain("Calorimeter"); @@ -1045,6 +1149,8 @@ if(ND) N = new TChain("NeutronD"); if(AC) A = new TChain("Anticounter"); if(ORB) B = new TChain("OrbitalInfo"); + + L = new TChain("SelectionList"); // loop over files and create chains TIter next(fl); @@ -1061,22 +1167,23 @@ if(ND) N->Add(name); if(AC) A->Add(name); if(ORB) B->Add(name); + if(SELLI==1) L->Add(name); }; } cout << "done chain \n"; - UInt_t *found=0; +// UInt_t *found=0; // Tracker if(T && (TRK2||TRK1||TRKh)) { if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2")); - else T->SetBranchStatus("TrkLevel2",0,found); +// else T->SetBranchStatus("TrkLevel2",0,found); if(TRK2)cout << "Tracker : set branch address TrkLevel2"<SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1")); - else T->SetBranchStatus("TrkLevel1",0,found); +// else T->SetBranchStatus("TrkLevel1",0,found); if(TRK1)cout << "Tracker : set branch address TrkLevel1"<SetBranchAddress("TrkHough", GetPointerTo("TrkHough")); - else T->SetBranchStatus("TrkHough",0,found); +// else T->SetBranchStatus("TrkHough",0,found); if(TRKh)cout << "Tracker : set branch address TrkHough"<AddFriend("Tracker"); @@ -1086,10 +1193,10 @@ // Calorimeter if(C && (CAL2||CAL1)) { if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2")); - else C->SetBranchStatus("CaloLevel2",0,found); +// else C->SetBranchStatus("CaloLevel2",0,found); if(CAL2)cout << "Calorimeter : set branch address CaloLevel2"<SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1")); - else C->SetBranchStatus("CaloLevel1",0,found); +// else C->SetBranchStatus("CaloLevel1",0,found); if(CAL1)cout << "Calorimeter : set branch address CaloLevel1"<AddFriend("Calorimeter"); @@ -1150,55 +1257,26 @@ }else{ cout << "OrbitalInfo : missing tree"<>> Found selection-list <<<"<SetBranchAddress("RunEntry",&irun); + cout << "SelectionList: set branch address RunEntry"<SetBranchAddress("EventEntry",&irunentry); + cout << "SelectionList: set branch address EventEntry"<AddFriend("SelectionList"); + }else{ +// cout << "SelectionList : missing tree"<Delete(); + }; // cout<GetEntries()<AddFriend("Tracker"); -// } -// // Calorimeter -// if(CAL2||CAL1) { -// if(!Tout)Tout=C; -// else Tout->AddFriend("Calorimeter"); -// }; -// // ToF -// if(TOF) { -// if(!Tout)Tout=O; -// else Tout->AddFriend("ToF"); -// }; -// // Trigger -// if(TRG) { -// if(!Tout)Tout=R; -// else Tout->AddFriend("Trigger"); -// }; -// // S4 -// if(S4) { -// if(!Tout)Tout=S; -// else Tout->AddFriend("S4"); -// }; -// // Neutron Detector -// if(ND) { -// if(!Tout)Tout=N; -// else Tout->AddFriend("NeutronD"); -// }; -// // Anticounters -// if(AC) { -// if(!Tout)Tout=A; -// else Tout->AddFriend("Anticounter"); -// }; -// // OrbitalInfo -// if(ORB) { -// if(!Tout)Tout=B; -// else Tout->AddFriend("OrbitalInfo"); -// }; - -// cout<GetEntries()<GetEntries() )PamLevel2::SetBranchAddress( Tout ); - + pam_tree = Trout; + return Trout; } @@ -1280,6 +1358,13 @@ t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo")); cout << "OrbitalInfo : set branch address OrbitalInfo"<SetBranchAddress("RunEntry", &irun); + cout << "SelectionList: set branch address RunEntry"<SetBranchAddress("EventEntry", &irunentry); + cout << "SelectionList: set branch address EventEntry"<SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo")); cout << "OrbitalInfo : set branch address OrbitalInfo"<SetBranchAddress("RunEntry", &irun); + cout << "SelectionList: set branch address RunEntry"<SetBranchAddress("EventEntry", &irunentry); + cout << "SelectionList: set branch address EventEntry"<Add(name); }; } + + if(R->GetNtrees()){ - R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo")); - cout << "Run : set branch address RunInfo"<SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano - cout << "Software : set branch address SoftInfo"<SetBranchAddress("RunInfo", GetPointerTo("RunInfo")); + cout << "Run : set branch address RunInfo"<SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano + cout << "Software : set branch address SoftInfo"<Get("Run"); - R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo")); - cout << "Run : set branch address RunInfo"<SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano - cout << "Software : set branch address SoftInfo"<SetBranchAddress("RunInfo", GetPointerTo("RunInfo")); + cout << "Run : set branch address RunInfo"<SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano + cout << "Software : set branch address SoftInfo"<GetEntries() <= 0 ) return(false); + // + + Int_t oldrun = irun; + // -------------------------------------- + // if it is a full file (not preselected) + // -------------------------------------- + if(SELLI==0){ + if ( irun < 0 ){ + irun = 0; + run->GetEntry(irun); + runfirstentry = 0ULL; + runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS); + if ( (ULong64_t)(this->GetRunInfo()->NEVENTS) > 0ULL ) runlastentry -= 1ULL; + return(true); + }; + + if( !GetOrbitalInfo() ){ + cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<absTime >= GetRunInfo()->RUNHEADER_TIME && GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries() ){ +// while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){ + irun++; + run->GetEntry(irun); + runfirstentry = runlastentry; + if ( (ULong64_t)(this->GetRunInfo()->NEVENTS) > 0ULL ) runfirstentry += 1ULL; + runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS); + // printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS))); + // printf(" abstime %u trailertime %u \n",GetOrbitalInfo()->absTime,GetRunInfo()->RUNTRAILER_TIME); + // printf(" IDRUN %u \n",GetRunInfo()->ID); + // + prevshift = 0; + // + if ( irun == run->GetEntries()-1 && fromfirst && !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME && GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME)){ + printf(" resetting irun \n"); + fromfirst = false; + irun = 0; + run->GetEntry(irun); + runfirstentry = 0ULL; + runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS); + if ( (ULong64_t)(this->GetRunInfo()->NEVENTS) > 0ULL ) runlastentry -= 1ULL; + }; + // + }; + // + if ( !fromfirst && !(GetOrbitalInfo()->absTime >= GetRunInfo()->RUNHEADER_TIME && GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME) ) printf(" Something very wrong here: cannot find RUN containing absolute time %u \n",GetOrbitalInfo()->absTime); + // + if ( irun == oldrun || irun >= run->GetEntries() ) return(false); + // + // printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry); + // + return(true); + }; + // ---------------------------------------------------- + // if it is a preselected file (there is SelectionList) + // NBNB - the event tree MUST be read first + // ---------------------------------------------------- + if(SELLI==1){ + sel_tree->GetEntry(iev); + if(irun != oldrun){ + run->GetEntry(irun); + prevshift = 0; + return true; + } + return false; + } + + return false; + // +}; +/** + * Update the runinfo informations (to be used to have Run infos event by event basis) + * @param run Pointer to the chain/tree which contains run infos + * @return true if a new run has been read, false if it is still the same run + */ +Bool_t PamLevel2::UpdateRunInfo(TTree *run, ULong64_t iev){ + return(UpdateRunInfo((TChain*)run,iev)); +}; + //-------------------------------------- // // @@ -1422,25 +1621,31 @@ void PamLevel2::SetWhichTrees(TString detlist){ if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){ + CAL0 = false; CAL1 = true; CAL2 = true; TRK2 = true; TRK1 = false; TRKh = false; + TRK0 = false; TRG = true; TOF = true; + TOF0 = false; S4 = true; ND = true; AC = true; ORB = true; }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){ + CAL0 = false; CAL1 = false; CAL2 = false; TRK2 = false; TRK1 = false; TRKh = false; + TRK0 = false; TRG = false; TOF = false; + TOF0 = false; S4 = false; ND = false; AC = false; @@ -1452,6 +1657,11 @@ if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false; if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true; }; + + if( detlist.Contains("CAL0", TString::kIgnoreCase) ){ + if ( detlist.Contains("-CAL0", TString::kIgnoreCase) )CAL0=false; + if ( detlist.Contains("+CAL0", TString::kIgnoreCase) )CAL0=true; + }; if( detlist.Contains("CAL2", TString::kIgnoreCase)){ if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false; @@ -1464,6 +1674,11 @@ CAL1=false; } // ------------------------------------------------------------------------- + if( detlist.Contains("TRK0", TString::kIgnoreCase) ){ + if ( detlist.Contains("-TRK0", TString::kIgnoreCase) )TRK0=false; + if ( detlist.Contains("+TRK0", TString::kIgnoreCase) )TRK0=true; + }; + if( detlist.Contains("TRK1", TString::kIgnoreCase) ){ if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false; if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true; @@ -1492,6 +1707,9 @@ if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false; else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true; + + if( detlist.Contains("-TOF0", TString::kIgnoreCase) )TOF0 = false; + else if( detlist.Contains("+TOF0", TString::kIgnoreCase) )TOF0 = true; if( detlist.Contains("-S4", TString::kIgnoreCase) )S4 = false; else if( detlist.Contains("+S4", TString::kIgnoreCase) )S4 = true; @@ -1526,7 +1744,10 @@ * Set tree/branch detector flags from the content of a tree */ void PamLevel2::GetWhichTrees(TFile* f){ - + + + + cout << "void PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<GetName() << endl; // cout << key->GetName() << ""<GetClassName()<Get(key->GetName())<GetName(),"Run" ) )RUN__ok = true; //========================================================= + if( !strcmp(key->GetName(),"SelectionList" ) ){ + SELLI__ok = true; + if(SELLI==1){ + Int_t nevt = ((TTree*)f->Get("SelectionList"))->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<" discarded ---- SelectionList tree has "<GetName(),"Trigger" ) ){ TRG__ok = true; if(TRG){ @@ -1839,7 +2075,19 @@ }; }; + + if( SELLI==-1 )SELLI = (Int_t)SELLI__ok; + if( SELLI==0 && SELLI__ok ){ + cout << "File: "<< f->GetName() <<" discarded ---- found SelectionList (it is not a full-event file)" << endl; + return false; + } + if( SELLI==1 && !SELLI__ok ){ + cout << "File: "<< f->GetName() <<" discarded ---- SelectionList missing" << endl; + return false; + } +// cout << "SELLI "< "; // if(TRK1__ok)cout<<"TRK1 "; // if(TRK2__ok)cout<<"TRK2 "; @@ -1948,11 +2196,11 @@ cout << "Create clones of PAMELA trees "<GetTree()->CloneTree(0); - TString name = tree_clone[i]->GetName(); + pam_tree_clone[i] = fChain->GetTree()->CloneTree(0); + TString name = pam_tree_clone[i]->GetName(); name.Append("_clone"); -// tree_clone[i]->SetName(name.Data()); - cout << tree_clone[i]->GetName() <SetName(name.Data()); + cout << pam_tree_clone[i]->GetName() <GetListOfFriends(); @@ -1962,12 +2210,12 @@ while( (T_friend = (TFriendElement*)next()) ){ // cout<IsA()->GetName()<<" "<GetName()<GetTree() << dec<GetTree()->GetName()<< endl; - tree_clone[i] = T_friend->GetTree()->CloneTree(0); - tree_clone[i]->SetAutoSave(1000000); - name = tree_clone[i]->GetName(); + pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0); + pam_tree_clone[i]->SetAutoSave(1000000); + name = pam_tree_clone[i]->GetName(); name.Append("_clone"); -// tree_clone[i]->SetName(name.Data()); - cout << tree_clone[i]->GetName() << endl; +// pam_tree_clone[i]->SetName(name.Data()); + cout << pam_tree_clone[i]->GetName() << endl; i++; } @@ -1987,21 +2235,35 @@ cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <Branch("RunInfo","GL_RUN",GetPointerTo("RunInfo")); + cout << "Run : branch RunInfo"<Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo")); + cout << "Run : branch SoftInfo"<Branch("RunEntry",&irun,"runentry/I"); + sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/I"); + + + Int_t i=0; if(TRK1||TRK2||TRKh){ - tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data "); + pam_tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data "); if(TRK1) { - tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1")); - tree_clone[i]->BranchRef(); + pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1")); + pam_tree_clone[i]->BranchRef(); cout << "Tracker : branch TrkLevel1"<Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2")); + pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2")); cout << "Tracker : branch TrkLevel2"<Branch("TrkHough","TrkHough", GetPointerTo("TrkHough")); + pam_tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough")); cout << "Tracker : branch TrkHough"<Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1")); + pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1")); cout << "Calorimeter : branch CaloLevel1"<Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2")); + pam_tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2")); cout << "Calorimeter : branch CaloLevel2"<Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2")); + pam_tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data "); + pam_tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2")); cout << "ToF : branch ToFLevel2"<Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2")); + pam_tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data "); + pam_tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2")); cout << "Trigger : branch TrigLevel2"<Branch("S4Level2","S4Level2", GetPointerTo("S4Level2")); + pam_tree_clone[i] = new TTree("S4","PAMELA S4 level2 data "); + pam_tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2")); cout << "S4 : branch S4Level2"<Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2")); + pam_tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data "); + pam_tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2")); cout << "NeutronD : branch NDLevel2"<Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2")); + pam_tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data "); + pam_tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2")); cout << "Anticounter : branch AcLevel2"<Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo")); + pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info "); + pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo")); cout << "OrbitalInfo : branch OrbitalInfo"<Fill(); + +// cout << "PamLevel2::FillCloneTrees()" << irunentry << endl; + + for(Int_t i=0; iFill(); } + if(sel_tree_clone)sel_tree_clone->Fill(); + } TTree* PamLevel2::GetCloneTree(TString name){ - for(Int_t i=0; i<8; i++){ - if(tree_clone[i]){ - TString na = tree_clone[i]->GetName(); - if(!name.CompareTo(na))return tree_clone[i]; + for(Int_t i=0; iGetName(); + if(!name.CompareTo(na))return pam_tree_clone[i]; }; } + if(run_tree_clone){ + TString na = run_tree_clone->GetName(); + if(!name.CompareTo(na))return run_tree_clone; + } + if(sel_tree_clone){ + TString na = sel_tree_clone->GetName(); + if(!name.CompareTo(na))return sel_tree_clone; + } return NULL; } void PamLevel2::WriteCloneTrees(){ cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <GetName()<Write(); + cout << run_tree_clone->GetName()<Write(); + cout << sel_tree_clone->GetName()<Write(); + for(Int_t i=0; iGetName()<Write(); }; } cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <GetEntry(ii) ) return 0; + + // + // ... that's way I put it here. Notice that nothing change in the code (is backward compatible) since in any case you return with 0. + // in theory one would like to return 1 if run is not loaded but now I don't have the will to add that 2 lines of code and it is not + // a problem if you don't check the return code of getentry. + // + if(!run_tree ){ + if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1? + cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<Fill(); + +// cout << "PamLevel2::GetEntry("<ID_ROOT_L0; +// cout << "iroot "<IsConnected())){ + cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<IsConnected() )return NULL; +// cout<<"...done"<Close(); + l0_file->Delete(); + } + cout << "Opening LEVEL0 file: "<< filename << endl; + FileStat_t t; + if( gSystem->GetPathInfo(filename.Data(),t) ){ + cout << " PamLevel2::GetYodaTree() -- ERROR opening file "<Get("Physics"); + if(!h0_obj)h0_obj = new EventHeader(); + l0_tree->SetBranchAddress("Header" ,&h0_obj); + prevshift = 0; + //--------------------------------------------------- + // TRACKER: + if(TRK0){ + if(!trk0_obj){ + trk0_obj = new TrkLevel0(); + trk0_obj->Set(); + }; + l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent()); + } + //--------------------------------------------------- + // CALORIMETER: + if(CAL0){ + if(!calo0_obj){ + calo0_obj = new CaloLevel0(); + calo0_obj->Set(); + }; + l0_tree->SetBranchAddress("Calorimeter" ,calo0_obj->GetPointerToCalorimeterEvent()); + // cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<IsConnected())){ + cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<EV_FROM; -// if(TRK1||TRK2||TRKh){ -// TTree *T = new TTree("Tracker_clone","PAMELA tracker level2 data "); -// if(TRK1) { -// trk1_clone = new TrkLevel1(); -// T->Branch("TrkLevel1","TrkLevel1", &trk1_clone); -// T->BranchRef(); -// cout << "Tracker : branch TrkLevel1"<Branch("TrkLevel2", "TrkLevel2",&trk2_clone); -// cout << "Tracker : branch TrkLevel2"<Branch("TrkHough","TrkHough", &trkh_clone); -// cout << "Tracker : branch TrkHough"<AddFriend("Tracker_clone"); -// } - -// // Calorimeter -// if(CAL1||CAL2){ -// TTree *C = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data "); -// if(CAL1) { -// calo1_clone = new CaloLevel1(); -// C->Branch("CaloLevel1", "CaloLevel1", &calo1_clone); -// cout << "Calorimeter : branch CaloLevel1"<Branch("CaloLevel2","CaloLevel2", &calo2_clone); -// cout << "Calorimeter : branch CaloLevel2"<AddFriend("Calorimeter_clone"); -// } - -// // ToF -// if(TOF) { -// TTree *O = new TTree("ToF_clone","PAMELA ToF level2 data "); -// tof_clone = new ToFLevel2(); -// O->Branch("ToFLevel2","ToFLevel2", &tof_clone); -// cout << "ToF : branch ToFLevel2"<AddFriend("ToF_clone"); -// }; -// // Trigger -// if(TRG) { -// TTree *R = new TTree("Trigger_clone","PAMELA trigger level2 data "); -// trig_clone = new TrigLevel2(); -// R->Branch("TrigLevel2","TrigLevel2", &trig_clone); -// cout << "Trigger : branch TrigLevel2"<AddFriend("Trigger_clone"); -// }; -// // S4 -// if(S4) { -// TTree *S = new TTree("S4_clone","PAMELA S4 level2 data "); -// s4_clone = new S4Level2(); -// S->Branch("S4Level2","S4Level2", &s4_clone); -// cout << "S4 : branch S4Level2"<AddFriend("S4_clone"); -// }; -// // Neutron Detector -// if(ND) { -// TTree *N = new TTree("NeutronD_clone","PAMELA neutron detector level2 data "); -// nd_clone = new NDLevel2(); -// N->Branch("NDLevel2","NDLevel2", &nd_clone); -// cout << "NeutronD : branch NDLevel2"<AddFriend("NeutronD_clone"); -// }; -// // Anticounters -// if(AC) { -// TTree *A = new TTree("Anticounter_clone","PAMELA anticounter detector level2 data "); -// ac_clone = new AcLevel2(); -// A->Branch("AcLevel2","AcLevel2", &ac_clone); -// cout << "Anticounter : branch AcLevel2"<AddFriend("Anticounter_clone"); -// }; -// // OrbitalInfo -// if(ORB) { -// TTree *B = new TTree("OrbitalInfo_clone","PAMELA oribital info "); -// orb_clone = new OrbitalInfo(); -// B->Branch("OrbitalInfo","OrbitalInfo", &orb_clone); -// cout << "OrbitalInfo : branch OrbitalInfo"<AddFriend("OrbitalInfo_clone"); -// }; -// cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <SetDirectory(0); +// cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<EV_FROM <<" quella giusta "<ID_ROOT_L0 "<ID_ROOT_L0<absTime << endl; +// cout << " trk_calib_used "<TRK_CALIB_USED<< endl; + + if( !GetOrbitalInfo() ){ + cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<0){ + cout << " level0 <--> level2 mismatch ( irun "<GetEntry(quellagiusta+shift+prevshift); + shift++; + if( !GetEventHeader() ){ + cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<GetEntries()+1 )cout << ">>> end of level0 tree <<<"<OBT "<< GetOrbitalInfo()->OBT << endl; +// cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl; +// cout << " GetOrbitalInfo()->pkt_num "<< GetOrbitalInfo()->pkt_num << endl; +// cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl; +// printf(" IDRUN %u \n",GetRunInfo()->ID); +// + if ( prevshift != 0 && (quellagiusta+shift) == GetYodaTree()->GetEntries() ){ + prevshift = 0; + shift = -1; + }; + + }while( ( GetOrbitalInfo()->OBT != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || GetOrbitalInfo()->pkt_num != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta+shift) < GetYodaTree()->GetEntries() ); + + if ( (quellagiusta+shift) == GetYodaTree()->GetEntries() ) cout << " Big trouble here, no such event in Level0 data! " <GetEntry(quellagiusta); + if ( shift > 1 ) prevshift += (shift-1); + + return answer; + +} -// if(trk1_clone) *trk1_clone = *trk1_obj; -// if(trk2_clone){ -// trk2_clone->Clear(); -// trk2_obj->Copy(*trk2_clone); -// // *trk2_clone = *trk2_obj; -// } -// if(trkh_clone) *trkh_clone = *trkh_obj; -// if(calo1_clone){ -// // *calo1_clone = *calo1_obj; -// calo1_clone->Clear(); -// calo1_obj->Copy(*calo1_clone); -// } -// if(calo2_clone){ -// // *calo2_clone = *calo2_obj; -// calo2_clone->Clear(); -// calo2_obj->Copy(*calo2_clone); -// } -// if(tof_clone) *tof_clone = *tof_obj; -// if(trig_clone) *trig_clone = *trig_obj; -// if(s4_clone) *s4_clone = *s4_obj; -// if(nd_clone) *nd_clone = *nd_obj; -// if(ac_clone) *ac_clone = *ac_obj; -// if(orb_clone) *orb_clone = *orb_obj; - -// TTree *T = tree_clone; - -// T->Fill(); //fill main tree -// // cout<IsA()->GetName()<<" "<GetName()<GetListOfFriends(); -// TIter next(li); -// TFriendElement* T_friend=0; -// while( (T_friend = (TFriendElement*)next()) ){ -// // cout<IsA()->GetName()<<" "<GetName()<GetTree() << dec<GetTree()->Fill();//fill friends -// } -// }