ATLAS Offline Software
Loading...
Searching...
No Matches
LArDSPThresholdFillInline.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
9#include "CaloDetDescr/CaloDetDescrElement.h"
11#include "GaudiKernel/ThreadLocalContext.h"
12
13#include <fstream>
14
16#include "CoralBase/Blob.h"
17#include "CoralBase/Attribute.h"
18#include "CoralBase/AttributeList.h"
19#include "CoralBase/AttributeListSpecification.h"
20
22//#include "CoolKernel/types.h"
23#include "CoolKernel/StorageType.h"
24
25LArDSPThresholdFillInline::LArDSPThresholdFillInline(const std::string& name, ISvcLocator* pSvcLocator) :
26 AthAlgorithm(name,pSvcLocator),
27 m_onlineID(0),
29{
30
31 declareProperty("Fill",m_fill=true);
32 declareProperty("NameOfSet",m_nameOfSet);
33 declareProperty("Key",m_key="DSPThresholds");
34 declareProperty("mode",m_mode="fixed",
35 "Select how to set thresholds. Allowed values are 'fixed','group' and 'noise'");
36
37 //For mode 'fixed'
38 declareProperty("tQThreshold",m_tqThrsh=250);
39 declareProperty("samplesThreshold",m_samplesThrsh=1000);
40
41 //For mode 'group'
42 declareProperty("ThresholdsPerCellGroup",m_cellGroupStr);
43
44 //For mode 'Noise'
45 declareProperty("sigmaNoiseSamples",m_sigmaNoiseSamples);
46 declareProperty("sigmaNoiseQt",m_sigmaNoiseQt);
47 declareProperty("usePileupNoiseSamples",m_usePileupNoiseSamples);
48 declareProperty("usePileupNoiseQt",m_usePileupNoiseQt);
49
50 //For channel masking
51 declareProperty("MaskBadChannels",m_maskBadChannels=false);
52 declareProperty("MaskedtQThreshold",m_maskedtqThrsh=static_cast<float>(0x7fffffff));
53 declareProperty("MaskedsamplesThreshold",m_maskedsamplesThrsh=static_cast<float>(0x7fffffff));
54
55 declareProperty("Dump",m_dump=false);
56 declareProperty("OutFile",m_outFileName="out.txt");
57 //declareProperty("InFile",m_inFileName="");
58}
59
61
62
64
65 ATH_MSG_DEBUG ( "start initialize()" );
66
67 ATH_CHECK( detStore()->retrieve(m_onlineID,"LArOnlineID") );
68 ATH_CHECK( m_cablingKey.initialize() );
69 ATH_CHECK( m_caloMgrKey.initialize() );
70
72 ATH_CHECK(m_bcMask.buildBitMask(m_problemsToMask,msg()));
73
74
75 if (m_mode.compare("fixed")==0) {
77 ATH_MSG_INFO ( "Will used fixed values defined by jobO "
78 << name() <<".tQThreshold and "
79 << name() << ".samplesThreshold for DSP thresholds" );
80 }
81 else if (m_mode.compare("group")==0) {
83 ATH_MSG_INFO ( "Will used cell groups defined in jobO " << name() << ".CellGroup for DSP thresholds" );
84 const CaloCell_ID* caloCellID = nullptr;
85 ATH_CHECK( detStore()->retrieve(caloCellID,"CaloCell_ID") );
86
87 if (m_thrPerCell.setDefinition(dynamic_cast<const CaloCell_Base_ID*>(caloCellID),m_cellGroupStr,msg())==false)
88 return StatusCode::FAILURE;
89 m_thrPerCell.printDef();
90
91 if (m_thrPerCell.getDefaults().size()!=2) {
92 ATH_MSG_ERROR ( "Expected 2 values per cell group, got " << m_thrPerCell.getDefaults().size() );
93 return StatusCode::FAILURE;
94 }
95 }
96 else if (m_mode.compare("noise")==0) {
98
100 ATH_MSG_INFO ( "Will used ICaloCellTool::totalNoiseRMS times " << name() << ".sigmaNoiseSamples and" );
101 else
102 ATH_MSG_INFO ( "Will used ICaloCellTool::elecNoiseRMS times " << name() << ".sigmaNoiseSamples and" );
103
105 ATH_MSG_INFO ( "ICaloCellTool::totalNoiseRMS times " << name() << ".sigmaNoiseQt for DSP thresholds" );
106 else
107 ATH_MSG_INFO ( "ICaloCellTool::elecNoiseRMS times " << name() << ".sigmaNoiseQt for DSP thresholds" );
108
109 }
110
111 ATH_CHECK( m_totalNoiseKey.initialize (m_workmode == NOISE) );
112 ATH_CHECK( m_elecNoiseKey.initialize (m_workmode == NOISE) );
113
114 return StatusCode::SUCCESS;
115}
116
118
119 ATH_MSG_DEBUG ( "start stop()" );
120
121 const EventContext& ctx = Gaudi::Hive::currentContext();
122
123 if (m_fill) {
124
125 ATH_MSG_INFO ( "Filling database" );
126
127 unsigned hashMax=m_onlineID->channelHashMax();
128
129 coral::AttributeListSpecification* spec = new coral::AttributeListSpecification();
130 //cool::RecordSpecification* spec = new cool::RecordSpecification();
131 spec->extend("tQThr", "blob");
132 spec->extend("samplesThr", "blob");
133 spec->extend("trigSumThr", "blob");
134 spec->extend("Name","string");
135
137
138
139 (*attr)["Name"].setValue(m_nameOfSet);
140 coral::Blob& tQThrBlob = (*attr)["tQThr"].data<coral::Blob>();
141 coral::Blob& samplesThrBlob = (*attr)["samplesThr"].data<coral::Blob>();
142 coral::Blob& trigSumThrBlob = (*attr)["trigSumThr"].data<coral::Blob>();
143
144 tQThrBlob.resize(hashMax*sizeof(float));
145 samplesThrBlob.resize(hashMax*sizeof(float));
146 trigSumThrBlob.resize(hashMax*sizeof(float));
147
148 float* ptQThrBlob=static_cast<float*>(tQThrBlob.startingAddress());
149 float* psamplesBlob=static_cast<float*>(samplesThrBlob.startingAddress());
150 float* ptrigSumBlob=static_cast<float*>(trigSumThrBlob.startingAddress());
151
152 ATH_CHECK( detStore()->record(attr,m_key) );
153
155 ATH_CHECK(caloMgrHandle.isValid());
156 const CaloDetDescrManager *theCaloDDM = *caloMgrHandle;
157 ATH_MSG_INFO ( "theCaloDDM retrieved" );
158
160 const LArOnOffIdMapping* cabling{*cablingHdl};
161 if(!cabling) {
162 ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key());
163 return StatusCode::FAILURE;
164 }
165
166 const CaloNoise* totalNoise = nullptr;
167 const CaloNoise* elecNoise = nullptr;
168 if (m_workmode == NOISE) {
170 totalNoise = totalNoiseH.cptr();
172 elecNoise = elecNoiseH.cptr();
173 }
174
175 //retrieve BadChannel info:
176 const LArBadChannelCont* bcCont=nullptr;
177 if (m_maskBadChannels) {
179 bcCont=(*bcContHdl);
180 }
181
182
183 for (unsigned hs=0;hs<hashMax;++hs) {
184 const HWIdentifier chid=m_onlineID->channel_Id(hs);
185 const Identifier id=cabling->cnvToIdentifier(chid);
186 ATH_MSG_DEBUG ( "cell id: " << id << " " << cabling->isOnlineConnected(chid) );
187
188 if(!cabling->isOnlineConnected(chid)){
189 ATH_MSG_DEBUG ( "cell id: " << id << " not connected channel, skip " );
190 // Same (very high) thresholds for disconnected channels as masked channels
191 ptQThrBlob[hs]=m_maskedtqThrsh;
192 psamplesBlob[hs]=m_maskedsamplesThrsh;
193 ptrigSumBlob[hs]=m_maskedtqThrsh;
194 continue;
195 }
196
197 if(m_maskBadChannels && m_bcMask.cellShouldBeMasked(bcCont,chid)){ // Default gain is CaloGain::UNKNOWNGAIN
198 ATH_MSG_DEBUG ( "cell id: " << id << " is masked; set thresholds to " << m_maskedtqThrsh << ", " << m_maskedsamplesThrsh );
199 ptQThrBlob[hs]=m_maskedtqThrsh;
200 psamplesBlob[hs]=m_maskedsamplesThrsh;
201 ptrigSumBlob[hs]=m_maskedtqThrsh;
202 continue;
203 }
204
205 if (m_workmode==FIXED) {
206 //cont->set(chid,m_tqThrsh,m_samplesThrsh,m_tqThrsh);
207 ptQThrBlob[hs]=m_tqThrsh;
208 psamplesBlob[hs]=m_samplesThrsh;
209 ptrigSumBlob[hs]=m_tqThrsh;
210 }
211 else if (m_workmode==GROUP) {
212 const std::vector<float>& thrs=m_thrPerCell.valuesForCell(id);
213 if(thrs.size()!=2) std::cout << "len=" << thrs.size() << std::endl;
214 ptQThrBlob[hs]=thrs[0];
215 psamplesBlob[hs]=thrs[1];
216 ptrigSumBlob[hs]=thrs[0];
217 }
218 else if (m_workmode==NOISE) {
219 const CaloDetDescrElement *caloDDE = theCaloDDM->get_element(id);
220 if(!caloDDE){
221 ATH_MSG_ERROR ( "Failed to return CaloDetDescrElement" );
222 return StatusCode::FAILURE;
223 }
224 /*
225 if(caloDDE->is_lar_em_barrel())
226 log << MSG::DEBUG << "EM barrel" << endmsg;
227
228 if(caloDDE->is_lar_em_endcap())
229 log << MSG::DEBUG << "EM endcap" << endmsg;
230
231 if(caloDDE->is_lar_hec())
232 log << MSG::DEBUG << "HEC" << endmsg;
233
234 if(caloDDE->is_lar_fcal())
235 log << MSG::DEBUG << "FCAL" << endmsg;
236 */
238
239 if(caloDDE->is_lar_fcal())
241 else
242 igain = CaloGain::LARHIGHGAIN;
243
244 ATH_MSG_DEBUG ( "hash, eta, phi: " << caloDDE->calo_hash() << ", " << caloDDE->eta() << ", " << caloDDE->phi() << "; noise: " << totalNoise->getNoise(id,igain) );
245
246 float samplesThr = 0.;
247 float QtThr = 0.;
248
250 samplesThr = totalNoise->getNoise(id,igain);
251 else
252 samplesThr = elecNoise->getNoise(id,igain);
253
255 QtThr = totalNoise->getNoise(id,igain);
256 else
257 QtThr = elecNoise->getNoise(id,igain);
258
259 //cont->set(chid,QtThr*m_sigmaNoiseQt,samplesThr*m_sigmaNoiseSamples,QtThr*m_sigmaNoiseQt);
260 ptQThrBlob[hs]=QtThr*m_sigmaNoiseQt;
261 psamplesBlob[hs]=samplesThr*m_sigmaNoiseSamples;
262 ptrigSumBlob[hs]=QtThr*m_sigmaNoiseQt;
263
264 }// end if NOISE
265
266 if( m_scaleIW > 0.) {
267 int slot = m_onlineID->slot(chid);
268 if (m_onlineID->isEMECIW(chid) || m_onlineID->isFCALchannel(chid) ||
269 (m_onlineID->isHECchannel(chid) && (slot==9 || slot==10) ) ||
270 (m_onlineID->isEMECchannel(chid) && (slot==6||slot==7||slot==14||slot==15))
271 ) {
272 ptQThrBlob[hs] *= m_scaleIW;
273 psamplesBlob[hs] *= m_scaleIW;
274 ptrigSumBlob[hs] *= m_scaleIW;
275 } else if ( (m_onlineID->isHECchannel(chid) && (slot==7 || slot==8) ) ||
276 (m_onlineID->isEMECchannel(chid) && (slot==12||slot==13)) ) {
277 ptQThrBlob[hs] *= m_scaleIW/2.;
278 psamplesBlob[hs] *= m_scaleIW/2.;
279 ptrigSumBlob[hs] *= m_scaleIW/2.;
280 }
281 } // scaling IW
282
283 }//end loop over cells
284 }//end if FILL
285
286 if (m_dump) {
287
288 const AthenaAttributeList* attr=0;
289
290 ATH_CHECK( detStore()->retrieve(attr,m_key) );
291
292 LArDSPThresholdsFlat cont(attr);
293
294
295 std::ofstream outfile;
296 if (!m_outFileName.size()) {
297 ATH_MSG_ERROR("No output file specified");
298 return StatusCode::FAILURE;
299 }
300 outfile.open(m_outFileName.c_str(),std::ios::out);
301 if (outfile.is_open()) {
302 ATH_MSG_INFO ( "Writing to file " << m_outFileName );
303 }
304 else {
305 ATH_MSG_ERROR ( "Failed to open file " << m_outFileName );
306 return StatusCode::FAILURE;
307 }
308
309 std::vector<HWIdentifier>::const_iterator chanIt=m_onlineID->channel_begin();
310 std::vector<HWIdentifier>::const_iterator chanIt_e=m_onlineID->channel_end ();
311 for (;chanIt!=chanIt_e;++chanIt) {
312 const HWIdentifier chid=*chanIt;
313 outfile << std::fixed << chid.get_compact() << " " << cont.tQThr(chid) << " " << cont.samplesThr(chid) << " " << cont.trigSumThr(chid)
314 << std::endl;
315
316 } //end if loop over channels
317
318 outfile.close();
319 }// end if m_dump
320
321 return StatusCode::SUCCESS;
322}
#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)
LArBadXCont< LArBadChannel > LArBadChannelCont
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
MsgStream & msg() const
An AttributeList represents a logical row of attributes in a metadata table.
Helper base class for offline cell identifiers.
Helper class for offline cell identifiers.
Definition CaloCell_ID.h:34
This class groups all DetDescr information related to a CaloCell.
bool is_lar_fcal() const
cell belongs to FCAL
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
This class provides the client interface for accessing the detector description information common to...
float getNoise(const IdentifierHash h, const int gain) const
Accessor by IdentifierHash and gain.
Definition CaloNoise.h:34
value_type get_compact() const
Get the compact id.
Gaudi::Property< float > m_scaleIW
SG::ReadCondHandleKey< CaloNoise > m_totalNoiseKey
SG::ReadCondHandleKey< CaloNoise > m_elecNoiseKey
LArBadChannelMask m_bcMask
Handle to bad-channel mask.
std::vector< std::string > m_cellGroupStr
Gaudi::Property< std::vector< std::string > > m_problemsToMask
SG::ReadCondHandleKey< LArBadChannelCont > m_bcContKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
virtual StatusCode stop() override
LArDSPThresholdFillInline(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
float trigSumThr(const HWIdentifier &CellID) const
float samplesThr(const HWIdentifier &CellID) const
float tQThr(const HWIdentifier &CellID) const
const_pointer_type cptr()
@ LARMEDIUMGAIN
Definition CaloGain.h:18
@ INVALIDGAIN
Definition CaloGain.h:18
@ LARHIGHGAIN
Definition CaloGain.h:18