ATLAS Offline Software
Loading...
Searching...
No Matches
LArCalib_PedestalAutoCorrConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
3from AthenaConfiguration.ComponentFactory import CompFactory
4from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
5
6def RawCalibDataReadingCfg(flags, digKey):
7 result=ComponentAccumulator()
8 result.addEventAlgo(CompFactory.LArRawCalibDataReadingAlg(LArDigitKey=digKey,
9 LArFebHeaderKey="LArFebHeader",
10 FailOnCorruption=False,
11 SubCaloPreselection=flags.LArCalib.Input.SubDet,
12 PosNegPreselection=flags.LArCalib.Preselection.Side,
13 BEPreselection=flags.LArCalib.Preselection.BEC,
14 FTNumPreselection=flags.LArCalib.Preselection.FT))
15 result.addEventAlgo(CompFactory.LArDigitsAccumulator("LArDigitsAccumulator", KeyList = [digKey],
16 LArAccuDigitContainerName = "", NTriggersPerStep = 100,
17 isSC = flags.LArCalib.isSC, DropPercentTrig = 0))
18 return result
19
20def AccCalibDataReadingCfg(flags, digKey):
21 result=ComponentAccumulator()
22 result.addEventAlgo(CompFactory.LArRawCalibDataReadingAlg(LArAccDigitKey=digKey,
23 LArFebHeaderKey="LArFebHeader",
24 FailOnCorruption=False,
25 SubCaloPreselection=flags.LArCalib.Input.SubDet,
26 PosNegPreselection=flags.LArCalib.Preselection.Side,
27 BEPreselection=flags.LArCalib.Preselection.BEC,
28 FTNumPreselection=flags.LArCalib.Preselection.FT))
29 return result
30
31
33
34 #Get basic services and cond-algos
35 from LArCalibProcessing.LArCalibBaseConfig import LArCalibBaseCfg
36 result=LArCalibBaseCfg(flags)
37
38 #Add ByteStream reading
39 from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
40 result.merge(ByteStreamReadCfg(flags))
41
42
43 #Calibration runs are taken in fixed gain.
44 #The SG key of the digit-container is name of the gain
45 gainStrMap={0:"HIGH",1:"MEDIUM",2:"LOW"}
46
47 if not flags.LArCalib.isSC:
48 digKey=gainStrMap[flags.LArCalib.Gain]
49 if flags.LArCalib.Input.isRawData:
50 result.addEventAlgo(CompFactory.LArRawCalibDataReadingAlg(LArDigitKey=digKey,
51 LArFebHeaderKey="LArFebHeader",
52 FailOnCorruption=False,
53 SubCaloPreselection=flags.LArCalib.Input.SubDet,
54 PosNegPreselection=flags.LArCalib.Preselection.Side,
55 BEPreselection=flags.LArCalib.Preselection.BEC,
56 FTNumPreselection=flags.LArCalib.Preselection.FT))
57
58 result.addEventAlgo(CompFactory.LArDigitsAccumulator("LArDigitsAccumulator", KeyList = [digKey],
59 LArAccuDigitContainerName = "", NTriggersPerStep = 100,
60 isSC = flags.LArCalib.isSC, DropPercentTrig = 0))
61 else:
62 result.merge(AccCalibDataReadingCfg(flags, digKey))
63
64 from LArROD.LArFebErrorSummaryMakerConfig import LArFebErrorSummaryMakerCfg
65 result.merge(LArFebErrorSummaryMakerCfg(flags))
66 result.getEventAlgo("LArFebErrorSummaryMaker").CheckAllFEB=False
67 result.addEventAlgo(CompFactory.LArBadEventCatcher(CheckAccCalibDigitCont=True,
68 CheckBSErrors=True,
69 KeyList=[digKey,],
70 StopOnError=False))
71
72 else:
73 digKey="SC"
74 theLArLATOMEDecoder = CompFactory.LArLATOMEDecoder("LArLATOMEDecoder",
75 IgnoreBarrelChannels = flags.LArCalib.SCIgnoreBarrelChannels,
76 IgnoreEndcapChannels = flags.LArCalib.SCIgnoreEndcapChannels)
77
78 if flags.LArCalib.Input.isRawData:
79 result.addEventAlgo(CompFactory.LArRawSCDataReadingAlg(adcCollKey = digKey, adcBasCollKey = "", etCollKey = "",
80 etIdCollKey = "", LATOMEDecoder = theLArLATOMEDecoder))
81 result.addEventAlgo(CompFactory.LArDigitsAccumulator("LArDigitsAccumulator", KeyList = [digKey],
82 LArAccuDigitContainerName = "", NTriggersPerStep = 100,
83 isSC = flags.LArCalib.isSC, DropPercentTrig = 0))
84 else:
85 # this needs also legacy maps
86 from LArCabling.LArCablingConfig import LArCalibIdMappingCfg,LArOnOffIdMappingCfg,LArCalibIdMappingSCCfg,LArOnOffIdMappingSCCfg
87 result.merge(LArOnOffIdMappingCfg(flags))
88 result.merge(LArCalibIdMappingSCCfg(flags))
89 result.merge(LArOnOffIdMappingSCCfg(flags))
90 result.merge(LArCalibIdMappingCfg(flags))
91
92 result.addEventAlgo(CompFactory.LArRawSCCalibDataReadingAlg(LArSCAccDigitKey = digKey, LATOMEDecoder = theLArLATOMEDecoder))
93
94 LArPedACBuilder=CompFactory.LArPedestalAutoCorrBuilder()
95 LArPedACBuilder.KeyList = [digKey,]
96 LArPedACBuilder.PedestalKey = "Pedestal"
97 LArPedACBuilder.AutoCorrKey = "LArAutoCorr"
98 LArPedACBuilder.GroupingType = flags.LArCalib.GroupingType
99
100 result.addEventAlgo(LArPedACBuilder)
101
102 if flags.LArCalib.isSC:
103 bcKey = "LArBadChannelSC"
104 else:
105 bcKey = "LArBadChannel"
106
107 if flags.LArCalib.CorrectBadChannels:
108 theLArAcorrPatcher=CompFactory.getComp("LArCalibPatchingAlg<LArAutoCorrComplete>")("LArAcorrPatch")
109 theLArAcorrPatcher.ContainerKey = "LArAutoCorr"
110 theLArAcorrPatcher.BadChanKey = bcKey
111 theLArAcorrPatcher.SuperCells = flags.LArCalib.isSC
112 theLArAcorrPatcher.PatchMethod="FEBNeighbor"
114 if flags.LArCalib.isSC:
115 theLArAcorrPatcher.ProblemsToPatch = [ "problematicForUnknownReason","transmissionErrorFibre"]
116 theLArAcorrPatcher.OnOffMap="LArOnOffIdMapSC"
117 theLArAcorrPatcher.CalibLineKey="LArCalibIdMapSC"
118 else:
119 theLArAcorrPatcher.ProblemsToPatch = [ "badAutoCorr", ]
120
121 theLArAcorrPatcher.UseCorrChannels=False
122 result.addEventAlgo(theLArAcorrPatcher)
123 pass
124
125 #ROOT ntuple writing:
126 rootfile=flags.LArCalib.Output.ROOTFile
127 if rootfile != "":
128 result.addEventAlgo(CompFactory.LArPedestals2Ntuple(ContainerKey = "Pedestal",
129 AddFEBTempInfo = False,
130 RealGeometry = True,
131 OffId = True,
132 AddCalib = True,
133 isSC = flags.LArCalib.isSC,
134 BadChanKey = bcKey
135 )
136 )
137
138 result.addEventAlgo(CompFactory.LArAutoCorr2Ntuple(ContainerKey = "LArAutoCorr",
139 AddFEBTempInfo = False, isSC = flags.LArCalib.isSC,
140 BadChanKey = bcKey,
141 OffId=True,
142 ApplyCorrection = True,
143 AddCorrUndo = True,
144 AddCalib = True
145 )
146 )
147
148 import os
149 if os.path.exists(rootfile):
150 os.remove(rootfile)
151 result.addService(CompFactory.NTupleSvc(Output = [ "FILE1 DATAFILE='"+rootfile+"' OPT='NEW'" ]))
152 result.setAppProperty("HistogramPersistency","ROOT")
153 pass # end if ROOT ntuple writing
154
155
156
157 #Get the current folder tag by interrogating the database:
158 from LArCalibProcessing.utils import FolderTagResolver
159 FolderTagResolver._globalTag=flags.IOVDb.GlobalTag
160 tagResolver=FolderTagResolver(dbname=flags.LArCalib.Input.CoolOflP1Replica)
161 pedestalTag=tagResolver.getFolderTag(flags.LArCalib.Pedestal.Folder)
162 autocorrTag=tagResolver.getFolderTag(flags.LArCalib.AutoCorr.Folder)
163 del tagResolver
164
165 #Output (POOL + sqlite) file writing:
166 from RegistrationServices.OutputConditionsAlgConfig import OutputConditionsAlgCfg
167 result.merge(OutputConditionsAlgCfg(flags,
168 outputFile=flags.LArCalib.Output.POOLFile,
169 ObjectList=["LArPedestalComplete#Pedestal#"+flags.LArCalib.Pedestal.Folder,
170 "LArAutoCorrComplete#LArAutoCorr#"+flags.LArCalib.AutoCorr.Folder],
171 IOVTagList=[pedestalTag,autocorrTag],
172 Run1=flags.LArCalib.IOVStart,
173 Run2=flags.LArCalib.IOVEnd
174 ))
175
176 #RegistrationSvc
177 result.addService(CompFactory.IOVRegistrationSvc(RecreateFolders = False))
178
179 #Validation (comparision with reference):
180 if flags.LArCalib.doValidation:
181 from IOVDbSvc.IOVDbSvcConfig import addFolders
182
183 result.merge(addFolders(flags,"/LAR/ElecCalibFlat/Pedestal<key>PedestalRefIn</key>","LAR_ONL","CondAttrListCollection"))
184 LArPedestalCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArPedestalFlat>")
185 result.addCondAlgo(LArPedestalCondAlg("LArFlatPedCondAlg",ReadKey="PedestalRefIn", WriteKey="PedestalRef"))
186 from LArCalibDataQuality.Thresholds import pedThr,rmsThr, pedThrFEB,rmsThrFEB
187 from AthenaCommon.Constants import ERROR,WARNING
188
189 thePedestalValidationAlg=CompFactory.LArPedestalValidationAlg("PedestalVal")
190 #thePedestalValidationAlg.BadChannelMaskingTool=theLArPedValBCMask
191 thePedestalValidationAlg.UseBadChannelInfo=False
192 thePedestalValidationAlg.ValidationKey="Pedestal"
193 thePedestalValidationAlg.ReferenceKey="PedestalRef"
194 thePedestalValidationAlg.PedestalTolerance=pedThr
195 thePedestalValidationAlg.PedestalRMSTolerance=rmsThr
196 thePedestalValidationAlg.PedestalToleranceFEB=pedThrFEB
197 thePedestalValidationAlg.PedestalRMSToleranceFEB=rmsThrFEB
198 thePedestalValidationAlg.MsgLevelForDeviations=WARNING
199 thePedestalValidationAlg.ListOfDevFEBs="pedFebs.txt"
200 thePedestalValidationAlg.CheckCompletness=True
201 thePedestalValidationAlg.PatchMissingFEBs=True
202 thePedestalValidationAlg.UseCorrChannels=False #Corrections go into the regular data channels
203 if flags.LArCalib.isSC:
204 thePedestalValidationAlg.CablingKey = "LArOnOffIdMapSC"
205 thePedestalValidationAlg.CalibLineKey = "LArCalibIdMapSC"
206 thePedestalValidationAlg.BadChanKey = bcKey
207 result.addEventAlgo(thePedestalValidationAlg)
208
209
210 theBadPedestal=CompFactory.LArPedestalValidationAlg("PedestalFail")
211 #theBadPedestal.BadChannelMaskingTool=theLArPedValBCMask
212 theBadPedestal.UseBadChannelInfo=False
213 theBadPedestal.ValidationKey="Pedestal"
214 theBadPedestal.ReferenceKey="PedestalRef"
215 theBadPedestal.PedestalTolerance = ["10,10,10"]
216 theBadPedestal.PedestalRMSTolerance = ["0.5, 0.5, 0.5"]
217 theBadPedestal.PedestalToleranceFEB = ["8, 8, 8"]
218 theBadPedestal.PedestalRMSToleranceFEB = ["1.2, 1.2, 1.2"]
219
220 theBadPedestal.MsgLevelForDeviations=ERROR
221 theBadPedestal.CheckCompletness=False
222 theBadPedestal.ListOfDevFEBs="Bad_pedFebs.txt"
223 if flags.LArCalib.isSC:
224 theBadPedestal.CablingKey = "LArOnOffIdMapSC"
225 theBadPedestal.CalibLineKey = "LArCalibIdMapSC"
226 theBadPedestal.BadChanKey = bcKey
227 result.addEventAlgo(theBadPedestal)
228
229
230 result.merge(addFolders(flags,"/LAR/ElecCalibOfl/AutoCorrs/AutoCorr<key>LArAutoCorrRef</key>","LAR_OFL"))
231 from LArCalibDataQuality.Thresholds import acThr, acThrFEB
232 theAutoCorrValidationAlg=CompFactory.LArAutoCorrValidationAlg("AutoCorrVal")
233 theAutoCorrValidationAlg.UseBadChannelInfo=False
234 theAutoCorrValidationAlg.ValidationKey="LArAutoCorr"
235 theAutoCorrValidationAlg.ReferenceKey="LArAutoCorrRef"
236 theAutoCorrValidationAlg.AutoCorrTolerance=acThr
237 theAutoCorrValidationAlg.AutoCorrToleranceFEB=acThrFEB
238 theAutoCorrValidationAlg.MsgLevelForDeviations=WARNING
239 theAutoCorrValidationAlg.ListOfDevFEBs="ACFebs.txt"
240 theAutoCorrValidationAlg.CheckCompletness=True
241 theAutoCorrValidationAlg.PatchMissingFEBs=True
242 theAutoCorrValidationAlg.UseCorrChannels=False #Corrections go into the regular data channels
243 if flags.LArCalib.isSC:
244 theAutoCorrValidationAlg.CablingKey = "LArOnOffIdMapSC"
245 theAutoCorrValidationAlg.CalibLineKey = "LArCalibIdMapSC"
246 theAutoCorrValidationAlg.BadChanKey = bcKey
247 result.addEventAlgo(theAutoCorrValidationAlg)
248
249
250 theBadAutoCorr=CompFactory.LArAutoCorrValidationAlg("AutoCorrFail")
251 theBadAutoCorr.UseBadChannelInfo=False
252 theBadAutoCorr.ValidationKey="LArAutoCorr"
253 theBadAutoCorr.ReferenceKey="LArAutoCorrRef"
254 theBadAutoCorr.AutoCorrTolerance = ["0.15, 0.15, 0.15"]
255 theBadAutoCorr.AutoCorrToleranceFEB = ["0.15, 0.15, 0.15"]
256 theBadAutoCorr.MsgLevelForDeviations=ERROR
257 theBadAutoCorr.CheckFifthSample=True
258 theBadAutoCorr.ListOfDevFEBs="Bad_ACFebs.txt"
259 theBadAutoCorr.CheckCompletness=False
260 if flags.LArCalib.isSC:
261 theBadAutoCorr.CablingKey = "LArOnOffIdMapSC"
262 theBadAutoCorr.CalibLineKey = "LArCalibIdMapSC"
263 theBadAutoCorr.BadChanKey = bcKey
264 result.addEventAlgo(theBadAutoCorr)
265
266 result.getService("IOVDbSvc").DBInstance=""
267
268 from PerfMonComps.PerfMonCompsConfig import PerfMonMTSvcCfg
269 result.merge(PerfMonMTSvcCfg(flags))
270
271
272 return result
273
274
275if __name__ == "__main__":
276
277 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
278 from AthenaConfiguration.AllConfigFlags import initConfigFlags
279 from AthenaConfiguration.TestDefaults import defaultGeometryTags
280 from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
281 import sys
282 ConfigFlags=initConfigFlags()
283 addLArCalibFlags(ConfigFlags)
284
285 ConfigFlags.LArCalib.Input.Dir = "/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/LArCalibProcessing"
286
287 ConfigFlags.LArCalib.Input.Type="calibration_LArElec-Pedestal"
288 ConfigFlags.LArCalib.Input.RunNumbers=[441236,]
289
290 ConfigFlags.Input.Files=ConfigFlags.LArCalib.Input.Files
291
292 ConfigFlags.LArCalib.Output.ROOTFile="larpededest.root"
293 ConfigFlags.LArCalib.Output.POOLFile="larpedestal.pool.root"
294 ConfigFlags.IOVDb.DBConnection="sqlite://;schema=output.sqlite;dbname=CONDBR2"
295 ConfigFlags.IOVDb.GlobalTag="LARCALIB-RUN2-00"
296 ConfigFlags.IOVDb.DatabaseInstance="CONDBR2"
297 ConfigFlags.GeoModel.AtlasVersion=defaultGeometryTags.RUN3
298
299 ConfigFlags.fillFromArgs()
300 ConfigFlags.lock()
301
302 from AthenaCommon import Logging
303 log = Logging.logging.getLogger( 'Athena' )
304 log.info("Input files to be processed:")
305 for f in ConfigFlags.Input.Files:
306 log.info(f)
307
308 cfg=MainServicesCfg(ConfigFlags)
309 cfg.merge(LArPedestalAutoCorrCfg(ConfigFlags))
310 log.info("Start running...")
311 sys.exit(cfg.run().isFailure())
312