#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_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(); run_obj = new GL_RUN(); sorted_tracks = new TRefArray(); CAL = true; TRK = true; TRG = true; TOF = true; S4 = true; ND = true; AC = true; ORB = true; TRK_L1 = false; Tout = NULL; }; /** * Destructor */ 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 }; /** * Clear the event */ 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 }; //-------------------------------------- // // //-------------------------------------- /** * 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(!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(!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()); // 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); if( !CAL && use_CAL) use_CAL = false; if( !TOF && use_TOF) use_TOF = false; if( !TRK ){ cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl; return; }; 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; // 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()); CaloTrkVar *ci = 0; ToFTrkVar *oi = 0; //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){ 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++; }; // ------------------------ // TOF check // ------------------------ // check the number of hit pmts along the track // on S12 S21 and S32, where paddles are parallel to Y axis if( use_TOF ){ Int_t nphit_p =0; Int_t nphit_i =0; op = GetToFStoredTrack(tp->GetSeqNo()); oi = GetToFStoredTrack(ti->GetSeqNo()); /* cout << "track: npmtadc "<< op->npmtadc << endl; cout << "track: npmttdc "<< op->npmttdc << endl; cout << "image: npmtadc "<< oi->npmtadc << endl; cout << "image: npmttdc "<< oi->npmttdc << endl;*/ 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; }; // cout <<" SortTracks() "<Add(ts);//save the track in the sorted array // cout << "SortTracks:: sorted_tracks->Add(it) "<=0 && it < TrkLevel2::GetNTracks() && itGetEntriesFast() ){ 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) { if(TRK_L1){ T->SetBranchAddress("TrkLevel1", GetPointerToTrk(1)); cout << "Tracker : set branch address TrkLevel1"<SetBranchAddress("TrkLevel2", GetPointerToTrk(2)); 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"<GetEntries()<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(); 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; cout <<"Input file list : " << flisttxt <> 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 "<WorkingDirectory()<< endl; 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 // cout << endl << "Selected files:" << endl; // contents->Print(); cout << contents->GetEntries()<<" files selected\n"; // cout << endl; // cout << "Working 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::GetPamTree(TList *fl, TString detlist="+ALL"){ // 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); }; } cout << "done chain \n"; // Tracker if(TRK) if(!Tout)Tout=T; // Calorimeter if(CAL) { if(!Tout)Tout=C; else Tout->AddFriend("Calorimeter"); }; // ToF if(TOF) { if(!Tout)Tout=O; else Tout->AddFriend("ToF"); }; // Trigger if(TRG) { if(!Tout)Tout=O; else Tout->AddFriend("Trigger"); }; // S4 if(S4) { if(!Tout)Tout=O; else Tout->AddFriend("S4"); }; // Neutron Detector if(ND) { if(!Tout)Tout=O; else Tout->AddFriend("NeutronD"); }; // Anticounters if(AC) { if(!Tout)Tout=O; else Tout->AddFriend("Anticounter"); }; // OrbitalInfo if(ORB) { if(!Tout)Tout=O; else Tout->AddFriend("OrbitalInfo"); }; // cout<GetEntries()<GetEntries() )PamLevel2::SetBranchAddress(); return Tout; } //-------------------------------------- // // //-------------------------------------- /** * Set branch addresses for Pamela friend trees */ void PamLevel2::SetBranchAddress(){ // 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("ToFLevel2", GetPointerToToF()); cout << "ToF : set branch address ToFLevel2"<SetBranchAddress("TrigLevel2", GetPointerToTrig()); cout << "Trigger : set branch address TrigLevel2"<SetBranchAddress("S4Level2", GetPointerToS4()); cout << "S4 : set branch address S4Level2"<SetBranchAddress("NDLevel2", GetPointerToND()); cout << "NeutronD : set branch address NDLevel2"<SetBranchAddress("AcLevel2", GetPointerToAc()); cout << "Anticounter : set branch address AcLevel2"<SetBranchAddress("OrbitalInfo", GetPointerToOrb()); cout << "OrbitalInfo : set branch address OrbitalInfo"<GetName(); // cout << "File: "<< name << endl; if( CheckLevel2File(name) ){ R->Add(name); }; } R->SetBranchAddress("RunInfo", GetPointerToRun()); cout << "Run : set branch address RunInfo"<Get("Run"); R->SetBranchAddress("RunInfo", GetPointerToRun()); cout << "Run : set branch address RunInfo"<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; Int_t nev_previous =0; while( (key = (TKey*)next()) ){ nev_previous = nev; nev = ((TTree*)f->Get(key->GetName()))->GetEntries(); if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){ cout << "File: "<< f->GetName() <<" discarded ---- "<< key->GetName() << " tree: n.entries does not match "<GetName(),"Calorimeter") )CAL__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; }; }; }; lk->Delete(); f->Close(); Bool_t FLAG = true; if(!RUN__ok) { cout << "File: "<< f->GetName() <<" discarded ---- Missing RunInfo tree"<< endl; return false; // FLAG = false; }; if(CAL && !CAL__ok){ cout << "File: "<< f->GetName() <<" discarded ---- Missing Calorimeter tree"<< endl; return false; // FLAG = false; }; if(TRK && !TRK__ok){ cout << "File: "<< f->GetName() <<" discarded ---- Missing Tracker tree"<< endl; return false; // FLAG = false; }; if(TRK_L1 && !TRK_L1__ok){ cout << "File: "<< f->GetName() <<" discarded ---- Missing Tracker Level1 Branch"<< endl; return false; // FLAG = false; }; if(TRG && !TRG__ok){ cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl; return false; // FLAG = false; }; if(TOF && !TOF__ok){ cout << "File: "<< f->GetName() <<" discarded ---- Missing ToF tree"<< endl; return false; // FLAG = false; }; if(S4 && !S4__ok){ cout << "File: "<< f->GetName() <<" discarded ---- Missing S4 tree"<< endl; return false; // FLAG = false; }; if(ND && !ND__ok){ cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl; return false; // FLAG = false; }; if(AC && !AC__ok){ cout << "File: "<< f->GetName() <<" discarded ---- Missing AC tree"<< endl; return false; // FLAG = false; }; if(ORB && !ORB__ok){ cout << "File: "<< f->GetName() <<" discarded ---- Missing ORB tree"<< endl; return false; // FLAG = false; }; return FLAG; };