FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairGeoBasicShape.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 : 11/11/2003 by Ilse Koenig
10 //*-- Modified : 29/06/99 by Ilse Koenig
11 
13 //
14 // FairGeoBasicShape
15 //
16 // Base class of the all shapes
17 //
19 #include "FairGeoBasicShape.h"
20 
21 #include "FairGeoTransform.h" // for FairGeoTransform
22 #include "FairGeoVector.h" // for FairGeoVector
23 #include "FairGeoVolume.h" // for FairGeoVolume
24 
25 #include <TArrayD.h> // for TArrayD
26 #include <fstream> // for fstream
27 #include <iostream> // for cout
28 #include <stdio.h> // for printf, sprintf, sscanf
29 #include <string.h> // for strlen
30 
31 using std::cout;
32 
34 
36  : TNamed()
37  , nPoints(0)
38  , nParam(0)
39  , param(0)
40  , center(new FairGeoTransform())
41  , position(new FairGeoTransform())
42 {
43  // default constructor
44 }
45 
47 {
48  // destructor
49  if (param) {
50  delete param;
51  param = 0;
52  }
53  if (center) {
54  delete center;
55  center = 0;
56  }
57  if (position) {
58  delete position;
59  position = 0;
60  }
61 }
62 
63 Int_t FairGeoBasicShape::readPoints(std::fstream* pFile, FairGeoVolume* volu)
64 {
65  // reads nPoints with 3 components from Ascii file
66  // if the array of points is not existing in the volume it is created and
67  // the values are stored inside
68  // returns the number of points
69  if (!pFile) {
70  return 0;
71  }
72  if (volu->getNumPoints() != nPoints) {
73  volu->createPoints(nPoints);
74  }
75  Double_t x, y, z;
76  const Int_t maxbuf = 155;
77  Text_t buf[maxbuf];
78  for (Int_t i = 0; i < nPoints; i++) {
79  pFile->getline(buf, maxbuf);
80  sscanf(buf, "%lf%lf%lf", &x, &y, &z);
81  volu->setPoint(i, x, y, z);
82  }
83  return nPoints;
84 }
85 
86 Bool_t FairGeoBasicShape::writePoints(std::fstream* pFile, FairGeoVolume* volu)
87 {
88  // writes nPoints with 3 components to Ascii file
89  if (!pFile) {
90  return kFALSE;
91  }
92  Text_t buf[155];
93  for (Int_t i = 0; i < volu->getNumPoints(); i++) {
94  FairGeoVector& v = *(volu->getPoint(i));
95  sprintf(buf, "%9.3f%10.3f%10.3f\n", v(0), v(1), v(2));
96  pFile->write(buf, strlen(buf));
97  }
98  return kTRUE;
99 }
100 
102 {
103  // prints nPoints with 3 components to screen
104  for (Int_t i = 0; i < volu->getNumPoints(); i++) {
105  FairGeoVector& v = *(volu->getPoint(i));
106  printf("%9.3f%10.3f%10.3f\n", v(0), v(1), v(2));
107  }
108 }
109 
111 {
112  // calculates the relevant information to position the corresponding volume
113  // in its mother and to position later other components inside this volume.
114  // The transformation mTR describes the position and orientation of the
115  // mother volume (center) relative to the physical coordinate system of
116  // the volume from which it was created.
117  FairGeoTransform& dTC = volu->getTransform();
118  calcVoluPosition(volu, dTC, mTR);
119 }
120 
122 {
123  // calculates the position of the volume inside its mother
124  // dTC is the coordinate system of the ROOT volume relative to its physical
125  // coordinate system
126  // mTR is the coordinate system of the mother volume relative to its
127  // physical coordinate system
130  position->transFrom(dTC);
131  position->transTo(mTR);
133  position->setTransVector(t *= 0.1);
134 }
135 
137 {
138  // prints the parameters of the ROOT shape
139  if (param) {
140  for (Int_t i = 0; i < nParam; i++) {
141  cout << param->At(i) << " ";
142  }
143  cout << '\n';
144  }
145 }
void posInMother(const FairGeoTransform &, const FairGeoTransform &)
virtual void calcVoluPosition(FairGeoVolume *, const FairGeoTransform &)
void setTransVector(const FairGeoVector &t)
virtual Bool_t writePoints(std::fstream *, FairGeoVolume *)
void setPoint(const Int_t, const Double_t, const Double_t, const Double_t)
FairGeoTransform * center
ClassImp(FairEventBuilder)
const FairGeoVector & getTransVector() const
FairGeoVector transFrom(const FairGeoVector &p) const
const FairGeoRotation & getRotMatrix() const
void createPoints(const Int_t)
FairGeoVector transTo(const FairGeoVector &p) const
void setRotMatrix(const FairGeoRotation &r)
FairGeoVector * getPoint(const Int_t n)
Definition: FairGeoVolume.h:85
virtual void printPoints(FairGeoVolume *volu)
Int_t getNumPoints()
Definition: FairGeoVolume.h:51
virtual Int_t readPoints(std::fstream *, FairGeoVolume *)
FairGeoTransform & getTransform()
Definition: FairGeoVolume.h:48
FairGeoTransform * position