BOSS 8.0.0
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 13 of file BesSim.hh.

Constructor & Destructor Documentation

◆ BesSim()

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

Definition at line 54 of file BesSim.cc.

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

Referenced by BesSim().

Member Function Documentation

◆ beginRun()

StatusCode BesSim::beginRun ( )

Definition at line 213 of file BesSim.cc.

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

Referenced by execute().

◆ bookEmcRootFile()

StatusCode BesSim::bookEmcRootFile ( )

Definition at line 315 of file BesSim.cc.

315 {
316 NTuplePtr nt1( ntupleSvc(), "FILE803/n1" );
317 NTuple::Tuple* tupleEmc1;
318 if ( nt1 ) tupleEmc1 = nt1;
319 else
320 {
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 {
330 tupleEmc2 = ntupleSvc()->book( "FILE803/n2", CLID_ColumnWiseTuple, "BesSim" );
331 m_G4Svc->SetTupleEmc2( tupleEmc2 );
332 }
333
334 return StatusCode::SUCCESS;
335}
INTupleSvc * ntupleSvc()

Referenced by initialize().

◆ bookMdcRootFile()

StatusCode BesSim::bookMdcRootFile ( )

Definition at line 260 of file BesSim.cc.

260 {
261 MsgStream log( msgSvc(), name() );
262 NTuplePtr nt( ntupleSvc(), "FILE801/n1" );
263 NTuple::Tuple* tupleMdc;
264 if ( nt ) tupleMdc = nt;
265 else
266 {
267 tupleMdc = ntupleSvc()->book( "FILE801/n1", CLID_ColumnWiseTuple, "BesSim" );
268 m_G4Svc->SetTupleMdc( tupleMdc );
269 }
270 return StatusCode::SUCCESS;
271}

Referenced by initialize().

◆ bookMucRootFile()

StatusCode BesSim::bookMucRootFile ( )

Definition at line 339 of file BesSim.cc.

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

Referenced by initialize().

◆ bookTofRootFile()

StatusCode BesSim::bookTofRootFile ( )

Definition at line 275 of file BesSim.cc.

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

Referenced by initialize().

◆ execute()

StatusCode BesSim::execute ( )

Definition at line 354 of file BesSim.cc.

354 {
355 if ( !m_beginRun )
356 {
357 StatusCode sc = beginRun();
358 if ( sc.isFailure() )
359 {
360 error() << "beginRun failed" << endmsg;
361 return StatusCode::FAILURE;
362 }
363 m_beginRun = true;
364 }
365
366 MsgStream log( msgSvc(), name() );
367
368 // log << MSG::INFO << "event ID:"<<m_nEvent<<endmsg;
369 if ( m_nEvent % m_logLevel == 0 )
370 std::cout << " BesSim Begin of Event: " << m_nEvent << std::endl;
371
372 m_G4Svc->SimulateEvents( m_nEvent );
373 m_nEvent++;
374
375 return StatusCode::SUCCESS;
376}
StatusCode beginRun()
Definition BesSim.cc:213

◆ finalize()

StatusCode BesSim::finalize ( )

Definition at line 380 of file BesSim.cc.

380 {
381
382 MsgStream log( msgSvc(), name() );
383 log << MSG::INFO << "finalize()" << endmsg;
384 log << MSG::DEBUG << "\t terminating the current G4 run" << endmsg;
385 m_G4Svc->RunTerminate();
386
387 std::cout << "BesSim::finalize(), total events in this run: " << m_nEvent << std::endl;
388
389 if ( m_G4Svc->runMgr() != 0 ) delete m_G4Svc->runMgr();
390
391#ifdef G4VIS_USE
392 if ( m_G4Svc->visMgr() != 0 ) delete m_G4Svc->visMgr();
393#endif
394
395 return StatusCode::SUCCESS;
396}

◆ initialize()

StatusCode BesSim::initialize ( )

Definition at line 79 of file BesSim.cc.

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

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