#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(){ delete sorted_tracks; }; /** * Clear the event */ void PamLevel2::Clear(){ sorted_tracks->Delete(); }; //-------------------------------------- // // //-------------------------------------- /** * 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){ TrkTrack *t = 0; CaloTrkVar *c = 0; ToFTrkVar *o = 0; if( itrk >=0 && itrk < TrkLevel2::ntrk() ){ t = TrkLevel2::GetStoredTrack(itrk); /* c = CaloLevel2::GetCaloTrkVar(t->GetSeqNo()); o = ToFLevel2::GetToFTrkVar(t->GetSeqNo()); */ Int_t it_calo=0; do{ c = CaloLevel2::GetCaloTrkVar(it_calo); it_calo++; } while(t->GetSeqNo() != c->trkseqno && it_calo < CaloLevel2::ntrk()); if( t->GetSeqNo() != c->trkseqno )cout << "PamLevel2::GetStoredTrack(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match Calorimeter SeqNo"<< c->trkseqno<GetSeqNo() != o->trkseqno && it_tof < ToFLevel2::ntrk()); if( t->GetSeqNo() != o->trkseqno )cout << "PamLevel2::GetStoredTrack(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match ToF SeqNo "<< o->trkseqno <Delete(); //temporaneo // loop over the tracks sorted by the tracker for(Int_t i=0; i < TrkLevel2::GetNTracks(); i++){ TrkTrack *ts = 0; // get tracker tracks TrkTrack *tp = TrkLevel2::GetTrack(i); //tracker CaloTrkVar *cp = CaloLevel2::GetCaloTrkVar(tp->GetSeqNo()); //calorimeter ToFTrkVar *op = ToFLevel2::GetToFTrkVar(tp->GetSeqNo()); //tof // if track has an image, check image selection if(tp->HasImage()){ TrkTrack *ti = TrkLevel2::GetTrackImage(i); //tracker (image) CaloTrkVar *ci = CaloLevel2::GetCaloTrkVar(ti->GetSeqNo());//calorimeter (image) ToFTrkVar *oi = ToFLevel2::GetToFTrkVar(ti->GetSeqNo()); //tof (image) //assign starting scores Int_t tp_score = 1; //"principal" track, sorted by the tracker Int_t ti_score = 0; //image track // ------------------------ // calorimeter check // ------------------------ if( npcfit[1] > 3 && //no. of fit planes on Y view // varcfit[1] < 50.&& //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 // ------------------------ // ------------------------ // the winner is.... // ------------------------ if(tp_score > ti_score) ts = tp;//the track sorted by the tracker!! else ts = ti;//its image!! }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(){ // if(!sorted_tracks->GetEntries()) SortTracks(); SortTracks(); 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(); TrkTrack *t = 0; CaloTrkVar *c = 0; ToFTrkVar *o = 0; if( it >=0 && it < TrkLevel2::GetNTracks() ){ t = (TrkTrack*)sorted_tracks->At(it); Int_t it_calo=0; do{ c = CaloLevel2::GetCaloTrkVar(it_calo); it_calo++; } while(t->GetSeqNo() != c->trkseqno && it_calo < CaloLevel2::ntrk()); if( t->GetSeqNo() != c->trkseqno )cout << "PamLevel2::GetTrack(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match Calorimeter SeqNo"<< c->trkseqno<GetSeqNo() != o->trkseqno && it_tof < ToFLevel2::ntrk()); if( t->GetSeqNo() != o->trkseqno )cout << "PamLevel2::GetTrack(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match ToF SeqNo "<< o->trkseqno <GetEntries()) SortTracks(); SortTracks(); TrkTrack *t = 0; CaloTrkVar *c = 0; ToFTrkVar *o = 0; if( it >=0 && it < TrkLevel2::GetNTracks() ){ TrkTrack *temp = (TrkTrack*)sorted_tracks->At(it); if( temp->HasImage() ){ t = TrkLevel2::GetStoredTrack(temp->GetImageSeqNo()); /* c = CaloLevel2::GetCaloTrkVar(temp->GetImageSeqNo()); o = ToFLevel2::GetToFTrkVar(temp->GetImageSeqNo());*/ Int_t it_calo=0; do{ c = CaloLevel2::GetCaloTrkVar(it_calo); it_calo++; } while(t->GetSeqNo() != c->trkseqno && it_calo < CaloLevel2::ntrk()); if( t->GetSeqNo() != c->trkseqno )cout << "PamLevel2::GetTrackImage(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match Calorimeter SeqNo"<< c->trkseqno<GetSeqNo() != o->trkseqno && it_tof < ToFLevel2::ntrk()); if( t->GetSeqNo() != o->trkseqno )cout << "PamLevel2::GetTrackImage(int) : tracker SeqNo "<< t->GetSeqNo() <<" does not match ToF SeqNo "<< o->trkseqno <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 required 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; };