-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30312 from smrenna/hdf5-lhe-interface
HDF5 interface for LHE-HDF5 event files
- Loading branch information
Showing
8 changed files
with
1,143 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ¶ms); | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.