Project
Loading...
Searching...
No Matches
FairGeoTubs.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// FairGeoTubs
15//
16// class for the GEANT shape TUBS
17//
18// The size of a TUBS is defined by 4 'points'.
19// point 0: origin of starting circle of the tubs;
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 tubs;
24// point 3: starting angle of the segment,
25// ending angle of the segment;
26// (z-component not used)
27// Warning: The x- and y-values of point 0 and 2 have to be the same!!!!
28// A rotation has to be desribed via the rotation matrix.
29//
30// The intrinsic coordinate system of a TUBS, which sits in the CAVE and is
31// not rotated, is identical with the laboratory system.
32//
34#include "FairGeoTubs.h"
35
36#include "FairGeoTransform.h" // for FairGeoTransform
37#include "FairGeoVector.h" // for FairGeoVector
38#include "FairGeoVolume.h" // for FairGeoVolume
39
40#include <TArrayD.h> // for TArrayD
41#include <TMathBase.h> // for Abs
42#include <TString.h> // for TString
43#include <fstream>
44#include <ostream> // for basic_ostream::write
45#include <stdio.h> // for printf, sprintf, sscanf
46#include <string.h> // for strlen
47
49
52{
53 // constructor
54 fName = "TUBS";
55 nPoints = 4;
56 nParam = 5;
57 param = new TArrayD(nParam);
58}
59
61{
62 // default destructor
63 delete param;
64 param = 0;
65 delete center;
66 center = 0;
67 delete position;
68 position = 0;
69}
70
71Int_t FairGeoTubs::readPoints(std::fstream* pFile, FairGeoVolume* volu)
72{
73 // reads the 4 'points' decribed above from ascii file
74 // if the array of points is not existing in the volume it is created and
75 // the values are stored inside
76 // returns the number of points
77 if (!pFile) {
78 return 0;
79 }
80 if (volu->getNumPoints() != nPoints) {
81 volu->createPoints(nPoints);
82 }
83 Double_t x, y, z;
84 const Int_t maxbuf = 155;
85 Text_t buf[maxbuf];
86 for (Int_t i = 0; i < nPoints; i++) {
87 pFile->getline(buf, maxbuf);
88 sscanf(buf, "%lf%lf%lf", &x, &y, &z);
89 volu->setPoint(i, x, y, z);
90 i++;
91 pFile->getline(buf, maxbuf);
92 sscanf(buf, "%lf%lf", &x, &y);
93 volu->setPoint(i, x, y, 0.0);
94 }
95 return nPoints;
96}
97
98Bool_t FairGeoTubs::writePoints(std::fstream* pFile, FairGeoVolume* volu)
99{
100 // writes the 4 'points' decribed above to ascii file
101 if (!pFile) {
102 return kFALSE;
103 }
104 Text_t buf[155];
105 for (Int_t i = 0; i < nPoints; i++) {
106 FairGeoVector& v = *(volu->getPoint(i));
107 if (i == 0 || i == 2) {
108 sprintf(buf, "%9.3f%10.3f%10.3f\n", v(0), v(1), v(2));
109 } else {
110 sprintf(buf, "%9.3f%10.3f\n", v(0), v(1));
111 }
112 pFile->write(buf, strlen(buf));
113 }
114 return kTRUE;
115}
116
118{
119 // prints volume points to screen
120 for (Int_t i = 0; i < nPoints; i++) {
121 FairGeoVector& v = *(volu->getPoint(i));
122 if (i == 0 || i == 2) {
123 printf("%9.3f%10.3f%10.3f\n", v(0), v(1), v(2));
124 } else {
125 printf("%9.3f%10.3f\n", v(0), v(1));
126 }
127 }
128}
129
131{
132 // calculates the parameters needed to create the shape TUBS
133 Double_t fac = 10.;
134 FairGeoVector& v1 = *(volu->getPoint(1));
135 param->AddAt(v1(0) / fac, 0);
136 param->AddAt(v1(1) / fac, 1);
137 FairGeoVector v = *(volu->getPoint(2)) - *(volu->getPoint(0));
138 param->AddAt(TMath::Abs(v(2)) / fac / 2., 2);
139 FairGeoVector& v3 = *(volu->getPoint(3));
140 param->AddAt(v3(0), 3);
141 param->AddAt(v3(1), 4);
142 return param;
143}
144
146{
147 // calculates the position of the center of the volume in the intrinsic
148 // coordinate system and stores it in the data element 'center'
149 // calls the function posInMother(...) to calculate the position of the
150 // volume in its mother
151 Double_t t[3] = {0., 0., 0.};
152 FairGeoVector v = *(volu->getPoint(2)) + *(volu->getPoint(0));
153 t[2] = v(2) / 2.;
154 center->clear();
156 posInMother(dTC, mTR);
157}
ClassImp(FairGeoTubs)
int32_t i
FairGeoTransform * center
void posInMother(const FairGeoTransform &, const FairGeoTransform &)
FairGeoTransform * position
void setTransVector(const FairGeoVector &t)
TArrayD * calcVoluParam(FairGeoVolume *)
Int_t readPoints(std::fstream *, FairGeoVolume *)
void printPoints(FairGeoVolume *volu)
void calcVoluPosition(FairGeoVolume *, const FairGeoTransform &, const FairGeoTransform &)
Bool_t writePoints(std::fstream *, FairGeoVolume *)
FairGeoVector * getPoint(const Int_t n)
void setPoint(const Int_t, const Double_t, const Double_t, const Double_t)
Int_t getNumPoints()
void createPoints(const Int_t)
GLint GLenum GLint x
Definition glcorearb.h:403
const GLdouble * v
Definition glcorearb.h:832
GLint y
Definition glcorearb.h:270
GLfloat GLfloat v1
Definition glcorearb.h:812
GLfloat GLfloat GLfloat GLfloat v3
Definition glcorearb.h:814
GLenum GLfloat param
Definition glcorearb.h:271
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition glcorearb.h:2514
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843