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