ATLAS Offline Software
HLTMBTSMonitoringAlgMT.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 HLTMBTSMonitoringAlgMT::HLTMBTSMonitoringAlgMT(const std::string &name, ISvcLocator *pSvcLocator)
8  : AthMonitorAlgorithm(name, pSvcLocator) {}
9 
11  using namespace Monitored;
14 
16 }
17 
18 StatusCode HLTMBTSMonitoringAlgMT::fillHistograms(const EventContext &context) const {
19  using namespace Monitored;
20 
21  const auto &trigDecTool = getTrigDecisionTool();
22 
23  //==============================================================================
24  // MBTS BITS INFORMATION
25  //==============================================================================
26 
27  auto mbtsbits = SG::makeHandle(m_TrigT2MbtsBitsContainerKey, context);
28  ATH_MSG_DEBUG("MBTS monitoring, handle validity " << mbtsbits.isValid());
29 
30  if (!mbtsbits.isValid()) {
31  ATH_MSG_DEBUG("Could not retrieve mbtsbits");
32  return StatusCode::SUCCESS;
33  }
34 
35  if (mbtsbits->size() == 0) {
36  return StatusCode::SUCCESS;
37  }
38 
39  ATH_CHECK(mbtsbits->size() == 1);
40 
41  std::bitset<32> triggerWord;
42  std::bitset<32> timeWord;
43  static constexpr std::bitset<32> mask = 0xFFFFFFFF;
44 
45  // Parameters to be tuned to correspond to trigger threshold:
46  // static constexpr double timeCut = 20.;
47  // static constexpr double energyCut = 40. / 222.;
48  static constexpr double timeCut = 10e-4; // minimal cut-off : copy from TileMBTSMonitorAlg
49  static constexpr double energyCut = 60. / 222.; // copy from TileMBTSMonitorAlgorithm
50 
51  for (const auto &trig : m_triggerList) {
52  if (not trigDecTool->isPassed(trig, TrigDefs::requireDecision)) {
53  continue;
54  }
55 
56  ATH_MSG_DEBUG("Chain " << trig << " is passed: YES");
57 
58  auto energyMean_A = Scalar<float>("MBTS_A_meanEnergy", 0.);
59  auto energyMean_C = Scalar<float>("MBTS_C_meanEnergy", 0.);
60  auto timeMean_A = Scalar<float>("MBTS_A_meanTime", 0.);
61  auto timeMean_C = Scalar<float>("MBTS_C_meanTime", 0.);
62  auto energyWeightedTime_A = Scalar<float>("MBTS_A_EWTime", 0.);
63  auto energyWeightedTime_C = Scalar<float>("MBTS_C_EWTime", 0.);
64  auto channelID = Scalar<int>("MBTS_channelID", 0);
65  auto mbtsEnergy = Scalar<float>("MBTS_energy", 0.);
66  auto mbtsTime = Scalar<float>("MBTS_time", 0.);
67  int ebaCounters = 0;
68  int ebcCounters = 0;
69 
70  auto TrigCounts = Scalar<std::string>("TrigCounts", trig);
71  fill("MBTSall", TrigCounts);
72 
73  // There always should be only one element in this collection
74  const auto mbts_itr = mbtsbits->front();
75 
76  // Energy (in pC) of signal in a counter (relative to IP), vector for all counters
77  const auto& mbtsHitEnergies = mbts_itr->triggerEnergies();
78 
79  // Time of signal in counter (relative to IP), vector for all counters
80  const auto& mbtsHitTimes = mbts_itr->triggerTimes();
81 
82  ATH_MSG_DEBUG("MBTS hits times container size: " << mbtsHitTimes.size());
83 
84  if (mbtsHitTimes.size() != 32)
86  "MBTS Cell Times are stored incorrectly. The array should have 32 elements (24 should be filled).");
87  if (mbtsHitEnergies.size() != 32)
89  "MBTS Cell Energies are stored incorrectly. The array should have 32 elements (24 should be filled).");
90 
91  for (unsigned i = 0; i < xAOD::TrigT2MbtsBits::NUM_MBTS; i++) {
92  channelID = i;
93  mbtsTime = mbtsHitTimes.at(i);
94  mbtsEnergy = mbtsHitEnergies.at(i);
95 
96  if (mbtsEnergy > energyCut) {
97  triggerWord.set(i);
98  }
99 
100  if (std::abs(mbtsTime) > timeCut) {
101  timeWord.set(i);
102  }
103 
104  if (not(triggerWord[i] and timeWord[i])) {
105  continue;
106  }
107 
108  ATH_MSG_DEBUG("MBTS channelID=" << channelID << ", mbtsEnergy=" << mbtsEnergy << ", mbtsTime=" << mbtsTime);
109  fill(trig + "_shifter", channelID, mbtsTime, mbtsEnergy);
110 
111  if (i < 16) { // A side
112  energyMean_A += mbtsHitEnergies.at(i);
113  timeMean_A += mbtsHitTimes.at(i);
114  energyWeightedTime_A += mbtsHitEnergies.at(i) * mbtsHitTimes.at(i);
115 
116  ebaCounters++;
117  } else { // C side
118  energyMean_C += mbtsHitEnergies.at(i);
119  timeMean_C += mbtsHitTimes.at(i);
120  energyWeightedTime_C += mbtsHitEnergies.at(i) * mbtsHitTimes.at(i);
121 
122  ebcCounters++;
123  }
124  }
125 
126  if (ebaCounters > 0) {
127  energyMean_A /= ebaCounters;
128  timeMean_A /= ebaCounters;
129 
130  if (energyMean_A > 0) {
131  energyWeightedTime_A /= energyMean_A * ebaCounters;
132  }
133 
134  ATH_MSG_DEBUG("Side A energyMean_A=" << energyMean_A << ", timeMean_A=" << timeMean_A
135  << ", energyWeightedTime_A=" << energyWeightedTime_A);
136 
137  fill(trig + "_expert", energyMean_A, timeMean_A);
138  } else {
139  energyWeightedTime_A = -999; // out of range
140  }
141 
142  if (ebcCounters > 0) {
143  energyMean_C /= ebcCounters;
144  timeMean_C /= ebcCounters;
145 
146  if (energyMean_C > 0) {
147  energyWeightedTime_C /= energyMean_C * ebcCounters;
148  }
149 
150  ATH_MSG_DEBUG("Side C energyMean_C=" << energyMean_C << ", timeMean_C=" << timeMean_C
151  << ", energyWeightedTime_C=" << energyWeightedTime_C);
152 
153  fill(trig + "_expert", energyMean_C, timeMean_C);
154  } else {
155  energyWeightedTime_C = -999; // out of range
156  }
157 
158  timeWord &= triggerWord;
159 
160  const std::bitset<8> InnerEbaBitset((triggerWord & timeWord & mask).to_ulong());
161  const std::bitset<8> OuterEbaBitset((((triggerWord & timeWord) >> 8) & mask).to_ulong());
162  const std::bitset<8> InnerEbcBitset((((triggerWord & timeWord) >> 16) & mask).to_ulong());
163  const std::bitset<8> OuterEbcBitset((((triggerWord & timeWord) >> 24) & mask).to_ulong());
164 
165  const auto sideA_hits = InnerEbaBitset.count() + OuterEbaBitset.count();
166  const auto sideC_hits = InnerEbcBitset.count() + OuterEbcBitset.count();
167 
168  auto MBTS_A_hits = Scalar<int>("MBTS_A_hits", sideA_hits);
169  auto MBTS_C_hits = Scalar<int>("MBTS_C_hits", sideC_hits);
170  auto MBTS_diff_timeMean = Scalar<float>("MBTS_diff_timeMean", timeMean_A - timeMean_C);
171  auto MBTS_diff_weightedTimeMean =
172  Scalar<float>("MBTS_diff_weightedTimeMean", energyWeightedTime_A - energyWeightedTime_C);
173 
174  fill(trig + "_shifter", MBTS_A_hits, MBTS_C_hits, energyWeightedTime_A, energyWeightedTime_C, MBTS_diff_timeMean,
175  MBTS_diff_weightedTimeMean);
176  }
177 
178  return StatusCode::SUCCESS;
179 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
AthMonitorAlgorithm::getTrigDecisionTool
const ToolHandle< Trig::TrigDecisionTool > & getTrigDecisionTool() const
Get the trigger decision tool member.
Definition: AthMonitorAlgorithm.cxx:189
HLTMBTSMonitoringAlgMT::HLTMBTSMonitoringAlgMT
HLTMBTSMonitoringAlgMT(const std::string &name, ISvcLocator *pSvcLocator)
Definition: HLTMBTSMonitoringAlgMT.cxx:7
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
AthMonitorAlgorithm
Base class for Athena Monitoring Algorithms.
Definition: AthMonitorAlgorithm.h:36
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
lumiFormat.i
int i
Definition: lumiFormat.py:85
Monitored
Generic monitoring tool for athena components.
Definition: GenericMonitoringTool.h:30
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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.
xAOD::TrigT2MbtsBits_v1::NUM_MBTS
static const unsigned int NUM_MBTS
Prints out data members to MsgStream.
Definition: TrigT2MbtsBits_v1.h:39
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
HLTMBTSMonitoringAlgMT::initialize
virtual StatusCode initialize() override
initialize
Definition: HLTMBTSMonitoringAlgMT.cxx:10
HLTMBTSMonitoringAlgMT.h
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
HLTMBTSMonitoringAlgMT::m_triggerList
Gaudi::Property< std::vector< std::string > > m_triggerList
Definition: HLTMBTSMonitoringAlgMT.h:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
HLTMBTSMonitoringAlgMT::fillHistograms
virtual StatusCode fillHistograms(const EventContext &context) const override
adds event to the monitoring histograms
Definition: HLTMBTSMonitoringAlgMT.cxx:18
HLTMBTSMonitoringAlgMT::m_TrigT2MbtsBitsContainerKey
SG::ReadHandleKey< xAOD::TrigT2MbtsBitsContainer > m_TrigT2MbtsBitsContainerKey
Definition: HLTMBTSMonitoringAlgMT.h:30
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34