BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
BesSim Class Reference

#include <BesSim.hh>

+ Inheritance diagram for BesSim:

Public Member Functions

 BesSim (const std::string &name, ISvcLocator *pSvcLocator)
 
StatusCode initialize ()
 
StatusCode execute ()
 
StatusCode finalize ()
 
StatusCode bookMdcRootFile ()
 
StatusCode bookTofRootFile ()
 
StatusCode bookEmcRootFile ()
 
StatusCode bookMucRootFile ()
 
StatusCode beginRun ()
 

Detailed Description

Definition at line 12 of file BesSim.hh.

Constructor & Destructor Documentation

◆ BesSim()

BesSim::BesSim ( const std::string & name,
ISvcLocator * pSvcLocator )

Definition at line 57 of file BesSim.cc.

57 :
58 Algorithm(name, pSvcLocator)
59{
60 declareProperty("Mdc",m_mdc=2);
61 declareProperty("Tof",m_tof=2);
62 declareProperty("Emc",m_emc=2);
63 declareProperty("Muc",m_muc=2);
64 declareProperty("PipeSCM",m_pipeSCM=2);
65 declareProperty("Field",m_field=1);
66 declareProperty("PhysicsList",m_physicsList=0);
67 declareProperty("FormatAR", m_formatAR =0);
68 declareProperty("Tuning",m_tuning=0);
69 declareProperty("TuningFile",m_tuningFile);
70 declareProperty("HitOut",m_hitOut=0);
71 declareProperty("TDSFlag",m_TDSFlag=false);
72 declareProperty("AsciiFlag",m_asciiFlag="00000000");
73 declareProperty("AsciiFile",m_asciiFile="boost.dat");
74 declareProperty("RootFlag",m_rootFlag=false);
75 declareProperty("RootFile",m_rootFile="Hit.root");
76 declareProperty("CutValue", newcut = 0.7);//unite is mm
77 declareProperty("LogLevel",m_logLevel=5000);
78 declareProperty("BesGenAction",m_besGenAction=false);
79
80}

Member Function Documentation

◆ beginRun()

StatusCode BesSim::beginRun ( )

Definition at line 240 of file BesSim.cc.

241{
242 static int flag = -1;
243 if(flag<0)
244 {
245 MsgStream log(msgSvc(), name());
246 log << MSG::DEBUG << "\t start initializing G4 "<<endreq;
247 //new visMgr, StartUISession(), runMgr->Initialize()
248 m_G4Svc->G4Init();
249
250 //to do: runMgr->RunInitialization()
251 m_G4Svc->RunInitialize();
252
253 //G4VPhysicalVolume* g4wv =G4TransportationManager::GetTransportationManager()-> GetNavigatorForTracking()->GetWorldVolume(); //Apply this for storing TOF GDML
254 //G4GDMLWriter g4writerBes("/afs/ihep.ac.cn/bes3/offline/sw/packages/BesGDML/2.8.0/GDMLSchema/gdml.xsd", "Bes.gdml",2);
255 //G4GDMLWriter g4writerMdc("/afs/ihep.ac.cn/bes3/offline/sw/packages/BesGDML/2.8.0/GDMLSchema/gdml.xsd", "Mdc.gdml",2);
256 //G4GDMLWriter g4writerTof("/afs/ihep.ac.cn/bes3/offline/sw/packages/BesGDML/2.8.0/GDMLSchema/gdml.xsd", "Tof.gdml",2);//Apply this for storing TOF GDML
257 //G4GDMLWriter g4writerEmc("/afs/ihep.ac.cn/bes3/offline/sw/packages/BesGDML/2.8.0/GDMLSchema/gdml.xsd", "Emc.gdml",2);
258 //G4GDMLWriter g4writerMuc("/afs/ihep.ac.cn/bes3/offline/sw/packages/BesGDML/2.8.0/GDMLSchema/gdml.xsd", "Muc.gdml",2);
259 //try
260 //{
261 //g4writerBes.DumpGeometryInfo(g4wv);
262 //g4writerTof.DumpGeometryInfo(g4wv->GetLogicalVolume()->GetDaughter(0)); //Changed from 0 to 3//Apply this for storing TOF GDML
263
264 //}
265 //catch(std::logic_error &lerr)
266 //{
267 // std::cout << "Caught an exception: "
268 // << lerr.what () << std::endl;
269 //}
270
271 //For random seed added by caogf. Note the position of the code, otherwise it is not available.
272 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->GetEngine("SIM");
273 HepRandom::setTheEngine(engine);
274 HepRandom::showEngineStatus();
275 }
276 return StatusCode::SUCCESS;
277}
IMessageSvc * msgSvc()
void RunInitialize()
Definition G4Svc.cpp:371
void G4Init()
Definition G4Svc.cpp:303
virtual CLHEP::HepRandomEngine * GetEngine(const std::string &StreamName)=0
Interface to the CLHEP engine.

◆ bookEmcRootFile()

StatusCode BesSim::bookEmcRootFile ( )

Definition at line 332 of file BesSim.cc.

333{
334 NTuplePtr nt1(ntupleSvc(), "FILE803/n1");
335 NTuple::Tuple* tupleEmc1;
336 if(nt1) tupleEmc1 = nt1;
337 else {
338 tupleEmc1 = ntupleSvc()->book("FILE803/n1",CLID_ColumnWiseTuple,"BesSim");
339 m_G4Svc->SetTupleEmc1(tupleEmc1);
340 }
341
342 NTuplePtr nt2(ntupleSvc(), "FILE803/n2");
343 NTuple::Tuple* tupleEmc2;
344 if(nt2) tupleEmc2 = nt2;
345 else {
346 tupleEmc2 = ntupleSvc()->book("FILE803/n2",CLID_ColumnWiseTuple,"BesSim");
347 m_G4Svc->SetTupleEmc2(tupleEmc2);
348 }
349
350
351 return StatusCode::SUCCESS;
352}
INTupleSvc * ntupleSvc()
void SetTupleEmc1(NTuple::Tuple *tuple)
Definition G4Svc.h:117
void SetTupleEmc2(NTuple::Tuple *tuple)
Definition G4Svc.h:120

Referenced by initialize().

◆ bookMdcRootFile()

StatusCode BesSim::bookMdcRootFile ( )

Definition at line 279 of file BesSim.cc.

280{
281 MsgStream log(msgSvc(), name());
282 NTuplePtr nt(ntupleSvc(), "FILE801/n1");
283 NTuple::Tuple* tupleMdc;
284 if(nt) tupleMdc = nt;
285 else {
286 tupleMdc = ntupleSvc()->book("FILE801/n1",CLID_ColumnWiseTuple,"BesSim");
287 m_G4Svc->SetTupleMdc(tupleMdc);
288 }
289 return StatusCode::SUCCESS;
290}
void SetTupleMdc(NTuple::Tuple *tuple)
Definition G4Svc.h:105

Referenced by initialize().

◆ bookMucRootFile()

StatusCode BesSim::bookMucRootFile ( )

Definition at line 356 of file BesSim.cc.

357{
358 MsgStream log(msgSvc(), name());
359 NTuplePtr nt(ntupleSvc(), "FILE804/n1");
360 NTuple::Tuple* tupleMuc;
361 if(nt) tupleMuc = nt;
362 else {
363 tupleMuc = ntupleSvc()->book("FILE804/n1",CLID_ColumnWiseTuple,"BesSim");
364 m_G4Svc->SetTupleMuc(tupleMuc);
365 }
366 return StatusCode::SUCCESS;
367}
void SetTupleMuc(NTuple::Tuple *tuple)
Definition G4Svc.h:123

Referenced by initialize().

◆ bookTofRootFile()

StatusCode BesSim::bookTofRootFile ( )

Definition at line 294 of file BesSim.cc.

295{
296 MsgStream log(msgSvc(), name());
297 NTuplePtr nt1(ntupleSvc(), "FILE802/n1");
298 NTuple::Tuple* tupleTof1;
299 if(nt1) tupleTof1 = nt1;
300 else {
301 tupleTof1 = ntupleSvc()->book("FILE802/n1",CLID_ColumnWiseTuple,"BesSim");
302 m_G4Svc->SetTupleTof1(tupleTof1);
303 }
304 NTuplePtr nt2(ntupleSvc(), "FILE802/n2");
305 NTuple::Tuple* tupleTof2;
306 if(nt2) tupleTof2 = nt2;
307 else {
308 tupleTof2 = ntupleSvc()->book("FILE802/n2",CLID_ColumnWiseTuple,"BesSim");
309 m_G4Svc->SetTupleTof2(tupleTof2);
310 }
311 NTuplePtr nt3(ntupleSvc(), "FILE802/n3");
312 NTuple::Tuple* tupleTof3;
313 if(nt3) tupleTof3 = nt3;
314 else {
315 tupleTof3 = ntupleSvc()->book("FILE802/n3",CLID_ColumnWiseTuple,"BesSim");
316 m_G4Svc->SetTupleTof3(tupleTof3);
317 }
318 /*
319 NTuplePtr nt4(ntupleSvc(), "FILE802/n4");
320 NTuple::Tuple* tupleTof4;
321 if(nt4) tupleTof4 = nt4;
322 else {
323 tupleTof4 = ntupleSvc()->book("FILE802/n4",CLID_ColumnWiseTuple,"BesSim");
324 m_G4Svc->SetTupleTof4(tupleTof4);
325 }
326 */
327 return StatusCode::SUCCESS;
328}
void SetTupleTof3(NTuple::Tuple *tuple)
Definition G4Svc.h:114
void SetTupleTof2(NTuple::Tuple *tuple)
Definition G4Svc.h:111
void SetTupleTof1(NTuple::Tuple *tuple)
Definition G4Svc.h:108

Referenced by initialize().

◆ execute()

StatusCode BesSim::execute ( )

Definition at line 371 of file BesSim.cc.

371 {
372
373 MsgStream log(msgSvc(), name());
374
375 //log << MSG::INFO << "event ID:"<<m_nEvent<<endreq;
376 if(m_nEvent%m_logLevel == 0)
377 std::cout<<" BesSim Begin of Event: "<<m_nEvent<<std::endl;
378
379 m_G4Svc->SimulateEvents(m_nEvent);
380 m_nEvent++;
381
382 return StatusCode::SUCCESS;
383}
void SimulateEvents(int)
Definition G4Svc.cpp:388

◆ finalize()

StatusCode BesSim::finalize ( )

Definition at line 387 of file BesSim.cc.

387 {
388
389 MsgStream log(msgSvc(), name());
390 log << MSG::INFO << "finalize()" << endreq;
391 log << MSG::DEBUG << "\t terminating the current G4 run"<<endreq;
392 m_G4Svc->RunTerminate();
393
394 std::cout<<"BesSim::finalize(), total events in this run: "<<m_nEvent<<std::endl;
395
396 if(m_G4Svc->runMgr() != 0)
397 delete m_G4Svc->runMgr();
398
399#ifdef G4VIS_USE
400 if(m_G4Svc->visMgr() != 0)
401 delete m_G4Svc->visMgr();
402#endif
403
404
405 return StatusCode::SUCCESS;
406}
void RunTerminate()
Definition G4Svc.cpp:383
G4RunManager * runMgr()
Definition G4Svc.cpp:124

◆ initialize()

StatusCode BesSim::initialize ( )

Definition at line 84 of file BesSim.cc.

84 {
85
86 MsgStream log(msgSvc(), name());
87 log << MSG::INFO << "initialize()" << endreq;
88 m_nEvent = 0;
89 m_nRun = 1;
90
91 //caogf for random seed
92 static const bool CREATEIFNOTTHERE(true);
93 StatusCode RndmStatus = service("BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
94 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
95 {
96 log << MSG::ERROR << " Could not initialize Random Number Service" << endreq;
97 return RndmStatus;
98 }
99
100 StatusCode status;
101 IG4Svc *tmpSvc;
102 status = service("G4Svc",tmpSvc);
103 if (status.isSuccess()) {
104 log << MSG::INFO << "got the G4Svc" << endreq;
105 m_G4Svc=dynamic_cast<G4Svc *>(tmpSvc);
106 } else {
107 log << MSG::ERROR << "could not get the G4Svc" << endreq;
108 return StatusCode::FAILURE;
109 }
110
112 StatusCode sc_det = service("DetVerSvc", detVerSvc);
113 if( sc_det.isFailure() ) {
114 log << MSG::ERROR << "can't retrieve DetVerSvc instance" << endreq;
115 return sc_det;
116 }
117
118 int phase = detVerSvc->phase();
119 log << MSG::INFO << "** ~~~ZZZ~~~ ** : retrieved DetectorStage = " << phase << endreq;
120
121 // phase 1: Endcap TOF Scintillator; phase 2: 4 Scintillator==> 2 MRPC; phase 3: Endcap TOF MRPC
122 if( phase>2 ) { m_tof = 4; }
123
124 //book Ntuple
125 if(m_G4Svc->MdcRootFlag())
127
128 if(m_G4Svc->TofRootFlag())
130
131 if(m_G4Svc->EmcRootFlag())
133
134 if(m_G4Svc->MucRootFlag())
136
137 log << MSG::INFO << "Four sub-detector construction flags: " <<m_mdc<<" "<<m_tof<<" "<<m_emc<<" "<<m_muc<<endreq;
138
139 ReadBoostRoot* readBoost =new ReadBoostRoot(m_mdc, m_tof,m_emc, m_muc, m_field,m_formatAR,m_tuning,m_hitOut);
140 BesMdcGeoParameter * mdcGeoService;
141 mdcGeoService = new BesMdcGeoParameter;
142
143 log << MSG::INFO << "Instantiating BESIII Detector" << endreq;
144
145 BesSensitiveManager* sensitiveManager = new BesSensitiveManager;
146 sensitiveManager->SetLogLevel(m_G4Svc->LogLevel());
147
148 BesDetectorConstruction* detectorConstruction = new BesDetectorConstruction();
149 detectorConstruction->SetPipeSCM(m_pipeSCM);
150 m_G4Svc->SetUserInitialization(detectorConstruction);
151
152 switch(m_physicsList)
153 {
154 case 1:
155 m_G4Svc->SetUserInitialization(new QBBC);
156 break;
157 case 2:
158 m_G4Svc->SetUserInitialization(new QGS_BIC);
159 break;
160 case 3:
161 m_G4Svc->SetUserInitialization(new QGSP_BERT);
162 break;
163 case 4:
164 m_G4Svc->SetUserInitialization(new QGSP_BERT_HP);
165 break;
166 case 5:
167 m_G4Svc->SetUserInitialization(new QGSP_BIC_AllHP);
168 break;
169 case 6:
170 m_G4Svc->SetUserInitialization(new QGSP_BIC);
171 break;
172 case 7:
173 m_G4Svc->SetUserInitialization(new FTF_BIC);
174 break;
175 case 8:
176 m_G4Svc->SetUserInitialization(new FTFP_BERT_ATL);
177 break;
178 case 9:
179 m_G4Svc->SetUserInitialization(new FTFP_BERT);
180 break;
181 case 10:
182 m_G4Svc->SetUserInitialization(new FTFP_BERT_HP);
183 break;
184 case 11:
185 m_G4Svc->SetUserInitialization(new FTFP_BERT_TRV);
186 break;
187 case 12:
188 m_G4Svc->SetUserInitialization(new FTFQGSP_BERT);
189 break;
190 default:
191 m_G4Svc->SetUserInitialization(new FTFP_BERT);
192 break;
193 }
194
195 BesActionInitializer* actionInit = new BesActionInitializer();
196 actionInit->SetBesGenActionFlag(m_besGenAction);
197 actionInit->SetTDSFlag(m_TDSFlag);
198 actionInit->SetAsciiFlag(m_asciiFlag);
199 actionInit->SetAsciiFile(m_asciiFile);
200 actionInit->SetRootFlag(m_rootFlag);
201 actionInit->SetRootFile(m_rootFile);
202 actionInit->SetTuningFile(m_tuningFile);
203
204 m_G4Svc->SetUserInitialization(actionInit);
205
206 //m_G4Svc->SetUserAction(new BesPrimaryGeneratorAction);
207 //BesRunAction* runAction = new BesRunAction;
208 //runAction->SetTDSFlag(m_TDSFlag);
209 //runAction->SetAsciiFlag(m_asciiFlag);
210 //runAction->SetAsciiFile(m_asciiFile);
211 //runAction->SetRootFlag(m_rootFlag);
212 //runAction->SetRootFile(m_rootFile);
213 //vector<string>::iterator pd;
214 //for (pd = m_tuningFile.begin(); pd != m_tuningFile.end(); pd++){
215 // std::cout << "tuning File: " << *pd << std::endl;
216 //}
217
218 //runAction->SetTuningFile(m_tuningFile);
219 //m_G4Svc->SetUserAction(runAction);
220
221 //BesEventAction* evtAction = new BesEventAction(runAction);
222 //m_G4Svc->SetUserAction(evtAction);
223
224 //m_G4Svc->SetUserAction(new BesSteppingAction);
225
226 //m_G4Svc->SetUserAction(new BesTrackingAction(runAction) );
227
228//#ifdef G4VIS_USE
229//visualization manager
230// G4VisManager* visManager = new BesVisManager;
231// visManager->Initialize();
232//#endif
233
234
235 return StatusCode::SUCCESS;
236}
IDetVerSvc * detVerSvc
void SetAsciiFile(std::string file)
void SetAsciiFlag(std::string flag)
void SetBesGenActionFlag(G4bool flag)
void SetTDSFlag(G4bool flag)
void SetTuningFile(std::vector< std::string > file)
void SetRootFile(std::string file)
void SetRootFlag(G4bool flag)
void SetLogLevel(G4int level)
StatusCode bookEmcRootFile()
Definition BesSim.cc:332
StatusCode bookMdcRootFile()
Definition BesSim.cc:279
StatusCode bookMucRootFile()
Definition BesSim.cc:356
StatusCode bookTofRootFile()
Definition BesSim.cc:294
Definition G4Svc.h:33
bool MdcRootFlag()
Definition G4Svc.h:125
bool EmcRootFlag()
Definition G4Svc.h:127
bool TofRootFlag()
Definition G4Svc.h:126
void SetUserInitialization(G4VUserDetectorConstruction *userInit)
Definition G4Svc.cpp:224
int LogLevel()
Definition G4Svc.h:145
bool MucRootFlag()
Definition G4Svc.h:128
virtual int phase()=0

The documentation for this class was generated from the following files: