CbmRoot
Loading...
Searching...
No Matches
CbmTarget.cxx
Go to the documentation of this file.
1/* Copyright (C) 2006-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer] */
4
10#include "CbmTarget.h"
11
12#include "TGeoManager.h"
13#include "TGeoMatrix.h"
14
15#include <sstream>
16
17#define RESET "\033[0m"
18#define RED "\033[1m\033[31m"
19#define GREEN "\033[32m"
20
21
22// ----- Default constructor --------------------------------------------
24 : FairModule("Target", "CBM target")
25 , fZ(0)
26 , fThickness(0.)
27 , fDiameter(0.)
28 , fDensity(0.)
29 , fPosX(0.)
30 , fPosY(0.)
31 , fPosZ(0.)
32 , fRotY(0.)
33 , fMaterial("")
34 , fBuildFromFile(kFALSE)
35{
36}
37// --------------------------------------------------------------------------
38
39
40// ----- Constructor with file name -------------------------------------
41CbmTarget::CbmTarget(const char* fileName)
42 : FairModule("Target", "CBM target")
43 , fZ(0.)
44 , fThickness(0.)
45 , fDiameter(0.)
46 , fDensity(0.)
47 , fPosX(0.)
48 , fPosY(0.)
49 , fPosZ(0.)
50 , fRotY(0.)
51 , fMaterial("")
52 , fBuildFromFile(kTRUE)
53{
54 SetGeometryFileName(fileName);
55}
56// --------------------------------------------------------------------------
57
58
59// ----- Constructor with properties ------------------------------------
60CbmTarget::CbmTarget(const char* element, Double_t thickness, Double_t diameter, Double_t density)
61 : FairModule("Target", "CBM target")
62 , fZ(0)
63 , fThickness(thickness)
64 , fDiameter(diameter)
65 , fDensity(density)
66 , fPosX(0.)
67 , fPosY(0.)
68 , fPosZ(0.)
69 , fRotY(0.)
70 , fMaterial(element)
71 , fBuildFromFile(kFALSE)
72{
73}
74// --------------------------------------------------------------------------
75
76
77// ----- Constructor with properties ------------------------------------
78CbmTarget::CbmTarget(Int_t z, Double_t thickness, Double_t diameter, Double_t density)
79 : FairModule("Target", "CBM target")
80 , fZ(z)
81 , fThickness(thickness)
82 , fDiameter(diameter)
83 , fDensity(density)
84 , fPosX(0.)
85 , fPosY(0.)
86 , fPosZ(0.)
87 , fRotY(0.)
88 , fMaterial("")
89 , fBuildFromFile(kFALSE)
90{
91}
92// --------------------------------------------------------------------------
93
94
95// ----- Construct the geometry -----------------------------------------
97{
98
99 std::cout << std::endl;
100
101 // --- Construct from ROOT file if specified
102 if (fBuildFromFile) {
103 if (!fgeoName.EndsWith(".geo.root")) {
104 LOG(info) << GetName() << ": geometry file is " << fgeoName;
105 LOG(fatal) << GetName() << ": only ROOT geometry files are supported!";
106 return;
107 }
108 LOG(info) << GetName() << ": Constructing geometry from " << fgeoName;
109 ConstructRootGeometry();
110 return;
111 }
112
113 LOG(info) << GetName() << ": Constructing geometry...";
114
115 // --- Get TGeoManager instance
116 TGeoManager* geoMan = gGeoManager;
117 assert(geoMan);
118
119 // --- Get target element
120 TGeoElement* targElem = NULL;
121 if (fZ) {
122 targElem = geoMan->GetElementTable()->GetElement(fZ);
123 if (!targElem) {
124 LOG(fatal) << GetName() << ": Unknown element " << fZ;
125 return;
126 }
127 fMaterial = targElem->GetTitle();
128 }
129 else if (!fMaterial.IsNull()) {
130 targElem = geoMan->GetElementTable()->FindElement(fMaterial.Data());
131 if (!targElem) {
132 LOG(fatal) << GetName() << ": Unknown element " << fMaterial;
133 }
134 fZ = targElem->Z();
135 }
136 else {
137 LOG(fatal) << GetName() << ": Target material not specified!";
138 return;
139 }
140 LOG(info) << GetName() << ": Use material " << fMaterial << ", z = " << fZ;
141
142 // --- Get density, if not set through the constructor
144 if (fDensity < 0.) {
145 LOG(fatal) << GetName() << ": No standard density for element " << fMaterial
146 << " available: density must be set explicitly.";
147 return;
148 }
149 LOG(info) << GetName() << ": Density " << fDensity;
150
151 // --- Create target medium
152 TGeoMaterial* targMat = new TGeoMaterial("targetMaterial", targElem, fDensity);
153 if (fair::Logger::Logging("DEBUG")) targMat->Print();
154 // The medium ID (second argument) has no meaning for transport
155 TGeoMedium* targMedium = new TGeoMedium("targetMedium", 9999, targMat);
156 targMedium->SetParam(0, 1.); // is active
157 targMedium->SetParam(1, 1.); // is in magnetic field
158 targMedium->SetParam(2, 20.); // max. field [kG]
159 targMedium->SetParam(6, 0.001); // boundary crossing precisison [cm]
160
161 // --- Get mother node
162 TGeoNode* motherNode = geoMan->FindNode(fPosX, fPosY, fPosZ);
163 if (!motherNode) {
164 LOG(fatal) << GetName() << ": No mother node found at target position!";
165 return;
166 }
167 LOG(info) << GetName() << ": Mother node is " << motherNode->GetName();
168
169 // Construct the transformation matrix for positioning of the target
170 // in its mother volume. The matrix is the inverse of the global
171 // transformation matrix of the mother node (thus assuring that the
172 // target is correctly placed w.r.t. the global c.s.) plus a translation
173 // in the global c.s. defined by the desired target position.
174 TGeoHMatrix r1 = geoMan->GetCurrentMatrix()->Inverse();
175 TGeoTranslation r2 = TGeoTranslation(fPosX, fPosY, fPosZ);
176 TGeoRotation* target_rotation = new TGeoRotation();
177 target_rotation->RotateY(fRotY * TMath::RadToDeg());
178 TGeoHMatrix* targetMatrix = new TGeoHMatrix("targetToGlobal");
179 *targetMatrix = r1 * r2 * *target_rotation;
180
181 // --- Create target volume and add it as node to the mother volume
182 TGeoVolume* target = geoMan->MakeTube("target", targMedium, 0., fDiameter / 2., fThickness / 2.);
183 motherNode->GetVolume()->AddNode(target, 0, targetMatrix);
184
185 // --- Check the resulting transformation from target to global
186 TGeoNode* testNode = geoMan->FindNode(fPosX, fPosY, fPosZ);
187 LOG(debug) << GetName() << ": Test node is " << testNode->GetName();
188 TGeoHMatrix* testMatrix = geoMan->GetCurrentMatrix();
189 if (fair::Logger::Logging("DEBUG")) testMatrix->Print();
190
191 std::cout << std::endl;
192}
193// --------------------------------------------------------------------------
194
195
196// ----- Normal vector --------------------------------------------------
197TVector3 CbmTarget::GetNormal() const { return TVector3(TMath::Sin(fRotY), 0., TMath::Cos(fRotY)); }
198// --------------------------------------------------------------------------
199
200
201// ----- Get the density at standard conditions -------------------------
202Double_t CbmTarget::GetStandardDensity(Int_t charge) const
203{
204
205 // TODO: Better implementation with array or the like
206
207 switch (charge) {
208 case 1: return 0.07085; break; // Liquid Hydrogen (20˚K at 1 atm)
209 case 4: return 1.848; break; // Beryllium
210 case 6: return 2.260; break; // Carbon
211 case 28: return 8.908; break; // Nickel
212 case 47: return 10.490; break; // Silver
213 case 49: return 7.310; break; // Indium
214 case 79: return 19.320; break; // Gold
215 case 82: return 11.342; break; // Lead
216 default: return -1.; break; // Not found
217 }
218
219 return -1.;
220}
221// --------------------------------------------------------------------------
222
223
224// ----- Downstream surface centre --------------------------------------
226{
227 return TVector3(fPosX + 0.5 * fThickness * TMath::Sin(fRotY), fPosY, fPosZ + 0.5 * fThickness * TMath::Cos(fRotY));
228}
229// --------------------------------------------------------------------------
230
231
232// ----- Upstream surface centre ----------------------------------------
234{
235 return TVector3(fPosX - 0.5 * fThickness * TMath::Sin(fRotY), fPosY, fPosZ - 0.5 * fThickness * TMath::Cos(fRotY));
236}
237// --------------------------------------------------------------------------
238
239
240// ----- Set a geometry file (overloaded from base class) ---------------
241void CbmTarget::SetGeometryFileName(TString name, TString version)
242{
243 fBuildFromFile = kTRUE;
244 LOG(info) << "Using target file name " << name;
245 return FairModule::SetGeometryFileName(name, version);
246}
247// --------------------------------------------------------------------------
248
249
250// ----- Info -----------------------------------------------------------
251std::string CbmTarget::ToString() const
252{
253
254 std::stringstream ss;
255
256 if (fBuildFromFile)
257 ss << GetName() << ": Geometry file " << fgeoName;
258
259 else {
260 ss << GetName() << ": Material " << fMaterial;
261 if (fDensity >= 0.)
262 ss << ", density " << fDensity << " g/cm^3, ";
263 else
264 ss << ", standard density, ";
265 ss << "thickness " << fThickness * 10000. << " mum, diameter " << fDiameter << " cm, position (" << fPosX << ", "
266 << fPosY << ", " << fPosZ << ") cm, rotation (y) " << fRotY << " rad";
267 } //? Not build from geometry file
268
269 return ss.str();
270}
271// --------------------------------------------------------------------------
272
273
ClassImp(CbmConverterManager)
Class for constructing the geometry of the CBM target.
Definition CbmTarget.h:37
Double_t fPosX
Target centre position in x [cm].
Definition CbmTarget.h:190
Bool_t fBuildFromFile
Flag for building from geometry file.
Definition CbmTarget.h:195
CbmTarget()
Default constructor.
Definition CbmTarget.cxx:23
Double_t GetStandardDensity(Int_t charge) const
virtual void ConstructGeometry()
Built the ROOT geometry.
Definition CbmTarget.cxx:96
Double_t fDensity
Density of target material [g/cm^3].
Definition CbmTarget.h:189
Double_t fRotY
Target rotation angle around the y axis [rad].
Definition CbmTarget.h:193
TVector3 GetSurfaceCentreUp() const
Upstream surface centre.
Double_t fThickness
Thickness [cm].
Definition CbmTarget.h:187
TVector3 GetSurfaceCentreDown() const
Downstream surface centre.
TString fMaterial
Material name.
Definition CbmTarget.h:194
std::string ToString() const
Info.
Int_t fZ
Atomic charge of target material.
Definition CbmTarget.h:186
TVector3 GetNormal() const
Normal vector.
Double_t fPosZ
Target centre position in z [cm].
Definition CbmTarget.h:192
Double_t fDiameter
Diameter [cm].
Definition CbmTarget.h:188
Double_t fPosY
Target centre position in y [cm].
Definition CbmTarget.h:191
virtual void SetGeometryFileName(TString name, TString geoVer="0")
Output to stdout.