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