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