ATLAS Offline Software
jetMakeRefSamples.py
Go to the documentation of this file.
1 #!/bin/env python
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 
5 
6 
17 
18 import os, os.path
19 import sys
20 import shlex, subprocess
21 import argparse
22 
23 parser = argparse.ArgumentParser(description='''
24 Creates reference ESD/AOD by running a series of Reco_tf.py from a given input
25 file (typically RDO or RAW).
26 Performs typically 2 jobs :
27  RDO/RAW --> ESD
28  ESD --> AOD
29 Each step produces a file which is expected to be similar to the reference
30 files in /afs/cern.ch/atlas/groups/JetEtmiss/ReferenceFiles/RTT/.
31 
32  Ex:
33  %s MC # -> create reference files from /afs/cern.ch/atlas/groups/JetEtmiss/ReferenceFiles/RTT/MC/RDO
34  %s MC MyDir # -> same but creates files under MyDir/
35  %s ESD.root MyDir # -> create an AOD reference file from ESD.root under MyDir/
36 '''%((os.path.basename(sys.argv[0]),)*3),
37  formatter_class=argparse.RawDescriptionHelpFormatter,
38  )
39 
40 parser.add_argument('sampleType', type=str, help='full path to a file. Or "mc" or "data" : will start with a reference RDO or RAW file from the JetEtmiss afs space' )
41 parser.add_argument('outputDir', type=str, nargs='?', default='jetRefFiles/')
42 
43 parser.add_argument('-n', '--noRun', action='store_true', help='Do not run the Reco_tf commands, just print them.')
44 parser.add_argument( '--maxEvents', type=int, default=50, help="Propaged to the maxEvents of the Reco_tf commands")
45 parser.add_argument( '--oneStep', action='store_true' , help="stop after 1st step processed")
46 parser.add_argument( '--overWrite', action='store_true' , help="force to overWrite the output dir")
47 
48 
49 arg=parser.parse_args()
50 
51 
52 #print (arg.sampleType , arg.outputDir, arg.noRun)
53 
54 maxEvents=arg.maxEvents
55 skipEvents=0
56 logFile="output.log"
57 
58 #Geometry/conditions tags:
59 # Matched what was done for the official production of the sample at the time of this writing
60 # geometryVersion=ATLAS-GEO-20-00-01
61 # conditionsTagMC=OFLCOND-MC12-SDR-06
62 # conditionsTagData=COMCOND-BLKPA-RUN1-01
63 # http://www-f9.ijs.si/atlpy/atlprod/prodrequest/?q=mc12_8TeV.117050.PowhegPythia_P2011C_ttbar
64 # http://panda.cern.ch/server/pandamon/query/?reqid=1162571&mode=showtask0
65 # https://twiki.cern.ch/twiki/bin/viewauth/AtlasComputing/CoolProdTags
66 specifyCondAndGeo= False # true to use the tags below, false to autoconfigure everything
67 geometryVersion="ATLAS-GEO-20-00-01"
68 conditionsTagMC="OFLCOND-MC12-SDR-06"
69 conditionsTagData="COMCOND-BLKPA-RUN1-01"
70 IsCOMMON=True
71 
72 
73 # Default input files
74 #defaultMC="/afs/cern.ch/atlas/groups/JetEtmiss/ReferenceFiles/RTT/MC/HITS/mc12_8TeV.CurrentRef.HITS.pool.root"
75 #defaultMC="/afs/cern.ch/atlas/groups/JetEtmiss/ReferenceFiles/MC/HITS/mc12_8TeV.117050.PowhegPythia_P2011C_ttbar.simul.HITS.e1728_s1581.039772.pool.root.1"
76 defaultMC="/afs/cern.ch/atlas/groups/JetEtmiss/ReferenceFiles/RTT/MC/RDO/mc12_8TeV.CurrentRef.RDO.pool.root"
77 defaultData="/afs/cern.ch/atlas/groups/JetEtmiss/ReferenceFiles/RTT/DATA/RAW/data12_8TeV.CurrentRef.RAW"
78 #defaultData="/afs/cern.ch/atlas/groups/JetEtmiss/ReferenceFiles/RTT/DATA/RAW/data12_8TeV.00209109.physics_JetTauEtmiss.merge.RAW._lb0186._SFO-1._0001.1"
79 
80 
81 def makeDirAndCd(dir):
82  if not os.path.exists(dir):
83  os.mkdir(dir)
84  elif not arg.overWrite:
85  print ()
86  print ("ERROR !!!")
87  print (" Directory ",dir,'already exists. Not overwriting it (use --overWrite option if needed)')
88  sys.exit(1)
89 
90  os.chdir(dir)
91 
92 
93 def runStep(inputFile):
94  if not os.path.exists(inputFile) and not arg.noRun:
95  print ('ERROR input file ', inputFile , ' missing')
96  sys.exit(2)
97 
98  preExec = ''
99  transform="Reco_tf.py"
100 
101  inputFileBase = os.path.basename(inputFile)
102 
103  if 'HITS' in inputFileBase:
104  inputType = 'HITS'
105  outputType = "RDO"
106  #transform="Digi_trf.py"
107  preExec=""
108 
109  elif "RDO" in inputFileBase:
110  inputType="RDO"
111  inputDataType=inputType
112  outputType="ESD"
113  preExec='''flags.Reco.EnableTrigger=False; flags.Reco.EnableBTagging=False'''
114 
115  elif "RAW" in inputFileBase:
116  inputType="RAW"
117  inputDataType="BS" #bytestream
118  outputType="ESD"
119  preExec='''flags.Reco.EnableTrigger=False'''
120 
121  elif 'ESD' in inputFileBase:
122  inputType="ESD"
123  inputDataType=inputType
124  outputType="AOD"
125  preExec='''flags.Reco.EnableTrigger=False'''
126 
127  else:
128  print ("ERROR RunStep: Input file does not appear to be a supported type (RAW, HITS, RDO, ESD)")
129  print (' -> got', inputFileBase)
130  sys.exit(3)
131 
132  print ("Starting ",inputType, ' to ', outputType)
133 
134 
135  runDir = arg.outputDir + '/' + inputType+'to'+outputType + '/'
136  if not os.path.exists(runDir):
137  os.mkdir(runDir)
138  outputFile = runDir + inputFileBase.replace(inputType, outputType)
139  if arg.overWrite and os.path.exists(outputFile):
140  os.remove(outputFile)
141 
142  outputLog = runDir+'log'
143 
144  if specifyCondAndGeo:
145  # from older sh script
146  fullComand="${transform} preExec=${preExec} input${inputDataType}File=${inputDir}/${inputFile} output${outputType}File=${outputFile} maxEvents=${maxEvents} skipEvents=${skipEvents} geometryVersion=$geometryVersion conditionsTag=$conditionsTag autoConfiguration=everything"
147  else:
148  comandArgs = [ '--preExec='+preExec,
149  '--input%sFile=%s'%(inputDataType, inputFile),
150  '--output%sFile=%s'%(outputType, outputFile),
151  '--maxEvents='+str(maxEvents),
152  '--skipEvents='+str(skipEvents),
153  '--autoConfiguration=everything',
154  #'--postExec=saxasxa'
155  ]
156 
157  print ('Running : ')
158  print (transform, ' '.join(comandArgs))
159  print()
160 
161  if arg.noRun :
162  res = 0
163  else:
164  logfile = open(outputLog, 'w')
165  res = subprocess.call( [transform] + comandArgs, stdout=logfile, stderr=logfile)
166  logfile.close()
167 
168  if res != 0:
169  print ('ERROR RunStep: Transform appears to have failed - exiting. Check ', outputLog)
170  sys.exit(4)
171 
172 
173 
174  print ('Done %s to %s step'%(inputType, outputType))
175  return outputFile
176 
177 
178 def runChain(inputFile):
179  print ('runChain ', inputFile)
180  while any( [t in os.path.basename(inputFile) for t in ['HITS','RDO','RAW','ESD'] ] ):
181  print ('runStep at ',os.path.basename(inputFile))
182  inputFile = runStep(inputFile)
183  if arg.oneStep:
184  return
185 
186 
187 if arg.sampleType.lower() == 'mc':
188  inputFile=defaultMC
189 elif arg.sampleType.lower() == 'data':
190  inputFile=defaultData
191 else:
192  # assume sampleType is a path
193  inputFile = os.path.abspath(arg.sampleType)
194 
195 if not os.path.exists(inputFile):
196  print ('ERROR Input path does not exist ', inputFile)
197  sys.exit(5)
198 
199 
200 arg.outputDir = os.path.abspath(arg.outputDir)
201 
202 makeDirAndCd( arg.outputDir )
203 
204 runChain(inputFile)
205 
206 sys.exit(0)
jetMakeRefSamples.runStep
def runStep(inputFile)
Definition: jetMakeRefSamples.py:93
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:26
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
Trk::open
@ open
Definition: BinningType.h:40
jetMakeRefSamples.makeDirAndCd
def makeDirAndCd(dir)
Definition: jetMakeRefSamples.py:81
str
Definition: BTagTrackIpAccessor.cxx:11
jetMakeRefSamples.runChain
def runChain(inputFile)
Definition: jetMakeRefSamples.py:178