G4ScoringManager.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 
00030 #include "G4ScoringManager.hh"
00031 #include "G4ScoringMessenger.hh"
00032 #include "G4ScoreQuantityMessenger.hh"
00033 #include "G4VScoringMesh.hh"
00034 #include "G4THitsMap.hh"
00035 #include "G4VScoreColorMap.hh"
00036 #include "G4DefaultLinearColorMap.hh"
00037 #include "G4ScoreLogColorMap.hh"
00038 
00039 G4ScoringManager* G4ScoringManager::fSManager = 0;
00040 
00041 G4int G4ScoringManager::replicaLevel = 3;
00042 
00043 G4ScoringManager* G4ScoringManager::GetScoringManager()
00044 {
00045   if(!fSManager)
00046   {
00047     fSManager = new G4ScoringManager;
00048   }
00049   return fSManager;
00050 }
00051 
00052 G4ScoringManager* G4ScoringManager::GetScoringManagerIfExist()
00053 { return fSManager; }
00054 
00055 G4ScoringManager::G4ScoringManager()
00056   : verboseLevel(0),fCurrentMesh(0)
00057 {
00058   fMessenger = new G4ScoringMessenger(this);
00059   fQuantityMessenger = new G4ScoreQuantityMessenger(this);
00060   fColorMapDict = new ColorMapDict();
00061   fDefaultLinearColorMap = new G4DefaultLinearColorMap("defaultLinearColorMap");
00062   (*fColorMapDict)[fDefaultLinearColorMap->GetName()] = fDefaultLinearColorMap;
00063   G4VScoreColorMap * logColorMap = new G4ScoreLogColorMap("logColorMap");
00064   (*fColorMapDict)[logColorMap->GetName()] = logColorMap;
00065   writer = new G4VScoreWriter();
00066 }
00067 
00068 G4ScoringManager::~G4ScoringManager()
00069 {
00070   if (writer) { delete writer; }
00071   delete fDefaultLinearColorMap;
00072   delete fColorMapDict;
00073   delete fQuantityMessenger;
00074   delete fMessenger;
00075   delete fSManager;
00076 }
00077 
00078 void G4ScoringManager::SetReplicaLevel(G4int lvl)
00079 { replicaLevel = lvl; }
00080 G4int G4ScoringManager::GetReplicaLevel()
00081 { return replicaLevel; }
00082 
00083 void G4ScoringManager::Accumulate(G4VHitsCollection* map)
00084 {
00085   G4String wName = map->GetSDname();
00086   G4VScoringMesh* sm = FindMesh(wName);
00087   if(sm == 0) return;
00088   if(verboseLevel>9)
00089   { G4cout << "G4ScoringManager::Accumulate() for " << map->GetSDname() << " / " << map->GetName() << G4endl;
00090     G4cout << "  is calling G4VScoringMesh::Accumulate() of " << sm->GetWorldName() << G4endl; }
00091   sm->Accumulate(static_cast<G4THitsMap<double>*>(map));
00092 }
00093 
00094 G4VScoringMesh* G4ScoringManager::FindMesh(const G4String& wName)
00095 {
00096   G4VScoringMesh* sm = 0;
00097   for(MeshVecItr itr = fMeshVec.begin(); itr != fMeshVec.end(); itr++) {
00098     G4String smName = (*itr)->GetWorldName();
00099     if(wName == smName) {
00100       sm = *itr;
00101       break;
00102     }
00103   }
00104   if(!sm && verboseLevel>9)
00105   { G4cout << "WARNING : G4ScoringManager::FindMesh() --- <" << wName << "> is not found. Null returned." << G4endl; }
00106 
00107   return sm;
00108 }
00109 
00110 void G4ScoringManager::List() const
00111 {
00112   G4cout << "G4ScoringManager has " << GetNumberOfMesh() << " scoring meshes." << G4endl;
00113   for(MeshVecConstItr itr = fMeshVec.begin(); itr != fMeshVec.end(); itr++) {
00114    (*itr)->List();
00115   }
00116 }
00117 
00118 void G4ScoringManager::Dump() const
00119 {
00120   for(MeshVecConstItr itr = fMeshVec.begin(); itr != fMeshVec.end(); itr++) {
00121    (*itr)->Dump();
00122   }
00123 }
00124 
00125 void G4ScoringManager::DrawMesh(const G4String& meshName,
00126                                 const G4String& psName,
00127                                 const G4String& colorMapName, G4int axflg)
00128 {
00129   G4VScoringMesh* mesh = FindMesh(meshName);
00130   if(mesh) 
00131   {
00132     G4VScoreColorMap* colorMap = GetScoreColorMap(colorMapName);
00133     if(!colorMap)
00134     {
00135       G4cerr << "WARNING : Score color map <" << colorMapName << "> is not found. Default linear color map is used." << G4endl;
00136       colorMap = fDefaultLinearColorMap;
00137     }
00138     mesh->DrawMesh(psName,colorMap,axflg);
00139   } else {
00140     G4cerr << "ERROR : G4ScoringManager::DrawMesh() --- <"
00141            << meshName << "> is not found. Nothing is done." << G4endl;
00142   }
00143 }
00144 
00145 void G4ScoringManager::DrawMesh(const G4String& meshName,
00146                                 const G4String& psName,
00147                                       G4int idxPlane, G4int iColumn,
00148                                 const G4String& colorMapName)
00149 {
00150   G4VScoringMesh* mesh = FindMesh(meshName);
00151   if(mesh) 
00152   {
00153     G4VScoreColorMap* colorMap = GetScoreColorMap(colorMapName);
00154     if(!colorMap)
00155     {
00156       G4cerr << "WARNING : Score color map <" << colorMapName << "> is not found. Default linear color map is used." << G4endl;
00157       colorMap = fDefaultLinearColorMap;
00158     }
00159     mesh->DrawMesh(psName,idxPlane,iColumn,colorMap);
00160   } else {
00161     G4cerr << "ERROR : G4ScoringManager::DrawMesh() --- <"
00162            << meshName << "> is not found. Nothing is done." << G4endl;
00163   }
00164 }
00165 
00166 void G4ScoringManager::DumpQuantityToFile(const G4String& meshName,
00167                                           const G4String& psName,
00168                                           const G4String& fileName,
00169                                           const G4String& option)
00170 {
00171   G4VScoringMesh* mesh = FindMesh(meshName);
00172   if(mesh) {
00173     writer->SetScoringMesh(mesh);
00174     writer->DumpQuantityToFile(psName, fileName, option);
00175   } else {
00176     G4cerr << "ERROR : G4ScoringManager::DrawQuantityToFile() --- <"
00177            << meshName << "> is not found. Nothing is done." << G4endl;
00178   }
00179 }
00180 
00181 void G4ScoringManager::DumpAllQuantitiesToFile(const G4String& meshName,
00182                                                const G4String& fileName,
00183                                                const G4String& option)
00184 {
00185   G4VScoringMesh* mesh = FindMesh(meshName);
00186   if(mesh) {
00187     writer->SetScoringMesh(mesh);
00188     writer->DumpAllQuantitiesToFile(fileName, option);
00189   } else {
00190     G4cerr << "ERROR : G4ScoringManager::DrawAllQuantitiesToFile() --- <"
00191            << meshName << "> is not found. Nothing is done." << G4endl;
00192   }
00193 }
00194 
00195 void G4ScoringManager::RegisterScoreColorMap(G4VScoreColorMap* colorMap)
00196 {
00197   if(fColorMapDict->find(colorMap->GetName()) != fColorMapDict->end())
00198   {
00199     G4cerr << "ERROR : G4ScoringManager::RegisterScoreColorMap -- "
00200            << colorMap->GetName() << " has already been registered. Method ignored." << G4endl;
00201   }
00202   else
00203   {
00204     (*fColorMapDict)[colorMap->GetName()] = colorMap;
00205   }
00206 }
00207 
00208 G4VScoreColorMap* G4ScoringManager::GetScoreColorMap(const G4String& mapName)
00209 {
00210   ColorMapDictItr mItr = fColorMapDict->find(mapName);
00211   if(mItr == fColorMapDict->end()) { return 0; }
00212   return (mItr->second);
00213 }
00214 
00215 void G4ScoringManager::ListScoreColorMaps()
00216 {
00217   G4cout << "Registered Score Color Maps -------------------------------------------------------" << G4endl;
00218   ColorMapDictItr mItr = fColorMapDict->begin();
00219   for(;mItr!=fColorMapDict->end();mItr++)
00220   { G4cout << "   " << mItr->first; }
00221   G4cout << G4endl;
00222 }
00223 
00224 

Generated on Mon May 27 17:49:48 2013 for Geant4 by  doxygen 1.4.7