CGEM BOSS 6.6.5.i
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 bookCgemRootFile ()
 
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 49 of file BesSim.cc.

49 :
50 Algorithm(name, pSvcLocator)
51{
52 declareProperty("Mdc",m_mdc=1);
53 declareProperty("Cgem",m_cgem=1); // 1: use CGEM IT 0: use DC IT
54 declareProperty("CgemDigitizer",m_CgemDigitizer=2); // 2: geo projection, 3: full digitization
55 declareProperty("CgemMisAligned",m_cgem_misAligned=0); // 0: aligned, 1: misaligned
56 declareProperty("Tof",m_tof=2);
57 declareProperty("Emc",m_emc=2);
58 declareProperty("Muc",m_muc=2);
59 declareProperty("PipeSCM",m_pipeSCM=2);
60 declareProperty("Field",m_field=1);
61 declareProperty("PhysicsList",m_physicsList=0);
62 declareProperty("FormatAR", m_formatAR =0);
63 declareProperty("Tuning",m_tuning=0);
64 declareProperty("TuningFile",m_tuningFile);
65 declareProperty("HitOut",m_hitOut=0);
66 declareProperty("TDSFlag",m_TDSFlag=false);
67 declareProperty("AsciiFlag",m_asciiFlag="00000000");
68 declareProperty("AsciiFile",m_asciiFile="boost.dat");
69 declareProperty("RootFlag",m_rootFlag=false);
70 declareProperty("RootFile",m_rootFile="Hit.root");
71 declareProperty("CutValue", newcut = 0.7);//unite is mm
72 declareProperty("LogLevel",m_logLevel=5000);
73
74}

Member Function Documentation

◆ beginRun()

StatusCode BesSim::beginRun ( )

Definition at line 207 of file BesSim.cc.

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

◆ bookCgemRootFile()

StatusCode BesSim::bookCgemRootFile ( )

Definition at line 260 of file BesSim.cc.

261{
262 MsgStream log(msgSvc(), name());
263 NTuplePtr nt(ntupleSvc(), "FILE801/n1");
264 NTuple::Tuple* tupleCgem;
265 if(nt) tupleCgem = nt;
266 else {
267 tupleCgem = ntupleSvc()->book("FILE801/n1",CLID_ColumnWiseTuple,"BesSim");
268 m_G4Svc->SetTupleCgem(tupleCgem);
269 }
270 return StatusCode::SUCCESS;
271}
INTupleSvc * ntupleSvc()
void SetTupleCgem(NTuple::Tuple *tuple)
Definition G4Svc.h:105

Referenced by initialize().

◆ bookEmcRootFile()

StatusCode BesSim::bookEmcRootFile ( )

Definition at line 315 of file BesSim.cc.

316{
317 NTuplePtr nt1(ntupleSvc(), "FILE803/n1");
318 NTuple::Tuple* tupleEmc1;
319 if(nt1) tupleEmc1 = nt1;
320 else {
321 tupleEmc1 = ntupleSvc()->book("FILE803/n1",CLID_ColumnWiseTuple,"BesSim");
322 m_G4Svc->SetTupleEmc1(tupleEmc1);
323 }
324
325 NTuplePtr nt2(ntupleSvc(), "FILE803/n2");
326 NTuple::Tuple* tupleEmc2;
327 if(nt2) tupleEmc2 = nt2;
328 else {
329 tupleEmc2 = ntupleSvc()->book("FILE803/n2",CLID_ColumnWiseTuple,"BesSim");
330 m_G4Svc->SetTupleEmc2(tupleEmc2);
331 }
332
333
334 return StatusCode::SUCCESS;
335}
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 247 of file BesSim.cc.

248{
249 MsgStream log(msgSvc(), name());
250 NTuplePtr nt(ntupleSvc(), "FILE801/n1");
251 NTuple::Tuple* tupleMdc;
252 if(nt) tupleMdc = nt;
253 else {
254 tupleMdc = ntupleSvc()->book("FILE801/n1",CLID_ColumnWiseTuple,"BesSim");
255 m_G4Svc->SetTupleMdc(tupleMdc);
256 }
257 return StatusCode::SUCCESS;
258}
void SetTupleMdc(NTuple::Tuple *tuple)
Definition G4Svc.h:98

Referenced by initialize().

◆ bookMucRootFile()

StatusCode BesSim::bookMucRootFile ( )

Definition at line 339 of file BesSim.cc.

340{
341 MsgStream log(msgSvc(), name());
342 NTuplePtr nt(ntupleSvc(), "FILE804/n1");
343 NTuple::Tuple* tupleMuc;
344 if(nt) tupleMuc = nt;
345 else {
346 tupleMuc = ntupleSvc()->book("FILE804/n1",CLID_ColumnWiseTuple,"BesSim");
347 m_G4Svc->SetTupleMuc(tupleMuc);
348 }
349 return StatusCode::SUCCESS;
350}
void SetTupleMuc(NTuple::Tuple *tuple)
Definition G4Svc.h:123

Referenced by initialize().

◆ bookTofRootFile()

StatusCode BesSim::bookTofRootFile ( )

Definition at line 275 of file BesSim.cc.

276{
277 MsgStream log(msgSvc(), name());
278 NTuplePtr nt1(ntupleSvc(), "FILE802/n1");
279 NTuple::Tuple* tupleTof1;
280 if(nt1) tupleTof1 = nt1;
281 else {
282 tupleTof1 = ntupleSvc()->book("FILE802/n1",CLID_ColumnWiseTuple,"BesSim");
283 m_G4Svc->SetTupleTof1(tupleTof1);
284 }
285 NTuplePtr nt2(ntupleSvc(), "FILE802/n2");
286 NTuple::Tuple* tupleTof2;
287 if(nt2) tupleTof2 = nt2;
288 else {
289 tupleTof2 = ntupleSvc()->book("FILE802/n2",CLID_ColumnWiseTuple,"BesSim");
290 m_G4Svc->SetTupleTof2(tupleTof2);
291 }
292 NTuplePtr nt3(ntupleSvc(), "FILE802/n3");
293 NTuple::Tuple* tupleTof3;
294 if(nt3) tupleTof3 = nt3;
295 else {
296 tupleTof3 = ntupleSvc()->book("FILE802/n3",CLID_ColumnWiseTuple,"BesSim");
297 m_G4Svc->SetTupleTof3(tupleTof3);
298 }
299
300 // NTuplePtr nt4(ntupleSvc(), "FILE802/n4");
301 //NTuple::Tuple* tupleTof4;
302 //if(nt4) tupleTof4 = nt4;
303 //else {
304 //tupleTof4 = ntupleSvc()->book("FILE802/n4",CLID_ColumnWiseTuple,"BesSim");
305 //m_G4Svc->SetTupleTof4(tupleTof4);
306 //}
307
308
309
310 return StatusCode::SUCCESS;
311}
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 354 of file BesSim.cc.

354 {
355
356 MsgStream log(msgSvc(), name());
357
358 //log << MSG::INFO << "event ID:"<<m_nEvent<<endreq;
359 if(m_nEvent%m_logLevel == 0)
360 std::cout<<" BesSim Begin of Event: "<<m_nEvent<<std::endl;
361
362 m_G4Svc->SimulateEvents(m_nEvent);
363 m_nEvent++;
364
365 return StatusCode::SUCCESS;
366}
void SimulateEvents(int)
Definition G4Svc.cpp:386

◆ finalize()

StatusCode BesSim::finalize ( )

Definition at line 370 of file BesSim.cc.

370 {
371
372 MsgStream log(msgSvc(), name());
373 log << MSG::INFO << "finalize()" << endreq;
374 log << MSG::DEBUG << "\t terminating the current G4 run"<<endreq;
375 m_G4Svc->RunTerminate();
376
377 std::cout<<"BesSim::finalize(), total events in this run: "<<m_nEvent<<std::endl;
378
379 if(m_G4Svc->runMgr() != 0)
380 delete m_G4Svc->runMgr();
381
382#ifdef G4VIS_USE
383 if(m_G4Svc->visMgr() != 0)
384 delete m_G4Svc->visMgr();
385#endif
386
387
388 return StatusCode::SUCCESS;
389}
void RunTerminate()
Definition G4Svc.cpp:381
G4RunManager * runMgr()
Definition G4Svc.cpp:128

◆ initialize()

StatusCode BesSim::initialize ( )

Definition at line 78 of file BesSim.cc.

78 {
79
80 MsgStream log(msgSvc(), name());
81 log << MSG::INFO << "initialize()" << endreq;
82 m_nEvent = 0;
83 m_nRun = 1;
84
85 //caogf for random seed
86 static const bool CREATEIFNOTTHERE(true);
87 StatusCode RndmStatus = service("BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
88 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
89 {
90 log << MSG::ERROR << " Could not initialize Random Number Service" << endreq;
91 return RndmStatus;
92 }
93
94 StatusCode status;
95 IG4Svc *tmpSvc;
96 status = service("G4Svc",tmpSvc);
97 if (status.isSuccess()) {
98 log << MSG::INFO << "got the G4Svc" << endreq;
99 m_G4Svc=dynamic_cast<G4Svc *>(tmpSvc);
100 } else {
101 log << MSG::ERROR << "could not get the G4Svc" << endreq;
102 return StatusCode::FAILURE;
103 }
104
105 //book Ntuple
106 if(m_G4Svc->MdcRootFlag())
108
109 if(m_G4Svc->CgemRootFlag())
111
112 if(m_G4Svc->TofRootFlag())
114
115 if(m_G4Svc->EmcRootFlag())
117
118 if(m_G4Svc->MucRootFlag())
120
121 log << MSG::INFO << "Four sub-detector construction flags: " <<m_mdc<<" "<<m_cgem<<" "<<m_tof<<" "<<m_emc<<" "<<m_muc<<endreq;
122
123 ReadBoostRoot* readBoost =new ReadBoostRoot(m_mdc, m_cgem, m_tof,m_emc, m_muc, m_field,m_formatAR,m_tuning,m_hitOut);
124 BesMdcGeoParameter * mdcGeoService;
125 mdcGeoService = new BesMdcGeoParameter;
126
127 // CHECK
128 // ISvcLocator* svcLocator = Gaudi::svcLocator();
129 // CgemGeomSvc * cgemGeoService = new CgemGeomSvc("CgemGeomSvc", svcLocator);
130
131 log << MSG::INFO << "Instantiating BESIII Detector" << endreq;
132
133 BesSensitiveManager* sensitiveManager = new BesSensitiveManager;
134 sensitiveManager->SetLogLevel(m_G4Svc->LogLevel());
135
136 BesDetectorConstruction* detectorConstruction = new BesDetectorConstruction();
137 detectorConstruction->SetPipeSCM(m_pipeSCM);
138 m_G4Svc->SetUserInitialization(detectorConstruction);
139
140 switch(m_physicsList)
141 {
142 case 1:
144 break;
145 case 2:
146 m_G4Svc->SetUserInitialization(new QGSP);
147 break;
148 case 3:
149 m_G4Svc->SetUserInitialization(new QGSP_BIC);
150 break;
151 case 4:
152 m_G4Svc->SetUserInitialization(new QGSP_BERT);
153 break;
154 case 5:
155 m_G4Svc->SetUserInitialization(new QGSP_BERT_HP);
156 break;
157 case 6:
159 break;
160 case 7:
161 m_G4Svc->SetUserInitialization(new CHIPS);
162 break;
163 case 8:
164 m_G4Svc->SetUserInitialization(new QBBC);
165 break;
166 case 9:
168 break;
169 default:
170 m_G4Svc->SetUserInitialization(new QGSP_BERT);
171 break;
172 }
174 BesRunAction* runAction = new BesRunAction;
175 runAction->SetTDSFlag(m_TDSFlag);
176 runAction->SetAsciiFlag(m_asciiFlag);
177 runAction->SetAsciiFile(m_asciiFile);
178 runAction->SetRootFlag(m_rootFlag);
179 runAction->SetRootFile(m_rootFile);
180 vector<string>::iterator pd;
181 for (pd = m_tuningFile.begin(); pd != m_tuningFile.end(); pd++){
182 std::cout << "tuning File: " << *pd << std::endl;
183 }
184
185 runAction->SetTuningFile(m_tuningFile);
186 m_G4Svc->SetUserAction(runAction);
187
188 BesEventAction* evtAction = new BesEventAction(runAction);
189 m_G4Svc->SetUserAction(evtAction);
190
191 m_G4Svc->SetUserAction(new BesSteppingAction);
192
193 m_G4Svc->SetUserAction(new BesTrackingAction(runAction) );
194
195//#ifdef G4VIS_USE
196//visualization manager
197// G4VisManager* visManager = new BesVisManager;
198// visManager->Initialize();
199//#endif
200
201
202 return StatusCode::SUCCESS;
203}
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()
Definition BesSim.cc:315
StatusCode bookMdcRootFile()
Definition BesSim.cc:247
StatusCode bookCgemRootFile()
Definition BesSim.cc:260
StatusCode bookMucRootFile()
Definition BesSim.cc:339
StatusCode bookTofRootFile()
Definition BesSim.cc:275
Definition G4Svc.h:32
bool MdcRootFlag()
Definition G4Svc.h:125
bool EmcRootFlag()
Definition G4Svc.h:128
bool CgemRootFlag()
Definition G4Svc.h:126
bool TofRootFlag()
Definition G4Svc.h:127
void SetUserInitialization(G4VUserDetectorConstruction *userInit)
Definition G4Svc.cpp:228
int LogLevel()
Definition G4Svc.h:144
bool MucRootFlag()
Definition G4Svc.h:129
void SetUserAction(G4UserRunAction *)
Definition G4Svc.cpp:244

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