ATLAS Offline Software
LArNoiseCorrelationMonAlg.cxx
Go to the documentation of this file.
1 
2 /*
3  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
4 */
5 /*
6 */
7 
8 
9 // ********************************************************************
10 // NAME: LArNoiseCorrelationMonAlg.cxx
11 // PACKAGE: LArMonTools
12 //
13 // AUTHOR: Margherita Spalla (margherita.spalla@cern.ch)
14 // Based on structure of LArDigitMon by Helary Louis (helary@lapp.in2p3.fr)
15 //
16 // Computes and plots the correlation between single channels to monitor coherent noise.
17 // The correlation is computed as:
18 // corr(i,j) = Cov(i,j)/sqrt(Var(i)*Var(j)) where 'Cov(i,j)' is the sample covariance of channels i and j and 'Var(i)' is the sample variance of channel i.
19 // Variance and covariance are computed summing over all samples and all events for each channel: Cov(i,j)=[sum(x_i*x_j)-N*mean_i*mean_j]/(N-1) , where x_i is the single sample minus the pedestal.
20 //
21 // Correlation histograms are computed per FEB. The FEBs to be monitored are set in the JO.
22 //
23 // Available parameters in the jo file:
24 // 1) List of FEBs to be monitored: should be passed as a list of strings of the form 'BarrelCFT00Slot02'. If the list is empty, all FEBs are monitored.
25 // 2) control PublishAllFebsOnline: if it is set to true, switched off the monitoring in case the FEB list (1) is empty and the algorithm is running online.
26 // 3) 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.
27 // 4) control IsCalibrationRun: to be set to true when running on calibration, it switches off the trigger selection.
28 // 5) control PublishPartialSums: tells the algorithm to also publish the partial sum histograms. default is false.
29 
30 //
31 // ********************************************************************
32 
33 //LAr infos:
36 #include "LArRawEvent/LArDigit.h"
38 
39 //Helper:
41 
42 //Header:
44 
45 
46 /*---------------------------------------------------------*/
48 { }
49 
50 
51 /*---------------------------------------------------------*/
54 {
55 
56  ATH_MSG_INFO( "Initialize LArNoiseCorrelationMonAlg" );
57 
58  ATH_CHECK(detStore()->retrieve( m_LArOnlineIDHelper, "LArOnlineID" ));
59 
63 
67 
68  // initialize superclass
70 
71  if(m_plotsOFF) return StatusCode::SUCCESS; // will not plot anything
72 
73  /*now the group*/
74  m_noiseCorrGroups=Monitored::buildToolMap<int>(m_tools,m_noiseCorrGroupName,m_FEBlist);
75 
76 
77  const std::set<std::string> febSet(m_FEBlist.begin(),m_FEBlist.end());
78 
79  //Check for abort-gap if the trigger m_abortGapTrig is in the list of triggers
81 
82 
85 
86  //Pre-fill the 'model' of the internal structure (to be copied for each event)
89  if (febSet.find(fName)!=febSet.end()) {
90  m_febMapModel.emplace(std::make_pair(fid,perFeb_t(fName)));
91  }
92  }
93 
94  return StatusCode::SUCCESS;
95 }
96 
97 
98 /*---------------------------------------------------------*/
100 LArNoiseCorrelationMonAlg::fillHistograms(const EventContext& ctx) const
101 {
102  if(m_plotsOFF) {
103  ATH_MSG_DEBUG("Plotting switched off, either we are online and custom FEB list is empty, OR something went wrong with the custom list of FEBs passed");
104  return StatusCode::SUCCESS;
105  }
106 
107  ATH_MSG_DEBUG("in fillHists()" );
108 
109 
111  if (m_checkAbortGap && !m_trigDecTool.empty()) {
112  // BCIDs of the abort gap
113  constexpr unsigned int ABORT_GAP_START = 3446;
114  constexpr unsigned int ABORT_GAP_END = 3563;
115  const unsigned int bcid=ctx.eventID().bunch_crossing_id();
116  if (m_trigDecTool->isPassed(m_abortGapTrig) && bcid<ABORT_GAP_START && bcid>ABORT_GAP_END) {
117  ATH_MSG_DEBUG("Passed trigger ["<<m_abortGapTrig <<"] and bcid "<< bcid <<" falls outside the abort gap. Ignoring this event");
118  return StatusCode::SUCCESS;
119  }
120  }
121 
122  /*retrieve cabling*/
124  const LArOnOffIdMapping* cabling=*cablingHdl;
125  if(!cabling) {
126  ATH_MSG_ERROR("Do not have cabling map with key: "<<m_cablingKey.key());
127  return StatusCode::FAILURE;
128  }
129 
130  /*retrieve pedestal*/
132  const ILArPedestal* pedestals=*pedestalHdl;
133 
134  const LArBadChannelCont* bcCont=nullptr;
137  bcCont=(*bcContHdl);
138  }
139 
140 
143 
144  ATH_MSG_DEBUG ( " LArDigitContainer size "<<pLArDigitContainer->size()<<" for key "<<m_LArDigitContainerKey);
145 
146  //copy model-map ...
147  std::map<HWIdentifier,perFeb_t> febMap{m_febMapModel};
148  //... and pre-fill with pointers to digits and pedestals
149  for (const LArDigit* pDig : *pLArDigitContainer) {
150  const HWIdentifier chid=pDig->channelID();
151  const HWIdentifier fid=m_LArOnlineIDHelper->feb_Id(chid);
152  auto febDat=febMap.find(fid);
153  if (febDat!=febMap.end()) {
154  CaloGain::CaloGain gain = pDig->gain();
155  double ped = pedestals->pedestal(chid,gain);
156  if(isGoodChannel(chid,ped,cabling,bcCont)) {
157  febDat->second.m_digitsAndPed.emplace_back(std::make_pair(pDig,ped));
158  }
159  }
160 
161  }
162 
163  //now fill the plots
164  for (auto& [febid,febdat] : febMap) {
165  febdat.sumSamples(m_LArOnlineIDHelper);
166  auto chanMean = Monitored::Collection("chanMean",febdat.m_meanSum,[](const std::pair<int,double> ch){return ch.second;});
167  auto chanMeanX = Monitored::Collection("chanMeanX",febdat.m_meanSum,[](const std::pair<int,double> ch){return ch.first;});
168  auto chanPartSum = Monitored::Collection("chanPartSum",febdat.m_partSum,[](const std::pair<std::pair<int,int>,double> ch){return ch.second;});
169  auto chanPartSumX = Monitored::Collection("chanPartSumX",febdat.m_partSum,[](const std::pair<std::pair<int,int>,double> ch){return std::min(ch.first.first,ch.first.second);});
170  auto chanPartSumY = Monitored::Collection("chanPartSumY",febdat.m_partSum,[](const std::pair<std::pair<int,int>,double> ch){return std::max(ch.first.first,ch.first.second);}); //needs max and min to fill the correlation plot always on the same side of the diagonal, otherwise it would be mixed up
171 
172  //fill the correct FEB
173  fill(m_tools[m_noiseCorrGroups.at(febdat.m_febName)],chanMean,chanMeanX,chanPartSum,chanPartSumX,chanPartSumY);
174 
175  /* actual correlations will be computed at post-processing stage */
176 
177  }
178  return StatusCode::SUCCESS;
179 }
180 
181 
182 
183 /*---------------------------------------------------------*/
186  {
189  return false;
190 
192  if(ped <= (1.0+LArElecCalib::ERRORCODE))
193  return false;
194 
196  if(!cabling->isOnlineConnected(ID))
197  return false;
198 
199  return true;
200  }
201 
202 
203 /*---------------------------------------------------------*/
204 
205 
207  const size_t S=m_digitsAndPed.size();
208  for (size_t i1=0;i1<S;++i1) {
209  const auto& [pDig1,pedestal1]=m_digitsAndPed[i1];
210  const int ch1 = lArOnlineIDHelper->channel(pDig1->channelID());
211  //Sum mean:
212  for (const short adc : pDig1->samples()) {
213  m_meanSum.emplace_back(ch1,adc-pedestal1);
214  }
215  //sum of squares
216  for (size_t i2=i1;i2<S;++i2) {
217  const auto& [pDig2,pedestal2]=m_digitsAndPed[i2];
218  const int ch2 = lArOnlineIDHelper->channel(pDig2->channelID());
219  double sumSquare=0;
220  const unsigned nADC=std::min(pDig1->nsamples(),pDig2->nsamples());
221  for (unsigned i=0;i<nADC;++i) {
222  sumSquare+=((pDig1->samples().at(i)-pedestal1)*(pDig2->samples().at(i)-pedestal2));
223  }//end loop over samples
224  m_partSum.emplace_back(std::make_pair(std::make_pair(ch1,ch2),sumSquare));
225  }//end loop pDig2
226  }//end loop pDig1
227 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArNoiseCorrelationMonAlg::perFeb_t::sumSamples
void sumSamples(const LArOnlineID *lArOnlineIDHelper)
Definition: LArNoiseCorrelationMonAlg.cxx:206
ILArPedestal::pedestal
virtual float pedestal(const HWIdentifier &id, int gain) const =0
LArNoiseCorrelationMonAlg::isGoodChannel
bool isGoodChannel(const HWIdentifier id, const float ped, const LArOnOffIdMapping *cabling, const LArBadChannelCont *bc) const
check if channel is ok for monitoring
Definition: LArNoiseCorrelationMonAlg.cxx:185
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
LArNoiseCorrelationMonAlg::m_problemsToMask
Gaudi::Property< std::vector< std::string > > m_problemsToMask
Definition: LArNoiseCorrelationMonAlg.h:60
LArNoiseCorrelationMonAlg::m_bcMask
LArBadChannelMask m_bcMask
Handle to bad-channel mask.
Definition: LArNoiseCorrelationMonAlg.h:58
LArNoiseCorrelationMonAlg::m_keyPedestal
SG::ReadCondHandleKey< ILArPedestal > m_keyPedestal
Handle to pedestal.
Definition: LArNoiseCorrelationMonAlg.h:66
LArStrHelper.h
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ID
std::vector< Identifier > ID
Definition: CalibHitIDCheck.h:24
AthMonitorAlgorithm::m_trigDecTool
PublicToolHandle< Trig::TrigDecisionTool > m_trigDecTool
Tool to tell whether a specific trigger is passed.
Definition: AthMonitorAlgorithm.h:340
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
LArNoiseCorrelationMonAlg::m_bcContKey
SG::ReadCondHandleKey< LArBadChannelCont > m_bcContKey
Definition: LArNoiseCorrelationMonAlg.h:59
rootconvert.fName
string fName
Definition: rootconvert.py:5
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
ILArPedestal
Definition: ILArPedestal.h:12
LArBadXCont
Conditions-Data class holding LAr Bad Channel or Bad Feb information.
Definition: LArBadChannelCont.h:28
LArNoiseCorrelationMonAlg.h
LArElecCalib::ERRORCODE
@ ERRORCODE
Definition: LArCalibErrorCode.h:17
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
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:1957
LArBadChannelMask::buildBitMask
StatusCode buildBitMask(const std::vector< std::string > &problemsToMask, MsgStream &msg)
Definition: LArBadChannelMask.cxx:10
LArStrHelper
Helper class to manipulate strings for LArOnlineID names.
Definition: LArStrHelper.h:24
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
LArBadChannelMask::cellShouldBeMasked
bool cellShouldBeMasked(const LArBadChannelCont *bcCont, const HWIdentifier &hardwareId) const
Definition: LArBadChannelMask.h:42
JetTiledMap::S
@ S
Definition: TiledEtaPhiMap.h:44
LArNoiseCorrelationMonAlg::m_plotsOFF
Gaudi::Property< bool > m_plotsOFF
Definition: LArNoiseCorrelationMonAlg.h:71
LArNoiseCorrelationMonAlg::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: LArNoiseCorrelationMonAlg.cxx:100
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
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
LArNoiseCorrelationMonAlg::m_noiseCorrGroupName
Gaudi::Property< std::string > m_noiseCorrGroupName
the group array
Definition: LArNoiseCorrelationMonAlg.h:83
LArNoiseCorrelationMonAlg::initialize
virtual StatusCode initialize() override
initialize
Definition: LArNoiseCorrelationMonAlg.cxx:53
LArNoiseCorrelationMonAlg::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Handle to cabling.
Definition: LArNoiseCorrelationMonAlg.h:63
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:1963
LArOnlineID_Base::feb_range
id_range feb_range() const
Definition: LArOnlineID_Base.cxx:1916
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LArDigit.h
LArDigit
Liquid Argon digit base class.
Definition: LArDigit.h:25
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArNoiseCorrelationMonAlg::m_febMapModel
std::map< HWIdentifier, perFeb_t > m_febMapModel
Definition: LArNoiseCorrelationMonAlg.h:102
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
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:1950
LArNoiseCorrelationMonAlg::perFeb_t::m_digitsAndPed
std::vector< std::pair< const LArDigit *, double > > m_digitsAndPed
Definition: LArNoiseCorrelationMonAlg.h:96
LArNoiseCorrelationMonAlg::m_FEBlist
Gaudi::Property< std::vector< std::string > > m_FEBlist
list of FEBs to monitor.
Definition: LArNoiseCorrelationMonAlg.h:69
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LArNoiseCorrelationMonAlg::perFeb_t::m_meanSum
std::vector< std::pair< int, double > > m_meanSum
Definition: LArNoiseCorrelationMonAlg.h:97
LArNoiseCorrelationMonAlg::perFeb_t::m_partSum
std::vector< std::pair< std::pair< int, int >, double > > m_partSum
Definition: LArNoiseCorrelationMonAlg.h:98
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
LArNoiseCorrelationMonAlg::~LArNoiseCorrelationMonAlg
virtual ~LArNoiseCorrelationMonAlg()
Default destructor.
Definition: LArNoiseCorrelationMonAlg.cxx:47
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:1479
min
#define min(a, b)
Definition: cfImp.cxx:40
LArNoiseCorrelationMonAlg::m_checkAbortGap
bool m_checkAbortGap
Definition: LArNoiseCorrelationMonAlg.h:89
LArNoiseCorrelationMonAlg::m_noiseCorrGroups
std::map< std::string, int > m_noiseCorrGroups
Definition: LArNoiseCorrelationMonAlg.h:84
LArNoiseCorrelationMonAlg::m_ignoreKnownBadChannels
Gaudi::Property< bool > m_ignoreKnownBadChannels
bool use to mask the bad channels
Definition: LArNoiseCorrelationMonAlg.h:77
AthMonitorAlgorithm::m_tools
ToolHandleArray< GenericMonitoringTool > m_tools
Array of Generic Monitoring Tools.
Definition: AthMonitorAlgorithm.h:338
HWIdentifier.h
LArNoiseCorrelationMonAlg::perFeb_t
Internally used data structure.
Definition: LArNoiseCorrelationMonAlg.h:93
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArOnlineID
Definition: LArOnlineID.h:20
xAOD::bcid
setEventNumber setTimeStamp bcid
Definition: EventInfo_v1.cxx:133
LArDigitContainer.h
LArOnlineID_Base::isEMBchannel
bool isEMBchannel(const HWIdentifier id) const
Definition: LArOnlineID_Base.cxx:1648
GlobalVariables.larStrHelp
larStrHelp
Definition: GlobalVariables.py:133
CaloGain::CaloGain
CaloGain
Definition: CaloGain.h:11
Example_ReadSampleNoise.ped
ped
Definition: Example_ReadSampleNoise.py:45
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
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:1944
ReadFloatFromCool.adc
adc
Definition: ReadFloatFromCool.py:48
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
LArNoiseCorrelationMonAlg::m_LArDigitContainerKey
SG::ReadHandleKey< LArDigitContainer > m_LArDigitContainerKey
Handle to digits.
Definition: LArNoiseCorrelationMonAlg.h:80
LArNoiseCorrelationMonAlg::m_abortGapTrig
const std::string m_abortGapTrig
Definition: LArNoiseCorrelationMonAlg.h:90
LArNoiseCorrelationMonAlg::m_LArOnlineIDHelper
const LArOnlineID * m_LArOnlineIDHelper
services
Definition: LArNoiseCorrelationMonAlg.h:55
LArOnlineID.h
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20