ATLAS Offline Software
Loading...
Searching...
No Matches
PlotSFuncertainty.py
Go to the documentation of this file.
1# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2
3#!/usr/bin/env python
4import ROOT
5from array import array
6import argparse, sys
7from PlotUtils import PlotUtils, DiagnosticHisto
8from CheckAppliedSFs import KnownWPs, getArgParser, getCalibReleasesAndWP
9import gc
10import os, math
11
13 def __init__(self,
14 var_name = "", axis_title ="",
15 bins = -1, bmin = 0., bmax = 0.,
16 bdir = None,
17 calib = "",
18 wp = "",
19 sys = "SYS",
20 test_tree = None,
21 log_binning = False,
22 ):
23
24 self.__muon_var = test_tree.GetLeaf("Muon_%s"%(var_name))
25 self.__norm = 1. if var_name.find("pt") == -1 else 1./1.e3
26
27 self.__var_name = "%s%s_%s_%s"%("" if len(calib) == 0 else calib+"_", wp,var_name, sys)
28 self.__wp = wp
29 self.__sys = sys
30 self.__calib = calib
31 self.__nom_sf = test_tree.GetLeaf("%s%s_SF"%("" if len(calib) == 0 else "c%s_"%(calib), wp))
32 self.__1up_sf = test_tree.GetLeaf("%s%s_SF__MUON_EFF_%s_%s__1up"%("" if len(calib) == 0 else "c%s_"%(calib), wp,KnownWPs[wp],sys))
33 self.__1dn_sf = test_tree.GetLeaf("%s%s_SF__MUON_EFF_%s_%s__1down"%("" if len(calib) == 0 else "c%s_"%(calib), wp,KnownWPs[wp],sys))
35 name = "%s"%(self.__var_name),
36 axis_title = axis_title,
37 bins = bins, bmin = bmin, bmax = bmax,
38 bdir = bdir,
39 log_binning = log_binning)
41 name = "%s_1UP"%(self.__var_name),
42 axis_title = axis_title,
43 bins = bins, bmin = bmin, bmax = bmax,
44 bdir = bdir,
45 log_binning = log_binning )
47 name = "%s_1DOWN"%(self.__var_name),
48 axis_title = axis_title,
49 bins = bins, bmin = bmin, bmax = bmax,
50 bdir = bdir,
51 log_binning = log_binning )
52
53 def fill(self):
54 self.__nom_histo.fill(value = self.__muon_var.GetValue()*self.__norm, weight= self.__nom_sf.GetValue())
55 self.__1up_histo.fill(value = self.__muon_var.GetValue()*self.__norm, weight= self.__1up_sf.GetValue())
56 self.__1dn_histo.fill(value = self.__muon_var.GetValue()*self.__norm, weight= self.__1dn_sf.GetValue())
57
58
59 def finalize(self):
60 self.__nom_histo.write()
61 self.__1dn_histo.write()
62 self.__1up_histo.write()
63
64 def name(self):
65 return self.__var_name
66
67 def get_nom_H1(self): return self.__nom_histo
68 def get_1up_H1(self): return self.__1up_histo
69 def get_1dn_H1(self): return self.__1dn_histo
70
71 def get_wp(self): return self.__wp
72 def get_sys(self): return self.__sys
73 def get_calib(self): return self.__calib
74
75if __name__ == "__main__":
76 Options = getArgParser().parse_args()
77
78 if not os.path.exists(Options.InputFile):
79 print 'ERROR: File %s does not exist!'%Options.InputFile
80 sys.exit(1)
81 infile = ROOT.TFile(Options.InputFile)
82
83 tree = infile.Get("MuonEfficiencyTest")
84 calibReleases, WPs = getCalibReleasesAndWP(tree)
85
86 if len(Options.WP)>0:
87 WPs = [wp for wp in Options.WP if wp in WPs]
88 print 'INFO: WPs given by user, only plot: %s'%(",".join(WPs))
89
90
91 ROOT.gROOT.Macro("rootlogon.C")
92 ROOT.gROOT.SetStyle("ATLAS")
93 ROOT.gROOT.SetBatch(1)
94 gc.disable()
95
96 if os.path.isdir(Options.outDir) == False:
97 os.system("mkdir -p %s"%(Options.outDir))
98
99 bonusname=Options.bonusname
100
101 Histos = []
102
103 for calib in calibReleases:
104 for wp in WPs:
105 for sys in ["SYS", "STAT"]:
106 Histos +=[
108 var_name = "pt",
109 axis_title ="p_{T} #mu(%s) [GeV]"%(wp),
110 calib = calib, log_binning = True,
111 bins = 25, bmin = 15, bmax = 1000,
112 wp =wp, sys = sys, test_tree = tree),
114 var_name = "eta",
115 axis_title ="#eta #mu(%s)"%(wp),
116 calib = calib,
117 bins =54 , bmin = -2.7, bmax = 2.7,
118 wp =wp, sys = sys, test_tree = tree),
120 var_name = "phi",
121 axis_title ="#phi (%s)"%(wp),
122 calib = calib,
123 bins =20 , bmin = -3.15, bmax = 3.15,
124 wp =wp, sys = sys, test_tree = tree) ]
125
126 for i in range(tree.GetEntries()):
127 tree.GetEntry(i)
128 if i > 0 and i % 5000 == 0:
129 print "INFO: %d/%d events processed"%(i, tree.GetEntries())
130 #if math.fabs(tree.Muon_eta) <= 2.5 or tree.Muon_pt < 15.e3: continue
131 for H in Histos:
132 if tree.Muon_isHighPt == True or H.name().find("HighPt") == -1: H.fill()
133
134 print "INFO: Histograms filled"
135 dummy = ROOT.TCanvas("dummy", "dummy", 800, 600)
136 dummy.SaveAs("%s/AllSystDep%s.pdf[" % (Options.outDir, bonusname))
137 for H in Histos:
138 pu = PlotUtils(status = Options.label)
139 pu.Prepare1PadCanvas(H.name())
140
141 nom = H.get_nom_H1().TH1()
142 dn = H.get_1dn_H1().TH1()
143 up = H.get_1up_H1().TH1()
144
145 up.SetLineColor(ROOT.kRed)
146 dn.SetLineColor(ROOT.kBlue)
147
148 up.Divide(nom)
149 dn.Divide(nom)
150
151
152 up.SetTitle("+1#sigma %s"%("systematic" if H.get_sys() == "SYS" else "statistics"))
153 dn.SetTitle("-1#sigma %s"%("systematic" if H.get_sys() == "SYS" else "statistics"))
154
155 nom.GetYaxis().SetTitle("Ratio to nominal")
156 pu.drawStyling(nom, 0.95,
157 1.05, TopPad = False)
158
159 up.Draw("SAMEHIST")
160 dn.Draw("HISTSAME")
161
162 pu.CreateLegend(0.7, 0.8, 0.9, 0.9)
163 pu.AddToLegend([up, dn])
164
165 pu.DrawAtlas(0.2, 0.9)
166 pu.DrawSqrtS(0.2, 0.85)
167 pu.DrawTLatex(0.2,0.8, "%s, %s"%(H.get_wp(), H.get_calib()))
168
169 pu.DrawLegend()
170
171 pu.saveHisto("%s/SysCheck%s%s"%(Options.outDir, H.name(),bonusname) ,["pdf"])
172 pu.saveHisto("%s/AllSystDep%s" % (Options.outDir, bonusname),["pdf"])
173
174 dummy.SaveAs("%s/AllSystDep%s.pdf]" % (Options.outDir, bonusname))
175
176
177
__init__(self, var_name="", axis_title="", bins=-1, bmin=0., bmax=0., bdir=None, calib="", wp="", sys="SYS", test_tree=None, log_binning=False)
__muon_var
Direct access to the branch which are going to be compared.
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138