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: G4ScoringBox.cc,v 1.48 2007/11/14 20:41:17 asaim Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-01-patch-02 $ |
---|
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 | |
---|
108 | // fisrt nested layer (replicated to x direction) |
---|
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, |
---|
125 | fNSegment[0], fSize[0]/fNSegment[0]*2.); |
---|
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, |
---|
161 | fNSegment[1], fSize[1]/fNSegment[1]*2.); |
---|
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, |
---|
224 | fNSegment[2], 2.*fSize[2]/fNSegment[2]); |
---|
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; |
---|
261 | |
---|
262 | G4VScoringMesh::List(); |
---|
263 | } |
---|
264 | |
---|
265 | void G4ScoringBox::Draw(std::map<G4int, G4double*> * map, G4VScoreColorMap* colorMap, G4int axflg) { |
---|
266 | |
---|
267 | G4VVisManager * pVisManager = G4VVisManager::GetConcreteInstance(); |
---|
268 | if(pVisManager) { |
---|
269 | |
---|
270 | // cell vectors |
---|
271 | std::vector<std::vector<std::vector<double> > > cell; // cell[X][Y][Z] |
---|
272 | std::vector<double> ez; |
---|
273 | for(int z = 0; z < fNSegment[2]; z++) ez.push_back(0.); |
---|
274 | std::vector<std::vector<double> > eyz; |
---|
275 | for(int y = 0; y < fNSegment[1]; y++) eyz.push_back(ez); |
---|
276 | for(int x = 0; x < fNSegment[0]; x++) cell.push_back(eyz); |
---|
277 | |
---|
278 | std::vector<std::vector<double> > xycell; // xycell[X][Y] |
---|
279 | std::vector<double> ey; |
---|
280 | for(int y = 0; y < fNSegment[1]; y++) ey.push_back(0.); |
---|
281 | for(int x = 0; x < fNSegment[0]; x++) xycell.push_back(ey); |
---|
282 | |
---|
283 | std::vector<std::vector<double> > yzcell; // yzcell[Y][Z] |
---|
284 | for(int y = 0; y < fNSegment[1]; y++) yzcell.push_back(ez); |
---|
285 | |
---|
286 | std::vector<std::vector<double> > xzcell; // xzcell[X][Z] |
---|
287 | for(int x = 0; x < fNSegment[0]; x++) xzcell.push_back(ez); |
---|
288 | |
---|
289 | G4double xymax = 0., yzmax = 0., xzmax = 0.; |
---|
290 | G4int q[3]; |
---|
291 | std::map<G4int, G4double*>::iterator itr = map->begin(); |
---|
292 | for(; itr != map->end(); itr++) { |
---|
293 | GetXYZ(itr->first, q); |
---|
294 | |
---|
295 | xycell[q[0]][q[1]] += *(itr->second); |
---|
296 | if(xymax < xycell[q[0]][q[1]]) xymax = xycell[q[0]][q[1]]; |
---|
297 | |
---|
298 | yzcell[q[1]][q[2]] += *(itr->second); |
---|
299 | if(yzmax < yzcell[q[1]][q[2]]) yzmax = yzcell[q[1]][q[2]]; |
---|
300 | |
---|
301 | xzcell[q[0]][q[2]] += *(itr->second); |
---|
302 | if(xzmax < xzcell[q[0]][q[2]]) xzmax = xzcell[q[0]][q[2]]; |
---|
303 | } |
---|
304 | |
---|
305 | G4VisAttributes att; |
---|
306 | att.SetForceSolid(true); |
---|
307 | att.SetForceAuxEdgeVisible(true); |
---|
308 | |
---|
309 | |
---|
310 | G4Scale3D scale; |
---|
311 | if(axflg/100==1) { |
---|
312 | // xy plane |
---|
313 | if(colorMap->IfFloatMinMax()) { colorMap->SetMinMax(0.,xymax); } |
---|
314 | G4ThreeVector zhalf(0., 0., fSize[2]/fNSegment[2]*0.98); |
---|
315 | G4Box xyplate("xy", fSize[0]/fNSegment[0], fSize[1]/fNSegment[1], fSize[2]/fNSegment[2]*0.01); |
---|
316 | for(int x = 0; x < fNSegment[0]; x++) { |
---|
317 | for(int y = 0; y < fNSegment[1]; y++) { |
---|
318 | G4ThreeVector pos(GetReplicaPosition(x, y, 0) - zhalf); |
---|
319 | G4ThreeVector pos2(GetReplicaPosition(x, y, fNSegment[2]-1) + zhalf); |
---|
320 | G4Transform3D trans, trans2; |
---|
321 | if(fRotationMatrix) { |
---|
322 | trans = G4Rotate3D(*fRotationMatrix).inverse()*G4Translate3D(pos); |
---|
323 | trans = G4Translate3D(fCenterPosition)*trans; |
---|
324 | trans2 = G4Rotate3D(*fRotationMatrix).inverse()*G4Translate3D(pos2); |
---|
325 | trans2 = G4Translate3D(fCenterPosition)*trans2; |
---|
326 | } else { |
---|
327 | trans = G4Translate3D(pos)*G4Translate3D(fCenterPosition); |
---|
328 | trans2 = G4Translate3D(pos2)*G4Translate3D(fCenterPosition); |
---|
329 | } |
---|
330 | G4double c[4]; |
---|
331 | colorMap->GetMapColor(xycell[x][y], c); |
---|
332 | att.SetColour(c[0], c[1], c[2]);//, c[3]); |
---|
333 | pVisManager->Draw(xyplate, att, trans); |
---|
334 | pVisManager->Draw(xyplate, att, trans2); |
---|
335 | |
---|
336 | } |
---|
337 | } |
---|
338 | } |
---|
339 | axflg = axflg%100; |
---|
340 | if(axflg/10==1) { |
---|
341 | // yz plane |
---|
342 | if(colorMap->IfFloatMinMax()) { colorMap->SetMinMax(0.,yzmax); } |
---|
343 | G4ThreeVector xhalf(fSize[0]/fNSegment[0]*0.98, 0., 0.); |
---|
344 | G4Box yzplate("yz", fSize[0]/fNSegment[0]*0.01, fSize[1]/fNSegment[1], fSize[2]/fNSegment[2]); |
---|
345 | for(int y = 0; y < fNSegment[1]; y++) { |
---|
346 | for(int z = 0; z < fNSegment[2]; z++) { |
---|
347 | G4ThreeVector pos(GetReplicaPosition(0, y, z) - xhalf); |
---|
348 | G4ThreeVector pos2(GetReplicaPosition(fNSegment[0]-1, y, z) + xhalf); |
---|
349 | G4Transform3D trans, trans2; |
---|
350 | if(fRotationMatrix) { |
---|
351 | trans = G4Rotate3D(*fRotationMatrix).inverse()*G4Translate3D(pos); |
---|
352 | trans = G4Translate3D(fCenterPosition)*trans; |
---|
353 | trans2 = G4Rotate3D(*fRotationMatrix).inverse()*G4Translate3D(pos2); |
---|
354 | trans2 = G4Translate3D(fCenterPosition)*trans2; |
---|
355 | } else { |
---|
356 | trans = G4Translate3D(pos)*G4Translate3D(fCenterPosition); |
---|
357 | trans2 = G4Translate3D(pos2)*G4Translate3D(fCenterPosition); |
---|
358 | } |
---|
359 | G4double c[4]; |
---|
360 | colorMap->GetMapColor(yzcell[y][z], c); |
---|
361 | att.SetColour(c[0], c[1], c[2]);//, c[3]); |
---|
362 | pVisManager->Draw(yzplate, att, trans); |
---|
363 | pVisManager->Draw(yzplate, att, trans2); |
---|
364 | |
---|
365 | } |
---|
366 | } |
---|
367 | } |
---|
368 | axflg = axflg%10; |
---|
369 | if(axflg==1) { |
---|
370 | // xz plane |
---|
371 | if(colorMap->IfFloatMinMax()) { colorMap->SetMinMax(0.,xzmax); } |
---|
372 | G4ThreeVector yhalf(0., fSize[1]/fNSegment[1]*0.98, 0.); |
---|
373 | G4Box xzplate("xz", fSize[0]/fNSegment[0], fSize[1]/fNSegment[1]*0.01, fSize[2]/fNSegment[2]); |
---|
374 | for(int x = 0; x < fNSegment[0]; x++) { |
---|
375 | for(int z = 0; z < fNSegment[2]; z++) { |
---|
376 | G4ThreeVector pos(GetReplicaPosition(x, 0, z) - yhalf); |
---|
377 | G4ThreeVector pos2(GetReplicaPosition(x, fNSegment[1]-1, z) + yhalf); |
---|
378 | G4Transform3D trans, trans2; |
---|
379 | if(fRotationMatrix) { |
---|
380 | trans = G4Rotate3D(*fRotationMatrix).inverse()*G4Translate3D(pos); |
---|
381 | trans = G4Translate3D(fCenterPosition)*trans; |
---|
382 | trans2 = G4Rotate3D(*fRotationMatrix).inverse()*G4Translate3D(pos2); |
---|
383 | trans2 = G4Translate3D(fCenterPosition)*trans2; |
---|
384 | } else { |
---|
385 | trans = G4Translate3D(pos)*G4Translate3D(fCenterPosition); |
---|
386 | trans2 = G4Translate3D(pos2)*G4Translate3D(fCenterPosition); |
---|
387 | } |
---|
388 | G4double c[4]; |
---|
389 | colorMap->GetMapColor(xzcell[x][z], c); |
---|
390 | att.SetColour(c[0], c[1], c[2]);//, c[3]); |
---|
391 | pVisManager->Draw(xzplate, att, trans); |
---|
392 | pVisManager->Draw(xzplate, att, trans2); |
---|
393 | |
---|
394 | } |
---|
395 | } |
---|
396 | } |
---|
397 | } |
---|
398 | } |
---|
399 | |
---|
400 | G4ThreeVector G4ScoringBox::GetReplicaPosition(G4int x, G4int y, G4int z) { |
---|
401 | |
---|
402 | G4ThreeVector width(fSize[0]/fNSegment[0], fSize[1]/fNSegment[1], fSize[2]/fNSegment[2]); |
---|
403 | G4ThreeVector pos(-fSize[0] + 2*(x+0.5)*width.x(), |
---|
404 | -fSize[1] + 2*(y+0.5)*width.y(), |
---|
405 | -fSize[2] + 2*(z+0.5)*width.z()); |
---|
406 | |
---|
407 | return pos; |
---|
408 | } |
---|
409 | |
---|
410 | void G4ScoringBox::GetXYZ(G4int index, G4int q[3]) const { |
---|
411 | |
---|
412 | q[0] = index/(fNSegment[2]*fNSegment[1]); |
---|
413 | q[1] = (index - q[0]*fNSegment[2]*fNSegment[1])/fNSegment[2]; |
---|
414 | q[2] = index - q[1]*fNSegment[2] - q[0]*fNSegment[2]*fNSegment[1]; |
---|
415 | |
---|
416 | } |
---|
417 | |
---|
418 | G4int G4ScoringBox::GetIndex(G4int x, G4int y, G4int z) const { |
---|
419 | return x + y*fNSegment[0] + z*fNSegment[0]*fNSegment[1]; |
---|
420 | } |
---|
421 | |
---|
422 | void G4ScoringBox::DrawColumn(std::map<G4int, G4double*> * map, G4VScoreColorMap* colorMap, |
---|
423 | G4int idxProj, G4int idxColumn) |
---|
424 | { |
---|
425 | if(idxColumn<0 || idxColumn>=fNSegment[idxProj]) |
---|
426 | { |
---|
427 | G4cerr << "ERROR : Column number " << idxColumn << " is out of scoring mesh [0," << fNSegment[idxProj]-1 << |
---|
428 | "]. Method ignored." << G4endl; |
---|
429 | return; |
---|
430 | } |
---|
431 | G4VVisManager * pVisManager = G4VVisManager::GetConcreteInstance(); |
---|
432 | if(pVisManager) { |
---|
433 | |
---|
434 | // cell vectors |
---|
435 | std::vector<std::vector<std::vector<double> > > cell; // cell[X][Y][Z] |
---|
436 | std::vector<double> ez; |
---|
437 | for(int z = 0; z < fNSegment[2]; z++) ez.push_back(0.); |
---|
438 | std::vector<std::vector<double> > eyz; |
---|
439 | for(int y = 0; y < fNSegment[1]; y++) eyz.push_back(ez); |
---|
440 | for(int x = 0; x < fNSegment[0]; x++) cell.push_back(eyz); |
---|
441 | |
---|
442 | std::vector<std::vector<double> > xycell; // xycell[X][Y] |
---|
443 | std::vector<double> ey; |
---|
444 | for(int y = 0; y < fNSegment[1]; y++) ey.push_back(0.); |
---|
445 | for(int x = 0; x < fNSegment[0]; x++) xycell.push_back(ey); |
---|
446 | |
---|
447 | std::vector<std::vector<double> > yzcell; // yzcell[Y][Z] |
---|
448 | for(int y = 0; y < fNSegment[1]; y++) yzcell.push_back(ez); |
---|
449 | |
---|
450 | std::vector<std::vector<double> > xzcell; // xzcell[X][Z] |
---|
451 | for(int x = 0; x < fNSegment[0]; x++) xzcell.push_back(ez); |
---|
452 | |
---|
453 | G4double xymax = 0., yzmax = 0., xzmax = 0.; |
---|
454 | G4int q[3]; |
---|
455 | std::map<G4int, G4double*>::iterator itr = map->begin(); |
---|
456 | for(; itr != map->end(); itr++) { |
---|
457 | GetXYZ(itr->first, q); |
---|
458 | |
---|
459 | if(idxProj == 0 && q[2] == idxColumn) { // xy plane |
---|
460 | xycell[q[0]][q[1]] += *(itr->second); |
---|
461 | if(xymax < xycell[q[0]][q[1]]) xymax = xycell[q[0]][q[1]]; |
---|
462 | } |
---|
463 | if(idxProj == 1 && q[0] == idxColumn) { // yz plane |
---|
464 | yzcell[q[1]][q[2]] += *(itr->second); |
---|
465 | if(yzmax < yzcell[q[1]][q[2]]) yzmax = yzcell[q[1]][q[2]]; |
---|
466 | } |
---|
467 | if(idxProj == 2 && q[1] == idxColumn) { // zx plane |
---|
468 | xzcell[q[0]][q[2]] += *(itr->second); |
---|
469 | if(xzmax < xzcell[q[0]][q[2]]) xzmax = xzcell[q[0]][q[2]]; |
---|
470 | } |
---|
471 | } |
---|
472 | |
---|
473 | G4VisAttributes att; |
---|
474 | att.SetForceSolid(true); |
---|
475 | att.SetForceAuxEdgeVisible(true); |
---|
476 | |
---|
477 | |
---|
478 | G4Scale3D scale; |
---|
479 | // xy plane |
---|
480 | if(idxProj == 0) { |
---|
481 | if(colorMap->IfFloatMinMax()) { colorMap->SetMinMax(0.,xymax); } |
---|
482 | G4Box xyplate("xy", fSize[0]/fNSegment[0], fSize[1]/fNSegment[1], fSize[2]/fNSegment[2]); |
---|
483 | for(int x = 0; x < fNSegment[0]; x++) { |
---|
484 | for(int y = 0; y < fNSegment[1]; y++) { |
---|
485 | G4ThreeVector pos(GetReplicaPosition(x, y, idxColumn)); |
---|
486 | G4Transform3D trans; |
---|
487 | if(fRotationMatrix) { |
---|
488 | trans = G4Rotate3D(*fRotationMatrix).inverse()*G4Translate3D(pos); |
---|
489 | trans = G4Translate3D(fCenterPosition)*trans; |
---|
490 | } else { |
---|
491 | trans = G4Translate3D(pos)*G4Translate3D(fCenterPosition); |
---|
492 | } |
---|
493 | G4double c[4]; |
---|
494 | colorMap->GetMapColor(xycell[x][y], c); |
---|
495 | att.SetColour(c[0], c[1], c[2]);//, c[3]); |
---|
496 | pVisManager->Draw(xyplate, att, trans); |
---|
497 | |
---|
498 | } |
---|
499 | } |
---|
500 | } else |
---|
501 | // yz plane |
---|
502 | if(idxProj == 1) { |
---|
503 | if(colorMap->IfFloatMinMax()) { colorMap->SetMinMax(0.,yzmax); } |
---|
504 | G4Box yzplate("yz", fSize[0]/fNSegment[0], fSize[1]/fNSegment[1], fSize[2]/fNSegment[2]); |
---|
505 | for(int y = 0; y < fNSegment[1]; y++) { |
---|
506 | for(int z = 0; z < fNSegment[2]; z++) { |
---|
507 | G4ThreeVector pos(GetReplicaPosition(idxColumn, y, z)); |
---|
508 | G4Transform3D trans; |
---|
509 | if(fRotationMatrix) { |
---|
510 | trans = G4Rotate3D(*fRotationMatrix).inverse()*G4Translate3D(pos); |
---|
511 | trans = G4Translate3D(fCenterPosition)*trans; |
---|
512 | } else { |
---|
513 | trans = G4Translate3D(pos)*G4Translate3D(fCenterPosition); |
---|
514 | } |
---|
515 | G4double c[4]; |
---|
516 | colorMap->GetMapColor(yzcell[y][z], c); |
---|
517 | att.SetColour(c[0], c[1], c[2]);//, c[3]); |
---|
518 | pVisManager->Draw(yzplate, att, trans); |
---|
519 | } |
---|
520 | } |
---|
521 | } else |
---|
522 | // xz plane |
---|
523 | if(idxProj == 2) { |
---|
524 | if(colorMap->IfFloatMinMax()) { colorMap->SetMinMax(0.,xzmax);} |
---|
525 | G4Box xzplate("xz", fSize[0]/fNSegment[0], fSize[1]/fNSegment[1], fSize[2]/fNSegment[2]); |
---|
526 | for(int x = 0; x < fNSegment[0]; x++) { |
---|
527 | for(int z = 0; z < fNSegment[2]; z++) { |
---|
528 | G4ThreeVector pos(GetReplicaPosition(x, idxColumn, z)); |
---|
529 | G4Transform3D trans; |
---|
530 | if(fRotationMatrix) { |
---|
531 | trans = G4Rotate3D(*fRotationMatrix).inverse()*G4Translate3D(pos); |
---|
532 | trans = G4Translate3D(fCenterPosition)*trans; |
---|
533 | } else { |
---|
534 | trans = G4Translate3D(pos)*G4Translate3D(fCenterPosition); |
---|
535 | } |
---|
536 | G4double c[4]; |
---|
537 | colorMap->GetMapColor(xzcell[x][z], c); |
---|
538 | att.SetColour(c[0], c[1], c[2]);//, c[3]); |
---|
539 | pVisManager->Draw(xzplate, att, trans); |
---|
540 | } |
---|
541 | } |
---|
542 | } |
---|
543 | } |
---|
544 | } |
---|
545 | |
---|
546 | |
---|