ATLAS Offline Software
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
10 #include "StoreGate/ReadHandle.h"
11 #include "StoreGate/WriteHandle.h"
13 
14 #include <memory>
15 
16 using 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 
35 
36  ATH_CHECK( m_mbtsContainerKey.initialize() );
40 
41  return StatusCode::SUCCESS;
42 }
43 
44 
45 StatusCode 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()) {
115  ATH_MSG_DEBUG( "Event identified as background, set bit 'MBTSTimeDiffHalo' in EventInfo Background word" );
116 
118  EventInfo::MBTSTimeDiffHalo) == false)
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 
125  EventInfo::MBTSTimeDiffCol) == false)
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 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TileCell
Definition: TileCell.h:57
MBTSTimeDiffEventInfoAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Algorithm execute once per event.
Definition: MBTSTimeDiffEventInfoAlg.cxx:45
MBTSTimeDiffEventInfoAlg::m_mask
const uint8_t m_mask
Definition: MBTSTimeDiffEventInfoAlg.h:49
xAOD::EventInfo
EventInfo_v1 EventInfo
Definition of the latest event info version.
Definition: IEventInfoCnvTool.h:17
MBTSTimeDiffEventInfoAlg::m_mbtsCollisionTimeKey
SG::WriteHandleKey< MBTSCollisionTime > m_mbtsCollisionTimeKey
Definition: MBTSTimeDiffEventInfoAlg.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:575
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
MBTSTimeDiffEventInfoAlg::m_minHitsPerSide
Gaudi::Property< unsigned int > m_minHitsPerSide
Definition: MBTSTimeDiffEventInfoAlg.h:37
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MBTSTimeDiffEventInfoAlg::m_mbtsContainerKey
SG::ReadHandleKey< TileCellContainer > m_mbtsContainerKey
Definition: MBTSTimeDiffEventInfoAlg.h:42
EventInfo::MBTSTimeDiffCol
@ MBTSTimeDiffCol
Definition: EventInfo/EventInfo/EventInfo.h:70
xAOD::EventInfo_v1::updateEventFlagBit
bool updateEventFlagBit(const EventFlagSubDet subDet, const size_t bit) const
Change detector flags with update semantics.
Definition: EventInfo_v1.cxx:746
AthCommonMsg< Gaudi::Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
TileTBID::type
int type(const Identifier &id) const
extract type field from TileTB identifier
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:146
MBTSTimeDiffEventInfoAlg::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: MBTSTimeDiffEventInfoAlg.h:43
MBTSTimeDiffEventInfoAlg::initialize
virtual StatusCode initialize() override
Algorithm initialize at begin of job.
Definition: MBTSTimeDiffEventInfoAlg.cxx:25
TileCell::MASK_BADCH
@ MASK_BADCH
Definition: TileCell.h:63
MBTSTimeDiffEventInfoAlg::m_pattern
const uint8_t m_pattern
Definition: MBTSTimeDiffEventInfoAlg.h:50
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:83
TileTBID::module
int module(const Identifier &id) const
extract module field from TileTB identifier
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:150
MBTSTimeDiffEventInfoAlg.h
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
WriteHandle.h
Handle class for recording to StoreGate.
MBTSTimeDiffEventInfoAlg::m_mbts_threshold
Gaudi::Property< float > m_mbts_threshold
Definition: MBTSTimeDiffEventInfoAlg.h:39
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx: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
TileCell::MASK_OVER
@ MASK_OVER
Definition: TileCell.h:64
TileCell::MASK_AMPL
@ MASK_AMPL
Definition: TileCell.h:65
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
MBTSTimeDiffEventInfoAlg::m_tileTBID
const TileTBID * m_tileTBID
Definition: MBTSTimeDiffEventInfoAlg.h:47
TileTBID::channel
int channel(const Identifier &id) const
extract channel field from TileTB identifier
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:154
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
errorcheck.h
Helpers for checking error return status codes and reporting errors.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
TileCell::MASK_TIME
@ MASK_TIME
Definition: TileCell.h:67
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
MBTSTimeDiffEventInfoAlg::m_timeDiffThreshold
Gaudi::Property< float > m_timeDiffThreshold
Definition: MBTSTimeDiffEventInfoAlg.h:35
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
MBTSTimeDiffEventInfoAlg::m_eventInfoDecorKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_eventInfoDecorKey
Definition: MBTSTimeDiffEventInfoAlg.h:45
TileTBID.h
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
ReadHandle.h
Handle class for reading from StoreGate.
python.LArCalib_HVCorrConfig.timediff
timediff
Definition: LArCalib_HVCorrConfig.py:81
EventInfo::MBTSTimeDiffHalo
@ MBTSTimeDiffHalo
Definition: EventInfo/EventInfo/EventInfo.h:70
EventInfo::Background
@ Background
Definition: EventInfo/EventInfo/EventInfo.h:54