ATLAS Offline Software
LArCalib_RampConfig.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.MainServicesConfig import MainServicesCfg
5 
6 def LArRampCfg(flags):
7  #Get basic services and cond-algos
8  from LArCalibProcessing.LArCalibBaseConfig import LArCalibBaseCfg,chanSelStr
9  result=LArCalibBaseCfg(flags)
10 
11  #Add ByteStream reading
12  from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
13  result.merge(ByteStreamReadCfg(flags))
14 
15  #Calibration runs are taken in fixed gain.
16  #The SG key of the digit-container is name of the gain
17  gainStrMap={0:"HIGH",1:"MEDIUM",2:"LOW"}
18  digKey=gainStrMap[flags.LArCalib.Gain]
19 
20  from LArCalibProcessing.utils import FolderTagResolver
21  FolderTagResolver._globalTag=flags.IOVDb.GlobalTag
22  tagResolver=FolderTagResolver()
23  pedestalTag=tagResolver.getFolderTag(flags.LArCalib.Pedestal.Folder)
24  caliOFCTag=tagResolver.getFolderTag(flags.LArCalib.OFCCali.Folder)
25 
26  rampTag=tagResolver.getFolderTag(flags.LArCalib.Ramp.Folder)
27  del tagResolver
28 
29  print("pedestalTag",pedestalTag)
30  print("rampTag",rampTag)
31 
32 
33  from IOVDbSvc.IOVDbSvcConfig import addFolders
34  result.merge(addFolders(flags,flags.LArCalib.Pedestal.Folder,detDb=flags.LArCalib.Input.Database, tag=pedestalTag, modifiers=chanSelStr(flags),
35  className="LArPedestalComplete"))
36  result.merge(addFolders(flags,flags.LArCalib.OFCCali.Folder,detDb=flags.LArCalib.Input.Database2, tag=caliOFCTag, modifiers=chanSelStr(flags)))
37 
38 
39  if not flags.LArCalib.isSC:
40  result.addEventAlgo(CompFactory.LArRawCalibDataReadingAlg(LArAccCalibDigitKey=digKey,
41  LArFebHeaderKey="LArFebHeader",
42  SubCaloPreselection=flags.LArCalib.Input.SubDet,
43  PosNegPreselection=flags.LArCalib.Preselection.Side,
44  BEPreselection=flags.LArCalib.Preselection.BEC,
45  FTNumPreselection=flags.LArCalib.Preselection.FT))
46 
47  from LArROD.LArFebErrorSummaryMakerConfig import LArFebErrorSummaryMakerCfg
48  result.merge(LArFebErrorSummaryMakerCfg(flags))
49  result.getEventAlgo("LArFebErrorSummaryMaker").CheckAllFEB=False
50 
51  if flags.LArCalib.Input.SubDet == "EM":
52  from LArCalibProcessing.LArStripsXtalkCorrConfig import LArStripsXtalkCorrCfg
53  result.merge(LArStripsXtalkCorrCfg(flags,[digKey,]))
54 
55  theLArCalibShortCorrector = CompFactory.LArCalibShortCorrector(KeyList = [digKey,])
56  result.addEventAlgo(theLArCalibShortCorrector)
57  else:
58  digKey="SC"
59  theLArLATOMEDecoder = CompFactory.LArLATOMEDecoder("LArLATOMEDecoder")
60  if flags.LArCalib.Input.isRawData:
61  result.addEventAlgo(CompFactory.LArRawSCDataReadingAlg(adcCollKey = digKey, adcBasCollKey = "", etCollKey = "",
62  etIdCollKey = "", LATOMEDecoder = theLArLATOMEDecoder))
63  from LArCalibProcessing.LArCalib_CalibDigitsMakerConfig import LArCalibDigitsMakerCfg
64  result.merge(LArCalibDigitsMakerCfg(flags,digKey))
65 
66  else:
67  # this needs also legacy maps
68  from LArCabling.LArCablingConfig import LArCalibIdMappingCfg,LArOnOffIdMappingCfg
69  result.merge(LArOnOffIdMappingCfg(flags))
70  result.merge(LArCalibIdMappingCfg(flags))
71 
72  result.addEventAlgo(CompFactory.LArRawSCCalibDataReadingAlg(LArSCAccCalibDigitKey = digKey, LATOMEDecoder = theLArLATOMEDecoder))
73 
74  pass
75 
76 
77  bcKey = "LArBadChannelSC" if flags.LArCalib.isSC else "LArBadChannel"
78 
79 
80  theLArRampBuilder = CompFactory.LArRampBuilder()
81  theLArRampBuilder.KeyList = [digKey,]
82  theLArRampBuilder.SubtractDac0 = False
83  if flags.LArCalib.isSC:
84  theLArRampBuilder.ProblemsToMask=["deadCalib","deadReadout","deadPhys","maskedOSUM","OffOFCs","transmissionErrorFibre",]
85  else:
86  theLArRampBuilder.ProblemsToMask=["deadCalib","deadReadout","deadPhys","almostDead","short"]
87 
88  theLArRampBuilder.RecoType = "OF"
89  theLArRampBuilder.PeakOFTool=CompFactory.LArOFPeakRecoTool(UseShape = False,OutputLevel=2)
90 
91  theLArRampBuilder.DAC0 = 4294967294
92  theLArRampBuilder.StoreRawRamp = True
93  theLArRampBuilder.StoreRecRamp = True
94  theLArRampBuilder.Polynom = 1
95  theLArRampBuilder.RampRange = 3600 # Check on the raw data ADC sample before ped subtraction and pulse reconstruction to include point in fit
96  theLArRampBuilder.correctBias = False
97  #theLArRampBuilder.ConsecutiveADCs = 0
98  theLArRampBuilder.minDAC = 10 # minimum DAC value to use in fit
99  theLArRampBuilder.KeyOutput = "LArRamp"
100  theLArRampBuilder.DeadChannelCut = -9999
101  theLArRampBuilder.GroupingType = flags.LArCalib.GroupingType
102  #theLArRampBuilder.LongNtuple = False
103 
104  theLArRampBuilder.isSC = flags.LArCalib.isSC
105  theLArRampBuilder.BadChanKey = bcKey
106 
107  if "HEC" in flags.LArCalib.Input.SubDet:
108  theLArRampBuilder.isHEC = True
109  theLArRampBuilder.HECKey = "LArHEC_PAmap"
110  result.merge(addFolders(flags,'/LAR/ElecCalibOfl/HecPAMap','LAR_OFL'))
111 
112  result.addEventAlgo(theLArRampBuilder)
113 
114 
115  # Bad-channel patching
116  if flags.LArCalib.CorrectBadChannels:
117  LArRampPatcher=CompFactory.getComp("LArCalibPatchingAlg<LArRampComplete>")
118  theLArRampPatcher=LArRampPatcher("LArRampPatcher")
119  theLArRampPatcher.ContainerKey="LArRamp"
120  theLArRampPatcher.BadChanKey=bcKey
121  theLArRampPatcher.PatchMethod="PhiAverage"
122  theLArRampPatcher.SuperCells=flags.LArCalib.isSC
123 
124  if flags.LArCalib.isSC:
125  theLArRampPatcher.ProblemsToPatch=["deadCalib","deadReadout","deadPhys","maskedOSUM","OffOFCs","transmissionErrorFibre"]
126  theLArRampPatcher.OnOffMap="LArOnOffIdMapSC"
127  theLArRampPatcher.CalibLineKey="LArCalibIdMapSC"
128  else:
129  theLArRampPatcher.ProblemsToPatch=["deadCalib","deadReadout","deadPhys","almostDead","short"]
130  theLArRampPatcher.UseCorrChannels=False
131  result.addEventAlgo(theLArRampPatcher)
132 
133  # Validation + CB patching
134  if flags.LArCalib.doValidation:
135 
136  if flags.LArCalib.isSC:
137  fldr="/LAR/ElecCalibFlatSC/Ramp"
138  rmpFlt=CompFactory.getComp("LArFlatConditionsAlg<LArRampSC>")("RampFltVal")
139  else:
140  fldr="/LAR/ElecCalibFlat/Ramp"
141  rmpFlt=CompFactory.getComp("LArFlatConditionsAlg<LArRampFlat>")("RampFltVal")
142  result.merge(addFolders(flags,fldr,"LAR_ONL"))
143  condLoader=result.getCondAlgo("CondInputLoader")
144  condLoader.Load.add(("CondAttrListCollection",fldr))
145 
146  rmpFlt.ReadKey=fldr
147  rmpFlt.WriteKey="LArRampRef"
148  result.addCondAlgo(rmpFlt)
149 
150  from LArCalibDataQuality.Thresholds import rampThr, rampThrFEB
151  from AthenaCommon.Constants import WARNING
152 
153  theRampValidationAlg=CompFactory.LArRampValidationAlg("RampVal")
154  theRampValidationAlg.RampTolerance=rampThr
155  theRampValidationAlg.RampToleranceFEB=rampThrFEB
156  if flags.LArCalib.isSC:
157  theRampValidationAlg.ProblemsToMask=["deadCalib","deadReadout","deadPhys","maskedOSUM",
158  "OffOFCs","transmissionErrorFibre"]
159  else:
160  theRampValidationAlg.ProblemsToMask=["deadReadout","deadCalib","deadPhys","almostDead",
161  "highNoiseHG","highNoiseMG","highNoiseLG"]
162  theRampValidationAlg.KeyList=["LArRamp"+digKey,]
163  if flags.LArCalib.isSC:
164  theRampValidationAlg.PatchMissingFEBs = False
165  theRampValidationAlg.CheckCompletness = False
166  else:
167  theRampValidationAlg.PatchMissingFEBs=True
168  theRampValidationAlg.UseCorrChannels=False
169  theRampValidationAlg.ValidationKey="LArRamp"
170  theRampValidationAlg.ReferenceKey="LArRampRef"
171 
172  theRampValidationAlg.MsgLevelForDeviations=WARNING
173  theRampValidationAlg.ListOfDevFEBs="rampFebs.txt"
174 
175  theRampValidationAlg.BadChanKey = bcKey
176  theRampValidationAlg.SuperCells = flags.LArCalib.isSC
177 
178  if flags.LArCalib.isSC:
179  theRampValidationAlg.CablingKey = "LArOnOffIdMapSC"
180  theRampValidationAlg.CalibLineKey = "LArCalibIdMapSC"
181 
182  result.addEventAlgo(theRampValidationAlg)
183 
184  #Output (POOL + sqlite) file writing:
185  from RegistrationServices.OutputConditionsAlgConfig import OutputConditionsAlgCfg
186  result.merge(OutputConditionsAlgCfg(flags,
187  outputFile=flags.LArCalib.Output.POOLFile,
188  ObjectList=["LArRampComplete#LArRamp#"+flags.LArCalib.Ramp.Folder,],
189  IOVTagList=[rampTag,],
190  Run1=flags.LArCalib.IOVStart,
191  Run2=flags.LArCalib.IOVEnd
192  ))
193 
194  #RegistrationSvc
195  result.addService(CompFactory.IOVRegistrationSvc(RecreateFolders = False))
196 
197 
198  #ROOT ntuple writing:
199  rootfile=flags.LArCalib.Output.ROOTFile
200 
201  ntupKey = digKey
202  if flags.LArCalib.isSC:
203  ntupKey = "HIGH" # Modification to avoid problems in LArRampBuilder
204  if rootfile != "":
205  result.addEventAlgo(CompFactory.LArRamps2Ntuple( ContainerKey = ["LArRamp"+ntupKey], #for RawRamp
206  AddFEBTempInfo = False,
207  RealGeometry = True,
208  OffId = True,
209  AddCalib = True,
210  RawRamp = True,
211  SaveAllSamples = True,
212  BadChanKey = bcKey,
213  ApplyCorr=True,
214  isSC = flags.LArCalib.isSC
215  ))
216  if flags.LArCalib.Output.SaveAverages:
217  result.addEventAlgo(CompFactory.LArAverages2Ntuple( "LArAverages2Ntuple"+digKey,
218  ContainerKey = "SC" if flags.LArCalib.isSC else digKey,
219  BadChanKey = bcKey,
220  isSC = flags.LArCalib.isSC
221  ))
222 
223  import os
224  if os.path.exists(rootfile):
225  os.remove(rootfile)
226  result.addService(CompFactory.NTupleSvc(Output = [ "FILE1 DATAFILE='"+rootfile+"' OPT='NEW'" ]))
227  result.setAppProperty("HistogramPersistency","ROOT")
228  pass # end if ROOT ntuple writing
229 
230 
231  from PerfMonComps.PerfMonCompsConfig import PerfMonMTSvcCfg
232  result.merge(PerfMonMTSvcCfg(flags))
233 
234  return result
235 
236 
237 if __name__ == "__main__":
238  from AthenaConfiguration.AllConfigFlags import initConfigFlags
239  from AthenaConfiguration.TestDefaults import defaultGeometryTags
240  from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
241  import sys
242  ConfigFlags=initConfigFlags()
243  addLArCalibFlags(ConfigFlags)
244 
245  ConfigFlags.LArCalib.Input.Dir = "/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/LArCalibProcessing"
246  ConfigFlags.LArCalib.Input.Type="calibration_LArElec-Ramp"
247  ConfigFlags.LArCalib.Input.RunNumbers=[441252,]
248  ConfigFlags.LArCalib.Input.SubDet="EM"
249  ConfigFlags.Input.Files=ConfigFlags.LArCalib.Input.Files
250  ConfigFlags.LArCalib.Input.Database="output.sqlite"
251  ConfigFlags.LArCalib.Output.POOLFile="larramp.pool.root"
252  ConfigFlags.LArCalib.Output.ROOTFile="larramp.root"
253 
254  ConfigFlags.IOVDb.DBConnection="sqlite://;schema=output.sqlite;dbname=CONDBR2"
255  ConfigFlags.IOVDb.GlobalTag="LARCALIB-RUN2-02"
256  ConfigFlags.GeoModel.AtlasVersion=defaultGeometryTags.RUN3
257  #ConfigFlags.Exec.OutputLevel=1
258  ConfigFlags.fillFromArgs()
259 
260  print ("Input files to be processed:")
261  for f in ConfigFlags.Input.Files:
262  print (f)
263 
264  ConfigFlags.lock()
265  cfg=MainServicesCfg(ConfigFlags)
266  cfg.merge(LArRampCfg(ConfigFlags))
267 
268  print("Start running...")
269  sys.exit(cfg.run().isFailure())
270 
OutputConditionsAlgConfig.OutputConditionsAlgCfg
def OutputConditionsAlgCfg(flags, name="OutputConditionsAlg", outputFile='condobjs.root', **kwargs)
Definition: OutputConditionsAlgConfig.py:5
LArCalibPatchingAlg
Definition: LArCalibPatchingAlg.h:53
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.LArCalibBaseConfig.chanSelStr
def chanSelStr(flags)
Definition: LArCalibBaseConfig.py:33
python.LArCalib_RampConfig.LArRampCfg
def LArRampCfg(flags)
Definition: LArCalib_RampConfig.py:6
python.LArFebErrorSummaryMakerConfig.LArFebErrorSummaryMakerCfg
def LArFebErrorSummaryMakerCfg(flags)
Definition: LArFebErrorSummaryMakerConfig.py:7
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
python.LArStripsXtalkCorrConfig.LArStripsXtalkCorrCfg
def LArStripsXtalkCorrCfg(flags, KeyList)
Definition: LArStripsXtalkCorrConfig.py:6
Constants
some useful constants -------------------------------------------------—
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.LArCalib_CalibDigitsMakerConfig.LArCalibDigitsMakerCfg
def LArCalibDigitsMakerCfg(flags, DigitsKey="")
Definition: LArCalib_CalibDigitsMakerConfig.py:41
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
python.LArCalibBaseConfig.LArCalibBaseCfg
def LArCalibBaseCfg(flags)
Definition: LArCalibBaseConfig.py:5
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.LArCalibConfigFlags.addLArCalibFlags
def addLArCalibFlags(flags, isSC=False)
Definition: LArCalibConfigFlags.py:3
LArCablingConfig.LArCalibIdMappingCfg
def LArCalibIdMappingCfg(configFlags)
Definition: LArCablingConfig.py:83