source: trunk/source/geometry/divisions/src/G4ParameterisationBox.cc

Last change on this file was 1347, checked in by garnier, 14 years ago

geant4 tag 9.4

File size: 11.3 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26//
27// $Id: G4ParameterisationBox.cc,v 1.12 2010/11/10 09:15:56 gcosmo Exp $
28// GEANT4 tag $Name: geant4-09-04-ref-00 $
29//
30// class G4ParameterisationBox Implementation file
31//
32// 26.05.03 - P.Arce, Initial version
33// 08.04.04 - I.Hrivnacova, Implemented reflection
34// 21.04.10 - M.Asai, Added gaps
35// --------------------------------------------------------------------
36
37#include "G4ParameterisationBox.hh"
38
39#include <iomanip>
40#include "G4ThreeVector.hh"
41#include "G4Transform3D.hh"
42#include "G4RotationMatrix.hh"
43#include "G4VPhysicalVolume.hh"
44#include "G4ReflectedSolid.hh"
45#include "G4Box.hh"
46
47//--------------------------------------------------------------------------
48G4VParameterisationBox::
49G4VParameterisationBox( EAxis axis, G4int nDiv, G4double width,
50                        G4double offset, G4VSolid* msolid,
51                        DivisionType divType )
52  :  G4VDivisionParameterisation( axis, nDiv, width, offset, divType, msolid )
53{
54  G4Box* msol = (G4Box*)(msolid);
55  if (msolid->GetEntityType() == "G4ReflectedSolid")
56  {
57    // Get constituent solid 
58    G4VSolid* mConstituentSolid
59       = ((G4ReflectedSolid*)msolid)->GetConstituentMovedSolid();
60    msol = (G4Box*)(mConstituentSolid);
61    fmotherSolid = msol;
62    fReflectedSolid = true;
63  }   
64}
65
66//--------------------------------------------------------------------------
67G4VParameterisationBox::~G4VParameterisationBox()
68{
69}
70
71//--------------------------------------------------------------------------
72G4ParameterisationBoxX::
73G4ParameterisationBoxX( EAxis axis, G4int nDiv, G4double width,
74                        G4double offset, G4VSolid* msolid,
75                        DivisionType divType )
76  :  G4VParameterisationBox( axis, nDiv, width, offset, msolid, divType )
77{
78  CheckParametersValidity();
79  SetType( "DivisionBoxX" );
80
81  G4Box* mbox = (G4Box*)(fmotherSolid);
82  if( divType == DivWIDTH )
83  {
84    fnDiv = CalculateNDiv( 2*mbox->GetXHalfLength(), width, offset );
85  }
86  else if( divType == DivNDIV )
87  {
88    fwidth = CalculateWidth( 2*mbox->GetXHalfLength(), nDiv, offset );
89  }
90#ifdef G4DIVDEBUG
91  if( verbose >= 1 )
92  {
93    G4cout << " G4ParameterisationBoxX - no divisions "
94           << fnDiv << " = " << nDiv << G4endl
95           << " Offset " << foffset << " = " << offset << G4endl
96           << " Width " << fwidth << " = " << width << G4endl;
97  }
98#endif
99}
100
101//------------------------------------------------------------------------
102G4ParameterisationBoxX::~G4ParameterisationBoxX()
103{
104}
105
106//------------------------------------------------------------------------
107G4double G4ParameterisationBoxX::GetMaxParameter() const
108{
109  G4Box* msol = (G4Box*)(fmotherSolid);
110  return 2*msol->GetXHalfLength();
111}
112
113//------------------------------------------------------------------------
114void
115G4ParameterisationBoxX::
116ComputeTransformation( const G4int copyNo, G4VPhysicalVolume* physVol ) const
117{
118  G4Box* msol = (G4Box*)(fmotherSolid );
119  G4double mdx = msol->GetXHalfLength( );
120
121  //----- translation
122  G4ThreeVector origin(0.,0.,0.); 
123  G4double posi = -mdx + foffset+(copyNo+0.5)*fwidth;
124
125  if( faxis == kXAxis )
126  {
127    origin.setX( posi ); 
128  }
129  else
130  { 
131    G4Exception("G4ParameterisationBoxX::ComputeTransformation()",
132                "IllegalConstruct", FatalException,
133                "Only axes along X are allowed !  Axis: "+faxis);
134  }
135#ifdef G4DIVDEBUG
136  if( verbose >= 2 )
137  {
138    G4cout << std::setprecision(8) << " G4ParameterisationBoxX: "
139           << copyNo << G4endl
140           << " Position " << origin << " Axis " << faxis << G4endl;
141  }
142#endif
143  //----- set translation
144  physVol->SetTranslation( origin );
145}
146
147//------------------------------------------------------------------------
148void
149G4ParameterisationBoxX::
150ComputeDimensions( G4Box& box, const G4int,
151                   const G4VPhysicalVolume* ) const
152{
153  G4Box* msol = (G4Box*)(fmotherSolid);
154
155  G4double pDx = fwidth/2. - fhgap;
156  G4double pDy = msol->GetYHalfLength();
157  G4double pDz = msol->GetZHalfLength();
158
159  box.SetXHalfLength( pDx );
160  box.SetYHalfLength( pDy );
161  box.SetZHalfLength( pDz );
162
163#ifdef G4DIVDEBUG
164  if( verbose >= 2 )
165  {
166    G4cout << " G4ParameterisationBoxX::ComputeDimensions()" << G4endl
167           << " pDx: " << pDz << G4endl;
168    box.DumpInfo();
169  }
170#endif
171}
172
173//------------------------------------------------------------------------
174G4ParameterisationBoxY::
175G4ParameterisationBoxY( EAxis axis, G4int nDiv, G4double width,
176                        G4double offset, G4VSolid* msolid,
177                        DivisionType divType)
178  :  G4VParameterisationBox( axis, nDiv, width, offset, msolid, divType )
179{
180  CheckParametersValidity();
181  SetType( "DivisionBoxY" );
182
183  G4Box* mbox = (G4Box*)(fmotherSolid);
184  if( divType == DivWIDTH )
185  {
186    fnDiv = CalculateNDiv( 2*mbox->GetYHalfLength(), width, offset );
187  }
188  else if( divType == DivNDIV )
189  {
190    fwidth = CalculateWidth( 2*mbox->GetYHalfLength(), nDiv, offset );
191  }
192
193#ifdef G4DIVDEBUG
194  if( verbose >= 1 )
195  {
196    G4cout << " G4ParameterisationBoxY - no divisions " << fnDiv << " = "
197           << nDiv << ". Offset " << foffset << " = " << offset
198           << ". Width " << fwidth << " = " << width << G4endl;
199  }
200#endif
201}
202
203//------------------------------------------------------------------------
204G4ParameterisationBoxY::~G4ParameterisationBoxY()
205{
206}
207
208//------------------------------------------------------------------------
209G4double G4ParameterisationBoxY::GetMaxParameter() const
210{
211  G4Box* msol = (G4Box*)(fmotherSolid);
212  return 2*msol->GetYHalfLength();
213}
214
215//------------------------------------------------------------------------
216void
217G4ParameterisationBoxY::
218ComputeTransformation( const G4int copyNo, G4VPhysicalVolume* physVol ) const
219{
220  G4Box* msol = (G4Box*)(fmotherSolid);
221  G4double mdy = msol->GetYHalfLength();
222
223  //----- translation
224  G4ThreeVector origin(0.,0.,0.); 
225  G4double posi = -mdy + foffset + (copyNo+0.5)*fwidth;
226  if( faxis == kYAxis )
227  {
228    origin.setY( posi ); 
229  }
230  else
231  {
232    G4Exception("G4ParameterisationBoxY::ComputeTransformation()",
233                "IllegalConstruct", FatalException,
234                "Only axes along Y are allowed !  Axis: "+faxis);
235  }
236#ifdef G4DIVDEBUG
237  if( verbose >= 2 )
238  {
239    G4cout << std::setprecision(8) << " G4ParameterisationBoxY: "
240           << copyNo << G4endl
241           << " Position " << origin << " Axis " << faxis << G4endl;
242  }
243#endif
244   //----- set translation
245  physVol->SetTranslation( origin );
246}
247
248//------------------------------------------------------------------------
249void
250G4ParameterisationBoxY::
251ComputeDimensions( G4Box& box, const G4int,
252                   const G4VPhysicalVolume* ) const
253{
254  G4Box* msol = (G4Box*)(fmotherSolid);
255
256  G4double pDx = msol->GetXHalfLength();
257  G4double pDy = fwidth/2. - fhgap;
258  G4double pDz = msol->GetZHalfLength();
259
260  box.SetXHalfLength( pDx );
261  box.SetYHalfLength( pDy );
262  box.SetZHalfLength( pDz );
263
264#ifdef G4DIVDEBUG
265  if( verbose >= 2 )
266  {
267    G4cout << " G4ParameterisationBoxY::ComputeDimensions()" << G4endl
268           << " pDx: " << pDz << G4endl;
269    box.DumpInfo();
270  }
271#endif
272}
273
274//------------------------------------------------------------------------
275G4ParameterisationBoxZ::
276G4ParameterisationBoxZ( EAxis axis, G4int nDiv, G4double width,
277                        G4double offset, G4VSolid* msolid,
278                        DivisionType divType )
279  :  G4VParameterisationBox( axis, nDiv, width, offset, msolid, divType )
280{
281  CheckParametersValidity();
282  SetType( "DivisionBoxZ" );
283
284  G4Box* mbox = (G4Box*)(fmotherSolid);
285  if( divType == DivWIDTH )
286  {
287    fnDiv = CalculateNDiv( 2*mbox->GetZHalfLength(), width, offset );
288  }
289  else if ( divType == DivNDIV )
290  {
291    fwidth = CalculateWidth( 2*mbox->GetZHalfLength(), nDiv, offset );
292  }
293#ifdef G4DIVDEBUG
294  if( verbose >= 1 )
295  {
296    G4cout << " G4ParameterisationBoxZ - no divisions " << fnDiv << " = "
297           << nDiv << ". Offset " << foffset << " = " << offset
298           << ". Width " << fwidth << " = " << width << G4endl;
299  }
300#endif
301}
302
303//------------------------------------------------------------------------
304G4ParameterisationBoxZ::~G4ParameterisationBoxZ()
305{
306}
307
308//------------------------------------------------------------------------
309G4double G4ParameterisationBoxZ::GetMaxParameter() const
310{
311  G4Box* msol = (G4Box*)(fmotherSolid);
312  return 2*msol->GetZHalfLength();
313}
314
315//------------------------------------------------------------------------
316void
317G4ParameterisationBoxZ::
318ComputeTransformation( const G4int copyNo, G4VPhysicalVolume *physVol ) const
319{
320  G4Box* msol = (G4Box*)(fmotherSolid );
321  G4double mdz = msol->GetZHalfLength();
322
323   //----- translation
324  G4ThreeVector origin(0.,0.,0.); 
325  G4double posi = -mdz + OffsetZ() + (copyNo+0.5)*fwidth;
326
327  if( faxis == kZAxis )
328  {
329    origin.setZ( posi ); 
330  }
331  else
332  { 
333    G4Exception("G4ParameterisationBoxZ::ComputeTransformation()",
334                "IllegalConstruct", FatalException,
335                "Only axes along Z are allowed !  Axis: "+faxis);
336  }
337#ifdef G4DIVDEBUG
338  if( verbose >= 2 )
339  {
340    G4cout << std::setprecision(8) << " G4ParameterisationBoxZ: "
341           << copyNo << G4endl
342           << " Position " << origin << " Axis " << faxis << G4endl;
343  }
344#endif
345   //----- set translation
346  physVol->SetTranslation( origin );
347}
348
349//------------------------------------------------------------------------
350void
351G4ParameterisationBoxZ::
352ComputeDimensions( G4Box& box, const G4int,
353                   const G4VPhysicalVolume* ) const
354{
355  G4Box* msol = (G4Box*)(fmotherSolid);
356
357  G4double pDx = msol->GetXHalfLength();
358  G4double pDy = msol->GetYHalfLength();
359  G4double pDz = fwidth/2. - fhgap;
360
361  box.SetXHalfLength( pDx );
362  box.SetYHalfLength( pDy );
363  box.SetZHalfLength( pDz );
364
365#ifdef G4DIVDEBUG
366  if( verbose >= 2 )
367  {
368    G4cout << " G4ParameterisationBoxZ::ComputeDimensions()" << G4endl
369           << " pDx: " << pDz << G4endl;
370    box.DumpInfo();
371  }
372#endif
373}
374
Note: See TracBrowser for help on using the repository browser.