#include //-------------------------------------- // // //-------------------------------------- /** * Default constructor */ PamTrack::PamTrack(){ trk_track = this->TrkTrack::GetTrkTrack(); calo_track = this->CaloTrkVar::GetCaloTrkVar(); tof_track = this->ToFTrkVar::GetToFTrkVar(); }; //-------------------------------------- // // //-------------------------------------- /** * 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; }; //-------------------------------------- // // //-------------------------------------- /** * Constructor */ PamLevel2::PamLevel2(){ 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(); sorted_tracks = new TRefArray(); CAL = true; TRK = true; TRG = true; TOF = true; S4 = true; ND = true; AC = true; ORB = true; }; /** * Destructor */ PamLevel2::~PamLevel2(){ TrkLevel2::Clear(); CaloLevel2::Clear(); ToFLevel2::Clear(); TrigLevel2::Clear(); S4Level2::Clear(); NDLevel2::Clear(); AcLevel2::Clear(); OrbitalInfo::Clear(); delete sorted_tracks; }; /** * Clear the event */ void PamLevel2::Clear(){ sorted_tracks->Delete(); }; //-------------------------------------- // // //-------------------------------------- /** * 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){ CaloTrkVar *c = 0; Int_t it_calo=0; do{ c = CaloLevel2::GetCaloTrkVar(it_calo); it_calo++; } while( seqno != c->trkseqno && it_calo < CaloLevel2::ntrk()); if(seqno != c->trkseqno){ c = 0; if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<trkseqno && it_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"<GetSeqNo()); o = GetToFStoredTrack(t->GetSeqNo()); // if(t && c && o)track = new PamTrack(t,c,o); PamTrack *track = new PamTrack(t,c,o); return track; }; //-------------------------------------- // // //-------------------------------------- /** * Retrieves the it-th stored track. * It override TrkLevel2::GetTrack(int it). * @param itrk Track number, ranging from 0 to GetNTracks(). */ PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){ PamTrack *track = 0; if( itrk >=0 && itrk < TrkLevel2::ntrk() ){ TrkTrack *t = 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); 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()); // if track has an image, check image selection if(tp->HasImage()){ TrkTrack *ti = TrkLevel2::GetTrackImage(i); //tracker (image) CaloTrkVar *ci = GetCaloStoredTrack(ti->GetSeqNo()); ToFTrkVar *oi = GetToFStoredTrack(ti->GetSeqNo()); //assign starting scores Int_t tp_score = 0; //main track sorted by the tracker Int_t ti_score = 0; //image track // ------------------------ // calorimeter check // ------------------------ // check the Y spatial residual on the first calorimeter plane // (cut on calorimeter variables from Emiliano) if( use_CAL && npcfit[1] > 15 && //no. of fit planes on Y view varcfit[1] < 1000. && //fit variance on Y view true){ Float_t resy_p = cp->tbar[0][1] - cbar[0][1]; if(resy_p < 0)resy_p= - resy_p; Float_t resy_i = ci->tbar[0][1] - cbar[0][1]; if(resy_i < 0)resy_i= - resy_i; if(resy_p <= resy_i) tp_score++; else ti_score++; }; // ------------------------ // TOF check // ------------------------ // check the number of hit pmts along the track // on S12 S21 and S32, where paddles are parallel to Y axis Int_t nphit_p =0; Int_t nphit_i =0; for (Int_t ih=0; ih < op->npmtadc; ih++){ Int_t pl = GetPlaneIndex( (op->pmtadc).At(ih) ); if(pl == 1 || pl == 2 || pl == 5)nphit_p++; }; for (Int_t ih=0; ih < oi->npmtadc; ih++){ Int_t pl = GetPlaneIndex( (oi->pmtadc).At(ih) ); if(pl == 1 || pl == 2 || pl == 5)nphit_i++; }; if( use_TOF && (nphit_p+nphit_i) !=0 && true){ if( nphit_p >= nphit_i) tp_score++; else ti_score++; }; if(tp_score == ti_score) use_TRK = true; // ------------------------ // tracker check // ------------------------ // chi**2 difference is not always large enough to distinguish among // the real track and its image. // Tracker check will be applied always when calorimeter and tof information is ambiguous. if(use_TRK){ if( tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ; else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ; }; // ------------------------ // the winner is.... // ------------------------ if (tp_score > ti_score) ts = tp;//the track sorted by the tracker!! else if (tp_score < ti_score) ts = ti;//its image!! else { ts = tp; // cout << "Warning - track image ambiguity not solved" << endl; // cout << ts->GetNtot() << " "<< ts->chi2 << " " << npcfit[1] << " "<< nphit_p << endl; }; }else{ ts = tp; }; sorted_tracks->Add(ts);//save the track in the sorted array }; }; //-------------------------------------- // // //-------------------------------------- /** * 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"); return sorted_tracks; }; //-------------------------------------- // // //-------------------------------------- /** * Retrieves the it-th Pamela "physical" track. * It override TrkLevel2::GetTrack(int it). * @param it Track number, ranging from 0 to GetNTracks(). */ PamTrack *PamLevel2::GetTrack(int it){ // *-*-*-*-*-*-* SortTracks("+CAL+TOF"); // *-*-*-*-*-*-* PamTrack *track = 0; if( it >=0 && it < TrkLevel2::GetNTracks() ){ TrkTrack *t = (TrkTrack*)sorted_tracks->At(it); track = GetPamTrackAlong(t); }else{ cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (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 "<Get("Tracker"); if(T && TRK) { T->SetBranchAddress("TrkLevel2", GetPointerToTrk()); cout << "Tracker : set branch address TrkLevel2"<Get("Calorimeter"); if(C && CAL) { C->SetBranchAddress("CaloLevel2", GetPointerToCalo()); cout << "Calorimeter : set branch address CaloLevel2"<AddFriend(C); }else{ cout << "Calorimeter : missing tree"<Get("ToF"); if(O && TOF) { O->SetBranchAddress("ToFLevel2", GetPointerToToF()); cout << "ToF : set branch address ToFLevel2"<AddFriend(O); }else{ cout << "ToF : missing tree"<Get("Trigger"); if(R && TRG) { R->SetBranchAddress("TrigLevel2", GetPointerToTrig()); cout << "Trigger : set branch address TrigLevel2"<AddFriend(R); }else{ cout << "Trigger : missing tree"<Get("S4"); if(S && S4) { S->SetBranchAddress("S4Level2", GetPointerToS4()); cout << "S4 : set branch address S4Level2"<AddFriend(S); }else{ cout << "S4 : missing tree"<Get("NeutronD"); if(N && ND) { N->SetBranchAddress("NDLevel2", GetPointerToND()); cout << "NeutronD : set branch address NDLevel2"<AddFriend(N); }else{ cout << "NeutronD : missing tree"<Get("Anticounter"); if(A && AC) { A->SetBranchAddress("AcLevel2", GetPointerToAc()); cout << "Anticounter : set branch address AcLevel2"<AddFriend(A); }else{ cout << "Anticounter : missing tree"<Get("OrbitalInfo"); if(B && ORB) { B->SetBranchAddress("OrbitalInfo", GetPointerToOrb()); cout << "OrbitalInfo : set branch address OrbitalInfo"<AddFriend(B); }else{ cout << "OrbitalInfo : missing tree"<Get("Tracker"); if(T && TRK) { T->SetBranchAddress("TrkLevel2", GetPointerToTrk()); cout << "Tracker : set branch address TrkLevel2"<Get("Calorimeter"); if(C && CAL) { C->SetBranchAddress("CaloLevel2", GetPointerToCalo()); cout << "Calorimeter : set branch address CaloLevel2"<AddFriend(C); }else{ cout << "Calorimeter : missing tree"<Get("ToF"); if(O && TOF) { O->SetBranchAddress("ToFLevel2", GetPointerToToF()); cout << "ToF : set branch address ToFLevel2"<AddFriend(O); }else{ cout << "ToF : missing tree"<Get("Trigger"); if(R && TRG) { R->SetBranchAddress("TrigLevel2", GetPointerToTrig()); cout << "Trigger : set branch address TrigLevel2"<AddFriend(R); }else{ cout << "Trigger : missing tree"<Get("S4"); if(S && S4) { S->SetBranchAddress("S4Level2", GetPointerToS4()); cout << "S4 : set branch address S4Level2"<AddFriend(S); }else{ cout << "S4 : missing tree"<Get("NeutronD"); if(N && ND) { N->SetBranchAddress("NDLevel2", GetPointerToND()); cout << "NeutronD : set branch address NDLevel2"<AddFriend(N); }else{ cout << "NeutronD : missing tree"<Get("Anticounter"); if(A && AC) { A->SetBranchAddress("AcLevel2", GetPointerToAc()); cout << "Anticounter : set branch address AcLevel2"<AddFriend(A); }else{ cout << "Anticounter : missing tree"<Get("OrbitalInfo"); if(B && ORB) { B->SetBranchAddress("OrbitalInfo", GetPointerToOrb()); cout << "OrbitalInfo : set branch address OrbitalInfo"<AddFriend(B); }else{ cout << "OrbitalInfo : missing tree"<WorkingDirectory(); if(ddir=="")ddir = wdir; TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir); cout << "Level2 data directory : "<< endl << ddir << endl; TList *contents = new TList; // create output list contents->SetOwner(); // if no input file list is given: if ( flisttxt != "" ){ if( !gSystem->ChangeDirectory(ddir) )return 0; flisttxt = gSystem->ConcatFileName(wdir,gSystem->BaseName(flisttxt)); cout <<"Input file list : "<< endl << flisttxt <> file; if (!in.good()) break; char *fullpath; 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 "<WorkingDirectory()<< endl; 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; }; gSystem->ChangeDirectory(wdir); cout << endl << "Selected files:" << endl; contents->Print(); cout << endl; // cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl; return contents; }; //-------------------------------------- // // //-------------------------------------- /** * Get the Pamela detector chains from a list of files and make them friends. * @param fl Pointer to a TList of TSystemFiles * @param detlist String to select trees to be included * @return Pointer to a TChain */ TChain *PamLevel2::LoadPamTrees(TList *fl, TString detlist="+ALL"){ 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(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) { T->SetBranchAddress("TrkLevel2", GetPointerToTrk()); cout << "Tracker : set branch address TrkLevel2"<SetBranchAddress("CaloLevel2", GetPointerToCalo()); cout << "Calorimeter : set branch address CaloLevel2"<AddFriend("Calorimeter"); }; // ToF if(TOF) { O->SetBranchAddress("ToFLevel2", GetPointerToToF()); cout << "ToF : set branch address ToFLevel2"<AddFriend("ToF"); }; // Trigger if(TRG) { R->SetBranchAddress("TrigLevel2", GetPointerToTrig()); cout << "Trigger : set branch address TrigLevel2"<AddFriend("Trigger"); }; // S4 if(S4) { S->SetBranchAddress("S4Level2", GetPointerToS4()); cout << "S4 : set branch address S4Level2"<AddFriend("S4"); }; // Neutron Detector if(ND) { N->SetBranchAddress("NDLevel2", GetPointerToND()); cout << "NeutronD : set branch address NDLevel2"<AddFriend("NeutronD"); }; // Anticounters if(AC) { A->SetBranchAddress("AcLevel2", GetPointerToAc()); cout << "Anticounter : set branch address AcLevel2"<AddFriend("Anticounter"); }; // OrbitalInfo if(ORB) { B->SetBranchAddress("OrbitalInfo", GetPointerToOrb()); cout << "OrbitalInfo : set branch address OrbitalInfo"<AddFriend("OrbitalInfo"); }; return Tout; } //-------------------------------------- // // //-------------------------------------- /** * Set which trees should be analysed * @param detlist TString containing the sequence of trees required */ void PamLevel2::SetWhichTrees(TString detlist){ if(detlist.Contains("+ALL", TString::kIgnoreCase)){ CAL = true; TRK = true; TRG = true; TOF = true; S4 = true; ND = true; AC = true; ORB = true; }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){ CAL = false; TRK = false; TRG = false; TOF = false; S4 = false; ND = false; AC = false; ORB = false; }; if( detlist.Contains("-CAL", TString::kIgnoreCase) )CAL = false; else if( detlist.Contains("+CAL", TString::kIgnoreCase) )CAL = true; if( detlist.Contains("-TRK", TString::kIgnoreCase) )TRK = false; else if( detlist.Contains("+TRK", TString::kIgnoreCase) )TRK = true; if( detlist.Contains("-TRG", TString::kIgnoreCase) )TRG = false; else if( detlist.Contains("+TRG", TString::kIgnoreCase) )TRG = true; if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false; else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true; if( detlist.Contains("-S4", TString::kIgnoreCase) )S4 = false; else if( detlist.Contains("+S4", TString::kIgnoreCase) )S4 = true; if( detlist.Contains("-ND", TString::kIgnoreCase) )ND = false; else if( detlist.Contains("+ND", TString::kIgnoreCase) )ND = true; if( detlist.Contains("-AC", TString::kIgnoreCase) )AC = false; else if( detlist.Contains("+AC", TString::kIgnoreCase) )AC = true; if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false; else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true; }; //-------------------------------------- // // //-------------------------------------- /** * Check if a file contains selected Pamela Level2 trees. * @param name File name * @return Pointer to a TChain */ Bool_t PamLevel2::CheckLevel2File(TString name){ Bool_t CAL__ok = false; Bool_t TRK__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; }; lk->Delete(); f->Close(); Bool_t FLAG = true; if(!RUN__ok) { cout << "File: "<< f->GetName() <<" discarded ---- Missing RunInfo tree"<< endl; FLAG = false; }; if(CAL && !CAL__ok){ cout << "File: "<< f->GetName() <<" discarded ---- Missing Calorimeter tree"<< endl; FLAG = false; }; if(TRK && !TRK__ok){ cout << "File: "<< f->GetName() <<" discarded ---- Missing Tracker tree"<< endl; FLAG = false; }; if(TRG && !TRG__ok){ cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl; FLAG = false; }; if(TOF && !TOF__ok){ cout << "File: "<< f->GetName() <<" discarded ---- Missing ToF tree"<< endl; FLAG = false; }; if(S4 && !S4__ok){ cout << "File: "<< f->GetName() <<" discarded ---- Missing S4 tree"<< endl; FLAG = false; }; if(ND && !ND__ok){ cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl; FLAG = false; }; if(AC && !AC__ok){ cout << "File: "<< f->GetName() <<" discarded ---- Missing AC tree"<< endl; FLAG = false; }; if(ORB && !ORB__ok){ cout << "File: "<< f->GetName() <<" discarded ---- Missing ORB tree"<< endl; FLAG = false; }; return FLAG; };