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