Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4ScoringManager << 26 // 27 // ------------------------------------------- << 27 // $Id: G4ScoringManager.cc,v 1.31 2008/03/25 02:18:38 akimura Exp $ >> 28 // GEANT4 tag $Name: geant4-09-02-patch-03 $ >> 29 // 28 30 29 #include "G4ScoringManager.hh" 31 #include "G4ScoringManager.hh" 30 #include "G4ScoringMessenger.hh" 32 #include "G4ScoringMessenger.hh" 31 #include "G4ScoreQuantityMessenger.hh" 33 #include "G4ScoreQuantityMessenger.hh" 32 #include "G4VScoringMesh.hh" 34 #include "G4VScoringMesh.hh" 33 #include "G4THitsMap.hh" 35 #include "G4THitsMap.hh" 34 #include "G4VScoreColorMap.hh" 36 #include "G4VScoreColorMap.hh" 35 #include "G4DefaultLinearColorMap.hh" 37 #include "G4DefaultLinearColorMap.hh" 36 #include "G4ScoreLogColorMap.hh" 38 #include "G4ScoreLogColorMap.hh" 37 39 38 G4ThreadLocal G4ScoringManager* G4ScoringManag << 40 G4ScoringManager* G4ScoringManager::fSManager = 0; 39 41 40 G4ThreadLocal G4int G4ScoringManager::replicaL << 42 G4int G4ScoringManager::replicaLevel = 2; 41 43 42 G4ScoringManager* G4ScoringManager::GetScoring 44 G4ScoringManager* G4ScoringManager::GetScoringManager() 43 { 45 { 44 if(fSManager == nullptr) << 46 if(!fSManager) 45 { 47 { 46 fSManager = new G4ScoringManager; 48 fSManager = new G4ScoringManager; 47 } 49 } 48 return fSManager; 50 return fSManager; 49 } 51 } 50 52 51 G4ScoringManager* G4ScoringManager::GetScoring 53 G4ScoringManager* G4ScoringManager::GetScoringManagerIfExist() 52 { << 54 { return fSManager; } 53 return fSManager; << 54 } << 55 55 56 G4ScoringManager::G4ScoringManager() 56 G4ScoringManager::G4ScoringManager() 57 : verboseLevel(0) << 57 :verboseLevel(0),fCurrentMesh(0) 58 , fCurrentMesh(nullptr) << 59 { 58 { 60 fMessenger = new G4ScoringMessen << 59 fMessenger = new G4ScoringMessenger(this); 61 fQuantityMessenger = new G4ScoreQuantity << 60 fQuantityMessenger = new G4ScoreQuantityMessenger(this); 62 fColorMapDict = new ColorMapDict(); << 61 fColorMapDict = new ColorMapDict(); 63 fDefaultLinearColorMap = new G4DefaultLinear 62 fDefaultLinearColorMap = new G4DefaultLinearColorMap("defaultLinearColorMap"); 64 (*fColorMapDict)[fDefaultLinearColorMap->Get 63 (*fColorMapDict)[fDefaultLinearColorMap->GetName()] = fDefaultLinearColorMap; 65 G4VScoreColorMap* logColorMap = new G4ScoreL << 64 G4VScoreColorMap * logColorMap = new G4ScoreLogColorMap("logColorMap"); 66 (*fColorMapDict)[logColorMap->GetName()] = l 65 (*fColorMapDict)[logColorMap->GetName()] = logColorMap; 67 writer = n << 66 writer = new G4VScoreWriter(); 68 } 67 } 69 68 70 G4ScoringManager::~G4ScoringManager() 69 G4ScoringManager::~G4ScoringManager() 71 { << 70 { 72 delete writer; << 73 delete fDefaultLinearColorMap; << 74 delete fColorMapDict; << 75 delete fQuantityMessenger; << 76 delete fMessenger; 71 delete fMessenger; 77 fSManager = nullptr; << 72 fSManager = 0; >> 73 if(writer) delete writer; 78 } 74 } 79 75 80 void G4ScoringManager::SetReplicaLevel(G4int l << 76 void G4ScoringManager::SetReplicaLevel(G4int lvl) 81 G4int G4ScoringManager::GetReplicaLevel() { re << 77 { replicaLevel = lvl; } >> 78 G4int G4ScoringManager::GetReplicaLevel() >> 79 { return replicaLevel; } 82 80 83 void G4ScoringManager::Accumulate(G4VHitsColle 81 void G4ScoringManager::Accumulate(G4VHitsCollection* map) 84 { 82 { 85 auto sm = FindMesh(map); << 83 G4String wName = map->GetSDname(); 86 if(sm == nullptr) << 84 G4VScoringMesh* sm = FindMesh(wName); 87 return; << 85 if(sm == NULL) return; 88 if(verboseLevel > 9) << 86 if(verboseLevel>9) 89 { << 87 { G4cout << "G4ScoringManager::Accumulate() for " << map->GetSDname() << " / " << map->GetName() << G4endl; 90 G4cout << "G4ScoringManager::Accumulate() << 88 G4cout << " is calling G4VScoringMesh::Accumulate() of " << sm->GetWorldName() << G4endl; } 91 << map->GetName() << G4endl; << 92 G4cout << " is calling G4VScoringMesh::Ac << 93 << sm->GetWorldName() << G4endl; << 94 } << 95 sm->Accumulate(static_cast<G4THitsMap<double 89 sm->Accumulate(static_cast<G4THitsMap<double>*>(map)); 96 } 90 } 97 91 98 G4VScoringMesh* G4ScoringManager::FindMesh(G4V << 92 G4VScoringMesh* G4ScoringManager::FindMesh(G4String wName) 99 { 93 { 100 auto colID = map->GetColID(); << 94 G4VScoringMesh* sm = 0; 101 G4VScoringMesh* sm = nullptr; << 95 for(MeshVecItr itr = fMeshVec.begin(); itr != fMeshVec.end(); itr++) { 102 auto msh = fMeshMap.find(colID); << 96 G4String smName = (*itr)->GetWorldName(); 103 if(msh == fMeshMap.end()) << 97 if(wName == smName) { 104 { << 98 sm = *itr; 105 const auto& wName = map->GetSDname(); << 99 break; 106 sm = FindMesh(wName); << 100 } 107 fMeshMap[colID] = sm; << 108 } << 109 else << 110 { << 111 sm = (*msh).second; << 112 } 101 } 113 return sm; << 102 if(!sm && verboseLevel>9) 114 } << 103 { G4cout << "WARNING : G4ScoringManager::FindMesh() --- <" << wName << "> is not found. Null returned." << G4endl; } 115 104 116 G4VScoringMesh* G4ScoringManager::FindMesh(con << 105 return sm; 117 { << 118 G4VScoringMesh* sm = nullptr; << 119 for(auto msh : fMeshVec) << 120 { << 121 if(msh->GetWorldName() == wName) << 122 return msh; << 123 } << 124 if((sm == nullptr) && verboseLevel > 9) << 125 { << 126 G4cout << "WARNING : G4ScoringManager::Fin << 127 << "> is not found. Null returned." << 128 } << 129 return nullptr; << 130 } 106 } 131 107 132 void G4ScoringManager::List() const 108 void G4ScoringManager::List() const 133 { 109 { 134 G4cout << "G4ScoringManager has " << GetNumb << 110 G4cout << "G4ScoringManager has " << GetNumberOfMesh() << " scoring meshes." << G4endl; 135 << G4endl; << 111 for(MeshVecConstItr itr = fMeshVec.begin(); itr != fMeshVec.end(); itr++) { 136 for(auto msh : fMeshVec) << 112 (*itr)->List(); 137 msh->List(); << 113 } 138 } 114 } 139 115 140 void G4ScoringManager::Dump() const 116 void G4ScoringManager::Dump() const 141 { 117 { 142 for(auto msh : fMeshVec) << 118 for(MeshVecConstItr itr = fMeshVec.begin(); itr != fMeshVec.end(); itr++) { 143 msh->Dump(); << 119 (*itr)->Dump(); >> 120 } 144 } 121 } 145 122 146 void G4ScoringManager::DrawMesh(const G4String << 123 void G4ScoringManager::DrawMesh(G4String meshName,G4String psName,G4String colorMapName,G4int axflg) 147 const G4String << 148 const G4String << 149 { 124 { 150 G4VScoringMesh* mesh = FindMesh(meshName); 125 G4VScoringMesh* mesh = FindMesh(meshName); 151 if(mesh != nullptr) << 126 if(mesh) 152 { 127 { 153 G4VScoreColorMap* colorMap = GetScoreColor 128 G4VScoreColorMap* colorMap = GetScoreColorMap(colorMapName); 154 if(colorMap == nullptr) << 129 if(!colorMap) 155 { 130 { 156 G4cerr << "WARNING : Score color map <" << 131 G4cerr << "WARNING : Score color map <" << colorMapName << "> is not found. Default linear color map is used." << G4endl; 157 << "> is not found. Default linea << 158 colorMap = fDefaultLinearColorMap; 132 colorMap = fDefaultLinearColorMap; 159 } 133 } 160 mesh->DrawMesh(psName, colorMap, axflg); << 134 mesh->DrawMesh(psName,colorMap,axflg); 161 } << 135 } else { 162 else << 136 G4cerr << "ERROR : G4ScoringManager::DrawMesh() --- <" 163 { << 137 << meshName << "> is not found. Nothing is done." << G4endl; 164 G4cerr << "ERROR : G4ScoringManager::DrawM << 165 << "> is not found. Nothing is done << 166 } 138 } 167 } 139 } 168 140 169 void G4ScoringManager::DrawMesh(const G4String << 141 void G4ScoringManager::DrawMesh(G4String meshName,G4String psName,G4int idxPlane,G4int iColumn,G4String colorMapName) 170 const G4String << 171 G4int iColumn, << 172 { 142 { 173 G4VScoringMesh* mesh = FindMesh(meshName); 143 G4VScoringMesh* mesh = FindMesh(meshName); 174 if(mesh != nullptr) << 144 if(mesh) 175 { 145 { 176 G4VScoreColorMap* colorMap = GetScoreColor 146 G4VScoreColorMap* colorMap = GetScoreColorMap(colorMapName); 177 if(colorMap == nullptr) << 147 if(!colorMap) 178 { 148 { 179 G4cerr << "WARNING : Score color map <" << 149 G4cerr << "WARNING : Score color map <" << colorMapName << "> is not found. Default linear color map is used." << G4endl; 180 << "> is not found. Default linea << 181 colorMap = fDefaultLinearColorMap; 150 colorMap = fDefaultLinearColorMap; 182 } 151 } 183 mesh->DrawMesh(psName, idxPlane, iColumn, << 152 mesh->DrawMesh(psName,idxPlane,iColumn,colorMap); 184 } << 153 } else { 185 else << 154 G4cerr << "ERROR : G4ScoringManager::DrawMesh() --- <" 186 { << 155 << meshName << "> is not found. Nothing is done." << G4endl; 187 G4cerr << "ERROR : G4ScoringManager::DrawM << 188 << "> is not found. Nothing is done << 189 } 156 } 190 } 157 } 191 158 192 void G4ScoringManager::DumpQuantityToFile(cons << 159 void G4ScoringManager::DumpQuantityToFile(G4String meshName,G4String psName,G4String fileName, G4String option) 193 cons << 194 cons << 195 cons << 196 { 160 { 197 G4VScoringMesh* mesh = FindMesh(meshName); 161 G4VScoringMesh* mesh = FindMesh(meshName); 198 if(mesh != nullptr) << 162 if(mesh) { 199 { << 200 writer->SetScoringMesh(mesh); 163 writer->SetScoringMesh(mesh); 201 writer->DumpQuantityToFile(psName, fileNam 164 writer->DumpQuantityToFile(psName, fileName, option); 202 } << 165 } else { 203 else << 166 G4cerr << "ERROR : G4ScoringManager::DrawQuantityToFile() --- <" 204 { << 167 << meshName << "> is not found. Nothing is done." << G4endl; 205 G4cerr << "ERROR : G4ScoringManager::DrawQ << 206 << "> is not found. Nothing is done << 207 } 168 } 208 } 169 } 209 170 210 void G4ScoringManager::DumpAllQuantitiesToFile << 171 void G4ScoringManager::DumpAllQuantitiesToFile(G4String meshName,G4String fileName, G4String option) 211 << 212 << 213 { 172 { 214 G4VScoringMesh* mesh = FindMesh(meshName); 173 G4VScoringMesh* mesh = FindMesh(meshName); 215 if(mesh != nullptr) << 174 if(mesh) { 216 { << 217 writer->SetScoringMesh(mesh); 175 writer->SetScoringMesh(mesh); 218 writer->DumpAllQuantitiesToFile(fileName, 176 writer->DumpAllQuantitiesToFile(fileName, option); 219 } << 177 } else { 220 else << 221 { << 222 G4cerr << "ERROR : G4ScoringManager::DrawA 178 G4cerr << "ERROR : G4ScoringManager::DrawAllQuantitiesToFile() --- <" 223 << meshName << "> is not found. Not << 179 << meshName << "> is not found. Nothing is done." << G4endl; 224 } 180 } 225 } 181 } 226 182 227 void G4ScoringManager::RegisterScoreColorMap(G 183 void G4ScoringManager::RegisterScoreColorMap(G4VScoreColorMap* colorMap) 228 { 184 { 229 if(fColorMapDict->find(colorMap->GetName()) << 185 if(fColorMapDict->find(colorMap->GetName()) != fColorMapDict->end()) 230 { 186 { 231 G4cerr << "ERROR : G4ScoringManager::Regis 187 G4cerr << "ERROR : G4ScoringManager::RegisterScoreColorMap -- " 232 << colorMap->GetName() << 188 << colorMap->GetName() << " has already been registered. Method ignored." << G4endl; 233 << " has already been registered. M << 234 } 189 } 235 else 190 else 236 { 191 { 237 (*fColorMapDict)[colorMap->GetName()] = co 192 (*fColorMapDict)[colorMap->GetName()] = colorMap; 238 } 193 } 239 } 194 } 240 195 241 G4VScoreColorMap* G4ScoringManager::GetScoreCo << 196 G4VScoreColorMap* G4ScoringManager::GetScoreColorMap(G4String mapName) 242 { 197 { 243 auto mItr = fColorMapDict->find(mapName); << 198 ColorMapDictItr mItr = fColorMapDict->find(mapName); 244 if(mItr == fColorMapDict->cend()) << 199 if(mItr == fColorMapDict->end()) { return 0; } 245 { << 246 return nullptr; << 247 } << 248 return (mItr->second); 200 return (mItr->second); 249 } 201 } 250 202 251 void G4ScoringManager::ListScoreColorMaps() 203 void G4ScoringManager::ListScoreColorMaps() 252 { 204 { 253 G4cout << "Registered Score Color Maps " << 205 G4cout << "Registered Score Color Maps -------------------------------------------------------" << G4endl; 254 "--------------------------------- << 206 ColorMapDictItr mItr = fColorMapDict->begin(); 255 << G4endl; << 207 for(;mItr!=fColorMapDict->end();mItr++) 256 auto mItr = fColorMapDict->cbegin(); << 208 { G4cout << " " << mItr->first; } 257 for(; mItr != fColorMapDict->cend(); ++mItr) << 258 { << 259 G4cout << " " << mItr->first; << 260 } << 261 G4cout << G4endl; 209 G4cout << G4endl; 262 } 210 } 263 211 264 void G4ScoringManager::Merge(const G4ScoringMa << 212 265 { << 266 for(auto i = 0; i < (G4int)GetNumberOfMesh() << 267 { << 268 G4VScoringMesh* fMesh = GetMesh(i); << 269 G4VScoringMesh* scMesh = mgr->GetMesh(i); << 270 fMesh->Merge(scMesh); << 271 } << 272 } << 273 213