ATLAS Offline Software
Loading...
Searching...
No Matches
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
10
11#include "SCT_CalibHvTool.h"
12#include "SCT_CalibUtilities.h"
13#include "SCT_CalibNumbers.h"
14
15using namespace SCT_CalibAlgs;
16
17namespace {
18void
19initQueue(std::queue<int>& q, const int numvals, const int setval) {
20 for (int i{0}; i<numvals; ++i) q.push(setval);
21}
22}
23
24SCT_CalibHvTool::SCT_CalibHvTool(const std::string& type, const std::string& name, const IInterface* parent) :
25 base_class(type, name, parent)
26{
27}
28
29StatusCode
32 return StatusCode::SUCCESS;
33}
34
35StatusCode
37 return StatusCode::SUCCESS;
38}
39
40bool
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);
55 m_summarytrips.insert(m_summarytrips.end(),n_elements, dummy);
56 m_summarytripslb.insert(m_summarytripslb.end(), n_elements, dummy);
58 return result;
59}
60
61bool
62SCT_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);
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
191bool
193 bool result{true};
194 return result;
195}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Header file for the SCT_CalibHvTool class.
header file for the SCTCalibUtilities
This is a "hash" representation of an Identifier.
ToolHandle< ISCT_DCSConditionsTool > m_DCSConditionsTool
VecInt m_phvtripProcessedEventsInt
SCT_CalibHvTool(const std::string &, const std::string &, const IInterface *)
std::vector< std::vector< std::pair< int, int > > > m_summarytripslb
VecInt m_phvtripRunningTotalInt
SCT_ID::const_id_iterator m_waferItrBegin
virtual StatusCode finalize()
VecInt m_phvtripHasItTripped_prev
std::queue< int > m_prevLBN
virtual bool book()
virtual bool fillFromData()
VecInt m_phvtripHasItTripped
SCT_ID::const_id_iterator m_waferItrEnd
virtual bool fill(const bool fromData=false)
VecInt * m_sct_waferHash
virtual StatusCode initialize()
const SCT_ID * m_pSCTHelper
std::vector< std::queue< int > > m_phvtripQueue
std::vector< std::vector< std::pair< int, int > > > m_summarytrips
std::vector< Identifier >::const_iterator const_id_iterator
Definition SCT_ID.h:73