ATLAS Offline Software
Loading...
Searching...
No Matches
LArDigitFillerTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
12
13
14
15#include "LArDigitFillerTool.h"
16
19#include "GaudiKernel/IToolSvc.h"
27#include <vector>
28
30#include <sstream>
31
32
33namespace D3PD {
34
35 /*
36LArDigitFillerTool::SortDigits::SortDigits(const LArOnlineID* onlineHelper)
37{
38 m_onlineHelper=onlineHelper;
39}
40 */
41
42
50 (const std::string& type,
51 const std::string& name,
52 const IInterface* parent)
53 : BlockFillerTool<LArDigit> (type, name, parent),
54 m_savesca(false),
55 //m_maxchannels(24000),
56 m_savedigit(true),
57 m_CaloType("EMHECFCAL"),
58 m_storeId(false),
59 m_em(false),
60 m_hec(false),
61 m_fcal(false),
62 //m_dump_cut(4096),
63 m_dump_gain("HIGHMEDIUMLOW"),
64 m_dumpIter(false),
65 //m_dumpDisc(false),
67 m_emId(0),
68 m_hecId(0),
69 m_fcalId(0),
71{
72 declareProperty("SaveDigit",m_savedigit);
73 declareProperty("SaveId",m_storeId);
74 declareProperty("SaveSCAAddress",m_savesca);
75 declareProperty("DumpIterResults",m_dumpIter);
76
77 //declareProperty("DumpDisconnected",m_dumpDisc);
78 //declareProperty("DumpGains",m_dump_gain);
79 //declareProperty("DumpCut",m_dump_cut);
80 //declareProperty("MaxChannels",m_maxChannels);
81 //declareProperty("Calo",m_CaloType);
82
83 for (int i = 0; i < CaloGain::LARNGAIN; i++)
84 m_gains[i] = false;
85
86 m_layer = 0;
87 m_eta = 0;
88 m_phi = 0;
89 m_gain = 0;
90 m_calo = 0;
91 m_barrel_ec = 0;
92 m_pos_neg = 0;
93 m_FT = 0;
94 m_slot = 0;
95 m_channel = 0;
96 m_samples = 0;
97 m_sca = 0;
98 m_offId = 0;
99 m_Itervalid = 0;
100 m_Iterconverged = 0;
101 m_IterNIter = 0;
102 m_IterAmpl = 0;
103 m_IterTau = 0;
105 m_IterDelay = 0;
106 m_IterQual = 0;
107 m_IterIdx = 0;
108}
109
110
115{
116 ATH_MSG_DEBUG( "in book()" );
117
118 const CaloCell_ID* idHelper = nullptr;
119 ATH_CHECK( detStore()->retrieve (idHelper, "CaloCell_ID") );
120 m_emId=idHelper->em_idHelper();
121 m_hecId=idHelper->hec_idHelper();
122 m_fcalId=idHelper->fcal_idHelper();
123
124
125 CHECK( m_cablingKey.initialize() );
126
127 CHECK( detStore()->retrieve(m_onlineHelper, "LArOnlineID") );
128
129
130 // CHECK(addVariable ("icell",m_cellIndex));
131 if (m_savedigit){
132 CHECK(addVariable ("layer", m_layer));
133 CHECK(addVariable ("ieta",m_eta));
134 CHECK(addVariable ("calo", m_calo));
135 CHECK(addVariable ("iphi", m_phi));
136 CHECK(addVariable ("barrel_ec",m_barrel_ec));
137 CHECK(addVariable ("pos_neg", m_pos_neg));
138 CHECK(addVariable ("FT", m_FT));
139 CHECK(addVariable ("slot", m_slot));
140 CHECK(addVariable ("channel", m_channel));
141 CHECK(addVariable ("gain",m_gain));
142 CHECK(addVariable ("Samples", m_samples));
143 }
144
145 if ( m_savesca == true ){
146 CHECK(addVariable ("sca_add", m_sca));
147 }
148 if ( m_storeId ) {
149 CHECK(addVariable ("offlineId", m_offId));
150 }
151
152 if (m_dumpIter) {
153 CHECK(addVariable("iter_valid" , m_Itervalid));
154 CHECK(addVariable("iter_converged" , m_Iterconverged));
155 CHECK(addVariable("iter_nIter" , m_IterNIter));
156 CHECK(addVariable("iter_ampl" , m_IterAmpl));
157 CHECK(addVariable("iter_tau" , m_IterTau));
158 CHECK(addVariable("iter_peakSample" , m_IterPeakSample));
159 CHECK(addVariable("iter_delay" , m_IterDelay));
160 CHECK(addVariable("iter_qual" , m_IterQual));
161 CHECK(addVariable("iter_index",m_IterIdx));
162 }
163
164 std::transform(m_CaloType.begin(), m_CaloType.end(), m_CaloType.begin(), toupper);
165 if(m_CaloType.find("EM") < m_CaloType.size()) m_em = true;
166 if(m_CaloType.find("HEC") < m_CaloType.size()) m_hec = true;
167 if(m_CaloType.find("FCAL") < m_CaloType.size()) m_fcal = true;
168
169 std::transform(m_dump_gain.begin(), m_dump_gain.end(), m_dump_gain.begin(), toupper);
170
171 if(m_dump_gain.find("HIGH")!=std::string::npos)
173 else
175
176 if(m_dump_gain.find("MEDIUM")!=std::string::npos)
178 else
180
181 if(m_dump_gain.find("LOW")!=std::string::npos)
183 else
185
186 return StatusCode::SUCCESS;
187
188}
189
190
191
192StatusCode LArDigitFillerTool::fill ( const LArDigit& digit)
193{
194 ATH_MSG_DEBUG( "in fill()" );
195
196 //if (m_NEvents!=-1 && ++m_count>m_NEvents ) return StatusCode::SUCCESS;
197
198 const LArFebHeaderContainer *larFebHeaderContainer=NULL;
199 if (m_savesca == true){
200 StatusCode sc = evtStore()->retrieve(larFebHeaderContainer);
201 if (sc.isFailure() || !larFebHeaderContainer) {
202 ATH_MSG_DEBUG( "Cannot read LArFebHeaderContainer from StoreGate! SCA address not saved." );
203 larFebHeaderContainer=NULL;
204 }
205 }
206
207 const LArOFIterResultsContainer *larOFIterCont=NULL;
208 if (m_dumpIter) {
209 StatusCode sc =evtStore()->retrieve(larOFIterCont);
210 if (sc.isFailure()) {
211 ATH_MSG_DEBUG( "Can't retrieve LArOFIterResultsContainer from StoreGate." );
212 larOFIterCont=NULL;
213 }
214 ATH_MSG_DEBUG( "Got LArOFIterResultsContainer from StoreGate." );
215 }
216
217
218 m_cellIndex=0;
219 //size_t digitContIdx=0;
220 size_t febHeaderContIdx=0;
221 size_t ofcIterContIdx=0;
222 size_t ofcIterContIdx_temp=0;
223
224 //There are various restrictions when to write channel to CBNT:
225
226 //Check gain
227 const long gain=digit.gain();
228
230 const LArOnOffIdMapping* cabling{*cablingHdl};
231 if(!cabling){
232 ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key() );
233 return StatusCode::FAILURE;
234 }
270 const std::vector<short>& vSamples=digit.samples();
271 const HWIdentifier chid=digit.hardwareID();
272 size_t n=vSamples.size();
273 int nsamples=vSamples.size();
274 const bool connected=cabling->isOnlineConnected(chid);
275 ATH_MSG_DEBUG( " is connected " <<connected );
276
277
278 if (m_savedigit){
279
280 (*m_samples).resize(n);
281 for (size_t i=0;i<n;++i) {
282 (*m_samples)[i] = vSamples[i] ; //Convert short -> long
283 }
284
285 //Add samples to ntuple
286 // *m_samples = vSamples;
287
288 //Add offline ID
289 if (connected) {
290 const Identifier id=cabling->cnvToIdentifier(chid);
291 if(m_storeId) *m_offId = id.get_identifier32().get_compact() ;
292 if (m_emId->is_lar_em(id)) {
293 *m_calo = 0;
294 *m_eta = m_emId->eta(id);
295 *m_phi = m_emId->phi(id);
296 *m_layer = m_emId->sampling(id);
297 }
298 else if (m_hecId->is_lar_hec(id)) {
299 *m_calo= 1;
300 *m_eta = m_hecId->eta(id);
301 *m_phi = m_hecId->phi(id);
302 *m_layer = m_hecId->sampling(id);
303 }
304 else if (m_fcalId->is_lar_fcal(id)) {
305 *m_calo = 2;
306 *m_eta = m_fcalId->eta(id);
307 *m_phi = m_fcalId->phi(id);
308 *m_layer = m_fcalId->module(id);
309 }
310 else {
311 ATH_MSG_WARNING( "LArDigit Id "<< MSG::hex << id.get_compact() << MSG::dec
312 << " (FT: " << m_onlineHelper->feedthrough(chid) << " FEBSlot: " << m_onlineHelper->slot(chid) << " Chan: " << m_onlineHelper->channel(chid)
313 << ") appears to be neither EM nor HEC nor FCAL." );
314 *m_calo = -998;
315 }
316 }
317 else {
318 if(m_storeId) *m_offId= 0;
319 *m_calo= -998;
320 *m_eta= -998;
321 *m_phi= -998;
322 *m_layer= -998;
323 } // end else disconnected
324
325 //Add online ID
326 *m_barrel_ec = m_onlineHelper->barrel_ec(chid);
327 *m_pos_neg = m_onlineHelper->pos_neg(chid);
328 *m_FT = m_onlineHelper->feedthrough(chid);
329 *m_slot= m_onlineHelper->slot(chid);
330 *m_channel = m_onlineHelper->channel(chid);
331 *m_gain = gain;
332 m_cellIndex++;
333 }
334
335 ATH_MSG_DEBUG( " m_savesca and FebHead, OFIterCont " << m_savesca <<" " << larFebHeaderContainer << " " <<larOFIterCont );
336
337 //Add SCA info if needed
338 if (m_savesca)
339 {
340 if (larFebHeaderContainer ){
341 const HWIdentifier chanFebId=m_onlineHelper->feb_Id(chid); //FebId of current channel
342 const size_t febHead_s=larFebHeaderContainer->size();
343
344 //Search for the right element in the FEB header container
345 for(;febHeaderContIdx<febHead_s && chanFebId!=larFebHeaderContainer->at(febHeaderContIdx)->FEBId();
346 ++febHeaderContIdx)
347 ;
348
349 if (febHeaderContIdx<febHead_s) {
350 const std::vector<unsigned short>& sca=larFebHeaderContainer->at(febHeaderContIdx)->SCA();
351 n=sca.size();
352 if ((long)n!=nsamples){
353 ATH_MSG_WARNING( "Inconsistent number of SCA entries" );
354 }
355
356 /* addSamples.resize(n);
357 for (size_t i=0;i<n;++i)
358 addSamples[i]=sca[i];//Convert short -> long
359 */
360
361 (*m_sca).resize(n);
362 for (size_t i=0;i<n;++i) {
363 (*m_sca)[i]=sca[i];
364 }
365
366 // *m_sca= sca;
367
368 }
369 else {
370 ATH_MSG_ERROR( "LArDigitContainer and LArFebHeaderContainer out of sync!" );
371 ATH_MSG_WARNING( "Can't find FEB with id = "<< std::hex << chanFebId.get_compact() << std::dec );
372 }
373 }
374 else
375 {
376 (*m_sca).clear();
377 }
378 }
379
380 // Add OFC Iter results if needed
381 ATH_MSG_DEBUG( " m_dumpIter, OFIterCont " << m_dumpIter<< " " << larOFIterCont );
382 if (m_dumpIter) {
383 if (larOFIterCont) {
384
385 const size_t iterRes_s=larOFIterCont->size();
386
387 ofcIterContIdx_temp = ofcIterContIdx;
388 //Search the right element of the results container
389 for(;ofcIterContIdx<iterRes_s && chid!=larOFIterCont->at(ofcIterContIdx).getChannelID();++ofcIterContIdx)
390 ;
391
392 // Check No Missing Iteration Result
393 if( ofcIterContIdx>=iterRes_s) {// && (ofcIterContIdx - ofcIterContIdx_temp)!=1){
394
395 ATH_MSG_DEBUG( "Could not get iteration results for channel with id " << chid.get_compact() << std::dec
396 <<" in LArOFIterResultsContainer. CellIndex="<< m_cellIndex );
397
398 ofcIterContIdx = ofcIterContIdx_temp;
399 *m_Itervalid= 0 ;
400 *m_Iterconverged= 0 ;
401 *m_IterNIter= -999 ;
402 *m_IterAmpl= -999 ;
403 *m_IterTau= -999 ;
404 *m_IterPeakSample= -999 ;
405 *m_IterDelay= -999 ;
406 *m_IterQual= -999 ;
407 *m_IterIdx= -999;
408 }
409 else{
410 const LArOFIterResults& iterRes=larOFIterCont->at(ofcIterContIdx);
411 //std::cout << chid << "\t" << iterRes.getChannelID() << std::endl;
412 if (chid!=iterRes.getChannelID()) {
413 ATH_MSG_ERROR( "Channel IDs don't match" );
414 return StatusCode::FAILURE;
415 }
416 *m_Itervalid= iterRes.getValid();
417 *m_Iterconverged= iterRes.getConverged();
418 *m_IterNIter= iterRes.getNIterPerf();
419 *m_IterAmpl= iterRes.getAmplitude();
420 *m_IterTau= iterRes.getTau();
422 *m_IterDelay= iterRes.getDelay_final();
423 *m_IterQual= iterRes.getQuality();
424 *m_IterIdx= iterRes.getOFCIndex();
425 }
426
427 }
428 else
429 {
430 *m_Itervalid= 0 ;
431 *m_Iterconverged= 0 ;
432 *m_IterNIter= -999 ;
433 *m_IterAmpl= -999 ;
434 *m_IterTau= -999 ;
435 *m_IterPeakSample= -999 ;
436 *m_IterDelay= -999 ;
437 *m_IterQual= -999 ;
438 *m_IterIdx= -999;
439 }
440 }
441
442 return StatusCode::SUCCESS ;
443
444}
445
446
447} // end of D3PD namespace
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
Block filler tool for CaloCell, implementing similar features of CBNTAA_CaloCell.
static Double_t sc
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
virtual StatusCode addVariable(const std::string &name, const std::type_info &ti, void *&ptr, const std::string &docstring="", const void *defval=0)
Type-safe wrapper for block filler tools.
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
std::vector< unsigned int > * m_sca
bool m_gains[CaloGain::LARNGAIN]
LArDigitFillerTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
const LArOnlineID * m_onlineHelper
virtual StatusCode fill(const LArDigit &p)
Fill one block — type-safe version.
virtual StatusCode book()
Book variables for this block.
std::vector< int > * m_samples
const LArFCAL_ID * m_fcalId
const T * at(size_type n) const
Access an element, as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
value_type get_compact() const
Get the compact id.
Liquid Argon digit base class.
Definition LArDigit.h:25
Container class for LArFebHeader.
const std::vector< uint16_t > & SCA() const
get the SCA's
int getNIterPerf() const
float getTau() const
bool getConverged() const
float getDelay_final() const
bool getValid() const
HWIdentifier getChannelID() const
float getAmplitude() const
unsigned getOFCIndex() const
unsigned getPeakSample_final() const
float getQuality() const
@ LARMEDIUMGAIN
Definition CaloGain.h:18
@ LARLOWGAIN
Definition CaloGain.h:18
@ LARNGAIN
Definition CaloGain.h:19
@ LARHIGHGAIN
Definition CaloGain.h:18
Block filler tool for noisy FEB information.