Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:12:55

0001 #include <iostream>
0002 #include <cstdlib>
0003 
0004 #include "TFile.h"
0005 #include "TTree.h"
0006 #include "TCanvas.h"
0007 
0008 TTree* loadTree(
0009           TString FILE_NAME="",
0010           TString TREE_NAME="",
0011           const TString DIR_PATH = "/sphenix/user/gregtom3/data/Summer2018/ECAL_probability_studies/"
0012         )
0013 {
0014   TFile *f = new TFile(DIR_PATH+FILE_NAME,"READ");
0015   TTree *t = (TTree*)f->Get(TREE_NAME);
0016   return t;
0017 }
0018 
0019 TH1F* fillHist(TH1F *THE_HIST, TTree *THE_TREE)
0020 {
0021   std::vector<float> measured_energy;
0022   std::vector<float> measured_ptotal;
0023   std::vector<float> shower_probability; //integration of chi2 PDF, tells us likelihood of this specific cluster radius corresponds to that of an electron's
0024   std::vector<float>* measured_energy_pointer = &measured_energy;
0025   std::vector<float>* measured_ptotal_pointer = &measured_ptotal;
0026   std::vector<float>* shower_probability_pointer = &shower_probability;
0027   THE_TREE->SetBranchAddress("em_cluster_e",&measured_energy_pointer);
0028   THE_TREE->SetBranchAddress("em_track_ptotal",&measured_ptotal_pointer);
0029   THE_TREE->SetBranchAddress("em_cluster_prob",&shower_probability_pointer);
0030   
0031   Int_t nentries = Int_t(THE_TREE->GetEntries());
0032   for(Int_t entryInChain=0; entryInChain<nentries; entryInChain++)
0033     {
0034       Int_t entryInTree = THE_TREE->LoadTree(entryInChain);
0035       if (entryInTree < 0) break;
0036       THE_TREE->GetEntry(entryInChain);
0037       for(int i=0;i<shower_probability.size();i++)
0038     {
0039       if(measured_energy[i]>0.5) //Cuts
0040         THE_HIST->Fill(shower_probability[i]);
0041     }
0042     }
0043   THE_HIST->SetXTitle("P_{EM}");
0044   THE_HIST->SetYTitle("Counts");
0045   
0046   return THE_HIST;
0047 }
0048 
0049 void histToPNG(TH1F* h_p, TH1F* h_e, char * title, char * saveFileName)
0050 {
0051   TCanvas *cPNG = new TCanvas("cPNG",title); // 700 x 500 default
0052   TImage *img = TImage::Create();
0053 
0054   h_p->Draw();
0055   h_e->Draw("SAME");
0056   h_p->GetXaxis()->SetNdivisions(6,2,0,false);
0057   h_p->GetYaxis()->SetNdivisions(5,3,0,false);
0058   h_p->GetYaxis()->SetRangeUser(0,5000);
0059   auto legend = new TLegend(0.7,0.65,0.95,0.90,title);
0060   legend->AddEntry(h_p,"Pions","l");
0061   legend->AddEntry(h_e,"Electrons","l");
0062   legend->SetTextSize(0.05);
0063   legend->Draw();
0064   gPad->RedrawAxis();
0065   img->FromPad(cPNG);
0066   img->WriteImage(saveFileName);
0067   
0068   delete img;
0069   delete cPNG;
0070 
0071 }
0072 
0073 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
0074 /                                 Main Code
0075 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0076 
0077 void prob_EMC_e_pi_plotMacro(
0078                  const TString DIR_PATH = "/sphenix/user/gregtom3/data/Summer2018/ECAL_probability_studies/"
0079                             )
0080 {
0081   
0082   /* *
0083    * sPHENIX Style
0084    */
0085   
0086   gROOT->LoadMacro("/sphenix/user/gregtom3/SBU/research/macros/macros/sPHENIXStyle/sPhenixStyle.C");
0087   SetsPhenixStyle();
0088   gROOT->SetBatch(kTRUE);
0089 
0090   /* *
0091    * Base Histogram
0092    */
0093    
0094   TH1F *h_base = new TH1F("h_base","",25,0,1.2);
0095   TH1F *h_base_e = (TH1F*)h_base->Clone(); 
0096   TH1F *h_base_p = (TH1F*)h_base->Clone();
0097 
0098   h_base_e->SetLineColor(kRed);
0099   h_base_p->SetLineColor(kBlue);
0100 
0101   /* *
0102    * Loading histograms and trees for electrons and pions [1, 2, 5, 10, 20] GeV
0103    * CEMC Eta -0.5 0.5
0104    * EEMC Eta -3 -2
0105    * 10000 events per energy per particle per detector
0106    */
0107 
0108   /* CEMC */
0109   TH1F *h_P_1GeV_CEMC = (TH1F*)h_base_p->Clone();
0110   TH1F *h_P_2GeV_CEMC = (TH1F*)h_base_p->Clone();
0111   TH1F *h_P_5GeV_CEMC = (TH1F*)h_base_p->Clone();
0112   TH1F *h_P_10GeV_CEMC = (TH1F*)h_base_p->Clone();
0113   TH1F *h_P_20GeV_CEMC = (TH1F*)h_base_p->Clone();
0114 
0115   TH1F *h_E_1GeV_CEMC = (TH1F*)h_base_e->Clone();
0116   TH1F *h_E_2GeV_CEMC = (TH1F*)h_base_e->Clone();
0117   TH1F *h_E_5GeV_CEMC = (TH1F*)h_base_e->Clone();
0118   TH1F *h_E_10GeV_CEMC = (TH1F*)h_base_e->Clone();
0119   TH1F *h_E_20GeV_CEMC = (TH1F*)h_base_e->Clone();
0120 
0121   h_P_1GeV_CEMC->SetName("h_P_1GeV_CEMC");
0122   h_P_2GeV_CEMC->SetName("h_P_2GeV_CEMC");
0123   h_P_5GeV_CEMC->SetName("h_P_5GeV_CEMC");
0124   h_P_10GeV_CEMC->SetName("h_P_10GeV_CEMC");
0125   h_P_20GeV_CEMC->SetName("h_P_20GeV_CEMC");
0126 
0127   h_E_1GeV_CEMC->SetName("h_E_1GeV_CEMC");
0128   h_E_2GeV_CEMC->SetName("h_E_2GeV_CEMC");
0129   h_E_5GeV_CEMC->SetName("h_E_5GeV_CEMC");
0130   h_E_10GeV_CEMC->SetName("h_E_10GeV_CEMC");
0131   h_E_20GeV_CEMC->SetName("h_E_20GeV_CEMC");
0132 
0133   TTree *t_P_1GeV_CEMC = loadTree("Pions/Pions1C.root", "event_cluster");
0134   TTree *t_P_2GeV_CEMC = loadTree("Pions/Pions2C.root", "event_cluster");
0135   TTree *t_P_5GeV_CEMC = loadTree("Pions/Pions5C.root", "event_cluster");
0136   TTree *t_P_10GeV_CEMC = loadTree("Pions/Pions10C.root", "event_cluster");
0137   TTree *t_P_20GeV_CEMC = loadTree("Pions/Pions20C.root", "event_cluster");
0138   
0139   TTree *t_E_1GeV_CEMC = loadTree("Electrons/Electrons1C.root", "event_cluster");
0140   TTree *t_E_2GeV_CEMC = loadTree("Electrons/Electrons2C.root", "event_cluster");
0141   TTree *t_E_5GeV_CEMC = loadTree("Electrons/Electrons5C.root", "event_cluster");
0142   TTree *t_E_10GeV_CEMC = loadTree("Electrons/Electrons10C.root", "event_cluster");
0143   TTree *t_E_20GeV_CEMC = loadTree("Electrons/Electrons20C.root", "event_cluster");
0144 
0145   /* EEMC */
0146   TH1F *h_P_1GeV_EEMC = (TH1F*)h_base_p->Clone();
0147   TH1F *h_P_2GeV_EEMC = (TH1F*)h_base_p->Clone();
0148   TH1F *h_P_5GeV_EEMC = (TH1F*)h_base_p->Clone();
0149   TH1F *h_P_10GeV_EEMC = (TH1F*)h_base_p->Clone();
0150   TH1F *h_P_20GeV_EEMC = (TH1F*)h_base_p->Clone();
0151 
0152   TH1F *h_E_1GeV_EEMC = (TH1F*)h_base_e->Clone();
0153   TH1F *h_E_2GeV_EEMC = (TH1F*)h_base_e->Clone();
0154   TH1F *h_E_5GeV_EEMC = (TH1F*)h_base_e->Clone();
0155   TH1F *h_E_10GeV_EEMC = (TH1F*)h_base_e->Clone();
0156   TH1F *h_E_20GeV_EEMC = (TH1F*)h_base_e->Clone();
0157 
0158   h_P_1GeV_EEMC->SetName("h_P_1GeV_EEMC");
0159   h_P_2GeV_EEMC->SetName("h_P_2GeV_EEMC");
0160   h_P_5GeV_EEMC->SetName("h_P_5GeV_EEMC");
0161   h_P_10GeV_EEMC->SetName("h_P_10GeV_EEMC");
0162   h_P_20GeV_EEMC->SetName("h_P_20GeV_EEMC");
0163 
0164   h_E_1GeV_EEMC->SetName("h_E_1GeV_EEMC");
0165   h_E_2GeV_EEMC->SetName("h_E_2GeV_EEMC");
0166   h_E_5GeV_EEMC->SetName("h_E_5GeV_EEMC");
0167   h_E_10GeV_EEMC->SetName("h_E_10GeV_EEMC");
0168   h_E_20GeV_EEMC->SetName("h_E_20GeV_EEMC");
0169 
0170   TTree *t_P_1GeV_EEMC = loadTree("Pions/Pions1E.root", "event_cluster");
0171   TTree *t_P_2GeV_EEMC = loadTree("Pions/Pions2E.root", "event_cluster");
0172   TTree *t_P_5GeV_EEMC = loadTree("Pions/Pions5E.root", "event_cluster");
0173   TTree *t_P_10GeV_EEMC = loadTree("Pions/Pions10E.root", "event_cluster");
0174   TTree *t_P_20GeV_EEMC = loadTree("Pions/Pions20E.root", "event_cluster");
0175   
0176   TTree *t_E_1GeV_EEMC = loadTree("Electrons/Electrons1E.root", "event_cluster");
0177   TTree *t_E_2GeV_EEMC = loadTree("Electrons/Electrons2E.root", "event_cluster");
0178   TTree *t_E_5GeV_EEMC = loadTree("Electrons/Electrons5E.root", "event_cluster");
0179   TTree *t_E_10GeV_EEMC = loadTree("Electrons/Electrons10E.root", "event_cluster");
0180   TTree *t_E_20GeV_EEMC = loadTree("Electrons/Electrons20E.root", "event_cluster");
0181 
0182   /* *
0183    * Filling Histograms
0184    */
0185   
0186   /* Pions CEMC */
0187   h_P_1GeV_CEMC=fillHist(h_P_1GeV_CEMC,t_P_1GeV_CEMC);
0188   h_P_2GeV_CEMC=fillHist(h_P_2GeV_CEMC,t_P_2GeV_CEMC);
0189   h_P_5GeV_CEMC=fillHist(h_P_5GeV_CEMC,t_P_5GeV_CEMC);
0190   h_P_10GeV_CEMC=fillHist(h_P_10GeV_CEMC,t_P_10GeV_CEMC);
0191   h_P_20GeV_CEMC=fillHist(h_P_20GeV_CEMC,t_P_20GeV_CEMC);
0192   /* Pions EEMC */
0193   //Lots of Bugs currently with event_cluster info from EEMC
0194   /*h_P_1GeV_EEMC=fillHist(h_P_1GeV_EEMC,t_P_1GeV_EEMC);
0195   h_P_2GeV_EEMC=fillHist(h_P_2GeV_EEMC,t_P_2GeV_EEMC);
0196   h_P_5GeV_EEMC=fillHist(h_P_5GeV_EEMC,t_P_5GeV_EEMC);
0197   h_P_10GeV_EEMC=fillHist(h_P_10GeV_EEMC,t_P_10GeV_EEMC);
0198   h_P_20GeV_EEMC=fillHist(h_P_20GeV_EEMC,t_P_20GeV_EEMC);*/
0199 
0200 
0201   /* Electrons CEMC */
0202   h_E_1GeV_CEMC=fillHist(h_E_1GeV_CEMC,t_E_1GeV_CEMC);
0203   h_E_2GeV_CEMC=fillHist(h_E_2GeV_CEMC,t_E_2GeV_CEMC);
0204   h_E_5GeV_CEMC=fillHist(h_E_5GeV_CEMC,t_E_5GeV_CEMC);
0205   h_E_10GeV_CEMC=fillHist(h_E_10GeV_CEMC,t_E_10GeV_CEMC);
0206   h_E_20GeV_CEMC=fillHist(h_E_20GeV_CEMC,t_E_20GeV_CEMC);
0207   /* Electrons EEMC */
0208   /*h_E_1GeV_EEMC=fillHist(h_E_1GeV_EEMC,t_E_1GeV_EEMC);
0209   h_E_2GeV_EEMC=fillHist(h_E_2GeV_EEMC,t_E_2GeV_EEMC);
0210   h_E_5GeV_EEMC=fillHist(h_E_5GeV_EEMC,t_E_5GeV_EEMC);
0211   h_E_10GeV_EEMC=fillHist(h_E_10GeV_EEMC,t_E_10GeV_EEMC);
0212   h_E_20GeV_EEMC=fillHist(h_E_20GeV_EEMC,t_E_20GeV_EEMC);*/
0213   
0214   /* *
0215    * Drawing Histograms and Saving Them
0216    */
0217   
0218   /* CEMC */
0219   histToPNG(h_P_1GeV_CEMC,h_E_1GeV_CEMC,"1GeV CEMC","prob_e_pi_1GeV_CEMC.png");
0220   histToPNG(h_P_2GeV_CEMC,h_E_2GeV_CEMC,"2GeV CEMC","prob_e_pi_2GeV_CEMC.png");
0221   histToPNG(h_P_5GeV_CEMC,h_E_5GeV_CEMC,"5GeV CEMC","prob_e_pi_5GeV_CEMC.png");
0222   histToPNG(h_P_10GeV_CEMC,h_E_10GeV_CEMC,"10GeV CEMC","prob_e_pi_10GeV_CEMC.png");
0223   histToPNG(h_P_20GeV_CEMC,h_E_20GeV_CEMC,"20GeV CEMC","prob_e_pi_20GeV_CEMC.png");
0224  /* EEMC */
0225   /*histToPNG(h_P_1GeV_EEMC,h_E_1GeV_EEMC,"1GeV EEMC","prob_e_pi_1GeV_EEMC.png");
0226   histToPNG(h_P_2GeV_EEMC,h_E_2GeV_EEMC,"2GeV EEMC","prob_e_pi_2GeV_EEMC.png");
0227   histToPNG(h_P_5GeV_EEMC,h_E_5GeV_EEMC,"5GeV EEMC","prob_e_pi_5GeV_EEMC.png");
0228   histToPNG(h_P_10GeV_EEMC,h_E_10GeV_EEMC,"10GeV EEMC","prob_e_pi_10GeV_EEMC.png");
0229   histToPNG(h_P_20GeV_EEMC,h_E_20GeV_EEMC,"20GeV EEMC","prob_e_pi_20GeV_EEMC.png");*/
0230 }
0231 
0232 
0233