BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
mpdshape.class.C
Go to the documentation of this file.
1
2/******************************************************************************
3 * Version: 09-Jun-2012 (EL)
4 *****************************************************************************/
5class FairGeoRotation;
6
7#include <iostream>
8#include <string>
9
10class Mpdshape : public TObject
11{
12
13 public:
15 Mpdshape(ofstream* file,
16 std::string volume_name,
17 std::string mother_volume_name,
18 std::string shape,
19 std::string media,
20 std::string points,
21 std::string position = "0. 0. 0.",
22 std::string rotation = "1. 0. 0. 0. 1. 0. 0. 0. 1.",
23 Int_t segment = 0,
24 Int_t mother_segment = 0);
25 Mpdshape(ofstream* file,
26 std::string volume_name,
27 std::string mother_volume_name,
28 std::string shape,
29 std::string media);
31
32 void SetFile(ofstream* file) { fFile = file; }
33 void SetVolumeName(std::string name) { fVolumeName = name; }
34 void SetMotherVolumeName(std::string name) { fMotherVolumeName = name; }
35 void SetShape(std::string shape) { fShape = shape; }
36 void SetMedia(std::string media) { fMedia = media; }
37 void SetPoints(std::string points) { fPoints = points; }
38
39 void SetPosition(std::string position) { fPosition = position; }
40 void SetPosition(Double_t x, Double_t y, Double_t z, Int_t precision = 6);
42
43 void SetRotation(std::string rotation) { fRotation = rotation; }
45 Double_t p2,
46 Double_t p3,
47 Double_t p4,
48 Double_t p5,
49 Double_t p6,
50 Double_t p7,
51 Double_t p8,
52 Double_t p9);
54
55 void SetPositionRotation(std::string position, std::string rotation)
56 {
57 fPosition = position;
58 fRotation = rotation;
59 }
60 void SetSegment(Int_t segment) { fSegment = segment; }
61 void SetMotherSegment(Int_t segment) { fMotherSegment = segment; }
62
63 void DumpToFile();
65 {
66 DumpToFile();
67 fSegment++;
68 }
69 static std::string itoa(Double_t x);
70
71 std::string GetVolumeName() const { return fVolumeName; }
72 Int_t GetSegment() const { return fSegment; }
73 void Clear();
74 void Fill_TUBE(Double_t length_z, Double_t r_max, Double_t r_min);
75 void Fill_TUBS(Double_t zmin, Double_t zmax, Double_t rmin, Double_t rmax, Double_t dr_st, Double_t dr_end);
76 void Fill_TRAP(Double_t x, Double_t X, Double_t yW, Double_t zW, Int_t ra = 0);
77 // void Fill_TRAP(Double_t x_small, Double_t x_large, Double_t yWidth, Double_t zWidth);
78 // void Fill_RECTRAP(Double_t x_small, Double_t x_large,Double_t xx_small, Double_t xx_large,
79 // Double_t yWidth, Double_t zWidth);
80 void Fill_PGON(Double_t zmin, Double_t zmax, Double_t rmin, Double_t rmax, Double_t phi1, Int_t nEdges = 12);
81 void Fill_BOX(Double_t xWidth, Double_t yWidth, Double_t zWidth);
82
83 protected:
84 ofstream* fFile;
85 std::string fVolumeName;
86 std::string fMotherVolumeName;
87 std::string fShape;
88 std::string fMedia;
89 std::string fPoints;
90 std::string fPosition;
91 std::string fRotation;
94 FairGeoRotation* rot;
95};
96
98{
99
100 gROOT->LoadMacro("$VMCWORKDIR/gconfig/basiclibs.C");
101 // basiclibs();
102 gSystem->Load("libGeoBase");
103 gSystem->Load("libParBase");
104 gSystem->Load("libBase");
105 rot = new FairGeoRotation();
106}
107
108Mpdshape::Mpdshape(ofstream* file,
109 std::string volume_name,
110 std::string mother_volume_name,
111 std::string shape,
112 std::string media,
113 std::string points,
114 std::string position,
115 std::string rotation,
116 Int_t segment,
117 Int_t mother_segment)
118 : fFile(file)
119 , fVolumeName(volume_name)
120 , fMotherVolumeName(mother_volume_name)
121 , fShape(shape)
122 , fMedia(media)
123 , fPoints(points)
124 , fPosition(position)
125 , fRotation(rotation)
126 , fSegment(segment)
127 , fMotherSegment(mother_segment)
128{
129
130 // gROOT->LoadMacro("$VMCWORKDIR/gconfig/basiclibs.C");
131 // basiclibs();
132 gSystem->Load("libGeoBase");
133 // gSystem->Load("libParBase");
134 // gSystem->Load("libBase");
135 rot = new FairGeoRotation();
136}
137
138Mpdshape::Mpdshape(ofstream* file,
139 std::string volume_name,
140 std::string mother_volume_name,
141 std::string shape,
142 std::string media)
143 : fFile(file)
144 , fVolumeName(volume_name)
145 , fMotherVolumeName(mother_volume_name)
146 , fShape(shape)
147 , fMedia(media)
148{
149
150 // gROOT->LoadMacro("$VMCWORKDIR/gconfig/basiclibs.C");
151 // basiclibs();
152
153 gSystem->Load("libGeoBase");
154 rot = new FairGeoRotation();
155 fSegment = 0;
156 fMotherSegment = 0;
157}
158
160
162{
163 *fFile << "//*************************************************" << endl;
164 if (fSegment > 0) {
165 *fFile << fVolumeName << "#" << fSegment << endl;
166 ;
167 } else {
168 *fFile << fVolumeName << endl;
169 }
170 if (fMotherSegment > 0) {
171 *fFile << fMotherVolumeName << "#" << fMotherSegment << endl;
172 } else {
173 *fFile << fMotherVolumeName << endl;
174 }
175
176 if (fSegment <= 1) {
177 *fFile << fShape << endl << fMedia << endl << fPoints << endl;
178 }
179 *fFile << fPosition << endl << fRotation << endl;
180}
181
182std::string Mpdshape::itoa(Double_t x)
183{
184 std::ostringstream o;
185 if (!(o << x))
186 return "ERROR";
187 return o.str();
188}
189
191{
192 ostringstream o;
193 o.precision(6);
194 o.setf(ios::showpoint);
195 o.setf(ios::fixed);
196 o << vec.x() << " " << vec.y() << " " << vec.z();
197 fPosition.append(o.str().c_str());
198}
199
201{
202 ostringstream o;
203 o.precision(precision);
204 o.setf(ios::showpoint);
205 o.setf(ios::fixed);
206 o << x << " " << y << " " << z;
207 fPosition = o.str();
208}
209
211 Double_t p2,
212 Double_t p3,
213 Double_t p4,
214 Double_t p5,
215 Double_t p6,
216 Double_t p7,
217 Double_t p8,
218 Double_t p9)
219{
220
221 std::ostringstream o;
222 o.setf(ios::showpoint);
223 o.setf(ios::fixed);
224 o.precision(10);
225 o << p1 << " " << p2 << " " << p3 << " " << p4 << " " << p5 << " " << p6 << " " << p7 << " " << p8 << " " << p9;
226 fRotation = o.str();
227}
228
230{
231 // z = phi
232 // y1 = theta
233 rot->setEulerAngles(z, y1, z1);
234 std::ostringstream o;
235 o.setf(ios::showpoint);
236 o.setf(ios::fixed);
237 o << setprecision(10);
238 for (Int_t i = 0; i < 9; i++) {
239 o << rot->operator()(i) << " ";
240 }
241 fRotation = o.str();
242}
243
244std::string itoa(Double_t x)
245{
246 std::ostringstream o;
247 if (!(o << x))
248 return "ERROR";
249 return o.str();
250}
251//______________________________________________________________
252void Mpdshape::Clear()
253{
254 fVolumeName.clear();
255 fMotherVolumeName.clear();
256 fShape.clear();
257 fMedia.clear();
258 fSegment = 0;
259 fMotherSegment = 0;
260 fPoints.clear();
261 fPosition.clear();
262 fRotation.clear();
263}
264
265//______________________________________________________________
266void Mpdshape::Fill_TUBE(Double_t length_z, Double_t r_in, Double_t r_out)
267{
268 //
269 fPoints.clear();
270 std::ostringstream o;
271 o.setf(ios::showpoint);
272 o.setf(ios::fixed);
273 o.precision(10);
274
275 o << 0.0 << " " << 0.0 << " " << -length_z << endl
276 << r_in << " " << r_out << endl
277 << 0.0 << " " << 0.0 << " " << length_z;
278
279 fPoints = o.str();
280}
281//______________________________________________________________
282void Mpdshape::Fill_TUBS(Double_t zmin, Double_t zmax, Double_t rmin, Double_t rmax, Double_t st, Double_t end)
283{
284 //
285 fPoints.clear();
286 std::ostringstream o;
287 o.setf(ios::showpoint);
288 o.setf(ios::fixed);
289 o.precision(10);
290
291 o << 0.0 << " " << 0.0 << " " << zmin << endl
292 << rmin << " " << rmax << endl
293 << 0.0 << " " << 0.0 << " " << zmax << endl
294 << st << " " << end;
295
296 fPoints = o.str();
297}
298
299//_______________________________________________________________
300void Mpdshape::Fill_PGON(Double_t zmin, Double_t zmax, Double_t rmin, Double_t rmax, Double_t phi1, Int_t nEdges)
301{
302 fPoints.clear();
303 std::ostringstream o;
304 o.setf(ios::showpoint);
305 o.setf(ios::fixed);
306 o.precision(10);
307 o << "2 " << endl
308 << phi1 << " 360 " << nEdges << endl
309 << zmin << " " << rmin << " " << rmax << endl
310 << zmax << " " << rmin << " " << rmax;
311 fPoints = o.str();
312}
313
314//______________________________________________________________
315//______________________________________________________________
316void Mpdshape::Fill_TRAP(Double_t x_small, Double_t x_large, Double_t yWidth, Double_t zWidth, Int_t right_angled)
317{
318 //
319 fPoints.clear();
320 std::ostringstream o;
321 o.setf(ios::showpoint);
322 o.setf(ios::fixed);
323 o.precision(10);
324
325 if (right_angled == 0) {
326
327 // trapezoid
328 // _____________
329 // \ / ^
330 // \ / | y /z
331 // \ /
332 // \_____/
333 // x
334
335 o << x_small << " " << -yWidth << " " << -zWidth << endl
336 << x_large << " " << yWidth << " " << -zWidth << endl
337 << -x_large << " " << yWidth << " " << -zWidth << endl
338 << -x_small << " " << -yWidth << " " << -zWidth << endl
339
340 << x_small << " " << -yWidth << " " << zWidth << endl
341 << x_large << " " << yWidth << " " << zWidth << endl
342 << -x_large << " " << yWidth << " " << zWidth << endl
343 << -x_small << " " << -yWidth << " " << zWidth;
344 } else {
345
346 // right-angled trapezoid
347 // _____________
348 // \ / ^
349 // \ / | y /z
350 // \ /
351 // \________/
352 // x
353
354 o << x_small << " " << -yWidth << " " << -zWidth << endl
355 << x_large << " " << yWidth << " " << -zWidth << endl
356 << -x_small << " " << yWidth << " " << -zWidth << endl
357 << -x_small << " " << -yWidth << " " << -zWidth << endl
358
359 << x_small << " " << -yWidth << " " << zWidth << endl
360 << x_large << " " << yWidth << " " << zWidth << endl
361 << -x_small << " " << yWidth << " " << zWidth << endl
362 << -x_small << " " << -yWidth << " " << zWidth;
363 }
364
365 fPoints = o.str();
366}
367
368//______________________________________________________________
369void Mpdshape::Fill_BOX(Double_t xWidth, Double_t yWidth, Double_t zWidth)
370{
371
372 // box
373 fPoints.clear();
374 std::ostringstream o;
375 o.setf(ios::showpoint);
376 o.setf(ios::fixed);
377 o.precision(6);
378
379 o << xWidth << " " << -yWidth << " " << -zWidth << endl
380 << xWidth << " " << yWidth << " " << -zWidth << endl
381 << -xWidth << " " << yWidth << " " << -zWidth << endl
382 << -xWidth << " " << -yWidth << " " << -zWidth << endl
383 << xWidth << " " << -yWidth << " " << zWidth << endl
384 << xWidth << " " << yWidth << " " << zWidth << endl
385 << -xWidth << " " << yWidth << " " << zWidth << endl
386 << -xWidth << " " << -yWidth << " " << zWidth;
387 fPoints = o.str();
388}
389
390//=============================================================
391//=============================================================
392//=============================================================
393
394TVector3 LineCrossesCircle(TVector3 CircleCenter, Double_t CircleRadius, TVector3 LineStart, TVector3 LineEnd)
395{
396
397 TVector3 LineVec = LineEnd - LineStart;
398 TVector3 VecToLine = LineStart - CircleCenter;
399 Double_t a, b, c;
400 Double_t sqrtterm, res1, res2, res;
401 a = LineVec.X() * LineVec.X() + LineVec.Y() * LineVec.Y();
402 b = 2 * (VecToLine.X() * LineVec.X() + VecToLine.Y() * LineVec.Y());
403 c = (VecToLine.X() * VecToLine.X() + VecToLine.Y() * VecToLine.Y()) - CircleRadius * CircleRadius;
404 sqrtterm = b * b - 4 * a * c;
405 if (sqrtterm < 0)
406 return LineStart;
407 sqrtterm = TMath::Sqrt(sqrtterm);
408 res1 = (-b - sqrtterm) / (2 * a);
409 res2 = (-b + sqrtterm) / (2 * a);
410 if (res1 >= 0 && res1 <= 1) {
411 res = res1;
412 } else {
413 res = res2;
414 }
415 TVector3 result(LineStart.X() + res * (LineEnd.X() - LineStart.X()),
416 LineStart.Y() + res * (LineEnd.Y() - LineStart.Y()), 0);
417 return result;
418}
419
420Double_t LineLength(Double_t alpha, TVector3 CircleCenter, Double_t CircleRadius, TVector3 LineStart)
421{
422
423 Double_t yend = CircleRadius * 1.1;
424 Double_t xend = yend * TMath::Tan(TMath::DegToRad() * alpha);
425 TVector3 LineEnd(xend, yend, 0);
426 TVector3 rend = LineCrossesCircle(CircleCenter, CircleRadius, LineStart, LineEnd);
427 if (rend != LineStart) {
428 TVector3 llen = rend - LineStart;
429 return llen.Mag();
430 }
431 return 0;
432}
433
434TVector3 StereoPosition(Double_t alpha, TVector3 CircleCenter, Double_t CircleRadius, TVector3 LineStart)
435{
436
437 Double_t yend = CircleRadius * 1.1;
438 Double_t xend = yend * TMath::Tan(TMath::DegToRad() * alpha);
439 TVector3 LineEnd(xend, yend, 0);
440 TVector3 rend = LineCrossesCircle(CircleCenter, CircleRadius, LineStart, LineEnd);
441 if (rend != LineStart) {
442 TVector3 res = rend + LineStart;
443 return res * 0.5;
444 }
445 return LineStart;
446}
447
448TVector3 StereoEnd(Double_t alpha, TVector3 CircleCenter, Double_t CircleRadius, TVector3 LineStart)
449{
450
451 Double_t yend = CircleRadius * 1.1;
452 Double_t xend = yend * TMath::Tan(TMath::DegToRad() * alpha);
453 TVector3 LineEnd(xend, yend, 0);
454 TVector3 rend = LineCrossesCircle(CircleCenter, CircleRadius, LineStart, LineEnd);
455 return rend;
456}
int i
Definition P4_F32vec4.h:22
int Int_t
double Double_t
#define gROOT
R__EXTERN TSystem * gSystem
void Fill_TRAP(Double_t x, Double_t X, Double_t yW, Double_t zW, Int_t ra=0)
void DumpToFile()
Mpdshape(ofstream *file, std::string volume_name, std::string mother_volume_name, std::string shape, std::string media)
void Fill_PGON(Double_t zmin, Double_t zmax, Double_t rmin, Double_t rmax, Double_t phi1, Int_t nEdges=12)
Int_t fSegment
void SetMedia(std::string media)
static std::string itoa(Double_t x)
void SetPositionRotation(std::string position, std::string rotation)
void SetFile(ofstream *file)
Int_t GetSegment() const
void SetRotation(Double_t p1, Double_t p2, Double_t p3, Double_t p4, Double_t p5, Double_t p6, Double_t p7, Double_t p8, Double_t p9)
void SetPosition(Double_t x, Double_t y, Double_t z, Int_t precision=6)
void SetPosition(std::string position)
FairGeoRotation * rot
void SetShape(std::string shape)
void SetVolumeName(std::string name)
std::string fShape
void Fill_BOX(Double_t xWidth, Double_t yWidth, Double_t zWidth)
void Fill_TUBE(Double_t length_z, Double_t r_max, Double_t r_min)
std::string fPoints
void SetPoints(std::string points)
std::string fPosition
std::string fVolumeName
std::string fRotation
Mpdshape(ofstream *file, std::string volume_name, std::string mother_volume_name, std::string shape, std::string media, std::string points, std::string position="0. 0. 0.", std::string rotation="1. 0. 0. 0. 1. 0. 0. 0. 1.", Int_t segment=0, Int_t mother_segment=0)
void SetMotherVolumeName(std::string name)
void SetSegment(Int_t segment)
Int_t fMotherSegment
void Clear()
void SetMotherSegment(Int_t segment)
void SetRotation(std::string rotation)
std::string GetVolumeName() const
static std::string itoa(Double_t x)
ofstream * fFile
void DumpWithIncrement()
void Fill_TUBS(Double_t zmin, Double_t zmax, Double_t rmin, Double_t rmax, Double_t dr_st, Double_t dr_end)
void SetRotation(Double_t z, Double_t y1, Double_t z1)
std::string fMotherVolumeName
void SetPosition(TVector3 vec)
std::string fMedia
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Double_t Y() const
Double_t X() const
Double_t z() const
Double_t x() const
Double_t Mag() const
Double_t y() const
TVector3 StereoPosition(Double_t alpha, TVector3 CircleCenter, Double_t CircleRadius, TVector3 LineStart)
Double_t LineLength(Double_t alpha, TVector3 CircleCenter, Double_t CircleRadius, TVector3 LineStart)
TVector3 LineCrossesCircle(TVector3 CircleCenter, Double_t CircleRadius, TVector3 LineStart, TVector3 LineEnd)
std::string itoa(Double_t x)
TVector3 StereoEnd(Double_t alpha, TVector3 CircleCenter, Double_t CircleRadius, TVector3 LineStart)
constexpr Double_t DegToRad()
Double_t Sqrt(Double_t x)
Double_t Tan(Double_t)
*brief create JSON pointer *sa reference_tokens end()