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.35 2008/03/23 14:32:13 akimura Exp $ |
---|
28 | // GEANT4 tag $Name: HEAD $ |
---|
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 | |
---|
38 | G4VScoringMesh::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 | { |
---|
43 | G4SDManager::GetSDMpointer()->AddNewDetector(fMFD); |
---|
44 | |
---|
45 | fSize[0] = fSize[1] = fSize[2] = 0.; |
---|
46 | fNSegment[0] = fNSegment[1] = fNSegment[2] = 1; |
---|
47 | } |
---|
48 | |
---|
49 | G4VScoringMesh::~G4VScoringMesh() |
---|
50 | { |
---|
51 | ; |
---|
52 | } |
---|
53 | |
---|
54 | void G4VScoringMesh::ResetScore() { |
---|
55 | if(verboseLevel > 9) G4cout << "G4VScoringMesh::ResetScore() is called." << G4endl; |
---|
56 | std::map<G4String, G4THitsMap<G4double>* >::iterator itr = fMap.begin(); |
---|
57 | for(; itr != fMap.end(); itr++) { |
---|
58 | if(verboseLevel > 9) G4cout << "G4VScoringMesh::ResetScore()" << itr->first << G4endl; |
---|
59 | itr->second->clear(); |
---|
60 | } |
---|
61 | } |
---|
62 | void G4VScoringMesh::SetSize(G4double size[3]) { |
---|
63 | for(int i = 0; i < 3; i++) fSize[i] = size[i]; |
---|
64 | sizeIsSet = true; |
---|
65 | } |
---|
66 | void G4VScoringMesh::SetCenterPosition(G4double centerPosition[3]) { |
---|
67 | fCenterPosition = G4ThreeVector(centerPosition[0], centerPosition[1], centerPosition[2]); |
---|
68 | } |
---|
69 | void G4VScoringMesh::SetNumberOfSegments(G4int nSegment[3]) { |
---|
70 | for(int i = 0; i < 3; i++) fNSegment[i] = nSegment[i]; |
---|
71 | nMeshIsSet = true; |
---|
72 | } |
---|
73 | void G4VScoringMesh::GetNumberOfSegments(G4int nSegment[3]) { |
---|
74 | for(int i = 0; i < 3; i++) nSegment[i] = fNSegment[i]; |
---|
75 | } |
---|
76 | void G4VScoringMesh::RotateX(G4double delta) { |
---|
77 | if(fRotationMatrix == NULL) fRotationMatrix = new G4RotationMatrix(); |
---|
78 | fRotationMatrix->rotateX(delta); |
---|
79 | } |
---|
80 | |
---|
81 | void G4VScoringMesh::RotateY(G4double delta) { |
---|
82 | if(fRotationMatrix == NULL) fRotationMatrix = new G4RotationMatrix(); |
---|
83 | fRotationMatrix->rotateY(delta); |
---|
84 | } |
---|
85 | |
---|
86 | void G4VScoringMesh::RotateZ(G4double delta) { |
---|
87 | if(fRotationMatrix == NULL) fRotationMatrix = new G4RotationMatrix(); |
---|
88 | fRotationMatrix->rotateZ(delta); |
---|
89 | } |
---|
90 | |
---|
91 | void G4VScoringMesh::SetPrimitiveScorer(G4VPrimitiveScorer * ps) { |
---|
92 | |
---|
93 | if(!ReadyForQuantity()) |
---|
94 | { |
---|
95 | G4cerr << "ERROR : G4VScoringMesh::SetPrimitiveScorer() : " << ps->GetName() |
---|
96 | << " does not yet have mesh size or number of bins. Set them first." << G4endl |
---|
97 | << "This Method is ignored." << G4endl; |
---|
98 | return; |
---|
99 | } |
---|
100 | if(verboseLevel > 0) G4cout << "G4VScoringMesh::SetPrimitiveScorer() : " |
---|
101 | << ps->GetName() << " is registered." |
---|
102 | << " 3D size: (" |
---|
103 | << fNSegment[0] << ", " |
---|
104 | << fNSegment[1] << ", " |
---|
105 | << fNSegment[2] << ")" << G4endl; |
---|
106 | |
---|
107 | ps->SetNijk(fNSegment[0], fNSegment[1], fNSegment[2]); |
---|
108 | fCurrentPS = ps; |
---|
109 | fMFD->RegisterPrimitive(ps); |
---|
110 | G4THitsMap<G4double> * map = new G4THitsMap<G4double>(fWorldName, ps->GetName()); |
---|
111 | fMap[ps->GetName()] = map; |
---|
112 | } |
---|
113 | |
---|
114 | void G4VScoringMesh::SetFilter(G4VSDFilter * filter) { |
---|
115 | |
---|
116 | if(fCurrentPS == NULL) { |
---|
117 | G4cerr << "ERROR : G4VScoringMesh::SetSDFilter() : a quantity must be defined first. This method is ignored." << G4endl; |
---|
118 | return; |
---|
119 | } |
---|
120 | if(verboseLevel > 0) G4cout << "G4VScoringMesh::SetFilter() : " |
---|
121 | << filter->GetName() |
---|
122 | << " is set to " |
---|
123 | << fCurrentPS->GetName() << G4endl; |
---|
124 | |
---|
125 | G4VSDFilter* oldFilter = fCurrentPS->GetFilter(); |
---|
126 | if(oldFilter) |
---|
127 | { |
---|
128 | G4cout << "WARNING : G4VScoringMesh::SetFilter() : " << oldFilter->GetName() |
---|
129 | << " is overwritten by " << filter->GetName() << G4endl; |
---|
130 | } |
---|
131 | fCurrentPS->SetFilter(filter); |
---|
132 | } |
---|
133 | |
---|
134 | void G4VScoringMesh::SetCurrentPrimitiveScorer(G4String & name) { |
---|
135 | fCurrentPS = GetPrimitiveScorer(name); |
---|
136 | if(fCurrentPS == NULL) { |
---|
137 | G4cerr << "ERROR : G4VScoringMesh::SetCurrentPrimitiveScorer() : The primitive scorer <" |
---|
138 | << name << "> does not found." << G4endl; |
---|
139 | } |
---|
140 | } |
---|
141 | |
---|
142 | G4bool G4VScoringMesh::FindPrimitiveScorer(G4String & psname) { |
---|
143 | std::map<G4String, G4THitsMap<G4double>* >::iterator itr = fMap.find(psname);; |
---|
144 | if(itr == fMap.end()) return false; |
---|
145 | return true; |
---|
146 | } |
---|
147 | |
---|
148 | G4VPrimitiveScorer * G4VScoringMesh::GetPrimitiveScorer(G4String & name) { |
---|
149 | if(fMFD == NULL) return NULL; |
---|
150 | |
---|
151 | G4int nps = fMFD->GetNumberOfPrimitives(); |
---|
152 | for(G4int i = 0; i < nps; i++) { |
---|
153 | G4VPrimitiveScorer * ps = fMFD->GetPrimitive(i); |
---|
154 | if(name == ps->GetName()) return ps; |
---|
155 | } |
---|
156 | |
---|
157 | return NULL; |
---|
158 | } |
---|
159 | void G4VScoringMesh::List() const { |
---|
160 | |
---|
161 | G4cout << " # of segments: (" |
---|
162 | << fNSegment[0] << ", " |
---|
163 | << fNSegment[1] << ", " |
---|
164 | << fNSegment[2] << ")" |
---|
165 | << G4endl; |
---|
166 | G4cout << " displacement: (" |
---|
167 | << fCenterPosition.x()/cm << ", " |
---|
168 | << fCenterPosition.y()/cm << ", " |
---|
169 | << fCenterPosition.z()/cm << ") [cm]" |
---|
170 | << G4endl; |
---|
171 | if(fRotationMatrix != 0) { |
---|
172 | G4cout << " rotation matrix: " |
---|
173 | << fRotationMatrix->xx() << " " |
---|
174 | << fRotationMatrix->xy() << " " |
---|
175 | << fRotationMatrix->xz() << G4endl |
---|
176 | << " " |
---|
177 | << fRotationMatrix->yx() << " " |
---|
178 | << fRotationMatrix->yy() << " " |
---|
179 | << fRotationMatrix->yz() << G4endl |
---|
180 | << " " |
---|
181 | << fRotationMatrix->zx() << " " |
---|
182 | << fRotationMatrix->zy() << " " |
---|
183 | << fRotationMatrix->zz() << G4endl; |
---|
184 | } |
---|
185 | |
---|
186 | |
---|
187 | G4cout << " registered primitve scorers : " << G4endl; |
---|
188 | G4int nps = fMFD->GetNumberOfPrimitives(); |
---|
189 | G4VPrimitiveScorer * ps; |
---|
190 | for(int i = 0; i < nps; i++) { |
---|
191 | ps = fMFD->GetPrimitive(i); |
---|
192 | G4cout << " " << i << " " << ps->GetName(); |
---|
193 | if(ps->GetFilter() != NULL) G4cout << " with " << ps->GetFilter()->GetName(); |
---|
194 | G4cout << G4endl; |
---|
195 | } |
---|
196 | |
---|
197 | |
---|
198 | } |
---|
199 | |
---|
200 | void G4VScoringMesh::Dump() { |
---|
201 | G4cout << "scoring mesh name: " << fWorldName << G4endl; |
---|
202 | |
---|
203 | G4cout << "# of G4THitsMap : " << fMap.size() << G4endl; |
---|
204 | std::map<G4String, G4THitsMap<G4double>* >::iterator itr = fMap.begin(); |
---|
205 | for(; itr != fMap.end(); itr++) { |
---|
206 | G4cout << "[" << itr->first << "]" << G4endl; |
---|
207 | itr->second->PrintAllHits(); |
---|
208 | } |
---|
209 | G4cout << G4endl; |
---|
210 | |
---|
211 | } |
---|
212 | |
---|