100int main(
int argc,
char** argv) {
101 std::string source =
"sDST";
102 std::vector<std::string> positional;
103 for (
int i = 1; i < argc; ++i) {
104 const std::string arg = argv[i];
105 if (arg ==
"--source") {
106 if (++i >= argc) { std::cerr <<
"error: --source requires sDST or fDST\n";
return 1; }
108 }
else if (arg.rfind(
"--source=", 0) == 0) {
109 source = arg.substr(std::string(
"--source=").size());
110 }
else if (arg.rfind(
"--", 0) == 0) {
111 std::cerr <<
"error: unknown option: " << arg <<
"\n";
114 positional.push_back(arg);
117 if (positional.size() != 2) {
usage(argv[0]);
return 1; }
118 if (source !=
"sDST" && source !=
"fDST") {
119 std::cerr <<
"error: --source must be sDST or fDST, got: " << source <<
"\n";
122 const std::string& input = positional[0];
123 const std::string& kind = positional[1];
124 if (kind !=
"data" && kind !=
"mc") {
125 std::cerr <<
"error: expected data or mc, got: " << kind <<
"\n";
129 const bool expectNegativeRun = (kind ==
"mc");
131 const std::string cfg = source +
"_BTAGCFG_";
132 const std::string
aa = source +
"_AABTAG_";
133 const std::string btg = source +
"_BTG_";
136 const std::string evt =
"sDST_EVT_";
140 podio::ROOTReader reader;
141 reader.openFile(input);
142 stats.entries = reader.getEntries(
"events");
144 for (std::uint64_t i = 0; i < stats.entries; ++i) {
145 podio::Frame frame(reader.readEntry(
"events", i));
146 ++stats.framesChecked;
149 const auto prefix = frame.getParameter<std::string>(cfg +
"SourcePrefix");
150 if (!prefix) ++stats.missingParameters;
151 else if (*prefix != source) ++stats.sourcePrefixFailures;
153 const auto beamspot = frame.getParameter<
int>(cfg +
"BeamSpotErrorCode");
154 if (!beamspot) ++stats.missingParameters;
155 else if (*beamspot != 0) ++stats.beamspotErrorEvents;
159 const auto run = frame.getParameter<
int>(evt +
"runNumber");
160 if (!run) ++stats.missingParameters;
161 else if ((*run < 0) != expectNegativeRun) ++stats.runSignFailures;
164 for (
const std::string& tag : {btg,
aa}) {
165 for (
const char* name : {
"ProbNegIP",
"ProbPosIP",
"ProbAllIP",
"ThrustAxis"}) {
166 const auto v = frame.getParameter<std::vector<float>>(tag + name);
167 if (!v) { ++stats.missingParameters;
continue; }
168 if (v->size() != 3) { ++stats.probabilityFailures;
continue; }
169 const bool cosine = std::string_view(name) ==
"ThrustAxis";
170 for (
const float x : *v) {
171 if (cosine ? !okCosine(x) : !okProbability(x)) ++stats.probabilityFailures;
174 const auto thrust = frame.getParameter<
float>(tag +
"ThrustValue");
175 if (!thrust) ++stats.missingParameters;
176 else if (!okProbability(*thrust)) ++stats.probabilityFailures;
179 const auto nTracks = frame.getParameter<
int>(
aa +
"NTracks");
180 const auto nAttached = frame.getParameter<
int>(
aa +
"NTracksAttached");
181 const auto valid = frame.getParameter<
int>(
aa +
"Valid");
182 if (!nTracks || !nAttached || !valid) { ++stats.missingParameters;
continue; }
184 const auto names = frame.getAvailableCollections();
185 const auto has = [&](
const std::string& n) {
186 for (
const auto& x : names)
if (x == n)
return true;
191 const std::string tagName =
aa +
"TrackTag";
192 if (!has(tagName)) { ++stats.missingCollections;
continue; }
193 const auto& tags = frame.get<edm4hep::ParticleIDCollection>(tagName);
194 if (
static_cast<int>(tags.size()) != *nTracks) ++stats.tagRowCountFailures;
196 std::uint64_t attachedRows = 0;
197 for (
const auto& tag : tags) {
198 const auto params = tag.getParameters();
200 ++stats.tagParamCountFailures;
201 ++stats.tagRowsUnchecked;
209 const bool attached =
214 ++stats.tagDomainFailures;
216 ++stats.tagDomainFailures;
223 ++stats.tagDomainFailures;
232 ++stats.tagDomainFailures;
243 ++stats.tagDomainFailures;
248 ++stats.tagDomainFailures;
251 if (attached) ++attachedRows;
252 if (!tag.getParticle().isAvailable()) ++stats.unresolvedParticles;
256 const std::string trackName = source +
"_TRAC_Tracks";
257 if (!has(trackName)) { ++stats.missingCollections;
continue; }
259 for (
const auto& track : frame.get<edm4hep::TrackCollection>(trackName)) {
260 for (
const auto& state : track.getTrackStates()) {
261 if (state.location != edm4hep::TrackState::AtVertex)
continue;
264 ++stats.impactDomainFailures;
266 const float vD0 = state.covMatrix[0];
267 const float vZ0 = state.covMatrix[9];
269 ++stats.impactDomainFailures;
272 if (atVertex != *nTracks) ++stats.impactStateCountFailures;
275 const std::string pvName =
aa +
"PrimaryVertex";
276 if (!has(pvName)) { ++stats.missingCollections;
continue; }
277 const auto& pvs = frame.get<edm4hep::VertexCollection>(pvName);
278 const std::size_t expectedPvs = (*valid == 1) ? 1u : 0u;
279 if (pvs.size() != expectedPvs) ++stats.vertexFailures;
280 for (
const auto& pv : pvs) {
281 if (!pv.isPrimary() ||
287 ++stats.vertexFailures;
293 ++stats.vertexFailures;
297 if (
static_cast<int>(pv.getParticles().size()) != *nAttached)
298 ++stats.attachedConsistencyFailures;
300 if (attachedRows !=
static_cast<std::uint64_t
>(*nAttached))
301 ++stats.attachedConsistencyFailures;
303 }
catch (
const std::exception& error) {
304 std::cerr <<
"error: validation failed: " << error.what() <<
"\n";
305 ++stats.frameReadFailures;
308 const bool ok = stats.failures() == 0;
309 std::cout <<
"status=" << (ok ?
"PASS" :
"FAIL")
310 <<
" entries=" << stats.entries
311 <<
" source=" << source
312 <<
" expected=" << kind
313 <<
" frames_checked=" << stats.framesChecked
314 <<
" failures=" << stats.failures()
315 <<
" frame_read_failures=" << stats.frameReadFailures
316 <<
" missing_parameters=" << stats.missingParameters
317 <<
" missing_collections=" << stats.missingCollections
318 <<
" source_prefix_failures=" << stats.sourcePrefixFailures
319 <<
" run_sign_failures=" << stats.runSignFailures
320 <<
" probability_failures=" << stats.probabilityFailures
321 <<
" tag_row_count_failures=" << stats.tagRowCountFailures
322 <<
" tag_param_count_failures=" << stats.tagParamCountFailures
323 <<
" tag_rows_unchecked=" << stats.tagRowsUnchecked
324 <<
" tag_domain_failures=" << stats.tagDomainFailures
325 <<
" impact_state_count_failures=" << stats.impactStateCountFailures
326 <<
" impact_domain_failures=" << stats.impactDomainFailures
327 <<
" vertex_failures=" << stats.vertexFailures
328 <<
" attached_consistency_failures=" << stats.attachedConsistencyFailures
329 <<
" unresolved_particles=" << stats.unresolvedParticles
330 <<
" beamspot_error_events=" << stats.beamspotErrorEvents