Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:13:24

0001 #pragma once
0002 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,00,0)
0003 //sphenix style
0004 #include "sPhenixStyle.C"
0005 #include "sPhenixStyle.h"
0006 
0007 //root includes
0008 #include <TH1.h>
0009 #include <TH2.h>
0010 #include <TFile.h>
0011 #include <TCanvas.h>
0012 #include <TLegend.h>
0013 #include <TLatex.h>
0014 #include <TPad.h>
0015 #include <TDirectory.h>
0016 #include <TFitResult.h>
0017 
0018 //c++ includes
0019 #include <string>
0020 #include <vector>
0021 #include <array>
0022 #include <algorithm>
0023 #include <sstream>
0024 #include <math.h>
0025 #include <map>
0026 std::vector<TDirectory*> file_dir_top;
0027 std::vector<std::array<TDirectory*,4>> lower_dirs;  
0028 void LoadInRegionPlots(TDirectory* botdir, std::vector<std::vector<TH1F*>*>* RegionPlots)
0029 {
0030     int Calo=0;
0031     for(auto b:*botdir->GetListOfKeys()){
0032         TKey* k=(TKey*)b;
0033         std::string hist_name = k->GetName();
0034         if(hist_name.find("EMCAL")!=std::string::npos) Calo=0;
0035         else if(hist_name.find("IHCAL")!=std::string::npos) Calo=1;
0036         else if(hist_name.find("OHCAL")!=std::string::npos) Calo=2;
0037         else continue;
0038         if(hist_name.find("e_")!=std::string::npos) RegionPlots->at(0)->at(Calo)=(TH1F*)botdir->Get(hist_name.c_str());
0039         if(hist_name.find("E2C_")!=std::string::npos)   RegionPlots->at(1)->at(Calo)=(TH1F*)botdir->Get(hist_name.c_str());
0040         if(hist_name.find("E3C_")!=std::string::npos)   RegionPlots->at(2)->at(Calo)=(TH1F*)botdir->Get(hist_name.c_str());
0041         if(hist_name.find("R_")!=std::string::npos) RegionPlots->at(3)->at(Calo)=(TH1F*)botdir->Get(hist_name.c_str());
0042         if(hist_name.find("n_")!=std::string::npos) RegionPlots->at(4)->at(Calo)=(TH1F*)botdir->Get(hist_name.c_str());
0043     }
0044     std::array<int, 3> n_evts;
0045     n_evts[0]=RegionPlots->at(0)->at(0)->GetEntries();
0046     n_evts[1]=RegionPlots->at(0)->at(1)->GetEntries();
0047     n_evts[2]=RegionPlots->at(0)->at(2)->GetEntries();
0048     
0049     for(auto R:*RegionPlots)
0050     {
0051         for(int i=0; i<(int)R->size(); i++)
0052         {
0053             auto p=R->at(i);
0054             if(!p) continue;
0055             if(n_evts[i]==0) n_evts[i]=1;
0056             p->Scale(1/((float) n_evts[i]));
0057             std::string ptitle = p->GetYaxis()->GetTitle();
0058             if(ptitle.find("Total Ev") == std::string::npos)
0059                 p->SetYTitle(Form("#frac{1}{Total Events} %s", p->GetYaxis()->GetTitle()));
0060         }
0061     }
0062     return;
0063 }
0064 std::array<std::vector<std::vector<std::string>>,4> GetPlotLabels(std::array<std::vector<std::vector<TH1F*>*>*, 4> RegPlts)
0065 {
0066     std::array<std::vector<std::vector<std::string>>, 4> plt_lbs;
0067     for(int k=0; k<(int)RegPlts.size(); k++){
0068         auto a=RegPlts[k];
0069         std::vector<std::vector<std::string>> a1;
0070         for(int i=0; i< (int)a->size(); i++)
0071         {
0072             std::vector<std::string> a2;
0073             for(int j=0; j <(int) a->at(i)->size(); j++)
0074             {
0075                 std::string lb="";
0076                 std::string plt_name, thr, cal;
0077                 if(! a->at(i)->at(j)) continue;
0078                 plt_name=a->at(i)->at(j)->GetName();
0079                 std::stringstream  str_plt (plt_name);
0080                 std::string subparts;
0081                 bool get_name=false;
0082                 while(std::getline(str_plt, subparts, '_')){
0083                     if( get_name){
0084                         thr=subparts;
0085                         break;
0086                     }
0087                     else if(subparts.find("CAL") != std::string::npos){
0088                         get_name=true;
0089                         cal=subparts;
0090                         continue;
0091                     }
0092                     else continue;
0093                 }
0094                 lb=cal+", E_{tower} #geq "+thr+" MeV";
0095                 a2.push_back(lb);
0096             }
0097             a1.push_back(a2);
0098         }
0099         plt_lbs[k]=a1;
0100     }
0101     return plt_lbs;
0102 }
0103 void LoadInPlots(int threshold_index, std::array<std::vector<std::vector<TH1F*>*>*, 4>* RegPlts){
0104         //std::cout<<__LINE__<<std::endl;
0105     TH1F* CEMC_FullEnergy=NULL, *CEMC_FullE2C=NULL, *CEMC_FullE3C=NULL, *CEMC_FullR=NULL, *CEMC_FullN=NULL;
0106     TH1F* CEMC_TowardsEnergy=NULL, *CEMC_TowardsE2C=NULL, *CEMC_TowardsE3C=NULL, *CEMC_TowardsR=NULL, *CEMC_TowardsN=NULL;
0107     TH1F* CEMC_AwayEnergy=NULL, *CEMC_AwayE2C=NULL, *CEMC_AwayE3C=NULL, *CEMC_AwayR=NULL, *CEMC_AwayN=NULL;
0108     TH1F* CEMC_TransEnergy=NULL, *CEMC_TransE2C=NULL, *CEMC_TransE3C=NULL, *CEMC_TransR=NULL, *CEMC_TransN=NULL;
0109     
0110     TH1F* OHCAL_FullEnergy=NULL, *OHCAL_FullE2C=NULL, *OHCAL_FullE3C=NULL, *OHCAL_FullR=NULL, *OHCAL_FullN=NULL;
0111     TH1F* OHCAL_TowardsEnergy=NULL, *OHCAL_TowardsE2C=NULL, *OHCAL_TowardsE3C=NULL, *OHCAL_TowardsR=NULL, *OHCAL_TowardsN=NULL;
0112     TH1F* OHCAL_AwayEnergy=NULL, *OHCAL_AwayE2C=NULL, *OHCAL_AwayE3C=NULL, *OHCAL_AwayR=NULL, *OHCAL_AwayN=NULL;
0113     TH1F* OHCAL_TransEnergy=NULL, *OHCAL_TransE2C=NULL, *OHCAL_TransE3C=NULL, *OHCAL_TransR=NULL, *OHCAL_TransN=NULL;
0114     
0115     TH1F* IHCAL_FullEnergy=NULL, *IHCAL_FullE2C=NULL, *IHCAL_FullE3C=NULL, *IHCAL_FullR=NULL, *IHCAL_FullN=NULL;
0116     TH1F* IHCAL_TowardsEnergy=NULL, *IHCAL_TowardsE2C=NULL, *IHCAL_TowardsE3C=NULL, *IHCAL_TowardsR=NULL, *IHCAL_TowardsN=NULL;
0117     TH1F* IHCAL_AwayEnergy=NULL, *IHCAL_AwayE2C=NULL, *IHCAL_AwayE3C=NULL, *IHCAL_AwayR=NULL, *IHCAL_AwayN=NULL;
0118     TH1F* IHCAL_TransEnergy=NULL, *IHCAL_TransE2C=NULL, *IHCAL_TransE3C=NULL, *IHCAL_TransR=NULL, *IHCAL_TransN=NULL;
0119     
0120     std::vector<TH1F*>* FullEnergy=new std::vector<TH1F*>{}, *FullE2C=new std::vector<TH1F*>{}, *FullE3C=new std::vector<TH1F*>{}, *FullR=new std::vector<TH1F*>{}, *FullN=new std::vector<TH1F*>{};
0121     std::vector<TH1F*>* TowardsEnergy=new std::vector<TH1F*>{}, *TowardsE2C=new std::vector<TH1F*>{}, *TowardsE3C=new std::vector<TH1F*>{}, *TowardsR=new std::vector<TH1F*>{}, *TowardsN=new std::vector<TH1F*>{};
0122     std::vector<TH1F*>* AwayEnergy=new std::vector<TH1F*>{}, *AwayE2C=new std::vector<TH1F*>{}, *AwayE3C=new std::vector<TH1F*>{}, *AwayR=new std::vector<TH1F*>{}, *AwayN=new std::vector<TH1F*>{};
0123     std::vector<TH1F*>* TransEnergy=new std::vector<TH1F*>{}, *TransE2C=new std::vector<TH1F*>{}, *TransE3C=new std::vector<TH1F*>{}, *TransR=new std::vector<TH1F*>{}, *TransN=new std::vector<TH1F*>{};
0124         //std::cout<<__LINE__<<std::endl;
0125     
0126     std::vector<std::vector<TH1F*>*>* Full, *Away, *Towards, *Trans;
0127     
0128     FullEnergy->push_back(CEMC_FullEnergy);
0129     FullEnergy->push_back(IHCAL_FullEnergy);
0130     FullEnergy->push_back(OHCAL_FullEnergy);
0131 
0132     FullE2C->push_back(CEMC_FullE2C);
0133     FullE2C->push_back(IHCAL_FullE2C);
0134     FullE2C->push_back(OHCAL_FullE2C);
0135     
0136     FullE3C->push_back(CEMC_FullE3C);
0137     FullE3C->push_back(IHCAL_FullE3C);
0138     FullE3C->push_back(OHCAL_FullE3C);
0139     
0140     FullR->push_back(CEMC_FullR);
0141     FullR->push_back(IHCAL_FullR);
0142     FullR->push_back(OHCAL_FullR);
0143     
0144     FullN->push_back(CEMC_FullN);
0145     FullN->push_back(IHCAL_FullN);
0146     FullN->push_back(OHCAL_FullN);
0147         //std::cout<<__LINE__<<std::endl;
0148     
0149     Full=new std::vector<std::vector<TH1F*>*> {FullEnergy, FullE2C, FullE3C, FullR, FullN};
0150     
0151     TowardsEnergy->push_back(CEMC_TowardsEnergy);
0152     TowardsEnergy->push_back(IHCAL_TowardsEnergy);
0153     TowardsEnergy->push_back(OHCAL_TowardsEnergy);
0154 
0155     TowardsE2C->push_back(CEMC_TowardsE2C);
0156     TowardsE2C->push_back(IHCAL_TowardsE2C);
0157     TowardsE2C->push_back(OHCAL_TowardsE2C);
0158     
0159     TowardsE3C->push_back(CEMC_TowardsE3C);
0160     TowardsE3C->push_back(IHCAL_TowardsE3C);
0161     TowardsE3C->push_back(OHCAL_TowardsE3C);
0162     
0163     TowardsR->push_back(CEMC_TowardsR);
0164     TowardsR->push_back(IHCAL_TowardsR);
0165     TowardsR->push_back(OHCAL_TowardsR);
0166     
0167     TowardsN->push_back(CEMC_TowardsN);
0168     TowardsN->push_back(IHCAL_TowardsN);
0169     TowardsN->push_back(OHCAL_TowardsN);
0170         //std::cout<<__LINE__<<std::endl;
0171     
0172     Towards=new std::vector<std::vector<TH1F*>*> {TowardsEnergy, TowardsE2C, TowardsE3C, TowardsR, TowardsN};
0173     
0174     AwayEnergy->push_back(CEMC_AwayEnergy);
0175     AwayEnergy->push_back(IHCAL_AwayEnergy);
0176     AwayEnergy->push_back(OHCAL_AwayEnergy);
0177 
0178     AwayE2C->push_back(CEMC_AwayE2C);
0179     AwayE2C->push_back(IHCAL_AwayE2C);
0180     AwayE2C->push_back(OHCAL_AwayE2C);
0181     
0182     AwayE3C->push_back(CEMC_AwayE3C);
0183     AwayE3C->push_back(IHCAL_AwayE3C);
0184     AwayE3C->push_back(OHCAL_AwayE3C);
0185     
0186     AwayR->push_back(CEMC_AwayR);
0187     AwayR->push_back(IHCAL_AwayR);
0188     AwayR->push_back(OHCAL_AwayR);
0189     
0190     AwayN->push_back(CEMC_AwayN);
0191     AwayN->push_back(IHCAL_AwayN);
0192     AwayN->push_back(OHCAL_AwayN);
0193         //std::cout<<__LINE__<<std::endl;
0194     
0195     Away=new std::vector<std::vector<TH1F*>*> {AwayEnergy, AwayE2C, AwayE3C, AwayR, AwayN};
0196     
0197     TransEnergy->push_back(CEMC_TransEnergy);
0198     TransEnergy->push_back(IHCAL_TransEnergy);
0199     TransEnergy->push_back(OHCAL_TransEnergy);
0200 
0201     TransE2C->push_back(CEMC_TransE2C);
0202     TransE2C->push_back(IHCAL_TransE2C);
0203     TransE2C->push_back(OHCAL_TransE2C);
0204     
0205     TransE3C->push_back(CEMC_TransE3C);
0206     TransE3C->push_back(IHCAL_TransE3C);
0207     TransE3C->push_back(OHCAL_TransE3C);
0208     
0209     TransR->push_back(CEMC_TransR);
0210     TransR->push_back(IHCAL_TransR);
0211     TransR->push_back(OHCAL_TransR);
0212     
0213     TransN->push_back(CEMC_TransN);
0214     TransN->push_back(IHCAL_TransN);
0215     TransN->push_back(OHCAL_TransN);
0216     
0217     Trans=new std::vector<std::vector<TH1F*>*> {TransEnergy, TransE2C, TransE3C, TransR, TransN};
0218     
0219         //std::cout<<__LINE__<<std::endl;
0220     TDirectory* topdir=file_dir_top[threshold_index];
0221     topdir->cd();
0222     for(int i=0; i<(int)lower_dirs[threshold_index].size(); i++){
0223         //std::cout<<__LINE__<<std::endl;
0224         TDirectory* botdir=lower_dirs[threshold_index][i];
0225         botdir->cd();
0226         //std::cout<<__LINE__<<std::endl;
0227         std::string dir_name=botdir->GetName();
0228         //std::cout<<__LINE__<<std::endl;
0229         std::vector<std::vector<TH1F*>*>* rp;
0230         //std::cout<<__LINE__<<std::endl;
0231         if(dir_name.find("Full") != std::string::npos) rp=Full;
0232         else if(dir_name.find("Towards") != std::string::npos ) rp=Towards; 
0233         else if(dir_name.find("Trans") != std::string::npos ) rp=Trans; 
0234         else if(dir_name.find("Away") != std::string::npos ) rp=Away;   
0235         //std::cout<<__LINE__<<std::endl;
0236         LoadInRegionPlots(botdir, rp);
0237         //std::cout<<__LINE__<<std::endl;
0238     }
0239     RegPlts->at(0)=Full;
0240     RegPlts->at(1)=Towards; 
0241     RegPlts->at(2)=Away;
0242     RegPlts->at(3)=Trans;
0243         //std::cout<<__LINE__<<std::endl;
0244     return;
0245 }
0246 
0247 std::array<std::vector<std::vector<TH1F*>*>*, 4> DrawOneThreshold(TFile* datafile, std::array<std::vector<TPad*>*, 4>* p1, std::array<std::vector<TLegend*>*, 4>* l1, int threshold_index, /*choose which of the set of indicies we use, rather thas spefcific value*/ int style)
0248 {
0249     //p1 is {full, towards, away} {E, E2C, E3C, R, N}
0250         //std::cout<<__LINE__<<std::endl;
0251     std::array<std::vector<std::vector<TH1F*>*>*, 4> RegPlts {};
0252     LoadInPlots(threshold_index, &RegPlts);
0253     //Plots are structured as {full, towards, away, transverse} and one level down {E, E2C, E3C, R, N} then {EMCAL, IHCAL, OHCAL}
0254         //std::cout<<__LINE__<<std::endl;
0255     int offset=0;
0256     std::string run_type="";
0257     if(style==0) run_type="Pedestal";
0258     if(style==1) run_type="Pulser";
0259     if(style==2) run_type="LED";
0260     std::array<std::vector<std::vector<std::string>>, 4> plot_label;
0261         //std::cout<<__LINE__<<std::endl;
0262     plot_label=GetPlotLabels(RegPlts);
0263         //std::cout<<__LINE__<<std::endl;
0264     if(threshold_index == 3 ) offset = 6;
0265     else if (threshold_index > 3) offset = 9; //keep the marker shapes distinguisable
0266     else if (threshold_index > 5) offset= 17;
0267         //std::cout<<__LINE__<<std::endl;
0268     for(int i=0; i<(int) p1->size(); i++){
0269         std::cout<<p1->size() <<std::endl;
0270         for(int j=0; j<(int)p1->at(i)->size(); j++)
0271         {
0272             if(!p1->at(i)->at(j)) continue;
0273             p1->at(i)->at(j)->cd();
0274             if(! RegPlts[i]->at(j)) continue;
0275             bool need_to_cont=false;
0276             for(int k=0; k<(int) RegPlts[i]->at(j)->size(); k++) 
0277                 if(!RegPlts[i]->at(j)->at(k))
0278                     need_to_cont=true;
0279             if(need_to_cont) continue;
0280             if(style== 0){
0281                 RegPlts[i]->at(j)->at(0)->SetLineColor(kGreen);
0282                 RegPlts[i]->at(j)->at(0)->SetMarkerColor(kGreen);
0283             }
0284             if(style== 1){
0285                 RegPlts[i]->at(j)->at(0)->SetLineColor(kTeal+3);
0286                 RegPlts[i]->at(j)->at(0)->SetMarkerColor(kTeal+3);
0287             }
0288             if(style== 2){
0289                 RegPlts[i]->at(j)->at(0)->SetLineColor(kBlack);
0290                 RegPlts[i]->at(j)->at(0)->SetMarkerColor(kBlack);
0291             }
0292             RegPlts[i]->at(j)->at(0)->SetMarkerStyle(20+threshold_index+offset);
0293             RegPlts[i]->at(j)->at(0)->SetMarkerSize(1.5f);
0294             RegPlts[i]->at(j)->at(0)->Draw("same");
0295             l1->at(i)->at(j)->AddEntry(RegPlts[i]->at(j)->at(0), Form("%s  %s ", run_type.c_str(), plot_label[i][j][0].c_str()));
0296 
0297             if(style== 0 ) {
0298                 RegPlts[i]->at(j)->at(1)->SetLineColor(kPink+9);
0299                 RegPlts[i]->at(j)->at(1)->SetMarkerColor(kPink+9);
0300             }
0301             if(style== 1 ) {
0302                 RegPlts[i]->at(j)->at(1)->SetLineColor(kOrange+7);
0303                 RegPlts[i]->at(j)->at(1)->SetMarkerColor(kOrange+7);
0304             }
0305             if(style== 2 ) {
0306                 RegPlts[i]->at(j)->at(1)->SetLineColor(kRed);
0307                 RegPlts[i]->at(j)->at(1)->SetMarkerColor(kRed);
0308             }
0309             
0310             RegPlts[i]->at(j)->at(1)->SetMarkerStyle(20+threshold_index+offset);
0311             RegPlts[i]->at(j)->at(2)->SetMarkerSize(1.5f);
0312             RegPlts[i]->at(j)->at(1)->Draw("same");
0313             l1->at(i)->at(j)->AddEntry(RegPlts[i]->at(j)->at(0), Form("%s %s", run_type.c_str(), plot_label[i][j][0].c_str()));
0314             if(style == 0){
0315                 RegPlts[i]->at(j)->at(2)->SetLineColor(kCyan);
0316                 RegPlts[i]->at(j)->at(2)->SetMarkerColor(kCyan);
0317             }
0318             if(style == 1){
0319                 RegPlts[i]->at(j)->at(2)->SetLineColor(kBlue);
0320                 RegPlts[i]->at(j)->at(2)->SetMarkerColor(kBlue);
0321             }
0322             if(style == 2){
0323                 RegPlts[i]->at(j)->at(2)->SetLineColor(kViolet+1);
0324                 RegPlts[i]->at(j)->at(2)->SetMarkerColor(kViolet+1);
0325             }
0326             RegPlts[i]->at(j)->at(2)->SetMarkerStyle(20+threshold_index+offset);
0327             RegPlts[i]->at(j)->at(2)->SetMarkerSize(1.5f);
0328             RegPlts[i]->at(j)->at(2)->Draw("same");
0329             l1->at(i)->at(j)->AddEntry(RegPlts[i]->at(j)->at(0), Form("%s %s", run_type.c_str(), plot_label[i][j][0].c_str()));
0330         }
0331     }
0332         //std::cout<<__LINE__<<std::endl;
0333     
0334     return RegPlts;
0335 }
0336 /*int CompareRegions(std::map <int, TH1F*> calo_hist, std::string calo, std::string 
0337 {
0338     return 1;
0339 }*/
0340 void PlotRatios(std::vector<std::map<std::string, std::array<std::vector<std::vector<TH1F*>*>*, 4>>> Thrs, std::array<std::vector<TPad*>*,4>* prat, std::array<std::vector<TLegend*>*, 4>* Lt)
0341 {
0342     //compare the pulser and LED to pedestal in all thresholds
0343     int t=0;
0344     for(auto th:Thrs)
0345     {
0346         std::array<std::vector<std::vector<TH1F*>*>*, 4> Ped, Pul, LED;
0347         Ped=th["Pedestal"];
0348         Pul=th["Pulser"];
0349         bool has_led=false;
0350         if(th.find("LED") != th.end()){
0351             has_led=true;
0352             LED=th["LED"];
0353         }
0354         for(int i=0; i<4; i++)
0355         {
0356             std::vector<std::vector<TH1F*>*>* pd_r=new std::vector<std::vector<TH1F*>*>{}, *pl_r=new std::vector<std::vector<TH1F*>*>{}, *ld_r=new std::vector<std::vector<TH1F*>*>{};
0357             pd_r=Ped[i];
0358             pl_r=Pul[i];
0359             if(has_led) ld_r=LED[i];
0360             std::vector<TPad*>* rps=prat->at(i);
0361             std::vector<TLegend*>* lts=Lt->at(i);
0362             for(int j=0; j<(int) pd_r->size(); j++)
0363             {
0364                 TPad* p=rps->at(j);
0365                 TLegend* l=lts->at(j);
0366                 p->cd();
0367                 if(j==0 || j==4 ) continue;
0368                 for(int k=0; k<(int) pd_r->at(j)->size(); k++)
0369                 {
0370                     if(!pd_r->at(j)->at(k)) continue;
0371                     TH1F* ped_hist=(TH1F*)pd_r->at(j)->at(k)->Clone();
0372                     if(pl_r->at(j)->at(k)->GetEntries() == 0 ) continue;
0373                     ped_hist->Divide(pl_r->at(j)->at(k));
0374                     ped_hist->SetYTitle(" Pedestal / (Pulser, LED) ");
0375                     ped_hist->GetYaxis()->SetTitleOffset(1);
0376                     ped_hist->GetYaxis()->SetTitleSize(0.05f);
0377                     int offset=0;
0378                     if(t== 5) offset=1;
0379                     if(t==6 ) offset=9; 
0380                     ped_hist->SetMarkerStyle(24+t+offset);
0381                     std::string lb="";
0382                     std::string plt_name, thr, cal;
0383                     plt_name=ped_hist->GetName();
0384                     std::stringstream  str_plt (plt_name);
0385                     std::string subparts;
0386                     bool get_name=false;
0387                     while(std::getline(str_plt, subparts, '_')){
0388                         if( get_name){
0389                             thr=subparts;
0390                             break;
0391                         }
0392                         else if(subparts.find("CAL") != std::string::npos){
0393                             get_name=true;
0394                             cal=subparts;
0395                             continue;
0396                         }
0397                         else continue;
0398                     }
0399                     lb=cal+", E_{tower} #geq "+thr+" MeV";
0400                     std::string lbp=" Pedestal / Pulser : "+lb;
0401                     l->AddEntry(ped_hist, lbp.c_str());
0402                     ped_hist->Draw("same");
0403                     if(has_led ){
0404                         TH1F* ped_hist_l=(TH1F*)pd_r->at(j)->at(k)->Clone();
0405                         if(ld_r->at(j)->at(k)->GetEntries() == 0 ) continue;
0406                         ped_hist_l->Divide(ld_r->at(j)->at(k));
0407                         ped_hist_l->SetMarkerColor(ld_r->at(j)->at(k)->GetMarkerColor());
0408                         ped_hist_l->SetLineColor(ld_r->at(j)->at(k)->GetLineColor());
0409                         ped_hist_l->SetYTitle(" Pedestal / (Pulser, LED) ");
0410                         ped_hist_l->GetYaxis()->SetTitleOffset(1);
0411                         ped_hist_l->GetYaxis()->SetTitleSize(0.05f);
0412                         ped_hist_l->SetMarkerStyle(24+t+offset);
0413                         std::string lbl=" Pedestal / LED : "+lb;
0414                         l->AddEntry(ped_hist_l, lbl.c_str());
0415                         ped_hist_l->Draw("same");
0416                     }
0417                 }
0418             }
0419         }
0420         t++;            
0421     }
0422     return;
0423 }
0424 /*int E2C_and_E3C_with_thresholds(TFile* datafile, )
0425 {
0426     
0427 }*/
0428 int LocalRunThresholdScan(TFile* Pedestal_data, int ped_run, TFile* Pulser_data, int pulse_run, TFile* LED_data=NULL, int led_run = 0, bool include_led=false)
0429 {
0430     SetsPhenixStyle();
0431     Pedestal_data->cd();
0432     for(int i=0; i< 7; i++){
0433         TDirectory* t=(TDirectory*)Pedestal_data->Get(Form("Threshold_Index_%d", i));
0434         file_dir_top.push_back(t);
0435         t->cd();
0436         TDirectory* ft=(TDirectory*)t->Get(Form("Full_Calorimeter_Threshold_index_%d", i));
0437         TDirectory* tw=(TDirectory*)t->Get(Form("Towards_Region_Threshold_index_%d", i));
0438         TDirectory* aw=(TDirectory*)t->Get(Form("Away_Region_Threshold_index_%d", i));
0439         TDirectory* trans=(TDirectory*)t->Get(Form("Transverse_Region_Threshold_index_%d", i));
0440         std::array<TDirectory*, 4> sub {ft, tw, aw, trans};
0441         lower_dirs.push_back(sub);
0442     }
0443     std::cout<<"Got the directory Names"<<std::endl;
0444     std::array<std::vector<TLegend*>*, 4> LegendTitles, PlotLeg;
0445     std::array<std::vector<TPad*>*, 4> p_main, p_ratio;
0446     std::array<std::vector<TCanvas*>*, 4> Canvases;
0447     for(int i= 0; i<4; i++)
0448     {
0449         std::string region;
0450         std::vector<TLegend*> *LT=new std::vector<TLegend*>{}, *PL=new std::vector<TLegend*>{};
0451         std::vector<TPad*> *P1=new std::vector<TPad*>{}, *P2=new std::vector<TPad*>{};
0452         std::vector<TCanvas*> *cs=new std::vector<TCanvas*>{};
0453         if(i==0) region="Full Calorimeter";
0454         if(i==1) region="Lead Region";
0455         if(i==2) region="Away Region";
0456         if(i==3) region="Transverse Regions";
0457         //std::cout<<__LINE__<<std::endl;
0458         for(int j=0; j < 5; j++)
0459         {
0460             TCanvas* c1=new TCanvas(Form("c_%d_%d", i, j), Form("c_%d_%d", i, j));
0461             c1->cd();
0462             float ymin=0.33;
0463             if( j == 0 || j == 4) ymin=0; //no need for the ratio plots in E and N
0464             TPad* p1=new TPad(Form("p_1_%d_%d", i, j), Form("p_1_%d_%d", i, j), 0, ymin, 1, 1);
0465             TPad* p2=new TPad(Form("p_2_%d_%d", i, j), Form("p_2_%d_%d", i, j), 0, 0, 1, 0.3);
0466             //std::cout<<__LINE__<<std::endl;   
0467             TLegend* l1=new TLegend(0.7, 0.5, 0.9, 0.95);
0468             l1->SetFillStyle(0);
0469             l1->SetFillColor(0);
0470             l1->SetBorderSize(0);
0471             l1->SetTextSize(0.1f);
0472             l1->AddEntry("", "#bf{#it{sPHENIX}} Internal", "");
0473             l1->AddEntry("", "Calorimeter Calibration Running", "");
0474             l1->AddEntry("", Form("Pedestal Run %d", ped_run), "");
0475             l1->AddEntry("", Form("Pulser Run %d", pulse_run), "");
0476             if(include_led) l1->AddEntry("", Form("LED Run %d", led_run), "");
0477             l1->AddEntry("", region.c_str(), "");
0478             std::string var;
0479             if(j==0) var="#sum_{Towers} Energy";
0480             if(j==1) var="2 Point Energy Correlator";
0481             if(j==2) var="3 Point Energy Correlator";
0482             if(j==3) var="Geometric Seperation of Non-zero Energy Towers";
0483             if(j==4) var="Number of non-zero energy towers";
0484             l1->AddEntry("", var.c_str(), "");
0485             LT->push_back(l1);
0486             //std::cout<<__LINE__<<std::endl;
0487             TLegend* l2=new TLegend(0.1, 0.6, 0.5, 0.85);
0488             l2->SetFillStyle(0);
0489             l2->SetFillColor(0);
0490             l2->SetBorderSize(0);
0491             l2->SetTextSize(0.01f);
0492             l2->SetNColumns(3);
0493             PL->push_back(l2);
0494                 
0495             P1->push_back(p1);
0496             P2->push_back(p2);
0497             cs->push_back(c1);
0498         }   
0499         LegendTitles[i]=LT;
0500         PlotLeg[i]=PL;
0501         p_main[i]=P1;
0502         p_ratio[i]=P2;
0503         Canvases[i]=cs;
0504         //std::cout<<__LINE__<<std::endl;
0505     }
0506     std::vector<std::map<std::string, std::array<std::vector<std::vector<TH1F*>*>*, 4>> > threshold_maps {}; 
0507     for(int i=0; i<7; i++)
0508     {
0509         //std::cout<<__LINE__<<std::endl;
0510         std::map<std::string, std::array<std::vector<std::vector<TH1F*>*>*, 4>> tm;
0511         std::cout<<p_main[0]->size()<<std::endl;
0512         std::array<std::vector<std::vector<TH1F*>*>*, 4> rg_1=DrawOneThreshold( Pedestal_data, &p_main, &PlotLeg, i, 0);
0513         tm["Pedestal"]=rg_1;
0514         //std::cout<<__LINE__<<std::endl;
0515         std::array<std::vector<std::vector<TH1F*>*>*, 4> rg_2=DrawOneThreshold( Pulser_data, &p_main, &PlotLeg, i, 0);
0516         tm["Pulser"]=rg_2;
0517         //std::cout<<__LINE__<<std::endl;
0518         if(include_led){
0519             std::array<std::vector<std::vector<TH1F*>*>*, 4> rg_3=DrawOneThreshold( LED_data, &p_main, &PlotLeg, i, 0);
0520             tm["LED"]=rg_3;
0521         }
0522         threshold_maps.push_back(tm);
0523         //std::cout<<__LINE__<<std::endl;
0524     }
0525         //std::cout<<__LINE__<<std::endl;
0526     PlotRatios(threshold_maps, &p_ratio, &PlotLeg);
0527         //std::cout<<__LINE__<<std::endl;
0528     for(int i=0; i<(int)Canvases.size(); i++)
0529     {
0530         std::string region="";
0531         if(i==0) region="Full";
0532         if(i==1) region="Lead";
0533         if(i==2) region="Away";
0534         if(i==3) region="Transverse";
0535         
0536         for(int j=0; j<(int)Canvases[i]->size(); j++)
0537         {
0538             Canvases[i]->at(j)->cd();
0539             p_main[i]->at(j)->Draw();
0540             if(j >= 1 && j <=3 ) p_ratio[i]->at(j)->Draw();
0541             p_main[i]->at(j)->cd();
0542             LegendTitles[i]->at(j)->Draw();
0543             PlotLeg[i]->at(j)->Draw();
0544             std::string var;
0545             if(j==0) var="E";
0546             if(j==1) var="E2C";
0547             if(j==2) var="E3C";
0548             if(j==3) var="RL";
0549             if(j==4) var="N";
0550             Canvases[i]->at(j)->Print(Form("~/local_run/thresh_scan_%s_var_%s.pdf", region.c_str(), var.c_str())); 
0551             Canvases[i]->at(j)->Print(Form("~/local_run/thresh_scan_%s_var_%s.ps", region.c_str(), var.c_str())); 
0552         }
0553     }
0554     return 0;
0555 }
0556 int EnergyDistr(TFile* f1, int run_num, std::string type)
0557 {
0558     SetsPhenixStyle();
0559     TCanvas* c1=new TCanvas(Form("EMC_%d_%s", run_num, type.c_str()), Form("EMC_%d_%s", run_num, type.c_str())); 
0560     TCanvas* c2=new TCanvas(Form("IHC_%d_%s", run_num, type.c_str()), Form("IHC_%d_%s", run_num, type.c_str())); 
0561     TCanvas* c3=new TCanvas(Form("OHC_%d_%s", run_num, type.c_str()), Form("OHC_%d_%s", run_num, type.c_str())); 
0562     std::vector<TCanvas*> cs {c1, c2, c3};
0563     for(int i=0; i<(int)cs.size(); i++)
0564     {
0565         cs[i]->cd();
0566         TPad* p1=new TPad("p1", "p1", 0, 0.51, 0.49, 0.75);
0567         TPad* p2=new TPad("p2", "p2", 0.51, 0.51, 0.9, 0.75);
0568         TPad* p3=new TPad("p3", "p3", 0, 0.25, 0.49, 0.5);
0569         TPad* p4=new TPad("p4", "p4", 0.51, 0.25, 0.9, 0.5);
0570         TPad* p5=new TPad("p5", "p5", 0, 0, 0.49, 0.24);
0571         TPad* p6=new TPad("p6", "p6", 0.51, 0, 0.9, 0.24);
0572         TPad* p7=new TPad("p7", "p7", 0, 0.76, 0.49, 0.95);
0573         p7->cd();
0574         TH2F* h1, *h2, *h3, *h4, *h5, *h6, *h7;
0575         float z_max=0.;
0576         if(i==0)
0577         {
0578             h1=(TH2F*)f1->Get("emcal_energy_10_MeV");
0579             h2=(TH2F*)f1->Get("emcal_energy_21_MeV");
0580             h3=(TH2F*)f1->Get("emcal_energy_33_MeV");
0581             h4=(TH2F*)f1->Get("emcal_energy_44_MeV");
0582             h5=(TH2F*)f1->Get("emcal_energy_56_MeV");
0583             h6=(TH2F*)f1->Get("emcal_energy_68_MeV");
0584             h7=(TH2F*)f1->Get("emcal_energy_80_MeV");
0585         }
0586         if(i==1)
0587         {
0588             h1=(TH2F*)f1->Get("ihcal_energy_5_MeV");
0589             h2=(TH2F*)f1->Get("ihcal_energy_6_MeV");
0590             h3=(TH2F*)f1->Get("ihcal_energy_8_MeV");
0591             h4=(TH2F*)f1->Get("ihcal_energy_10_MeV");
0592             h5=(TH2F*)f1->Get("ihcal_energy_11_MeV");
0593             h6=(TH2F*)f1->Get("ihcal_energy_13_MeV");
0594             h7=(TH2F*)f1->Get("ihcal_energy_15_MeV");
0595         
0596         }
0597         if(i==2)
0598         {
0599             h1=(TH2F*)f1->Get("ohcal_energy_10_MeV");
0600             h2=(TH2F*)f1->Get("ohcal_energy_21_MeV");
0601             h3=(TH2F*)f1->Get("ohcal_energy_33_MeV");
0602             h4=(TH2F*)f1->Get("ohcal_energy_44_MeV");
0603             h5=(TH2F*)f1->Get("ohcal_energy_56_MeV");
0604             h6=(TH2F*)f1->Get("ohcal_energy_68_MeV");
0605             h7=(TH2F*)f1->Get("ohcal_energy_80_MeV");
0606         }
0607         z_max=h1->GetMaximum();
0608         h2->GetZaxis()->SetRangeUser(0, z_max);
0609         h3->GetZaxis()->SetRangeUser(0, z_max);
0610         h4->GetZaxis()->SetRangeUser(0, z_max);
0611         h5->GetZaxis()->SetRangeUser(0, z_max);
0612         h6->GetZaxis()->SetRangeUser(0, z_max);
0613         h7->GetZaxis()->SetRangeUser(0, z_max);
0614         h1->Draw("colz");
0615         TLegend* l1=new TLegend(0.2, 0.9, 0.2, 1);
0616         l1->SetTextSize(0.1f);
0617         l1->SetFillStyle(0);
0618         l1->SetFillColor(0);
0619         l1->SetBorderSize(0);
0620         l1->AddEntry("", h1->GetTitle(), "");
0621         l1->Draw();
0622         cs[i]->cd();
0623         p7->Draw();
0624         TLegend* l=new TLegend(0.4, 0.8, 1, 1);
0625         l->SetFillStyle(0);
0626         l->SetFillColor(0);
0627         l->SetBorderSize(0);
0628         cs[i]->cd();
0629         std::string Calo="Electromagnetic";
0630         if(i==1) Calo="Inner Hadronic";
0631         else if (i==2) Calo="Outer Hadronic";
0632         l->AddEntry("", "#bf{#it{sPHENIX}} Internal", "");
0633         l->AddEntry("", Form("%s Calorimeter", Calo.c_str()), "");
0634         l->AddEntry("", Form("%s Run %d", type.c_str(), run_num), "");
0635         l->Draw();
0636         p1->cd();
0637         h2->Draw("colz");
0638         TLegend* l2=new TLegend(0, 0.9, 0.2, 1);
0639         l2->SetTextSize(0.1f);
0640         l2->SetFillStyle(0);
0641         l2->SetFillColor(0);
0642         l2->SetBorderSize(0);
0643         l2->AddEntry("", h2->GetTitle(), "");
0644         l2->Draw();
0645         cs[i]->cd();
0646         p1->Draw();
0647         
0648         p3->cd();
0649         h2->Draw("colz");
0650         TLegend* l3=new TLegend(0, 0.9, 0.2, 1);
0651         l3->SetTextSize(0.1f);
0652         l3->SetFillStyle(0);
0653         l3->SetFillColor(0);
0654         l3->SetBorderSize(0);
0655         l3->AddEntry("", h3->GetTitle(), "");
0656         l3->Draw();
0657         cs[i]->cd();
0658         p3->Draw();
0659 
0660         p5->cd();
0661         h4->Draw("colz");
0662         TLegend* l4=new TLegend(0, 0.9, 0.2, 1);
0663         l4->SetTextSize(0.1f);
0664         l4->SetFillStyle(0);
0665         l4->SetFillColor(0);
0666         l4->SetBorderSize(0);
0667         l4->AddEntry("", h4->GetTitle(), "");
0668         l4->Draw();
0669         cs[i]->cd();
0670         p5->Draw();
0671             
0672         p2->cd();
0673         h5->Draw("colz");
0674         TLegend* l5=new TLegend(0, 0.9, 0.2, 1);
0675         l5->SetTextSize(0.1f);
0676         l5->SetFillStyle(0);
0677         l5->SetFillColor(0);
0678         l5->SetBorderSize(0);
0679         l5->AddEntry("", h5->GetTitle(), "");
0680         l5->Draw();
0681         cs[i]->cd();
0682         p2->Draw();
0683         
0684         p4->cd();
0685         h6->Draw("colz");
0686         TLegend* l6=new TLegend(0, 0.9, 0.2, 1);
0687         l6->SetTextSize(0.1f);  
0688         l6->SetFillStyle(0);
0689         l6->SetFillColor(0);
0690         l6->SetBorderSize(0);
0691         l6->AddEntry("", h6->GetTitle(), "");
0692         l6->Draw();
0693         cs[i]->cd();
0694         p4->Draw();
0695         
0696         p6->cd();
0697         h7->Draw("colz");
0698         TLegend* l7=new TLegend(0, 0.9, 0.2, 1);
0699         l7->SetTextSize(0.1f);
0700         l7->SetFillStyle(0);
0701         l7->SetFillColor(0);
0702         l7->SetBorderSize(0);
0703         l7->AddEntry("", h7->GetTitle(), "");
0704         l7->Draw();
0705         cs[i]->cd();
0706         p6->Draw();
0707     }
0708     cs[0]->Print(Form("~/EMCAL_run_%d_type_%s.pdf", run_num, type.c_str()));
0709     cs[1]->Print(Form("~/IHCAL_run_%d_type_%s.pdf", run_num, type.c_str()));
0710     cs[2]->Print(Form("~/OHCAL_run_%d_type_%s.pdf", run_num, type.c_str()));
0711     return 0;
0712 }   
0713 TH1F* getReflected(TH1F* norm)
0714 {
0715     TH1F* rf = (TH1F*) norm->Clone();
0716     rf->SetName(Form("%s_reflected", norm->GetName()));
0717     rf->SetTitle(Form("%s |E|", norm->GetTitle()));
0718     for(int i=0; i<rf->GetNbinsX(); i++)
0719     {
0720         rf->SetBinContent(i, 0);
0721     }
0722     for(int i= 0; i<norm->GetNbinsX(); i++)
0723     {
0724         float bin_center = norm->GetBinCenter(i);
0725         if( bin_center > 0 ) break;
0726         float bin_val = norm->GetBinContent(i);
0727         rf->Fill(abs(bin_center), bin_val);
0728     }
0729     return rf;
0730 }
0731 TH1F* regeneratePlot(TH1F* energies)
0732 {
0733     TH1F* thres=(TH1F*) energies->Clone();
0734     std::vector<int> freq {};
0735     float max_val = 0;
0736     for(int i = 0; i<energies->GetNbinsX(); i++)
0737     {
0738         float bin_center = energies->GetBinCenter(i);
0739         if(bin_center < 0 ) continue;
0740         freq.push_back(0);
0741         if(energies->GetBinContent(i) > 0 ) max_val = bin_center;
0742     }
0743     for(int i = 0;  i < energies->GetNbinsX(); i++)
0744     {
0745         float bin_center = energies->GetBinCenter(i);
0746         if(bin_center < 0 ) continue;
0747         if((int)bin_center >= (int)max_val) break;
0748         for(int j=(int) bin_center; j < max_val; j++)
0749         {
0750             freq[j]+=energies->GetBinContent(i); 
0751         }
0752     }
0753     for(int i = 0; i<(int)freq.size(); i++){
0754         thres->Fill(i, freq.at(i));
0755     }
0756     return thres;
0757 }
0758 double fitTheNegSide(TH1F* data_energy, TCanvas* c, TLegend* l, TLegend* ll, float n_evt, int cal)
0759 {
0760     c->cd();
0761     c->SetLogy();
0762     TH1F* negative_side=new TH1F(Form("neg_data_%s", data_energy->GetName()), Form("Negative Energy Side %s", data_energy->GetTitle()), data_energy->GetNbinsX(), data_energy->GetBinLowEdge(1), data_energy->GetBinLowEdge(data_energy->GetNbinsX()));
0763     if(cal==2) data_energy->Rebin(4);
0764     for(int i=0; i<data_energy->GetNbinsX(); i++)
0765     {
0766         float E=data_energy->GetBinCenter(i);
0767         if(E > 0 ) break;
0768         int N=data_energy->GetBinContent(i);
0769         for(int j=0; j<N; j++){
0770             negative_side->Fill(E);
0771             negative_side->Fill(std::abs(E));
0772         }
0773     }
0774     data_energy->Scale(1/(float)n_evt);
0775     negative_side->Scale(1/(float)n_evt);
0776     if(cal==2){
0777         data_energy->Scale(1/4.0);
0778         negative_side->Scale(1/4.0);
0779     }
0780     TF1* f_fit=new TF1("fit","gaus",data_energy->GetBinLowEdge(1), data_energy->GetBinLowEdge(data_energy->GetNbinsX()));
0781     TFitResultPtr p=negative_side->Fit(f_fit, "S");
0782     double sigma = p->Parameter(2);
0783     data_energy->Draw();
0784     if(cal==0){
0785         data_energy->GetXaxis()->SetRangeUser(-300, 999);
0786         data_energy->GetYaxis()->SetRangeUser(0.01, 1100);
0787     }
0788     else if(cal==1){
0789         data_energy->GetXaxis()->SetRangeUser(-50, 600);
0790         data_energy->GetYaxis()->SetRangeUser(0.01, 500);
0791     }
0792     else{
0793         data_energy->GetXaxis()->SetRangeUser(-100, 600);
0794         data_energy->GetYaxis()->SetRangeUser(0.01, 500);
0795     }
0796 
0797     negative_side->SetMarkerColor(kPink+1);
0798     negative_side->SetLineColor(kPink+1);
0799 //  negative_side->SetMarkerStyle(21);
0800     negative_side->Draw("same");
0801     f_fit->SetLineColor(kBlack);
0802     f_fit->Draw("same");
0803     l->AddEntry(negative_side, "E_{tow} < 0, Reflected");
0804     l->AddEntry(f_fit, Form("#splitline{Gaussian Fit to Negative Side noise}{ #splitline{#mu = %.3g #pm %.2g MeV}{ #sigma = %3.3g #pm %.1g MeV }}", p->Parameter(1),p->ParError(1), sigma, p->ParError(2)), "l");
0805     l->Draw();
0806     ll->Draw();
0807     return sigma;
0808 }
0809         
0810 int OneDEnergyPlots(TFile* fpedestal, int run_ph, int run_pe, TFile* fdata, int run_d, TFile* fsim10, TFile* fsim30, TFile* fsimMB)
0811 {
0812     SetsPhenixStyle();
0813     TCanvas* c1=new TCanvas("OHE", "Outer HCal Energy");
0814     TCanvas* c2=new TCanvas("IHE", "Inner HCal Energy");
0815     TCanvas* c3=new TCanvas("EME", "EM Cal Energy");
0816     TCanvas* c4=new TCanvas("OHH", "Outer HCal Hits");
0817     TCanvas* c5=new TCanvas("IHH", "Inner HCal Hits");
0818     TCanvas* c6=new TCanvas("EMH", "EM Cal Hits");
0819     TCanvas* c7=new TCanvas("AE", "AllCal Energy");
0820     TCanvas* c8=new TCanvas("AH", "All Cal Hits");
0821     /*TCanvas* cr1=new TCanvas("OHEr", "Outer HCal Energy");
0822     TCanvas* cr3=new TCanvas("IHEr", "Inner HCal Energy");
0823     TCanvas* cr5=new TCanvas("EMEr", "EM Cal Energy");
0824     TCanvas* cr2=new TCanvas("OHHr", "Outer HCal Hits");
0825     TCanvas* cr4=new TCanvas("IHHr", "Inner HCal Hits");
0826     TCanvas* cr6=new TCanvas("EMHr", "EM Cal Hits");
0827     TCanvas* cr7=new TCanvas("AEr", "AllCal Energy");
0828     TCanvas* cr8=new TCanvas("AHr", "All Cal Hits");*/
0829     std::vector<TFile*> files {fpedestal, fdata, fsim10, fsim30, fsimMB};
0830     std::vector<TLegend*> lt {}, ll {}; //lt_ref {};
0831     std::vector<TCanvas*> Canvases {c1, c4, c2, c5, c3, c6, c7, c8};
0832 //  std::vector<TCanvas*> Cr {cr1, cr2, cr3, cr4, cr5, cr6, cr7, cr8};
0833     std::vector<TPad*> pad_val, pad_rats;
0834     for(int i=0; i<8; i++)
0835     {
0836         Canvases[i]->cd();
0837         TPad* p1=new TPad("p1", "p1", 0, 0.35, 1, 1);
0838         TPad* p2=new TPad("p2", "p2", 0, 0, 1, 0.33);
0839         p1->cd();
0840         p1->SetLogy();
0841         Canvases[i]->SetLogy(); 
0842         if(i%2 == 1) Canvases[i]->SetLogx();
0843         float xmin=0.5;
0844         float xmax=0.85;
0845         if(i%2 == 1 ){
0846              xmin=0.2;
0847              xmax=0.35;
0848         }
0849         TLegend* l1=new TLegend(0.5, 0.7, 0.85, 1);
0850         TLegend* l=new TLegend(xmin, 0.2, xmax, 0.45);
0851         TLegend* l2=new TLegend(xmin, 0.2, xmax, 0.45);
0852         l1->SetFillStyle(0);
0853         l1->SetFillColor(0);
0854         l1->SetBorderSize(0);
0855         l->SetFillStyle(0);
0856         l->SetFillColor(0);
0857         l->SetBorderSize(0);
0858         l2->SetFillColor(0);
0859         l2->SetBorderSize(0);
0860         l->SetTextSize(0.04f);
0861         l1->SetTextSize(0.04f);
0862         l2->SetTextSize(0.04f);
0863         l1->AddEntry("", "#it{#bf{sPHENIX}} Preliminary", "");
0864         l1->AddEntry("", "p+p #sqrt{s} = 200 GeV", "");
0865         //l1->SetFillColorAlpha(0);
0866     //  l->SetFillColorAlpha(0);
0867         
0868         if(i==0){
0869             l1->AddEntry("", "Outer Hadronic Calorimeter", "");
0870         //  l1->AddEntry("", "Tower Energy", "");
0871         }
0872         if(i==1){
0873             l1->AddEntry("", "Outer Hadronic Calorimeter", "");
0874         //  l1->AddEntry("", "Tower hits above threshold", "");
0875         }
0876         if(i==2){
0877             l1->AddEntry("", "Inner Hadronic Calorimeter", "");
0878         //  l1->AddEntry("", "Tower Energy", "");
0879         }
0880         if(i==3){
0881             l1->AddEntry("", "Inner Hadronic Calorimeter", "");
0882         //  l1->AddEntry("", "Tower hits above threshold", "");
0883         }
0884         if(i==4){
0885             l1->AddEntry("", "Electromagnetic Calorimeter", "");
0886         //  l1->AddEntry("", "Tower Energy", "");
0887         }
0888         if(i==5){
0889             l1->AddEntry("", "Electromagnetic Calorimeter", "");
0890         //  l1->AddEntry("", "Tower hits above threshold", "");
0891         }
0892         if(i==6){
0893             l1->AddEntry("", "All Calorimeters binned to HCAL", "");
0894         //  l1->AddEntry("", "Tower Energy", "");
0895         }
0896         if(i==7){
0897             l1->AddEntry("", "All Calorimeters binned to HCAL", "");
0898         //  l1->AddEntry("", "Tower hits above threshold", "");
0899         }
0900         lt.push_back(l);
0901         ll.push_back(l1);
0902         pad_val.push_back(p1);
0903         pad_rats.push_back(p2); 
0904     }
0905     std::vector <std::string> label {"Pedestal", "p+p, 10 GeV #leq Lead jet p_{T} #leq 30 GeV ", "Pythia8 + GEANT4 + Noise, Lead jet p_{T} #geq 10 GeV","Pythia8 + GEANT4 + Noise, Lead jet p_{T} #geq 30 GeV", "Pythia, Minimum bias Detroit Tune"};
0906 
0907     std::array<float, 6> maxes {0.,0.,0.,0.,0.,0.};
0908     std::vector<std::array<TH1F*,6>> rats{};
0909     
0910 /*  for(int i=0; i<(int)files.size(); i++)
0911     {
0912         if(i==0) continue;
0913         TFile* f=files[i];
0914         TH1F* oh_e = (TH1F*) f->Get("ohcal_energy")->Clone();
0915         TH1F* oh_h = (TH1F*) f->Get("ohc_hit")->Clone();
0916         TH1F* ih_e = (TH1F*) f->Get("ihcal_energy")->Clone();
0917         TH1F* ih_h = (TH1F*) f->Get("ihc_hit")->Clone();
0918         TH1F* em_e = (TH1F*) f->Get("emcal_energy")->Clone();
0919         TH1F* em_h = (TH1F*) f->Get("emc_hit")->Clone();
0920     //  TH1F* a_e = (TH1F*) f->Get("allcal_energy")->Clone();
0921     //  TH1F* a_h = (TH1F*) f->Get("allc_hit")->Clone();
0922         TH1F* oh_Et = (TH1F*) f->Get("ohcal_total_E");
0923         TH1F* ih_Et = (TH1F*) f->Get("ihcal_total_E");
0924         TH1F* em_Et = (TH1F*) f->Get("emcal_total_E");
0925     //  TH1F* a_Et = (TH1F*) f->Get("allcal_total_E");
0926         TFile* f1=files[1];
0927         TH1F* oh_e1 = (TH1F*) f1->Get("ohcal_energy")->Clone();
0928         TH1F* oh_h1 = (TH1F*) f1->Get("ohc_hit")->Clone();
0929         TH1F* ih_e1 = (TH1F*) f1->Get("ihcal_energy")->Clone();
0930         TH1F* ih_h1 = (TH1F*) f1->Get("ihc_hit")->Clone();
0931         TH1F* em_e1 = (TH1F*) f1->Get("emcal_energy")->Clone();
0932         TH1F* em_h1 = (TH1F*) f1->Get("emc_hit")->Clone();
0933     //  TH1F* a_e1 = (TH1F*) f1->Get("allcal_energy")->Clone();
0934     //  TH1F* a_h1 = (TH1F*) f1->Get("allc_hit")->Clone();
0935         TH1F* oh_Et1 = (TH1F*) f1->Get("ohcal_total_E");
0936         TH1F* ih_Et1 = (TH1F*) f1->Get("ihcal_total_E");
0937         TH1F* em_Et1 = (TH1F*) f1->Get("emcal_total_E");
0938     //  TH1F* a_Et1 = (TH1F*) f1->Get("allcal_total_E");
0939         int n_evt_oh=oh_Et->GetEntries();
0940         int n_evt_ih=ih_Et->GetEntries();
0941         int n_evt_em=em_Et->GetEntries();
0942     //  int n_evt_all=a_Et->GetEntries();
0943         oh_e->Scale(1/(float)n_evt_oh);
0944         oh_h->Scale(1/(float)n_evt_oh);
0945         ih_e->Scale(1/(float)n_evt_ih);
0946         ih_h->Scale(1/(float)n_evt_ih);
0947         em_e->Scale(1/(float)n_evt_em);
0948         em_h->Scale(1/(float)n_evt_em);
0949         //a_hScale(1/(float)n_evt_all);
0950         //a_hScale(1/(float)n_evt_all);
0951         oh_e->GetXaxis()->SetRangeUser(0.1, 4000);
0952         em_e->GetXaxis()->SetRangeUser(0.1, 5000);
0953         ih_h->GetXaxis()->SetRangeUser(0.1, 1600);*/
0954         
0955 /*      int n_evt_oh1=oh_Et1->GetEntries();
0956         int n_evt_ih1=ih_Et1->GetEntries();
0957         int n_evt_em1=em_Et->GetEntries();
0958     //  int n_evt_all1=a_Et1->GetEntries();
0959         oh_e1->Scale(1/(float)n_evt_oh1);
0960         oh_h1->Scale(1/(float)n_evt_oh1);
0961         ih_e1->Scale(1/(float)n_evt_ih1);
0962         ih_h1->Scale(1/(float)n_evt_ih1);
0963         em_e1->Scale(1/(float)n_evt_em1);
0964         em_h1->Scale(1/(float)n_evt_em1);
0965     //  a_e1->Scale(1/(float)n_evt_all1);
0966     //  a_h1->Scale(1/(float)n_evt_all1);
0967         oh_e1->GetXaxis()->SetRangeUser(0.1, 4000);
0968         em_e1->GetXaxis()->SetRangeUser(0.1, 5000);
0969         ih_e1->GetXaxis()->SetRangeUser(0.1, 1500);*/
0970 /*      if(i==0){
0971             oh_e->SetLineColor(kGreen);
0972             oh_e->SetMarkerColor(kGreen);
0973             oh_h->SetLineColor(kGreen);
0974             oh_h->SetMarkerColor(kGreen);
0975             ih_e->SetLineColor(kGreen);
0976             ih_e->SetMarkerColor(kGreen);
0977             ih_h->SetLineColor(kGreen);
0978             ih_h->SetMarkerColor(kGreen);
0979             em_e->SetLineColor(kGreen);
0980             em_e->SetMarkerColor(kGreen);
0981             em_h->SetLineColor(kGreen);
0982             em_h->SetMarkerColor(kGreen);
0983             //a_hSetLineColor(kGreen);
0984             //a_hSetMarkerColor(kGreen);
0985             //a_hSetLineColor(kGreen);
0986             //a_hSetMarkerColor(kGreen);
0987         }
0988         if(i==1){
0989             oh_e->SetLineColor(kBlack);
0990             oh_e->SetMarkerColor(kBlack);
0991             oh_h->SetLineColor(kBlack);
0992             oh_h->SetMarkerColor(kBlack);
0993             ih_e->SetLineColor(kBlack);
0994             ih_e->SetMarkerColor(kBlack);
0995             ih_h->SetLineColor(kBlack);
0996             ih_h->SetMarkerColor(kBlack);
0997             em_e->SetLineColor(kBlack);
0998             em_e->SetMarkerColor(kBlack);
0999             em_h->SetLineColor(kBlack);
1000             em_h->SetMarkerColor(kBlack);
1001             //a_hSetLineColor(kBlack);
1002             //a_hSetMarkerColor(kBlack);
1003             //a_hSetLineColor(kBlack);
1004             //a_hSetMarkerColor(kBlack);
1005         }
1006         if(i==2){
1007             oh_e->SetLineColor(kBlue);
1008             oh_e->SetMarkerColor(kBlue);
1009             oh_h->SetLineColor(kBlue);
1010             oh_h->SetMarkerColor(kBlue);
1011             ih_e->SetLineColor(kBlue);
1012             ih_e->SetMarkerColor(kBlue);
1013             ih_h->SetLineColor(kBlue);
1014             ih_h->SetMarkerColor(kBlue);
1015             em_e->SetLineColor(kBlue);
1016             em_e->SetMarkerColor(kBlue);
1017             em_h->SetLineColor(kBlue);
1018             em_h->SetMarkerColor(kBlue);
1019             //a_hSetLineColor(kBlue);
1020             //a_hSetMarkerColor(kBlue);
1021             //a_hSetLineColor(kBlue);
1022             //a_hSetMarkerColor(kBlue);
1023         }
1024         if(i==3){
1025             oh_e->SetLineColor(kRed);
1026             oh_e->SetMarkerColor(kRed);
1027             oh_h->SetLineColor(kRed);
1028             oh_h->SetMarkerColor(kRed);
1029             ih_e->SetLineColor(kRed);
1030             ih_e->SetMarkerColor(kRed);
1031             ih_h->SetLineColor(kRed);
1032             ih_h->SetMarkerColor(kRed);
1033             em_e->SetLineColor(kRed);
1034             em_e->SetMarkerColor(kRed);
1035             em_h->SetLineColor(kRed);
1036             em_h->SetMarkerColor(kRed);
1037             //a_hSetLineColor(kRed);
1038             //a_hSetMarkerColor(kRed);
1039             //a_hSetLineColor(kRed);
1040             //a_hSetMarkerColor(kRed);
1041         }
1042         if(i==4){
1043             oh_e->SetLineColor(kViolet+1);
1044             oh_e->SetMarkerColor(kViolet+1);
1045             oh_h->SetLineColor(kViolet+1);
1046             oh_h->SetMarkerColor(kViolet+1);
1047             ih_e->SetLineColor(kViolet+1);
1048             ih_e->SetMarkerColor(kViolet+1);
1049             ih_h->SetLineColor(kViolet+1);
1050             ih_h->SetMarkerColor(kViolet+1);
1051             em_e->SetLineColor(kViolet+1);
1052             em_e->SetMarkerColor(kViolet+1);
1053             em_h->SetLineColor(kViolet+1);
1054             em_h->SetMarkerColor(kViolet+1);
1055             //a_hSetLineColor(kViolet+1);
1056             //a_hSetMarkerColor(kViolet+1);
1057             //a_hSetLineColor(kViolet+1);
1058             //a_hSetMarkerColor(kViolet+1);
1059         }
1060         oh_e->SetMarkerStyle(21);
1061         oh_h->SetMarkerStyle(21);
1062         ih_e->SetMarkerStyle(21);
1063         ih_h->SetMarkerStyle(21);
1064         em_e->SetMarkerStyle(21);
1065         em_h->SetMarkerStyle(21);
1066         //a_hSetMarkerStyle(21);
1067         //a_hSetMarkerStyle(21);
1068         oh_e->SetMarkerSize(1.5f);
1069         oh_h->SetMarkerSize(1.5f);
1070         ih_e->SetMarkerSize(1.5f);
1071         ih_h->SetMarkerSize(1.5f);
1072         em_e->SetMarkerSize(1.5f);
1073         em_h->SetMarkerSize(1.5f);
1074         //a_hSetMarkerSize(1.5f);
1075         //a_hSetMarkerSize(1.5f);
1076         oh_e->SetYTitle("Ratio to Collision Data");
1077         oh_h->SetYTitle("Ratio to Collision Data");
1078         ih_e->SetYTitle("Ratio to Collision Data");
1079         ih_h->SetYTitle("Ratio to Collision Data");
1080         em_e->SetYTitle("Ratio to Collision Data");
1081         em_h->SetYTitle("Ratio to Collision Data");
1082         //a_hSetYTitle("Ratio to Collision Data");
1083         //a_hSetYTitle("Ratio to Collision Data");
1084     
1085     
1086         oh_e->Divide(oh_e1);
1087         oh_h->Divide(oh_h1);
1088         ih_e->Divide(ih_e1);
1089         ih_h->Divide(ih_h1);
1090         em_e->Divide(em_e1);
1091         em_h->Divide(em_h1);
1092         //a_hDivide(a_e1);
1093         //a_hDivide(a_h1);
1094         rats.push_back(std::array<TH1F*, 6> {oh_e, oh_h, ih_e, ih_h, em_e, em_h, a_h, a_e*);    
1095         if(oh_e->GetMaximum() > maxes[0]) maxes[0]=oh_e->GetMaximum();
1096         if(oh_h->GetMaximum() > maxes[1]) maxes[1]=oh_h->GetMaximum();
1097         if(ih_e->GetMaximum() > maxes[2]) maxes[2]=ih_e->GetMaximum();
1098         if(ih_h->GetMaximum() > maxes[3]) maxes[3]=ih_h->GetMaximum();
1099         if(em_e->GetMaximum() > maxes[4]) maxes[4]=em_e->GetMaximum();
1100         if(em_h->GetMaximum() > maxes[5]) maxes[5]=em_h->GetMaximum();*/
1101 //  }
1102     for(int i=0; i<(int)files.size(); i++)
1103     {
1104         if(i==0 || i== 4) continue;
1105         TFile* f=files[i];
1106         TH1F* oh_e = (TH1F*) f->Get("ohcal_energy");
1107         TH1F* oh_h = (TH1F*) f->Get("ohc_hit");
1108         TH1F* ih_e = (TH1F*) f->Get("ihcal_energy");
1109         TH1F* ih_h = (TH1F*) f->Get("ihc_hit");
1110         TH1F* em_e = (TH1F*) f->Get("emcal_energy");
1111         TH1F* em_h = (TH1F*) f->Get("emc_hit");
1112         TH1F* a_e = (TH1F*) f->Get("allcal_energy");
1113         TH1F* a_h = (TH1F*) f->Get("amc_hit");
1114         TH1F* oh_Et = (TH1F*) f->Get("ohcal_total_E");
1115         TH1F* ih_Et = (TH1F*) f->Get("ihcal_total_E");
1116         TH1F* em_Et = (TH1F*) f->Get("emcal_total_E");
1117         TH1F* a_Et = (TH1F*) f->Get("allcal_total_E");
1118         int n_evt_oh=oh_Et->GetEntries();
1119         int n_evt_ih=ih_Et->GetEntries();
1120         int n_evt_em=em_Et->GetEntries();
1121         int n_evt_a=a_Et->GetEntries();
1122         
1123         
1124         //set the y title to reflect the actual plot
1125         oh_e->SetYTitle(Form("#frac{1}{N_{events}} %s ", oh_e->GetYaxis()->GetTitle()));
1126         oh_h->SetYTitle(Form("#frac{1}{N_{events}} %s) ", oh_h->GetYaxis()->GetTitle()));
1127         ih_e->SetYTitle(Form("#frac{1}{N_{events}} %s ", ih_e->GetYaxis()->GetTitle()));
1128         ih_h->SetYTitle(Form("#frac{1}{N_{events}} %s) ", ih_h->GetYaxis()->GetTitle()));
1129         em_e->SetYTitle(Form("#frac{1}{N_{events}} %s ", em_e->GetYaxis()->GetTitle()));
1130         em_h->SetYTitle(Form("#frac{1}{N_{events}} %s) ", em_h->GetYaxis()->GetTitle()));
1131         a_e->SetYTitle(Form("#frac{1}{N_{events}} %s ", a_e->GetYaxis()->GetTitle()));
1132         a_h->SetYTitle(Form("#frac{1}{N_{events}} %s) ", a_h->GetYaxis()->GetTitle()));
1133         //set the limits 
1134         oh_e->GetYaxis()->SetRangeUser(0.08, 500);
1135         em_e->GetYaxis()->SetRangeUser(0.08, 25000);
1136         ih_e->GetYaxis()->SetRangeUser(0.08, 500);
1137         a_e->GetYaxis()->SetRangeUser(0.08, 1600);
1138         a_h->GetYaxis()->SetRangeUser(0.08, 1600);
1139         oh_h->GetYaxis()->SetRangeUser(0.08, 1600);
1140         em_h->GetYaxis()->SetRangeUser(0.08, 25000);
1141         ih_h->GetYaxis()->SetRangeUser(0.08, 1600);
1142         oh_h->GetXaxis()->SetRangeUser(0.01, 500);
1143         ih_h->GetXaxis()->SetRangeUser(0.01, 500);
1144         oh_e->GetXaxis()->SetRangeUser(-100, 600);
1145         ih_e->GetXaxis()->SetRangeUser(-100, 600);
1146         em_e->GetXaxis()->SetRangeUser(-300, 1000);
1147         if(i==0){
1148             oh_e->SetLineColor(kGreen);
1149             oh_e->SetMarkerColor(kGreen);
1150             oh_h->SetLineColor(kGreen);
1151             oh_h->SetMarkerColor(kGreen);
1152             ih_e->SetLineColor(kGreen);
1153             ih_e->SetMarkerColor(kGreen);
1154             ih_h->SetLineColor(kGreen);
1155             ih_h->SetMarkerColor(kGreen);
1156             em_e->SetLineColor(kGreen);
1157             em_e->SetMarkerColor(kGreen);
1158             em_h->SetLineColor(kGreen);
1159             em_h->SetMarkerColor(kGreen);
1160             a_h->SetLineColor(kGreen);
1161             a_h->SetMarkerColor(kGreen);
1162             a_h->SetLineColor(kGreen);
1163             a_h->SetMarkerColor(kGreen);
1164             
1165         }
1166 
1167         if(i==4){
1168             oh_e->SetLineColor(kBlack);
1169             oh_e->SetMarkerColor(kBlack);
1170             oh_h->SetLineColor(kBlack);
1171             oh_h->SetMarkerColor(kBlack);
1172             ih_e->SetLineColor(kBlack);
1173             ih_e->SetMarkerColor(kBlack);
1174             ih_h->SetLineColor(kBlack);
1175             ih_h->SetMarkerColor(kBlack);
1176             em_e->SetLineColor(kBlack);
1177             em_e->SetMarkerColor(kBlack);
1178             em_h->SetLineColor(kBlack);
1179             em_h->SetMarkerColor(kBlack);
1180             a_h->SetLineColor(kBlack);
1181             a_h->SetMarkerColor(kBlack);
1182             a_h->SetLineColor(kBlack);
1183             a_h->SetMarkerColor(kBlack);
1184         }
1185         if(i==2){
1186             oh_e->SetLineColor(kBlue);
1187             oh_e->SetMarkerColor(kBlue);
1188             oh_h->SetLineColor(kBlue);
1189             oh_h->SetMarkerColor(kBlue);
1190             ih_e->SetLineColor(kBlue);
1191             ih_e->SetMarkerColor(kBlue);
1192             ih_h->SetLineColor(kBlue);
1193             ih_h->SetMarkerColor(kBlue);
1194             em_e->SetLineColor(kBlue);
1195             em_e->SetMarkerColor(kBlue);
1196             em_h->SetLineColor(kBlue);
1197             em_h->SetMarkerColor(kBlue);
1198             a_e->SetLineColor(kBlue);
1199             a_e->SetMarkerColor(kBlue);
1200             a_h->SetLineColor(kBlue);
1201             a_h->SetMarkerColor(kBlue);
1202         }
1203         if(i==3){
1204             oh_e->SetLineColor(kRed);
1205             oh_e->SetMarkerColor(kRed);
1206             oh_h->SetLineColor(kRed);
1207             oh_h->SetMarkerColor(kRed);
1208             ih_e->SetLineColor(kRed);
1209             ih_e->SetMarkerColor(kRed);
1210             ih_h->SetLineColor(kRed);
1211             ih_h->SetMarkerColor(kRed);
1212             em_e->SetLineColor(kRed);
1213             em_e->SetMarkerColor(kRed);
1214             em_h->SetLineColor(kRed);
1215             em_h->SetMarkerColor(kRed);
1216             a_e->SetLineColor(kRed);
1217             a_e->SetMarkerColor(kRed);
1218             a_h->SetLineColor(kRed);
1219             a_h->SetMarkerColor(kRed);
1220         }
1221         if(i==1){
1222             oh_e->SetLineColor(kViolet+1);
1223             oh_e->SetMarkerColor(kViolet+1);
1224             oh_h->SetLineColor(kViolet+1);
1225             oh_h->SetMarkerColor(kViolet+1);
1226             ih_e->SetLineColor(kViolet+1);
1227             ih_e->SetMarkerColor(kViolet+1);
1228             ih_h->SetLineColor(kViolet+1);
1229             ih_h->SetMarkerColor(kViolet+1);
1230             em_e->SetLineColor(kViolet+1);
1231             em_e->SetMarkerColor(kViolet+1);
1232             em_h->SetLineColor(kViolet+1);
1233             em_h->SetMarkerColor(kViolet+1);
1234             a_e->SetLineColor(kViolet+1);
1235             a_e->SetMarkerColor(kViolet+1);
1236             a_h->SetLineColor(kViolet+1);
1237             a_h->SetMarkerColor(kViolet+1);
1238         }
1239     /*  TH1F* ih_hg = regeneratePlot(ih_e); 
1240         TH1F* oh_hg = regeneratePlot(oh_e);
1241         TH1F* em_hg = regeneratePlot(em_e);*/
1242         lt[0]->AddEntry(oh_e, Form("%s", label[i].c_str()));
1243         //lt_ref[0]->AddEntry(oh_e, Form("%s", label[i].c_str()));
1244         //lt_ref[0]->AddEntry(oh_e_ref, Form("%s", label[i].c_str()));
1245         lt[1]->AddEntry(oh_h, Form("%s", label[i].c_str()));
1246         //lt_ref[1]->AddEntry(oh_e, Form("%s", label[i].c_str()));
1247         //lt_ref[1]->AddEntry(oh_e_ref, Form("%s", label[i].c_str()));
1248         lt[2]->AddEntry(ih_e, Form("%s", label[i].c_str()));
1249         //lt_ref[2]->AddEntry(oh_e, Form("%s", label[i].c_str()));
1250         //lt_ref[2]->AddEntry(oh_e_ref, Form("%s", label[i].c_str()));
1251         lt[3]->AddEntry(ih_h, Form("%s", label[i].c_str()));
1252         //lt_ref[3]->AddEntry(oh_e, Form("%s", label[i].c_str()));
1253         //lt_ref[3]->AddEntry(oh_e_ref, Form("%s", label[i].c_str()));
1254         lt[4]->AddEntry(em_e, Form("%s", label[i].c_str()));
1255         //lt_ref[4]->AddEntry(oh_e, Form("%s", label[i].c_str()));
1256         //lt_ref[4]->AddEntry(oh_e_ref, Form("%s", label[i].c_str()));
1257         lt[5]->AddEntry(em_h, Form("%s", label[i].c_str()));
1258         //lt_ref[5]->AddEntry(oh_e, Form("%s", label[i].c_str()));
1259         //lt_ref[5]->AddEntry(oh_e_ref, Form("%s", label[i].c_str()));
1260         lt[6]->AddEntry(a_e, Form("%s", label[i].c_str()));
1261         //lt_ref[6]->AddEntry(oh_e, Form("%s", label[i].c_str()));
1262         //lt_ref[6]->AddEntry(oh_e_ref, Form("%s", label[i].c_str()));
1263         lt[7]->AddEntry(a_h, Form("%s", label[i].c_str()));
1264         //lt_ref[7]->AddEntry(oh_e, Form("%s", label[i].c_str()));
1265         //lt_ref[7]->AddEntry(oh_e_ref, Form("%s", label[i].c_str()));
1266         //scale by total number of events
1267         if(i==1){ 
1268             TCanvas* co=new TCanvas("c_ohcal", "data_ohcal");
1269             TCanvas* ci=new TCanvas("c_ihcal", "data_ihcal");
1270             TCanvas* ce=new TCanvas("c_emcal", "data_emcal");;
1271             co->cd();
1272             TLegend* lb1=(TLegend*)ll[0]->Clone();
1273             lb1->Draw();
1274             ci->cd();
1275             TLegend* lb2=(TLegend*)ll[2]->Clone();
1276             lb2->Draw();
1277             ce->cd();
1278             TLegend* lb3=(TLegend*)ll[4]->Clone();
1279             lb3->Draw();
1280 
1281             TLegend* lo=(TLegend*)lt[0]->Clone();
1282             TLegend* li=(TLegend*)lt[2]->Clone();
1283             TLegend* le=(TLegend*)lt[4]->Clone();
1284             TH1F* oh_e2=(TH1F*)oh_e->Clone();
1285             TH1F* ih_e2=(TH1F*)ih_e->Clone();
1286             TH1F* em_e2=(TH1F*)em_e->Clone();
1287             double sigma_o=fitTheNegSide(oh_e2, co, lo, lb1, n_evt_oh, 2);
1288             double sigma_i=fitTheNegSide(ih_e2, ci, li, lb2, n_evt_ih, 1);
1289             double sigma_e=fitTheNegSide(em_e2, ce, le, lb3, n_evt_em, 0);
1290         }
1291         oh_e->Rebin(4);
1292         oh_e->Scale(1/((float)n_evt_oh*4.0));
1293         oh_h->Scale(1/(float)n_evt_oh);
1294         //oh_hg->Scale(1/(float)n_evt_oh);
1295         ih_e->Scale(1/(float)n_evt_ih);
1296         ih_h->Scale(1/(float)n_evt_ih);
1297         //ih_hg->Scale(1/(float)n_evt_ih);
1298         em_e->Scale(1/(float)n_evt_em);
1299         em_h->Scale(1/(float)n_evt_em);
1300         //em_hg->Scale(1/(float)n_evt_em);
1301         a_e->Scale(1/(float)n_evt_a);
1302         a_h->Scale(1/(float)n_evt_a);
1303 
1304         //get the reflected part of the energy 
1305     /*  TH1F* oh_e_ref=getReflected(oh_e);
1306         TH1F* ih_e_ref=getReflected(ih_e);
1307         TH1F* em_e_ref=getReflected(em_e);
1308         TH1F* a_e_ref=getReflected(a_e);
1309         
1310         oh_e_ref->SetMarkerStyle(21);
1311         ih_e_ref->SetMarkerStyle(21);
1312         em_e_ref->SetMarkerStyle(21);
1313         a_e_ref->SetMarkerStyle(21);
1314     */
1315 /*      if(i==0){
1316             lt[0]->AddEntry(rats[i][0], "Pedestal / Collision");
1317             lt[1]->AddEntry(rats[i][1], "Pedestal / Collision");
1318             lt[2]->AddEntry(rats[i][2], "Pedestal / Collision");
1319             lt[3]->AddEntry(rats[i][3], "Pedestal / Collision");
1320             lt[4]->AddEntry(rats[i][4], "Pedestal / Collision");
1321             lt[5]->AddEntry(rats[i][5], "Pedestal / Collision");
1322             //lt[6]->AddEntry(rats[i][7], "Pedestal / Collision");
1323             //lt[7]->AddEntry(rats[i][7], "Pedestal / Collision");
1324         }
1325         else if(i==1)
1326         {
1327             TH1F* h_null=new TH1F("h", "h", oh_e->GetNbinsX(), -0.5, 4999.5);
1328             for(int j=0; j<5000; j++) h_null->Fill(j);
1329             h_null->SetLineColor(kRed);
1330             for(int j=0; j<8; j++)
1331             {
1332                 pad_rats[j]->cd();
1333                 h_null->Draw();
1334             }
1335         }
1336         else{
1337             lt[0]->AddEntry(rats[i][0], Form("%s / Collision", label[i].c_str()));
1338             lt[1]->AddEntry(rats[i][1], Form("%s / Collision", label[i].c_str()));
1339             lt[2]->AddEntry(rats[i][2], Form("%s / Collision", label[i].c_str()));
1340             lt[3]->AddEntry(rats[i][3], Form("%s / Collision", label[i].c_str()));
1341             lt[4]->AddEntry(rats[i][4], Form("%s / Collision", label[i].c_str()));
1342             lt[5]->AddEntry(rats[i][5], Form("%s / Collision", label[i].c_str()));
1343             //lt[6]->AddEntry(rats[i][6], Form("%s / Collision", label[i].c_str()));
1344             //lt[7]->AddEntry(rats[i][7], Form("%s / Collision", label[i].c_str()));
1345         }*/
1346         Canvases[0]->cd();
1347         //pad_val[0]->cd();
1348         oh_e->Draw("same");
1349     //  Canvases[0]->cd();
1350     //  pad_val[0]->Draw();
1351     //  pad_rats[0]->cd();
1352     //  rats[i][0]->Draw();
1353     //  Canvases[0]->cd();
1354     //  pad_rats[0]->Draw("same");
1355         
1356         Canvases[1]->cd();
1357         oh_h->Draw("same");
1358     /*  Canvases[1]->cd();
1359         pad_val[1]->Draw();
1360         pad_rats[1]->cd();
1361         rats[i][1]->Draw("same");
1362         
1363         Canvases[1]->cd();
1364         pad_rats[1]->Draw();
1365 */
1366         Canvases[2]->cd();
1367         ih_e->Draw("same");
1368 /*      Canvases[2]->cd();
1369         pad_val[2]->Draw();
1370         pad_rats[2]->cd();
1371         rats[i][2]->Draw("same");
1372         Canvases[2]->cd();
1373         pad_rats[2]->Draw();
1374 */      
1375         Canvases[3]->cd();
1376         ih_h->Draw("same");
1377 /*      Canvases[3]->cd();
1378         pad_val[3]->Draw();
1379         pad_rats[3]->cd();
1380         rats[i][3]->Draw("same");
1381         Canvases[3]->cd();
1382         pad_rats[3]->Draw();
1383 */      
1384         Canvases[4]->cd();
1385         em_e->Draw("same");
1386 /*      Canvases[4]->cd();
1387         pad_val[4]->Draw();
1388         pad_rats[4]->cd();
1389         rats[i][4]->Draw("same");
1390         Canvases[4]->cd();
1391         pad_rats[4]->Draw();
1392 */      
1393         Canvases[5]->cd();
1394         em_h->Draw("same"); 
1395 /*      Canvases[5]->cd();
1396         pad_val[5]->Draw();
1397         pad_rats[5]->cd();
1398         rats[i][5]->Draw("same");
1399         Canvases[5]->cd();
1400         pad_rats[5]->Draw();
1401 */      Canvases[6]->cd();
1402         a_e->Draw("same");  
1403     /*  Canvases[6]->cd();
1404         pad_val[6]->Draw();
1405         pad_rats[6]->cd();
1406         rats[i][6]->Draw("same");
1407         Canvases[6]->cd();
1408         pad_rats[6]->Draw();
1409     */  Canvases[7]->cd();
1410         a_h->Draw("same");  
1411     /*  Canvases[7]->cd();
1412         pad_val[7]->Draw();
1413         pad_rats[7]->cd();
1414         rats[i][7]->Draw("same");
1415         Canvases[7]->cd();
1416         pad_rats[7]->Draw();*/
1417     /*  Cr[0]->cd();
1418         oh_e_ref->Draw("same"); 
1419         oh_e->Draw("same");
1420         Cr[2]->cd();
1421         ih_e_ref->Draw("same"); 
1422         ih_e->Draw("same");
1423         Cr[4]->cd();
1424         em_e_ref->Draw("same"); 
1425         em_e->Draw("same");
1426         
1427         Cr[1]->cd();
1428         //oh_hg->Draw("same");  
1429         
1430         Cr[3]->cd();
1431         //ih_hg->Draw("same");  
1432         
1433         Cr[5]->cd();*/
1434         //em_hg->Draw("same");  
1435         
1436     }
1437     for(int i=0; i<(int)Canvases.size(); i++)
1438     {
1439         Canvases[i]->cd();
1440         lt[i]->Draw();
1441         ll[i]->Draw();
1442 //      Canvases[i]->Print(Form("~/Hit_energy_canvas_%d.pdf", i));
1443     }
1444 /*  for(int i= 0; i<(int) Cr.size(); i++) 
1445     {
1446         Cr[i]->cd();
1447         lt[i]->Draw();
1448         if(i % 2 == 0 ) //lt_ref[i]->Draw();
1449         else ll[i]->Draw();
1450     }*/
1451     return 0;
1452 }
1453 #endif