[814] | 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 | // |
---|
[850] | 27 | // $Id: G4ScoringBox.cc,v 1.54 2008/08/29 02:50:05 akimura Exp $ |
---|
[998] | 28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $ |
---|
[814] | 29 | // |
---|
| 30 | |
---|
| 31 | #include "G4ScoringBox.hh" |
---|
| 32 | |
---|
| 33 | #include "G4Box.hh" |
---|
| 34 | #include "G4LogicalVolume.hh" |
---|
| 35 | #include "G4VPhysicalVolume.hh" |
---|
| 36 | #include "G4PVPlacement.hh" |
---|
| 37 | #include "G4PVReplica.hh" |
---|
| 38 | #include "G4PVDivision.hh" |
---|
| 39 | #include "G4PVParameterised.hh" |
---|
| 40 | #include "G4VisAttributes.hh" |
---|
| 41 | #include "G4ScoringBoxParameterisation.hh" |
---|
| 42 | #include "G4VVisManager.hh" |
---|
| 43 | #include "G4VScoreColorMap.hh" |
---|
| 44 | |
---|
| 45 | #include "G4MultiFunctionalDetector.hh" |
---|
| 46 | #include "G4SDParticleFilter.hh" |
---|
| 47 | #include "G4VPrimitiveScorer.hh" |
---|
| 48 | |
---|
| 49 | #include "G4ScoringManager.hh" |
---|
| 50 | |
---|
| 51 | #include <map> |
---|
| 52 | #include <fstream> |
---|
| 53 | |
---|
| 54 | G4ScoringBox::G4ScoringBox(G4String wName) |
---|
| 55 | :G4VScoringMesh(wName), fSegmentDirection(-1), |
---|
| 56 | fMeshElementLogical(0) |
---|
| 57 | { |
---|
| 58 | fShape = boxMesh; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | G4ScoringBox::~G4ScoringBox() |
---|
| 62 | { |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | void G4ScoringBox::Construct(G4VPhysicalVolume* fWorldPhys) |
---|
| 66 | { |
---|
| 67 | if(fConstructed) { |
---|
| 68 | |
---|
| 69 | if(verboseLevel > 0) |
---|
| 70 | G4cout << fWorldPhys->GetName() << " --- All quantities are reset." << G4endl; |
---|
| 71 | ResetScore(); |
---|
| 72 | |
---|
| 73 | } else { |
---|
| 74 | fConstructed = true; |
---|
| 75 | SetupGeometry(fWorldPhys); |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | void G4ScoringBox::SetupGeometry(G4VPhysicalVolume * fWorldPhys) { |
---|
| 82 | |
---|
| 83 | if(verboseLevel > 9) G4cout << "G4ScoringBox::SetupGeometry() ..." << G4endl; |
---|
| 84 | |
---|
| 85 | // World |
---|
| 86 | G4VPhysicalVolume * scoringWorld = fWorldPhys; |
---|
| 87 | G4LogicalVolume * worldLogical = scoringWorld->GetLogicalVolume(); |
---|
| 88 | |
---|
| 89 | // Scoring Mesh |
---|
| 90 | if(verboseLevel > 9) G4cout << fWorldName << G4endl; |
---|
| 91 | G4String boxName = fWorldName; |
---|
| 92 | |
---|
| 93 | if(verboseLevel > 9) G4cout << fSize[0] << ", " << fSize[1] << ", " << fSize[2] << G4endl; |
---|
| 94 | G4VSolid * boxSolid = new G4Box(boxName+"0", fSize[0], fSize[1], fSize[2]); |
---|
| 95 | G4LogicalVolume * boxLogical = new G4LogicalVolume(boxSolid, 0, boxName); |
---|
| 96 | new G4PVPlacement(fRotationMatrix, fCenterPosition, |
---|
| 97 | boxLogical, boxName+"0", worldLogical, false, 0); |
---|
| 98 | |
---|
| 99 | //G4double fsegment[3][3]; |
---|
| 100 | //G4int segOrder[3]; |
---|
| 101 | //GetSegmentOrder(fSegmentDirection, fNSegment, segOrder, fsegment); |
---|
| 102 | //EAxis axis[3] = {kXAxis, kYAxis, kZAxis}; |
---|
| 103 | |
---|
| 104 | G4String layerName[2] = {boxName + "1", boxName + "2"}; |
---|
| 105 | G4VSolid * layerSolid[2]; |
---|
| 106 | G4LogicalVolume * layerLogical[2]; |
---|
| 107 | |
---|
[850] | 108 | //-- fisrt nested layer (replicated to x direction) |
---|
[814] | 109 | if(verboseLevel > 9) G4cout << "layer 1 :" << G4endl; |
---|
| 110 | layerSolid[0] = new G4Box(layerName[0], |
---|
| 111 | fSize[0]/fNSegment[0], |
---|
| 112 | fSize[1], |
---|
| 113 | fSize[2]); |
---|
| 114 | layerLogical[0] = new G4LogicalVolume(layerSolid[0], 0, layerName[0]); |
---|
| 115 | if(fNSegment[0] > 1) { |
---|
| 116 | if(verboseLevel > 9) G4cout << "G4ScoringBox::Construct() : Replicate to x direction" << G4endl; |
---|
| 117 | if(G4ScoringManager::GetReplicaLevel()>0) |
---|
| 118 | { |
---|
| 119 | new G4PVReplica(layerName[0], layerLogical[0], boxLogical, kXAxis, |
---|
| 120 | fNSegment[0], fSize[0]/fNSegment[0]*2.); |
---|
| 121 | } |
---|
| 122 | else |
---|
| 123 | { |
---|
| 124 | new G4PVDivision(layerName[0], layerLogical[0], boxLogical, kXAxis, |
---|
[850] | 125 | fNSegment[0], 0.); |
---|
[814] | 126 | } |
---|
| 127 | } else if(fNSegment[0] == 1) { |
---|
| 128 | if(verboseLevel > 9) G4cout << "G4ScoringBox::Construct() : Placement" << G4endl; |
---|
| 129 | new G4PVPlacement(0, G4ThreeVector(0.,0.,0.), layerLogical[0], layerName[0], boxLogical, false, 0); |
---|
| 130 | } else |
---|
| 131 | G4cerr << "ERROR : G4ScoringBox::SetupGeometry() : invalid parameter (" |
---|
| 132 | << fNSegment[0] << ") " |
---|
| 133 | << "in placement of the first nested layer." << G4endl; |
---|
| 134 | |
---|
| 135 | if(verboseLevel > 9) { |
---|
| 136 | G4cout << fSize[0]/fNSegment[0] << ", " |
---|
| 137 | << fSize[1] << ", " |
---|
| 138 | << fSize[2] << G4endl; |
---|
| 139 | G4cout << layerName[0] << ": kXAxis, " |
---|
| 140 | << fNSegment[0] << ", " |
---|
| 141 | << 2.*fSize[0]/fNSegment[0] << G4endl; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | // second nested layer (replicated to y direction) |
---|
| 145 | if(verboseLevel > 9) G4cout << "layer 2 :" << G4endl; |
---|
| 146 | layerSolid[1] = new G4Box(layerName[1], |
---|
| 147 | fSize[0]/fNSegment[0], |
---|
| 148 | fSize[1]/fNSegment[1], |
---|
| 149 | fSize[2]); |
---|
| 150 | layerLogical[1] = new G4LogicalVolume(layerSolid[1], 0, layerName[1]); |
---|
| 151 | if(fNSegment[1] > 1) { |
---|
| 152 | if(verboseLevel > 9) G4cout << "G4ScoringBox::Construct() : Replicate to y direction" << G4endl; |
---|
| 153 | if(G4ScoringManager::GetReplicaLevel()>1) |
---|
| 154 | { |
---|
| 155 | new G4PVReplica(layerName[1], layerLogical[1], layerLogical[0], kYAxis, |
---|
| 156 | fNSegment[1], fSize[1]/fNSegment[1]*2.); |
---|
| 157 | } |
---|
| 158 | else |
---|
| 159 | { |
---|
| 160 | new G4PVDivision(layerName[1], layerLogical[1], layerLogical[0], kYAxis, |
---|
[850] | 161 | fNSegment[1], 0.); |
---|
[814] | 162 | } |
---|
| 163 | } else if(fNSegment[1] == 1) { |
---|
| 164 | if(verboseLevel > 9) G4cout << "G4ScoringBox::Construct() : Placement" << G4endl; |
---|
| 165 | new G4PVPlacement(0, G4ThreeVector(0.,0.,0.), layerLogical[1], layerName[1], layerLogical[0], false, 0); |
---|
| 166 | } else |
---|
| 167 | G4cerr << "ERROR : G4ScoringBox::SetupGeometry() : invalid parameter (" |
---|
| 168 | << fNSegment[1] << ") " |
---|
| 169 | << "in placement of the second nested layer." << G4endl; |
---|
| 170 | |
---|
| 171 | if(verboseLevel > 9) { |
---|
| 172 | G4cout << fSize[0]/fNSegment[0] << ", " |
---|
| 173 | << fSize[1]/fNSegment[1] << ", " |
---|
| 174 | << fSize[2] << G4endl; |
---|
| 175 | G4cout << layerName[1] << ": kYAxis, " |
---|
| 176 | << fNSegment[1] << ", " |
---|
| 177 | << 2.*fSize[1]/fNSegment[1] << G4endl; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | // mesh elements (replicated to z direction) |
---|
| 181 | if(verboseLevel > 9) G4cout << "mesh elements :" << G4endl; |
---|
| 182 | G4String elementName = boxName +"3"; |
---|
| 183 | G4VSolid * elementSolid = new G4Box(elementName, |
---|
| 184 | fSize[0]/fNSegment[0], |
---|
| 185 | fSize[1]/fNSegment[1], |
---|
| 186 | fSize[2]/fNSegment[2]); |
---|
| 187 | fMeshElementLogical = new G4LogicalVolume(elementSolid, 0, elementName); |
---|
| 188 | if(fNSegment[2] > 1) |
---|
| 189 | if(fSegmentPositions.size() > 0) { |
---|
| 190 | if(verboseLevel > 9) G4cout << "G4ScoringBox::Construct() : Parameterise to z direction" << G4endl; |
---|
| 191 | G4double motherDims[3] ={fSize[0]/fNSegment[0], |
---|
| 192 | fSize[1]/fNSegment[1], |
---|
| 193 | fSize[2]/fNSegment[2]}; |
---|
| 194 | G4int nelement = fNSegment[2]; |
---|
| 195 | fSegmentPositions.push_back(fSize[2]*2.); |
---|
| 196 | //G4ScoringBoxParameterisation * param = |
---|
| 197 | G4VPVParameterisation * param = |
---|
| 198 | new G4ScoringBoxParameterisation(kZAxis, motherDims, fSegmentPositions); |
---|
| 199 | new G4PVParameterised(elementName, |
---|
| 200 | fMeshElementLogical, |
---|
| 201 | layerLogical[1], |
---|
| 202 | kZAxis, |
---|
| 203 | nelement, |
---|
| 204 | param); |
---|
| 205 | |
---|
| 206 | if(verboseLevel > 9) { |
---|
| 207 | G4cout << motherDims[0] << ", " << motherDims[1] << ", " << motherDims[2] << G4endl; |
---|
| 208 | for(int i = 0; i < (int)fSegmentPositions.size(); i++) |
---|
| 209 | G4cout << fSegmentPositions[i] << ", "; |
---|
| 210 | G4cout << G4endl; |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | } else { |
---|
| 214 | if(verboseLevel > 9) G4cout << "G4ScoringBox::Construct() : Replicate to z direction" << G4endl; |
---|
| 215 | |
---|
| 216 | if(G4ScoringManager::GetReplicaLevel()>2) |
---|
| 217 | { |
---|
| 218 | new G4PVReplica(elementName, fMeshElementLogical, layerLogical[1], kZAxis, |
---|
| 219 | fNSegment[2], 2.*fSize[2]/fNSegment[2]); |
---|
| 220 | } |
---|
| 221 | else |
---|
| 222 | { |
---|
| 223 | new G4PVDivision(elementName, fMeshElementLogical, layerLogical[1], kZAxis, |
---|
[850] | 224 | fNSegment[2], 0.); |
---|
[814] | 225 | } |
---|
| 226 | } |
---|
| 227 | else if(fNSegment[2] == 1) { |
---|
| 228 | if(verboseLevel > 9) G4cout << "G4ScoringBox::Construct() : Placement" << G4endl; |
---|
| 229 | new G4PVPlacement(0, G4ThreeVector(0.,0.,0.), fMeshElementLogical, elementName, layerLogical[1], false, 0); |
---|
| 230 | } else |
---|
| 231 | G4cerr << "ERROR : G4ScoringBox::SetupGeometry() : " |
---|
| 232 | << "invalid parameter (" << fNSegment[2] << ") " |
---|
| 233 | << "in mesh element placement." << G4endl; |
---|
| 234 | |
---|
| 235 | if(verboseLevel > 9) { |
---|
| 236 | G4cout << fSize[0]/fNSegment[0] << ", " |
---|
| 237 | << fSize[1]/fNSegment[1] << ", " |
---|
| 238 | << fSize[2]/fNSegment[2] << G4endl; |
---|
| 239 | G4cout << elementName << ": kZAxis, " |
---|
| 240 | << fNSegment[2] << ", " |
---|
| 241 | << 2.*fSize[2]/fNSegment[2] << G4endl; |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | |
---|
| 245 | // set the sensitive detector |
---|
| 246 | fMeshElementLogical->SetSensitiveDetector(fMFD); |
---|
| 247 | |
---|
| 248 | |
---|
| 249 | // vis. attributes |
---|
| 250 | G4VisAttributes * visatt = new G4VisAttributes(G4Colour(.5,.5,.5)); |
---|
| 251 | visatt->SetVisibility(false); |
---|
| 252 | layerLogical[0]->SetVisAttributes(visatt); |
---|
| 253 | layerLogical[1]->SetVisAttributes(visatt); |
---|
| 254 | visatt->SetVisibility(true); |
---|
| 255 | fMeshElementLogical->SetVisAttributes(visatt); |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | |
---|
| 259 | void G4ScoringBox::List() const { |
---|
| 260 | G4cout << "G4ScoringBox : " << fWorldName << " --- Shape: Box mesh" << G4endl; |
---|
[850] | 261 | G4cout << " Size (x, y, z): (" |
---|
| 262 | << fSize[0]/cm << ", " |
---|
| 263 | << fSize[1]/cm << ", " |
---|
| 264 | << fSize[2]/cm << ") [cm]" |
---|
| 265 | << G4endl; |
---|
[814] | 266 | |
---|
| 267 | G4VScoringMesh::List(); |
---|
| 268 | } |
---|
| 269 | |
---|
| 270 | void G4ScoringBox::Draw(std::map<G4int, G4double*> * map, G4VScoreColorMap* colorMap, G4int axflg) { |
---|
| 271 | |
---|
| 272 | G4VVisManager * pVisManager = G4VVisManager::GetConcreteInstance(); |
---|
| 273 | if(pVisManager) { |
---|
| 274 | |
---|
| 275 | // cell vectors |
---|
| 276 | std::vector<std::vector<std::vector<double> > > cell; // cell[X][Y][Z] |
---|
| 277 | std::vector<double> ez; |
---|
| 278 | for(int z = 0; z < fNSegment[2]; z++) ez.push_back(0.); |
---|
| 279 | std::vector<std::vector<double> > eyz; |
---|
| 280 | for(int y = 0; y < fNSegment[1]; y++) eyz.push_back(ez); |
---|
| 281 | for(int x = 0; x < fNSegment[0]; x++) cell.push_back(eyz); |
---|
| 282 | |
---|
| 283 | std::vector<std::vector<double> > xycell; // xycell[X][Y] |
---|
| 284 | std::vector<double> ey; |
---|
| 285 | for(int y = 0; y < fNSegment[1]; y++) ey.push_back(0.); |
---|
| 286 | for(int x = 0; x < fNSegment[0]; x++) xycell.push_back(ey); |
---|
| 287 | |
---|
| 288 | std::vector<std::vector<double> > yzcell; // yzcell[Y][Z] |
---|
| 289 | for(int y = 0; y < fNSegment[1]; y++) yzcell.push_back(ez); |
---|
| 290 | |
---|
| 291 | std::vector<std::vector<double> > xzcell; // xzcell[X][Z] |
---|
| 292 | for(int x = 0; x < fNSegment[0]; x++) xzcell.push_back(ez); |
---|
| 293 | |
---|
[850] | 294 | G4double xymin = DBL_MAX, yzmin = DBL_MAX, xzmin = DBL_MAX; |
---|
[814] | 295 | G4double xymax = 0., yzmax = 0., xzmax = 0.; |
---|
| 296 | G4int q[3]; |
---|
| 297 | std::map<G4int, G4double*>::iterator itr = map->begin(); |
---|
| 298 | for(; itr != map->end(); itr++) { |
---|
| 299 | GetXYZ(itr->first, q); |
---|
| 300 | |
---|
| 301 | xycell[q[0]][q[1]] += *(itr->second); |
---|
[850] | 302 | if(xymin > xycell[q[0]][q[1]]) xymin = xycell[q[0]][q[1]]; |
---|
[814] | 303 | if(xymax < xycell[q[0]][q[1]]) xymax = xycell[q[0]][q[1]]; |
---|
| 304 | |
---|
| 305 | yzcell[q[1]][q[2]] += *(itr->second); |
---|
[850] | 306 | if(yzmin > yzcell[q[1]][q[2]]) yzmin = yzcell[q[1]][q[2]]; |
---|
[814] | 307 | if(yzmax < yzcell[q[1]][q[2]]) yzmax = yzcell[q[1]][q[2]]; |
---|
| 308 | |
---|
| 309 | xzcell[q[0]][q[2]] += *(itr->second); |
---|
[850] | 310 | if(xzmin > xzcell[q[0]][q[2]]) xzmin = xzcell[q[0]][q[2]]; |
---|
[814] | 311 | if(xzmax < xzcell[q[0]][q[2]]) xzmax = xzcell[q[0]][q[2]]; |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | G4VisAttributes att; |
---|
| 315 | att.SetForceSolid(true); |
---|
| 316 | att.SetForceAuxEdgeVisible(true); |
---|
| 317 | |
---|
| 318 | G4Scale3D scale; |
---|
| 319 | if(axflg/100==1) { |
---|
| 320 | // xy plane |
---|
[850] | 321 | if(colorMap->IfFloatMinMax()) { colorMap->SetMinMax(xymin ,xymax); } |
---|
[814] | 322 | G4ThreeVector zhalf(0., 0., fSize[2]/fNSegment[2]*0.98); |
---|
| 323 | G4Box xyplate("xy", fSize[0]/fNSegment[0], fSize[1]/fNSegment[1], fSize[2]/fNSegment[2]*0.01); |
---|
| 324 | for(int x = 0; x < fNSegment[0]; x++) { |
---|
| 325 | for(int y = 0; y < fNSegment[1]; y++) { |
---|
| 326 | G4ThreeVector pos(GetReplicaPosition(x, y, 0) - zhalf); |
---|
| 327 | G4ThreeVector pos2(GetReplicaPosition(x, y, fNSegment[2]-1) + zhalf); |
---|
| 328 | G4Transform3D trans, trans2; |
---|
| 329 | if(fRotationMatrix) { |
---|
| 330 | trans = G4Rotate3D(*fRotationMatrix).inverse()*G4Translate3D(pos); |
---|
| 331 | trans = G4Translate3D(fCenterPosition)*trans; |
---|
| 332 | trans2 = G4Rotate3D(*fRotationMatrix).inverse()*G4Translate3D(pos2); |
---|
| 333 | trans2 = G4Translate3D(fCenterPosition)*trans2; |
---|
| 334 | } else { |
---|
| 335 | trans = G4Translate3D(pos)*G4Translate3D(fCenterPosition); |
---|
| 336 | trans2 = G4Translate3D(pos2)*G4Translate3D(fCenterPosition); |
---|
| 337 | } |
---|
| 338 | G4double c[4]; |
---|
| 339 | colorMap->GetMapColor(xycell[x][y], c); |
---|
| 340 | att.SetColour(c[0], c[1], c[2]);//, c[3]); |
---|
| 341 | pVisManager->Draw(xyplate, att, trans); |
---|
| 342 | pVisManager->Draw(xyplate, att, trans2); |
---|
| 343 | |
---|
| 344 | } |
---|
| 345 | } |
---|
| 346 | } |
---|
| 347 | axflg = axflg%100; |
---|
| 348 | if(axflg/10==1) { |
---|
| 349 | // yz plane |
---|
[850] | 350 | if(colorMap->IfFloatMinMax()) { colorMap->SetMinMax(yzmin, yzmax); } |
---|
[814] | 351 | G4ThreeVector xhalf(fSize[0]/fNSegment[0]*0.98, 0., 0.); |
---|
| 352 | G4Box yzplate("yz", fSize[0]/fNSegment[0]*0.01, fSize[1]/fNSegment[1], fSize[2]/fNSegment[2]); |
---|
| 353 | for(int y = 0; y < fNSegment[1]; y++) { |
---|
| 354 | for(int z = 0; z < fNSegment[2]; z++) { |
---|
| 355 | G4ThreeVector pos(GetReplicaPosition(0, y, z) - xhalf); |
---|
| 356 | G4ThreeVector pos2(GetReplicaPosition(fNSegment[0]-1, y, z) + xhalf); |
---|
| 357 | G4Transform3D trans, trans2; |
---|
| 358 | if(fRotationMatrix) { |
---|
| 359 | trans = G4Rotate3D(*fRotationMatrix).inverse()*G4Translate3D(pos); |
---|
| 360 | trans = G4Translate3D(fCenterPosition)*trans; |
---|
| 361 | trans2 = G4Rotate3D(*fRotationMatrix).inverse()*G4Translate3D(pos2); |
---|
| 362 | trans2 = G4Translate3D(fCenterPosition)*trans2; |
---|
| 363 | } else { |
---|
| 364 | trans = G4Translate3D(pos)*G4Translate3D(fCenterPosition); |
---|
| 365 | trans2 = G4Translate3D(pos2)*G4Translate3D(fCenterPosition); |
---|
| 366 | } |
---|
| 367 | G4double c[4]; |
---|
| 368 | colorMap->GetMapColor(yzcell[y][z], c); |
---|
| 369 | att.SetColour(c[0], c[1], c[2]);//, c[3]); |
---|
| 370 | pVisManager->Draw(yzplate, att, trans); |
---|
| 371 | pVisManager->Draw(yzplate, att, trans2); |
---|
| 372 | |
---|
| 373 | } |
---|
| 374 | } |
---|
| 375 | } |
---|
| 376 | axflg = axflg%10; |
---|
| 377 | if(axflg==1) { |
---|
| 378 | // xz plane |
---|
[850] | 379 | if(colorMap->IfFloatMinMax()) { colorMap->SetMinMax(xzmin,xzmax); } |
---|
[814] | 380 | G4ThreeVector yhalf(0., fSize[1]/fNSegment[1]*0.98, 0.); |
---|
| 381 | G4Box xzplate("xz", fSize[0]/fNSegment[0], fSize[1]/fNSegment[1]*0.01, fSize[2]/fNSegment[2]); |
---|
| 382 | for(int x = 0; x < fNSegment[0]; x++) { |
---|
| 383 | for(int z = 0; z < fNSegment[2]; z++) { |
---|
| 384 | G4ThreeVector pos(GetReplicaPosition(x, 0, z) - yhalf); |
---|
| 385 | G4ThreeVector pos2(GetReplicaPosition(x, fNSegment[1]-1, z) + yhalf); |
---|
| 386 | G4Transform3D trans, trans2; |
---|
| 387 | if(fRotationMatrix) { |
---|
| 388 | trans = G4Rotate3D(*fRotationMatrix).inverse()*G4Translate3D(pos); |
---|
| 389 | trans = G4Translate3D(fCenterPosition)*trans; |
---|
| 390 | trans2 = G4Rotate3D(*fRotationMatrix).inverse()*G4Translate3D(pos2); |
---|
| 391 | trans2 = G4Translate3D(fCenterPosition)*trans2; |
---|
| 392 | } else { |
---|
| 393 | trans = G4Translate3D(pos)*G4Translate3D(fCenterPosition); |
---|
| 394 | trans2 = G4Translate3D(pos2)*G4Translate3D(fCenterPosition); |
---|
| 395 | } |
---|
| 396 | G4double c[4]; |
---|
| 397 | colorMap->GetMapColor(xzcell[x][z], c); |
---|
| 398 | att.SetColour(c[0], c[1], c[2]);//, c[3]); |
---|
| 399 | pVisManager->Draw(xzplate, att, trans); |
---|
| 400 | pVisManager->Draw(xzplate, att, trans2); |
---|
| 401 | |
---|
| 402 | } |
---|
| 403 | } |
---|
| 404 | } |
---|
| 405 | } |
---|
[850] | 406 | colorMap->DrawColorChart(); |
---|
[814] | 407 | } |
---|
| 408 | |
---|
| 409 | G4ThreeVector G4ScoringBox::GetReplicaPosition(G4int x, G4int y, G4int z) { |
---|
| 410 | |
---|
| 411 | G4ThreeVector width(fSize[0]/fNSegment[0], fSize[1]/fNSegment[1], fSize[2]/fNSegment[2]); |
---|
| 412 | G4ThreeVector pos(-fSize[0] + 2*(x+0.5)*width.x(), |
---|
| 413 | -fSize[1] + 2*(y+0.5)*width.y(), |
---|
| 414 | -fSize[2] + 2*(z+0.5)*width.z()); |
---|
| 415 | |
---|
| 416 | return pos; |
---|
| 417 | } |
---|
| 418 | |
---|
| 419 | void G4ScoringBox::GetXYZ(G4int index, G4int q[3]) const { |
---|
| 420 | |
---|
| 421 | q[0] = index/(fNSegment[2]*fNSegment[1]); |
---|
| 422 | q[1] = (index - q[0]*fNSegment[2]*fNSegment[1])/fNSegment[2]; |
---|
| 423 | q[2] = index - q[1]*fNSegment[2] - q[0]*fNSegment[2]*fNSegment[1]; |
---|
| 424 | |
---|
| 425 | } |
---|
| 426 | |
---|
| 427 | G4int G4ScoringBox::GetIndex(G4int x, G4int y, G4int z) const { |
---|
| 428 | return x + y*fNSegment[0] + z*fNSegment[0]*fNSegment[1]; |
---|
| 429 | } |
---|
| 430 | |
---|
| 431 | void G4ScoringBox::DrawColumn(std::map<G4int, G4double*> * map, G4VScoreColorMap* colorMap, |
---|
| 432 | G4int idxProj, G4int idxColumn) |
---|
| 433 | { |
---|
| 434 | if(idxColumn<0 || idxColumn>=fNSegment[idxProj]) |
---|
| 435 | { |
---|
| 436 | G4cerr << "ERROR : Column number " << idxColumn << " is out of scoring mesh [0," << fNSegment[idxProj]-1 << |
---|
| 437 | "]. Method ignored." << G4endl; |
---|
| 438 | return; |
---|
| 439 | } |
---|
| 440 | G4VVisManager * pVisManager = G4VVisManager::GetConcreteInstance(); |
---|
| 441 | if(pVisManager) { |
---|
| 442 | |
---|
| 443 | // cell vectors |
---|
| 444 | std::vector<std::vector<std::vector<double> > > cell; // cell[X][Y][Z] |
---|
| 445 | std::vector<double> ez; |
---|
| 446 | for(int z = 0; z < fNSegment[2]; z++) ez.push_back(0.); |
---|
| 447 | std::vector<std::vector<double> > eyz; |
---|
| 448 | for(int y = 0; y < fNSegment[1]; y++) eyz.push_back(ez); |
---|
| 449 | for(int x = 0; x < fNSegment[0]; x++) cell.push_back(eyz); |
---|
| 450 | |
---|
| 451 | std::vector<std::vector<double> > xycell; // xycell[X][Y] |
---|
| 452 | std::vector<double> ey; |
---|
| 453 | for(int y = 0; y < fNSegment[1]; y++) ey.push_back(0.); |
---|
| 454 | for(int x = 0; x < fNSegment[0]; x++) xycell.push_back(ey); |
---|
| 455 | |
---|
| 456 | std::vector<std::vector<double> > yzcell; // yzcell[Y][Z] |
---|
| 457 | for(int y = 0; y < fNSegment[1]; y++) yzcell.push_back(ez); |
---|
| 458 | |
---|
| 459 | std::vector<std::vector<double> > xzcell; // xzcell[X][Z] |
---|
| 460 | for(int x = 0; x < fNSegment[0]; x++) xzcell.push_back(ez); |
---|
| 461 | |
---|
| 462 | G4double xymax = 0., yzmax = 0., xzmax = 0.; |
---|
| 463 | G4int q[3]; |
---|
| 464 | std::map<G4int, G4double*>::iterator itr = map->begin(); |
---|
| 465 | for(; itr != map->end(); itr++) { |
---|
| 466 | GetXYZ(itr->first, q); |
---|
| 467 | |
---|
| 468 | if(idxProj == 0 && q[2] == idxColumn) { // xy plane |
---|
| 469 | xycell[q[0]][q[1]] += *(itr->second); |
---|
| 470 | if(xymax < xycell[q[0]][q[1]]) xymax = xycell[q[0]][q[1]]; |
---|
| 471 | } |
---|
| 472 | if(idxProj == 1 && q[0] == idxColumn) { // yz plane |
---|
| 473 | yzcell[q[1]][q[2]] += *(itr->second); |
---|
| 474 | if(yzmax < yzcell[q[1]][q[2]]) yzmax = yzcell[q[1]][q[2]]; |
---|
| 475 | } |
---|
| 476 | if(idxProj == 2 && q[1] == idxColumn) { // zx plane |
---|
| 477 | xzcell[q[0]][q[2]] += *(itr->second); |
---|
| 478 | if(xzmax < xzcell[q[0]][q[2]]) xzmax = xzcell[q[0]][q[2]]; |
---|
| 479 | } |
---|
| 480 | } |
---|
| 481 | |
---|
| 482 | G4VisAttributes att; |
---|
| 483 | att.SetForceSolid(true); |
---|
| 484 | att.SetForceAuxEdgeVisible(true); |
---|
| 485 | |
---|
| 486 | |
---|
| 487 | G4Scale3D scale; |
---|
| 488 | // xy plane |
---|
| 489 | if(idxProj == 0) { |
---|
| 490 | if(colorMap->IfFloatMinMax()) { colorMap->SetMinMax(0.,xymax); } |
---|
| 491 | G4Box xyplate("xy", fSize[0]/fNSegment[0], fSize[1]/fNSegment[1], fSize[2]/fNSegment[2]); |
---|
| 492 | for(int x = 0; x < fNSegment[0]; x++) { |
---|
| 493 | for(int y = 0; y < fNSegment[1]; y++) { |
---|
| 494 | G4ThreeVector pos(GetReplicaPosition(x, y, idxColumn)); |
---|
| 495 | G4Transform3D trans; |
---|
| 496 | if(fRotationMatrix) { |
---|
| 497 | trans = G4Rotate3D(*fRotationMatrix).inverse()*G4Translate3D(pos); |
---|
| 498 | trans = G4Translate3D(fCenterPosition)*trans; |
---|
| 499 | } else { |
---|
| 500 | trans = G4Translate3D(pos)*G4Translate3D(fCenterPosition); |
---|
| 501 | } |
---|
| 502 | G4double c[4]; |
---|
| 503 | colorMap->GetMapColor(xycell[x][y], c); |
---|
| 504 | att.SetColour(c[0], c[1], c[2]);//, c[3]); |
---|
| 505 | pVisManager->Draw(xyplate, att, trans); |
---|
| 506 | |
---|
| 507 | } |
---|
| 508 | } |
---|
| 509 | } else |
---|
| 510 | // yz plane |
---|
| 511 | if(idxProj == 1) { |
---|
| 512 | if(colorMap->IfFloatMinMax()) { colorMap->SetMinMax(0.,yzmax); } |
---|
| 513 | G4Box yzplate("yz", fSize[0]/fNSegment[0], fSize[1]/fNSegment[1], fSize[2]/fNSegment[2]); |
---|
| 514 | for(int y = 0; y < fNSegment[1]; y++) { |
---|
| 515 | for(int z = 0; z < fNSegment[2]; z++) { |
---|
| 516 | G4ThreeVector pos(GetReplicaPosition(idxColumn, y, z)); |
---|
| 517 | G4Transform3D trans; |
---|
| 518 | if(fRotationMatrix) { |
---|
| 519 | trans = G4Rotate3D(*fRotationMatrix).inverse()*G4Translate3D(pos); |
---|
| 520 | trans = G4Translate3D(fCenterPosition)*trans; |
---|
| 521 | } else { |
---|
| 522 | trans = G4Translate3D(pos)*G4Translate3D(fCenterPosition); |
---|
| 523 | } |
---|
| 524 | G4double c[4]; |
---|
| 525 | colorMap->GetMapColor(yzcell[y][z], c); |
---|
| 526 | att.SetColour(c[0], c[1], c[2]);//, c[3]); |
---|
| 527 | pVisManager->Draw(yzplate, att, trans); |
---|
| 528 | } |
---|
| 529 | } |
---|
| 530 | } else |
---|
| 531 | // xz plane |
---|
| 532 | if(idxProj == 2) { |
---|
| 533 | if(colorMap->IfFloatMinMax()) { colorMap->SetMinMax(0.,xzmax);} |
---|
| 534 | G4Box xzplate("xz", fSize[0]/fNSegment[0], fSize[1]/fNSegment[1], fSize[2]/fNSegment[2]); |
---|
| 535 | for(int x = 0; x < fNSegment[0]; x++) { |
---|
| 536 | for(int z = 0; z < fNSegment[2]; z++) { |
---|
| 537 | G4ThreeVector pos(GetReplicaPosition(x, idxColumn, z)); |
---|
| 538 | G4Transform3D trans; |
---|
| 539 | if(fRotationMatrix) { |
---|
| 540 | trans = G4Rotate3D(*fRotationMatrix).inverse()*G4Translate3D(pos); |
---|
| 541 | trans = G4Translate3D(fCenterPosition)*trans; |
---|
| 542 | } else { |
---|
| 543 | trans = G4Translate3D(pos)*G4Translate3D(fCenterPosition); |
---|
| 544 | } |
---|
| 545 | G4double c[4]; |
---|
| 546 | colorMap->GetMapColor(xzcell[x][z], c); |
---|
| 547 | att.SetColour(c[0], c[1], c[2]);//, c[3]); |
---|
| 548 | pVisManager->Draw(xzplate, att, trans); |
---|
| 549 | } |
---|
| 550 | } |
---|
| 551 | } |
---|
| 552 | } |
---|
[850] | 553 | |
---|
| 554 | colorMap->DrawColorChart(); |
---|
[814] | 555 | } |
---|
| 556 | |
---|
| 557 | |
---|