BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
G4SvcRunManager.cpp
Go to the documentation of this file.
1//------------------------------------------------------------------
2//
3// ClassName: G4SvcRunManager
4//
5// Description: replacement G4RunManager with extra features
6//
7// $Id: G4SvcRunManager.cpp,v 1.13 2011/02/15 01:05:25 dengzy Exp $
8// Simulation/G4Sim/G4Svc tag $Name: G4Svc-00-01-56 $
9
12#include "G4ios.hh"
13#include "G4Event.hh"
14#include "G4VHit.hh"
15#include "G4HCofThisEvent.hh"
16#include "G4VHitsCollection.hh"
17#include "G4THitsCollection.hh"
18#include "G4VUserDetectorConstruction.hh"
19#include "G4VUserPhysicsList.hh"
20#include "G4SDManager.hh"
21#include "G4PrimaryParticle.hh"
22
23#include "G4TrajectoryContainer.hh"
24#include "G4Trajectory.hh"
25
26#include "GaudiKernel/System.h"
27#include "GaudiKernel/IMessageSvc.h"
28
29//#include "FadsKinematics/GeneratorCenter.hh"
30#include "G4VUserPrimaryGeneratorAction.hh"
31
32#include <iostream>
33#include <string>
34#include <vector>
35
36//*************************************************************************//
37
39 G4RunManager(),
40 m_logLevel(6) {
41}
42
43//*************************************************************************//
44
46}
47
48G4Event* G4SvcRunManager::GenerateEvent(G4int i_event)
49{
50 G4Event* anEvent = new G4Event(i_event);
51
52 if(!userPrimaryGeneratorAction)
53 {
54 if(m_logLevel<=4)
55 std::cout<<"calling the hepmc interface"<<std::endl;
56 BesHepMCInterface* hepmcInterface = new BesHepMCInterface;
57 hepmcInterface->SetLogLevel(m_logLevel);
58 HepMC::GenEvent* hepmcEvent = hepmcInterface->GenerateHepMCEvent();
59 if(m_logLevel<=4)
60 std::cout<<"got the hepmcEvent"<<std::endl;
61 hepmcInterface->HepMC2G4(hepmcEvent, anEvent);
62 delete hepmcInterface;
63 if(m_logLevel<=4)
64 PrintPrimary(anEvent);
65
66 }
67 else{
68 if(storeRandomNumberStatus) {
69 G4String fileN = randomNumberStatusDir + "currentEvent.rndm";
70 CLHEP::HepRandom::saveEngineStatus(fileN);
71 }
72 userPrimaryGeneratorAction->GeneratePrimaries(anEvent);
73 }
74 return anEvent;
75}
76
77void G4SvcRunManager::PrintPrimary(G4Event* anEvent)
78{
79 G4cout<<G4endl<<"primary particles of this event: "<<G4endl;
80 G4int n_vertex = anEvent->GetNumberOfPrimaryVertex();
81 for( G4int i=0; i<n_vertex; i++ )
82 {
83 G4cout<<"vertex:"<<i<<G4endl;
84 G4PrimaryVertex* primaryVertex = anEvent->GetPrimaryVertex(i);
85 G4PrimaryParticle* primaryParticle = primaryVertex->GetPrimary();
86 G4cout<<"PDGCode:";
87 while( primaryParticle != 0 )
88 {
89 G4int PDGcode = primaryParticle->GetPDGcode();
90 G4cout<<PDGcode<<" ";
91 primaryParticle = primaryParticle->GetNext();
92 }
93 G4cout<<G4endl;
94 }
95 G4cout<<G4endl;
96}
98{
99 //G4StateManager* stateManager = G4StateManager::GetStateManager();
100 //stateManager->SetNewState(G4State_EventProc);
101 currentEvent = GenerateEvent(i);
102 eventManager->ProcessOneEvent(currentEvent);
103 AnalyzeEvent(currentEvent);
104 //stateManager->SetNewState(G4State_GeomClosed);
105 StackPreviousEvent(currentEvent);
106 currentEvent = 0;
107 if(m_logLevel<=4)
108 std::cout<<"SimulateEvent : done simulating one event "<<std::endl<<std::endl;
109}
110
111
112
HepMC::GenEvent * GenerateHepMCEvent()
void HepMC2G4(HepMC::GenEvent *hepmcevt, G4Event *g4event)
void SetLogLevel(G4int level)
void PrintPrimary(G4Event *anEvent)
void SimulateEvent(int i)
G4Event * GenerateEvent(G4int i_event)
virtual ~G4SvcRunManager()