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