Geant4-11
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4VScoringMesh.cc
Go to the documentation of this file.
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//
28// ---------------------------------------------------------------------
29// Modifications
30// 17-Apr-2012 T.Aso SetSize() and SetNumberOfSegments() is not allowed
31// to call twice in same geometrical mesh. Add warning
32// message to notify.
33//
34// ---------------------------------------------------------------------
35
36#include "G4VScoringMesh.hh"
37#include "G4THitsMap.hh"
38#include "G4SystemOfUnits.hh"
39#include "G4VPhysicalVolume.hh"
41#include "G4VPrimitiveScorer.hh"
42#include "G4VSDFilter.hh"
43#include "G4SDManager.hh"
44
46 : fWorldName(wName)
47 , fCurrentPS(nullptr)
48 , fConstructed(false)
49 , fActive(true)
50 , fShape(MeshShape::undefined)
51 , fRotationMatrix(nullptr)
52 , fMFD(new G4MultiFunctionalDetector(wName))
53 , verboseLevel(0)
54 , sizeIsSet(false)
55 , nMeshIsSet(false)
56 , fDrawUnit("")
57 , fDrawUnitValue(1.)
58 , fMeshElementLogical(nullptr)
59 , fParallelWorldProcess(nullptr)
60 , fGeometryHasBeenDestroyed(false)
61 , copyNumberLevel(0)
62 , layeredMassFlg(false)
63{
65
66 fSize[0] = fSize[1] = fSize[2] = 0.;
67 fAngle[0] = 0.0;
68 fAngle[1] = CLHEP::twopi * rad;
69 fNSegment[0] = fNSegment[1] = fNSegment[2] = 1;
71}
72
74
76{
77 if(verboseLevel > 9)
78 G4cout << "G4VScoringMesh::ResetScore() is called." << G4endl;
79 for(auto mp : fMap)
80 {
81 if(verboseLevel > 9)
82 G4cout << "G4VScoringMesh::ResetScore()" << mp.first << G4endl;
83 mp.second->clear();
84 }
85}
86
88{
89 if(!sizeIsSet)
90 {
91 sizeIsSet = true;
92 for(int i = 0; i < 3; i++)
93 {
94 fSize[i] = size[i];
95 }
96 }
97 else
98 {
99 G4String message = " Mesh size has already been set and it cannot be changed.\n";
100 message += " This method is ignored.";
101 G4Exception("G4VScoringMesh::SetSize()",
102 "DigiHitsUtilsScoreVScoringMesh000", JustWarning, message);
103 }
104}
106{
107 if(sizeIsSet)
108 return G4ThreeVector(fSize[0], fSize[1], fSize[2]);
109 else
110 return G4ThreeVector(0., 0., 0.);
111}
112void G4VScoringMesh::SetAngles(G4double startAngle, G4double spanAngle)
113{
114 fAngle[0] = startAngle;
115 fAngle[1] = spanAngle;
116}
117
119{
121 G4ThreeVector(centerPosition[0], centerPosition[1], centerPosition[2]);
122}
124{
127 {
128 for(int i = 0; i < 3; i++)
129 fNSegment[i] = nSegment[i];
130 nMeshIsSet = true;
131 }
132 else
133 {
134 G4String message = " Number of bins has already been set and it cannot be changed.\n";
135 message += " This method is ignored.";
136 G4Exception("G4VScoringMesh::SetNumberOfSegments()",
137 "DigiHitsUtilsScoreVScoringMesh000", JustWarning, message);
138 }
139}
141{
142 for(int i = 0; i < 3; i++)
143 nSegment[i] = fNSegment[i];
144}
146{
147 if(!fRotationMatrix)
149 fRotationMatrix->rotateX(delta);
150}
151
153{
154 if(!fRotationMatrix)
156 fRotationMatrix->rotateY(delta);
157}
158
160{
161 if(!fRotationMatrix)
163 fRotationMatrix->rotateZ(delta);
164}
165
167{
168 if(!ReadyForQuantity())
169 {
170 G4cerr << "ERROR : G4VScoringMesh::SetPrimitiveScorer() : "
171 << prs->GetName()
172 << " does not yet have mesh size or number of bins. Set them first."
173 << G4endl << "This Method is ignored." << G4endl;
174 return;
175 }
176 if(verboseLevel > 0)
177 G4cout << "G4VScoringMesh::SetPrimitiveScorer() : " << prs->GetName()
178 << " is registered."
179 << " 3D size: (" << fNSegment[0] << ", " << fNSegment[1] << ", "
180 << fNSegment[2] << ")" << G4endl;
181
182 prs->SetNijk(fNSegment[0], fNSegment[1], fNSegment[2]);
183 fCurrentPS = prs;
187 fMap[prs->GetName()] = map;
188}
189
191{
192 if(!fCurrentPS)
193 {
194 G4cerr << "ERROR : G4VScoringMesh::SetSDFilter() : a quantity must be "
195 "defined first. This method is ignored."
196 << G4endl;
197 return;
198 }
199 if(verboseLevel > 0)
200 G4cout << "G4VScoringMesh::SetFilter() : " << filter->GetName()
201 << " is set to " << fCurrentPS->GetName() << G4endl;
202
203 G4VSDFilter* oldFilter = fCurrentPS->GetFilter();
204 if(oldFilter)
205 {
206 G4cout << "WARNING : G4VScoringMesh::SetFilter() : " << oldFilter->GetName()
207 << " is overwritten by " << filter->GetName() << G4endl;
208 }
209 fCurrentPS->SetFilter(filter);
210}
211
213{
215 if(!fCurrentPS)
216 {
217 G4cerr << "ERROR : G4VScoringMesh::SetCurrentPrimitiveScorer() : The "
218 "primitive scorer <"
219 << name << "> does not found." << G4endl;
220 }
221}
222
224{
225 MeshScoreMap::iterator itr = fMap.find(psname);
226 if(itr == fMap.end())
227 return false;
228 return true;
229}
230
232{
233 MeshScoreMap::iterator itr = fMap.find(psname);
234 if(itr == fMap.end())
235 {
236 return G4String("");
237 }
238 else
239 {
240 return GetPrimitiveScorer(psname)->GetUnit();
241 }
242}
243
245{
246 G4String unit = "";
247 if(!fCurrentPS)
248 {
249 G4String msg = "ERROR : G4VScoringMesh::GetCurrentPSUnit() : ";
250 msg += " Current primitive scorer is null.";
251 G4cerr << msg << G4endl;
252 }
253 else
254 {
255 unit = fCurrentPS->GetUnit();
256 }
257 return unit;
258}
259
261{
262 if(!fCurrentPS)
263 {
264 G4String msg = "ERROR : G4VScoringMesh::GetCurrentPSUnit() : ";
265 msg += " Current primitive scorer is null.";
266 G4cerr << msg << G4endl;
267 }
268 else
269 {
270 fCurrentPS->SetUnit(unit);
271 }
272}
273
275{
276 MeshScoreMap::iterator itr = fMap.find(psname);
277 if(itr == fMap.end())
278 {
279 return 1.;
280 }
281 else
282 {
283 return GetPrimitiveScorer(psname)->GetUnitValue();
284 }
285}
286
288{
289 for(int i = 0; i < 3; i++)
290 divisionAxisNames[i] = fDivisionAxisNames[i];
291}
292
294{
295 if(!fMFD)
296 return nullptr;
297
299 for(G4int i = 0; i < nps; i++)
300 {
302 if(name == prs->GetName())
303 return prs;
304 }
305
306 return nullptr;
307}
309{
310 G4cout << " # of segments: (" << fNSegment[0] << ", " << fNSegment[1] << ", "
311 << fNSegment[2] << ")" << G4endl;
312 G4cout << " displacement: (" << fCenterPosition.x() / cm << ", "
313 << fCenterPosition.y() / cm << ", " << fCenterPosition.z() / cm
314 << ") [cm]" << G4endl;
315 if(fRotationMatrix != 0)
316 {
317 G4cout << " rotation matrix: " << fRotationMatrix->xx() << " "
318 << fRotationMatrix->xy() << " " << fRotationMatrix->xz() << G4endl
319 << " " << fRotationMatrix->yx() << " "
320 << fRotationMatrix->yy() << " " << fRotationMatrix->yz() << G4endl
321 << " " << fRotationMatrix->zx() << " "
322 << fRotationMatrix->zy() << " " << fRotationMatrix->zz() << G4endl;
323 }
324
325 G4cout << " registered primitve scorers : " << G4endl;
328 for(int i = 0; i < nps; i++)
329 {
330 prs = fMFD->GetPrimitive(i);
331 G4cout << " " << i << " " << prs->GetName();
332 if(prs->GetFilter() != 0)
333 G4cout << " with " << prs->GetFilter()->GetName();
334 G4cout << G4endl;
335 }
336}
337
339{
340 G4cout << "scoring mesh name: " << fWorldName << G4endl;
341 G4cout << "# of G4THitsMap : " << fMap.size() << G4endl;
342 for(auto mp : fMap)
343 {
344 G4cout << "[" << mp.first << "]" << G4endl;
345 mp.second->PrintAllHits();
346 }
347 G4cout << G4endl;
348}
349
351 G4VScoreColorMap* colorMap, G4int axflg)
352{
353 fDrawPSName = psName;
354 MeshScoreMap::const_iterator fMapItr = fMap.find(psName);
355 if(fMapItr != fMap.end())
356 {
357 fDrawUnit = GetPSUnit(psName);
359 Draw(fMapItr->second, colorMap, axflg);
360 }
361 else
362 {
363 G4cerr << "Scorer <" << psName << "> is not defined. Method ignored."
364 << G4endl;
365 }
366}
367
368void G4VScoringMesh::DrawMesh(const G4String& psName, G4int idxPlane,
369 G4int iColumn, G4VScoreColorMap* colorMap)
370{
371 fDrawPSName = psName;
372 MeshScoreMap::const_iterator fMapItr = fMap.find(psName);
373 if(fMapItr != fMap.end())
374 {
375 fDrawUnit = GetPSUnit(psName);
377 DrawColumn(fMapItr->second, colorMap, idxPlane, iColumn);
378 }
379 else
380 {
381 G4cerr << "Scorer <" << psName << "> is not defined. Method ignored."
382 << G4endl;
383 }
384}
385
387{
388 G4String psName = map->GetName();
389 MeshScoreMap::const_iterator fMapItr = fMap.find(psName);
390 *(fMapItr->second) += *map;
391
392 if(verboseLevel > 9)
393 {
394 G4cout << G4endl;
395 G4cout << "G4VScoringMesh::Accumulate()" << G4endl;
396 G4cout << " PS name : " << psName << G4endl;
397 if(fMapItr == fMap.end())
398 {
399 G4cout << " " << psName << " was not found." << G4endl;
400 }
401 else
402 {
403 G4cout << " map size : " << map->GetSize() << G4endl;
404 map->PrintAllHits();
405 }
406 G4cout << G4endl;
407 }
408}
409
411{
412 G4String psName = map->GetName();
413 MeshScoreMap::const_iterator fMapItr = fMap.find(psName);
414 *(fMapItr->second) += *map;
415
416 if(verboseLevel > 9)
417 {
418 G4cout << G4endl;
419 G4cout << "G4VScoringMesh::Accumulate()" << G4endl;
420 G4cout << " PS name : " << psName << G4endl;
421 if(fMapItr == fMap.end())
422 {
423 G4cout << " " << psName << " was not found." << G4endl;
424 }
425 else
426 {
427 G4cout << " map size : " << map->GetSize() << G4endl;
428 map->PrintAllHits();
429 }
430 G4cout << G4endl;
431 }
432}
433
435{
436 if(fConstructed)
437 {
439 {
440 SetupGeometry(fWorldPhys);
442 }
443 if(verboseLevel > 0)
444 G4cout << fWorldName << " --- All quantities are reset." << G4endl;
445 ResetScore();
446 }
447 else
448 {
449 fConstructed = true;
450 SetupGeometry(fWorldPhys);
451 }
452}
453
455{
456 if(fConstructed)
457 {
459 {
462 }
463
464 if(verboseLevel > 0)
465 G4cout << fWorldPhys->GetName() << " --- All quantities are reset."
466 << G4endl;
467 ResetScore();
468 }
469 else
470 {
471 fConstructed = true;
473 }
474}
475
477{
478 const MeshScoreMap scMap = scMesh->GetScoreMap();
479
480 MeshScoreMap::const_iterator fMapItr = fMap.begin();
481 MeshScoreMap::const_iterator mapItr = scMap.begin();
482 for(; fMapItr != fMap.end(); fMapItr++)
483 {
484 if(verboseLevel > 9)
485 G4cout << "G4VScoringMesh::Merge()" << fMapItr->first << G4endl;
486 *(fMapItr->second) += *(mapItr->second);
487 mapItr++;
488 }
489}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
CLHEP::HepRotation G4RotationMatrix
static constexpr double rad
Definition: G4SIunits.hh:129
static constexpr double cm
Definition: G4SIunits.hh:99
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
double z() const
double x() const
double y() const
double zz() const
double yz() const
double zx() const
double yx() const
double zy() const
double xx() const
HepRotation & rotateX(double delta)
Definition: Rotation.cc:61
HepRotation & rotateZ(double delta)
Definition: Rotation.cc:87
double yy() const
double xz() const
HepRotation & rotateY(double delta)
Definition: Rotation.cc:74
double xy() const
void SetSensitiveDetector(G4VSensitiveDetector *pSDetector)
G4bool RegisterPrimitive(G4VPrimitiveScorer *)
G4VPrimitiveScorer * GetPrimitive(G4int id) const
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:38
void AddNewDetector(G4VSensitiveDetector *aSD)
Definition: G4SDManager.cc:70
const G4String & GetName() const
void SetUnit(const G4String &unit)
G4VSDFilter * GetFilter() const
void SetNijk(G4int i, G4int j, G4int k)
void SetFilter(G4VSDFilter *f)
G4String GetName() const
const G4String & GetUnit() const
G4double GetUnitValue() const
G4String GetName() const
Definition: G4VSDFilter.hh:55
void SetFilter(G4VSDFilter *filter)
G4bool ReadyForQuantity() const
G4RotationMatrix * fRotationMatrix
G4ThreeVector GetSize() const
virtual void SetupGeometry(G4VPhysicalVolume *fWorldPhys)=0
virtual void List() const
G4double fDrawUnitValue
virtual void WorkerConstruct(G4VPhysicalVolume *fWorldPhys)
G4String fDrawPSName
G4bool fGeometryHasBeenDestroyed
MeshScoreMap fMap
void RotateY(G4double delta)
void GetNumberOfSegments(G4int nSegment[3])
G4double GetPSUnitValue(const G4String &psname)
G4String GetPSUnit(const G4String &psname)
void SetAngles(G4double, G4double)
void SetCurrentPSUnit(const G4String &unit)
G4MultiFunctionalDetector * fMFD
void SetCurrentPrimitiveScorer(const G4String &name)
G4String fDivisionAxisNames[3]
G4LogicalVolume * fMeshElementLogical
void SetPrimitiveScorer(G4VPrimitiveScorer *ps)
std::map< G4String, RunScore * > MeshScoreMap
G4VPrimitiveScorer * fCurrentPS
G4double fAngle[2]
G4String GetCurrentPSUnit()
void GetDivisionAxisNames(G4String divisionAxisNames[3])
void DrawMesh(const G4String &psName, G4VScoreColorMap *colorMap, G4int axflg=111)
void Accumulate(G4THitsMap< G4double > *map)
void SetNumberOfSegments(G4int nSegment[3])
G4double fSize[3]
G4VScoringMesh(const G4String &wName)
MeshScoreMap GetScoreMap() const
void Merge(const G4VScoringMesh *scMesh)
virtual ~G4VScoringMesh()
virtual void Draw(RunScore *map, G4VScoreColorMap *colorMap, G4int axflg=111)=0
void SetCenterPosition(G4double centerPosition[3])
void RotateX(G4double delta)
virtual void Construct(G4VPhysicalVolume *fWorldPhys)
void SetSize(G4double size[3])
virtual void DrawColumn(RunScore *map, G4VScoreColorMap *colorMap, G4int idxProj, G4int idxColumn)=0
G4bool FindPrimitiveScorer(const G4String &psname)
void RotateZ(G4double delta)
G4VPrimitiveScorer * GetPrimitiveScorer(const G4String &name)
G4ThreeVector fCenterPosition
static constexpr double twopi
Definition: SystemOfUnits.h:56
const char * name(G4int ptype)