17#include "QGSP_BERT.hh"
19#include "QGSP_BERT_HP.hh"
23#include "G4RunManager.hh"
25#include "GaudiKernel/MsgStream.h"
26#include "GaudiKernel/AlgFactory.h"
27#include "GaudiKernel/SmartIF.h"
28#include "GaudiKernel/Property.h"
31#include "GaudiKernel/NTuple.h"
34#include "G4Writer/G4GDMLWriter.h"
36#include "CLHEP/Random/Random.h"
49 Algorithm(name, pSvcLocator)
51 declareProperty(
"Mdc",m_mdc=2);
52 declareProperty(
"Tof",m_tof=2);
53 declareProperty(
"Emc",m_emc=2);
54 declareProperty(
"Muc",m_muc=2);
55 declareProperty(
"PipeSCM",m_pipeSCM=2);
56 declareProperty(
"Field",m_field=1);
57 declareProperty(
"PhysicsList",m_physicsList=0);
58 declareProperty(
"FormatAR", m_formatAR =0);
59 declareProperty(
"Tuning",m_tuning=0);
60 declareProperty(
"TuningFile",m_tuningFile);
61 declareProperty(
"HitOut",m_hitOut=0);
62 declareProperty(
"TDSFlag",m_TDSFlag=
false);
63 declareProperty(
"AsciiFlag",m_asciiFlag=
"00000000");
64 declareProperty(
"AsciiFile",m_asciiFile=
"boost.dat");
65 declareProperty(
"RootFlag",m_rootFlag=
false);
66 declareProperty(
"RootFile",m_rootFile=
"Hit.root");
67 declareProperty(
"CutValue", newcut = 0.7);
68 declareProperty(
"LogLevel",m_logLevel=5000);
76 MsgStream log(
msgSvc(), name());
77 log << MSG::INFO <<
"initialize()" << endreq;
82 static const bool CREATEIFNOTTHERE(
true);
83 StatusCode RndmStatus = service(
"BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
84 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
86 log << MSG::ERROR <<
" Could not initialize Random Number Service" << endreq;
92 status = service(
"G4Svc",tmpSvc);
93 if (status.isSuccess()) {
94 log << MSG::INFO <<
"got the G4Svc" << endreq;
95 m_G4Svc=
dynamic_cast<G4Svc *
>(tmpSvc);
97 log << MSG::ERROR <<
"could not get the G4Svc" << endreq;
98 return StatusCode::FAILURE;
102 StatusCode sc_det = service(
"DetVerSvc",
detVerSvc);
103 if( sc_det.isFailure() ) {
104 log << MSG::ERROR <<
"can't retrieve DetVerSvc instance" << endreq;
109 log << MSG::INFO <<
"** ~~~ZZZ~~~ ** : retrieved DetectorStage = " << phase << endreq;
112 if( phase>2 ) { m_tof = 4; }
127 log << MSG::INFO <<
"Four sub-detector construction flags: " <<m_mdc<<
" "<<m_tof<<
" "<<m_emc<<
" "<<m_muc<<endreq;
133 log << MSG::INFO <<
"Instantiating BESIII Detector" << endreq;
142 switch(m_physicsList)
182 vector<string>::iterator pd;
183 for (pd = m_tuningFile.begin(); pd != m_tuningFile.end(); pd++){
184 std::cout <<
"tuning File: " << *pd << std::endl;
204 return StatusCode::SUCCESS;
211 static int flag = -1;
214 MsgStream log(
msgSvc(), name());
215 log << MSG::DEBUG <<
"\t start initializing G4 "<<endreq;
241 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->
GetEngine(
"SIM");
242 HepRandom::setTheEngine(engine);
243 HepRandom::showEngineStatus();
245 return StatusCode::SUCCESS;
250 MsgStream log(
msgSvc(), name());
252 NTuple::Tuple* tupleMdc;
253 if(nt) tupleMdc = nt;
255 tupleMdc =
ntupleSvc()->book(
"FILE801/n1",CLID_ColumnWiseTuple,
"BesSim");
258 return StatusCode::SUCCESS;
265 MsgStream log(
msgSvc(), name());
266 NTuplePtr nt1(
ntupleSvc(),
"FILE802/n1");
267 NTuple::Tuple* tupleTof1;
268 if(nt1) tupleTof1 = nt1;
270 tupleTof1 =
ntupleSvc()->book(
"FILE802/n1",CLID_ColumnWiseTuple,
"BesSim");
273 NTuplePtr nt2(
ntupleSvc(),
"FILE802/n2");
274 NTuple::Tuple* tupleTof2;
275 if(nt2) tupleTof2 = nt2;
277 tupleTof2 =
ntupleSvc()->book(
"FILE802/n2",CLID_ColumnWiseTuple,
"BesSim");
280 NTuplePtr nt3(
ntupleSvc(),
"FILE802/n3");
281 NTuple::Tuple* tupleTof3;
282 if(nt3) tupleTof3 = nt3;
284 tupleTof3 =
ntupleSvc()->book(
"FILE802/n3",CLID_ColumnWiseTuple,
"BesSim");
296 return StatusCode::SUCCESS;
303 NTuplePtr nt1(
ntupleSvc(),
"FILE803/n1");
304 NTuple::Tuple* tupleEmc1;
305 if(nt1) tupleEmc1 = nt1;
307 tupleEmc1 =
ntupleSvc()->book(
"FILE803/n1",CLID_ColumnWiseTuple,
"BesSim");
311 NTuplePtr nt2(
ntupleSvc(),
"FILE803/n2");
312 NTuple::Tuple* tupleEmc2;
313 if(nt2) tupleEmc2 = nt2;
315 tupleEmc2 =
ntupleSvc()->book(
"FILE803/n2",CLID_ColumnWiseTuple,
"BesSim");
320 return StatusCode::SUCCESS;
327 MsgStream log(
msgSvc(), name());
329 NTuple::Tuple* tupleMuc;
330 if(nt) tupleMuc = nt;
332 tupleMuc =
ntupleSvc()->book(
"FILE804/n1",CLID_ColumnWiseTuple,
"BesSim");
335 return StatusCode::SUCCESS;
342 MsgStream log(
msgSvc(), name());
345 if(m_nEvent%m_logLevel == 0)
346 std::cout<<
" BesSim Begin of Event: "<<m_nEvent<<std::endl;
351 return StatusCode::SUCCESS;
358 MsgStream log(
msgSvc(), name());
359 log << MSG::INFO <<
"finalize()" << endreq;
360 log << MSG::DEBUG <<
"\t terminating the current G4 run"<<endreq;
363 std::cout<<
"BesSim::finalize(), total events in this run: "<<m_nEvent<<std::endl;
365 if(m_G4Svc->
runMgr() != 0)
369 if(m_G4Svc->visMgr() != 0)
370 delete m_G4Svc->visMgr();
374 return StatusCode::SUCCESS;
void SetPipeSCM(G4int value)
void SetTuningFile(std::vector< std::string > file)
void SetRootFile(std::string file)
void SetTDSFlag(G4bool flag)
void SetRootFlag(G4bool flag)
void SetAsciiFlag(std::string flag)
void SetAsciiFile(std::string file)
void SetLogLevel(G4int level)
StatusCode bookEmcRootFile()
StatusCode bookMdcRootFile()
StatusCode bookMucRootFile()
BesSim(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode bookTofRootFile()
void SetTupleTof3(NTuple::Tuple *tuple)
void SetTupleMdc(NTuple::Tuple *tuple)
void SetTupleMuc(NTuple::Tuple *tuple)
void SetTupleEmc1(NTuple::Tuple *tuple)
void SetTupleEmc2(NTuple::Tuple *tuple)
void SetTupleTof2(NTuple::Tuple *tuple)
void SetUserInitialization(G4VUserDetectorConstruction *userInit)
void SetTupleTof1(NTuple::Tuple *tuple)
void SetUserAction(G4UserRunAction *)
virtual CLHEP::HepRandomEngine * GetEngine(const std::string &StreamName)=0
Interface to the CLHEP engine.