ATLAS Offline Software
Loading...
Searching...
No Matches
MbtsFex.cxx
Go to the documentation of this file.
1/*
2Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4#include "MbtsFex.h"
5
8
9MbtsFex::MbtsFex(const std::string& name, ISvcLocator* pSvcLocator):
10AthReentrantAlgorithm(name, pSvcLocator)
11{
12
13}
14
16{
17 ATH_CHECK( m_emScaleKey.initialize() );
18 ATH_CHECK( m_badChannelsKey.initialize() );
19 ATH_CHECK( m_TileHelperKey.initialize() );
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
27StatusCode 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
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Header file to be included by clients of the Monitored infrastructure.
An algorithm that can be simultaneously executed in multiple threads.
ToolHandle< GenericMonitoringTool > m_monTool
Definition MbtsFex.h:36
SG::WriteHandleKey< xAOD::TrigT2MbtsBitsContainer > m_MbtsBitsKey
Definition MbtsFex.h:31
ServiceHandle< ITrigCaloDataAccessSvc > m_dataAccessSvc
Definition MbtsFex.h:35
virtual StatusCode execute(const EventContext &context) const override
Definition MbtsFex.cxx:27
virtual StatusCode initialize() override
Definition MbtsFex.cxx:15
MbtsFex(const std::string &name, ISvcLocator *pSvcLocator)
Definition MbtsFex.cxx:9
SG::ReadCondHandleKey< TileEMScale > m_emScaleKey
Definition MbtsFex.h:33
SG::ReadHandleKey< TileTBID > m_TileHelperKey
Definition MbtsFex.h:32
SG::ReadCondHandleKey< TileBadChannels > m_badChannelsKey
Definition MbtsFex.h:34
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
void setTriggerTimes(const std::vector< float > &trigTm)
void setTriggerEnergies(const std::vector< float > &trigEg)
static const unsigned int NUM_MBTS
Prints out data members to MsgStream.
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.