DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4EventSeed.cpp
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : A.Sailer
12 //
13 //=========================================================================
14 
15 //Class include file
16 #include "DDG4/Geant4EventSeed.h"
17 
18 // Framework include files
19 #include "DD4hep/InstanceCount.h"
20 #include "DD4hep/Printout.h"
21 
22 #include "DDG4/Geant4EventAction.h"
23 #include "DDG4/Geant4Random.h"
24 #include "DDG4/Factories.h"
25 
26 #include "CLHEP/Random/EngineFactory.h"
27 
28 //Geant includes
29 #include <G4Run.hh>
30 #include <G4Event.hh>
31 
32 using namespace DD4hep::Simulation;
33 
35 Geant4EventSeed::Geant4EventSeed(Geant4Context* c, const std::string& typ) : Geant4RunAction(c, typ),
36  m_initialSeed(0),
37  m_runID(0),
38  m_type(typ),
39  m_initialised(false)
40 {
44 }
45 
49 }
50 
52 void Geant4EventSeed::begin(const G4Run* run) {
53 
54  if(not m_initialised){
55  m_initialised = true;
57  }
58 
59  m_runID = run->GetRunID();
60 
61  DD4hep::printout( DD4hep::INFO, m_type, "Get RunID: runID=%u", m_runID );
62 
63 }
64 
66 void Geant4EventSeed::beginEvent(const G4Event* evt) {
67 
69 
70  unsigned int eventID = evt->GetEventID();
71  unsigned int newSeed = hash( m_initialSeed, eventID, m_runID );
72 
74  "At beginEvent: eventID=%u, runID=%u initialSeed=%u, newSeed=%u" ,
75  evt->GetEventID(), m_runID, m_initialSeed, newSeed );
76 
77  rndm->setSeed( newSeed );
78 
79  if ( DD4hep::printLevel() <= DD4hep::DEBUG ) {
80  rndm->showStatus();
81  }
82 
83 }
84 
virtual ~Geant4EventSeed()
Default destructor.
void begin(const G4Run *)
begin-of-run callback
#define DECLARE_GEANT4ACTION(name)
Plugin defintion to create Geant4Action objects.
Definition: Factories.h:166
static void decrement(T *)
Decrement count according to type information.
Concrete basic implementation of the Geant4 run action base class.
PrintLevel printLevel()
Access the current printer level.
Definition: Printout.cpp:323
void callAtBegin(Q *p, void(T::*f)(const G4Event *))
Register begin-of-event callback.
void beginEvent(const G4Event *)
begin-of-event callback
static Geant4Random * instance(bool throw_exception=true)
Access the main Geant4 random generator instance. Must be created before used!
void callAtBegin(Q *p, void(T::*f)(const G4Run *))
Register begin-of-run callback. Types Q and T must be polymorph!
virtual void setSeed(long seed)
Should initialise the status of the algorithm according to seed.
unsigned int hash(unsigned int initialSeed, unsigned int eventNumber, unsigned int runNumber)
calculate hash from initialSeed, eventID and runID
CLHEP::HepRandomEngine * engine()
CLHEP random number engine (valid after initialization only)
Definition: Geant4Random.h:117
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
Geant4EventSeed(Geant4Context *, const std::string &)
Standard constructor with initializing arguments.
virtual void showStatus() const
Should dump the current engine status on the screen.
Geant4RunActionSequence & runAction() const
Access to the main run action sequence from the kernel object.
Generic context to extend user, run and event information.
Mini interface to THE random generator of the application.
Definition: Geant4Random.h:60
Geant4EventActionSequence & eventAction() const
Access to the main event action sequence from the kernel object.
int printout(PrintLevel severity, const char *src, const char *fmt,...)
Calls the display action with a given severity level.
Definition: Printout.cpp:111