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/StorageType.h"
23
25
26
28
29 ATH_MSG_DEBUG ( "start initialize()" );
30
31 ATH_CHECK( detStore()->retrieve(m_onlineID,"LArOnlineID") );
32 ATH_CHECK( m_cablingKey.initialize() );
33 ATH_CHECK( m_caloMgrKey.initialize() );
34
36 ATH_CHECK(m_bcMask.buildBitMask(m_problemsToMask,msg()));
37
38
39 if (m_mode == "fixed") {
41 ATH_MSG_INFO ( "Will used fixed values defined by jobO "
42 << name() <<".tQThreshold and "
43 << name() << ".samplesThreshold for DSP thresholds" );
44 }
45 else if (m_mode == "group") {
47 ATH_MSG_INFO ( "Will used cell groups defined in jobO " << name() << ".CellGroup for DSP thresholds" );
48 const CaloCell_ID* caloCellID = nullptr;
49 ATH_CHECK( detStore()->retrieve(caloCellID,"CaloCell_ID") );
50
51 if (m_thrPerCell.setDefinition(dynamic_cast<const CaloCell_Base_ID*>(caloCellID),m_cellGroupStr,msg())==false)
52 return StatusCode::FAILURE;
53 m_thrPerCell.printDef();
54
55 if (m_thrPerCell.getDefaults().size()!=2) {
56 ATH_MSG_ERROR ( "Expected 2 values per cell group, got " << m_thrPerCell.getDefaults().size() );
57 return StatusCode::FAILURE;
58 }
59 }
60 else if (m_mode == "noise") {
62
64 ATH_MSG_INFO ( "Will used ICaloCellTool::totalNoiseRMS times " << name() << ".sigmaNoiseSamples and" );
65 else
66 ATH_MSG_INFO ( "Will used ICaloCellTool::elecNoiseRMS times " << name() << ".sigmaNoiseSamples and" );
67
69 ATH_MSG_INFO ( "ICaloCellTool::totalNoiseRMS times " << name() << ".sigmaNoiseQt for DSP thresholds" );
70 else
71 ATH_MSG_INFO ( "ICaloCellTool::elecNoiseRMS times " << name() << ".sigmaNoiseQt for DSP thresholds" );
72
73 }
74
75 ATH_CHECK( m_totalNoiseKey.initialize (m_workmode == NOISE) );
76 ATH_CHECK( m_elecNoiseKey.initialize (m_workmode == NOISE) );
77
78 return StatusCode::SUCCESS;
79}
80
82
83 ATH_MSG_DEBUG ( "start stop()" );
84 if( m_scaleIW > 0.) { ATH_MSG_INFO (" Scaling EMECIW by: "<<m_scaleIW);}
85
86 const EventContext& ctx = Gaudi::Hive::currentContext();
87
88 if (m_fill) {
89
90 ATH_MSG_INFO ( "Filling database" );
91
92 unsigned hashMax=m_onlineID->channelHashMax();
93
94 coral::AttributeListSpecification* spec = new coral::AttributeListSpecification();
95 spec->extend("tQThr", "blob");
96 spec->extend("samplesThr", "blob");
97 spec->extend("trigSumThr", "blob");
98 spec->extend("Name","string");
99
101
102
103 (*attr)["Name"].setValue(m_nameOfSet);
104 coral::Blob& tQThrBlob = (*attr)["tQThr"].data<coral::Blob>();
105 coral::Blob& samplesThrBlob = (*attr)["samplesThr"].data<coral::Blob>();
106 coral::Blob& trigSumThrBlob = (*attr)["trigSumThr"].data<coral::Blob>();
107
108 tQThrBlob.resize(hashMax*sizeof(float));
109 samplesThrBlob.resize(hashMax*sizeof(float));
110 trigSumThrBlob.resize(hashMax*sizeof(float));
111
112 float* ptQThrBlob=static_cast<float*>(tQThrBlob.startingAddress());
113 float* psamplesBlob=static_cast<float*>(samplesThrBlob.startingAddress());
114 float* ptrigSumBlob=static_cast<float*>(trigSumThrBlob.startingAddress());
115
116 ATH_CHECK( detStore()->record(attr,m_key) );
117
119 ATH_CHECK(caloMgrHandle.isValid());
120 const CaloDetDescrManager *theCaloDDM = *caloMgrHandle;
121 ATH_MSG_INFO ( "theCaloDDM retrieved" );
122
124 const LArOnOffIdMapping* cabling{*cablingHdl};
125 if(!cabling) {
126 ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key());
127 return StatusCode::FAILURE;
128 }
129
130 const CaloNoise* totalNoise = nullptr;
131 const CaloNoise* elecNoise = nullptr;
132 if (m_workmode == NOISE) {
134 totalNoise = totalNoiseH.cptr();
136 elecNoise = elecNoiseH.cptr();
137 }
138
139 //retrieve BadChannel info:
140 const LArBadChannelCont* bcCont=nullptr;
141 if (m_maskBadChannels) {
143 bcCont=(*bcContHdl);
144 }
145
146
147 for (unsigned hs=0;hs<hashMax;++hs) {
148 const HWIdentifier chid=m_onlineID->channel_Id(hs);
149 const Identifier id=cabling->cnvToIdentifier(chid);
150 ATH_MSG_DEBUG ( "cell id: " << id << " " << cabling->isOnlineConnected(chid) );
151
152 if(!cabling->isOnlineConnected(chid)){
153 ATH_MSG_DEBUG ( "cell id: " << id << " not connected channel, skip " );
154 // Same (very high) thresholds for disconnected channels as masked channels
155 ptQThrBlob[hs]=m_maskedtqThrsh;
156 psamplesBlob[hs]=m_maskedsamplesThrsh;
157 ptrigSumBlob[hs]=m_maskedtqThrsh;
158 continue;
159 }
160
161 if(m_maskBadChannels && m_bcMask.cellShouldBeMasked(bcCont,chid)){ // Default gain is CaloGain::UNKNOWNGAIN
162 ATH_MSG_DEBUG ( "cell id: " << id << " is masked; set thresholds to " << m_maskedtqThrsh << ", " << m_maskedsamplesThrsh );
163 ptQThrBlob[hs]=m_maskedtqThrsh;
164 psamplesBlob[hs]=m_maskedsamplesThrsh;
165 ptrigSumBlob[hs]=m_maskedtqThrsh;
166 continue;
167 }
168
169 if (m_workmode==FIXED) {
170 ptQThrBlob[hs]=m_tqThrsh;
171 psamplesBlob[hs]=m_samplesThrsh;
172 ptrigSumBlob[hs]=m_tqThrsh;
173 }
174 else if (m_workmode==GROUP) {
175 const std::vector<float>& thrs=m_thrPerCell.valuesForCell(id);
176 if(thrs.size()!=2) std::cout << "len=" << thrs.size() << std::endl;
177 ptQThrBlob[hs]=thrs[0];
178 psamplesBlob[hs]=thrs[1];
179 ptrigSumBlob[hs]=thrs[0];
180 }
181 else if (m_workmode==NOISE) {
182 const CaloDetDescrElement *caloDDE = theCaloDDM->get_element(id);
183 if(!caloDDE){
184 ATH_MSG_ERROR ( "Failed to return CaloDetDescrElement" );
185 return StatusCode::FAILURE;
186 }
188
189 if(caloDDE->is_lar_fcal())
191 else
192 igain = CaloGain::LARHIGHGAIN;
193
194 ATH_MSG_DEBUG ( "hash, eta, phi: " << caloDDE->calo_hash() << ", " << caloDDE->eta() << ", " << caloDDE->phi() << "; noise: " << totalNoise->getNoise(id,igain) );
195
196 float samplesThr = 0.;
197 float QtThr = 0.;
198
200 samplesThr = totalNoise->getNoise(id,igain);
201 else
202 samplesThr = elecNoise->getNoise(id,igain);
203
205 QtThr = totalNoise->getNoise(id,igain);
206 else
207 QtThr = elecNoise->getNoise(id,igain);
208
209 ptQThrBlob[hs]=QtThr*m_sigmaNoiseQt;
210 psamplesBlob[hs]=samplesThr*m_sigmaNoiseSamples;
211 ptrigSumBlob[hs]=QtThr*m_sigmaNoiseQt;
212
213 }// end if NOISE
214
215 if( m_scaleIW > 0.) {
216 int slot = m_onlineID->slot(chid);
217 if (m_onlineID->isEMECIW(chid) ) {
218 ptQThrBlob[hs] *= m_scaleIW;
219 psamplesBlob[hs] *= m_scaleIW;
220 ptrigSumBlob[hs] *= m_scaleIW;
221 } else if ( (m_onlineID->isHECchannel(chid) && (slot==7 || slot==8) ) ||
222 (m_onlineID->isEMECchannel(chid) && (slot==12||slot==13)) ) {
223 ptQThrBlob[hs] *= m_scaleIW/2.;
224 psamplesBlob[hs] *= m_scaleIW/2.;
225 ptrigSumBlob[hs] *= m_scaleIW/2.;
226 }
227 } // scaling IW
228
229 }//end loop over cells
230 }//end if FILL
231
232 if (m_dump) {
233
234 const AthenaAttributeList* attr=0;
235
236 ATH_CHECK( detStore()->retrieve(attr,m_key) );
237
238 LArDSPThresholdsFlat cont(attr);
239 if (!cont.good()){
240 ATH_MSG_ERROR("LArDSPThresholdsFlat did not initialise.");
241 return StatusCode::FAILURE;
242 }
243 std::ofstream outfile;
244 if (!m_outFileName.size()) {
245 ATH_MSG_ERROR("No output file specified");
246 return StatusCode::FAILURE;
247 }
248 outfile.open(m_outFileName,std::ios::out);
249 if (outfile.is_open()) {
250 ATH_MSG_INFO ( "Writing to file " << m_outFileName );
251 }
252 else {
253 ATH_MSG_ERROR ( "Failed to open file " << m_outFileName );
254 return StatusCode::FAILURE;
255 }
256
257 std::vector<HWIdentifier>::const_iterator chanIt=m_onlineID->channel_begin();
258 std::vector<HWIdentifier>::const_iterator chanIt_e=m_onlineID->channel_end ();
259 for (;chanIt!=chanIt_e;++chanIt) {
260 const HWIdentifier chid=*chanIt;
261 outfile << std::fixed << chid.get_compact() << " " << cont.tQThr(chid) << " " << cont.samplesThr(chid) << " " << cont.trigSumThr(chid)
262 << std::endl;
263
264 } //end if loop over channels
265
266 outfile.close();
267 }// end if m_dump
268
269 return StatusCode::SUCCESS;
270}
#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
const ServiceHandle< StoreGateSvc > & detStore() 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:35
value_type get_compact() const
Get the compact id.
Gaudi::Property< float > m_scaleIW
virtual ~LArDSPThresholdFillInline()
SG::ReadCondHandleKey< CaloNoise > m_totalNoiseKey
SG::ReadCondHandleKey< CaloNoise > m_elecNoiseKey
LArBadChannelMask m_bcMask
Handle to bad-channel mask.
Gaudi::Property< std::vector< std::string > > m_problemsToMask
SG::ReadCondHandleKey< LArBadChannelCont > m_bcContKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
virtual StatusCode stop() override
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