Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/Geant4/G4VPrimitiveScorer.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 // G4VPrimitiveScorer
0027 //
0028 // Class description:
0029 //
0030 // This is the base class of the sensitive detector which owns
0031 // only one hits collection.
0032 // A concrete class object derived from this base class can be
0033 // used either as a sensitive detector or to be registered to
0034 // G4MultiFunctionalDetector to define multiple functionalities.
0035 //
0036 // Author: Makoto Asai
0037 // --------------------------------------------------------------------
0038 #ifndef G4VPrimitiveScorer_h
0039 #define G4VPrimitiveScorer_h 1
0040 
0041 #include "G4MultiFunctionalDetector.hh"
0042 #include "G4VSDFilter.hh"
0043 #include "globals.hh"
0044 
0045 #include <functional>
0046 
0047 class G4Step;
0048 class G4HCofThisEvent;
0049 class G4TouchableHistory;
0050 
0051 // Define the signature for the weighting calculation
0052 // It should take: (const G4Step*) and return G4double
0053 using G4ScoreWeightCalculator = std::function<G4double(const G4Step*)>;
0054 
0055 class G4VPrimitiveScorer
0056 {
0057   friend class G4MultiFunctionalDetector;
0058 
0059  public:
0060   G4VPrimitiveScorer(const G4String& name, G4int depth = 0);
0061   virtual ~G4VPrimitiveScorer() = default;
0062 
0063   // This method returns the ID of its hitsCollection. This mehod
0064   // gives valid value only after it is registered to G4MultiFunctionalDetector
0065   // and the G4MultiFunctionalDetector is registered to G4SDManager.
0066   G4int GetCollectionID(G4int);
0067 
0068   // These five methods are exactly identical to those in G4VSensitiveDetector.
0069   // These methods are invoked by G4SDManager through G4MultiFunctionalDetector.
0070   virtual void Initialize(G4HCofThisEvent*);
0071   virtual void EndOfEvent(G4HCofThisEvent*);
0072   virtual void clear();
0073   virtual void DrawAll();
0074   virtual void PrintAll();
0075 
0076   void SetUnit(const G4String& unit) { unitName = unit; }
0077   const G4String& GetUnit() const { return unitName; }
0078   G4double GetUnitValue() const { return unitValue; }
0079 
0080   inline void ScoreWeighted(G4bool flg = false) { scoreWeighted = flg; }
0081   // Use specific weight for scoring
0082 
0083   inline G4bool IsScoreWeighted() const { return scoreWeighted; }
0084   // Get option for specific weight for scoring
0085 
0086   // Set/Get methods
0087   inline void SetMultiFunctionalDetector(G4MultiFunctionalDetector* d) { detector = d; }
0088   inline G4MultiFunctionalDetector* GetMultiFunctionalDetector() const { return detector; }
0089   inline const G4String& GetName() const { return primitiveName; }
0090   inline void SetFilter(G4VSDFilter* f) { filter = f; }
0091   inline G4VSDFilter* GetFilter() const { return filter; }
0092   inline void SetScoreWeightCalculator(G4ScoreWeightCalculator calculator) {
0093     fScoreWeightCalculator = calculator;
0094   }
0095 
0096   inline void SetVerboseLevel(G4int vl) { verboseLevel = vl; }
0097   inline G4int GetVerboseLevel() const { return verboseLevel; }
0098 
0099   inline void SetNijk(G4int i, G4int j, G4int k)
0100   {
0101     fNi = i;
0102     fNj = j;
0103     fNk = k;
0104   }
0105 
0106  protected:
0107   // Get the solid at current depth, ensuring it's correct by
0108   //   calling a parameterisation is called if it's that volume type
0109   G4VSolid* ComputeSolid(G4Step* aStep, G4int replicaIdx);
0110 
0111   // Same as above -- using stored replica number
0112   G4VSolid* ComputeCurrentSolid(G4Step* aStep);
0113 
0114   // This is the method must be implemented in each concrete class.
0115   virtual G4bool ProcessHits(G4Step*, G4TouchableHistory*) = 0;
0116 
0117   // This is a function mapping from copy number(s) to an index of
0118   // the hit collection. In the default implementation, just the
0119   // copy number of the physical volume is taken.
0120   virtual G4int GetIndex(G4Step*);
0121 
0122   void CheckAndSetUnit(const G4String& unit, const G4String& category);
0123 
0124  protected:
0125   G4String primitiveName;
0126   G4MultiFunctionalDetector* detector{nullptr};
0127   G4VSDFilter* filter{nullptr};
0128   G4int verboseLevel{0};
0129   G4int indexDepth;
0130   G4String unitName{"NoUnit"};
0131   G4double unitValue{1.0};
0132   G4int fNi{0}, fNj{0}, fNk{0};  // used for 3D scorers
0133   G4bool scoreWeighted{false};
0134   G4ScoreWeightCalculator fScoreWeightCalculator = [](const G4Step*) -> G4double {
0135     return 1.0;
0136   };
0137 
0138  private:
0139   inline G4bool HitPrimitive(G4Step* aStep, G4TouchableHistory* ROhis)
0140   {
0141     if (filter != nullptr) {
0142       if (! (filter->Accept(aStep))) return false;
0143     }
0144     return ProcessHits(aStep, ROhis);
0145   }
0146 };
0147 
0148 #endif