FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairGeoTorus.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 : M. Al-Turany 06/11/2006
9 
11 //
12 // FairGeoTorus
13 //
14 // class for the shape Torus
15 // A torus has 5 parameters :
16 // R - axial radius
17 // Rmin - inner radius
18 // Rmax - outer radius
19 // Phi1 - starting phi
20 // Dphi - phi extent
22 #include "FairGeoTorus.h"
23 
24 #include "FairGeoTransform.h" // for FairGeoTransform
25 #include "FairGeoVector.h" // for FairGeoVector
26 #include "FairGeoVolume.h" // for FairGeoVolume
27 
28 #include <TArrayD.h> // for TArrayD
29 #include <TString.h> // for TString
30 #include <fstream>
31 #include <ostream> // for basic_ostream::write
32 #include <stdio.h> // for printf, sprintf, sscanf
33 #include <string.h> // for strlen
34 
36 
39 {
40  // constructor
41  fName = "TORUS";
42  nPoints = 5;
43  nParam = 5;
44  param = new TArrayD(nParam);
45 }
46 
48 {
49  // destructor
50  if (param) {
51  delete param;
52  param = 0;
53  }
54  if (center) {
55  delete center;
56  center = 0;
57  }
58  if (position) {
59  delete position;
60  position = 0;
61  }
62 }
63 
64 Int_t FairGeoTorus::readPoints(std::fstream* pFile, FairGeoVolume* volu)
65 {
66  // reads nPoints with 3 components from Ascii file
67  // if the array of points is not existing in the volume it is created and
68  // the values are stored inside
69  // returns the number of points
70  if (!pFile) {
71  return 0;
72  }
73  if (volu->getNumPoints() != nPoints) {
74  volu->createPoints(nPoints);
75  }
76  Double_t x;
77  const Int_t maxbuf = 155;
78  Text_t buf[maxbuf];
79  for (Int_t i = 0; i < nPoints; i++) {
80  pFile->getline(buf, maxbuf);
81  sscanf(buf, "%lf", &x);
82  volu->setPoint(i, x, 0, 0);
83  }
84  return nPoints;
85 }
86 
88 {
89  // calculates the parameters needed to create the shape
90 
91  for (Int_t i = 0; i < 3; i++) {
92  FairGeoVector v = *(volu->getPoint(i));
93  v *= (1 / 10.);
94  param->AddAt(v(0), i);
95  }
96  FairGeoVector v = *(volu->getPoint(3));
97  param->AddAt(v(0), 3);
98 
99  v = *(volu->getPoint(4));
100  param->AddAt(v(0), 4);
101 
102  return param;
103 }
104 
105 Bool_t FairGeoTorus::writePoints(std::fstream* pFile, FairGeoVolume* volu)
106 {
107  // writes the 4 'points' decribed above to ascii file
108  if (!pFile) {
109  return kFALSE;
110  }
111  Text_t buf[155];
112  for (Int_t i = 0; i < nPoints; i++) {
113  FairGeoVector& v = *(volu->getPoint(i));
114  sprintf(buf, "%9.3f\n", v(0));
115  pFile->write(buf, strlen(buf));
116  }
117  return kTRUE;
118 }
119 
121 {
122  // prints volume points to screen
123  for (Int_t i = 0; i < nPoints; i++) {
124  FairGeoVector& v = *(volu->getPoint(i));
125  printf("%9.3f\n", v(0));
126  }
127 }
128 
130 {
131  // calls the function posInMother(...) to calculate the position of the
132  // volume in its mother
133  Double_t t[3] = {0., 0., 0.};
135  posInMother(dTC, mTR);
136 }
void posInMother(const FairGeoTransform &, const FairGeoTransform &)
void setTransVector(const FairGeoVector &t)
void printPoints(FairGeoVolume *volu)
void setPoint(const Int_t, const Double_t, const Double_t, const Double_t)
Int_t readPoints(std::fstream *pFile, FairGeoVolume *volu)
FairGeoTransform * center
ClassImp(FairEventBuilder)
TArrayD * calcVoluParam(FairGeoVolume *)
void createPoints(const Int_t)
void calcVoluPosition(FairGeoVolume *, const FairGeoTransform &, const FairGeoTransform &)
FairGeoVector * getPoint(const Int_t n)
Definition: FairGeoVolume.h:85
Int_t getNumPoints()
Definition: FairGeoVolume.h:51
FairGeoTransform * position
Bool_t writePoints(std::fstream *, FairGeoVolume *)