PandaRoot
PndMatrixUtil.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 /*
14  matrix helper macro
15 
16  NOTE: we're always using column-major notation for vectors and matrices.
17  Even though ROOT uses column major notation for TGeoMatrices and TGeoHMatrices
18  (sometimes), the actual implementation is wrong. Inside the homogenous matrix,
19  the rotation matrix is stored colum-major, but the translation matrix is stored
20  row-major. Therefore, the matrix elements must be picked individually.
21 
22  */
23 
24 #ifndef PNDMATRIXUTIL_H
25 #define PNDMATRIXUTIL_H
26 
27 #include <TFile.h>
28 #include <TGeoMatrix.h>
29 #include <TROOT.h>
30 #include <TGeoManager.h>
31 
32 #include <nlohmann/json.hpp>
33 
34 #include <iomanip> // for setw
35 #include <iostream>
36 #include <fstream>
37 #include <ostream>
38 #include <map>
39 #include <string>
40 
41 using std::cerr;
42 using std::cout;
43 using std::map;
44 using std::string;
45 
47 
49 
50  private:
51  static bool saveMatricesToJson(std::map<std::string, TGeoHMatrix> *matrices, std::string &outfilename);
52  static bool saveMatricesToRootFile(std::map<std::string, TGeoHMatrix> *matrices, std::string &fileName);
53 
54  static std::map<string, TGeoHMatrix> *readMatricesFromRootFile(string &fileName);
55  static std::map<std::string, TGeoHMatrix> *readMatricesFromJSON(string &filename);
56 
57  static bool saveGeoManagerMatricesToDisk(std::vector<string> &paths, string &fileName);
58  static bool hasEnding(std::string const &fullString, std::string const &ending);
59  static std::vector<string> getPathsFromMatrixFile(string &fileName);
60 
61  public:
62  PndMatrixUtil();
63  static bool saveMatrices(std::map<std::string, TGeoHMatrix> *matrices, std::string &outfilename);
64  static std::map<string, TGeoHMatrix> *readMatrices(std::string &fileName);
65 
67 };
68 
69 #endif
static std::map< string, TGeoHMatrix > * readMatrices(std::string &fileName)
static bool saveMatrices(std::map< std::string, TGeoHMatrix > *matrices, std::string &outfilename)
ClassDef(PndMatrixUtil, 0)
nlohmann::json json
Definition: PndMatrixUtil.h:46