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