CMS 3D CMS Logo

EtlSimHitsValidation.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Validation/MtdValidation
4 // Class: EtlSimHitsValidation
5 //
14 #include <string>
15 
20 
23 
27 
29 
32 
33 struct MTDHit {
34  float energy;
35  float time;
36  float x;
37  float y;
38  float z;
39 };
40 
42 public:
43  explicit EtlSimHitsValidation(const edm::ParameterSet&);
44  ~EtlSimHitsValidation() override;
45 
46  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
47 
48 private:
49  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
50 
51  void analyze(const edm::Event&, const edm::EventSetup&) override;
52 
53  // ------------ member data ------------
54 
56 
57  const float hitMinEnergy_;
58 
60 
61  // --- histograms declaration
62 
63  MonitorElement* meNhits_[2];
64  MonitorElement* meNtrkPerCell_[2];
65 
66  MonitorElement* meHitEnergy_[2];
67  MonitorElement* meHitTime_[2];
68 
69  MonitorElement* meHitXlocal_[2];
70  MonitorElement* meHitYlocal_[2];
71  MonitorElement* meHitZlocal_[2];
72 
73  MonitorElement* meOccupancy_[2];
74 
75  MonitorElement* meHitX_[2];
76  MonitorElement* meHitY_[2];
77  MonitorElement* meHitZ_[2];
78  MonitorElement* meHitPhi_[2];
79  MonitorElement* meHitEta_[2];
80 
81  MonitorElement* meHitTvsE_[2];
82  MonitorElement* meHitEvsPhi_[2];
83  MonitorElement* meHitEvsEta_[2];
84  MonitorElement* meHitTvsPhi_[2];
85  MonitorElement* meHitTvsEta_[2];
86 };
87 
88 // ------------ constructor and destructor --------------
90  : folder_(iConfig.getParameter<std::string>("folder")),
91  hitMinEnergy_(iConfig.getParameter<double>("hitMinimumEnergy")) {
92  etlSimHitsToken_ = consumes<edm::PSimHitContainer>(iConfig.getParameter<edm::InputTag>("inputTag"));
93 }
94 
96 
97 // ------------ method called for each event ------------
99  using namespace edm;
100  using namespace geant_units::operators;
101 
102  edm::ESHandle<MTDGeometry> geometryHandle;
103  iSetup.get<MTDDigiGeometryRecord>().get(geometryHandle);
104  const MTDGeometry* geom = geometryHandle.product();
105 
106  auto etlSimHitsHandle = makeValid(iEvent.getHandle(etlSimHitsToken_));
107 
108  std::unordered_map<uint32_t, MTDHit> m_etlHits[2];
109  std::unordered_map<uint32_t, std::set<int> > m_etlTrkPerCell[2];
110 
111  // --- Loop over the BLT SIM hits
112  for (auto const& simHit : *etlSimHitsHandle) {
113  // --- Use only hits compatible with the in-time bunch-crossing
114  if (simHit.tof() < 0 || simHit.tof() > 25.)
115  continue;
116 
117  ETLDetId id = simHit.detUnitId();
118 
119  int idet = (id.zside() + 1) / 2;
120 
121  m_etlTrkPerCell[idet][id.rawId()].insert(simHit.trackId());
122 
123  auto simHitIt = m_etlHits[idet].emplace(id.rawId(), MTDHit()).first;
124 
125  // --- Accumulate the energy (in MeV) of SIM hits in the same detector cell
126  (simHitIt->second).energy += convertUnitsTo(0.001_MeV, simHit.energyLoss());
127 
128  // --- Get the time of the first SIM hit in the cell
129  if ((simHitIt->second).time == 0 || simHit.tof() < (simHitIt->second).time) {
130  (simHitIt->second).time = simHit.tof();
131 
132  auto hit_pos = simHit.entryPoint();
133  (simHitIt->second).x = hit_pos.x();
134  (simHitIt->second).y = hit_pos.y();
135  (simHitIt->second).z = hit_pos.z();
136  }
137 
138  } // simHit loop
139 
140  // ==============================================================================
141  // Histogram filling
142  // ==============================================================================
143 
144  for (int idet = 0; idet < 2; ++idet) {
145  meNhits_[idet]->Fill(m_etlHits[idet].size());
146 
147  for (auto const& hit : m_etlTrkPerCell[idet])
148  meNtrkPerCell_[idet]->Fill((hit.second).size());
149 
150  for (auto const& hit : m_etlHits[idet]) {
151  if ((hit.second).energy < hitMinEnergy_)
152  continue;
153 
154  // --- Get the SIM hit global position
155  ETLDetId detId(hit.first);
156 
157  DetId geoId = detId.geographicalId();
158  const MTDGeomDet* thedet = geom->idToDet(geoId);
159  if (thedet == nullptr)
160  throw cms::Exception("EtlSimHitsValidation") << "GeographicalID: " << std::hex << geoId.rawId() << " ("
161  << detId.rawId() << ") is invalid!" << std::dec << std::endl;
162 
163  Local3DPoint local_point(
164  convertMmToCm((hit.second).x), convertMmToCm((hit.second).y), convertMmToCm((hit.second).z));
165  const auto& global_point = thedet->toGlobal(local_point);
166 
167  // --- Fill the histograms
168 
169  meHitEnergy_[idet]->Fill((hit.second).energy);
170  meHitTime_[idet]->Fill((hit.second).time);
171 
172  meHitXlocal_[idet]->Fill((hit.second).x);
173  meHitYlocal_[idet]->Fill((hit.second).y);
174  meHitZlocal_[idet]->Fill((hit.second).z);
175 
176  meOccupancy_[idet]->Fill(global_point.x(), global_point.y());
177 
178  meHitX_[idet]->Fill(global_point.x());
179  meHitY_[idet]->Fill(global_point.y());
180  meHitZ_[idet]->Fill(global_point.z());
181  meHitPhi_[idet]->Fill(global_point.phi());
182  meHitEta_[idet]->Fill(global_point.eta());
183 
184  meHitTvsE_[idet]->Fill((hit.second).energy, (hit.second).time);
185  meHitEvsPhi_[idet]->Fill(global_point.phi(), (hit.second).energy);
186  meHitEvsEta_[idet]->Fill(global_point.eta(), (hit.second).energy);
187  meHitTvsPhi_[idet]->Fill(global_point.phi(), (hit.second).time);
188  meHitTvsEta_[idet]->Fill(global_point.eta(), (hit.second).time);
189 
190  } // hit loop
191 
192  } // idet loop
193 }
194 
195 // ------------ method for histogram booking ------------
197  edm::Run const& run,
198  edm::EventSetup const& iSetup) {
199  ibook.setCurrentFolder(folder_);
200 
201  // --- histograms booking
202 
203  meNhits_[1] = ibook.book1D("EtlNhitsZpos", "Number of ETL cells with SIM hits (+Z);N_{ETL cells}", 100, 0., 5000.);
204  meNhits_[0] = ibook.book1D("EtlNhitsZneg", "Number of ETL cells with SIM hits (-Z);N_{ETL cells}", 100, 0., 5000.);
205  meNtrkPerCell_[1] = ibook.book1D("EtlNtrkPerCellZpos", "Number of tracks per ETL sensor (+Z);N_{trk}", 10, 0., 10.);
206  meNtrkPerCell_[0] = ibook.book1D("EtlNtrkPerCellZneg", "Number of tracks per ETL sensor (-Z);N_{trk}", 10, 0., 10.);
207 
208  meHitEnergy_[1] = ibook.book1D("EtlHitEnergyZpos", "ETL SIM hits energy (+Z);E_{SIM} [MeV]", 100, 0., 3.);
209  meHitEnergy_[0] = ibook.book1D("EtlHitEnergyZneg", "ETL SIM hits energy (-Z);E_{SIM} [MeV]", 100, 0., 3.);
210  meHitTime_[1] = ibook.book1D("EtlHitTimeZpos", "ETL SIM hits ToA (+Z);ToA_{SIM} [ns]", 100, 0., 25.);
211  meHitTime_[0] = ibook.book1D("EtlHitTimeZneg", "ETL SIM hits ToA (-Z);ToA_{SIM} [ns]", 100, 0., 25.);
212 
213  meHitXlocal_[1] = ibook.book1D("EtlHitXlocalZpos", "ETL SIM local X (+Z);X_{SIM}^{LOC} [mm]", 100, -25., 25.);
214  meHitXlocal_[0] = ibook.book1D("EtlHitXlocalZneg", "ETL SIM local X (-Z);X_{SIM}^{LOC} [mm]", 100, -25., 25.);
215  meHitYlocal_[1] = ibook.book1D("EtlHitYlocalZpos", "ETL SIM local Y (+Z);Y_{SIM}^{LOC} [mm]", 100, -48., 48.);
216  meHitYlocal_[0] = ibook.book1D("EtlHitYlocalZneg", "ETL SIM local Y (-Z);Y_{SIM}^{LOC} [mm]", 100, -48., 48.);
217  meHitZlocal_[1] = ibook.book1D("EtlHitZlocalZpos", "ETL SIM local Z (+Z);Z_{SIM}^{LOC} [mm]", 80, -0.16, 0.16);
218  meHitZlocal_[0] = ibook.book1D("EtlHitZlocalZneg", "ETL SIM local Z (-Z);Z_{SIM}^{LOC} [mm]", 80, -0.16, 0.16);
219 
220  meOccupancy_[1] = ibook.book2D(
221  "EtlOccupancyZpos", "ETL SIM hits occupancy (+Z);X_{SIM} [cm];Y_{SIM} [cm]", 135, -135., 135., 135, -135., 135.);
222  meOccupancy_[0] = ibook.book2D(
223  "EtlOccupancyZneg", "ETL SIM hits occupancy (-Z);X_{SIM} [cm];Y_{SIM} [cm]", 135, -135., 135., 135, -135., 135.);
224 
225  meHitX_[1] = ibook.book1D("EtlHitXZpos", "ETL SIM hits X (+Z);X_{SIM} [cm]", 100, -130., 130.);
226  meHitX_[0] = ibook.book1D("EtlHitXZneg", "ETL SIM hits X (-Z);X_{SIM} [cm]", 100, -130., 130.);
227  meHitY_[1] = ibook.book1D("EtlHitYZpos", "ETL SIM hits Y (+Z);Y_{SIM} [cm]", 100, -130., 130.);
228  meHitY_[0] = ibook.book1D("EtlHitYZneg", "ETL SIM hits Y (-Z);Y_{SIM} [cm]", 100, -130., 130.);
229  meHitZ_[1] = ibook.book1D("EtlHitZZpos", "ETL SIM hits Z (+Z);Z_{SIM} [cm]", 100, 303.4, 304.2);
230  meHitZ_[0] = ibook.book1D("EtlHitZZneg", "ETL SIM hits Z (-Z);Z_{SIM} [cm]", 100, -304.2, -303.4);
231 
232  meHitPhi_[1] = ibook.book1D("EtlHitPhiZpos", "ETL SIM hits #phi (+Z);#phi_{SIM} [rad]", 100, -3.15, 3.15);
233  meHitPhi_[0] = ibook.book1D("EtlHitPhiZneg", "ETL SIM hits #phi (-Z);#phi_{SIM} [rad]", 100, -3.15, 3.15);
234  meHitEta_[1] = ibook.book1D("EtlHitEtaZpos", "ETL SIM hits #eta (+Z);#eta_{SIM}", 100, 1.56, 3.2);
235  meHitEta_[0] = ibook.book1D("EtlHitEtaZneg", "ETL SIM hits #eta (-Z);#eta_{SIM}", 100, -3.2, -1.56);
236 
237  meHitTvsE_[1] = ibook.bookProfile(
238  "EtlHitTvsEZpos", "ETL SIM time vs energy (+Z);E_{SIM} [MeV];T_{SIM} [ns]", 50, 0., 2., 0., 100.);
239  meHitTvsE_[0] = ibook.bookProfile(
240  "EtlHitTvsEZneg", "ETL SIM time vs energy (-Z);E_{SIM} [MeV];T_{SIM} [ns]", 50, 0., 2., 0., 100.);
241  meHitEvsPhi_[1] = ibook.bookProfile(
242  "EtlHitEvsPhiZpos", "ETL SIM energy vs #phi (+Z);#phi_{SIM} [rad];E_{SIM} [MeV]", 50, -3.15, 3.15, 0., 100.);
243  meHitEvsPhi_[0] = ibook.bookProfile(
244  "EtlHitEvsPhiZneg", "ETL SIM energy vs #phi (-Z);#phi_{SIM} [rad];E_{SIM} [MeV]", 50, -3.15, 3.15, 0., 100.);
245  meHitEvsEta_[1] = ibook.bookProfile(
246  "EtlHitEvsEtaZpos", "ETL SIM energy vs #eta (+Z);#eta_{SIM};E_{SIM} [MeV]", 50, 1.56, 3.2, 0., 100.);
247  meHitEvsEta_[0] = ibook.bookProfile(
248  "EtlHitEvsEtaZneg", "ETL SIM energy vs #eta (-Z);#eta_{SIM};E_{SIM} [MeV]", 50, -3.2, -1.56, 0., 100.);
249  meHitTvsPhi_[1] = ibook.bookProfile(
250  "EtlHitTvsPhiZpos", "ETL SIM time vs #phi (+Z);#phi_{SIM} [rad];T_{SIM} [ns]", 50, -3.15, 3.15, 0., 100.);
251  meHitTvsPhi_[0] = ibook.bookProfile(
252  "EtlHitTvsPhiZneg", "ETL SIM time vs #phi (-Z);#phi_{SIM} [rad];T_{SIM} [ns]", 50, -3.15, 3.15, 0., 100.);
253  meHitTvsEta_[1] = ibook.bookProfile(
254  "EtlHitTvsEtaZpos", "ETL SIM time vs #eta (+Z);#eta_{SIM};T_{SIM} [ns]", 50, 1.56, 3.2, 0., 100.);
255  meHitTvsEta_[0] = ibook.bookProfile(
256  "EtlHitTvsEtaZneg", "ETL SIM time vs #eta (-Z);#eta_{SIM};T_{SIM} [ns]", 50, -3.2, -1.56, 0., 100.);
257 }
258 
259 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
262 
263  desc.add<std::string>("folder", "MTD/ETL/SimHits");
264  desc.add<edm::InputTag>("inputTag", edm::InputTag("g4SimHits", "FastTimerHitsEndcap"));
265  desc.add<double>("hitMinimumEnergy", 0.1); // [MeV]
266 
267  descriptions.add("etlSimHits", desc);
268 }
269 
size
Write out results.
T getParameter(std::string const &) const
MonitorElement * meHitTime_[2]
MonitorElement * meHitXlocal_[2]
std::string folder_
constexpr NumType convertUnitsTo(long double desiredUnits, NumType val)
Definition: GeantUnits.h:128
MonitorElement * meHitTvsPhi_[2]
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:113
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
edm::EDGetTokenT< edm::PSimHitContainer > etlSimHitsToken_
MonitorElement * meNtrkPerCell_[2]
MonitorElement * meHitZ_[2]
MonitorElement * meHitEvsPhi_[2]
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
MonitorElement * meHitEnergy_[2]
MonitorElement * meHitZlocal_[2]
MonitorElement * meHitY_[2]
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
MonitorElement * meHitEta_[2]
void Fill(long long x)
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:539
const MTDGeomDet * idToDet(DetId) const override
Definition: MTDGeometry.cc:184
int iEvent
Definition: GenABIO.cc:224
EtlSimHitsValidation(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
ETLDetId geographicalId() const
Definition: ETLDetId.cc:4
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
MonitorElement * meHitYlocal_[2]
MonitorElement * meHitTvsEta_[2]
ParameterDescriptionBase * add(U const &iLabel, T const &value)
MonitorElement * meOccupancy_[2]
MonitorElement * meHitTvsE_[2]
Definition: DetId.h:18
MonitorElement * meHitX_[2]
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
void analyze(const edm::Event &, const edm::EventSetup &) override
example_stream void bookHistograms(DQMStore::IBooker &,@example_stream edm::Run const &,@example_stream edm::EventSetup const &) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
MonitorElement * meHitPhi_[2]
MonitorElement * meHitEvsEta_[2]
MonitorElement * meNhits_[2]
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Detector identifier class for the Endcap Timing Layer.
Definition: ETLDetId.h:15
HLT enums.
T get() const
Definition: EventSetup.h:71
constexpr NumType convertMmToCm(NumType millimeters)
Definition: GeantUnits.h:110
auto makeValid(const U &iOtherHandleType) noexcept(false)
Definition: ValidHandle.h:59
const std::string folder_
T const * product() const
Definition: ESHandle.h:86
Definition: Run.h:45