--- PamelaLevel2/src/PamLevel2.cpp 2006/10/09 08:57:42 1.5 +++ PamelaLevel2/src/PamLevel2.cpp 2007/03/21 09:07:32 1.33 @@ -7,9 +7,10 @@ * 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; }; //-------------------------------------- // @@ -19,14 +20,66 @@ * 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; + } +} +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(); + } +} //-------------------------------------- // // @@ -36,75 +89,185 @@ */ PamLevel2::PamLevel2(){ - trk_l1_obj = this->TrkLevel1::GetTrkLevel1(); - trk_obj = this->TrkLevel2::GetTrkLevel2(); - calo_obj = this->CaloLevel2::GetCaloLevel2(); - tof_obj = this->ToFLevel2::GetToFLevel2(); - trig_obj = this->TrigLevel2::GetTrigLevel2(); - s4_obj = this->S4Level2::GetS4Level2(); - nd_obj = this->NDLevel2::GetNDLevel2(); - ac_obj = this->AcLevel2::GetAcLevel2(); - orb_obj = this->OrbitalInfo::GetOrbitalInfo(); +// 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(); + + 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; + + 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; - run_obj = new GL_RUN(); - - sorted_tracks = new TRefArray(); + prevshift = 0; + + 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; - CAL = true; - TRK = true; - TRG = true; - TOF = true; - S4 = true; - ND = true; - AC = true; - ORB = true; + + +// sorted_tracks = 0;//new TRefArray(); + + CAL0 = false; + CAL1 = true; + CAL2 = true; + TRK2 = true; + TRK1 = false; + TRKh = false; + TRKh = false; + TRG = true; + TOF = true; + TOF0 = false; + S4 = true; + ND = true; + AC = true; + ORB = true; + + RUN = true; - TRK_L1 = false; + SELLI = -1; + + tsorted=0; + timage=0; - Tout = NULL; }; /** - * Destructor + * Delete the event (act as Dtor) */ -PamLevel2::~PamLevel2(){ - - TrkLevel1::Clear(); - - TrkLevel2::Clear(); - CaloLevel2::Clear(); - ToFLevel2::Clear(); - TrigLevel2::Clear(); - S4Level2::Clear(); - NDLevel2::Clear(); - AcLevel2::Clear(); - OrbitalInfo::Clear(); - - delete run_obj; - -// delete sorted_tracks; - sorted_tracks->Delete(); // clean the reference array - - if(Tout)Tout->Delete(); // delete loaded tree from memory +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(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(); - - 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(calo0_obj) calo0_obj->Clear(); + if(trk1_obj) trk1_obj->Clear(); + if(trk2_obj) trk2_obj->Clear(); + if(trkh_obj) trkh_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(sorted_tracks)sorted_tracks->Clear(); +// sorted_tracks.Clear(); + + if(tsorted){ + tsorted->Delete(); + } + if(timage){ + timage->Delete(); + } + }; @@ -112,31 +275,104 @@ // // //-------------------------------------- +void *PamLevel2::GetPointerTo(const char* c ){ + + TString objname = c; + + 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("RunInfo"))return &run_obj; + + if(!objname.CompareTo("SoftInfo"))return &soft_obj; // Emiliano + + return NULL; +}; +//-------------------------------------- +// +// +//-------------------------------------- /** * Retrieves the calorimeter track matching the seqno-th tracker stored track. * (If seqno = -1 retrieves the self-trigger calorimeter track) */ CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){ - - if( CaloLevel2::ntrk()==0 ){ - cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<trkseqno && it_calo < CaloLevel2::ntrk()); - - if(seqno != c->trkseqno){ - c = 0; - if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<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 < calo2_obj->CaloLevel2::ntrk()); + + if(!c || seqno != c->trkseqno){ + c = 0; + if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<trkseqno && it_tof < ToFLevel2::ntrk()); - - if(seqno != c->trkseqno){ - c = 0; - if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<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 < tof_obj->ToFLevel2::ntrk()); + + if(!c || seqno != c->trkseqno){ + c = 0; + if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<GetSeqNo()); - if(TOF) o = GetToFStoredTrack(t->GetSeqNo()); - + + cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<GetSeqNo()); + if(TOF) o = GetToFStoredTrack(t->GetSeqNo()); + // if(t && c && o)track = new PamTrack(t,c,o); - PamTrack *track = new PamTrack(t,c,o); - - return track; + PamTrack *track = new PamTrack(t,c,o); + + return track; }; //-------------------------------------- @@ -202,19 +443,24 @@ PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){ - PamTrack *track = 0; - - if( itrk >=0 && itrk < TrkLevel2::ntrk() ){ - - TrkTrack *t = TrkLevel2::GetStoredTrack(itrk); - track = GetPamTrackAlong(t); + cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<=0 && itrk < trk2_obj->TrkLevel2::ntrk() ){ + + 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??? - + Int_t ObjectNumber = TProcessID::GetObjectCount(); + +// 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; + + // 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( !CAL && use_CAL) use_CAL = false; - if( !TOF && use_TOF) use_TOF = false; + 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 << "use_CAL "<TrkLevel2::GetNTracks(); i++){ - if( !TRK ){ - cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl; - return; - }; + TrkTrack *ts = 0; + CaloTrkVar *cs = 0; + ToFTrkVar *os = 0; - for(Int_t i=0; i < TrkLevel2::GetNTracks(); i++){ - - TrkTrack *ts = 0; - // get tracker tracks - TrkTrack *tp = TrkLevel2::GetTrack(i); //tracker -// CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo()); -// ToFTrkVar *op = GetToFStoredTrack(tp->GetSeqNo()); - CaloTrkVar *cp = 0; - ToFTrkVar *op = 0; - + 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()){ - - TrkTrack *ti = TrkLevel2::GetTrackImage(i); //tracker (image) -// CaloTrkVar *ci = GetCaloStoredTrack(ti->GetSeqNo()); -// ToFTrkVar *oi = GetToFStoredTrack(ti->GetSeqNo()); - CaloTrkVar *ci = 0; - ToFTrkVar *oi = 0; + if(tp->HasImage()){ + + 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){ - - cp = GetCaloStoredTrack(tp->GetSeqNo()); - ci = GetCaloStoredTrack(ti->GetSeqNo()); - - Float_t resy_p = cp->tbar[0][1] - cbar[0][1]; if(resy_p < 0)resy_p= - resy_p; - Float_t resy_i = ci->tbar[0][1] - cbar[0][1]; if(resy_i < 0)resy_i= - resy_i; - - if(resy_p <= resy_i) tp_score++; - else ti_score++; - }; + // 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(TString how): how= "<npcfit[1] > 15 && //no. of fit planes on Y view + calo2_obj->varcfit[1] < 1000. && //fit variance on Y view + cp && ci && + true){ + + + 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++; + +// cout << "CALO "<GetSeqNo()); - oi = GetToFStoredTrack(ti->GetSeqNo()); - + // check the number of hit pmts along the track + // on S12 S21 and S32, where paddles are parallel to Y axis + if( use_TOF && !tof_obj ){ + cout << "void PamLevel2::SortTracks(TString how): how= "<npmtadc << endl; cout << "track: npmttdc "<< op->npmttdc << endl; cout << "image: npmtadc "<< oi->npmtadc << endl; cout << "image: npmttdc "<< oi->npmttdc << endl;*/ - - for (Int_t ih=0; ih < op->npmtadc; ih++){ - Int_t pl = GetPlaneIndex( (op->pmtadc).At(ih) ); - if(pl == 1 || pl == 2 || pl == 5)nphit_p++; - }; - - for (Int_t ih=0; ih < oi->npmtadc; ih++){ - Int_t pl = GetPlaneIndex( (oi->pmtadc).At(ih) ); - if(pl == 1 || pl == 2 || pl == 5)nphit_i++; - }; - - if( - use_TOF && - (nphit_p+nphit_i) !=0 && - true){ - - if( nphit_p >= nphit_i) tp_score++; - else ti_score++; - }; - }; - if(tp_score == ti_score) use_TRK = true; - // ------------------------ + + 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 < oi->npmtadc; ih++){ + Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) ); + if(pl == 1 || pl == 2 || pl == 5)nphit_i++; + }; + + if( + use_TOF && + (nphit_p+nphit_i) !=0 && + true){ + + if( nphit_p >= nphit_i) tp_score++; + else ti_score++; + }; +// cout << "TOF "<chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ; - else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ; - }; - + // chi**2 difference is not always large enough to distinguish among + // the real track and its image. + // Tracker check will be applied always when calorimeter and tof information is ambiguous. + if(use_TRK){ + if( tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ; + else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ; +// 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; - }; + if (tp_score > ti_score) { +// ts = tp;//the track sorted by the tracker!! +// cs = cp; +// os = op; + }else if (tp_score < ti_score) { + ts = ti;//its image!! + cs = ci; + os = oi; + + ti = tp;//its image!! + ci = cp; + oi = op; + + tp = ts;//its image!! + cp = cs; + op = os; - }else{ - ts = tp; - }; - -// cout <<" SortTracks() "<Add(ts);//save the track in the sorted array -// cout << "SortTracks:: sorted_tracks->Add(it) "<GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl; + }; + + }else{ +// ts = tp; +// cs = cp; +// os = op; }; - //Restore Object count - //To save space in the table keeping track of all referenced objects - //we assume that our events do not address each other. We reset the - //object count to what it was at the beginning of the event. - TProcessID::SetObjectCount(ObjectNumber); + +// cout <<" SortTracks() "<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) "<GetEntries() != trk2_obj->GetNTracks() ){ + cout << "void PamLevel2::SortTracks(TString how): 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); + }; //-------------------------------------- // @@ -379,12 +691,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(){ - // -// SortTracks("+CAL+TOF"); - SortTracks("+CAL+TRK");//TEMP!!!!!!!!!!!!! - // - return sorted_tracks; +// TRefArray *PamLevel2::GetTracks(){ + +// // *-*-*-*-*-*-*-*-*-*-*-*-* +// SortTracks("+CAL+TOF"); +// // *-*-*-*-*-*-*-*-*-*-*-*-* + +// // return sorted_tracks; +// return &sorted_tracks; + +// }; +TClonesArray *PamLevel2::GetTracks(){ + +// *-*-*-*-*-*-*-*-*-*-*-*-* + SortTracks("+CAL+TOF"); +// *-*-*-*-*-*-*-*-*-*-*-*-* + + return tsorted; + }; //-------------------------------------- // @@ -396,24 +720,47 @@ * @param it Track number, ranging from 0 to GetNTracks(). */ PamTrack *PamLevel2::GetTrack(int it){ + +// if(!trk2_obj) return 0; -// *-*-*-*-*-*-* -// SortTracks("+CAL+TOF"); - SortTracks("+CAL+TRK");//TEMP!!!!!!!!!!!!! -// *-*-*-*-*-*-* - - PamTrack *track = 0; - - if( it >=0 && it < TrkLevel2::GetNTracks() ){ - TrkTrack *t = (TrkTrack*)sorted_tracks->At(it); -// cout << "GetTrack(int it):: sorted_tracks->At(it) "<=0 && it < trk2_obj->TrkLevel2::GetNTracks() && itGetEntries())return 0; + PamTrack *track = 0; + + 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() = "<TrkLevel2::GetNTracks()<<")"<=0 && it < TrkLevel2::GetNTracks() ){ - TrkTrack *temp = (TrkTrack*)sorted_tracks->At(it); - if( temp->HasImage() ){ - TrkTrack *t = TrkLevel2::GetStoredTrack(temp->GetImageSeqNo()); - image = GetPamTrackAlong(t); - }else{ - cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<=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 < 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) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<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 "; + cout << endl; + if(SELLI)cout<<">>> Found selection-list <<<"<cd(); -// cout << "WARNING!!! -- obsolete method -- \n"; -// cout << "better use TChain *PamLevel2::GetPamTree(TList*, TString) \n"; - - TTree *Trout =0; - - SetWhichTrees(detlist); // Tracker TTree *T = (TTree*)f->Get("Tracker"); - if(T && TRK) { - if(TRK_L1){ - T->SetBranchAddress("TrkLevel1", GetPointerToTrk(1)); - cout << "Tracker : set branch address TrkLevel1"<SetBranchAddress("TrkLevel2", GetPointerToTrk(2)); - cout << "Tracker : set branch address TrkLevel2"<SetBranchAddress("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); }else{ cout << "Tracker : missing tree"<Get("Calorimeter"); - if(C && CAL) { - C->SetBranchAddress("CaloLevel2", GetPointerToCalo()); - cout << "Calorimeter : set branch address CaloLevel2"<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) { - O->SetBranchAddress("ToFLevel2", GetPointerToToF()); + O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2")); cout << "ToF : set branch address ToFLevel2"<AddFriend(O); @@ -500,7 +910,7 @@ // Trigger TTree *R = (TTree*)f->Get("Trigger"); if(R && TRG) { - R->SetBranchAddress("TrigLevel2", GetPointerToTrig()); + R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2")); cout << "Trigger : set branch address TrigLevel2"<AddFriend(R); @@ -510,7 +920,7 @@ // S4 TTree *S = (TTree*)f->Get("S4"); if(S && S4) { - S->SetBranchAddress("S4Level2", GetPointerToS4()); + S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2")); cout << "S4 : set branch address S4Level2"<AddFriend(S); @@ -520,7 +930,7 @@ // Neutron Detector TTree *N = (TTree*)f->Get("NeutronD"); if(N && ND) { - N->SetBranchAddress("NDLevel2", GetPointerToND()); + N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2")); cout << "NeutronD : set branch address NDLevel2"<AddFriend(N); @@ -530,7 +940,7 @@ // Anticounters TTree *A = (TTree*)f->Get("Anticounter"); if(A && AC) { - A->SetBranchAddress("AcLevel2", GetPointerToAc()); + A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2")); cout << "Anticounter : set branch address AcLevel2"<AddFriend(A); @@ -538,19 +948,35 @@ cout << "Anticounter : missing tree"<Get("OrbitalInfo"); - if(B && ORB) { - B->SetBranchAddress("OrbitalInfo", GetPointerToOrb()); - cout << "OrbitalInfo : set branch address OrbitalInfo"<AddFriend(B); - }else{ - cout << "OrbitalInfo : missing tree"<Get("OrbitalInfo"); + if(B && ORB) { + B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo")); + cout << "OrbitalInfo : set branch address OrbitalInfo"<AddFriend(B); + }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()<GetEntries()<WorkingDirectory(); - - if(ddir=="")ddir = wdir; + TString wdir = gSystem->WorkingDirectory(); + + if(ddir=="")ddir = wdir; // TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir); - cout << "Level2 data directory : "<< ddir << endl; - - TList *contents = new TList; // create output list - contents->SetOwner(); + cout << "Level2 data directory : "<< ddir << endl; + + TList *contents = new TList; // create output list + contents->SetOwner(); + +// char *fullpath; +// const char *fullpath; + + // if no input file list is given: + if ( flisttxt != "" ){ - 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 : "<> file; - if (!in.good()) break; - if( gSystem->IsFileInIncludePath(file,&fullpath) ){ -// contents->Add(new TSystemDirectory(fullpath,ddir)); // add file to the list -// contents->Add(new TSystemFile(fullpath,ddir)); // add file to the list - contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list - }else{ - cout << "warning! --- File "<ChangeDirectory(wdir); // back to the working directory + return 0; + } + int line=0; + while (1) { + TString file; + in >> file; + if (!in.good()) break; + line++; +// cout <<"(1) " << file << endl; + if(file.IsNull()){ + cout << "-- list interrupted at line "<IsFileInIncludePath(file,&fullpath) ){ +// 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 + 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."<WorkingDirectory()<< endl; - - TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir); - TList *temp = datadir->GetListOfFiles(); + + TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir); + TList *temp = datadir->GetListOfFiles(); // temp->Print(); // cout << "*************************************" << endl; - - TIter next(temp); - TSystemFile *questo = 0; - - - while ( (questo = (TSystemFile*) next()) ) { - TString name = questo-> GetName(); - if( name.EndsWith(".root") ){ - char *fullpath; - gSystem->IsFileInIncludePath(name,&fullpath); - contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath))); - }; - } - delete temp; - delete datadir; - }; - gSystem->ChangeDirectory(wdir); // back to the working directory + TIter next(temp); + TSystemFile *questo = 0; + + + while ( (questo = (TSystemFile*) next()) ) { + TString name = questo-> GetName(); + if( name.EndsWith(".root") ){ +// 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; + delete datadir; + + }; + 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; + return contents; }; //-------------------------------------- // @@ -649,96 +1108,179 @@ * @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 ){ + + TChain *Trout =0; -// TChain *Tout=0; - if(Tout)Tout->Delete(); - Tout = NULL; - - SetWhichTrees(detlist); - - TChain *T = 0; - TChain *C = 0; - TChain *O = 0; - TChain *R = 0; - TChain *S = 0; - TChain *N = 0; - TChain *A = 0; - TChain *B = 0; - - if(TRK) T = new TChain("Tracker"); - if(CAL) C = new TChain("Calorimeter"); - if(TOF) O = new TChain("ToF"); - if(TRG) R = new TChain("Trigger"); - if(S4) S = new TChain("S4"); - if(ND) N = new TChain("NeutronD"); - if(AC) A = new TChain("Anticounter"); - if(ORB) B = new TChain("OrbitalInfo"); - - // loop over files and create chains - TIter next(fl); - TSystemFile *questo = 0; - while ( (questo = (TSystemFile*) next()) ) { - TString name = questo->GetName(); -// cout << "File: "<< name << endl; - if( CheckLevel2File(name) ){ - if(TRK) T->Add(name); - if(CAL) C->Add(name); - if(TOF) O->Add(name); - if(TRG) R->Add(name); - if(S4) S->Add(name); - if(ND) N->Add(name); - if(AC) A->Add(name); - if(ORB) B->Add(name); - }; - } - - // Tracker - if(TRK) if(!Tout)Tout=T; - - // Calorimeter - if(CAL) { - if(!Tout)Tout=C; - else Tout->AddFriend("Calorimeter"); +// if( !detlist.IsNull() )SetWhichTrees(detlist); + SetWhichTrees(detlist); + + cout<< "GetPamTree(TList*,TString): input 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 "; + cout << endl; + + 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 *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"); + + 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; + 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(SELLI==1) L->Add(name); }; - + } + + cout << "done chain \n"; + +// UInt_t *found=0; +// 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("Tracker"); + }else{ + cout << "Tracker : missing tree"<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("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("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"); - }; - // OrbitalInfo - if(ORB) { - if(!Tout)Tout=O; - else Tout->AddFriend("OrbitalInfo"); - }; - - cout<GetEntries()<SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2")); + cout << "Anticounter : set branch address AcLevel2"<AddFriend("Anticounter"); + }else{ + cout << "Anticounter : missing tree"<SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo")); + cout << "OrbitalInfo : set branch address OrbitalInfo"<AddFriend("OrbitalInfo"); + }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()<GetBranchStatus("TrkLevel2"); + TRK1 = TRK1 & t->GetBranchStatus("TrkLevel1"); + TRKh = TRKh & t->GetBranchStatus("TrkHough"); + CAL2 = CAL2 & t->GetBranchStatus("CaloLevel2"); + CAL1 = CAL1 & t->GetBranchStatus("CaloLevel1"); + 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"); + + // Tracker - if(TRK) { - if(TRK_L1){ - Tout->SetBranchAddress("TrkLevel1", GetPointerToTrk(1)); - cout << "Tracker : set branch address TrkLevel1"<SetBranchAddress("TrkLevel2", GetPointerToTrk(2)); - cout << "Tracker : set branch address TrkLevel2"<SetBranchAddress("CaloLevel2", GetPointerToCalo()); - cout << "Calorimeter : set branch address CaloLevel2"<SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel2")); + cout << "Tracker : set branch address TrkLevel1"<SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1")); + cout << "Tracker : set branch address TrkLevel2"<SetBranchAddress("TrkHough", GetPointerTo("TrkHough")); + cout << "Tracker : set branch address TrkHough"<SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1")); + cout << "Calorimeter : set branch address CaloLevel1"<SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2")); + cout << "Calorimeter : set branch address CaloLevel2"<SetBranchAddress("ToFLevel2", GetPointerToToF()); - cout << "ToF : set branch address ToFLevel2"<SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2")); + cout << "ToF : set branch address ToFLevel2"<SetBranchAddress("TrigLevel2", GetPointerToTrig()); - cout << "Trigger : set branch address TrigLevel2"<SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2")); + cout << "Trigger : set branch address TrigLevel2"<SetBranchAddress("S4Level2", GetPointerToS4()); - cout << "S4 : set branch address S4Level2"<SetBranchAddress("S4Level2", GetPointerTo("S4Level2")); + cout << "S4 : set branch address S4Level2"<SetBranchAddress("NDLevel2", GetPointerToND()); - cout << "NeutronD : set branch address NDLevel2"<SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2")); + cout << "NeutronD : set branch address NDLevel2"<SetBranchAddress("AcLevel2", GetPointerToAc()); - cout << "Anticounter : set branch address AcLevel2"<SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2")); + cout << "Anticounter : set branch address AcLevel2"<SetBranchAddress("OrbitalInfo", GetPointerToOrb()); - cout << "OrbitalInfo : set branch address OrbitalInfo"<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"<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"); + + // Tracker + if(TRK2) { + t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2")); + cout << "Tracker : set branch address TrkLevel2"<SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1")); + cout << "Tracker : set branch address TrkLevel1"<SetBranchAddress("TrkHough", GetPointerTo("TrkHough")); + cout << "Tracker : set branch address TrkHough"<SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2")); + cout << "Calorimeter : set branch address CaloLevel2"<SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1")); + cout << "Calorimeter : set branch address CaloLevel1"<SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2")); + cout << "ToF : set branch address ToFLevel2"<SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2")); + cout << "Trigger : set branch address TrigLevel2"<SetBranchAddress("S4Level2", GetPointerTo("S4Level2")); + cout << "S4 : set branch address S4Level2"<SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2")); + cout << "NeutronD : set branch address NDLevel2"<SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2")); + cout << "Anticounter : set branch address AcLevel2"<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"<GetName(); + TChain *R = new TChain("Run"); + + // loop over files and create chains + TIter next(fl); + TSystemFile *questo = 0; + while ( (questo = (TSystemFile*) next()) ) { + TString name = questo->GetName(); // cout << "File: "<< name << endl; - if( CheckLevel2File(name) ){ - R->Add(name); - }; - } - - R->SetBranchAddress("RunInfo", GetPointerToRun()); - cout << "Run : set branch address RunInfo"<Add(name); + }; + } + + if(R->GetNtrees()){ - return R; + R->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", GetPointerToRun()); - cout << "Run : set branch address RunInfo"<Get("Run"); - return R; + if(R){ + R->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){ + + if( !GetOrbitalInfo() ){ + cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<GetEntry(irun); + runfirstentry = 0LL; + runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS); + if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL; +// cout << " ))))) UPDATE RUN INFO ((((( @iev "<ID<<" irun "<absTime >= GetRunInfo()->RUNHEADER_TIME && GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1 ){ +// 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",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 (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 ( !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); + 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); + 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"<GetEntry(irun); +// runfirstentry = iev; +// if( iev != 0){ +// cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- WARNING -- "<absTime >= GetRunInfo()->RUNHEADER_TIME && GetOrbitalInfo()->absTime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries() ){ +// irun++; +// if( irun == run->GetEntries() ){ +// if(!fromfirst){ +// cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- event entry #"<GetEntry(irun); +// runfirstentry = iev; +// }; +// // +// if ( irun == oldrun ) return(false); +// // +// cout << " ))))) UPDATE RUN INFO ((((( @iev "<ID<<" irun "<GetEntry(iev); +// if(irun != oldrun){ +// run->GetEntry(irun); +// cout << " ))))) UPDATE RUN INFO ((((( @iev "<ID<<" irun "< "; +// 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 "; +// 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(); + }; + + }; + + delete lk; + +// cout<< "Get detector list from input file --> "; +// 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 "; +// cout << endl; + + return ; }; + + //-------------------------------------- // // @@ -929,93 +1998,736 @@ */ Bool_t PamLevel2::CheckLevel2File(TString name){ - Bool_t CAL__ok = false; - Bool_t TRK__ok = false; - Bool_t TRK_L1__ok = false; - Bool_t TRG__ok = false; - Bool_t TOF__ok = false; - Bool_t S4__ok = false; - Bool_t ND__ok = false; - Bool_t AC__ok = false; - Bool_t ORB__ok = false; - - Bool_t RUN__ok = false; - - TFile *f = new TFile(name.Data()); - TList *lk = f->GetListOfKeys(); -// lk->Print(); - TIter next(lk); - TKey *key =0; - while( (key = (TKey*)next()) ){ -// cout << key->GetName() << endl; - if( !strcmp(key->GetName(),"Calorimeter") )CAL__ok = true; -// if( !strcmp(key->GetName(),"Tracker" ) )TRK__ok = true; - if( !strcmp(key->GetName(),"Trigger" ) )TRG__ok = true; - if( !strcmp(key->GetName(),"ToF" ) )TOF__ok = true; - if( !strcmp(key->GetName(),"S4" ) )S4__ok = true; - if( !strcmp(key->GetName(),"NeutronD" ) )ND__ok = true; - if( !strcmp(key->GetName(),"Anticounter") )AC__ok = true; - if( !strcmp(key->GetName(),"OrbitalInfo") )ORB__ok = true; - if( !strcmp(key->GetName(),"Run" ) )RUN__ok = true; - - if( !strcmp(key->GetName(),"Tracker" ) ){ - TRK__ok = true; - TTree *T = (TTree*)f->Get("Tracker"); - for(Int_t i=0; iGetListOfBranches()->GetEntries(); i++){ - TString name = T->GetListOfBranches()->At(i)->GetName(); - if( !name.CompareTo("TrkLevel1") )TRK_L1__ok=true; - }; - }; + Bool_t CAL1__ok = false; + Bool_t CAL2__ok = false; + Bool_t TRK2__ok = false; + Bool_t TRK1__ok = false; + Bool_t TRKh__ok = false; + Bool_t TRG__ok = false; + Bool_t TOF__ok = false; + Bool_t S4__ok = false; + Bool_t ND__ok = false; + Bool_t AC__ok = false; + Bool_t ORB__ok = false; + + Bool_t RUN__ok = false; + + Bool_t SELLI__ok = false; - }; - - lk->Delete(); - f->Close(); + cout << "Checking file: "<IsZombie() ){ + cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false; + } +// cout << "Get list of keys: "<GetListOfKeys(); +// lk->Print(); + TIter next(lk); + TKey *key =0; + + Int_t nev = 0; + + while( (key = (TKey*)next()) ){ + +// cout << key->GetName() << endl; +// cout << key->GetName() << ""<GetClassName()<Get(key->GetName())<GetClassName()=="TTree" && nev_previous && nev != nev_previous ){ +// nev = ((TTree*)f->Get(key->GetName()))->GetEntries(); +// cout << "File: "<< f->GetName() <<" discarded ---- "<< key->GetName() << " tree: n.entries does not match "<GetName(),"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){ + Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<" discarded ---- Trigger tree has "<GetName(),"ToF" ) ){ + TOF__ok = true; + if(TOF){ + Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<" discarded ---- ToF tree has "<GetName(),"S4" ) ){ + S4__ok = true; + if(S4){ + Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<" discarded ---- S4 tree has "<GetName(),"NeutronD" ) ){ + ND__ok = true; + if(ND){ + Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<" discarded ---- NeutronD tree has "<GetName(),"Anticounter") ){ + AC__ok = true; + if(AC){ + Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<" discarded ---- Anticounter tree has "<GetName(),"OrbitalInfo") ){ + ORB__ok = true; + if(ORB){ + Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<GetName(),"Tracker" ) ){ + TTree *T = (TTree*)f->Get("Tracker"); + if(TRK1||TRK2||TRKh){ + Int_t nevt = T->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<" discarded ---- Tracker tree has "<GetListOfBranches()->GetEntries(); i++){ + TString name = T->GetListOfBranches()->At(i)->GetName(); + if( !name.CompareTo("TrkLevel1") )TRK1__ok=true; + if( !name.CompareTo("TrkLevel2") )TRK2__ok=true; + if( !name.CompareTo("TrkHough") )TRKh__ok=true; + }; + T->Delete(); + }; + //========================================================= + if( !strcmp(key->GetName(),"Calorimeter" ) ){ + TTree *T = (TTree*)f->Get("Calorimeter"); + if(CAL1||CAL2){ + Int_t nevt = T->GetEntries(); + if( nev && nevt!=nev){ + cout << "File: "<< f->GetName() <<" discarded ---- Calorimeter tree has "<GetListOfBranches()->GetEntries(); i++){ + TString name = T->GetListOfBranches()->At(i)->GetName(); + if( !name.CompareTo("CaloLevel1") )CAL1__ok=true; + if( !name.CompareTo("CaloLevel2") )CAL2__ok=true; + }; + T->Delete(); + }; + + }; + + 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 "; +// 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) { + cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree"<< endl; +// return false; + }; + + if(CAL1 && !CAL1__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel1 branch"<< endl; + return false; + }; + if(CAL2 && !CAL2__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel2 branch"<< endl; + return false; + }; + if(TRK2 && !TRK2__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel2 branch"<< endl; + return false; + }; + if(TRK1 && !TRK1__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel1 branch"<< endl; + return false; + }; + if(TRKh && !TRKh__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkHough branch"<< endl; + return false; + }; + if(ORB && !ORB__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing ORB tree"<< endl; + return false; + }; + if(AC && !AC__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing AC tree"<< endl; + return false; + }; + if(S4 && !S4__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing S4 tree"<< endl; + return false; + }; + if(TOF && !TOF__ok){ + cout << "File: "<< f->GetName() <<" discarded ---- Missing ToF 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; + }; + + +// 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 "; +// cout << endl; + + return true; - Bool_t FLAG = true; - if(!RUN__ok) { - cout << "File: "<< f->GetName() <<" discarded ---- Missing RunInfo tree"<< endl; - FLAG = false; - }; - if(CAL && !CAL__ok){ - cout << "File: "<< f->GetName() <<" discarded ---- Missing Calorimeter tree"<< endl; - FLAG = false; - }; - if(TRK && !TRK__ok){ - cout << "File: "<< f->GetName() <<" discarded ---- Missing Tracker tree"<< endl; - FLAG = false; - }; - if(TRK_L1 && !TRK_L1__ok){ - cout << "File: "<< f->GetName() <<" discarded ---- Missing Tracker Level1 Branch"<< endl; - FLAG = false; - }; - if(TRG && !TRG__ok){ - cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl; - FLAG = false; - }; - if(TOF && !TOF__ok){ - cout << "File: "<< f->GetName() <<" discarded ---- Missing ToF tree"<< endl; - FLAG = false; - }; - if(S4 && !S4__ok){ - cout << "File: "<< f->GetName() <<" discarded ---- Missing S4 tree"<< endl; - FLAG = false; +}; + + +/** + * Create clone-trees + */ +void PamLevel2::CreateCloneTrees0( TChain *fChain, TFile *ofile ){ + + cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <GetTree()->CloneTree(0); + TString name = pam_tree_clone[i]->GetName(); + name.Append("_clone"); +// pam_tree_clone[i]->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; + pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0); + pam_tree_clone[i]->SetAutoSave(1000000); + name = pam_tree_clone[i]->GetName(); + name.Append("_clone"); +// pam_tree_clone[i]->SetName(name.Data()); + cout << pam_tree_clone[i]->GetName() << endl; + i++; + } + + delete li; + + cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <cd(); + + 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){ + pam_tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data "); + if(TRK1) { + pam_tree_clone[i]->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"<GetName() <<" discarded ---- Missing ND tree"<< endl; - FLAG = false; + i++; + } + + // Calorimeter + if(CAL1||CAL2){ + pam_tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data "); + if(CAL1) { + pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1")); + cout << "Calorimeter : branch CaloLevel1"<Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2")); + cout << "Calorimeter : branch CaloLevel2"<GetName() <<" discarded ---- Missing AC tree"<< endl; - FLAG = false; + i++; + } + + // ToF + if(TOF) { + 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")); + 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"<Fill(); + } + if(sel_tree_clone)sel_tree_clone->Fill(); + +} + + +TTree* PamLevel2::GetCloneTree(TString name){ + + 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 << sel_tree_clone->GetName()<Write(); + for(Int_t i=0; iGetName()<Write(); }; - if(ORB && !ORB__ok){ - cout << "File: "<< f->GetName() <<" discarded ---- Missing ORB tree"<< endl; - FLAG = false; + } + cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <GetEntry(ii) ){ + cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<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); + + +// 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+(Long64_t)shift+(Long64_t)prevshift); + shift++; + if( !GetEventHeader() ){ + cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<pkt_num << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<OBT << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<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+(Long64_t)shift) == GetYodaTree()->GetEntries() ){ + prevshift = 0; + shift = -1; + }; + + }while( ( GetOrbitalInfo()->OBT != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || GetOrbitalInfo()->pkt_num != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() ); + + if ( (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ) cout << " Big trouble here, no such event in Level0 data! " <GetEntry(quellagiusta); + if ( shift > 1 ) prevshift += (shift-1); + + return answer; + +}