Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:12:25

0001 
0002 int Fun4All_MCEventGen(
0003                        const int nEvents = 100,
0004                        const char * outputFile = "G4MCEventGen.root"
0005                        )
0006 {
0007   //===============
0008   // Input options
0009   //===============
0010 
0011   // read files in HepMC format (typically output from event generators like hijing or pythia)
0012   const bool readhepmc = false; // read HepMC files
0013 
0014   // read files in EICTree format generated by eicsmear package
0015   const bool readeictree = false;
0016 
0017   // Use particle generator Pythia 8
0018   const bool runpythia8 = false;
0019 
0020   // Use particle generator Pythia 6
0021   const bool runpythia6 = true;
0022   const char * pythia6configfile = "config_pythia6/phpythia6_ep.cfg";
0023 
0024   // Use particle generator HEPGen
0025   const bool runhepgen = false;
0026 
0027   // Use particle generator Sartre
0028   const bool runsartre = false;
0029 
0030   // Other options
0031   const bool do_dst_compress = true;
0032 
0033   // Option to save DST output file (for later use with Genat4 simulation)
0034   const bool do_DSTOutput = true;
0035 
0036   // Option to convert DST to human command readable TTree for quick poke around the outputs
0037   const bool do_DSTReader = false;
0038 
0039   // Option to save events in ASCII HepMC format
0040   const bool do_ASCIIOutput = false;
0041 
0042 
0043   //---------------
0044   // Load libraries
0045   //---------------
0046   gSystem->Load("libfun4all.so");
0047   gSystem->Load("libphhepmc.so");
0048   gSystem->Load("libg4detectors.so");
0049   gSystem->Load("libg4eval.so");
0050 
0051   //---------------
0052   // Fun4All server
0053   //---------------
0054   Fun4AllServer *se = Fun4AllServer::instance();
0055   se->Verbosity(0); // uncomment for batch production running with minimal output messages
0056   // se->Verbosity(Fun4AllServer::VERBOSITY_SOME); // uncomment for some info for interactive running
0057 
0058   // just if we set some flags somewhere in this macro
0059   recoConsts *rc = recoConsts::instance();
0060   // By default every random number generator uses
0061   // PHRandomSeed() which reads /dev/urandom to get its seed
0062   // if the RANDOMSEED flag is set its value is taken as seed
0063   // You can either set this to a random value using PHRandomSeed()
0064   // which will make all seeds identical (not sure what the point of
0065   // this would be:
0066   //  rc->set_IntFlag("RANDOMSEED",PHRandomSeed());
0067   // or set it to a fixed value so you can debug your code
0068   // rc->set_IntFlag("RANDOMSEED", 12345);
0069 
0070   /* Set world parameters in reco consts */
0071   rc->set_FloatFlag("WorldSizex", 1000.);
0072   rc->set_FloatFlag("WorldSizey", 1000.);
0073   rc->set_FloatFlag("WorldSizez", 1000.);
0074   rc->set_CharFlag("WorldShape", "G4Tubs");
0075 
0076 
0077   //-----------------
0078   // Event generation
0079   //-----------------
0080 
0081   if (readhepmc)
0082     {
0083     }
0084   else if (readeictree)
0085     {
0086       // this module is needed to read the EICTree style records into our G4 sims
0087       ReadEICFiles *eicr = new ReadEICFiles();
0088       eicr->OpenInputFile("data/eictree_milou_dvcs_10x250.root");
0089 
0090       se->registerSubsystem(eicr);
0091     }
0092   else if (runpythia8)
0093     {
0094       gSystem->Load("libPHPythia8.so");
0095 
0096       PHPythia8* pythia8 = new PHPythia8();
0097       // see coresoftware/generators/PHPythia8 for example config
0098       pythia8->set_config_file("phpythia8.cfg");
0099       se->registerSubsystem(pythia8);
0100     }
0101   else if (runpythia6)
0102     {
0103       gSystem->Load("libPHPythia6.so");
0104 
0105       PHPythia6 *pythia6 = new PHPythia6();
0106       pythia6->set_config_file( pythia6configfile );
0107       se->registerSubsystem(pythia6);
0108     }
0109   else if (runhepgen)
0110     {
0111       gSystem->Load("libsHEPGen.so");
0112 
0113       sHEPGen *hepgen = new sHEPGen();
0114       hepgen->set_datacard_file("config/hepgen_eic_dvcs.data");
0115       hepgen->set_momentum_electron(-10);
0116       hepgen->set_momentum_hadron(250);
0117       se->registerSubsystem(hepgen);
0118     }
0119   else if (runsartre)
0120     {
0121       // see coresoftware/generators/PHSartre/README for setup instructions
0122       // before running:
0123       // setenv SARTRE_DIR /opt/sphenix/core/sartre-1.20_root-5.34.36
0124       gSystem->Load("libPHSartre.so");
0125 
0126       PHSartre* mysartre = new PHSartre();
0127       // see coresoftware/generators/PHSartre for example config
0128       mysartre->set_config_file("config/sartre_ep.cfg");
0129 
0130       // particle trigger to enhance forward J/Psi -> ee
0131       //PHSartreParticleTrigger* pTrig = new PHSartreParticleTrigger("MySartreTrigger");
0132       //pTrig->AddParticles(-11);
0133       //pTrig->SetEtaHighLow(4.0,1.4);
0134       //pTrig->SetEtaHighLow(1.0,-1.1);  // central arm
0135       //pTrig->PrintConfig();
0136       //mysartre->register_trigger((PHSartreGenTrigger *)pTrig);
0137       se->registerSubsystem(mysartre);
0138     }
0139 
0140   /* Write DST output file */
0141   if ( do_DSTOutput )
0142     {
0143       Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", outputFile);
0144       se->registerOutputManager(out);
0145     }
0146 
0147   /* write DSTReader human readable output tree */
0148   if (do_DSTReader)
0149     {
0150       // load HepMCNodeReader
0151       HepMCNodeReader *hr = new HepMCNodeReader();
0152       se->registerSubsystem(hr);
0153 
0154       // load module to access truth particle information
0155       PHG4Reco* g4Reco = new PHG4Reco();
0156       PHG4TruthSubsystem *truth = new PHG4TruthSubsystem();
0157       g4Reco->registerSubsystem(truth);
0158       se->registerSubsystem( g4Reco );
0159 
0160       // save a comprehensive  evaluation file
0161       PHG4DSTReader* ana = new PHG4DSTReader(string(outputFile) + string("_DSTReader.root"));
0162       ana->set_save_particle(true);
0163       ana->set_load_all_particle(false);
0164       ana->set_load_active_particle(true);
0165       ana->set_save_vertex(true);
0166 
0167       se->registerSubsystem(ana);
0168     }
0169 
0170   /* Write HepMC ASCII output */
0171   else if ( do_ASCIIOutput )
0172     {
0173       Fun4AllHepMCOutputManager *asciiout = new Fun4AllHepMCOutputManager("HEPMCOUT",outputFile);
0174       se->registerOutputManager(asciiout);
0175     }
0176 
0177   //-----------------
0178   // Event processing
0179   //-----------------
0180   if (nEvents <= 0 && !readhepmc)
0181     {
0182       cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
0183       cout << "it will run forever, so I just return without running anything" << endl;
0184       return;
0185     }
0186   else
0187     {
0188       se->run(nEvents);
0189 
0190       se->End();
0191       std::cout << "All done" << std::endl;
0192       delete se;
0193       gSystem->Exit(0);
0194     }
0195 
0196 }
0197 
0198 
0199 void
0200 G4Cmd(const char * cmd)
0201 {
0202   Fun4AllServer *se = Fun4AllServer::instance();
0203   PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco("PHG4RECO");
0204   g4->ApplyCommand(cmd);
0205 }