ATLAS Offline Software
LArCoherentNoisefractionMonAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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:
54 
55 
56 /*---------------------------------------------------------*/
57 LArCoherentNoisefractionMonAlg::LArCoherentNoisefractionMonAlg( const std::string& name, ISvcLocator* pSvcLocator)
58  : AthMonitorAlgorithm(name, pSvcLocator),
59  m_LArOnlineIDHelper(nullptr)
60 {
61 }
62 
63 /*---------------------------------------------------------*/
65 { }
66 
67 
68 /*---------------------------------------------------------*/
71 {
72 
73  ATH_MSG_INFO( "Initialize LArCoherentNoisefractionMonAlg" );
74 
75  ATH_CHECK(detStore()->retrieve( m_LArOnlineIDHelper, "LArOnlineID" ));
76 
80 
81  // initialize superclass
83 
84  if(m_processGroup.size() == 0 || m_groupNames.size() == 0 || m_groupNChan.size() ==0 ||
85  m_processGroup.size() != m_groupNames.size() || m_processGroup.size() != m_groupNChan.size() ){
86  ATH_MSG_ERROR("Wrong configuration of LArCoherentNoisefractionMonAlg, bombing !");
87  return StatusCode::FAILURE;
88  }
89  unsigned int nGroups=0;
90  ATH_MSG_DEBUG("Running for selected groups ...");
91  for(auto g : m_processGroup) {
92  if(g) ++nGroups;
93  }
94  if(nGroups==0) { // something wrong
95  ATH_MSG_ERROR(" List of groups to monitor is empty !!! ");
96  return StatusCode::FAILURE;
97  }
98 
99  m_febMap.reserve(m_FEBlist.size());
100  for(auto feb = m_LArOnlineIDHelper->feb_begin(); feb != m_LArOnlineIDHelper->feb_end(); ++feb) {
101  bool plotThisFEB=false;
102  for(uint ifm=0;ifm<m_FEBlist.size();ifm++) {
103  if(febString(*feb)==m_FEBlist[ifm]) {
104  plotThisFEB=true;
105  break;
106  }
107  }
108  if(plotThisFEB) m_febMap.emplace_back(*feb);
109  }
110 
111  /*now the groups*/
112  for(unsigned group=0; group<m_processGroup.size(); ++group) {
113  if(m_processGroup[group]) {
114  m_histoGroups.push_back(Monitored::buildToolMap<int>(m_tools,m_groupNames[group],m_FEBlist));
115  }
116  }
117 
118  return StatusCode::SUCCESS;
119 }
120 
121 
122 /*---------------------------------------------------------*/
123 StatusCode
125 {
126 
127  ATH_MSG_DEBUG("in fillHists()" );
129  if(m_FEBlist.size() == 0) return StatusCode::SUCCESS;
130 
132  bool passTrig = m_isCalibrationRun;
133  if(!m_isCalibrationRun) {
134  ATH_MSG_DEBUG( "Parsing trigger chain list" );
135  const ToolHandle<Trig::TrigDecisionTool> trigTool=getTrigDecisionTool();
136 
137  bool passBCID;
138  if(!trigTool.empty()) {
139  // BCIDs of the abort gap
140  const int ABORT_GAP_START = 3446;
141  const int ABORT_GAP_END = 3563;
142  for(auto trig_chain : m_vTrigChainNames) {
143  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);
144  passTrig=(passTrig || (passBCID && trigTool->isPassed(trig_chain)));
145  }
146  }
147  } else {
148  ATH_MSG_INFO( "Running as 'calibration run'. No trigger selection will be applied...");
149  }
150 
151  if (!passTrig) {
152  ATH_MSG_DEBUG ( " Failed trigger selection " );
153  return StatusCode::SUCCESS;
154  } else {
155  ATH_MSG_DEBUG ( " Pass trigger selection " );
156  }
157 
158  /*retrieve cabling*/
160  const LArOnOffIdMapping* cabling=*cablingHdl;
161  if(!cabling) {
162  ATH_MSG_ERROR("Do not have cabling map with key: "<<m_cablingKey.key());
163  return StatusCode::FAILURE;
164  }
165 
166  /*retrieve pedestal*/
168  const ILArPedestal* pedestals=*pedestalHdl;
169 
172 
173  ATH_MSG_DEBUG ( " LArDigitContainer size "<<pLArDigitContainer->size()<<" for key "<<m_LArDigitContainerKey);
175  LArDigitContainer::const_iterator itDig = pLArDigitContainer->begin();
176  LArDigitContainer::const_iterator itDig_e= pLArDigitContainer->end();
177 
179  //for (auto & arr_entry : m_div) arr_entry.second.clear();
180  std::map<std::pair<HWIdentifier,unsigned>, std::vector<float> > div_array;
181  for (auto arr_entry : m_febMap) {
182  for(unsigned group=0; group<m_processGroup.size(); ++group) {
183  if(m_processGroup[group]) div_array[std::make_pair(arr_entry,group)]=std::vector<float>();
184  }
185  }
186  HWIdentifier febID;
187  unsigned chan;
188 
190  for ( ; itDig!=itDig_e;++itDig) {
191  const LArDigit* pLArDigit = *itDig;
192 
194  HWIdentifier id = pLArDigit->hardwareID();
195  CaloGain::CaloGain gain = pLArDigit->gain();
196  float pedestal = pedestals->pedestal(id,gain);
197 
199  const std::vector<short>* digito = &pLArDigit->samples();
200 
202  febID = m_LArOnlineIDHelper->feb_Id(id);
204 
205  for(unsigned group=0; group < m_processGroup.size(); ++group) {
206 
207  if(!m_processGroup[group]) continue;
208  if(div_array.count(std::make_pair(febID,group)) > 0) {
209  try {
210  std::vector<float> &tmparr=div_array.at(std::make_pair(febID,group));
211  short sample=digito->at(2);
212  float sdiff = sample-pedestal;
213  if(group==0) {
214  tmparr.push_back(sdiff);
215  }else if (group==1 && chan%2==0) {
216  tmparr.push_back(sdiff);
217  }else if (group==2 && chan%2==1) {
218  tmparr.push_back(sdiff);
219  }else if (group==3 && chan<64) {
220  tmparr.push_back(sdiff);
221  }else if (group==4 && chan>63) {
222  tmparr.push_back(sdiff);
223  }else if (group==5 && chan%2==0 && chan<64) {
224  tmparr.push_back(sdiff);
225  }else if (group==6 && chan%2==1 && chan<64) {
226  tmparr.push_back(sdiff);
227  }else if (group==7 && chan%2==0 && chan>63) {
228  tmparr.push_back(sdiff);
229  }else if (group==8 && chan%2==1 && chan>63) {
230  tmparr.push_back(sdiff);
231  }else if (group==9 && chan<32) {
232  tmparr.push_back(sdiff);
233  }else if (group==10 && chan>31 && chan<64) {
234  tmparr.push_back(sdiff);
235  }else if (group==11 && chan>63 && chan<96) {
236  tmparr.push_back(sdiff);
237  }else if (group==12 && chan>95) {
238  tmparr.push_back(sdiff);
239  }
240  }
241  catch (const std::out_of_range& oor) {
242  continue;
243  }
244  } // if kay exists
245  } //over groups
246 
247  }
249  //now fill the plots
250  for(unsigned group=0; group < m_processGroup.size(); ++group) {
251  if(!m_processGroup[group]) {
252  ATH_MSG_DEBUG("Group "<<m_groupNames[group]<<" not filled");
253  continue;
254  }
255  ATH_MSG_DEBUG("febMap size: "<<m_febMap.size());
256  for(auto const& feb_entry : m_febMap) {
257  std::string febstr = febString(feb_entry);
258  auto chanSumDev = Monitored::Scalar<double>("SumDev",calc_sum_dev(&div_array[std::make_pair(feb_entry,group)]));
259  auto chanDev = Monitored::Scalar<double>("Dev",calc_dev(&div_array[std::make_pair(feb_entry,group)]));
260  fill(m_tools[m_histoGroups.at(group).at(febstr)],chanSumDev,chanDev);
261  }
262  }
263 
264  return StatusCode::SUCCESS;
265 }
266 
267 
268 /*---------------------------------------------------------*/
271  std::string eb=m_LArOnlineIDHelper->isEMBchannel(afeb) ? "Barrel" : "Endcap";
272  std::string ac=(m_LArOnlineIDHelper->pos_neg(afeb)==1) ? "A" : "C";
273  int FT = m_LArOnlineIDHelper->feedthrough(afeb);
274  int SL = m_LArOnlineIDHelper->slot(afeb);
275  return eb+ac+Form("ft%02d",FT)+Form("slot%02d",SL);
276 }
277 
278 double LArCoherentNoisefractionMonAlg::calc_dev(std::vector<float> *input_vector) const {
279  double tmean=0.;
280  double tdiv = 0.;
281  for(auto it : *input_vector) tmean += it;
282  tmean = tmean / input_vector->size();
283  for(auto it : *input_vector) tdiv += (tmean - it)*(tmean - it);
284  tdiv = tdiv / input_vector->size();
285  return tdiv;
286 }
287 double LArCoherentNoisefractionMonAlg::calc_sum_dev(std::vector<float> *input_vector) const {
288  double tsum=0.;
289  for(auto it : *input_vector) tsum += it;
290  return tsum;
291 }
292 
293 
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:278
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:270
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:70
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:110
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:423
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:189
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
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:64
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:100
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
LArCoherentNoisefractionMonAlg::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: LArCoherentNoisefractionMonAlg.cxx:124
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:195
LArCoherentNoisefractionMonAlg::calc_sum_dev
double calc_sum_dev(std::vector< float > *input_vector) const
Definition: LArCoherentNoisefractionMonAlg.cxx:287
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
LArNewCalib_Delay_OFC_Cali.FT
FT
Definition: LArNewCalib_Delay_OFC_Cali.py:120
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:57
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:70
LArOnlineID.h
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20