// macro for analys bkg channels via sum of PDG id // and print out results // Attention! sum of PDG id corresponds to primary final state only! // author: a.karavdina // date: 10 January 2014 #include "TString.h" #include "TFile.h" #include "TTree.h" #include "TBranch.h" #include "TChain.h" #include "TClonesArray.h" #include "/panda/pandaroot/lmd/LmdQA/PndLmdTrackQ.h" #include #include using namespace std; bool myfunction_el (int i,int j) { return (i,int> i,pair,int> j) { return (i.second>j.second); } void sumPDGcodes(int gl_id=-2212,double fcs_tot=0, TString path="/panda/myResults/DPMoutputDec2013/all_15/results/", bool fworstc = true){ if(fworstc) cout<<"Count cross-section for the worst case scenario!"< need loop over event in the tree with "id" and "sumid" branches TString filename1 = path+"/TOT_Lumi_BkgSig_el_inel.root"; TFile *fin1 = new TFile(filename1,"READ"); TTree *tbkg1 = (TTree *)fin1->Get("tBkg"); //Bkg data int f_id, f_sumid; TBranch *bid = tbkg1->GetBranch("id"); bid->SetAddress(&f_id); TBranch *bsumid = tbkg1->GetBranch("sumid"); bsumid->SetAddress(&f_sumid); int f_issec; TBranch *bissec = tbkg1->GetBranch("issecond"); bissec->SetAddress(&f_issec); Int_t nevent = tbkg1->GetEntries(); Int_t nevent_pri = tbkg1->GetEntries("issecond<0");//only primary events vector > v_sum_id; //vector of channels: first=id,second=counter for (Int_t i=0;iGetEvent(i); if(f_issec>=0) continue;//primaries only if(f_id==gl_id){ // cout<<" sum_id = "< >::iterator it = v_sum_id.begin(); it != v_sum_id.end(); ++it){ if((*it).first==f_sumid){ addit=false;// add only channels not listed before; (*it).second++; } } if(addit) v_sum_id.push_back(std::make_pair(f_sumid,1)); } } std::cout<<"List of channels for particle with ID="< >::iterator it = v_sum_id.begin(); it != v_sum_id.end(); ++it){ contrSum +=100*((*it).second/double(nevent_pri)); std::cout << ' ' << (*it).first <<" with contribution "<< 100*((*it).second/double(nevent_pri))<<" % from tot.prim.inel.bkg"; std::cout << '\n'; } cout<<"TOTAL: "<Close(); //[END] 1. ------------------------------------------------------------------------------------------------ //2. Make list of final state particles for each channel ------------------------------------- // -> need loop over events in full tree over "LMDTrackQ.fPDGcode" and "LMDTrackQ.fsumID" branches TString filename2 = path+"/TOT_Lumi_TrksQA_el_inel.root";//one sample for el+inel mode TChain tTrkRec("cbmsim"); TString in=filename2; tTrkRec.Add(in); //--- Tracks ------------------------------------------------------------------- TClonesArray* qtrk=new TClonesArray("PndLmdTrackQ"); tTrkRec.SetBranchAddress("LMDTrackQ",&qtrk); //Tracks //---------------------------------------------------------------------------------- const int nEvents= tTrkRec.GetEntries();//number of simulated events //const int nEvents=1e4;//number of simulated events vector,int> > fchparts; //now let's make lists of each sub-channel // for (Int_t j=0; jGetEntriesFast();//Number of trks/ev if(nTrksQ<1) continue; PndLmdTrackQ *trkcur0 = (PndLmdTrackQ *)qtrk->At(0); int sumPDGev = trkcur0->GetSumEvPDG(); for (std::vector >::iterator it = v_sum_id.begin(); it != v_sum_id.end(); ++it){//loop over channels obtained in previous step bool nxtch = true; vector chparts; int el_parts=0; if(sumPDGev==(*it).first){//found needed event cout<<" "<At(iq); int issec = trkcur->GetSecondary(); if(issec>=0) continue;//primaries only int PDGcode = trkcur->GetPDGcode(); cout<<"PDGcode = "<GetTrkRecStatus(); // if(fworstc){ if(PDGcode==gl_id) runagain=true; //check only channels, which really contain interesting particle, doesn't matter was it reconstructed or not -> "worst case" } else{ if(PDGcode==gl_id && trkSt==0) runagain=true; //check only channels, which really contain interesting & reconstructed particle } } if(!runagain) continue; for(int iq=0;iqAt(iq); int issec = trkcur->GetSecondary(); if(issec>=0) continue;//primaries only int PDGcode = trkcur->GetPDGcode(); chparts.push_back(PDGcode); el_parts++; }// end loop over all trks in event //range elements in the list std::sort (chparts.begin(), chparts.end(), myfunction_el); for(std::vector,int> >::iterator itl = fchparts.begin(); itl != fchparts.end(); ++itl){ //loop over already saved sub-channels if(chparts==(*itl).first){ (*itl).second++; nxtch = false; } }//end loop over already saved sub-channels if(nxtch) fchparts.push_back(std::make_pair(chparts,1)); } }// end loop over channels obtained in previous step }//end loop over all events cout<<"ranging elements"<,int> >::iterator itl = fchparts.begin(); itl != fchparts.end(); ++itl){ //loop over saved sub-channels vector subch = (*itl).first; tot_sum_ck +=100.*double((*itl).second)/double(nevent_pri); // cout<<"List of particles [sumIDs="<<(*it).first<<"]: "<<" ("<<100.*double((*itl).second)/double(nevent_pri)<<" % from tot.inel.bkg): "; cout<<" ("<<100.*double((*itl).second)/double(nevent_pri)<<" % from prim.inel.bkg): "; for(std::vector::iterator isch = subch.begin(); isch != subch.end(); ++isch){ //loop over particles sub-channel switch ((*isch)){//assign human readable values to PDG code case 11: cout << " e^{-} "; break; case -11: cout << " e^{+} "; break; case 13: cout << " mu^{-} "; break; case -13: cout << " mu^{+} "; break; case 22: cout << " gamma "; break; case 111: cout << " pi^{0} "; break; case 130: cout << " K^{0}_{L} "; break; case -211: cout << " pi^{-} "; break; case 211: cout << " pi^{+} "; break; case 311: cout << " K^{0}"; break; case 310: cout << " K^{0}_{S} "; break; case 321: cout << " K^{+} "; break; case -321: cout << " K^{-} "; break; case -2112: cout << " bar{n} "; break; case 2112: cout << " n"; break; case 2212: cout << " p "; break; case -2212: cout << " bar{p} "; break; case 3112: cout << " Sigma^{-} "; break; case 3122: cout << " Lambda "; break; case 3212: cout << " Sigma^{0} "; break; case 3222: cout << " Sigma^{+} "; break; default: cout<<" "<<(*isch); } } cout<<" eff.cs= "<<((*itl).second*cs_tot)/3e1<<" nb"<