CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
AlpgenSource Class Reference
Inheritance diagram for AlpgenSource:
edm::ProducerSourceFromFiles edm::ProducerSourceBase edm::FromFiles edm::IDGeneratorSourceBase< PuttableSourceBase > edm::PuttableSourceBase edm::InputSource edm::ProducerBase edm::ProductRegistryHelper

Public Member Functions

 AlpgenSource (const edm::ParameterSet &params, const edm::InputSourceDescription &desc)
 Constructor. More...
 
 ~AlpgenSource () override
 Destructor. More...
 
- Public Member Functions inherited from edm::ProducerSourceFromFiles
InputFileCatalogcatalog ()
 
std::vector< std::string > fileNames (unsigned iCatalog) const
 
std::vector< std::string > const & logicalFileNames () const
 
 ProducerSourceFromFiles (ParameterSet const &pset, InputSourceDescription const &desc, bool realData)
 
 ~ProducerSourceFromFiles () override
 
- Public Member Functions inherited from edm::ProducerSourceBase
 ProducerSourceBase (ParameterSet const &pset, InputSourceDescription const &desc, bool realData)
 
 ~ProducerSourceBase () noexcept(false) override
 
- Public Member Functions inherited from edm::IDGeneratorSourceBase< PuttableSourceBase >
EventNumber_t event () const
 
unsigned int eventCreationDelay () const
 
EventID const & eventID () const
 
 IDGeneratorSourceBase (ParameterSet const &pset, InputSourceDescription const &desc, bool realData)
 
LuminosityBlockNumber_t luminosityBlock () const
 
unsigned int numberEventsInLumi () const
 
unsigned int numberEventsInRun () const
 
unsigned int numberEventsInThisLumi () const
 
unsigned int numberEventsInThisRun () const
 
TimeValue_t presentTime () const
 
RunNumber_t run () const
 
unsigned int timeBetweenEvents () const
 
 ~IDGeneratorSourceBase () noexcept(false) override
 
- Public Member Functions inherited from edm::PuttableSourceBase
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
PuttableSourceBaseoperator= (const PuttableSourceBase &)=delete
 
 PuttableSourceBase (ParameterSet const &, InputSourceDescription const &)
 
 PuttableSourceBase (const PuttableSourceBase &)=delete
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
void registerProducts () final
 Register any produced products. More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
- Public Member Functions inherited from edm::InputSource
std::shared_ptr< ActivityRegistryactReg () const
 Accessor for Activity Registry. More...
 
std::shared_ptr< BranchIDListHelper const > branchIDListHelper () const
 Accessors for branchIDListHelper. More...
 
std::shared_ptr< BranchIDListHelper > & branchIDListHelper ()
 
void closeFile (FileBlock *, bool cleaningUpAfterException)
 close current file More...
 
void doBeginJob ()
 Called by framework at beginning of job. More...
 
void doEndJob ()
 Called by framework at end of job. More...
 
void fillProcessBlockHelper ()
 Fill the ProcessBlockHelper with info for the current file. More...
 
ProcessingController::ForwardState forwardState () const
 
bool goToEvent (EventID const &eventID)
 
 InputSource (ParameterSet const &, InputSourceDescription const &)
 Constructor. More...
 
 InputSource (InputSource const &)=delete
 
void issueReports (EventID const &eventID, StreamID streamID)
 issue an event report More...
 
LuminosityBlockNumber_t luminosityBlock () const
 Accessor for current luminosity block number. More...
 
std::shared_ptr< LuminosityBlockAuxiliaryluminosityBlockAuxiliary () const
 Called by the framework to merge or insert lumi in principal cache. More...
 
int maxEvents () const
 
int maxLuminosityBlocks () const
 
ModuleDescription const & moduleDescription () const
 Accessor for 'module' description. More...
 
ItemTypeInfo nextItemType ()
 Advances the source to the next item. More...
 
bool nextProcessBlock (ProcessBlockPrincipal &)
 Next process block, return false if there is none, sets the processName in the principal. More...
 
InputSourceoperator= (InputSource const &)=delete
 
std::shared_ptr< ProcessBlockHelper const > processBlockHelper () const
 Accessors for processBlockHelper. More...
 
std::shared_ptr< ProcessBlockHelper > & processBlockHelper ()
 
ProcessConfiguration const & processConfiguration () const
 Accessor for Process Configuration. More...
 
std::string const & processGUID () const
 Accessor for global process identifier. More...
 
ProcessHistoryRegistry const & processHistoryRegistry () const
 Accessors for process history registry. More...
 
ProcessHistoryRegistryprocessHistoryRegistry ()
 
ProcessingMode processingMode () const
 RunsLumisAndEvents (default), RunsAndLumis, or Runs. More...
 
std::shared_ptr< ProductRegistry const > productRegistry () const
 Accessors for product registry. More...
 
bool randomAccess () const
 
void readAndMergeLumi (LuminosityBlockPrincipal &lbp)
 Read next luminosity block (same as a prior lumi) More...
 
void readAndMergeRun (RunPrincipal &rp)
 Read next run (same as a prior run) More...
 
void readEvent (EventPrincipal &ep, StreamContext &)
 Read next event. More...
 
bool readEvent (EventPrincipal &ep, EventID const &, StreamContext &)
 Read a specific event. More...
 
std::shared_ptr< FileBlockreadFile ()
 Read next file. More...
 
void readLuminosityBlock (LuminosityBlockPrincipal &lumiPrincipal, HistoryAppender &historyAppender)
 Read next luminosity block (new lumi) More...
 
std::shared_ptr< LuminosityBlockAuxiliaryreadLuminosityBlockAuxiliary ()
 Read next luminosity block Auxilary. More...
 
void readProcessBlock (ProcessBlockPrincipal &)
 Read next process block. More...
 
void readRun (RunPrincipal &runPrincipal, HistoryAppender &historyAppender)
 Read next run (new run) More...
 
std::shared_ptr< RunAuxiliaryreadRunAuxiliary ()
 Read next run Auxiliary. More...
 
ProcessHistoryID const & reducedProcessHistoryID () const
 
int remainingEvents () const
 
int remainingLuminosityBlocks () const
 
void repeat ()
 Reset the remaining number of events/lumis to the maximum number. More...
 
std::pair< SharedResourcesAcquirer *, std::recursive_mutex * > resourceSharedWithDelayedReader ()
 Returns nullptr if no resource shared between the Source and a DelayedReader. More...
 
ProcessingController::ReverseState reverseState () const
 
void rewind ()
 Begin again at the first event. More...
 
RunNumber_t run () const
 Accessor for current run number. More...
 
std::shared_ptr< RunAuxiliaryrunAuxiliary () const
 Called by the framework to merge or insert run in principal cache. More...
 
void setLuminosityBlockNumber_t (LuminosityBlockNumber_t lb)
 Set the luminosity block ID. More...
 
void setRunNumber (RunNumber_t r)
 Set the run number. More...
 
void skipEvents (int offset)
 
void switchTo (std::shared_ptr< ProductRegistry > iOther)
 switch to a different ProductRegistry. More...
 
std::shared_ptr< ThinnedAssociationsHelper const > thinnedAssociationsHelper () const
 Accessors for thinnedAssociationsHelper. More...
 
std::shared_ptr< ThinnedAssociationsHelper > & thinnedAssociationsHelper ()
 
Timestamp const & timestamp () const
 Accessor for the current time, as seen by the input source. More...
 
virtual ~InputSource () noexcept(false)
 Destructor. More...
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
std::vector< bool > const & recordProvenanceList () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~ProducerBase () noexcept(false) override
 

Private Member Functions

void beginRun (edm::Run &run) override
 
template<typename T >
T getParameter (AlpgenHeader::Parameter index) const
 Function to get parameter by name from AlpgenHeader. More...
 
template<typename T >
T getParameter (AlpgenHeader::Parameter index, const T &defValue) const
 Function to get parameter by name from AlpgenHeader, w/ default. More...
 
unsigned int processID () const
 
void produce (edm::Event &event) override
 
bool readAlpgenEvent (lhef::HEPEUP &hepeup)
 Read an event and put it into the HEPEUP. More...
 
bool setRunAndEventInfo (edm::EventID &, edm::TimeValue_t &, edm::EventAuxiliary::ExperimentType &) override
 
std::string slhaMassLine (int pdgId, AlpgenHeader::Masses mass, const std::string &comment) const
 

Private Attributes

std::string extraHeaderFileName_
 Name of the extra header file. More...
 
std::string extraHeaderName_
 Name given to the extra header. More...
 
std::string fileName_
 Name of the input file. More...
 
AlpgenHeader header
 Alpgen _unw.par file as an AlpgenHeader. More...
 
std::unique_ptr< lhef::HEPEUPhepeup_
 
std::unique_ptr< std::ifstream > inputFile_
 Pointer to the input file. More...
 
LHERunInfoProduct::Header lheAlpgenUnwParHeader
 Alpgen _unw.par file as a LHE header. More...
 
unsigned long nEvent_
 Number of events. More...
 
unsigned long skipEvents_
 Number of events to skip. More...
 
bool writeAlpgenParFile
 
bool writeAlpgenWgtFile
 configuration flags More...
 
bool writeExtraHeader
 

Additional Inherited Members

- Public Types inherited from edm::InputSource
enum  ItemPosition : char { ItemPosition::Invalid, ItemPosition::LastItemToBeMerged, ItemPosition::NotLastItemToBeMerged }
 
enum  ItemType : char {
  ItemType::IsInvalid, ItemType::IsStop, ItemType::IsFile, ItemType::IsRun,
  ItemType::IsLumi, ItemType::IsEvent, ItemType::IsRepeat, ItemType::IsSynchronize
}
 
enum  ProcessingMode { Runs, RunsAndLumis, RunsLumisAndEvents }
 
- Public Types inherited from edm::ProducerBase
template<typename T >
using BranchAliasSetterT = ProductRegistryHelper::BranchAliasSetterT< T >
 
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex > >
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Static Public Member Functions inherited from edm::ProducerSourceFromFiles
static void fillDescription (ParameterSetDescription &desc)
 
- Static Public Member Functions inherited from edm::IDGeneratorSourceBase< PuttableSourceBase >
static void fillDescription (ParameterSetDescription &desc)
 
- Static Public Member Functions inherited from edm::InputSource
static const std::string & baseType ()
 
static void fillDescription (ParameterSetDescription &desc)
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Public Attributes inherited from edm::InputSource
signalslot::Signal< void(StreamContext const &, ModuleCallingContext const &)> postEventReadFromSourceSignal_
 
signalslot::Signal< void(StreamContext const &, ModuleCallingContext const &)> preEventReadFromSourceSignal_
 
- Protected Member Functions inherited from edm::ProducerSourceFromFiles
void incrementFileIndex ()
 
- Protected Member Functions inherited from edm::IDGeneratorSourceBase< PuttableSourceBase >
void doReadEvent (EventPrincipal &eventPrincipal, F &&f)
 
void doReadEventWithDelayedReader (EventPrincipal &eventPrincipal, ProcessHistoryID const &historyID, EventSelectionIDVector eventSelectionIDs, BranchListIndexes branchListIndexes, DelayedReader *reader)
 
- Protected Member Functions inherited from edm::InputSource
void decreaseRemainingEventsBy (int iSkipped)
 
bool eventCached () const
 
bool newLumi () const
 
bool newRun () const
 
ProcessHistoryRegistryprocessHistoryRegistryForUpdate ()
 
ProductRegistryproductRegistryUpdate ()
 
void reset () const
 
void resetEventCached ()
 
void resetLuminosityBlockAuxiliary (bool isNewLumi=true) const
 
void resetNewLumi ()
 
void resetNewRun ()
 
void resetRunAuxiliary (bool isNewRun=true) const
 
void setEventCached ()
 Called by the framework to merge or ached() const {return eventCached_;}. More...
 
void setLuminosityBlockAuxiliary (LuminosityBlockAuxiliary *lbp)
 
void setNewLumi ()
 
void setNewRun ()
 
void setRunAuxiliary (RunAuxiliary *rp)
 
void setTimestamp (Timestamp const &theTime)
 To set the current time, as seen by the input source. More...
 
ItemTypeInfo state () const
 
- Protected Member Functions inherited from edm::ProducerBase
template<Transition Tr = Transition::Event>
auto produces (std::string instanceName) noexcept
 declare what type of product will make and with which optional label More...
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
template<Transition Tr = Transition::Event>
auto produces () noexcept
 
ProducesCollector producesCollector ()
 

Detailed Description

Definition at line 31 of file AlpgenSource.cc.

Constructor & Destructor Documentation

◆ AlpgenSource()

AlpgenSource::AlpgenSource ( const edm::ParameterSet params,
const edm::InputSourceDescription desc 
)

Constructor.

Definition at line 94 of file AlpgenSource.cc.

References LHERunInfoProduct::Header::addLine(), LHERunInfoProduct::Header::begin(), edmScanValgrind::buffer, LHERunInfoProduct::Header::end(), Exception, fileName_, edm::FromFiles::fileNames(), header, lheAlpgenUnwParHeader, AlpgenHeader::parse(), SQLiteCheck_cfg::reader, and AlCaHLTBitMon_QueryRunRegistry::string.

96  skipEvents_(params.getUntrackedParameter<unsigned int>("skipEvents", 0)),
97  nEvent_(0),
98  lheAlpgenUnwParHeader("AlpgenUnwParFile"),
99  extraHeaderFileName_(params.getUntrackedParameter<std::string>("extraHeaderFileName", "")),
100  extraHeaderName_(params.getUntrackedParameter<std::string>("extraHeaderName", "")),
101  writeAlpgenWgtFile(params.getUntrackedParameter<bool>("writeAlpgenWgtFile", true)),
102  writeAlpgenParFile(params.getUntrackedParameter<bool>("writeAlpgenParFile", true)),
103  writeExtraHeader(params.getUntrackedParameter<bool>("writeExtraHeader", false)) {
104  std::vector<std::string> allFileNames = fileNames(0);
105 
106  // Only one filename
107  if (allFileNames.size() != 1)
108  throw cms::Exception("Generator|AlpgenInterface") << "AlpgenSource needs exactly one file specified "
109  "for now."
110  << std::endl;
111 
112  fileName_ = allFileNames[0];
113 
114  // Strip the "file:" prefix
115  if (fileName_.find("file:") != 0)
116  throw cms::Exception("Generator|AlpgenInterface") << "AlpgenSource only supports the file: scheme "
117  "for now."
118  << std::endl;
119  fileName_.erase(0, 5);
120 
121  // Open the _unw.par file to store additional
122  // informations in the LHERunInfoProduct
123  std::ifstream reader((fileName_ + "_unw.par").c_str());
124  if (!reader.good())
125  throw cms::Exception("Generator|AlpgenInterface")
126  << "AlpgenSource was unable to open the file \"" << fileName_ << "_unw.par\"." << std::endl;
127 
128  // A full copy of the _unw.par file in the LHE header.
129  char buffer[256];
130  while (reader.getline(buffer, sizeof buffer))
132 
133  // Parse that header to setup an Alpgen header,
134  // which will be used in the production itself.
136  throw cms::Exception("Generator|AlpgenInterface") << "AlpgenSource was unable to parse the Alpgen "
137  << "unweighted parameter file." << std::endl;
138 
139  // Declare the products.
140  produces<LHERunInfoProduct, edm::Transition::BeginRun>();
141  produces<LHEEventProduct>();
142 }
bool parse(const std::vector< std::string >::const_iterator &begin, const std::vector< std::string >::const_iterator &end)
Definition: AlpgenHeader.cc:62
AlpgenHeader header
Alpgen _unw.par file as an AlpgenHeader.
Definition: AlpgenSource.cc:78
bool writeAlpgenParFile
Definition: AlpgenSource.cc:90
bool writeExtraHeader
Definition: AlpgenSource.cc:91
unsigned long nEvent_
Number of events.
Definition: AlpgenSource.cc:73
unsigned long skipEvents_
Number of events to skip.
Definition: AlpgenSource.cc:70
bool writeAlpgenWgtFile
configuration flags
Definition: AlpgenSource.cc:89
const_iterator end() const
LHERunInfoProduct::Header lheAlpgenUnwParHeader
Alpgen _unw.par file as a LHE header.
Definition: AlpgenSource.cc:76
std::string extraHeaderFileName_
Name of the extra header file.
Definition: AlpgenSource.cc:83
void addLine(const std::string &line)
const_iterator begin() const
std::string fileName_
Name of the input file.
Definition: AlpgenSource.cc:64
std::string extraHeaderName_
Name given to the extra header.
Definition: AlpgenSource.cc:86
std::vector< std::string > fileNames(unsigned iCatalog) const
Definition: FromFiles.h:22

◆ ~AlpgenSource()

AlpgenSource::~AlpgenSource ( )
override

Destructor.

Definition at line 144 of file AlpgenSource.cc.

144 {}

Member Function Documentation

◆ beginRun()

void AlpgenSource::beginRun ( edm::Run run)
overrideprivatevirtual

Reimplemented from edm::PuttableSourceBase.

Definition at line 153 of file AlpgenSource.cc.

References LHERunInfoProduct::Header::addLine(), edmScanValgrind::buffer, AlpgenHeader::ebeam, lhef::HEPRUP::EBMUP, Exception, extraHeaderFileName_, extraHeaderName_, fileName_, header, lhef::HEPRUP::IDBMUP, lhef::HEPRUP::IDWTUP, AlpgenHeader::ih2, inputFile_, lheAlpgenUnwParHeader, lhe2HepMCConverter_cff::LHERunInfoProduct, lhef::HEPRUP::LPRUP, AlpgenHeader::mb, AlpgenHeader::mc, AlpgenHeader::mh, eostools::move(), AlpgenHeader::mt, AlpgenHeader::mw, AlpgenHeader::mz, lhef::HEPRUP::PDFGUP, lhef::HEPRUP::PDFSUP, processID(), lhef::HEPRUP::resize(), edm::IDGeneratorSourceBase< PuttableSourceBase >::run(), submitPVValidationJobs::runInfo, slhaMassLine(), AlCaHLTBitMon_QueryRunRegistry::string, writeAlpgenParFile, writeAlpgenWgtFile, writeExtraHeader, lhef::HEPRUP::XERRUP, lhef::HEPRUP::XMAXUP, AlpgenHeader::xsec, AlpgenHeader::xsecErr, and lhef::HEPRUP::XSECUP.

153  {
154  // At this point, the lheUnwParHeader has the full contents of the _unw.par
155  // file. So we can get the HEPRUP information from the LHE header itself.
156  lhef::HEPRUP heprup;
157 
158  // Get basic run information.
159  // Beam identity.
160  heprup.IDBMUP.first = 2212;
161  switch (getParameter<int>(AlpgenHeader::ih2)) {
162  case 1:
163  heprup.IDBMUP.second = 2212;
164  break;
165  case -1:
166  heprup.IDBMUP.second = -2212;
167  break;
168  default:
169  throw cms::Exception("Generator|AlpgenInterface") << "AlpgenSource was unable to understand the ih2 "
170  << "parameter." << std::endl;
171  }
172 
173  // Beam energy.
174  heprup.EBMUP.second = heprup.EBMUP.first = getParameter<double>(AlpgenHeader::ebeam);
175 
176  // PDF info. Initially, Alpgen doesn't fill it.
177  heprup.PDFGUP.first = -1;
178  heprup.PDFGUP.second = -1;
179  heprup.PDFSUP.first = -1;
180  heprup.PDFSUP.second = -1;
181 
182  // Unweighted events.
183  heprup.IDWTUP = 3;
184 
185  // Only one process.
186  heprup.resize(1);
187 
188  // Cross section and error.
189  heprup.XSECUP[0] = header.xsec;
190  heprup.XERRUP[0] = header.xsecErr;
191 
192  // Maximum weight.
193  heprup.XMAXUP[0] = header.xsec;
194 
195  // Process code for Pythia.
196  heprup.LPRUP[0] = processID();
197 
198  // Comments on top.
199  LHERunInfoProduct::Header comments;
200  comments.addLine("\n");
201  comments.addLine("\tExtracted by AlpgenInterface\n");
202 
203  // Add SLHA header containing particle masses from Alpgen.
204  // Pythia6Hadronisation will feed the masses to Pythia automatically.
205  LHERunInfoProduct::Header slha("slha");
206  slha.addLine("\n# SLHA header containing masses from Alpgen\n");
207  slha.addLine("Block MASS # Mass spectrum (kinematic masses)\n");
208  slha.addLine("# PDG Mass\n");
209  slha.addLine(slhaMassLine(4, AlpgenHeader::mc, "charm pole mass"));
210  slha.addLine(slhaMassLine(5, AlpgenHeader::mb, "bottom pole mass"));
211  slha.addLine(slhaMassLine(6, AlpgenHeader::mt, "top pole mass"));
212  slha.addLine(slhaMassLine(23, AlpgenHeader::mz, "Z mass"));
213  slha.addLine(slhaMassLine(24, AlpgenHeader::mw, "W mass"));
214  slha.addLine(slhaMassLine(25, AlpgenHeader::mh, "H mass"));
215 
216  char buffer[512];
217 
218  // We also add the information on weighted events.
219  LHERunInfoProduct::Header lheAlpgenWgtHeader("AlpgenWgtFile");
220  if (writeAlpgenWgtFile) {
221  std::ifstream wgtascii((fileName_ + ".wgt").c_str());
222  while (wgtascii.getline(buffer, 512)) {
223  lheAlpgenWgtHeader.addLine(std::string(buffer) + "\n");
224  }
225  }
226 
227  LHERunInfoProduct::Header lheAlpgenParHeader("AlpgenParFile");
228  if (writeAlpgenParFile) {
229  std::ifstream parascii((fileName_ + ".par").c_str());
230  while (parascii.getline(buffer, 512)) {
231  lheAlpgenParHeader.addLine(std::string(buffer) + "\n");
232  }
233  }
234 
235  // If requested by the user, we also add any specific header provided.
236  // Nota bene: the header is put in the LHERunInfoProduct AS IT WAS GIVEN.
237  // That means NO CROSS-CHECKS WHATSOEVER. Use with care.
239  if (writeExtraHeader) {
240  std::ifstream extraascii(extraHeaderFileName_.c_str());
241  while (extraascii.getline(buffer, 512)) {
242  extraHeader.addLine(std::string(buffer) + "\n");
243  }
244  }
245 
246  // Build the final Run info object. Backwards-compatible order.
247  std::unique_ptr<LHERunInfoProduct> runInfo(new LHERunInfoProduct(heprup));
248  runInfo->addHeader(comments);
249  runInfo->addHeader(lheAlpgenUnwParHeader);
250  if (writeAlpgenWgtFile)
251  runInfo->addHeader(lheAlpgenWgtHeader);
252  if (writeAlpgenParFile)
253  runInfo->addHeader(lheAlpgenParHeader);
254  runInfo->addHeader(slha);
255  if (writeExtraHeader)
256  runInfo->addHeader(extraHeader);
257  run.put(std::move(runInfo));
258 
259  // Open the .unw file in the heap, and set the global pointer to it.
260  inputFile_ = std::make_unique<std::ifstream>((fileName_ + ".unw").c_str());
261  if (!inputFile_->good())
262  throw cms::Exception("Generator|AlpgenInterface")
263  << "AlpgenSource was unable to open the file \"" << fileName_ << ".unw\"." << std::endl;
264 }
void resize(int nrup)
Definition: LesHouches.h:44
std::string slhaMassLine(int pdgId, AlpgenHeader::Masses mass, const std::string &comment) const
std::pair< double, double > EBMUP
Definition: LesHouches.h:82
AlpgenHeader header
Alpgen _unw.par file as an AlpgenHeader.
Definition: AlpgenSource.cc:78
std::pair< int, int > IDBMUP
Definition: LesHouches.h:77
std::unique_ptr< std::ifstream > inputFile_
Pointer to the input file.
Definition: AlpgenSource.cc:67
bool writeAlpgenParFile
Definition: AlpgenSource.cc:90
bool writeExtraHeader
Definition: AlpgenSource.cc:91
std::pair< int, int > PDFGUP
Definition: LesHouches.h:88
bool writeAlpgenWgtFile
configuration flags
Definition: AlpgenSource.cc:89
LHERunInfoProduct::Header lheAlpgenUnwParHeader
Alpgen _unw.par file as a LHE header.
Definition: AlpgenSource.cc:76
std::string extraHeaderFileName_
Name of the extra header file.
Definition: AlpgenSource.cc:83
void addLine(const std::string &line)
unsigned int processID() const
std::vector< double > XERRUP
Definition: LesHouches.h:118
std::string fileName_
Name of the input file.
Definition: AlpgenSource.cc:64
std::vector< double > XMAXUP
Definition: LesHouches.h:123
std::string extraHeaderName_
Name given to the extra header.
Definition: AlpgenSource.cc:86
std::pair< int, int > PDFSUP
Definition: LesHouches.h:94
double xsecErr
Definition: AlpgenHeader.h:68
std::vector< double > XSECUP
Definition: LesHouches.h:112
def move(src, dest)
Definition: eostools.py:511
std::vector< int > LPRUP
Definition: LesHouches.h:128

◆ getParameter() [1/2]

template<typename T >
T AlpgenSource::getParameter ( AlpgenHeader::Parameter  index) const
private

Function to get parameter by name from AlpgenHeader.

Definition at line 267 of file AlpgenSource.cc.

References header, AlpgenHeader::parameterName(), and AlpgenHeader::params.

267  {
268  std::map<AlpgenHeader::Parameter, double>::const_iterator pos = header.params.find(index);
269  if (pos == header.params.end())
270  throw cms::Exception("Generator|AlpgenInterface")
271  << "Requested Alpgen parameter \"" << AlpgenHeader::parameterName(index)
272  << "\" "
273  "not found in Alpgen parameter file."
274  << std::endl;
275 
276  return T(pos->second);
277 }
std::map< Parameter, double > params
Definition: AlpgenHeader.h:65
AlpgenHeader header
Alpgen _unw.par file as an AlpgenHeader.
Definition: AlpgenSource.cc:78
static std::string parameterName(Parameter index)
long double T

◆ getParameter() [2/2]

template<typename T >
T AlpgenSource::getParameter ( AlpgenHeader::Parameter  index,
const T defValue 
) const
private

Function to get parameter by name from AlpgenHeader, w/ default.

Definition at line 280 of file AlpgenSource.cc.

References header, and AlpgenHeader::params.

280  {
281  std::map<AlpgenHeader::Parameter, double>::const_iterator pos = header.params.find(index);
282  if (pos == header.params.end())
283  return defValue;
284  else
285  return T(pos->second);
286 }
std::map< Parameter, double > params
Definition: AlpgenHeader.h:65
AlpgenHeader header
Alpgen _unw.par file as an AlpgenHeader.
Definition: AlpgenSource.cc:78
long double T

◆ processID()

unsigned int AlpgenSource::processID ( ) const
private

The Alpgen process ID. This is defined as processID() = 100*X + 10*Y + Z, where = ihrd, Y = ihvy, Z = njets

Definition at line 288 of file AlpgenSource.cc.

References header, AlpgenHeader::ihrd, AlpgenHeader::ihvy, and AlpgenHeader::njets.

Referenced by beginRun(), and readAlpgenEvent().

288  {
289  // return 661; // The original, old thing.
290  // digits #XYZ: X = ihrd, Y = ihvy, Z = njets
291  return header.ihrd * 100 + getParameter<unsigned int>(AlpgenHeader::ihvy, 0) * 10 +
292  getParameter<unsigned int>(AlpgenHeader::njets, 0);
293 }
AlpgenHeader header
Alpgen _unw.par file as an AlpgenHeader.
Definition: AlpgenSource.cc:78
unsigned int ihrd
Definition: AlpgenHeader.h:66

◆ produce()

void AlpgenSource::produce ( edm::Event event)
overrideprivatevirtual

Implements edm::ProducerSourceBase.

Definition at line 422 of file AlpgenSource.cc.

References Exception, alpgen::fixEventHiggsTTbar(), alpgen::fixEventMultiBoson(), alpgen::fixEventSingleTop(), alpgen::fixEventTTbar(), alpgen::fixEventWZ(), header, hepeup_, AlpgenHeader::ihrd, AlpgenHeader::itopprc, lhe2HepMCConverter_cff::LHEEventProduct, AlpgenHeader::masses, AlpgenHeader::mb, eostools::move(), and AlpgenHeader::params.

422  {
423  // Here are the Alpgen routines for filling up the rest
424  // of the LHE Event Record. The .unw file has the information
425  // in a compressed way, e.g. it doesn't list the W boson -
426  // one has to reconstruct it from the e nu pair.
427  lhef::HEPEUP &hepeup = *hepeup_;
428 
429  switch (header.ihrd) {
430  case 1:
431  case 2:
432  case 3:
433  case 4:
434  case 10:
435  case 14:
436  case 15:
437  alpgen::fixEventWZ(hepeup);
438  break;
439  case 5:
441  break;
442  case 6:
443  alpgen::fixEventTTbar(hepeup);
444  break;
445  case 8:
447  break;
448  case 13:
450  break;
451  case 7:
452  case 9:
453  case 11:
454  case 12:
455  case 16:
456  // No fixes needed.
457  break;
458 
459  default:
460  throw cms::Exception("Generator|AlpgenInterface") << "Unrecognized IHRD process code" << std::endl;
461  }
462 
463  // Create the LHEEventProduct and put it into the Event.
464  std::unique_ptr<LHEEventProduct> lheEvent(new LHEEventProduct(hepeup));
465  event.put(std::move(lheEvent));
466 
467  hepeup_.reset();
468 }
std::map< Parameter, double > params
Definition: AlpgenHeader.h:65
AlpgenHeader header
Alpgen _unw.par file as an AlpgenHeader.
Definition: AlpgenSource.cc:78
std::unique_ptr< lhef::HEPEUP > hepeup_
Definition: AlpgenSource.cc:80
void fixEventWZ(lhef::HEPEUP &hepeup)
Fixes Event Record for ihrd = 1,2,3,4,10,14,15.
void fixEventMultiBoson(lhef::HEPEUP &hepeup)
Fixes Event Record for ihrd = 5.
void fixEventHiggsTTbar(lhef::HEPEUP &hepeup)
Fixes Event Record for ihrd = 8.
void fixEventSingleTop(lhef::HEPEUP &hepeup, double mb, int itopprc)
Fixes Event Record for ihrd = 13.
unsigned int ihrd
Definition: AlpgenHeader.h:66
void fixEventTTbar(lhef::HEPEUP &hepeup)
Fixes Event Record for ihrd = 6.
double masses[MASS_MAX]
Definition: AlpgenHeader.h:71
def move(src, dest)
Definition: eostools.py:511

◆ readAlpgenEvent()

bool AlpgenSource::readAlpgenEvent ( lhef::HEPEUP hepeup)
private

Read an event and put it into the HEPEUP.

Definition at line 295 of file AlpgenSource.cc.

References edmScanValgrind::buffer, HBHEDarkening_cff::energy, mps_fire::i, lhef::HEPEUP::ICOLUP, lhef::HEPEUP::IDPRUP, lhef::HEPEUP::IDUP, inputFile_, lhef::HEPEUP::ISTUP, relval_nano::ls, EgHLTOffHistBins_cfi::mass, lhef::HEPEUP::MOTHUP, nPart(), processID(), lhef::HEPEUP::PUP, multPhiCorr_741_25nsDY_cfi::px, multPhiCorr_741_25nsDY_cfi::py, lhef::HEPEUP::resize(), lhef::HEPEUP::SCALUP, mathSSE::sqrt(), and lhef::HEPEUP::XWGTUP.

Referenced by setRunAndEventInfo().

295  {
296  char buffer[512];
297  double dummy;
298  int nPart;
299  double sWgtRes;
300  double sQ;
301 
302  inputFile_->getline(buffer, sizeof buffer);
303  if (!inputFile_->good())
304  return false;
305 
306  std::istringstream ls(buffer);
307 
308  // Event number and process don't matter (or do they?)
309  ls >> dummy >> dummy;
310 
311  // Number of particles in the record, sample's average weight and Q scale
312  ls >> nPart >> sWgtRes >> sQ;
313 
314  if (ls.bad() || nPart < 1 || nPart > 1000)
315  return false;
316 
317  // Make room for the particles listed in the Alpgen file
318  hepeup.resize(nPart);
319 
320  // Scales, weights and process ID.
321  hepeup.SCALUP = sQ;
322  hepeup.XWGTUP = sWgtRes;
323  hepeup.IDPRUP = processID();
324 
325  // Incoming lines
326  for (int i = 0; i != 2; ++i) {
327  inputFile_->getline(buffer, sizeof buffer);
328  std::istringstream ls(buffer);
329  int flavour;
330  ls >> flavour;
331  int colour1;
332  ls >> colour1;
333  int colour2;
334  ls >> colour2;
335  double zMomentum;
336  ls >> zMomentum;
337 
338  if (inputFile_->bad())
339  return false;
340 
341  // Setting the HEPEUP of the incoming lines.
342  hepeup.IDUP[i] = flavour;
343  hepeup.ISTUP[i] = -1;
344  hepeup.MOTHUP[i].first = 0;
345  hepeup.MOTHUP[i].second = 0;
346  hepeup.PUP[i][0] = 0.;
347  hepeup.PUP[i][1] = 0.;
348  hepeup.PUP[i][2] = zMomentum;
349  hepeup.PUP[i][3] = std::fabs(zMomentum);
350  hepeup.PUP[i][4] = 0.;
351  if (colour1)
352  colour1 += 500;
353  if (colour2)
354  colour2 += 500;
355  hepeup.ICOLUP[i].first = colour1;
356  hepeup.ICOLUP[i].second = colour2;
357  }
358 
359  // Outgoing lines
360  for (int i = 2; i != nPart; ++i) {
361  inputFile_->getline(buffer, sizeof buffer);
362  std::istringstream ls(buffer);
363  int flavour;
364  ls >> flavour;
365  int colour1;
366  ls >> colour1;
367  int colour2;
368  ls >> colour2;
369  double px, py, pz, mass;
370  ls >> px >> py >> pz >> mass;
371  double energy = std::sqrt(px * px + py * py + pz * pz + mass * mass);
372 
373  if (inputFile_->bad())
374  return false;
375 
376  // Setting the HEPEUP of the outgoing lines.
377  hepeup.IDUP[i] = flavour;
378  hepeup.ISTUP[i] = 1;
379  hepeup.MOTHUP[i].first = 1;
380  hepeup.MOTHUP[i].second = 2;
381  hepeup.PUP[i][0] = px;
382  hepeup.PUP[i][1] = py;
383  hepeup.PUP[i][2] = pz;
384  hepeup.PUP[i][3] = energy;
385  hepeup.PUP[i][4] = mass;
386  if (colour1)
387  colour1 += 500;
388  if (colour2)
389  colour2 += 500;
390  hepeup.ICOLUP[i].first = colour1;
391  hepeup.ICOLUP[i].second = colour2;
392  }
393 
394  return true;
395 }
std::vector< std::pair< int, int > > ICOLUP
Definition: LesHouches.h:240
std::unique_ptr< std::ifstream > inputFile_
Pointer to the input file.
Definition: AlpgenSource.cc:67
void resize(int nup)
Definition: LesHouches.h:161
T sqrt(T t)
Definition: SSEVec.h:23
std::vector< FiveVector > PUP
Definition: LesHouches.h:246
unsigned int processID() const
std::vector< int > ISTUP
Definition: LesHouches.h:228
std::vector< std::pair< int, int > > MOTHUP
Definition: LesHouches.h:234
std::vector< int > IDUP
Definition: LesHouches.h:223
TString nPart(Int_t part, TString string, TString delimit=";", Bool_t removerest=true)
double XWGTUP
Definition: LesHouches.h:194
double SCALUP
Definition: LesHouches.h:208

◆ setRunAndEventInfo()

bool AlpgenSource::setRunAndEventInfo ( edm::EventID ,
edm::TimeValue_t ,
edm::EventAuxiliary::ExperimentType  
)
overrideprivatevirtual

Implements edm::IDGeneratorSourceBase< PuttableSourceBase >.

Definition at line 397 of file AlpgenSource.cc.

References Exception, hepeup_, inputFile_, nEvent_, readAlpgenEvent(), and skipEvents_.

397  {
398  // The LHE Event Record
399  hepeup_ = std::make_unique<lhef::HEPEUP>();
400 
401  lhef::HEPEUP &hepeup = *hepeup_;
402 
403  // Read the .unw file until it is over.
404  for (;;) {
405  if (!readAlpgenEvent(hepeup)) {
406  if (inputFile_->eof())
407  return false;
408 
409  throw cms::Exception("Generator|AlpgenInterface")
410  << "AlpgenSource is not able read event no. " << nEvent_ << std::endl;
411  }
412 
413  nEvent_++;
414  if (skipEvents_ > 0)
415  skipEvents_--;
416  else
417  break;
418  }
419  return true;
420 }
std::unique_ptr< std::ifstream > inputFile_
Pointer to the input file.
Definition: AlpgenSource.cc:67
unsigned long nEvent_
Number of events.
Definition: AlpgenSource.cc:73
unsigned long skipEvents_
Number of events to skip.
Definition: AlpgenSource.cc:70
std::unique_ptr< lhef::HEPEUP > hepeup_
Definition: AlpgenSource.cc:80
bool readAlpgenEvent(lhef::HEPEUP &hepeup)
Read an event and put it into the HEPEUP.

◆ slhaMassLine()

std::string AlpgenSource::slhaMassLine ( int  pdgId,
AlpgenHeader::Masses  mass,
const std::string &  comment 
) const
private

Converts the AlpgenHeader::Masses to a std::string formatted as a slhaMassLine to facilitate passing them to Alpgen.

Definition at line 146 of file AlpgenSource.cc.

References header, EgHLTOffHistBins_cfi::mass, AlpgenHeader::masses, EgammaValidation_cff::pdgId, and contentValuesCheck::ss.

Referenced by beginRun().

146  {
147  std::ostringstream ss;
148  ss << std::setw(9) << pdgId << " " << std::scientific << std::setprecision(9) << header.masses[mass] << " # "
149  << comment << std::endl;
150  return ss.str();
151 }
AlpgenHeader header
Alpgen _unw.par file as an AlpgenHeader.
Definition: AlpgenSource.cc:78
double masses[MASS_MAX]
Definition: AlpgenHeader.h:71

Member Data Documentation

◆ extraHeaderFileName_

std::string AlpgenSource::extraHeaderFileName_
private

Name of the extra header file.

Definition at line 83 of file AlpgenSource.cc.

Referenced by beginRun().

◆ extraHeaderName_

std::string AlpgenSource::extraHeaderName_
private

Name given to the extra header.

Definition at line 86 of file AlpgenSource.cc.

Referenced by beginRun().

◆ fileName_

std::string AlpgenSource::fileName_
private

Name of the input file.

Definition at line 64 of file AlpgenSource.cc.

Referenced by AlpgenSource(), and beginRun().

◆ header

AlpgenHeader AlpgenSource::header
private

Alpgen _unw.par file as an AlpgenHeader.

Definition at line 78 of file AlpgenSource.cc.

Referenced by AlpgenSource(), beginRun(), getParameter(), processID(), produce(), and slhaMassLine().

◆ hepeup_

std::unique_ptr<lhef::HEPEUP> AlpgenSource::hepeup_
private

Definition at line 80 of file AlpgenSource.cc.

Referenced by produce(), and setRunAndEventInfo().

◆ inputFile_

std::unique_ptr<std::ifstream> AlpgenSource::inputFile_
private

Pointer to the input file.

Definition at line 67 of file AlpgenSource.cc.

Referenced by beginRun(), readAlpgenEvent(), and setRunAndEventInfo().

◆ lheAlpgenUnwParHeader

LHERunInfoProduct::Header AlpgenSource::lheAlpgenUnwParHeader
private

Alpgen _unw.par file as a LHE header.

Definition at line 76 of file AlpgenSource.cc.

Referenced by AlpgenSource(), and beginRun().

◆ nEvent_

unsigned long AlpgenSource::nEvent_
private

Number of events.

Definition at line 73 of file AlpgenSource.cc.

Referenced by setRunAndEventInfo().

◆ skipEvents_

unsigned long AlpgenSource::skipEvents_
private

Number of events to skip.

Definition at line 70 of file AlpgenSource.cc.

Referenced by setRunAndEventInfo().

◆ writeAlpgenParFile

bool AlpgenSource::writeAlpgenParFile
private

Definition at line 90 of file AlpgenSource.cc.

Referenced by beginRun().

◆ writeAlpgenWgtFile

bool AlpgenSource::writeAlpgenWgtFile
private

configuration flags

Definition at line 89 of file AlpgenSource.cc.

Referenced by beginRun().

◆ writeExtraHeader

bool AlpgenSource::writeExtraHeader
private

Definition at line 91 of file AlpgenSource.cc.

Referenced by beginRun().