void G4Cmd(const char * cmd) { Fun4AllServer *se = Fun4AllServer::instance(); PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco("PHG4RECO"); g4->ApplyCommand(cmd); }
// stupid macro to turn on the geant4 display // we ask Fun4All for a pointer to PHG4Reco // using the ApplyCommand will start up the // G4 cmd interpreter and graphics system // the vis.mac contains the necessary commands to // start up the visualization, the next event will // be displayed. Do not execute this macro // before PHG4Reco was registered with Fun4All PHG4Reco * DisplayOn(const char *mac = "vis_prototype3.mac") { char cmd[100]; Fun4AllServer *se = Fun4AllServer::instance(); PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco("PHG4RECO"); g4->InitRun(se->topNode()); g4->ApplyDisplayAction(); sprintf(cmd, "/control/execute %s", mac); g4->ApplyCommand(cmd); return g4; }
void MaterialScan() { Fun4AllServer *se = Fun4AllServer::instance(); PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco("PHG4RECO"); g4->ApplyCommand("/control/matScan/phi 4 -22.5 45 deg"); g4->ApplyCommand("/control/matScan/phi 5 -22.5 45 deg"); g4->ApplyCommand("/control/matScan/theta 90 0 180 deg"); g4->ApplyCommand("/control/matScan/scan"); }
//! ePHENIX simulation loading script //! \param[in] nEvents Number of events to run. If nEvents=1, then a event display will be shown //! \param[in] outputFile output for G4DSTReader //! \param[in] inputFile HepMC input files, not activated by default int Fun4All_G4_ePHENIX( // // int nEvents = 0, // // int nEvents = 1, // int nEvents = 2, // // int nEvents = 100000, // const char * outputFile = "G4ePHENIX.root", // const char * inputFile = "MyPythia.dat" // ) { //--------------- // Load libraries //--------------- const bool readhepmc = false; // read HepMC files const int absorberactive = 1; // set to 1 to make all absorbers active volumes const bool verbosity = false; // very slow but very detailed logs // const bool verbosity = true; // very slow but very detailed logs gSystem->Load("libg4testbench.so"); gSystem->Load("libfun4all.so"); gSystem->Load("libcemc.so"); gSystem->Load("libg4eval.so"); gROOT->LoadMacro("G4Setup_ePHENIX.C"); G4Init(); // initialize layer numbers for barrel //--------------- // Fun4All server //--------------- Fun4AllServer *se = Fun4AllServer::instance(); se->Verbosity(0); //----------------- // Event generation //----------------- if (readhepmc) { // this module is needed to read the HepMC records into our G4 sims // but only if you read HepMC input files HepMCNodeReader *hr = new HepMCNodeReader(); se->registerSubsystem(hr); } else { // The PHG4ParticleGun runs the same particle(s) in // every event PHG4ParticleGun *gun = new PHG4ParticleGun(); // gun->set_name("geantino+"); // gun->set_name("chargedgeantino"); gun->set_name("mu-"); // gun->set_name("pi-"); // e,pi,mu,p,gamma // gun->set_vtx(0,12.09,200); gun->set_vtx(0, 0, 0); // gun->set_mom(0, 0, 10); gun->set_mom(1.12641e-16, 1.83962, 13.6021); // se->registerSubsystem(gun); PHG4ParticleGenerator *gen = new PHG4ParticleGenerator(); // gen->set_seed(TRandom3(0).GetSeed()); gen->set_seed(1234); // gen->set_name("geantino"); gen->set_name("mu-"); // gun->set_name("pi-"); // e,pi,mu,p,gamma gen->set_vtx(0, 0, 0); gen->set_z_range(0, 0); // gen->set_eta_range(3.5, 3.5); gen->set_eta_range(-4, 4); gen->set_phi_range(TMath::Pi() / 2, TMath::Pi() / 2); gen->set_mom_range(1.0, 50.0); gen->Verbosity(1); // se->registerSubsystem(gen); // //! high Q2 250x10 GeV pythia file from Kieran ReadEICFiles *eic = new ReadEICFiles(); const char *infile = "/direct/phenix+sim02/phnxreco/ePHENIX/jinhuang/display/pythia.ep.250x010.10000000events.seed679586890.root"; eic->OpenInputFile(infile); eic->SetFirstEntry(565); se->registerSubsystem(eic); } //--------------------- // Detector description from loaded macro //--------------------- G4Setup(absorberactive, -1); // G4Setup_Sandbox(absorberactive, -1); // MaterialScan(); //---------------------- // Simulation evaluation //---------------------- // SubsysReco* eval = new PHG4Evaluator("PHG4EVALUATOR","g4eval.root"); //eval->Verbosity(0); //se->registerSubsystem( eval ); //SubsysReco* eval = new PHG4CEMCEvaluator("PHG4CEMCEVALUATOR","out/g4eval.root"); //eval->Verbosity(1); //se->registerSubsystem( eval ); // HitNtuples *hits = new HitNtuples(); // hits->AddNode("FEMCABS",0); // hits->AddNode("FEMC",3); // hits->AddNode("FPRESHOWER",1); // hits->AddNode("GEM",2); // hits->AddNode("GEMLIDFRONT",4); // hits->AddNode("GEMLIDBACK",5); // se->registerSubsystem(hits); //---------------------- // Save selected nodes to root file //---------------------- { // require offline/analysis/g4analysis_fsphenix PHG4DSTReader* ana = new PHG4DSTReader(outputFile); if (nEvents > 0 && nEvents < 3) ana->Verbosity(2); ana->AddNode("GEMSTATION0"); ana->AddNode("GEMSTATION1"); ana->AddNode("GEMSTATION2"); ana->AddNode("GEMSTATION3"); ana->AddNode("GEMSTATION4"); // ana->AddNode("TestDetector_0"); se->registerSubsystem(ana); } //-------------- // IO management //-------------- if (readhepmc) { Fun4AllInputManager *in = new Fun4AllHepMCInputManager("DSTIN"); se->registerInputManager(in); se->fileopen(in->Name(), inputFile); } else { // for single particle generators we just need something which drives // the event loop, the Dummy Input Mgr does just that Fun4AllInputManager *in = new Fun4AllDummyInputManager("JADE"); se->registerInputManager(in); } // File Managers bool save_dst = false; if (save_dst) { Fun4AllDstOutputManager *dstManager = new Fun4AllDstOutputManager( "DSTOUT", "DST.root"); //FVTX nodes dstManager->AddNode("PHG4INEVENT"); dstManager->AddNode("G4TruthInfo"); se->registerOutputManager(dstManager); } //----------------- // Event processing //----------------- if (nEvents == 1) { PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco("PHG4RECO"); g4->ApplyCommand("/control/execute eic.mac"); // g4->StartGui(); se->run(1); se->End(); std::cout << "All done" << std::endl; } else { if (verbosity) { se->Verbosity(3); PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco("PHG4RECO"); g4->Verbosity(3); g4->ApplyCommand("/control/verbose 5"); g4->ApplyCommand("/run/verbose 5"); g4->ApplyCommand("/tracking/verbose 5"); } se->run(nEvents); se->End(); std::cout << "All done" << std::endl; delete se; gSystem->Exit(0); } // //----- // // Exit // //----- return 0; }
PHG4ParticleGun *get_gun(const char *name = "PGUN") { Fun4AllServer *se = Fun4AllServer::instance(); PHG4ParticleGun *pgun = (PHG4ParticleGun *) se->getSubsysReco(name); return pgun; }
int Fun4All_G4_EICIR( const int nEvents = 1, const char * inputFile = "/gpfs02/phenix/prod/sPHENIX/preCDR/pro.1-beta.5/single_particle/spacal1d/fieldmap/G4Hits_sPHENIX_e-_eta0_16GeV.root", const char * outputFile = "G4EICIR.root" ) { //=============== // Input options //=============== // Use particle gun const bool pgun = true; //====================== // What to run //====================== bool do_pipe = false; bool do_magnet = true; // Extended IR bool do_ExtendedIR = true; //--------------- // Load libraries //--------------- gSystem->Load("libfun4all.so"); gSystem->Load("libg4detectors.so"); gSystem->Load("libphhepmc.so"); gSystem->Load("libg4testbench.so"); gSystem->Load("libg4hough.so"); gSystem->Load("libcemc.so"); gSystem->Load("libg4eval.so"); // establish the geometry and reconstruction setup gROOT->LoadMacro("G4Setup_EICIR.C"); G4Init(do_magnet,do_pipe,do_ExtendedIR); int absorberactive = 0; // set to 1 to make all absorbers active volumes // const string magfield = "1.5"; // if like float -> solenoidal field in T, if string use as fieldmap name (including path) const string magfield = "/phenix/upgrades/decadal/fieldmaps/sPHENIX.2d.root"; // if like float -> solenoidal field in T, if string use as fieldmap name (including path) const float magfield_rescale = 1.4/1.5; // scale the map to a 1.4 T field //--------------- // Fun4All server //--------------- Fun4AllServer *se = Fun4AllServer::instance(); //se->Verbosity(100); // uncomment for batch production running with minimal output messages se->Verbosity(Fun4AllServer::VERBOSITY_SOME); // uncomment for some info for interactive running // just if we set some flags somewhere in this macro recoConsts *rc = recoConsts::instance(); // By default every random number generator uses // PHRandomSeed() which reads /dev/urandom to get its seed // if the RANDOMSEED flag is set its value is taken as seed // You can either set this to a random value using PHRandomSeed() // which will make all seeds identical (not sure what the point of // this would be: // rc->set_IntFlag("RANDOMSEED",PHRandomSeed()); // or set it to a fixed value so you can debug your code // rc->set_IntFlag("RANDOMSEED", 12345); //----------------- // Event generation //----------------- if (pgun) { /* angle of particle phi: pz = p * cos(psi) px = p * sin(psi) */ double psi_mrad = 0; double ptot = 250*1; double vx = 0; double vy = 0; double vz = 0; double px = ptot * sin(psi_mrad / 1000.); double py = 0; double pz = ptot * cos(psi_mrad / 1000.); PHG4ParticleGun*gun = new PHG4ParticleGun(); gun->set_name("proton"); gun->set_vtx(vx,vy,vz); gun->set_mom(px,py,pz); se->registerSubsystem(gun); } else { cout << "WARNING: No events being generated!" << endl; } //--------------------- // Detector description //--------------------- G4Setup(absorberactive, magfield, TPythia6Decayer::kAll,do_magnet,do_pipe,do_ExtendedIR,magfield_rescale); //-------------- // IO management //-------------- // for single particle generators we just need something which drives // the event loop, the Dummy Input Mgr does just that Fun4AllInputManager *in = new Fun4AllDummyInputManager( "JADE"); se->registerInputManager( in ); //Convert DST to human command readable TTree for quick poke around the outputs gROOT->LoadMacro("G4_DSTReader_EICIR.C"); G4DSTreader_EICIR( outputFile, // /*int*/ absorberactive ); Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", outputFile); //if (do_dst_compress) DstCompress(out); se->registerOutputManager(out); if (nEvents == 0 && !readhits && !readhepmc) { cout << "using 0 for number of events is a bad idea when using particle generators" << endl; cout << "it will run forever, so I just return without running anything" << endl; return; } if (nEvents < 0) { PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco("PHG4RECO"); g4->ApplyCommand("/control/execute vis.mac"); //g4->StartGui(); se->run(1); se->End(); std::cout << "All done" << std::endl; std::cout << "==== Useful display commands ==" << std::endl; cout << "draw axis: " << endl; cout << " G4Cmd(\"/vis/scene/add/axes 0 0 0 50 cm\")" << endl; cout << "zoom" << endl; cout << " G4Cmd(\"/vis/viewer/zoom 1\")" << endl; cout << "viewpoint:" << endl; cout << " G4Cmd(\"/vis/viewer/set/viewpointThetaPhi 0 0\")" << endl; cout << "panTo:" << endl; cout << " G4Cmd(\"/vis/viewer/panTo 0 0 cm\")" << endl; cout << "print to eps:" << endl; cout << " G4Cmd(\"/vis/ogl/printEPS\")" << endl; cout << "set background color:" << endl; cout << " G4Cmd(\"/vis/viewer/set/background white\")" << endl; std::cout << "===============================" << std::endl; } else { se->run(nEvents); se->End(); std::cout << "All done" << std::endl; delete se; gSystem->Exit(0); } }