--- PamelaLevel2/src/PamLevel2.cpp 2006/12/05 12:13:39 1.9 +++ PamelaLevel2/src/PamLevel2.cpp 2007/11/07 10:39:37 1.53 @@ -1,4 +1,278 @@ #include + + + +///////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////// + +void GPamela::Clear(){ + Irun = 0; + Ievnt = 0; + Ipa = 0; + X0 = 0.; + Y0 = 0.; + Z0 = 0.; + Theta = 0.; + Phi = 0.; + P0 = 0.; + Nthtof = 0; + Nthcat = 0; + Nthcas = 0; + Nthspe = 0; + Nstrpx = 0; + Nstrpy = 0; + Nthcali = 0; + Nthcal = 0; + Nthnd = 0; + Nthcard = 0; +} + +void GPamela::Delete(){ + + Clear(); + + delete [] Ipltof; + delete [] Ipaddle; + delete [] Ipartof; + delete [] Xintof; + delete [] Yintof; + delete [] Zintof; + delete [] Xouttof; + delete [] Youttof; + delete [] Zouttof; + delete [] Ereltof; + delete [] Timetof; + delete [] Pathtof; + delete [] P0tof; + delete [] Iparcat; + delete [] Icat; + delete [] Xincat; + delete [] Yincat; + delete [] Zincat; + delete [] Xoutcat; + delete [] Youtcat; + delete [] Zoutcat; + delete [] Erelcat; + delete [] Timecat; + delete [] Pathcat; + delete [] P0cat; + delete [] Iparcas; + delete [] Icas; + delete [] Xincas; + delete [] Yincas; + delete [] Zincas; + delete [] Xoutcas; + delete [] Youtcas; + delete [] Zoutcas; + delete [] Erelcas; + delete [] Timecas; + delete [] Pathcas; + delete [] P0cas; + delete [] Iparspe; + delete [] Itrpb; + delete [] Itrsl; + delete [] Itspa; + delete [] Xinspe; + delete [] Yinspe; + delete [] Zinspe; + delete [] Xoutspe; + delete [] Youtspe; + delete [] Zoutspe; + delete [] Xavspe; + delete [] Yavspe; + delete [] Zavspe; + delete [] Erelspe; + delete [] Pathspe; + delete [] P0spe; + delete [] Nxmult; + delete [] Nymult; + delete [] Npstripx; + delete [] Ntstripx; + delete [] Istripx; + delete [] Qstripx; + delete [] Xstripx; + delete [] Npstripy; + delete [] Ntstripy; + delete [] Istripy; + delete [] Qstripy; + delete [] Ystripy; + delete [] Icaplane; + delete [] Icastrip; + delete [] Icamod; + delete [] Enestrip; + delete [] Icapl; + delete [] Icasi; + delete [] Icast; + delete [] Xincal; + delete [] Yincal; + delete [] Zincal; + delete [] Erelcal; + delete [] Itubend; + delete [] Iparnd; + delete [] Xinnd; + delete [] Yinnd; + delete [] Zinnd; + delete [] Xoutnd; + delete [] Youtnd; + delete [] Zoutnd; + delete [] Erelnd; + delete [] Timend; + delete [] Pathnd; + delete [] P0nd; + delete [] Iparcard; + delete [] Icard; + delete [] Xincard; + delete [] Yincard; + delete [] Zincard; + delete [] Xoutcard; + delete [] Youtcard; + delete [] Zoutcard; + delete [] Erelcard; + delete [] Timecard; + delete [] Pathcard; + delete [] P0card; + + +}; + + + +void GPamela::SetBranchAddress( TChain* fhBookTree ){ + +// cout << "fhBookTree "<SetBranchAddress("Irun",&Irun); + fhBookTree->SetBranchAddress("Ievnt",&Ievnt); + fhBookTree->SetBranchAddress("Ipa",&Ipa); + fhBookTree->SetBranchAddress("X0",&X0); + fhBookTree->SetBranchAddress("Y0",&Y0); + fhBookTree->SetBranchAddress("Z0",&Z0); + fhBookTree->SetBranchAddress("Theta",&Theta); + fhBookTree->SetBranchAddress("Phi",&Phi); + fhBookTree->SetBranchAddress("P0",&P0); + fhBookTree->SetBranchAddress("Nthtof",&Nthtof); + fhBookTree->SetBranchAddress("Ipltof",Ipltof); + fhBookTree->SetBranchAddress("Ipaddle",Ipaddle); + fhBookTree->SetBranchAddress("Ipartof",Ipartof); + fhBookTree->SetBranchAddress("Xintof",Xintof); + fhBookTree->SetBranchAddress("Yintof",Yintof); + fhBookTree->SetBranchAddress("Zintof",Zintof); + fhBookTree->SetBranchAddress("Xouttof",Xouttof); + fhBookTree->SetBranchAddress("Youttof",Youttof); + fhBookTree->SetBranchAddress("Zouttof",Zouttof); + fhBookTree->SetBranchAddress("Ereltof",Ereltof); + fhBookTree->SetBranchAddress("Timetof",Timetof); + fhBookTree->SetBranchAddress("Pathtof",Pathtof); + fhBookTree->SetBranchAddress("P0tof",P0tof); + fhBookTree->SetBranchAddress("Nthcat",&Nthcat); + fhBookTree->SetBranchAddress("Iparcat",Iparcat); + fhBookTree->SetBranchAddress("Icat",Icat); + fhBookTree->SetBranchAddress("Xincat",Xincat); + fhBookTree->SetBranchAddress("Yincat",Yincat); + fhBookTree->SetBranchAddress("Zincat",Zincat); + fhBookTree->SetBranchAddress("Xoutcat",Xoutcat); + fhBookTree->SetBranchAddress("Youtcat",Youtcat); + fhBookTree->SetBranchAddress("Zoutcat",Zoutcat); + fhBookTree->SetBranchAddress("Erelcat",Erelcat); + fhBookTree->SetBranchAddress("Timecat",Timecat); + fhBookTree->SetBranchAddress("Pathcat",Pathcat); + fhBookTree->SetBranchAddress("P0cat",P0cat); + fhBookTree->SetBranchAddress("Nthcas",&Nthcas); + fhBookTree->SetBranchAddress("Iparcas",Iparcas); + fhBookTree->SetBranchAddress("Icas",Icas); + fhBookTree->SetBranchAddress("Xincas",Xincas); + fhBookTree->SetBranchAddress("Yincas",Yincas); + fhBookTree->SetBranchAddress("Zincas",Zincas); + fhBookTree->SetBranchAddress("Xoutcas",Xoutcas); + fhBookTree->SetBranchAddress("Youtcas",Youtcas); + fhBookTree->SetBranchAddress("Zoutcas",Zoutcas); + fhBookTree->SetBranchAddress("Erelcas",Erelcas); + fhBookTree->SetBranchAddress("Timecas",Timecas); + fhBookTree->SetBranchAddress("Pathcas",Pathcas); + fhBookTree->SetBranchAddress("P0cas",P0cas); + fhBookTree->SetBranchAddress("Nthspe",&Nthspe); + fhBookTree->SetBranchAddress("Iparspe",Iparspe); + fhBookTree->SetBranchAddress("Itrpb",Itrpb); + fhBookTree->SetBranchAddress("Itrsl",Itrsl); + fhBookTree->SetBranchAddress("Itspa",Itspa); + fhBookTree->SetBranchAddress("Xinspe",Xinspe); + fhBookTree->SetBranchAddress("Yinspe",Yinspe); + fhBookTree->SetBranchAddress("Zinspe",Zinspe); + fhBookTree->SetBranchAddress("Xoutspe",Xoutspe); + fhBookTree->SetBranchAddress("Youtspe",Youtspe); + fhBookTree->SetBranchAddress("Zoutspe",Zoutspe); + fhBookTree->SetBranchAddress("Xavspe",Xavspe); + fhBookTree->SetBranchAddress("Yavspe",Yavspe); + fhBookTree->SetBranchAddress("Zavspe",Zavspe); + fhBookTree->SetBranchAddress("Erelspe",Erelspe); + fhBookTree->SetBranchAddress("Pathspe",Pathspe); + fhBookTree->SetBranchAddress("P0spe",P0spe); + fhBookTree->SetBranchAddress("Nxmult",Nxmult); + fhBookTree->SetBranchAddress("Nymult",Nymult); + fhBookTree->SetBranchAddress("Nstrpx",&Nstrpx); + fhBookTree->SetBranchAddress("Npstripx",Npstripx); + fhBookTree->SetBranchAddress("Ntstripx",Ntstripx); + fhBookTree->SetBranchAddress("Istripx",Istripx); + fhBookTree->SetBranchAddress("Qstripx",Qstripx); + fhBookTree->SetBranchAddress("Xstripx",Xstripx); + fhBookTree->SetBranchAddress("Nstrpy",&Nstrpy); + fhBookTree->SetBranchAddress("Npstripy",Npstripy); + fhBookTree->SetBranchAddress("Ntstripy",Ntstripy); + fhBookTree->SetBranchAddress("Istripy",Istripy); + fhBookTree->SetBranchAddress("Qstripy",Qstripy); + fhBookTree->SetBranchAddress("Ystripy",Ystripy); + fhBookTree->SetBranchAddress("Nthcali",&Nthcali); + fhBookTree->SetBranchAddress("Icaplane",Icaplane); + fhBookTree->SetBranchAddress("Icastrip",Icastrip); + fhBookTree->SetBranchAddress("Icamod",Icamod); + fhBookTree->SetBranchAddress("Enestrip",Enestrip); + fhBookTree->SetBranchAddress("Nthcal",&Nthcal); + fhBookTree->SetBranchAddress("Icapl",Icapl); + fhBookTree->SetBranchAddress("Icasi",Icasi); + fhBookTree->SetBranchAddress("Icast",Icast); + fhBookTree->SetBranchAddress("Xincal",Xincal); + fhBookTree->SetBranchAddress("Yincal",Yincal); + fhBookTree->SetBranchAddress("Zincal",Zincal); + fhBookTree->SetBranchAddress("Erelcal",Erelcal); + fhBookTree->SetBranchAddress("Nthnd",&Nthnd); + fhBookTree->SetBranchAddress("Itubend",Itubend); + fhBookTree->SetBranchAddress("Iparnd",Iparnd); + fhBookTree->SetBranchAddress("Xinnd",Xinnd); + fhBookTree->SetBranchAddress("Yinnd",Yinnd); + fhBookTree->SetBranchAddress("Zinnd",Zinnd); + fhBookTree->SetBranchAddress("Xoutnd",Xoutnd); + fhBookTree->SetBranchAddress("Youtnd",Youtnd); + fhBookTree->SetBranchAddress("Zoutnd",Zoutnd); + fhBookTree->SetBranchAddress("Erelnd",Erelnd); + fhBookTree->SetBranchAddress("Timend",Timend); + fhBookTree->SetBranchAddress("Pathnd",Pathnd); + fhBookTree->SetBranchAddress("P0nd",P0nd); + fhBookTree->SetBranchAddress("Nthcard",&Nthcard); + fhBookTree->SetBranchAddress("Iparcard",Iparcard); + fhBookTree->SetBranchAddress("Icard",Icard); + fhBookTree->SetBranchAddress("Xincard",Xincard); + fhBookTree->SetBranchAddress("Yincard",Yincard); + fhBookTree->SetBranchAddress("Zincard",Zincard); + fhBookTree->SetBranchAddress("Xoutcard",Xoutcard); + fhBookTree->SetBranchAddress("Youtcard",Youtcard); + fhBookTree->SetBranchAddress("Zoutcard",Zoutcard); + fhBookTree->SetBranchAddress("Erelcard",Erelcard); + fhBookTree->SetBranchAddress("Timecard",Timecard); + fhBookTree->SetBranchAddress("Pathcard",Pathcard); + fhBookTree->SetBranchAddress("P0card",P0card); + +// fhBookTree->SetBranchStatus("*",0); + +} + +ClassImp(GPamela); + +///////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////// //-------------------------------------- // // @@ -7,9 +281,12 @@ * Default constructor */ PamTrack::PamTrack(){ - trk_track = this->TrkTrack::GetTrkTrack(); - calo_track = this->CaloTrkVar::GetCaloTrkVar(); - tof_track = this->ToFTrkVar::GetToFTrkVar(); + trk_track = 0; + calo_track = 0; + tof_track = 0; + candeleteobj = 0; + pscore = 0; + iscore = 0; }; //-------------------------------------- // @@ -19,115 +296,421 @@ * Constructor */ PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o){ - trk_track = this->TrkTrack::GetTrkTrack(); - calo_track = this->CaloTrkVar::GetCaloTrkVar(); - tof_track = this->ToFTrkVar::GetToFTrkVar(); - if(t) *trk_track = *t; - if(c) *calo_track = *c; - if(o) *tof_track = *o; + + trk_track = 0; + calo_track = 0; + tof_track = 0; +// if(t)trk_track = new TrkTrack(*t); +// if(c)calo_track = new CaloTrkVar(*c); +// if(o)tof_track = new ToFTrkVar(*o); + if(t)trk_track = t; + if(c)calo_track = c; + if(o)tof_track = o; + candeleteobj = 0; + }; +PamTrack::PamTrack(const PamTrack& track){ + + TrkTrack *t = track.trk_track; + CaloTrkVar *c = track.calo_track; + ToFTrkVar *o = track.tof_track; + + trk_track = 0; + calo_track = 0; + tof_track = 0; + if(t)trk_track = new TrkTrack(*t); + if(c)calo_track = new CaloTrkVar(*c); + if(o)tof_track = new ToFTrkVar(*o); + candeleteobj = 1; + +} +void PamTrack::Clear(){ + +// cout << "PamTrack::Clear() "<TrkTrack::Clear(); + if(calo_track) calo_track->CaloTrkVar::Clear();//??? + if(tof_track) tof_track->ToFTrkVar::Clear();//??? + }else{ + trk_track = 0; + calo_track = 0; + tof_track = 0; + } + pscore = 0; + iscore = 0; +} +void PamTrack::Delete(){ +// cout << "PamTrack::Delete() "<TrkTrack::Clear(); + delete trk_track; + } + if(calo_track){ + calo_track->CaloTrkVar::Clear();//??? + delete calo_track; + } + if(tof_track){ + tof_track->ToFTrkVar::Clear();//??? + delete tof_track; + } + }else{ + Clear(); + } +} //-------------------------------------- // // //-------------------------------------- /** - * Constructor + * Default Constructor */ PamLevel2::PamLevel2(){ + Initialize(); +}; + +/** + * Constructor + * @param ddir Name of directory where level2 files are stored. + * @param list Name of an ascii file containing the list of file names + * @param detlist Options to chose what to load. + * Possible options are: + * +AUTO --> load all trees/branches in the input files + * +(-)ALL --> inlcude(exclude) all trees/branches + * +(-)TRK1+(-)TRK2+(-)CAL1+(-)CAL2+(-)TOF+(-)TRG+(-)ND+(-)S4+(-)ORB+(-)AC --> inlcude(exclude) trees and branches + * +(-)TRK0 --> include(exclude) tracker level0 tree + * +(-)GP --> include exclude GPAMELA output tree + * If no options are specified, the default is assumed. Default is: + * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB + */ +PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){ + Initialize(); + GetPamTree(GetListOfLevel2Files(ddir,list),detlist); + GetRunTree(GetListOfLevel2Files(ddir,list)); +}; + +/** + * Constructor + * @param ddir Name of directory where level2 files are stored. + * @param list Name of an ascii file containing the list of file names + * Default trees/branches are loaded. Default is: + * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB + */ +PamLevel2::PamLevel2(TString ddir,TString list){ + Initialize(); + GetPamTree(GetListOfLevel2Files(ddir,list),""); + GetRunTree(GetListOfLevel2Files(ddir,list)); +}; + + +void PamLevel2::Initialize(){ - trk2_obj = TrkLevel2::GetTrkLevel2(); - trk1_obj = TrkLevel1::GetTrkLevel1(); - trkh_obj = TrkHough::GetTrkHough(); - calo1_obj = CaloLevel1::GetCaloLevel1(); - calo2_obj = CaloLevel2::GetCaloLevel2(); - tof_obj = ToFLevel2::GetToFLevel2(); - trig_obj = TrigLevel2::GetTrigLevel2(); - s4_obj = S4Level2::GetS4Level2(); - nd_obj = NDLevel2::GetNDLevel2(); - ac_obj = AcLevel2::GetAcLevel2(); - orb_obj = OrbitalInfo::GetOrbitalInfo(); - - run_obj = new GL_RUN(); - -// trk1_clone = 0; -// trk2_clone = 0; -// trkh_clone = 0; -// calo1_clone = 0; -// calo2_clone = 0; -// tof_clone = 0; -// trig_clone = 0; -// s4_clone = 0; -// nd_clone = 0; -// ac_clone = 0; -// orb_clone = 0; - -// T_clone = 0; -// C_clone = 0; -// O_clone = 0; -// R_clone = 0; -// S_clone = 0; -// N_clone = 0; -// A_clone = 0; -// B_clone = 0; + h0_obj = 0; + trk0_obj = 0; + calo0_obj = 0; + + trk2_obj = 0; + trk1_obj = 0; + trkh_obj = 0; + calo1_obj = 0; + calo2_obj = 0; + tof_obj = 0; + trig_obj = 0; + s4_obj = 0; + nd_obj = 0; + ac_obj = 0; + orb_obj = 0; + gp_obj = 0; + + run_obj = 0;//new GL_RUN(); + soft_obj = 0;// Emiliano + irun = -1LL; + runfirstentry = 0LL; + runlastentry = 0LL; + + l0_file = NULL; + l0_tree = NULL; + iroot = -1; + dbc = 0; + + prevshift = 0; + maxshift = 10; //EMILIANO + + run_tree = NULL; + run_tree_clone = NULL; + sel_tree = NULL; + sel_tree_clone = NULL; + + irunentry = -1LL; + 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 = new TRefArray(); +// sorted_tracks = 0;//new TRefArray(); + CAL0 = false; CAL1 = true; CAL2 = true; TRK2 = true; TRK1 = false; + TRK0 = false; TRKh = false; - TRG = true; - TOF = true; - S4 = true; - ND = true; - AC = true; - ORB = true; - + TRG = true; + TOF = true; + TOF0 = false; + S4 = true; + ND = true; + AC = true; + ORB = true; + GP = false; + + RUN = true; + + SELLI = -1; + + ISGP = false; + + tsorted=0; + timage=0; + + howtosort = "+CAL+TOF"; + //howtosort = "+TOF"; + sortthr = 100.; }; /** - * Destructor + * Delete the event (act as Dtor) */ -PamLevel2::~PamLevel2(){ - delete run_obj; - Clear(); +void PamLevel2::Delete(){ + + if(run_obj)delete run_obj; + if(soft_obj)delete soft_obj; //Emiliano + +// cout << "void PamLevel2::Clear()"<Delete(); + delete tsorted; + } + if(timage){ + timage->Delete(); + delete timage; + } + + if(dbc){ + dbc->Close(); + delete dbc; + } + + if(l0_file)l0_file->Close(); + // if(pam_tree)pam_tree->Delete();; + + if ( pam_tree ){ + // + // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault... + // + TList *temp = pam_tree->GetListOfFriends(); + TList *contents = new TList; // create chain friend list + contents->SetOwner(); + TIter next(temp); + TChain *questo = 0; + while ( (questo = (TChain*) next()) ){ + TString name = questo->GetName(); + contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list + }; + // + // deleting the main chain + // + pam_tree->Delete(); + // + // deleting the friends... + // + TIter next2(contents); + TChain *questa = 0; + while ( questa = (TChain*)next2() ){ + TString name = questa->GetName(); + questa->Delete(); + questa=NULL; + }; + // + }; + pam_tree = NULL; + + 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();; + + }; + /** - * Clear the event + * Clear the event (NB! does not deallocate objects) */ void PamLevel2::Clear(){ - TrkLevel1::Clear(); - - TrkLevel2::Clear(); - CaloLevel2::Clear(); - ToFLevel2::Clear(); - TrigLevel2::Clear(); - S4Level2::Clear(); - NDLevel2::Clear(); - AcLevel2::Clear(); - OrbitalInfo::Clear(); - -// if(trk1_clone)trk1_clone->Clear(); -// if(trk2_clone)trk2_clone->Clear(); -// if(trkh_clone)trkh_clone->Clear(); -// if(calo1_clone)calo1_clone->Clear(); -// if(calo2_clone)calo2_clone->Clear(); -// if(tof_clone)tof_clone->Clear(); -// if(trig_clone)trig_clone->Clear(); -// if(s4_clone)s4_clone->Clear(); -// if(nd_clone)nd_clone->Clear(); -// if(ac_clone)ac_clone->Clear(); -// if(orb_clone)orb_clone->Clear(); - - sorted_tracks->Delete(); // clean the reference array +// 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(h0_obj) h0_obj->Clear(); +// if(trk0_obj) trk0_obj->Clear(); + if(trk1_obj) trk1_obj->Clear(); + if(trk2_obj) trk2_obj->Clear(); + if(trkh_obj) trkh_obj->Clear(); + if(calo0_obj) calo0_obj->Clear(); + if(calo1_obj)calo1_obj->Clear(); + if(calo2_obj)calo2_obj->Clear(); + if(tof_obj) tof_obj->Clear(); + if(trig_obj) trig_obj->Clear(); + if(s4_obj) s4_obj->Clear(); + if(nd_obj) nd_obj->Clear(); + if(ac_obj) ac_obj->Clear(); + if(orb_obj) orb_obj->Clear(); + if(gp_obj) gp_obj->Clear(); +// if(sorted_tracks)sorted_tracks->Clear(); +// sorted_tracks.Clear(); + + if(tsorted){ + tsorted->Delete(); + } + if(timage){ + timage->Delete(); + } +}; + +void PamLevel2::Reset(){ + // + // First of all clear everything + // + Clear(); + // + // close and reset chains and pointers + // + if ( pam_tree ){ + // + // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault... + // + TList *temp = pam_tree->GetListOfFriends(); + TList *contents = new TList; // create chain friend list + contents->SetOwner(); + TIter next(temp); + TChain *questo = 0; + while ( (questo = (TChain*) next()) ){ + TString name = questo->GetName(); + contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list + }; + // + // deleting the main chain + // + pam_tree->Delete(); + // + // deleting the friends... + // + TIter next2(contents); + TChain *questa = 0; + while ( questa = (TChain*)next2() ){ + TString name = questa->GetName(); + questa->Delete(); + questa=NULL; + }; + // + }; + pam_tree = NULL; + // + if(run_tree)run_tree->Delete();; + run_tree = NULL; + if(sel_tree)sel_tree->Delete();; + sel_tree = NULL; + // + // Close file + // + if(l0_file)l0_file->Close("R"); + l0_file = NULL; + // + h0_obj = 0; + trk0_obj = 0; + calo0_obj = 0; + // + trk2_obj = 0; + trk1_obj = 0; + trkh_obj = 0; + calo1_obj = 0; + calo2_obj = 0; + tof_obj = 0; + trig_obj = 0; + s4_obj = 0; + nd_obj = 0; + ac_obj = 0; + orb_obj = 0; + gp_obj = 0; + // + // Reset run pointers + // + run_obj = 0;//new GL_RUN(); + soft_obj = 0;// Emiliano + irun = -1; + runfirstentry = 0ULL; + runlastentry = 0ULL; + // + totdltime[0] = 0LL; + totdltime[1] = 0LL; + // }; +Bool_t PamLevel2::IsGood(){ + Bool_t goodev=true; + // if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false; + if(calo2_obj && calo2_obj->good != 1) goodev = false; + if(tof_obj && tof_obj->unpackError != 0) goodev = false; + if(trig_obj && trig_obj->unpackError != 0) goodev = false; + if(s4_obj && s4_obj->unpackError != 0) goodev = false; + if(nd_obj && nd_obj->unpackError != 0) goodev = false; + if(ac_obj && ac_obj->unpackError != 255) goodev = false; + // if(orb_obj) + return goodev; +}; //-------------------------------------- // @@ -136,18 +719,72 @@ void *PamLevel2::GetPointerTo(const char* c ){ TString objname = c; - if(!objname.CompareTo("TrkLevel1"))return &trk1_obj; - if(!objname.CompareTo("TrkLevel2"))return &trk2_obj; - if(!objname.CompareTo("TrkHough"))return &trkh_obj; - if(!objname.CompareTo("CaloLevel1"))return &calo1_obj; - if(!objname.CompareTo("CaloLevel2"))return &calo2_obj; - if(!objname.CompareTo("ToFLevel2"))return &tof_obj; - if(!objname.CompareTo("TrigLevel2"))return &trig_obj; - if(!objname.CompareTo("S4Level2"))return &s4_obj; - if(!objname.CompareTo("NDLevel2"))return &nd_obj; - if(!objname.CompareTo("AcLevel2"))return &ac_obj; - if(!objname.CompareTo("OrbitalInfo"))return &orb_obj; + + if(!objname.CompareTo("TrkLevel1")) { + if(!trk1_obj){ + trk1_obj = new TrkLevel1(); + trk1_obj->Set(); + } + return &trk1_obj; + }; + if(!objname.CompareTo("TrkLevel2")) { + if(!trk2_obj){ + trk2_obj = new TrkLevel2(); + trk2_obj->Set(); + } + return &trk2_obj; + }; + if(!objname.CompareTo("TrkHough")) { + if(!trkh_obj) trkh_obj = new TrkHough(); + return &trkh_obj; + }; + if(!objname.CompareTo("CaloLevel1")) { + if(!calo1_obj) calo1_obj = new CaloLevel1(); + return &calo1_obj; + }; + if(!objname.CompareTo("CaloLevel2")) { + if(!calo2_obj){ + calo2_obj = new CaloLevel2(); + calo2_obj->Set(); + }; + return &calo2_obj; + }; + if(!objname.CompareTo("ToFLevel2")) { + if(!tof_obj){ + tof_obj = new ToFLevel2(); + tof_obj->Set(); + } + return &tof_obj; + }; + if(!objname.CompareTo("TrigLevel2")) { + if(!trig_obj) trig_obj = new TrigLevel2(); + return &trig_obj; + }; + if(!objname.CompareTo("S4Level2")) { + if(!s4_obj) s4_obj = new S4Level2(); + return &s4_obj; + }; + if(!objname.CompareTo("NDLevel2")) { + if(!nd_obj) nd_obj = new NDLevel2(); + return &nd_obj; + }; + if(!objname.CompareTo("AcLevel2")) { + if(!ac_obj) ac_obj = new AcLevel2(); + return &ac_obj; + }; + if(!objname.CompareTo("OrbitalInfo")){ + if(!orb_obj) orb_obj = new OrbitalInfo(); + return &orb_obj; + }; + if(!objname.CompareTo("GPamela")){ + if(!gp_obj) gp_obj = new GPamela(); + return &gp_obj; + }; + if(!objname.CompareTo("RunInfo"))return &run_obj; + + if(!objname.CompareTo("SoftInfo"))return &soft_obj; // Emiliano + return NULL; }; //-------------------------------------- @@ -159,8 +796,10 @@ * (If seqno = -1 retrieves the self-trigger calorimeter track) */ CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){ - - if( CaloLevel2::ntrk()==0 ){ + + if( !calo2_obj )return 0; + + if( calo2_obj->CaloLevel2::ntrk()==0 ){ cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<CaloLevel2::GetCaloTrkVar(it_calo); it_calo++; - } while( c && seqno != c->trkseqno && it_calo < CaloLevel2::ntrk()); + } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk()); if(!c || seqno != c->trkseqno){ c = 0; @@ -190,7 +829,9 @@ */ ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){ - if( ToFLevel2::ntrk()==0 ){ + if( !tof_obj )return 0; + + if( tof_obj->ToFLevel2::ntrk()==0 ){ cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<ToFLevel2::GetToFTrkVar(it_tof); it_tof++; - } while( c && seqno != c->trkseqno && it_tof < ToFLevel2::ntrk()); + } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk()); if(!c || seqno != c->trkseqno){ c = 0; @@ -219,7 +860,10 @@ * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information. */ PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){ - + + cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<=0 && itrk < TrkLevel2::ntrk() ){ + if( itrk >=0 && itrk < trk2_obj->TrkLevel2::ntrk() ){ - TrkTrack *t = TrkLevel2::GetStoredTrack(itrk); + TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk); track = GetPamTrackAlong(t); + + }else{ - cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<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); - - if( !CAL2 && use_CAL) use_CAL = false; - if( !TOF && use_TOF) use_TOF = false; - - if( !TRK2 ){ -// cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl; - return; - }; + // cout << "ObjectNumber "<Clear(); + // sorted_tracks.Clear(); + + if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks()); + tsorted->Delete(); + TClonesArray &ttsorted = *tsorted; + if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks()); + timage->Delete(); + TClonesArray &ttimage = *timage; + + + + //-------------------------------------------------- + // retrieve sorting method + //-------------------------------------------------- + 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_S1 = how.Contains("S1", TString::kIgnoreCase); + Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase); + Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase); + + if ( use_TOF ){ + use_S1 = true; + use_S2 = true; + use_S3 = true; + }; + if( !CAL2 && use_CAL) use_CAL = false; + if( !TOF ){ + use_TOF = false; + use_S1 = false; + use_S2 = false; + use_S3 = false; + } + + if( !TRK2 ){ + // cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl; + return; + }; + + // cout << "use_CAL "<TrkLevel2::GetNTracks(); i++){ + + TrkTrack *ts = 0; + CaloTrkVar *cs = 0; + ToFTrkVar *os = 0; + + // get tracker tracks + TrkTrack *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker + CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo()); + ToFTrkVar *op = GetToFStoredTrack(tp->GetSeqNo()); + + TrkTrack *ti = 0; //tracker (image) + CaloTrkVar *ci = 0; + ToFTrkVar *oi = 0; + // cout << "trk track n. "<HasImage()){ + if(tp->HasImage()){ - TrkTrack *ti = TrkLevel2::GetTrackImage(i); //tracker (image) - CaloTrkVar *ci = 0; - ToFTrkVar *oi = 0; + ti = trk2_obj->TrkLevel2::GetTrackImage(i); //tracker (image) + ci = GetCaloStoredTrack(ti->GetSeqNo()); + oi = GetToFStoredTrack(ti->GetSeqNo()); -// cout << "its image "< 15 && //no. of fit planes on Y view - varcfit[1] < 1000. && //fit variance on Y view - true){ + // ----------------------------------------------------------------------------------------- + // calorimeter check + // ----------------------------------------------------------------------------------------- + // check the Y spatial residual on the first calorimeter plane + // (cut on calorimeter variables from Emiliano) + if( use_CAL && !calo2_obj ){ + cout << "void PamLevel2::SortTracks(): howtosort= "<npcfit[1] > 5 && //no. of fit planes on Y view +// calo2_obj->varcfit[1] < 1000. && //fit variance on Y view + cp && ci && + 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; +// Float_t resy_p = cp->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_p < 0)resy_p= - resy_p; +// Float_t resy_i = ci->tbar[0][1] - calo2_obj->cbar[0][1]; if(resy_i < 0)resy_i= - resy_i; - if(resy_p <= resy_i) tp_score++; - else ti_score++; +// if(resy_p <= resy_i) tp_score++; +// else ti_score++; + -// cout << "CALO "<npresh > ci->npresh){ + tp_score++; + totp_score++; + }; + if( cp->npresh < ci->npresh){ + ti_score++; + toti_score++; + }; + + // cout << "CALO "<npmtadc; ih++){ + Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) ); + if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih); + }; + for (Int_t ih=0; ih < oi->npmtadc; ih++){ + Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) ); + if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih); + }; + // + if ( sen >= sortthr && false){ // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!) + //printf(" IS A NUCLEUS! en = %f \n",sen); + // + // is a nucleus use a different algorithm + // + Int_t nz = 6; Float_t zin[6]; // << define TOF z-coordinates + for(Int_t ip=0; ipToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip)); // << read ToF plane z-coordinates + Trajectory *tr = new Trajectory(nz,zin); + // + Int_t nphit_p =0; + Int_t nphit_i =0; + Float_t enhit_p = 0.; + Float_t enhit_i = 0.; + // + for (Int_t ih=0; ih < op->npmtadc; ih++){ + Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) ); + if(pl == 1 || pl == 2 || pl == 5){ + nphit_p++; + enhit_p += (op->dedx).At(ih); + }; + }; + // + tp->DoTrack2(tr); + // + if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){ + for (Int_t ih=0; ih < op->npmtadc; ih++){ + Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) ); + if(pl == 0){ + nphit_p++; + enhit_p += (op->dedx).At(ih); + }; + }; + }; + if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){ + for (Int_t ih=0; ih < op->npmtadc; ih++){ + Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) ); + if(pl == 3){ + nphit_p++; + enhit_p += (op->dedx).At(ih); + }; + }; + }; + if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){ + for (Int_t ih=0; ih < op->npmtadc; ih++){ + Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) ); + if(pl == 4){ + nphit_p++; + enhit_p += (op->dedx).At(ih); + }; + }; + }; + + for (Int_t ih=0; ih < oi->npmtadc; ih++){ + Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) ); + if(pl == 1 || pl == 2 || pl == 5){ + nphit_i++; + enhit_i += (op->dedx).At(ih); + }; + }; + // + ti->DoTrack2(tr); + // + if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){ + for (Int_t ih=0; ih < oi->npmtadc; ih++){ + Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) ); + if(pl == 0){ + nphit_i++; + enhit_i += (op->dedx).At(ih); + }; + }; + }; + if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){ + for (Int_t ih=0; ih < oi->npmtadc; ih++){ + Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) ); + if(pl == 3){ + nphit_i++; + enhit_i += (op->dedx).At(ih); + }; + }; + }; + if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){ + for (Int_t ih=0; ih < oi->npmtadc; ih++){ + Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) ); + if(pl == 4){ + nphit_i++; + enhit_i += (op->dedx).At(ih); + }; + }; + }; + + if( + (use_TOF || use_S1 || use_S2 || use_S3) && + (nphit_p+nphit_i) !=0 && + true){ + + // printf(" seqno %i nphit_p %i nphit_i %i enhit_p %f enhit_i %f \n",trk2_obj->TrkLevel2::GetSeqNo(i),nphit_p,nphit_i,enhit_p,enhit_i); + // printf(" score p %i score i %i \n",tp_score,ti_score); + // if( enhit_p > enhit_i ) tp_score++; + // if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++; + if ( nphit_p > nphit_i ) tp_score++; + if ( nphit_p < nphit_i ) ti_score++; + if ( nphit_p == nphit_i ){ + if ( enhit_p > enhit_i ) tp_score++; + else ti_score++; }; - // ------------------------ - // TOF check - // ------------------------ - // check the number of hit pmts along the track - // on S12 S21 and S32, where paddles are parallel to Y axis - if( use_TOF ){ + // printf(" dopo score p %i score i %i \n",tp_score,ti_score); + }; + delete tr; + // + } else { + // + // NOT a NUCLEUS + // + //printf(" NOT a NUCLEUS! en = %f \n",sen); + + Int_t nphit_p =0; + Int_t nphit_i =0; - 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;*/ -/* cout << "track: npmtadc "<< op->npmtadc << endl; - cout << "track: npmttdc "<< op->npmttdc << endl; - cout << "image: npmtadc "<< oi->npmtadc << endl; - cout << "image: npmttdc "<< oi->npmttdc << endl;*/ +// for (Int_t ih=0; ih < op->npmtadc; ih++){ +// Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) ); +// if(pl == 1 || pl == 2 || pl == 5)nphit_p++; +// }; - for (Int_t ih=0; ih < 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 = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) ); +// if(pl == 1 || pl == 2 || pl == 5)nphit_i++; +// }; + // --- modified to count tdc signals (more efficient?) + // --- and to implement check on tdcflag + for (Int_t ih=0; ih < op->npmttdc; ih++){ + Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) ); +// if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++; + if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){ + if( (op->tdcflag).At(ih)==0 )nphit_p++; + }; + }; - for (Int_t ih=0; ih < oi->npmtadc; ih++){ - Int_t pl = GetPlaneIndex( (oi->pmtadc).At(ih) ); - if(pl == 1 || pl == 2 || pl == 5)nphit_i++; - }; + for (Int_t ih=0; ih < oi->npmttdc; ih++){ + Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) ); +// if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++; + if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){ + if( (oi->tdcflag).At(ih)==0 )nphit_i++; + }; + }; - if( - use_TOF && - (nphit_p+nphit_i) !=0 && - true){ + if( + (nphit_p+nphit_i) !=0 && + true){ - if( nphit_p >= nphit_i) tp_score++; - else ti_score++; - }; -// cout << "TOF "<chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ; - else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ; -// cout << "TRK "< nphit_i) tp_score+=nphit_p; + // else if( nphit_p < nphit_i) ti_score+=nphit_i; + // else ;//niente + }; + }; + // cout << "TOF "<chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ; +// else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ; + + // CHECK 1 : number of points along X + if ( tp->GetNX() >= ti->GetNX() ){ + tp_score++ ; + totp_score++ ; + }; + if ( tp->GetNX() <= ti->GetNX() ){ + ti_score++ ; + toti_score++ ; + }; + // CHECK 2 : number of points along Y + if ( tp->GetNY() >= ti->GetNY() ){ + tp_score++ ; + totp_score++ ; + }; + if ( tp->GetNY() <= ti->GetNY() ){ + ti_score++ ; + toti_score++ ; + }; + // CHECK 3 : chi**2 along X +// if( tp->GetChi2X() > 0 && (tp->GetChi2X() < ti->GetChi2X() || ti->GetChi2X() <=0) ) tp_score++ ; +// if( ti->GetChi2X() > 0 && (ti->GetChi2X() < tp->GetChi2X() || tp->GetChi2X() <=0) ) ti_score++ ; + // CHECK 4 : chi**2 along Y +// if( tp->GetChi2Y() > 0 && (tp->GetChi2Y() < ti->GetChi2Y() || ti->GetChi2Y() <=0) ) tp_score++ ; +// if( ti->GetChi2Y() > 0 && (ti->GetChi2Y() < tp->GetChi2Y() || tp->GetChi2Y() <=0) ) ti_score++ ; + // CHECK 5 : total chi**2 +// if( tp->chi2 > 0 && (tp->chi2 < ti->chi2 || ti->chi2 <=0) ) tp_score++ ; +// if( ti->chi2 > 0 && (ti->chi2 < tp->chi2 || tp->chi2 <=0) ) ti_score++ ; + + // cout << "TRK "< 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; - }; + + + // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + // the winner is.... + // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* + if (tp_score > ti_score) { + + + }else if (tp_score < ti_score) { + + + ts = ti;//its image!! + cs = ci; + os = oi; + Int_t totis = toti_score; + + ti = tp;//its image!! + ci = cp; + oi = op; + + tp = ts;//its image!! + cp = cs; + op = os; + + toti_score = totp_score; + totp_score = totis; + + + }else { + +// cout << "Warning - track image ambiguity not solved" << endl; + + }; - }else{ - ts = tp; - }; - -// cout <<" SortTracks() "<Add(ts);//save the track in the sorted array -// cout << "SortTracks:: sorted_tracks->Add(it) "<Add(ts);//save the track in the sorted array + // sorted_tracks.Add(ts);//save the track in the sorted array + // sorted_tracks.Add(tp);//save the track in the sorted array + // cout << "SortTracks:: sorted_tracks->Add(it) "<SetPScore(totp_score); + ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score); + ((PamTrack*)(ttimage[i]))->SetPScore(totp_score); + ((PamTrack*)(ttimage[i]))->SetIScore(toti_score); + }; + + if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){ + cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<GetEntries()<<" != trk2_obj->GetNTracks() = "<GetNTracks() <Delete(); tsorted=0; + timage->Delete(); timage=0; + } + + //Restore Object count + //To save space in the table keeping track of all referenced objects + //We reset the object count to what it was at the beginning of the event. + TProcessID::SetObjectCount(ObjectNumber); }; //-------------------------------------- @@ -430,13 +1399,24 @@ * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2. * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information. */ -TRefArray *PamLevel2::GetTracks(){ +// TRefArray *PamLevel2::GetTracks(){ + +// // *-*-*-*-*-*-*-*-*-*-*-*-* +// SortTracks("+CAL+TOF"); +// // *-*-*-*-*-*-*-*-*-*-*-*-* + +// // return sorted_tracks; +// return &sorted_tracks; + +// }; +TClonesArray *PamLevel2::GetTracks(){ // *-*-*-*-*-*-*-*-*-*-*-*-* - SortTracks("+CAL+TOF"); + SortTracks(); // *-*-*-*-*-*-*-*-*-*-*-*-* - return sorted_tracks; + return tsorted; + }; //-------------------------------------- // @@ -448,18 +1428,43 @@ * @param it Track number, ranging from 0 to GetNTracks(). */ PamTrack *PamLevel2::GetTrack(int it){ + +// if(!trk2_obj) return 0; +// // *-*-*-*+-*-*-*-*-*-*-*-*-* +// SortTracks("+CAL+TOF"); +// // *-*-*-*-*-*-*-*-*-*-*-*-* +// // if(!sorted_tracks)return 0; +// if(sorted_tracks.IsEmpty())return 0; + +// PamTrack *track = 0; + +// if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() && itGetEntries())return 0; + PamTrack *track = 0; - if( it >=0 && it < TrkLevel2::GetNTracks() && itGetEntriesFast() ){ - TrkTrack *t = (TrkTrack*)sorted_tracks->At(it); - track = GetPamTrackAlong(t); + if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks()){ +// TrkTrack *t = (TrkTrack*)sorted_tracks.At(it); +// track = GetPamTrackAlong(t); + TClonesArray &t = *(tsorted); + track = (PamTrack*)t[it]; + }else{ - cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){ +// TrkTrack *temp = (TrkTrack*)sorted_tracks.At(it); +// if( temp->HasImage() ){ +// TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(temp->GetImageSeqNo()); +// image = GetPamTrackAlong(t); +// }else{ +// cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<GetEntries())return 0; PamTrack *image = 0; - if( it >=0 && it < TrkLevel2::GetNTracks() ){ - TrkTrack *temp = (TrkTrack*)sorted_tracks->At(it); - if( temp->HasImage() ){ - TrkTrack *t = TrkLevel2::GetStoredTrack(temp->GetImageSeqNo()); - image = GetPamTrackAlong(t); + if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){ + TClonesArray &t = *(tsorted); + PamTrack *temp = (PamTrack*)t[it]; + if( temp->GetTrkTrack()->HasImage() ){ + TClonesArray &t = *(timage); + image = (PamTrack*)t[it]; }else{ - cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<GetName(); if(!CheckLevel2File(fname))return NULL; - +// UInt_t *found=0; + + cout<< "GetPamTree(TFile*,TString): detector list --> "; + if(TRK1)cout<<"TRK1 "; + if(TRK2)cout<<"TRK2 "; + if(TRKh)cout<<"TRKH "; + if(CAL1)cout<<"CAL1 "; + if(CAL2)cout<<"CAL2 "; + if(TOF)cout<<"TOF "; + if(TRG)cout<<"TRG "; + if(AC)cout<<"AC "; + if(ND)cout<<"ND "; + if(S4)cout<<"S4 "; + if(ORB)cout<<"ORB "; + if(GP)cout<<"GP "; + cout << endl; + if(SELLI)cout<<">>> Found selection-list <<<"<cd(); + // Tracker TTree *T = (TTree*)f->Get("Tracker"); if(T && (TRK2||TRK1||TRKh)) { if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2")); +// else T->SetBranchStatus("TrkLevel2",0,found); if(TRK2)cout << "Tracker : set branch address TrkLevel2"<SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1")); +// else T->SetBranchStatus("TrkLevel1",0,found); if(TRK1)cout << "Tracker : set branch address TrkLevel1"<SetBranchAddress("TrkHough", GetPointerTo("TrkHough")); +// else T->SetBranchStatus("TrkHough",0,found); if(TRKh)cout << "Tracker : set branch address TrkHough"<AddFriend(T); @@ -538,14 +1604,17 @@ TTree *C = (TTree*)f->Get("Calorimeter"); if(C && (CAL2||CAL1)) { if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2")); +// else C->SetBranchStatus("CaloLevel2",0,found); if(CAL2)cout << "Calorimeter : set branch address CaloLevel2"<SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1")); +// else C->SetBranchStatus("CaloLevel1",0,found); if(CAL1)cout << "Calorimeter : set branch address CaloLevel1"<AddFriend(C); }else{ cout << "Calorimeter : missing tree"<Get("ToF"); if(O && TOF) { @@ -561,7 +1630,7 @@ if(R && TRG) { R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2")); cout << "Trigger : set branch address TrigLevel2"<AddFriend(R); }else{ cout << "Trigger : missing tree"<SetBranchAddress("S4Level2", GetPointerTo("S4Level2")); cout << "S4 : set branch address S4Level2"<AddFriend(S); }else{ cout << "S4 : missing tree"<SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2")); cout << "NeutronD : set branch address NDLevel2"<AddFriend(N); }else{ cout << "NeutronD : missing tree"<SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2")); cout << "Anticounter : set branch address AcLevel2"<AddFriend(A); }else{ cout << "Anticounter : missing tree"<Get("OrbitalInfo"); - if(B && ORB) { - B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo")); - cout << "OrbitalInfo : set branch address OrbitalInfo"<AddFriend(B); - }else{ - cout << "OrbitalInfo : missing tree"<Get("OrbitalInfo"); + if(B && ORB) { + B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo")); + cout << "OrbitalInfo : set branch address OrbitalInfo"<AddFriend(B); + }else{ + cout << "OrbitalInfo : missing tree"<Get("h20"); + if(G && GP) { + if(!gp_obj)gp_obj=new GPamela(); +// ------------------------------------ +// ATTENZIONE!!! +// non so per quale arcano motivo, +// per l'albero di gpamela il branch address lo devo settare +// DOPO aver fatto friend +// FGRRRVZZZZUTSALKJMSLKJ!!! +// ------------------------------------ +// gp_obj->SetBranchAddress(G); //ho dovuto fare in maniera diversa dagli altri +// cout << "h20 : set branch address GPamela "<AddFriend(G); + }else{ +// cout << "h20 : 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()<GetEntries()<SetBranchAddress(Trout); //ho dovuto fare in maniera diversa dagli altri + cout << "h20 : set branch address GPamela "<WorkingDirectory(); - if(ddir=="")ddir = wdir; + // if(ddir=="")ddir = wdir; // TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir); - cout << "Level2 data directory : "<< ddir << endl; - + if ( ddir != ""){ + cout << "Level2 data directory : "<< ddir << endl; + } else { + cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory " << endl; + }; TList *contents = new TList; // create output list contents->SetOwner(); - char *fullpath; +// char *fullpath; +// const 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; +// if( !gSystem->IsFileInIncludePath(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; @@ -656,28 +1792,47 @@ if (!in.good()) break; line++; // cout <<"(1) " << file << endl; - if(file.Contains("#"))file = file(0,file.First("#")); -// cout <<"(2) " << file << endl; if(file.IsNull()){ cout << "-- list interrupted at line "<IsFileInIncludePath(file,&fullpath) ){ - + if(file.Contains("#"))file = file(0,file.First("#")); +// cout <<"(2) " << file << endl; +// if( gSystem->IsFileInIncludePath(file,&fullpath) ){ +// if( (fullpath = gSystem->FindFile(ddir,file)) ){ + if( file.EndsWith(".root") ){ + TString filedir; + if (ddir != ""){ + filedir = ddir; // take the input dir + } else { + gSystem->ChangeDirectory(wdir); // back to the working directory + filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir + }; + char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file)); contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list - - }else{ - if(file.Data()!="")cout << "File: "< missing "<< endl; - }; + delete fullpath; + } +// }else{ +// if(file.Data()!="")cout << "File: "< missing "<< endl; +// }; }; in.close(); - + } else { + if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#")); + 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."<WorkingDirectory()<< endl; - + if ( ddir == "" ){ + ddir = wdir; + cout << "Level2 data directory : "<< ddir << endl; + }; + TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir); TList *temp = datadir->GetListOfFiles(); // temp->Print(); @@ -690,9 +1845,12 @@ while ( (questo = (TSystemFile*) next()) ) { TString name = questo-> GetName(); if( name.EndsWith(".root") ){ - char *fullpath; - gSystem->IsFileInIncludePath(name,&fullpath); +// 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; @@ -702,7 +1860,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; @@ -717,101 +1875,220 @@ * @param detlist String to select trees to be included * @return Pointer to a TChain */ -TChain *PamLevel2::GetPamTree(TList *fl, TString detlist="+ALL"){ +TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){ + // + // + // + if ( pam_tree ){ + printf("WARNING: TChain *PamLevel2::GetPamTree(TList *fl, TString detlist) -- pam_tree already exists!\n "); + return pam_tree; + }; + // + + TChain *Trout =0; + + + if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) { + if( fl->GetEntries()>0 ){ + cout << "+AUTO"<At(0)->GetName() ); + GetWhichTrees(fprimo); + fprimo->Delete(); + } + }; + SetWhichTrees(detlist); -// TChain *Tout=0; -// if(Tout)Tout->Delete(); -// Tout = NULL; - - TChain *Tout =0; - 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( !detlist.IsNull() )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; + TChain *G = 0; + + TChain *L = 0; if(TRK2||TRK1||TRKh) T = new TChain("Tracker"); - if(CAL2||CAL1) 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"); + if(CAL2||CAL1) 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"); + if(GP) G = new TChain("h20"); + L = new TChain("SelectionList"); // loop over files and create chains TIter next(fl); TSystemFile *questo = 0; while ( (questo = (TSystemFile*) next()) ) { TString name = questo->GetName(); -// cout << "File: "<< name << endl; + cout << "File: "<< name << endl; if( CheckLevel2File(name) ){ if(TRK2||TRK1||TRKh) T->Add(name); - if(CAL1||CAL2) 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); + if(CAL1||CAL2) 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); + if(GP) G->Add(name); + if(SELLI==1) L->Add(name); }; - } + }; cout << "done chain \n"; - + cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2")); +// if(TRK2)cout << "Tracker : set branch address TrkLevel2"<SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1")); +// if(TRK1)cout << "Tracker : set branch address TrkLevel1"<SetBranchAddress("TrkHough", GetPointerTo("TrkHough")); +// if(TRKh)cout << "Tracker : set branch address TrkHough"<AddFriend("Tracker"); + }else{ +// cout << "Tracker : missing tree"<AddFriend("Calorimeter"); + if(C && (CAL2||CAL1)) { +// if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2")); +// if(CAL2)cout << "Calorimeter : set branch address CaloLevel2"<SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1")); +// if(CAL1)cout << "Calorimeter : set branch address CaloLevel1"<AddFriend("Calorimeter"); + }else{ +// cout << "Calorimeter : missing tree"<AddFriend("ToF"); + if(O && TOF) { +// O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2")); +// cout << "ToF : set branch address ToFLevel2"<AddFriend("ToF"); + }else{ +// cout << "ToF : missing tree"<AddFriend("Tracker"); - } // Trigger - if(TRG) { - if(!Tout)Tout=R; - else Tout->AddFriend("Trigger"); + if(R && TRG) { +// R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2")); +// cout << "Trigger : set branch address TrigLevel2"<AddFriend("Trigger"); + }else{ +// cout << "Trigger : missing tree"<AddFriend("S4"); + if(S && S4) { +// S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2")); +// cout << "S4 : set branch address S4Level2"<AddFriend("S4"); + }else{ +// cout << "S4 : missing tree"<AddFriend("NeutronD"); + if(N && ND) { +// N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2")); +// cout << "NeutronD : set branch address NDLevel2"<AddFriend("NeutronD"); + }else{ +// cout << "NeutronD : missing tree"<AddFriend("Anticounter"); + if(A && AC) { +// A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2")); +// cout << "Anticounter : set branch address AcLevel2"<AddFriend("Anticounter"); + }else{ +// cout << "Anticounter : missing tree"<AddFriend("OrbitalInfo"); + // Orbital Info + if(B && ORB) { +// B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo")); +// cout << "OrbitalInfo : set branch address OrbitalInfo"<AddFriend("OrbitalInfo"); + }else{ +// cout << "OrbitalInfo : missing tree"<SetBranchAddress(G); //ho dovuto fare in maniera diversa dagli altri +// cout << "h20 : set branch address GPamela "<AddFriend("h20"); + }else{ +// cout << "h20 : 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"); + cout << "----------------------------------------------------" <Delete(); }; -// cout<GetEntries()<GetEntries() )PamLevel2::SetBranchAddress(); - if( Tout->GetEntries() )PamLevel2::SetBranchAddress( Tout ); +// cout<GetEntries()<SetBranchAddress(Trout); //ho dovuto fare in maniera diversa dagli altri +// cout << "h20 : set branch address GPamela "<GetBranchStatus("NDLevel2"); AC = AC & t->GetBranchStatus("AcLevel2"); ORB = ORB & t->GetBranchStatus("OrbitalInfo"); + GP = GP & t->GetBranchStatus("h20"); // Tracker @@ -892,6 +2170,20 @@ t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo")); cout << "OrbitalInfo : set branch address OrbitalInfo"<SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri + cout << "h20 : set branch address GPamela "<SetBranchAddress("RunEntry", &irun); + cout << "SelectionList: set branch address RunEntry"<SetBranchAddress("EventEntry", &irunentry); + cout << "SelectionList: set branch address EventEntry"<GetBranchStatus("TrkLevel2"); - TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1"); - TRKh = TRKh & t->GetBranchStatus("TrkHough"); - CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1"); - CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2"); - TOF = TOF & t->GetBranchStatus("ToFLevel2"); - TRG = TRG & t->GetBranchStatus("TrigLevel2"); - S4 = S4 & t->GetBranchStatus("S4Level2"); - ND = ND & t->GetBranchStatus("NDLevel2"); - AC = AC & t->GetBranchStatus("AcLevel2"); - ORB = ORB & t->GetBranchStatus("OrbitalInfo"); +// TRK2 = TRK2 & t->GetBranchStatus("TrkLevel2"); +// TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1"); +// TRKh = TRKh & t->GetBranchStatus("TrkHough"); +// CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1"); +// CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2"); +// TOF = TOF & t->GetBranchStatus("ToFLevel2"); +// TRG = TRG & t->GetBranchStatus("TrigLevel2"); +// S4 = S4 & t->GetBranchStatus("S4Level2"); +// ND = ND & t->GetBranchStatus("NDLevel2"); +// AC = AC & t->GetBranchStatus("AcLevel2"); +// ORB = ORB & t->GetBranchStatus("OrbitalInfo"); +// GP = GP & t->GetBranchStatus("h20"); // Tracker if(TRK2) { - t->SetBranchAddress("TrkLevel2", this->GetPointerTo("TrkLevel2")); + t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2")); cout << "Tracker : set branch address TrkLevel2"<SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo")); cout << "OrbitalInfo : set branch address OrbitalInfo"<SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri + cout << "h20 : set branch address GPamela "<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("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"<Get("Run"); - return R; + if(T){ + T->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; + Long64_t oldrun = irun; + + // -------------------------------------- + // if it is a full file (not preselected) + // -------------------------------------- + if(SELLI==0){ + + // + // the absolute time is necessary to relate the event with the run + // + if( !GetOrbitalInfo() && !ISGP){ + cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<absTime; + + + // + // the first time the routine is called, set run search from the beginning + // + if ( irun < 0LL ){ + irun = 0LL; + run->GetEntry(irun); + runfirstentry = 0LL; + runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS); + if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL; + + if( ISGP && run->GetEntries()!=1 ){ + cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl; + cout << "** WARNING ** run will not be updated"<RUNHEADER_TIME; // BARBATRUCCO + // + if ( irun == run->GetEntries()-1LL && + !(abstime >= GetRunInfo()->RUNHEADER_TIME && + abstime <= GetRunInfo()->RUNTRAILER_TIME) + ){ + irun = -1LL; + runfirstentry = 0LL; + runlastentry = -1LL; + }; + // modificato il controllo sull'aggiornamento del run, per evitare problemi + // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!) + // + bool fromfirst = true; + // + while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){ +// while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){ + irun++; + run->GetEntry(irun); + runfirstentry = runlastentry; + if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL; + runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS); +// cout << " ))))) UPDATE RUN INFO ((((( @iev "<ID<<" irun "<GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS))); + // printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME); + // printf(" IDRUN %u \n",GetRunInfo()->ID); + // +// prevshift = 0; + // + if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){ + printf(" resetting irun (it should NOT happen!!!)\n"); + fromfirst = false; + irun = 0; + run->GetEntry(irun); + runfirstentry = 0ULL; + runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS); + if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL; + }; + // + }; + // + if ( + !(abstime >= GetRunInfo()->RUNHEADER_TIME && + abstime <= GetRunInfo()->RUNTRAILER_TIME) + ) { + printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n",abstime); + return false; + } + // + if ( irun == oldrun || irun >= run->GetEntries() ) return(false); + // + // printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry); + // + prevshift = 0; + cout << " ))))) UPDATE RUN INFO ((((( @iev "<ID<<" irun "<GetEntry(iev); +// cout << irun << " "<< irunentry << endl; + if(irun != oldrun){ + run->GetEntry(irun); + cout << " ))))) UPDATE RUN INFO ((((( @iev "<ID<<" irun "<GetEntries() <= 0 ) { + cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty"<dltime[0]; + totdltime[1]+=GetTrigLevel2()->dltime[1]; + } + totdltime[2]++; + +// cout << setw(10)<absTime; + obt = GetOrbitalInfo()->OBT; + } + // --------------------------------------------------------------- + // the absolute time is necessary to relate the event with the run + // --------------------------------------------------------------- + if( !GetOrbitalInfo() && !ISGP ){ + cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<GetEntry(irun); + + if( ISGP && run_tree->GetEntries()!=1 ){ + cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl; + cout << "** WARNING ** run will not be updated"<RUNHEADER_TIME; // BARBATRUCCO + obt = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO + } + // + bool fromfirst = true; // first loop over runs + +// Bool_t hasfrag = false; +// if( GetRunInfo()->ID_RUN_FRAG!=0 && GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID)hasfrag=true; +// ULong64_t fragid = GetRunInfo()->ID_RUN_FRAG; + + // ------------------------------------------------------ + // loop over runs to find the one that contains the event + // ------------------------------------------------------ + while ( + ( + ( + !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s) + abstime <= GetRunInfo()->RUNTRAILER_TIME) && + !(obt >= GetRunInfo()->RUNHEADER_OBT && // additional check on OBT (ms) + obt <= GetRunInfo()->RUNTRAILER_OBT) + ) + || GetRunInfo()->NEVENTS==0 +// || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento + || !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) + ) + && irun < run_tree->GetEntries() ){ + + // - - - - - - - - - - - - - + // irunentry = position of current entry, relative to the run + // prevshift = shift needed to synchronize l0 and l2 data (nested events) + // - - - - - - - - - - - - - + + // ----------------------------------------- + // store dead and live-time of previous run + // ----------------------------------------- + if(fromfirst){ + if(oldrun==irun){ + /// decrement counters + if( GetTrigLevel2()){ + totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time + totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time + } + totdltime[2]--; //event counter + cout << endl; + cout << "n.events : "<GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries()) + run_tree_clone->GetBranch("DeadLiveTime")->Fill(); + /// reset counters + if( GetTrigLevel2() ){ + totdltime[0]=GetTrigLevel2()->dltime[0];//live-time + totdltime[1]=0; //dead-time + } + totdltime[2]=1; //event counter + } + + + irun++; + // ------------------------------------ + // if the end of run tree is reached... + // ------------------------------------ + if( irun == run_tree->GetEntries() ){ + if(!fromfirst){ + // ----------------------------------------------------- + // if it happened already once and the run was not found + // ---> exit with error + // ----------------------------------------------------- + cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- event entry #"<0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift; + irunentry = 0; + prevshift = 0; + run_tree->GetEntry(irun); + if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){ + cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<=RUNTRAILER_OBT " <ID){ +// cout << "... where is the next fragment ??"< exit with FALSE + // -------------------------------------- + if ( irun == oldrun ) return(false); + + // -------------------------------------- + // ... otherwise + // -------------------------------------- + + + +// // ----------------------------------------- +// // store dead and live-time of previous run +// // ----------------------------------------- +// // -------------------------------------------------------------- +// // if the run is empty, fill the dead-live time branch with zeros +// // -------------------------------------------------------------- +// /// if some runs have been jumped, fill with zeros +// if(irun-oldrun>1){ +// ULong64_t temp[3]; +// temp[0]=totdltime[0]; +// temp[1]=totdltime[1]; +// temp[2]=totdltime[2]; +// for(int i=oldrun+1; iGetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries()) +// run_tree_clone->GetBranch("DeadLiveTime")->Fill(); +// } +// totdltime[0]=temp[0]; +// totdltime[1]=temp[1]; +// totdltime[2]=temp[2]; +// } +// /// decrement counters +// if( GetTrigLevel2() ){ +// totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time +// totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time +// } +// totdltime[2]--; //event counter +// /// add an entry +// if(irun>0 ){ +// cout << endl; +// cout << "n.events : "<GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries()) +// run_tree_clone->GetBranch("DeadLiveTime")->Fill(); +// } +// /// reset counters +// if( GetTrigLevel2() ){ +// totdltime[0]=GetTrigLevel2()->dltime[0];//live-time +// totdltime[1]=0; //dead-time +// } +// totdltime[2]=1; //event counter + + + // -------------------------------------- + // ---> exit with TRUE + // -------------------------------------- + cout << endl << " ))))) UPDATE RUN INFO ((((( @iev "<ID<<" irun "<ID_RUN_FRAG != 0 && +// GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID && + true ){ + cout << "* fragment *"<GetEntry(iev); + if(irun != oldrun){ + run_tree->GetEntry(irun); + cout << endl << " ))))) UPDATE RUN INFO ((((( @iev "<ID<<" irun "< "; + if(TRK0)cout<<"TRK0 "; + if(TRK1)cout<<"TRK1 "; + if(TRK2)cout<<"TRK2 "; + if(TRKh)cout<<"TRKH "; + if(CAL0)cout<<"CAL0 "; + if(CAL1)cout<<"CAL1 "; + if(CAL2)cout<<"CAL2 "; + if(TOF)cout<<"TOF "; + if(TRG)cout<<"TRG "; + if(AC)cout<<"AC "; + if(ND)cout<<"ND "; + if(S4)cout<<"S4 "; + if(ORB)cout<<"ORB "; + if(GP)cout<<"GP "; + cout << endl; +// cout<< "Set detector list --> "; +// if(TRK1)cout<<"TRK1 "; +// if(TRK2)cout<<"TRK2 "; +// if(TRKh)cout<<"TRKH "; +// if(CAL1)cout<<"CAL1 "; +// if(CAL2)cout<<"CAL2 "; +// if(TOF0)cout<<"TOF0 "; +// if(TOF)cout<<"TOF "; +// if(TRG)cout<<"TRG "; +// if(AC)cout<<"AC "; +// if(ND)cout<<"ND "; +// if(S4)cout<<"S4 "; +// if(ORB)cout<<"ORB "; +// cout << endl; }; + + +/** + * 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()<IsZombie() ){ + cout << "File: "<< f->GetName() <<" Non valid root file"<< endl; + return; + } + + TList *lk = f->GetListOfKeys(); + TIter next(lk); + TKey *key =0; + + Int_t nev = 0; + + while( (key = (TKey*)next()) ){ + + if( !strcmp(key->GetName(),"Run" ) )RUN = true; + + //========================================================= + if( !strcmp(key->GetName(),"Trigger" ) ){ + TRG = true; + Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<" Trigger tree has "<GetName(),"ToF" ) ){ + TOF = true; + Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<" ToF tree has "<GetName(),"S4" ) ){ + S4 = true; + Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<" S4 tree has "<GetName(),"NeutronD" ) ){ + ND = true; + Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<"NeutronD tree has "<GetName(),"Anticounter") ){ + AC = true; + Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<" Anticounter tree has "<GetName(),"OrbitalInfo") ){ + ORB = true; + Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<" OrbitalInfo tree has "<GetName(),"Tracker" ) ){ + 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") )TRK1=true; + if( !name.CompareTo("TrkLevel2") )TRK2=true; + if( !name.CompareTo("TrkHough") )TRKh=true; + }; + Int_t nevt = T->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<" Tracker tree has "<Delete(); + }; + //========================================================= + if( !strcmp(key->GetName(),"Calorimeter" ) ){ + TTree *T = (TTree*)f->Get("Calorimeter"); + for(Int_t i=0; iGetListOfBranches()->GetEntries(); i++){ + TString name = T->GetListOfBranches()->At(i)->GetName(); + if( !name.CompareTo("CaloLevel1") )CAL1=true; + if( !name.CompareTo("CaloLevel2") )CAL2=true; + }; + Int_t nevt = T->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<" Calorimeter tree has "<Delete(); + }; + //========================================================= + if( !strcmp(key->GetName(),"h20") ){ + GP = true; + Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<" h20 tree has "< "; + if(TRK1)cout<<"TRK1 "; + if(TRK2)cout<<"TRK2 "; + if(TRKh)cout<<"TRKH "; + if(CAL1)cout<<"CAL1 "; + if(CAL2)cout<<"CAL2 "; + if(TOF)cout<<"TOF "; + if(TRG)cout<<"TRG "; + if(AC)cout<<"AC "; + if(ND)cout<<"ND "; + if(S4)cout<<"S4 "; + if(ORB)cout<<"ORB "; + if(GP)cout<<"GP "; + cout << endl; + + return ; + +}; + + //-------------------------------------- // // @@ -1171,10 +3113,11 @@ Bool_t ND__ok = false; Bool_t AC__ok = false; Bool_t ORB__ok = false; + Bool_t GP__ok = false; Bool_t RUN__ok = false; - + Bool_t SELLI__ok = false; cout << "Checking file: "<GetName() << endl; -// cout << " Get tree: " << f->Get(key->GetName())<GetName() << ""<GetClassName()<Get(key->GetName())<GetClassName()=="TTree" && nev_previous && nev != nev_previous ){ @@ -1201,9 +3145,26 @@ // return false; // }; + //========================================================= + // check if the file + + if( !strcmp(key->GetName(),"Run" ) )RUN__ok = true; //========================================================= + if( !strcmp(key->GetName(),"SelectionList" ) ){ + SELLI__ok = true; + if(SELLI==1){ + Int_t nevt = ((TTree*)f->Get("SelectionList"))->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<" discarded ---- SelectionList tree has "<GetName(),"Trigger" ) ){ TRG__ok = true; if(TRG){ @@ -1313,9 +3274,56 @@ }; T->Delete(); }; + //========================================================= + if( !strcmp(key->GetName(),"h20") ){ + ISGP = true; + GP__ok = true; + if(GP){ + Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<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 "; +// if(TRKh__ok)cout<<"TRKH "; +// if(CAL1__ok)cout<<"CAL1 "; +// if(CAL2__ok)cout<<"CAL2 "; +// if(TOF__ok)cout<<"TOF "; +// if(TRG__ok)cout<<"TRG "; +// if(AC__ok)cout<<"AC "; +// if(ND__ok)cout<<"ND "; +// if(S4__ok)cout<<"S4 "; +// if(ORB__ok)cout<<"ORB "; +// cout << endl; + + + if(TRK2 && TRK1__ok)TRK1=1; +// ---------------------------------------------------------------------------- +// NOTA +// se c'e` il level1, lo devo necessarimente leggere. +// infatti (non ho capito perche`) i cluster vengono letti e allocati in memoria +// comunque, ma non vengono disallocati da PamLevel2::Clear() +// ---------------------------------------------------------------------------- if(!RUN__ok) { @@ -1360,21 +3368,38 @@ return false; }; - if(ND && !ND__ok){ - cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl; - return false; - }; - if(TRG && !TRG__ok){ - cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl; - return false; - }; - - - - + if(ND && !ND__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl; + return false; + }; + if(TRG && !TRG__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl; + return false; + }; + if(GP && !GP__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing h20 tree"<< endl; + return false; + }; + - lk->Delete(); +// lk->Delete(); +// delete lk; f->Close(); + +// cout<< "CheckLevel2File(TString): detector list --> "; +// if(TRK1)cout<<"TRK1 "; +// if(TRK2)cout<<"TRK2 "; +// if(TRKh)cout<<"TRKH "; +// if(CAL1)cout<<"CAL1 "; +// if(CAL2)cout<<"CAL2 "; +// if(TOF)cout<<"TOF "; +// if(TRG)cout<<"TRG "; +// if(AC)cout<<"AC "; +// if(ND)cout<<"ND "; +// if(S4)cout<<"S4 "; +// if(ORB)cout<<"ORB "; +// if(GP)cout<<"GP "; +// cout << endl; return true; @@ -1384,216 +3409,176 @@ /** * Create clone-trees */ -void PamLevel2::CreateCloneTrees( TChain *fChain ){ +void PamLevel2::CreateCloneTrees0( TChain *fChain, TFile *ofile ){ cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <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(); TIter next(li); TFriendElement* T_friend=0; + ofile->cd(); while( (T_friend = (TFriendElement*)next()) ){ // cout<IsA()->GetName()<<" "<GetName()<GetTree() << dec<GetTree()->GetName()<< endl; - tree_clone[i] = T_friend->GetTree()->CloneTree(0); - 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++; } + + delete li; cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <cd(); + + cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1")); -// T_clone->BranchRef(); -// cout << "Tracker : branch TrkLevel1"<Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2")); -// cout << "Tracker : branch TrkLevel2"<Branch("TrkHough","TrkHough", GetPointerTo("TrkHough")); -// cout << "Tracker : branch TrkHough"<Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1")); -// cout << "Calorimeter : branch CaloLevel1"<Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2")); -// cout << "Calorimeter : branch CaloLevel2"<Branch("RunInfo","GL_RUN",GetPointerTo("RunInfo")); + cout << "Run : branch RunInfo"<Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo")); + cout << "Run : branch SoftInfo"<GetEntries(); i++){ + run_tree->GetEntry(i); + cout << i<< "\t | "<ID<<"\t "<NEVENTS<< "\t "<RUNHEADER_TIME<<" <---> "<RUNTRAILER_TIME<Fill(); + } + cout << "----------------------------------------------------"<Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2")); -// cout << "ToF : branch ToFLevel2"<Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2")); -// cout << "Trigger : branch TrigLevel2"<Branch("S4Level2","S4Level2", GetPointerTo("S4Level2")); -// cout << "S4 : branch S4Level2"<Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2")); -// cout << "NeutronD : branch NDLevel2"<Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2")); -// cout << "Anticounter : branch AcLevel2"<Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo")); -// cout << "OrbitalInfo : branch OrbitalInfo"<Branch("DeadLiveTime",totdltime,"dltime[3]/l"); + cout << "Run : branch DeadLiveTime"<Branch("RunEntry",&irun,"runentry/L"); + sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L"); + -// cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <Branch("TrkLevel1","TrkLevel1", &trk1_clone); -// T_clone->BranchRef(); -// cout << "Tracker : branch TrkLevel1"<Branch("TrkLevel2", "TrkLevel2",&trk2_clone); -// cout << "Tracker : branch TrkLevel2"<Branch("TrkHough","TrkHough", &trkh_clone); -// cout << "Tracker : branch TrkHough"<Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1")); + pam_tree_clone[i]->BranchRef(); + cout << "Tracker : branch TrkLevel1"<Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2")); + cout << "Tracker : branch TrkLevel2"<Branch("TrkHough","TrkHough", GetPointerTo("TrkHough")); + cout << "Tracker : branch TrkHough"<Branch("CaloLevel1", "CaloLevel1", &calo1_clone); -// cout << "Calorimeter : branch CaloLevel1"<Branch("CaloLevel2","CaloLevel2", &calo2_clone); -// cout << "Calorimeter : branch CaloLevel2"<Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1")); + cout << "Calorimeter : branch CaloLevel1"<Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2")); + cout << "Calorimeter : branch CaloLevel2"<Branch("ToFLevel2","ToFLevel2", &tof_clone); -// cout << "ToF : branch ToFLevel2"<Branch("TrigLevel2","TrigLevel2", &trig_clone); -// cout << "Trigger : branch TrigLevel2"<Branch("S4Level2","S4Level2", &s4_clone); -// cout << "S4 : branch S4Level2"<Branch("NDLevel2","NDLevel2", &nd_clone); -// cout << "NeutronD : branch NDLevel2"<Branch("AcLevel2","AcLevel2", &ac_clone); -// cout << "Anticounter : branch AcLevel2"<Branch("OrbitalInfo","OrbitalInfo", &orb_clone); -// cout << "OrbitalInfo : branch OrbitalInfo"<Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2")); + cout << "ToF : branch ToFLevel2"<Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2")); + cout << "Trigger : branch TrigLevel2"<Branch("S4Level2","S4Level2", GetPointerTo("S4Level2")); + cout << "S4 : branch S4Level2"<Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2")); + cout << "NeutronD : branch NDLevel2"<Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2")); + cout << "Anticounter : branch AcLevel2"<Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo")); + cout << "OrbitalInfo : branch OrbitalInfo"<Branch("GPamela","GPamela", GetPointerTo("GPamela"),32000,1);//split + cout << "OrbitalInfo : branch OrbitalInfo"<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; - -// if(T_clone)T_clone->Fill(); -// if(C_clone)C_clone->Fill(); -// if(O_clone)O_clone->Fill(); -// if(R_clone)R_clone->Fill(); -// if(S_clone)S_clone->Fill(); -// if(N_clone)N_clone->Fill(); -// if(A_clone)A_clone->Fill(); -// if(O_clone)O_clone->Fill(); + +// cout << "PamLevel2::FillCloneTrees()" << irunentry << endl; - for(Int_t i=0; i<8; i++){ - if(tree_clone[i])tree_clone[i]->Fill(); + 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()<GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries()) + run_tree_clone->GetBranch("DeadLiveTime")->Fill(); + run_tree_clone->Write(); + cout << sel_tree_clone->GetName()<Write(); + for(Int_t i=0; iGetName()<Write(); }; } cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <GetEntry(ii) ){ + cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<P0 "<P0<Fill(); + +// cout << "PamLevel2::GetEntry("<NEVENTS<< endl; + +// if( TRK0 || CAL0 || TOF0 ){ +// if( !GetYodaEntry( ) ){ +// cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<ID_ROOT_L0; +// cout << "iroot "<IsConnected()))SetDBConnection(); + GL_ROOT glroot = GL_ROOT(); + if( glroot.Query_GL_ROOT(iroot,dbc) ){ + cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<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 "<Close(); + + + }; + +// if(!dbc || (dbc && !dbc->IsConnected())){ +// cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<IsConnected()))SetDBConnection(); + TrkParams::SetCalib(run_obj,dbc); + TrkParams::LoadCalib( ); + if( !TrkParams::CalibIsLoaded() ){ + cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<EV_FROM); +// cout << " irunentry "<EV_FROM<EV_FROM "<EV_FROM <<" quella giusta "<ID_ROOT_L0 "<ID_ROOT_L0<TRK_CALIB_USED<< endl; + + ULong64_t obt = 0; + ULong64_t pktn = 0; + if( GetOrbitalInfo() ){ + obt = GetOrbitalInfo()->OBT; + pktn = GetOrbitalInfo()->pkt_num; + } + + if( !GetOrbitalInfo() && !ISGP){ + cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<0){ + cout << " PKTNUM L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<ID << " ID_ROOT_L0 "<ID_ROOT_L0<<" ID_RUN_FRAG "<ID_RUN_FRAG << " EV_FROM "<EV_FROM < L0 mismatch ( irun "<GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift); + shift++; + if( !GetEventHeader() ){ + cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO + pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO + } + +// cout << "PKTNUM "<GetPscuHeader()->GetCounter()<GetPscuHeader()->GetOrbitalTime()<GetEntries()+1 )cout << ">>> end of level0 tree <<<"<GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl; +// cout << " pktn "<< pktn << endl; +// cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl; +// printf(" IDRUN %u \n",GetRunInfo()->ID); +// + if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){ + prevshift = 0; + shift = -1; + }; + + }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || + pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) ) + && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift); + + if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) { + cout << " Big trouble here, no such event in Level0 data! " <GetEntry(quellagiusta); + if ( shift > 1 ) prevshift += (shift-1); + return answer; -// 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"); -// } +} +/** + * \Brief Set DB connection + */ +Bool_t PamLevel2::SetDBConnection(){ -// // 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 << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <IsConnected() )return false; + stringstream myquery; // EMILIANO + myquery.str(""); // EMILIANO + myquery << "SET time_zone='+0:00'"; // EMILIANO + dbc->Query(myquery.str().c_str()); // EMILIANO + cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<SetDirectory(0); +} -// return Tout; -// } -// /** -// * Fill a tree (created with GetNewPamTree) -// * -// */ -// //void PamLevel2::FillNewPamTree(TTree *T){ -// void PamLevel2::FillNewPamTree(){ - +/** + * \Brief Add a friend to the pamela chain. + * @param cname name of the chain to be added + */ + +TChain* PamLevel2::AddFriend(TString cname){ + + if(!GetPamTree()){ + cout << " TChain* PamLevel2::AddFriend(TString cname) --- a pamela tree must be created first"<GetListOfFiles() ); + Int_t nf = 0; + TChainElement* element = 0; + while ((element = (TChainElement*) next())) { + c->Add(element->GetTitle()); + nf++; + } + + GetPamTree()->AddFriend(cname.Data()); + + cout << "external chain created and added to pamela friends :"<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 -// } -// }