FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairGeoPgon.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 : 26/11/2001 by Ilse Koenig
11 
13 //
14 // FairGeoPgon
15 //
16 // class for the GEANT shape PGON
17 //
18 // The size of a PGON is defined by a variable number of 'points'.
19 // point 0: number of planes perpendicular to the z axis where the
20 // dimension of the section is given;
21 // point 1: azimutal angle phi at which the volume begins,
22 // opening angle dphi of the volume,
23 // number of sides of the cross section between the phi-limits;
24 // point 2ff: z coordinate of the section,
25 // inner radius at position z,
26 // outer radius at position z;
27 //
28 // The intrinsic coordinate system of a PGON, which sits in the CAVE and is
29 // not rotated, is identical with the laboratory system.
30 //
32 #include "FairGeoPgon.h"
33 
34 #include "FairGeoTransform.h" // for FairGeoTransform
35 #include "FairGeoVector.h" // for FairGeoVector
36 #include "FairGeoVolume.h" // for FairGeoVolume
37 
38 #include <TArrayD.h> // for TArrayD
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 = "PGON";
52  nPoints = 0;
53  nParam = 0;
54 }
55 
57 {
58  // default destructor
59  delete param;
60  param = 0;
61  delete center;
62  center = 0;
63  delete position;
64  position = 0;
65 }
66 
67 Int_t FairGeoPgon::readPoints(std::fstream* pFile, FairGeoVolume* volu)
68 {
69  // reads the 'points' decribed above from ascii file and stores them in the
70  // array 'points' of the volume
71  // returns the number of points
72  if (!pFile) {
73  return 0;
74  }
75  Double_t x, y, z;
76  const Int_t maxbuf = 155;
77  Text_t buf[maxbuf];
78  pFile->getline(buf, maxbuf);
79  Int_t n;
80  sscanf(buf, "%i", &n);
81  if (n <= 0) {
82  return 0;
83  }
84  nPoints = n + 2;
85  if (volu->getNumPoints() != nPoints) {
86  volu->createPoints(nPoints);
87  }
88  volu->setPoint(0, static_cast<Double_t>(n), 0.0, 0.0);
89  for (Int_t i = 1; i < nPoints; i++) {
90  pFile->getline(buf, maxbuf);
91  sscanf(buf, "%lf%lf%lf", &x, &y, &z);
92  volu->setPoint(i, x, y, z);
93  }
94  return nPoints;
95 }
96 
97 Bool_t FairGeoPgon::writePoints(std::fstream* pFile, FairGeoVolume* volu)
98 {
99  // writes the 'points' decribed above to ascii file
100  if (!pFile) {
101  return kFALSE;
102  }
103  Text_t buf[155];
104  for (Int_t i = 0; i < volu->getNumPoints(); i++) {
105  FairGeoVector& v = *(volu->getPoint(i));
106  if (i != 0) {
107  sprintf(buf, "%9.3f%10.3f%10.3f\n", v(0), v(1), v(2));
108  } else {
109  sprintf(buf, "%3i\n", static_cast<Int_t>(v(0)));
110  }
111  pFile->write(buf, strlen(buf));
112  }
113  return kTRUE;
114 }
115 
117 {
118  // prints volume points to screen
119  for (Int_t i = 0; i < volu->getNumPoints(); i++) {
120  FairGeoVector& v = *(volu->getPoint(i));
121  if (i != 0) {
122  printf("%9.3f%10.3f%10.3f\n", v(0), v(1), v(2));
123  } else {
124  printf("%3i\n", static_cast<Int_t>(v(0)));
125  }
126  }
127 }
128 
130 {
131  // calculates the parameters needed to create the shape PGON
132  Double_t fac = 10.;
133  nPoints = volu->getNumPoints();
134  nParam = nPoints * 3 - 2;
135  if (param && param->GetSize() != nParam) {
136  delete param;
137  param = 0;
138  }
139  if (!param) {
140  param = new TArrayD(nParam);
141  }
142  FairGeoVector& v1 = *(volu->getPoint(1));
143  Int_t k = 0;
144  param->AddAt(v1(0), k++);
145  param->AddAt(v1(1), k++);
146  param->AddAt(v1(2), k++);
147  param->AddAt((nPoints - 2), k++);
148  for (Int_t i = 2; i < nPoints; i++) {
149  FairGeoVector& v = *(volu->getPoint(i));
150  param->AddAt(v(0) / fac, k++);
151  param->AddAt(v(1) / fac, k++);
152  param->AddAt(v(2) / fac, k++);
153  }
154  return param;
155 }
156 
158 {
159  // calls the function posInMother(...) to calculate the position of the
160  // volume in its mother
161  center->clear();
162  posInMother(dTC, mTR);
163 }
void posInMother(const FairGeoTransform &, const FairGeoTransform &)
void setPoint(const Int_t, const Double_t, const Double_t, const Double_t)
FairGeoTransform * center
ClassImp(FairEventBuilder)
void printPoints(FairGeoVolume *volu)
Bool_t writePoints(std::fstream *, FairGeoVolume *)
Definition: FairGeoPgon.cxx:97
Int_t readPoints(std::fstream *, FairGeoVolume *)
Definition: FairGeoPgon.cxx:67
void calcVoluPosition(FairGeoVolume *, const FairGeoTransform &, const FairGeoTransform &)
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 *)