File indexing completed on 2024-04-06 12:24:03
0001 void patElectron_recoEfficiency()
0002 {
0003
0004 setNiceStyle();
0005 gStyle->SetOptStat(0);
0006
0007
0008 TFile* file = new TFile("analyzePatElectron.root");
0009
0010
0011 TH1F* recPt_ = file->Get("analyzePatElectron/pt");
0012 TH1F* recEta_ = file->Get("analyzePatElectron/eta");
0013 TH1F* recPhi_ = file->Get("analyzePatElectron/phi");
0014
0015
0016 TH1F* genPt_ = file->Get("analyzePatElectron/genPt");
0017 TH1F* genEta_ = file->Get("analyzePatElectron/genEta");
0018 TH1F* genPhi_ = file->Get("analyzePatElectron/genPhi");
0019
0020
0021 TCanvas* canv0 = new TCanvas("canv0", "electron kinemtics", 600, 300);
0022 canv0->Divide(2,1);
0023 canv0->cd(1);
0024 TH1F* kinPt_=recPt_->Clone();
0025 kinPt_->SetFillStyle(3005.);
0026 kinPt_->SetFillColor(4.);
0027 setHistStyle(kinPt_);
0028 kinPt_ ->DrawCopy();
0029
0030 canv0->cd(2);
0031 TH1F* kinEta_=recEta_->Clone();
0032 kinEta_->SetFillStyle(3005.);
0033 kinEta_->SetFillColor(4.);
0034 setHistStyle(kinEta_);
0035 kinEta_->DrawCopy();
0036
0037
0038 TCanvas* canv1 = new TCanvas("canv1", "electron reco efficiency", 600, 600);
0039 canv1->Divide(2,2);
0040 if(correlatedError(recPt_, genPt_ )==0){
0041 canv1->cd(1);
0042 canv1->GetPad(1)->SetGridx(1);
0043 canv1->GetPad(1)->SetGridy(1);
0044 recPt_ ->SetMaximum(1.3);
0045 setHistStyle(recPt_);
0046 recPt_ ->DrawCopy();
0047 }
0048 if(correlatedError(recEta_, genEta_)==0){
0049 canv1->cd(2);
0050 canv1->GetPad(2)->SetGridx(1);
0051 canv1->GetPad(2)->SetGridy(1);
0052 recEta_ ->SetMaximum(1.3);
0053 setHistStyle(recEta_);
0054 recEta_->DrawCopy();
0055 }
0056 if(correlatedError(recPhi_, genPhi_)==0){
0057 canv1->cd(3);
0058 canv1->GetPad(3)->SetGridx(1);
0059 canv1->GetPad(3)->SetGridy(1);
0060 recPhi_ ->SetMaximum(1.3);
0061 setHistStyle(recPhi_);
0062 recPhi_->DrawCopy();
0063 }
0064 }
0065
0066 int correlatedError(TH1F* nominator, TH1F* denominator)
0067 {
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078 if(nominator->GetNbinsX()!=denominator->GetNbinsX()){
0079
0080 return -1;
0081 }
0082
0083
0084 for(Int_t i=0; i<denominator->GetNbinsX(); ++i){
0085 float dval = nominator->GetBinError(i+1);
0086 float val = nominator->GetBinContent(i+1);
0087 float dref = denominator->GetBinError(i+1);
0088 float ref = denominator->GetBinContent(i+1);
0089
0090 float err;
0091 if(val<=0){
0092
0093 err=0; continue;
0094 }
0095 if(ref==0){
0096
0097 err=0; continue;
0098 }
0099
0100 if(val/ref<1)
0101 err=(val/ref)*TMath::Sqrt(TMath::Abs((dref*dref)/(ref*ref)+(1.-2.*(val/ref))*(dval*dval)/(val*val)));
0102 else
0103 err=(ref/val)*TMath::Sqrt(TMath::Abs((dval*dval)/(val*val)+(1.-2.*(ref/val))*(dref*dref)/(ref*ref)));
0104
0105
0106 nominator->SetBinContent(i+1, val/ref);
0107 nominator->SetBinError(i+1, err);
0108 }
0109 return 0;
0110 }
0111
0112 void setAxisStyle(TH1* hist) {
0113
0114
0115
0116 hist->GetXaxis()->SetTitleSize( 0.06);
0117 hist->GetXaxis()->SetTitleColor( 1);
0118 hist->GetXaxis()->SetTitleOffset( 0.8);
0119 hist->GetXaxis()->SetTitleFont( 62);
0120 hist->GetXaxis()->SetLabelSize( 0.05);
0121 hist->GetXaxis()->SetLabelFont( 62);
0122 hist->GetXaxis()->CenterTitle();
0123 hist->GetXaxis()->SetNdivisions( 505);
0124
0125 hist->GetYaxis()->SetTitleSize( 0.07);
0126 hist->GetYaxis()->SetTitleColor( 1);
0127 hist->GetYaxis()->SetTitleOffset( 0.5);
0128 hist->GetYaxis()->SetTitleFont( 62);
0129 hist->GetYaxis()->SetLabelSize( 0.05);
0130 hist->GetYaxis()->SetLabelFont( 62);
0131 }
0132
0133 void setHistStyle(TH1F* hist)
0134 {
0135
0136
0137
0138 setAxisStyle(hist);
0139 hist->GetXaxis()->SetTitle(hist->GetTitle());
0140 hist->SetTitle();
0141 hist->SetLineColor(4.);
0142 hist->SetLineWidth(3.);
0143 hist->SetMarkerSize(0.75);
0144 hist->SetMarkerColor(4.);
0145 hist->SetMarkerStyle(20.);
0146 }
0147
0148 void setNiceStyle()
0149 {
0150
0151
0152
0153 TStyle *MyStyle = new TStyle ("MyStyle", "My style for nicer plots");
0154
0155 Float_t xoff = MyStyle->GetLabelOffset("X"),
0156 yoff = MyStyle->GetLabelOffset("Y"),
0157 zoff = MyStyle->GetLabelOffset("Z");
0158
0159 MyStyle->SetCanvasBorderMode ( 0 );
0160 MyStyle->SetPadBorderMode ( 0 );
0161 MyStyle->SetPadColor ( 0 );
0162 MyStyle->SetCanvasColor ( 0 );
0163 MyStyle->SetTitleColor ( 0 );
0164 MyStyle->SetStatColor ( 0 );
0165 MyStyle->SetTitleBorderSize ( 0 );
0166 MyStyle->SetTitleFillColor ( 0 );
0167 MyStyle->SetTitleH ( 0.07 );
0168 MyStyle->SetTitleW ( 1.00 );
0169 MyStyle->SetTitleFont ( 132 );
0170
0171 MyStyle->SetLabelOffset (1.5*xoff, "X");
0172 MyStyle->SetLabelOffset (1.5*yoff, "Y");
0173 MyStyle->SetLabelOffset (1.5*zoff, "Z");
0174
0175 MyStyle->SetTitleOffset (0.9, "X");
0176 MyStyle->SetTitleOffset (0.9, "Y");
0177 MyStyle->SetTitleOffset (0.9, "Z");
0178
0179 MyStyle->SetTitleSize (0.045, "X");
0180 MyStyle->SetTitleSize (0.045, "Y");
0181 MyStyle->SetTitleSize (0.045, "Z");
0182
0183 MyStyle->SetLabelFont (132, "X");
0184 MyStyle->SetLabelFont (132, "Y");
0185 MyStyle->SetLabelFont (132, "Z");
0186
0187 MyStyle->SetPalette(1);
0188
0189 MyStyle->cd();
0190 }