FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairAlignmentHandler.cxx
Go to the documentation of this file.
1 #include "FairAlignmentHandler.h"
2 
3 #include "FairLogger.h"
4 
5 #include <TGeoManager.h>
6 #include <TGeoPhysicalNode.h>
7 
9 
11 
12 void FairAlignmentHandler::AlignGeometry() const
13 {
14  if (fAlignmentMatrices.size() > 0) {
15  LOG(info) << "aligning the geometry...";
16 
17  LOG(info) << "aligning in total " << fAlignmentMatrices.size() << " volumes.";
18  if (gGeoManager->GetNAlignable() > 0) {
19  AlignGeometryBySymlink();
20  } else {
21  AlignGeometryByFullPath();
22  }
23 
24  LOG(info) << "alignment finished!";
25  }
26 }
27 
28 void FairAlignmentHandler::AlignGeometryByFullPath() const
29 {
30  TString volume_path;
31 
32  LOG(info) << "aligning using full path.";
33  for (auto const& alignment_entry : fAlignmentMatrices) {
34  volume_path = alignment_entry.first;
35 
36  gGeoManager->cd(volume_path);
37 
38  TGeoNode* volume_node = gGeoManager->GetCurrentNode();
39  TGeoMatrix* volume_matrix = volume_node->GetMatrix();
40  // Need to do this as since ROOT 6.14 TGeoMatrix has no multiplication operator anymore
41  // it is implimnted now in TGeoHMatrix
42 
43  TGeoHMatrix local_volume_matrix = TGeoHMatrix(*volume_matrix);
44 
45  TGeoHMatrix* new_volume_matrix = new TGeoHMatrix(local_volume_matrix * alignment_entry.second);
46  // new matrix, representing real position (from new local mis RS to the global one)
47 
48  TGeoPhysicalNode* pn = gGeoManager->MakePhysicalNode(volume_path);
49 
50  pn->Align(new_volume_matrix);
51  }
52  LOG(info) << "alignments applied!";
53 }
54 
55 void FairAlignmentHandler::AlignGeometryBySymlink() const
56 {
57  TString volume_path;
58 
59  LOG(info) << "aligning using symlinks";
60  for (auto const& alignment_entry : fAlignmentMatrices) {
61  volume_path = alignment_entry.first;
62 
63  TGeoPhysicalNode* node = NULL;
64  TGeoPNEntry* entry = gGeoManager->GetAlignableEntry(volume_path);
65  if (entry) {
66  node = gGeoManager->MakeAlignablePN(entry);
67  }
68 
69  TGeoMatrix* volume_matrix = NULL;
70  if (node) {
71  volume_matrix = node->GetMatrix();
72  } else {
73  continue;
74  }
75  // Need to do this as since ROOT 6.14 TGeoMatrix has no multiplication operator anymore
76  // it is implimnted now in TGeoHMatrix
77  TGeoHMatrix local_volume_matrix = TGeoHMatrix(*volume_matrix);
78 
79  TGeoHMatrix* new_volume_matrix = new TGeoHMatrix(local_volume_matrix * alignment_entry.second);
80  // new matrix, representing real position (from new local mis RS to the global one)
81  node->Align(new_volume_matrix);
82  }
83 }
84 
85 void FairAlignmentHandler::AddAlignmentMatrices(const std::map<std::string, TGeoHMatrix>& alignmentMatrices,
86  bool invertMatrices)
87 {
88  LOG(info) << "adding inverting matrices...";
89  for (auto const& m : alignmentMatrices) {
90  if (invertMatrices)
91  fAlignmentMatrices[m.first] *= m.second.Inverse();
92  else
93  fAlignmentMatrices[m.first] *= m.second;
94  }
95 }