Skip to content

Commit 359ee6d

Browse files
committed
Avoid equality operator to replace with None
This is bad practice in Python, because it only works if the type of the operand implements the equality operator. In particular, it will fail with newer ROOT versions, because the `TObject` base class won't implement the equality operator anymore: root-project/root#19145 This commit was done automatically with code modernization tools.
1 parent 2ef353c commit 359ee6d

31 files changed

+110
-110
lines changed

data/hww/errorMatrix2Lands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
for l in file:
4747
l = l.replace("---", "0")
4848
m = re.match(r"(.*?)\s+0\s+((\d+\.?\d*(E[+\-]\d+)?\s+)+)", l)
49-
if m == None:
49+
if m is None:
5050
raise ValueError("Missing line " + l)
5151
sysname = m.group(1)
5252
syseff = [float(x) for x in m.group(2).split()]
@@ -91,7 +91,7 @@
9191
# open file
9292
filename = "%s-%s-mH%s.txt" % (options.label, name, mh)
9393
fout = open(filename, "w")
94-
if fout == None:
94+
if fout is None:
9595
raise RuntimeError("Cannot open %s for writing" % filename)
9696
print(" - " + filename)
9797
# write datacard

data/hww/errorMatrix2Lands_multiChannel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def iddify(x):
117117
continue
118118
l = re.sub("--+", "0", l)
119119
m = re.match(r"(.*?)\s+(0\s+(\d+\.?\d*(E[+\-]\d+)?\s+)+)", l)
120-
if m == None:
120+
if m is None:
121121
raise ValueError("Missing line " + l)
122122
sysname = m.group(1)
123123
syseff = [float(x) for x in m.group(2).split()]
@@ -188,7 +188,7 @@ def iddify(x):
188188
# open file
189189
filename = "%s-mH%s.txt" % (options.label, mh)
190190
fout = open(filename, "w")
191-
if fout == None:
191+
if fout is None:
192192
raise RuntimeError("Cannot open %s for writing" % filename)
193193
print(" - " + filename)
194194
nproc = len(data[mh]["exp"]) // data[mh]["nch"]

data/tutorials/longexercise/diffNuisances.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
) + str(options)
134134

135135
file = ROOT.TFile(args[0])
136-
if file == None:
136+
if file is None:
137137
raise RuntimeError("Cannot open file %s" % args[0])
138138
fit_s = file.Get("fit_s")
139139
fit_b = file.Get("fit_b")
@@ -203,7 +203,7 @@ def getGraph(hist,shift):
203203
flag = False
204204
mean_p, sigma_p, sigma_pu, sigma_pd = 0, 0, 0, 0
205205

206-
if nuis_p == None:
206+
if nuis_p is None:
207207
# nuisance parameter NOT present in the prefit result
208208
if not options.absolute_values and not (options.pullDef == "unconstPullAsym"):
209209
continue
@@ -231,15 +231,15 @@ def getGraph(hist,shift):
231231
row += ["%.6f +%.6f %.6f" % (nuis_p.getVal(), nuis_p.getErrorHi(), nuis_p.getErrorLo())]
232232

233233
for fit_name, nuis_x in [("b", nuis_b), ("s", nuis_s)]:
234-
if nuis_x == None:
234+
if nuis_x is None:
235235
row += [" n/a "]
236236
else:
237237
nuisIsSymm = abs(abs(nuis_x.getErrorLo()) - abs(nuis_x.getErrorHi())) < 0.01 or nuis_x.getErrorLo() == 0
238238
if nuisIsSymm:
239239
nuis_x.setError(nuis_x.getErrorHi())
240240
nuiselo = abs(nuis_x.getErrorLo()) if nuis_x.getErrorLo() > 0 else nuis_x.getError()
241241
nuisehi = nuis_x.getErrorHi()
242-
if options.pullDef and nuis_p != None:
242+
if options.pullDef and nuis_p is not None:
243243
nx, ned, neu = CP.returnPullAsym(
244244
options.pullDef,
245245
nuis_x.getVal(),
@@ -257,11 +257,11 @@ def getGraph(hist,shift):
257257
else:
258258
row += ["%+.2f +%.2f %.2f" % (nx, neu, ned)]
259259

260-
if nuis_p != None:
260+
if nuis_p is not None:
261261
if options.plotfile:
262262
if fit_name == "b":
263263
nuis_p_i += 1
264-
if options.pullDef and nuis_p != None:
264+
if options.pullDef and nuis_p is not None:
265265
# nx,ned,neu = CP.returnPullAsym(options.pullDef,nuis_x.getVal(),mean_p,nuis_x.getErrorHi(),sigma_pu,abs(nuis_x.getErrorLo()),abs(sigma_pd))
266266
gr_fit_b.SetPoint(nuis_p_i - 1, nuis_p_i - 0.5 + 0.1, nx)
267267
gr_fit_b.SetPointError(nuis_p_i - 1, 0, 0, ned, neu)
@@ -279,7 +279,7 @@ def getGraph(hist,shift):
279279
hist_fit_b.GetXaxis().SetBinLabel(nuis_p_i, name)
280280
gr_fit_b.GetXaxis().SetBinLabel(nuis_p_i, name)
281281
if fit_name == "s":
282-
if options.pullDef and nuis_p != None:
282+
if options.pullDef and nuis_p is not None:
283283
# nx,ned,neu = CP.returnPullAsym(options.pullDef,nuis_x.getVal(),mean_p,nuis_x.getErrorHi(),sigma_pu,abs(nuis_x.getErrorLo()),abs(sigma_pd))
284284
gr_fit_s.SetPoint(nuis_p_i - 1, nuis_p_i - 0.5 - 0.1, nx)
285285
gr_fit_s.SetPointError(nuis_p_i - 1, 0, 0, ned, neu)
@@ -474,9 +474,9 @@ def getGraph(hist,shift):
474474
v = table[n]
475475
if options.format == "latex":
476476
n = n.replace(r"_", r"\_")
477-
if pmsub != None:
477+
if pmsub is not None:
478478
v = [re.sub(pmsub[0], pmsub[1], i) for i in v]
479-
if sigsub != None:
479+
if sigsub is not None:
480480
v = [re.sub(sigsub[0], sigsub[1], i) for i in v]
481481
if (n, "b") in isFlagged:
482482
v[-3] = highlighters[isFlagged[(n, "b")]] % v[-3]

python/AdditionalModels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def getHiggsSignalYieldScale(self, production, decay, energy):
107107
name = f"c8_XSBRscal_{production}_{decay}"
108108
print("[LOFullParametrization::C7]")
109109
print(name, production, decay, energy)
110-
if self.modelBuilder.out.function(name) == None:
110+
if self.modelBuilder.out.function(name) is None:
111111
XSscal = "kgluon"
112112
if production in ["WH", "ZH", "VH", "qqH"]:
113113
XSscal = "kV"
@@ -266,7 +266,7 @@ def getHiggsSignalYieldScale(self, production, decay, energy):
266266
name = f"c7_XSBRscal_{production}_{decay}"
267267
print("[LOFullParametrization::C7]")
268268
print(name, production, decay, energy)
269-
if self.modelBuilder.out.function(name) == None:
269+
if self.modelBuilder.out.function(name) is None:
270270
XSscal = "kgluon"
271271
if production in ["WH", "ZH", "VH", "qqH"]:
272272
XSscal = "kV"

python/DatacardParser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def parseCard(file, options):
447447
if ret.obs != [] and type(ret.obs) == list: # still as list, must change into map with bin names
448448
ret.obs = {b: ret.obs[i] for i, b in enumerate(ret.bins)}
449449
for b, p, s in ret.keyline:
450-
if ret.isSignal[p] == None:
450+
if ret.isSignal[p] is None:
451451
ret.isSignal[p] = s
452452
elif ret.isSignal[p] != s:
453453
raise RuntimeError("Process %s is declared as signal in some bins and as background in other bins" % p)
@@ -653,8 +653,8 @@ def parseCard(file, options):
653653
ret.systs.append([lsyst, nofloat, pdf, args, errline])
654654
ret.add_syst_id(lsyst)
655655
except Exception as ex:
656-
if lineNumber != None:
657-
if lineNumber2 != None:
656+
if lineNumber is not None:
657+
if lineNumber2 is not None:
658658
lineNumber += lineNumber2 + 1 # lineNumber2 also started at 0
659659
msg = "Error reading line %d" % (lineNumber + 1)
660660
if hasattr(file, "name"):

python/DatacardPruner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def manipulate_datacard(self, DATACARD, MANIPULATION, EXCLUDE=None):
341341
if "shape" in words[1] or "lnN" in words[1]:
342342
name = words[0]
343343
if MANIPULATION == "COMMENT":
344-
if EXCLUDE != None:
344+
if EXCLUDE is not None:
345345
if name in EXCLUDE:
346346
excl += 1
347347
line = "#" + line

python/HiggsBenchmarkModels/CustodialSymmetryModels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def getHiggsSignalYieldScale(self, production, decay, energy):
318318
return 0
319319

320320
name = f"Czw_XSBRscal_{production}_{decay}_{energy}"
321-
if self.modelBuilder.out.function(name) == None:
321+
if self.modelBuilder.out.function(name) is None:
322322
if production in ["ggH", "ttH"]:
323323
self.modelBuilder.factory_(f'expr::{name}("@0", Czw_BRscal_{decay})')
324324
else:
@@ -399,7 +399,7 @@ def getHiggsSignalYieldScale(self, production, decay, energy):
399399
return 0
400400

401401
name = f"Cwz_XSBRscal_{production}_{decay}_{energy}"
402-
if self.modelBuilder.out.function(name) == None:
402+
if self.modelBuilder.out.function(name) is None:
403403
if production in ["ggH", "ttH"]:
404404
self.modelBuilder.factory_(f'expr::{name}("@0", Cwz_BRscal_{decay})')
405405
else:

python/HiggsBenchmarkModels/FermionSectorModels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def setup(self):
353353

354354
def getHiggsSignalYieldScale(self, production, decay, energy):
355355
name = f"C5ql_XSBRscal_{production}_{decay}"
356-
if self.modelBuilder.out.function(name) == None:
356+
if self.modelBuilder.out.function(name) is None:
357357
XSscal = "Cglu" if production in ["ggH"] else "Cv"
358358
if production in ["ttH"]:
359359
XSscal = "Cf" if self.universalCF else "Cq"
@@ -470,7 +470,7 @@ def setup(self):
470470

471471
def getHiggsSignalYieldScale(self, production, decay, energy):
472472
name = f"C5ud_XSBRscal_{production}_{decay}"
473-
if self.modelBuilder.out.function(name) == None:
473+
if self.modelBuilder.out.function(name) is None:
474474
XSscal = "Cglu" if production in ["ggH"] else "Cv"
475475
if production in ["ttH"]:
476476
XSscal = "Cf" if self.universalCF else "Cu"

python/HiggsBenchmarkModels/VectorsAndFermionsModels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def setup(self):
216216

217217
def getHiggsSignalYieldScale(self, production, decay, energy):
218218
name = f"CvCfXg_XSBRscal_{production}_{decay}"
219-
if self.modelBuilder.out.function(name) == None:
219+
if self.modelBuilder.out.function(name) is None:
220220
XSscal = "CF" if production in ["ggH", "ttH"] else "CV"
221221
BRscal = "hgg"
222222
if decay in ["hww", "hzz"]:
@@ -313,7 +313,7 @@ def setup(self):
313313

314314
def getHiggsSignalYieldScale(self, production, decay, energy):
315315
name = f"CfXg_XSBRscal_{production}_{decay}"
316-
if self.modelBuilder.out.function(name) == None:
316+
if self.modelBuilder.out.function(name) is None:
317317
XSscal = "CF" if production in ["ggH", "ttH"] else "CV"
318318
BRscal = "hgg"
319319
if decay in ["hww", "hzz"]:

python/HiggsCouplingsLOSM.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def setup(self):
8989

9090
def getHiggsSignalYieldScale(self, production, decay, energy):
9191
name = f"CvCf_XSBRscal_{production}_{decay}"
92-
if self.modelBuilder.out.function(name) == None:
92+
if self.modelBuilder.out.function(name) is None:
9393
XSscal = "CF" if production in ["ggH", "ttH"] else "CV"
9494
BRscal = "hgg"
9595
if decay in ["hww", "hzz"]:
@@ -186,7 +186,7 @@ def setup(self):
186186

187187
def getHiggsSignalYieldScale(self, production, decay, energy):
188188
name = f"CvCfXg_XSBRscal_{production}_{decay}"
189-
if self.modelBuilder.out.function(name) == None:
189+
if self.modelBuilder.out.function(name) is None:
190190
XSscal = "CF" if production in ["ggH", "ttH"] else "CV"
191191
BRscal = "hgg"
192192
if decay in ["hww", "hzz"]:
@@ -283,7 +283,7 @@ def setup(self):
283283

284284
def getHiggsSignalYieldScale(self, production, decay, energy):
285285
name = f"CfXg_XSBRscal_{production}_{decay}"
286-
if self.modelBuilder.out.function(name) == None:
286+
if self.modelBuilder.out.function(name) is None:
287287
XSscal = "CF" if production in ["ggH", "ttH"] else "CV"
288288
BRscal = "hgg"
289289
if decay in ["hww", "hzz"]:

0 commit comments

Comments
 (0)