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