82 {
83
84
86
87 if (writeHandle.isValid()) {
89 "CondHandle "
90 << writeHandle.fullKey() << " is already valid.");
91 return StatusCode::SUCCESS;
92 }
93
94
95
96 const LArOnlineID_Base *larOnlineID = nullptr;
98 const LArOnline_SuperCellID *scidhelper;
100 larOnlineID = scidhelper;
101 } else {
102 const LArOnlineID *idhelper;
104 larOnlineID = idhelper;
105 }
106
107
108 const LArOnOffIdMapping *larOnOffIdMapping = nullptr;
109 SG::ReadCondHandle<LArOnOffIdMapping> larOnOffIdMappingHdl{
111 };
112 larOnOffIdMapping = *larOnOffIdMappingHdl;
113 if (larOnOffIdMapping == nullptr) {
114 ATH_MSG_ERROR(
"Failed to retrieve LArOnOffIdMapping object");
115 return StatusCode::FAILURE;
116 }
117 writeHandle.addDependency(larOnOffIdMappingHdl);
118
119
120
122
123
124
125 const ILArShape *larShape{ *ShapeHdl };
126 if (larShape == nullptr) {
128 return StatusCode::FAILURE;
129 }
130 writeHandle.addDependency(ShapeHdl);
131
133 const LArAutoCorrTotal *larAutoCorrTotal = nullptr;
134 larAutoCorrTotal= *AutoCorrTotalHdl;
135 if (larAutoCorrTotal == nullptr) {
137 return StatusCode::FAILURE;
138 }
139 writeHandle.addDependency(AutoCorrTotalHdl);
140
141
142 const ILArNoise *larNoise = nullptr;
143 const ILArPedestal *larPedestal = nullptr;
144
147 larNoise = *NoiseHdl;
148 if (larNoise == nullptr) {
150 return StatusCode::FAILURE;
151 }
152 writeHandle.addDependency(NoiseHdl);
153 } else {
155 larPedestal = *PedestalHdl;
156 if (larPedestal == nullptr) {
158 return StatusCode::FAILURE;
159 }
160 writeHandle.addDependency(PedestalHdl);
161 }
162
163 ATH_MSG_INFO(
"IOV found from intersection for LArOFCCondObj object: "
164 << writeHandle.getRange());
165
166
167
168
169 std::unique_ptr<LArOFC> larOFC =
170 std::make_unique<LArOFC>(larOnlineID, larOnOffIdMapping,
m_nGains);
171
172 std::vector<float> OFCa_tmp, OFCb_tmp;
173
174 for (
const HWIdentifier chid : larOnlineID->
channel_range()) {
175 const IdentifierHash hid = larOnlineID->
channel_Hash(chid);
176
177
180
181
182
183
184
186 unsigned int nsamples_shape = Shape.size();
188
189
190
191 int igain_autocorr = 0;
192
195
196 const std::vector<double>
AutoCorr =
198
199 unsigned int nsamples_AC_OFC = (1+((
int)(sqrt(1+8*
AutoCorr.size()))))/2;
200
201 const std::vector<double>& rmsSampl =
203 unsigned int nsamples2 = rmsSampl.size();
204 if (nsamples2 != nsamples_AC_OFC) {
206
207 }
208
209
210
211
214 firstSample=1;
215 }
216 unsigned int iBeginOfNSamples = firstSample;
217 if(nsamples_AC_OFC + iBeginOfNSamples > nsamples_shape)
218 iBeginOfNSamples=0;
219
220
222 }
223 else
224 {
225 float RMSpedestal = larPedestal->
pedestalRMS(chid,igain);
227 ;
228 else
229 {
231 <<chid<<" at gain "<<igain );
232 }
233 }
234
235
236
237 if(Shape.size()==0 || ShapeDer.size()==0 ||
AutoCorr.empty())
238 {
240 <<chid<<" at gain "<<igain );
241
242
243 }
244 if (Shape.size()!=ShapeDer.size()) {
245 ATH_MSG_ERROR(
"Got invalid shape object: Size=" << Shape.size() <<
", DerSize=" << ShapeDer.size());
246 return StatusCode::SUCCESS;
247 }
248
250
251
252
253
254
255
256 Eigen::MatrixXf
AC = Eigen::MatrixXf::Zero(nsamples_AC_OFC,nsamples_AC_OFC);
257 Eigen::MatrixXf ACinv = Eigen::MatrixXf::Zero(nsamples_AC_OFC,nsamples_AC_OFC);
258 for(l=0;
l<nsamples_AC_OFC;++
l) {
259 for(c=0;
c<nsamples_AC_OFC;++
c) {
260 if (l==c) {
262 }
263 else {
264 int i1=std::min(l,c);
265 int i2=std::max(l,c);
266 int index = i1*nsamples_AC_OFC - i1*(i1+1)/2 -(i1+1) + i2;
268 }
269 AC(l,c) =
AC(l,c)*rmsSampl[
l]*rmsSampl[
c];
270 }
271 }
273
274
275
276 float ACinv_PS[32];
277 float ACinv_PSD[32];
278
279 float Q1=0.;
280 float Q2=0.;
281 float Q3=0.;
282
283 for(l=0;
l<nsamples_AC_OFC;++
l)
284 {
285 ACinv_PS[
l]=0.; ACinv_PSD[
l]=0.;
286 for(c=0;
c<nsamples_AC_OFC;++
c){
287 ACinv_PS[
l]+=ACinv(l,c)*Shape[
c+iBeginOfNSamples];
288 ACinv_PSD[
l]+=ACinv(l,c)*ShapeDer[
c+iBeginOfNSamples];
289 }
290 Q1+=Shape[
l+iBeginOfNSamples]*ACinv_PS[
l];
291 Q2+=ShapeDer[
l+iBeginOfNSamples]*ACinv_PSD[
l];
292 Q3+=ShapeDer[
l+iBeginOfNSamples]*ACinv_PS[
l];
293 }
294 float DELTA=Q1*Q2-Q3*Q3;
295
296
297 OFCa_tmp.resize(nsamples_AC_OFC);
298 for(i=0;
i<nsamples_AC_OFC;++
i)
299 OFCa_tmp[i]=(ACinv_PS[i]*Q2-ACinv_PSD[i]*Q3)/
DELTA;
300
301 OFCb_tmp.resize(nsamples_AC_OFC);
302 for(i=0;
i<nsamples_AC_OFC;++
i)
303 OFCb_tmp[i]=(ACinv_PS[i]*Q3-ACinv_PSD[i]*Q1)/
DELTA;
304
305
307 {
308 std::cout<<larOnlineID
311 std::cout<<"Shape: ";
312 for(c=0;
c<nsamples_shape;++
c)
313 std::cout<<Shape[c]<<" ";
314 std::cout<<std::endl;
315 std::cout<<"ShapeDer: ";
316 for(c=0;
c<nsamples_shape;++
c)
317 std::cout<<ShapeDer[c]<<" ";
318 std::cout<<std::endl;
319 for(c=0;
c<nsamples_AC_OFC;++
c)
320 std::cout<<Shape[c+iBeginOfNSamples]<<" ";
321 std::cout<<" <- "<<iBeginOfNSamples<<std::endl;
322 for(i=0;
i<nsamples_AC_OFC;++
i) std::cout<<ACinv_PS[i]<<
" ";
323 std::cout<<std::endl;
324 for(i=0;
i<nsamples_AC_OFC;++
i) std::cout<<ACinv_PSD[i]<<
" ";
325 std::cout<<std::endl;
326 std::cout<<" Q1="<<Q1<<" Q2="<<Q2<<" Q3="<<Q3
327 <<
" DELTA="<<
DELTA<<std::endl;
328 std::cout << " OFCa: ";
329 for(i=0;
i<nsamples_AC_OFC;++
i)
330 std::cout<<(ACinv_PS[i]*Q2-ACinv_PSD[i]*Q3)/
DELTA<<
" ";
331 std::cout<<std::endl;
332 }
333 bool stat = larOFC->setOFC(hid, igain, std::make_pair(OFCa_tmp, OFCb_tmp));
334 if (!stat) {
335 msg(MSG::ERROR) <<
"LArOFC::setOFC fails for gain " <<
igain <<
", hash " << hid <<
endmsg;
336 }
337 }
338 } else {
340 std::vector<float>
empty;
341 bool stat = larOFC->setOFC(hid,igain, std::make_pair(
empty,
empty));
342 if (!stat) {
343 msg(MSG::ERROR) <<
"LArOFC::setOFC fails for gain " <<
igain <<
", hash " << hid <<
endmsg;
344 }
345 }
346 }
347
348 }
349
350
351 ATH_CHECK(writeHandle.record(std::move(larOFC)));
353 return StatusCode::SUCCESS;
354}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
static const double DELTA
static const Attributes_t empty
const ServiceHandle< StoreGateSvc > & detStore() const
std::string show_to_string(Identifier id, const IdContext *context=0, char sep='.') const
or provide the printout in string form
virtual float pedestalRMS(const HWIdentifier &id, int gain) const =0
access to RMS of Pedestal index by Identifier, and gain setting
LArVectorProxy ShapeRef_t
This class defines the interface for accessing Shape (Nsample variable, Dt = 25 ns fixed) @stereotype...
virtual ShapeRef_t Shape(const HWIdentifier &id, int gain, int tbin=0, int mode=0) const =0
virtual ShapeRef_t ShapeDer(const HWIdentifier &id, int gain, int tbin=0, int mode=0) const =0
const std::vector< double > autoCorrTotal(const IdentifierHash &hid, int gain, float Nminbias) const
const std::vector< double > samplRMS(const IdentifierHash &hid, int gain, float Nminbias) const
Identifier cnvToIdentifier(const HWIdentifier &sid) const
create an Identifier from a HWIdentifier (inline)
bool isOnlineConnected(const HWIdentifier &sid) const
Test whether a HWIdentifier is connected of not (inline) .
id_range channel_range() const
IdentifierHash channel_Hash(HWIdentifier channelId) const
Create channel_hash from channel_Id.
bool isFCALchannel(const HWIdentifier id) const
virtual bool isHECchannel(const HWIdentifier id) const =0
l
Printing final latex table to .tex output file.