Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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{
75 if(verboseLevel > 9)
76 G4cout << "G4VScoringMesh::ResetScore() is called." << G4endl;
77 for(const auto& mp : fMap)
78 {
79 if(verboseLevel > 9)
80 G4cout << "G4VScoringMesh::ResetScore()" << mp.first << G4endl;
81 mp.second->clear();
82 }
83}
84
86{
87 if(!sizeIsSet)
88 {
89 sizeIsSet = true;
90 for(G4int i = 0; i < 3; ++i)
91 {
92 fSize[i] = size[i];
93 }
94 }
95 else
96 {
97 G4String message = " Mesh size has already been set and it cannot be changed.\n";
98 message += " This method is ignored.";
99 G4Exception("G4VScoringMesh::SetSize()",
100 "DigiHitsUtilsScoreVScoringMesh000", JustWarning, message);
101 }
102}
103
105{
106 if(sizeIsSet)
107 return G4ThreeVector(fSize[0], fSize[1], fSize[2]);
108 return G4ThreeVector(0., 0., 0.);
109}
110
111void G4VScoringMesh::SetAngles(G4double startAngle, G4double spanAngle)
112{
113 fAngle[0] = startAngle;
114 fAngle[1] = spanAngle;
115}
116
118{
120 G4ThreeVector(centerPosition[0], centerPosition[1], centerPosition[2]);
121}
122
124{
127 {
128 for(G4int 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}
140
142{
143 for(G4int i = 0; i < 3; ++i)
144 nSegment[i] = fNSegment[i];
145}
146
148{
149 if(fRotationMatrix == nullptr)
151 fRotationMatrix->rotateX(delta);
152}
153
155{
156 if(fRotationMatrix == nullptr)
158 fRotationMatrix->rotateY(delta);
159}
160
162{
163 if(fRotationMatrix == nullptr)
165 fRotationMatrix->rotateZ(delta);
166}
167
169{
170 if(!ReadyForQuantity())
171 {
172 G4cerr << "ERROR : G4VScoringMesh::SetPrimitiveScorer() : "
173 << prs->GetName()
174 << " does not yet have mesh size or number of bins. Set them first."
175 << G4endl << "This Method is ignored." << G4endl;
176 return;
177 }
178 if(verboseLevel > 0)
179 G4cout << "G4VScoringMesh::SetPrimitiveScorer() : " << prs->GetName()
180 << " is registered."
181 << " 3D size: (" << fNSegment[0] << ", " << fNSegment[1] << ", "
182 << fNSegment[2] << ")" << G4endl;
183
184 prs->SetNijk(fNSegment[0], fNSegment[1], fNSegment[2]);
185 fCurrentPS = prs;
187 auto map =
189 fMap[prs->GetName()] = map;
190}
191
193{
194 if(fCurrentPS == nullptr)
195 {
196 G4cerr << "ERROR : G4VScoringMesh::SetSDFilter() : a quantity must be "
197 "defined first. This method is ignored."
198 << G4endl;
199 return;
200 }
201 if(verboseLevel > 0)
202 G4cout << "G4VScoringMesh::SetFilter() : " << filter->GetName()
203 << " is set to " << fCurrentPS->GetName() << G4endl;
204
205 G4VSDFilter* oldFilter = fCurrentPS->GetFilter();
206 if(oldFilter != nullptr)
207 {
208 G4cout << "WARNING : G4VScoringMesh::SetFilter() : " << oldFilter->GetName()
209 << " is overwritten by " << filter->GetName() << G4endl;
210 }
211 fCurrentPS->SetFilter(filter);
212}
213
215{
217 if(fCurrentPS == nullptr)
218 {
219 G4cerr << "ERROR : G4VScoringMesh::SetCurrentPrimitiveScorer() : The "
220 "primitive scorer <"
221 << name << "> does not found." << G4endl;
222 }
223}
224
226{
227 const auto itr = fMap.find(psname);
228 return itr != fMap.cend();
229}
230
232{
233 const auto itr = fMap.find(psname);
234 if(itr == fMap.cend())
235 {
236 return G4String("");
237 }
238
239 return GetPrimitiveScorer(psname)->GetUnit();
240}
241
243{
244 G4String unit = "";
245 if(fCurrentPS == nullptr)
246 {
247 G4String msg = "ERROR : G4VScoringMesh::GetCurrentPSUnit() : ";
248 msg += " Current primitive scorer is null.";
249 G4cerr << msg << G4endl;
250 }
251 else
252 {
253 unit = fCurrentPS->GetUnit();
254 }
255 return unit;
256}
257
259{
260 if(fCurrentPS == nullptr)
261 {
262 G4String msg = "ERROR : G4VScoringMesh::GetCurrentPSUnit() : ";
263 msg += " Current primitive scorer is null.";
264 G4cerr << msg << G4endl;
265 }
266 else
267 {
268 fCurrentPS->SetUnit(unit);
269 }
270}
271
273{
274 const auto itr = fMap.find(psname);
275 if(itr == fMap.cend())
276 {
277 return 1.;
278 }
279
280 return GetPrimitiveScorer(psname)->GetUnitValue();
281}
282
284{
285 for(G4int i = 0; i < 3; ++i)
286 divisionAxisNames[i] = fDivisionAxisNames[i];
287}
288
290{
291 if(fMFD == nullptr)
292 return nullptr;
293
295 for(G4int i = 0; i < nps; ++i)
296 {
298 if(name == prs->GetName())
299 return prs;
300 }
301
302 return nullptr;
303}
304
306{
307 G4cout << " # of segments: (" << fNSegment[0] << ", " << fNSegment[1] << ", "
308 << fNSegment[2] << ")" << G4endl;
309 G4cout << " displacement: (" << fCenterPosition.x() / cm << ", "
310 << fCenterPosition.y() / cm << ", " << fCenterPosition.z() / cm
311 << ") [cm]" << G4endl;
312 if(fRotationMatrix != nullptr)
313 {
314 G4cout << " rotation matrix: " << fRotationMatrix->xx() << " "
315 << fRotationMatrix->xy() << " " << fRotationMatrix->xz() << G4endl
316 << " " << fRotationMatrix->yx() << " "
317 << fRotationMatrix->yy() << " " << fRotationMatrix->yz() << G4endl
318 << " " << fRotationMatrix->zx() << " "
319 << fRotationMatrix->zy() << " " << fRotationMatrix->zz() << G4endl;
320 }
321
322 G4cout << " registered primitve scorers : " << G4endl;
325 for(G4int i = 0; i < nps; ++i)
326 {
327 prs = fMFD->GetPrimitive(i);
328 G4cout << " " << i << " " << prs->GetName();
329 if(prs->GetFilter() != nullptr)
330 G4cout << " with " << prs->GetFilter()->GetName();
331 G4cout << G4endl;
332 }
333}
334
336{
337 G4cout << "scoring mesh name: " << fWorldName << G4endl;
338 G4cout << "# of G4THitsMap : " << fMap.size() << G4endl;
339 for(const auto& mp : fMap)
340 {
341 G4cout << "[" << mp.first << "]" << G4endl;
342 mp.second->PrintAllHits();
343 }
344 G4cout << G4endl;
345}
346
348 G4VScoreColorMap* colorMap, G4int axflg)
349{
350 fDrawPSName = psName;
351 const auto fMapItr = fMap.find(psName);
352 if(fMapItr != fMap.cend())
353 {
354 fDrawUnit = GetPSUnit(psName);
356 Draw(fMapItr->second, colorMap, axflg);
357 }
358 else
359 {
360 G4cerr << "Scorer <" << psName << "> is not defined. Method ignored."
361 << G4endl;
362 }
363}
364
365void G4VScoringMesh::DrawMesh(const G4String& psName, G4int idxPlane,
366 G4int iColumn, G4VScoreColorMap* colorMap)
367{
368 fDrawPSName = psName;
369 const auto fMapItr = fMap.find(psName);
370 if(fMapItr != fMap.cend())
371 {
372 fDrawUnit = GetPSUnit(psName);
374 DrawColumn(fMapItr->second, colorMap, idxPlane, iColumn);
375 }
376 else
377 {
378 G4cerr << "Scorer <" << psName << "> is not defined. Method ignored."
379 << G4endl;
380 }
381}
382
384{
385 G4String psName = map->GetName();
386 const auto fMapItr = fMap.find(psName);
387 *(fMapItr->second) += *map;
388
389 if(verboseLevel > 9)
390 {
391 G4cout << G4endl;
392 G4cout << "G4VScoringMesh::Accumulate()" << G4endl;
393 G4cout << " PS name : " << psName << G4endl;
394 if(fMapItr == fMap.cend())
395 {
396 G4cout << " " << psName << " was not found." << G4endl;
397 }
398 else
399 {
400 G4cout << " map size : " << map->GetSize() << G4endl;
401 map->PrintAllHits();
402 }
403 G4cout << G4endl;
404 }
405}
406
408{
409 G4String psName = map->GetName();
410 const auto fMapItr = fMap.find(psName);
411 *(fMapItr->second) += *map;
412
413 if(verboseLevel > 9)
414 {
415 G4cout << G4endl;
416 G4cout << "G4VScoringMesh::Accumulate()" << G4endl;
417 G4cout << " PS name : " << psName << G4endl;
418 if(fMapItr == fMap.cend())
419 {
420 G4cout << " " << psName << " was not found." << G4endl;
421 }
422 else
423 {
424 G4cout << " map size : " << map->GetSize() << G4endl;
425 map->PrintAllHits();
426 }
427 G4cout << G4endl;
428 }
429}
430
432{
433 if(fConstructed)
434 {
436 {
437 SetupGeometry(fWorldPhys);
439 }
440 if(verboseLevel > 0)
441 G4cout << fWorldName << " --- All quantities are reset." << G4endl;
442 ResetScore();
443 }
444 else
445 {
446 fConstructed = true;
447 SetupGeometry(fWorldPhys);
448 }
449}
450
452{
453 if(fConstructed)
454 {
456 {
459 }
460
461 if(verboseLevel > 0)
462 G4cout << fWorldPhys->GetName() << " --- All quantities are reset."
463 << G4endl;
464 ResetScore();
465 }
466 else
467 {
468 fConstructed = true;
470 }
471}
472
474{
475 const MeshScoreMap scMap = scMesh->GetScoreMap();
476
477 auto fMapItr = fMap.cbegin();
478 auto mapItr = scMap.cbegin();
479 for(; fMapItr != fMap.cend(); ++fMapItr)
480 {
481 if(verboseLevel > 9)
482 G4cout << "G4VScoringMesh::Merge()" << fMapItr->first << G4endl;
483 *(fMapItr->second) += *(mapItr->second);
484 ++mapItr;
485 }
486}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
CLHEP::HepRotation G4RotationMatrix
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
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 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
virtual size_t GetSize() const
Definition: G4THitsMap.hh:164
virtual void PrintAllHits()
Definition: G4THitsMap.hh:503