ATLAS Offline Software
CscRdoValMonAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Athena include(s)
6 #include "CscRdoValMonAlg.h"
7 #include "MuonRDO/CscRawData.h"
9 
10 //
11 // constructor ----------------------------------------------------------------
12 //
13 CscRdoValMonAlg::CscRdoValMonAlg(const std::string& name, ISvcLocator* pSvcLocator ) :
14  AthMonitorAlgorithm(name, pSvcLocator)
15  { }
16 
17 //
18 // initialize ----------------------------------------------------------------
19 //
21 {
22  ATH_MSG_DEBUG ("CscRdoValMonAlg : in initialize()");
23  ATH_CHECK(m_idHelperSvc.retrieve());
24  ATH_CHECK(m_cscRdoDecoderTool.retrieve());
27 }
28 
29 //
30 // fillHistograms ----------------------------------------------------------------
31 //
32 StatusCode CscRdoValMonAlg::fillHistograms(const EventContext& ctx) const
33 {
34  ATH_MSG_DEBUG ( "CscRdoValMonAlg :: in fillHistograms()" );
35 
36  if(m_cscRdoKey.key() == ""){ //it seems that protection is needed for this case
37  ATH_MSG_WARNING("CSC RDO key is blank, returning");
38  return StatusCode::SUCCESS;
39  }
40 
42 
43  // ==============================================================================
44  // Field Range Notes
45  // ==============================================================================
46  // StationName unsigned integer maps to "CSS", "CSL", etc.
47  // StationEta [-1,1] -1 for backward, 1 for forward endcap
48  // StationPhi [1,8] increases with Phi
49  // Technology [1] maps to "CSC"
50  // ChamberLayer [1,2] increases with |Z|
51  // WireLayer [1,4] increases with |Z|
52  // MeasuresPhi [0,1] 0 if measures R, 1 if measures Phi
53  // Strip [1,n] increases with R for MeasuresPhi=0
54  // increases with Phi for MeasuresPhi=1
55  // ==============================================================================
56 
57  ATH_MSG_DEBUG ( " Size of RDO Container : " << CscRDO->size() );
58 
59  // Begin Event ==================================================
60  ATH_MSG_DEBUG ( " BEGIN EVENT ========================================== " );
61 
62  for (CscRawDataContainer::const_iterator it = CscRDO->begin(); it != CscRDO->end(); ++it)
63  {
64  const CscRawDataCollection * rdo = *it;
65  ATH_MSG_DEBUG ( " Number of Samples : " << rdo->numSamples() );
66  ATH_MSG_DEBUG ( " Size of Collection : " << rdo->size() );
67 
68  size_t nEtaClusWidthCnt = 0, nPhiClusWidthCnt = 0; //cluster position in each phi-layer
69  Identifier stationId, channelId;
70 
71  int clusCount[33][9], sigclusCount[33][9];
72  for(size_t kl = 0; kl < 33; kl++ )
73  {
74  for(size_t km = 0; km < 9; km++ )
75  {
76  clusCount[kl][km] = 0;
77  sigclusCount[kl][km] = 0;
78  }
79  }
80 
81  // loop over ROD-clusters
82  for(CscRawDataCollection::const_iterator ic = (*it)->begin(); ic != (*it)->end(); ++ic)
83  {
84  const CscRawData *raw = (*ic);
85  if(raw)
86  {
87  // Identify side(A/C), sector(1-16)/layer(1-4)
88  stationId = m_cscRdoDecoderTool->stationIdentifier(raw,&m_idHelperSvc->cscIdHelper());
89  channelId = m_cscRdoDecoderTool->channelIdentifier(raw,&m_idHelperSvc->cscIdHelper(),0);
90  int stationName = m_idHelperSvc->cscIdHelper().stationName(channelId);
91  int chamberType = m_idHelperSvc->cscIdHelper().stationNameIndex("CSS") == stationName ? 0 : 1;
92  int stationEta = m_idHelperSvc->cscIdHelper().stationEta(channelId);
93  int stationPhi = m_idHelperSvc->cscIdHelper().stationPhi(channelId);
94  int wireLayer = m_idHelperSvc->cscIdHelper().wireLayer(channelId);
95  int measuresPhi = m_idHelperSvc->cscIdHelper().measuresPhi(channelId);
96  auto measuresPhi_mon = Monitored::Scalar<int>("measuresPhi_mon", measuresPhi);
97  auto measuresEta = Monitored::Scalar<int>("measuresEta", !measuresPhi );
98 
99  // determine the sector number
100  int sectorNo = stationEta * (2 * stationPhi - chamberType);
101 
102  // compute the indices to store cluster count
103  int ns = sectorNo < 0 ? sectorNo*(-1) : sectorNo+16; // [-16 -> -1] shifted to [1 -> 16] and [+1 -> +16] shifted to [+17 -> +32]
104  int nl = (measuresPhi ? wireLayer : wireLayer+4); // [ 1 -> 4] (phi-layers) and [5 -> 8] (eta-layers)
105  clusCount[ns][nl]++;
106 
107  // indices for ns = [+1 -> +32]; 32 places (index '0' is not counted); allocated 33 places
108  // indices for nl = [+1 -> +8]; 8 places (index '0' is not counted); allocated 9 places
109  ATH_MSG_DEBUG(" ns = " << ns << "\tm_nl = " << nl << "\tm_sec = " << sectorNo << "\t m_lay= " << wireLayer << "\tmPhi = " << measuresPhi);
110 
111  // y-axis fill value
112  // sector# +2 layer 1 maps to +2 + 0.2*(1-1) + 0.1 = +2.1
113  // sector# +2 layer 2 maps to +2 + 0.2*(2-1) + 0.1 = +2.3
114  // sector# +2 layer 3 maps to +2 + 0.2*(3-1) + 0.1 = +2.5
115  // sector# +2 layer 4 maps to +2 + 0.2*(4-1) + 0.1 = +2.7
116  auto secLayer = Monitored::Scalar<float>("secLayer",sectorNo + 0.2 * (wireLayer - 1) + 0.1);
117  int xfac = measuresPhi ? -1 : 1; // -48 / +192
118 
119  // this way we get 4 time samples per strip
120  ATH_MSG_DEBUG (" Width of ROD cluster : " << raw->width() );
121  uint16_t diff_max = 0., diff = 0.;
122  std::vector<float> xVals;
123 
124  // loop over strips in ROD cluster
125  auto raw_clus_width = Monitored::Scalar<size_t>("raw_clus_width",raw->width());
126 
127  if (measuresPhi) nPhiClusWidthCnt++;
128  else nEtaClusWidthCnt++;
129  fill("CscRdoMonitor", raw_clus_width, secLayer, measuresPhi_mon, measuresEta);
130 
131  // loop over strips
132  for (size_t n = 0; n < raw_clus_width; n++ )
133  {
134  // identify this strip
135  Identifier chID = m_cscRdoDecoderTool->channelIdentifier(raw, &m_idHelperSvc->cscIdHelper(), n);
136  int strip = m_idHelperSvc->cscIdHelper().strip(chID);
137  auto stripId = Monitored::Scalar<float>("stripId",strip * xfac); // x-axis fill value
138  fill("CscRdoMonitor", stripId, secLayer);
139 
140  // for every strip that has a hit, store the X,Y values
141  xVals.push_back(stripId);
142 
143  // extract the (four) time samples for this strip
144  std::vector<uint16_t> samples;
145  bool extractSamples = raw->samples(n, rdo->numSamples(), samples);
146  uint16_t n_max=0, n_min = 9999;
147 
148  // if we have the time samples, identify the max/min sampling values i.e., ADC_max and ADC_min
149  if (extractSamples)
150  {
151  for (size_t np = 0; np < samples.size(); np++)
152  {
153  if(samples[np] < n_min) n_min = samples[np];
154  if(samples[np] > n_max) n_max = samples[np];
155  }
156  // the diff between max and min samplings Delta_ADC = (ADC_max - ADC_min)
157  diff = n_max - n_min;
158 
159  // compute the max difference Max_Delta_ADC
160  if(diff > diff_max) diff_max = diff;
161 
162  ATH_MSG_DEBUG ( n << " Max = " << n_max << " Min = " << n_min << " Diff = " << diff );
163  } // end if extractSamples
164  } // end for loop over strips in cluster
165 
166  ATH_MSG_DEBUG ( " End loop over strips======================" );
167 
168  ATH_MSG_DEBUG ( " Max difference : " << diff_max );
169 
170  auto diff_max_mon = Monitored::Scalar<uint16_t>("diff_max_mon",diff_max);
171  fill("CscRdoMonitor", diff_max_mon);
172 
173  // determine of the cluster is a noise/signal cluster Max_Delta_ADC > NoiseCut
174  bool signal = diff_max > m_cscNoiseCut ? true : false;
175  std::vector<int> tmp_xVals_signal;
176  std::vector<int> tmp_xVals_noise;
177  std::vector<float> tmp_secLayer_signal;
178  std::vector<float> tmp_secLayer_noise;
179 
180  if (signal)
181  {
182  sigclusCount[ns][nl]++;
183  for(size_t nf = 0; nf < xVals.size(); nf++)
184  {
185  tmp_xVals_signal.push_back(xVals[nf]);
186  tmp_secLayer_signal.push_back(secLayer);
187  }
188  }
189  else
190  {
191  for(size_t nf = 0; nf < xVals.size(); nf++)
192  {
193  tmp_xVals_noise.push_back(xVals[nf]);
194  tmp_secLayer_noise.push_back(secLayer);
195  }
196  }
197  auto isSignal = Monitored::Scalar<int>("isSignal", (int) signal);
198  auto isNoise = Monitored::Scalar<int>("isNoise", (int) !signal);
199  auto tmp_xVals_signal_mon = Monitored::Collection("tmp_xVals_signal_mon", tmp_xVals_signal);
200  auto tmp_secLayer_sig_mon = Monitored::Collection("tmp_secLayer_sig_mon", tmp_secLayer_signal);
201  auto tmp_secLayer_noise_mon = Monitored::Collection("tmp_secLayer_noise_mon", tmp_secLayer_noise);
202  auto sideC_signal = Monitored::Scalar<int>("sideC_signal", (int) (signal && stationEta == -1));
203  auto sideA_signal = Monitored::Scalar<int>("sideA_signal", (int) (signal && stationEta == 1));
204  auto signal_measuresEta = Monitored::Scalar<int>("signal_measuresEta", (int)(signal && !measuresPhi));
205  auto signal_measuresEta_sideC = Monitored::Scalar<int>("signal_measuresEta_sideC", (int)(signal && !measuresPhi && stationEta == -1));
206  auto signal_measuresEta_sideA = Monitored::Scalar<int>("signal_measuresEta_sideA", (int)(signal && !measuresPhi && stationEta == 1));
207  auto signal_measuresPhi = Monitored::Scalar<int>("signal_measuresPhi", (int)(signal && measuresPhi));
208  auto signal_measuresPhi_sideC = Monitored::Scalar<int>("signal_measuresPhi_sideC", (int)(signal && measuresPhi && stationEta == -1));
209  auto signal_measuresPhi_sideA = Monitored::Scalar<int>("signal_measuresPhi_sideA", (int)(signal && measuresPhi && stationEta == 1));
210  auto tmp_xVals_noise_mon = Monitored::Collection("tmp_xVals_noise_mon", tmp_xVals_noise);
211  auto noise_measuresEta = Monitored::Scalar<int>("noise_measuresEta", (int)(!signal && !measuresPhi ));
212  auto noise_measuresPhi = Monitored::Scalar<int>("noise_measuresPhi", (int)(!signal && measuresPhi ));
213 
214  fill("CscRdoMonitor", isSignal, isNoise, secLayer, tmp_secLayer_sig_mon, tmp_secLayer_noise_mon, tmp_xVals_signal_mon, tmp_xVals_noise_mon, raw_clus_width, sideC_signal, sideA_signal, signal_measuresEta, signal_measuresEta_sideC, signal_measuresEta_sideA, signal_measuresPhi, signal_measuresPhi_sideC, signal_measuresPhi_sideA, noise_measuresEta, noise_measuresPhi);
215 
216  } // end if raw
217  } // end loop over ROD-clusters
218 
219  ATH_MSG_DEBUG ( " End loop over clusters======================" );
220  auto nPhiClusWidthCnt_mon = Monitored::Scalar<size_t>("nPhiClusWidthCnt_mon", nPhiClusWidthCnt);
221  auto nEtaClusWidthCnt_mon = Monitored::Scalar<size_t>("nEtaClusWidthCnt_mon", nEtaClusWidthCnt);
222  fill("CscRdoMonitor", nPhiClusWidthCnt_mon, nEtaClusWidthCnt_mon);
223 
224  int numeta = 0, numphi = 0, numetasignal = 0, numphisignal = 0;
225  for(int kl = 1; kl < 33; kl++ )
226  {
227  // int m_sec = kl < 17 ? kl*(-1) : kl; // [1->16](-side) [17-32] (+side)
228  for(int km = 1; km < 9; km++ )
229  {
230  int lay = (km > 4 && km < 9) ? km-4 : km; // 1,2,3,4 (phi-layers) 5-4, 6-4, 7-4, 8-4 (eta-layers)
231  bool mphi = (km > 0 && km < 5) ? true : false; // 1,2,3,4 (phi-layers) 5,6,7,8 (eta-layers)
232  std::string wlay = mphi ? "Phi-Layer " : "Eta-Layer: ";
233  int count = clusCount[kl][km];
234  int scount = sigclusCount[kl][km];
235  int tmp_counts_phi = 0, tmp_counts_eta = 0;
236 
237  if(count > 0)
238  {
239  float secLayer = kl-16 + 0.2 * (lay - 1) + 0.1;
240  if(mphi)
241  {
242  numphi += count;
243  if(scount > 0)
244  {
245  numphisignal += scount;
246  tmp_counts_phi = count - scount;
247  }
248  else tmp_counts_phi = count;
249  }
250  else
251  {
252  numeta += count;
253  if(scount > 0)
254  {
255  numetasignal += scount;
256  tmp_counts_eta = count - scount;
257  }
258  else tmp_counts_eta = count;
259  }
260  ATH_MSG_DEBUG ( wlay << "Counts sec: [" << kl-16 << "]\tlayer: [" << km << "] = " << secLayer << "\t = " << count << "\t" << scount);
261 
262  auto secLayer_count = Monitored::Scalar<float>("secLayer_count", secLayer);
263  auto mphi_mon = Monitored::Scalar<int>("mphi_mon",(int) ( (count>0) && mphi));
264  auto count_mon = Monitored::Scalar<int>("count_mon", count);
265  auto scount_mon = Monitored::Scalar<int>("scount_mon", scount);
266  auto mphi_scount = Monitored::Scalar<int>("mphi_scount",(int) ( (count>0) && mphi && (scount>0)));
267  auto mphi_inv = Monitored::Scalar<int>("mphi_inv", (int) ( (count>0) && !mphi));
268  auto mphi_inv_scount = Monitored::Scalar<int>("mphi_inv_scount", (int) ( (count>0) && !mphi && (scount>0)));
269  auto tmp_counts_phi_mon = Monitored::Scalar<int>("tmp_counts_phi_mon",tmp_counts_phi);
270  auto tmp_counts_eta_mon = Monitored::Scalar<int>("tmp_counts_eta_mon",tmp_counts_eta);
271 
272  fill("CscRdoMonitor", count_mon, secLayer_count, mphi_mon, mphi_scount, scount_mon, tmp_counts_phi_mon, mphi_inv, mphi_inv_scount, tmp_counts_eta_mon);
273  } // end if count
274  }
275  }
276 
277  auto numphi_mon = Monitored::Scalar<int>("numphi_mon",numphi);
278  auto numeta_mon = Monitored::Scalar<int>("numeta_mon",numeta);
279  auto numphisignal_mon = Monitored::Scalar<int>("numphisignal_mon",numphisignal);
280  auto numetasignal_mon = Monitored::Scalar<int>("numetasignal_mon",numetasignal);
281  auto diffnumphi = Monitored::Scalar<int>("diffnumphi", numphi-numphisignal);
282  auto diffnumeta = Monitored::Scalar<int>("diffnumeta",numeta-numetasignal);
283 
284  fill("CscRdoMonitor", numphi_mon, numeta_mon, numphisignal_mon, numetasignal_mon, diffnumphi, diffnumeta);
285  }
286 
287  ATH_MSG_DEBUG ( " END EVENT ============================================ " );
288  ATH_MSG_DEBUG ( "done collecting histograms" );
289  ATH_MSG_DEBUG ( "CSCRdoMon::fillHistograms reports success" );
290 
291  return StatusCode::SUCCESS;
292 }
calibdata.scount
int scount
Definition: calibdata.py:355
Muon::nsw::STGTPSegments::moduleIDBits::stationPhi
constexpr uint8_t stationPhi
station Phi 1 to 8
Definition: NSWSTGTPDecodeBitmaps.h:161
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
SiliconTech::strip
@ strip
dumpTgcDigiDeadChambers.stationName
dictionary stationName
Definition: dumpTgcDigiDeadChambers.py:30
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
CscRdoValMonAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: CscRdoValMonAlg.h:29
skel.it
it
Definition: skel.GENtoEVGEN.py:396
IdentifiableContainerMT::size
size_t size() const
Duplicate of fullSize for backwards compatability.
Definition: IdentifiableContainerMT.h:206
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
PlotPulseshapeFromCool.np
np
Definition: PlotPulseshapeFromCool.py:64
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
AthMonitorAlgorithm
Base class for Athena Monitoring Algorithms.
Definition: AthMonitorAlgorithm.h:36
Cut::signal
@ signal
Definition: SUSYToolsAlg.cxx:67
keylayer_zslicemap.kl
kl
Definition: keylayer_zslicemap.py:109
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
CscRdoValMonAlg::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: CscRdoValMonAlg.cxx:32
CscRawData::width
uint16_t width() const
Definition: CscRawData.h:128
beamspotman.n
n
Definition: beamspotman.py:731
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
CscRdoValMonAlg::m_cscRdoDecoderTool
ToolHandle< Muon::ICSC_RDO_Decoder > m_cscRdoDecoderTool
Definition: CscRdoValMonAlg.h:30
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
IdentifiableContainerMT::end
const_iterator end() const
return const_iterator for end of container
Definition: IdentifiableContainerMT.h:239
IdentifiableContainerMT::const_iterator
Definition: IdentifiableContainerMT.h:79
IdentifiableContainerMT::begin
const_iterator begin() const
return const_iterator for first entry
Definition: IdentifiableContainerMT.h:233
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
CaloCondBlobAlgs_fillNoiseFromASCII.channelId
channelId
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:122
CscRdoValMonAlg::m_cscRdoKey
SG::ReadHandleKey< CscRawDataContainer > m_cscRdoKey
Definition: CscRdoValMonAlg.h:31
CscRawDataCollection
Collection of CSC Raw Hits, arranged according to CSC Detector Elements Author: Ketevi A.
Definition: CscRawDataCollection.h:24
CscRdoValMonAlg.h
CscRawDataCollection::numSamples
uint16_t numSamples() const
Definition: CscRawDataCollection.cxx:8
grepfile.ic
int ic
Definition: grepfile.py:33
CscRawDataCollection.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
CscRawData::samples
const std::vector< uint16_t > & samples() const
Definition: CscRawData.h:130
CscRawData.h
CscRdoValMonAlg::initialize
virtual StatusCode initialize() override
initialize
Definition: CscRdoValMonAlg.cxx:20
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
CscRawData
Class to hold the electronic output for a single CSC readout channel: n sampling ADC data + the addre...
Definition: CscRawData.h:21
CscRdoValMonAlg::m_cscNoiseCut
Gaudi::Property< size_t > m_cscNoiseCut
Definition: CscRdoValMonAlg.h:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.SystemOfUnits.ns
int ns
Definition: SystemOfUnits.py:130
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
Muon::nsw::STGTPSegments::moduleIDBits::stationEta
constexpr uint8_t stationEta
1 to 3
Definition: NSWSTGTPDecodeBitmaps.h:159
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
python.SystemOfUnits.km
int km
Definition: SystemOfUnits.py:95
CscRdoValMonAlg::CscRdoValMonAlg
CscRdoValMonAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CscRdoValMonAlg.cxx:13
Identifier
Definition: IdentifierFieldParser.cxx:14