ATLAS Offline Software
LArCalib_OFCPhysConfig.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.ComponentAccumulator import ComponentAccumulator
5 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
6 from LArCalibProcessing.utils import FolderTagResolver
7 from IOVDbSvc.IOVDbSvcConfig import addFolders
8 from copy import deepcopy
9 
10 def _ofcAlg(flags,postfix,folderSuffix,nPhases,dPhases,nDelays,nColl):
11  result=ComponentAccumulator()
12  LArPhysOFCAlg = CompFactory.LArOFCAlg("LArOFCPhysAlg_"+postfix)
13  LArPhysOFCAlg.isSC = flags.LArCalib.isSC
14  LArPhysOFCAlg.ReadCaliWave = False
15  LArPhysOFCAlg.KeyList = [ "LArPhysWave" ]
16  LArPhysOFCAlg.Normalize = flags.LArCalib.OFC.Normalize
17  LArPhysOFCAlg.Verify = True
18  LArPhysOFCAlg.GroupingType = flags.LArCalib.GroupingType
19  LArPhysOFCAlg.Nphase = nPhases
20  LArPhysOFCAlg.Dphase = dPhases
21  LArPhysOFCAlg.Ndelay = nDelays
22  LArPhysOFCAlg.Nsample = flags.LArCalib.OFC.Nsamples
23  LArPhysOFCAlg.FillShape = True
24  LArPhysOFCAlg.TimeShift = False
25  LArPhysOFCAlg.AddTimeOffset = -1.0*12.0#TimeShiftGuardRegion
26  if not flags.LArCalib.isSC:
27  LArPhysOFCAlg.LArPhysWaveBinKey = "LArPhysWaveShift"
28  LArPhysOFCAlg.UseDelta = flags.LArCalib.OFC.useDelta
29  LArPhysOFCAlg.KeyOFC = "LArOFC_"+postfix
30  LArPhysOFCAlg.KeyShape = "LArShape_"+postfix
31 
32  if flags.LArCalib.OFC.Nsamples==4 and not flags.LArCalib.isSC:
33  LArPhysOFCAlg.ReadDSPConfig = True
34  LArPhysOFCAlg.DSPConfigFolder = "/LAR/Configuration/DSPConfiguration"
35 
36 
37  LArPhysOFCAlg.DecoderTool = CompFactory.LArAutoCorrDecoderTool(UseAlwaysHighGain=flags.LArCalib.PhysACuseHG,
38  isSC = flags.LArCalib.isSC)
39 
40  result.addEventAlgo(LArPhysOFCAlg)
41  if (nColl>0):
42  #create a copy to calculate pile-up OFCs
43  LArPhysOFCAlgMu=deepcopy(LArPhysOFCAlg)
44  LArPhysOFCAlgMu.name=LArPhysOFCAlg.name+"_mu"
45  LArPhysOFCAlgMu.KeyOFC = "LArOFC_"+postfix+"_mu"
46  LArPhysOFCAlg.KeyShape = "LArShape_"+postfix+"_mu"
47  LArPhysOFCAlgMu.DecoderTool = CompFactory.LArAutoCorrDecoderTool(DecodeMode=1,
48  UseAlwaysHighGain=flags.LArCalib.PhysACuseHG,
49  isSC = flags.LArCalib.isSC,
50  KeyAutoCorr="LArPhysAutoCorr")
51  result.addEventAlgo(LArPhysOFCAlgMu)
52 
53 
54  rootfile=flags.LArCalib.Output.ROOTFile
55  if rootfile != "":
56  bcKey = "LArBadChannelSC" if flags.LArCalib.isSC else "LArBadChannel"
57  OFC2Ntup=CompFactory.LArOFC2Ntuple("LArOFC2Ntuple_"+postfix)
58  OFC2Ntup.ContainerKey = "LArOFC_"+postfix
59  OFC2Ntup.NtupleName = "OFC_"+postfix
60  OFC2Ntup.AddFEBTempInfo = False
61  OFC2Ntup.AddCalib = True
62  OFC2Ntup.isSC = flags.LArCalib.isSC
63  OFC2Ntup.BadChanKey = bcKey
64  result.addEventAlgo(OFC2Ntup)
65 
66  if (nColl>0):
67  OFC2NtupMu=CompFactory.LArOFC2Ntuple("LArOFC2Ntuple_"+postfix+"_mu")
68  OFC2NtupMu.ContainerKey = "LArOFC_"+postfix+"_mu"
69  OFC2NtupMu.NtupleName = "OFC_"+postfix+"_mu"
70  OFC2NtupMu.AddFEBTempInfo = False
71  OFC2NtupMu.AddCalib = True
72  OFC2NtupMu.isSC = flags.LArCalib.isSC
73  OFC2NtupMu.BadChanKey = bcKey
74  result.addEventAlgo(OFC2NtupMu)
75 
76 
77  Shape2Ntup=CompFactory.LArShape2Ntuple("LArShape2Ntuple_"+postfix)
78  Shape2Ntup.ContainerKey="LArShape_"+postfix
79  Shape2Ntup.NtupleName="SHAPE_"+postfix
80  Shape2Ntup.AddFEBTempInfo = False
81  Shape2Ntup.AddCalib = True
82  Shape2Ntup.isSC = flags.LArCalib.isSC
83  Shape2Ntup.BadChanKey = bcKey
84  result.addEventAlgo(Shape2Ntup)
85 
86 
87  objList=["LArOFCComplete#LArOFC_"+postfix+"#"+flags.LArCalib.OFCPhys.Folder+folderSuffix,
88  "LArShapeComplete#LArShape_"+postfix+"#"+flags.LArCalib.Shape.Folder+folderSuffix]
89 
90  if flags.LArCalib.isSC:
91  FolderTagResolver._defaultSuffix="-UPD3-00"
92  rs=FolderTagResolver(dbname="sqlite://;schema=%s;dbname=CONDBR2"%flags.LArCalib.Input.Database)
93  OFCTag=rs.getFolderTag(flags.LArCalib.OFCPhys.Folder+folderSuffix)
94  ShapeTag=rs.getFolderTag(flags.LArCalib.Shape.Folder+folderSuffix)
95  tagList=[OFCTag,ShapeTag]
96 
97  if nColl > 0:
98  objList+=["LArOFCComplete#LArOFC_"+postfix+"_mu#"+flags.LArCalib.OFCPhys.Folder+folderSuffix]
99  tagstr=rs.getFolderTag(flags.LArCalib.OFCPhys.Folder+folderSuffix)
100  tagpref=tagstr[0:tagstr.find(folderSuffix)+len(folderSuffix)]
101  tagpost=tagstr[tagstr.find(folderSuffix)+len(folderSuffix):]
102  nc=int(nColl)
103  OFCTagmu=f'{tagpref}-mu-{nc}{tagpost}'
104  tagList.append(OFCTagmu)
105  del rs #Close database
106 
107  from RegistrationServices.OutputConditionsAlgConfig import OutputConditionsAlgCfg
108  result.merge(OutputConditionsAlgCfg(flags,name="OutCondAlg",
109  outputFile=flags.LArCalib.Output.POOLFile,
110  ObjectList=objList,
111  IOVTagList=tagList,
112  Run1=flags.LArCalib.IOVStart,
113  Run2=flags.LArCalib.IOVEnd
114  ))
115 
116  return result
117 
118 
119 def LArOFCPhysCfg(flags,loadPhysAC=True):
120 
121  #Get basic services and cond-algos
122  from LArCalibProcessing.LArCalibBaseConfig import LArCalibBaseCfg,chanSelStr
123  result=LArCalibBaseCfg(flags)
124 
125  nColl=flags.LArCalib.OFC.Ncoll
126  from LArCalibProcessing.utils import FolderTagResolver
127  FolderTagResolver._globalTag=flags.IOVDb.GlobalTag
128  if flags.LArCalib.isSC:
129  FolderTagResolver._defaultSuffix="-UPD3-00"
130  rs=FolderTagResolver(dbname="sqlite://;schema=%s;dbname=CONDBR2"%flags.LArCalib.Input.Database)
131  PhysWaveTag=rs.getFolderTag(flags.LArCalib.PhysWave.Folder)
132  AutoCorrTag=rs.getFolderTag(flags.LArCalib.AutoCorr.Folder)
133  PhysAutoCorrTag= rs.getFolderTag(flags.LArCalib.PhysAutoCorr.Folder)
134  if (nColl>0 and "mu" not in PhysAutoCorrTag):
135  #Insert mu in tag-name:
136  elems=PhysAutoCorrTag.split("-")
137  PhysAutoCorrTag="-".join([elems[0]+"_mu_%i"%nColl,]+elems[1:])
138  del elems
139 
140  PhysCaliTdiffTag=rs.getFolderTag(flags.LArCalib.PhysCaliTdiff.Folder)
141  del rs #Close database
142 
143  result.merge(addFolders(flags,flags.LArCalib.PhysWave.Folder,detDb=flags.LArCalib.Input.Database, tag=PhysWaveTag, modifiers=chanSelStr(flags)))
144  result.merge(addFolders(flags,flags.LArCalib.AutoCorr.Folder,detDb=flags.LArCalib.Input.Database, tag=AutoCorrTag, modifiers=chanSelStr(flags)))
145  if loadPhysAC:
146  result.merge(addFolders(flags,flags.LArCalib.PhysAutoCorr.Folder,detDb=flags.LArCalib.Input.Database, tag=PhysAutoCorrTag,modifiers=chanSelStr(flags)))
147 
148 
149 
150  result.merge(addFolders(flags,"/LAR/ElecCalibOfl/OFCBin/PhysWaveShifts","LAR_OFL",tag="LARElecCalibOflOFCBinPhysWaveShifts-UPD3-00"))
151  result.merge(addFolders(flags,"/LAR/Configuration/DSPConfiguration","LAR_ONL"))
152 
153  if (flags.LArCalib.OFC.UsePhysCalibTDiff):
154  result.merge(addFolders(flags,flags.LArCalib.PhysCaliTdiff.Folder,detDb="LAR_OFL", db="COMP200", tag=PhysCaliTdiffTag))
155 
156 
157  if flags.LArCalib.isSC:
158  result.merge(_ofcAlg(flags,"1ns","%isamples"%(flags.LArCalib.OFC.Nsamples),nPhases=50,dPhases=1,nDelays=24,nColl=nColl))
159  else:
160  result.merge(_ofcAlg(flags,"3ns","%isamples3bins17phases"%flags.LArCalib.OFC.Nsamples,nPhases=8,dPhases=3,nDelays=24,nColl=nColl))
161 
162  #RegistrationSvc
163  result.addService(CompFactory.IOVRegistrationSvc(RecreateFolders = False))
164  result.getService("IOVDbSvc").DBInstance=""
165 
166  #Ntuple writing
167  rootfile=flags.LArCalib.Output.ROOTFile
168  if rootfile != "":
169  import os
170  if os.path.exists(rootfile):
171  os.remove(rootfile)
172  result.addService(CompFactory.NTupleSvc(Output = [ "FILE1 DATAFILE='"+rootfile+"' OPT='NEW'" ]))
173  result.setAppProperty("HistogramPersistency","ROOT")
174  pass # end if ROOT ntuple writing
175 
176 
177  #MC Event selector since we have no input data file
178  from McEventSelector.McEventSelectorConfig import McEventSelectorCfg
179  result.merge(McEventSelectorCfg(flags,
180  RunNumber = flags.LArCalib.Input.RunNumbers[0],
181  EventsPerRun = 1,
182  FirstEvent = 1,
183  InitialTimeStamp = 0,
184  TimeStampInterval = 1))
185 
186  from PerfMonComps.PerfMonCompsConfig import PerfMonMTSvcCfg
187  result.merge(PerfMonMTSvcCfg(flags))
188 
189  return result
190 
191 
192 
193 if __name__ == "__main__":
194 
195  import sys
196  from AthenaConfiguration.AllConfigFlags import initConfigFlags
197  ConfigFlags=initConfigFlags()
198  from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
199  addLArCalibFlags(ConfigFlags)
200 
201  ConfigFlags.Input.Files=[]
202  ConfigFlags.LArCalib.Input.RunNumbers=[500000]
203  ConfigFlags.LArCalib.Input.Database="/home/wlampl/calibTest/00403758_00403761_00403762_EndCap-EMB-EMEC_HIGH_40_21.0.20_1/poolFiles/myDB200_00403758_00403761_00403762_EB-EMECC_one.db"
204  ConfigFlags.LArCalib.Input.SubDet="EM"
205  ConfigFlags.LArCalib.BadChannelDB="/home/wlampl/calibTest/00403758_00403761_00403762_EndCap-EMB-EMEC_HIGH_40_21.0.20_1/poolFiles/SnapshotBadChannel_00403758_00403761_00403762_EB-EMECC.db"
206  ConfigFlags.LArCalib.OFC.Ncoll=20
207  ConfigFlags.LArCalib.BadChannelTag="-RUN2-UPD3-00"
208  ConfigFlags.LArCalib.Output.ROOTFile="larofc.root"
209  ConfigFlags.IOVDb.DatabaseInstance="CONDBR2"
210  ConfigFlags.IOVDb.DBConnection="sqlite://;schema=output.sqlite;dbname=CONDBR2"
211  ConfigFlags.IOVDb.GlobalTag="LARCALIB-RUN2-02"
212  from AthenaConfiguration.TestDefaults import defaultGeometryTags
213  ConfigFlags.GeoModel.AtlasVersion=defaultGeometryTags.RUN3
214  ConfigFlags.IOVDb.DatabaseInstance="CONDBR2"
215  ConfigFlags.LAr.doAlign=False
216  ConfigFlags.Input.RunNumbers=ConfigFlags.LArCalib.Input.RunNumbers
217  #ConfigFlags.Exec.OutputLevel=1
218  ConfigFlags.fillFromArgs()
219  ConfigFlags.lock()
220  cfg=MainServicesCfg(ConfigFlags)
221  cfg.merge(LArOFCPhysCfg(ConfigFlags))
222 
223  print(cfg.getService("IOVDbSvc").Folders)
224  print("Start running...")
225  sys.exit(cfg.run(1).isFailure())
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
OutputConditionsAlgConfig.OutputConditionsAlgCfg
def OutputConditionsAlgCfg(flags, name="OutputConditionsAlg", outputFile='condobjs.root', **kwargs)
Definition: OutputConditionsAlgConfig.py:5
python.LArCalib_OFCPhysConfig._ofcAlg
def _ofcAlg(flags, postfix, folderSuffix, nPhases, dPhases, nDelays, nColl)
Definition: LArCalib_OFCPhysConfig.py:10
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.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
python.McEventSelectorConfig.McEventSelectorCfg
def McEventSelectorCfg(flags, **kwargs)
Definition: McEventSelectorConfig.py:5
python.IOVDbSvcConfig.addFolders
def addFolders(flags, folderStrings, detDb=None, className=None, extensible=False, tag=None, db=None, modifiers='')
Definition: IOVDbSvcConfig.py:72
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.LArCalib_OFCPhysConfig.LArOFCPhysCfg
def LArOFCPhysCfg(flags, loadPhysAC=True)
Definition: LArCalib_OFCPhysConfig.py:119
python.LArCalibBaseConfig.LArCalibBaseCfg
def LArCalibBaseCfg(flags)
Definition: LArCalibBaseConfig.py:5
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
python.LArCalibConfigFlags.addLArCalibFlags
def addLArCalibFlags(flags, isSC=False)
Definition: LArCalibConfigFlags.py:3