ATLAS Offline Software
Loading...
Searching...
No Matches
LArCaliWaveAverage.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include "GaudiKernel/Bootstrap.h"
8#include "GaudiKernel/MsgStream.h"
9#include "GaudiKernel/ToolHandle.h"
10
14
15#include <vector>
16#include <map>
17
18using WaveMap = std::map<int, LArCaliWave>;
19
20LArCaliWaveAverage::LArCaliWaveAverage(const std::string& name, ISvcLocator* pSvcLocator) :
21 AthCondAlgorithm(name, pSvcLocator),
22 m_onlineHelper(nullptr),
23 m_emId(nullptr),
24 m_hecId(nullptr),
25 m_fcalId(nullptr)
26{
27 m_chids.clear();
28 declareProperty("ChannelIDs", m_chids);
29 declareProperty("GroupingType", m_groupingType = "ExtendedFeedThrough"); // SubDetector, Single, FeedThrough, ExtendedFeedThrough
30}
31
33
35 const CaloCell_ID* idHelper = nullptr;
36 ATH_CHECK( detStore()->retrieve (idHelper, "CaloCell_ID") );
37 m_emId = idHelper->em_idHelper();
38 if (!m_emId) {
39 ATH_MSG_ERROR ( "Could not get lar EM ID helper!" );
40 return StatusCode::FAILURE;
41 }
42 m_fcalId=idHelper->fcal_idHelper();
43 if (!m_fcalId) {
44 ATH_MSG_ERROR ( "Could not get lar FCAL ID helper" );
45 return StatusCode::FAILURE;
46 }
47 m_hecId=idHelper->hec_idHelper();
48 if (!m_hecId) {
49 ATH_MSG_ERROR ( "Could not get lar HEC ID helper" );
50 return StatusCode::FAILURE;
51 }
52
53 ATH_CHECK( detStore()->retrieve(m_onlineHelper, "LArOnlineID") );
54
55 ATH_CHECK(m_cablingKey.initialize());
56 ATH_CHECK(m_keyInput.initialize());
57 ATH_CHECK(m_keyOutputCorr.initialize());
58 ATH_CHECK(m_keyOutputSymm.initialize());
59
60 if ( !m_chids.empty() ) {
61 ATH_MSG_INFO ( m_chids.size() << " channels selected for averaging." );
62 } else {
63 ATH_MSG_ERROR ( "No channels selected for averaging!" );
64 return StatusCode::FAILURE;
65 }
66
67 return StatusCode::SUCCESS;
68}
69
70StatusCode LArCaliWaveAverage::execute(const EventContext& /*ctx*/) const {
71 ATH_MSG_INFO ( "execute()" );
72 return StatusCode::SUCCESS;
73}
74
76 ATH_MSG_INFO ( "stop()" );
77
78 // Get input LArCaliWaveContainer
80 const LArCaliWaveContainer* theLArCaliWaveContainer = *inHdl;
81 if (! theLArCaliWaveContainer ) {
82 ATH_MSG_ERROR ( "LArCaliWaveContainer (key = " << m_keyInput << ") is empty" );
83 return StatusCode::FAILURE;
84 }
85
86 // create correction LArCaliWaveContainer
87 auto larCaliWaveContainerCorr = std::make_unique<LArCaliWaveContainer>();
88 ATH_CHECK( larCaliWaveContainerCorr->setGroupingType(m_groupingType,msg()) );
89 ATH_CHECK( larCaliWaveContainerCorr->initialize() );
90
91 // create symmetric waves LArCaliWaveContainer
92 auto larCaliWaveContainerSymm = std::make_unique<LArCaliWaveContainer>();
93 ATH_CHECK( larCaliWaveContainerSymm->setGroupingType(m_groupingType,msg()) );
94
95 if (larCaliWaveContainerSymm->initialize()) {
96 ATH_MSG_ERROR ( "Failed to initialize LArCaliWaveContainer object" );
97 return StatusCode::FAILURE;
98 }
99
101 const LArOnOffIdMapping* cabling{*cablingHdl};
102 if(!cabling) {
103 ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key() );
104 return StatusCode::FAILURE;
105 }
106
107 for ( unsigned i=0; i<m_chids.size();++i) { // loop over selected channels
108
109 const HWIdentifier chid(m_chids[i]);
110
111 std::vector<HWIdentifier> theSymmetricChannels = SymmetricChannels(chid,m_chids,cabling);
112
113 if ( theSymmetricChannels.empty()) {
114 ATH_MSG_WARNING ( "No symmetric channels found for channel 0x" << MSG::hex << chid << MSG::dec << ". Cannot average." );
115 continue;
116 }
117
118 ATH_MSG_INFO ( theSymmetricChannels.size() << " symmetric channels indentified for channel 0x" << MSG::hex << chid << MSG::dec );
119
120 for ( unsigned gain = CaloGain::LARHIGHGAIN ; gain < CaloGain::LARNGAIN ; ++ gain ) { // loop over gains
121
122 ATH_MSG_VERBOSE ( "Now processing gain = " << gain );
123
124 // get Wave vector for current ChID/Gain, assuming it exists
125 const LArCaliWaveContainer::LArCaliWaves& theCaliWaves = theLArCaliWaveContainer->get(chid,gain);
126 if ( theCaliWaves.empty() ){
127 ATH_MSG_WARNING ( "No pulses found for channel 0x" << MSG::hex << chid << MSG::dec
128 << " in gain " << gain
129 << ". Are you sure that readout is working? For the time being I'm skipping..." );
130 continue;
131 }
132
133 LArCaliWaveVec theAverageWaves;
134
135 LArCaliWaveVec theSymmetricWavesAll; // vector of symmetric waves for the all DAC
136
137 for (unsigned iDAC=0;iDAC<theCaliWaves.size();++iDAC) { // loop over DAC values
138
139 int theDAC = theCaliWaves[iDAC].getDAC();
140
141 LArCaliWaveVec theSymmetricWavesThisDAC; // vector of symmetric waves for the current DAC
142
143 for (unsigned iSym=0;iSym<theSymmetricChannels.size();++iSym) { // loop over SymmetricChannels and fill LArCaliWave vector corresponding to current DAC
144
145 const LArCaliWaveContainer::LArCaliWaves& theseCaliWaves = theLArCaliWaveContainer->get(HWIdentifier(theSymmetricChannels[iSym]),gain);
146
147 for (unsigned kDAC=0;kDAC<theseCaliWaves.size();++kDAC) {
148 if ( theseCaliWaves[kDAC].getDAC() == theDAC ) {
149 LArCaliWave thisWave = theseCaliWaves[kDAC];
150 // store additional information in LArWave flag, e.g. FT
151 unsigned theFlag = m_onlineHelper->feedthrough(HWIdentifier(theSymmetricChannels[iSym]));
152 thisWave.setFlag(theFlag);
153 // save symmetric wave in vetor to be averaged
154 theSymmetricWavesThisDAC.push_back(thisWave);
155 }
156 }
157
158 }
159
160 if ( !theSymmetricWavesThisDAC.empty() ) {
161
162 ATH_MSG_INFO ( theSymmetricWavesThisDAC.size()
163 << " symmetric LArCaliWaves found for channel 0x" << MSG::hex << chid << MSG::dec
164 << " for DAC " << theDAC << " in gain " << gain
165 << ". Now averaging ... " );
166
167 // Average symmetric waves corresponding to this DAC/gain
168 LArCaliWave theAverageWave = WaveAverage(theSymmetricWavesThisDAC);
169
170 ATH_MSG_VERBOSE ( "... Done. Saving average to LArCaliWave vector." );
171
172 theAverageWaves.push_back(theAverageWave);
173
174 ATH_MSG_VERBOSE ( "Storing symmetric waves for the current DAC..." );
175
176 for (unsigned kSym=0;kSym<theSymmetricWavesThisDAC.size();++kSym) {
177 theSymmetricWavesAll.push_back(theSymmetricWavesThisDAC[kSym]);
178 }
179
180
181 } else {
182 ATH_MSG_WARNING ( "No symmetrich waves found for channel 0x" << MSG::hex << chid << MSG::dec
183 << " for DAC " << theDAC << ": no average will be computed." );
184 }
185
186 } // end of loop over DAC values
187
188 // fill new LArCaliWaveContainer with average wave
189 ATH_MSG_VERBOSE ( "Saving LArCaliWave vector to correction container." );
190 larCaliWaveContainerCorr->setPdata(chid,theAverageWaves,gain);
191
192 // store symmetric waves in other LArCaliWaveContainer (this is working only for a sinle DAC value!)
193 ATH_MSG_VERBOSE ( "Saving LArCaliWave vector to symmetric waves' container (flag contains FT info)" );
194 larCaliWaveContainerSymm->setPdata(chid,theSymmetricWavesAll,gain);
195
196 } // end of loop over gains
197
198 } // end of loop over selected channels
199
200 // Record average LArCaliWaveContainer to DetectorStore
201 // Define validity of the output cond object
202 const EventIDBase start{EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, 0, 0, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
203 const EventIDBase stop{EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
204 EventIDRange rangeW{start, stop};
206 const EventIDRange& crangeW(rangeW);
207 if(corrHdl.record(crangeW,larCaliWaveContainerCorr.release()).isFailure()) {
208 ATH_MSG_ERROR("Could not record LArCaliWaveContainer object with " << m_keyOutputCorr.key()
209 << " with EventRange " << crangeW << " into Conditions Store");
210 return StatusCode::FAILURE;
211 }
212 ATH_MSG_INFO("recorded new " << m_keyOutputCorr.key() << " with range " << crangeW << " into Conditions Store");
214 if(symHdl.record(crangeW,larCaliWaveContainerSymm.release()).isFailure()) {
215 ATH_MSG_ERROR("Could not record LArCaliWaveContainer object with " << m_keyOutputSymm.key()
216 << " with EventRange " << crangeW << " into Conditions Store");
217 return StatusCode::FAILURE;
218 }
219 ATH_MSG_INFO("recorded new " << m_keyOutputCorr.key() << " with range " << crangeW << " into Conditions Store");
220 return StatusCode::SUCCESS;
221}
222
223/*
224 SymmetricChannels() returns a vector of HWIdentifier corresponding
225 to the list of channels in the same et/phi position in all other FTs
226*/
227std::vector<HWIdentifier> LArCaliWaveAverage::SymmetricChannels(HWIdentifier ChID, const std::vector<unsigned>& ChannelsNotToUse, const LArOnOffIdMapping* cabling)
228{
229 ATH_MSG_VERBOSE ( "Seeking symmetric cells for channel 0x" << MSG::hex << ChID << MSG::dec );
230
231 std::vector<HWIdentifier> theSymmetricChannels;
232 theSymmetricChannels.resize(0);
233
234 Identifier id;
235 try {
236 id = cabling->cnvToIdentifier(ChID);
237 } catch (LArID_Exception & execpt) {
238 ATH_MSG_ERROR ( "LArCabling exception caught for channel 0x" << MSG::hex << ChID << MSG::dec );
239 return theSymmetricChannels;
240 }
241
242 int detector = -999;
243 int pos_neg = m_onlineHelper->pos_neg(ChID);
244 int barrel_ec = m_onlineHelper->barrel_ec(ChID);
245
246 int FT = m_onlineHelper->feedthrough(ChID);
247 int slot = m_onlineHelper->slot(ChID);
248 int channel = m_onlineHelper->channel(ChID);
249
250 /*
251 int region = -999;
252 int layer = -999;
253 int eta = -999;
254 int phi = -999;
255 */
256
257 if ( m_emId->is_em_barrel(id) || m_emId->is_em_endcap(id) ) {
258 detector = 0;
259 /*
260 eta = m_emId->eta(id);
261 phi = m_emId->phi(id);
262 layer = m_emId->sampling(id);
263 region = m_emId->region(id);
264 */
265 }
266 if ( m_hecId->is_lar_hec(id) ) {
267 detector = 1;
268 /*
269 eta = m_hecId->eta(id);
270 phi = m_hecId->phi(id);
271 layer = m_hecId->sampling(id);
272 region = m_hecId->region(id);
273 */
274 }
275 if ( m_fcalId->is_lar_fcal(id) ) {
276 detector = 2;
277 /*
278 eta = m_fcalId->eta(id);
279 phi = m_fcalId->phi(id);
280 layer = m_fcalId->module(id);
281 region = 0;
282 */
283 }
284
285 ATH_MSG_VERBOSE ( " Detector = " << detector );
286 ATH_MSG_VERBOSE ( " PosNeg = " << pos_neg );
287 ATH_MSG_VERBOSE ( " Barrel/EC = " << barrel_ec );
288
289 ATH_MSG_VERBOSE ( " FT = " << FT );
290 ATH_MSG_VERBOSE ( " Slot = " << slot );
291 ATH_MSG_VERBOSE ( " Channel = " << channel );
292
293 /*
294 ATH_MSG_VERBOSE ( " Region = " << region );
295 ATH_MSG_VERBOSE ( " Layer = " << layer );
296 ATH_MSG_VERBOSE ( " Eta = " << eta );
297 ATH_MSG_VERBOSE ( " Phi = " << phi );
298 */
299
300 unsigned nFT = 0;
301
302 if ( detector != 0 ) {
303 ATH_MSG_ERROR ( "Sorry, still implemented for EM only :-(" );
304 return theSymmetricChannels;
305 } else {
306 nFT = 32;
307 }
308
309 for ( unsigned iFT = 0;iFT<nFT;++iFT) { // loop over all FTs
310
311 // compute ChID fpr channel in iFT in same position
312 bool useThisChannel = true;
313 HWIdentifier thisChID = m_onlineHelper->channel_Id(barrel_ec,pos_neg,iFT,slot,channel);
314
315 // check if channel is allowed...
316 for ( unsigned i=0;i<ChannelsNotToUse.size();++i) {
317 if ( thisChID == HWIdentifier(ChannelsNotToUse[i]) ) {
318 useThisChannel = false;
319 break;
320 }
321 }
322
323 if ( useThisChannel )
324 theSymmetricChannels.push_back(thisChID);
325 }
326
327 return theSymmetricChannels;
328}
329
330
331LArCaliWave LArCaliWaveAverage::WaveAverage(const std::vector<LArCaliWave>& ToBeAveraged)
332{
333 if ( !ToBeAveraged.empty() ) {
334
335 ATH_MSG_VERBOSE ( "... Averaging wave number 1" );
336 LArWave theWaveAverage = (LArWave)ToBeAveraged[0];
337
338 for (unsigned i=1;i<ToBeAveraged.size();++i) {
339 ATH_MSG_VERBOSE ( "... Averaging wave number " << i+1 );
340 theWaveAverage = theWaveAverage + (LArWave)ToBeAveraged[i];
341 }
342
343 theWaveAverage = theWaveAverage * (1./float(ToBeAveraged.size()));
344
345 LArCaliWave theCaliWaveAverage( theWaveAverage.getWave() ,
346 ToBeAveraged[0].getErrors(),
347 ToBeAveraged[0].getTriggers(),
348 ToBeAveraged[0].getDt(),
349 ToBeAveraged[0].getDAC(),
350 ToBeAveraged[0].getIsPulsedInt(),
351 ToBeAveraged[0].getFlag() );
352
353 return theCaliWaveAverage;
354
355 } else {
356 LArCaliWave emptyWave = LArCaliWave();
357 return emptyWave;
358 }
359
360}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
std::map< int, LArCaliWave > WaveMap
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
Base class for conditions algorithms.
Helper class for offline cell identifiers.
Definition CaloCell_ID.h:34
const LArFCAL_ID * fcal_idHelper() const
access to FCAL idHelper
Definition CaloCell_ID.h:75
const LArEM_ID * em_idHelper() const
access to EM idHelper
Definition CaloCell_ID.h:63
const LArHEC_ID * hec_idHelper() const
access to HEC idHelper
Definition CaloCell_ID.h:69
SG::ReadCondHandleKey< LArCaliWaveContainer > m_keyInput
LArCaliWave WaveAverage(const std::vector< LArCaliWave > &ToBeAveraged)
LArCaliWaveAverage(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteCondHandleKey< LArCaliWaveContainer > m_keyOutputCorr
std::vector< HWIdentifier > SymmetricChannels(HWIdentifier ChID, const std::vector< unsigned > &ChannelsNotToUse, const LArOnOffIdMapping *cabling)
const LArOnlineID * m_onlineHelper
StatusCode stop() override final
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
const LArFCAL_ID * m_fcalId
const LArEM_ID * m_emId
StatusCode execute(const EventContext &ctx) const override final
StatusCode initialize() override final
const LArHEC_ID * m_hecId
SG::WriteCondHandleKey< LArCaliWaveContainer > m_keyOutputSymm
std::vector< unsigned > m_chids
Liquid Argon Cumulative Wave Container.
ConstReference get(const HWIdentifier id, unsigned int gain=0) const
get data with online identifier
Exception class for LAr Identifiers.
const std::vector< double > & getWave() const
Wave parameters.
Definition LArWave.h:167
void setFlag(const unsigned flag)
set flag
Definition LArWave.h:199
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
@ LARNGAIN
Definition CaloGain.h:19
@ LARHIGHGAIN
Definition CaloGain.h:18