source: trunk/source/digits_hits/utils/src/G4VScoringMesh.cc@ 1347

Last change on this file since 1347 was 1340, checked in by garnier, 15 years ago

update ti head

File size: 8.9 KB
Line 
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: G4VScoringMesh.cc,v 1.42 2010/07/27 01:44:54 akimura Exp $
28// GEANT4 tag $Name: $
29//
30
31#include "G4VScoringMesh.hh"
32#include "G4VPhysicalVolume.hh"
33#include "G4MultiFunctionalDetector.hh"
34#include "G4VPrimitiveScorer.hh"
35#include "G4VSDFilter.hh"
36#include "G4SDManager.hh"
37
38G4VScoringMesh::G4VScoringMesh(G4String wName)
39 : fWorldName(wName),fConstructed(false),fActive(true),
40 fRotationMatrix(NULL), fMFD(new G4MultiFunctionalDetector(wName)),
41 verboseLevel(0),sizeIsSet(false),nMeshIsSet(false),
42 fDrawUnit(""), fDrawUnitValue(1.)
43{
44 G4SDManager::GetSDMpointer()->AddNewDetector(fMFD);
45
46 fSize[0] = fSize[1] = fSize[2] = 0.;
47 fNSegment[0] = fNSegment[1] = fNSegment[2] = 1;
48 fDivisionAxisNames[0] = fDivisionAxisNames[1] = fDivisionAxisNames[2] = "";
49}
50
51G4VScoringMesh::~G4VScoringMesh()
52{
53 ;
54}
55
56void G4VScoringMesh::ResetScore() {
57 if(verboseLevel > 9) G4cout << "G4VScoringMesh::ResetScore() is called." << G4endl;
58 std::map<G4String, G4THitsMap<G4double>* >::iterator itr = fMap.begin();
59 for(; itr != fMap.end(); itr++) {
60 if(verboseLevel > 9) G4cout << "G4VScoringMesh::ResetScore()" << itr->first << G4endl;
61 itr->second->clear();
62 }
63}
64void G4VScoringMesh::SetSize(G4double size[3]) {
65 for(int i = 0; i < 3; i++) fSize[i] = size[i];
66 sizeIsSet = true;
67}
68G4ThreeVector G4VScoringMesh::GetSize() const {
69 if(sizeIsSet)
70 return G4ThreeVector(fSize[0], fSize[1], fSize[2]);
71 else
72 return G4ThreeVector(0., 0., 0.);
73}
74void G4VScoringMesh::SetCenterPosition(G4double centerPosition[3]) {
75 fCenterPosition = G4ThreeVector(centerPosition[0], centerPosition[1], centerPosition[2]);
76}
77void G4VScoringMesh::SetNumberOfSegments(G4int nSegment[3]) {
78 for(int i = 0; i < 3; i++) fNSegment[i] = nSegment[i];
79 nMeshIsSet = true;
80}
81void G4VScoringMesh::GetNumberOfSegments(G4int nSegment[3]) {
82 for(int i = 0; i < 3; i++) nSegment[i] = fNSegment[i];
83}
84void G4VScoringMesh::RotateX(G4double delta) {
85 if(fRotationMatrix == NULL) fRotationMatrix = new G4RotationMatrix();
86 fRotationMatrix->rotateX(delta);
87}
88
89void G4VScoringMesh::RotateY(G4double delta) {
90 if(fRotationMatrix == NULL) fRotationMatrix = new G4RotationMatrix();
91 fRotationMatrix->rotateY(delta);
92}
93
94void G4VScoringMesh::RotateZ(G4double delta) {
95 if(fRotationMatrix == NULL) fRotationMatrix = new G4RotationMatrix();
96 fRotationMatrix->rotateZ(delta);
97}
98
99void G4VScoringMesh::SetPrimitiveScorer(G4VPrimitiveScorer * ps) {
100
101 if(!ReadyForQuantity())
102 {
103 G4cerr << "ERROR : G4VScoringMesh::SetPrimitiveScorer() : " << ps->GetName()
104 << " does not yet have mesh size or number of bins. Set them first." << G4endl
105 << "This Method is ignored." << G4endl;
106 return;
107 }
108 if(verboseLevel > 0) G4cout << "G4VScoringMesh::SetPrimitiveScorer() : "
109 << ps->GetName() << " is registered."
110 << " 3D size: ("
111 << fNSegment[0] << ", "
112 << fNSegment[1] << ", "
113 << fNSegment[2] << ")" << G4endl;
114
115 ps->SetNijk(fNSegment[0], fNSegment[1], fNSegment[2]);
116 fCurrentPS = ps;
117 fMFD->RegisterPrimitive(ps);
118 G4THitsMap<G4double> * map = new G4THitsMap<G4double>(fWorldName, ps->GetName());
119 fMap[ps->GetName()] = map;
120}
121
122void G4VScoringMesh::SetFilter(G4VSDFilter * filter) {
123
124 if(fCurrentPS == NULL) {
125 G4cerr << "ERROR : G4VScoringMesh::SetSDFilter() : a quantity must be defined first. This method is ignored." << G4endl;
126 return;
127 }
128 if(verboseLevel > 0) G4cout << "G4VScoringMesh::SetFilter() : "
129 << filter->GetName()
130 << " is set to "
131 << fCurrentPS->GetName() << G4endl;
132
133 G4VSDFilter* oldFilter = fCurrentPS->GetFilter();
134 if(oldFilter)
135 {
136 G4cout << "WARNING : G4VScoringMesh::SetFilter() : " << oldFilter->GetName()
137 << " is overwritten by " << filter->GetName() << G4endl;
138 }
139 fCurrentPS->SetFilter(filter);
140}
141
142void G4VScoringMesh::SetCurrentPrimitiveScorer(G4String & name) {
143 fCurrentPS = GetPrimitiveScorer(name);
144 if(fCurrentPS == NULL) {
145 G4cerr << "ERROR : G4VScoringMesh::SetCurrentPrimitiveScorer() : The primitive scorer <"
146 << name << "> does not found." << G4endl;
147 }
148}
149
150G4bool G4VScoringMesh::FindPrimitiveScorer(G4String & psname) {
151 std::map<G4String, G4THitsMap<G4double>* >::iterator itr = fMap.find(psname);;
152 if(itr == fMap.end()) return false;
153 return true;
154}
155
156G4String G4VScoringMesh::GetPSUnit(G4String & psname) {
157 std::map<G4String, G4THitsMap<G4double>* >::iterator itr = fMap.find(psname);;
158 if(itr == fMap.end()) {
159 return G4String("");
160 } else {
161 return GetPrimitiveScorer(psname)->GetUnit();
162 }
163}
164
165G4String G4VScoringMesh::GetCurrentPSUnit(){
166 G4String unit = "";
167 if(fCurrentPS == NULL) {
168 G4String msg = "ERROR : G4VScoringMesh::GetCurrentPSUnit() : ";
169 msg += " Current primitive scorer is null.";
170 G4cerr << msg << G4endl;
171 }else{
172 unit = fCurrentPS->GetUnit();
173 }
174 return unit;
175}
176
177void G4VScoringMesh::SetCurrentPSUnit(const G4String& unit){
178 if(fCurrentPS == NULL) {
179 G4String msg = "ERROR : G4VScoringMesh::GetCurrentPSUnit() : ";
180 msg += " Current primitive scorer is null.";
181 G4cerr << msg << G4endl;
182 }else{
183 fCurrentPS->SetUnit(unit);
184 }
185}
186
187G4double G4VScoringMesh::GetPSUnitValue(G4String & psname) {
188 std::map<G4String, G4THitsMap<G4double>* >::iterator itr = fMap.find(psname);;
189 if(itr == fMap.end()) {
190 return 1.;
191 } else {
192 return GetPrimitiveScorer(psname)->GetUnitValue();
193 }
194}
195
196void G4VScoringMesh::GetDivisionAxisNames(G4String divisionAxisNames[3]) {
197 for(int i = 0; i < 3; i++) divisionAxisNames[i] = fDivisionAxisNames[i];
198}
199
200G4VPrimitiveScorer * G4VScoringMesh::GetPrimitiveScorer(G4String & name) {
201 if(fMFD == NULL) return NULL;
202
203 G4int nps = fMFD->GetNumberOfPrimitives();
204 for(G4int i = 0; i < nps; i++) {
205 G4VPrimitiveScorer * ps = fMFD->GetPrimitive(i);
206 if(name == ps->GetName()) return ps;
207 }
208
209 return NULL;
210}
211void G4VScoringMesh::List() const {
212
213 G4cout << " # of segments: ("
214 << fNSegment[0] << ", "
215 << fNSegment[1] << ", "
216 << fNSegment[2] << ")"
217 << G4endl;
218 G4cout << " displacement: ("
219 << fCenterPosition.x()/cm << ", "
220 << fCenterPosition.y()/cm << ", "
221 << fCenterPosition.z()/cm << ") [cm]"
222 << G4endl;
223 if(fRotationMatrix != 0) {
224 G4cout << " rotation matrix: "
225 << fRotationMatrix->xx() << " "
226 << fRotationMatrix->xy() << " "
227 << fRotationMatrix->xz() << G4endl
228 << " "
229 << fRotationMatrix->yx() << " "
230 << fRotationMatrix->yy() << " "
231 << fRotationMatrix->yz() << G4endl
232 << " "
233 << fRotationMatrix->zx() << " "
234 << fRotationMatrix->zy() << " "
235 << fRotationMatrix->zz() << G4endl;
236 }
237
238
239 G4cout << " registered primitve scorers : " << G4endl;
240 G4int nps = fMFD->GetNumberOfPrimitives();
241 G4VPrimitiveScorer * ps;
242 for(int i = 0; i < nps; i++) {
243 ps = fMFD->GetPrimitive(i);
244 G4cout << " " << i << " " << ps->GetName();
245 if(ps->GetFilter() != NULL) G4cout << " with " << ps->GetFilter()->GetName();
246 G4cout << G4endl;
247 }
248
249
250}
251
252void G4VScoringMesh::Dump() {
253 G4cout << "scoring mesh name: " << fWorldName << G4endl;
254
255 G4cout << "# of G4THitsMap : " << fMap.size() << G4endl;
256 std::map<G4String, G4THitsMap<G4double>* >::iterator itr = fMap.begin();
257 for(; itr != fMap.end(); itr++) {
258 G4cout << "[" << itr->first << "]" << G4endl;
259 itr->second->PrintAllHits();
260 }
261 G4cout << G4endl;
262
263}
264
Note: See TracBrowser for help on using the repository browser.