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 num_layers_ = ps.get<int>("num_layers");
12
13 return;
14}
15
17 // get truth information sorted into an ID based map
18 std::vector<ldmx::SimCalorimeterHit> ecal_sim_hits =
21
22 // sort sim hits by ID
23 std::sort(ecal_sim_hits.begin(), ecal_sim_hits.end(),
24 [](const ldmx::SimCalorimeterHit &lhs,
25 const ldmx::SimCalorimeterHit &rhs) {
26 return lhs.getID() < rhs.getID();
27 });
28
29 std::vector<ldmx::EcalHit> ecal_rec_hits = event.getCollection<ldmx::EcalHit>(
31
32 // sort rec hits by ID
33 std::sort(ecal_rec_hits.begin(), ecal_rec_hits.end(),
34 [](const ldmx::EcalHit &lhs, const ldmx::EcalHit &rhs) {
35 return lhs.getID() < rhs.getID();
36 });
37
38 int num_rec_hits{0};
39 int num_noise_hits{0};
40 double total_rec_energy{0.};
41 int num_mod_with_0hits{0};
42 int num_mod_with_1hits{0};
43 int num_mod_with_2hits{0};
44 int num_mod_with_more_than_2hits{0};
45 std::vector<int> my_costum_mod_ids;
46 // I need a set for the case when there are repeated elements
47 std::set<int> my_costum_mod_ids_set;
48
49 // Loop on the ecal rechits
50 for (const ldmx::EcalHit &rec_hit : ecal_rec_hits) {
51 num_rec_hits++;
52
53 // Building up an ID that has layer + module information
54 ldmx::EcalID ecal_id(rec_hit.getID());
55 int layer = ecal_id.layer() + 1;
56 int module_id = ecal_id.getModuleID() + 1;
57 int my_mod_costum_id = layer * 100 + module_id;
58
59 my_costum_mod_ids.push_back(my_mod_costum_id);
60 my_costum_mod_ids_set.insert(my_mod_costum_id);
61
62 // Measure the sum energy of all rechits (inc noise)
63 total_rec_energy += rec_hit.getEnergy();
64
65 // skip anything that digi flagged as noise
66 if (rec_hit.isNoise()) {
67 num_noise_hits++;
68 histograms_.fill("is_noise_hit", 1.);
69 continue;
70 } // end if noise
71 histograms_.fill("is_noise_hit", 0.);
72
73 int raw_id = rec_hit.getID();
74
75 // energy weighted sim hit positions
76 double sim_pos_x_weighted = 0.;
77 double sim_pos_y_weighted = 0.;
78 double sim_pos_z_weighted = 0.;
79
80 // get information for this hit
81 int num_sim_hits = 0;
82 double total_sim_energy_dep = 0.;
83 for (const ldmx::SimCalorimeterHit &sim_hit : ecal_sim_hits) {
84 if (raw_id == sim_hit.getID()) {
85 num_sim_hits += sim_hit.getNumberOfContribs();
86 total_sim_energy_dep += sim_hit.getEdep();
87 sim_pos_x_weighted += sim_hit.getPosition()[0] * sim_hit.getEdep();
88 sim_pos_y_weighted += sim_hit.getPosition()[1] * sim_hit.getEdep();
89 sim_pos_z_weighted += sim_hit.getPosition()[2] * sim_hit.getEdep();
90
91 } else if (raw_id < sim_hit.getID()) {
92 // later sim hits - all done
93 break;
94 }
95 } // end loop on sim hits
96
97 sim_pos_x_weighted /= total_sim_energy_dep;
98 sim_pos_y_weighted /= total_sim_energy_dep;
99 sim_pos_z_weighted /= total_sim_energy_dep;
100 auto residual_x = rec_hit.getXPos() - sim_pos_x_weighted;
101 auto residual_y = rec_hit.getYPos() - sim_pos_y_weighted;
102 auto residual_z = rec_hit.getZPos() - sim_pos_z_weighted;
103 histograms_.fill("rec_sim_hit_residual_x", residual_x);
104 histograms_.fill("rec_sim_hit_residual_y", residual_y);
105 histograms_.fill("rec_sim_hit_residual_z", residual_z);
106 histograms_.fill("rec_sim_hit_residual_x:layer", residual_x, layer);
107 histograms_.fill("rec_sim_hit_residual_y:layer", residual_y, layer);
108 histograms_.fill("rec_sim_hit_residual_z:layer", residual_z, layer);
109 histograms_.fill("num_sim_hits_per_cell", num_sim_hits);
110 histograms_.fill("sim_edep:rec_amplitude", total_sim_energy_dep,
111 rec_hit.getAmplitude());
112 histograms_.fill("sim_edep:rec_energy", total_sim_energy_dep,
113 rec_hit.getEnergy());
114 } // end loop on rec hits
115
116 std::map<int, int> module_hits;
117 for (const int &my_costum_mod_id : my_costum_mod_ids) {
118 module_hits[my_costum_mod_id]++;
119 }
120
121 // all modules is 34*7 = 238
122 // this would be nice if not hardcoded...
123 num_mod_with_0hits = num_layers_ * 7 - my_costum_mod_ids_set.size();
124
125 for (const auto &module_hit : module_hits) {
126 if (module_hit.second == 1) {
127 num_mod_with_1hits++;
128 } else if (module_hit.second == 2) {
129 num_mod_with_2hits++;
130 } else if (module_hit.second > 2) {
131 histograms_.fill("num_hit_if_more_than_2hits", module_hit.second);
132 num_mod_with_more_than_2hits++;
133 }
134 }
135
136 histograms_.fill("num_rec_hits", num_rec_hits);
137 histograms_.fill("num_noise_hits", num_noise_hits);
138 histograms_.fill("total_rec_energy", total_rec_energy);
139
140 histograms_.fill("num_mod_with_0hits", num_mod_with_0hits);
141 // only fill the histograms in the case there are hits, otherwise it goes to
142 // the other categories
143 if (num_mod_with_1hits > 0)
144 histograms_.fill("num_mod_with_1hits", num_mod_with_1hits);
145 if (num_mod_with_2hits > 0)
146 histograms_.fill("num_mod_with_2hits", num_mod_with_2hits);
147 if (num_mod_with_more_than_2hits > 0)
148 histograms_.fill("num_mod_with_more_than_2hits",
149 num_mod_with_more_than_2hits);
150
151 if (total_rec_energy > 6000.) {
153 } else {
155 }
156
157 return;
158}
159
160} // namespace dqm
161
#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_rec_hit_coll_
Collection Name for RecHits.
virtual void configure(framework::config::Parameters &ps)
Input python configuration parameters.
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
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