ATLAS Offline Software
Loading...
Searching...
No Matches
MBTSTimeDiffEventInfoAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Tile includes
8
9// Atlas includes
13
14#include <memory>
15
16using xAOD::EventInfo;
17
18/*
19 We have actually about five almost-identical copies of the code below in our repository.
20 I am adding now the sixth because I need it fast. But we should try to clean that up.
21 My suggestion: Adopt the strategy used by LAr, put a object in SG containing MBTS times
22 (and counts, possibly energies) usable by all clients.
23 */
24
26 if (m_minHitsPerSide == 0u) {
27 m_minHitsPerSide = 1; //Avoid div-by-zero later
28 }
29
30 ATH_MSG_INFO("Initializing. MBTS_Threshold=" << m_mbts_threshold
31 << ", MinHitsPerSide=" << m_minHitsPerSide
32 << ", TimeDiffThreshold=" << m_timeDiffThreshold );
33
34 CHECK( detStore()->retrieve(m_tileTBID));
35
36 ATH_CHECK( m_mbtsContainerKey.initialize() );
37 ATH_CHECK( m_eventInfoKey.initialize() );
38 ATH_CHECK( m_mbtsCollisionTimeKey.initialize() );
39 ATH_CHECK( m_eventInfoDecorKey.initialize() );
40
41 return StatusCode::SUCCESS;
42}
43
44
45StatusCode MBTSTimeDiffEventInfoAlg::execute(const EventContext& ctx) const {
46
48
49 float eneA = 0.F;
50 float eneC = 0.F;
51 float timeA = 0.F;
52 float timeC = 0.F;
53 unsigned countA = 0;
54 unsigned countC = 0;
55
57 ATH_CHECK( mbtsContainer.isValid() );
58
59 for (const TileCell* mbtsCell : *mbtsContainer) {
60
61 if (mbtsCell->energy() < m_mbts_threshold) continue;
62 //Got cell above threshold
63
64 const uint8_t qbit1 = mbtsCell->qbit1();
65 const Identifier& id = mbtsCell->ID();
66
67 if (msgLvl(MSG::VERBOSE)) {
68 msg(MSG::VERBOSE) << "Working on MBTS cell side=" << m_tileTBID->type(id)
69 << " module_id=" << m_tileTBID->module(id)
70 << " channel_id=" << m_tileTBID->channel(id)
71 << " Energy=" << mbtsCell->energy()
72 << " Time=" << mbtsCell->time()
73 << " Qbit1=" << (int) qbit1
74 << " Q1Mask(BC|OF|AP|TM)=[" << ((qbit1 & TileCell::MASK_BADCH) != 0)
75 << "|" << ((qbit1 & TileCell::MASK_OVER) != 0) << "|"
76 << ((qbit1 & TileCell::MASK_AMPL) != 0) << "|"
77 << ((qbit1 & TileCell::MASK_TIME) != 0) << "] "
78 // << " Q2Mask(BC|OF|AP|TM)=[" << (qbit2 & TileCell::MASK_BADCH)==1 << "|" << (qbit2 & TileCell::MASK_OVER)==1 << "|"
79 // << (qbit2 & TileCell::MASK_AMPL) << "|" << (qbit2 & TileCell::MASK_TIME) << "]"
80 << endmsg;
81 }
82
83 //Accept only cells with time computed, not known to be bad and no overflow:
84 if ((qbit1 & m_mask) != m_pattern) {
85 ATH_MSG_DEBUG( "Rejected based on quality bits" );
86 continue;
87 }
88
89 // MBTS Id type is "side" +/- 1
90 const int type_id = m_tileTBID->type(id);
91 if (type_id == 1) { //A-side
92 eneA += mbtsCell->energy();
93 timeA += mbtsCell->time();
94 countA++;
95 } else if (type_id == -1) { //C-side
96 eneC += mbtsCell->energy();
97 timeC += mbtsCell->time();
98 countC++;
99 } else {
100 ATH_MSG_WARNING( "Unexpected 'side' from MBTS identifier " );
101 continue;
102 }
103 } //end loop over MBTS cells
104
105 if (countA > 0) timeA /= countA;
106 if (countC > 0) timeC /= countC;
107
108 if (countA > m_minHitsPerSide && countC > m_minHitsPerSide) {
109 ATH_MSG_DEBUG( "Got MBTS cells above threshold on both sides" );
110 const float timediff = fabs(timeA - timeC);
111 ATH_MSG_DEBUG( "Time diff " << timediff << "(" << m_timeDiffThreshold << ")");
112
113 if (eventInfo.isValid()) {
114 if (timediff > m_timeDiffThreshold) {
115 ATH_MSG_DEBUG( "Event identified as background, set bit 'MBTSTimeDiffHalo' in EventInfo Background word" );
116
117 if (eventInfo->updateEventFlagBit(EventInfo::Background,
119
120 ATH_MSG_WARNING( "Failed to set EventInfo Background word!" );
121 } else { //end if above theshold
122 ATH_MSG_DEBUG( "Event identified as collision, set bit 'MBTSTimeDiffCol' in EventInfo Background word" );
123
124 if (eventInfo->updateEventFlagBit(EventInfo::Background,
126 ATH_MSG_WARNING( "Failed to set EventInfo Background word!" );
127 } //end if below threshold
128 } else {
129 ATH_MSG_WARNING( " cannot retrieve EventInfo, will not set Tile information " );
130 }
131 } else {
132 ATH_MSG_DEBUG( "Not enough hits above threshold to distinguish halo from collision event");
133 }
134
136
137 if (mbtsTime.record(std::make_unique<MBTSCollisionTime>(countA, countC, eneA, eneC, timeA, timeC)).isFailure()) {
138 ATH_MSG_WARNING( "Cannot record MBTSCollisionTime " );
139 } else {
140 ATH_MSG_DEBUG( "MBTSCollisionTime recorded in event store" );
141 ATH_MSG_DEBUG( " countA=" << countA
142 << " countC=" << countC
143 << " eneA=" << eneA
144 << " eneC=" << eneC
145 << " timeA=" << timeA
146 << " timeC=" << timeC );
147 }
148
149 return StatusCode::SUCCESS;
150}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
Gaudi::Property< float > m_mbts_threshold
SG::WriteDecorHandleKey< xAOD::EventInfo > m_eventInfoDecorKey
virtual StatusCode execute(const EventContext &ctx) const override
Algorithm execute once per event.
Gaudi::Property< float > m_timeDiffThreshold
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
virtual StatusCode initialize() override
Algorithm initialize at begin of job.
SG::WriteHandleKey< MBTSCollisionTime > m_mbtsCollisionTimeKey
SG::ReadHandleKey< TileCellContainer > m_mbtsContainerKey
Gaudi::Property< unsigned int > m_minHitsPerSide
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
@ MASK_AMPL
Definition TileCell.h:65
@ MASK_TIME
Definition TileCell.h:67
@ MASK_OVER
Definition TileCell.h:64
@ MASK_BADCH
Definition TileCell.h:63
@ Background
The beam background detectors.
EventInfo_v1 EventInfo
Definition of the latest event info version.