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