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