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