FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairGeoTube.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 : 28/06/99 by Ilse Koenig
11 
13 //
14 // FairGeoTube
15 //
16 // class for the GEANT shape TUBE
17 //
18 // The size of a TUBE is defined by 3 'points'.
19 // point 0: origin of starting circle of the tube;
20 // point 1: inner radius of starting circle,
21 // outer radius of starting circle;
22 // (z-component not used)
23 // point 2: origin of ending circle of the tube;
24 // Warning: The x- and y-values of point 0 and 2 have to be the same!!!!
25 // A rotation has to be desribed via the rotation matrix.
26 //
27 // The intrinsic coordinate system of a TUBE, which sits in the CAVE and is
28 // not rotated, is identical with the laboratory system.
29 //
31 #include "FairGeoTube.h"
32 
33 #include "FairGeoTransform.h" // for FairGeoTransform
34 #include "FairGeoVector.h" // for FairGeoVector
35 #include "FairGeoVolume.h" // for FairGeoVolume
36 
37 #include <TArrayD.h> // for TArrayD
38 #include <TMathBase.h> // for Abs
39 #include <TString.h> // for TString
40 #include <fstream>
41 #include <ostream> // for basic_ostream::write
42 #include <stdio.h> // for printf, sprintf, sscanf
43 #include <string.h> // for strlen
44 
46 
49 {
50  // constructor
51  fName = "TUBE";
52  nPoints = 3;
53  nParam = 3;
54  param = new TArrayD(nParam);
55 }
56 
58 {
59  // default destructor
60  delete param;
61  param = 0;
62  delete center;
63  center = 0;
64  delete position;
65  position = 0;
66 }
67 
68 Int_t FairGeoTube::readPoints(std::fstream* pFile, FairGeoVolume* volu)
69 {
70  // reads the 3 'points' decribed above from ascii file
71  // if the array of points is not existing in the volume it is created and
72  // the values are stored inside
73  // returns the number of points
74  if (!pFile) {
75  return 0;
76  }
77  if (volu->getNumPoints() != nPoints) {
78  volu->createPoints(nPoints);
79  }
80  Double_t x, y, z;
81  const Int_t maxbuf = 155;
82  Text_t buf[maxbuf];
83  for (Int_t i = 0; i < nPoints; i++) {
84  pFile->getline(buf, maxbuf);
85  if (i != 1) {
86  sscanf(buf, "%lf%lf%lf", &x, &y, &z);
87  volu->setPoint(i, x, y, z);
88  } else {
89  sscanf(buf, "%lf%lf", &x, &y);
90  volu->setPoint(i, x, y, 0.0);
91  }
92  }
93  return nPoints;
94 }
95 
96 Bool_t FairGeoTube::writePoints(std::fstream* pFile, FairGeoVolume* volu)
97 {
98  // writes the 3 'points' decribed above to ascii file
99  if (!pFile) {
100  return kFALSE;
101  }
102  Text_t buf[155];
103  for (Int_t i = 0; i < nPoints; i++) {
104  FairGeoVector& v = *(volu->getPoint(i));
105  if (i != 1) {
106  sprintf(buf, "%9.3f%10.3f%10.3f\n", v(0), v(1), v(2));
107  } else {
108  sprintf(buf, "%9.3f%10.3f\n", v(0), v(1));
109  }
110  pFile->write(buf, strlen(buf));
111  }
112  return kTRUE;
113 }
114 
116 {
117  // prints volume points to screen
118  for (Int_t i = 0; i < nPoints; i++) {
119  FairGeoVector& v = *(volu->getPoint(i));
120  if (i != 1) {
121  printf("%9.3f%10.3f%10.3f\n", v(0), v(1), v(2));
122  } else {
123  printf("%9.3f%10.3f\n", v(0), v(1));
124  }
125  }
126 }
127 
129 {
130  // calculates the parameters needed to create the shape TUBE
131  Double_t fac = 10.;
132  FairGeoVector& v1 = *(volu->getPoint(1));
133  param->AddAt(v1(0) / fac, 0);
134  param->AddAt(v1(1) / fac, 1);
135  FairGeoVector v = *(volu->getPoint(2)) - *(volu->getPoint(0));
136  param->AddAt(TMath::Abs(v(2)) / fac / 2., 2);
137  return param;
138 }
139 
141 {
142  // calculates the position of the center of the ROOT volume in the intrinsic
143  // coordinate system and stores it in the data element 'center'
144  // calls the function posInMother(...) to calculate the position of the
145  // volume in its mother
146  Double_t t[3] = {0., 0., 0.};
147  FairGeoVector v = *(volu->getPoint(2)) + *(volu->getPoint(0));
148  t[2] = v(2) / 2.;
149  center->clear();
151  posInMother(dTC, mTR);
152 }
void posInMother(const FairGeoTransform &, const FairGeoTransform &)
void calcVoluPosition(FairGeoVolume *, const FairGeoTransform &, const FairGeoTransform &)
void setTransVector(const FairGeoVector &t)
void setPoint(const Int_t, const Double_t, const Double_t, const Double_t)
void printPoints(FairGeoVolume *volu)
Bool_t writePoints(std::fstream *, FairGeoVolume *)
Definition: FairGeoTube.cxx:96
FairGeoTransform * center
ClassImp(FairEventBuilder)
Int_t readPoints(std::fstream *, FairGeoVolume *)
Definition: FairGeoTube.cxx:68
void createPoints(const Int_t)
FairGeoVector * getPoint(const Int_t n)
Definition: FairGeoVolume.h:85
Int_t getNumPoints()
Definition: FairGeoVolume.h:51
FairGeoTransform * position
TArrayD * calcVoluParam(FairGeoVolume *)