LDMX Software
ReSimVerifier.cxx
1#include "DQM/ReSimVerifier.h"
2namespace dqm {
3
5 simPassName_ = parameters.getParameter<std::string>("sim_pass_name");
6 reSimPassName_ = parameters.getParameter<std::string>("resim_pass_name");
7 stop_on_error = parameters.getParameter<bool>("stop_on_error");
8 collections =
9 parameters.getParameter<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& simParticles{
41 event.getMap<int, ldmx::SimParticle>("SimParticles", simPassName_)};
42 const auto& reSimParticles{
43 event.getMap<int, ldmx::SimParticle>("SimParticles", reSimPassName_)};
44 for (auto [id, simParticle] : simParticles) {
45 if (!reSimParticles.count(id)) {
46 return false;
47 }
48 auto reSimParticle{reSimParticles.at(id)};
49 if (simParticle.getEnergy() != reSimParticle.getEnergy()) {
50 return false;
51 }
52 if (simParticle.getPdgID() != reSimParticle.getPdgID()) {
53 return false;
54 }
55 if (simParticle.getTime() != reSimParticle.getTime()) {
56 return false;
57 }
58 }
59 return true;
60}
62 std::stringstream ss;
63 bool passing{true};
64 bool skipped{false};
65 auto eventNumber{event.getEventNumber()};
66 for (auto collection : collections) {
67 const auto SimHits =
68 event.getCollection<ldmx::SimCalorimeterHit>(collection, simPassName_);
69 const auto ReSimHits = event.getCollection<ldmx::SimCalorimeterHit>(
70 collection, reSimPassName_);
71 if (ReSimHits.size() == 0) {
72 skipped = true;
73 continue;
74 } else {
75 skipped = false;
76 }
77
78 if (!verifySimCalorimeterHits(SimHits, ReSimHits)) {
79 passing = false;
80 ss << "Event " << eventNumber << " has different simhits for "
81 << collection << std::endl;
82 }
83 }
84 if (skipped) {
85 std::cout << "Skipping event " << eventNumber
86 << "since it was not resimulated" << std::endl;
87 }
88 if (!verifySimParticles(event)) {
89 passing = false;
90 ss << "Event " << eventNumber
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 std::cout << ss.str();
98 }
99 }
100
101} // Analyze
102} // namespace dqm
103DECLARE_ANALYZER_NS(dqm, ReSimVerifier);
#define DECLARE_ANALYZER_NS(NS, 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:41
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
Stores simulated calorimeter hit information.
Class representing a simulated particle.
Definition SimParticle.h:23