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);
103 declareProperty(
"MucNoiseMode", m_mucNoiseMode=1);
124 MsgStream log(
msgSvc(), name() );
128 p_runMgr->SetLogLevel( m_logLevel );
141 MsgStream log(
msgSvc(), name() );
143 StatusCode status = Service::initialize();
144 log << MSG::INFO <<
"Service initialized" << endreq;
148 status = service(
"RealizationSvc", tmpReal);
149 if (!status.isSuccess())
151 log << MSG::ERROR <<
" Could not initialize Realization Service" << endreq;
154 log << MSG::INFO <<
"got the RealizationSvc" << endreq;
158 m_runID = m_RealizationSvc->
getRunId();
168 MsgStream log(
msgSvc(), name() );
169 StatusCode status = Service::finalize();
171 if ( status.isSuccess() )
172 log << MSG::INFO <<
"Service finalised successfully" << endreq;
179 void** ppvInterface ) {
180 StatusCode sc = StatusCode::FAILURE;
182 if (riid == IID_IG4Svc) {
183 *ppvInterface =
dynamic_cast<IG4Svc*
>(
this);
184 sc = StatusCode::SUCCESS;
186 sc = Service::queryInterface( riid, ppvInterface );
194 const G4Event *evt = p_runMgr->GetCurrentEvent();
197 MsgStream log(
msgSvc(), name() );
198 log << MSG::ERROR <<
"Could not get current G4Event" << endreq;
208 return ( p_runMgr->GetCurrentRun() );
215 p_uiMgr = G4UImanager::GetUIpointer();
224 p_runMgr->SetUserInitialization(userInit);
232 p_runMgr->SetUserInitialization(userInit);
240 p_runMgr->SetUserAction(action);
247 p_runMgr->SetUserAction(action);
255 p_runMgr->SetUserAction( action );
262 p_runMgr->SetUserAction(action);
269 p_runMgr->SetUserAction(action);
276 p_runMgr->SetUserAction(action);
284 MsgStream log(
msgSvc(), name() );
285 log << MSG::DEBUG <<
"Starting G4 terminal" << endreq;
287 G4UIsession * ses =
new G4UIterminal(
new G4UItcsh);
297 MsgStream log(
msgSvc(), name() );
299 log << MSG::VERBOSE <<
"Attempting G4 Initialization" << endreq;
311 log << MSG::INFO <<
"Initializing G4SvcVisManager" << endreq;
313 p_visMgr =
new G4VisExecutive;
314 p_visMgr->Initialize();
321 log << MSG::INFO <<
"Not including Visualization" << endreq;
325 log << MSG::DEBUG <<
"Setting verbosity levels - "
326 <<
"run: " << m_runVerb <<
" event: " << m_eventVerb
327 <<
" track: " << m_trackVerb << endreq;
331 ost <<
"/run/verbose " << m_runVerb << std::ends;
332 uiMgr()->ApplyCommand(ost.str());
336 ost <<
"/event/verbose " << m_eventVerb << std::ends;
337 uiMgr()->ApplyCommand(ost.str());
341 ost <<
"/tracking/verbose " << m_trackVerb << std::ends;
342 uiMgr()->ApplyCommand(ost.str());
345 log << MSG::DEBUG <<
"Initializing G4 kernel" << endreq;
346 p_runMgr->Initialize();
349 if (m_macroName!=
"none"){
350 log << MSG::INFO <<
"Running G4 macro "<<m_macroName<< endreq;
351 uiMgr()->ApplyCommand(
"/control/execute "+m_macroName);
353 if (m_interactiveG4) {
358 log << MSG::ERROR <<
"G4 kernel already initialized" << endreq;
365 bool cond = p_runMgr->ConfirmBeamOnCondition();
368 std::cout<<
"########### initializing the G4Run ############"<<
370 p_runMgr->SetRunIDCounter( -std::abs(m_runID) );
371 p_runMgr->RunInitialization();
377 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 *)