ATLAS Offline Software
Loading...
Searching...
No Matches
LArHECNoise.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "GaudiKernel/MsgStream.h"
6#include "GaudiKernel/IToolSvc.h"
7
9
17
19
20#include "Identifier/Range.h"
23
25
30
33
37
38#include "TTree.h"
39
41
43
45
46#include <algorithm>
47#include <math.h>
48#include <functional>
49#include <iostream>
50
51using namespace std;
52using xAOD::EventInfo;
53
56
57LArHECNoise::LArHECNoise(const std::string& name,
58 ISvcLocator* pSvcLocator)
59 : AthAlgorithm(name, pSvcLocator),
60 m_tree(nullptr),
61 m_LArOnlineIDHelper(nullptr),
62 m_calocell_id(nullptr),
63 m_nt_run(0),
64 m_nt_evtId(0),
66 m_nt_evtTime(0),
68 m_nt_lb(0),
69 m_nt_bcid(0),
70 m_nt_gain(0),
71 m_nt_side(0),
72 m_nt_samp(0),
73 m_nt_reg(0),
74 m_nt_ieta(0),
75 m_nt_iphi(0),
76 m_nt_quality(0),
77 m_nt_digi(),
78 m_nt_max(0),
79 m_nt_min(0),
80 m_nt_OID(0),
81 m_nt_avgMu(0),
82 m_nt_actMu(0),
83 m_nt_e(0),
84 m_nt_t(0),
85 m_nt_eta(0),
86 m_nt_phi(0),
87 m_nt_z(0),
88 m_nt_r(0),
89 m_nt_ped(0),
91 {
92
93 // Trigger
94
96
97 declareProperty("TriggerLines",m_TriggerLines={"L1_J5", "L1_J10", "L1_J12", "L1_J30", "L1_TAU5", "L1_TAU8", "L1_J5_EMPTY", "L1_J10_EMPTY", "L1_J12_EMPTY", "L1_J30_EMPTY", "L1_TAU5_EMPTY", "L1_TAU8_EMPTY", "L1_J5_FIRSTEMPTY", "L1_J10_FIRSTEMPTY", "L1_J12_FIRSTEMPTY", "L1_J30_FIRSTEMPTY", "L1_TAU5_FIRSTEMPTY", "L1_TAU8_FIRSTEMPTY"});
98
99 declareProperty("MinDigitADC",m_MinDigitADC=20);
100 declareProperty("MaxDeltaT",m_MaxDeltaT=5);
101
102 m_nt_prescale = new float[m_TriggerLines.size()];
103 m_nt_trigger = new bool[m_TriggerLines.size()];
104 }
105
106// An out-of-line dtor keeps cppcheck from warning about the memory
107// allocations in the ctor.
111
113
114 ATH_MSG_DEBUG ( "Initializing LArHECNoise" );
115
116 // Trigger Decision Tool
117 CHECK(m_trigDec.retrieve());
118
119 ATH_CHECK( m_cablingKey.initialize() );
120 ATH_CHECK( m_pedKey.initialize() );
121
122 // Retrieve online ID helper
123 const LArOnlineID* LArOnlineIDHelper = nullptr;
124 ATH_CHECK( detStore()->retrieve(LArOnlineIDHelper, "LArOnlineID") );
125 m_LArOnlineIDHelper = LArOnlineIDHelper;
126 ATH_MSG_DEBUG( " Found LArOnline Helper");
127
128 // Retrieve ID helpers
129 ATH_CHECK( detStore()->retrieve (m_calocell_id, "CaloCell_ID") );
130 ATH_CHECK(m_caloMgrKey.initialize());
131
133 ATH_CHECK( m_thistSvc.retrieve() );
134
136 m_tree = new TTree( "HECNoise", "HECNoise" );
137
138 // General properties of events
139 m_tree->Branch("iRun",&m_nt_run,"iRun/I");// Event ID
140 m_tree->Branch("iEvent",&m_nt_evtId,"iEvent/I");// Event ID
141 m_tree->Branch("iEventCount",&m_nt_evtCount,"iEventCount/I");
142 m_tree->Branch("iTime",&m_nt_evtTime,"iTime/I");// Event time
143 m_tree->Branch("iTime_ns",&m_nt_evtTime_ns,"iTime_ns/I");// Event time in nanosecond
144 m_tree->Branch("iLB",&m_nt_lb,"iLB/I"); // LB
145 m_tree->Branch("iBCID",&m_nt_bcid,"iBCID/I"); // BCID
146 // prescale and trigger here
147 //const std::vector<float> &tp = m_nt_prescale;
148 //const std::vector<bool> &tt = m_nt_trigger;
149 for(unsigned i=0; i<m_TriggerLines.size(); ++i) {
150 //m_tree->Branch((m_TriggerLines[i]+"_Prescale").c_str(),&(tp[i]),(m_TriggerLines[i]+"_Prescale/F").c_str());
151 //m_tree->Branch((m_TriggerLines[i]+"_Trigger").c_str(),tt[i],(m_TriggerLines[i]+"_Trigger/O").c_str());
152 m_tree->Branch((m_TriggerLines[i]+"_Prescale").c_str(),&(m_nt_prescale[i]),(m_TriggerLines[i]+"_Prescale/F").c_str());
153 m_tree->Branch((m_TriggerLines[i]+"_Trigger").c_str(),&(m_nt_trigger[i]),(m_TriggerLines[i]+"_Trigger/I").c_str());
154 }
155 m_tree->Branch("avgMu",&m_nt_avgMu,"avgMu/F");
156 m_tree->Branch("actMu",&m_nt_actMu,"actMu/F");
157 m_tree->Branch("iGain",&m_nt_gain,"iGain/I");
158 m_tree->Branch("iOID",&m_nt_OID,"iOID/L");
159 m_tree->Branch("iSide",&m_nt_side,"iSide/I");
160 m_tree->Branch("iSamp",&m_nt_samp,"iSamp/I");
161 m_tree->Branch("iReg",&m_nt_reg,"iReg/I");
162 m_tree->Branch("iEta",&m_nt_ieta,"iEta/I");
163 m_tree->Branch("iPhi",&m_nt_iphi,"iPhi/I");
164 m_tree->Branch("iQuality",&m_nt_quality,"iQuality/I");
165 m_tree->Branch("e",&m_nt_e,"e/F");
166 m_tree->Branch("t",&m_nt_t,"t/F");
167 m_tree->Branch("eta",&m_nt_eta,"eta/F");
168 m_tree->Branch("phi",&m_nt_phi,"phi/F");
169 m_tree->Branch("z",&m_nt_z,"z/F");
170 m_tree->Branch("r",&m_nt_r,"r/F");
171 m_tree->Branch("Ped",&m_nt_ped,"Ped/F");
172 m_tree->Branch("PedRMS",&m_nt_pedRMS,"PedRMS/F");
173 m_tree->Branch("iDigi",m_nt_digi,"iDigi[32]/S");
174 m_tree->Branch("iMax",&m_nt_max,"iMax/I");
175 m_tree->Branch("iMin",&m_nt_min,"iMin/I");
176
177 std::string treeName = "/HEC/HECNoise" ;
178 ATH_CHECK( m_thistSvc->regTree(treeName, m_tree) );
179
180
181 ATH_MSG_DEBUG ( "End of Initializing LArHECNoise" );
182
183 return StatusCode::SUCCESS;
184}
185
187 ATH_MSG_DEBUG ( "in finalize()" );
188 return StatusCode::SUCCESS;
189}
190
191
193
194 ATH_MSG_DEBUG ( "in execute()" );
195
196 for(unsigned i=0; i<m_TriggerLines.size(); ++i){
197 m_nt_prescale[i] = m_trigDec->getPrescale(m_TriggerLines[i]);
198 if (m_trigDec->isPassed(m_TriggerLines[i])){
199 m_nt_trigger[i] = true;
200 } else {
201 m_nt_trigger[i] = false;
202 }
203 }
204
205 const xAOD::EventInfo* eventInfo = nullptr;
206 ATH_CHECK( evtStore()->retrieve(eventInfo) );
207
208 m_nt_evtCount = 0;
209 const CaloCellContainer* cc = nullptr;
210 const LArRawChannelContainer* lraw = nullptr;
211 if (evtStore()->contains<CaloCellContainer>("AllCalo")) {
212 ATH_CHECK(evtStore()->retrieve(cc, "AllCalo"));
213 } else if (evtStore()->contains<LArRawChannelContainer>("LArRawChannels")){
214 ATH_CHECK(evtStore()->retrieve(lraw, "LArRawChannels"));
215 }
216
218 const LArOnOffIdMapping* cabling{*cablingHdl};
219 if(!cabling) {
220 ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key() );
221 return StatusCode::FAILURE;
222 }
223
224
226 const ILArPedestal* ped{*pedHdl};
227 if(!ped) {
228 ATH_MSG_ERROR("Do not have pedestal object " << m_pedKey.key() );
229 return StatusCode::FAILURE;
230 }
231
233 ATH_CHECK(caloMgrHandle.isValid());
234 const CaloDetDescrManager* caloMgr = *caloMgrHandle;
235
236
237 const LArDigitContainer* ld = nullptr;
238 if (evtStore()->contains<LArDigitContainer>("LArDigitContainer")) {
239 ATH_CHECK(evtStore()->retrieve(ld, "LArDigitContainer"));
240 } else if (evtStore()->contains<LArDigitContainer>("LArDigitContainer_Thinned")) {
241 ATH_CHECK(evtStore()->retrieve(ld, "LArDigitContainer_Thinned"));
242 } else if (evtStore()->contains<LArDigitContainer>("FREE")) {
243 ATH_CHECK(evtStore()->retrieve(ld, "FREE"));
244 } else {
245 msg(MSG::WARNING) << "Neither LArDigitContainer nor LArDigitContainer_Thinned nor FREE present, not filling anything "<<endmsg;
246 return StatusCode::SUCCESS;
247 }
249 LArDigitContainer::const_iterator itDig = ld->begin();
250 LArDigitContainer::const_iterator itDig_e= ld->end();
251 const LArDigit* pLArDigit;
252
253 for ( ; itDig!=itDig_e;++itDig) {
254 pLArDigit = *itDig;
255 HWIdentifier hid = pLArDigit->hardwareID();
256 if(! m_LArOnlineIDHelper->isHECchannel(hid)) continue; //and ld.gain() == 2:
257 int sigmax=0;
258 int sigmin=0;
259 int imax=0;
260 int imin=0;
261 short samp0= pLArDigit->samples()[0];
262 for(unsigned i=0; i<(pLArDigit->samples()).size(); ++i){
263 short samp=pLArDigit->samples()[i];
264 if( i < 32) m_nt_digi[i] = samp;
265 if(samp-samp0 > sigmax) {
266 sigmax = samp-samp0;
267 imax=i;
268 }
269 if( samp-samp0 < sigmin) {
270 sigmin = samp-samp0;
271 imin=i;
272 }
273 }
274 if( sigmax > m_MinDigitADC && sigmin < -m_MinDigitADC && ( (imin-imax) < m_MaxDeltaT || imin < imax)) {
275 m_nt_run = eventInfo->runNumber();
276 m_nt_evtId = eventInfo->eventNumber();
277 m_nt_evtTime = eventInfo->timeStamp();
278 m_nt_evtTime_ns = eventInfo->timeStampNSOffset();
279 m_nt_lb = eventInfo->lumiBlock();
280 m_nt_bcid = eventInfo->bcid();
283
284 m_nt_evtCount += 1;
285 m_nt_gain = pLArDigit->gain();
286 Identifier oid = cabling->cnvToIdentifier(hid);
287 m_nt_OID = pLArDigit->channelID().get_compact();
288 m_nt_ped = ped->pedestal(pLArDigit->channelID(),pLArDigit->gain());
289 m_nt_pedRMS = ped->pedestalRMS(pLArDigit->channelID(),pLArDigit->gain());
290 m_nt_side = m_calocell_id->pos_neg(oid);
291 m_nt_samp = m_calocell_id->sampling(oid);
292 m_nt_reg = m_calocell_id->region(oid);
293 m_nt_ieta = m_calocell_id->eta(oid);
294 m_nt_iphi = m_calocell_id->phi(oid);
295 m_nt_max = imax;
296 m_nt_min = imin;
297 IdentifierHash ihash = m_calocell_id->calo_cell_hash(oid);
298 m_nt_e = 0.0;
299 m_nt_t = 0.0;
300 m_nt_quality = 0;
301 if(cc) {
302 const CaloCell *rcell = cc->findCell(ihash);
303 if(rcell->ID() != oid) {
304 msg(MSG::WARNING) <<"Cell iHash does not match ..."<<endmsg;
305 }else{
306 m_nt_e = rcell->e();
307 m_nt_t = rcell->time();
308 m_nt_quality = rcell->quality();
309 }
310 } else if(lraw) {
311 for(unsigned l=0; l<lraw->size(); ++l) {
312 if((*lraw)[l].identify() == hid) {
313 m_nt_e = (*lraw)[l].energy();
314 m_nt_t = (*lraw)[l].time()*1e-3;
315 m_nt_quality = (*lraw)[l].quality();
316 break;
317 }
318 }
319 }
320 const CaloDetDescrElement *cdde = caloMgr->get_element(oid);
321 if(cdde) {
322 m_nt_eta = cdde->eta();
323 m_nt_phi = cdde->phi();
324 m_nt_z = cdde->z();
325 m_nt_r = cdde->r();
326 }
327 m_tree->Fill();
328 }//found our digit
329 }//over digits
330
331 return StatusCode::SUCCESS;
332}
333
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Definition of CaloDetDescrManager.
Calo Subsystem specific Detector Elements + Dummy element for testing.
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
#define CHECK(...)
Evaluate an expression and check for errors.
int imax(int i, int j)
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
Container class for CaloCell.
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
float time() const
get time (data member)
Definition CaloCell.h:368
virtual double e() const override final
get energy (data member) (synonym to method energy()
Definition CaloCell.h:333
uint16_t quality() const
get quality (data member)
Definition CaloCell.h:348
Identifier ID() const
get ID (from cached data member) non-virtual and inline for fast access
Definition CaloCell.h:295
This class groups all DetDescr information related to a CaloCell.
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...
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
This is a "hash" representation of an Identifier.
value_type get_compact() const
Get the compact id.
Container class for LArDigit.
Liquid Argon digit base class.
Definition LArDigit.h:25
CaloGain::CaloGain gain() const
Definition LArDigit.h:72
const HWIdentifier & hardwareID() const
Definition LArDigit.h:66
const std::vector< short > & samples() const
Definition LArDigit.h:78
const HWIdentifier & channelID() const
Definition LArDigit.h:69
virtual StatusCode initialize() override
SG::ReadCondHandleKey< ILArPedestal > m_pedKey
Definition LArHECNoise.h:64
bool * m_nt_trigger
PublicToolHandle< Trig::TrigDecisionTool > m_trigDec
Definition LArHECNoise.h:67
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition LArHECNoise.h:71
const LArOnlineID * m_LArOnlineIDHelper
Definition LArHECNoise.h:70
float * m_nt_prescale
ServiceHandle< ITHistSvc > m_thistSvc
Definition LArHECNoise.h:59
virtual StatusCode execute() override
short m_nt_digi[32]
Definition LArHECNoise.h:93
virtual StatusCode finalize() override
float m_nt_actMu
Definition LArHECNoise.h:98
std::vector< std::string > m_TriggerLines
float m_nt_pedRMS
int m_nt_evtCount
Definition LArHECNoise.h:81
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition LArHECNoise.h:63
float m_nt_avgMu
Definition LArHECNoise.h:97
TTree * m_tree
Definition LArHECNoise.h:61
int m_nt_evtTime_ns
Definition LArHECNoise.h:83
const CaloCell_ID * m_calocell_id
Definition LArHECNoise.h:76
LArHECNoise(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Container for LArRawChannel (IDC using LArRawChannelCollection)
uint32_t lumiBlock() const
The current event's luminosity block number.
uint32_t bcid() const
The bunch crossing ID of the event.
float averageInteractionsPerCrossing() const
Average interactions per crossing for all BCIDs - for out-of-time pile-up.
float actualInteractionsPerCrossing() const
Average interactions per crossing for the current BCID - for in-time pile-up.
uint32_t timeStamp() const
POSIX time in seconds from 1970. January 1st.
uint32_t runNumber() const
The current event's run number.
uint32_t timeStampNSOffset() const
Nanosecond time offset wrt. the time stamp.
uint64_t eventNumber() const
The current event's event number.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
STL namespace.
EventInfo_v1 EventInfo
Definition of the latest event info version.