ATLAS Offline Software
Loading...
Searching...
No Matches
MatrixTool.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef TRKALIGNGENTOOLS_MATRIXTOOL_H
6#define TRKALIGNGENTOOLS_MATRIXTOOL_H
7
21
22#include "GaudiKernel/ToolHandle.h"
24
26
27#include <TMatrixDSym.h>
28#include "CLHEP/Matrix/SymMatrix.h"
29
30#include <string>
31#include <memory>
32
33class TString;
34
46
47namespace Trk {
48
49 class AlSymMatBase;
50 class AlSymMat;
51 class AlMat;
52 class AlVec;
53
54 class IAlignModuleTool;
55
56 class MatrixTool : public AthAlgTool, virtual public IMatrixTool {
57 public:
58
69
71 MatrixTool(const std::string& type, const std::string& name,
72 const IInterface* parent);
73
75 virtual ~MatrixTool();
76
78 StatusCode initialize();
79
81 StatusCode finalize();
82
84 StatusCode allocateMatrix(int nDoF=0);
85
87 void prepareBinaryFiles(int solveOption);
88
91
93 void addFirstDerivatives(std::list<int,double>& derivatives);
94
95 void addFirstDerivative(int irow, double firstderiv);
96
99
101 void addSecondDerivatives(std::list<std::pair<int,int>,double >& derivatives);
102
103 void addSecondDerivative(int irow, int icol, double secondderiv);
104
105
107 bool accumulateFromFiles();
108
111
113 int solve();
114
115
117 void storeInTFile(const TString& filename);
118
121
122 void printModuleSolution(std::ostream & os, const AlignModule * module, const CLHEP::HepSymMatrix * cov) const;
123 void printGlobalSolution(std::ostream & os, const CLHEP::HepSymMatrix * cov);
124 void printGlobalSolution(std::ostream & os, const TMatrixDSym * cov);
125
126 private:
127
128 // private methods
129 int solveROOT();
130 int solveCLHEP();
131 int solveLapack();
132 int solveSparseEigen();
133 int solveLocal();
134
135 StatusCode spuriousRemoval();
136 static int fillVecMods();
137 void postSolvingLapack(AlVec * dChi2, AlSymMat * d2Chi2, AlVec &w, AlMat &z, int size);
138
139 void writeHitmap();
140 void readHitmaps();
141
142 // private variables
143 PublicToolHandle<IAlignModuleTool> m_alignModuleTool{
144 this, "AlignModuleTool", "Trk::AlignModuleTool/AlignModuleTool"};
145
147 std::unique_ptr<AlSymMatBase> m_bigmatrix;
148
150 std::unique_ptr<AlVec> m_bigvector;
151
153 Gaudi::Property<bool> m_useSparse{this, "UseSparse", false};
154
155 Gaudi::Property<bool> m_diagonalize{this, "Diagonalize", true,
156 "run diagonalization instead of inversion"};
157 Gaudi::Property<double> m_eigenvaluethreshold
158 {this, "EigenvalueThreshold", 0., "cut on the minimum eigenvalue"};
159
160 Gaudi::Property<int> m_solveOption
161 {this, "SolveOption", NONE, "solving option"};
162 Gaudi::Property<int> m_modcut{this, "ModCut", 0,
163 "cut on the weak modes which number is <par_modcut"};
164 Gaudi::Property<int> m_minNumHits{this, "MinNumHitsPerModule", 0,
165 "cut on the minimum number of hits per module"};
166 Gaudi::Property<int> m_minNumTrks{this, "MinNumTrksPerModule", 0,
167 "cut on the minimum number of tracks per module"};
168 Gaudi::Property<float> m_pullcut{this, "PullCut", 1.0,
169 "pull cut for the automatic weak mode removal method"};
170 Gaudi::Property<float> m_eigenvalueStep{this, "EigenvalueStep", 1e3,
171 "eigenvalue step for the second pass in the automatic weak mode removal method"};
172 Gaudi::Property<float> m_Align_db_step{this, "AlignCorrDBStep", 10.,
173 "corr in the diagonal basis step for the third pass in the auto weak mode removal method"};
174
175 Gaudi::Property<bool> m_calDet{this, "MatrixDet", false,
176 "compute bigmatrix's determinant ?"};
177 Gaudi::Property<bool> m_wSqMatrix{this, "WriteSquareMatrix", false,
178 "write a triangular matrix by default (true: square format) ?"};
179 Gaudi::Property<bool> m_writeMat{this, "WriteMat", true,
180 "write big matrix and vector into files ?"};
181 Gaudi::Property<bool> m_writeMatTxt{this, "WriteMatTxt", true,
182 "also write big matrix and vector into txt files ?"};
183 Gaudi::Property<bool> m_writeEigenMat{this, "WriteEigenMat", true,
184 "write eigenvalues and eigenvectors into files ?"};
185 Gaudi::Property<bool> m_writeEigenMatTxt{this, "WriteEigenMatTxt", true,
186 "also write eigenvalues and eigenvectors into txt files ?"};
187 Gaudi::Property<bool> m_writeModuleNames{this, "WriteModuleNames", false,
188 "write module name instead of Identifier to vector file"};
189
190 Gaudi::Property<bool> m_writeHitmap{this, "WriteHitmap", false,
191 "write hitmap into file"};
192 Gaudi::Property<bool> m_writeHitmapTxt{this, "WriteHitmapTxt", false,
193 "write hitmap into text file"};
194 Gaudi::Property<bool> m_readHitmaps{this, "ReadHitmaps", false,
195 "accumulate hitymap from files"};
196
197 Gaudi::Property<bool> m_writeTFile{this, "WriteTFile", false,
198 "write out files to a root file"};
199 Gaudi::Property<bool> m_readTFiles{this, "ReadTFile", false,
200 "if True then files will be read from TFiles instead of Binary files"};
201
202 Gaudi::Property<bool> m_runLocal{this, "RunLocalMethod", true,
203 "Run solving using Local method"};
204
205 double m_scale = -1.;
206 Gaudi::Property<bool> m_scaleMatrix{this, "ScaleMatrix", false,
207 "scale matrix by number of hits before solving"};
208
209 Gaudi::Property<double> m_softEigenmodeCut{this, "SoftEigenmodeCut", 0.,
210 "add constant to diagonal to effectively cut on weak eigenmodes"};
211
212 Gaudi::Property<double> m_removeSpurious{this, "RemoveSpurious", false,
213 "run spurious removal"};
214
215 Gaudi::Property<double> m_calculateFullCovariance
216 {this, "CalculateFullCovariance", true,
217 "calculate full covariance matrix for Lapack"};
218
219 Gaudi::Property<std::string> m_pathbin{this, "PathBinName", "./",
220 "path binary files (in/out)"};
221 Gaudi::Property<std::string> m_pathtxt{this, "PathTxtName", "./",
222 "path ascii files (in/out)"};
223 Gaudi::Property<std::string> m_prefixName{this, "PrefixName", "",
224 "prefix string to filenames"};
225
226 Gaudi::Property<std::string> m_tfileName
227 {this, "TFileName", "AlignmentTFile.root", "prefix string to filenames"};
228
229 Gaudi::Property<std::string> m_scalaMatName
230 {this, "ScalapackMatrixName", "eigenvectors.bin", "Scalapack matrix name"};
231 Gaudi::Property<std::string> m_scalaVecName
232 {this, "ScalapackVectorName", "eigenvalues.bin", "Scalapack vector name"};
233
234 Gaudi::Property<std::vector<std::string>> m_inputMatrixFiles
235 {this, "InputMatrixFiles", {"matrix.bin"},
236 "input binary files containing matrix terms"};
237 Gaudi::Property<std::vector<std::string>> m_inputVectorFiles
238 {this, "InputVectorFiles", {"vector.bin"},
239 "input binary files containing vector terms"};
240
241 Gaudi::Property<std::vector<std::string>> m_inputHitmapFiles
242 {this, "InputHitmapFiles", {"hitmap.bin"},
243 "input binary files containing the hitmaps"};
244
245 Gaudi::Property<std::vector<std::string>> m_inputTFiles
246 {this, "InputTFiles", {"AlignmentTFile.root"},
247 "input binary files containing matrix terms"};
248
249 std::vector<int> m_activeIndices{};
250 int m_aNDoF = 0;
251
252 Gaudi::Property<int> m_maxReadErrors{this, "MaxReadErrors", 10,
253 "maximum number of reading TFile errors"};
254
255 //To skip IBL or Pixel Alignment
256 Gaudi::Property<bool> m_AlignIBLbutNotPixel
257 {this, "AlignIBLbutNotPixel", false};
258 Gaudi::Property<bool> m_AlignPixelbutNotIBL
259 {this, "AlignPixelbutNotIBL", false};
260 //To Skip Solving of SCT ECA Last Disk
261 Gaudi::Property<bool> m_DeactivateSCT_ECA_LastDisk
262 {this, "DeactivateSCT_ECA_LastDisk", false};
263
264 //By Pixel DoF
265 Gaudi::Property<bool> m_Remove_Pixel_Tx{this, "Remove_Pixel_Tx", false};
266 Gaudi::Property<bool> m_Remove_Pixel_Ty{this, "Remove_Pixel_Ty", false};
267 Gaudi::Property<bool> m_Remove_Pixel_Tz{this, "Remove_Pixel_Tz", false};
268 Gaudi::Property<bool> m_Remove_Pixel_Rx{this, "Remove_Pixel_Rx", false};
269 Gaudi::Property<bool> m_Remove_Pixel_Ry{this, "Remove_Pixel_Ry", false};
270 Gaudi::Property<bool> m_Remove_Pixel_Rz{this, "Remove_Pixel_Rz", false};
271
272 //By IBL DoF
273 Gaudi::Property<bool> m_Remove_IBL_Tx{this, "Remove_IBL_Tx", false};
274 Gaudi::Property<bool> m_Remove_IBL_Ty{this, "Remove_IBL_Ty", false};
275 Gaudi::Property<bool> m_Remove_IBL_Tz{this, "Remove_IBL_Tz", false};
276 Gaudi::Property<bool> m_Remove_IBL_Rx{this, "Remove_IBL_Rx", false};
277 Gaudi::Property<bool> m_Remove_IBL_Ry{this, "Remove_IBL_Ry", false};
278 Gaudi::Property<bool> m_Remove_IBL_Rz{this, "Remove_IBL_Rz", false};
279
280 }; // end of class
281
282} // End of namespace
283
284
285
286#endif // TRKALIGNGENTOOLS_MATRIXTOOL_H
287
288
289
size_t size() const
Number of registered mappings.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
contains the implementation of the methods of class AlMat, for handling general NxM matrices
Definition AlMat.h:27
contains the base implementation for handling symmertic matrices
contains the implementation for handling symmetric matrices in triangular representation
Definition AlSymMat.h:26
IMatrixTool()
constructor
std::unique_ptr< AlSymMatBase > m_bigmatrix
matrix to contain second derivative terms to be used for alignment
Definition MatrixTool.h:147
Gaudi::Property< std::string > m_tfileName
Definition MatrixTool.h:227
MatrixTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
Gaudi::Property< int > m_maxReadErrors
Definition MatrixTool.h:252
Gaudi::Property< std::string > m_prefixName
Definition MatrixTool.h:223
Gaudi::Property< bool > m_AlignIBLbutNotPixel
Definition MatrixTool.h:257
void prepareBinaryFiles(int solveOption)
reads/writes matrix entries from/to binary files as necessary
Gaudi::Property< bool > m_readHitmaps
Definition MatrixTool.h:194
Gaudi::Property< bool > m_wSqMatrix
Definition MatrixTool.h:177
Gaudi::Property< bool > m_Remove_Pixel_Ry
Definition MatrixTool.h:269
Gaudi::Property< bool > m_writeHitmap
Definition MatrixTool.h:190
Gaudi::Property< bool > m_Remove_Pixel_Rz
Definition MatrixTool.h:270
Gaudi::Property< bool > m_writeEigenMatTxt
Definition MatrixTool.h:185
Gaudi::Property< bool > m_Remove_IBL_Rx
Definition MatrixTool.h:276
double m_scale
scale for big matrix and vector normalization
Definition MatrixTool.h:205
Gaudi::Property< bool > m_runLocal
Definition MatrixTool.h:202
StatusCode spuriousRemoval()
Gaudi::Property< double > m_removeSpurious
Definition MatrixTool.h:212
Gaudi::Property< bool > m_Remove_Pixel_Tz
Definition MatrixTool.h:267
StatusCode allocateMatrix(int nDoF=0)
allocates memory for big matrix and big vector
std::vector< int > m_activeIndices
vector of indices which pass the min-hits cut
Definition MatrixTool.h:249
void addSecondDerivative(int irow, int icol, double secondderiv)
Gaudi::Property< bool > m_Remove_IBL_Rz
Definition MatrixTool.h:278
Gaudi::Property< bool > m_Remove_Pixel_Ty
Definition MatrixTool.h:266
bool accumulateFromFiles()
accumulates derivates from files.
Gaudi::Property< std::vector< std::string > > m_inputVectorFiles
Definition MatrixTool.h:238
Gaudi::Property< bool > m_Remove_IBL_Tx
Definition MatrixTool.h:273
Gaudi::Property< int > m_minNumHits
Definition MatrixTool.h:164
static int fillVecMods()
Gaudi::Property< std::vector< std::string > > m_inputMatrixFiles
Definition MatrixTool.h:235
int m_aNDoF
number of active DoF (size of m_activeIndices)
Definition MatrixTool.h:250
Gaudi::Property< bool > m_Remove_Pixel_Tx
Definition MatrixTool.h:265
Gaudi::Property< double > m_calculateFullCovariance
Definition MatrixTool.h:216
Gaudi::Property< std::string > m_scalaVecName
Definition MatrixTool.h:232
Gaudi::Property< bool > m_Remove_IBL_Tz
Definition MatrixTool.h:275
int solve()
solves for alignment parameters
Gaudi::Property< float > m_eigenvalueStep
Definition MatrixTool.h:170
Gaudi::Property< float > m_Align_db_step
Definition MatrixTool.h:172
virtual ~MatrixTool()
Virtual destructor.
Gaudi::Property< bool > m_writeMatTxt
Definition MatrixTool.h:181
Gaudi::Property< std::vector< std::string > > m_inputHitmapFiles
Definition MatrixTool.h:242
void addSecondDerivatives(AlSymMatBase *matrix)
adds second derivatives to matrix
PublicToolHandle< IAlignModuleTool > m_alignModuleTool
Definition MatrixTool.h:143
Gaudi::Property< int > m_solveOption
Definition MatrixTool.h:161
Gaudi::Property< bool > m_writeHitmapTxt
Definition MatrixTool.h:192
bool accumulateFromTFiles()
Store Files in a tfile.
Gaudi::Property< bool > m_scaleMatrix
Definition MatrixTool.h:206
Gaudi::Property< bool > m_DeactivateSCT_ECA_LastDisk
Definition MatrixTool.h:262
Gaudi::Property< bool > m_writeMat
Definition MatrixTool.h:179
void storeInTFile(const TString &filename)
Store Files in a tfile.
void addFirstDerivatives(AlVec *vector)
adds first derivative to vector
void printModuleSolution(std::ostream &os, const AlignModule *module, const CLHEP::HepSymMatrix *cov) const
std::unique_ptr< AlVec > m_bigvector
vector to contain first derivative terms to be used for alignment
Definition MatrixTool.h:150
Gaudi::Property< int > m_minNumTrks
Definition MatrixTool.h:166
Gaudi::Property< bool > m_diagonalize
Definition MatrixTool.h:155
Gaudi::Property< double > m_softEigenmodeCut
Definition MatrixTool.h:209
Gaudi::Property< std::vector< std::string > > m_inputTFiles
Definition MatrixTool.h:246
Gaudi::Property< bool > m_writeEigenMat
Definition MatrixTool.h:183
Gaudi::Property< int > m_modcut
Definition MatrixTool.h:162
Gaudi::Property< double > m_eigenvaluethreshold
Definition MatrixTool.h:158
Gaudi::Property< std::string > m_scalaMatName
Definition MatrixTool.h:230
Gaudi::Property< bool > m_writeTFile
Definition MatrixTool.h:197
Gaudi::Property< std::string > m_pathbin
Definition MatrixTool.h:219
Gaudi::Property< bool > m_useSparse
flag to use AlSpaMat for the big matrix (default is AlSymMat)
Definition MatrixTool.h:153
void postSolvingLapack(AlVec *dChi2, AlSymMat *d2Chi2, AlVec &w, AlMat &z, int size)
Gaudi::Property< bool > m_Remove_Pixel_Rx
Definition MatrixTool.h:268
Gaudi::Property< bool > m_calDet
Definition MatrixTool.h:175
Gaudi::Property< bool > m_AlignPixelbutNotIBL
Definition MatrixTool.h:259
@ SOLVE_FAST
Fast (Eigen method) solving after data accumulation.
Definition MatrixTool.h:62
@ SOLVE_ROOT
computation using ROOT
Definition MatrixTool.h:66
@ SOLVE
solving after data accumulation (LAPACK)
Definition MatrixTool.h:61
@ DIRECT_SOLVE_FAST
direct Fast (Eigen method) solving, already available matrix & vector
Definition MatrixTool.h:64
@ DIRECT_SOLVE
direct solving (LAPACK), already available matrix & vector
Definition MatrixTool.h:63
@ DIRECT_SOLVE_CLUSTER
computation of alignment parameters from SCALAPAK already solved matrix
Definition MatrixTool.h:65
@ NONE
not solve in any case (to be used when ipc)
Definition MatrixTool.h:60
@ SOLVE_CLHEP
computation using CLHEP
Definition MatrixTool.h:67
void addFirstDerivative(int irow, double firstderiv)
StatusCode finalize()
initialize
bool accumulateFromBinaries()
accumulates derivates from binary files
Gaudi::Property< bool > m_Remove_IBL_Ry
Definition MatrixTool.h:277
Gaudi::Property< float > m_pullcut
Definition MatrixTool.h:168
StatusCode initialize()
initialize
Gaudi::Property< bool > m_Remove_IBL_Ty
Definition MatrixTool.h:274
void printGlobalSolution(std::ostream &os, const CLHEP::HepSymMatrix *cov)
Gaudi::Property< bool > m_readTFiles
Definition MatrixTool.h:199
Gaudi::Property< std::string > m_pathtxt
Definition MatrixTool.h:221
Gaudi::Property< bool > m_writeModuleNames
Definition MatrixTool.h:187
Ensure that the ATLAS eigen extensions are properly loaded.
@ z
global position (cartesian)
Definition ParamDefs.h:57