LDMX Software
EcalDigiVerifier.cxx
1
2#include "DQM/EcalDigiVerifier.h"
3
4namespace dqm {
5
7 ecal_sim_hit_coll_ = ps.get<std::string>("ecal_sim_hit_coll");
8 ecal_sim_hit_pass_ = ps.get<std::string>("ecal_sim_hit_pass");
9 ecal_rec_hit_coll_ = ps.get<std::string>("ecal_rec_hit_coll");
10 ecal_rec_hit_pass_ = ps.get<std::string>("ecal_rec_hit_pass");
11 ecal_presel_coll_ = ps.get<std::string>("ecal_presel_coll");
12 ecal_presel_pass_ = ps.get<std::string>("ecal_presel_pass");
13 num_layers_ = ps.get<int>("num_layers");
14
15 return;
16}
17
19 // get truth information sorted into an ID based map
20 std::vector<ldmx::SimCalorimeterHit> ecal_sim_hits =
23
24 // sort sim hits by ID
25 std::sort(ecal_sim_hits.begin(), ecal_sim_hits.end(),
26 [](const ldmx::SimCalorimeterHit &lhs,
27 const ldmx::SimCalorimeterHit &rhs) {
28 return lhs.getID() < rhs.getID();
29 });
30
31 std::vector<ldmx::EcalHit> ecal_rec_hits = event.getCollection<ldmx::EcalHit>(
33
34 // sort rec hits by ID
35 std::sort(ecal_rec_hits.begin(), ecal_rec_hits.end(),
36 [](const ldmx::EcalHit &lhs, const ldmx::EcalHit &rhs) {
37 return lhs.getID() < rhs.getID();
38 });
39
40 int num_rec_hits{0};
41 int num_noise_hits{0};
42 double total_rec_energy{0.};
43 int num_mod_with_0hits{0};
44 int num_mod_with_1hits{0};
45 int num_mod_with_2hits{0};
46 int num_mod_with_more_than_2hits{0};
47 std::vector<int> my_costum_mod_ids;
48 // I need a set for the case when there are repeated elements
49 std::set<int> my_costum_mod_ids_set;
50
51 // Loop on the ecal rechits
52 for (const ldmx::EcalHit &rec_hit : ecal_rec_hits) {
53 num_rec_hits++;
54
55 // Building up an ID that has layer + module information
56 ldmx::EcalID ecal_id(rec_hit.getID());
57 int layer = ecal_id.layer() + 1;
58 int module_id = ecal_id.getModuleID() + 1;
59 int my_mod_costum_id = layer * 100 + module_id;
60
61 my_costum_mod_ids.push_back(my_mod_costum_id);
62 my_costum_mod_ids_set.insert(my_mod_costum_id);
63
64 // Measure the sum energy of all rechits (inc noise)
65 total_rec_energy += rec_hit.getEnergy();
66
67 // skip anything that digi flagged as noise
68 if (rec_hit.isNoise()) {
69 num_noise_hits++;
70 histograms_.fill("is_noise_hit", 1.);
71 continue;
72 } // end if noise
73 histograms_.fill("is_noise_hit", 0.);
74
75 int raw_id = rec_hit.getID();
76
77 // energy weighted sim hit positions
78 double sim_pos_x_weighted = 0.;
79 double sim_pos_y_weighted = 0.;
80 double sim_pos_z_weighted = 0.;
81
82 // get information for this hit
83 int num_sim_hits = 0;
84 double total_sim_energy_dep = 0.;
85 for (const ldmx::SimCalorimeterHit &sim_hit : ecal_sim_hits) {
86 if (raw_id == sim_hit.getID()) {
87 num_sim_hits += sim_hit.getNumberOfContribs();
88 total_sim_energy_dep += sim_hit.getEdep();
89 sim_pos_x_weighted += sim_hit.getPosition()[0] * sim_hit.getEdep();
90 sim_pos_y_weighted += sim_hit.getPosition()[1] * sim_hit.getEdep();
91 sim_pos_z_weighted += sim_hit.getPosition()[2] * sim_hit.getEdep();
92
93 } else if (raw_id < sim_hit.getID()) {
94 // later sim hits - all done
95 break;
96 }
97 } // end loop on sim hits
98
99 sim_pos_x_weighted /= total_sim_energy_dep;
100 sim_pos_y_weighted /= total_sim_energy_dep;
101 sim_pos_z_weighted /= total_sim_energy_dep;
102 auto residual_x = rec_hit.getXPos() - sim_pos_x_weighted;
103 auto residual_y = rec_hit.getYPos() - sim_pos_y_weighted;
104 auto residual_z = rec_hit.getZPos() - sim_pos_z_weighted;
105 histograms_.fill("rec_sim_hit_residual_x", residual_x);
106 histograms_.fill("rec_sim_hit_residual_y", residual_y);
107 histograms_.fill("rec_sim_hit_residual_z", residual_z);
108 histograms_.fill("rec_sim_hit_residual_x:layer", residual_x, layer);
109 histograms_.fill("rec_sim_hit_residual_y:layer", residual_y, layer);
110 histograms_.fill("rec_sim_hit_residual_z:layer", residual_z, layer);
111 histograms_.fill("num_sim_hits_per_cell", num_sim_hits);
112 histograms_.fill("sim_edep:rec_amplitude", total_sim_energy_dep,
113 rec_hit.getAmplitude());
114 histograms_.fill("sim_edep:rec_energy", total_sim_energy_dep,
115 rec_hit.getEnergy());
116 } // end loop on rec hits
117
118 std::map<int, int> module_hits;
119 for (const int &my_costum_mod_id : my_costum_mod_ids) {
120 module_hits[my_costum_mod_id]++;
121 }
122
123 // all modules is 34*7 = 238
124 // this would be nice if not hardcoded...
125 num_mod_with_0hits = num_layers_ * 7 - my_costum_mod_ids_set.size();
126
127 for (const auto &module_hit : module_hits) {
128 if (module_hit.second == 1) {
129 num_mod_with_1hits++;
130 } else if (module_hit.second == 2) {
131 num_mod_with_2hits++;
132 } else if (module_hit.second > 2) {
133 histograms_.fill("num_hit_if_more_than_2hits", module_hit.second);
134 num_mod_with_more_than_2hits++;
135 }
136 }
137
138 histograms_.fill("num_rec_hits", num_rec_hits);
139 histograms_.fill("num_noise_hits", num_noise_hits);
140 histograms_.fill("total_rec_energy", total_rec_energy);
141
142 histograms_.fill("num_mod_with_0hits", num_mod_with_0hits);
143 // only fill the histograms in the case there are hits, otherwise it goes to
144 // the other categories
145 if (num_mod_with_1hits > 0)
146 histograms_.fill("num_mod_with_1hits", num_mod_with_1hits);
147 if (num_mod_with_2hits > 0)
148 histograms_.fill("num_mod_with_2hits", num_mod_with_2hits);
149 if (num_mod_with_more_than_2hits > 0)
150 histograms_.fill("num_mod_with_more_than_2hits",
151 num_mod_with_more_than_2hits);
152
153 // Check if preselection decision exists and fill histogram
155 bool presel_passed =
156 event.getObject<bool>(ecal_presel_coll_, ecal_presel_pass_);
157 histograms_.fill("preselection_passed", presel_passed ? 1. : 0.);
158 }
159
160 if (total_rec_energy > 6000.) {
162 } else {
164 }
165
166 return;
167}
168
169} // namespace dqm
170
#define DECLARE_ANALYZER(CLASS)
Macro which allows the framework to construct an analyzer given its name during configuration.
Generate histograms to check digi pipeline performance.
std::string ecal_sim_hit_coll_
Collection Name for SimHits.
int num_layers_
Number of layers in the ECAL.
std::string ecal_sim_hit_pass_
Pass Name for SimHits.
virtual void analyze(const framework::Event &event)
Fills histograms.
std::string ecal_rec_hit_pass_
Pass Name for RecHits.
std::string ecal_presel_coll_
Collection Name for Preselection Decision.
std::string ecal_rec_hit_coll_
Collection Name for RecHits.
virtual void configure(framework::config::Parameters &ps)
Input python configuration parameters.
std::string ecal_presel_pass_
Pass Name for Preselection Decision.
HistogramPool histograms_
helper object for making and filling histograms
void setStorageHint(framework::StorageControl::Hint hint)
Mark the current event as having the given storage control hint from this module_.
Implements an event buffer system for storing event data.
Definition Event.h:42
bool exists(const std::string &name, const std::string &passName, bool unique=true) const
Check for the existence of an object or collection with the given name and pass name in the event.
Definition Event.cxx:92
void fill(const std::string &name, const T &val)
Fill a 1D histogram.
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 reconstructed hit information from the ECAL.
Definition EcalHit.h:19
Extension of DetectorID providing access to ECal layers and cell numbers in a hex grid.
Definition EcalID.h:20
int getModuleID() const
Get the value of the module field from the ID.
Definition EcalID.h:93
int layer() const
Get the value of the layer field from the ID.
Definition EcalID.h:99
Stores simulated calorimeter hit information.
constexpr StorageControl::Hint HINT_SHOULD_DROP
storage control hint alias for backwards compatibility
constexpr StorageControl::Hint HINT_SHOULD_KEEP
storage control hint alias for backwards compatibility