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 "TGeoBBox.h"
16#include "TGeoMatrix.h"
17#include "TVector3.h"
18#include <algorithm>
19#include <iostream>
20
21#include "FairParamList.h"
22
23R3BNeulandGeoPar::R3BNeulandGeoPar(const char* name, const char* title, const char* context)
24 : FairParGenericSet(name, title, context)
25 , fNeulandGeoNode(nullptr)
26{
27}
28
30{
31 // Note: Deleting stuff here or in clear() causes segfaults?
32}
33
35
36void R3BNeulandGeoPar::putParams(FairParamList* l)
37{
38 if (!l)
39 {
40 return;
41 }
42 l->addObject("NeulandGeoNode", fNeulandGeoNode);
43}
44
45Bool_t R3BNeulandGeoPar::getParams(FairParamList* l)
46{
47 if (!l)
48 {
49 return kFALSE;
50 }
51 if (!l->fillObject("NeulandGeoNode", fNeulandGeoNode))
52 {
53 return kFALSE;
54 }
55 BuildPaddleLookup();
56 return kTRUE;
57}
58
60{
61 std::cout << "R3BNeulandGeoPar: Neuland Paddle Positions ...\n";
62
63 fNeulandGeoNode->GetMatrix()->Print();
64
65 for (Int_t i = 0; i < fNeulandGeoNode->GetNdaughters(); i++)
66 {
67 TGeoNode* node = fNeulandGeoNode->GetDaughter(i);
68 std::cout << node->GetNumber() << "\n";
69 node->GetMatrix()->Print();
70 }
71}
72
73void R3BNeulandGeoPar::SetNeulandGeoNode(const TGeoNode* const p)
74{
75 fNeulandGeoNode = dynamic_cast<TGeoNode*>(p->Clone());
76 BuildPaddleLookup();
77}
78
80{
81 // All paddles have to have the same length
82 return (dynamic_cast<TGeoBBox*>(fNeulandGeoNode->GetDaughter(0)->GetVolume()->GetShape()))->GetDX();
83}
84
85// Convert positions of e.g. points to the local coordinate of the respective paddle [(-135,135),(-2.5,2.5),(-2.5,2.5)]
86TVector3 R3BNeulandGeoPar::ConvertToLocalCoordinates(const TVector3& position, const Int_t paddleID) const
87{
88 Double_t pos_in[3] = { position.X(), position.Y(), position.Z() };
89 Double_t pos_tmp[3];
90 Double_t pos_out[3];
91
92 // First, convert to Neuland-local coordinates (consisting of all paddles)
93 fNeulandGeoNode->GetMatrix()->MasterToLocal(pos_in, pos_tmp);
94 // Second, convert to the repective paddle
95 fPaddleGeoNodes.at(paddleID)->MasterToLocal(pos_tmp, pos_out);
96
97 return TVector3(pos_out[0], pos_out[1], pos_out[2]);
98}
99
100TVector3 R3BNeulandGeoPar::ConvertToGlobalCoordinates(const TVector3& position, const Int_t paddleID) const
101{
102 Double_t pos_in[3] = { position.X(), position.Y(), position.Z() };
103 Double_t pos_tmp[3];
104 Double_t pos_out[3];
105
106 // Note reverse order of Global->Local
107 fPaddleGeoNodes.at(paddleID)->LocalToMaster(pos_in, pos_tmp);
108
109 fNeulandGeoNode->GetMatrix()->LocalToMaster(pos_tmp, pos_out);
110
111 return TVector3(pos_out[0], pos_out[1], pos_out[2]);
112}
113
114TVector3 R3BNeulandGeoPar::ConvertGlobalToPixel(const TVector3& position) const
115{
116 const Int_t nPixels = 50;
117 const Double_t sizePixel = 5;
118 const Int_t nPaddles = fNeulandGeoNode->GetNdaughters();
119 const Int_t nPlanes = nPaddles / nPixels;
120
121 Double_t pos_in[3] = { position.X(), position.Y(), position.Z() };
122 Double_t pos_tmp[3];
123
124 // First, convert to Neuland-local coordinates (consisting of all paddles)
125 fNeulandGeoNode->GetMatrix()->MasterToLocal(pos_in, pos_tmp);
126
127 // Note: PaddleHalfLength is 135 (light guides)
128 // Map x and y values with [-125.:125.] float to [0:nPixels-1] int
129 const Int_t x = std::min(std::max<Int_t>(0, pos_tmp[0] / sizePixel + nPixels / 2), nPixels - 1);
130 const Int_t y = std::min(std::max<Int_t>(0, pos_tmp[1] / sizePixel + nPixels / 2), nPixels - 1);
131
132 // Map z to [0:nPlanes-1]
133 const Int_t z = std::min(std::max<Int_t>(0, pos_tmp[2] / sizePixel + nPlanes / 2), nPlanes - 1);
134
135 return TVector3(x, y, z);
136}
137
138void R3BNeulandGeoPar::BuildPaddleLookup()
139{
140 for (Int_t i = 0; i < fNeulandGeoNode->GetNdaughters(); i++)
141 {
142 TGeoNode* node = fNeulandGeoNode->GetDaughter(i);
143 fPaddleGeoNodes[node->GetNumber()] = node;
144 }
145}
ClassImp(R3BNeulandGeoPar)
NeuLAND geometry parameter storage.
void clear() override
~R3BNeulandGeoPar() override
TVector3 ConvertToGlobalCoordinates(const TVector3 &position, const Int_t paddleID) const
void SetNeulandGeoNode(const TGeoNode *const p)
void printParams() override
TVector3 ConvertGlobalToPixel(const TVector3 &position) const
void putParams(FairParamList *) override
R3BNeulandGeoPar(const char *name="R3BNeulandGeoPar", const char *title="Neuland Geometry Parameters", const char *context="TestDefaultContext")
Bool_t getParams(FairParamList *) override
Double_t GetPaddleHalfLength() const
TVector3 ConvertToLocalCoordinates(const TVector3 &position, const Int_t paddleID) const
TGeoNode * fNeulandGeoNode
constexpr Int_t nPlanes