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");
52 declareProperty(
"CgemNoiseFile", m_cgemNoiseFile=
"none");
56 declareProperty(
"LogLevel", m_logLevel=6);
58 declareProperty(
"InteractiveG4" , m_interactiveG4=
false);
60 declareProperty(
"BesGenAction", m_besGenAction=
false);
62 declareProperty(
"BeamPosX",m_beamPosX=0);
63 declareProperty(
"BeamPosY",m_beamPosY=0);
64 declareProperty(
"BeamPosZ",m_beamPosZ=0);
66 declareProperty(
"BeamSizeX", m_beamSizeX=10);
67 declareProperty(
"BeamSizeY", m_beamSizeY=20);
68 declareProperty(
"BeamSizeZ", m_beamSizeZ=30);
70 declareProperty(
"BeamStartTime",m_beamStartTime=0);
71 declareProperty(
"BeamDeltaTime",m_beamDeltaTime=0);
72 declareProperty(
"NBunch",m_nBunch=1);
74 declareProperty(
"BunchTimeSigma",m_bunchTimeSigma=0);
76 declareProperty(
"MdcDataInput",m_mdcDataInput=1);
77 declareProperty(
"MdcDedxFlag",m_mdcDedxFlag=1);
79 declareProperty(
"CgemDataInput",m_cgemDataInput=1);
80 declareProperty(
"CgemDedxFlag",m_cgemDedxFlag=1);
81 declareProperty(
"CgemStripEff",m_cgemStripEff=1.0);
83 declareProperty(
"BoostLab",m_boostLab=
false);
84 declareProperty(
"BeamAngle",m_beamAngle=11);
86 declareProperty(
"SetBeamShift",m_setBeamShift=
false);
87 declareProperty(
"BeamShiftPx" ,m_beamShiftPx=39.45);
88 declareProperty(
"BeamShiftPy" ,m_beamShiftPy=-0.98);
89 declareProperty(
"BeamShiftPz" ,m_beamShiftPz=3.70);
91 declareProperty(
"CgemRootFlag",m_cgemRootFlag=
false);
92 declareProperty(
"MdcRootFlag",m_mdcRootFlag=
false);
93 declareProperty(
"TofRootFlag",m_tofRootFlag=
false);
94 declareProperty(
"EmcRootFlag",m_emcRootFlag=
false);
95 declareProperty(
"MucRootFlag",m_mucRootFlag=
false);
98 declareProperty(
"TofSaturationFlag",m_tofSaturationFlag=
true);
100 declareProperty(
"EmcLightOutput",m_emcLightOutput=
true);
101 declareProperty(
"EmcIncoherentNoise",m_emcIncoherentNoise=0.2);
102 declareProperty(
"EmcCoherentNoise",m_emcCoherentNoise=0.);
103 declareProperty(
"EmcNoiseMean",m_emcNoiseMean=1.16);
104 declareProperty(
"EmcNoiseSigma",m_emcNoiseSigma=0.23);
105 declareProperty(
"EmcNoiseThreshold",m_emcNoiseThreshold=0.5);
106 declareProperty(
"EmcNoiseLevel",m_emcNoiseLevel=3);
107 declareProperty(
"EmcTime",m_emcTime=20);
109 declareProperty(
"MucNoiseMode", m_mucNoiseMode=1);
130 MsgStream log(
msgSvc(), name() );
134 p_runMgr->SetLogLevel( m_logLevel );
147 MsgStream log(
msgSvc(), name() );
149 StatusCode status = Service::initialize();
150 log << MSG::INFO <<
"Service initialized" << endreq;
154 status = service(
"RealizationSvc", tmpReal);
155 if (!status.isSuccess())
157 log << MSG::ERROR <<
" Could not initialize Realization Service" << endreq;
160 log << MSG::INFO <<
"got the RealizationSvc" << endreq;
164 m_runID = m_RealizationSvc->
getRunId();
174 MsgStream log(
msgSvc(), name() );
175 StatusCode status = Service::finalize();
177 if ( status.isSuccess() )
178 log << MSG::INFO <<
"Service finalised successfully" << endreq;
185 void** ppvInterface ) {
186 StatusCode sc = StatusCode::FAILURE;
188 if (riid == IID_IG4Svc) {
189 *ppvInterface =
dynamic_cast<IG4Svc*
>(
this);
190 sc = StatusCode::SUCCESS;
192 sc = Service::queryInterface( riid, ppvInterface );
200 const G4Event *evt = p_runMgr->GetCurrentEvent();
203 MsgStream log(
msgSvc(), name() );
204 log << MSG::ERROR <<
"Could not get current G4Event" << endreq;
214 return ( p_runMgr->GetCurrentRun() );
221 p_uiMgr = G4UImanager::GetUIpointer();
230 p_runMgr->SetUserInitialization(userInit);
238 p_runMgr->SetUserInitialization(userInit);
246 p_runMgr->SetUserAction(action);
253 p_runMgr->SetUserAction(action);
261 p_runMgr->SetUserAction( action );
268 p_runMgr->SetUserAction(action);
275 p_runMgr->SetUserAction(action);
282 p_runMgr->SetUserAction(action);
290 MsgStream log(
msgSvc(), name() );
291 log << MSG::DEBUG <<
"Starting G4 terminal" << endreq;
293 G4UIsession * ses =
new G4UIterminal(
new G4UItcsh);
303 MsgStream log(
msgSvc(), name() );
305 log << MSG::VERBOSE <<
"Attempting G4 Initialization" << endreq;
317 log << MSG::INFO <<
"Initializing G4SvcVisManager" << endreq;
319 p_visMgr =
new G4VisExecutive;
320 p_visMgr->Initialize();
327 log << MSG::INFO <<
"Not including Visualization" << endreq;
331 log << MSG::DEBUG <<
"Setting verbosity levels - "
332 <<
"run: " << m_runVerb <<
" event: " << m_eventVerb
333 <<
" track: " << m_trackVerb << endreq;
337 ost <<
"/run/verbose " << m_runVerb << std::ends;
338 uiMgr()->ApplyCommand(ost.str());
342 ost <<
"/event/verbose " << m_eventVerb << std::ends;
343 uiMgr()->ApplyCommand(ost.str());
347 ost <<
"/tracking/verbose " << m_trackVerb << std::ends;
348 uiMgr()->ApplyCommand(ost.str());
351 log << MSG::DEBUG <<
"Initializing G4 kernel" << endreq;
352 p_runMgr->Initialize();
355 if (m_macroName!=
"none"){
356 log << MSG::INFO <<
"Running G4 macro "<<m_macroName<< endreq;
357 uiMgr()->ApplyCommand(
"/control/execute "+m_macroName);
359 if (m_interactiveG4) {
364 log << MSG::ERROR <<
"G4 kernel already initialized" << endreq;
371 bool cond = p_runMgr->ConfirmBeamOnCondition();
374 std::cout<<
"########### initializing the G4Run ############"<<
376 p_runMgr->SetRunIDCounter( -std::abs(m_runID) );
377 p_runMgr->RunInitialization();
383 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 *)