ATLAS Offline Software
MbtsFex.cxx
Go to the documentation of this file.
1 /*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 #include "MbtsFex.h"
5 
7 #include "TileEvent/TileCell.h"
8 
9 MbtsFex::MbtsFex(const std::string& name, ISvcLocator* pSvcLocator):
10 AthReentrantAlgorithm(name, pSvcLocator)
11 {
12 
13 }
14 
16 {
20  ATH_CHECK( m_dataAccessSvc.retrieve() );
21  ATH_CHECK(m_MbtsBitsKey.initialize());
22  if (! m_monTool.empty() ) ATH_CHECK( m_monTool.retrieve() );
23  ATH_MSG_DEBUG("Init done");
24  return StatusCode::SUCCESS;
25 }
26 
27 StatusCode MbtsFex::execute(const EventContext& context) const
28 {
29 
30  std::vector<const TileCell*> mbtsContainer;
31  ATH_CHECK(m_dataAccessSvc->loadMBTS( context, mbtsContainer));
32  ATH_MSG_DEBUG ("Successfully retrieved mbtsContainer collection of size " << mbtsContainer.size());
33 
34  SG::ReadHandle<TileTBID> TileHelper(m_TileHelperKey, context );
35  std::vector<float> triggerEnergies(xAOD::TrigT2MbtsBits::NUM_MBTS, 0.);
36  std::vector<float> triggerTimes(xAOD::TrigT2MbtsBits::NUM_MBTS, 0.);
37 
38  for(auto mbtsTile: mbtsContainer ){
39  Identifier id=mbtsTile->ID();
40 
41  // MBTS Id type is "side" +/- 1
42  int type_id = TileHelper->type(id);
43 
44  // MBTS Id channel is "eta" 0-1 zero is closer to beam pipe
45  unsigned int channel_id = TileHelper->channel(id);
46 
47  // MBTS Id module is "phi" 0-7
48  unsigned int module_id = TileHelper->module(id);
49 
50  ATH_MSG_DEBUG("type_id = " << type_id<<" channel_id = " << channel_id<<" module_id = " << module_id);
51 
52  // Catch errors
53  if(abs(type_id) != 1) {
54  ATH_MSG_WARNING("MBTS identifier type is out of range");
55  continue;
56  }
57  if( channel_id > 1 ){
58  ATH_MSG_WARNING("MBTS identifier channel is out of range");
59  continue;
60  }
61  if( module_id > 7 ){
62  ATH_MSG_WARNING("MBTS identifier module is out of range");
63  continue;
64  }
65 
66  unsigned int bit_pos = 0; // The position of the bit
67 
68  if(type_id == -1) { // C-side
69  bit_pos += 16;
70  }
71 
72  bit_pos += channel_id*8;
73  bit_pos += module_id;
74 
75  ATH_CHECK(bit_pos < triggerEnergies.size());
76  triggerEnergies[bit_pos] = mbtsTile->energy();
77  ATH_MSG_DEBUG("Counter id = " << bit_pos << ", energy = " << triggerEnergies[bit_pos] << " pC");
78 
79 
80  ATH_CHECK(bit_pos < triggerTimes.size());
81  triggerTimes[bit_pos] = mbtsTile->time();
82  ATH_MSG_DEBUG("Counter id = " << bit_pos << ", time = " << triggerTimes[bit_pos] << " ns");
83 
84  }
85  // channel IDs are deined in this tedious way in order to allow for a quick remappings or channels removal if needed
86  // e.g. entering -1 in any position will move that channel entries out of scope of the monitoring histograms
87  static const std::vector<int> channelID({0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
88  16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31});
89  auto mon_triggerEnergies = Monitored::Collection("triggerEnergies",triggerEnergies);
90  auto mon_channelID = Monitored::Collection("channelID", channelID);
91  auto mon_triggerTimes = Monitored::Collection("triggerTimes",triggerTimes);
92  double weightedTime = 0;
93  double weights = 0;
94 
95  for ( size_t i = 0; i < xAOD::TrigT2MbtsBits::NUM_MBTS; ++i) {
96  weightedTime += triggerTimes[i] * triggerEnergies[i];
97  weights += triggerEnergies[i];
98  }
99  const double timeDelta = (weights == 0 ? -999.0 : weightedTime/weights);
100  auto mon_weightedTimeDelta = Monitored::Scalar("timeDelta", timeDelta);
101 
102  Monitored::Group(m_monTool, mon_triggerEnergies, mon_channelID, mon_triggerTimes, mon_weightedTimeDelta);
103 
105 
106  auto trigMbtsContainer = std::make_unique< xAOD::TrigT2MbtsBitsContainer>();
107  auto trigMbtsAuxContainer = std::make_unique< xAOD::TrigT2MbtsBitsAuxContainer>();
108  trigMbtsContainer->setStore(trigMbtsAuxContainer.get());
109 
110  xAOD::TrigT2MbtsBits * mbtsObj = new xAOD::TrigT2MbtsBits();
111  trigMbtsContainer->push_back(mbtsObj);
112 
113  mbtsObj->setTriggerEnergies(triggerEnergies);
114  mbtsObj->setTriggerTimes(triggerTimes);
115 
116  ATH_MSG_DEBUG("Recording " << mbtsHandle.key());
117  ATH_CHECK(mbtsHandle.record( std::move(trigMbtsContainer), std::move( trigMbtsAuxContainer ) ) );
118  return StatusCode::SUCCESS;
119 }
xAOD::TrigT2MbtsBits_v1::setTriggerTimes
void setTriggerTimes(const std::vector< float > &trigTm)
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::TrigT2MbtsBits_v1::setTriggerEnergies
void setTriggerEnergies(const std::vector< float > &trigEg)
MbtsFex::m_MbtsBitsKey
SG::WriteHandleKey< xAOD::TrigT2MbtsBitsContainer > m_MbtsBitsKey
Definition: MbtsFex.h:31
MbtsFex::initialize
virtual StatusCode initialize() override
Definition: MbtsFex.cxx:15
TileTBID::type
int type(const Identifier &id) const
extract type field from TileTB identifier
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:146
TileTBID::module
int module(const Identifier &id) const
extract module field from TileTB identifier
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:150
MbtsFex::m_emScaleKey
SG::ReadCondHandleKey< TileEMScale > m_emScaleKey
Definition: MbtsFex.h:33
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
xAOD::TrigT2MbtsBits
TrigT2MbtsBits_v1 TrigT2MbtsBits
Definition: Event/xAOD/xAODTrigMinBias/xAODTrigMinBias/TrigT2MbtsBits.h:11
lumiFormat.i
int i
Definition: lumiFormat.py:85
MbtsFex::m_TileHelperKey
SG::ReadHandleKey< TileTBID > m_TileHelperKey
Definition: MbtsFex.h:32
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
xAOD::TrigT2MbtsBits_v1
Definition: TrigT2MbtsBits_v1.h:14
TileCell.h
createCoolChannelIdFile.channel_id
channel_id
Definition: createCoolChannelIdFile.py:52
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
MbtsFex::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: MbtsFex.h:36
TileTBID::channel
int channel(const Identifier &id) const
extract channel field from TileTB identifier
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:154
xAOD::TrigT2MbtsBits_v1::NUM_MBTS
static const unsigned int NUM_MBTS
Prints out data members to MsgStream.
Definition: TrigT2MbtsBits_v1.h:39
MbtsFex::MbtsFex
MbtsFex(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MbtsFex.cxx:9
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
weights
Definition: herwig7_interface.h:44
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
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
MbtsFex.h
MbtsFex::m_dataAccessSvc
ServiceHandle< ITrigCaloDataAccessSvc > m_dataAccessSvc
Definition: MbtsFex.h:35
MbtsFex::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: MbtsFex.cxx:27
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
MbtsFex::m_badChannelsKey
SG::ReadCondHandleKey< TileBadChannels > m_badChannelsKey
Definition: MbtsFex.h:34
Identifier
Definition: IdentifierFieldParser.cxx:14