BOSS 6.6.4.p03
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 47 of file BesSim.cc.

47 :
48 Algorithm(name, pSvcLocator)
49{
50 declareProperty("Mdc",m_mdc=2);
51 declareProperty("Tof",m_tof=2);
52 declareProperty("Emc",m_emc=2);
53 declareProperty("Muc",m_muc=2);
54 declareProperty("PipeSCM",m_pipeSCM=2);
55 declareProperty("Field",m_field=1);
56 declareProperty("PhysicsList",m_physicsList=0);
57 declareProperty("FormatAR", m_formatAR =0);
58 declareProperty("Tuning",m_tuning=0);
59 declareProperty("TuningFile",m_tuningFile);
60 declareProperty("HitOut",m_hitOut=0);
61 declareProperty("TDSFlag",m_TDSFlag=false);
62 declareProperty("AsciiFlag",m_asciiFlag="00000000");
63 declareProperty("AsciiFile",m_asciiFile="boost.dat");
64 declareProperty("RootFlag",m_rootFlag=false);
65 declareProperty("RootFile",m_rootFile="Hit.root");
66 declareProperty("CutValue", newcut = 0.7);//unite is mm
67 declareProperty("LogLevel",m_logLevel=5000);
68
69}

Member Function Documentation

◆ beginRun()

StatusCode BesSim::beginRun ( )

Definition at line 195 of file BesSim.cc.

196{
197 static int flag = -1;
198 if(flag<0)
199 {
200 MsgStream log(msgSvc(), name());
201 log << MSG::DEBUG << "\t start initializing G4 "<<endreq;
202 //new visMgr, StartUISession(), runMgr->Initialize()
203 m_G4Svc->G4Init();
204
205 //to do: runMgr->RunInitialization()
206 m_G4Svc->RunInitialize();
207
208 //G4VPhysicalVolume* g4wv =G4TransportationManager::GetTransportationManager()-> GetNavigatorForTracking()->GetWorldVolume(); //Apply this for storing TOF GDML
209 //G4GDMLWriter g4writerBes("/afs/ihep.ac.cn/bes3/offline/sw/packages/BesGDML/2.8.0/GDMLSchema/gdml.xsd", "Bes.gdml",2);
210 //G4GDMLWriter g4writerMdc("/afs/ihep.ac.cn/bes3/offline/sw/packages/BesGDML/2.8.0/GDMLSchema/gdml.xsd", "Mdc.gdml",2);
211 //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
212 //G4GDMLWriter g4writerEmc("/afs/ihep.ac.cn/bes3/offline/sw/packages/BesGDML/2.8.0/GDMLSchema/gdml.xsd", "Emc.gdml",2);
213 //G4GDMLWriter g4writerMuc("/afs/ihep.ac.cn/bes3/offline/sw/packages/BesGDML/2.8.0/GDMLSchema/gdml.xsd", "Muc.gdml",2);
214 //try
215 //{
216 //g4writerBes.DumpGeometryInfo(g4wv);
217 //g4writerTof.DumpGeometryInfo(g4wv->GetLogicalVolume()->GetDaughter(0)); //Changed from 0 to 3//Apply this for storing TOF GDML
218
219 //}
220 //catch(std::logic_error &lerr)
221 //{
222 // std::cout << "Caught an exception: "
223 // << lerr.what () << std::endl;
224 //}
225
226 //For random seed added by caogf. Note the position of the code, otherwise it is not available.
227 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->GetEngine("SIM");
228 HepRandom::setTheEngine(engine);
229 HepRandom::showEngineStatus();
230 }
231 return StatusCode::SUCCESS;
232}
IMessageSvc * msgSvc()
void RunInitialize()
Definition: G4Svc.cpp:363
void G4Init()
Definition: G4Svc.cpp:295
virtual CLHEP::HepRandomEngine * GetEngine(const std::string &StreamName)=0
Interface to the CLHEP engine.

◆ bookEmcRootFile()

StatusCode BesSim::bookEmcRootFile ( )

Definition at line 289 of file BesSim.cc.

290{
291 NTuplePtr nt1(ntupleSvc(), "FILE803/n1");
292 NTuple::Tuple* tupleEmc1;
293 if(nt1) tupleEmc1 = nt1;
294 else {
295 tupleEmc1 = ntupleSvc()->book("FILE803/n1",CLID_ColumnWiseTuple,"BesSim");
296 m_G4Svc->SetTupleEmc1(tupleEmc1);
297 }
298
299 NTuplePtr nt2(ntupleSvc(), "FILE803/n2");
300 NTuple::Tuple* tupleEmc2;
301 if(nt2) tupleEmc2 = nt2;
302 else {
303 tupleEmc2 = ntupleSvc()->book("FILE803/n2",CLID_ColumnWiseTuple,"BesSim");
304 m_G4Svc->SetTupleEmc2(tupleEmc2);
305 }
306
307
308 return StatusCode::SUCCESS;
309}
INTupleSvc * ntupleSvc()
void SetTupleEmc1(NTuple::Tuple *tuple)
Definition: G4Svc.h:109
void SetTupleEmc2(NTuple::Tuple *tuple)
Definition: G4Svc.h:112

Referenced by initialize().

◆ bookMdcRootFile()

StatusCode BesSim::bookMdcRootFile ( )

Definition at line 234 of file BesSim.cc.

235{
236 MsgStream log(msgSvc(), name());
237 NTuplePtr nt(ntupleSvc(), "FILE801/n1");
238 NTuple::Tuple* tupleMdc;
239 if(nt) tupleMdc = nt;
240 else {
241 tupleMdc = ntupleSvc()->book("FILE801/n1",CLID_ColumnWiseTuple,"BesSim");
242 m_G4Svc->SetTupleMdc(tupleMdc);
243 }
244 return StatusCode::SUCCESS;
245}
void SetTupleMdc(NTuple::Tuple *tuple)
Definition: G4Svc.h:97

Referenced by initialize().

◆ bookMucRootFile()

StatusCode BesSim::bookMucRootFile ( )

Definition at line 313 of file BesSim.cc.

314{
315 MsgStream log(msgSvc(), name());
316 NTuplePtr nt(ntupleSvc(), "FILE804/n1");
317 NTuple::Tuple* tupleMuc;
318 if(nt) tupleMuc = nt;
319 else {
320 tupleMuc = ntupleSvc()->book("FILE804/n1",CLID_ColumnWiseTuple,"BesSim");
321 m_G4Svc->SetTupleMuc(tupleMuc);
322 }
323 return StatusCode::SUCCESS;
324}
void SetTupleMuc(NTuple::Tuple *tuple)
Definition: G4Svc.h:115

Referenced by initialize().

◆ bookTofRootFile()

StatusCode BesSim::bookTofRootFile ( )

Definition at line 249 of file BesSim.cc.

250{
251 MsgStream log(msgSvc(), name());
252 NTuplePtr nt1(ntupleSvc(), "FILE802/n1");
253 NTuple::Tuple* tupleTof1;
254 if(nt1) tupleTof1 = nt1;
255 else {
256 tupleTof1 = ntupleSvc()->book("FILE802/n1",CLID_ColumnWiseTuple,"BesSim");
257 m_G4Svc->SetTupleTof1(tupleTof1);
258 }
259 NTuplePtr nt2(ntupleSvc(), "FILE802/n2");
260 NTuple::Tuple* tupleTof2;
261 if(nt2) tupleTof2 = nt2;
262 else {
263 tupleTof2 = ntupleSvc()->book("FILE802/n2",CLID_ColumnWiseTuple,"BesSim");
264 m_G4Svc->SetTupleTof2(tupleTof2);
265 }
266 NTuplePtr nt3(ntupleSvc(), "FILE802/n3");
267 NTuple::Tuple* tupleTof3;
268 if(nt3) tupleTof3 = nt3;
269 else {
270 tupleTof3 = ntupleSvc()->book("FILE802/n3",CLID_ColumnWiseTuple,"BesSim");
271 m_G4Svc->SetTupleTof3(tupleTof3);
272 }
273
274 // NTuplePtr nt4(ntupleSvc(), "FILE802/n4");
275 //NTuple::Tuple* tupleTof4;
276 //if(nt4) tupleTof4 = nt4;
277 //else {
278 //tupleTof4 = ntupleSvc()->book("FILE802/n4",CLID_ColumnWiseTuple,"BesSim");
279 //m_G4Svc->SetTupleTof4(tupleTof4);
280 //}
281
282
283
284 return StatusCode::SUCCESS;
285}
void SetTupleTof3(NTuple::Tuple *tuple)
Definition: G4Svc.h:106
void SetTupleTof2(NTuple::Tuple *tuple)
Definition: G4Svc.h:103
void SetTupleTof1(NTuple::Tuple *tuple)
Definition: G4Svc.h:100

Referenced by initialize().

◆ execute()

StatusCode BesSim::execute ( )

Definition at line 328 of file BesSim.cc.

328 {
329
330 MsgStream log(msgSvc(), name());
331
332 //log << MSG::INFO << "event ID:"<<m_nEvent<<endreq;
333 if(m_nEvent%m_logLevel == 0)
334 std::cout<<" BesSim Begin of Event: "<<m_nEvent<<std::endl;
335
336 m_G4Svc->SimulateEvents(m_nEvent);
337 m_nEvent++;
338
339 return StatusCode::SUCCESS;
340}
void SimulateEvents(int)
Definition: G4Svc.cpp:380

◆ finalize()

StatusCode BesSim::finalize ( )

Definition at line 344 of file BesSim.cc.

344 {
345
346 MsgStream log(msgSvc(), name());
347 log << MSG::INFO << "finalize()" << endreq;
348 log << MSG::DEBUG << "\t terminating the current G4 run"<<endreq;
349 m_G4Svc->RunTerminate();
350
351 std::cout<<"BesSim::finalize(), total events in this run: "<<m_nEvent<<std::endl;
352
353 if(m_G4Svc->runMgr() != 0)
354 delete m_G4Svc->runMgr();
355
356#ifdef G4VIS_USE
357 if(m_G4Svc->visMgr() != 0)
358 delete m_G4Svc->visMgr();
359#endif
360
361
362 return StatusCode::SUCCESS;
363}
void RunTerminate()
Definition: G4Svc.cpp:375
G4RunManager * runMgr()
Definition: G4Svc.cpp:122

◆ initialize()

StatusCode BesSim::initialize ( )

Definition at line 73 of file BesSim.cc.

73 {
74
75 MsgStream log(msgSvc(), name());
76 log << MSG::INFO << "initialize()" << endreq;
77 m_nEvent = 0;
78 m_nRun = 1;
79
80 //caogf for random seed
81 static const bool CREATEIFNOTTHERE(true);
82 StatusCode RndmStatus = service("BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
83 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
84 {
85 log << MSG::ERROR << " Could not initialize Random Number Service" << endreq;
86 return RndmStatus;
87 }
88
89 StatusCode status;
90 IG4Svc *tmpSvc;
91 status = service("G4Svc",tmpSvc);
92 if (status.isSuccess()) {
93 log << MSG::INFO << "got the G4Svc" << endreq;
94 m_G4Svc=dynamic_cast<G4Svc *>(tmpSvc);
95 } else {
96 log << MSG::ERROR << "could not get the G4Svc" << endreq;
97 return StatusCode::FAILURE;
98 }
99
100 //book Ntuple
101 if(m_G4Svc->MdcRootFlag())
103
104 if(m_G4Svc->TofRootFlag())
106
107 if(m_G4Svc->EmcRootFlag())
109
110 if(m_G4Svc->MucRootFlag())
112
113 log << MSG::INFO << "Four sub-detector construction flags: " <<m_mdc<<" "<<m_tof<<" "<<m_emc<<" "<<m_muc<<endreq;
114
115 ReadBoostRoot* readBoost =new ReadBoostRoot(m_mdc, m_tof,m_emc, m_muc, m_field,m_formatAR,m_tuning,m_hitOut);
116 BesMdcGeoParameter * mdcGeoService;
117 mdcGeoService = new BesMdcGeoParameter;
118
119 log << MSG::INFO << "Instantiating BESIII Detector" << endreq;
120
121 BesSensitiveManager* sensitiveManager = new BesSensitiveManager;
122 sensitiveManager->SetLogLevel(m_G4Svc->LogLevel());
123
124 BesDetectorConstruction* detectorConstruction = new BesDetectorConstruction();
125 detectorConstruction->SetPipeSCM(m_pipeSCM);
126 m_G4Svc->SetUserInitialization(detectorConstruction);
127
128 switch(m_physicsList)
129 {
130 case 1:
132 break;
133 case 2:
134 m_G4Svc->SetUserInitialization(new QGSP);
135 break;
136 case 3:
137 m_G4Svc->SetUserInitialization(new QGSP_BIC);
138 break;
139 case 4:
140 m_G4Svc->SetUserInitialization(new QGSP_BERT);
141 break;
142 case 5:
143 m_G4Svc->SetUserInitialization(new QGSP_BERT_HP);
144 break;
145 case 6:
147 break;
148 case 7:
149 m_G4Svc->SetUserInitialization(new CHIPS);
150 break;
151 case 8:
152 m_G4Svc->SetUserInitialization(new QBBC);
153 break;
154 case 9:
156 break;
157 default:
158 m_G4Svc->SetUserInitialization(new QGSP_BERT);
159 break;
160 }
162 BesRunAction* runAction = new BesRunAction;
163 runAction->SetTDSFlag(m_TDSFlag);
164 runAction->SetAsciiFlag(m_asciiFlag);
165 runAction->SetAsciiFile(m_asciiFile);
166 runAction->SetRootFlag(m_rootFlag);
167 runAction->SetRootFile(m_rootFile);
168 vector<string>::iterator pd;
169 for (pd = m_tuningFile.begin(); pd != m_tuningFile.end(); pd++){
170 std::cout << "tuning File: " << *pd << std::endl;
171 }
172
173 runAction->SetTuningFile(m_tuningFile);
174 m_G4Svc->SetUserAction(runAction);
175
176 BesEventAction* evtAction = new BesEventAction(runAction);
177 m_G4Svc->SetUserAction(evtAction);
178
179 m_G4Svc->SetUserAction(new BesSteppingAction);
180
181 m_G4Svc->SetUserAction(new BesTrackingAction(runAction) );
182
183//#ifdef G4VIS_USE
184//visualization manager
185// G4VisManager* visManager = new BesVisManager;
186// visManager->Initialize();
187//#endif
188
189
190 return StatusCode::SUCCESS;
191}
void SetTuningFile(std::vector< std::string > file)
Definition: BesRunAction.hh:59
void SetRootFile(std::string file)
Definition: BesRunAction.hh:58
void SetTDSFlag(G4bool flag)
Definition: BesRunAction.hh:61
void SetRootFlag(G4bool flag)
Definition: BesRunAction.hh:57
void SetAsciiFlag(std::string flag)
Definition: BesRunAction.hh:55
void SetAsciiFile(std::string file)
Definition: BesRunAction.hh:56
void SetLogLevel(G4int level)
StatusCode bookEmcRootFile()
Definition: BesSim.cc:289
StatusCode bookMdcRootFile()
Definition: BesSim.cc:234
StatusCode bookMucRootFile()
Definition: BesSim.cc:313
StatusCode bookTofRootFile()
Definition: BesSim.cc:249
Definition: G4Svc.h:32
bool MdcRootFlag()
Definition: G4Svc.h:117
bool EmcRootFlag()
Definition: G4Svc.h:119
bool TofRootFlag()
Definition: G4Svc.h:118
void SetUserInitialization(G4VUserDetectorConstruction *userInit)
Definition: G4Svc.cpp:222
int LogLevel()
Definition: G4Svc.h:135
bool MucRootFlag()
Definition: G4Svc.h:120
void SetUserAction(G4UserRunAction *)
Definition: G4Svc.cpp:238
Definition: IG4Svc.h:30

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