ATLAS Offline Software
LArCalib_PedestalAutoCorrConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaConfiguration.ComponentFactory import CompFactory
4 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
5 
6 def 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 
20 def 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","badAutoCorr",]
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()
161  pedestalTag=tagResolver.getFolderTag(flags.LArCalib.Pedestal.Folder)
162  autocorrTag=tagResolver.getFolderTag(flags.LArCalib.AutoCorr.Folder)
163  del tagResolver
164 
165 
166  #Output (POOL + sqlite) file writing:
167  from RegistrationServices.OutputConditionsAlgConfig import OutputConditionsAlgCfg
168  result.merge(OutputConditionsAlgCfg(flags,
169  outputFile=flags.LArCalib.Output.POOLFile,
170  ObjectList=["LArPedestalComplete#Pedestal#"+flags.LArCalib.Pedestal.Folder,
171  "LArAutoCorrComplete#LArAutoCorr#"+flags.LArCalib.AutoCorr.Folder],
172  IOVTagList=[pedestalTag,autocorrTag],
173  Run1=flags.LArCalib.IOVStart,
174  Run2=flags.LArCalib.IOVEnd
175  ))
176 
177  #RegistrationSvc
178  result.addService(CompFactory.IOVRegistrationSvc(RecreateFolders = False))
179 
180  #Validation (comparision with reference):
181  if flags.LArCalib.doValidation:
182  from IOVDbSvc.IOVDbSvcConfig import addFolders
183 
184  #result.merge(addFolders(flags,"/LAR/ElecCalibOnl/Pedestal<key>PedestalRef</key>","LAR_ONL"))
185  result.merge(addFolders(flags,"/LAR/ElecCalibFlat/Pedestal<key>PedestalRefIn</key>","LAR_ONL","CondAttrListCollection"))
186  LArPedestalCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArPedestalFlat>")
187  result.addCondAlgo(LArPedestalCondAlg("LArFlatPedCondAlg",ReadKey="PedestalRefIn", WriteKey="PedestalRef"))
188  from LArCalibDataQuality.Thresholds import pedThr,rmsThr, pedThrFEB,rmsThrFEB
189  from AthenaCommon.Constants import ERROR,WARNING
190 
191  thePedestalValidationAlg=CompFactory.LArPedestalValidationAlg("PedestalVal")
192  #thePedestalValidationAlg.BadChannelMaskingTool=theLArPedValBCMask
193  thePedestalValidationAlg.UseBadChannelInfo=False
194  thePedestalValidationAlg.ValidationKey="Pedestal"
195  thePedestalValidationAlg.ReferenceKey="PedestalRef"
196  thePedestalValidationAlg.PedestalTolerance=pedThr
197  thePedestalValidationAlg.PedestalRMSTolerance=rmsThr
198  thePedestalValidationAlg.PedestalToleranceFEB=pedThrFEB
199  thePedestalValidationAlg.PedestalRMSToleranceFEB=rmsThrFEB
200  thePedestalValidationAlg.MsgLevelForDeviations=WARNING
201  thePedestalValidationAlg.ListOfDevFEBs="pedFebs.txt"
202  thePedestalValidationAlg.CheckCompletness=True
203  thePedestalValidationAlg.PatchMissingFEBs=True
204  thePedestalValidationAlg.UseCorrChannels=False #Corrections go into the regular data channels
205  if flags.LArCalib.isSC:
206  thePedestalValidationAlg.CablingKey = "LArOnOffIdMapSC"
207  thePedestalValidationAlg.CalibLineKey = "LArCalibIdMapSC"
208  thePedestalValidationAlg.BadChanKey = bcKey
209  result.addEventAlgo(thePedestalValidationAlg)
210 
211 
212  theBadPedestal=CompFactory.LArPedestalValidationAlg("PedestalFail")
213  #theBadPedestal.BadChannelMaskingTool=theLArPedValBCMask
214  theBadPedestal.UseBadChannelInfo=False
215  theBadPedestal.ValidationKey="Pedestal"
216  theBadPedestal.ReferenceKey="PedestalRef"
217  theBadPedestal.PedestalTolerance = ["10,10,10"]
218  theBadPedestal.PedestalRMSTolerance = ["0.5, 0.5, 0.5"]
219  theBadPedestal.PedestalToleranceFEB = ["8, 8, 8"]
220  theBadPedestal.PedestalRMSToleranceFEB = ["1.2, 1.2, 1.2"]
221 
222  theBadPedestal.MsgLevelForDeviations=ERROR
223  theBadPedestal.CheckCompletness=False
224  theBadPedestal.ListOfDevFEBs="Bad_pedFebs.txt"
225  if flags.LArCalib.isSC:
226  theBadPedestal.CablingKey = "LArOnOffIdMapSC"
227  theBadPedestal.CalibLineKey = "LArCalibIdMapSC"
228  theBadPedestal.BadChanKey = bcKey
229  result.addEventAlgo(theBadPedestal)
230 
231 
232  result.merge(addFolders(flags,"/LAR/ElecCalibOfl/AutoCorrs/AutoCorr<key>LArAutoCorrRef</key>","LAR_OFL"))
233  from LArCalibDataQuality.Thresholds import acThr, acThrFEB
234  theAutoCorrValidationAlg=CompFactory.LArAutoCorrValidationAlg("AutoCorrVal")
235  theAutoCorrValidationAlg.UseBadChannelInfo=False
236  theAutoCorrValidationAlg.ValidationKey="LArAutoCorr"
237  theAutoCorrValidationAlg.ReferenceKey="LArAutoCorrRef"
238  theAutoCorrValidationAlg.AutoCorrTolerance=acThr
239  theAutoCorrValidationAlg.AutoCorrToleranceFEB=acThrFEB
240  theAutoCorrValidationAlg.MsgLevelForDeviations=WARNING
241  theAutoCorrValidationAlg.ListOfDevFEBs="ACFebs.txt"
242  theAutoCorrValidationAlg.CheckCompletness=True
243  theAutoCorrValidationAlg.PatchMissingFEBs=True
244  theAutoCorrValidationAlg.UseCorrChannels=False #Corrections go into the regular data channels
245  if flags.LArCalib.isSC:
246  theAutoCorrValidationAlg.CablingKey = "LArOnOffIdMapSC"
247  theAutoCorrValidationAlg.CalibLineKey = "LArCalibIdMapSC"
248  theAutoCorrValidationAlg.BadChanKey = bcKey
249  result.addEventAlgo(theAutoCorrValidationAlg)
250 
251 
252  theBadAutoCorr=CompFactory.LArAutoCorrValidationAlg("AutoCorrFail")
253  theBadAutoCorr.UseBadChannelInfo=False
254  theBadAutoCorr.ValidationKey="LArAutoCorr"
255  theBadAutoCorr.ReferenceKey="LArAutoCorrRef"
256  theBadAutoCorr.AutoCorrTolerance = ["0.15, 0.15, 0.15"]
257  theBadAutoCorr.AutoCorrToleranceFEB = ["0.15, 0.15, 0.15"]
258  theBadAutoCorr.MsgLevelForDeviations=ERROR
259  theBadAutoCorr.CheckFifthSample=True
260  theBadAutoCorr.ListOfDevFEBs="Bad_ACFebs.txt"
261  theBadAutoCorr.CheckCompletness=False
262  if flags.LArCalib.isSC:
263  theBadAutoCorr.CablingKey = "LArOnOffIdMapSC"
264  theBadAutoCorr.CalibLineKey = "LArCalibIdMapSC"
265  theBadAutoCorr.BadChanKey = bcKey
266  result.addEventAlgo(theBadAutoCorr)
267 
268  result.getService("IOVDbSvc").DBInstance=""
269 
270  from PerfMonComps.PerfMonCompsConfig import PerfMonMTSvcCfg
271  result.merge(PerfMonMTSvcCfg(flags))
272 
273 
274  return result
275 
276 
277 if __name__ == "__main__":
278 
279  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
280  from AthenaConfiguration.AllConfigFlags import initConfigFlags
281  from AthenaConfiguration.TestDefaults import defaultGeometryTags
282  from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
283  import sys
284  ConfigFlags=initConfigFlags()
285  addLArCalibFlags(ConfigFlags)
286 
287  ConfigFlags.LArCalib.Input.Dir = "/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/LArCalibProcessing"
288 
289  ConfigFlags.LArCalib.Input.Type="calibration_LArElec-Pedestal"
290  ConfigFlags.LArCalib.Input.RunNumbers=[441236,]
291 
292  ConfigFlags.Input.Files=ConfigFlags.LArCalib.Input.Files
293 
294  ConfigFlags.LArCalib.Output.ROOTFile="larpededest.root"
295  ConfigFlags.LArCalib.Output.POOLFile="larpedestal.pool.root"
296  ConfigFlags.IOVDb.DBConnection="sqlite://;schema=output.sqlite;dbname=CONDBR2"
297  ConfigFlags.IOVDb.GlobalTag="LARCALIB-RUN2-00"
298  ConfigFlags.IOVDb.DatabaseInstance="CONDBR2"
299  ConfigFlags.GeoModel.AtlasVersion=defaultGeometryTags.RUN3
300 
301  ConfigFlags.fillFromArgs()
302  ConfigFlags.lock()
303 
304  from AthenaCommon import Logging
305  log = Logging.logging.getLogger( 'Athena' )
306  log.info("Input files to be processed:")
307  for f in ConfigFlags.Input.Files:
308  log.info(f)
309 
310  cfg=MainServicesCfg(ConfigFlags)
311  cfg.merge(LArPedestalAutoCorrCfg(ConfigFlags))
312 
313  log.info("Start running...")
314  sys.exit(cfg.run().isFailure())
315 
LArCablingConfig.LArOnOffIdMappingSCCfg
def LArOnOffIdMappingSCCfg(configFlags)
Definition: LArCablingConfig.py:65
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.LArElecCalibDBConfig.LArPedestalCondAlg
LArPedestalCondAlg
Definition: LArElecCalibDBConfig.py:26
OutputConditionsAlgConfig.OutputConditionsAlgCfg
def OutputConditionsAlgCfg(flags, name="OutputConditionsAlg", outputFile='condobjs.root', **kwargs)
Definition: OutputConditionsAlgConfig.py:5
python.ByteStreamConfig.ByteStreamReadCfg
def ByteStreamReadCfg(flags, type_names=None)
Definition: Event/ByteStreamCnvSvc/python/ByteStreamConfig.py:25
python.PerfMonCompsConfig.PerfMonMTSvcCfg
def PerfMonMTSvcCfg(flags, **kwargs)
A minimal new-style configuration for PerfMonMTSvc.
Definition: PerfMonCompsConfig.py:10
python.LArFebErrorSummaryMakerConfig.LArFebErrorSummaryMakerCfg
def LArFebErrorSummaryMakerCfg(flags)
Definition: LArFebErrorSummaryMakerConfig.py:7
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
Constants
some useful constants -------------------------------------------------—
python.LArCalib_PedestalAutoCorrConfig.LArPedestalAutoCorrCfg
def LArPedestalAutoCorrCfg(flags)
Definition: LArCalib_PedestalAutoCorrConfig.py:32
python.LArCalib_PedestalAutoCorrConfig.RawCalibDataReadingCfg
def RawCalibDataReadingCfg(flags, digKey)
Definition: LArCalib_PedestalAutoCorrConfig.py:6
python.IOVDbSvcConfig.addFolders
def addFolders(flags, folderStrings, detDb=None, className=None, extensible=False, tag=None, db=None, modifiers='')
Definition: IOVDbSvcConfig.py:72
LArCablingConfig.LArOnOffIdMappingCfg
def LArOnOffIdMappingCfg(configFlags)
Definition: LArCablingConfig.py:62
python.LArCalibBaseConfig.LArCalibBaseCfg
def LArCalibBaseCfg(flags)
Definition: LArCalibBaseConfig.py:5
LArCablingConfig.LArCalibIdMappingSCCfg
def LArCalibIdMappingSCCfg(configFlags)
Definition: LArCablingConfig.py:86
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.LArCalib_PedestalAutoCorrConfig.AccCalibDataReadingCfg
def AccCalibDataReadingCfg(flags, digKey)
Definition: LArCalib_PedestalAutoCorrConfig.py:20
python.LArCalibConfigFlags.addLArCalibFlags
def addLArCalibFlags(flags, isSC=False)
Definition: LArCalibConfigFlags.py:3
LArCablingConfig.LArCalibIdMappingCfg
def LArCalibIdMappingCfg(configFlags)
Definition: LArCablingConfig.py:83