ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimMergeOutputsAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
9
10#include "TH2F.h"
11#include "TTree.h"
12#include "TFile.h"
13
14FPGATrackSimMergeOutputsAlg::FPGATrackSimMergeOutputsAlg (const std::string& name, ISvcLocator* pSvcLocator) :
15 AthAlgorithm(name, pSvcLocator) {
16}
17
18
20{
21
22 ATH_MSG_INFO ( "FPGATrackSimMergeOutputsAlg::initialize()");
23
24 ATH_CHECK(m_FPGATrackKey.initialize());
25 ATH_CHECK(m_FPGAHitKey.initialize());
27
28 unsigned nfiles = m_inpaths.size();
29
30 m_files.resize(nfiles);
31 m_trees.resize(nfiles);
32
33 m_eventOutputHeaders.resize(nfiles);
34
35 bool regionsFound[N]; // did we find this region in ANY file yet?
36 for (unsigned iregion = 0; iregion < N; iregion++) {
37 regionsFound[iregion] = false;
38 }
39
40 bool foundDP=false;
41
42 for (unsigned ifile = 0; ifile < nfiles; ifile++) { // loop over paths to files
43 m_files[ifile] = new TFile(m_inpaths[ifile].c_str(),"READ");
44 if (!m_files[ifile]->IsOpen() || m_files[ifile]->IsZombie()) {
45 ATH_MSG_ERROR("Could not open" << m_inpaths[ifile]);
46 return StatusCode::FAILURE;
47 }
48
49 if (!foundDP) { // only needed for one file
50 m_dataprep_tree = (TTree*)(m_files[ifile]->Get("FPGATrackSimDataPrepTree"));
51 if (m_dataprep_tree) {
52 if (m_dataprep_tree->GetEntries() > 0) {
53 foundDP = true;
55
56 TBranch *dpb = m_dataprep_tree->GetBranch("LogicalEventInputHeader_PostCluster");
57 if (!dpb) {
58 ATH_MSG_ERROR("Could not get LogicalEventInputHeader_PostCluster file " << m_inpaths[ifile]);
59 return StatusCode::FAILURE;
60 }
61 dpb->SetAddress(&m_dataprep);
62 m_dataprep_tree->SetBranchStatus("LogicalEventInputHeader_Pre*",0);
63 }
64 }
65 }
66
67
68 m_trees[ifile].resize(N);
69 m_eventOutputHeaders[ifile].resize(N);
70
71 for (unsigned iregion = 0; iregion < N; iregion++) {
72 m_trees[ifile][iregion] = (TTree*)(m_files[ifile]->Get(Form("FPGATrackSimLogicalEventTree_reg%d",iregion)));
73 if (!m_trees[ifile][iregion]) {
74 continue;
75 }
76 else if (regionsFound[iregion]) {
77 ATH_MSG_ERROR("Found two files with region number " << iregion << " and I do not know which one to use!");
78 return StatusCode::FAILURE;
79 }
80 else {
81 regionsFound[iregion] = true;
82 }
83
85 TBranch *b = m_trees[ifile][iregion]->GetBranch("LogicalEventOutputHeader");
86 if (!b) {
87 ATH_MSG_ERROR("Could not get LogicalEventOutputHeader in file " << m_inpaths[ifile]);
88 return StatusCode::FAILURE;
89 }
90 b->SetAddress(&m_eventOutputHeaders[ifile][iregion]);
91
92 m_trees[ifile][iregion]->SetBranchStatus("LogicalEventSecond*",0);
93 m_trees[ifile][iregion]->SetBranchStatus("LogicalEventFirstP*",0);
94 m_trees[ifile][iregion]->SetBranchStatus("LogicalEventSpace*",0);
95 m_trees[ifile][iregion]->SetBranchStatus("LogicalEventStrip*",0);
96
97 }
98 }
99
100 if (!foundDP) {
101 ATH_MSG_ERROR("Did not find the DP tree");
102 return StatusCode::FAILURE;
103 }
104
105 return StatusCode::SUCCESS;
106}
107
109 ATH_MSG_DEBUG ("Running on event ");
110
111 const EventContext& ctx = getContext();
112 SG::WriteHandle<FPGATrackSimHitCollection> FPGAHits_Handle (m_FPGAHitKey, ctx); // all the clusters across the regions
113
114 SG::WriteHandle<FPGATrackSimTrackCollection> FPGATracks_Handle (m_FPGATrackKey, ctx); // all the tracks across the regions
115 // Do this now so we can deference it
116 ATH_CHECK(FPGATracks_Handle.record (std::make_unique<FPGATrackSimTrackCollection>()));
117 FPGATrackSimTrackCollection *FPGATracks = FPGATracks_Handle.ptr();
118
119 // get the hits
120 ATH_CHECK(FPGAHits_Handle.record (std::make_unique<FPGATrackSimHitCollection>()));
121 m_dataprep_tree->GetEntry(m_evtloop);
122 for (const auto & tower : m_dataprep->towers()) {
123 const std::vector<FPGATrackSimHit> hits = tower.hits();
124 for (auto& hit : hits) {
125 FPGAHits_Handle->push_back(std::make_unique<FPGATrackSimHit>(std::move(hit)));
126 }
127 }
128
129 for (unsigned ivec = 0; ivec < m_eventOutputHeaders.size(); ivec++) {
130 for (unsigned iregion = 0; iregion < N; iregion++) {
131 if (!m_trees[ivec][iregion]) continue;
132 if (m_evtloop >= m_trees[ivec][iregion]->GetEntries()) {
133 ATH_MSG_ERROR("Tried reading in more events than the tree had available!");
134 return StatusCode::FAILURE;
135 }
136 m_trees[ivec][iregion]->GetEntry(m_evtloop);
137 // Time to load up these tracks! Only bother using ones that already passed OLR
138 std::vector<FPGATrackSimTrack> const tracks = m_eventOutputHeaders[ivec][iregion]->getFPGATrackSimTracks_1st();
139 m_alltracks += tracks.size();
140 for (const auto &track : tracks) {
141 if (track.passedOR()) FPGATracks->push_back(track);
142 }
143 }
144 }
145
146 // Now run overlap removal on all the tracks that already passed overlap removal between other regions
147 ATH_CHECK(m_overlapRemovalTool->runOverlapRemoval(*FPGATracks));
148 for (const auto &track : *FPGATracks) {
149 if (track.passedOR()) m_tracksPassOR++;
150 }
151 // Increase evtloop
152 m_evtloop++;
153 return StatusCode::SUCCESS;
154}
155
157 ATH_MSG_INFO("Processed " << m_evtloop << " events.");
158 ATH_MSG_INFO("Average number of tracks per event = " << (m_alltracks/m_evtloop));
159 ATH_MSG_INFO("Average number of tracks per event passing global OLR = " << (m_tracksPassOR/m_evtloop));
160 return StatusCode::SUCCESS;
161}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Overlap removal tool for FPGATrackSimTrack.
std::vector< FPGATrackSimTrack > FPGATrackSimTrackCollection
TGraphErrors * GetEntries(TH2F *histo)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
std::vector< std::vector< FPGATrackSimLogicalEventOutputHeader * > > m_eventOutputHeaders
ToolHandle< FPGATrackSimOverlapRemovalTool > m_overlapRemovalTool
virtual StatusCode finalize() override
virtual StatusCode initialize() override
FPGATrackSimLogicalEventInputHeader * m_dataprep
FPGATrackSimMergeOutputsAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteHandleKey< FPGATrackSimHitCollection > m_FPGAHitKey
Gaudi::Property< std::vector< std::string > > m_inpaths
virtual StatusCode execute() override
std::vector< std::vector< TTree * > > m_trees
SG::WriteHandleKey< FPGATrackSimTrackCollection > m_FPGATrackKey
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
T * Get(TFile &f, const std::string &n, const std::string &dir="", const chainmap_t *chainmap=0, std::vector< std::string > *saved=0)
get a histogram given a path, and an optional initial directory if histogram is not found,...