///////////// code for counting the different particles hitting the Ftof+Stof detector by shyam kumar // This macro will work only if we put a function GetPdgCode(); in class PndFtofPoint #include "TGraphErrors.h" #include "TF1.h" #include "TRandom.h" #include "TCanvas.h" #include "TLegend.h" #include "TMath.h" #include "TClonesArray.h" void countparticle() { Int_t k=0; Int_t mu=0; Int_t pi=0; Int_t pr=0; Int_t e=0; Int_t ka=0; Int_t i=0; Int_t ph=0; ///////////////////////////////////////////////Reading the root file TFile* f = new TFile("../sim_complete.root"); // the sim file you want to analyse TTree *t=(TTree *) f->Get("cbmsim") ; TClonesArray *ftof_array=new TClonesArray("PndFtofPoint"); t->SetBranchAddress("FtofPoint",&ftof_array);//Branch names TCanvas *c1 = new TCanvas("c1", "c1",0,52,1191,692); TH2D* h1 = new TH2D("hist","Particles hitting Ftof+Stof",100,0,2300,100,0,1000); h1->SetTitle("PdgCode vs Entries"); h1->GetXaxis()->SetTitle("PdgCode"); h1->GetXaxis()->CenterTitle(true); h1->GetXaxis()->SetLabelFont(132); h1->GetXaxis()->SetLabelSize(0.035); h1->GetXaxis()->SetTitleSize(0.035); h1->GetXaxis()->SetTitleFont(42); h1->GetYaxis()->SetTitle("Entries"); h1->GetYaxis()->CenterTitle(true); h1->GetYaxis()->SetLabelFont(132); h1->GetYaxis()->SetLabelSize(0.035); h1->GetYaxis()->SetTitleSize(0.035); TH2D* h2 = new TH2D("hist","Particles hitting Ftof+Stof",100,0,2300,2300,0,1000); TH2D* h3 = new TH2D("hist","Particles hitting Ftof+Stof",100,0,2300,100,0,1000); TH2D* h4 = new TH2D("hist","Particles hitting Ftof+Stof",100,0,2300,100,0,1000); TH2D* h5 = new TH2D("hist","Particles hitting Ftof+Stof",100,0,2300,100,0,1000); TH2D* h6 = new TH2D("hist","Particles hitting Ftof+Stof",100,0,2300,100,0,1000); TH2D* h7 = new TH2D("hist","Particles hitting Ftof+Stof",100,0,2300,100,0,1000); Int_t nEntries = t->GetEntriesFast(); for (Int_t j=0; j< nEntries; j++) { std::vector a, b; t->GetEntry(j); cout<<"Event="<GetEntriesFast(); n++) { PndFtofPoint* ftofpoint = (PndFtofPoint*)ftof_array->At(n); k++; Int_t m= abs(ftofpoint->GetPdgCode()); std::cout<<"The particle hiting the tof has Pdgcode="<SetMarkerColor(2); h1->SetMarkerStyle(7); h1->Fill(211,pi); h1->Draw(); if(m==321) ka++; h2->Fill(321,ka); h2->SetMarkerColor(3); h2->SetMarkerStyle(7); h2->Draw("same"); if (m==2212) pr++; h3->Fill(2212,pr); h3->SetMarkerColor(4); h3->SetMarkerStyle(7); h3->Draw("same"); if(m==13) mu++; h4->Fill(13,mu); h4->SetMarkerColor(5); h4->SetMarkerStyle(7); h4->Draw("same"); if(m==11) e++; h5->Fill(11,e); h5->SetMarkerColor(6); h5->SetMarkerStyle(7); h5->Draw("same"); if(m==22) ph++; h6->Fill(22,ph); h6->SetMarkerColor(7); h6->SetMarkerStyle(7); h6->Draw("same"); if(m>10000) i++; h7->Fill(10000,i); h7->SetMarkerColor(8); h7->SetMarkerStyle(7); h7->Draw("same"); } } h1->SetStats(true); h2->Draw("same"); h1->SetLineColor(2); h2->SetLineColor(3); h3->SetLineColor(4); h4->SetLineColor(5); h5->SetLineColor(6); h6->SetLineColor(7); h7->SetLineColor(8); leg_hist = new TLegend(0.5,0.6,0.75,0.85); leg_hist->SetTextSize(0.03); leg_hist->SetHeader("Particles hitting Ftof+Stof"); leg_hist->AddEntry(h1,"#pi","l"); leg_hist->AddEntry(h2,"K","l"); leg_hist->AddEntry(h3,"Proton","l"); leg_hist->AddEntry(h4,"Muon","l"); leg_hist->AddEntry(h5,"Electron","l"); leg_hist->AddEntry(h6,"Photon","l"); leg_hist->AddEntry(h7,"Others","l"); leg_hist->Draw(); // c1->Modified(); // c1->cd(); cout<<" Total number of Events="<