ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimConstGenAlgo.h
Go to the documentation of this file.
1// Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3#ifndef FPGATrackSimConstGenAlgo_h
4#define FPGATrackSimConstGenAlgo_h
5
26
27#include "GaudiKernel/ITHistSvc.h"
29#include "FPGATrackSimObjects/FPGATrackSimTypes.h" //module_t typedef
34
35#include "TMatrixDfwd.h"
36#include <string>
37#include <vector>
38#include <memory>
39
42class TTree;
43class TH1F;
44class TFile;
45
46// data structure that contain definition of geometrical constants for linear fits
48{
49 //these are the matrices themselves
50 std::vector<double> Vd0; // impact paramers coefs
51 std::vector<double> Vcurvature; // curvature coefs
52 std::vector<double> Vphi; // phi coefs
53 std::vector<double> Vz0; // z0 coefs
54 std::vector<double> Veta; // eta coefs
55 vector2D<double> kernel; // kernel (covariance matrix). Size (ndim - npar, ndim)
56 std::vector<double> kaverages; // averages, useful to keep track of
57
58 // these are the constant/offset values
60
61 int real{}; // this value is greater than 0 if these constants are correctly evaulated
62
63 geo_constants(size_t nCoords) :
64 Vd0(nCoords),
65 Vcurvature(nCoords),
66 Vphi(nCoords),
67 Vz0(nCoords),
68 Veta(nCoords),
69 kernel(nCoords - FPGATrackSimTrackPars::NPARS, nCoords),
71 pars(0),
72 real(0)
73 {
74 }
75};
76
77
79{
80 public:
81
82 FPGATrackSimConstGenAlgo(const std::string& name, ISvcLocator* pSvcLocator);
83 virtual ~FPGATrackSimConstGenAlgo() = default;
84 StatusCode initialize() override;
85 StatusCode finalize() override;
86
87 // Execute does not do anything for this alg. This class does not process events, everything is done in initalize
88 StatusCode execute() override;
89
90 StatusCode bookHistograms();
91
92 private:
93
95 // Handles
96
97 ServiceHandle<IFPGATrackSimMappingSvc> m_FPGATrackSimMapping{this, "FPGATrackSimMappingSvc","FPGATrackSimMappingSvc"};
98 ServiceHandle<IFPGATrackSimEventSelectionSvc> m_EvtSel{this,"FPGATrackSimEventSelectionSvc","FPGATrackSimEventSelectionSvc"};
99 ServiceHandle<ITHistSvc> m_tHistSvc{this, "THistSvc","THistSvc"};
100
101 const FPGATrackSimPlaneMap* m_pmap = nullptr;
102
103
104
106 // Configuration
107 Gaudi::Property<std::string> m_cfpath{this, "merged_file_path", "", "merged file"};
108 Gaudi::Property<std::string> m_skipFile{this, "skip_sectors", "File with list of sectors to skip"};
109 Gaudi::Property<bool> m_Monitor{this,"Monitor",false,"flag to enable the monitor"};
110 Gaudi::Property<int> m_region{this, "region",0,"region to run"};
111 Gaudi::Property<bool> m_CheckGood2ndStage{this,"CheckGood2ndStage",true,"Check goodness of 2nd stage fit constants?"};
112 Gaudi::Property<bool> m_useHitScaleFactor{this,"UseHitScaleFactor",false,"Scale factor for hits"};
113 Gaudi::Property<bool> m_isSecondStage{this,"IsSecondStage",false,"If false, we're doing a 1st stage fit, otherwise 2nd stage"};
114 Gaudi::Property<bool> m_dumpMissingHitsConstants{this, "missHitsConsts", false, "if this is true we dump constants assuming a missing hit in each layer, too"};
115
117 // ROOT Objects
118
119 TFile *m_mafile = nullptr;
120 TTree *m_ctree = nullptr;
121 TTree *m_matrix_tree = nullptr;
122 TTree *m_good_tree = nullptr;
123
124
126 // Slice Info
127
131
133 // Sizes
134
135 int m_nLayers = 0;
136 int m_nKernel = 0;
138 int m_nCoords = 0;
139 int m_nCoords_2 = 0; // m_nCoords^2
140
141
143 // Main Storage Objects
144
145 // These have size = # of good sectors.
146 std::vector<geo_constants> m_geo_consts;
147
148 // These are the constants for missing hits, first index is missing hit
149 // The second index is the same as above (good sector number)
150 std::vector<std::vector<geo_constants>> m_geo_consts_with_missinghit;
151
152 // Size = # of sectors. Which sectors to skip for generating constants.
153 std::vector<bool> m_skipList;
154
156 // Helper Functions
157
158 StatusCode copySliceTree(TFile *file);
159 StatusCode prepareOutputTree();
160 void readSkipList(size_t nEntries);
161 void generate_constants();
162 void fillConstTree(std::vector<module_t> & modules, FPGATrackSimMatrixAccumulator & acc, geo_constants & geo);
163 bool isNAN(double value, const char* name);
164 bool failedConstants(geo_constants const & geo, std::vector<bool> const & usable);
165 StatusCode DumpConstants(std::vector<geo_constants> &geo_consts, std::string & filename);
166 StatusCode writeSectors();
167 bool GetConstants(FPGATrackSimMatrixAccumulator const &acc_norm, geo_constants &geo, int entryNumber); // use values in acc_norm
168 bool GetConstants(FPGATrackSimMatrixAccumulator const &acc_norm, geo_constants &geo, int entryNumber, std::vector<bool> const &coordsToUse, unsigned int nusable); // full method with different number of usable coordinates
169 void createMissingHitsConstants(FPGATrackSimMatrixAccumulator const & acc_norm, size_t entry);
171 geo_constants makeConsts(FPGATrackSimMatrixAccumulator const & acc, std::vector<bool> const & usable,
172 std::vector<double> const & inv_covariance,
173 std::vector<double> const & eigvals, vector2D<double> const & eigvecs);
174 std::vector<double> matrix_multiply(std::vector<double> const & A, std::vector<double> const & b);
175 void eigen(size_t n_redu, size_t n_full, TMatrixD &mtx, std::vector<bool> const & usable, std::vector<double> & eigvals_v, vector2D<double> & eigvecs_v);
176 std::vector<double> invert(size_t n_full, TMatrixD mtx, std::vector<bool> const & usable);
177 TMatrixD getReducedMatrix(size_t n, std::vector<double> const & mtx_v, std::vector<bool> const & usable, size_t nDimToUse);
178 bool isSingular(TMatrixD mtx);
179 double dot(const double* vec1, const double* vec2, size_t size);
180 geo_constants calculate_gcorth(geo_constants geo, int nCoords, std::vector<bool> const & usable);
181
182
183
184};
185
186#endif // FPGATrackSimConstGenAlgo_h
187
Structs that store the 5 track parameters.
Defines several vector wrappers for homogenous multi-dimensional vectors, declared as 1D arrays for l...
#define NPARS
Definition GraphTest.cxx:20
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
ServiceHandle< IFPGATrackSimEventSelectionSvc > m_EvtSel
ServiceHandle< ITHistSvc > m_tHistSvc
std::vector< std::vector< geo_constants > > m_geo_consts_with_missinghit
geo_constants calculate_gcorth(geo_constants geo, int nCoords, std::vector< bool > const &usable)
bool isNAN(double value, const char *name)
Gaudi::Property< std::string > m_skipFile
TMatrixD getReducedMatrix(size_t n, std::vector< double > const &mtx_v, std::vector< bool > const &usable, size_t nDimToUse)
Removes the rows/columns specified by !usable.
std::vector< double > matrix_multiply(std::vector< double > const &A, std::vector< double > const &b)
void eigen(size_t n_redu, size_t n_full, TMatrixD &mtx, std::vector< bool > const &usable, std::vector< double > &eigvals_v, vector2D< double > &eigvecs_v)
FPGATrackSimTrackParsI m_sliceNBins
std::vector< geo_constants > m_geo_consts
Gaudi::Property< bool > m_dumpMissingHitsConstants
FPGATrackSimMatrixAccumulator normalize(FPGATrackSimMatrixAccumulator const &acc_raw)
bool GetConstants(FPGATrackSimMatrixAccumulator const &acc_norm, geo_constants &geo, int entryNumber)
geo_constants makeConsts(FPGATrackSimMatrixAccumulator const &acc, std::vector< bool > const &usable, std::vector< double > const &inv_covariance, std::vector< double > const &eigvals, vector2D< double > const &eigvecs)
FPGATrackSimConstGenAlgo(const std::string &name, ISvcLocator *pSvcLocator)
void createMissingHitsConstants(FPGATrackSimMatrixAccumulator const &acc_norm, size_t entry)
std::vector< double > invert(size_t n_full, TMatrixD mtx, std::vector< bool > const &usable)
Inverts a reduced matrix, then pads with zeros to recover a full-sized matrix.
Gaudi::Property< bool > m_Monitor
StatusCode copySliceTree(TFile *file)
Gaudi::Property< bool > m_isSecondStage
StatusCode DumpConstants(std::vector< geo_constants > &geo_consts, std::string &filename)
const FPGATrackSimPlaneMap * m_pmap
Gaudi::Property< std::string > m_cfpath
Gaudi::Property< bool > m_CheckGood2ndStage
virtual ~FPGATrackSimConstGenAlgo()=default
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
void fillConstTree(std::vector< module_t > &modules, FPGATrackSimMatrixAccumulator &acc, geo_constants &geo)
bool failedConstants(geo_constants const &geo, std::vector< bool > const &usable)
Gaudi::Property< bool > m_useHitScaleFactor
Definition dot.py:1
TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
hold the test vectors and ease the comparison
std::vector< double > Vcurvature
std::vector< double > Vd0
vector2D< double > kernel
geo_constants(size_t nCoords)
FPGATrackSimTrackPars pars
std::vector< double > Vz0
std::vector< double > kaverages
std::vector< double > Vphi
std::vector< double > Veta
TFile * file