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