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: G4VDivisionParameterisation.cc,v 1.16 2010/11/10 09:16:18 gcosmo Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-04-ref-00 $ |
---|
29 | // |
---|
30 | // class G4VDivisionParameterisation 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 "G4VDivisionParameterisation.hh" |
---|
38 | #include "G4VSolid.hh" |
---|
39 | #include "G4VPhysicalVolume.hh" |
---|
40 | #include "G4RotationMatrix.hh" |
---|
41 | #include "G4ReflectedSolid.hh" |
---|
42 | #include "G4GeometryTolerance.hh" |
---|
43 | |
---|
44 | G4int G4VDivisionParameterisation::verbose = 5; |
---|
45 | |
---|
46 | //-------------------------------------------------------------------------- |
---|
47 | G4VDivisionParameterisation:: |
---|
48 | G4VDivisionParameterisation( EAxis axis, G4int nDiv, |
---|
49 | G4double step, G4double offset, |
---|
50 | DivisionType divType, G4VSolid* motherSolid ) |
---|
51 | : faxis(axis), fnDiv( nDiv), fwidth(step), foffset(offset), |
---|
52 | fDivisionType(divType), fmotherSolid( motherSolid ), fReflectedSolid(false), |
---|
53 | fDeleteSolid(false), theVoluFirstCopyNo(1), fhgap(0.) |
---|
54 | { |
---|
55 | #ifdef G4DIVDEBUG |
---|
56 | if (verbose >= 1) |
---|
57 | { |
---|
58 | G4cout << " G4VDivisionParameterisation no divisions " << fnDiv |
---|
59 | << " = " << nDiv << G4endl |
---|
60 | << " offset " << foffset << " = " << offset << G4endl |
---|
61 | << " step " << fwidth << " = " << step << G4endl; |
---|
62 | } |
---|
63 | #endif |
---|
64 | kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance(); |
---|
65 | } |
---|
66 | |
---|
67 | //-------------------------------------------------------------------------- |
---|
68 | G4VDivisionParameterisation::~G4VDivisionParameterisation() |
---|
69 | { |
---|
70 | if (fDeleteSolid) delete fmotherSolid; |
---|
71 | } |
---|
72 | |
---|
73 | //-------------------------------------------------------------------------- |
---|
74 | G4VSolid* |
---|
75 | G4VDivisionParameterisation:: |
---|
76 | ComputeSolid( const G4int i, G4VPhysicalVolume* pv ) |
---|
77 | { |
---|
78 | G4VSolid* solid = G4VPVParameterisation::ComputeSolid(i, pv); |
---|
79 | if (solid->GetEntityType() == "G4ReflectedSolid") |
---|
80 | { |
---|
81 | solid = ((G4ReflectedSolid*)solid)->GetConstituentMovedSolid(); |
---|
82 | } |
---|
83 | return solid; |
---|
84 | } |
---|
85 | |
---|
86 | //-------------------------------------------------------------------------- |
---|
87 | void |
---|
88 | G4VDivisionParameterisation:: |
---|
89 | ChangeRotMatrix( G4VPhysicalVolume *physVol, G4double rotZ ) const |
---|
90 | { |
---|
91 | G4RotationMatrix* rm = new G4RotationMatrix(); |
---|
92 | rm->rotateZ( rotZ ); |
---|
93 | //----- set rotation |
---|
94 | //----- delete first old rotation matrix |
---|
95 | G4RotationMatrix* rmold = physVol->GetRotation(); |
---|
96 | delete rmold; |
---|
97 | physVol->SetRotation(rm); |
---|
98 | } |
---|
99 | |
---|
100 | //-------------------------------------------------------------------------- |
---|
101 | G4int |
---|
102 | G4VDivisionParameterisation:: |
---|
103 | CalculateNDiv( G4double motherDim, G4double width, G4double offset ) const |
---|
104 | { |
---|
105 | #ifdef G4DIVDEBUG |
---|
106 | G4cout << " G4VDivisionParameterisation::CalculateNDiv: " |
---|
107 | << ( motherDim - offset ) / width |
---|
108 | << " Motherdim: " << motherDim << ", Offset: " << offset |
---|
109 | << ", Width: " << width << G4endl; |
---|
110 | #endif |
---|
111 | |
---|
112 | return G4int( ( motherDim - offset ) / width ); |
---|
113 | } |
---|
114 | |
---|
115 | //-------------------------------------------------------------------------- |
---|
116 | G4double |
---|
117 | G4VDivisionParameterisation:: |
---|
118 | CalculateWidth( G4double motherDim, G4int nDiv, G4double offset ) const |
---|
119 | { |
---|
120 | #ifdef G4DIVDEBUG |
---|
121 | G4cout << " G4VDivisionParameterisation::CalculateWidth: " |
---|
122 | << ( motherDim - offset ) / nDiv |
---|
123 | << ", Motherdim: " << motherDim << ", Offset: " << offset |
---|
124 | << ", Number of divisions: " << nDiv << G4endl; |
---|
125 | #endif |
---|
126 | |
---|
127 | return ( motherDim - offset ) / nDiv; |
---|
128 | } |
---|
129 | |
---|
130 | //-------------------------------------------------------------------------- |
---|
131 | void G4VDivisionParameterisation::CheckParametersValidity() |
---|
132 | { |
---|
133 | G4double maxPar = GetMaxParameter(); |
---|
134 | CheckOffset( maxPar ); |
---|
135 | CheckNDivAndWidth( maxPar ); |
---|
136 | } |
---|
137 | |
---|
138 | //-------------------------------------------------------------------------- |
---|
139 | void G4VDivisionParameterisation::CheckOffset( G4double maxPar ) |
---|
140 | { |
---|
141 | if( foffset >= maxPar ) |
---|
142 | { |
---|
143 | G4cerr << "ERROR - G4VDivisionParameterisation::CheckOffset()" << G4endl |
---|
144 | << " Division of solid " << fmotherSolid->GetName() |
---|
145 | << " has too big offset = " << G4endl |
---|
146 | << " " << foffset << " > " << maxPar << " !" << G4endl; |
---|
147 | G4Exception("G4VDivisionParameterisation::CheckOffset()", |
---|
148 | "IllegalConstruct", FatalException, |
---|
149 | "Not supported configuration."); |
---|
150 | } |
---|
151 | } |
---|
152 | |
---|
153 | //-------------------------------------------------------------------------- |
---|
154 | void G4VDivisionParameterisation::CheckNDivAndWidth( G4double maxPar ) |
---|
155 | { |
---|
156 | if( (fDivisionType == DivNDIVandWIDTH) |
---|
157 | && (foffset + fwidth*fnDiv - maxPar > kCarTolerance ) ) |
---|
158 | { |
---|
159 | G4cerr << "ERROR - G4VDivisionParameterisation::CheckNDivAndWidth()" |
---|
160 | << G4endl |
---|
161 | << " Division of solid " << fmotherSolid->GetName() |
---|
162 | << " has too big offset + width*nDiv = " << G4endl |
---|
163 | << " " << foffset + fwidth*fnDiv << " > " |
---|
164 | << foffset << ". Width = " |
---|
165 | << G4endl |
---|
166 | << " " << fwidth << ". nDiv = " << fnDiv << " !" |
---|
167 | << G4endl; |
---|
168 | G4Exception("G4VDivisionParameterisation::CheckNDivAndWidth()", |
---|
169 | "IllegalConstruct", FatalException, |
---|
170 | "Not supported configuration."); |
---|
171 | } |
---|
172 | } |
---|
173 | |
---|
174 | //-------------------------------------------------------------------------- |
---|
175 | G4double G4VDivisionParameterisation::OffsetZ() const |
---|
176 | { |
---|
177 | // take into account reflection in the offset |
---|
178 | G4double offset = foffset; |
---|
179 | if (fReflectedSolid) offset = GetMaxParameter() - fwidth*fnDiv - foffset; |
---|
180 | |
---|
181 | return offset; |
---|
182 | } |
---|
183 | |
---|
184 | |
---|