Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:59:23

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4ScoringManager
0027 //
0028 // Class description:
0029 //
0030 // This is a singleton class which manages the interactive scoring.
0031 // The user cannot access to the constructor. The pointer of the
0032 // only existing object can be got via G4ScoringManager::GetScoringManager()
0033 // static method. The first invocation of this static method makes
0034 // the singleton object.
0035 //
0036 // Author: Makoto Asai
0037 // --------------------------------------------------------------------
0038 #ifndef G4ScoringManager_h
0039 #define G4ScoringManager_h 1
0040 
0041 #include "globals.hh"
0042 #include "G4VScoringMesh.hh"
0043 #include "G4VScoreWriter.hh"
0044 
0045 #include <vector>
0046 #include <map>
0047 
0048 class G4ScoringMessenger;
0049 class G4ScoreQuantityMessenger;
0050 class G4VHitsCollection;
0051 class G4VScoreColorMap;
0052 
0053 using MeshVec = std::vector<G4VScoringMesh *>;
0054 using MeshVecItr = MeshVec::iterator;
0055 using MeshVecConstItr = MeshVec::const_iterator;
0056 using ColorMapDict = std::map<G4String, G4VScoreColorMap *>;
0057 using ColorMapDictItr = ColorMapDict::iterator;
0058 using ColorMapDictConstItr = ColorMapDict::const_iterator;
0059 using MeshMap = std::map<G4int, G4VScoringMesh *>;
0060 using MeshMapItr = MeshMap::iterator;
0061 using MeshMapConstItr = MeshMap::const_iterator;
0062 
0063 class G4ScoringManager
0064 {
0065  public:
0066 
0067   static G4ScoringManager* GetScoringManager();
0068   // Returns the pointer to the singleton object.
0069   
0070   static G4ScoringManager* GetScoringManagerIfExist();
0071 
0072   G4ScoringManager(const G4ScoringManager&) = delete;
0073   G4ScoringManager& operator=(const G4ScoringManager&) = delete;
0074 
0075   ~G4ScoringManager();
0076 
0077   static void SetReplicaLevel(G4int);
0078   static G4int GetReplicaLevel();
0079 
0080   void RegisterScoreColorMap(G4VScoreColorMap* colorMap);
0081   // Register a color map. Once registered, it is available by /score/draw and
0082   // /score/drawColumn commands.
0083 
0084   void Accumulate(G4VHitsCollection* map);
0085   void Merge(const G4ScoringManager* scMan);
0086   G4VScoringMesh* FindMesh(G4VHitsCollection* map);
0087   G4VScoringMesh* FindMesh(const G4String&);
0088   void List() const;
0089   void Dump() const;
0090   void DrawMesh(const G4String& meshName, const G4String& psName,
0091                 const G4String& colorMapName, G4int axflg = 111);
0092   void DrawMesh(const G4String& meshName, const G4String& psName,
0093                 G4int idxPlane, G4int iColumn, const G4String& colorMapName);
0094   void DumpQuantityToFile(const G4String& meshName, const G4String& psName,
0095                           const G4String& fileName,
0096                           const G4String& option = "");
0097   void DumpAllQuantitiesToFile(const G4String& meshName,
0098                                const G4String& fileName,
0099                                const G4String& option = "");
0100   G4VScoreColorMap* GetScoreColorMap(const G4String& mapName);
0101   void ListScoreColorMaps();
0102 
0103   inline void SetCurrentMesh(G4VScoringMesh* scm) { fCurrentMesh = scm; }
0104   inline G4VScoringMesh* GetCurrentMesh() const { return fCurrentMesh; }
0105   inline void CloseCurrentMesh() { fCurrentMesh = nullptr; }
0106   inline void SetVerboseLevel(G4int vl)
0107   {
0108     verboseLevel = vl;
0109     for(auto& itr : fMeshVec)
0110     {
0111       itr->SetVerboseLevel(vl);
0112     }
0113     if(writer != nullptr)
0114       writer->SetVerboseLevel(vl);
0115   }
0116   inline G4int GetVerboseLevel() const { return verboseLevel; }
0117   inline std::size_t GetNumberOfMesh() const { return fMeshVec.size(); }
0118   inline void RegisterScoringMesh(G4VScoringMesh* scm)
0119   {
0120     scm->SetVerboseLevel(verboseLevel);
0121     fMeshVec.push_back(scm);
0122     SetCurrentMesh(scm);
0123   }
0124   inline G4VScoringMesh* GetMesh(G4int i) const { return fMeshVec[i]; }
0125   inline const G4String& GetWorldName(G4int i) const
0126   {
0127     return fMeshVec[i]->GetWorldName();
0128   }
0129 
0130   inline void SetScoreWriter(G4VScoreWriter* sw)
0131   {
0132     delete writer;
0133     writer = sw;
0134     if(writer != nullptr)
0135       writer->SetVerboseLevel(verboseLevel);
0136   }
0137   // Replace score writers.
0138 
0139   inline void SetFactor(G4double val = 1.0)
0140   {
0141     if(writer != nullptr)
0142       writer->SetFactor(val);
0143   }
0144   inline G4double GetFactor() const
0145   {
0146     if(writer != nullptr)
0147     {
0148       return writer->GetFactor();
0149     }
0150     
0151     return -1.0;
0152   }
0153 
0154  protected:
0155 
0156   G4ScoringManager();
0157 
0158  private:
0159 
0160   static G4ThreadLocal G4ScoringManager* fSManager;
0161   static G4ThreadLocal G4int replicaLevel;
0162 
0163   G4int verboseLevel;
0164   G4ScoringMessenger* fMessenger;
0165   G4ScoreQuantityMessenger* fQuantityMessenger;
0166 
0167   MeshVec fMeshVec;
0168   G4VScoringMesh* fCurrentMesh;
0169 
0170   G4VScoreWriter* writer;
0171   G4VScoreColorMap* fDefaultLinearColorMap;
0172   ColorMapDict* fColorMapDict;
0173 
0174   MeshMap fMeshMap;
0175 };
0176 
0177 #endif