FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairGeoVolume.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 //*-- Modified : 27/05/99
10 
12 // FairGeoVolume
13 //
14 // Class to hold the basic geometry properties of a volume
15 // Each volume has a name, a pointer to a reference volume and
16 // a lab transformation.
17 // The reference volume defines the shape, the mother, the size
18 // and the transformation relative to the mother volume which
19 // is either the cave (for modules) or the detector (for the
20 // inner parts).
21 // As an example:
22 // The Mdc modules built at GSI (plane 1 type) are all identical
23 // independent where the sit in the cave. This module type has a
24 // fixed coordinate system. The first layers in all these modules
25 // are identical and they have the same position in the module
26 // coordinate system.
27 //
29 #include "FairGeoVolume.h"
30 
31 #include <iostream> // for operator<<, basic_ostream, etc
32 
33 using std::cout;
34 using std::endl;
35 
37 
39  : TNamed(r)
40  , shape("")
41  , mother("")
42  , points(NULL)
43  , transform(FairGeoTransform())
44  , fLabTransform(FairGeoTransform())
45  , fMedium(0)
46  , nPoints(0)
47  , fHadFormat(0)
48  , fgMCid(0)
49 {
50  // copy constructor
51  // fName=r.GetName();
52  setVolumePar(r);
53 }
54 
56 {
57  // copies all volume parameters except the name
58  shape = r.getShape();
59  mother = r.getMother();
60  Int_t n = r.getNumPoints();
61  createPoints(n);
62  for (Int_t i = 0; i < nPoints; i++) {
63  setPoint(i, *(r.getPoint(i)));
64  }
65  transform = r.getTransform();
66 }
67 
68 void FairGeoVolume::createPoints(const Int_t n)
69 {
70  // Creates n Points (objects of class FairGeoVector).
71  // If the array exists already and the size is different from n it is
72  // deleted and recreated with the new size n.
73  // If n==0 the points are deleted.
74  if (n != nPoints) {
75  nPoints = n;
76  if (n > 0) {
77  if (points != 0) {
78  points->Delete();
79  delete points;
80  }
81  points = new TObjArray(n);
82  for (Int_t i = 0; i < n; i++) {
83  points->AddAt(new FairGeoVector(), i);
84  }
85  } else {
86  if (points) {
87  points->Delete();
88  }
89  delete points;
90  points = 0;
91  }
92  }
93 }
94 
95 void FairGeoVolume::setPoint(const Int_t n, const Double_t x, const Double_t y, const Double_t z)
96 {
97  // set the 3 values of the point with index n
98  if (points && n < nPoints) {
99  FairGeoVector* v = static_cast<FairGeoVector*>(points->At(n));
100  v->setX(x);
101  v->setY(y);
102  v->setZ(z);
103  }
104 }
105 
106 void FairGeoVolume::setPoint(const Int_t n, const FairGeoVector& p)
107 {
108  // sets point with index n by copying the 3 components of point p
109  if (points && n < nPoints) {
110  FairGeoVector& v = *(static_cast<FairGeoVector*>(points->At(n)));
111  v = p;
112  }
113 }
114 
116 {
117  // clears the volume
118  // deletes the points
119  shape = "";
120  mother = "";
121  if (points) {
122  points->Delete();
123  }
124  delete points;
125  points = 0;
126  nPoints = 0;
127  transform.clear();
128 }
129 
131 {
132  // prints all parameters of a volume
133  cout << "Volume: " << (const_cast<const char*>(fName.Data()))
134  << " Shape: " << (const_cast<const char*>(shape.Data()))
135  << " Mother: " << (const_cast<const char*>(mother.Data())) << '\n';
136  cout << "Points definition " << endl;
137  if (points) {
138  for (Int_t i = 0; i < nPoints; i++) {
139  cout << (*(static_cast<FairGeoVector*>(points->At(i))));
140  }
141  }
142  cout << "Lab Transform " << endl;
144  cout << '\n';
145 }
146 
147 Double_t FairGeoVolume::getVolParameter(Int_t nPoint, Int_t pos)
148 {
149  FairGeoVector* vec = static_cast<FairGeoVector*>(points->At(nPoint));
150  if (vec) {
151  return vec->getValues(pos);
152  } else {
153  return -1;
154  }
155 }
156 
158 {
159  if (points) {
160  points->Delete();
161  delete points;
162  points = 0;
163  }
164 }
void setX(const Double_t a)
Definition: FairGeoVector.h:71
virtual ~FairGeoVolume()
void setVolumePar(FairGeoVolume &)
const TString & getMother() const
Definition: FairGeoVolume.h:47
TString mother
Definition: FairGeoVolume.h:32
void setPoint(const Int_t, const Double_t, const Double_t, const Double_t)
ClassImp(FairEventBuilder)
Double_t getVolParameter(Int_t nPoint, Int_t pos)
FairGeoTransform fLabTransform
Definition: FairGeoVolume.h:35
void setZ(const Double_t a)
Definition: FairGeoVector.h:73
void createPoints(const Int_t)
Double_t getValues(Int_t i)
Definition: FairGeoVector.h:48
FairGeoVector * getPoint(const Int_t n)
Definition: FairGeoVolume.h:85
Int_t getNumPoints()
Definition: FairGeoVolume.h:51
virtual void clear()
FairGeoTransform transform
Definition: FairGeoVolume.h:34
FairGeoTransform & getTransform()
Definition: FairGeoVolume.h:48
const TString & getShape() const
Definition: FairGeoVolume.h:46
virtual void print()
void setY(const Double_t a)
Definition: FairGeoVector.h:72
TObjArray * points
Definition: FairGeoVolume.h:33