ATLAS Offline Software
PURW_create_mc_default_profile.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 
4 import argparse
5 import os
6 import sys
7 import ROOT
8 
9 if __name__== '__main__':
10 
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)',
14  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")
17 
18 
19 
20  args = parser.parse_args()
21 
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)
26  sys.exit(1)
27 
28  RunDMC_testing_configuration = True
29  def include(s) : return
30  exec(open(args.profileFile).read())
31 
32  if "JobMaker" not in dir():
33  print("Could not find mu profile in",args.profileFile)
34  sys.exit(1)
35 
36  tool = ROOT.CP.TPileupReweighting("tool")
37  tool.UsePeriodConfig("Run2")
38  # decide binning based on if first mu is half int or not (override Run2 default)
39  if (JobMaker[0]["mu"] * 2) % 2 == 1:
40  tool.SetUniformBinning(100,0,100) # half-integer mu values so use this binning
41  else:
42  tool.SetUniformBinning(100,-0.5,99.5)
43 
44  for d in JobMaker:
45  # d is a dict, want run, evts, and mu
46  tool.Fill(d['run'],0,d['evts'],d['mu'])
47 
48  tool.WriteToFile(args.outfile)
49 
50  if args.lcRunNum > 0:
51  # create a dummy lumicalc file too
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]) # unsigned int
56  AvergeInteractionPerXing = array('f',[0.])
57  IntLumi = array('f',[0.])
58  LBStart = array('I',[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")
63  for d in JobMaker:
64  IntLumi[0] = d['evts']
65  AvergeInteractionPerXing[0] = d['mu']
66  t.Fill()
67  t.Write()
68  f.Close()
69 
70  print("Testing the files",args.outfile,f.GetName())
71  ROOT.AAH() # makes possible to use ToolHandles
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()}']")
75  # must also 'reset' the following properties that have become equal to run2-analysis specific defaults
76  ROOT.AAH.setProperty(testTool,"PeriodAssignments","[]")
77  ROOT.AAH.setProperty(testTool,"DataScaleFactor","1")
78  testTool.retrieve()
79 
80  for d in JobMaker:
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'])
84  sys.exit(-1)
85  rrn = testTool.expert().GetRandomRunNumber(d['run'],d['mu'])
86  if rrn != args.lcRunNum:
87  print("Unexpected random run number",rrn)
88  sys.exit(-1)
89 
90  print("Test passed")
91 
92 
read
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)
Definition: openCoraCool.cxx:569
vtune_athena.format
format
Definition: vtune_athena.py:14
beamspotman.dir
string dir
Definition: beamspotman.py:623
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
array
PURW_create_mc_default_profile.include
def include(s)
Definition: PURW_create_mc_default_profile.py:29
Trk::open
@ open
Definition: BinningType.h:40