#include <BesSim.hh>
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 () |
Private Attributes | |
int | m_nEvent |
int | m_nRun |
G4Svc * | m_G4Svc |
int | m_mdc |
int | m_tof |
int | m_emc |
int | m_muc |
int | m_pipeSCM |
int | m_field |
int | m_physicsList |
int | m_formatAR |
int | m_tuning |
int | m_hitOut |
bool | m_TDSFlag |
double | newcut |
std::vector< std::string > | m_tuningFile |
std::string | m_asciiFlag |
std::string | m_asciiFile |
bool | m_rootFlag |
std::string | m_rootFile |
IBesRndmGenSvc * | p_BesRndmGenSvc |
int | m_logLevel |
Definition at line 12 of file BesSim.hh.
BesSim::BesSim | ( | const std::string & | name, | |
ISvcLocator * | pSvcLocator | |||
) |
Definition at line 48 of file BesSim.cc.
References m_asciiFile, m_asciiFlag, m_emc, m_field, m_formatAR, m_hitOut, m_logLevel, m_mdc, m_muc, m_physicsList, m_pipeSCM, m_rootFile, m_rootFlag, m_TDSFlag, m_tof, m_tuning, m_tuningFile, and newcut.
00048 : 00049 Algorithm(name, pSvcLocator) 00050 { 00051 declareProperty("Mdc",m_mdc=2); 00052 declareProperty("Tof",m_tof=2); 00053 declareProperty("Emc",m_emc=2); 00054 declareProperty("Muc",m_muc=2); 00055 declareProperty("PipeSCM",m_pipeSCM=2); 00056 declareProperty("Field",m_field=1); 00057 declareProperty("PhysicsList",m_physicsList=0); 00058 declareProperty("FormatAR", m_formatAR =0); 00059 declareProperty("Tuning",m_tuning=0); 00060 declareProperty("TuningFile",m_tuningFile); 00061 declareProperty("HitOut",m_hitOut=0); 00062 declareProperty("TDSFlag",m_TDSFlag=false); 00063 declareProperty("AsciiFlag",m_asciiFlag="00000000"); 00064 declareProperty("AsciiFile",m_asciiFile="boost.dat"); 00065 declareProperty("RootFlag",m_rootFlag=false); 00066 declareProperty("RootFile",m_rootFile="Hit.root"); 00067 declareProperty("CutValue", newcut = 0.7);//unite is mm 00068 declareProperty("LogLevel",m_logLevel=5000); 00069 00070 }
StatusCode BesSim::beginRun | ( | ) |
Definition at line 209 of file BesSim.cc.
References Bes_Common::DEBUG, G4Svc::G4Init(), IBesRndmGenSvc::GetEngine(), m_G4Svc, msgSvc(), p_BesRndmGenSvc, and G4Svc::RunInitialize().
00210 { 00211 static int flag = -1; 00212 if(flag<0) 00213 { 00214 MsgStream log(msgSvc(), name()); 00215 log << MSG::DEBUG << "\t start initializing G4 "<<endreq; 00216 //new visMgr, StartUISession(), runMgr->Initialize() 00217 m_G4Svc->G4Init(); 00218 00219 //to do: runMgr->RunInitialization() 00220 m_G4Svc->RunInitialize(); 00221 00222 //G4VPhysicalVolume* g4wv =G4TransportationManager::GetTransportationManager()-> GetNavigatorForTracking()->GetWorldVolume(); //Apply this for storing TOF GDML 00223 //G4GDMLWriter g4writerBes("/afs/ihep.ac.cn/bes3/offline/sw/packages/BesGDML/2.8.0/GDMLSchema/gdml.xsd", "Bes.gdml",2); 00224 //G4GDMLWriter g4writerMdc("/afs/ihep.ac.cn/bes3/offline/sw/packages/BesGDML/2.8.0/GDMLSchema/gdml.xsd", "Mdc.gdml",2); 00225 //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 00226 //G4GDMLWriter g4writerEmc("/afs/ihep.ac.cn/bes3/offline/sw/packages/BesGDML/2.8.0/GDMLSchema/gdml.xsd", "Emc.gdml",2); 00227 //G4GDMLWriter g4writerMuc("/afs/ihep.ac.cn/bes3/offline/sw/packages/BesGDML/2.8.0/GDMLSchema/gdml.xsd", "Muc.gdml",2); 00228 //try 00229 //{ 00230 //g4writerBes.DumpGeometryInfo(g4wv); 00231 //g4writerTof.DumpGeometryInfo(g4wv->GetLogicalVolume()->GetDaughter(0)); //Changed from 0 to 3//Apply this for storing TOF GDML 00232 00233 //} 00234 //catch(std::logic_error &lerr) 00235 //{ 00236 // std::cout << "Caught an exception: " 00237 // << lerr.what () << std::endl; 00238 //} 00239 00240 //For random seed added by caogf. Note the position of the code, otherwise it is not available. 00241 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->GetEngine("SIM"); 00242 HepRandom::setTheEngine(engine); 00243 HepRandom::showEngineStatus(); 00244 } 00245 return StatusCode::SUCCESS; 00246 }
StatusCode BesSim::bookEmcRootFile | ( | ) |
Definition at line 301 of file BesSim.cc.
References m_G4Svc, ntupleSvc(), G4Svc::SetTupleEmc1(), and G4Svc::SetTupleEmc2().
Referenced by initialize().
00302 { 00303 NTuplePtr nt1(ntupleSvc(), "FILE803/n1"); 00304 NTuple::Tuple* tupleEmc1; 00305 if(nt1) tupleEmc1 = nt1; 00306 else { 00307 tupleEmc1 = ntupleSvc()->book("FILE803/n1",CLID_ColumnWiseTuple,"BesSim"); 00308 m_G4Svc->SetTupleEmc1(tupleEmc1); 00309 } 00310 00311 NTuplePtr nt2(ntupleSvc(), "FILE803/n2"); 00312 NTuple::Tuple* tupleEmc2; 00313 if(nt2) tupleEmc2 = nt2; 00314 else { 00315 tupleEmc2 = ntupleSvc()->book("FILE803/n2",CLID_ColumnWiseTuple,"BesSim"); 00316 m_G4Svc->SetTupleEmc2(tupleEmc2); 00317 } 00318 00319 00320 return StatusCode::SUCCESS; 00321 }
StatusCode BesSim::bookMdcRootFile | ( | ) |
Definition at line 248 of file BesSim.cc.
References m_G4Svc, msgSvc(), ntupleSvc(), and G4Svc::SetTupleMdc().
Referenced by initialize().
00249 { 00250 MsgStream log(msgSvc(), name()); 00251 NTuplePtr nt(ntupleSvc(), "FILE801/n1"); 00252 NTuple::Tuple* tupleMdc; 00253 if(nt) tupleMdc = nt; 00254 else { 00255 tupleMdc = ntupleSvc()->book("FILE801/n1",CLID_ColumnWiseTuple,"BesSim"); 00256 m_G4Svc->SetTupleMdc(tupleMdc); 00257 } 00258 return StatusCode::SUCCESS; 00259 }
StatusCode BesSim::bookMucRootFile | ( | ) |
Definition at line 325 of file BesSim.cc.
References m_G4Svc, msgSvc(), ntupleSvc(), and G4Svc::SetTupleMuc().
Referenced by initialize().
00326 { 00327 MsgStream log(msgSvc(), name()); 00328 NTuplePtr nt(ntupleSvc(), "FILE804/n1"); 00329 NTuple::Tuple* tupleMuc; 00330 if(nt) tupleMuc = nt; 00331 else { 00332 tupleMuc = ntupleSvc()->book("FILE804/n1",CLID_ColumnWiseTuple,"BesSim"); 00333 m_G4Svc->SetTupleMuc(tupleMuc); 00334 } 00335 return StatusCode::SUCCESS; 00336 }
StatusCode BesSim::bookTofRootFile | ( | ) |
Definition at line 263 of file BesSim.cc.
References m_G4Svc, msgSvc(), ntupleSvc(), G4Svc::SetTupleTof1(), G4Svc::SetTupleTof2(), and G4Svc::SetTupleTof3().
Referenced by initialize().
00264 { 00265 MsgStream log(msgSvc(), name()); 00266 NTuplePtr nt1(ntupleSvc(), "FILE802/n1"); 00267 NTuple::Tuple* tupleTof1; 00268 if(nt1) tupleTof1 = nt1; 00269 else { 00270 tupleTof1 = ntupleSvc()->book("FILE802/n1",CLID_ColumnWiseTuple,"BesSim"); 00271 m_G4Svc->SetTupleTof1(tupleTof1); 00272 } 00273 NTuplePtr nt2(ntupleSvc(), "FILE802/n2"); 00274 NTuple::Tuple* tupleTof2; 00275 if(nt2) tupleTof2 = nt2; 00276 else { 00277 tupleTof2 = ntupleSvc()->book("FILE802/n2",CLID_ColumnWiseTuple,"BesSim"); 00278 m_G4Svc->SetTupleTof2(tupleTof2); 00279 } 00280 NTuplePtr nt3(ntupleSvc(), "FILE802/n3"); 00281 NTuple::Tuple* tupleTof3; 00282 if(nt3) tupleTof3 = nt3; 00283 else { 00284 tupleTof3 = ntupleSvc()->book("FILE802/n3",CLID_ColumnWiseTuple,"BesSim"); 00285 m_G4Svc->SetTupleTof3(tupleTof3); 00286 } 00287 /* 00288 NTuplePtr nt4(ntupleSvc(), "FILE802/n4"); 00289 NTuple::Tuple* tupleTof4; 00290 if(nt4) tupleTof4 = nt4; 00291 else { 00292 tupleTof4 = ntupleSvc()->book("FILE802/n4",CLID_ColumnWiseTuple,"BesSim"); 00293 m_G4Svc->SetTupleTof4(tupleTof4); 00294 } 00295 */ 00296 return StatusCode::SUCCESS; 00297 }
StatusCode BesSim::execute | ( | ) |
Definition at line 340 of file BesSim.cc.
References m_G4Svc, m_logLevel, m_nEvent, msgSvc(), and G4Svc::SimulateEvents().
00340 { 00341 00342 MsgStream log(msgSvc(), name()); 00343 00344 //log << MSG::INFO << "event ID:"<<m_nEvent<<endreq; 00345 if(m_nEvent%m_logLevel == 0) 00346 std::cout<<" BesSim Begin of Event: "<<m_nEvent<<std::endl; 00347 00348 m_G4Svc->SimulateEvents(m_nEvent); 00349 m_nEvent++; 00350 00351 return StatusCode::SUCCESS; 00352 }
StatusCode BesSim::finalize | ( | ) |
Definition at line 356 of file BesSim.cc.
References Bes_Common::DEBUG, Bes_Common::INFO, m_G4Svc, m_nEvent, msgSvc(), G4Svc::runMgr(), and G4Svc::RunTerminate().
00356 { 00357 00358 MsgStream log(msgSvc(), name()); 00359 log << MSG::INFO << "finalize()" << endreq; 00360 log << MSG::DEBUG << "\t terminating the current G4 run"<<endreq; 00361 m_G4Svc->RunTerminate(); 00362 00363 std::cout<<"BesSim::finalize(), total events in this run: "<<m_nEvent<<std::endl; 00364 00365 if(m_G4Svc->runMgr() != 0) 00366 delete m_G4Svc->runMgr(); 00367 00368 #ifdef G4VIS_USE 00369 if(m_G4Svc->visMgr() != 0) 00370 delete m_G4Svc->visMgr(); 00371 #endif 00372 00373 00374 return StatusCode::SUCCESS; 00375 }
StatusCode BesSim::initialize | ( | ) |
Definition at line 74 of file BesSim.cc.
References bookEmcRootFile(), bookMdcRootFile(), bookMucRootFile(), bookTofRootFile(), detVerSvc, G4Svc::EmcRootFlag(), calibUtil::ERROR, Bes_Common::INFO, G4Svc::LogLevel(), m_asciiFile, m_asciiFlag, m_emc, m_field, m_formatAR, m_G4Svc, m_hitOut, m_mdc, m_muc, m_nEvent, m_nRun, m_physicsList, m_pipeSCM, m_rootFile, m_rootFlag, m_TDSFlag, m_tof, m_tuning, m_tuningFile, G4Svc::MdcRootFlag(), msgSvc(), G4Svc::MucRootFlag(), p_BesRndmGenSvc, IDetVerSvc::phase(), BesRunAction::SetAsciiFile(), BesRunAction::SetAsciiFlag(), BesSensitiveManager::SetLogLevel(), BesDetectorConstruction::SetPipeSCM(), BesRunAction::SetRootFile(), BesRunAction::SetRootFlag(), BesRunAction::SetTDSFlag(), BesRunAction::SetTuningFile(), G4Svc::SetUserAction(), G4Svc::SetUserInitialization(), and G4Svc::TofRootFlag().
00074 { 00075 00076 MsgStream log(msgSvc(), name()); 00077 log << MSG::INFO << "initialize()" << endreq; 00078 m_nEvent = 0; 00079 m_nRun = 1; 00080 00081 //caogf for random seed 00082 static const bool CREATEIFNOTTHERE(true); 00083 StatusCode RndmStatus = service("BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE); 00084 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc) 00085 { 00086 log << MSG::ERROR << " Could not initialize Random Number Service" << endreq; 00087 return RndmStatus; 00088 } 00089 00090 StatusCode status; 00091 IG4Svc *tmpSvc; 00092 status = service("G4Svc",tmpSvc); 00093 if (status.isSuccess()) { 00094 log << MSG::INFO << "got the G4Svc" << endreq; 00095 m_G4Svc=dynamic_cast<G4Svc *>(tmpSvc); 00096 } else { 00097 log << MSG::ERROR << "could not get the G4Svc" << endreq; 00098 return StatusCode::FAILURE; 00099 } 00100 00101 IDetVerSvc* detVerSvc; 00102 StatusCode sc_det = service("DetVerSvc", detVerSvc); 00103 if( sc_det.isFailure() ) { 00104 log << MSG::ERROR << "can't retrieve DetVerSvc instance" << endreq; 00105 return sc_det; 00106 } 00107 00108 int phase = detVerSvc->phase(); 00109 log << MSG::INFO << "** ~~~ZZZ~~~ ** : retrieved DetectorStage = " << phase << endreq; 00110 00111 // phase 1: Endcap TOF Scintillator; phase 2: 4 Scintillator==> 2 MRPC; phase 3: Endcap TOF MRPC 00112 if( phase>2 ) { m_tof = 4; } 00113 00114 //book Ntuple 00115 if(m_G4Svc->MdcRootFlag()) 00116 bookMdcRootFile(); 00117 00118 if(m_G4Svc->TofRootFlag()) 00119 bookTofRootFile(); 00120 00121 if(m_G4Svc->EmcRootFlag()) 00122 bookEmcRootFile(); 00123 00124 if(m_G4Svc->MucRootFlag()) 00125 bookMucRootFile(); 00126 00127 log << MSG::INFO << "Four sub-detector construction flags: " <<m_mdc<<" "<<m_tof<<" "<<m_emc<<" "<<m_muc<<endreq; 00128 00129 ReadBoostRoot* readBoost =new ReadBoostRoot(m_mdc, m_tof,m_emc, m_muc, m_field,m_formatAR,m_tuning,m_hitOut); 00130 BesMdcGeoParameter * mdcGeoService; 00131 mdcGeoService = new BesMdcGeoParameter; 00132 00133 log << MSG::INFO << "Instantiating BESIII Detector" << endreq; 00134 00135 BesSensitiveManager* sensitiveManager = new BesSensitiveManager; 00136 sensitiveManager->SetLogLevel(m_G4Svc->LogLevel()); 00137 00138 BesDetectorConstruction* detectorConstruction = new BesDetectorConstruction(); 00139 detectorConstruction->SetPipeSCM(m_pipeSCM); 00140 m_G4Svc->SetUserInitialization(detectorConstruction); 00141 00142 switch(m_physicsList) 00143 { 00144 case 1: 00145 m_G4Svc->SetUserInitialization(new BesPhysicsList); 00146 break; 00147 case 2: 00148 m_G4Svc->SetUserInitialization(new QGSP); 00149 break; 00150 case 3: 00151 m_G4Svc->SetUserInitialization(new QGSP_BIC); 00152 break; 00153 case 4: 00154 m_G4Svc->SetUserInitialization(new QGSP_BERT); 00155 break; 00156 case 5: 00157 m_G4Svc->SetUserInitialization(new QGSP_BERT_HP); 00158 break; 00159 case 6: 00160 m_G4Svc->SetUserInitialization(new BgsPhysicsList); 00161 break; 00162 case 7: 00163 m_G4Svc->SetUserInitialization(new CHIPS); 00164 break; 00165 case 8: 00166 m_G4Svc->SetUserInitialization(new QBBC); 00167 break; 00168 case 9: 00169 m_G4Svc->SetUserInitialization(new QGSP_BERT_CHIPS); 00170 break; 00171 default: 00172 m_G4Svc->SetUserInitialization(new QGSP_BERT); 00173 break; 00174 } 00175 m_G4Svc->SetUserAction(new BesPrimaryGeneratorAction); 00176 BesRunAction* runAction = new BesRunAction; 00177 runAction->SetTDSFlag(m_TDSFlag); 00178 runAction->SetAsciiFlag(m_asciiFlag); 00179 runAction->SetAsciiFile(m_asciiFile); 00180 runAction->SetRootFlag(m_rootFlag); 00181 runAction->SetRootFile(m_rootFile); 00182 vector<string>::iterator pd; 00183 for (pd = m_tuningFile.begin(); pd != m_tuningFile.end(); pd++){ 00184 std::cout << "tuning File: " << *pd << std::endl; 00185 } 00186 00187 runAction->SetTuningFile(m_tuningFile); 00188 m_G4Svc->SetUserAction(runAction); 00189 00190 BesEventAction* evtAction = new BesEventAction(runAction); 00191 m_G4Svc->SetUserAction(evtAction); 00192 00193 m_G4Svc->SetUserAction(new BesSteppingAction); 00194 00195 m_G4Svc->SetUserAction(new BesTrackingAction(runAction) ); 00196 00197 //#ifdef G4VIS_USE 00198 //visualization manager 00199 // G4VisManager* visManager = new BesVisManager; 00200 // visManager->Initialize(); 00201 //#endif 00202 00203 00204 return StatusCode::SUCCESS; 00205 }
std::string BesSim::m_asciiFile [private] |
std::string BesSim::m_asciiFlag [private] |
int BesSim::m_emc [private] |
int BesSim::m_field [private] |
int BesSim::m_formatAR [private] |
G4Svc* BesSim::m_G4Svc [private] |
Definition at line 29 of file BesSim.hh.
Referenced by beginRun(), bookEmcRootFile(), bookMdcRootFile(), bookMucRootFile(), bookTofRootFile(), execute(), finalize(), and initialize().
int BesSim::m_hitOut [private] |
int BesSim::m_logLevel [private] |
int BesSim::m_mdc [private] |
int BesSim::m_muc [private] |
int BesSim::m_nEvent [private] |
int BesSim::m_nRun [private] |
int BesSim::m_physicsList [private] |
int BesSim::m_pipeSCM [private] |
std::string BesSim::m_rootFile [private] |
bool BesSim::m_rootFlag [private] |
bool BesSim::m_TDSFlag [private] |
int BesSim::m_tof [private] |
int BesSim::m_tuning [private] |
std::vector<std::string> BesSim::m_tuningFile [private] |
double BesSim::newcut [private] |
IBesRndmGenSvc* BesSim::p_BesRndmGenSvc [private] |