FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairGeoPcon.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 // FairGeoPcon
15 //
16 // class for the GEANT shape PCON
17 //
18 // The size of a PCON 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 // (z-component not used)
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 PCON, which sits in the CAVE and is
29 // not rotated, is identical with the laboratory system.
30 //
32 #include "FairGeoPcon.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 fstream, etc
42 #include <stdio.h> // for printf, sprintf, sscanf
43 #include <string.h> // for strlen
44 
46 
49 {
50  // constructor
51  fName = "PCON";
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 FairGeoPcon::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  if (i != 1) {
92  sscanf(buf, "%lf%lf%lf", &x, &y, &z);
93  volu->setPoint(i, x, y, z);
94  } else {
95  sscanf(buf, "%lf%lf", &x, &y);
96  volu->setPoint(i, x, y, 0.0);
97  }
98  }
99  return nPoints;
100 }
101 
102 Bool_t FairGeoPcon::writePoints(std::fstream* pFile, FairGeoVolume* volu)
103 {
104  // writes the 'points' decribed above to ascii file
105  if (!pFile) {
106  return kFALSE;
107  }
108  Text_t buf[155];
109  for (Int_t i = 0; i < volu->getNumPoints(); i++) {
110  FairGeoVector& v = *(volu->getPoint(i));
111  switch (i) {
112  case 0:
113  sprintf(buf, "%3i\n", static_cast<Int_t>(v(0)));
114  break;
115  case 1:
116  sprintf(buf, "%9.3f%10.3f\n", v(0), v(1));
117  break;
118  default:
119  sprintf(buf, "%9.3f%10.3f%10.3f\n", v(0), v(1), v(2));
120  }
121  pFile->write(buf, strlen(buf));
122  }
123  return kTRUE;
124 }
125 
127 {
128  // prints volume points to screen
129  for (Int_t i = 0; i < volu->getNumPoints(); i++) {
130  FairGeoVector& v = *(volu->getPoint(i));
131  switch (i) {
132  case 0:
133  printf("%3i\n", static_cast<Int_t>(v(0)));
134  break;
135  case 1:
136  printf("%9.3f%10.3f\n", v(0), v(1));
137  break;
138  default:
139  printf("%9.3f%10.3f%10.3f\n", v(0), v(1), v(2));
140  }
141  }
142 }
143 
145 {
146  // calculates the parameters needed to create the shape PCON
147  Double_t fac = 10.;
148  nPoints = volu->getNumPoints();
149  nParam = (nPoints - 1) * 3;
150  if (param && param->GetSize() != nParam) {
151  delete param;
152  param = 0;
153  }
154  if (!param) {
155  param = new TArrayD(nParam);
156  }
157  FairGeoVector& v1 = *(volu->getPoint(1));
158  Int_t k = 0;
159  param->AddAt(v1(0), k++);
160  param->AddAt(v1(1), k++);
161  param->AddAt((nPoints - 2), k++);
162  for (Int_t i = 2; i < nPoints; i++) {
163  FairGeoVector& v = *(volu->getPoint(i));
164  param->AddAt(v(0) / fac, k++);
165  param->AddAt(v(1) / fac, k++);
166  param->AddAt(v(2) / fac, k++);
167  }
168  return param;
169 }
170 
172 {
173  // calls the function posInMother(...) to calculate the position of the
174  // volume in its mother
175  center->clear();
176  posInMother(dTC, mTR);
177 }
void posInMother(const FairGeoTransform &, const FairGeoTransform &)
void setPoint(const Int_t, const Double_t, const Double_t, const Double_t)
Int_t readPoints(std::fstream *, FairGeoVolume *)
Definition: FairGeoPcon.cxx:67
void printPoints(FairGeoVolume *volu)
FairGeoTransform * center
ClassImp(FairEventBuilder)
Bool_t writePoints(std::fstream *, FairGeoVolume *)
void createPoints(const Int_t)
TArrayD * calcVoluParam(FairGeoVolume *)
FairGeoVector * getPoint(const Int_t n)
Definition: FairGeoVolume.h:85
Int_t getNumPoints()
Definition: FairGeoVolume.h:51
void calcVoluPosition(FairGeoVolume *, const FairGeoTransform &, const FairGeoTransform &)
FairGeoTransform * position