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"
36DECLARE_COMPONENT(
G4Svc)
39 base_class(name, svc), p_runMgr(0), p_uiMgr(0), p_visMgr(0),
40 _init(
false), m_beamTime(0)
44 declareProperty(
"Visualize", m_vis=
false);
47 declareProperty(
"RunVerbosity", m_runVerb=0);
48 declareProperty(
"EventVerbosity", m_eventVerb=0);
49 declareProperty(
"TrackingVerbosity", m_trackVerb=0);
51 declareProperty(
"FADSmacro",m_macroName=
"none" );
52 declareProperty(
"MdcNoiseFile", m_mdcNoiseFile=
"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(
"BoostLab",m_boostLab=
false);
80 declareProperty(
"BeamAngle",m_beamAngle=11);
82 declareProperty(
"SetBeamShift",m_setBeamShift=
false);
83 declareProperty(
"BeamShiftPx" ,m_beamShiftPx=39.45);
84 declareProperty(
"BeamShiftPy" ,m_beamShiftPy=-0.98);
85 declareProperty(
"BeamShiftPz" ,m_beamShiftPz=3.70);
87 declareProperty(
"MdcRootFlag",m_mdcRootFlag=
false);
88 declareProperty(
"TofRootFlag",m_tofRootFlag=
false);
89 declareProperty(
"EmcRootFlag",m_emcRootFlag=
false);
90 declareProperty(
"MucRootFlag",m_mucRootFlag=
false);
93 declareProperty(
"TofSaturationFlag",m_tofSaturationFlag=
true);
95 declareProperty(
"EmcLightOutput",m_emcLightOutput=
true);
96 declareProperty(
"EmcIncoherentNoise",m_emcIncoherentNoise=0.2);
97 declareProperty(
"EmcCoherentNoise",m_emcCoherentNoise=0.);
98 declareProperty(
"EmcNoiseMean",m_emcNoiseMean=1.16);
99 declareProperty(
"EmcNoiseSigma",m_emcNoiseSigma=0.23);
100 declareProperty(
"EmcNoiseThreshold",m_emcNoiseThreshold=0.5);
101 declareProperty(
"EmcNoiseLevel",m_emcNoiseLevel=3);
102 declareProperty(
"EmcTime",m_emcTime=20);
103 declareProperty(
"EmcELecSaturation",m_emcELecSaturation=1);
104 declareProperty(
"EmcELecSatuDead",m_emcELecSatuDead=0);
105 declareProperty(
"MucNoiseMode", m_mucNoiseMode=1);
126 MsgStream log(
msgSvc(), name() );
130 p_runMgr->SetLogLevel( m_logLevel );
143 MsgStream log(
msgSvc(), name() );
145 StatusCode status = Service::initialize();
146 log << MSG::INFO <<
"Service initialized" << endreq;
150 status = service(
"RealizationSvc", tmpReal);
151 if (!status.isSuccess())
153 log << MSG::ERROR <<
" Could not initialize Realization Service" << endreq;
156 log << MSG::INFO <<
"got the RealizationSvc" << endreq;
160 m_runID = m_RealizationSvc->
getRunId();
170 MsgStream log(
msgSvc(), name() );
171 StatusCode status = Service::finalize();
173 if ( status.isSuccess() )
174 log << MSG::INFO <<
"Service finalised successfully" << endreq;
196 const G4Event *evt = p_runMgr->GetCurrentEvent();
199 MsgStream log(
msgSvc(), name() );
200 log << MSG::ERROR <<
"Could not get current G4Event" << endreq;
210 return ( p_runMgr->GetCurrentRun() );
217 p_uiMgr = G4UImanager::GetUIpointer();
226 p_runMgr->SetUserInitialization(userInit);
234 p_runMgr->SetUserInitialization(userInit);
240 p_runMgr->SetUserInitialization(userInit);
292 MsgStream log(
msgSvc(), name() );
293 log << MSG::DEBUG <<
"Starting G4 terminal" << endreq;
295 G4UIsession * ses =
new G4UIterminal(
new G4UItcsh);
305 MsgStream log(
msgSvc(), name() );
307 log << MSG::VERBOSE <<
"Attempting G4 Initialization" << endreq;
319 log << MSG::INFO <<
"Initializing G4SvcVisManager" << endreq;
321 p_visMgr =
new G4VisExecutive;
322 p_visMgr->Initialize();
329 log << MSG::INFO <<
"Not including Visualization" << endreq;
333 log << MSG::DEBUG <<
"Setting verbosity levels - "
334 <<
"run: " << m_runVerb <<
" event: " << m_eventVerb
335 <<
" track: " << m_trackVerb << endreq;
339 ost <<
"/run/verbose " << m_runVerb << std::ends;
340 uiMgr()->ApplyCommand(ost.str());
344 ost <<
"/event/verbose " << m_eventVerb << std::ends;
345 uiMgr()->ApplyCommand(ost.str());
349 ost <<
"/tracking/verbose " << m_trackVerb << std::ends;
350 uiMgr()->ApplyCommand(ost.str());
353 log << MSG::DEBUG <<
"Initializing G4 kernel" << endreq;
354 p_runMgr->Initialize();
357 if (m_macroName!=
"none"){
358 log << MSG::INFO <<
"Running G4 macro "<<m_macroName<< endreq;
359 uiMgr()->ApplyCommand(
"/control/execute "+m_macroName);
361 if (m_interactiveG4) {
366 log << MSG::ERROR <<
"G4 kernel already initialized" << endreq;
373 bool cond = p_runMgr->ConfirmBeamOnCondition();
376 std::cout<<
"########### initializing the G4Run ############"<<
378 p_runMgr->SetRunIDCounter( -std::abs(m_runID) );
379 p_runMgr->RunInitialization();
385 p_runMgr->RunTermination();
void SimulateEvent(int i)
virtual StatusCode initialize()
const G4Event * GetCurrentEvent() const
void SetUserInitialization(G4VUserDetectorConstruction *userInit)
virtual StatusCode finalize()
const G4Run * GetCurrentRun() const