[831] | 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: G4GeomTestStreamLogger.cc,v 1.3 2006/06/29 18:36:49 gunter Exp $ |
---|
[921] | 28 | // GEANT4 tag $Name: geant4-09-02-cand-01 $ |
---|
[831] | 29 | // |
---|
| 30 | // -------------------------------------------------------------------- |
---|
| 31 | // GEANT 4 class source file |
---|
| 32 | // |
---|
| 33 | // G4GeomTestStreamLogger |
---|
| 34 | // |
---|
| 35 | // Author: D.C.Williams, UCSC (davidw@scipp.ucsc.edu) |
---|
| 36 | // -------------------------------------------------------------------- |
---|
| 37 | |
---|
| 38 | #include "G4GeomTestStreamLogger.hh" |
---|
| 39 | #include "G4VSolid.hh" |
---|
| 40 | #include "G4VPhysicalVolume.hh" |
---|
| 41 | #include <iomanip> |
---|
| 42 | |
---|
| 43 | #include "G4GeomTestOverlapList.hh" |
---|
| 44 | #include "G4GeomTestOvershootList.hh" |
---|
| 45 | |
---|
| 46 | // |
---|
| 47 | // Constructor and destructor |
---|
| 48 | // |
---|
| 49 | G4GeomTestStreamLogger::G4GeomTestStreamLogger( std::ostream &o, |
---|
| 50 | G4int theMaxPointsPerError ) |
---|
| 51 | : out(o), maxPointsPerError(theMaxPointsPerError) |
---|
| 52 | {;} |
---|
| 53 | |
---|
| 54 | G4GeomTestStreamLogger::~G4GeomTestStreamLogger() |
---|
| 55 | {;} |
---|
| 56 | |
---|
| 57 | // |
---|
| 58 | // ::PrintPos |
---|
| 59 | // |
---|
| 60 | // Utility class for printing a 3 vector position |
---|
| 61 | // |
---|
| 62 | void G4GeomTestStreamLogger::PrintPos::Print( std::ostream &o ) const |
---|
| 63 | { |
---|
| 64 | o << std::setprecision(6) << std::setw(14) << p.x()/cm; |
---|
| 65 | o << std::setprecision(6) << std::setw(14) << p.y()/cm; |
---|
| 66 | o << std::setprecision(6) << std::setw(14) << p.z()/cm; |
---|
| 67 | if (unit) o << " cm"; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | std::ostream &operator<<( std::ostream &o, |
---|
| 71 | const G4GeomTestStreamLogger::PrintPos &p ) |
---|
| 72 | { |
---|
| 73 | p.Print(o); |
---|
| 74 | return o; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | // |
---|
| 78 | // ::VolumeNameAndCopy |
---|
| 79 | // |
---|
| 80 | // Utility class for printing a volume's name and copy number |
---|
| 81 | // |
---|
| 82 | void |
---|
| 83 | G4GeomTestStreamLogger::VolumeNameAndCopy::Print( std::ostream &o ) const |
---|
| 84 | { |
---|
| 85 | o << volume->GetName() << "[" << volume->GetCopyNo() << "]"; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | std::ostream &operator<<( std::ostream &o, |
---|
| 89 | const G4GeomTestStreamLogger::VolumeNameAndCopy &p ) |
---|
| 90 | { |
---|
| 91 | p.Print(o); |
---|
| 92 | return o; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | // |
---|
| 97 | // SolidProblem |
---|
| 98 | // |
---|
| 99 | void G4GeomTestStreamLogger::SolidProblem( const G4VSolid *solid, |
---|
| 100 | const G4String &message, |
---|
| 101 | const G4ThreeVector &point ) |
---|
| 102 | { |
---|
| 103 | out << "GeomTest Error: SolidProblem\n" |
---|
| 104 | << " " << message << "\n" |
---|
| 105 | << " Solid name = " << solid->GetName() << "\n" |
---|
| 106 | << " Local position = " << PrintPos(point) << std::endl; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | // |
---|
| 111 | // NoProblem |
---|
| 112 | // |
---|
| 113 | void G4GeomTestStreamLogger::NoProblem( const G4String &message ) |
---|
| 114 | { |
---|
| 115 | out << message << std::endl; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | // |
---|
| 120 | // OverlappingDaughters |
---|
| 121 | // |
---|
| 122 | void |
---|
| 123 | G4GeomTestStreamLogger::OverlappingDaughters(const G4GeomTestOverlapList *list) |
---|
| 124 | { |
---|
| 125 | G4int n = list->NumError(); |
---|
| 126 | if (n <= 0) return; |
---|
| 127 | |
---|
| 128 | out << "GeomTest Error: Overlapping daughter volumes\n" |
---|
| 129 | << " The volumes " << VolumeNameAndCopy(list->GetDaughter1()) |
---|
| 130 | << " and " << VolumeNameAndCopy(list->GetDaughter2()) << ",\n" |
---|
| 131 | << " both daughters of volume " << VolumeNameAndCopy(list->GetMother()) |
---|
| 132 | << ",\n" |
---|
| 133 | << " appear to overlap at the following " << (n>1 ? "points" : "point") |
---|
| 134 | << " in global coordinates:"; |
---|
| 135 | |
---|
| 136 | G4int nInterval, nStop; |
---|
| 137 | |
---|
| 138 | if (n <= maxPointsPerError) { |
---|
| 139 | out << "\n"; |
---|
| 140 | nInterval = 1; |
---|
| 141 | nStop = n; |
---|
| 142 | } |
---|
| 143 | else { |
---|
| 144 | out << " (list truncated)\n"; |
---|
| 145 | nInterval = n/maxPointsPerError; |
---|
| 146 | nStop = maxPointsPerError*nInterval; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | G4int i; |
---|
| 150 | G4ThreeVector s1, s2; |
---|
| 151 | |
---|
| 152 | PrintSegmentListHeader(); |
---|
| 153 | for(i=0;i<nStop;i+=nInterval) { |
---|
| 154 | list->GetGlobalPoints( i, s1, s2 ); |
---|
| 155 | PrintSegmentListElement( s1, s2 ); |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | out << " Which in the mother coordinate system " << IsAre(n) << ":\n"; |
---|
| 159 | |
---|
| 160 | PrintSegmentListHeader(); |
---|
| 161 | for(i=0;i<nStop;i+=nInterval) { |
---|
| 162 | list->GetMotherPoints( i, s1, s2 ); |
---|
| 163 | PrintSegmentListElement( s1, s2 ); |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | out << " Which in the coordinate system of " |
---|
| 167 | << VolumeNameAndCopy(list->GetDaughter1()) << " " << IsAre(n) << ":\n"; |
---|
| 168 | |
---|
| 169 | PrintSegmentListHeader(); |
---|
| 170 | for(i=0;i<nStop;i+=nInterval) { |
---|
| 171 | list->GetDaught1Points( i, s1, s2 ); |
---|
| 172 | PrintSegmentListElement( s1, s2 ); |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | out << " Which in the coordinate system of " |
---|
| 176 | << VolumeNameAndCopy(list->GetDaughter2()) << " " << IsAre(n) << ":\n"; |
---|
| 177 | |
---|
| 178 | PrintSegmentListHeader(); |
---|
| 179 | for(i=0;i<nStop;i+=nInterval) { |
---|
| 180 | list->GetDaught2Points( i, s1, s2 ); |
---|
| 181 | PrintSegmentListElement( s1, s2 ); |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | out << std::endl; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | // |
---|
| 189 | // OvershootingDaughter |
---|
| 190 | // |
---|
| 191 | void G4GeomTestStreamLogger:: |
---|
| 192 | OvershootingDaughter( const G4GeomTestOvershootList *list ) |
---|
| 193 | { |
---|
| 194 | G4int n = list->NumError(); |
---|
| 195 | if (n <= 0) return; |
---|
| 196 | |
---|
| 197 | out << "GeomTest Error: Overshooting daughter volume\n" |
---|
| 198 | << " The volume " << VolumeNameAndCopy(list->GetDaughter()) |
---|
| 199 | << " appears to extend outside the mother volume " |
---|
| 200 | << VolumeNameAndCopy(list->GetMother()) << "\n" |
---|
| 201 | << " at the following " << (n>1 ? "points" : "point") |
---|
| 202 | << " in global coordinates:"; |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | G4int nInterval, nStop; |
---|
| 206 | |
---|
| 207 | if (n <= maxPointsPerError) { |
---|
| 208 | out << "\n"; |
---|
| 209 | nInterval = 1; |
---|
| 210 | nStop = n; |
---|
| 211 | } |
---|
| 212 | else { |
---|
| 213 | out << " (list truncated)\n"; |
---|
| 214 | nInterval = n/maxPointsPerError; |
---|
| 215 | nStop = maxPointsPerError*nInterval; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | G4int i; |
---|
| 219 | G4ThreeVector s1, s2; |
---|
| 220 | |
---|
| 221 | PrintSegmentListHeader(); |
---|
| 222 | for(i=0;i<nStop;i+=nInterval) { |
---|
| 223 | list->GetGlobalPoints( i, s1, s2 ); |
---|
| 224 | PrintSegmentListElement( s1, s2 ); |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | out << " Which in the mother coordinate system " << IsAre(n) << ":\n"; |
---|
| 228 | |
---|
| 229 | PrintSegmentListHeader(); |
---|
| 230 | for(i=0;i<nStop;i+=nInterval) { |
---|
| 231 | list->GetMotherPoints( i, s1, s2 ); |
---|
| 232 | PrintSegmentListElement( s1, s2 ); |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | out << " Which in the coordinate system of " |
---|
| 236 | << VolumeNameAndCopy(list->GetDaughter()) << " " << IsAre(n) << ":\n"; |
---|
| 237 | |
---|
| 238 | PrintSegmentListHeader(); |
---|
| 239 | for(i=0;i<nStop;i+=nInterval) { |
---|
| 240 | list->GetDaughtPoints( i, s1, s2 ); |
---|
| 241 | PrintSegmentListElement( s1, s2 ); |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | out << std::endl; |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | |
---|
| 248 | |
---|
| 249 | // |
---|
| 250 | // PrintSegmentListHeader (protected) |
---|
| 251 | // |
---|
| 252 | // Print out a header for a segment list |
---|
| 253 | // |
---|
| 254 | void G4GeomTestStreamLogger::PrintSegmentListHeader() |
---|
| 255 | { |
---|
| 256 | static const char *header = |
---|
| 257 | " length (cm) ---------- start position (cm) ----------- ----------- end position (cm) ------------\n"; |
---|
| 258 | // .............| .............|.............|.............| .............|.............|.............| |
---|
| 259 | // 1234 1234 123 |
---|
| 260 | |
---|
| 261 | out << header; |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | |
---|
| 265 | // |
---|
| 266 | // PrintSegmentListElement (protected) |
---|
| 267 | // |
---|
| 268 | // Print out one segment value |
---|
| 269 | // |
---|
| 270 | void G4GeomTestStreamLogger::PrintSegmentListElement( const G4ThreeVector &s1, |
---|
| 271 | const G4ThreeVector &s2 ) |
---|
| 272 | { |
---|
| 273 | out << " " << std::setprecision(6) << std::setw(14) |
---|
| 274 | << (s1-s2).mag()/cm |
---|
| 275 | << " " << PrintPos(s1,false) << " " << PrintPos(s2,false) << "\n"; |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | |
---|
| 279 | // |
---|
| 280 | // IsAre (protected) |
---|
| 281 | // |
---|
| 282 | // Return a pointer to the string "is" if the argument |
---|
| 283 | // is equal to 1, otherwise return a pointer to "are" |
---|
| 284 | // |
---|
| 285 | const char *G4GeomTestStreamLogger::IsAre( G4int n ) |
---|
| 286 | { |
---|
| 287 | const char *is = "is"; |
---|
| 288 | const char *are = "are"; |
---|
| 289 | |
---|
| 290 | return n > 1 ? are : is; |
---|
| 291 | } |
---|