BOSS 7.0.4
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 ()
 
 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 InstallArea/include/BesSim/BesSim/BesSim.hh.

Constructor & Destructor Documentation

◆ BesSim() [1/2]

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

Definition at line 48 of file BesSim.cc.

48 :
49 Algorithm(name, pSvcLocator)
50{
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);//unite is mm
68 declareProperty("LogLevel",m_logLevel=5000);
69
70}

◆ BesSim() [2/2]

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

Member Function Documentation

◆ beginRun() [1/2]

StatusCode BesSim::beginRun ( )

Definition at line 209 of file BesSim.cc.

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

◆ beginRun() [2/2]

StatusCode BesSim::beginRun ( )

◆ bookEmcRootFile() [1/2]

StatusCode BesSim::bookEmcRootFile ( )

Definition at line 301 of file BesSim.cc.

302{
303 NTuplePtr nt1(ntupleSvc(), "FILE803/n1");
304 NTuple::Tuple* tupleEmc1;
305 if(nt1) tupleEmc1 = nt1;
306 else {
307 tupleEmc1 = ntupleSvc()->book("FILE803/n1",CLID_ColumnWiseTuple,"BesSim");
308 m_G4Svc->SetTupleEmc1(tupleEmc1);
309 }
310
311 NTuplePtr nt2(ntupleSvc(), "FILE803/n2");
312 NTuple::Tuple* tupleEmc2;
313 if(nt2) tupleEmc2 = nt2;
314 else {
315 tupleEmc2 = ntupleSvc()->book("FILE803/n2",CLID_ColumnWiseTuple,"BesSim");
316 m_G4Svc->SetTupleEmc2(tupleEmc2);
317 }
318
319
320 return StatusCode::SUCCESS;
321}
void SetTupleEmc1(NTuple::Tuple *tuple)
void SetTupleEmc2(NTuple::Tuple *tuple)

Referenced by initialize().

◆ bookEmcRootFile() [2/2]

StatusCode BesSim::bookEmcRootFile ( )

◆ bookMdcRootFile() [1/2]

StatusCode BesSim::bookMdcRootFile ( )

Definition at line 248 of file BesSim.cc.

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

Referenced by initialize().

◆ bookMdcRootFile() [2/2]

StatusCode BesSim::bookMdcRootFile ( )

◆ bookMucRootFile() [1/2]

StatusCode BesSim::bookMucRootFile ( )

Definition at line 325 of file BesSim.cc.

326{
327 MsgStream log(msgSvc(), name());
328 NTuplePtr nt(ntupleSvc(), "FILE804/n1");
329 NTuple::Tuple* tupleMuc;
330 if(nt) tupleMuc = nt;
331 else {
332 tupleMuc = ntupleSvc()->book("FILE804/n1",CLID_ColumnWiseTuple,"BesSim");
333 m_G4Svc->SetTupleMuc(tupleMuc);
334 }
335 return StatusCode::SUCCESS;
336}
void SetTupleMuc(NTuple::Tuple *tuple)

Referenced by initialize().

◆ bookMucRootFile() [2/2]

StatusCode BesSim::bookMucRootFile ( )

◆ bookTofRootFile() [1/2]

StatusCode BesSim::bookTofRootFile ( )

Definition at line 263 of file BesSim.cc.

264{
265 MsgStream log(msgSvc(), name());
266 NTuplePtr nt1(ntupleSvc(), "FILE802/n1");
267 NTuple::Tuple* tupleTof1;
268 if(nt1) tupleTof1 = nt1;
269 else {
270 tupleTof1 = ntupleSvc()->book("FILE802/n1",CLID_ColumnWiseTuple,"BesSim");
271 m_G4Svc->SetTupleTof1(tupleTof1);
272 }
273 NTuplePtr nt2(ntupleSvc(), "FILE802/n2");
274 NTuple::Tuple* tupleTof2;
275 if(nt2) tupleTof2 = nt2;
276 else {
277 tupleTof2 = ntupleSvc()->book("FILE802/n2",CLID_ColumnWiseTuple,"BesSim");
278 m_G4Svc->SetTupleTof2(tupleTof2);
279 }
280 NTuplePtr nt3(ntupleSvc(), "FILE802/n3");
281 NTuple::Tuple* tupleTof3;
282 if(nt3) tupleTof3 = nt3;
283 else {
284 tupleTof3 = ntupleSvc()->book("FILE802/n3",CLID_ColumnWiseTuple,"BesSim");
285 m_G4Svc->SetTupleTof3(tupleTof3);
286 }
287 /*
288 NTuplePtr nt4(ntupleSvc(), "FILE802/n4");
289 NTuple::Tuple* tupleTof4;
290 if(nt4) tupleTof4 = nt4;
291 else {
292 tupleTof4 = ntupleSvc()->book("FILE802/n4",CLID_ColumnWiseTuple,"BesSim");
293 m_G4Svc->SetTupleTof4(tupleTof4);
294 }
295 */
296 return StatusCode::SUCCESS;
297}
void SetTupleTof3(NTuple::Tuple *tuple)
void SetTupleTof2(NTuple::Tuple *tuple)
void SetTupleTof1(NTuple::Tuple *tuple)

Referenced by initialize().

◆ bookTofRootFile() [2/2]

StatusCode BesSim::bookTofRootFile ( )

◆ execute() [1/2]

StatusCode BesSim::execute ( )

Definition at line 340 of file BesSim.cc.

340 {
341
342 MsgStream log(msgSvc(), name());
343
344 //log << MSG::INFO << "event ID:"<<m_nEvent<<endreq;
345 if(m_nEvent%m_logLevel == 0)
346 std::cout<<" BesSim Begin of Event: "<<m_nEvent<<std::endl;
347
348 m_G4Svc->SimulateEvents(m_nEvent);
349 m_nEvent++;
350
351 return StatusCode::SUCCESS;
352}
void SimulateEvents(int)
Definition: G4Svc.cpp:381

◆ execute() [2/2]

StatusCode BesSim::execute ( )

◆ finalize() [1/2]

StatusCode BesSim::finalize ( )

Definition at line 356 of file BesSim.cc.

356 {
357
358 MsgStream log(msgSvc(), name());
359 log << MSG::INFO << "finalize()" << endreq;
360 log << MSG::DEBUG << "\t terminating the current G4 run"<<endreq;
361 m_G4Svc->RunTerminate();
362
363 std::cout<<"BesSim::finalize(), total events in this run: "<<m_nEvent<<std::endl;
364
365 if(m_G4Svc->runMgr() != 0)
366 delete m_G4Svc->runMgr();
367
368#ifdef G4VIS_USE
369 if(m_G4Svc->visMgr() != 0)
370 delete m_G4Svc->visMgr();
371#endif
372
373
374 return StatusCode::SUCCESS;
375}
void RunTerminate()
Definition: G4Svc.cpp:376
G4RunManager * runMgr()
Definition: G4Svc.cpp:123

◆ finalize() [2/2]

StatusCode BesSim::finalize ( )

◆ initialize() [1/2]

StatusCode BesSim::initialize ( )

Definition at line 74 of file BesSim.cc.

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

◆ initialize() [2/2]

StatusCode BesSim::initialize ( )

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