ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VScoringMesh.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4VScoringMesh.cc
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),fCurrentPS(nullptr),fConstructed(false),fActive(true),
47  fShape(MeshShape::undefined),
48  fRotationMatrix(nullptr), fMFD(new G4MultiFunctionalDetector(wName)),
49  verboseLevel(0),sizeIsSet(false),nMeshIsSet(false),
50  fDrawUnit(""), fDrawUnitValue(1.), fMeshElementLogical(nullptr),
51  fParallelWorldProcess(nullptr), fGeometryHasBeenDestroyed(false),
52  copyNumberLevel(0)
53 {
55 
56  fSize[0] = fSize[1] = fSize[2] = 0.;
57  fNSegment[0] = fNSegment[1] = fNSegment[2] = 1;
59 }
60 
62  ;
63 }
64 
66  if(verboseLevel > 9) G4cout << "G4VScoringMesh::ResetScore() is called." << G4endl;
67  for(auto mp : fMap)
68  {
69  if(verboseLevel > 9) G4cout << "G4VScoringMesh::ResetScore()" << mp.first << G4endl;
70  mp.second->clear();
71  }
72 }
73 
75  if ( !sizeIsSet ){
76  for(int i = 0; i < 3; i++) fSize[i] = size[i];
77  sizeIsSet = true;
78  }else{
79  G4String message = " The size of scoring mesh can not be changed.";
80  G4Exception("G4VScoringMesh::SetSize()",
81  "DigiHitsUtilsScoreVScoringMesh000", JustWarning,
82  message);
83  }
84 }
86  if(sizeIsSet)
87  return G4ThreeVector(fSize[0], fSize[1], fSize[2]);
88  else
89  return G4ThreeVector(0., 0., 0.);
90 }
92  fCenterPosition = G4ThreeVector(centerPosition[0], centerPosition[1], centerPosition[2]);
93 }
95  if ( !nMeshIsSet || fShape==MeshShape::realWorldLogVol ){
96  for(int i = 0; i < 3; i++) fNSegment[i] = nSegment[i];
97  nMeshIsSet = true;
98  } else {
99  G4String message = " The size of scoring segments can not be changed.";
100  G4Exception("G4VScoringMesh::SetNumberOfSegments()",
101  "DigiHitsUtilsScoreVScoringMesh000", JustWarning,
102  message);
103  }
104 }
106  for(int i = 0; i < 3; i++) nSegment[i] = fNSegment[i];
107 }
110  fRotationMatrix->rotateX(delta);
111 }
112 
115  fRotationMatrix->rotateY(delta);
116 }
117 
120  fRotationMatrix->rotateZ(delta);
121 }
122 
124 
125  if(!ReadyForQuantity())
126  {
127  G4cerr << "ERROR : G4VScoringMesh::SetPrimitiveScorer() : "
128  << prs->GetName()
129  << " does not yet have mesh size or number of bins. Set them first." << G4endl
130  << "This Method is ignored." << G4endl;
131  return;
132  }
133  if(verboseLevel > 0) G4cout << "G4VScoringMesh::SetPrimitiveScorer() : "
134  << prs->GetName() << " is registered."
135  << " 3D size: ("
136  << fNSegment[0] << ", "
137  << fNSegment[1] << ", "
138  << fNSegment[2] << ")" << G4endl;
139 
140  prs->SetNijk(fNSegment[0], fNSegment[1], fNSegment[2]);
141  fCurrentPS = prs;
142  fMFD->RegisterPrimitive(prs);
144  fMap[prs->GetName()] = map;
145 }
146 
148 
149  if(!fCurrentPS) {
150  G4cerr << "ERROR : G4VScoringMesh::SetSDFilter() : a quantity must be defined first. This method is ignored." << G4endl;
151  return;
152  }
153  if(verboseLevel > 0) G4cout << "G4VScoringMesh::SetFilter() : "
154  << filter->GetName()
155  << " is set to "
156  << fCurrentPS->GetName() << G4endl;
157 
158  G4VSDFilter* oldFilter = fCurrentPS->GetFilter();
159  if(oldFilter)
160  {
161  G4cout << "WARNING : G4VScoringMesh::SetFilter() : " << oldFilter->GetName()
162  << " is overwritten by " << filter->GetName() << G4endl;
163  }
164  fCurrentPS->SetFilter(filter);
165 }
166 
169  if(!fCurrentPS) {
170  G4cerr << "ERROR : G4VScoringMesh::SetCurrentPrimitiveScorer() : The primitive scorer <"
171  << name << "> does not found." << G4endl;
172  }
173 }
174 
176  MeshScoreMap::iterator itr = fMap.find(psname);
177  if(itr == fMap.end()) return false;
178  return true;
179 }
180 
182  MeshScoreMap::iterator itr = fMap.find(psname);
183  if(itr == fMap.end()) {
184  return G4String("");
185  } else {
186  return GetPrimitiveScorer(psname)->GetUnit();
187  }
188 }
189 
191  G4String unit = "";
192  if(!fCurrentPS) {
193  G4String msg = "ERROR : G4VScoringMesh::GetCurrentPSUnit() : ";
194  msg += " Current primitive scorer is null.";
195  G4cerr << msg << G4endl;
196  }else{
197  unit = fCurrentPS->GetUnit();
198  }
199  return unit;
200 }
201 
203  if(!fCurrentPS) {
204  G4String msg = "ERROR : G4VScoringMesh::GetCurrentPSUnit() : ";
205  msg += " Current primitive scorer is null.";
206  G4cerr << msg << G4endl;
207  }else{
208  fCurrentPS->SetUnit(unit);
209  }
210 }
211 
213  MeshScoreMap::iterator itr = fMap.find(psname);
214  if(itr == fMap.end()) {
215  return 1.;
216  } else {
217  return GetPrimitiveScorer(psname)->GetUnitValue();
218  }
219 }
220 
221 void G4VScoringMesh::GetDivisionAxisNames(G4String divisionAxisNames[3]) {
222  for(int i = 0; i < 3; i++) divisionAxisNames[i] = fDivisionAxisNames[i];
223 }
224 
226  if(!fMFD) return nullptr;
227 
229  for(G4int i = 0; i < nps; i++) {
231  if(name == prs->GetName()) return prs;
232  }
233 
234  return nullptr;
235 }
236 void G4VScoringMesh::List() const {
237 
238  G4cout << " # of segments: ("
239  << fNSegment[0] << ", "
240  << fNSegment[1] << ", "
241  << fNSegment[2] << ")"
242  << G4endl;
243  G4cout << " displacement: ("
244  << fCenterPosition.x()/cm << ", "
245  << fCenterPosition.y()/cm << ", "
246  << fCenterPosition.z()/cm << ") [cm]"
247  << G4endl;
248  if(fRotationMatrix != 0) {
249  G4cout << " rotation matrix: "
250  << fRotationMatrix->xx() << " "
251  << fRotationMatrix->xy() << " "
252  << fRotationMatrix->xz() << G4endl
253  << " "
254  << fRotationMatrix->yx() << " "
255  << fRotationMatrix->yy() << " "
256  << fRotationMatrix->yz() << G4endl
257  << " "
258  << fRotationMatrix->zx() << " "
259  << fRotationMatrix->zy() << " "
260  << fRotationMatrix->zz() << G4endl;
261  }
262 
263 
264  G4cout << " registered primitve scorers : " << G4endl;
266  G4VPrimitiveScorer * prs;
267  for(int i = 0; i < nps; i++) {
268  prs = fMFD->GetPrimitive(i);
269  G4cout << " " << i << " " << prs->GetName();
270  if(prs->GetFilter() != 0) G4cout << " with " << prs->GetFilter()->GetName();
271  G4cout << G4endl;
272  }
273 }
274 
276  G4cout << "scoring mesh name: " << fWorldName << G4endl;
277  G4cout << "# of G4THitsMap : " << fMap.size() << G4endl;
278  for(auto mp : fMap)
279  {
280  G4cout << "[" << mp.first << "]" << G4endl;
281  mp.second->PrintAllHits();
282  }
283  G4cout << G4endl;
284 
285 }
286 
287 
288 void G4VScoringMesh::DrawMesh(const G4String& psName,G4VScoreColorMap* colorMap,G4int axflg)
289 {
290  fDrawPSName = psName;
291  MeshScoreMap::const_iterator fMapItr = fMap.find(psName);
292  if(fMapItr!=fMap.end()) {
293  fDrawUnit = GetPSUnit(psName);
294  fDrawUnitValue = GetPSUnitValue(psName);
295  Draw(fMapItr->second, colorMap,axflg);
296  } else {
297  G4cerr << "Scorer <" << psName << "> is not defined. Method ignored." << G4endl;
298  }
299 }
300 
301 void G4VScoringMesh::DrawMesh(const G4String& psName,G4int idxPlane,G4int iColumn,G4VScoreColorMap* colorMap)
302 {
303  fDrawPSName = psName;
304  MeshScoreMap::const_iterator fMapItr = fMap.find(psName);
305  if(fMapItr!=fMap.end()) {
306  fDrawUnit = GetPSUnit(psName);
307  fDrawUnitValue = GetPSUnitValue(psName);
308  DrawColumn(fMapItr->second,colorMap,idxPlane,iColumn);
309  } else {
310  G4cerr << "Scorer <" << psName << "> is not defined. Method ignored." << G4endl;
311  }
312 }
313 
315 {
316  G4String psName = map->GetName();
317  MeshScoreMap::const_iterator fMapItr = fMap.find(psName);
318  *(fMapItr->second) += *map;
319 
320  if(verboseLevel > 9) {
321  G4cout << G4endl;
322  G4cout << "G4VScoringMesh::Accumulate()" << G4endl;
323  G4cout << " PS name : " << psName << G4endl;
324  if(fMapItr == fMap.end()) {
325  G4cout << " " << psName << " was not found." << G4endl;
326  } else {
327  G4cout << " map size : " << map->GetSize() << G4endl;
328  map->PrintAllHits();
329  }
330  G4cout << G4endl;
331  }
332 }
333 
335 {
336  G4String psName = map->GetName();
337  MeshScoreMap::const_iterator fMapItr = fMap.find(psName);
338  *(fMapItr->second) += *map;
339 
340  if(verboseLevel > 9) {
341  G4cout << G4endl;
342  G4cout << "G4VScoringMesh::Accumulate()" << G4endl;
343  G4cout << " PS name : " << psName << G4endl;
344  if(fMapItr == fMap.end()) {
345  G4cout << " " << psName << " was not found." << G4endl;
346  } else {
347  G4cout << " map size : " << map->GetSize() << G4endl;
348  map->PrintAllHits();
349  }
350  G4cout << G4endl;
351  }
352 }
353 
355 {
356  if(fConstructed) {
358  SetupGeometry(fWorldPhys);
360  }
361  if(verboseLevel > 0)
362  G4cout << fWorldName << " --- All quantities are reset."
363  << G4endl;
364  ResetScore();
365  }
366  else {
367  fConstructed = true;
368  SetupGeometry(fWorldPhys);
369  }
370 }
371 
373 {
374  if(fConstructed) {
378  }
379 
380  if(verboseLevel > 0)
381  G4cout << fWorldPhys->GetName() << " --- All quantities are reset." << G4endl;
382  ResetScore();
383 
384  } else {
385  fConstructed = true;
387  }
388 }
389 
391 {
392  const MeshScoreMap scMap = scMesh->GetScoreMap();
393 
394  MeshScoreMap::const_iterator fMapItr = fMap.begin();
395  MeshScoreMap::const_iterator mapItr = scMap.begin();
396  for(; fMapItr != fMap.end(); fMapItr++) {
397  if(verboseLevel > 9) G4cout << "G4VScoringMesh::Merge()" << fMapItr->first << G4endl;
398  *(fMapItr->second) += *(mapItr->second);
399  mapItr++;
400  }
401 }
402