ATLAS Offline Software
LArCalib_RampConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 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  result.addEventAlgo(CompFactory.LArDigitsAccumulator("LArDigitsAccumulator", KeyList = [digKey],
64  LArAccuDigitContainerName = "", NTriggersPerStep = 100,
65  isSC = flags.LArCalib.isSC, DropPercentTrig = 0))
66 
67 
68  else:
69  # this needs also legacy maps
70  from LArCabling.LArCablingConfig import LArCalibIdMappingCfg,LArOnOffIdMappingCfg
71  result.merge(LArOnOffIdMappingCfg(flags))
72  result.merge(LArCalibIdMappingCfg(flags))
73 
74  result.addEventAlgo(CompFactory.LArRawSCCalibDataReadingAlg(LArSCAccCalibDigitKey = digKey, LATOMEDecoder = theLArLATOMEDecoder))
75 
76  pass
77 
78 
79  bcKey = "LArBadChannelSC" if flags.LArCalib.isSC else "LArBadChannel"
80 
81 
82  theLArRampBuilder = CompFactory.LArRampBuilder()
83  theLArRampBuilder.KeyList = [digKey,]
84  theLArRampBuilder.SubtractDac0 = False
85  if flags.LArCalib.isSC:
86  theLArRampBuilder.ProblemsToMask=["deadCalib","deadReadout","deadPhys","maskedOSUM","OffOFCs"]
87  else:
88  theLArRampBuilder.ProblemsToMask=["deadCalib","deadReadout","deadPhys","almostDead","short"]
89 
90  theLArRampBuilder.RecoType = "OF"
91  theLArRampBuilder.PeakOFTool=CompFactory.LArOFPeakRecoTool(UseShape = False,OutputLevel=2)
92 
93  theLArRampBuilder.DAC0 = 4294967294
94  theLArRampBuilder.StoreRawRamp = True
95  theLArRampBuilder.StoreRecRamp = True
96  theLArRampBuilder.Polynom = 1
97  theLArRampBuilder.RampRange = 3600 # Check on the raw data ADC sample before ped subtraction and pulse reconstruction to include point in fit
98  theLArRampBuilder.correctBias = False
99  #theLArRampBuilder.ConsecutiveADCs = 0
100  theLArRampBuilder.minDAC = 10 # minimum DAC value to use in fit
101  theLArRampBuilder.KeyOutput = "LArRamp"
102  theLArRampBuilder.DeadChannelCut = -9999
103  theLArRampBuilder.GroupingType = flags.LArCalib.GroupingType
104  #theLArRampBuilder.LongNtuple = False
105 
106  theLArRampBuilder.isSC = flags.LArCalib.isSC
107  theLArRampBuilder.BadChanKey = bcKey
108 
109  if "HEC" in flags.LArCalib.Input.SubDet:
110  theLArRampBuilder.isHEC = True
111  theLArRampBuilder.HECKey = "LArHEC_PAmap"
112  result.merge(addFolders(flags,'/LAR/ElecCalibOfl/HecPAMap','LAR_OFL'))
113 
114  result.addEventAlgo(theLArRampBuilder)
115 
116 
117  # Bad-channel patching
118  if flags.LArCalib.CorrectBadChannels:
119  LArRampPatcher=CompFactory.getComp("LArCalibPatchingAlg<LArRampComplete>")
120  theLArRampPatcher=LArRampPatcher("LArRampPatcher")
121  theLArRampPatcher.ContainerKey="LArRamp"
122  theLArRampPatcher.BadChanKey=bcKey
123  theLArRampPatcher.PatchMethod="PhiAverage"
124  theLArRampPatcher.SuperCells=flags.LArCalib.isSC
125 
126  if flags.LArCalib.isSC:
127  theLArRampPatcher.ProblemsToPatch=["deadCalib","deadReadout","deadPhys","maskedOSUM","OffOFCs"]
128  theLArRampPatcher.OnOffMap="LArOnOffIdMapSC"
129  theLArRampPatcher.CalibLineKey="LArCalibIdMapSC"
130  else:
131  theLArRampPatcher.ProblemsToPatch=["deadCalib","deadReadout","deadPhys","almostDead","short"]
132  theLArRampPatcher.UseCorrChannels=False
133  result.addEventAlgo(theLArRampPatcher)
134 
135  # Validation + CB patching
136  if flags.LArCalib.doValidation:
137 
138  if flags.LArCalib.isSC:
139  fldr="/LAR/ElecCalibFlatSC/Ramp"
140  rmpFlt=CompFactory.getComp("LArFlatConditionsAlg<LArRampSC>")("RampFltVal")
141  else:
142  fldr="/LAR/ElecCalibFlat/Ramp"
143  rmpFlt=CompFactory.getComp("LArFlatConditionsAlg<LArRampFlat>")("RampFltVal")
144  result.merge(addFolders(flags,fldr,"LAR_ONL"))
145  condLoader=result.getCondAlgo("CondInputLoader")
146  condLoader.Load.add(("CondAttrListCollection",fldr))
147 
148  rmpFlt.ReadKey=fldr
149  rmpFlt.WriteKey="LArRampRef"
150  result.addCondAlgo(rmpFlt)
151 
152  from LArCalibDataQuality.Thresholds import rampThr, rampThrFEB
153  from AthenaCommon.Constants import WARNING
154 
155  theRampValidationAlg=CompFactory.LArRampValidationAlg("RampVal")
156  theRampValidationAlg.RampTolerance=rampThr
157  theRampValidationAlg.RampToleranceFEB=rampThrFEB
158  theRampValidationAlg.ProblemsToMask=["deadReadout","deadCalib","deadPhys","almostDead",
159  "highNoiseHG","highNoiseMG","highNoiseLG"]
160  theRampValidationAlg.KeyList=[digKey,]
161  if flags.LArCalib.isSC:
162  theRampValidationAlg.PatchMissingFEBs = False
163  theRampValidationAlg.CheckCompletness = False
164  else:
165  theRampValidationAlg.PatchMissingFEBs=True
166  theRampValidationAlg.UseCorrChannels=False
167  theRampValidationAlg.ValidationKey="LArRamp"
168  theRampValidationAlg.ReferenceKey="LArRampRef"
169 
170  theRampValidationAlg.MsgLevelForDeviations=WARNING
171  theRampValidationAlg.ListOfDevFEBs="rampFebs.txt"
172 
173  theRampValidationAlg.BadChanKey = bcKey
174  theRampValidationAlg.SuperCells = flags.LArCalib.isSC
175 
176  if flags.LArCalib.isSC:
177  theRampValidationAlg.CablingKey = "LArOnOffIdMapSC"
178  theRampValidationAlg.CalibLineKey = "LArCalibIdMapSC"
179 
180  result.addEventAlgo(theRampValidationAlg)
181 
182  #Output (POOL + sqlite) file writing:
183  from RegistrationServices.OutputConditionsAlgConfig import OutputConditionsAlgCfg
184  result.merge(OutputConditionsAlgCfg(flags,
185  outputFile=flags.LArCalib.Output.POOLFile,
186  ObjectList=["LArRampComplete#LArRamp#"+flags.LArCalib.Ramp.Folder,],
187  IOVTagList=[rampTag,],
188  Run1=flags.LArCalib.IOVStart,
189  Run2=flags.LArCalib.IOVEnd
190  ))
191 
192  #RegistrationSvc
193  result.addService(CompFactory.IOVRegistrationSvc(RecreateFolders = False))
194  result.getService("IOVDbSvc").DBInstance=""
195 
196 
197  #ROOT ntuple writing:
198  rootfile=flags.LArCalib.Output.ROOTFile
199 
200  ntupKey = digKey
201  if flags.LArCalib.isSC:
202  ntupKey = "HIGH" # Modification to avoid problems in LArRampBuilder
203  if rootfile != "":
204  result.addEventAlgo(CompFactory.LArRamps2Ntuple( ContainerKey = ["LArRamp"+ntupKey], #for RawRamp
205  AddFEBTempInfo = False,
206  RealGeometry = True,
207  OffId = True,
208  AddCalib = True,
209  RawRamp = True,
210  SaveAllSamples = True,
211  BadChanKey = bcKey,
212  ApplyCorr=True,
213  isSC = flags.LArCalib.isSC
214  ))
215 
216  import os
217  if os.path.exists(rootfile):
218  os.remove(rootfile)
219  result.addService(CompFactory.NTupleSvc(Output = [ "FILE1 DATAFILE='"+rootfile+"' OPT='NEW'" ]))
220  result.setAppProperty("HistogramPersistency","ROOT")
221  pass # end if ROOT ntuple writing
222 
223 
224  from PerfMonComps.PerfMonCompsConfig import PerfMonMTSvcCfg
225  result.merge(PerfMonMTSvcCfg(flags))
226 
227  return result
228 
229 
230 if __name__ == "__main__":
231  from AthenaConfiguration.AllConfigFlags import initConfigFlags
232  from AthenaConfiguration.TestDefaults import defaultGeometryTags
233  from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
234  import sys
235  ConfigFlags=initConfigFlags()
236  addLArCalibFlags(ConfigFlags)
237 
238  ConfigFlags.LArCalib.Input.Dir = "/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/LArCalibProcessing"
239  ConfigFlags.LArCalib.Input.Type="calibration_LArElec-Ramp"
240  ConfigFlags.LArCalib.Input.RunNumbers=[441252,]
241  ConfigFlags.LArCalib.Input.SubDet="EM"
242  ConfigFlags.Input.Files=ConfigFlags.LArCalib.Input.Files
243  ConfigFlags.LArCalib.Input.Database="output.sqlite"
244  ConfigFlags.LArCalib.Output.POOLFile="larramp.pool.root"
245  ConfigFlags.LArCalib.Output.ROOTFile="larramp.root"
246 
247  ConfigFlags.IOVDb.DBConnection="sqlite://;schema=output.sqlite;dbname=CONDBR2"
248  ConfigFlags.IOVDb.GlobalTag="LARCALIB-RUN2-02"
249  ConfigFlags.GeoModel.AtlasVersion=defaultGeometryTags.RUN3
250  #ConfigFlags.Exec.OutputLevel=1
251  ConfigFlags.fillFromArgs()
252 
253  print ("Input files to be processed:")
254  for f in ConfigFlags.Input.Files:
255  print (f)
256 
257  ConfigFlags.lock()
258  cfg=MainServicesCfg(ConfigFlags)
259  cfg.merge(LArRampCfg(ConfigFlags))
260 
261  print("Start running...")
262  sys.exit(cfg.run().isFailure())
263 
OutputConditionsAlgConfig.OutputConditionsAlgCfg
def OutputConditionsAlgCfg(flags, name="OutputConditionsAlg", outputFile='condobjs.root', **kwargs)
Definition: OutputConditionsAlgConfig.py:5
LArCalibPatchingAlg
Definition: LArCalibPatchingAlg.h:52
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:256
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.LArCalibBaseConfig.LArCalibBaseCfg
def LArCalibBaseCfg(flags)
Definition: LArCalibBaseConfig.py:5
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
python.LArCalibConfigFlags.addLArCalibFlags
def addLArCalibFlags(flags, isSC=False)
Definition: LArCalibConfigFlags.py:3
LArCablingConfig.LArCalibIdMappingCfg
def LArCalibIdMappingCfg(configFlags)
Definition: LArCablingConfig.py:83