7def LArDelay_OFCCaliCfg(flags):
8
9
10 from LArCalibProcessing.LArCalibBaseConfig import LArCalibBaseCfg,chanSelStr
11 result=LArCalibBaseCfg(flags)
12
13
14 from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
15 result.merge(ByteStreamReadCfg(flags))
16
17
18
19 gainStrMap={0:"HIGH",1:"MEDIUM",2:"LOW"}
20 digKey=gainStrMap[flags.LArCalib.Gain]
21
22 from LArCalibProcessing.utils import FolderTagResolver
23 FolderTagResolver._globalTag=flags.IOVDb.GlobalTag
24 tagResolver=FolderTagResolver(dbname=flags.LArCalib.Input.CoolOflP1Replica)
25 caliWaveTag=tagResolver.getFolderTag(flags.LArCalib.CaliWave.Folder)
26 caliOFCTag=tagResolver.getFolderTag(flags.LArCalib.OFCCali.Folder)
27 if (flags.LArCalib.Input.Database == "LAR_OFL" and flags.LArCalib.Input.Database2 == "LAR_OFL"):
28 pedestalTag=tagResolver.getFolderTag(flags.LArCalib.Pedestal.Folder)
29 acTag=tagResolver.getFolderTag(flags.LArCalib.AutoCorr.Folder)
30 else:
31 pedestalTag=None
32 acTag=None
33
34 del tagResolver
35 from IOVDbSvc.IOVDbSvcConfig import addFolders
36 result.merge(addFolders(flags,flags.LArCalib.Pedestal.Folder,detDb=flags.LArCalib.Input.Database, tag=pedestalTag, modifiers=chanSelStr(flags),
37 className="LArPedestalComplete"))
38 result.merge(addFolders(flags,flags.LArCalib.AutoCorr.Folder,detDb=flags.LArCalib.Input.Database, tag=acTag,modifiers=chanSelStr(flags)))
39
40 if not flags.LArCalib.isSC:
41 if flags.LArCalib.Input.isRawData:
42 result.addEventAlgo(CompFactory.LArRawDataReadingAlg(LArRawChannelKey="", LArDigitKey=digKey, LArFebHeaderKey="LArFebHeader",
43 SubCaloPreselection=flags.LArCalib.Input.SubDet,
44 PosNegPreselection=flags.LArCalib.Preselection.Side,
45 BEPreselection=flags.LArCalib.Preselection.BEC,
46 FTNumPreselection=flags.LArCalib.Preselection.FT))
47 from LArCalibProcessing.LArCalib_CalibDigitsMakerConfig import LArCalibDigitsMakerCfg
48 result.merge(LArCalibDigitsMakerCfg(flags,digKey))
49 else:
50 result.addEventAlgo(CompFactory.LArRawCalibDataReadingAlg(LArAccCalibDigitKey=digKey,
51 LArFebHeaderKey="LArFebHeader",
52 SubCaloPreselection=flags.LArCalib.Input.SubDet,
53 PosNegPreselection=flags.LArCalib.Preselection.Side,
54 BEPreselection=flags.LArCalib.Preselection.BEC,
55 FTNumPreselection=flags.LArCalib.Preselection.FT))
56
57 from LArROD.LArFebErrorSummaryMakerConfig import LArFebErrorSummaryMakerCfg
58 result.merge(LArFebErrorSummaryMakerCfg(flags))
59 result.getEventAlgo("LArFebErrorSummaryMaker").CheckAllFEB=False
60
61 if flags.LArCalib.Input.SubDet == "EM":
62 theLArCalibShortCorrector = CompFactory.LArCalibShortCorrector(KeyList = [digKey,])
63 result.addEventAlgo(theLArCalibShortCorrector)
64
65 from LArCalibProcessing.LArStripsXtalkCorrConfig import LArStripsXtalkCorrCfg
66 result.merge(LArStripsXtalkCorrCfg(flags,[digKey,]))
67 else:
68 digKey="SC"
69 theLArLATOMEDecoder = CompFactory.LArLATOMEDecoder("LArLATOMEDecoder")
70 if flags.LArCalib.Input.isRawData:
71 result.addEventAlgo(CompFactory.LArRawSCDataReadingAlg(adcCollKey = digKey, adcBasCollKey = "", etCollKey = "",
72 etIdCollKey = "", LATOMEDecoder = theLArLATOMEDecoder))
73 from LArCalibProcessing.LArCalib_CalibDigitsMakerConfig import LArCalibDigitsMakerCfg
74 result.merge(LArCalibDigitsMakerCfg(flags,digKey))
75
76 else:
77
78 from LArCabling.LArCablingConfig import LArCalibIdMappingCfg,LArOnOffIdMappingCfg
79 result.merge(LArOnOffIdMappingCfg(flags))
80 result.merge(LArCalibIdMappingCfg(flags))
81 result.addEventAlgo(CompFactory.LArRawSCCalibDataReadingAlg(LArSCAccCalibDigitKey = digKey,
82 CalibCablingKeyLeg="LArCalibLineMap",
83 OnOffMapLeg="LArOnOffIdMap",
84 LATOMEDecoder = theLArLATOMEDecoder, ))
85
86 bcKey = "LArBadChannelSC" if flags.LArCalib.isSC else "LArBadChannel"
87
88 theLArCaliWaveBuilder = CompFactory.LArCaliWaveBuilder()
89 theLArCaliWaveBuilder.KeyList= [digKey,]
90 theLArCaliWaveBuilder.KeyOutput="LArCaliWave"
91 theLArCaliWaveBuilder.GroupingType = flags.LArCalib.GroupingType
92 theLArCaliWaveBuilder.SubtractPed = True
93 theLArCaliWaveBuilder.NSteps = flags.LArCalib.CaliWave.Nsteps
94 theLArCaliWaveBuilder.CheckEmptyPhases = not flags.LArCalib.isSC
95 theLArCaliWaveBuilder.NBaseline = 0
96 theLArCaliWaveBuilder.UseDacAndIsPulsedIndex = False
97 theLArCaliWaveBuilder.RecAllCells = False
98 theLArCaliWaveBuilder.CheckEmptyPhases = False
99 theLArCaliWaveBuilder.isSC = flags.LArCalib.isSC
100 result.addEventAlgo(theLArCaliWaveBuilder)
101
102
103 if flags.LArCalib.Input.SubDet == "HEC" or flags.LArCalib.Input.SubDet == "HECFCAL":
104 theLArCaliWaveBuilder.KeyOutput="LArCaliWave_multi"
105 theLArCaliWaveSelector = CompFactory.LArCaliWaveSelector("LArCaliWaveSelector")
106 theLArCaliWaveSelector.KeyList = ["LArCaliWave_multi",]
107 theLArCaliWaveSelector.KeyOutput = "LArCaliWave"
108 theLArCaliWaveSelector.GroupingType = flags.LArCalib.GroupingType
109 if flags.LArCalib.Gain==0:
110 theLArCaliWaveSelector.SelectionList = [ "HEC/0/0/460","HEC/1/0/460","HEC/2/0/230","HEC/3/0/230" ]
111 theLArCaliWaveSelector.SelectionList += [ "FCAL/0/0/500","FCAL/1/0/500","FCAL/2/0/500","FCAL/3/0/500" ]
112
113 elif flags.LArCalib.Gain==1:
114 theLArCaliWaveSelector.SelectionList = [ "HEC/0/1/3600","HEC/1/1/3600","HEC/2/1/1800","HEC/3/1/1800"]
115 theLArCaliWaveSelector.SelectionList += [ "FCAL/0/1/5000","FCAL/1/1/5000","FCAL/2/1/5000","FCAL/3/1/5000" ]
116
117 elif flags.LArCalib.Gain==2:
118 theLArCaliWaveSelector.SelectionList = [ "HEC/0/2/24000","HEC/1/2/24000","HEC/2/2/18000","HEC/3/2/18000" ]
119 theLArCaliWaveSelector.SelectionList += [ "FCAL/0/2/40000","FCAL/1/2/40000","FCAL/2/2/40000","FCAL/3/2/40000" ]
120
121 result.addEventAlgo(theLArCaliWaveSelector)
122 pass
123
124 if flags.LArCalib.CorrectBadChannels:
125 theLArCaliWavePatcher=CompFactory.getComp("LArCalibPatchingAlg<LArCaliWaveContainer>")("LArCaliWavePatch")
126 theLArCaliWavePatcher.ContainerKey = "LArCaliWave"
127 theLArCaliWavePatcher.BadChanKey = bcKey
128 theLArCaliWavePatcher.SuperCells = flags.LArCalib.isSC
129
130 theLArCaliWavePatcher.PatchMethod = "PhiAverage"
131 if flags.LArCalib.isSC:
132 theLArCaliWavePatcher.ProblemsToPatch = [
133 "deadCalib","deadReadout","deadPhys","maskedOSUM","OffOFCs","transmissionErrorFibre",]
134 theLArCaliWavePatcher.OnOffMap="LArOnOffIdMapSC"
135 theLArCaliWavePatcher.CalibLineKey="LArCalibIdMapSC"
136 else:
137 theLArCaliWavePatcher.ProblemsToPatch = [
138 "deadCalib","deadReadout","deadPhys","almostDead","short", ]
139
140 result.addEventAlgo(theLArCaliWavePatcher)
141 pass
142
143 if flags.LArCalib.doValidation:
144
145 result.merge(addFolders(flags,flags.LArCalib.CaliWave.Folder+"<key>LArCaliWaveRef</key>","LAR_OFL"))
146
147 from LArCalibDataQuality.Thresholds import cwAmpThr,cwFWHMThr,cwAmpThrFEB,cwFWHMThrFEB
149
150 theCaliWaveValidationAlg=CompFactory.LArCaliWaveValidationAlg("CaliWaveVal")
151 if flags.LArCalib.isSC:
152 theCaliWaveValidationAlg.ProblemsToMask=["deadCalib","deadReadout","deadPhys","maskedOSUM",
153 "OffOFCs","transmissionErrorFibre",]
154 else:
155 theCaliWaveValidationAlg.ProblemsToMask=["deadReadout","deadCalib","deadPhys","almostDead",
156 "highNoiseHG","highNoiseMG","highNoiseLG"]
157 theCaliWaveValidationAlg.ValidationKey="LArCaliWave"
158 theCaliWaveValidationAlg.ReferenceKey="LArCaliWaveRef"
159 theCaliWaveValidationAlg.MsgLevelForDeviations=WARNING
160 theCaliWaveValidationAlg.ListOfDevFEBs="caliWaveFebs.txt"
161 theCaliWaveValidationAlg.AmplitudeTolerance=cwAmpThr
162 theCaliWaveValidationAlg.CaliWaveFWHMTolerance=cwFWHMThr
163 theCaliWaveValidationAlg.AmplitudeToleranceFEB=cwAmpThrFEB
164 theCaliWaveValidationAlg.CaliWaveFWHMToleranceFEB=cwFWHMThrFEB
165 theCaliWaveValidationAlg.TimeShiftDetection=True
166 theCaliWaveValidationAlg.PatchMissingFEBs=True
167 theCaliWaveValidationAlg.UseCorrChannels=False
168 theCaliWaveValidationAlg.BadChanKey = bcKey
169 theCaliWaveValidationAlg.SuperCells = flags.LArCalib.isSC
170
171 if flags.LArCalib.isSC:
172 theCaliWaveValidationAlg.CablingKey = "LArOnOffIdMapSC"
173 theCaliWaveValidationAlg.CalibLineKey = "LArCalibIdMapSC"
174
175 result.addEventAlgo(theCaliWaveValidationAlg)
176
177
178 if flags.LArCalib.doOFCCali:
179
180 LArCaliOFCAlg = CompFactory.LArOFCAlg("LArCaliOFCAlg")
181 LArCaliOFCAlg.ReadCaliWave = True
182 LArCaliOFCAlg.KeyList = [ "LArCaliWave" ]
183 LArCaliOFCAlg.Nphase = 50
184 LArCaliOFCAlg.Dphase = 1
185 LArCaliOFCAlg.Ndelay = 24
186 LArCaliOFCAlg.Nsample = 5
187 LArCaliOFCAlg.Normalize = True
188 LArCaliOFCAlg.TimeShift = False
189 LArCaliOFCAlg.TimeShiftByIndex = -1
190 LArCaliOFCAlg.Verify = True
191 LArCaliOFCAlg.FillShape = False
192
193 LArCaliOFCAlg.GroupingType = flags.LArCalib.GroupingType
194 LArCaliOFCAlg.isSC = flags.LArCalib.isSC
195 LArCaliOFCAlg.DecoderTool=CompFactory.LArAutoCorrDecoderTool(isSC=flags.LArCalib.isSC)
196 result.addEventAlgo(LArCaliOFCAlg)
197
198
199
200 rootfile=flags.LArCalib.Output.ROOTFile
201 rootfile2=flags.LArCalib.Output.ROOTFile2
202 if rootfile != "":
203 result.addEventAlgo(CompFactory.LArCaliWaves2Ntuple(KeyList = ["LArCaliWave",],
204 NtupleName = "CALIWAVE",
205 AddFEBTempInfo = False,
206 RealGeometry = True,
207 SaveDerivedInfo = True,
208 ApplyCorrection = True,
209 isSC = flags.LArCalib.isSC,
210 BadChanKey = bcKey,
211 OffId=True,
212 AddCalib=True,
213 SaveJitter=True if flags.LArCalib.CaliWave.Nsteps >= 24 else False
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
222
223 if rootfile2 != "" and flags.LArCalib.doOFCCali:
224 result.addEventAlgo(CompFactory.LArOFC2Ntuple(ContainerKey = "LArOFC",
225 AddFEBTempInfo = False,
226 NtupleFile = "FILE2",
227 BadChanKey = bcKey,
228 isSC = flags.LArCalib.isSC,
229 AddCalib=True
230 ))
231
232 import os
233 if os.path.exists(rootfile2):
234 os.remove(rootfile2)
235 if rootfile == "":
236 result.addService(CompFactory.NTupleSvc(Output = [ "FILE2 DATAFILE='"+rootfile2+"' OPT='NEW'" ]))
237 else:
238 result.getService("NTupleSvc").Output += [ "FILE2 DATAFILE='"+rootfile2+"' OPT='NEW'" ]
239 result.setAppProperty("HistogramPersistency","ROOT")
240 pass
241
242
243 from RegistrationServices.OutputConditionsAlgConfig import OutputConditionsAlgCfg
244 result.merge(OutputConditionsAlgCfg(flags,
245 outputFile=flags.LArCalib.Output.POOLFile,
246 ObjectList=["LArCaliWaveContainer#LArCaliWave#"+flags.LArCalib.CaliWave.Folder,],
247 IOVTagList=[caliWaveTag,],
248 Run1=flags.LArCalib.IOVStart,
249 Run2=flags.LArCalib.IOVEnd
250 ))
251 if flags.LArCalib.doOFCCali:
252 result.getEventAlgo("OutputConditionsAlg").ObjectList += ["LArOFCComplete#LArOFC#"+flags.LArCalib.OFCCali.Folder]
253 result.getEventAlgo("OutputConditionsAlg").IOVTagList += [caliOFCTag]
254
255
256 result.addService(CompFactory.IOVRegistrationSvc(RecreateFolders = False))
257
258
259 from PerfMonComps.PerfMonCompsConfig import PerfMonMTSvcCfg
260 result.merge(PerfMonMTSvcCfg(flags))
261
262 return result
263