ATLAS Offline Software
FPGATrackSimConstGenAlgo.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 #ifndef FPGATrackSimConstGenAlgo_h
4 #define FPGATrackSimConstGenAlgo_h
5 
27 #include "GaudiKernel/ITHistSvc.h"
32 #include "TTree.h"
34 
35 #include <string>
36 #include <vector>
37 
38 #include <TMatrixD.h>
39 
40 #include "TTree.h"
41 #include "TH1I.h"
42 #include "TH1F.h"
43 
45 
46 
47 // data structure that contain definition of geometrical constants for linear fits
49 {
50  //these are the matrices themselves
51  std::vector<double> Vd0; // impact paramers coefs
52  std::vector<double> Vcurvature; // curvature coefs
53  std::vector<double> Vphi; // phi coefs
54  std::vector<double> Vz0; // z0 coefs
55  std::vector<double> Veta; // eta coefs
56  vector2D<double> kernel; // kernel (covariance matrix). Size (ndim - npar, ndim)
57  std::vector<double> kaverages; // averages, useful to keep track of
58 
59  // these are the constant/offset values
61 
62  int real; // this value is greater than 0 if these constants are correctly evaulated
63 
64  geo_constants(size_t nCoords) :
65  Vd0(nCoords),
66  Vcurvature(nCoords),
67  Vphi(nCoords),
68  Vz0(nCoords),
69  Veta(nCoords),
70  kernel(nCoords - FPGATrackSimTrackPars::NPARS, nCoords),
72  pars(0),
73  real(0)
74  {
75  }
76 };
77 
78 
80 {
81  public:
82 
83  FPGATrackSimConstGenAlgo(const std::string& name, ISvcLocator* pSvcLocator);
84  virtual ~FPGATrackSimConstGenAlgo() = default;
85  StatusCode initialize() override;
86  StatusCode finalize() override;
87 
88  // Execute does not do anything for this alg. This class does not process events, everything is done in initalize
89  StatusCode execute() override;
90 
92 
93  private:
94 
96  // Handles
97 
98  ServiceHandle<IFPGATrackSimMappingSvc> m_FPGATrackSimMapping{this, "FPGATrackSimMappingSvc","FPGATrackSimMappingSvc"};
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  TH1F *m_h_vc = nullptr;
125  TH1F *m_h_vd = nullptr;
126  TH1F *m_h_vf = nullptr;
127  TH1F *m_h_vz = nullptr;
128  TH1F *m_h_veta = nullptr;
129 
131  // Slice Info
132 
136 
138  // Sizes
139 
140  int m_nLayers = 0;
141  int m_nKernel = 0;
142  int m_nKAverages = 0;
143  int m_nCoords = 0;
144  int m_nCoords_2 = 0; // m_nCoords^2
145 
146 
148  // Main Storage Objects
149 
150  // These have size = # of good sectors.
151  std::vector<geo_constants> m_geo_consts;
152 
153  // These are the constants for missing hits, first index is missing hit
154  // The second index is the same as above (good sector number)
155  std::vector<std::vector<geo_constants>> m_geo_consts_with_missinghit;
156 
157  // Size = # of sectors. Which sectors to skip for generating constants.
158  std::vector<bool> m_skipList;
159 
161  // Helper Functions
162 
163  StatusCode copySliceTree(TFile *file);
165  void readSkipList(size_t nEntries);
166  void generate_constants();
167  void fillConstTree(std::vector<module_t> & modules, FPGATrackSimMatrixAccumulator & acc, geo_constants & geo);
168  bool isNAN(double value, const char* name);
169  bool failedConstants(geo_constants const & geo, std::vector<bool> const & usable);
170  void DumpConstants(std::vector<geo_constants> &geo_consts, std::string & filename);
171  void writeSectors();
172  bool GetConstants(FPGATrackSimMatrixAccumulator const &acc_norm, geo_constants &geo, int entryNumber); // use values in acc_norm
173  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
174  void createMissingHitsConstants(FPGATrackSimMatrixAccumulator const & acc_norm, size_t entry);
176  geo_constants makeConsts(FPGATrackSimMatrixAccumulator const & acc, std::vector<bool> const & usable,
177  std::vector<double> const & inv_covariance,
178  std::vector<double> const & eigvals, vector2D<double> const & eigvecs);
179  std::vector<double> matrix_multiply(std::vector<double> const & A, std::vector<double> const & b);
180  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);
181  std::vector<double> invert(size_t n_full, TMatrixD mtx, std::vector<bool> const & usable);
182  TMatrixD getReducedMatrix(size_t n, std::vector<double> const & mtx_v, std::vector<bool> const & usable, size_t nDimToUse);
183  bool isSingular(TMatrixD mtx);
184  double dot(const double* vec1, const double* vec2, size_t size);
185  geo_constants calculate_gcorth(geo_constants geo, int nCoords, std::vector<bool> const & usable);
186 
187 
188 
189 };
190 
191 #endif // FPGATrackSimConstGenAlgo_h
192 
FPGATrackSimConstGenAlgo::m_good_tree
TTree * m_good_tree
Definition: FPGATrackSimConstGenAlgo.h:122
FPGATrackSimConstGenAlgo::m_mafile
TFile * m_mafile
Definition: FPGATrackSimConstGenAlgo.h:119
FPGATrackSimConstGenAlgo::generate_constants
void generate_constants()
Definition: FPGATrackSimConstGenAlgo.cxx:247
D3PDMakerTestInstan::vec2
std::vector< D3PDTest::MyVec2 > vec2
Definition: D3PDMakerTestDict.h:14
FPGATrackSimConstGenAlgo::m_CheckGood2ndStage
Gaudi::Property< bool > m_CheckGood2ndStage
Definition: FPGATrackSimConstGenAlgo.h:111
geo_constants::kernel
vector2D< double > kernel
Definition: FPGATrackSimConstGenAlgo.h:56
FPGATrackSimConstGenAlgo::calculate_gcorth
geo_constants calculate_gcorth(geo_constants geo, int nCoords, std::vector< bool > const &usable)
Definition: FPGATrackSimConstGenAlgo.cxx:684
FPGATrackSimConstGenAlgo::~FPGATrackSimConstGenAlgo
virtual ~FPGATrackSimConstGenAlgo()=default
FPGATrackSimConstGenAlgo::eigen
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)
Definition: FPGATrackSimConstGenAlgo.cxx:644
FPGATrackSimPlaneMap.h
Maps physical layers to logical layers.
FPGATrackSimConstGenAlgo::isNAN
bool isNAN(double value, const char *name)
Definition: FPGATrackSimConstGenAlgo.cxx:394
FPGATrackSimTrackPars
Definition: FPGATrackSimTrackPars.h:22
FPGATrackSimConstGenAlgo::m_skipFile
Gaudi::Property< std::string > m_skipFile
Definition: FPGATrackSimConstGenAlgo.h:108
FPGATrackSimConstGenAlgo::dot
double dot(const double *vec1, const double *vec2, size_t size)
Definition: FPGATrackSimConstGenAlgo.cxx:675
FPGATrackSimConstGenAlgo::execute
StatusCode execute() override
Definition: FPGATrackSimConstGenAlgo.cxx:709
FPGATrackSimConstGenAlgo::m_nCoords
int m_nCoords
Definition: FPGATrackSimConstGenAlgo.h:143
IFPGATrackSimMappingSvc.h
FPGATrackSimConstGenAlgo::m_Monitor
Gaudi::Property< bool > m_Monitor
Definition: FPGATrackSimConstGenAlgo.h:109
FPGATrackSimConstGenAlgo::m_h_veta
TH1F * m_h_veta
Definition: FPGATrackSimConstGenAlgo.h:128
FPGATrackSimConstGenAlgo::DumpConstants
void DumpConstants(std::vector< geo_constants > &geo_consts, std::string &filename)
Definition: FPGATrackSimConstGenAlgo.cxx:794
FPGATrackSimConstGenAlgo::m_sliceMax
FPGATrackSimTrackPars m_sliceMax
Definition: FPGATrackSimConstGenAlgo.h:135
FPGATrackSimConstGenAlgo::m_tHistSvc
ServiceHandle< ITHistSvc > m_tHistSvc
Definition: FPGATrackSimConstGenAlgo.h:99
athena.value
value
Definition: athena.py:124
IFPGATrackSimMappingSvc
Definition: IFPGATrackSimMappingSvc.h:17
FPGATrackSimConstGenAlgo::initialize
StatusCode initialize() override
Definition: FPGATrackSimConstGenAlgo.cxx:53
FPGATrackSimConstGenAlgo::m_region
Gaudi::Property< int > m_region
Definition: FPGATrackSimConstGenAlgo.h:110
FPGATrackSimConstGenAlgo::GetConstants
bool GetConstants(FPGATrackSimMatrixAccumulator const &acc_norm, geo_constants &geo, int entryNumber)
Definition: FPGATrackSimConstGenAlgo.cxx:322
FPGATrackSimConstGenAlgo::m_skipList
std::vector< bool > m_skipList
Definition: FPGATrackSimConstGenAlgo.h:158
FPGATrackSimConstGenAlgo::m_pmap
const FPGATrackSimPlaneMap * m_pmap
Definition: FPGATrackSimConstGenAlgo.h:101
FPGATrackSimConstGenAlgo::m_isSecondStage
Gaudi::Property< bool > m_isSecondStage
Definition: FPGATrackSimConstGenAlgo.h:113
FPGATrackSimConstGenAlgo::m_nCoords_2
int m_nCoords_2
Definition: FPGATrackSimConstGenAlgo.h:144
FPGATrackSimConstGenAlgo::matrix_multiply
std::vector< double > matrix_multiply(std::vector< double > const &A, std::vector< double > const &b)
Definition: FPGATrackSimConstGenAlgo.cxx:543
FPGATrackSimConstGenAlgo::m_nLayers
int m_nLayers
Definition: FPGATrackSimConstGenAlgo.h:140
FPGATrackSimConstGenAlgo::getReducedMatrix
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.
Definition: FPGATrackSimConstGenAlgo.cxx:572
AthAlgorithm.h
FPGATrackSimConstGenAlgo::normalize
FPGATrackSimMatrixAccumulator normalize(FPGATrackSimMatrixAccumulator const &acc_raw)
Definition: FPGATrackSimConstGenAlgo.cxx:458
FPGATrackSimConstGenAlgo::finalize
StatusCode finalize() override
Definition: FPGATrackSimConstGenAlgo.cxx:722
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
A
FPGATrackSimVectors.h
Defines several vector wrappers for homogenous multi-dimensional vectors, declared as 1D arrays for l...
vector2D< double >
FPGATrackSimConstGenAlgo::m_nKAverages
int m_nKAverages
Definition: FPGATrackSimConstGenAlgo.h:142
FPGATrackSimConstGenAlgo::m_useHitScaleFactor
Gaudi::Property< bool > m_useHitScaleFactor
Definition: FPGATrackSimConstGenAlgo.h:112
beamspotman.n
n
Definition: beamspotman.py:731
FPGATrackSimConstGenAlgo::m_sliceNBins
FPGATrackSimTrackParsI m_sliceNBins
Definition: FPGATrackSimConstGenAlgo.h:133
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
geo_constants::Vcurvature
std::vector< double > Vcurvature
Definition: FPGATrackSimConstGenAlgo.h:52
FPGATrackSimMatrixAccumulator
Definition: FPGATrackSimMatrixAccumulator.h:36
FPGATrackSimConstGenAlgo::m_geo_consts_with_missinghit
std::vector< std::vector< geo_constants > > m_geo_consts_with_missinghit
Definition: FPGATrackSimConstGenAlgo.h:155
geo_constants::Vd0
std::vector< double > Vd0
Definition: FPGATrackSimConstGenAlgo.h:51
file
TFile * file
Definition: tile_monitor.h:29
FPGATrackSimConstGenAlgo::m_h_vf
TH1F * m_h_vf
Definition: FPGATrackSimConstGenAlgo.h:126
FPGATrackSimConstGenAlgo::m_geo_consts
std::vector< geo_constants > m_geo_consts
Definition: FPGATrackSimConstGenAlgo.h:151
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
FPGATrackSimConstGenAlgo::FPGATrackSimConstGenAlgo
FPGATrackSimConstGenAlgo(const std::string &name, ISvcLocator *pSvcLocator)
Definition: FPGATrackSimConstGenAlgo.cxx:47
geo_constants::pars
FPGATrackSimTrackPars pars
Definition: FPGATrackSimConstGenAlgo.h:60
FPGATrackSimConstGenAlgo::failedConstants
bool failedConstants(geo_constants const &geo, std::vector< bool > const &usable)
Definition: FPGATrackSimConstGenAlgo.cxx:407
AthAlgorithm
Definition: AthAlgorithm.h:47
FPGATrackSimConstGenAlgo
Definition: FPGATrackSimConstGenAlgo.h:80
FPGATrackSimPlaneMap
Definition: FPGATrackSimPlaneMap.h:62
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
FPGATrackSimConstGenAlgo::m_sliceMin
FPGATrackSimTrackPars m_sliceMin
Definition: FPGATrackSimConstGenAlgo.h:134
FPGATrackSimMatrixAccumulator.h
Helper struct for accumulating sector information for matrix generation.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
FPGATrackSimConstGenAlgo::isSingular
bool isSingular(TMatrixD mtx)
Definition: FPGATrackSimConstGenAlgo.cxx:556
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
geo_constants::geo_constants
geo_constants(size_t nCoords)
Definition: FPGATrackSimConstGenAlgo.h:64
geo_constants::Vz0
std::vector< double > Vz0
Definition: FPGATrackSimConstGenAlgo.h:54
FPGATrackSimConstGenAlgo::m_ctree
TTree * m_ctree
Definition: FPGATrackSimConstGenAlgo.h:120
FPGATrackSimConstGenAlgo::createMissingHitsConstants
void createMissingHitsConstants(FPGATrackSimMatrixAccumulator const &acc_norm, size_t entry)
Definition: FPGATrackSimConstGenAlgo.cxx:284
FPGATrackSimConstGenAlgo::m_matrix_tree
TTree * m_matrix_tree
Definition: FPGATrackSimConstGenAlgo.h:121
FPGATrackSimConstGenAlgo::makeConsts
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)
Definition: FPGATrackSimConstGenAlgo.cxx:495
geo_constants::Veta
std::vector< double > Veta
Definition: FPGATrackSimConstGenAlgo.h:55
FPGATrackSimConstGenAlgo::m_nKernel
int m_nKernel
Definition: FPGATrackSimConstGenAlgo.h:141
FPGATrackSimConstGenAlgo::m_h_vz
TH1F * m_h_vz
Definition: FPGATrackSimConstGenAlgo.h:127
FPGATrackSimConstGenAlgo::invert
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.
Definition: FPGATrackSimConstGenAlgo.cxx:605
FPGATrackSimConstGenAlgo::bookHistograms
StatusCode bookHistograms()
Definition: FPGATrackSimConstGenAlgo.cxx:107
FPGATrackSimConstGenAlgo::m_FPGATrackSimMapping
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
Definition: FPGATrackSimConstGenAlgo.h:98
FPGATrackSimConstGenAlgo::m_h_vd
TH1F * m_h_vd
Definition: FPGATrackSimConstGenAlgo.h:125
LArCellConditions.geo
bool geo
Definition: LArCellConditions.py:46
geo_constants
Definition: FPGATrackSimConstGenAlgo.h:49
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
geo_constants::real
int real
Definition: FPGATrackSimConstGenAlgo.h:62
NPARS
#define NPARS
Definition: GraphTest.cxx:20
FPGATrackSimConstGenAlgo::m_h_vc
TH1F * m_h_vc
Definition: FPGATrackSimConstGenAlgo.h:124
FPGATrackSimConstGenAlgo::writeSectors
void writeSectors()
Definition: FPGATrackSimConstGenAlgo.cxx:747
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
FPGATrackSimTrackParsI
Definition: FPGATrackSimTrackPars.h:56
FPGATrackSimConstGenAlgo::readSkipList
void readSkipList(size_t nEntries)
Definition: FPGATrackSimConstGenAlgo.cxx:221
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:73
FPGATrackSimConstGenAlgo::m_dumpMissingHitsConstants
Gaudi::Property< bool > m_dumpMissingHitsConstants
Definition: FPGATrackSimConstGenAlgo.h:114
geo_constants::Vphi
std::vector< double > Vphi
Definition: FPGATrackSimConstGenAlgo.h:53
FPGATrackSimConstGenAlgo::prepareOutputTree
StatusCode prepareOutputTree()
Definition: FPGATrackSimConstGenAlgo.cxx:180
geo_constants::kaverages
std::vector< double > kaverages
Definition: FPGATrackSimConstGenAlgo.h:57
FPGATrackSimConstGenAlgo::copySliceTree
StatusCode copySliceTree(TFile *file)
Definition: FPGATrackSimConstGenAlgo.cxx:124
FPGATrackSimConstGenAlgo::m_cfpath
Gaudi::Property< std::string > m_cfpath
Definition: FPGATrackSimConstGenAlgo.h:107
FPGATrackSimConstGenAlgo::fillConstTree
void fillConstTree(std::vector< module_t > &modules, FPGATrackSimMatrixAccumulator &acc, geo_constants &geo)
Definition: FPGATrackSimConstGenAlgo.cxx:356
ServiceHandle< IFPGATrackSimMappingSvc >