DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4EventSeed.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : A.Sailer
11 //
12 //=========================================================================
13 
14 // Class include file
15 #include "Geant4EventSeed.h"
16 
17 // Framework include files
18 #include <DD4hep/InstanceCount.h>
19 #include <DD4hep/Printout.h>
20 
21 #include <DDG4/Geant4EventAction.h>
22 #include <DDG4/Geant4Random.h>
23 #include <DDG4/Factories.h>
24 
25 #include <CLHEP/Random/EngineFactory.h>
26 
27 //Geant includes
28 #include <G4Run.hh>
29 #include <G4Event.hh>
30 
31 using namespace dd4hep::sim;
32 
34 Geant4EventSeed::Geant4EventSeed(Geant4Context* c, const std::string& typ) : Geant4RunAction(c, typ),
35  m_initialSeed(0),
36  m_runID(0),
37  m_type(typ),
38  m_initialised(false)
39 {
43 }
44 
48 }
49 
51 void Geant4EventSeed::begin(const G4Run* run) {
52 
53  if(not m_initialised){
54  m_initialised = true;
56  }
57 
58  m_runID = run->GetRunID();
59 
60  dd4hep::printout( dd4hep::INFO, m_type, "Get RunID: runID=%u", m_runID );
61 
62 }
63 
65 void Geant4EventSeed::beginEvent(const G4Event* evt) {
66 
68 
69  unsigned int eventID = evt->GetEventID();
70  unsigned int newSeed = hash( m_initialSeed, eventID, m_runID );
71 
72  dd4hep::printout( dd4hep::INFO, m_type,
73  "At beginEvent: eventID=%u, runID=%u initialSeed=%u, newSeed=%u" ,
74  evt->GetEventID(), m_runID, m_initialSeed, newSeed );
75 
76  rndm->setSeed( newSeed );
77 
78  if ( dd4hep::printLevel() <= dd4hep::DEBUG ) {
79  rndm->showStatus();
80  }
81 
82 }
83 
dd4hep::sim::Geant4Random::instance
static Geant4Random * instance(bool throw_exception=true)
Access the main Geant4 random generator instance. Must be created before used!
Definition: Geant4Random.cpp:113
dd4hep::sim::Geant4Random::engine
CLHEP::HepRandomEngine * engine()
CLHEP random number engine (valid after initialization only)
Definition: Geant4Random.h:116
dd4hep::sim::Geant4EventSeed::begin
void begin(const G4Run *)
begin-of-run callback
Definition: Geant4EventSeed.cpp:51
Geant4EventAction.h
dd4hep::sim::Geant4EventSeed::~Geant4EventSeed
virtual ~Geant4EventSeed()
Default destructor.
Definition: Geant4EventSeed.cpp:46
dd4hep::sim::Geant4RunActionSequence::callAtBegin
void callAtBegin(Q *p, void(T::*f)(const G4Run *))
Register begin-of-run callback. Types Q and T must be polymorph!
Definition: Geant4RunAction.h:144
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::sim::Geant4EventSeed
Plugin class to set the event seed for each event.
Definition: Geant4EventSeed.h:53
DECLARE_GEANT4ACTION
#define DECLARE_GEANT4ACTION(name)
Plugin defintion to create Geant4Action objects.
Definition: Factories.h:210
dd4hep::sim::Geant4EventSeed::Geant4EventSeed
Geant4EventSeed(Geant4Context *, const std::string &)
Standard constructor with initializing arguments.
Definition: Geant4EventSeed.cpp:34
dd4hep::sim::Geant4Random::setSeed
virtual void setSeed(long seed)
Should initialise the status of the algorithm according to seed.
Definition: Geant4Random.cpp:199
dd4hep::sim::Geant4Action::eventAction
Geant4EventActionSequence & eventAction() const
Access to the main event action sequence from the kernel object.
Definition: Geant4Action.cpp:283
dd4hep::sim::Geant4EventSeed::m_initialSeed
unsigned int m_initialSeed
Definition: Geant4EventSeed.h:56
Geant4Random.h
dd4hep::sim::Geant4EventActionSequence::callAtBegin
void callAtBegin(Q *p, void(T::*f)(const G4Event *))
Register begin-of-event callback.
Definition: Geant4EventAction.h:152
dd4hep::sim::Geant4Random::showStatus
virtual void showStatus() const
Should dump the current engine status on the screen.
Definition: Geant4Random.cpp:230
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::Geant4EventSeed::beginEvent
void beginEvent(const G4Event *)
begin-of-event callback
Definition: Geant4EventSeed.cpp:65
dd4hep::sim::Geant4Random
Mini interface to THE random generator of the application.
Definition: Geant4Random.h:59
dd4hep::sim::Geant4Action::runAction
Geant4RunActionSequence & runAction() const
Access to the main run action sequence from the kernel object.
Definition: Geant4Action.cpp:278
Factories.h
Geant4EventSeed.h
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::Geant4EventSeed::m_runID
unsigned int m_runID
Definition: Geant4EventSeed.h:57
dd4hep::sim::Geant4RunAction
Concrete basic implementation of the Geant4 run action base class.
Definition: Geant4RunAction.h:45
dd4hep::sim::hash
unsigned int hash(unsigned int initialSeed, unsigned int eventNumber, unsigned int runNumber)
calculate hash from initialSeed, eventID and runID
Definition: Geant4EventSeed.h:201
dd4hep::sim::Geant4EventSeed::m_type
std::string m_type
Definition: Geant4EventSeed.h:58
InstanceCount.h
Printout.h
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4EventSeed::m_initialised
bool m_initialised
Definition: Geant4EventSeed.h:59