ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
EFTracking
FPGATrackSim
FPGATrackSimBankGen
src
FPGATrackSimMatrixMergeAlgo.cxx
Go to the documentation of this file.
1
// Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2
11
12
13
#include "
FPGATrackSimMatrixMergeAlgo.h
"
14
#include "GaudiKernel/MsgStream.h"
15
#include "GaudiKernel/ITHistSvc.h"
16
17
#include "TTree.h"
18
#include "TFile.h"
19
#include "TROOT.h"
20
21
#include <sstream>
22
#include <iostream>
23
#include <fstream>
24
#include <cmath>
25
#include <string>
26
#include <stdio.h>
27
#include <math.h>
28
#include <stdlib.h>
29
30
using namespace
std
;
31
33
// Constructor / Initialize
35
36
FPGATrackSimMatrixMergeAlgo::FPGATrackSimMatrixMergeAlgo
(
const
std::string& name, ISvcLocator* pSvcLocator) :
37
AthAlgorithm
(name, pSvcLocator)
38
{
39
}
40
41
42
StatusCode
FPGATrackSimMatrixMergeAlgo::initialize
()
43
{
44
ATH_MSG_DEBUG
(
"initialize()"
);
45
46
ATH_CHECK
(
m_tHistSvc
.retrieve());
47
if
(
m_Monitor
)
ATH_CHECK
(
bookHistograms
());
48
49
m_nFiles
=
m_fpath
.size();
50
ATH_MSG_INFO
(
"Merging "
<<
m_nFiles
<<
" files"
);
51
52
// Use the first valid file to extract some general information used to intialize
53
TFile *
file
=
nullptr
;
54
std::vector<std::string>
files
=
m_fpath
.value();
55
for
(
int
iFile = 0; iFile <
m_nFiles
; iFile++) {
56
file
= TFile::Open(
files
[iFile].c_str());
57
if
(!
file
)
58
ATH_MSG_WARNING
(
"Could not open "
<<
files
[iFile]);
59
else
{
60
if
(
file
->GetNkeys() != 0)
break
;
61
else
file
->Close();
62
}
63
}
64
if
(!
file
)
return
StatusCode::FAILURE;
65
66
// Get the number of layers and total dimension from a sample region
67
TTree *matrix_tree = (TTree*)
file
->Get(Form(
"am%d"
,
m_region
.value()));
68
matrix_tree->SetBranchAddress(
"nplanes"
, &
m_nLayers
);
69
matrix_tree->SetBranchAddress(
"ndim"
, &
m_nDim
);
70
matrix_tree->SetBranchAddress(
"ndim2"
, &
m_nDim2
);
71
matrix_tree->GetEntry(0);
72
73
// Copy the slice tree into the merged file
74
ATH_CHECK
(
copySliceTree
(
file
));
75
76
file
->Close();
77
78
// Setup the boundaries for the merge
79
if
(
m_allregion
) {
80
m_region_start
= 0;
81
m_region_end
=
m_nRegions
;
82
}
83
else
{
84
m_region_start
=
m_region
;
85
m_region_end
=
m_region
+ 1;
86
}
87
88
m_sector_cum
.resize(
m_nRegions
);
89
90
91
readFiles
();
92
return
StatusCode::SUCCESS;
93
}
94
95
96
StatusCode
FPGATrackSimMatrixMergeAlgo::bookHistograms
()
97
{
98
m_h_nSector
=
new
TH1I(
"h_nSector"
,
"number of sectors in merged file"
, 100, 0, 10000);
99
ATH_CHECK
(
m_tHistSvc
->regHist(
"/TRIGFPGATrackSimMATRIXOUT/h_nSector"
,
m_h_nSector
));
100
101
m_h_nHit
=
new
TH1I(
"h_nHit"
,
"number of hits in sector"
, 100, 0, 10000);
102
ATH_CHECK
(
m_tHistSvc
->regHist(
"/TRIGFPGATrackSimMATRIXOUT/h_nHit"
,
m_h_nHit
));
103
104
m_h_c
=
new
TH1F(
"h_c"
,
"Truth curvature in sector"
,100,-1e-8,1e-8);
105
ATH_CHECK
(
m_tHistSvc
->regHist(
"/TRIGFPGATrackSimMATRIXOUT/h_c"
,
m_h_c
));
106
107
m_h_d
=
new
TH1F(
"h_d"
,
"Truth d0 in sector"
,100,-2.5,2.5);
108
ATH_CHECK
(
m_tHistSvc
->regHist(
"/TRIGFPGATrackSimMATRIXOUT/h_d"
,
m_h_d
));
109
110
m_h_phi
=
new
TH1F(
"h_phi"
,
"Truth phi in sector"
,100,0,6.3);
111
ATH_CHECK
(
m_tHistSvc
->regHist(
"/TRIGFPGATrackSimMATRIXOUT/h_phi"
,
m_h_phi
));
112
113
m_h_coto
=
new
TH1F(
"h_coto"
,
"Truth coto in sector"
,100,-4,4);
114
ATH_CHECK
(
m_tHistSvc
->regHist(
"/TRIGFPGATrackSimMATRIXOUT/h_coto"
,
m_h_coto
));
115
116
m_h_z
=
new
TH1F(
"h_z"
,
"Truth z in sector"
,100,-200,200);
117
ATH_CHECK
(
m_tHistSvc
->regHist(
"/TRIGFPGATrackSimMATRIXOUT/h_z"
,
m_h_z
));
118
119
return
StatusCode::SUCCESS;
120
}
121
122
123
StatusCode
FPGATrackSimMatrixMergeAlgo::copySliceTree
(TFile *
file
)
124
{
125
FPGATrackSimTrackPars
max
;
126
FPGATrackSimTrackPars
min
;
127
FPGATrackSimTrackParsI
nBins;
128
129
// Read old tree
130
TTree *old_tree = (TTree*)
file
->Get(
"slice"
);
131
old_tree->SetBranchAddress(
"c_max"
, &
max
.qOverPt);
132
old_tree->SetBranchAddress(
"c_min"
, &
min
.qOverPt);
133
old_tree->SetBranchAddress(
"c_slices"
, &nBins.qOverPt);
134
135
old_tree->SetBranchAddress(
"phi_max"
, &
max
.phi);
136
old_tree->SetBranchAddress(
"phi_min"
, &
min
.phi);
137
old_tree->SetBranchAddress(
"phi_slices"
, &nBins.phi);
138
139
old_tree->SetBranchAddress(
"d0_max"
, &
max
.d0);
140
old_tree->SetBranchAddress(
"d0_min"
, &
min
.d0);
141
old_tree->SetBranchAddress(
"d0_slices"
, &nBins.d0);
142
143
old_tree->SetBranchAddress(
"z0_max"
, &
max
.z0);
144
old_tree->SetBranchAddress(
"z0_min"
, &
min
.z0);
145
old_tree->SetBranchAddress(
"z0_slices"
, &nBins.z0);
146
147
old_tree->SetBranchAddress(
"eta_max"
, &
max
.eta);
148
old_tree->SetBranchAddress(
"eta_min"
, &
min
.eta);
149
old_tree->SetBranchAddress(
"eta_slices"
, &nBins.eta);
150
151
old_tree->GetEntry(0);
152
153
// Write new tree
154
TTree *new_tree =
new
TTree(
"slice"
,
"Slice boundaries"
);
155
ATH_CHECK
(
m_tHistSvc
->regTree(
"/TRIGFPGATrackSimMATRIXOUT/slice"
, new_tree));
156
157
new_tree->Branch(
"c_max"
, &
max
.qOverPt);
158
new_tree->Branch(
"c_min"
, &
min
.qOverPt);
159
new_tree->Branch(
"c_slices"
, &nBins.qOverPt);
160
161
new_tree->Branch(
"phi_max"
, &
max
.phi);
162
new_tree->Branch(
"phi_min"
, &
min
.phi);
163
new_tree->Branch(
"phi_slices"
, &nBins.phi);
164
165
new_tree->Branch(
"d0_max"
, &
max
.d0);
166
new_tree->Branch(
"d0_min"
, &
min
.d0);
167
new_tree->Branch(
"d0_slices"
, &nBins.d0);
168
169
new_tree->Branch(
"z0_max"
, &
max
.z0);
170
new_tree->Branch(
"z0_min"
, &
min
.z0);
171
new_tree->Branch(
"z0_slices"
, &nBins.z0);
172
173
new_tree->Branch(
"eta_max"
, &
max
.eta);
174
new_tree->Branch(
"eta_min"
, &
min
.eta);
175
new_tree->Branch(
"eta_slices"
, &nBins.eta);
176
177
new_tree->Fill();
178
179
return
StatusCode::SUCCESS;
180
}
181
182
183
// Read each file and accumulate everything into m_sector_cum
184
void
FPGATrackSimMatrixMergeAlgo::readFiles
()
185
{
186
for
(
int
iFile = 0; iFile <
m_nFiles
; iFile++)
187
{
188
// Open the file
189
const
string
&fpath =
m_fpath
[iFile];
190
ATH_MSG_INFO
(
"Reading "
<< fpath);
191
TFile *
file
= TFile::Open(fpath.c_str());
192
193
// Check if the file is valid
194
if
(!
file
||
file
->GetNkeys() == 0)
195
{
196
ATH_MSG_WARNING
(
"Invalid file: "
<< fpath);
197
continue
;
198
}
199
200
// Read each tree
201
for
(
int
region =
m_region_start
; region <
m_region_end
; region++)
202
{
203
TTree *
tree
= (TTree*)
file
->Get(Form(
"am%d"
, region));
204
::readTree
(
m_sector_cum
[region],
tree
,
m_nLayers
,
m_nDim
);
205
delete
tree
;
206
}
207
208
file
->Close();
209
delete
file
;
210
}
211
}
212
214
// Execute
216
217
218
StatusCode
FPGATrackSimMatrixMergeAlgo::execute
(
const
EventContext&
/*ctx*/
)
219
{
220
// Do nothing; this class does not process events. The main algorithm is
221
// called in initialize() and finalize().
222
return
StatusCode::SUCCESS;
223
}
224
226
// Finalize
228
229
StatusCode
FPGATrackSimMatrixMergeAlgo::finalize
()
230
{
231
for
(
int
region =
m_region_start
; region <
m_region_end
; region++)
232
{
233
// Create the tree
234
std::stringstream name;
235
std::stringstream title;
236
name <<
"am"
<< region;
237
title <<
"Ambank "
<< region <<
" parameters"
;
238
TTree*
tree
=
new
TTree(name.str().c_str(), title.str().c_str());
239
ATH_CHECK
(
m_tHistSvc
->regTree(Form(
"/TRIGFPGATrackSimMATRIXOUT/%s"
,
tree
->GetName()),
tree
));
240
241
ATH_MSG_INFO
(
"Sectors found in region "
<< region <<
": "
<<
m_sector_cum
[region].
size
());
242
243
244
// Fill the tree
245
::fillTree
(
m_sector_cum
[region],
tree
,
m_nLayers
,
m_nDim
);
246
247
// Monitoring
248
if
(
m_Monitor
)
249
{
250
ATH_MSG_INFO
(
"Sectors found in region "
<< region <<
": "
<<
m_sector_cum
[region].
size
());
251
m_h_nSector
->Fill(
m_sector_cum
[region].
size
());
252
for
(
auto
& sector_info :
m_sector_cum
[region])
253
{
254
double
coverage = sector_info.second.track_bins.size();
255
m_h_nHit
->Fill(coverage);
256
m_h_c
->Fill(sector_info.second.pars.qOverPt / coverage);
257
m_h_d
->Fill(sector_info.second.pars.d0 / coverage);
258
m_h_phi
->Fill(sector_info.second.pars.phi / coverage);
259
m_h_coto
->Fill(sector_info.second.pars.eta / coverage);
260
m_h_z
->Fill(sector_info.second.pars.z0 / coverage);
261
}
262
}
263
}
264
265
ATH_CHECK
(
m_tHistSvc
->finalize());
266
return
StatusCode::SUCCESS;
267
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
fillTree
void fillTree(AccumulateMap &map, TTree *tree, int nLayers, int nCoords)
Writes the contents of an AccumulateMap into the supplied tree (one entry per sector).
Definition
FPGATrackSimMatrixIO.cxx:226
FPGATrackSimMatrixMergeAlgo.h
Algorithm to merge matrix files, to be used for sector and constant generation.
size
size_t size() const
Number of registered mappings.
min
#define min(a, b)
Definition
cfImp.cxx:40
max
#define max(a, b)
Definition
cfImp.cxx:41
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
FPGATrackSimMatrixMergeAlgo::m_h_phi
TH1F * m_h_phi
Definition
FPGATrackSimMatrixMergeAlgo.h:83
FPGATrackSimMatrixMergeAlgo::readFiles
void readFiles()
Definition
FPGATrackSimMatrixMergeAlgo.cxx:184
FPGATrackSimMatrixMergeAlgo::m_Monitor
Gaudi::Property< bool > m_Monitor
Definition
FPGATrackSimMatrixMergeAlgo.h:64
FPGATrackSimMatrixMergeAlgo::m_nDim
int m_nDim
Definition
FPGATrackSimMatrixMergeAlgo.h:72
FPGATrackSimMatrixMergeAlgo::m_sector_cum
std::vector< AccumulateMap > m_sector_cum
Definition
FPGATrackSimMatrixMergeAlgo.h:50
FPGATrackSimMatrixMergeAlgo::readTree
void readTree(TTree *matrix_tree, int region)
FPGATrackSimMatrixMergeAlgo::m_h_c
TH1F * m_h_c
Definition
FPGATrackSimMatrixMergeAlgo.h:81
FPGATrackSimMatrixMergeAlgo::m_h_coto
TH1F * m_h_coto
Definition
FPGATrackSimMatrixMergeAlgo.h:84
FPGATrackSimMatrixMergeAlgo::m_region
Gaudi::Property< int > m_region
Definition
FPGATrackSimMatrixMergeAlgo.h:62
FPGATrackSimMatrixMergeAlgo::initialize
StatusCode initialize() override
Definition
FPGATrackSimMatrixMergeAlgo.cxx:42
FPGATrackSimMatrixMergeAlgo::finalize
StatusCode finalize() override
Definition
FPGATrackSimMatrixMergeAlgo.cxx:229
FPGATrackSimMatrixMergeAlgo::m_nRegions
Gaudi::Property< int > m_nRegions
Definition
FPGATrackSimMatrixMergeAlgo.h:63
FPGATrackSimMatrixMergeAlgo::bookHistograms
StatusCode bookHistograms()
Definition
FPGATrackSimMatrixMergeAlgo.cxx:96
FPGATrackSimMatrixMergeAlgo::m_nFiles
int m_nFiles
Definition
FPGATrackSimMatrixMergeAlgo.h:70
FPGATrackSimMatrixMergeAlgo::m_fpath
Gaudi::Property< std::vector< std::string > > m_fpath
Definition
FPGATrackSimMatrixMergeAlgo.h:60
FPGATrackSimMatrixMergeAlgo::m_nLayers
int m_nLayers
Definition
FPGATrackSimMatrixMergeAlgo.h:71
FPGATrackSimMatrixMergeAlgo::execute
StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
FPGATrackSimMatrixMergeAlgo.cxx:218
FPGATrackSimMatrixMergeAlgo::m_allregion
Gaudi::Property< bool > m_allregion
Definition
FPGATrackSimMatrixMergeAlgo.h:61
FPGATrackSimMatrixMergeAlgo::m_h_nHit
TH1I * m_h_nHit
Definition
FPGATrackSimMatrixMergeAlgo.h:80
FPGATrackSimMatrixMergeAlgo::m_region_start
int m_region_start
Definition
FPGATrackSimMatrixMergeAlgo.h:67
FPGATrackSimMatrixMergeAlgo::m_h_d
TH1F * m_h_d
Definition
FPGATrackSimMatrixMergeAlgo.h:82
FPGATrackSimMatrixMergeAlgo::m_h_nSector
TH1I * m_h_nSector
Definition
FPGATrackSimMatrixMergeAlgo.h:79
FPGATrackSimMatrixMergeAlgo::copySliceTree
StatusCode copySliceTree(TFile *file)
Definition
FPGATrackSimMatrixMergeAlgo.cxx:123
FPGATrackSimMatrixMergeAlgo::m_h_z
TH1F * m_h_z
Definition
FPGATrackSimMatrixMergeAlgo.h:85
FPGATrackSimMatrixMergeAlgo::m_nDim2
int m_nDim2
Definition
FPGATrackSimMatrixMergeAlgo.h:73
FPGATrackSimMatrixMergeAlgo::FPGATrackSimMatrixMergeAlgo
FPGATrackSimMatrixMergeAlgo(const std::string &name, ISvcLocator *pSvcLocator)
Definition
FPGATrackSimMatrixMergeAlgo.cxx:36
FPGATrackSimMatrixMergeAlgo::m_region_end
int m_region_end
Definition
FPGATrackSimMatrixMergeAlgo.h:68
FPGATrackSimMatrixMergeAlgo::m_tHistSvc
ServiceHandle< ITHistSvc > m_tHistSvc
Definition
FPGATrackSimMatrixMergeAlgo.h:55
FPGATrackSimTrackParsI
Definition
FPGATrackSimTrackPars.h:56
FPGATrackSimTrackPars
Definition
FPGATrackSimTrackPars.h:22
files
std::vector< std::string > files
file names and file pointers
Definition
hcg.cxx:52
std
STL namespace.
tree
TChain * tree
Definition
tile_monitor.h:30
file
TFile * file
Definition
tile_monitor.h:29
Generated on
for ATLAS Offline Software by
1.17.0