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