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: SolidAnalyser.cc,v 1.6 2006/06/29 17:23:19 gunter Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-04-beta-01 $ |
---|
29 | // |
---|
30 | // |
---|
31 | // -------------------------------------------------------------- |
---|
32 | // SolidAnalyser |
---|
33 | // |
---|
34 | // Author: Martin Liendl - Martin.Liendl@cern.ch |
---|
35 | // |
---|
36 | // -------------------------------------------------------------- |
---|
37 | // |
---|
38 | #include "SolidAnalyser.hh" |
---|
39 | |
---|
40 | #include <sstream> |
---|
41 | |
---|
42 | #include "G4Box.hh" |
---|
43 | #include "G4Cons.hh" |
---|
44 | #include "G4Polycone.hh" |
---|
45 | #include "G4Polyhedra.hh" |
---|
46 | #include "G4Trap.hh" |
---|
47 | #include "G4Trd.hh" |
---|
48 | #include "G4Tubs.hh" |
---|
49 | |
---|
50 | SolidAnalyser * SolidAnalyser::theInstance = 0; |
---|
51 | |
---|
52 | SolidAnalyser::SolidAnalyser() |
---|
53 | { |
---|
54 | } |
---|
55 | |
---|
56 | |
---|
57 | SolidAnalyser::~SolidAnalyser() |
---|
58 | { |
---|
59 | delete theInstance; |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | SolidAnalyser * SolidAnalyser::GetSolidAnalyser() |
---|
64 | { |
---|
65 | if (! theInstance) |
---|
66 | theInstance = new SolidAnalyser(); |
---|
67 | |
---|
68 | return theInstance; |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | G4int SolidAnalyser::GetParam(const G4VSolid * s, |
---|
73 | std::vector<std::pair<G4String,G4double> > & result ) const |
---|
74 | { |
---|
75 | const G4Box * box = dynamic_cast<const G4Box*>(s); |
---|
76 | if ( box ) return GetParam(box,result); |
---|
77 | |
---|
78 | const G4Cons * cons = dynamic_cast<const G4Cons*>(s); |
---|
79 | if ( cons ) return GetParam(cons,result); |
---|
80 | |
---|
81 | const G4Polycone * pcon = dynamic_cast<const G4Polycone*>(s); |
---|
82 | if ( pcon ) return GetParam(pcon,result); |
---|
83 | |
---|
84 | const G4Polyhedra * phed = dynamic_cast<const G4Polyhedra*>(s); |
---|
85 | if ( phed ) return GetParam(phed,result); |
---|
86 | |
---|
87 | const G4Trap * trap = dynamic_cast<const G4Trap*>(s); |
---|
88 | if ( trap ) return GetParam(trap,result); |
---|
89 | |
---|
90 | const G4Trd * trd = dynamic_cast<const G4Trd*>(s); |
---|
91 | if ( trd ) return GetParam(trd,result); |
---|
92 | |
---|
93 | const G4Tubs * tubs = dynamic_cast<const G4Tubs*>(s); |
---|
94 | if ( tubs ) return GetParam(tubs,result); |
---|
95 | |
---|
96 | return NotImplemented(s,result); |
---|
97 | } |
---|
98 | |
---|
99 | // default parameters for not implemented solids |
---|
100 | G4int SolidAnalyser::NotImplemented(const G4VSolid * s, |
---|
101 | std::vector<std::pair<G4String,G4double> > & result) const |
---|
102 | { |
---|
103 | G4String temp = s->GetEntityType() + G4String(": not impl."); |
---|
104 | result.push_back(std::make_pair(temp,-1.0)); |
---|
105 | return -1; |
---|
106 | } |
---|
107 | |
---|
108 | // G4Box |
---|
109 | G4int SolidAnalyser::GetParam(const G4Box * s, |
---|
110 | std::vector<std::pair<G4String,G4double> > & result) const |
---|
111 | { |
---|
112 | result.push_back(std::make_pair(G4String("x/2"), s->GetXHalfLength())); |
---|
113 | result.push_back(std::make_pair(G4String("y/2"), s->GetYHalfLength())); |
---|
114 | result.push_back(std::make_pair(G4String("z/2"), s->GetZHalfLength())); |
---|
115 | return 3; |
---|
116 | } |
---|
117 | |
---|
118 | // G4Cons |
---|
119 | G4int SolidAnalyser::GetParam(const G4Cons * s, |
---|
120 | std::vector<std::pair<G4String,G4double> > & result) const |
---|
121 | { |
---|
122 | result.push_back(std::make_pair(G4String("rInZ-"), |
---|
123 | s->GetInnerRadiusMinusZ())); |
---|
124 | result.push_back(std::make_pair(G4String("rInZ+"), |
---|
125 | s->GetInnerRadiusPlusZ())); |
---|
126 | result.push_back(std::make_pair(G4String("rOutZ-"), |
---|
127 | s->GetOuterRadiusMinusZ())); |
---|
128 | result.push_back(std::make_pair(G4String("rOutZ+"), |
---|
129 | s->GetOuterRadiusPlusZ())); |
---|
130 | result.push_back(std::make_pair(G4String("z/2"), |
---|
131 | s->GetZHalfLength())); |
---|
132 | result.push_back(std::make_pair(G4String("startPhi"), |
---|
133 | s->GetStartPhiAngle())); |
---|
134 | result.push_back(std::make_pair(G4String("deltaPhi"), |
---|
135 | s->GetDeltaPhiAngle())); |
---|
136 | return 7; |
---|
137 | } |
---|
138 | |
---|
139 | // G4Polycone |
---|
140 | G4int SolidAnalyser::GetParam(const G4Polycone * s, |
---|
141 | std::vector<std::pair<G4String,G4double> > & result) const |
---|
142 | { |
---|
143 | result.push_back(std::make_pair(G4String("startPhi"), s->GetStartPhi())); |
---|
144 | result.push_back(std::make_pair(G4String("endPhi"), s->GetEndPhi())); |
---|
145 | |
---|
146 | G4int nr = s->GetNumRZCorner(); |
---|
147 | G4String temp("nrRZ"); |
---|
148 | result.push_back(std::make_pair(temp, G4double(nr))); |
---|
149 | for (G4int i=0; i<nr; i++) |
---|
150 | { |
---|
151 | std::ostringstream sstr_r, sstr_z; |
---|
152 | G4PolyconeSideRZ sideRz = s->GetCorner(i); |
---|
153 | sstr_z << "z_" << i << '\0'; |
---|
154 | sstr_r << "r_" << i << '\0'; |
---|
155 | G4String z_str(sstr_z.str()); |
---|
156 | G4String r_str(sstr_r.str()); |
---|
157 | result.push_back(std::make_pair(z_str, sideRz.z)); |
---|
158 | result.push_back(std::make_pair(r_str, sideRz.r)); |
---|
159 | } |
---|
160 | return 3 + 2*nr; |
---|
161 | } |
---|
162 | |
---|
163 | // G4Polyhedra |
---|
164 | G4int SolidAnalyser::GetParam(const G4Polyhedra * s, |
---|
165 | std::vector<std::pair<G4String,G4double> > & result) const |
---|
166 | { |
---|
167 | result.push_back(std::make_pair(G4String("startPhi"), s->GetStartPhi())); |
---|
168 | result.push_back(std::make_pair(G4String("endPhi"), s->GetEndPhi())); |
---|
169 | result.push_back(std::make_pair(G4String("nrSide"), |
---|
170 | G4double(s->GetNumSide()))); |
---|
171 | |
---|
172 | G4int nr = s->GetNumRZCorner(); |
---|
173 | |
---|
174 | result.push_back(std::make_pair(G4String("nrRZ"), G4double(nr))); |
---|
175 | |
---|
176 | for (G4int i=0; i<nr; i++) |
---|
177 | { |
---|
178 | std::ostringstream sstr_r, sstr_z; |
---|
179 | G4PolyhedraSideRZ sideRz = s->GetCorner(i); |
---|
180 | sstr_z << "z_" << i << '\0'; |
---|
181 | sstr_r << "r_" << i << '\0'; |
---|
182 | G4String z_str(sstr_z.str()); |
---|
183 | G4String r_str(sstr_r.str()); |
---|
184 | result.push_back(std::make_pair(z_str, sideRz.z)); |
---|
185 | result.push_back(std::make_pair(r_str, sideRz.r)); |
---|
186 | } |
---|
187 | return 4 + 2*nr; |
---|
188 | } |
---|
189 | |
---|
190 | // G4Trap |
---|
191 | G4int SolidAnalyser::GetParam(const G4Trap * s, |
---|
192 | std::vector<std::pair<G4String,G4double> > & result) const |
---|
193 | { |
---|
194 | result.push_back(std::make_pair(G4String("z/2"), s->GetZHalfLength())); |
---|
195 | |
---|
196 | result.push_back(std::make_pair(G4String("y/2_1"), s->GetYHalfLength1())); |
---|
197 | result.push_back(std::make_pair(G4String("x/2_1"), s->GetXHalfLength1())); |
---|
198 | result.push_back(std::make_pair(G4String("x/2_2"), s->GetXHalfLength2())); |
---|
199 | result.push_back(std::make_pair(G4String("tanAlpha_1"),s->GetTanAlpha1())); |
---|
200 | |
---|
201 | result.push_back(std::make_pair(G4String("y/2_2"), s->GetYHalfLength2())); |
---|
202 | result.push_back(std::make_pair(G4String("x/2_3"), s->GetXHalfLength3())); |
---|
203 | result.push_back(std::make_pair(G4String("x/2_4"), s->GetXHalfLength4())); |
---|
204 | result.push_back(std::make_pair(G4String("tanAlpha_2"),s->GetTanAlpha2())); |
---|
205 | |
---|
206 | return 9; |
---|
207 | } |
---|
208 | |
---|
209 | // G4Trd |
---|
210 | G4int SolidAnalyser::GetParam(const G4Trd * s, |
---|
211 | std::vector<std::pair<G4String,G4double> > & result) const |
---|
212 | { |
---|
213 | result.push_back(std::make_pair(G4String("x/2_1"), s->GetXHalfLength1())); |
---|
214 | result.push_back(std::make_pair(G4String("x/2_2"), s->GetXHalfLength2())); |
---|
215 | result.push_back(std::make_pair(G4String("y/2_1"), s->GetYHalfLength1())); |
---|
216 | result.push_back(std::make_pair(G4String("y/2_2"), s->GetYHalfLength2())); |
---|
217 | result.push_back(std::make_pair(G4String("z/2"), s->GetZHalfLength())); |
---|
218 | |
---|
219 | return 5; |
---|
220 | } |
---|
221 | |
---|
222 | // G4Tubs |
---|
223 | G4int SolidAnalyser::GetParam(const G4Tubs * s, |
---|
224 | std::vector<std::pair<G4String,G4double> > & result) const |
---|
225 | { |
---|
226 | result.push_back(std::make_pair(G4String("rIn"), s->GetInnerRadius())); |
---|
227 | result.push_back(std::make_pair(G4String("rOut"), s->GetOuterRadius())); |
---|
228 | result.push_back(std::make_pair(G4String("z/2"), s->GetZHalfLength())); |
---|
229 | result.push_back(std::make_pair(G4String("startPhi"), |
---|
230 | s->GetStartPhiAngle())); |
---|
231 | result.push_back(std::make_pair(G4String("deltaPhi"), |
---|
232 | s->GetDeltaPhiAngle())); |
---|
233 | |
---|
234 | return 5; |
---|
235 | } |
---|
236 | |
---|
237 | std::ostream & operator<<(std::ostream& flux, |
---|
238 | std::vector<std::pair<G4String,G4double> > & v) |
---|
239 | { |
---|
240 | std::vector<std::pair<G4String,G4double> >::iterator it = v.begin(); |
---|
241 | while ( it != v.end() ) |
---|
242 | { |
---|
243 | flux << (*it).first << '=' << (*it).second << "<br/>" << G4endl; |
---|
244 | it++; |
---|
245 | } |
---|
246 | return flux; |
---|
247 | } |
---|