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
55 args = parser.parse_args()
56 if help in args and args.help is not None and args.help:
57 parser.print_help()
58 sys.exit(0)
59
60 for _, value in args._get_kwargs():
61 if value is not None:
62 log.debug(value)
63
64 #Import the flag-container that is the arguemnt to the configuration methods
65 from AthenaConfiguration.AllConfigFlags import initConfigFlags
66 flags=initConfigFlags()
67 if args.accsamples or args.acccalibsamples:
68 from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
69 addLArCalibFlags(flags, True)
70 if len(args.posneg) >= 0:
71 flags.LArCalib.Preselection.Side = args.posneg
72 if len(args.be) >=0:
73 flags.LArCalib.Preselection.BEC = args.be
74 if len(args.ft) > 0:
75 flags.LArCalib.Preselection.FT = args.ft
76 #add SC dumping specific flags
77 from LArCafJobs.LArSCDumperFlags import addSCDumpFlags
78 addSCDumpFlags(flags)
79
80 # check samples combination:
81 if (args.accsamples or args.acccalibsamples) and (args.samples or args.samplesBas):
82 log.error('Could not dump both samples and accumulated calib samples')
83 sys.exit(1)
84 if args.accsamples and args.acccalibsamples:
85 log.error('Could not dump both accsamples and acc calib samples')
86 sys.exit(1)
87
88 if len(args.infile) > 0:
89 flags.Input.Files = [args.infile]
90 elif len(args.inppatt) > 0:
91 from LArCalibProcessing.GetInputFiles import GetInputFilesFromPattern
92 flags.Input.Files = GetInputFilesFromPattern(args.indir,args.inppatt)
93 else:
94 from LArCalibProcessing.GetInputFiles import GetInputFilesFromPrefix
95 flags.Input.Files = GetInputFilesFromPrefix(args.indir,args.inpref)
96
97 if args.run != 0:
98 flags.Input.RunNumbers = [args.run]
99
100 # geometry
101 from AthenaConfiguration.TestDefaults import defaultGeometryTags
102 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
103
104 if args.accsamples:
105 flags.LArSCDump.accdigitsKey="accSC"
106 else:
107 flags.LArSCDump.accdigitsKey=""
108 if args.acccalibsamples:
109 flags.LArSCDump.acccalibdigitsKey="acccalibSC"
110 else:
111 flags.LArSCDump.acccalibdigitsKey=""
112
113 flags.LArSCDump.doBC = args.bc
114 bckey='LArBadChannel'
115
116 flags.LArSCDump.digitsKey=""
117 CKeys=[]
118 fwversion=5
119
120 # autoconfig
121 from LArConditionsCommon.LArRunFormat import getLArDTInfoForRun
122 try:
123 runinfo=getLArDTInfoForRun(flags.Input.RunNumbers[0], connstring="COOLONL_LAR/CONDBR2")
124 except Exception:
125 log.warning("Could not get DT run info, using defaults !")
126 flags.LArSCDump.doEt=True
127 if args.nsamp > 0:
128 flags.LArSCDump.nSamples=args.nsamp
129 else:
130 flags.LArSCDump.nSamples=5
131 flags.LArSCDump.nEt=1
132 if args.samples:
133 flags.LArSCDump.digitsKey="SC"
134 CKeys=["SC_ET"]
135 else:
136 fwversion=runinfo.FWversion()
137 if not (args.accsamples or args.acccalibsamples):
138 flags.LArSCDump.digitsKey=""
139 for i in range(0,len(runinfo.streamTypes())):
140 if args.EtId and runinfo.streamTypes()[i] == "SelectedEnergy":
141 CKeys += ["SC_ET_ID"]
142 flags.LArSCDump.doEt=True
143 flags.LArSCDump.nEt=runinfo.streamLengths()[i]
144 elif args.Et and runinfo.streamTypes()[i] == "Energy":
145 CKeys += ["SC_ET"]
146 flags.LArSCDump.doEt=True
147 flags.LArSCDump.nEt=runinfo.streamLengths()[i]
148 elif args.samples and runinfo.streamTypes()[i] == "RawADC":
149 flags.LArSCDump.digitsKey="SC"
150 if args.nsamp > 0:
151 flags.LArSCDump.nSamples=args.nsamp
152 else:
153 flags.LArSCDump.nSamples=runinfo.streamLengths()[i]
154 elif args.samplesBas and runinfo.streamTypes()[i] == "ADC":
155 CKeys += ["SC_ADC_BAS"]
156 if args.nsamp > 0:
157 flags.LArSCDump.nSamples=args.nsamp
158 else:
159 flags.LArSCDump.nSamples=runinfo.streamLengths()[i]
160 if args.nsamp > 0 and args.nsamp < flags.LArSCDump.nSamples:
161 flags.LArSCDump.nSamples=args.nsamp
162
163 # calib runs do not have info about accumulation
164 if args.accsamples or args.acccalibsamples:
165 flags.Input.OverrideRunNumber = True
166
167 # now set flags according parsed options
168 #if args.samples and not ("SC" in CKeys or flags.LArSCDump.digitsKey=="SC"):
169 # log.warning("Samples asked, but they are not in RunLogger, no output !!!!")
170
171 if args.samples and not ("SC" in flags.LArSCDump.digitsKey):
172 flags.LArSCDump.digitsKey="SC"
173 if args.samplesBas and "SC_ADC_BAS" not in CKeys:
174 CKeys += ["SC_ADC_BAS"]
175 flags.LArSCDump.doSamplesBas=True
176 if args.Et and "SC_ET" not in CKeys:
177 CKeys += ["SC_ET"]
178 if args.EtId and "SC_ET_ID" not in CKeys:
179 CKeys += ["SC_ET_ID"]
180 if args.lheader and "SC_LATOME_HEADER" not in CKeys:
181 CKeys += ["SC_LATOME_HEADER"]
182
183 if args.rod:
184 flags.LArSCDump.doRawChan=True
185 CKeys += ["LArRawChannels"]
186 log.info("Adding ROD energies")
187
188 log.info("Autoconfigured: ")
189 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)
190 log.info(CKeys)
191
192 # now construct the job
193 flags.LAr.doAlign=False
194
195 if args.evtree: # should include trigger info
196 flags.Trigger.triggerConfig = 'DB'
197 flags.Trigger.L1.doCTP = True
198 flags.Trigger.L1.doMuon = False
199 flags.Trigger.L1.doCalo = False
200 flags.Trigger.L1.doTopo = False
201
202 flags.Trigger.enableL1CaloLegacy = True
203 flags.Trigger.enableL1CaloPhase1 = False
204
205 if args.TT:
206 flags.Trigger.L1.doCalo = True
207 flags.Trigger.triggerConfig = 'DB'
208
209 flags.LArSCDump.fillNoisyRO=args.noisyRO
210 # in case stores needs to be debugged:
211 #from AthenaCommon.Constants import DEBUG
212 flags.Exec.OutputLevel=args.olevel
213 #flags.Debug.DumpCondStore=True
214 #flags.Debug.DumpDetStore=True
215 #flags.Debug.DumpEvtStore=True
216
217 if args.emf:
218 # additions for EMF
219 flags.IOVDb.SqliteInput="/afs/cern.ch/user/p/pavol/public/EMF_otherCond.db"
220 flags.IOVDb.SqliteFolders = ("/LAR/BadChannelsOfl/BadChannelsSC","/LAR/BadChannels/BadChannelsSC","/LAR/Identifier/OnOffIdMap",)
221
222 if args.etthresh > 0.:
223 flags.LArSCDump.ETThresh = args.etthresh
224
225 if args.etthreshmain > 0.:
226 flags.LArSCDump.ETThreshMain = args.etthreshmain
227
228 flags.lock()
229 flags.dump('LArSCDump.*')
230
231
232
233 #Import the MainServices (boilerplate)
234 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
235 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
236
237 acc = MainServicesCfg(flags)
238 acc.merge(LArGMCfg(flags))
239
240 if args.accsamples:
241 from LArCalibProcessing.LArCalibBaseConfig import LArCalibBaseCfg
242 acc.merge(LArCalibBaseCfg(flags))
243 from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
244 acc.merge(ByteStreamReadCfg(flags))
245
246 if args.evtree: # should include trigger info
247 from LArCafJobs.LArSCDumperSkeleton import L1CaloMenuCfg
248 acc.merge(L1CaloMenuCfg(flags))
249 from TrigDecisionTool.TrigDecisionToolConfig import TrigDecisionToolCfg
250 tdt = acc.getPrimaryAndMerge(TrigDecisionToolCfg(flags))
251 else:
252 tdt = None
253
254
255 if args.fw6 or fwversion==6:
256 # addition for new firmware
257 from IOVDbSvc.IOVDbSvcConfig import addOverride
258 if args.emf:
259 acc.merge(addOverride(flags,"/LAR/Identifier/LatomeMapping","LARIdentifierLatomeMapping-emf-fw6"))
260 else:
261 acc.merge(addOverride(flags,"/LAR/Identifier/LatomeMapping","LARIdentifierLatomeMapping-fw6"))
262 if args.bc:
263 from LArBadChannelTool.LArBadChannelConfig import LArBadFebCfg, LArBadChannelCfg
264 acc.merge(LArBadChannelCfg(flags,None,True))
265 acc.merge(LArBadFebCfg(flags))
266 bckey+='SC'
267
268 if args.geom:
269 acc.addCondAlgo(CompFactory.CaloAlignCondAlg(LArAlignmentStore="",CaloCellPositionShiftFolder=""))
270 acc.addCondAlgo(CompFactory.CaloSuperCellAlignCondAlg())
271 args.offline=True
272
273 from LArCalibTools.LArSC2NtupleConfig import LArSC2NtupleCfg
274 acc.merge(LArSC2NtupleCfg(flags, isEmf = args.emf, AddBadChannelInfo=args.bc, AddFEBTempInfo=False, isSC=True, isFlat=False,
275 OffId=args.offline, AddHash=args.ahash, AddCalib=args.calib, RealGeometry=args.geom, ExpandId=args.expid, BadChanKey=bckey, # from LArCond2NtupleBase
276 NSamples=flags.LArSCDump.nSamples, FTlist=[], FillBCID=args.bcid, ContainerKey=flags.LArSCDump.digitsKey, AccContainerKey=flags.LArSCDump.accdigitsKey, AccCalibContainerKey=flags.LArSCDump.acccalibdigitsKey,# from LArDigits2Ntuple
277 SCContainerKeys=CKeys, OverwriteEventNumber = args.overEvN, # from LArSC2Ntuple
278 FillRODEnergy = flags.LArSCDump.doRawChan,
279 FillLB=args.evtree, FillTriggerType = args.evtree,
280 ETThreshold = flags.LArSCDump.ETThresh, ETThresholdMain = flags.LArSCDump.ETThreshMain, ADCThreshold=args.adcthresh,
281 TrigNames=["L1_EM3","L1_EM7","L1_EM15","L1_EM22VHI","L1_eEM5","L1_eEM15","L1_eEM22M"],
282 TrigDecisionTool=tdt, FillTriggerTowers = args.TT,
283 OutputLevel=args.olevel
284 ))
285 # ROOT file writing
286 if os.path.exists(args.outfile):
287 os.remove(args.outfile)
288 acc.addService(CompFactory.NTupleSvc(Output = [ "FILE1 DATAFILE='"+args.outfile+"' OPT='NEW'" ]))
289 acc.setAppProperty("HistogramPersistency","ROOT")
290
291 # calib runs do not have proper run number in metadata
292 if args.accsamples or args.acccalibsamples:
293 acc.getService("IOVDbSvc").forceRunNumber=int(args.run)
294
295 acc.getService("MessageSvc").defaultLimit=999999
296
297 # some logging
298 acc.getService("MessageSvc").defaultLimit=99999999
299 log.info("Input files to be processed:")
300 for f in flags.Input.Files:
301 log.info(f)
302 log.info("Output file: ")
303 log.info(args.outfile)
304
305 # and run
306 acc.run(args.maxev)