ATLAS Offline Software
EgammaAnalysisAlgorithmsTest_eljob.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
4 #
5 # @author Nils Krumnack
6 
7 
8 # Read the submission directory as a command line argument. You can
9 # extend the list of arguments with your private ones later on.
10 import optparse
11 parser = optparse.OptionParser()
12 parser.add_option( '-d', '--data-type', dest = 'data_type',
13  action = 'store', type = 'string', default = 'data',
14  help = 'Type of data to run over. Valid options are data, mc, afii' )
15 parser.add_option( '--dnn', dest = 'dnn',
16  action = 'store_true', default = False,
17  help = 'Use the DNN electron ID instead of the likelihood. ')
18 parser.add_option( '-s', '--submission-dir', dest = 'submission_dir',
19  action = 'store', type = 'string', default = 'submitDir',
20  help = 'Submission directory for EventLoop' )
21 parser.add_option( '-u', '--unit-test', dest='unit_test',
22  action = 'store_true', default = False,
23  help = 'Run the job in "unit test mode"' )
24 ( options, args ) = parser.parse_args()
25 
26 # Set up (Py)ROOT.
27 import ROOT
28 ROOT.xAOD.Init().ignore()
29 
30 # ideally we'd run over all of them, but we don't have a mechanism to
31 # configure per-sample right now
32 
33 dataType = options.data_type
34 useDNNeID = options.dnn
35 
36 if dataType not in ["data", "mc", "afii"] :
37  raise ValueError ("invalid data type: " + dataType)
38 
39 # Set up the sample handler object. See comments from the C++ macro
40 # for the details about these lines.
41 import os
42 sh = ROOT.SH.SampleHandler()
43 sh.setMetaString( 'nc_tree', 'CollectionTree' )
44 sample = ROOT.SH.SampleLocal (dataType)
45 if dataType == "data" :
46  sample.add (os.getenv ('ASG_TEST_FILE_DATA'))
47  pass
48 if dataType == "mc" :
49  sample.add (os.getenv ('ASG_TEST_FILE_MC'))
50  pass
51 if dataType == "afii" :
52  sample.add (os.getenv ('ASG_TEST_FILE_MC_AFII'))
53  pass
54 sh.add (sample)
55 sh.printContent()
56 
57 # Create an EventLoop job.
58 job = ROOT.EL.Job()
59 job.sampleHandler( sh )
60 job.options().setDouble( ROOT.EL.Job.optMaxEvents, 500 )
61 
62 from EgammaAnalysisAlgorithms.EgammaAnalysisAlgorithmsTest import makeSequence
63 algSeq = makeSequence (dataType, not useDNNeID)
64 print (algSeq) # For debugging
65 algSeq.addSelfToJob( job )
66 
67 # Find the right output directory:
68 submitDir = options.submission_dir
69 if options.unit_test:
70  import os
71  import tempfile
72  eSelection = '_DNN' if useDNNeID else '_LH'
73  submitDir = tempfile.mkdtemp( prefix = 'egammaTest_'+dataType+eSelection+'_', dir = os.getcwd() )
74  os.rmdir( submitDir )
75  pass
76 
77 # Run the job using the direct driver.
78 driver = ROOT.EL.DirectDriver()
79 driver.submit( job, submitDir )
DiTauMassTools::ignore
void ignore(T &&)
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:58