9 if __name__==
'__main__':
11 parser = argparse.ArgumentParser(description=
'Create a default config file for a specific mu profile file')
12 parser.add_argument(
'--outfile', type=str,
13 help=
'Output file for PURW tool (default: purw.root)',
15 parser.add_argument(
'--lcRunNum',type=int,default=0,help=
"if specified, create a matching dummy lumicalc file")
16 parser.add_argument(
'profileFile', type=str,help=
"name of the config file - will automatically obtain with get_files")
20 args = parser.parse_args()
22 if not os.path.exists(args.profileFile):
23 os.system(
"get_files {}".
format(args.profileFile))
24 if not os.path.exists(args.profileFile):
25 print(
"Could not obtain profile file:",args.profileFile)
28 RunDMC_testing_configuration =
True
32 if "JobMaker" not in dir():
33 print(
"Could not find mu profile in",args.profileFile)
36 tool = ROOT.CP.TPileupReweighting(
"tool")
37 tool.UsePeriodConfig(
"Run2")
39 if (JobMaker[0][
"mu"] * 2) % 2 == 1:
40 tool.SetUniformBinning(100,0,100)
42 tool.SetUniformBinning(100,-0.5,99.5)
46 tool.Fill(d[
'run'],0,d[
'evts'],d[
'mu'])
48 tool.WriteToFile(args.outfile)
52 f = ROOT.TFile(f
"dummy.lumicalc.{args.lcRunNum}.root",
"RECREATE")
53 t = ROOT.TTree(
"LumiMetaData",
"LumiMetaData")
54 from array
import array
55 RunNbr =
array(
'I',[args.lcRunNum])
56 AvergeInteractionPerXing =
array(
'f',[0.])
59 t.Branch(
"RunNbr",RunNbr,
"RunNbr/i")
60 t.Branch(
"AvergeInteractionPerXing",AvergeInteractionPerXing,
"AvergeInteractionPerXing/F")
61 t.Branch(
"IntLumi",IntLumi,
"IntLumi/F")
62 t.Branch(
"LBStart",LBStart,
"LBStart/i")
64 IntLumi[0] = d[
'evts']
65 AvergeInteractionPerXing[0] = d[
'mu']
70 print(
"Testing the files",args.outfile,f.GetName())
72 testTool = ROOT.ToolHandle[
'CP::IPileupReweightingTool'](
"CP::PileupReweightingTool/tool")
73 ROOT.AAH.setProperty(testTool,
"ConfigFiles",f
"['{args.outfile}']")
74 ROOT.AAH.setProperty(testTool,
"LumiCalcFiles",f
"['{f.GetName()}']")
76 ROOT.AAH.setProperty(testTool,
"PeriodAssignments",
"[]")
77 ROOT.AAH.setProperty(testTool,
"DataScaleFactor",
"1")
81 weight = testTool.expert().GetCombinedWeight(d[
'run'],45,d[
'mu'])
82 if abs(weight - 1.)>1e-9:
83 print(
"Unexpected pileup weight",weight,
"for mu=",d[
'mu'])
85 rrn = testTool.expert().GetRandomRunNumber(d[
'run'],d[
'mu'])
86 if rrn != args.lcRunNum:
87 print(
"Unexpected random run number",rrn)