LDMX Software
ReSimVerifier.cxx
1#include "DQM/ReSimVerifier.h"
2namespace dqm {
3
5 sim_coll_name_ = parameters.get<std::string>("sim_coll_name");
6 sim_pass_name_ = parameters.get<std::string>("sim_pass_name");
7 re_sim_pass_name_ = parameters.get<std::string>("resim_pass_name");
8 stop_on_error_ = parameters.get<bool>("stop_on_error");
9 collections_ = parameters.get<std::vector<std::string>>("collections");
10}
11bool ReSimVerifier::verifySimCalorimeterHits(
12 const std::vector<ldmx::SimCalorimeterHit>& simHits,
13 const std::vector<ldmx::SimCalorimeterHit>& reSimHits) {
14 for (auto i{0}; i < simHits.size(); ++i) {
15 auto hit{simHits[i]};
16 auto rehit{reSimHits[i]};
17
18 if (hit.getEdep() != rehit.getEdep()) {
19 return false;
20 }
21 if (hit.getID() != rehit.getID()) {
22 return false;
23 }
24 if (hit.getTime() != rehit.getTime()) {
25 return false;
26 }
27 if (hit.getNumberOfContribs() != rehit.getNumberOfContribs()) {
28 return false;
29 }
30 auto pos{hit.getPosition()};
31 auto repos{rehit.getPosition()};
32 if (pos[0] != repos[0] || pos[1] != repos[1] || pos[2] != repos[2]) {
33 return false;
34 }
35 }
36 return true;
37}
38
39bool ReSimVerifier::verifySimParticles(const framework::Event& event) {
40 const auto& sim_particles{
41 event.getMap<int, ldmx::SimParticle>(sim_coll_name_, sim_pass_name_)};
42 const auto& re_sim_particles{
43 event.getMap<int, ldmx::SimParticle>(sim_coll_name_, re_sim_pass_name_)};
44 for (auto [id, simParticle] : sim_particles) {
45 if (!re_sim_particles.count(id)) {
46 return false;
47 }
48 auto re_sim_particle{re_sim_particles.at(id)};
49 if (simParticle.getEnergy() != re_sim_particle.getEnergy()) {
50 return false;
51 }
52 if (simParticle.getPdgID() != re_sim_particle.getPdgID()) {
53 return false;
54 }
55 if (simParticle.getTime() != re_sim_particle.getTime()) {
56 return false;
57 }
58 }
59 return true;
60}
62 std::stringstream ss;
63 bool passing{true};
64 bool skipped{false};
65 auto event_number{event.getEventNumber()};
66 for (auto collection : collections_) {
67 const auto sim_hits = event.getCollection<ldmx::SimCalorimeterHit>(
68 collection, sim_pass_name_);
69 const auto re_sim_hits = event.getCollection<ldmx::SimCalorimeterHit>(
70 collection, re_sim_pass_name_);
71 if (re_sim_hits.size() == 0) {
72 skipped = true;
73 continue;
74 } else {
75 skipped = false;
76 }
77
78 if (!verifySimCalorimeterHits(sim_hits, re_sim_hits)) {
79 passing = false;
80 ss << "Event " << event_number << " has different simhits for "
81 << collection << std::endl;
82 }
83 }
84 if (skipped) {
85 ldmx_log(info) << "Skipping event " << event_number
86 << "since it was not resimulated";
87 }
88 if (!verifySimParticles(event)) {
89 passing = false;
90 ss << "Event " << event_number
91 << " has different SimParticles between the two passes" << std::endl;
92 }
93 if (!passing) {
94 if (stop_on_error_) {
95 EXCEPTION_RAISE("ReSimVerify", ss.str());
96 } else {
97 ldmx_log(info) << ss.str();
98 }
99 }
100
101} // Analyze
102} // namespace dqm
#define DECLARE_ANALYZER(CLASS)
Macro which allows the framework to construct an analyzer given its name during configuration.
void analyze(const framework::Event &event) override
Process the event and make histograms or summaries.
void configure(framework::config::Parameters &parameters) override
Callback for the EventProcessor to configure itself from the given set of parameters.
Implements an event buffer system for storing event data.
Definition Event.h:42
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
Stores simulated calorimeter hit information.
Class representing a simulated particle.
Definition SimParticle.h:23