ATLAS Offline Software
MM_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 "MM_DigitToRDO.h"
6 
9 
10 MM_DigitToRDO::MM_DigitToRDO(const std::string& name, ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator) {}
11 
13  ATH_MSG_DEBUG(" in initialize()");
14  ATH_CHECK(m_idHelperSvc.retrieve());
17  ATH_CHECK(m_calibTool.retrieve());
19  return StatusCode::SUCCESS;
20 }
21 
22 StatusCode MM_DigitToRDO::execute(const EventContext& ctx) const {
23  using namespace Muon;
24  ATH_MSG_DEBUG("in execute()");
26  ATH_CHECK(digits.isPresent());
27  std::unique_ptr<MM_RawDataContainer> rdos = std::make_unique<MM_RawDataContainer>(m_idHelperSvc->mmIdHelper().module_hash_max());
28 
29  const Nsw_CablingMap* mmCablingMap{nullptr};
30  if (!m_cablingKey.empty()) {
32  if(!readCondHandle.isValid()){
33  ATH_MSG_ERROR("Cannot find Micromegas cabling map!");
34  return StatusCode::FAILURE;
35  }
36  mmCablingMap = readCondHandle.cptr();
37  }
38 
39  for (const MmDigitCollection* digitColl : *digits) {
40  // the identifier of the digit collection is the detector element Id ( multilayer granularity )
41  Identifier digitId = digitColl->identify();
42 
43  // get the hash of the RDO collection
44  IdentifierHash hash;
45  int getRdoCollHash = m_idHelperSvc->mmIdHelper().get_module_hash(digitId, hash);
46  if (getRdoCollHash != 0) {
47  ATH_MSG_ERROR("Could not get the module hash Id");
48  return StatusCode::FAILURE;
49  }
50 
52  if (rdos->addCollection(coll, hash).isFailure()) {
53  ATH_MSG_WARNING("Failed to add collection with hash " << (int)hash);
54  delete coll;
55  continue;
56  }
57 
58  for (const MmDigit* digit : *digitColl) {
59  Identifier newId = digit->identify();
60  // RDO has time and charge in counts
61  int tdo{0}, relBcid{0}, pdo{0};
62  m_calibTool->timeToTdo(ctx, digit->stripResponseTime(), newId, tdo, relBcid);
63  m_calibTool->chargeToPdo(ctx, digit->stripResponseCharge(), newId, pdo);
64 
65  // the cabling map is introduced here for studies of the MM strip misalignment. It does not run in standart jobs (read key is empty)
66  if (mmCablingMap) {
67  std::optional<Identifier> correctedChannelId = mmCablingMap->correctChannel(newId, msgStream());
68  if (!correctedChannelId) {
69  ATH_MSG_DEBUG("Channel was shifted outside its connector and is therefore not decoded into and RDO");
70  continue;
71  }
72  newId = (*correctedChannelId);
73  }
74  // Fill object
75  std::unique_ptr<MM_RawData> rdo = std::make_unique<MM_RawData>(newId, m_idHelperSvc->mmIdHelper().channel(newId),
76  tdo, pdo, relBcid, true);
77  coll->push_back(std::move(rdo));
78  }
79  }
80 
82  ATH_CHECK(writeHanlde.record(std::move(rdos)));
83 
84  ATH_MSG_DEBUG("done execute()");
85  return StatusCode::SUCCESS;
86 }
MmDigitCollection
Definition: MmDigitCollection.h:18
MM_DigitToRDO::initialize
virtual StatusCode initialize() override final
Definition: MM_DigitToRDO.cxx:12
Nsw_CablingMap
Definition: Nsw_CablingMap.h:18
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
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MM_DigitToRDO::m_rdoContainer
SG::WriteHandleKey< Muon::MM_RawDataContainer > m_rdoContainer
Definition: MM_DigitToRDO.h:28
MmDigit
Definition: MmDigit.h:20
MM_DigitToRDO::MM_DigitToRDO
MM_DigitToRDO(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MM_DigitToRDO.cxx:10
MM_DigitToRDO::m_cablingKey
SG::ReadCondHandleKey< Nsw_CablingMap > m_cablingKey
Definition: MM_DigitToRDO.h:33
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:45
Muon::MM_RawDataCollection
Definition: MM_RawDataCollection.h:15
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
MM_DigitToRDO.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MM_DigitToRDO::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MM_DigitToRDO.h:27
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:221
MM_DigitToRDO::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: MM_DigitToRDO.cxx:22
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)
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
MM_DigitToRDO::m_calibTool
ToolHandle< Muon::INSWCalibTool > m_calibTool
Definition: MM_DigitToRDO.h:31
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
MM_DigitToRDO::m_digitContainer
SG::ReadHandleKey< MmDigitContainer > m_digitContainer
Definition: MM_DigitToRDO.h:30
SG::VarHandleBase::isPresent
bool isPresent() const
Is the referenced object present in SG?
Definition: StoreGate/src/VarHandleBase.cxx:394
Identifier
Definition: IdentifierFieldParser.cxx:14