ATLAS Offline Software
Loading...
Searching...
No Matches
LArAutoCorrTotalCondAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
7
9
12
14
15
17
19 ATH_MSG_DEBUG("initialize " << name());
20
21 // ReadCondHandle initialization
22 ATH_CHECK(m_LArShapeObjKey.initialize());
23 ATH_CHECK(m_LArAutoCorrObjKey.initialize());
25 ATH_CHECK( m_LArADC2MeVObjKey.initialize());
26
28
33
34 // Supercells have only one gain
35 if (m_isSuperCell) {
36 m_nGains = 1;
37 }
38
39 ATH_MSG_DEBUG("settings: m_NoPile " << m_NoPile);
40 return StatusCode::SUCCESS;
41}
42
43StatusCode LArAutoCorrTotalCondAlg::execute(const EventContext& ctx) const {
44
45 // WriteHandle setup
47 // So the following should not be called usually?!
48 if (writeHandle.isValid()) {
50 "CondHandle "
51 << writeHandle.fullKey() << " is already valid.");
52 return StatusCode::SUCCESS;
53 }
54
55 // Identifier helper
56 const LArOnlineID_Base *larOnlineID = nullptr;
57 if (m_isSuperCell) {
58 const LArOnline_SuperCellID *scidhelper;
59 ATH_CHECK(detStore()->retrieve(scidhelper, "LArOnline_SuperCellID"));
60 larOnlineID = scidhelper; // cast to base-class
61 } else { // regular cells
62 const LArOnlineID *idhelper;
63 ATH_CHECK(detStore()->retrieve(idhelper, "LArOnlineID"));
64 larOnlineID = idhelper; // cast to base-class
65 }
66 // Mapping helper
67 const LArOnOffIdMapping *larOnOffIdMapping = nullptr;
68 SG::ReadCondHandle<LArOnOffIdMapping> larOnOffIdMappingHdl{
70 };
71 larOnOffIdMapping = *larOnOffIdMappingHdl;
72 if (larOnOffIdMapping == nullptr) {
73 ATH_MSG_ERROR("Failed to retrieve LArOnOffIdMapping object");
74 }
75
76 // Get pointers to inputs
78 // FIXME: should check if handle is properly created and/or check if handle is
79 // properly retrieved
80 // operator star of a ReadCondHandle returns a const pointer to type T
81 const ILArShape *larShape{ *ShapeHdl };
82 writeHandle.addDependency(ShapeHdl);
83
85 const ILArAutoCorr *larAutoCorr{ *AutoCorrHdl };
86 writeHandle.addDependency(AutoCorrHdl);
87
89 const LArADC2MeV *larADC2MeV = nullptr;
90 larADC2MeV = *ADC2MeVHdl;
91 if (larADC2MeV == nullptr) {
92 ATH_MSG_ERROR("Failed to retrieve LArADC2MeV object");
93 return StatusCode::FAILURE;
94 }
95 writeHandle.addDependency(ADC2MeVHdl);
96
97 // Consider the determinstic objects
98 // checking isMC and NoPile again seems very clumsy. How to check if key has
99 // already been initialized?
100 const ILArNoise *larNoise = nullptr;
101 const ILArPedestal *larPedestal = nullptr;
102 const ILArfSampl *larfSampl = nullptr;
103 const ILArMinBias *larMinBias = nullptr;
104
105 if (!m_NoPile) {
106 if (m_isMC) {
108 larNoise = *NoiseHdl;
109 writeHandle.addDependency(NoiseHdl);
110 } else {
112 larPedestal = *PedestalHdl;
113 writeHandle.addDependency(PedestalHdl);
114 }
115
117 larfSampl = *fSamplHdl;
118 writeHandle.addDependency(fSamplHdl);
119
121 larMinBias = *MinBiasHdl;
122 writeHandle.addDependency(MinBiasHdl);
123 }
124
125 ATH_MSG_INFO("IOV found from intersection for AutoCorrTotal object: "
126 << writeHandle.getRange());
127
128 // make output object
129 // dimensions: number of gains x number of channel IDs x elements of
130 // AutoCorrTotal
131 std::unique_ptr<LArAutoCorrTotal> larAutoCorrTotal =
132 std::make_unique<LArAutoCorrTotal>(larOnlineID, larOnOffIdMapping, m_nGains);
133
134 int count = 0;
135 int count2 = 0;
136 int count3 =0;
137
138 for (const HWIdentifier chid : larOnlineID->channel_range()) {
139 count++;
140 const IdentifierHash hid = larOnlineID->channel_Hash(chid);
141 // const unsigned int id32 = chid.get_identifier32().get_compact();
142
143 if (larOnOffIdMapping->isOnlineConnected(chid)) {
144 count2++;
145
146 for (size_t igain = 0; igain < m_nGains; igain++) {
147 const ILArShape::ShapeRef_t Shape = larShape->Shape(chid, igain);
148 const int nsamples_shape = static_cast<int>(Shape.size());
149
151 larAutoCorr->autoCorr(chid, igain);
152
153 if (AC.size() == 0) {
154 ATH_MSG_INFO("No ElecCalib AC for channel " << larOnlineID->channel_name(chid) << ", gain "<<igain << ". Skip.");
155 continue;
156 }
157
158 count3++;
159 int nsamples_AC_OFC = AC.size() + 1;
160
161 if (nsamples_AC_OFC > m_Nsamples) {
162 nsamples_AC_OFC = m_Nsamples;
163 }
164
165 // fix HEC first sample +1 if the firstSample is 0 and nsamples 4
166 unsigned int ihecshift = 0;
167 if (larOnlineID->isHECchannel(chid) && nsamples_AC_OFC == 4 &&
168 m_firstSample == 0) {
169 ihecshift = 1;
170 // ATH_MSG_DEBUG( "Using firstSample +1 for HEC ChID 0x" << MSG::hex
171 // << id << MSG::dec );
172 }
173
174 //:::::::::::::::::::::::::::::::
175 // NB:
176 // nsamples_shape = number of samples of the Shape function (e.g 32)
177 // nsamples_AC_OFC = size of AC matrix & OFC vector (e.g 5 in Atlas)
178 //:::::::::::::::::::::::::::::::
179 float fSigma2 = 0.;
180 if (!m_NoPile) {
181 float SigmaNoise;
182 if (m_isMC)
183 SigmaNoise = larNoise->noise(chid, igain);
184 else {
185 float RMSpedestal = larPedestal->pedestalRMS(chid, igain);
186 if (RMSpedestal > (1.0 + LArElecCalib::ERRORCODE))
187 SigmaNoise = RMSpedestal;
188 else
189 SigmaNoise = 0.; //(we will have the ERROR message below)
190 }
191 float fSampl = larfSampl->FSAMPL(chid);
192 float MinBiasRMS = larMinBias->minBiasRMS(chid);
193 if (fSampl != 0)
194 MinBiasRMS /= fSampl;
195 const auto polynom_adc2mev =
196 larADC2MeV->ADC2MEV(hid, igain);
197 float Adc2MeV = 0.;
198 if (polynom_adc2mev.size() > 0) {
199 Adc2MeV = (polynom_adc2mev)[1];
200 }
201 if (SigmaNoise != 0 && Adc2MeV != 0)
202 fSigma2 = pow(MinBiasRMS / (SigmaNoise * Adc2MeV), 2);
203
204 if (fSampl == 0 || SigmaNoise == 0 || Adc2MeV == 0) {
205 if (m_isMC) {
206 ATH_MSG_ERROR(larOnlineID->show_to_string(
207 larOnOffIdMapping->cnvToIdentifier(chid))
208 << "fSampl (" << fSampl << "), SigmaNoise ("
209 << SigmaNoise << ") or Adc2MeV (" << Adc2MeV
210 << ") null "
211 << "=> AutoCorrTotal = only AutoCorr elect. part ");
212 }
213 fSigma2 = 0.;
214 }
215 ATH_MSG_DEBUG(chid.get_identifier32().get_compact()
216 << ") fSampl (" << fSampl << ") "
217 << ") SigmaNoise (" << SigmaNoise << ") "
218 << ") Adc2MeV (" << Adc2MeV << ") "
219
220 );
221
222 // warning: MinBiasRMS is in MeV (at the scale of the hits)
223 // SigmaNoise is in ADC counts
224 // so MinBiasRMS/fScale and SigmaNoise*Adc2MeV are the same scale
225 // (MeV at the scale of the cells)
226 } // end if m_NoPile
227
228 // get in vTerms all the possible non trivial N(N-1)/2 terms of the
229 // autocorrelation matrix
230 int nsize_tot = (nsamples_AC_OFC - 1) * (nsamples_AC_OFC) / 2;
231
232 ATH_MSG_DEBUG(chid.get_identifier32().get_compact()
233 << ") fSigma2 (" << fSigma2 << ") "
234 << ") nsamples_AC_OFC ( " << nsamples_AC_OFC);
235 std::vector<float> vTerms;
236
237 vTerms.resize(2 * nsize_tot + nsamples_AC_OFC, 0.);
238 //:::::::::::::::::::::::::::::::
239
240 for (int j1 = 0; j1 < nsamples_AC_OFC - 1; j1++) {
241 for (int j2 = j1 + 1; j2 < nsamples_AC_OFC; j2++) {
242 int l = abs(j2 - j1) - 1;
243 int index =
244 j1 * nsamples_AC_OFC - j1 * (j1 + 1) / 2 + j2 - (j1 + 1);
245 vTerms[index] = AC[l];
246 }
247 }
248
249 ATH_MSG_DEBUG(chid.get_identifier32().get_compact()
250 << ") vTerms[1] (" << vTerms[1] << ") ");
251 // 2nd terms :
252 for (int j1 = 0; j1 < nsamples_AC_OFC - 1; ++j1) {
253 for (int j2 = j1 + 1; j2 < nsamples_AC_OFC; j2++) {
254 int index =
255 j1 * nsamples_AC_OFC - j1 * (j1 + 1) / 2 + j2 - (j1 + 1);
256 float Rij = 0;
257 for (int k = 0; k < nsamples_shape; ++k) {
258 if ((j2 - j1 + k) >= 0 && (j2 - j1 + k) < nsamples_shape) {
259 int ibunch = 0;
260 if ((j1 + m_firstSample + ihecshift - k) % m_deltaBunch == 0)
261 ibunch = 1;
262 Rij += Shape[k] * Shape[j2 - j1 + k] * ibunch;
263 }
264 }
265 vTerms[nsize_tot + index] = fSigma2 * Rij;
266 }
267 }
268 ATH_MSG_DEBUG(chid.get_identifier32().get_compact()
269 << ") vTerms[mid] (" << vTerms[vTerms.size()/2] << ") ");
270
271 // 3rd term : RMS of pileup per samples (multiplied by fSigma2)
272 for (int j1 = 0; j1 < nsamples_AC_OFC; j1++) {
273 float Rms2i = 0;
274 for (int k = 0; k < nsamples_shape; ++k) {
275 int ibunch = 0;
276 if ((j1 + m_firstSample + ihecshift - k) % m_deltaBunch == 0)
277 ibunch = 1;
278 Rms2i += pow(Shape[k], 2) * ibunch;
279 }
280 vTerms[2 * nsize_tot + j1] = fSigma2 * Rms2i;
281 }
282 ATH_MSG_DEBUG(chid.get_identifier32().get_compact()
283 << ") vTerms[last] (" << vTerms[vTerms.size()-1] << ") ");
284
285
286 // storage
287 larAutoCorrTotal->set(hid, igain, vTerms);
288
289 } //(loop on gains)
290
291 } else // unconnected
292 for (unsigned int igain = 0; igain < m_nGains; igain++) {
293 unsigned nsize_tot = (m_Nsamples - 1) * (m_Nsamples) + m_Nsamples;
294 std::vector<float> empty(nsize_tot, 0.);
295 larAutoCorrTotal->set(hid, igain, empty);
296 }
297 }
298
299 ATH_MSG_INFO("LArAutoCorrTotal Ncell " << count);
300 ATH_MSG_INFO("LArAutoCorrTotal Ncell * Ngain " << count3);
301 ATH_MSG_INFO("LArAutoCorrTotal Nconnected " << count2);
302
303 ATH_MSG_INFO("LArAutoCorrTotal record with key" << m_LArAutoCorrTotalObjKey);
304
305 ATH_CHECK(writeHandle.record(std::move(larAutoCorrTotal)));
306
307
308 return StatusCode::SUCCESS;
309}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
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
This class defines the interface for accessing AutoCorrelation parameters for each channel @stereotyp...
LArVectorProxy AutoCorrRef_t
virtual AutoCorrRef_t autoCorr(const HWIdentifier &CellID, int gain) const =0
virtual const float & minBiasRMS(const HWIdentifier &id) const =0
access to RMS of E in minimum bias events index by Identifier
virtual const float & noise(const HWIdentifier &id, int gain) const =0
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...
Definition ILArShape.h:26
virtual ShapeRef_t Shape(const HWIdentifier &id, int gain, int tbin=0, int mode=0) const =0
virtual const float & FSAMPL(const HWIdentifier &id) const =0
This is a "hash" representation of an Identifier.
const LArVectorProxy ADC2MEV(const HWIdentifier &id, int gain) const
Definition LArADC2MeV.h:32
SG::WriteCondHandleKey< LArAutoCorrTotal > m_LArAutoCorrTotalObjKey
Gaudi::Property< unsigned > m_nGains
SG::ReadCondHandleKey< LArOnOffIdMapping > m_LArOnOffIdMappingObjKey
SG::ReadCondHandleKey< ILArShape > m_LArShapeObjKey
SG::ReadCondHandleKey< ILArPedestal > m_LArPedestalObjKey
SG::ReadCondHandleKey< ILArMinBias > m_LArMinBiasObjKey
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadCondHandleKey< ILArAutoCorr > m_LArAutoCorrObjKey
virtual ~LArAutoCorrTotalCondAlg() override
Gaudi::Property< bool > m_isMC
Gaudi::Property< int > m_deltaBunch
SG::ReadCondHandleKey< LArADC2MeV > m_LArADC2MeVObjKey
SG::ReadCondHandleKey< ILArNoise > m_LArNoiseObjKey
SG::ReadCondHandleKey< ILArfSampl > m_LArfSamplObjKey
Gaudi::Property< unsigned int > m_firstSample
Gaudi::Property< bool > m_isSuperCell
Gaudi::Property< bool > m_NoPile
virtual StatusCode initialize() override
Gaudi::Property< int > m_Nsamples
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) .
Helper for the Liquid Argon Calorimeter cell identifiers.
id_range channel_range() const
IdentifierHash channel_Hash(HWIdentifier channelId) const
Create channel_hash from channel_Id.
std::string channel_name(const HWIdentifier id) const
Return a string corresponding to a feedthrough name given an identifier.
virtual bool isHECchannel(const HWIdentifier id) const =0
void addDependency(const EventIDRange &range)
const EventIDRange & getRange() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:148
Definition index.py:1