Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:19:30

0001 #ifndef PHPYTHIA8_PHPYTHIA8_H
0002 #define PHPYTHIA8_PHPYTHIA8_H
0003 
0004 #include <fun4all/SubsysReco.h>
0005 
0006 #include <phhepmc/PHHepMCGenHelper.h>
0007 
0008 #include <cmath>
0009 #include <memory>
0010 #include <string>
0011 #include <vector>
0012 
0013 class PHCompositeNode;
0014 class PHGenIntegral;
0015 class PHPy8GenTrigger;
0016 
0017 namespace HepMC
0018 {
0019   class Pythia8ToHepMC;
0020 }  // namespace HepMC
0021 
0022 namespace Pythia8
0023 {
0024   class Pythia;
0025 }
0026 
0027 class PHPythia8 : public SubsysReco, public PHHepMCGenHelper
0028 {
0029  public:
0030   //! constructor
0031   explicit PHPythia8(const std::string &name = "PHPythia8");
0032 
0033   //! destructor
0034   ~PHPythia8() override = default;
0035 
0036   int Init(PHCompositeNode *topNode) override;
0037   int process_event(PHCompositeNode *topNode) override;
0038   int End(PHCompositeNode *topNode) override;
0039 
0040   void set_config_file(const std::string &cfg_file)
0041   {
0042     m_ConfigFileName = cfg_file;
0043   }
0044 
0045   void print_config() const;
0046 
0047   /// set event selection criteria
0048   void register_trigger(PHPy8GenTrigger *theTrigger);
0049   void set_trigger_OR()
0050   {
0051     m_TriggersOR = true;
0052     m_TriggersAND = false;
0053   }  // default true
0054   void set_trigger_AND()
0055   {
0056     m_TriggersAND = true;
0057     m_TriggersOR = false;
0058   }
0059 
0060   /// pass commands directly to PYTHIA8
0061   void process_string(const std::string &s) { m_Commands.push_back(s); }
0062   void beam_vertex_parameters(double beamX,
0063                               double beamY,
0064                               double beamZ,
0065                               double beamXsigma,
0066                               double beamYsigma,
0067                               double beamZsigma)
0068   {
0069     set_vertex_distribution_mean(beamX, beamY, beamZ, 0);
0070     set_vertex_distribution_width(beamXsigma, beamYsigma, beamZsigma, 0);
0071   }
0072 
0073   void save_event_weight(const bool b) { m_SaveEventWeightFlag = b; }
0074   void save_integrated_luminosity(const bool b) { m_SaveIntegratedLuminosityFlag = b; }
0075 
0076  private:
0077   int read_config(const std::string &cfg_file);
0078   int create_node_tree(PHCompositeNode *topNode) final;
0079   double percent_diff(const double a, const double b) { return std::fabs((a - b) / a); }
0080   int m_EventCount = 0;
0081 
0082   // event selection
0083   std::vector<PHPy8GenTrigger *> m_RegisteredTriggers;
0084   bool m_TriggersOR{true};
0085   bool m_TriggersAND{false};
0086 
0087   // PYTHIA
0088   std::unique_ptr<Pythia8::Pythia> m_Pythia8;
0089 
0090   std::string m_ConfigFileName{"phpythia8.cfg"};
0091   std::vector<std::string> m_Commands;
0092 
0093   // HepMC
0094   std::unique_ptr<HepMC::Pythia8ToHepMC> m_Pythia8ToHepMC;
0095 
0096   //! whether to store the overall event weight into the HepMC weights
0097   bool m_SaveEventWeightFlag{true};
0098 
0099   //! whether to store the integrated luminosity and other event statistics to the TOP/RUN/PHGenIntegral node
0100   bool m_SaveIntegratedLuminosityFlag{true};
0101 
0102   //! pointer to data node saving the integrated luminosity
0103   PHGenIntegral *m_IntegralNode{};
0104 };
0105 
0106 #endif /* PHPYTHIA8_PHPYTHIA8_H */