@@ -96,26 +96,35 @@ def shape_to_num(f, region, sName, ptbin, syst, mask, muon=False, bound=0.5):
9696 _nom_rate = np .sum (_nom [0 ] * mask )
9797 if _nom_rate < .1 :
9898 return 1.0
99+
100+ _one_side = get_templ (f , region , sName , ptbin , syst = syst , muon = muon )
99101 _up = get_templ (f , region , sName , ptbin , syst = syst + "Up" , muon = muon )
100102 _down = get_templ (f , region , sName , ptbin , syst = syst + "Down" , muon = muon )
101- if _up is None and _down is None :
103+ if _up is None and _down is None and _one_side is None :
102104 return None
103105 else :
104- if _down is not None :
105- _down_rate = np .sum (_down [0 ] * mask )
106- else :
107- _down_rate = _nom_rate
108- if _up is not None :
106+ if _one_side is not None :
107+ _up_rate = np .sum (_one_side [0 ] * mask )
108+ _diff = np . abs ( _up_rate - _nom_rate )
109+ magnitude = _diff / _nom_rate
110+ elif _down is not None and _up is not None :
109111 _up_rate = np .sum (_up [0 ] * mask )
112+ _down_rate = np .sum (_down [0 ] * mask )
113+ _diff = np .abs (_up_rate - _nom_rate ) + np .abs (_down_rate - _nom_rate )
114+ magnitude = _diff / (2. * _nom_rate )
110115 else :
111- _up_rate = _nom_rate
112- _diff = np .abs (_up_rate - _nom_rate ) + np .abs (_down_rate - _nom_rate )
113- magnitude = _diff / (2. * _nom_rate )
116+ raise NotImplementedError
114117 if bound is not None :
115118 magnitude = min (magnitude , bound )
116119 return 1.0 + magnitude
117120
118121def get_templ (f , region , sample , ptbin , syst = None , muon = False ):
122+ if "16" in f .name :
123+ year = 2016
124+ elif "17" in f .name :
125+ year = 2017
126+ else :
127+ year = 2018
119128 hist_name = '{}_{}' .format (sample , region )
120129 if syst is not None :
121130 hist_name += "_" + syst
@@ -126,8 +135,16 @@ def get_templ(f, region, sample, ptbin, syst=None, muon=False):
126135 try :
127136 f [hist_name ]
128137 except :
129- print ("{}Sample {}, {}, {}, {} not found." .format ('(Muon) ' if muon else "" ,
130- sample , region , ptbin if not muon else "-" , syst ))
138+ if syst is not None :
139+ if "HEM" in syst and year in [2016 , 2017 ]: # always empty
140+ pass
141+ elif "HEM" in syst and ("Up" in syst or "Down" in syst ) and year == 2018 : # always empty
142+ pass
143+ elif "L1Prefiring" in syst and year == 2018 : # always empty
144+ pass
145+ else :
146+ print ("{}Sample {}, {}, {}, {} not found." .format ('(Muon) ' if muon else "" ,
147+ sample , region , ptbin if not muon else "-" , syst ))
131148 return None
132149 h_vals = f [hist_name ].values
133150 h_edges = f [hist_name ].edges
@@ -172,6 +189,9 @@ def dummy_rhalphabet(pseudo,
172189 year = 2017 ,
173190 opts = None ):
174191
192+ print (year )
193+ assert year in ['2016' , '2017' , '2018' ]
194+
175195 # Default lumi (needs at least one systematics for prefit)
176196 sys_lumi = rl .NuisanceParameter ('CMS_lumi_13TeV_{}' .format (year ), 'lnN' )
177197 sys_lumi_correlated = rl .NuisanceParameter ('CMS_lumi_13TeV_correlated' , 'lnN' )
@@ -389,7 +409,6 @@ def dummy_rhalphabet(pseudo,
389409
390410 for ptbin in range (npt ):
391411 for region in ['pass' , 'fail' ]:
392- #ch = rl.Channel("ptbin%d%s" % (ptbin, region))
393412 ch = rl .Channel ("ptbin{}{}{}" .format (ptbin , region , year ))
394413 model .addChannel (ch )
395414 if justZ :
@@ -953,13 +972,6 @@ def str2bool(v):
953972
954973 parser .add_argument ("--year" , type = int , default = 2017 , help = "Year" )
955974
956- parser .add_argument ("--matched" ,
957- type = str2bool ,
958- default = 'False' ,
959- choices = {True , False },
960- help = ("Use matched/unmatched templates"
961- "(w/o there is some W/Z/H contamination from QCD)" ))
962-
963975 parser .add_argument ("--mcstat" ,
964976 type = str2bool ,
965977 default = 'True' ,
0 commit comments