ATLAS Offline Software
MuonDetailedTrackTruthMaker.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Algorithm producing truth info for PrepRawData, keeping all MC particles contributed to a PRD.
6 // A. Gaponenko, 2006
7 
9 
10 #include <iterator>
11 #include <vector>
12 
14  ATH_MSG_DEBUG("MuonDetailedTrackTruthMaker::initialize()");
15 
16  if (m_PRD_TruthNames.empty()) {
17  ATH_MSG_FATAL("No PRD truth collections have been configured for processing");
18  return StatusCode::FAILURE;
19  }
20  //----------------
21  ATH_CHECK(m_truthTool.retrieve());
22  ATH_MSG_DEBUG("Retrieved tool " << m_truthTool);
23 
25  for (unsigned int i = 0; i < m_trackCollectionNames.size(); i++) {
26  m_detailedTrackTruthNames.at(i)=m_trackCollectionNames.at(i).key() + "DetailedTruth";;
27  ATH_MSG_INFO("process " << m_trackCollectionNames.at(i).key() << " for detailed truth collection "
28  << m_detailedTrackTruthNames.at(i).key());
29  }
30 
31  ATH_CHECK(m_trackCollectionNames.initialize());
32  ATH_CHECK(m_PRD_TruthNames.initialize());
34 
35  //----------------
36  return StatusCode::SUCCESS;
37 }
38 
39 // -----------------------------------------------------------------------------------------------------
40 StatusCode MuonDetailedTrackTruthMaker::execute(const EventContext& ctx) const {
41  ATH_MSG_DEBUG("MuonDetailedTrackTruthMaker::execute()");
42 
43  //----------------------------------------------------------------
44  // Retrieve prep raw data truth
45  std::vector<const PRD_MultiTruthCollection*> prdCollectionVector;
46  for (const auto& truthKey : m_PRD_TruthNames){
47  prdCollectionVector.emplace_back(nullptr);
48  ATH_CHECK(SG::get(prdCollectionVector.back(), truthKey, ctx));
49  }
50 
51  ATH_MSG_DEBUG("Loaded in total "<<prdCollectionVector.size()<<" prd truth collections");
52  //----------------------------------------------------------------
53  // Retrieve track collections
54 
55  int i = 0;
56  for (const auto& trkKey : m_trackCollectionNames) {
57  const TrackCollection* tcol{nullptr};
58  ATH_CHECK(SG::get(tcol, trkKey, ctx));
59 
60  //----------------------------------------------------------------
61  // Produce and store the output.
62 
64  ATH_MSG_DEBUG("Write detailed collection "<<m_detailedTrackTruthNames.at(i).fullKey());
65  ATH_CHECK(dttc.record(std::make_unique<DetailedTrackTruthCollection>()));
66  dttc->setTrackCollection(tcol);
67  m_truthTool->buildDetailedTrackTruth(dttc.ptr(), *tcol, prdCollectionVector, ctx);
68  i++;
69  }
70  return StatusCode::SUCCESS;
71 }
MuonDetailedTrackTruthMaker::m_PRD_TruthNames
SG::ReadHandleKeyArray< PRD_MultiTruthCollection > m_PRD_TruthNames
Definition: MuonDetailedTrackTruthMaker.h:35
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
MuonDetailedTrackTruthMaker::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: MuonDetailedTrackTruthMaker.cxx:40
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
MuonDetailedTrackTruthMaker::initialize
virtual StatusCode initialize() override
Definition: MuonDetailedTrackTruthMaker.cxx:13
MuonDetailedTrackTruthMaker::m_detailedTrackTruthNames
SG::WriteHandleKeyArray< DetailedTrackTruthCollection > m_detailedTrackTruthNames
Definition: MuonDetailedTrackTruthMaker.h:42
MuonDetailedTrackTruthMaker::m_trackCollectionNames
SG::ReadHandleKeyArray< TrackCollection > m_trackCollectionNames
Definition: MuonDetailedTrackTruthMaker.h:38
lumiFormat.i
int i
Definition: lumiFormat.py:85
SG::get
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition: ReadCondHandle.h:287
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector< Trk::Track >
MuonDetailedTrackTruthMaker.h
MuonDetailedTrackTruthMaker::m_truthTool
ToolHandle< Trk::IDetailedTrackTruthBuilder > m_truthTool
Definition: MuonDetailedTrackTruthMaker.h:45
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.