ATLAS Offline Software
Loading...
Searching...
No Matches
LArNoiseCorrelationMonAlg.cxx
Go to the documentation of this file.
1
2/*
3 Copyright (C) 2002-2025 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:
38
39//Helper:
41
42//Header:
45
46
47/*---------------------------------------------------------*/
50
51
52/*---------------------------------------------------------*/
53StatusCode
55{
56
57 ATH_MSG_INFO( "Initialize LArNoiseCorrelationMonAlg" );
58
59 ATH_CHECK(detStore()->retrieve( m_LArOnlineIDHelper, "LArOnlineID" ));
60
61 ATH_CHECK(m_cablingKey.initialize());
62 ATH_CHECK(m_keyPedestal.initialize());
64
67 ATH_CHECK(m_bcMask.buildBitMask(m_problemsToMask,msg()));
68
69 // initialize superclass
71
72 if(m_plotsOFF) return StatusCode::SUCCESS; // will not plot anything
73
74 /*now the group*/
76
77
78 const std::set<std::string> febSet(m_FEBlist.begin(),m_FEBlist.end());
79
80 //Check for abort-gap if the trigger m_abortGapTrig is in the list of triggers
82
83
85 LArStrHelper larStrHelp;
86
87 //Pre-fill the 'model' of the internal structure (to be copied for each event)
88 for (HWIdentifier fid : m_LArOnlineIDHelper->feb_range()) {
89 const std::string fName=larStrHelp.febNameString(m_LArOnlineIDHelper->isEMBchannel(fid),m_LArOnlineIDHelper->pos_neg(fid),m_LArOnlineIDHelper->feedthrough(fid),m_LArOnlineIDHelper->slot(fid));
90 if (febSet.find(fName)!=febSet.end()) {
91 m_febMapModel.emplace(std::make_pair(fid,perFeb_t(fName)));
92 }
93 }
94
95 return StatusCode::SUCCESS;
96}
97
98
99/*---------------------------------------------------------*/
100StatusCode
101LArNoiseCorrelationMonAlg::fillHistograms(const EventContext& ctx) const
102{
103 if(m_plotsOFF) {
104 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");
105 return StatusCode::SUCCESS;
106 }
107
108 ATH_MSG_DEBUG("in fillHists()" );
109
110
112 if (m_checkAbortGap && !m_trigDecTool.empty()) {
113 // BCIDs of the abort gap
114 constexpr unsigned int ABORT_GAP_START = 3446;
115 constexpr unsigned int ABORT_GAP_END = 3563;
116 const unsigned int bcid=ctx.eventID().bunch_crossing_id();
117 if (m_trigDecTool->isPassed(m_abortGapTrig) && bcid<ABORT_GAP_START && bcid>ABORT_GAP_END) {
118 ATH_MSG_DEBUG("Passed trigger ["<<m_abortGapTrig <<"] and bcid "<< bcid <<" falls outside the abort gap. Ignoring this event");
119 return StatusCode::SUCCESS;
120 }
121 }
122
123 /*retrieve cabling*/
125 const LArOnOffIdMapping* cabling=*cablingHdl;
126 if(!cabling) {
127 ATH_MSG_ERROR("Do not have cabling map with key: "<<m_cablingKey.key());
128 return StatusCode::FAILURE;
129 }
130
131 /*retrieve pedestal*/
133 const ILArPedestal* pedestals=*pedestalHdl;
134
135 const LArBadChannelCont* bcCont=nullptr;
138 bcCont=(*bcContHdl);
139 }
140
141
144
145 ATH_MSG_DEBUG ( " LArDigitContainer size "<<pLArDigitContainer->size()<<" for key "<<m_LArDigitContainerKey);
146
147 //copy model-map ...
148 std::map<HWIdentifier,perFeb_t> febMap{m_febMapModel};
149 //... and pre-fill with pointers to digits and pedestals
150 for (const LArDigit* pDig : *pLArDigitContainer) {
151 const HWIdentifier chid=pDig->channelID();
152 const HWIdentifier fid=m_LArOnlineIDHelper->feb_Id(chid);
153 auto febDat=febMap.find(fid);
154 if (febDat!=febMap.end()) {
155 CaloGain::CaloGain gain = pDig->gain();
156 double ped = pedestals->pedestal(chid,gain);
157 if(isGoodChannel(chid,ped,cabling,bcCont)) {
158 febDat->second.m_digitsAndPed.emplace_back(std::make_pair(pDig,ped));
159 }
160 }
161
162 }
163
164 //now fill the plots
165 for (auto& [febid,febdat] : febMap) {
166 febdat.sumSamples(m_LArOnlineIDHelper);
167 auto chanMean = Monitored::Collection("chanMean",febdat.m_meanSum,[](const std::pair<int,double> ch){return ch.second;});
168 auto chanMeanX = Monitored::Collection("chanMeanX",febdat.m_meanSum,[](const std::pair<int,double> ch){return ch.first;});
169 auto chanPartSum = Monitored::Collection("chanPartSum",febdat.m_partSum,[](const std::pair<std::pair<int,int>,double> ch){return ch.second;});
170 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);});
171 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
172
173 //fill the correct FEB
174 fill(m_tools[m_noiseCorrGroups.at(febdat.m_febName)],chanMean,chanMeanX,chanPartSum,chanPartSumX,chanPartSumY);
175
176 /* actual correlations will be computed at post-processing stage */
177
178 }
179 return StatusCode::SUCCESS;
180}
181
182
183
184/*---------------------------------------------------------*/
186bool LArNoiseCorrelationMonAlg::isGoodChannel(const HWIdentifier ID,const float ped, const LArOnOffIdMapping *cabling, const LArBadChannelCont* bcCont) const
187 {
189 if (m_ignoreKnownBadChannels && m_bcMask.cellShouldBeMasked(bcCont,ID))
190 return false;
191
193 if(ped <= (1.0+LArElecCalib::ERRORCODE))
194 return false;
195
197 if(!cabling->isOnlineConnected(ID))
198 return false;
199
200 return true;
201 }
202
203
204/*---------------------------------------------------------*/
205
206
208 const size_t S=m_digitsAndPed.size();
209 for (size_t i1=0;i1<S;++i1) {
210 const auto& [pDig1,pedestal1]=m_digitsAndPed[i1];
211 const int ch1 = lArOnlineIDHelper->channel(pDig1->channelID());
212 //Sum mean:
213 for (const short adc : pDig1->samples()) {
214 m_meanSum.emplace_back(ch1,adc-pedestal1);
215 }
216 //sum of squares
217 for (size_t i2=i1;i2<S;++i2) {
218 const auto& [pDig2,pedestal2]=m_digitsAndPed[i2];
219 const int ch2 = lArOnlineIDHelper->channel(pDig2->channelID());
220 double sumSquare=0;
221 const unsigned nADC=std::min(pDig1->nsamples(),pDig2->nsamples());
222 for (unsigned i=0;i<nADC;++i) {
223 sumSquare+=((pDig1->samples().at(i)-pedestal1)*(pDig2->samples().at(i)-pedestal2));
224 }//end loop over samples
225 m_partSum.emplace_back(std::make_pair(std::make_pair(ch1,ch2),sumSquare));
226 }//end loop pDig2
227 }//end loop pDig1
228}
#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)
std::vector< Identifier > ID
LArBadXCont< LArBadChannel > LArBadChannelCont
const ServiceHandle< StoreGateSvc > & detStore() const
virtual StatusCode initialize() override
initialize
std::vector< std::string > m_vTrigChainNames
Vector of trigger chain names parsed from trigger chain string.
PublicToolHandle< Trig::TrigDecisionTool > m_trigDecTool
Tool to tell whether a specific trigger is passed.
ToolHandleArray< GenericMonitoringTool > m_tools
Array of Generic Monitoring Tools.
virtual float pedestal(const HWIdentifier &id, int gain) const =0
Liquid Argon digit base class.
Definition LArDigit.h:25
std::map< std::string, int > m_noiseCorrGroups
const LArOnlineID * m_LArOnlineIDHelper
services
virtual ~LArNoiseCorrelationMonAlg()
Default destructor.
Gaudi::Property< std::string > m_noiseCorrGroupName
the group array
Gaudi::Property< bool > m_ignoreKnownBadChannels
bool use to mask the bad channels
virtual StatusCode initialize() override
initialize
LArBadChannelMask m_bcMask
Handle to bad-channel mask.
std::map< HWIdentifier, perFeb_t > m_febMapModel
SG::ReadCondHandleKey< ILArPedestal > m_keyPedestal
Handle to pedestal.
SG::ReadHandleKey< LArDigitContainer > m_LArDigitContainerKey
Handle to digits.
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
bool isGoodChannel(const HWIdentifier id, const float ped, const LArOnOffIdMapping *cabling, const LArBadChannelCont *bc) const
check if channel is ok for monitoring
SG::ReadCondHandleKey< LArBadChannelCont > m_bcContKey
Gaudi::Property< bool > m_plotsOFF
Gaudi::Property< std::vector< std::string > > m_problemsToMask
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Handle to cabling.
Gaudi::Property< std::vector< std::string > > m_FEBlist
list of FEBs to monitor.
int channel(const HWIdentifier id) const
Return the channel number of a hardware cell identifier channel = [0,127] in all FEB.
Helper class to manipulate strings for LArOnlineID names.
std::vector< V > buildToolMap(const ToolHandleArray< GenericMonitoringTool > &tools, const std::string &baseName, int nHist)
Builds an array of indices (base case)
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
std::vector< std::pair< int, double > > m_meanSum
std::vector< std::pair< std::pair< int, int >, double > > m_partSum
std::vector< std::pair< const LArDigit *, double > > m_digitsAndPed
void sumSamples(const LArOnlineID *lArOnlineIDHelper)
void fill(H5::Group &out_file, size_t iterations)