ATLAS Offline Software
SCT_CalibHvTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
11 #include "SCT_CalibHvTool.h"
12 #include "SCT_CalibUtilities.h"
13 #include "SCT_CalibNumbers.h"
14 
15 using namespace SCT_CalibAlgs;
16 
17 namespace {
18 void
19 initQueue(std::queue<int>& q, const int numvals, const int setval) {
20  for (int i{0}; i<numvals; ++i) q.push(setval);
21 }
22 }
23 
24 SCT_CalibHvTool::SCT_CalibHvTool(const std::string& type, const std::string& name, const IInterface* parent) :
25  base_class(type, name, parent)
26 {
27 }
28 
31  ATH_CHECK(m_DCSConditionsTool.retrieve());
32  return StatusCode::SUCCESS;
33 }
34 
37  return StatusCode::SUCCESS;
38 }
39 
40 bool
42  bool result{true};
43  ATH_MSG_DEBUG("Book HVTrips");
44  //now initialize the queues (fill 100 spots with 0):
45  std::queue<int> qtemp;
46  initQueue(qtemp, m_maxq,0);
47  // need to keep previous bins lbn 4 deep.
48  initQueue(m_prevLBN, 4, 0);
49  std::vector<std::pair <int,int>> dummy;
50  //first set num events processed to 0
54  m_phvtripQueue.insert(m_phvtripQueue.end(), n_elements, qtemp);
58  return result;
59 }
60 
61 bool
62 SCT_CalibHvTool::fill(const bool fromData) {
63  const EventContext& ctx = Gaudi::Hive::currentContext();
64 
65  if (fromData) {
66  return fillFromData();
67  }
68  bool result{true};
69  int lumi_block{0}; //fix me!
70  const int wafersize{static_cast<int>(m_sct_waferHash->size())};
71  int time_stamp{static_cast<int>(ctx.eventID().time_stamp())};
72  int curr_time{time_stamp};
73  int dtime{curr_time - m_phvtripPrevTime};
74  int totalHits{0};
75  if (curr_time<m_phvtripPrevTime) {
76  ATH_MSG_ERROR("Events not sorted properly (time is going backwards!) ");
77  return false;
78  }
79  // for first event
80  if (m_phvtripFirstTime > curr_time) {
81  m_phvtripFirstTime = curr_time;
82  }
83  bool newbin{false};
84  // check if we have a new time bin, if we do pop off the back (oldest) part
85  // of the queue and enqueue 0 for every wafer
86  int maxtbins{5};
87  if (dtime > maxtbins) {
88  newbin = true;
89  ATH_MSG_DEBUG(" new t bin " << dtime <<" since start "<< (curr_time-(m_phvtripFirstTime-1.01)));
91  for (int iwaf{0}; iwaf!=n_elements; ++iwaf) {
92  m_phvtripQueue[iwaf].pop();
93  m_phvtripQueue[iwaf].push(0);
94  m_phvtripHasItTripped[iwaf]=0;
95  }
96  }
97  // Loop over all hits in the event
98  bool isgoodnow;
99  for( int itrk{0}; itrk!=wafersize; ++itrk) {
100  int waferhash{(*m_sct_waferHash)[itrk]};
101  Identifier waferId{m_pSCTHelper->wafer_id(waferhash)};
102  Identifier moduleId{m_pSCTHelper->module_id(waferId)};
103  //step one is to make sure this one isn't already know to be messed up:
104  isgoodnow = m_DCSConditionsTool->isGood(moduleId,InDetConditions::SCT_MODULE);
105  ATH_MSG_DEBUG("checked is good "<< isgoodnow);
106  if (isgoodnow) {
107  int numhits{(*m_sct_numHitsInWafer)[itrk]};
108  totalHits += numhits;
113  double limit{m_relativetriplimit * static_cast<double>(m_phvtripRunningTotalInt[waferhash]) / (static_cast<double>(curr_time)-(static_cast<double>(m_phvtripFirstTime-0.01)))};
114 
115  ATH_MSG_DEBUG("waferhash "<<waferhash<<" itrk "<<itrk <<" run tot "<< m_phvtripRunningTotalInt[waferhash]
116  <<" num hits "<<numhits<<" evnts processed "<< m_phvtripProcessedEventsInt[waferhash] <<" limit "<<limit
117  <<" abs limit, rel limit "<<m_absolutetriplimit<<","<< m_relativetriplimit<<" max bins "<<maxtbins);
118 
119  if ( ((numhits + m_phvtripQueue[waferhash].back() )/ static_cast<double>(maxtbins) ) > m_absolutetriplimit
120  and ((numhits + m_phvtripQueue[waferhash].back() )/ static_cast<double>(maxtbins) ) > limit) {
121  //read back queue and see if the high hit rate is persistant for 3 previous bins (a bin is 5 seconds by default)
122  for (int iq{0}; iq<m_maxq; ++iq) {
123  m_tq[iq]=m_phvtripQueue[waferhash].front();
124  m_phvtripQueue[waferhash].pop();
125  }
126  if (m_tq[m_maxq-2]/static_cast<double>(maxtbins) > limit && m_tq[m_maxq-3]/static_cast<double>(maxtbins) > limit && m_tq[m_maxq-4]/static_cast<double>(maxtbins) > limit) {
127  // found a persistent trip/thing
128  ATH_MSG_DEBUG("Found a potential trip in SCT wafer " << waferhash);
129  ATH_MSG_DEBUG("TRIP more info: limit = " << limit << " abslimit = " << m_absolutetriplimit
130  << " hits/secs now = " << ((numhits + m_tq[m_maxq-1])/ maxtbins )
131  << " running total = " << m_phvtripRunningTotalInt[waferhash]
132  << " running average = " << m_phvtripRunningTotalInt[waferhash] / (curr_time-(m_phvtripFirstTime-1.01)));
133  m_phvtripHasItTripped[waferhash] = (numhits + m_tq[m_maxq-1] );
134  } // end trip found
135 
136  //put queue back the way we found it:
137  for (int iq{0}; iq < m_maxq; ++iq) {
138  m_phvtripQueue[waferhash].push(m_tq[iq]);
139  }
140  } // end potential trip id
141  //incriment event counter
142  m_phvtripProcessedEventsInt[waferhash] += 1;
143  //recalcuate running total:
144  m_phvtripRunningTotalInt[waferhash] += numhits;
145  m_phvtripQueue[waferhash].back() += numhits;
146  } //end is good check
147  else {
148  ATH_MSG_DEBUG("Was a bad module already: " << waferhash);
149  }
150  } //end loop over tracks
151 
152  // text output, summarizing the event
153  //if new bin summarzie the previous event.
154  if (newbin) {
157  for (; waferItr not_eq waferItrE; ++waferItr) {
158  Identifier waferId{*waferItr};
159  IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
160  if (m_phvtripHasItTripped_prev[waferHash]>0) {
161  std::pair<int, int> wp;
162  wp.first = (m_phvtripPrevTime - 3*maxtbins);
163  wp.second = (m_phvtripPrevTime + maxtbins);
164  m_summarytrips[waferHash].push_back(wp);
165  std::pair<int,int> lbn;
166  lbn.first = m_prevLBN.front();
167  lbn.second = m_prevLBN.back();
168  m_summarytripslb[waferHash].push_back(lbn);
169  }
170  }
171  m_phvtripPrevTime = curr_time; //reset prev and current time
172  m_prevLBN.pop();
173  m_prevLBN.push(lumi_block);
174  }
175 
176  for (int iwaf{0}; iwaf!=n_elements; ++iwaf) {
177  ATH_MSG_DEBUG("mod "<< iwaf <<" events with that waf " <<m_phvtripProcessedEventsInt[iwaf] << " numhits "<<m_phvtripRunningTotalInt[iwaf]);
178  ATH_MSG_DEBUG("did it trip "<<m_phvtripHasItTripped[iwaf]);
179  if (m_phvtripHasItTripped[iwaf]) {
180  ATH_MSG_DEBUG("TRIP more info: abslimit = "<< m_absolutetriplimit
181  <<" hits/secs now = "<< ( m_phvtripQueue[iwaf].back() / maxtbins )
182  <<" running total = "<< m_phvtripRunningTotalInt[iwaf]
183  <<" running average = "<< m_phvtripRunningTotalInt[iwaf] / (curr_time-(m_phvtripFirstTime-1.01)));
184  }
185  }
186  if (m_outputLowHits && (totalHits < m_lowHitCut) ) {
187  }
188  return result;
189 }
190 
191 bool
193  bool result{true};
194  return result;
195 }
SCT_CalibHvTool::m_outputLowHits
bool m_outputLowHits
Definition: SCT_CalibHvTool.h:90
SCT_CalibHvTool.h
SCT_CalibHvTool::m_phvtripQueue
std::vector< std::queue< int > > m_phvtripQueue
Definition: SCT_CalibHvTool.h:75
SCT_CalibHvTool::initialize
virtual StatusCode initialize()
Definition: SCT_CalibHvTool.cxx:30
get_generator_info.result
result
Definition: get_generator_info.py:21
SCT_CalibHvTool::m_waferItrEnd
SCT_ID::const_id_iterator m_waferItrEnd
Definition: SCT_CalibHvTool.h:67
SCT_CalibHvTool::m_sct_waferHash
VecInt * m_sct_waferHash
Definition: SCT_CalibHvTool.h:69
SCT_CalibHvTool::fillFromData
virtual bool fillFromData()
Definition: SCT_CalibHvTool.cxx:192
SCT_CalibHvTool::m_relativetriplimit
double m_relativetriplimit
Definition: SCT_CalibHvTool.h:85
SCT_CalibHvTool::SCT_CalibHvTool
SCT_CalibHvTool(const std::string &, const std::string &, const IInterface *)
Definition: SCT_CalibHvTool.cxx:24
SCT_ID::const_id_iterator
std::vector< Identifier >::const_iterator const_id_iterator
Definition: SCT_ID.h:73
SCT_CalibHvTool::m_phvtripHasItTripped_prev
VecInt m_phvtripHasItTripped_prev
Definition: SCT_CalibHvTool.h:80
SCT_CalibAlgs
Definition: IElementStreamer.cxx:13
SCT_CalibHvTool::m_pSCTHelper
const SCT_ID * m_pSCTHelper
Definition: SCT_CalibHvTool.h:65
SCT_ID::module_id
Identifier module_id(int barrel_ec, int layer_disk, int phi_module, int eta_module) const
For a single crystal.
Definition: SCT_ID.h:416
SCT_CalibHvTool::book
virtual bool book()
Definition: SCT_CalibHvTool.cxx:41
SCT_CalibHvTool::m_absolutetriplimit
double m_absolutetriplimit
Definition: SCT_CalibHvTool.h:84
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SCT_CalibHvTool::m_summarytripslb
std::vector< std::vector< std::pair< int, int > > > m_summarytripslb
Definition: SCT_CalibHvTool.h:89
InDetConditions::SCT_MODULE
@ SCT_MODULE
Definition: InDetHierarchy.h:14
lumiFormat.i
int i
Definition: lumiFormat.py:85
SCT_CalibHvTool::m_DCSConditionsTool
ToolHandle< ISCT_DCSConditionsTool > m_DCSConditionsTool
Definition: SCT_CalibHvTool.h:63
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
SCT_CalibHvTool::n_elements
@ n_elements
Definition: SCT_CalibHvTool.h:59
SCT_CalibHvTool::m_phvtripRunningTotalInt
VecInt m_phvtripRunningTotalInt
Definition: SCT_CalibHvTool.h:77
test_pyathena.parent
parent
Definition: test_pyathena.py:15
python.xAODType.dummy
dummy
Definition: xAODType.py:4
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SCT_ID::wafer_hash
IdentifierHash wafer_hash(const Identifier &wafer_id) const
wafer hash from id - optimized
Definition: SCT_ID.h:492
PlotSFuncertainty.wp
wp
Definition: PlotSFuncertainty.py:112
SCT_CalibNumbers.h
SCT_CalibHvTool::fill
virtual bool fill(const bool fromData=false)
Definition: SCT_CalibHvTool.cxx:62
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
SCT_CalibHvTool::m_phvtripHasItTripped
VecInt m_phvtripHasItTripped
Definition: SCT_CalibHvTool.h:79
SCT_CalibHvTool::m_prevLBN
std::queue< int > m_prevLBN
Definition: SCT_CalibHvTool.h:76
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
SCT_CalibHvTool::m_tq
int m_tq[100]
Definition: SCT_CalibHvTool.h:86
SCT_CalibHvTool::finalize
virtual StatusCode finalize()
Definition: SCT_CalibHvTool.cxx:36
extractSporadic.q
list q
Definition: extractSporadic.py:98
SCT_CalibHvTool::m_phvtripPrevTime
int m_phvtripPrevTime
Definition: SCT_CalibHvTool.h:82
SCT_CalibHvTool::m_maxq
int m_maxq
Definition: SCT_CalibHvTool.h:73
SCT_CalibHvTool::m_phvtripProcessedEventsInt
VecInt m_phvtripProcessedEventsInt
Definition: SCT_CalibHvTool.h:78
SCT_ID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module, int side) const
For a single side of module.
Definition: SCT_ID.h:464
SCT_CalibHvTool::m_waferItrBegin
SCT_ID::const_id_iterator m_waferItrBegin
Definition: SCT_CalibHvTool.h:66
SCT_CalibUtilities.h
updateCoolNtuple.limit
int limit
Definition: updateCoolNtuple.py:45
SCT_CalibHvTool::m_lowHitCut
int m_lowHitCut
Definition: SCT_CalibHvTool.h:91
SCT_CalibHvTool::m_summarytrips
std::vector< std::vector< std::pair< int, int > > > m_summarytrips
Definition: SCT_CalibHvTool.h:88
LB_AnalMapSplitter.lbn
lbn
Definition: LB_AnalMapSplitter.py:28
SCT_CalibHvTool::m_phvtripFirstTime
int m_phvtripFirstTime
Definition: SCT_CalibHvTool.h:83
Identifier
Definition: IdentifierFieldParser.cxx:14