12#include "GaudiKernel/SvcFactory.h"
13#include "GaudiKernel/ISvcLocator.h"
14#include "GaudiKernel/MsgStream.h"
20 #include "G4VisExecutive.hh"
25#include "G4UIsession.hh"
26#include "G4UIterminal.hh"
27#include "G4RunManager.hh"
38 Service( name, svc ), p_runMgr(0), p_uiMgr(0), p_visMgr(0),
39 _init(
false), m_beamTime(0)
43 declareProperty(
"Visualize", m_vis=
false);
46 declareProperty(
"RunVerbosity", m_runVerb=0);
47 declareProperty(
"EventVerbosity", m_eventVerb=0);
48 declareProperty(
"TrackingVerbosity", m_trackVerb=0);
50 declareProperty(
"FADSmacro",m_macroName=
"none" );
51 declareProperty(
"MdcNoiseFile", m_mdcNoiseFile=
"none");
55 declareProperty(
"LogLevel", m_logLevel=6);
57 declareProperty(
"InteractiveG4" , m_interactiveG4=
false);
59 declareProperty(
"BesGenAction", m_besGenAction=
false);
61 declareProperty(
"BeamPosX",m_beamPosX=0);
62 declareProperty(
"BeamPosY",m_beamPosY=0);
63 declareProperty(
"BeamPosZ",m_beamPosZ=0);
65 declareProperty(
"BeamSizeX", m_beamSizeX=10);
66 declareProperty(
"BeamSizeY", m_beamSizeY=20);
67 declareProperty(
"BeamSizeZ", m_beamSizeZ=30);
69 declareProperty(
"BeamStartTime",m_beamStartTime=0);
70 declareProperty(
"BeamDeltaTime",m_beamDeltaTime=0);
71 declareProperty(
"NBunch",m_nBunch=1);
73 declareProperty(
"BunchTimeSigma",m_bunchTimeSigma=0);
75 declareProperty(
"MdcDataInput",m_mdcDataInput=1);
76 declareProperty(
"MdcDedxFlag",m_mdcDedxFlag=1);
78 declareProperty(
"BoostLab",m_boostLab=
false);
79 declareProperty(
"BeamAngle",m_beamAngle=11);
81 declareProperty(
"SetBeamShift",m_setBeamShift=
false);
82 declareProperty(
"BeamShiftPx" ,m_beamShiftPx=39.45);
83 declareProperty(
"BeamShiftPy" ,m_beamShiftPy=-0.98);
84 declareProperty(
"BeamShiftPz" ,m_beamShiftPz=3.70);
86 declareProperty(
"MdcRootFlag",m_mdcRootFlag=
false);
87 declareProperty(
"TofRootFlag",m_tofRootFlag=
false);
88 declareProperty(
"EmcRootFlag",m_emcRootFlag=
false);
89 declareProperty(
"MucRootFlag",m_mucRootFlag=
false);
92 declareProperty(
"TofSaturationFlag",m_tofSaturationFlag=
true);
94 declareProperty(
"EmcLightOutput",m_emcLightOutput=
true);
95 declareProperty(
"EmcIncoherentNoise",m_emcIncoherentNoise=0.2);
96 declareProperty(
"EmcCoherentNoise",m_emcCoherentNoise=0.);
97 declareProperty(
"EmcNoiseMean",m_emcNoiseMean=1.16);
98 declareProperty(
"EmcNoiseSigma",m_emcNoiseSigma=0.23);
99 declareProperty(
"EmcNoiseThreshold",m_emcNoiseThreshold=0.5);
100 declareProperty(
"EmcNoiseLevel",m_emcNoiseLevel=3);
101 declareProperty(
"EmcTime",m_emcTime=20);
102 declareProperty(
"EmcELecSaturation",m_emcELecSaturation=1);
103 declareProperty(
"EmcELecSatuDead",m_emcELecSatuDead=0);
104 declareProperty(
"MucNoiseMode", m_mucNoiseMode=1);
125 MsgStream log(
msgSvc(), name() );
129 p_runMgr->SetLogLevel( m_logLevel );
142 MsgStream log(
msgSvc(), name() );
144 StatusCode status = Service::initialize();
145 log << MSG::INFO <<
"Service initialized" << endreq;
149 status = service(
"RealizationSvc", tmpReal);
150 if (!status.isSuccess())
152 log << MSG::ERROR <<
" Could not initialize Realization Service" << endreq;
155 log << MSG::INFO <<
"got the RealizationSvc" << endreq;
159 m_runID = m_RealizationSvc->
getRunId();
169 MsgStream log(
msgSvc(), name() );
170 StatusCode status = Service::finalize();
172 if ( status.isSuccess() )
173 log << MSG::INFO <<
"Service finalised successfully" << endreq;
180 void** ppvInterface ) {
181 StatusCode sc = StatusCode::FAILURE;
183 if (riid == IID_IG4Svc) {
184 *ppvInterface =
dynamic_cast<IG4Svc*
>(
this);
185 sc = StatusCode::SUCCESS;
187 sc = Service::queryInterface( riid, ppvInterface );
195 const G4Event *evt = p_runMgr->GetCurrentEvent();
198 MsgStream log(
msgSvc(), name() );
199 log << MSG::ERROR <<
"Could not get current G4Event" << endreq;
209 return ( p_runMgr->GetCurrentRun() );
216 p_uiMgr = G4UImanager::GetUIpointer();
225 p_runMgr->SetUserInitialization(userInit);
233 p_runMgr->SetUserInitialization(userInit);
241 p_runMgr->SetUserAction(action);
248 p_runMgr->SetUserAction(action);
256 p_runMgr->SetUserAction( action );
263 p_runMgr->SetUserAction(action);
270 p_runMgr->SetUserAction(action);
277 p_runMgr->SetUserAction(action);
285 MsgStream log(
msgSvc(), name() );
286 log << MSG::DEBUG <<
"Starting G4 terminal" << endreq;
288 G4UIsession * ses =
new G4UIterminal(
new G4UItcsh);
298 MsgStream log(
msgSvc(), name() );
300 log << MSG::VERBOSE <<
"Attempting G4 Initialization" << endreq;
312 log << MSG::INFO <<
"Initializing G4SvcVisManager" << endreq;
314 p_visMgr =
new G4VisExecutive;
315 p_visMgr->Initialize();
322 log << MSG::INFO <<
"Not including Visualization" << endreq;
326 log << MSG::DEBUG <<
"Setting verbosity levels - "
327 <<
"run: " << m_runVerb <<
" event: " << m_eventVerb
328 <<
" track: " << m_trackVerb << endreq;
332 ost <<
"/run/verbose " << m_runVerb << std::ends;
333 uiMgr()->ApplyCommand(ost.str());
337 ost <<
"/event/verbose " << m_eventVerb << std::ends;
338 uiMgr()->ApplyCommand(ost.str());
342 ost <<
"/tracking/verbose " << m_trackVerb << std::ends;
343 uiMgr()->ApplyCommand(ost.str());
346 log << MSG::DEBUG <<
"Initializing G4 kernel" << endreq;
347 p_runMgr->Initialize();
350 if (m_macroName!=
"none"){
351 log << MSG::INFO <<
"Running G4 macro "<<m_macroName<< endreq;
352 uiMgr()->ApplyCommand(
"/control/execute "+m_macroName);
354 if (m_interactiveG4) {
359 log << MSG::ERROR <<
"G4 kernel already initialized" << endreq;
366 bool cond = p_runMgr->ConfirmBeamOnCondition();
369 std::cout<<
"########### initializing the G4Run ############"<<
371 p_runMgr->SetRunIDCounter( -std::abs(m_runID) );
372 p_runMgr->RunInitialization();
378 p_runMgr->RunTermination();
void SimulateEvent(int i)
virtual StatusCode initialize()
const G4Event * GetCurrentEvent() const
G4Svc(const std::string &name, ISvcLocator *svc)
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
void SetUserInitialization(G4VUserDetectorConstruction *userInit)
virtual StatusCode finalize()
const G4Run * GetCurrentRun() const
void SetUserAction(G4UserRunAction *)