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