ATLAS Offline Software
CscPrdValMonAlg.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)
8 #include "CscPrdValMonAlg.h"
9 
10 using namespace Muon;
11 
12 namespace {
13  struct MonStruct1 {
14  std::vector<float> spid;
15  std::vector<float> secLayer;
16  std::vector<int> lumiblock_mon;
17  std::vector<int> noStrips;
18  std::vector<int> signal_mon;
19  std::vector<int> noise_mon;
20  std::vector<int> clus_phiSig;
21  std::vector<int> clus_etaSig;
22  std::vector<int> clus_etaNoise;
23  std::vector<int> clus_phiNoise;
24  std::vector<int> sideC;
25  std::vector<int> sideA;
26  std::vector<int> measphi;
27  std::vector<int> measeta;
28  };
29 
30  struct MonStruct2 {
31  std::vector<int> count_mon;
32  std::vector<int> scount_mon;
33  std::vector<float> tmp_val_mon;
34  std::vector<float> secLayer;
35  std::vector<int> mphi_true;
36  std::vector<int> mphi_false;
37  std::vector<int> scount_phi_false;
38  std::vector<int> scount_phi_true;
39  std::vector<int> scount_eta_false;
40  std::vector<int> scount_eta_true;
41  };
42 }
43 
44 CscPrdValMonAlg::CscPrdValMonAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
45  AthMonitorAlgorithm(name,pSvcLocator)
46  { }
47 
49  ATH_MSG_INFO( "CscPrdValMonAlg: in initialize" );
50  ATH_CHECK(m_idHelperSvc.retrieve());
51  ATH_CHECK(m_stripFitter.retrieve());
52  ATH_MSG_INFO( "CscPrdValMonAlg " << name() << ": retrieved " << m_stripFitter );
53  ATH_CHECK(m_cscPrdKey.initialize());
54 
56 
57 }
58 
59 //
60 // fillHistograms ----------------------------------------------------------------
61 //
62 StatusCode CscPrdValMonAlg::fillHistograms( const EventContext& ctx ) const {
63 
64  int lumiblock = -1;
66  lumiblock = evt->lumiBlock();
67  auto lumiblock_mon = Monitored::Scalar<int>("lumiblock_mon",lumiblock);
68  if(lumiblock < 0 ) return StatusCode::FAILURE;
69 
70 
71  // Part 1: Get the messaging service, print where you are
72  ATH_MSG_DEBUG( "CscPrdValMonAlg: in fillHistograms" );
73 
75 
76  // ==============================================================================
77  // Field Range Notes
78  // ==============================================================================
79  // StationName unsigned integer maps to "CSS", "CSL", etc.
80  // StationEta [-1,1] -1 for backward, 1 for forward endcap
81  // StationPhi [1,8] increases with Phi
82  // Technology [1] maps to "CSC"
83  // ChamberLayer [1,2] increases with |Z|
84  // WireLayer [1,4] increases with |Z|
85  // MeasuresPhi [0,1] 0 if measures R, 1 if measures Phi
86  // Strip [1,n] increases with R for MeasuresPhi=0
87  // increases with Phi for MeasuresPhi=1
88  // ==============================================================================
89 
90 
91 
92  // Begin Event ==================================================
93  ATH_MSG_DEBUG ( " BEGIN EVENT ========================================== " );
94  ATH_MSG_DEBUG(" Size of PRD Container : " << CscPRD->size());
95 
96  MonStruct1 monstruct1;
97  MonStruct2 monstruct2;
98 
99  for (CscStripPrepDataContainer::const_iterator it = CscPRD->begin(); it != CscPRD->end(); ++it) {
100  const CscStripPrepDataCollection *prd = *it;
101  ATH_MSG_DEBUG ( " Size of Collection : " << prd->size() );
102  size_t nEtaClusWidthCnt[5], nPhiClusWidthCnt[5]; // cluster position in each phi-layer
103  int clusCount[33][9], sigclusCount[33][9];
104  for(size_t kl = 0; kl < 33; kl++ ) {
105  for(size_t km = 0; km < 9; km++ ) {
106  if(kl == 0 && km < 5) {
107  nEtaClusWidthCnt[km] = 0;
108  nPhiClusWidthCnt[km] = 0;
109  }
110  clusCount[kl][km] = 0;
111  sigclusCount[kl][km] = 0;
112  } // end loop over km
113  } // end loop over kl
114 
115  // loop over PRD-clusters
116  // Loop over strip id's vector -- this is just one strip even though its a vector of ID's
117  ATH_MSG_DEBUG ( " BEGIN Loop over Strips ========================================== " );
118  for (CscStripPrepDataCollection::const_iterator ic = (*it)->begin(); ic != (*it)->end(); ++ic) { // for-loop over PRD collection
119  const CscStripPrepData& praw = **ic;
120 
121  // Identify the PRD cluster
122  Identifier prawId = praw.identify();
123  int stationName = m_idHelperSvc->cscIdHelper().stationName(prawId);
124  int chamberType = m_idHelperSvc->cscIdHelper().stationNameIndex("CSS") == stationName ? 0 : 1;
125  int stationEta = m_idHelperSvc->cscIdHelper().stationEta(prawId);
126  int stationPhi = m_idHelperSvc->cscIdHelper().stationPhi(prawId);
127  int wireLayer = m_idHelperSvc->cscIdHelper().wireLayer(prawId);
128  int measuresPhi = m_idHelperSvc->cscIdHelper().measuresPhi(prawId);
129  int stripId = m_idHelperSvc->cscIdHelper().strip(prawId);
130 
131  int sectorNo = stationEta * (2 * stationPhi - chamberType);
132 
133  // compute the indices to store cluster count
134  int ns = sectorNo < 0 ? sectorNo*(-1) : sectorNo+16; // [-16 -> -1] shifted to [1 -> 16] and [+1 -> +16] shifted to [+17 -> +32]
135  int nl = (measuresPhi ? wireLayer : wireLayer+4); // [ 1 -> 4] (phi-layers) and [5 -> 8] (eta-layers)
136 
137  clusCount[ns][nl]++;
138 
139  // indices for ns = [+1 -> +32]; 32 places (index '0' is not counted); allocated 33 places
140  // indices for nl = [+1 -> +8]; 8 places (index '0' is not counted); allocated 9 places
141  ATH_MSG_DEBUG(" ns = " << ns << "\tm_nl = " << nl << "\tm_sec = " << sectorNo << "\t m_lay= "
142  << wireLayer << "\t strip = " << stripId << "\tmPhi = " << measuresPhi);
143 
144 
145  monstruct1.noStrips.push_back(prd->size());
146  // y-axis fill value
147  // sector# +2 layer 1 maps to +2 + 0.2*(1-1) + 0.1 = +2.1
148  // sector# +2 layer 2 maps to +2 + 0.2*(2-1) + 0.1 = +2.3
149  // sector# +2 layer 3 maps to +2 + 0.2*(3-1) + 0.1 = +2.5
150  // sector# +2 layer 4 maps to +2 + 0.2*(4-1) + 0.1 = +2.7
151  monstruct1.secLayer.push_back((sectorNo + 0.2 * (wireLayer - 1) + 0.1));
152  int xfac = measuresPhi ? -1 : 1; // [-1 -> -48] / [+1 -> +192]
153 
154  // x-axis fill value
155  monstruct1.spid.push_back((stripId * xfac));
156  monstruct1.measphi.push_back((int)measuresPhi);
157  monstruct1.measeta.push_back((int)!(measuresPhi));
158 
159  if(m_mapxyrz) {
160 
161  auto x = Monitored::Scalar<float>("x",praw.globalPosition().x());
162  auto y = Monitored::Scalar<float>("y",praw.globalPosition().y());
163  auto z = Monitored::Scalar<float>("z",praw.globalPosition().z());
164  auto r = Monitored::Scalar<float>("r",std::hypot(x,y));
165 
166  fill("CscPrdMonitor",z,r,y,x);
167  ATH_MSG_DEBUG(" prd x = " << x << "\t y = " << y << "\t z = " << z );
168  } // end if(m_mapxyrz)
169 
170  // Fit this strip and get Charge (in units of: # of electrons)
172  res = m_stripFitter->fit(praw);
173 
174  ATH_MSG_DEBUG ( "Strip q +- dq = " << res.charge << " +- " << res.dcharge << "\t t +- dt = "
175  << res.time << " +- " << res.dtime << "\t w +- dw = " << res.width << " +- "
176  << res.dwidth << "\t status= " << res.status << "\t chisq= " << res.chsq);
177 
178  // determine of the cluster is a noise/signal cluster Max_Delta_ADC > NoiseCut
179  float kiloele = 1.0e-3; // multiply # of electrons by this number to get kiloElectrons (1 ke = 1 ADC)
180  float qstripADC = res.charge * kiloele;
181 
182  // By default res.status = -1
183  // if strip fit is success res.status = 0
184  // If fit fails use the peak sample. In this case res.status = 1
185 
186  bool signal = ((qstripADC > m_cscNoiseCut) && (res.status >= 0)) ? true : false;
187 
188 
189 
190  monstruct1.signal_mon.push_back((int)signal);
191  monstruct1.noise_mon.push_back((int)!(signal));
192  monstruct1.clus_phiSig.push_back((int)measuresPhi && (signal));
193  monstruct1.clus_etaSig.push_back((int)(!measuresPhi) && (signal));
194  monstruct1.clus_phiNoise.push_back((int)measuresPhi && !(signal));
195  monstruct1.clus_etaNoise.push_back((int)(!measuresPhi) && !(signal));
196  monstruct1.sideA.push_back((int)(stationEta==1) && (signal));
197  monstruct1.sideC.push_back((int)(stationEta==-1) && (signal));
198 
199  // increment the signal-cluster count
200  if(signal){
201  sigclusCount[ns][nl]++;
202  measuresPhi ? nPhiClusWidthCnt[wireLayer]++ : nEtaClusWidthCnt[wireLayer]++ ;
203  }
204 
205  } // end for-loop over PRD collection
206  ATH_MSG_DEBUG ( " End loop over PRD collection======================" );
207 
208  for(size_t lcnt = 1; lcnt < 5; lcnt++ ) {
209  auto nPhiClusWidthCnt_mon = Monitored::Scalar<int>("nPhiClusWidthCnt_mon",nPhiClusWidthCnt[lcnt]);
210  auto nEtaClusWidthCnt_mon = Monitored::Scalar<int>("nEtaClusWidthCnt_mon",nEtaClusWidthCnt[lcnt]);
211  fill("CscPrdMonitor", nPhiClusWidthCnt_mon, nEtaClusWidthCnt_mon);
212  } // end loop over lcnt
213 
214 
215  int numeta = 0, numphi = 0;
216  int numetasignal = 0, numphisignal = 0;
217 
218  for(int kl = 1; kl < 33; kl++ ) {
219  float tmp_val = 0;
220 
221  for(int km = 1; km < 9; km++ ) {
222  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)
223  bool mphi = (km > 0 && km < 5) ? true : false; // 1,2,3,4 (phi-layers) 5,6,7,8 (eta-layers)
224  std::string wlay = mphi ? "Phi-Layer " : "Eta-Layer: ";
225 
226  int count = clusCount[kl][km];
227  int scount = sigclusCount[kl][km];
228 
229  monstruct2.count_mon.push_back(count);
230  monstruct2.scount_mon.push_back(scount);
231  monstruct2.mphi_true.push_back((int)mphi && count);
232  monstruct2.mphi_false.push_back((int)!(mphi) && count);
233  monstruct2.scount_phi_true.push_back((int)mphi && count && scount);
234  monstruct2.scount_phi_false.push_back((int)mphi && count && !scount);
235  monstruct2.scount_eta_true.push_back((int)!(mphi) && count && scount);
236  monstruct2.scount_eta_false.push_back((int)!(mphi) && count && !scount);
237  monstruct2.secLayer.push_back((kl-16 + 0.2 * (lay - 1) + 0.1));
238 
239  if(count) {
240  if(mphi){
241  numphi += count;
242  if(scount){
243  numphisignal += scount;
244  tmp_val = count - scount;
245  } else tmp_val = count;
246  } else{
247  numeta += count;
248  if(scount){
249  numetasignal += scount;
250  tmp_val = count - scount;
251  } else tmp_val = count;
252  }
253  ATH_MSG_DEBUG ( wlay << "Counts sec: [" << kl-16 << "]\tlayer: [" << km << "] = " <<
254  monstruct2.secLayer.back() << "\t = " << monstruct2.count_mon.back()
255  << "\t" << monstruct2.scount_mon.back());
256  }//end count
257  monstruct2.tmp_val_mon.push_back(tmp_val);
258  } //end for km
259  } //end for kl
260 
261  auto numphi_mon = Monitored::Scalar<int>("numphi_mon", numphi);
262  auto numeta_mon = Monitored::Scalar<int>("numeta_mon", numeta);
263  auto numphi_sig_mon = Monitored::Scalar<int>("numphi_sig_mon", numphisignal);
264  auto numeta_sig_mon = Monitored::Scalar<int>("numeta_sig_mon", numetasignal);
265  auto numphi_diff_mon = Monitored::Scalar<int>("numphi_diff_mon", numphi-numphisignal);
266  auto numeta_diff_mon = Monitored::Scalar<int>("numeta_diff_mon", numeta-numetasignal);
267 
268  fill("CscPrdMonitor", numphi_mon, numeta_mon, numphi_sig_mon, numeta_sig_mon, numphi_diff_mon, numeta_diff_mon );
269 
270  } // end for-loop over container
271 
272 auto noStrips = Monitored::Collection("noStrips",monstruct1.noStrips);
273 auto secLayer1 = Monitored::Collection("secLayer", monstruct1.secLayer);
274 auto spid = Monitored::Collection("spid", monstruct1.spid);
275 auto measphi = Monitored::Collection("measphi", monstruct1.measphi);
276 auto measeta = Monitored::Collection("measeta", monstruct1.measeta);
277 auto signal_mon = Monitored::Collection("signal_mon", monstruct1.signal_mon);
278 auto noise_mon = Monitored::Collection("noise_mon", monstruct1.noise_mon);
279 auto clus_phiSig = Monitored::Collection("clus_phiSig", monstruct1.clus_phiSig);
280 auto clus_etaSig = Monitored::Collection("clus_etaSig", monstruct1.clus_etaSig);
281 auto clus_phiNoise = Monitored::Collection("clus_phiNoise", monstruct1.clus_phiNoise);
282 auto clus_etaNoise = Monitored::Collection("clus_etaNoise", monstruct1.clus_etaNoise);
283 auto sideA = Monitored::Collection("sideA",monstruct1.sideA);
284 auto sideC = Monitored::Collection("sideC",monstruct1.sideC);
285 fill("CscPrdMonitor", spid, secLayer1, lumiblock_mon, noStrips, signal_mon, noise_mon, clus_phiSig, clus_etaSig, clus_etaNoise, clus_phiNoise, sideC, sideA, measphi, measeta );
286 
287 auto count_mon = Monitored::Collection("count_mon", monstruct2.count_mon);
288 auto scount_mon = Monitored::Collection("scount_mon", monstruct2.scount_mon);
289 auto mphi_true = Monitored::Collection("mphi_true", monstruct2.mphi_true);
290 auto mphi_false = Monitored::Collection("mphi_false", monstruct2.mphi_false);
291 auto scount_phi_true = Monitored::Collection("scount_phi_true", monstruct2.scount_phi_true);
292 auto scount_phi_false = Monitored::Collection("scount_phi_false", monstruct2.scount_phi_false);
293 auto scount_eta_true = Monitored::Collection("scount_eta_true", monstruct2.scount_eta_true);
294 auto scount_eta_false = Monitored::Collection("scount_eta_false", monstruct2.scount_eta_false);
295 auto secLayer = Monitored::Collection("secLayer", monstruct2.secLayer);
296 auto tmp_val_mon = Monitored::Collection("tmp_val_mon", monstruct2.tmp_val_mon);
297 fill("CscPrdMonitor", count_mon, scount_mon, tmp_val_mon, secLayer, mphi_true, mphi_false, scount_phi_false, scount_phi_true, scount_eta_false, scount_eta_true );
298 
299 
300  ATH_MSG_DEBUG ( " End EVENT======================" );
301 
302  ATH_MSG_DEBUG( "CscPrdValMonAlg: fillHistograms reports success" );
303 
304  return StatusCode::SUCCESS;
305 } // end CscPrdValMonAlg::fillHistograms()
calibdata.scount
int scount
Definition: calibdata.py:355
beamspotman.r
def r
Definition: beamspotman.py:676
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
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
python.MagFieldUtils.lumiblock
lumiblock
Definition: MagFieldUtils.py:188
CscPrdValMonAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: CscPrdValMonAlg.h:31
dumpTgcDigiDeadChambers.stationName
dictionary stationName
Definition: dumpTgcDigiDeadChambers.py:30
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
CscPrdValMonAlg::m_cscPrdKey
SG::ReadHandleKey< Muon::CscStripPrepDataContainer > m_cscPrdKey
Definition: CscPrdValMonAlg.h:33
CscPrdValMonAlg::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: CscPrdValMonAlg.cxx:62
AthMonitorAlgorithm::m_EventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_EventInfoKey
Key for retrieving EventInfo from StoreGate.
Definition: AthMonitorAlgorithm.h:362
skel.it
it
Definition: skel.GENtoEVGEN.py:396
IdentifiableContainerMT::size
size_t size() const
Duplicate of fullSize for backwards compatability.
Definition: IdentifiableContainerMT.h:206
CscStripPrepDataCollection.h
CscStripPrepData.h
CscPrdValMonAlg.h
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
CscPrdValMonAlg::initialize
virtual StatusCode initialize() override
initialize
Definition: CscPrdValMonAlg.cxx:48
Muon
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Definition: TrackSystemController.h:45
x
#define x
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
CscPrdValMonAlg::m_cscNoiseCut
Gaudi::Property< size_t > m_cscNoiseCut
Definition: CscPrdValMonAlg.h:39
Muon::CscStripPrepData
Class representing the raw data of one CSC strip (for clusters look at Muon::CscPrepData).
Definition: CscStripPrepData.h:40
Cut::signal
@ signal
Definition: SUSYToolsAlg.cxx:67
keylayer_zslicemap.kl
kl
Definition: keylayer_zslicemap.py:109
CscPrdValMonAlg::m_mapxyrz
Gaudi::Property< bool > m_mapxyrz
Definition: CscPrdValMonAlg.h:38
z
#define z
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
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
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.
ICscStripFitter::Result
Definition: ICscStripFitter.h:25
Muon::MuonPrepDataCollection
Template to hold collections of MuonPrepRawData objects.
Definition: MuonPrepDataCollection.h:46
CscPrdValMonAlg::m_stripFitter
ToolHandle< ICscStripFitter > m_stripFitter
Definition: CscPrdValMonAlg.h:36
RPDUtils::sideA
unsigned constexpr int sideA
Definition: RPDUtils.h:16
grepfile.ic
int ic
Definition: grepfile.py:33
Trk::PrepRawData::identify
Identifier identify() const
return the identifier
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
Muon::CscStripPrepData::globalPosition
const Amg::Vector3D & globalPosition() const
return global position reference
Definition: CscStripPrepData.h:141
y
#define y
CscPrdValMonAlg::CscPrdValMonAlg
CscPrdValMonAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CscPrdValMonAlg.cxx:44
RPDUtils::sideC
unsigned constexpr int sideC
Definition: RPDUtils.h:15
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
Identifier
Definition: IdentifierFieldParser.cxx:14