19 long long NumberEventsToRead) {
21 std::ifstream InputStream(InputFilePath);
22 if (!InputStream.good())
28 auto Position = InputStream.tellg();
33 " misses a header with PIDs");
36 bool HasWeights =
false;
37 double weight, px, py, pz, e;
39 while (std::getline(InputStream, Line)) {
40 if (std::all_of(Line.begin(), Line.end(),
41 [](
char c) {
return std::isspace(c); }))
43 std::stringstream StringStream(Line);
44 if ((StringStream >> weight) && !(StringStream >> py))
48 InputStream.seekg(Position);
51 size_t NumberOfParticles = 0;
53 double weight, px, py, pz, e;
54 InputStream >> weight;
56 while (std::getline(InputStream, Line)) {
57 if (std::all_of(Line.begin(), Line.end(),
58 [](
char c) {
return std::isspace(c); }))
60 std::stringstream StringStream(Line);
61 if (!(StringStream >> e >> px >> py >> pz))
65 InputStream.seekg(Position);
68 "number of tuple lines in file \"" +
69 InputFilePath +
"\"");
75 bool IsEnergyFirst =
false;
77 InputStream >> weight;
78 InputStream >> e >> px >> py >> pz;
79 if (e * e - px * px - py * py - pz * pz > 0.)
81 InputStream.seekg(Position);
84 "Energy-momentum order is not same as stated in header for file \"" +
85 InputFilePath +
"\"");
91 while (InputStream.good()) {
93 InputStream >> weight;
94 std::vector<FourMomentum> FourVectors;
95 FourVectors.reserve(NumberOfParticles);
96 for (
size_t i = 0; i < NumberOfParticles; ++i) {
98 InputStream >> e >> px >> py >> pz;
100 InputStream >> px >> py >> pz >> e;
103 if (!InputStream.fail())
104 ImportedData.Events.push_back(
Event{FourVectors, weight});
105 if (NumberEventsToRead > 0 &&
106 ImportedData.Events.size() == (std::size_t)NumberEventsToRead)
115 const std::string &OutputFilePath,
bool OverwriteFile) {
116 if (!DataSample.
Events.size())
121 auto OpenMode = std::ofstream::out;
122 if (!OverwriteFile) {
123 std::ifstream InputStream(OutputFilePath);
125 if (HeaderContent !=
"") {
131 "\", because its PIDs are not the same as the " 132 "event list you try to write");
135 "\", because there is a mismatch in units");
138 "Cannot append to file \"" + OutputFilePath +
139 "\", because the momentum-energy order is not the same");
141 OpenMode |= std::ofstream::app;
145 std::ofstream OutputStream;
146 OutputStream.open(OutputFilePath, OpenMode);
152 OutputStream << std::endl;
159 OutputStream << FourMom.px() <<
"\t";
160 OutputStream << FourMom.py() <<
"\t";
161 OutputStream << FourMom.pz() <<
"\t";
162 OutputStream << FourMom.e() << std::endl;
ComPWA four momentum class.
Input data file is corrupt or incomplete.
EventCollection readData(const std::string &InputFilePath, long long NumberEventsToRead)
Read momentum tuples from an ASCII file.
std::vector< Event > Events
std::vector< FourMomentum > FourMomenta
void writeData(const EventCollection &DataSample, const std::string &OutputFilePath, bool OverwriteFile)
Data structure containing all kinematic information of a physics event.
Logging class provides an interface for logging all over the framework.