]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant3/AliG3Volume.cxx
Mostly minor style modifications to be ready for cloning with EMCAL
[u/mrichter/AliRoot.git] / AliGeant3 / AliG3Volume.cxx
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$
18 Revision 1.1  2001/07/09 11:41:46  morsch
19 AliGUIMedium, AliGUIMaterial and AliDrawVolume obselete. Development continues
20 on AliG3Material, AliG3Medium and AliG3Volume.
21
22 */
23
24 /*
25 Old Logs: AliDrawVolume.cxx,v $
26 Revision 1.1  2000/07/13 16:19:10  fca
27 Mainly coding conventions + some small bug fixes
28
29 Revision 1.8  2000/07/12 08:56:32  fca
30 Coding convention correction and warning removal
31
32 Revision 1.7  2000/06/28 21:27:45  morsch
33 Most coding rule violations corrected.
34 Still to do: Split the file (on file per class) ? Avoid the global variables.
35 Copy constructors and assignment operators (dummy ?)
36
37 Revision 1.6  2000/04/14 11:07:46  morsch
38 Correct volume to medium assignment in case several media are asigned to the
39 same material.
40
41 Revision 1.5  2000/03/20 15:11:03  fca
42 Mods to make the code compile on HP
43
44 Revision 1.4  2000/01/18 16:12:08  morsch
45 Bug in calculation of number of volume divisions and number of positionings corrected
46 Browser for Material and Media properties added
47
48 Revision 1.3  1999/11/14 14:31:14  fca
49 Correct small error and remove compilation warnings on HP
50
51 Revision 1.2  1999/11/10 16:53:35  fca
52 The new geometry viewer from A.Morsch
53
54 */
55
56 /* 
57  *  Version: 0
58  *  Written by Andreas Morsch
59  *  
60  * 
61  *
62  * For questions critics and suggestions to this part of the code
63  * contact andreas.morsch@cern.ch
64  * 
65  **************************************************************************/
66
67 #include "AliG3Volume.h"
68 #include <TArrayF.h>
69 #include "TMaterial.h"
70 #include "TShape.h"
71 #include "TTUBE.h"
72 #include "TBRIK.h"
73 #include "TTRD1.h"
74 #include "TTRD2.h"
75 #include "TTRAP.h"
76 #include "TTUBS.h"
77 #include "TCONE.h"
78 #include "TCONS.h"
79 #include "TSPHE.h"
80 #include "TPARA.h"
81 #include "TPGON.h"
82 #include "TPCON.h"
83 #include "TTUBS.h"
84 #include "TELTU.h"
85 #include "THYPE.h"
86 #include "TGTRA.h"
87 #include "TCTUB.h"
88
89 ClassImp(AliG3Volume)
90
91     AliG3Volume::AliG3Volume(const char* name) 
92         : TNamed(name, " ")
93 {
94 // Constructor
95
96     fTheta  = 30;
97     fPhi    = 30;
98     fPsi    = 0;
99     fU      = 10;
100     fV      = 10;
101     fUscale = 0.01;
102     fVscale = 0.01;
103     fHide=0;
104     fShadow=0;
105     fFill=1;
106     fSeen=1;
107     fClip=0;
108     fClipXmin=0.;
109     fClipXmax=2000.;
110     fClipYmin=0.;
111     fClipYmax=2000.;
112     fClipZmin=0.;
113     fClipZmax=2000.;
114     fNParam = 0;
115     fPosition.Set(3);
116     fCopies = new TList;
117     fNCopies = 0;
118     fPosp = kFALSE;
119     fAxis = -1;
120 }
121
122 AliG3Volume::AliG3Volume(const AliG3Volume& volume)
123     : TNamed(volume)
124 {
125 // Constructor
126
127     fTheta  = 30;
128     fPhi    = 30;
129     fPsi    = 0;
130     fU      = 10;
131     fV      = 10;
132     fUscale = 0.01;
133     fVscale = 0.01;
134     fHide=0;
135     fShadow=0;
136     fFill=1;
137     fSeen=1;
138     fClip=0;
139     fClipXmin=0.;
140     fClipXmax=2000.;
141     fClipYmin=0.;
142     fClipYmax=2000.;
143     fClipZmin=0.;
144     fClipZmax=2000.;
145     fAxis = -1;
146 //
147     fIdVolume   = volume.GetIdVolume();
148     fIdCopy     = volume.GetIdCopy();
149     fIdMedium   = volume.Medium();
150     fIdMaterial = volume.Material();
151     fPosition   = volume.Position(0);
152     fShape      = volume.Shape();
153     fRotMatrix  = volume.RotMatrix();
154     TArrayF par;
155     volume.Parameters(0, fParameters);
156     fNCopies    = volume.NCopies();
157     fPosp       = volume.Posp();
158     
159     fNParam     = volume.NParam();
160     fCopies     = volume.Copies();
161     fRotMatrix  = volume.RotMatrix();
162     volume.Division(fNdiv, fAxis, fStartC, fStep);
163     
164 }
165
166
167
168
169 void AliG3Volume::Draw(Option_t *)
170 {
171 // Wraps the geant Gdraw
172     gMC->Gsatt(fName,"seen", fSeen);
173     
174     if (fHide) {
175         gMC->Gdopt("hide", "on");
176     } else {
177         gMC->Gdopt("hide", "off");
178     }
179
180     if (fShadow) {
181         gMC->Gdopt("shad", "on");
182         gMC->Gsatt("*", "fill", fFill);
183     } else {
184         gMC->Gdopt("shad", "off");
185     }
186
187         gMC->SetClipBox(".");
188     if (fClip) {
189         gMC->SetClipBox("*", fClipXmin, fClipXmax, 
190                         fClipYmin, fClipYmax, fClipZmin, fClipZmax);
191     } else {
192         gMC->SetClipBox(".");
193     }
194     
195
196     gMC->Gdraw(fName, fTheta, fPhi, fPsi, fU, fV, fUscale, fVscale);
197     THIGZ *higz = (THIGZ*)gROOT->GetListOfCanvases()->FindObject("higz");
198     if (higz) higz->Update();
199 }
200
201 void AliG3Volume::DrawSpec()
202 {
203 // Wraps the Geant DrawSpec
204     gMC->Gsatt(fName,"seen", fSeen);
205     
206     if (fHide) {
207         gMC->Gdopt("hide", "on");
208     } else {
209         gMC->Gdopt("hide", "off");
210     }
211
212     if (fShadow) {
213         gMC->Gdopt("shad", "on");
214         gMC->Gsatt("*", "fill", fFill);
215     } else {
216         gMC->Gdopt("shad", "off");
217     }
218
219     gMC->SetClipBox(".");
220     if (fClip) {
221         gMC->SetClipBox("*", fClipXmin, fClipXmax, fClipYmin, fClipYmax, fClipZmin, fClipZmax);
222     } else {
223         gMC->SetClipBox(".");
224     }
225     
226
227     ((TGeant3*) gMC)->DrawOneSpec(fName);
228     THIGZ *higz = (THIGZ*)gROOT->GetListOfCanvases()->FindObject("higz");
229     if (higz) higz->Update();
230 }
231
232 void AliG3Volume::SetParam(Int_t ip, Float_t param)
233 {
234 // Set drawing parameters
235     switch (ip) {
236     case kTheta:
237         fTheta=param;
238         break;
239     case kPhi:
240         fPhi=param;
241         break;
242     case kPsi:
243         fPsi=param;
244         break;
245     case kU:
246         fU=param;
247         break;
248     case kV:
249         fV=param;
250         break;
251     case kUscale:
252         fUscale=param;
253         break;
254     case kVscale:
255         fVscale=param;
256         break;
257     case kHide:
258         fHide=Int_t(param);
259         break;
260     case kShadow:
261         fShadow=Int_t(param);
262         break;
263     case kFill:
264         fFill=Int_t(param);
265         break;
266     case kSeen:
267         fSeen=Int_t(param);
268         break;
269     case kClip:
270         fClip=Int_t(param);
271         break;
272     case kClipXmin:
273         fClipXmin=param;
274         break;
275     case kClipXmax:
276         fClipXmax=param;
277         break;
278     case kClipYmin:
279         fClipYmin=param;
280         break;
281     case kClipYmax:
282         fClipYmax=param;
283         break;
284     case kClipZmin:
285         fClipZmin=param;
286         break;
287     case kClipZmax:
288         fClipZmax=param;
289         break;
290     }
291 }
292
293 Float_t  AliG3Volume::GetParam(Int_t ip)
294 {
295 // Get drawing parameters
296     switch (ip) {
297     case kTheta:
298         return fTheta;
299     case kPhi:
300         return fPhi;
301     case kPsi:
302         return fPsi;
303     case kU:
304         return fU;
305     case kV:
306         return fV;
307     case kUscale:
308         return fUscale;
309     case kVscale:
310         return fVscale;
311     case kHide:
312         return Float_t(fHide);
313     case kShadow:
314         return Float_t(fShadow);
315     case kFill:
316         return Float_t(fFill);
317     case kSeen:
318         return Float_t(fSeen);
319     case kClip:
320         return Float_t(fClip);
321     case kClipXmin:
322         return fClipXmin;
323     case kClipXmax:
324         return fClipXmax;
325     case kClipYmin:
326         return fClipYmin;
327     case kClipYmax:
328         return fClipYmax;
329     case kClipZmin:
330         return fClipZmin;
331     case kClipZmax:
332         return fClipZmax;
333     default:
334         return 0.;
335     }
336     return 0.;
337 }
338
339 void  AliG3Volume::AddCopy(AliG3Volume* volume)
340 {
341     volume->SetIdMaterial(Material());
342     fCopies->Add(volume);
343     fNCopies++;
344 }
345
346 AliG3Volume* AliG3Volume::Copy(Int_t i)
347 {
348     return (AliG3Volume*) fCopies->At(i);
349 }
350
351
352 TArrayF AliG3Volume::Position(Int_t i) const
353 {
354 //
355 // Get position for volume copy i 
356 //
357     if (i==0) {
358         return fPosition;
359     } else {
360         return ((AliG3Volume*) fCopies->At(i-1))->Position(0);
361     }
362 }
363
364 void AliG3Volume::SetPosition(Float_t x, Float_t y, Float_t z)
365 {
366 //
367 // Set position
368 //
369   fPosition[0] = x;
370   fPosition[1] = y;
371   fPosition[2] = z;
372 }
373
374
375 void  AliG3Volume::SetParameters(Int_t np, Float_t* param) 
376 {
377 //
378 // Set parameters 
379 //
380     fParameters.Set(np);
381     for (Int_t j=0; j<np; j++) fParameters[j]=param[j];
382     fNParam = np;
383 }
384     
385
386 void  AliG3Volume::Parameters(Int_t i, TArrayF& param) const
387 {
388 //
389 // Get parameters for volume copy i 
390 //
391     TArrayF p;
392     if (i==0) {
393         p = fParameters;
394     } else {
395         ((AliG3Volume*) (fCopies->At(i-1)))->Parameters(0, p);
396     }
397     Int_t np = fNParam;
398     param.Set(np);
399     for (Int_t j=0; j<np; j++) {
400         param[j] = p.At(j);
401     }
402 }
403     
404
405 void AliG3Volume::CreateTShape(char* nameV, TMaterial* mat)
406 {
407 //
408 // Create a root volume from G3 volume
409 //
410     Int_t   ip;
411     
412     Float_t kRadDeg = 180./TMath::Pi();
413     Float_t theta, phi, alpha1, alpha2;
414     Float_t p1, p2;
415     
416     TShape* nShape=0;
417     const char* tmp = mat->GetName();
418     char nameM[21];
419     strncpy(nameM, tmp, 20);
420     nameM[20]='\0';
421     switch(fShape)
422     {
423     case 1:
424 // BOX
425         nShape = new TBRIK(nameV,"BRIK",nameM,fParameters[0], fParameters[1], fParameters[2]);
426         break;
427         
428     case 2:
429 // TRD1   
430         nShape = new TTRD1(nameV, "TRD1", nameM, fParameters[0], fParameters[1], fParameters[2],
431                            fParameters[3]);
432         break;
433         
434     case 3:
435 // TRD2
436         nShape = new TTRD2(nameV, "TRD2", nameM, fParameters[0], fParameters[1], fParameters[2], 
437                            fParameters[3], fParameters[4]);
438         break;
439         
440     case 4:
441 // TRAP
442         p1     = fParameters[1];
443         p2     = fParameters[2];
444         
445         theta  = TMath::ATan(TMath::Sqrt(p1*p1+p2*p2))*kRadDeg;
446         phi    = TMath::ATan2(p2,p1)*kRadDeg;
447         alpha1 = fParameters[6 ]*kRadDeg;
448         alpha2 = fParameters[10]*kRadDeg;
449
450         if (theta < 0.) theta+=180.;
451         
452         nShape =  new TTRAP(nameV, "TRAP", nameM, fParameters[0], 
453                             theta, phi,
454                             fParameters[3], fParameters[4], fParameters[5], 
455                             alpha1, 
456                             fParameters[7], fParameters[8], fParameters[9], 
457                             alpha2);
458         break;
459         
460     case 5:
461 // TUBE
462         nShape =  new TTUBE(nameV,"TUBE",nameM,fParameters[0], fParameters[1], fParameters[2]);
463         break;
464         
465     case 6:
466 // TUBS
467         nShape =  new TTUBS(nameV,"TUBS",nameM,fParameters[0], fParameters[1], fParameters[2], 
468                             fParameters[3], fParameters[4]);
469         break;
470         
471     case 7:
472 // CONE
473         nShape =  new TCONE(nameV, "CONE", nameM, fParameters[0], fParameters[1], fParameters[2], 
474                             fParameters[3], fParameters[4]);
475         break;
476         
477     case 8:
478         
479 // CONS
480         nShape =  new TCONS(nameV, "CONS", nameM, fParameters[0], fParameters[1], fParameters[2], 
481                             fParameters[3], fParameters[4], fParameters[5], fParameters[6]);
482         break;
483         
484     case 9:
485 // SPHE
486         
487         nShape =  new TSPHE(nameV, "SPHE", nameM, fParameters[0], fParameters[1], fParameters[2], 
488                             fParameters[3], fParameters[4], fParameters[5]);
489         break;
490         
491     case 10:
492 // PARA
493         alpha1 = fParameters[3]*kRadDeg;
494         p1     = fParameters[4];
495         p2     = fParameters[5];
496         theta  = TMath::ATan(TMath::Sqrt(p1*p1+p2*p2))*kRadDeg;
497         phi    = TMath::ATan2(p2,p1)*kRadDeg;
498
499         nShape =  new TPARA(nameV, "PARA", nameM, fParameters[0], fParameters[1], fParameters[2], 
500                                     alpha1, theta, phi);
501         break;
502         
503     case 11:
504 // PGON
505         nShape =  new TPGON(nameV, "PGON", nameM, fParameters[0], fParameters[1], Int_t(fParameters[2]), 
506                             Int_t(fParameters[3]));
507         for (ip=0; ip<Int_t(fParameters[3]); ip++) {
508             ((TPGON*) nShape)->DefineSection(ip, fParameters[4+3*ip], fParameters[4+3*ip+1], 
509                                              fParameters[4+3*ip+2]);
510         }
511         break;
512         
513     case 12:
514 // PCON
515         nShape = new TPCON(nameV, "PCON", nameM, fParameters[0], fParameters[1], Int_t(fParameters[2]));
516         for (ip=0; ip<Int_t(fParameters[2]); ip++) {
517             ((TPCON*) nShape)->DefineSection(ip, fParameters[3+3*ip], fParameters[3+3*ip+1], 
518                                              fParameters[3+3*ip+2]);
519         }
520         break;
521         
522     case 13:
523 // ELTU  
524         nShape = new TELTU(nameV,"ELTU",nameM,fParameters[0], fParameters[1], fParameters[2]);
525         break;
526         
527     case 14:
528 // HYPE
529         nShape = new THYPE(nameV,"HYPE",nameM,fParameters[0], fParameters[1], fParameters[2], 
530                            fParameters[3]);
531         break;
532         
533     case 15:
534 // GTRA
535         nShape = new TGTRA(nameV, "GTRA", nameM, fParameters[0], fParameters[1], fParameters[2], 
536                            fParameters[3], fParameters[4], fParameters[5], fParameters[6], 
537                            fParameters[7], fParameters[8], fParameters[9], fParameters[10], 
538                            fParameters[11]);
539         break;
540         
541     case 16:
542 // CTUB
543         nShape = new TCTUB(nameV, "CTUB", nameM, fParameters[0], fParameters[1], fParameters[2], 
544                            fParameters[3], fParameters[4], fParameters[5], fParameters[6], 
545                            fParameters[7], fParameters[8], fParameters[9], fParameters[10]);
546         break;
547     default:
548         break;
549     }
550     if (nShape) {
551         Float_t density = mat->GetDensity();
552         if (density < 0.01) {
553             nShape->SetVisibility(0);
554         } else {
555             nShape->SetVisibility(1);
556         }
557         
558         Int_t color = Int_t(density/20.*100.);
559         nShape->SetLineColor(color);
560     }
561 }
562
563 void   AliG3Volume::SetDivision(Int_t ndiv, Int_t axis, Float_t start, Float_t step)
564 {
565     fNdiv   = ndiv;
566     fAxis   = axis;
567     fStartC = start;
568     fStep   = step;
569 }
570
571 void   AliG3Volume::Division(Int_t& ndiv, Int_t& axis, Float_t& start, Float_t& step) const
572 {
573     ndiv  = fNdiv;
574     axis  = fAxis;
575     start = fStartC;
576     step  = fStep;
577 }