ATLAS Offline Software
Loading...
Searching...
No Matches
LArSC2NtupleDumper.py
Go to the documentation of this file.
1#!/usr/bin/env python
2#
3# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
4
5from AthenaConfiguration.ComponentFactory import CompFactory
6from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
7
8if __name__=='__main__':
9
10 import os,sys
11 import argparse
12 import subprocess
13 from AthenaCommon import Logging
14 log = Logging.logging.getLogger( 'LArSC2Ntuple' )
15
16 parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
17
18 parser.add_argument('-i','--indir', dest='indir', default="/eos/atlas/atlastier0/rucio/data_test/calibration_pulseall/00414414/data_test.00414414.calibration_pulseall.daq.RAW/", help='input files dir', type=str)
19 parser.add_argument('-p','--inprefix', dest='inpref', default="data_test", help='Input filenames prefix', type=str)
20 parser.add_argument('-y','--inppatt', dest='inppatt', default="lb3512", help='Input filenames pattern', type=str)
21 parser.add_argument('-f','--infile', dest='infile', default="", help='Input filename (if given indir and inprefix are ignored', type=str)
22 parser.add_argument('-r','--run', dest='run', default=0, help='Run number (if not given trying to judge from input file name)', type=int)
23 parser.add_argument('-m','--maxev', dest='maxev', default=-1, help='Max number of events to dump', type=int)
24 parser.add_argument('-x','--outlevel', dest='olevel', default=5, help='OuputLevel for dumping algo', type=int)
25 parser.add_argument('-o','--outfile', dest='outfile', default="Digits.root", help='Output root filename', type=str)
26 parser.add_argument('-s','--addSamples', dest='samples', default=False, help='Add Samples to output ntuple', action="store_true")
27 parser.add_argument('-a','--addSampBas', dest='samplesBas', default=False, help='Add ADC_BAS to output ntuple', action="store_true")
28 parser.add_argument( '--addAccSamples', dest='accsamples', default=False, help='work on accumulated samples', action="store_true")
29 parser.add_argument( '--addAccCalibSamples', dest='acccalibsamples', default=False, help='work on accumulated samples', action="store_true")
30 parser.add_argument('-z','--addEt', dest='Et', default=False, help='Add ET to output ntuple', action="store_true")
31 parser.add_argument('-g','--addEtId', dest='EtId', default=False, help='Add ET_ID to output ntuple', action="store_true")
32 parser.add_argument('-l','--noLatHeader', dest='lheader', default=True, help='Add LATOME Header to output ntuple', action='store_false')
33 parser.add_argument('-b','--noBCID', dest='bcid', default=True, help='Add BCID info to output ntuple', action='store_false')
34 parser.add_argument('-e','--expandId', dest='expid', default=False, help='Expand online Id to fields', action='store_true')
35 parser.add_argument('-n','--nsamp', dest='nsamp', default=0, help='Number of samples to dump', type=int)
36 parser.add_argument('-c','--overEvNumber', dest='overEvN', default=False, help='Overwrite event number', action='store_true')
37 parser.add_argument('-d','--addHash', dest='ahash', default=False, help='Add hash number to output ntuple', action='store_true')
38 parser.add_argument('-j','--addOffline', dest='offline', default=False, help='Add offline Id to output ntuple', action='store_true')
39 parser.add_argument('-k','--addCalib', dest='calib', default=False, help='Add calib. info to output ntuple', action='store_true')
40 parser.add_argument('-t','--addGeom', dest='geom', default=False, help='Add real geom info to output ntuple', action='store_true')
41 parser.add_argument('-u','--noBC', dest='bc', default=False, help='Add Bad. chan info to output ntuple', action='store_true')
42 parser.add_argument('-w','--addROD', dest='rod', default=False, help='Add ROD energies sum to output ntuple', action='store_true')
43 parser.add_argument('-v','--addEvTree', dest='evtree', default=False, help='Add tree with per event info to output ntuple', action='store_true')
44 parser.add_argument('-q','--addNoisyRO', dest='noisyRO', default=False, help='Add reco and info from LArNoisyROSummary to output ntuple', action='store_true')
45 parser.add_argument('--addTT', dest='TT', default=False, help='Add info from LArTriggerTowers to output ntuple', action='store_true')
46 parser.add_argument('--EMF', dest='emf', default=False, help='Is it for EMF', action='store_true')
47 parser.add_argument('--FW6', dest='fw6', default=False, help='Is it for fw v. 6', action='store_true')
48 parser.add_argument('--FTs', dest='ft', default=[], nargs="+", type=int, help='list of FT which will be read out (space separated).')
49 parser.add_argument('--posneg', dest='posneg', default=[], nargs="+", help='side to read out (-1 means both), can give multiple arguments (space separated). Default %(default)s.', type=int,choices=range(-1,2))
50 parser.add_argument('--barrel_ec', dest='be', default=[], nargs="+", help='subdet to read out (-1 means both), can give multiple arguments (space separated) Default %(default)s.', type=int,choices=range(-1,2))
51 parser.add_argument('--ETThresh', dest='etthresh', default=-1., help='ET threshold to dump info', type=float)
52 parser.add_argument('--ETThreshMain', dest='etthreshmain', default=-1., help='ET threshold from Main to dump info', type=float)
53 parser.add_argument('--ADCThresh', dest='adcthresh', default=-1, help='ADC threshold to dump info', type=int)
54 parser.add_argument('--doPEBStream', dest='peb', default=False, help='Is it for PEB stream', action='store_true')
55
56 args = parser.parse_args()
57 if help in args and args.help is not None and args.help:
58 parser.print_help()
59 sys.exit(0)
60
61 for _, value in args._get_kwargs():
62 if value is not None:
63 log.debug(value)
64
65 #Import the flag-container that is the arguemnt to the configuration methods
66 from AthenaConfiguration.AllConfigFlags import initConfigFlags
67 flags=initConfigFlags()
68 if args.accsamples or args.acccalibsamples:
69 from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
70 addLArCalibFlags(flags, True)
71 if len(args.posneg) >= 0:
72 flags.LArCalib.Preselection.Side = args.posneg
73 if len(args.be) >=0:
74 flags.LArCalib.Preselection.BEC = args.be
75 if len(args.ft) > 0:
76 flags.LArCalib.Preselection.FT = args.ft
77 #add SC dumping specific flags
78 from LArCafJobs.LArSCDumperFlags import addSCDumpFlags
79 addSCDumpFlags(flags)
80
81 # check samples combination:
82 if (args.accsamples or args.acccalibsamples) and (args.samples or args.samplesBas):
83 log.error('Could not dump both samples and accumulated calib samples')
84 sys.exit(1)
85 if args.accsamples and args.acccalibsamples:
86 log.error('Could not dump both accsamples and acc calib samples')
87 sys.exit(1)
88
89 if len(args.infile) > 0:
90 flags.Input.Files = [args.infile]
91 elif len(args.inppatt) > 0:
92 from LArCalibProcessing.GetInputFiles import GetInputFilesFromPattern
93 flags.Input.Files = GetInputFilesFromPattern(args.indir,args.inppatt)
94 else:
95 from LArCalibProcessing.GetInputFiles import GetInputFilesFromPrefix
96 flags.Input.Files = GetInputFilesFromPrefix(args.indir,args.inpref)
97
98 if args.run != 0:
99 flags.Input.RunNumbers = [args.run]
100
101 # geometry
102 from AthenaConfiguration.TestDefaults import defaultGeometryTags
103 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
104
105 if args.accsamples:
106 flags.LArSCDump.accdigitsKey="accSC"
107 else:
108 flags.LArSCDump.accdigitsKey=""
109 if args.acccalibsamples:
110 flags.LArSCDump.acccalibdigitsKey="acccalibSC"
111 else:
112 flags.LArSCDump.acccalibdigitsKey=""
113
114 flags.LArSCDump.doBC = args.bc
115 bckey='LArBadChannel'
116
117 flags.LArSCDump.digitsKey=""
118 CKeys=[]
119 fwversion=5
120
121 # autoconfig
122 from LArConditionsCommon.LArRunFormat import getLArDTInfoForRun
123 try:
124 runinfo=getLArDTInfoForRun(flags.Input.RunNumbers[0], connstring="COOLONL_LAR/CONDBR2")
125 except Exception:
126 log.warning("Could not get DT run info, using defaults !")
127 flags.LArSCDump.doEt=True
128 if args.nsamp > 0:
129 flags.LArSCDump.nSamples=args.nsamp
130 else:
131 flags.LArSCDump.nSamples=5
132 flags.LArSCDump.nEt=1
133 if args.samples:
134 flags.LArSCDump.digitsKey="SC"
135 CKeys=["SC_ET"]
136 else:
137 fwversion=runinfo.FWversion()
138 if not (args.accsamples or args.acccalibsamples):
139 flags.LArSCDump.digitsKey=""
140 if args.peb:
141 for i in range(0,len(runinfo.streamTypesPEB())):
142 if args.EtId and runinfo.streamTypesPEB()[i] == "SelectedEnergy":
143 CKeys += ["SC_ET_ID"]
144 flags.LArSCDump.doEt=True
145 flags.LArSCDump.nEt=runinfo.streamLengthsPEB()[i]
146 elif args.Et and runinfo.streamTypesPEB()[i] == "Energy":
147 CKeys += ["SC_ET"]
148 flags.LArSCDump.doEt=True
149 flags.LArSCDump.nEt=runinfo.streamLengthsPEB()[i]
150 elif args.samples and runinfo.streamTypesPEB()[i] == "RawADC":
151 flags.LArSCDump.digitsKey="SC"
152 if args.nsamp > 0:
153 flags.LArSCDump.nSamples=args.nsamp
154 else:
155 flags.LArSCDump.nSamples=runinfo.streamLengthsPEB()[i]
156 elif args.samplesBas and runinfo.streamTypesPEB()[i] == "ADC":
157 CKeys += ["SC_ADC_BAS"]
158 if args.nsamp > 0:
159 flags.LArSCDump.nSamples=args.nsamp
160 else:
161 flags.LArSCDump.nSamples=runinfo.streamLengthsPEB()[i]
162
163 else:
164 for i in range(0,len(runinfo.streamTypes())):
165 if args.EtId and runinfo.streamTypes()[i] == "SelectedEnergy":
166 CKeys += ["SC_ET_ID"]
167 flags.LArSCDump.doEt=True
168 flags.LArSCDump.nEt=runinfo.streamLengths()[i]
169 elif args.Et and runinfo.streamTypes()[i] == "Energy":
170 CKeys += ["SC_ET"]
171 flags.LArSCDump.doEt=True
172 flags.LArSCDump.nEt=runinfo.streamLengths()[i]
173 elif args.samples and runinfo.streamTypes()[i] == "RawADC":
174 flags.LArSCDump.digitsKey="SC"
175 if args.nsamp > 0:
176 flags.LArSCDump.nSamples=args.nsamp
177 else:
178 flags.LArSCDump.nSamples=runinfo.streamLengths()[i]
179 elif args.samplesBas and runinfo.streamTypes()[i] == "ADC":
180 CKeys += ["SC_ADC_BAS"]
181 if args.nsamp > 0:
182 flags.LArSCDump.nSamples=args.nsamp
183 else:
184 flags.LArSCDump.nSamples=runinfo.streamLengths()[i]
185 if args.nsamp > 0 and args.nsamp < flags.LArSCDump.nSamples:
186 flags.LArSCDump.nSamples=args.nsamp
187
188 # calib runs do not have info about accumulation
189 if args.accsamples or args.acccalibsamples:
190 flags.Input.OverrideRunNumber = True
191
192 # now set flags according parsed options
193 #if args.samples and not ("SC" in CKeys or flags.LArSCDump.digitsKey=="SC"):
194 # log.warning("Samples asked, but they are not in RunLogger, no output !!!!")
195
196 if args.samples and not ("SC" in flags.LArSCDump.digitsKey):
197 flags.LArSCDump.digitsKey="SC"
198 if args.samplesBas and "SC_ADC_BAS" not in CKeys:
199 CKeys += ["SC_ADC_BAS"]
200 flags.LArSCDump.doSamplesBas=True
201 if args.Et and "SC_ET" not in CKeys:
202 CKeys += ["SC_ET"]
203 if args.EtId and "SC_ET_ID" not in CKeys:
204 CKeys += ["SC_ET_ID"]
205 if args.lheader and "SC_LATOME_HEADER" not in CKeys:
206 CKeys += ["SC_LATOME_HEADER"]
207
208 if args.rod:
209 flags.LArSCDump.doRawChan=True
210 CKeys += ["LArRawChannels"]
211 log.info("Adding ROD energies")
212
213 log.info("Autoconfigured: ")
214 log.info("nSamples: %d nEt: %d digitsKey %s accdigitsKey %s acccalibdigitsKey %s",flags.LArSCDump.nSamples, flags.LArSCDump.nEt, flags.LArSCDump.digitsKey, flags.LArSCDump.accdigitsKey, flags.LArSCDump.acccalibdigitsKey)
215 log.info(CKeys)
216
217 # now construct the job
218 flags.LAr.doAlign=False
219
220 if args.evtree: # should include trigger info
221 flags.Trigger.triggerConfig = 'DB'
222 flags.Trigger.L1.doCTP = True
223 flags.Trigger.L1.doMuon = False
224 flags.Trigger.L1.doCalo = False
225 flags.Trigger.L1.doTopo = False
226
227 flags.Trigger.enableL1CaloLegacy = True
228 flags.Trigger.enableL1CaloPhase1 = False
229
230 if args.TT:
231 flags.Trigger.L1.doCalo = True
232 flags.Trigger.triggerConfig = 'DB'
233
234 flags.LArSCDump.fillNoisyRO=args.noisyRO
235 # in case stores needs to be debugged:
236 #from AthenaCommon.Constants import DEBUG
237 flags.Exec.OutputLevel=args.olevel
238 #flags.Debug.DumpCondStore=True
239 #flags.Debug.DumpDetStore=True
240 #flags.Debug.DumpEvtStore=True
241
242 if args.emf:
243 # additions for EMF
244 flags.IOVDb.SqliteInput="/afs/cern.ch/user/p/pavol/public/EMF_otherCond.db"
245 flags.IOVDb.SqliteFolders = ("/LAR/BadChannelsOfl/BadChannelsSC","/LAR/BadChannels/BadChannelsSC","/LAR/Identifier/OnOffIdMap",)
246
247 if args.etthresh > 0.:
248 flags.LArSCDump.ETThresh = args.etthresh
249
250 if args.etthreshmain > 0.:
251 flags.LArSCDump.ETThreshMain = args.etthreshmain
252
253 flags.lock()
254 flags.dump('LArSCDump.*')
255
256
257
258 #Import the MainServices (boilerplate)
259 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
260 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
261
262 acc = MainServicesCfg(flags)
263 acc.merge(LArGMCfg(flags))
264
265 if args.accsamples:
266 from LArCalibProcessing.LArCalibBaseConfig import LArCalibBaseCfg
267 acc.merge(LArCalibBaseCfg(flags))
268 from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
269 acc.merge(ByteStreamReadCfg(flags))
270
271 if args.evtree: # should include trigger info
272 from LArCafJobs.LArSCDumperSkeleton import L1CaloMenuCfg
273 acc.merge(L1CaloMenuCfg(flags))
274 from TrigDecisionTool.TrigDecisionToolConfig import TrigDecisionToolCfg
275 tdt = acc.getPrimaryAndMerge(TrigDecisionToolCfg(flags))
276 else:
277 tdt = None
278
279
280 if args.fw6 or fwversion==6:
281 # addition for new firmware
282 from IOVDbSvc.IOVDbSvcConfig import addOverride
283 if args.emf:
284 acc.merge(addOverride(flags,"/LAR/Identifier/LatomeMapping","LARIdentifierLatomeMapping-emf-fw6"))
285 else:
286 acc.merge(addOverride(flags,"/LAR/Identifier/LatomeMapping","LARIdentifierLatomeMapping-fw6"))
287 if args.bc:
288 from LArBadChannelTool.LArBadChannelConfig import LArBadFebCfg, LArBadChannelCfg
289 acc.merge(LArBadChannelCfg(flags,None,True))
290 acc.merge(LArBadFebCfg(flags))
291 bckey+='SC'
292
293 if args.geom:
294 acc.addCondAlgo(CompFactory.CaloAlignCondAlg(LArAlignmentStore="",CaloCellPositionShiftFolder=""))
295 acc.addCondAlgo(CompFactory.CaloSuperCellAlignCondAlg())
296 args.offline=True
297
298 from LArCalibTools.LArSC2NtupleConfig import LArSC2NtupleCfg
299 acc.merge(LArSC2NtupleCfg(flags, isEmf = args.emf, AddBadChannelInfo=args.bc, AddFEBTempInfo=False, isSC=True, isFlat=False,
300 OffId=args.offline, AddHash=args.ahash, AddCalib=args.calib, RealGeometry=args.geom, ExpandId=args.expid, BadChanKey=bckey, # from LArCond2NtupleBase
301 NSamples=flags.LArSCDump.nSamples, FTlist=[], FillBCID=args.bcid, ContainerKey=flags.LArSCDump.digitsKey, AccContainerKey=flags.LArSCDump.accdigitsKey, AccCalibContainerKey=flags.LArSCDump.acccalibdigitsKey,# from LArDigits2Ntuple
302 SCContainerKeys=CKeys, OverwriteEventNumber = args.overEvN, # from LArSC2Ntuple
303 FillRODEnergy = flags.LArSCDump.doRawChan,
304 FillLB=args.evtree, FillTriggerType = args.evtree,
305 ETThreshold = flags.LArSCDump.ETThresh, ETThresholdMain = flags.LArSCDump.ETThreshMain, ADCThreshold=args.adcthresh,
306 TrigNames=["L1_EM3","L1_EM7","L1_EM15","L1_EM22VHI","L1_eEM5","L1_eEM15","L1_eEM22M"],
307 TrigDecisionTool=tdt, FillTriggerTowers = args.TT,
308 OutputLevel=args.olevel
309 ))
310 # ROOT file writing
311 if os.path.exists(args.outfile):
312 os.remove(args.outfile)
313 acc.addService(CompFactory.NTupleSvc(Output = [ "FILE1 DATAFILE='"+args.outfile+"' OPT='NEW'" ]))
314 acc.setAppProperty("HistogramPersistency","ROOT")
315
316 # calib runs do not have proper run number in metadata
317 if args.accsamples or args.acccalibsamples:
318 acc.getService("IOVDbSvc").forceRunNumber=int(args.run)
319
320 acc.getService("MessageSvc").defaultLimit=999999
321
322 # some logging
323 acc.getService("MessageSvc").defaultLimit=99999999
324 log.info("Input files to be processed:")
325 for f in flags.Input.Files:
326 log.info(f)
327 log.info("Output file: ")
328 log.info(args.outfile)
329
330 # and run
331 acc.run(args.maxev)