ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
EFTracking
FPGATrackSim
FPGATrackSimAlgorithms
src
FPGATrackSimMergeOutputsAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
#include "
FPGATrackSimMergeOutputsAlg.h
"
5
#include "
FPGATrackSimAlgorithms/FPGATrackSimOverlapRemovalTool.h
"
6
#include "
FPGATrackSimObjects/FPGATrackSimLogicalEventInputHeader.h
"
7
#include "
FPGATrackSimObjects/FPGATrackSimLogicalEventOutputHeader.h
"
8
#include "
FPGATrackSimObjects/FPGATrackSimTrack.h
"
9
10
#include "TH2F.h"
11
#include "TTree.h"
12
#include "TFile.h"
13
14
FPGATrackSimMergeOutputsAlg::FPGATrackSimMergeOutputsAlg
(
const
std::string& name, ISvcLocator* pSvcLocator) :
15
AthAlgorithm
(name, pSvcLocator) {
16
}
17
18
19
StatusCode
FPGATrackSimMergeOutputsAlg::initialize
()
20
{
21
22
ATH_MSG_INFO
(
"FPGATrackSimMergeOutputsAlg::initialize()"
);
23
24
ATH_CHECK
(
m_FPGATrackKey
.initialize());
25
ATH_CHECK
(
m_FPGAHitKey
.initialize());
26
ATH_CHECK
(
m_overlapRemovalTool
.retrieve());
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
;
54
m_dataprep
=
new
FPGATrackSimLogicalEventInputHeader
();
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
84
m_eventOutputHeaders
[ifile][iregion] =
new
FPGATrackSimLogicalEventOutputHeader
();
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
108
StatusCode
FPGATrackSimMergeOutputsAlg::execute
(
const
EventContext& ctx) {
109
ATH_MSG_DEBUG
(
"Running on event "
);
110
111
SG::WriteHandle<FPGATrackSimHitCollection>
FPGAHits_Handle (
m_FPGAHitKey
, ctx);
// all the clusters across the regions
112
113
SG::WriteHandle<FPGATrackSimTrackCollection>
FPGATracks_Handle (
m_FPGATrackKey
, ctx);
// all the tracks across the regions
114
// Do this now so we can deference it
115
ATH_CHECK
(FPGATracks_Handle.
record
(std::make_unique<FPGATrackSimTrackCollection>()));
116
FPGATrackSimTrackCollection
*FPGATracks = FPGATracks_Handle.
ptr
();
117
118
// get the hits
119
ATH_CHECK
(FPGAHits_Handle.
record
(std::make_unique<FPGATrackSimHitCollection>()));
120
m_dataprep_tree
->GetEntry(
m_evtlooptree
);
121
for
(
const
auto
& tower :
m_dataprep
->towers()) {
122
const
std::vector<FPGATrackSimHit> hits = tower.hits();
123
for
(
auto
&
hit
: hits) {
124
FPGAHits_Handle->push_back(std::make_unique<FPGATrackSimHit>(std::move(
hit
)));
125
}
126
}
127
128
for
(
unsigned
ivec = 0; ivec <
m_eventOutputHeaders
.size(); ivec++) {
129
for
(
unsigned
iregion = 0; iregion <
N
; iregion++) {
130
if
(!
m_trees
[ivec][iregion])
continue
;
131
if
(
m_evtlooptree
>=
m_trees
[ivec][iregion]->
GetEntries
()) {
132
ATH_MSG_ERROR
(
"Tried reading in more events than the tree had available!"
);
133
return
StatusCode::FAILURE;
134
}
135
m_trees
[ivec][iregion]->GetEntry(
m_evtlooptree
);
136
// Time to load up these tracks! Only bother using ones that already passed OLR
137
std::vector<FPGATrackSimTrack>
const
tracks =
m_eventOutputHeaders
[ivec][iregion]->getFPGATrackSimTracks_1st();
138
m_alltracks
+= tracks.size();
139
for
(
auto
&track : tracks) {
140
if
(track.passedOR()) {
141
auto
track_copy = track;
142
track_copy.rebuildHitPtrs();
143
FPGATracks->push_back(track_copy);
144
}
145
}
146
}
147
}
148
149
// Now run overlap removal on all the tracks that already passed overlap removal between other regions
150
ATH_CHECK
(
m_overlapRemovalTool
->runOverlapRemoval(*FPGATracks));
151
152
if
(
m_SortTracks
) {
153
std::sort
(FPGATracks->begin(), FPGATracks->end(),
154
[] (
FPGATrackSimTrack
const
&
a
,
FPGATrackSimTrack
const
& b) {return (a.getChi2() < b.getChi2() ); });
155
}
156
157
for
(
const
auto
&track : *FPGATracks) {
158
if
(track.passedOR())
m_tracksPassOR
++;
159
}
160
// Increase evtloop
161
++
m_evtloop
;
162
++
m_evtlooptree
;
163
164
return
StatusCode::SUCCESS;
165
}
166
167
StatusCode
FPGATrackSimMergeOutputsAlg::finalize
() {
168
ATH_MSG_INFO
(
"Processed "
<<
m_evtloop
<<
" events."
);
169
ATH_MSG_INFO
(
"Average number of tracks per event = "
<< (
m_alltracks
/
m_evtloop
));
170
ATH_MSG_INFO
(
"Average number of tracks per event passing global OLR = "
<< (
m_tracksPassOR
/
m_evtloop
));
171
return
StatusCode::SUCCESS;
172
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
FPGATrackSimLogicalEventInputHeader.h
FPGATrackSimLogicalEventOutputHeader.h
FPGATrackSimMergeOutputsAlg.h
FPGATrackSimOverlapRemovalTool.h
Overlap removal tool for FPGATrackSimTrack.
FPGATrackSimTrackCollection
std::vector< FPGATrackSimTrack > FPGATrackSimTrackCollection
Definition
FPGATrackSimTrackCollection.h:12
FPGATrackSimTrack.h
hit
bool hit(const Container &ids, int pdgId)
Definition
JetIRCSafeLabelTool.cxx:64
a
static Double_t a
Definition
LArPhysWaveHECTool.cxx:38
GetEntries
TGraphErrors * GetEntries(TH2F *histo)
Definition
TRTCalib_makeplots.cxx:4025
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
FPGATrackSimLogicalEventInputHeader
Definition
FPGATrackSimLogicalEventInputHeader.h:21
FPGATrackSimLogicalEventOutputHeader
Definition
FPGATrackSimLogicalEventOutputHeader.h:12
FPGATrackSimMergeOutputsAlg::m_evtlooptree
Gaudi::Property< unsigned > m_evtlooptree
Definition
FPGATrackSimMergeOutputsAlg.h:53
FPGATrackSimMergeOutputsAlg::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
FPGATrackSimMergeOutputsAlg.cxx:108
FPGATrackSimMergeOutputsAlg::m_alltracks
unsigned long m_alltracks
Definition
FPGATrackSimMergeOutputsAlg.h:56
FPGATrackSimMergeOutputsAlg::m_eventOutputHeaders
std::vector< std::vector< FPGATrackSimLogicalEventOutputHeader * > > m_eventOutputHeaders
Definition
FPGATrackSimMergeOutputsAlg.h:43
FPGATrackSimMergeOutputsAlg::m_overlapRemovalTool
ToolHandle< FPGATrackSimOverlapRemovalTool > m_overlapRemovalTool
Definition
FPGATrackSimMergeOutputsAlg.h:51
FPGATrackSimMergeOutputsAlg::finalize
virtual StatusCode finalize() override
Definition
FPGATrackSimMergeOutputsAlg.cxx:167
FPGATrackSimMergeOutputsAlg::initialize
virtual StatusCode initialize() override
Definition
FPGATrackSimMergeOutputsAlg.cxx:19
FPGATrackSimMergeOutputsAlg::m_dataprep
FPGATrackSimLogicalEventInputHeader * m_dataprep
Definition
FPGATrackSimMergeOutputsAlg.h:45
FPGATrackSimMergeOutputsAlg::m_files
std::vector< TFile * > m_files
Definition
FPGATrackSimMergeOutputsAlg.h:41
FPGATrackSimMergeOutputsAlg::m_tracksPassOR
unsigned long m_tracksPassOR
Definition
FPGATrackSimMergeOutputsAlg.h:57
FPGATrackSimMergeOutputsAlg::FPGATrackSimMergeOutputsAlg
FPGATrackSimMergeOutputsAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
FPGATrackSimMergeOutputsAlg.cxx:14
FPGATrackSimMergeOutputsAlg::m_SortTracks
Gaudi::Property< bool > m_SortTracks
Definition
FPGATrackSimMergeOutputsAlg.h:40
FPGATrackSimMergeOutputsAlg::m_dataprep_tree
TTree * m_dataprep_tree
Definition
FPGATrackSimMergeOutputsAlg.h:46
FPGATrackSimMergeOutputsAlg::m_FPGAHitKey
SG::WriteHandleKey< FPGATrackSimHitCollection > m_FPGAHitKey
Definition
FPGATrackSimMergeOutputsAlg.h:50
FPGATrackSimMergeOutputsAlg::m_inpaths
Gaudi::Property< std::vector< std::string > > m_inpaths
Definition
FPGATrackSimMergeOutputsAlg.h:39
FPGATrackSimMergeOutputsAlg::m_evtloop
double m_evtloop
Definition
FPGATrackSimMergeOutputsAlg.h:55
FPGATrackSimMergeOutputsAlg::N
static const unsigned N
Definition
FPGATrackSimMergeOutputsAlg.h:37
FPGATrackSimMergeOutputsAlg::m_trees
std::vector< std::vector< TTree * > > m_trees
Definition
FPGATrackSimMergeOutputsAlg.h:42
FPGATrackSimMergeOutputsAlg::m_FPGATrackKey
SG::WriteHandleKey< FPGATrackSimTrackCollection > m_FPGATrackKey
Definition
FPGATrackSimMergeOutputsAlg.h:49
FPGATrackSimTrack
Definition
FPGATrackSimTrack.h:23
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.
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
Get
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,...
Definition
comparitor.cxx:181
std::sort
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Definition
DVL_algorithms.h:554
Generated on
for ATLAS Offline Software by
1.17.0