Skip to content

Commit

Permalink
Merge pull request #30312 from smrenna/hdf5-lhe-interface
Browse files Browse the repository at this point in the history
HDF5 interface for LHE-HDF5 event files
  • Loading branch information
cmsbuild authored Sep 1, 2020
2 parents 4180585 + 00b5cc6 commit 0f1252a
Show file tree
Hide file tree
Showing 8 changed files with 1,143 additions and 5 deletions.
2 changes: 2 additions & 0 deletions GeneratorInterface/LHEInterface/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<use name="rootmath"/>
<use name="fastjet"/>
<use name="xz"/>
<use name="hdf5"/>
<use name="highfive"/>
<export>
<lib name="1"/>
</export>
68 changes: 68 additions & 0 deletions GeneratorInterface/LHEInterface/interface/LH5Reader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#ifndef GeneratorInterface_LHEInterface_LH5Reader_h
#define GeneratorInterface_LHEInterface_LH5Reader_h

#include <string>
#include <vector>
#include <memory>

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "GeneratorInterface/LHEInterface/interface/lheh5.h"

namespace lhef {

class LHERunInfo;
class LHEEvent;

class H5Handler {
public:
H5Handler(const std::string &fileNameIn);
virtual ~H5Handler() {}
void readBlock();
void counter(int, int);
std::unique_ptr<HighFive::File> h5file;
bool indexStatus;
HighFive::Group _index, _particle, _event, _init, _procInfo;
int npLO, npNLO;
unsigned int long _eventsRead;
lheh5::Events2 _events2;
lheh5::Events _events1;
std::vector<lheh5::Particle> getEvent();
lheh5::EventHeader getHeader();
std::pair<lheh5::EventHeader, std::vector<lheh5::Particle> > getEventProperties();

private:
unsigned int long _eventsTotal;
int _eventsInBlock;
int _formatType;
int _blocksRead;
};

class LH5Reader {
public:
LH5Reader(const edm::ParameterSet &params);
LH5Reader(const std::vector<std::string> &fileNames, unsigned int skip = 0, int maxEvents = -1);
LH5Reader(const std::string &inputs, unsigned int skip = 0, int maxEvents = -1);
~LH5Reader();

std::shared_ptr<LHEEvent> next(bool *newFileOpened = nullptr);

private:
class Source;
class FileSource;
class StringSource;

const std::vector<std::string> fileURLs;
const std::string strName;
unsigned int firstEvent;
int maxEvents;
unsigned int curIndex;
std::vector<std::string> weightsinconfig;

std::unique_ptr<Source> curSource;
bool curDoc;
std::shared_ptr<LHERunInfo> curRunInfo;
};

} // namespace lhef

#endif // GeneratorInterface_LHEInterface_LH5Reader_h
127 changes: 127 additions & 0 deletions GeneratorInterface/LHEInterface/interface/lheh5.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// lheh5.h
#ifndef GeneratorInterface_LHEInterface_LHEH5_H
#define GeneratorInterface_LHEInterface_LHEH5_H

#include <iostream>
#include <string>
#include <vector>

#include <unistd.h>

#include "highfive/H5File.hpp"
#include "highfive/H5DataSet.hpp"

namespace lheh5 {

struct Particle {
int id, status, mother1, mother2, color1, color2;
double px, py, pz, e, m, lifetime, spin;
// id .. IDUP
// color1/2 .. ICOLUP firt/second
// mother1/2 .. MOTHUP first/second
// status .. ISTUP
// px ... m .. PUP[..]
// lifetime .. VTIMUP (UP ... user process)
// spin .. SPINUP
};

struct EventHeader {
// Event info
int nparticles; // corr to NUP
int pid; // this is all LHAu-::setProcess
double weight;
size_t trials;
double scale;
double rscale;
double fscale;
double aqed;
double aqcd;
int npLO;
int npNLO;
};

struct Events {
// Lookup
std::vector<size_t> _vstart;
std::vector<size_t> _vend;
// Particles
std::vector<int> _vid;
std::vector<int> _vstatus;
std::vector<int> _vmother1;
std::vector<int> _vmother2;
std::vector<int> _vcolor1;
std::vector<int> _vcolor2;
std::vector<double> _vpx;
std::vector<double> _vpy;
std::vector<double> _vpz;
std::vector<double> _ve;
std::vector<double> _vm;
std::vector<double> _vlifetime;
std::vector<double> _vspin;
// Event info
std::vector<int> _vnparticles;
std::vector<int> _vpid;
std::vector<double> _vweight;
std::vector<size_t> _vtrials;
std::vector<double> _vscale;
std::vector<double> _vrscale;
std::vector<double> _vfscale;
std::vector<double> _vaqed;
std::vector<double> _vaqcd;
std::vector<int> _vnpLO;
std::vector<int> _vnpNLO;
size_t _particle_offset;

Particle mkParticle(size_t idx) const;
std::vector<Particle> mkEvent(size_t ievent) const;
EventHeader mkEventHeader(int ievent) const;
};

struct Events2 {
// Lookup
std::vector<size_t> _vstart;
// Particles
std::vector<int> _vid;
std::vector<int> _vstatus;
std::vector<int> _vmother1;
std::vector<int> _vmother2;
std::vector<int> _vcolor1;
std::vector<int> _vcolor2;
std::vector<double> _vpx;
std::vector<double> _vpy;
std::vector<double> _vpz;
std::vector<double> _ve;
std::vector<double> _vm;
std::vector<double> _vlifetime;
std::vector<double> _vspin;
// Event info
std::vector<int> _vnparticles;
std::vector<int> _vpid;
std::vector<double> _vweight;
std::vector<size_t> _vtrials;
std::vector<double> _vscale;
std::vector<double> _vrscale;
std::vector<double> _vfscale;
std::vector<double> _vaqed;
std::vector<double> _vaqcd;
int npLO;
int npNLO;
size_t _particle_offset;

Particle mkParticle(size_t idx) const;
std::vector<Particle> mkEvent(size_t ievent) const;
EventHeader mkEventHeader(int ievent) const;
};

Events readEvents(HighFive::Group& g_index,
HighFive::Group& g_particle,
HighFive::Group& g_event,
size_t first_event,
size_t n_events);
Events2 readEvents(
HighFive::Group& g_particle, HighFive::Group& g_event, size_t first_event, size_t n_events, int npLO, int npNLO);
std::ostream& operator<<(std::ostream& os, Particle const& p);
std::ostream& operator<<(std::ostream& os, EventHeader const& eh);
} // namespace lheh5

#endif
10 changes: 5 additions & 5 deletions GeneratorInterface/LHEInterface/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
<use name="SimDataFormats/GeneratorProducts"/>
<flags EDM_PLUGIN="1"/>
</library>
<library name="GeneratorInterfaceLHEIO" file="LH5Source.cc LHESource.cc LHEProvenanceHelper.cc LHEWriter.cc">
<use name="FWCore/Framework"/>
<use name="FWCore/Sources"/>
<use name="SimDataFormats/GeneratorProducts"/>
<flags EDM_PLUGIN="1"/>

<library name="GeneratorInterfaceLHEIO" file="LHESource.cc LHEProvenanceHelper.cc LHEWriter.cc">
<use name="FWCore/Framework"/>
<use name="FWCore/Sources"/>
<use name="SimDataFormats/GeneratorProducts"/>
<flags EDM_PLUGIN="1"/>
</library>

<library name="GeneratorInterfaceLHECOMWeightProducer" file="LHECOMWeightProducer.cc">
Expand Down
Loading

0 comments on commit 0f1252a

Please sign in to comment.