R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandGeoPar.cxx
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3 * Copyright (C) 2019-2025 Members of R3B Collaboration *
4 * *
5 * This software is distributed under the terms of the *
6 * GNU General Public Licence (GPL) version 3, *
7 * copied verbatim in the file "LICENSE". *
8 * *
9 * In applying this license GSI does not waive the privileges and immunities *
10 * granted to it by virtue of its status as an Intergovernmental Organization *
11 * or submit itself to any jurisdiction. *
12 ******************************************************************************/
13
14#include "R3BNeulandGeoPar.h"
15#include "FairParamList.h"
16#include "TGeoBBox.h"
17#include "TGeoMatrix.h"
18#include <FairParGenericSet.h>
19#include <Math/Vector3Dfwd.h>
20#include <Rtypes.h>
21#include <RtypesCore.h>
22#include <TGeoNode.h>
23#include <algorithm>
24#include <array>
25#include <iostream>
26
27// NOLINTNEXTLINE (misc-include-cleaner)
28#include <Math/Vector3D.h>
29
30R3BNeulandGeoPar::R3BNeulandGeoPar(const char* name, const char* title, const char* context)
31 : FairParGenericSet(name, title, context)
32 , fNeulandGeoNode(nullptr)
33{
34}
35
37
39
40void R3BNeulandGeoPar::putParams(FairParamList* lst)
41{
42 if (lst == nullptr)
43 {
44 return;
45 }
46 lst->addObject("NeulandGeoNode", fNeulandGeoNode);
47}
48
49auto R3BNeulandGeoPar::getParams(FairParamList* lst) -> bool
50{
51 if (lst == nullptr)
52 {
53 return kFALSE;
54 }
55 if (!lst->fillObject("NeulandGeoNode", fNeulandGeoNode))
56 {
57 return kFALSE;
58 }
60 return kTRUE;
61}
62
64{
65 std::cout << "R3BNeulandGeoPar: Neuland Paddle Positions ...\n";
66
67 fNeulandGeoNode->GetMatrix()->Print();
68
69 for (int i = 0; i < fNeulandGeoNode->GetNdaughters(); i++)
70 {
71 TGeoNode* node = fNeulandGeoNode->GetDaughter(i);
72 std::cout << node->GetNumber() << "\n";
73 node->GetMatrix()->Print();
74 }
75}
76
77void R3BNeulandGeoPar::SetNeulandGeoNode(const TGeoNode* const node)
78{
79 fNeulandGeoNode = dynamic_cast<TGeoNode*>(node->Clone());
81}
82
84{
85 // All paddles have to have the same length
86 return (dynamic_cast<TGeoBBox*>(fNeulandGeoNode->GetDaughter(0)->GetVolume()->GetShape()))->GetDX();
87}
88
89// Convert positions of e.g. points to the local coordinate of the respective paddle [(-135,135),(-2.5,2.5),(-2.5,2.5)]
90auto R3BNeulandGeoPar::ConvertToLocalCoordinates(const ROOT::Math::XYZVector& position,
91 const int paddleID) const -> ROOT::Math::XYZVector
92{
93 auto pos_in = std::array{ position.X(), position.Y(), position.Z() };
94 auto pos_tmp = std::array<double, 3>{};
95 auto pos_out = std::array<double, 3>{};
96
97 // First, convert to Neuland-local coordinates (consisting of all paddles)
98 fNeulandGeoNode->GetMatrix()->MasterToLocal(pos_in.data(), pos_tmp.data());
99 // Second, convert to the repective paddle
100 fPaddleGeoNodes.at(paddleID)->MasterToLocal(pos_tmp.data(), pos_out.data());
101
102 return { pos_out[0], pos_out[1], pos_out[2] };
103}
104
105auto R3BNeulandGeoPar::ConvertToGlobalCoordinates(const ROOT::Math::XYZVector& position,
106 const int paddleID) const -> ROOT::Math::XYZVector
107{
108 auto pos_in = std::array{ position.X(), position.Y(), position.Z() };
109 auto pos_tmp = std::array<double, 3>{};
110 auto pos_out = std::array<double, 3>{};
111
112 // Note reverse order of Global->Local
113 fPaddleGeoNodes.at(paddleID)->LocalToMaster(pos_in.data(), pos_tmp.data());
114
115 fNeulandGeoNode->GetMatrix()->LocalToMaster(pos_tmp.data(), pos_out.data());
116
117 return { pos_out[0], pos_out[1], pos_out[2] };
118}
119
120auto R3BNeulandGeoPar::ConvertGlobalToPixel(const ROOT::Math::XYZVector& position) const -> ROOT::Math::XYZVector
121{
122 const auto nPixels = 50;
123 const auto sizePixel = 5.;
124 const auto nPaddles = fNeulandGeoNode->GetNdaughters();
125 const auto nPlanes = nPaddles / nPixels;
126
127 auto pos_in = std::array{ position.X(), position.Y(), position.Z() };
128 auto pos_tmp = std::array<double, 3>{};
129
130 // First, convert to Neuland-local coordinates (consisting of all paddles)
131 fNeulandGeoNode->GetMatrix()->MasterToLocal(pos_in.data(), pos_tmp.data());
132
133 // Note: PaddleHalfLength is 135 (light guides)
134 // Map x and y values with [-125.:125.] float to [0:nPixels-1] int
135 const auto x_pos = std::min(std::max(0, (nPixels / 2) + static_cast<int>((pos_tmp[0] / sizePixel))), nPixels - 1);
136 const auto y_pos =
137 std::min(std::max<int>(0, (nPixels / 2) + static_cast<int>(pos_tmp[1] / sizePixel)), nPixels - 1);
138
139 // Map z to [0:nPlanes-1]
140 const auto z_pos =
141 std::min(std::max<int>(0, (nPlanes / 2) + static_cast<int>(pos_tmp[2] / sizePixel)), nPlanes - 1);
142
143 return { static_cast<double>(x_pos), static_cast<double>(y_pos), static_cast<double>(z_pos) };
144}
145
147{
148 for (int i = 0; i < fNeulandGeoNode->GetNdaughters(); i++)
149 {
150 TGeoNode* node = fNeulandGeoNode->GetDaughter(i);
151 fPaddleGeoNodes[node->GetNumber()] = node;
152 }
153}
ClassImp(R3BNeulandGeoPar)
NeuLAND geometry parameter storage.
void clear() override
auto ConvertToGlobalCoordinates(const ROOT::Math::XYZVector &position, int paddleID) const -> ROOT::Math::XYZVector
auto getParams(FairParamList *) -> bool override
~R3BNeulandGeoPar() override
void printParams() override
void putParams(FairParamList *) override
std::map< int32_t, TGeoNode * > fPaddleGeoNodes
R3BNeulandGeoPar(const char *name="R3BNeulandGeoPar", const char *title="Neuland Geometry Parameters", const char *context="TestDefaultContext")
void SetNeulandGeoNode(const TGeoNode *node)
auto GetPaddleHalfLength() const -> double
TGeoNode * fNeulandGeoNode
auto ConvertToLocalCoordinates(const ROOT::Math::XYZVector &position, int paddleID) const -> ROOT::Math::XYZVector
auto ConvertGlobalToPixel(const ROOT::Math::XYZVector &position) const -> ROOT::Math::XYZVector
constexpr Int_t nPlanes