Project
Loading...
Searching...
No Matches
FairGeoNode.cxx
Go to the documentation of this file.
1/********************************************************************************
2 * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3 * *
4 * This software is distributed under the terms of the *
5 * GNU Lesser General Public Licence (LGPL) version 3, *
6 * copied verbatim in the file "LICENSE" *
7 ********************************************************************************/
8//*-- AUTHOR : Ilse Koenig
9//*-- Created : 10/11/2003
10//*---Modified: 21/06/2005 D.Bertini
11
13// FairGeoNode
14//
15// Class to hold the basic geometry properties of a GEANT volume
16//
18#include "FairGeoNode.h"
19
20#include "FairGeoRotation.h" // for FairGeoRotation
21#include "FairGeoVector.h" // for FairGeoVector
22
23#include <TList.h> // for TList
24#include <cmath> // IWYU pragma: keep for abs
25// IWYU pragma: no_include <architecture/i386/math.h>
26#include <cstdio> // for sscanf
27#include <fstream>
28#include <iostream> // for operator<<, basic_ostream, etc
29
30using std::cout;
31using std::endl;
32
34
37 , active(kFALSE)
39 , volumeType(kFairGeoElement)
40 , created(kFALSE)
41 , copyNode(nullptr)
42 , rootVolume(nullptr)
43 , pShape(0)
44 , pMother(nullptr)
45 , medium(nullptr)
46 , labTransform(nullptr)
47 , fDaughterList(new TObjArray(5))
48 , fTruncName("")
49{
50 // Constructor
51 clear();
52}
53
56 , active(kFALSE)
57 , center(r.getCenterPosition())
58 , volumeType(r.getVolumeType())
59 , created(kFALSE)
60 , copyNode(r.getCopyNode())
61 , rootVolume(r.getRootVolume())
62 , pShape(nullptr)
63 , pMother(nullptr)
64 , medium(nullptr)
65 , labTransform(new FairGeoTransform(*(r.getLabTransform())))
66 , fDaughterList(new TObjArray(*(r.GetListOfDaughters())))
67 , fTruncName(r.getTruncName())
68{
69 // Copy constructor
70 points = 0;
71 nPoints = 0;
72 fName = r.GetName();
74 if (r.isActive()) {
75 active = kTRUE;
76 }
77 if (r.isCreated()) {
78 created = kTRUE;
79 }
80}
81
83{
84 // Destructor
85 if (points) {
86 for (Int_t i = 0; i < nPoints; i++) {
87 points->RemoveAt(i);
88 }
89 delete points;
90 points = 0;
91 }
92 if (labTransform) {
93 delete labTransform;
94 labTransform = 0;
95 }
96 if (fDaughterList) {
97 fDaughterList->Delete();
98 delete fDaughterList;
99 }
100}
101
103{
104 // Copies all volume parameters except the name
105 setMother(r.getMotherNode());
106 medium = r.getMedium();
107 setShape(r.getShapePointer());
108 Int_t n = r.getNumPoints();
110 for (Int_t i = 0; i < nPoints; i++) {
111 setPoint(i, *(r.getPoint(i)));
112 }
113 transform = r.getTransform();
114}
115
117{
118 // Clears the volume and deletes the points
119 /* pMother=0;
120 medium=0;
121 pShape=0;
122 volumeType=kFairGeoElement;
123 active=kFALSE;
124 created=kFALSE;
125 copyNode=0;
126 rootVolume=0;
127 */
128 if (labTransform) {
129 delete labTransform;
130 labTransform = 0;
131 }
133}
134
136{
137 // Returns the copy number
138 Int_t n = 0;
139 if (fHadFormat == 1) {
140 Int_t l = fName.Length();
141 if (l > 4) {
142 TString s(fName);
143 s.Remove(0, 4);
144 sscanf(s.Data(), "%i", &n);
145 }
146 } else {
147
148 Ssiz_t l = fName.Last('#');
149 if (l > 0) {
150 TString s(fName);
151 s.Remove(0, l + 1);
152 sscanf(s.Data(), "%i", &n);
153 }
154 }
155
156 return n;
157}
158
160{
161 // Returns the parameters to create a GEANT/ROOT volume
162 if (pShape) {
163 return pShape->calcVoluParam(this);
164 }
165 return 0;
166}
167
169{
170 // Returns the transformation to position a volume in GEANT/ROOT
171 if (pShape && pMother) {
174 return pShape->getVoluPosition();
175 }
176 return 0;
177}
178
180{
181 // Prints all parameters of a volume
182 cout << "//----------------------------------------------------------\n";
184 cout << "//----------------------------------------------------------\n";
185 return;
186
187 /*
188 cout<<((const char*)fName)<<'\n';
189 if (pMother) { cout<<((const char*)mother)<<'\n'; }
190 else { cout<<"-- unknown mother --\n"; }
191 if (!copyNode) {
192 if (pShape) { cout<<((const char*)shape)<<'\n'; }
193 else { cout<<"-- unknown shape --\n"; }
194 if (medium) { cout<<medium->GetName()<<'\n'; }
195 else { cout<<"-- unknown medium --\n"; }
196 if (points && pShape) { pShape->printPoints(this); }
197 else { cout<<"-- no points --\n"; }
198 }
199 transform.getTransVector().print();
200 transform.getRotMatrix().print();
201 cout<<"//----------------------------------------------------------\n";
202 */
203}
204
205Bool_t FairGeoNode::write(std::fstream& fout)
206{
207 // Writes all parameters of a volume to file
208 fout << fName.Data() << '\n';
209 if (pMother) {
210 fout << (const_cast<const char*>(mother.Data())) << '\n';
211 } else {
212 Error("write", "Unknown mother for %s\n", fName.Data());
213 return kFALSE;
214 }
215 if (!copyNode) {
216 if (pShape) {
217 fout << (const_cast<const char*>(shape.Data())) << '\n';
218 } else {
219 Error("write", "Unknown shape for %s\n", fName.Data());
220 return kFALSE;
221 }
222 if (medium) {
223 fout << medium->GetName() << '\n';
224 } else {
225 Error("write", "Unknown medium for %s\n", fName.Data());
226 return kFALSE;
227 }
228 if (points && pShape) {
229 pShape->writePoints(&fout, this);
230 } else {
231 Error("write", "No points for %s\n", fName.Data());
232 return kFALSE;
233 }
234 }
237 fout.precision(3);
238 fout << v(0) << " " << v(1) << " " << v(2) << '\n';
239 fout.precision(7);
240 for (Int_t i = 0; i < 9; i++) {
241 fout << r(i) << " ";
242 }
243 fout << '\n';
244 fout << "//----------------------------------------------------------\n";
245 return kTRUE;
246}
247
249{
250 // Returns the tree of the mother volumes
251 TList* tree = new TList();
252 FairGeoNode* v = this;
253 FairGeoNode* lmother;
254 do {
255 lmother = v->getMotherNode();
256 if (lmother) {
257 tree->Add(lmother);
258 }
259 v = lmother;
260 } while (v && !v->isTopNode());
261 return tree;
262}
263
265{
266 // Returns the lab transformation
267 if (labTransform) {
268 return labTransform;
269 } else {
270 return calcLabTransform();
271 }
272}
273
275{
276 // Calculates the lab transformation
277
279
280 if (!isTopNode()) {
281 if (!pMother) {
282 Error("calcLabTransform()", "Mother volume of %s not found!", GetName());
283 delete labTransform;
284 return 0;
285 }
287 if (!tm) {
288 ;
289 Error("calcLabTransform()", "Lab Transformation of mother volume of %s not found!", GetName());
290 delete labTransform;
291 return 0;
292 }
294 }
295
297 fMedium = *medium;
298 return labTransform;
299}
300
302{
303 // Sets the lab transformation
304 if (!isTopNode()) {
305 if (labTransform) {
307 } else {
309 }
310 if (!pMother) {
311 Error("calcLabTransform()", "Mother volume of %s not found!", GetName());
312 delete labTransform;
313 return;
314 }
316 if (!tm) {
317 ;
318 Error("calcLabTransform()", "Lab Transformation of mother volume of %s not found!", GetName());
319 delete labTransform;
320 return;
321 }
322 transform = t;
323 transform.transTo(*tm);
324 }
325}
326
328{
329 // Calculates the transformation relative to the detectors coordinate system
330 FairGeoNode* node = this;
331 modTransform = transform;
332 while (node && !node->isModule()) {
334 if (!pm) {
335 Error("calcModuleTransform", "Mother volume of %s not found!", node->GetName());
336 return kFALSE;
337 }
338 modTransform.transFrom(pm->getTransform());
339 node = pm;
340 }
341 if (isTopNode()) {
342 return kFALSE;
343 } else {
344 return kTRUE;
345 }
346}
347
349{
350 // Calculates the position in the detectors coordinate system
351 FairGeoNode* node = this;
352 refPos = center.getTransVector();
353 do {
354 refPos = node->getTransform().transFrom(refPos);
355 node = node->getMotherNode();
356 if (!node) {
357 Error("calcModuleTransform", "Mother of volume %s not found!", GetName());
358 return kFALSE;
359 }
360 } while (node && !node->isModule());
361 if (isTopNode()) {
362 return kFALSE;
363 } else {
364 return kTRUE;
365 }
366}
367
369{
370 // Compares the volume with the volume rn and prints the diagnose
371 // Returns kTRUE if the volume parameters are the same
372 Int_t diff[] = {0, 0, 0, 0, 0, 0};
373 Int_t n = 0;
374 cout << fName << '\t';
375 if (mother.CompareTo(rn.getMother()) != 0) {
376 diff[0] = 1;
377 n++;
378 }
379 if (medium && rn.getMedium()) {
380 TString med = medium->GetName();
381 if (med.CompareTo(rn.getMedium()->GetName()) != 0) {
382 diff[1] = 1;
383 n++;
384 }
385 } else {
386 diff[1] = 1;
387 n++;
388 }
389 if (shape.CompareTo(rn.getShape()) != 0) {
390 diff[2] = 1;
391 n++;
392 }
393 Int_t np = rn.getNumPoints();
394 if (points && nPoints == np) {
395 for (Int_t i = 0; i < np; i++) {
397 FairGeoVector v2 = *(rn.getPoint(i));
398 if (fabs(v1(0) - v2(0)) >= 0.001 || fabs(v1(1) - v2(1)) >= 0.001 || fabs(v1(1) - v2(1)) >= 0.001) {
399 diff[3] = 1;
400 n++;
401 break;
402 }
403 }
404 } else {
405 diff[3] = 1;
406 n++;
407 }
410 if (fabs(v1(0) - v2(0)) >= 0.001 || fabs(v1(1) - v2(1)) >= 0.001 || fabs(v1(1) - v2(1)) >= 0.001) {
411 diff[4] = 1;
412 n++;
413 }
416 for (Int_t i = 0; i < 9; i++) {
417 if (fabs(r1(i) - r2(i)) >= 1.e-7) {
418 diff[5] = 1;
419 n++;
420 break;
421 }
422 }
423 if (n > 0) {
424 for (Int_t i = 0; i < 6; i++) {
425 cout << " " << diff[i] << " ";
426 }
427 cout << '\n';
428 } else {
429 cout << " same\n";
430 }
431 return n;
432}
std::unique_ptr< expressions::Node > node
ClassImp(FairGeoNode)
@ kFairGeoElement
Definition FairGeoNode.h:28
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
float center
FairGeoTransform * getCenterPosition()
FairGeoTransform * getVoluPosition()
virtual Bool_t writePoints(std::fstream *, FairGeoVolume *)
virtual void calcVoluPosition(FairGeoVolume *, const FairGeoTransform &)
virtual TArrayD * calcVoluParam(FairGeoVolume *)
FairGeoTransform * getPosition()
TList * getTree()
Int_t compare(FairGeoNode &)
FairGeoBasicShape * pShape
Definition FairGeoNode.h:52
Int_t getCopyNo()
Bool_t created
Definition FairGeoNode.h:49
FairGeoMedium * medium
/‍** pointer to the mother volume *‍/
Definition FairGeoNode.h:54
void setLabTransform(FairGeoTransform &)
Bool_t write(std::fstream &)
FairGeoNode * getMotherNode()
Definition FairGeoNode.h:73
virtual ~FairGeoNode()
FairGeoNode * copyNode
Definition FairGeoNode.h:50
Bool_t isTopNode()
Definition FairGeoNode.h:67
FairGeoTransform * getLabTransform()
FairGeoTransform center
Definition FairGeoNode.h:47
void setVolumePar(FairGeoNode &)
FairGeoTransform & getCenterPosition()
Definition FairGeoNode.h:76
Bool_t calcModuleTransform(FairGeoTransform &)
TObjArray * fDaughterList
Definition FairGeoNode.h:56
Bool_t active
Definition FairGeoNode.h:46
TArrayD * getParameters()
FairGeoTransform * calcLabTransform()
FairGeoMedium * getMedium()
Definition FairGeoNode.h:74
FairGeoNode * pMother
Definition FairGeoNode.h:53
Bool_t calcRefPos(FairGeoVector &)
void setShape(FairGeoBasicShape *s)
FairGeoTransform * labTransform
Definition FairGeoNode.h:55
void setMother(FairGeoNode *s)
void setTransform(const FairGeoTransform &t)
const FairGeoVector & getTransVector() const
const FairGeoRotation & getRotMatrix() const
FairGeoVector transTo(const FairGeoVector &p) const
FairGeoVector transFrom(const FairGeoVector &p) const
const TString & getShape() const
FairGeoVector * getPoint(const Int_t n)
TObjArray * points
virtual void print()
void setPoint(const Int_t, const Double_t, const Double_t, const Double_t)
FairGeoTransform & getTransform()
virtual void clear()
Int_t getNumPoints()
FairGeoTransform transform
const TString & getMother() const
FairGeoMedium fMedium
FairGeoTransform fLabTransform
void createPoints(const Int_t)
GLdouble n
Definition glcorearb.h:1982
const GLdouble * v
Definition glcorearb.h:832
GLfloat GLfloat v1
Definition glcorearb.h:812
GLboolean r
Definition glcorearb.h:1233
GLfloat GLfloat GLfloat v2
Definition glcorearb.h:813
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))