CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GEMSimHitValidation.cc
Go to the documentation of this file.
4 
6  : GEMBaseValidation(pset, "GEMSimHitValidation") {
7  const auto& simhit_pset = pset.getParameterSet("gemSimHit");
8  const auto& simhit_tag = simhit_pset.getParameter<edm::InputTag>("inputTag");
9  simhit_token_ = consumes<edm::PSimHitContainer>(simhit_tag);
10 
11  tof_range_ = pset.getUntrackedParameter<std::vector<Double_t> >("TOFRange");
12  geomToken_ = esConsumes<GEMGeometry, MuonGeometryRecord>();
13  geomTokenBeginRun_ = esConsumes<GEMGeometry, MuonGeometryRecord, edm::Transition::BeginRun>();
14 }
15 
17 
19  const GEMGeometry* gem = &setup.getData(geomTokenBeginRun_);
20 
21  // NOTE Time of flight
22  booker.setCurrentFolder("GEM/SimHits");
23 
24  TString tof_xtitle = "Time of flight [ns]";
25  TString tof_ytitle = "Entries";
26 
27  for (const auto& region : gem->regions()) {
28  Int_t region_id = region->region();
29 
30  for (const auto& station : region->stations()) {
31  Int_t station_id = station->station();
32 
33  const auto [tof_min, tof_max] = getTOFRange(station_id);
34  ME2IdsKey key2{region_id, station_id};
35 
36  me_tof_mu_[key2] = bookHist1D(
37  booker, key2, "sim_tof_muon", "SimHit TOF (Muon only)", 20, tof_min, tof_max, tof_xtitle, tof_ytitle);
38 
39  me_tof_others_[key2] = bookHist1D(
40  booker, key2, "sim_tof_others", "SimHit TOF (Other Particles)", 20, tof_min, tof_max, tof_xtitle, tof_ytitle);
41  } // station loop
42  } // region loop
43 
44  if (detail_plot_) {
45  for (const auto& region : gem->regions()) {
46  Int_t region_id = region->region();
47 
48  for (const auto& station : region->stations()) {
49  Int_t station_id = station->station();
50 
51  const auto [tof_min, tof_max] = getTOFRange(station_id);
52  const auto& superChamberVec = station->superChambers();
53  if (superChamberVec.empty() || superChamberVec.front() == nullptr) {
54  edm::LogError(kLogCategory_) << "Super chambers missing or null for region = " << region_id
55  << " and station = " << station_id;
56  } else {
57  const GEMSuperChamber* super_chamber = superChamberVec.front();
58 
59  for (const auto& chamber : super_chamber->chambers()) {
60  Int_t layer_id = chamber->id().layer();
61  ME3IdsKey key3{region_id, station_id, layer_id};
62 
63  me_detail_tof_[key3] = bookHist1D(
64  booker, key3, "sim_tof", "Time of Flight of Muon SimHits", 40, tof_min, tof_max, tof_xtitle, tof_ytitle);
65 
67  booker, key3, "sim_tof_muon", "SimHit TOF (Muon only)", 40, tof_min, tof_max, tof_xtitle, tof_ytitle);
68  } // chamber loop
69  } // end else
70  } // station loop
71  } // region loop
72  } // detail plot
73 
74  // NOTE Energy Loss
75  TString eloss_xtitle = "Energy loss [eV]";
76  TString eloss_ytitle = "Entries / 0.5 keV";
77 
78  for (const auto& station : gem->regions()[0]->stations()) {
79  Int_t station_id = station->station();
80 
81  auto eloss_mu_name = TString::Format("sim_eloss_muon_GE%d1", station_id);
82  auto eloss_mu_title = TString::Format("SimHit Energy Loss (Muon only) : GE%d1", station_id);
83 
84  me_eloss_mu_[station_id] =
85  booker.book1D(eloss_mu_name, eloss_mu_title + ";" + eloss_xtitle + ";" + eloss_ytitle, 20, 0.0, 10.0);
86 
87  auto eloss_others_name = TString::Format("sim_eloss_others_GE%d1", station_id);
88  auto eloss_others_title = TString::Format("SimHit Energy Loss (Other Particles) : GE%d1", station_id);
89 
90  me_eloss_others_[station_id] =
91  booker.book1D(eloss_others_name, eloss_others_title + ";" + eloss_xtitle + ";" + eloss_ytitle, 20, 0.0, 10.0);
92  } // station loop
93 
94  if (detail_plot_) {
95  for (const auto& region : gem->regions()) {
96  Int_t region_id = region->region();
97  for (const auto& station : region->stations()) {
98  Int_t station_id = station->station();
99  const auto& superChamberVec = station->superChambers();
100  if (superChamberVec.empty() || superChamberVec.front() == nullptr) {
101  edm::LogError(kLogCategory_) << "Super chambers missing or null for region = " << region_id
102  << " and station = " << station_id;
103  } else {
104  for (const auto& chamber : superChamberVec.front()->chambers()) {
105  Int_t layer_id = chamber->id().layer();
106  ME3IdsKey key3{region_id, station_id, layer_id};
107 
109  booker, key3, "sim_eloss", "SimHit Energy Loss", 60, 0.0, 6000.0, eloss_xtitle, eloss_ytitle);
110 
111  me_detail_eloss_mu_[key3] = bookHist1D(booker,
112  key3,
113  "sim_eloss_muon",
114  "SimHit Energy Loss (Muon Only)",
115  60,
116  0.0,
117  6000.0,
118  eloss_xtitle,
119  eloss_ytitle);
120 
121  } // chamber loop
122  } // end else
123  } // station loop
124  } // region loop
125  } // detail plot
126 
127  // NOTE Occupancy
128  for (const auto& region : gem->regions()) {
129  Int_t region_id = region->region();
130 
131  if (detail_plot_)
132  me_detail_occ_zr_[region_id] = bookZROccupancy(booker, region_id, "sim_simhit", "SimHit");
133 
134  for (const auto& station : region->stations()) {
135  Int_t station_id = station->station();
136  ME2IdsKey key2{region_id, station_id};
137 
138  if (detail_plot_) {
139  me_detail_occ_det_[key2] = bookDetectorOccupancy(booker, key2, station, "sim_simhit", "SimHit");
140  me_detail_occ_det_mu_[key2] = bookDetectorOccupancy(booker, key2, station, "sim_muon_simhit", "Muon SimHit");
141  }
142 
143  const auto& superChamberVec = station->superChambers();
144  if (superChamberVec.empty() || superChamberVec.front() == nullptr) {
145  edm::LogError(kLogCategory_) << "Super chambers missing or null for region = " << region_id
146  << " and station = " << station_id;
147  } else {
148  const GEMSuperChamber* super_chamber = superChamberVec.front();
149  for (const auto& chamber : super_chamber->chambers()) {
150  Int_t layer_id = chamber->id().layer();
151  ME3IdsKey key3{region_id, station_id, layer_id};
152 
153  me_occ_eta_mu_[key3] = bookHist1D(booker,
154  key3,
155  "sim_muon_occ_eta",
156  "Muon SimHit Eta Occupancy",
157  16,
158  eta_range_[station_id * 2 + 0],
159  eta_range_[station_id * 2 + 1],
160  "#eta");
161 
162  me_occ_phi_mu_[key3] =
163  bookHist1D(booker, key3, "sim_muon_occ_phi", "Muon SimHit Phi Occupancy", 36, -5, 355, "#phi [degrees]");
164 
165  me_occ_pid_[key3] = bookPIDHist(booker, key3, "sim_occ_pid", "Particle population");
166 
167  if (detail_plot_)
168  me_detail_occ_xy_[key3] = bookXYOccupancy(booker, key3, "sim_simhit", "SimHit");
169  } // layer loop
170  } // end else
171  } // station loop
172  } // region loop
173 }
174 
175 std::tuple<Double_t, Double_t> GEMSimHitValidation::getTOFRange(Int_t station_id) {
176  UInt_t start_index = station_id * 2;
177  Double_t tof_min = tof_range_[start_index];
178  Double_t tof_max = tof_range_[start_index + 1];
179  return std::make_tuple(tof_min, tof_max);
180 }
181 
183  const GEMGeometry* gem = &setup.getData(geomToken_);
184 
185  edm::Handle<edm::PSimHitContainer> simhit_container;
186  event.getByToken(simhit_token_, simhit_container);
187  if (not simhit_container.isValid()) {
188  edm::LogError(kLogCategory_) << "Cannot get GEMHits by Token simhitLabel" << std::endl;
189  return;
190  }
191 
192  for (const auto& simhit : *simhit_container.product()) {
193  const GEMDetId gemid(simhit.detUnitId());
194 
195  if (gem->idToDet(gemid) == nullptr) {
196  edm::LogError(kLogCategory_) << "SimHit did not matched with GEM Geometry." << std::endl;
197  continue;
198  }
199 
200  Int_t region_id = gemid.region();
201  Int_t station_id = gemid.station();
202  Int_t layer_id = gemid.layer();
203  Int_t chamber_id = gemid.chamber();
204  Int_t ieta = gemid.ieta();
205  Int_t num_layers = gemid.nlayers();
206 
207  ME2IdsKey key2{region_id, station_id};
208  ME3IdsKey key3{region_id, station_id, layer_id};
209 
210  GlobalPoint&& simhit_global_pos = gem->idToDet(gemid)->surface().toGlobal(simhit.localPosition());
211 
212  Float_t simhit_g_r = simhit_global_pos.perp();
213  Float_t simhit_g_x = simhit_global_pos.x();
214  Float_t simhit_g_y = simhit_global_pos.y();
215  Float_t simhit_g_abs_z = std::fabs(simhit_global_pos.z());
216  Float_t simhit_g_eta = std::fabs(simhit_global_pos.eta());
217  Float_t simhit_g_phi = toDegree(simhit_global_pos.phi());
218 
219  Float_t energy_loss = kEnergyCF_ * simhit.energyLoss();
220  energy_loss = energy_loss > 10 ? 9.9 : energy_loss;
221  Float_t tof = simhit.timeOfFlight();
222  Int_t pid = simhit.particleType();
223  Int_t pid_idx = getPidIdx(pid);
224 
225  // NOTE Fill MonitorElement
226  Int_t bin_x = getDetOccBinX(num_layers, chamber_id, layer_id);
227 
228  bool is_muon_simhit = isMuonSimHit(simhit);
229  if (is_muon_simhit) {
230  me_tof_mu_[key2]->Fill(tof);
231  me_eloss_mu_[station_id]->Fill(energy_loss);
232  me_occ_eta_mu_[key3]->Fill(simhit_g_eta);
233  me_occ_phi_mu_[key3]->Fill(simhit_g_phi);
234  } else {
235  me_tof_others_[key2]->Fill(tof);
236  me_eloss_others_[station_id]->Fill(energy_loss);
237  }
238 
239  me_occ_pid_[key3]->Fill(pid_idx);
240 
241  if (detail_plot_) {
242  me_detail_tof_[key3]->Fill(tof);
243  me_detail_eloss_[key3]->Fill(energy_loss);
244 
245  me_detail_occ_zr_[region_id]->Fill(simhit_g_abs_z, simhit_g_r);
246  me_detail_occ_det_[key2]->Fill(bin_x, ieta);
247  me_detail_occ_xy_[key3]->Fill(simhit_g_x, simhit_g_y);
248 
249  if (is_muon_simhit) {
250  me_detail_tof_mu_[key3]->Fill(tof);
251  me_detail_eloss_mu_[key3]->Fill(energy_loss);
252  me_detail_occ_det_mu_[key2]->Fill(bin_x, ieta);
253  }
254 
255  } // detail_plot
256  } // simhit loop
257 }
dqm::impl::MonitorElement * bookHist1D(DQMStore::IBooker &booker, const T &key, const char *name, const char *title, Int_t nbinsx, Double_t xlow, Double_t xup, const char *x_title="", const char *y_title="Entries")
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
T getUntrackedParameter(std::string const &, T const &) const
T perp() const
Definition: PV3DBase.h:69
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
GEMSimHitValidation(const edm::ParameterSet &)
Bool_t isMuonSimHit(const PSimHit &)
const GeomDet * idToDet(DetId) const override
Definition: GEMGeometry.cc:25
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
T y() const
Definition: PV3DBase.h:60
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > geomToken_
Log< level::Error, false > LogError
dqm::impl::MonitorElement * bookZROccupancy(DQMStore::IBooker &booker, Int_t region_id, const char *name_prfix, const char *title_prefix)
edm::EDGetTokenT< edm::PSimHitContainer > simhit_token_
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
bool getData(T &iHolder) const
Definition: EventSetup.h:128
dqm::impl::MonitorElement * bookXYOccupancy(DQMStore::IBooker &booker, const T &key, const char *name_prefix, const char *title_prefix)
std::vector< Double_t > tof_range_
const std::vector< const GEMRegion * > & regions() const
Return a vector of all GEM regions.
Definition: GEMGeometry.cc:30
T z() const
Definition: PV3DBase.h:61
Int_t getPidIdx(Int_t pid)
std::vector< Double_t > eta_range_
bool isValid() const
Definition: HandleBase.h:70
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > geomTokenBeginRun_
std::tuple< Double_t, Double_t > getTOFRange(Int_t station_id)
T const * product() const
Definition: Handle.h:70
ParameterSet const & getParameterSet(std::string const &) const
constexpr int layer() const
Definition: GEMDetId.h:190
GEMDetId id() const
Return the GEMDetId of this super chamber.
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
T eta() const
Definition: PV3DBase.h:73
const std::vector< const GEMChamber * > & chambers() const
Return the chambers in the super chamber.
std::tuple< Int_t, Int_t > ME2IdsKey
Float_t toDegree(Float_t radian)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::tuple< Int_t, Int_t, Int_t > ME3IdsKey
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
Int_t getDetOccBinX(Int_t num_layers, Int_t chamber_id, Int_t layer_id)
void analyze(const edm::Event &, const edm::EventSetup &) override
T x() const
Definition: PV3DBase.h:59
dqm::impl::MonitorElement * bookPIDHist(DQMStore::IBooker &booker, const T &key, const char *name, const char *title)
const std::string kLogCategory_
Definition: Run.h:45
dqm::impl::MonitorElement * bookDetectorOccupancy(DQMStore::IBooker &booker, const T &key, const GEMStation *station, const char *name_prfix, const char *title_prefix)