Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-11 03:13:11

0001 // -*- C++ -*-
0002 //
0003 //
0004 
0005 // class BaseHadronizer meant as base class for hadronizers
0006 // implements a few common methods concerning communication with the
0007 // gen::HadronizerFilter<...> and gen::GeneratorFilter<...> templates,
0008 // mostly memory management regarding the GenEvent pointers and such
0009 
0010 #ifndef gen_BaseHadronizer_h
0011 #define gen_BaseHadronizer_h
0012 
0013 #include <memory>
0014 #include <string>
0015 #include <vector>
0016 
0017 #include <memory>
0018 
0019 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0020 #include "SimDataFormats/GeneratorProducts/interface/HepMC3Product.h"
0021 
0022 #include "SimDataFormats/GeneratorProducts/interface/GenRunInfoProduct.h"
0023 #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
0024 #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct3.h"
0025 #include "SimDataFormats/GeneratorProducts/interface/GenLumiInfoHeader.h"
0026 
0027 #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h"
0028 #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
0029 
0030 #include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h"
0031 #include "GeneratorInterface/LHEInterface/interface/LHEEvent.h"
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 #include "FWCore/Framework/interface/LuminosityBlock.h"
0034 
0035 #include "CLHEP/Random/RandomEngine.h"
0036 
0037 // foward declarations
0038 namespace edm {
0039   class Event;
0040 }
0041 
0042 namespace CLHEP {
0043   class HepRandomEngine;
0044 }
0045 
0046 namespace gen {
0047 
0048   class BaseHadronizer {
0049   public:
0050     BaseHadronizer(edm::ParameterSet const& ps);
0051     virtual ~BaseHadronizer() noexcept(false) {}
0052 
0053     // GenRunInfo and GenEvent passing
0054     GenRunInfoProduct& getGenRunInfo() { return genRunInfo_; }
0055     std::unique_ptr<HepMC::GenEvent> getGenEvent() { return std::move(genEvent_); }
0056     std::unique_ptr<HepMC3::GenEvent> getGenEvent3() { return std::move(genEvent3_); }
0057     std::unique_ptr<GenEventInfoProduct> getGenEventInfo() { return std::move(genEventInfo_); }
0058     std::unique_ptr<GenEventInfoProduct3> getGenEventInfo3() { return std::move(genEventInfo3_); }
0059     virtual std::unique_ptr<GenLumiInfoHeader> getGenLumiInfoHeader() const;
0060     std::unique_ptr<lhef::LHEEvent> getLHEEvent() { return std::move(lheEvent_); }
0061 
0062     void resetEvent(std::unique_ptr<HepMC::GenEvent> event) { genEvent_ = std::move(event); }
0063     void resetEvent3(std::unique_ptr<HepMC3::GenEvent> event3) { genEvent3_ = std::move(event3); }
0064     void resetEventInfo(std::unique_ptr<GenEventInfoProduct> eventInfo) { genEventInfo_ = std::move(eventInfo); }
0065     void resetEventInfo3(std::unique_ptr<GenEventInfoProduct3> eventInfo) { genEventInfo3_ = std::move(eventInfo); }
0066 
0067     // LHERunInfo and LHEEvent passing
0068     const std::shared_ptr<lhef::LHERunInfo>& getLHERunInfo() const { return lheRunInfo_; }
0069 
0070     void setLHERunInfo(std::unique_ptr<lhef::LHERunInfo> runInfo) { lheRunInfo_ = std::move(runInfo); }
0071     void setLHEEvent(std::unique_ptr<lhef::LHEEvent> event) { lheEvent_ = std::move(event); }
0072 
0073     // interface for accessing the EDM information from the hadronizer
0074     void setEDMEvent(edm::Event& event) { edmEvent_ = &event; }
0075     edm::Event& getEDMEvent() const { return *edmEvent_; }
0076     virtual bool select(HepMC::GenEvent*) const { return true; }
0077 
0078     void setRandomEngine(CLHEP::HepRandomEngine* v) { doSetRandomEngine(v); }
0079 
0080     std::vector<std::string> const& sharedResources() const { return doSharedResources(); }
0081 
0082     int randomIndex() const { return randomIndex_; }
0083     const std::string& randomInitConfigDescription() const { return randomInitConfigDescriptions_[randomIndex_]; }
0084     const std::string& gridpackPath() const { return gridpackPaths_[std::max(randomIndex_, 0)]; }
0085 
0086     void randomizeIndex(edm::LuminosityBlock const& lumi, CLHEP::HepRandomEngine* rengine);
0087     void generateLHE(edm::LuminosityBlock const& lumi, CLHEP::HepRandomEngine* rengine, unsigned int ncpu);
0088     void cleanLHE();
0089     unsigned int getVHepMC() { return ivhepmc; }
0090 
0091   protected:
0092     unsigned int ivhepmc = 2;
0093     GenRunInfoProduct& runInfo() { return genRunInfo_; }
0094     std::unique_ptr<HepMC::GenEvent>& event() { return genEvent_; }
0095     std::unique_ptr<GenEventInfoProduct>& eventInfo() { return genEventInfo_; }
0096     //HepMC3:
0097     std::unique_ptr<HepMC3::GenEvent>& event3() { return genEvent3_; }
0098     std::unique_ptr<GenEventInfoProduct3>& eventInfo3() { return genEventInfo3_; }
0099 
0100     lhef::LHEEvent* lheEvent() { return lheEvent_.get(); }
0101     lhef::LHERunInfo* lheRunInfo() { return lheRunInfo_.get(); }
0102     int randomIndex_;
0103     std::string lheFile_;
0104 
0105   private:
0106     virtual void doSetRandomEngine(CLHEP::HepRandomEngine* v) {}
0107 
0108     virtual std::vector<std::string> const& doSharedResources() const { return theSharedResources; }
0109 
0110     GenRunInfoProduct genRunInfo_;
0111     std::unique_ptr<HepMC::GenEvent> genEvent_;
0112     std::unique_ptr<HepMC3::GenEvent> genEvent3_;
0113     std::unique_ptr<GenEventInfoProduct> genEventInfo_;
0114     std::unique_ptr<GenEventInfoProduct3> genEventInfo3_;
0115 
0116     std::shared_ptr<lhef::LHERunInfo> lheRunInfo_;
0117     std::unique_ptr<lhef::LHEEvent> lheEvent_;
0118 
0119     edm::Event* edmEvent_;
0120 
0121     static const std::vector<std::string> theSharedResources;
0122 
0123     std::vector<double> randomInitWeights_;
0124     std::vector<std::string> randomInitConfigDescriptions_;
0125     std::vector<std::string> gridpackPaths_;
0126   };
0127 
0128 }  // namespace gen
0129 
0130 #endif  // gen_BaseHadronizer_h