All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3Volume.cxx
Go to the documentation of this file.
1 /* *************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 
16 /*
17 $Log: G3Volume.cxx,v $
18 Revision 1.4 2005/07/21 17:50:46 brun
19 From Frederico
20 Use MakeCopy instead of Copy
21 
22 Revision 1.3 2004/01/28 08:17:52 brun
23 Reintroduce the Geant3 graphics classes (thanks Andreas Morsch)
24 
25 Revision 1.1.1.1 2002/07/24 15:56:26 rdm
26 initial import into CVS
27 
28 */
29 
30 //
31 // G3 Volume Class for the G3 GUI
32 // Author: Andreas Morsch
33 // andreas.morsch@cern.ch
34 //
35 
36 
37 
38 
40 #include <TArrayF.h>
41 #include "TMaterial.h"
42 #include "TShape.h"
43 #include "TTUBE.h"
44 #include "TBRIK.h"
45 #include "TTRD1.h"
46 #include "TTRD2.h"
47 #include "TTRAP.h"
48 #include "TTUBS.h"
49 #include "TCONE.h"
50 #include "TCONS.h"
51 #include "TSPHE.h"
52 #include "TPARA.h"
53 #include "TPGON.h"
54 #include "TPCON.h"
55 #include "TTUBS.h"
56 #include "TELTU.h"
57 #include "THYPE.h"
58 #include "TGTRA.h"
59 #include "TCTUB.h"
60 
62 
63  G3Volume::G3Volume(const char* name)
64  : TNamed(name, " ")
65 {
66 // Constructor
67 
68  fTheta = 30;
69  fPhi = 30;
70  fPsi = 0;
71  fU = 10;
72  fV = 10;
73  fUscale = 0.01;
74  fVscale = 0.01;
75  fHide=0;
76  fShadow=0;
77  fFill=1;
78  fSeen=1;
79  fClip=0;
80  fClipXmin=0.;
81  fClipXmax=2000.;
82  fClipYmin=0.;
83  fClipYmax=2000.;
84  fClipZmin=0.;
85  fClipZmax=2000.;
86  fNParam = 0;
87  fPosition.Set(3);
88  fCopies = new TList;
89  fNCopies = 0;
90  fPosp = kFALSE;
91  fAxis = -1;
92 }
93 
95  : TNamed(volume)
96 {
97 // Constructor
98 
99  fTheta = 30;
100  fPhi = 30;
101  fPsi = 0;
102  fU = 10;
103  fV = 10;
104  fUscale = 0.01;
105  fVscale = 0.01;
106  fHide=0;
107  fShadow=0;
108  fFill=1;
109  fSeen=1;
110  fClip=0;
111  fClipXmin=0.;
112  fClipXmax=2000.;
113  fClipYmin=0.;
114  fClipYmax=2000.;
115  fClipZmin=0.;
116  fClipZmax=2000.;
117  fAxis = -1;
118 //
119  fIdVolume = volume.GetIdVolume();
120  fIdCopy = volume.GetIdCopy();
121  fIdMedium = volume.Medium();
122  fIdMaterial = volume.Material();
123  fPosition = volume.Position(0);
124  fShape = volume.Shape();
125  fRotMatrix = volume.RotMatrix();
126  TArrayF par;
127  volume.Parameters(0, fParameters);
128  fNCopies = volume.NCopies();
129  fPosp = volume.Posp();
130 
131  fNParam = volume.NParam();
132  fCopies = volume.Copies();
133  fRotMatrix = volume.RotMatrix();
134  volume.Division(fNdiv, fAxis, fStartC, fStep);
135 
136 }
137 
138 
139 
140 
141 void G3Volume::Draw(Option_t *)
142 {
143 // Wraps the geant Gdraw
144  gMC->Gsatt(fName,"seen", fSeen);
145 
146  if (fHide) {
147  gMC->Gdopt("hide", "on");
148  } else {
149  gMC->Gdopt("hide", "off");
150  }
151 
152  if (fShadow) {
153  gMC->Gdopt("shad", "on");
154  gMC->Gsatt("*", "fill", fFill);
155  } else {
156  gMC->Gdopt("shad", "off");
157  }
158 
159  gMC->SetClipBox(".");
160  if (fClip) {
161  gMC->SetClipBox("*", fClipXmin, fClipXmax,
163  } else {
164  gMC->SetClipBox(".");
165  }
166 
167 
168  gMC->Gdraw(fName, fTheta, fPhi, fPsi, fU, fV, fUscale, fVscale);
169 }
170 
172 {
173 // Wraps the Geant DrawSpec
174  gMC->Gsatt(fName,"seen", fSeen);
175 
176  if (fHide) {
177  gMC->Gdopt("hide", "on");
178  } else {
179  gMC->Gdopt("hide", "off");
180  }
181 
182  if (fShadow) {
183  gMC->Gdopt("shad", "on");
184  gMC->Gsatt("*", "fill", fFill);
185  } else {
186  gMC->Gdopt("shad", "off");
187  }
188 
189  gMC->SetClipBox(".");
190  if (fClip) {
191  gMC->SetClipBox("*", fClipXmin, fClipXmax, fClipYmin, fClipYmax, fClipZmin, fClipZmax);
192  } else {
193  gMC->SetClipBox(".");
194  }
195 
196 
197  ((TGeant3*) gMC)->DrawOneSpec(fName);
198 }
199 
200 void G3Volume::SetParam(Int_t ip, Float_t param)
201 {
202 // Set drawing parameters
203  switch (ip) {
204  case kTheta:
205  fTheta=param;
206  break;
207  case kPhi:
208  fPhi=param;
209  break;
210  case kPsi:
211  fPsi=param;
212  break;
213  case kU:
214  fU=param;
215  break;
216  case kV:
217  fV=param;
218  break;
219  case kUscale:
220  fUscale=param;
221  break;
222  case kVscale:
223  fVscale=param;
224  break;
225  case kHide:
226  fHide=Int_t(param);
227  break;
228  case kShadow:
229  fShadow=Int_t(param);
230  break;
231  case kFill:
232  fFill=Int_t(param);
233  break;
234  case kSeen:
235  fSeen=Int_t(param);
236  break;
237  case kClip:
238  fClip=Int_t(param);
239  break;
240  case kClipXmin:
241  fClipXmin=param;
242  break;
243  case kClipXmax:
244  fClipXmax=param;
245  break;
246  case kClipYmin:
247  fClipYmin=param;
248  break;
249  case kClipYmax:
250  fClipYmax=param;
251  break;
252  case kClipZmin:
253  fClipZmin=param;
254  break;
255  case kClipZmax:
256  fClipZmax=param;
257  break;
258  }
259 }
260 
261 Float_t G3Volume::GetParam(Int_t ip)
262 {
263 // Get drawing parameters
264  switch (ip) {
265  case kTheta:
266  return fTheta;
267  case kPhi:
268  return fPhi;
269  case kPsi:
270  return fPsi;
271  case kU:
272  return fU;
273  case kV:
274  return fV;
275  case kUscale:
276  return fUscale;
277  case kVscale:
278  return fVscale;
279  case kHide:
280  return Float_t(fHide);
281  case kShadow:
282  return Float_t(fShadow);
283  case kFill:
284  return Float_t(fFill);
285  case kSeen:
286  return Float_t(fSeen);
287  case kClip:
288  return Float_t(fClip);
289  case kClipXmin:
290  return fClipXmin;
291  case kClipXmax:
292  return fClipXmax;
293  case kClipYmin:
294  return fClipYmin;
295  case kClipYmax:
296  return fClipYmax;
297  case kClipZmin:
298  return fClipZmin;
299  case kClipZmax:
300  return fClipZmax;
301  default:
302  return 0.;
303  }
304  return 0.;
305 }
306 
308 {
309  volume->SetIdMaterial(Material());
310  fCopies->Add(volume);
311  fNCopies++;
312 }
313 
315 {
316  return (G3Volume*) fCopies->At(i);
317 }
318 
319 
320 TArrayF G3Volume::Position(Int_t i) const
321 {
322 //
323 // Get position for volume copy i
324 //
325  if (i==0) {
326  return fPosition;
327  } else {
328  return ((G3Volume*) fCopies->At(i-1))->Position(0);
329  }
330 }
331 
332 void G3Volume::SetPosition(Float_t x, Float_t y, Float_t z)
333 {
334 //
335 // Set position
336 //
337  fPosition[0] = x;
338  fPosition[1] = y;
339  fPosition[2] = z;
340 }
341 
342 
343 void G3Volume::SetParameters(Int_t np, Float_t* param)
344 {
345 //
346 // Set parameters
347 //
348  fParameters.Set(np);
349  for (Int_t j=0; j<np; j++) fParameters[j]=param[j];
350  fNParam = np;
351 }
352 
353 
354 void G3Volume::Parameters(Int_t i, TArrayF& param) const
355 {
356 //
357 // Get parameters for volume copy i
358 //
359  TArrayF p;
360  if (i==0) {
361  p = fParameters;
362  } else {
363  ((G3Volume*) (fCopies->At(i-1)))->Parameters(0, p);
364  }
365  Int_t np = fNParam;
366  param.Set(np);
367  for (Int_t j=0; j<np; j++) {
368  param[j] = p.At(j);
369  }
370 }
371 
372 
373 void G3Volume::CreateTShape(char* nameV, TMaterial* mat)
374 {
375 //
376 // Create a root volume from G3 volume
377 //
378  Int_t ip;
379 
380  Float_t kRadDeg = 180./TMath::Pi();
381  Float_t theta, phi, alpha1, alpha2;
382  Float_t p1, p2;
383 
384  TShape* nShape=0;
385  const char* tmp = mat->GetName();
386  char nameM[21];
387  strncpy(nameM, tmp, 20);
388  nameM[20]='\0';
389  switch(fShape)
390  {
391  case 1:
392 // BOX
393  nShape = new TBRIK(nameV,"BRIK",nameM,fParameters[0], fParameters[1], fParameters[2]);
394  break;
395 
396  case 2:
397 // TRD1
398  nShape = new TTRD1(nameV, "TRD1", nameM, fParameters[0], fParameters[1], fParameters[2],
399  fParameters[3]);
400  break;
401 
402  case 3:
403 // TRD2
404  nShape = new TTRD2(nameV, "TRD2", nameM, fParameters[0], fParameters[1], fParameters[2],
405  fParameters[3], fParameters[4]);
406  break;
407 
408  case 4:
409 // TRAP
410  p1 = fParameters[1];
411  p2 = fParameters[2];
412 
413  theta = TMath::ATan(TMath::Sqrt(p1*p1+p2*p2))*kRadDeg;
414  phi = TMath::ATan2(p2,p1)*kRadDeg;
415  alpha1 = fParameters[6 ]*kRadDeg;
416  alpha2 = fParameters[10]*kRadDeg;
417 
418  if (theta < 0.) theta+=180.;
419 
420  nShape = new TTRAP(nameV, "TRAP", nameM, fParameters[0],
421  theta, phi,
422  fParameters[3], fParameters[4], fParameters[5],
423  alpha1,
424  fParameters[7], fParameters[8], fParameters[9],
425  alpha2);
426  break;
427 
428  case 5:
429 // TUBE
430  nShape = new TTUBE(nameV,"TUBE",nameM,fParameters[0], fParameters[1], fParameters[2]);
431  break;
432 
433  case 6:
434 // TUBS
435  nShape = new TTUBS(nameV,"TUBS",nameM,fParameters[0], fParameters[1], fParameters[2],
436  fParameters[3], fParameters[4]);
437  break;
438 
439  case 7:
440 // CONE
441  nShape = new TCONE(nameV, "CONE", nameM, fParameters[0], fParameters[1], fParameters[2],
442  fParameters[3], fParameters[4]);
443  break;
444 
445  case 8:
446 
447 // CONS
448  nShape = new TCONS(nameV, "CONS", nameM, fParameters[0], fParameters[1], fParameters[2],
450  break;
451 
452  case 9:
453 // SPHE
454 
455  nShape = new TSPHE(nameV, "SPHE", nameM, fParameters[0], fParameters[1], fParameters[2],
456  fParameters[3], fParameters[4], fParameters[5]);
457  break;
458 
459  case 10:
460 // PARA
461  alpha1 = fParameters[3]*kRadDeg;
462  p1 = fParameters[4];
463  p2 = fParameters[5];
464  theta = TMath::ATan(TMath::Sqrt(p1*p1+p2*p2))*kRadDeg;
465  phi = TMath::ATan2(p2,p1)*kRadDeg;
466 
467  nShape = new TPARA(nameV, "PARA", nameM, fParameters[0], fParameters[1], fParameters[2],
468  alpha1, theta, phi);
469  break;
470 
471  case 11:
472 // PGON
473  nShape = new TPGON(nameV, "PGON", nameM, fParameters[0], fParameters[1], Int_t(fParameters[2]),
474  Int_t(fParameters[3]));
475  for (ip=0; ip<Int_t(fParameters[3]); ip++) {
476  ((TPGON*) nShape)->DefineSection(ip, fParameters[4+3*ip], fParameters[4+3*ip+1],
477  fParameters[4+3*ip+2]);
478  }
479  break;
480 
481  case 12:
482 // PCON
483  nShape = new TPCON(nameV, "PCON", nameM, fParameters[0], fParameters[1], Int_t(fParameters[2]));
484  for (ip=0; ip<Int_t(fParameters[2]); ip++) {
485  ((TPCON*) nShape)->DefineSection(ip, fParameters[3+3*ip], fParameters[3+3*ip+1],
486  fParameters[3+3*ip+2]);
487  }
488  break;
489 
490  case 13:
491 // ELTU
492  nShape = new TELTU(nameV,"ELTU",nameM,fParameters[0], fParameters[1], fParameters[2]);
493  break;
494 
495  case 14:
496 // HYPE
497  nShape = new THYPE(nameV,"HYPE",nameM,fParameters[0], fParameters[1], fParameters[2],
498  fParameters[3]);
499  break;
500 
501  case 15:
502 // GTRA
503  nShape = new TGTRA(nameV, "GTRA", nameM, fParameters[0], fParameters[1], fParameters[2],
506  fParameters[11]);
507  break;
508 
509  case 16:
510 // CTUB
511  nShape = new TCTUB(nameV, "CTUB", nameM, fParameters[0], fParameters[1], fParameters[2],
514  break;
515  default:
516  break;
517  }
518  if (nShape) {
519  Float_t density = mat->GetDensity();
520  if (density < 0.01) {
521  nShape->SetVisibility(0);
522  } else {
523  nShape->SetVisibility(1);
524  }
525 
526  Int_t color = Int_t(density/20.*100.);
527  nShape->SetLineColor(color);
528  }
529 }
530 
531 void G3Volume::SetDivision(Int_t ndiv, Int_t axis, Float_t start, Float_t step)
532 {
533  fNdiv = ndiv;
534  fAxis = axis;
535  fStartC = start;
536  fStep = step;
537 }
538 
539 void G3Volume::Division(Int_t& ndiv, Int_t& axis, Float_t& start, Float_t& step) const
540 {
541  ndiv = fNdiv;
542  axis = fAxis;
543  start = fStartC;
544  step = fStep;
545 }
virtual void SetIdMaterial(Int_t id)
Definition: G3Volume.h:39
virtual Int_t Shape() const
Definition: G3Volume.h:59
virtual Int_t NParam() const
Definition: G3Volume.h:61
Int_t fSeen
Definition: G3Volume.h:109
virtual void SetParam(Int_t i, Float_t param)
Definition: G3Volume.cxx:200
Float_t fClipXmin
Definition: G3Volume.h:111
virtual void CreateTShape(char *nameV, TMaterial *mat)
Definition: G3Volume.cxx:373
Int_t fRotMatrix
Definition: G3Volume.h:92
Bool_t fPosp
Definition: G3Volume.h:90
Int_t fShape
Definition: G3Volume.h:98
virtual Bool_t Posp() const
Definition: G3Volume.h:68
Definition: G3Volume.h:131
Int_t fIdCopy
Definition: G3Volume.h:120
virtual G3Volume * MakeCopy(Int_t i)
Definition: G3Volume.cxx:314
virtual Int_t Medium() const
Definition: G3Volume.h:45
Float_t fClipXmax
Definition: G3Volume.h:112
G3Volume()
Definition: G3Volume.h:21
virtual void Draw(Option_t *option=0)
Definition: G3Volume.cxx:141
static const std::string volume[nvol]
Int_t fIdMaterial
Definition: G3Volume.h:119
Float_t fClipYmax
Definition: G3Volume.h:114
Float_t fStep
Definition: G3Volume.h:96
ClassImp(G3Volume) G3Volume
Definition: G3Volume.cxx:61
Int_t fIdMedium
Definition: G3Volume.h:118
virtual Int_t GetIdVolume() const
Definition: G3Volume.h:41
virtual void Parameters(Int_t i, TArrayF &param) const
Definition: G3Volume.cxx:354
virtual TArrayF Position(Int_t i) const
Definition: G3Volume.cxx:320
double y
virtual void SetParameters(Int_t np, Float_t *param)
Definition: G3Volume.cxx:343
Int_t fIdVolume
Definition: G3Volume.h:117
Int_t fNdiv
Definition: G3Volume.h:95
Float_t fUscale
Definition: G3Volume.h:104
virtual void SetPosition(Float_t x, Float_t y, Float_t z)
Definition: G3Volume.cxx:332
Float_t fStartC
Definition: G3Volume.h:97
double z
Definition: G3Volume.h:134
virtual Int_t NCopies() const
Definition: G3Volume.h:67
Bool_t fShadow
Definition: G3Volume.h:107
virtual void AddCopy()
Definition: G3Volume.h:49
Bool_t fHide
Definition: G3Volume.h:106
Int_t fNCopies
Definition: G3Volume.h:91
virtual Float_t GetParam(Int_t i)
Definition: G3Volume.cxx:261
Float_t fClipZmin
Definition: G3Volume.h:115
virtual void Division(Int_t &ndiv, Int_t &axis, Float_t &start, Float_t &step) const
Definition: G3Volume.cxx:539
p
Definition: test.py:223
std::size_t color(std::string const &procname)
Float_t fVscale
Definition: G3Volume.h:105
Int_t fNParam
Definition: G3Volume.h:93
Definition: G3Volume.h:133
virtual Int_t GetIdCopy() const
Definition: G3Volume.h:43
TList * fCopies
Definition: G3Volume.h:89
Int_t fAxis
Definition: G3Volume.h:94
Float_t fPhi
Definition: G3Volume.h:100
Float_t fClipZmax
Definition: G3Volume.h:116
virtual void SetDivision(Int_t ndiv, Int_t axis, Float_t start, Float_t step)
Definition: G3Volume.cxx:531
start
Definition: test.py:4
Float_t fV
Definition: G3Volume.h:103
list x
Definition: train.py:276
Int_t fFill
Definition: G3Volume.h:108
Float_t fPsi
Definition: G3Volume.h:101
virtual Int_t Material() const
Definition: G3Volume.h:47
virtual TList * Copies() const
Definition: G3Volume.h:63
Float_t fU
Definition: G3Volume.h:102
virtual Int_t RotMatrix() const
Definition: G3Volume.h:57
TArrayF fPosition
Definition: G3Volume.h:87
Float_t fTheta
Definition: G3Volume.h:99
TArrayF fParameters
Definition: G3Volume.h:88
virtual void DrawSpec()
Definition: G3Volume.cxx:171
Bool_t fClip
Definition: G3Volume.h:110
Float_t fClipYmin
Definition: G3Volume.h:113
Definition: G3Volume.h:132