ATLAS Offline Software
TestSUSYToolsAlg.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Read the submission directory as a command line argument. You can
4 # extend the list of arguments with your private ones later on.
5 import sys
6 import optparse
7 from glob import glob
8 from datetime import date
9 
10 #import AthenaPoolCnvSvc.ReadAthenaPool #read xAOD files
11 
12 parser = optparse.OptionParser()
13 #
14 parser.add_option('--driver', dest = 'driver', choices = ['direct','grid','lxplus'], default = 'direct')
15 parser.add_option('--gridTag', dest = 'gridTag')
16 parser.add_option('--submitFlags', dest = 'submitFlags')
17 parser.add_option('--express', dest = 'express', default = False, action = 'store_true' )
18 parser.add_option('-n', '--dryrun', dest = 'dryrun', default=False, action = 'store_true' )
19 #
20 parser.add_option('--log-level', dest = 'log_level', default = 'INFO', choices = ['ALWAYS','FATAL','ERROR','WARNING','INFO','DEBUG','VERBOSE'])
21 parser.add_option('--dosyst', dest = 'dosyst', default = False, action = 'store_true')
22 parser.add_option( '-s', '--submission-dir', dest = 'submission_dir', default = 'submitDir', help = 'Submission directory for EventLoop' )
23 parser.add_option('-t', '--type', dest = 'type', default = 'mc20e', help = 'Job type. (mc20a, mc20d, mc20e, mc23a, mc23d, data18, data22, data23)', choices = ['mc20a', 'mc20d', 'mc20e', 'mc23a', 'mc23d', 'data18', 'data22','data23'])
24 parser.add_option('--AF', dest = 'AF', default = False, action = 'store_true' )
25 parser.add_option('-f', '--flav', dest = 'flav', default = 'PHYS', choices = ["PHYS", "PHYSLITE"], help = 'input DAOD flavour' )
26 parser.add_option('-m', '--maxEvts', dest = 'maxEvts', type = 'int', default = -1, help = 'Max events (-1 is all)' )
27 parser.add_option('-M', '--maxEvtsManual', dest = 'maxEvtsManual', type = 'int')
28 parser.add_option('-p', '--ptag', dest = 'ptag', default = 'p6266', help = 'ptag' )
29 parser.add_option('--grl', dest = 'grl')
30 parser.add_option('--inputDir', dest = 'inputDir')
31 parser.add_option('--inputFile', dest = 'inputFile')
32 parser.add_option('--inputGrid', dest = 'inputGrid')
33 parser.add_option('--inputXRD', dest = 'inputXRD')
34 parser.add_option('--overwrite', dest = 'overwrite', default = False, action = 'store_true' )
35 ( options, args ) = parser.parse_args()
36 
37 # Print configuration
38 print("Configured input data ptag: %s"%(options.ptag))
39 ptageqdata = {'p6266' : 'p6269'}
40 if 'data2' in options.type and options.ptag in ptageqdata:
41  options.ptag = ptageqdata[options.ptag]
42  print("Overriding ptag to equivalent data ptag: -> %s"%(options.ptag))
43 print("Configured input data type: %s"%(options.type))
44 print("Configured input data DAOD flavour: %s"%(options.flav))
45 print("Configured input data sim type: %s"%('FullSim' if not options.AF else 'AF'))
46 
47 # Set up (Py)ROOT.
48 import ROOT
49 ROOT.xAOD.Init().ignore()
50 
51 # for logging
52 outputlvl = {'INFO':ROOT.MSG.INFO,'DEBUG':ROOT.MSG.DEBUG,'VERBOSE':ROOT.MSG.VERBOSE,'FATAL':ROOT.MSG.FATAL,'ALWAYS':ROOT.MSG.ALWAYS,'ERROR':ROOT.MSG.ERROR,'WARNING':ROOT.MSG.WARNING}
53 
54 # Set up the sample handler object. See comments from the C++ macro
55 # for the details about these lines.
56 import os
57 sh = ROOT.SH.SampleHandler()
58 sh.setMetaString( 'nc_tree', 'CollectionTree' )
59 
60 import shutil
61 if options.overwrite and os.path.exists(options.submission_dir): shutil.rmtree(options.submission_dir)
62 
63 # set up file source
64 cvmfsInputArea = '/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/SUSYTools'
65 sim_type = "FS" if not options.AF else "AF3"
66 inputFiles = {}
67 inputFiles['mc20e'] = 'DAOD_%s.mc20_13TeV.410470.%s_mc20e_%s.%s.pool.root'%(options.flav, sim_type, options.ptag, options.flav)
68 inputFiles['mc23a'] = 'mc23_13p6TeV.601229.%s_mc23a_%s.%s.pool.root'%(sim_type, options.ptag, options.flav)
69 inputFiles['mc23d'] = 'mc23_13p6TeV.601229.%s_mc23d_%s.%s.pool.root'%(sim_type, options.ptag, options.flav)
70 inputFiles['data18'] = 'data18_13TeV.39757132_%s.%s.pool.root'%(options.ptag,options.flav)
71 inputFiles['data22'] = 'data22_13p6TeV.39672246_%s.%s.pool.root'%(options.ptag,options.flav)
72 inputFiles['data23'] = 'data23_13p6TeV.39756993_%s.%s.pool.root'%(options.ptag,options.flav)
73 
74 inputDir = ''
75 inputFile = ''
76 
77 # configure test type
78 if options.inputXRD:
79  print("Using inputXRD: ",options.inputXRD)
80  pref,server,fname = options.inputXrootd.plit('//')
81  dl = ROOT.SH.DiskListXRD(server,fname)
82  ROOT.SH.ScanDir().scan(sh,dl)
83 elif options.inputGrid:
84  print("Using inputGrid: ",options.inputGrid)
85  dsname = options.inputGrid.split(':')[-1].rstrip() # drop scope if present, and not trailing spaces
86  ROOT.SH.addGrid(sh,dsname)
87 else:
88  inputDir = cvmfsInputArea
89  inputFile = inputFiles[options.type] if options.type in inputFiles else ''
90 
91  if options.inputDir: inputDir = options.inputDir
92  if options.inputFile: inputFile = options.inputFile
93 
94  print("Using inputDir: ",inputDir)
95  print("Using inputFile:",inputFile)
96  ROOT.SH.ScanDir().filePattern(inputFile).scan(sh, inputDir)
97 sh.printContent()
98 
99 # Create an EventLoop job.
100 job = ROOT.EL.Job()
101 job.sampleHandler( sh )
102 job.options().setDouble( ROOT.EL.Job.optMaxEvents, options.maxEvts )
103 
104 # Create the algorithm's configuration. Note that we'll be able to add
105 # algorithm property settings here later on.
106 from AnaAlgorithm.AnaAlgorithmConfig import AnaAlgorithmConfig
107 config = AnaAlgorithmConfig( 'SUSYToolsAlg' )
108 config.addPrivateTool("SUSYTools","ST::SUSYObjDef_xAOD")
109 
110 config.SUSYTools.ConfigFile = "SUSYTools/SUSYTools_Default.conf"
111 if ("data2" in options.type or "mc23" in options.type): config.SUSYTools.ConfigFile = "SUSYTools/SUSYTools_Default_Run3.conf"
112 if ("data" not in options.type): config.DoSyst = options.dosyst
113 config.SUSYTools.DataSource = 1
114 config.OutputLevel = outputlvl[options.log_level]
115 config.SUSYTools.OutputLevel = outputlvl[options.log_level]
116 config.SUSYTools.PRWLumiCalcFiles = []
117 config.SUSYTools.AutoconfigurePRWTool = True
118 config.SUSYTools.PRWUseCommonMCFiles = True
119 if options.flav == "PHYSLITE":
120  print("Running on PHYSLITE : ", inputFile)
121  STconfig_lite = str(config.SUSYTools.ConfigFile).replace(".conf","_LITE.conf")
122  config.SUSYTools.ConfigFile = STconfig_lite
123  config.SUSYTools.IsPHYSLITE = True
124 
125 # set datasource if AF3
126 if options.AF:
127  config.SUSYTools.DataSource = 2
128 
129 # set mcCampaign
130 if 'mc' in options.type:
131  mcCampaign = options.type
132  config.SUSYTools.mcCampaign = options.type
133 elif options.type == 'data18':
134  mcCampaign = 'mc20e'
135  config.SUSYTools.mcCampaign = options.type
136  config.SUSYTools.DataSource = 0
137 elif options.type == 'data22':
138  mcCampaign = 'mc23a'
139  config.SUSYTools.mcCampaign = options.type
140  config.SUSYTools.DataSource = 0
141 elif options.type == 'data23':
142  mcCampaign = 'mc23d'
143  config.SUSYTools.mcCampaign = options.type
144  config.SUSYTools.DataSource = 0
145 
146 
147 # set lumicalc info
148 PRWLumiCalc = {}
149 PRWLumiCalc['mc20a'] = ['/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/GoodRunsLists/data16_13TeV/20180129/PHYS_StandardGRL_All_Good_25ns_297730-311481_OflLumi-13TeV-009.root',
150  '/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/GoodRunsLists/data15_13TeV/20170619/PHYS_StandardGRL_All_Good_25ns_276262-284484_OflLumi-13TeV-008.root']
151 PRWLumiCalc['mc20d'] = ['/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/GoodRunsLists/data17_13TeV/20180619/physics_25ns_Triggerno17e33prim.lumicalc.OflLumi-13TeV-010.root']
152 PRWLumiCalc['mc20e'] = ['/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/GoodRunsLists/data18_13TeV/20190318/ilumicalc_histograms_None_348885-364292_OflLumi-13TeV-010.root']
153 PRWLumiCalc['mc23a'] = ['/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/GoodRunsLists/data22_13p6TeV/20230207/ilumicalc_histograms_None_431810-440613_OflLumi-Run3-003.root']
154 PRWLumiCalc['mc23d'] = ['/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/GoodRunsLists/data23_13p6TeV/20230828/ilumicalc_histograms_None_451587-456749_OflLumi-Run3-003.root']
155 
156 config.SUSYTools.PRWLumiCalcFiles = PRWLumiCalc[mcCampaign]
157 
158 if options.grl: config.GRLFiles = options.grl.split(',')
159 if options.maxEvtsManual: config.maxEvts = options.maxEvtsManual
160 
161 # submit
162 job.algsAdd( config )
163 if options.driver == 'direct':
164  # Run the job using the direct driver.
165  driver = ROOT.EL.DirectDriver()
166  if not options.dryrun:
167  driver.submit( job, options.submission_dir )
168 elif options.driver == 'grid':
169  driver = ROOT.EL.PrunDriver()
170  submitFlags = ['--addNthFieldOfInDSToLFN=2,6']
171  if options.submitFlags: submitFlags += [options.submitFlags]
172  if not options.gridTag: options.gridTag = date.today().strftime('%y%m%d')
173  outName = 'user.%s.%%in:name[1]%%.%%in:name[2]%%.%%in:name[3]%%.STAlg_%s'%(os.environ['USER'],options.gridTag)
174  driver.options().setString("nc_outputSampleName", outName );
175  driver.options().setString("nc_EventLoop_SubmitFlags", ' '.join(submitFlags))
176  driver.options().setDouble(ROOT.EL.Job.optGridMergeOutput, 0)
177  if not options.dryrun:
178  if options.express: driver.options().setDouble(ROOT.EL.Job.optGridExpress, 1)
179  driver.submitOnly( job, options.submission_dir )
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
DiTauMassTools::ignore
void ignore(T &&)
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:58
test_AnalysisBaseEventLoopJob.filePattern
string filePattern
Definition: test_AnalysisBaseEventLoopJob.py:17
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
scan
void scan(TDirectory *td=0, int depth=0)
Definition: listroot.cxx:440
str
Definition: BTagTrackIpAccessor.cxx:11
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70