// macro for analys bkg particles PDG id and drawing results // in cool histogram // author: a.karavdina // date: 07 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 "TPie.h" #include "TLegend.h" #include using namespace std; void PDGcodes(TString path="/panda/myResults/DPMoutputDec2013/FTF/NoDipole/mom_15/"){ // // // color table: barp = 2, pi- = 8, e- = 4, e+ = 43, pi+ = 7, K- = 11, mu- = 13, p = 6, mu+ = 38, K+ = 9 // // // ///list all id's and count each contribution ------------------------------ // TString filename1 = path+"/TOT_Lumi_BkgSig_el_inel.root"; // TFile *fin1 = new TFile(filename1,"READ"); // TTree *tbkg1 = (TTree *)fin1->Get("tBkg"); //Bkg data // // Int_t nevent = tbkg1->GetEntries(); // Int_t nevent = tbkg1->GetEntries(); // int f_id; // int f_issec; // TBranch *bid = tbkg1->GetBranch("id"); // bid->SetAddress(&f_id); // // TBranch *bissec = tbkg1->GetBranch("issecond"); // // bissec->SetAddress(&f_issec); // vector > v_id; //vector of particles: first=id,second=counter // for (Int_t i=0;iGetEntries(); // tbkg1->GetEvent(i); // // if(f_issec<0) continue;//secondaries only // // if(f_issec>=0) continue;//promaries only // bool addit=true; // for (std::vector >::iterator it = v_id.begin(); it != v_id.end(); ++it){ // if((*it).first==f_id){ // addit=false;// add only ids not listed before; // (*it).second++; // } // } // if(addit) v_id.push_back(std::make_pair(f_id,1)); // }// end loop over all trks // std::cout<<"List of particles: "< >::iterator it = v_id.begin(); it != v_id.end(); ++it){ // //ids[ncontr]=(*it).first; // if((*it).first>1e4) continue; // contr[ncontr]=(*it).second; // ncontr++; // contrSum +=100*((*it).second/double(nevent)); // std::cout << ' ' << (*it).first <<" with contribution "<<(*it).second<<" "<< 100*((*it).second/double(nevent))<<" % from tot.bkg"; // std::cout << '\n'; // } // cout<<"TOTAL: "<SetEntryLabel(0,"#bar{p}"); // pie1->SetEntryLabel(1,"#pi^{-}"); // pie1->SetEntryLabel(2,"#pi^{+}"); // pie1->SetEntryLabel(3,"e^{-}"); // pie1->SetEntryLabel(4,"e^{+}"); // pie1->SetEntryLabel(5,"p"); // pie1->SetEntryLabel(6,"#mu^{-}"); // pie1->SetEntryLabel(8,"K^{+}"); // pie1->SetEntryLabel(7,"K^{-}"); // // pie1->SetEntryLabel(9,"#mu^{+}"); // //pie1->SetLabelFormat("%txt #scale[0.6]{(%perc)}"); // pie1->SetAngularOffset(160.); // pie1->SetLabelsOffset(1); // pie1->SetEntryRadiusOffset(0, 0.04); // // pie1->SetEntryRadiusOffset(8, 0.1); // // pie1->SetEntryRadiusOffset(7, 0.16); // // pie1->SetEntryRadiusOffset(6, 0.14); // // pie1->SetEntryRadiusOffset(5, 0.12); // // pie1->SetEntryRadiusOffset(4, 0.09); // // pie1->SetEntryRadiusOffset(3, 0.07); // // pie1->SetEntryRadiusOffset(2, 0.04); // // pie1->SetEntryRadiusOffset(1, 0.02); // pie1->SetRadius(.35); // // pie1->Draw("r"); // pie1->Draw("3d"); // TLegend *leg = new TLegend(0.1,0.7,0.48,0.9); // // leg->SetHeader("The Legend Title"); // for(int i=0;i<9;i++){ // TString entry = pie1->GetEntryLabel(i); // entry +=" "; // char buf[256] = {0}; // snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf) - 1, "%c%0.02f",1,float(100.*(rangcont[i])/nevent)); // entry += buf; // entry += " %"; // leg->AddEntry(entry,entry,""); // } // // leg->AddEntry("f1","Function abs(#frac{sin(x)}{x})","l"); // // leg->AddEntry("gr","Graph with error bars","lep"); // leg->Draw(); // // ///[END] list all id's and count each contribution ------------------------------ ///primaries ------------------------------ TString filename1 = path+"/TOT_Lumi_BkgSig_el_inel.root"; TFile *fin1 = new TFile(filename1,"READ"); TTree *tbkg1 = (TTree *)fin1->Get("tBkg"); //Bkg data // Int_t nevent = tbkg1->GetEntries(); Int_t neventGL = tbkg1->GetEntries("issecond<0"); int f_id; int f_issec; TBranch *bid = tbkg1->GetBranch("id"); bid->SetAddress(&f_id); TBranch *bissec = tbkg1->GetBranch("issecond"); bissec->SetAddress(&f_issec); double f_prec; TBranch *bismom = tbkg1->GetBranch("prec"); bismom->SetAddress(&f_prec); vector > v_id; //vector of particles: first=id,second=counter int nevent=0; for (Int_t i=0;iGetEntries(); tbkg1->GetEvent(i); if(f_issec>=0) continue;//primaries only // if(fabs(f_prec-15.0)>5e-4) continue; // mom cut nevent++; bool addit=true; for (std::vector >::iterator it = v_id.begin(); it != v_id.end(); ++it){ if((*it).first==f_id){ addit=false;// add only ids not listed before; (*it).second++; } } if(addit) v_id.push_back(std::make_pair(f_id,1)); }// end loop over all trks std::cout<<"List of particles: "< >::iterator it = v_id.begin(); it != v_id.end(); ++it){ //ids[ncontr]=(*it).first; contr[ncontr]=(*it).second; ncontr++; contrSum +=100*((*it).second/double(nevent)); std::cout << ' ' << (*it).first <<" with contribution "<<(*it).second<<" "<< 100*((*it).second/double(nevent))<<" % from tot.bkg"; std::cout << '\n'; } cout<<"TOTAL: "<SetEntryLabel(0,"#pi^{-}"); pie1->SetEntryLabel(1,"#bar{p}"); pie1->SetEntryLabel(2,"#pi^{+}"); pie1->SetEntryLabel(3,"p"); pie1->SetEntryLabel(4,"K^{-}"); pie1->SetEntryLabel(5,"K^{+}"); //pie1->SetLabelFormat("%txt #scale[0.6]{(%perc)}"); pie1->SetAngularOffset(160.); pie1->SetLabelsOffset(1); pie1->SetEntryRadiusOffset(0, 0.04); // pie1->SetEntryRadiusOffset(8, 0.1); // pie1->SetEntryRadiusOffset(7, 0.16); // pie1->SetEntryRadiusOffset(6, 0.14); // pie1->SetEntryRadiusOffset(5, 0.12); // pie1->SetEntryRadiusOffset(4, 0.05); // pie1->SetEntryRadiusOffset(3, 0.03); // pie1->SetEntryRadiusOffset(2, 0.01); // pie1->SetEntryRadiusOffset(2, 0.04); // pie1->SetEntryRadiusOffset(3, 0.03); // pie1->SetEntryRadiusOffset(4, 0.02); pie1->SetRadius(.35); // pie1->Draw("r"); pie1->Draw("3d"); ///[END] primaries ------------------------------ // // // ///secondaries ------------------------------ // TString filename1 = path+"/TOT_Lumi_BkgSig_el_inel.root"; // TFile *fin1 = new TFile(filename1,"READ"); // TTree *tbkg1 = (TTree *)fin1->Get("tBkg"); //Bkg data // // Int_t nevent = tbkg1->GetEntries(); // Int_t neventGL = tbkg1->GetEntries("issecond<0"); // int f_id; // int f_issec; // TBranch *bid = tbkg1->GetBranch("id"); // bid->SetAddress(&f_id); // TBranch *bissec = tbkg1->GetBranch("issecond"); // bissec->SetAddress(&f_issec); // vector > v_id; //vector of particles: first=id,second=counter // int nevent=0; // for (Int_t i=0;iGetEntries(); // tbkg1->GetEvent(i); // if(f_issec<0) continue;//secondaries only // nevent++; // bool addit=true; // for (std::vector >::iterator it = v_id.begin(); it != v_id.end(); ++it){ // if((*it).first==f_id){ // addit=false;// add only ids not listed before; // (*it).second++; // } // } // if(addit) v_id.push_back(std::make_pair(f_id,1)); // }// end loop over all trks // std::cout<<"List of particles: "< >::iterator it = v_id.begin(); it != v_id.end(); ++it){ // //ids[ncontr]=(*it).first; // contr[ncontr]=(*it).second; // ncontr++; // contrSum +=100*((*it).second/double(nevent)); // std::cout << ' ' << (*it).first <<" with contribution "<<(*it).second<<" "<< 100*((*it).second/double(nevent))<<" % from tot.bkg"; // std::cout << '\n'; // } // cout<<"TOTAL: "<SetEntryLabel(0,"#pi^{-}"); // // pie1->SetEntryLabel(1,"e^{-}"); // // pie1->SetEntryLabel(2,"e^{+}"); // // pie1->SetEntryLabel(3,"#pi^{+}"); // // pie1->SetEntryLabel(4,"#bar{p}"); // // pie1->SetEntryLabel(5,"#mu^{-}"); // // pie1->SetEntryLabel(2,"K^{-}"); // // pie1->SetEntryLabel(3,"p"); // // pie1->SetEntryLabel(4,"#pi^{+}"); // //pie1->SetLabelFormat("%txt #scale[0.6]{(%perc)}"); // pie1->SetAngularOffset(160.); // pie1->SetLabelsOffset(1); // pie1->SetEntryRadiusOffset(0, 0.02); // // pie1->SetEntryRadiusOffset(8, 0.1); // // pie1->SetEntryRadiusOffset(7, 0.16); // // pie1->SetEntryRadiusOffset(6, 0.14); // // pie1->SetEntryRadiusOffset(5, 0.12); // // pie1->SetEntryRadiusOffset(4, 0.05); // // pie1->SetEntryRadiusOffset(3, 0.03); // // pie1->SetEntryRadiusOffset(2, 0.01); // // pie1->SetEntryRadiusOffset(2, 0.04); // // pie1->SetEntryRadiusOffset(3, 0.03); // // pie1->SetEntryRadiusOffset(4, 0.02); // pie1->SetRadius(.35); // // pie1->Draw("r"); // pie1->Draw("3d"); // // // ///[END] secondaries ------------------------------ // // // // // /// primary/secondary --------------------------------------------------------------------------- // TString filename1 = path+"/TOT_Lumi_BkgSig_el_inel.root"; // TFile *fin1 = new TFile(filename1,"READ"); // TTree *tbkg1 = (TTree *)fin1->Get("tBkg"); //Bkg data // double n_prim = tbkg1->GetEntries("issecond<0"); //primaries // double n_sec = tbkg1->GetEntries("issecond>=0"); //secondaries // cout<<"n_prim = "<SetEntryLabel(0,"primaries"); // pie1->SetEntryLabel(1,"secondaries"); // pie1->SetLabelFormat("%txt #scale[0.9]{(%perc)}"); // pie1->SetAngularOffset(250.); // pie1->SetLabelsOffset(0.1); // // pie1->SetEntryRadiusOffset(5, 0.12); // // pie1->SetEntryRadiusOffset(4, 0.09); // // pie1->SetEntryRadiusOffset(3, 0.07); // pie1->SetEntryRadiusOffset(0, 0.1); // // pie1->SetEntryRadiusOffset(1, 0.02); // pie1->SetRadius(.35); // pie1->Draw("3d"); // // // // // /// [END] primary/secondary --------------------------------------------------------------------------- }