ATLAS Offline Software
Loading...
Searching...
No Matches
STGC_DigitToRDO.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "STGC_DigitToRDO.h"
6
8
11
12STGC_DigitToRDO::STGC_DigitToRDO(const std::string& name, ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator) {}
13
15 ATH_MSG_DEBUG(" in initialize()");
16 ATH_CHECK(m_idHelperSvc.retrieve());
17 ATH_CHECK(m_rdoContainer.initialize());
18 ATH_CHECK(m_digitContainer.initialize());
19 ATH_CHECK(m_calibTool.retrieve());
20 ATH_CHECK(m_cablingKey.initialize(!m_cablingKey.empty()));
21
22 return StatusCode::SUCCESS;
23}
24
25StatusCode STGC_DigitToRDO::execute(const EventContext& ctx) const {
26 using namespace Muon;
27 ATH_MSG_DEBUG("in execute()");
29 ATH_CHECK(digits.isPresent());
30 std::unique_ptr<STGC_RawDataContainer> rdos = std::make_unique<STGC_RawDataContainer>(m_idHelperSvc->stgcIdHelper().module_hash_max());
31
32 const Nsw_CablingMap* sTgcCablingMap{nullptr};
33 if (!m_cablingKey.empty()) {
35 if(!readCondHandle.isValid()){
36 ATH_MSG_ERROR("Cannot find Micromegas cabling map!");
37 return StatusCode::FAILURE;
38 }
39 sTgcCablingMap = readCondHandle.cptr();
40 }
41
42 for (const sTgcDigitCollection* digitColl : *digits) {
43 // Transform the hash id ( digit collection use detector element ID hash, RDO's use
44 // module Id hash
45 Identifier digitId = digitColl->identify();
46 IdentifierHash hash = m_idHelperSvc->moduleHash(digitId);
47
49 if (rdos->addCollection(coll, hash).isFailure()) {
50 ATH_MSG_WARNING("Failed to add collection with hash " << (int)hash);
51 delete coll;
52 continue;
53 }
54
55 constexpr double lowerTimeBound = Muon::STGC_RawData::s_lowerTimeBound;
56 constexpr int BCWindow = Muon::STGC_RawData::s_BCWindow;
57 for (const sTgcDigit* digit : *digitColl) {
58 // Set proper data time window in simulated sTGC RDOs
59 // BC0 has t = [-12.5, +12.5]
60 // and data will use BC = [-3,+4]
61 // totaling digits within t = [-87.5, 112.5]
62 float digitTime = digit->time();
63 if (digitTime < lowerTimeBound || digitTime >= lowerTimeBound + BCWindow * 25) continue;
64 Identifier id = digit->identify();
65 if (sTgcCablingMap) {
66 std::optional<Identifier> correctedChannelId = sTgcCablingMap->correctChannel(id, msgStream());
67 if (!correctedChannelId) {
68 ATH_MSG_DEBUG("Channel was shifted outside its connector and is therefore not decoded into and RDO");
69 continue;
70 }
71 id = (*correctedChannelId);
72 }
73 bool isDead = digit->isDead();
74 int tdo{0}, pdo{0}, relBCID{0};
75 m_calibTool->timeToTdo(ctx, digitTime, id, tdo, relBCID);
76 m_calibTool->chargeToPdo(ctx, digit->charge(), id, pdo);
77 STGC_RawData* rdo = new STGC_RawData(id, static_cast<unsigned int>(relBCID), static_cast<float>(tdo),
78 static_cast<unsigned int>(tdo), static_cast<unsigned int>(pdo), isDead, true);
79 coll->push_back(rdo);
80 }
81 }
82
84 ATH_CHECK(writeHandle.record(std::move(rdos)));
85
86 ATH_MSG_DEBUG("done execute()");
87 return StatusCode::SUCCESS;
88}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
An algorithm that can be simultaneously executed in multiple threads.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
This is a "hash" representation of an Identifier.
static constexpr int s_BCWindow
static constexpr double s_lowerTimeBound
std::optional< Identifier > correctChannel(const Identifier &id, MsgStream &msg) const
const_pointer_type cptr()
bool isPresent() const
Is the referenced object present in SG?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ToolHandle< Muon::INSWCalibTool > m_calibTool
virtual StatusCode initialize() override final
STGC_DigitToRDO(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadCondHandleKey< Nsw_CablingMap > m_cablingKey
SG::WriteHandleKey< Muon::STGC_RawDataContainer > m_rdoContainer
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
virtual StatusCode execute(const EventContext &ctx) const override final
SG::ReadHandleKey< sTgcDigitContainer > m_digitContainer
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.