Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-10-15 08:24:44

0001 // PHHerwig7 -- Herwig 7 as an in-process Fun4All generator, the way PHPythia8
0002 // wraps PYTHIA 8.  One Fun4All process, no FIFO, no HepMC on disk; seed from
0003 // PHRandomSeed(); generated-event count and cross section in RUN/PHGenIntegral;
0004 // truth triggers applied inside the generation loop so only triggered events
0005 // reach the node tree.
0006 //
0007 // Input is a Herwig .run file (the output of `Herwig read card.in`, which
0008 // hwrun.sh produces from a config).  Reading the card in-process is deliberately
0009 // not done here: `read` builds the whole repository and is best kept as the
0010 // separate, cached step Herwig designed it to be.
0011 #ifndef PHHERWIG7_H
0012 #define PHHERWIG7_H
0013 
0014 #include <fun4all/SubsysReco.h>
0015 #include <phhepmc/PHHepMCGenHelper.h>
0016 
0017 #include <memory>
0018 #include <string>
0019 #include <vector>
0020 
0021 class PHCompositeNode;
0022 class PHGenIntegral;
0023 class PHHerwig7Core;
0024 class PHHerwig7GenTrigger;
0025 
0026 class PHHerwig7 : public SubsysReco, public PHHepMCGenHelper
0027 {
0028  public:
0029   explicit PHHerwig7(const std::string &name = "PHHerwig7");
0030   ~PHHerwig7() override = default;
0031 
0032   int Init(PHCompositeNode *topNode) override;
0033   int process_event(PHCompositeNode *topNode) override;
0034   int End(PHCompositeNode *topNode) override;
0035   void Print(const std::string &what = "ALL") const override;
0036 
0037   // ---- what to run --------------------------------------------------------
0038   void set_run_file(const std::string &f) { m_RunFile = f; }
0039   // optional Herwig setup file applied on top of the .run (Herwig --setupfile)
0040   void set_setup_file(const std::string &f) { m_SetupFile = f; }
0041   // directories searched for files referenced by the setup file
0042   void add_read_directory(const std::string &d) { m_ReadDirs.push_back(d); }
0043   // 0 (default): seed from PHRandomSeed(); >0: use this seed
0044   void set_seed(int s) { m_Seed = s; }
0045 
0046   // give up after this many consecutive failed attempts (0 = never)
0047   void set_max_trigger_attempts(long n) { m_MaxAttempts = n; }
0048 
0049   // ---- bookkeeping ---------------------------------------------------------
0050   void save_integrated_luminosity(bool b) { m_SaveIntegratedLuminosityFlag = b; }
0051   void save_event_weight(bool b) { m_SaveEventWeightFlag = b; }
0052 
0053   unsigned long get_n_generated() const { return m_NGenerated; }
0054   unsigned long get_n_passed() const { return m_NPassed; }
0055 
0056   // ---- public setters to register trigger and logic as PHPythia8
0057   void register_trigger(PHHerwig7GenTrigger *trigger);
0058   void set_trigger_OR()
0059   {
0060     set_trigger_logic(true);
0061   }
0062   void set_trigger_AND()
0063   {
0064     set_trigger_logic(false);
0065   }
0066 
0067  private:
0068   void set_trigger_logic(bool triggerOR)
0069   {
0070     m_TriggersOR = triggerOR;
0071     m_TriggersAND = !triggerOR;
0072   }
0073 
0074   int create_node_tree(PHCompositeNode *topNode) override;
0075 
0076   std::string m_RunFile;
0077   std::string m_SetupFile;
0078   std::vector<std::string> m_ReadDirs;
0079   int m_Seed = 0;
0080 
0081   long m_MaxAttempts = 0;
0082 
0083   bool m_SaveIntegratedLuminosityFlag = true;
0084   bool m_SaveEventWeightFlag = true;
0085 
0086   std::unique_ptr<PHHerwig7Core> m_Core;
0087   PHGenIntegral *m_IntegralNode = nullptr;
0088 
0089   unsigned long m_NGenerated = 0;
0090   unsigned long m_NPassed = 0;
0091   double m_SumWAll = 0.0;
0092   double m_SumWPass = 0.0;
0093 
0094   // event selection
0095   std::vector<PHHerwig7GenTrigger *> m_RegisteredTriggers;
0096   bool m_TriggersOR{true};
0097   bool m_TriggersAND{false};
0098 };
0099 
0100 #endif