ATLAS Offline Software
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:
39 #include "LArRawEvent/LArDigit.h"
42 
43 //Events infos:
45 
46 //for looping on FEBs
48 
49 //Helper:
51 
52 //Header:
55 
56 
57 /*---------------------------------------------------------*/
58 LArCoherentNoisefractionMonAlg::LArCoherentNoisefractionMonAlg( const std::string& name, ISvcLocator* pSvcLocator)
59  : AthMonitorAlgorithm(name, pSvcLocator),
60  m_LArOnlineIDHelper(nullptr)
61 {
62 }
63 
64 /*---------------------------------------------------------*/
66 { }
67 
68 
69 /*---------------------------------------------------------*/
72 {
73 
74  ATH_MSG_INFO( "Initialize LArCoherentNoisefractionMonAlg" );
75 
76  ATH_CHECK(detStore()->retrieve( m_LArOnlineIDHelper, "LArOnlineID" ));
77 
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]) {
115  m_histoGroups.push_back(Monitored::buildToolMap<int>(m_tools,m_groupNames[group],m_FEBlist));
116  }
117  }
118 
119  return StatusCode::SUCCESS;
120 }
121 
122 
123 /*---------------------------------------------------------*/
124 StatusCode
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);
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  }
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 
279 double 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 }
288 double 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 
LArCoherentNoisefractionMonAlg::m_LArOnlineIDHelper
const LArOnlineID * m_LArOnlineIDHelper
services
Definition: LArCoherentNoisefractionMonAlg.h:53
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ILArPedestal::pedestal
virtual float pedestal(const HWIdentifier &id, int gain) const =0
LArCoherentNoisefractionMonAlg::calc_dev
double calc_dev(std::vector< float > *input_vector) const
Definition: LArCoherentNoisefractionMonAlg.cxx:279
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
LArCoherentNoisefractionMonAlg::febString
std::string febString(const HWIdentifier) const
build the FEB string, following instructions from python config
Definition: LArCoherentNoisefractionMonAlg.cxx:271
LArCoherentNoisefractionMonAlg::m_keyPedestal
SG::ReadCondHandleKey< ILArPedestal > m_keyPedestal
Handle to pedestal.
Definition: LArCoherentNoisefractionMonAlg.h:59
LArStrHelper.h
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
ILArPedestal
Definition: ILArPedestal.h:12
AthMonitorAlgorithm::m_vTrigChainNames
std::vector< std::string > m_vTrigChainNames
Vector of trigger chain names parsed from trigger chain string.
Definition: AthMonitorAlgorithm.h:356
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
LArDigit::samples
const std::vector< short > & samples() const
Definition: LArDigit.h:78
skel.it
it
Definition: skel.GENtoEVGEN.py:407
LArDigit::hardwareID
const HWIdentifier & hardwareID() const
Definition: LArDigit.h:66
AthMonitorAlgorithm::getTrigDecisionTool
const ToolHandle< Trig::TrigDecisionTool > & getTrigDecisionTool() const
Get the trigger decision tool member.
Definition: AthMonitorAlgorithm.cxx:194
LArOnlineID_Base::slot
int slot(const HWIdentifier id) const
Return the slot number of a hardware cell identifier: slot = [1,15] Slot-ID in top part of the crat...
Definition: LArOnlineID_Base.cxx:1961
TrigDecisionTool.h
LArOnlineID_Base::feb_begin
id_iterator feb_begin() const
Returns an iterator pointing to a feb identifier collection.
Definition: LArOnlineID_Base.cxx:1910
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
HWIdentifier
Definition: HWIdentifier.h:13
LArCoherentNoisefractionMonAlg::~LArCoherentNoisefractionMonAlg
virtual ~LArCoherentNoisefractionMonAlg()
Default destructor.
Definition: LArCoherentNoisefractionMonAlg.cxx:65
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
LArCoherentNoisefractionMonAlg::m_groupNChan
Gaudi::Property< std::vector< unsigned > > m_groupNChan
Definition: LArCoherentNoisefractionMonAlg.h:69
AthMonitorAlgorithm
Base class for Athena Monitoring Algorithms.
Definition: AthMonitorAlgorithm.h:36
LArCoherentNoisefractionMonAlg::m_groupNames
Gaudi::Property< std::vector< std::string > > m_groupNames
Definition: LArCoherentNoisefractionMonAlg.h:68
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
LArOnlineID_Base::channel
int channel(const HWIdentifier id) const
Return the channel number of a hardware cell identifier channel = [0,127] in all FEB.
Definition: LArOnlineID_Base.cxx:1967
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LArDigit.h
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:116
LArDigit
Liquid Argon digit base class.
Definition: LArDigit.h:25
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
LArCoherentNoisefractionMonAlg::m_febMap
std::vector< HWIdentifier > m_febMap
Definition: LArCoherentNoisefractionMonAlg.h:84
LArCoherentNoisefractionMonAlg::m_processGroup
Gaudi::Property< std::vector< bool > > m_processGroup
Definition: LArCoherentNoisefractionMonAlg.h:70
LArOnlineID_Base::pos_neg
int pos_neg(const HWIdentifier id) const
Return the side of a hardware cell identifier pos_neg = [0,1] positive-side or negative-side Barrel...
Definition: LArOnlineID_Base.cxx:1954
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthMonitorAlgorithm::fill
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.
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
LArCoherentNoisefractionMonAlg.h
LArDigits2NtupleDumper.FT
FT
Definition: LArDigits2NtupleDumper.py:77
LArCoherentNoisefractionMonAlg::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: LArCoherentNoisefractionMonAlg.cxx:125
LArOnlineID_Base::feb_Id
HWIdentifier feb_Id(int barrel_ec, int pos_neg, int feedthrough, int slot) const
Create feb_Id from fields.
Definition: LArOnlineID_Base.cxx:1483
LArOnlineID_Base::feb_end
id_iterator feb_end() const
Definition: LArOnlineID_Base.cxx:1915
AthMonitorAlgorithm::m_tools
ToolHandleArray< GenericMonitoringTool > m_tools
Array of Generic Monitoring Tools.
Definition: AthMonitorAlgorithm.h:338
LArFebHeaderContainer.h
HWIdentifier.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
LArCoherentNoisefractionMonAlg::calc_sum_dev
double calc_sum_dev(std::vector< float > *input_vector) const
Definition: LArCoherentNoisefractionMonAlg.cxx:288
LArNoisyROSummary.h
LArCoherentNoisefractionMonAlg::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Handle to cabling.
Definition: LArCoherentNoisefractionMonAlg.h:56
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArDigitContainer.h
LArOnlineID_Base::isEMBchannel
bool isEMBchannel(const HWIdentifier id) const
Definition: LArOnlineID_Base.cxx:1652
EventInfo.h
LArCoherentNoisefractionMonAlg::m_LArDigitContainerKey
SG::ReadHandleKey< LArDigitContainer > m_LArDigitContainerKey
Handle to digits.
Definition: LArCoherentNoisefractionMonAlg.h:77
CaloGain::CaloGain
CaloGain
Definition: CaloGain.h:11
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
LArCoherentNoisefractionMonAlg::m_histoGroups
std::vector< std::map< std::string, int > > m_histoGroups
the group array
Definition: LArCoherentNoisefractionMonAlg.h:80
LArCoherentNoisefractionMonAlg::m_FEBlist
Gaudi::Property< std::vector< std::string > > m_FEBlist
Definition: LArCoherentNoisefractionMonAlg.h:67
LArOnlineID_Base::feedthrough
int feedthrough(const HWIdentifier id) const
Return the feedthrough of a hardware cell identifier : feedthrough = [0,31] Barrel - A/C side or H/...
Definition: LArOnlineID_Base.cxx:1948
LArDigit::gain
CaloGain::CaloGain gain() const
Definition: LArDigit.h:72
CaloLCW_tf.group
group
Definition: CaloLCW_tf.py:28
LArCoherentNoisefractionMonAlg::LArCoherentNoisefractionMonAlg
LArCoherentNoisefractionMonAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArCoherentNoisefractionMonAlg.cxx:58
LArCoherentNoisefractionMonAlg::m_isCalibrationRun
Gaudi::Property< bool > m_isCalibrationRun
to avoid asking for triggers in case of a calibration run
Definition: LArCoherentNoisefractionMonAlg.h:74
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
LArCoherentNoisefractionMonAlg::initialize
virtual StatusCode initialize() override
initialize
Definition: LArCoherentNoisefractionMonAlg.cxx:71
LArOnlineID.h
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20