CbmRoot
Loading...
Searching...
No Matches
CbmKfTarget.cxx
Go to the documentation of this file.
1/* Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
10// TODO: Move this class somewhere in the cbmroot/core
11
12#include "CbmKfTarget.h"
13
14#include "Logger.h"
15#include "TGeoManager.h"
16#include "TGeoNode.h"
17#include "TGeoTube.h"
18#include "TGeoVolume.h"
19
20#include <iomanip>
21
22using cbm::kf::Target;
23
25std::mutex Target::fMutex;
26
27// ---------------------------------------------------------------------------------------------------------------------
28//
30{
31 std::lock_guard<std::mutex> lock(fMutex);
32 if (!fpInstance) {
33 fpInstance = new Target();
35 }
36 return fpInstance;
37}
38
39// ---------------------------------------------------------------------------------------------------------------------
40//
41void Target::FindTargetNode(TString& targetPath, TGeoNode*& targetNode)
42{
43 if (!targetNode) { // init at the top of the tree
44 targetNode = gGeoManager->GetTopNode();
45 targetPath = "/" + TString(targetNode->GetName());
46 }
47
48 if (TString(targetNode->GetName()).Contains("target")) {
49 return;
50 }
51
52 for (Int_t iNode = 0; iNode < targetNode->GetNdaughters(); ++iNode) {
53 TGeoNode* newNode = targetNode->GetDaughter(iNode);
54 TString newPath = targetPath + "/" + newNode->GetName();
55 FindTargetNode(newPath, newNode);
56 if (newNode) {
57 targetPath = newPath;
58 targetNode = newNode;
59 return;
60 }
61 }
62 targetPath = "";
63 targetNode = nullptr;
64}
65
66// ---------------------------------------------------------------------------------------------------------------------
67//
69{
70 if (!gGeoManager) {
71 throw std::logic_error("cbm::kf::Target: the TGeoManager instance is not initialized on this step. Please be "
72 "ensured to call the Target::Init() after the TGeoManager initialization.");
73 }
74
75 TString targetPath;
76 TGeoNode* pTargetNode{nullptr};
77 FindTargetNode(targetPath, pTargetNode);
78
79 if (!pTargetNode) {
80 throw std::runtime_error("cbm::kf::Target: the target node is not found in the setup");
81 }
82
83 Double_t local[3] = {0., 0., 0.}; // target centre, local c.s.
84 Double_t global[3] = {0}; // target centre, global c.s.
85 gGeoManager->cd(targetPath);
86 gGeoManager->GetCurrentMatrix()->LocalToMaster(local, global);
87 fX = global[0];
88 fY = global[1];
89 fZ = global[2];
90
91 if (const auto* pTube = dynamic_cast<TGeoTube*>(pTargetNode->GetVolume()->GetShape())) {
92 fDz = pTube->GetDz();
93 fRmax = pTube->GetRmax();
94 }
95 else {
96 throw std::logic_error("cbm::kf::Target: target is supposed to be a Tube, but it is not. Please, "
97 "provide a proper handling of the new target shape (return it's reference central point "
98 "and half of its thickness)");
99 }
100}
Target property initialization and access in CBM (source)
CBM target accessor and property handler.
Definition CbmKfTarget.h:25
void Init()
Target initializer.
static std::mutex fMutex
Definition CbmKfTarget.h:73
Target()=default
Default constructor.
static Target * Instance()
Instance access.
static Target * fpInstance
Definition CbmKfTarget.h:72
double fRmax
target transverse size [cm]
Definition CbmKfTarget.h:69
double fDz
target half-thickness [cm]
Definition CbmKfTarget.h:68
double fZ
reference z-coordinate of the target position [cm]
Definition CbmKfTarget.h:67
double fX
reference x-coordinate of the target position [cm]
Definition CbmKfTarget.h:65
double fY
reference y-coordinate of the target position [cm]
Definition CbmKfTarget.h:66
static void FindTargetNode(TString &targetPath, TGeoNode *&targetNode)
Finds a target.