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