ATLAS Offline Software
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 
12 STGC_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());
19  ATH_CHECK(m_calibTool.retrieve());
21 
22  return StatusCode::SUCCESS;
23 }
24 
25 StatusCode 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 }
Nsw_CablingMap
Definition: Nsw_CablingMap.h:18
STGC_DigitToRDO::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: STGC_DigitToRDO.cxx:25
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
IdentifiableContainerMT::addCollection
virtual StatusCode addCollection(const T *coll, IdentifierHash hashId) override final
insert collection into container with id hash if IDC should not take ownership of collection,...
Definition: IdentifiableContainerMT.h:300
STGC_DigitToRDO::m_digitContainer
SG::ReadHandleKey< sTgcDigitContainer > m_digitContainer
Definition: STGC_DigitToRDO.h:32
STGC_DigitToRDO::initialize
virtual StatusCode initialize() override final
Definition: STGC_DigitToRDO.cxx:14
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
STGC_DigitToRDO.h
STGC_DigitToRDO::m_cablingKey
SG::ReadCondHandleKey< Nsw_CablingMap > m_cablingKey
Definition: STGC_DigitToRDO.h:37
checkRpcDigits.digit
digit
Definition: checkRpcDigits.py:186
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
Muon
This class provides conversion from CSC RDO data to CSC Digits.
Definition: TrackSystemController.h:49
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
Muon::STGC_RawData::s_lowerTimeBound
static constexpr double s_lowerTimeBound
Definition: STGC_RawData.h:67
sTgcDigit
Definition: sTgcDigit.h:20
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Muon::STGC_RawData
Definition: STGC_RawData.h:14
sTgcDigitCollection
Definition: sTgcDigitCollection.h:18
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
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
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
STGC_DigitToRDO::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: STGC_DigitToRDO.h:29
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.
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
STGC_DigitToRDO::m_calibTool
ToolHandle< Muon::INSWCalibTool > m_calibTool
Definition: STGC_DigitToRDO.h:34
Muon::STGC_RawDataCollection
Definition: STGC_RawDataCollection.h:18
STGC_DigitToRDO::STGC_DigitToRDO
STGC_DigitToRDO(const std::string &name, ISvcLocator *pSvcLocator)
Definition: STGC_DigitToRDO.cxx:12
STGC_DigitToRDO::m_rdoContainer
SG::WriteHandleKey< Muon::STGC_RawDataContainer > m_rdoContainer
Definition: STGC_DigitToRDO.h:30
NswCalibDbTimeChargeData
Definition: NswCalibDbTimeChargeData.h:19
SG::VarHandleBase::isPresent
bool isPresent() const
Is the referenced object present in SG?
Definition: StoreGate/src/VarHandleBase.cxx:397
Muon::STGC_RawData::s_BCWindow
static constexpr int s_BCWindow
Definition: STGC_RawData.h:70