[807] | 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 | // File name: RadmonDetectorPadsData.cc |
---|
| 28 | // Creation date: Sep 2005 |
---|
| 29 | // Main author: Riccardo Capra <capra@ge.infn.it> |
---|
| 30 | // |
---|
| 31 | // Id: $Id: RadmonDetectorPadsData.cc,v 1.3 2006/06/29 16:14:11 gunter Exp $ |
---|
| 32 | // Tag: $Name: $ |
---|
| 33 | // |
---|
| 34 | |
---|
| 35 | // Include files |
---|
| 36 | #include "RadmonDetectorPadsData.hh" |
---|
| 37 | #include "RadmonMessenger.hh" |
---|
| 38 | |
---|
| 39 | RadmonDetectorPadsData :: RadmonDetectorPadsData(const RadmonDetectorPadsData & copy) |
---|
| 40 | : |
---|
| 41 | padWidth(copy.padWidth), |
---|
| 42 | padHeight(copy.padHeight), |
---|
| 43 | padMaterial(copy.padMaterial), |
---|
| 44 | padPositions(copy.padPositions), |
---|
| 45 | padRotations(copy.padRotations) |
---|
| 46 | { |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | G4int RadmonDetectorPadsData :: GetNPads(void) const |
---|
| 54 | { |
---|
| 55 | return padPositions.size(); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | const G4ThreeVector & RadmonDetectorPadsData :: GetPosition(G4int index) const |
---|
| 61 | { |
---|
| 62 | return padPositions[index]; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | const G4RotationMatrix & RadmonDetectorPadsData :: GetRotation(G4int index) const |
---|
| 68 | { |
---|
| 69 | return padRotations[index]; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | void RadmonDetectorPadsData :: AppendPositionAndRotation(const G4ThreeVector & position, const G4RotationMatrix & rotation) |
---|
| 77 | { |
---|
| 78 | padPositions.push_back(position); |
---|
| 79 | padRotations.push_back(rotation); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | RadmonDetectorPadsData & RadmonDetectorPadsData :: operator=(const RadmonDetectorPadsData & copy) |
---|
| 87 | { |
---|
| 88 | padWidth=copy.padWidth; |
---|
| 89 | padHeight=copy.padHeight; |
---|
| 90 | padMaterial=copy.padMaterial; |
---|
| 91 | padPositions=copy.padPositions; |
---|
| 92 | padRotations=copy.padRotations; |
---|
| 93 | |
---|
| 94 | return (*this); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | bool RadmonDetectorPadsData :: ReadPositionsAndRotationsFromString(const G4String & positionStr) |
---|
| 102 | { |
---|
| 103 | // (xx mm, yy mm, [delta deg]) |
---|
| 104 | |
---|
| 105 | G4bool somethingDone(false); |
---|
| 106 | G4String positions(positionStr); |
---|
| 107 | str_size i(0); |
---|
| 108 | const str_size size(positions.length()); |
---|
| 109 | |
---|
| 110 | while (i<size) |
---|
| 111 | { |
---|
| 112 | if (positions(i)==' ') |
---|
| 113 | { |
---|
| 114 | i++; |
---|
| 115 | continue; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | if (positions(i)=='(') |
---|
| 119 | { |
---|
| 120 | str_size j(positions.index(')', i)); |
---|
| 121 | |
---|
| 122 | if (j==G4String::npos) |
---|
| 123 | return false; |
---|
| 124 | |
---|
| 125 | somethingDone=true; |
---|
| 126 | G4String content(positions(i+1, j-i-1)); |
---|
| 127 | |
---|
| 128 | G4double x; |
---|
| 129 | G4double y; |
---|
| 130 | G4double delta; |
---|
| 131 | if (!ProcessElement(x, y, delta, content)) |
---|
| 132 | return false; |
---|
| 133 | |
---|
| 134 | G4RotationMatrix rotation(G4RotationMatrix::IDENTITY); |
---|
| 135 | rotation.setDelta(delta); |
---|
| 136 | AppendPositionAndRotation(G4ThreeVector(x, y, 0.), rotation); |
---|
| 137 | |
---|
| 138 | i=j+1; |
---|
| 139 | continue; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | return false; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | return somethingDone; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | bool RadmonDetectorPadsData :: ProcessElement(G4double & x, G4double & y, G4double & delta, const G4String & content) |
---|
| 151 | { |
---|
| 152 | G4String cont(content); |
---|
| 153 | |
---|
| 154 | str_size i(cont.index(',')); |
---|
| 155 | str_size size(cont.length()); |
---|
| 156 | while (size>1) |
---|
| 157 | { |
---|
| 158 | if (cont(size-1)!=' ') |
---|
| 159 | break; |
---|
| 160 | |
---|
| 161 | size--; |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | if (i==G4String::npos) |
---|
| 165 | return false; |
---|
| 166 | |
---|
| 167 | if (!ReadUmis(x, cont(0, i), "Length")) |
---|
| 168 | return false; |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | do |
---|
| 172 | { |
---|
| 173 | i++; |
---|
| 174 | |
---|
| 175 | if (i>=size) |
---|
| 176 | return false; |
---|
| 177 | } |
---|
| 178 | while (cont(i)==' '); |
---|
| 179 | |
---|
| 180 | str_size j(cont.index(',', i)); |
---|
| 181 | |
---|
| 182 | if (j==G4String::npos) |
---|
| 183 | { |
---|
| 184 | delta=0.*deg; |
---|
| 185 | |
---|
| 186 | return ReadUmis(y, cont(i, size-i), "Length"); |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | if (!ReadUmis(y, cont(i+1, j-i-1), "Length")) |
---|
| 190 | return false; |
---|
| 191 | |
---|
| 192 | do |
---|
| 193 | { |
---|
| 194 | j++; |
---|
| 195 | |
---|
| 196 | if (j>=size) |
---|
| 197 | return false; |
---|
| 198 | } |
---|
| 199 | while (cont(j)==' '); |
---|
| 200 | |
---|
| 201 | return ReadUmis(y, cont(j, size-j), "Angle"); |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | |
---|
| 206 | bool RadmonDetectorPadsData :: ReadUmis(G4double & value, const G4String & text, const char * category) |
---|
| 207 | { |
---|
| 208 | G4String args[2]; |
---|
| 209 | |
---|
| 210 | if (!RadmonMessenger::ProcessArguments(text, 2, args)) |
---|
| 211 | return false; |
---|
| 212 | |
---|
| 213 | value=RadmonMessenger::GetUnit(args[1], category); |
---|
| 214 | if (value<=0.) |
---|
| 215 | return false; |
---|
| 216 | |
---|
| 217 | value*=G4UIcommand::ConvertToDouble(args[0]); |
---|
| 218 | |
---|
| 219 | return true; |
---|
| 220 | } |
---|
| 221 | |
---|