ATLAS Offline Software
Loading...
Searching...
No Matches
LArCoherentNoisefractionMonAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4/*
5*/
6
7// ********************************************************************
8// NAME: LArCoherentNoisefractionMon.cxx
9// PACKAGE: LArMonTools
10//
11// AUTHOR: Pavol Strizenec, based on codes from M. Spalla and Y. Enari
12//
13// Computes and plots the coherent noise fraction (CNF) for some group of the channels on the FEB
14//
15// CNF are computed per FEB. The FEBs to be monitored are set in the JO.
16//
17// Available parameters in the jo file:
18// 1) List of FEBs to be monitored: should be passed as a list of strings of the form 'BarrelCFT00Slot02', case insensitive (corresponding to type LARONLINEID defined in the package atlas/LArCalorimeter/LArMonTools/LArMonTools/LArOnlineIDStrHelper.h). If the list is empty, all FEBs are monitored.
19// 2) list of triggers to be used ('TriggerChain'): to be passed as a single string "trigger_chain_1, trigger_chain_2". The default is "HLT_noalg_zb_L1ZB, HLT_noalg_cosmiccalo_L1RD1_EMPTY", for the latter, only events in the abort gap are used, selection done by hand.
20// 3) control IsCalibrationRun: to be set to true when running on calibration, it switches off the trigger selection.
21// 4) list of groups to be computed, vector of strings, possible values: ["tot","top","bot","left","right","q1","q2","q3","q4","qs1","qs2","qs3","qs4"] - default is empty list, which means all groups are computed
22//
23// ********************************************************************
24
25//STL:
26#include <sstream>
27#include <iomanip>
28#include <cmath>
29#include <vector>
30#include <algorithm>
31
32//ROOT
33#include "TPRegexp.h"
34
35
36//LAr infos:
42
43//Events infos:
45
46//for looping on FEBs
48
49//Helper:
51
52//Header:
55
56
57/*---------------------------------------------------------*/
58LArCoherentNoisefractionMonAlg::LArCoherentNoisefractionMonAlg( const std::string& name, ISvcLocator* pSvcLocator)
59 : AthMonitorAlgorithm(name, pSvcLocator),
60 m_LArOnlineIDHelper(nullptr)
61{
62}
63
64/*---------------------------------------------------------*/
67
68
69/*---------------------------------------------------------*/
70StatusCode
72{
73
74 ATH_MSG_INFO( "Initialize LArCoherentNoisefractionMonAlg" );
75
76 ATH_CHECK(detStore()->retrieve( m_LArOnlineIDHelper, "LArOnlineID" ));
77
78 ATH_CHECK(m_cablingKey.initialize());
79 ATH_CHECK(m_keyPedestal.initialize());
81
82 // initialize superclass
84
85 if(m_processGroup.size() == 0 || m_groupNames.size() == 0 || m_groupNChan.size() ==0 ||
86 m_processGroup.size() != m_groupNames.size() || m_processGroup.size() != m_groupNChan.size() ){
87 ATH_MSG_ERROR("Wrong configuration of LArCoherentNoisefractionMonAlg, bombing !");
88 return StatusCode::FAILURE;
89 }
90 unsigned int nGroups=0;
91 ATH_MSG_DEBUG("Running for selected groups ...");
92 for(auto g : m_processGroup) {
93 if(g) ++nGroups;
94 }
95 if(nGroups==0) { // something wrong
96 ATH_MSG_ERROR(" List of groups to monitor is empty !!! ");
97 return StatusCode::FAILURE;
98 }
99
100 m_febMap.reserve(m_FEBlist.size());
101 for(auto feb = m_LArOnlineIDHelper->feb_begin(); feb != m_LArOnlineIDHelper->feb_end(); ++feb) {
102 bool plotThisFEB=false;
103 for(uint ifm=0;ifm<m_FEBlist.size();ifm++) {
104 if(febString(*feb)==m_FEBlist[ifm]) {
105 plotThisFEB=true;
106 break;
107 }
108 }
109 if(plotThisFEB) m_febMap.emplace_back(*feb);
110 }
111
112 /*now the groups*/
113 for(unsigned group=0; group<m_processGroup.size(); ++group) {
114 if(m_processGroup[group]) {
116 }
117 }
118
119 return StatusCode::SUCCESS;
120}
121
122
123/*---------------------------------------------------------*/
124StatusCode
126{
127
128 ATH_MSG_DEBUG("in fillHists()" );
130 if(m_FEBlist.size() == 0) return StatusCode::SUCCESS;
131
133 bool passTrig = m_isCalibrationRun;
134 if(!m_isCalibrationRun) {
135 ATH_MSG_DEBUG( "Parsing trigger chain list" );
136 const ToolHandle<Trig::TrigDecisionTool> trigTool=getTrigDecisionTool();
137
138 bool passBCID;
139 if(!trigTool.empty()) {
140 // BCIDs of the abort gap
141 const int ABORT_GAP_START = 3446;
142 const int ABORT_GAP_END = 3563;
143 for(auto trig_chain : m_vTrigChainNames) {
144 passBCID = ((trig_chain == "HLT_noalg_cosmiccalo_L1RD1_EMPTY")?(ctx.eventID().bunch_crossing_id() >= ABORT_GAP_START && ctx.eventID().bunch_crossing_id() <= ABORT_GAP_END):true);
145 passTrig=(passTrig || (passBCID && trigTool->isPassed(trig_chain)));
146 }
147 }
148 } else {
149 ATH_MSG_INFO( "Running as 'calibration run'. No trigger selection will be applied...");
150 }
151
152 if (!passTrig) {
153 ATH_MSG_DEBUG ( " Failed trigger selection " );
154 return StatusCode::SUCCESS;
155 } else {
156 ATH_MSG_DEBUG ( " Pass trigger selection " );
157 }
158
159 /*retrieve cabling*/
161 const LArOnOffIdMapping* cabling=*cablingHdl;
162 if(!cabling) {
163 ATH_MSG_ERROR("Do not have cabling map with key: "<<m_cablingKey.key());
164 return StatusCode::FAILURE;
165 }
166
167 /*retrieve pedestal*/
169 const ILArPedestal* pedestals=*pedestalHdl;
170
173
174 ATH_MSG_DEBUG ( " LArDigitContainer size "<<pLArDigitContainer->size()<<" for key "<<m_LArDigitContainerKey);
176 LArDigitContainer::const_iterator itDig = pLArDigitContainer->begin();
177 LArDigitContainer::const_iterator itDig_e= pLArDigitContainer->end();
178
180 //for (auto & arr_entry : m_div) arr_entry.second.clear();
181 std::map<std::pair<HWIdentifier,unsigned>, std::vector<float> > div_array;
182 for (auto arr_entry : m_febMap) {
183 for(unsigned group=0; group<m_processGroup.size(); ++group) {
184 if(m_processGroup[group]) div_array[std::make_pair(arr_entry,group)]=std::vector<float>();
185 }
186 }
187 HWIdentifier febID;
188 unsigned chan;
189
191 for ( ; itDig!=itDig_e;++itDig) {
192 const LArDigit* pLArDigit = *itDig;
193
195 HWIdentifier id = pLArDigit->hardwareID();
196 CaloGain::CaloGain gain = pLArDigit->gain();
197 float pedestal = pedestals->pedestal(id,gain);
198
200 const std::vector<short>* digito = &pLArDigit->samples();
201
203 febID = m_LArOnlineIDHelper->feb_Id(id);
204 chan = m_LArOnlineIDHelper->channel(id);
205
206 for(unsigned group=0; group < m_processGroup.size(); ++group) {
207
208 if(!m_processGroup[group]) continue;
209 if(div_array.count(std::make_pair(febID,group)) > 0) {
210 try {
211 std::vector<float> &tmparr=div_array.at(std::make_pair(febID,group));
212 short sample=digito->at(2);
213 float sdiff = sample-pedestal;
214 if(group==0) {
215 tmparr.push_back(sdiff);
216 }else if (group==1 && chan%2==0) {
217 tmparr.push_back(sdiff);
218 }else if (group==2 && chan%2==1) {
219 tmparr.push_back(sdiff);
220 }else if (group==3 && chan<64) {
221 tmparr.push_back(sdiff);
222 }else if (group==4 && chan>63) {
223 tmparr.push_back(sdiff);
224 }else if (group==5 && chan%2==0 && chan<64) {
225 tmparr.push_back(sdiff);
226 }else if (group==6 && chan%2==1 && chan<64) {
227 tmparr.push_back(sdiff);
228 }else if (group==7 && chan%2==0 && chan>63) {
229 tmparr.push_back(sdiff);
230 }else if (group==8 && chan%2==1 && chan>63) {
231 tmparr.push_back(sdiff);
232 }else if (group==9 && chan<32) {
233 tmparr.push_back(sdiff);
234 }else if (group==10 && chan>31 && chan<64) {
235 tmparr.push_back(sdiff);
236 }else if (group==11 && chan>63 && chan<96) {
237 tmparr.push_back(sdiff);
238 }else if (group==12 && chan>95) {
239 tmparr.push_back(sdiff);
240 }
241 }
242 catch (const std::out_of_range& oor) {
243 continue;
244 }
245 } // if kay exists
246 } //over groups
247
248 }
249
250 //now fill the plots
251 for(unsigned group=0; group < m_processGroup.size(); ++group) {
252 if(!m_processGroup[group]) {
253 ATH_MSG_DEBUG("Group "<<m_groupNames[group]<<" not filled");
254 continue;
255 }
256 ATH_MSG_DEBUG("febMap size: "<<m_febMap.size());
257 for(auto const& feb_entry : m_febMap) {
258 std::string febstr = febString(feb_entry);
259 auto chanSumDev = Monitored::Scalar<double>("SumDev",calc_sum_dev(&div_array[std::make_pair(feb_entry,group)]));
260 auto chanDev = Monitored::Scalar<double>("Dev",calc_dev(&div_array[std::make_pair(feb_entry,group)]));
261 fill(m_tools[m_histoGroups.at(group).at(febstr)],chanSumDev,chanDev);
262 }
263 }
264
265 return StatusCode::SUCCESS;
266}
267
268
269/*---------------------------------------------------------*/
272 std::string eb=m_LArOnlineIDHelper->isEMBchannel(afeb) ? "Barrel" : "Endcap";
273 std::string ac=(m_LArOnlineIDHelper->pos_neg(afeb)==1) ? "A" : "C";
274 int FT = m_LArOnlineIDHelper->feedthrough(afeb);
275 int SL = m_LArOnlineIDHelper->slot(afeb);
276 return eb+ac+Form("ft%02d",FT)+Form("slot%02d",SL);
277}
278
279double LArCoherentNoisefractionMonAlg::calc_dev(std::vector<float> *input_vector) const {
280 double tmean=0.;
281 double tdiv = 0.;
282 for(auto it : *input_vector) tmean += it;
283 tmean = tmean / input_vector->size();
284 for(auto it : *input_vector) tdiv += (tmean - it)*(tmean - it);
285 tdiv = tdiv / input_vector->size();
286 return tdiv;
287}
288double LArCoherentNoisefractionMonAlg::calc_sum_dev(std::vector<float> *input_vector) const {
289 double tsum=0.;
290 for(auto it : *input_vector) tsum += it;
291 return tsum;
292}
293
294
#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)
unsigned int uint
const ServiceHandle< StoreGateSvc > & detStore() const
virtual StatusCode initialize() override
initialize
const ToolHandle< Trig::TrigDecisionTool > & getTrigDecisionTool() const
Get the trigger decision tool member.
std::vector< std::string > m_vTrigChainNames
Vector of trigger chain names parsed from trigger chain string.
AthMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
ToolHandleArray< GenericMonitoringTool > m_tools
Array of Generic Monitoring Tools.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
virtual float pedestal(const HWIdentifier &id, int gain) const =0
Gaudi::Property< std::vector< std::string > > m_groupNames
double calc_sum_dev(std::vector< float > *input_vector) const
virtual StatusCode initialize() override
initialize
SG::ReadCondHandleKey< ILArPedestal > m_keyPedestal
Handle to pedestal.
double calc_dev(std::vector< float > *input_vector) const
virtual ~LArCoherentNoisefractionMonAlg()
Default destructor.
Gaudi::Property< std::vector< std::string > > m_FEBlist
SG::ReadHandleKey< LArDigitContainer > m_LArDigitContainerKey
Handle to digits.
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Gaudi::Property< std::vector< bool > > m_processGroup
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Handle to cabling.
std::vector< std::map< std::string, int > > m_histoGroups
the group array
Gaudi::Property< std::vector< unsigned > > m_groupNChan
Gaudi::Property< bool > m_isCalibrationRun
to avoid asking for triggers in case of a calibration run
std::string febString(const HWIdentifier) const
build the FEB string, following instructions from python config
const LArOnlineID * m_LArOnlineIDHelper
services
LArCoherentNoisefractionMonAlg(const std::string &name, ISvcLocator *pSvcLocator)
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
Declare a monitored scalar variable.
void fill(const ToolHandle< GenericMonitoringTool > &groupHandle, std::vector< std::reference_wrapper< Monitored::IMonitoredVariable > > &&variables) const
Fills a vector of variables to a group by reference.
std::vector< V > buildToolMap(const ToolHandleArray< GenericMonitoringTool > &tools, const std::string &baseName, int nHist)
Builds an array of indices (base case)