Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-04-06 08:10:18

0001 #ifndef MACRO_G4INPUT_C
0002 #define MACRO_G4INPUT_C
0003 
0004 #include <GlobalVariables.C>
0005 
0006 #include <G4_TrkrVariables.C>
0007 
0008 #include <phpythia8/PHPythia8.h>
0009 
0010 #include <g4main/CosmicSpray.h>
0011 #include <g4main/HepMCNodeReader.h>
0012 #include <g4main/PHG4IonGun.h>
0013 #include <g4main/PHG4ParticleGenerator.h>
0014 #include <g4main/PHG4ParticleGeneratorD0.h>
0015 #include <g4main/PHG4ParticleGeneratorVectorMeson.h>
0016 #include <g4main/PHG4ParticleGun.h>
0017 #include <g4main/PHG4SimpleEventGenerator.h>
0018 // #include <g4main/ReadEICFiles.h>
0019 
0020 #include <fermimotionafterburner/FermimotionAfterburner.h>
0021 
0022 #include <hijingflipafterburner/HIJINGFlipAfterburner.h>
0023 
0024 #include <reactionplaneafterburner/ReactionPlaneAfterburner.h>
0025 
0026 #include <phhepmc/Fun4AllHepMCInputManager.h>
0027 #include <phhepmc/Fun4AllHepMCPileupInputManager.h>
0028 #include <phhepmc/HepMCFlowAfterBurner.h>
0029 #include <phhepmc/PHHepMCGenHelper.h>
0030 
0031 #include <fun4all/Fun4AllDstInputManager.h>
0032 #include <fun4all/Fun4AllDummyInputManager.h>
0033 #include <fun4all/Fun4AllInputManager.h>
0034 #include <fun4all/Fun4AllNoSyncDstInputManager.h>
0035 #include <fun4all/Fun4AllServer.h>
0036 
0037 #include <TSystem.h>  // for gSystem
0038 
0039 #include <set>
0040 
0041 R__LOAD_LIBRARY(libfun4all.so)
0042 R__LOAD_LIBRARY(libg4testbench.so)
0043 R__LOAD_LIBRARY(libPHPythia8.so)
0044 R__LOAD_LIBRARY(libFermimotionAfterburner.so)
0045 R__LOAD_LIBRARY(libHIJINGFlipAfterburner.so)
0046 R__LOAD_LIBRARY(libReactionPlaneAfterburner.so)
0047 
0048 namespace Input
0049 {
0050   // Real Event generators
0051   bool PYTHIA6 = false;
0052   int PYTHIA6_EmbedId = 0;
0053 
0054   bool PYTHIA8 = false;
0055   int PYTHIA8_NUMBER = 1;
0056   int PYTHIA8_VERBOSITY = 0;
0057   std::set<int> PYTHIA8_EmbedIds;
0058 
0059   // Single/multiple particle generators
0060   bool DZERO = false;
0061   int DZERO_NUMBER = 1;
0062   int DZERO_VERBOSITY = 0;
0063   std::set<int> DZERO_EmbedIds;
0064 
0065   bool GUN = false;
0066   int GUN_NUMBER = 1;
0067   int GUN_VERBOSITY = 0;
0068   std::set<int> GUN_EmbedIds;
0069 
0070   bool IONGUN = false;
0071   int IONGUN_NUMBER = 1;
0072   int IONGUN_VERBOSITY = 0;
0073   std::set<int> IONGUN_EmbedIds;
0074 
0075   bool PGEN = false;
0076   int PGEN_NUMBER = 1;
0077   int PGEN_VERBOSITY = 0;
0078   std::set<int> PGEN_EmbedIds;
0079 
0080   bool SIMPLE = false;
0081   int SIMPLE_NUMBER = 1;
0082   int SIMPLE_VERBOSITY = 0;
0083 
0084   int UPSILON_NUMBER = 1;
0085   int UPSILON_VERBOSITY = 0;
0086   // other UPSILON settings which are also used elsewhere are in GlobalVariables.C
0087 
0088   double PILEUPRATE = 0.;
0089   bool READHITS = false;
0090   int VERBOSITY = 0;
0091   int EmbedId = 1;
0092   int VertexEmbedId = 0;
0093 
0094   bool COSMIC = false;
0095   double COSMIC_R = 650.;
0096 
0097   double beam_crossing = -1.5;  // -1.5 mRad
0098   //! apply reference sPHENIX nominal beam parameter with 1.5mrad crossing as used in 2024
0099   //! \param[in] HepMCGen any HepMC generator, e.g. Fun4AllHepMCInputManager, Fun4AllHepMCPileupInputManager, PHPythia8, PHPythia6, ReadEICFiles
0100   //! \param[in] collision_type select the beam configuration with Input::BeamConfiguration
0101   void ApplysPHENIXBeamParameter(PHHepMCGenHelper *HepMCGen, const Input::BeamConfiguration &beam_config)
0102   {
0103     if (HepMCGen == nullptr)
0104     {
0105       std::cout << "ApplysPHENIXBeamParameter(): Fatal Error - null input pointer HepMCGen" << std::endl;
0106       exit(1);
0107     }
0108     double localbcross = Input::beam_crossing / 2. * 1e-3;
0109     switch (beam_config)
0110     {
0111     case AA_COLLISION:
0112     case mRad_10:
0113       // heavy ion mode
0114       Input::beam_crossing = 1.;  // +1 mRad for late 2024 with triggered readout for mvtx
0115       //  Xing angle is split among both beams, means set to 0.5 mRad
0116       localbcross = Input::beam_crossing / 2. * 1e-3;
0117       HepMCGen->set_beam_direction_theta_phi(localbcross, 0, M_PI - localbcross, 0);
0118       HepMCGen->set_vertex_distribution_width(
0119           100e-4,         // approximation from past STAR/Run16 AuAu data
0120           100e-4,         // approximation from past STAR/Run16 AuAu data
0121           13.5,           // measured 2024 with 1mRad beam Xing
0122           20 / 29.9792);  // 20cm collision length / speed of light in cm/ns
0123 
0124       HepMCGen->set_vertex_distribution_mean(-0.058,0.133,0,0); // rough position of actual beam spot. This can vary by a few hundred microns
0125       break;
0126     case pA_COLLISION:
0127 
0128       // pA mode
0129 
0130       // 1.5mRad is split among both beams, means set to 0.75 mRad
0131       HepMCGen->set_beam_direction_theta_phi(localbcross, 0, M_PI - localbcross, 0);
0132       HepMCGen->set_vertex_distribution_width(
0133           100e-4,         // set to be similar to AA
0134           100e-4,         // set to be similar to AA
0135           8,              // sPH-TRG-2022-001. Fig B.4
0136           20 / 29.9792);  // 20cm collision length / speed of light in cm/ns
0137 
0138       break;
0139     case pp_COLLISION:
0140     case mRad_15:
0141 
0142       // pp mode
0143       // 1.5mRad is split among both beams, means set to 0.75 mRad
0144       HepMCGen->set_beam_direction_theta_phi(localbcross, 0, M_PI - localbcross, 0);
0145       HepMCGen->set_vertex_distribution_width(
0146           120e-4,         // approximation from past PHENIX data
0147           120e-4,         // approximation from past PHENIX data
0148           16,             // measured in 2024 for 1.5mrad Xing angle
0149           20 / 29.9792);  // 20cm collision length / speed of light in cm/ns
0150       HepMCGen->set_vertex_distribution_mean(-0.0716,0.1401,-0.4175,0); // rough position of actual beam spot. This can vary by a few hundred microns
0151       
0152       break;
0153     case pp_ZEROANGLE:
0154     case mRad_00:
0155 
0156       // pp mode
0157 
0158       HepMCGen->set_vertex_distribution_width(
0159           120e-4,         // approximation from past PHENIX data
0160           120e-4,         // approximation from past PHENIX data
0161           65,             // measured in 2024 for 0 Xing angle
0162           20 / 29.9792);  // 20cm collision length / speed of light in cm/ns
0163 
0164       break;
0165 
0166     case ppg02:
0167       Input::beam_crossing = 1.;  // +1 mRad for late 2024 with triggered readout for mvtx
0168       localbcross = Input::beam_crossing / 2. * 1e-3;
0169       //  Xing angle is split among both beams, means set to 0.5 mRad
0170       HepMCGen->set_beam_direction_theta_phi(localbcross, 0, M_PI - localbcross, 0);  // 1.5mrad x-ing of sPHENIX
0171       HepMCGen->set_vertex_distribution_mean(-0.022, 0.223, -4.03, 0.);
0172       HepMCGen->set_vertex_distribution_width(
0173           120e-4,         // approximation from past PHENIX data
0174           120e-4,         // approximation from past PHENIX data
0175           9.358,          // measured by intt
0176           20 / 29.9792);  // 20cm collision length / speed of light in cm/ns
0177       break;
0178 
0179     case mRad_05:
0180       Input::beam_crossing = 0.5;
0181       //0.5 mRad is split among both beams, means set to 0.25 mRad
0182       localbcross = Input::beam_crossing / 2. * 1e-3;
0183 
0184       HepMCGen->set_beam_direction_theta_phi(localbcross, 0, M_PI - localbcross, 0);
0185       HepMCGen->set_vertex_distribution_width(
0186           120e-4,         // approximation from past PHENIX data
0187           120e-4,         // approximation from past PHENIX data
0188           24.5,             // estimate from Colorado
0189           20 / 29.9792);  // 20cm collision length / speed of light in cm/ns
0190 
0191       break;
0192     case mRad_075:
0193       Input::beam_crossing = 0.75;
0194       //0.75 mRad is split among both beams, means set to 0.375 mRad
0195       localbcross = Input::beam_crossing / 2. * 1e-3;
0196 
0197       HepMCGen->set_beam_direction_theta_phi(localbcross, 0, M_PI - localbcross, 0);
0198       HepMCGen->set_vertex_distribution_width(
0199           120e-4,         // approximation from past PHENIX data
0200           120e-4,         // approximation from past PHENIX data
0201           20,             // from online monitoring mbd
0202           20 / 29.9792);  // 20cm collision length / speed of light in cm/ns
0203 
0204       break;
0205     default:
0206       std::cout << "ApplysPHENIXBeamParameter: invalid beam_config = " << beam_config << std::endl;
0207 
0208       exit(1);
0209     }
0210 
0211     HepMCGen->set_vertex_distribution_function(
0212         PHHepMCGenHelper::Gaus,
0213         PHHepMCGenHelper::Gaus,
0214         PHHepMCGenHelper::Gaus,
0215         PHHepMCGenHelper::Gaus);
0216   }
0217 
0218   //! apply sPHENIX nominal beam parameter according to the beam collision setting of Input::IS_PP_COLLISION
0219   //! \param[in] HepMCGen any HepMC generator, e.g. Fun4AllHepMCInputManager, Fun4AllHepMCPileupInputManager, PHPythia8, PHPythia6, ReadEICFiles
0220   void ApplysPHENIXBeamParameter(PHHepMCGenHelper *HepMCGen)
0221   {
0222     ApplysPHENIXBeamParameter(HepMCGen, Input::BEAM_CONFIGURATION);
0223   }
0224 
0225   void ApplysPHENIXBeamParameter(std::vector<PHPythia8 *> &HepMCGenVec)
0226   {
0227     PHHepMCGenHelper *gen = dynamic_cast<PHHepMCGenHelper *> (HepMCGenVec[0]);
0228     if (gen)
0229     {
0230       ApplysPHENIXBeamParameter(gen, Input::BEAM_CONFIGURATION);
0231     }
0232   }
0233 
0234   //! apply EIC beam parameter to any HepMC generator following EIC CDR,
0235   //! including in-time collision's space time shift, beam crossing angle and angular divergence
0236   //! \param[in] HepMCGen any HepMC generator, e.g. Fun4AllHepMCInputManager, Fun4AllHepMCPileupInputManager, PHPythia8, PHPythia6, ReadEICFiles
0237   void ApplyEICBeamParameter(PHHepMCGenHelper *HepMCGen)
0238   {
0239     if (HepMCGen == nullptr)
0240     {
0241       std::cout << "ApplyEICBeamParameter(): Fatal Error - null input pointer HepMCGen" << std::endl;
0242       exit(1);
0243     }
0244 
0245     // 25mrad x-ing as in EIC CDR
0246     const double EIC_hadron_crossing_angle = 25e-3;
0247 
0248     HepMCGen->set_beam_direction_theta_phi(
0249         EIC_hadron_crossing_angle,  // beamA_theta
0250         0,                          // beamA_phi
0251         M_PI,                       // beamB_theta
0252         0                           // beamB_phi
0253     );
0254     HepMCGen->set_beam_angular_divergence_hv(
0255         119e-6, 119e-6,  // proton beam divergence horizontal & vertical, as in EIC CDR Table 1.1
0256         211e-6, 152e-6   // electron beam divergence horizontal & vertical, as in EIC CDR Table 1.1
0257     );
0258 
0259     // angular kick within a bunch as result of crab cavity
0260     // using an naive assumption of transfer matrix from the cavity to IP,
0261     // which is NOT yet validated with accelerator optics simulations!
0262     const double z_hadron_cavity = 52e2;  // CDR Fig 3.3
0263     const double z_e_cavity = 38e2;       // CDR Fig 3.2
0264     HepMCGen->set_beam_angular_z_coefficient_hv(
0265         -EIC_hadron_crossing_angle / 2. / z_hadron_cavity, 0,
0266         -EIC_hadron_crossing_angle / 2. / z_e_cavity, 0);
0267 
0268     // calculate beam sigma width at IP  as in EIC CDR table 1.1
0269     const double sigma_p_h = sqrt(80 * 11.3e-7);
0270     const double sigma_p_v = sqrt(7.2 * 1.0e-7);
0271     const double sigma_p_l = 6;
0272     const double sigma_e_h = sqrt(45 * 20.0e-7);
0273     const double sigma_e_v = sqrt(5.6 * 1.3e-7);
0274     const double sigma_e_l = 2;
0275 
0276     // combine two beam gives the collision sigma in z
0277     const double collision_sigma_z = sqrt(sigma_p_l * sigma_p_l + sigma_e_l * sigma_e_l) / 2;
0278     const double collision_sigma_t = collision_sigma_z / 29.9792;  // speed of light in cm/ns
0279 
0280     HepMCGen->set_vertex_distribution_width(
0281         sigma_p_h * sigma_e_h / sqrt(sigma_p_h * sigma_p_h + sigma_e_h * sigma_e_h),  // x
0282         sigma_p_v * sigma_e_v / sqrt(sigma_p_v * sigma_p_v + sigma_e_v * sigma_e_v),  // y
0283         collision_sigma_z,                                                            // z
0284         collision_sigma_t);                                                           // t
0285     HepMCGen->set_vertex_distribution_function(
0286         PHHepMCGenHelper::Gaus,   // x
0287         PHHepMCGenHelper::Gaus,   // y
0288         PHHepMCGenHelper::Gaus,   // z
0289         PHHepMCGenHelper::Gaus);  // t
0290   }
0291 }  // namespace Input
0292 
0293 namespace INPUTHEPMC
0294 {
0295   std::string filename;
0296   std::string listfile;
0297   int EmbedId = 0;
0298   bool FLOW = false;
0299   int FLOW_VERBOSITY = 0;
0300   bool FLOW_FLUCTUATIONS = false;
0301   float FLOW_SCALING = 1.0;  // scaling factor for flow
0302   bool FERMIMOTION = false;
0303   bool HIJINGFLIP = false;
0304   bool REACTIONPLANERAND = false;
0305   float HEPMC_STRANGENESS_FRACTION = -1.;
0306 
0307 }  // namespace INPUTHEPMC
0308 
0309 namespace INPUTREADEIC
0310 {
0311   std::string filename;
0312 }  // namespace INPUTREADEIC
0313 
0314 namespace INPUTREADHITS
0315 {
0316   std::map<unsigned int, std::string> filename;
0317   std::map<unsigned int, std::string> listfile;
0318 }  // namespace INPUTREADHITS
0319 
0320 namespace INPUTEMBED
0321 {
0322   std::map<unsigned int, std::string> filename;
0323   std::map<unsigned int, std::string> listfile;
0324   bool REPEAT = true;
0325 }  // namespace INPUTEMBED
0326 
0327 namespace PYTHIA6
0328 {
0329   std::string config_file = std::string(getenv("CALIBRATIONROOT")) + "/Generators/phpythia6.cfg";
0330 }
0331 
0332 namespace PYTHIA8
0333 {
0334   std::map<int, std::string> config_file =
0335   {
0336     {0, std::string(getenv("CALIBRATIONROOT")) + "/Generators/phpythia8.cfg"}
0337   };
0338 }
0339 
0340 namespace PILEUP
0341 {
0342   std::string pileupfile = "/sphenix/sim/sim01/sphnxpro/MDC1/sHijing_HepMC/data/sHijing_0_20fm-0000000001-00000.dat";
0343   double TpcDriftVelocity = G4TPC::tpc_drift_velocity_sim;
0344 }  // namespace PILEUP
0345 
0346 // collection of pointers to particle generators we can grab in the Fun4All macro
0347 namespace INPUTGENERATOR
0348 {
0349   std::vector<PHG4IonGun *> IonGun;
0350   std::vector<PHG4ParticleGenerator *> ParticleGenerator;
0351   std::vector<PHG4ParticleGeneratorD0 *> DZeroMesonGenerator;
0352   std::vector<PHG4ParticleGeneratorVectorMeson *> VectorMesonGenerator;
0353   std::vector<PHG4SimpleEventGenerator *> SimpleEventGenerator;
0354   std::vector<PHG4ParticleGun *> Gun;
0355   PHPythia8 *Pythia6 = nullptr;
0356   std::vector<PHPythia8 *> Pythia8;
0357   //  ReadEICFiles *EICFileReader = nullptr;
0358   CosmicSpray *Cosmic = nullptr;
0359 }  // namespace INPUTGENERATOR
0360 
0361 namespace INPUTMANAGER
0362 {
0363   Fun4AllHepMCInputManager *HepMCInputManager = nullptr;
0364   Fun4AllHepMCPileupInputManager *HepMCPileupInputManager = nullptr;
0365 }  // namespace INPUTMANAGER
0366 
0367 void InputInit()
0368 {
0369   // for pileup sims embed id is 1, to distinguish particles
0370   // which will be embedded (when Input::EMBED = true) into pileup sims
0371   // we need to start at embedid = 2
0372   if (Input::EMBED)
0373   {
0374     Input::EmbedId = 2;
0375   }
0376   // first consistency checks - not all input generators play nice
0377   // with each other
0378   if (Input::READHITS && Input::EMBED)
0379   {
0380     std::cout << "Reading Hits and Embedding into background at the same time is not supported" << std::endl;
0381     gSystem->Exit(1);
0382   }
0383   if (Input::READHITS && (Input::PYTHIA6 || Input::PYTHIA8 || Input::SIMPLE || Input::GUN || Input::UPSILON || Input::HEPMC))
0384   {
0385     std::cout << "Reading Hits and running G4 simultanously is not supported" << std::endl;
0386     gSystem->Exit(1);
0387   }
0388   if (Input::PYTHIA6 && Input::PYTHIA8)
0389   {
0390     std::cout << "Pythia6 and Pythia8 cannot be run together - might be possible but needs R&D" << std::endl;
0391     gSystem->Exit(1);
0392   }
0393 
0394   if (INPUTHEPMC::FLOW && Input::PILEUPRATE > 0)
0395   {
0396     std::cout << "Flow Afterburner and Pileup cannot be run simultanously" << std::endl;
0397     gSystem->Exit(1);
0398   }
0399   // done with consistency checks, create generators in no specific order
0400 
0401   //  Fun4AllServer *se = Fun4AllServer::instance();
0402   if (Input::PYTHIA6)
0403   {
0404     std::cout << "Pythia6 not implemented" << std::endl;
0405     gSystem->Exit(1);
0406     // INPUTGENERATOR::Pythia6 = new PHPythia6();
0407     // INPUTGENERATOR::Pythia6->set_config_file(PYTHIA6::config_file);
0408 
0409     // INPUTGENERATOR::Pythia6->set_embedding_id(Input::EmbedId);
0410     // Input::PYTHIA6_EmbedId = Input::EmbedId;
0411     // Input::EmbedId++;
0412   }
0413   if (Input::PYTHIA8)
0414   {
0415     for (int i = 0; i < Input::PYTHIA8_NUMBER; i++)
0416     {
0417       std::string name = "PYTHIA_" + std::to_string(i);
0418       PHPythia8 *pythia8 = new PHPythia8(name);
0419       INPUTGENERATOR::Pythia8.push_back(pythia8);
0420       pythia8->set_embedding_id(Input::EmbedId);
0421       // see coresoftware/generators/PHPythia8 for example config
0422       if (PYTHIA8::config_file[i].empty())
0423       {
0424     std::cout << "No Pythia8 config file for pythia8 generator no " << i << std::endl;
0425     gSystem->Exit(1);
0426       }
0427       pythia8->set_config_file(PYTHIA8::config_file[i]);
0428       // luminosity makes no sense when running multiple pythia8 generators
0429       if (Input::PYTHIA8_NUMBER > 1)
0430       {
0431     pythia8->save_integrated_luminosity(false);
0432       }
0433 
0434       Input::PYTHIA8_EmbedIds.insert(Input::EmbedId);
0435       Input::EmbedId++;
0436       if (Input::EMBED)
0437       {
0438     pythia8->set_reuse_vertex(Input::VertexEmbedId);
0439       }
0440     }
0441   }
0442   // single particle generators
0443   if (Input::DZERO)
0444   {
0445     for (int i = 0; i < Input::DZERO_NUMBER; ++i)
0446     {
0447       std::string name = "DZERO_" + std::to_string(i);
0448       PHG4ParticleGeneratorD0 *dzero = new PHG4ParticleGeneratorD0(name);
0449       dzero->Embed(Input::EmbedId);
0450       Input::DZERO_EmbedIds.insert(Input::EmbedId);
0451       Input::EmbedId++;
0452       INPUTGENERATOR::DZeroMesonGenerator.push_back(dzero);
0453     }
0454   }
0455   if (Input::GUN)
0456   {
0457     for (int i = 0; i < Input::GUN_NUMBER; ++i)
0458     {
0459       std::string name = "GUN_" + std::to_string(i);
0460       PHG4ParticleGun *gun = new PHG4ParticleGun(name);
0461       gun->Embed(Input::EmbedId);
0462       Input::GUN_EmbedIds.insert(Input::EmbedId);
0463       Input::EmbedId++;
0464       INPUTGENERATOR::Gun.push_back(gun);
0465     }
0466   }
0467   if (Input::IONGUN)
0468   {
0469     for (int i = 0; i < Input::IONGUN_NUMBER; ++i)
0470     {
0471       std::string name = "IONGUN_" + std::to_string(i);
0472       PHG4IonGun *iongun = new PHG4IonGun(name);
0473       iongun->Embed(Input::EmbedId);
0474       Input::IONGUN_EmbedIds.insert(Input::EmbedId);
0475       Input::EmbedId++;
0476       INPUTGENERATOR::IonGun.push_back(iongun);
0477     }
0478   }
0479   if (Input::PGEN)
0480   {
0481     for (int i = 0; i < Input::PGEN_NUMBER; ++i)
0482     {
0483       std::string name = "PGEN_" + std::to_string(i);
0484       PHG4ParticleGenerator *pgen = new PHG4ParticleGenerator(name);
0485       pgen->Embed(Input::EmbedId);
0486       Input::PGEN_EmbedIds.insert(Input::EmbedId);
0487       Input::EmbedId++;
0488       INPUTGENERATOR::ParticleGenerator.push_back(pgen);
0489     }
0490   }
0491   if (Input::SIMPLE)
0492   {
0493     for (int i = 0; i < Input::SIMPLE_NUMBER; ++i)
0494     {
0495       std::string name = "EVTGENERATOR_" + std::to_string(i);
0496       PHG4SimpleEventGenerator *simple = new PHG4SimpleEventGenerator(name);
0497       simple->Embed(Input::EmbedId);
0498       Input::PGEN_EmbedIds.insert(Input::EmbedId);
0499       Input::EmbedId++;
0500       INPUTGENERATOR::SimpleEventGenerator.push_back(simple);
0501     }
0502   }
0503   if (Input::UPSILON)
0504   {
0505     for (int i = 0; i < Input::UPSILON_NUMBER; ++i)
0506     {
0507       std::string name = "UPSILON_" + std::to_string(i);
0508       PHG4ParticleGeneratorVectorMeson *upsilon = new PHG4ParticleGeneratorVectorMeson(name);
0509       upsilon->Embed(Input::EmbedId);
0510       Input::UPSILON_EmbedIds.insert(Input::EmbedId);
0511       Input::EmbedId++;
0512       INPUTGENERATOR::VectorMesonGenerator.push_back(upsilon);
0513     }
0514   }
0515 
0516   // input managers for which we might need to set options
0517   if (Input::HEPMC)
0518   {
0519     INPUTMANAGER::HepMCInputManager = new Fun4AllHepMCInputManager("HEPMCin");
0520     INPUTMANAGER::HepMCInputManager->set_embedding_id(INPUTHEPMC::EmbedId);
0521   }
0522   if (Input::PILEUPRATE > 0)
0523   {
0524     INPUTMANAGER::HepMCPileupInputManager = new Fun4AllHepMCPileupInputManager("HepMCPileupInput");
0525   }
0526 }
0527 
0528 void InputRegister()
0529 {
0530   Fun4AllServer *se = Fun4AllServer::instance();
0531   // if (Input::PYTHIA6)
0532   // {
0533   //   se->registerSubsystem(INPUTGENERATOR::Pythia6);
0534   // }
0535   if (Input::PYTHIA8)
0536   {
0537     int verbosity = std::max(Input::PYTHIA8_VERBOSITY, Input::VERBOSITY);
0538     for (auto &generator : INPUTGENERATOR::Pythia8)
0539     {
0540       generator->Verbosity(verbosity);
0541       se->registerSubsystem(generator);
0542     }
0543   }
0544   if (Input::DZERO)
0545   {
0546     int verbosity = std::max(Input::DZERO_VERBOSITY, Input::VERBOSITY);
0547     for (auto &generator : INPUTGENERATOR::DZeroMesonGenerator)
0548     {
0549       generator->Verbosity(verbosity);
0550       se->registerSubsystem(generator);
0551     }
0552   }
0553   if (Input::GUN)
0554   {
0555     int verbosity = std::max(Input::GUN_VERBOSITY, Input::VERBOSITY);
0556     for (auto &generator : INPUTGENERATOR::Gun)
0557     {
0558       generator->Verbosity(verbosity);
0559       se->registerSubsystem(generator);
0560     }
0561   }
0562   if (Input::IONGUN)
0563   {
0564     int verbosity = std::max(Input::IONGUN_VERBOSITY, Input::VERBOSITY);
0565     for (auto &generator : INPUTGENERATOR::IonGun)
0566     {
0567       generator->Verbosity(verbosity);
0568       se->registerSubsystem(generator);
0569     }
0570   }
0571   if (Input::PGEN)
0572   {
0573     int verbosity = std::max(Input::PGEN_VERBOSITY, Input::VERBOSITY);
0574     for (auto &generator : INPUTGENERATOR::ParticleGenerator)
0575     {
0576       generator->Verbosity(verbosity);
0577       se->registerSubsystem(generator);
0578     }
0579   }
0580   if (Input::SIMPLE)
0581   {
0582     int verbosity = std::max(Input::SIMPLE_VERBOSITY, Input::VERBOSITY);
0583     for (auto &generator : INPUTGENERATOR::SimpleEventGenerator)
0584     {
0585       generator->Verbosity(verbosity);
0586       se->registerSubsystem(generator);
0587     }
0588   }
0589   if (Input::UPSILON)
0590   {
0591     for (auto &generator : INPUTGENERATOR::VectorMesonGenerator)
0592     {
0593       int verbosity = std::max(Input::UPSILON_VERBOSITY, Input::VERBOSITY);
0594       if (Input::HEPMC || Input::SIMPLE)
0595       {
0596         generator->set_reuse_existing_vertex(true);
0597       }
0598       generator->Verbosity(verbosity);
0599       se->registerSubsystem(generator);
0600     }
0601   }
0602   if (Input::READEIC)
0603   {
0604     std::cout << "Eic File Reading disabled" << std::endl;
0605     gSystem->Exit(1);
0606     // INPUTGENERATOR::EICFileReader = new ReadEICFiles();
0607     // INPUTGENERATOR::EICFileReader->OpenInputFile(INPUTREADEIC::filename);
0608     // INPUTGENERATOR::EICFileReader->Verbosity(Input::VERBOSITY);
0609     // se->registerSubsystem(INPUTGENERATOR::EICFileReader);
0610   }
0611   if (Input::COSMIC)
0612   {
0613     INPUTGENERATOR::Cosmic = new CosmicSpray("COSMIC", Input::COSMIC_R);
0614     se->registerSubsystem(INPUTGENERATOR::Cosmic);
0615   }
0616   // here are the various utility modules which read particles and
0617   // put them onto the G4 particle stack
0618   if (Input::HEPMC || Input::PYTHIA8 || Input::PYTHIA6 || Input::READEIC)
0619   {
0620     if (Input::HEPMC)
0621     {
0622       if (INPUTHEPMC::REACTIONPLANERAND)
0623       {
0624         ReactionPlaneAfterburner *rp = new ReactionPlaneAfterburner();
0625         se->registerSubsystem(rp);
0626       }
0627 
0628       if (INPUTHEPMC::HIJINGFLIP)
0629       {
0630         HIJINGFlipAfterburner *flip = new HIJINGFlipAfterburner();
0631         se->registerSubsystem(flip);
0632       }
0633       // these need to be applied before the HepMCNodeReader since they
0634       // work on the hepmc records
0635       if (INPUTHEPMC::FLOW)
0636       {
0637         HepMCFlowAfterBurner *burn = new HepMCFlowAfterBurner();
0638         burn->Verbosity(INPUTHEPMC::FLOW_VERBOSITY);
0639         burn->enableFluctuations(INPUTHEPMC::FLOW_FLUCTUATIONS);
0640         burn->scaleFlow(INPUTHEPMC::FLOW_SCALING);
0641         se->registerSubsystem(burn);
0642       }
0643       if (INPUTHEPMC::FERMIMOTION)
0644       {
0645         FermimotionAfterburner *fermi = new FermimotionAfterburner();
0646         se->registerSubsystem(fermi);
0647       }
0648     }
0649     // copy HepMC records into G4
0650     HepMCNodeReader *hr = new HepMCNodeReader();
0651     if (INPUTHEPMC::HEPMC_STRANGENESS_FRACTION >= 0)
0652     {
0653       hr->AddStrangeness(INPUTHEPMC::HEPMC_STRANGENESS_FRACTION);
0654     }
0655     se->registerSubsystem(hr);
0656   }
0657 }
0658 
0659 void InputManagers()
0660 {
0661   Fun4AllServer *se = Fun4AllServer::instance();
0662   if (Input::EMBED)
0663   {
0664     gSystem->Load("libg4dst.so");
0665     if (!INPUTEMBED::filename.empty() && !INPUTEMBED::listfile.empty())
0666     {
0667       std::cout << "only filenames or filelists are supported, not mixtures" << std::endl;
0668       gSystem->Exit(1);
0669     }
0670     if (INPUTEMBED::filename.empty() && INPUTEMBED::listfile.empty())
0671     {
0672       std::cout << "you need to give an input filenames or filelist" << std::endl;
0673       gSystem->Exit(1);
0674     }
0675     for (auto &iter : INPUTEMBED::filename)
0676     {
0677       std::string mgrname = "DSTin" + std::to_string(iter.first);
0678       Fun4AllInputManager *hitsin = new Fun4AllDstInputManager(mgrname);
0679       hitsin->fileopen(iter.second);
0680       hitsin->Verbosity(Input::VERBOSITY);
0681       if (INPUTEMBED::REPEAT)
0682       {
0683         hitsin->Repeat();
0684       }
0685       se->registerInputManager(hitsin);
0686     }
0687     for (auto &iter : INPUTEMBED::listfile)
0688     {
0689       std::string mgrname = "DSTin" + std::to_string(iter.first);
0690       Fun4AllInputManager *hitsin = new Fun4AllDstInputManager(mgrname);
0691       hitsin->AddListFile(iter.second);
0692       hitsin->Verbosity(Input::VERBOSITY);
0693       if (INPUTEMBED::REPEAT)
0694       {
0695         hitsin->Repeat();
0696       }
0697       se->registerInputManager(hitsin);
0698     }
0699   }
0700   if (Input::HEPMC)
0701   {
0702     INPUTMANAGER::HepMCInputManager->Verbosity(Input::VERBOSITY);
0703     se->registerInputManager(INPUTMANAGER::HepMCInputManager);
0704     if (!INPUTHEPMC::filename.empty() && INPUTHEPMC::listfile.empty())
0705     {
0706       INPUTMANAGER::HepMCInputManager->fileopen(INPUTHEPMC::filename);
0707     }
0708     else if (!INPUTHEPMC::listfile.empty())
0709     {
0710       INPUTMANAGER::HepMCInputManager->AddListFile(INPUTHEPMC::listfile);
0711     }
0712     else
0713     {
0714       std::cout << "no filename INPUTHEPMC::filename or listfile INPUTHEPMC::listfile given" << std::endl;
0715       gSystem->Exit(1);
0716     }
0717   }
0718   else if (Input::READHITS)
0719   {
0720     gSystem->Load("libg4dst.so");
0721     if (!INPUTREADHITS::filename.empty() && !INPUTREADHITS::listfile.empty())
0722     {
0723       std::cout << "only filenames or filelists are supported, not mixtures" << std::endl;
0724       gSystem->Exit(1);
0725     }
0726     if (INPUTREADHITS::filename.empty() && INPUTREADHITS::listfile.empty())
0727     {
0728       std::cout << "you need to give an input filenames or filelist" << std::endl;
0729       gSystem->Exit(1);
0730     }
0731     for (auto &iter : INPUTREADHITS::filename)
0732     {
0733       std::string mgrname = "DSTin" + std::to_string(iter.first);
0734       Fun4AllInputManager *hitsin = new Fun4AllDstInputManager(mgrname);
0735       hitsin->fileopen(iter.second);
0736       hitsin->Verbosity(Input::VERBOSITY);
0737       se->registerInputManager(hitsin);
0738     }
0739     for (auto &iter : INPUTREADHITS::listfile)
0740     {
0741       std::string mgrname = "DSTin" + std::to_string(iter.first);
0742       Fun4AllInputManager *hitsin = new Fun4AllDstInputManager(mgrname);
0743       hitsin->AddListFile(iter.second);
0744       hitsin->Verbosity(Input::VERBOSITY);
0745       se->registerInputManager(hitsin);
0746     }
0747   }
0748   else
0749   {
0750     Fun4AllInputManager *in = new Fun4AllDummyInputManager("JADE");
0751     in->Verbosity(Input::VERBOSITY);
0752     se->registerInputManager(in);
0753   }
0754   if (Input::PILEUPRATE > 0)
0755   {
0756     INPUTMANAGER::HepMCPileupInputManager->SignalInputManager(INPUTMANAGER::HepMCInputManager);
0757     INPUTMANAGER::HepMCPileupInputManager->Verbosity(Input::VERBOSITY);
0758     INPUTMANAGER::HepMCPileupInputManager->AddFile(PILEUP::pileupfile);
0759     INPUTMANAGER::HepMCPileupInputManager->set_collision_rate(Input::PILEUPRATE);
0760     double time_window = G4TPC::maxDriftLength / PILEUP::TpcDriftVelocity;
0761     double extended_readout_time = 0.0;
0762     if (TRACKING::pp_mode)
0763     {
0764       extended_readout_time = TRACKING::pp_extended_readout_time;
0765     }
0766     INPUTMANAGER::HepMCPileupInputManager->set_time_window(-time_window, time_window + extended_readout_time);
0767     std::cout << "Pileup window is from " << -time_window << " to " << time_window + extended_readout_time << std::endl;
0768     se->registerInputManager(INPUTMANAGER::HepMCPileupInputManager);
0769   }
0770 }
0771 #endif