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 ecalSimHitColl_ = ps.getParameter<std::string>("ecalSimHitColl");
12 ecalSimHitPass_ = ps.getParameter<std::string>("ecalSimHitPass");
13 ecalRecHitColl_ = ps.getParameter<std::string>("ecalRecHitColl");
14 ecalRecHitPass_ = ps.getParameter<std::string>("ecalRecHitPass");
15
16 return;
17}
18
20 // get truth information sorted into an ID based map
21 std::vector<ldmx::SimCalorimeterHit> ecalSimHits =
22 event.getCollection<ldmx::SimCalorimeterHit>(ecalSimHitColl_,
24
25 // sort sim hits by ID
26 std::sort(ecalSimHits.begin(), ecalSimHits.end(),
27 [](const ldmx::SimCalorimeterHit &lhs,
28 const ldmx::SimCalorimeterHit &rhs) {
29 return lhs.getID() < rhs.getID();
30 });
31
32 std::vector<ldmx::EcalHit> ecalRecHits =
33 event.getCollection<ldmx::EcalHit>(ecalRecHitColl_, ecalRecHitPass_);
34
35 // sort rec hits by ID
36 std::sort(ecalRecHits.begin(), ecalRecHits.end(),
37 [](const ldmx::EcalHit &lhs, const ldmx::EcalHit &rhs) {
38 return lhs.getID() < rhs.getID();
39 });
40
41 int numRecHits{0};
42 int numNoiseHits{0};
43 double totalRecEnergy{0.};
44 int numModWith0Hits{0};
45 int numModWith1Hits{0};
46 int numModWith2Hits{0};
47 int numModWithMoreThan2Hits{0};
48 std::vector<int> myCostumModIDs;
49 // I need a set for the case when there are repeated elements
50 std::set<int> myCostumModIDsSet;
51
52 // Loop on the ecal rechits
53 for (const ldmx::EcalHit &recHit : ecalRecHits) {
54 numRecHits++;
55
56 // Building up an ID that has layer + module information
57 ldmx::EcalID ecal_id(recHit.getID());
58 int layer = ecal_id.layer() + 1;
59 int moduleID = ecal_id.getModuleID() + 1;
60 int myModConstumID = layer * 100 + moduleID;
61
62 myCostumModIDs.push_back(myModConstumID);
63 myCostumModIDsSet.insert(myModConstumID);
64
65 // Measure the sum energy of all rechits (inc noise)
66 totalRecEnergy += recHit.getEnergy();
67
68 // skip anything that digi flagged as noise
69 if (recHit.isNoise()) {
70 numNoiseHits++;
71 histograms_.fill("is_noise_hit", 1.);
72 continue;
73 }
74 histograms_.fill("is_noise_hit", 0.);
75
76 int rawID = recHit.getID();
77
78 // get information for this hit
79 int numSimHits = 0;
80 double totalSimEDep = 0.;
81 for (const ldmx::SimCalorimeterHit &simHit : ecalSimHits) {
82 if (rawID == simHit.getID()) {
83 numSimHits += simHit.getNumberOfContribs();
84 totalSimEDep += simHit.getEdep();
85 auto residualX = recHit.getXPos() - simHit.getPosition()[0];
86 auto residualY = recHit.getYPos() - simHit.getPosition()[1];
87 auto residualZ = recHit.getZPos() - simHit.getPosition()[2];
88 histograms_.fill("rec_sim_hit_residual_x", residualX);
89 histograms_.fill("rec_sim_hit_residual_y", residualY);
90 histograms_.fill("rec_sim_hit_residual_z", residualZ);
91 } else if (rawID < simHit.getID()) {
92 // later sim hits - all done
93 break;
94 }
95 }
96
97 histograms_.fill("num_sim_hits_per_cell", numSimHits);
98 histograms_.fill("sim_edep__rec_amplitude", totalSimEDep,
99 recHit.getAmplitude());
100 }
101
102 std::map<int, int> moduleHits;
103 for (const int &myCostumModID : myCostumModIDs) {
104 moduleHits[myCostumModID]++;
105 }
106
107 // all modules is 34*7 = 238
108 // this would be nice if not hardcoded...
109 numModWith0Hits = 34 * 7 - myCostumModIDsSet.size();
110
111 for (const auto &moduleHit : moduleHits) {
112 if (moduleHit.second == 1) {
113 numModWith1Hits++;
114 } else if (moduleHit.second == 2) {
115 numModWith2Hits++;
116 } else if (moduleHit.second > 2) {
117 histograms_.fill("num_hit_if_more_than_2hits", moduleHit.second);
118 numModWithMoreThan2Hits++;
119 }
120 }
121
122 histograms_.fill("num_rec_hits", numRecHits);
123 histograms_.fill("num_noise_hits", numNoiseHits);
124 histograms_.fill("total_rec_energy", totalRecEnergy);
125
126 histograms_.fill("num_mod_with_0hits", numModWith0Hits);
127 // only fill the histograms in the case there are hits, otherwise it goes to
128 // the other categories
129 if (numModWith1Hits > 0)
130 histograms_.fill("num_mod_with_1hits", numModWith1Hits);
131 if (numModWith2Hits > 0)
132 histograms_.fill("num_mod_with_2hits", numModWith2Hits);
133 if (numModWithMoreThan2Hits > 0)
134 histograms_.fill("num_mod_with_more_than_2hits", numModWithMoreThan2Hits);
135
136 if (totalRecEnergy > 6000.) {
138 } else {
140 }
141
142 return;
143}
144
145} // namespace dqm
146
147DECLARE_ANALYZER_NS(dqm, EcalDigiVerifier);
Class that defines an ECal detector ID with a cell number.
#define DECLARE_ANALYZER_NS(NS, CLASS)
Macro which allows the framework to construct an analyzer given its name during configuration.
Class which stores simulated calorimeter hit information.
std::string ecalSimHitPass_
Pass Name for SimHits.
std::string ecalRecHitColl_
Collection Name for RecHits.
virtual void analyze(const framework::Event &event)
Fills histograms.
std::string ecalSimHitColl_
Collection Name for SimHits.
virtual void configure(framework::config::Parameters &ps)
Input python configuration parameters.
std::string ecalRecHitPass_
Pass Name for RecHits.
HistogramHelper histograms_
Interface class 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 double &val)
Fill a 1D histogram.
Definition Histograms.h:166
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
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_shouldKeep
storage control hint alias for backwards compatibility
constexpr StorageControl::Hint hint_shouldDrop
storage control hint alias for backwards compatibility