CMS 3D CMS Logo

GEMPadDigiValidation.cc
Go to the documentation of this file.
2 
4  : GEMBaseValidation(pset, "GEMPadDigiValidation") {
5  const auto& pad_pset = pset.getParameterSet("gemPadDigi");
6  const auto& pad_tag = pad_pset.getParameter<edm::InputTag>("inputTag");
7  pad_token_ = consumes<GEMPadDigiCollection>(pad_tag);
8 
9  const auto& simhit_pset = pset.getParameterSet("gemSimHit");
10  const auto& simhit_tag = simhit_pset.getParameter<edm::InputTag>("inputTag");
11  simhit_token_ = consumes<edm::PSimHitContainer>(simhit_tag);
12 
13  const auto& digisimlink_tag = pset.getParameter<edm::InputTag>("gemDigiSimLink");
14  digisimlink_token_ = consumes<edm::DetSetVector<GEMDigiSimLink>>(digisimlink_tag);
15 
16  geomToken_ = esConsumes<GEMGeometry, MuonGeometryRecord>();
17  geomTokenBeginRun_ = esConsumes<GEMGeometry, MuonGeometryRecord, edm::Transition::BeginRun>();
18 }
19 
21  edm::Run const& Run,
22  edm::EventSetup const& setup) {
23  const auto gemH = setup.getHandle(geomTokenBeginRun_);
24  if (!gemH.isValid()) {
25  edm::LogError(kLogCategory_) << "Failed to initialize GEM geometry.";
26  return;
27  }
28  const GEMGeometry* gem = gemH.product();
29 
30  // NOTE Occupancy
31  booker.setCurrentFolder("GEM/Pad");
32 
33  for (const auto& region : gem->regions()) {
34  Int_t region_id = region->region();
35 
36  if (detail_plot_)
37  me_detail_occ_zr_[region_id] = bookZROccupancy(booker, region_id, "pad", "Pad");
38 
39  for (const auto& station : region->stations()) {
40  Int_t station_id = station->station();
41  ME2IdsKey key2(region_id, station_id);
42 
43  if (detail_plot_) {
44  me_detail_occ_det_[key2] = bookDetectorOccupancy(booker, key2, station, "pad", "Pad");
45  me_detail_pad_occ_det_[key2] = bookDetectorOccupancy(booker, key2, station, "sim_matched", "Matched Pad");
46  }
47 
48  const auto& superChamberVec = station->superChambers();
49  if (superChamberVec.empty()) {
50  edm::LogError(kLogCategory_) << "Super chambers missing for region = " << region_id
51  << " and station = " << station_id;
52  continue;
53  }
54  const GEMSuperChamber* super_chamber = superChamberVec.front();
55  if (super_chamber == nullptr) {
56  edm::LogError(kLogCategory_) << "Failed to find super chamber for region = " << region_id
57  << " and station = " << station_id;
58  continue;
59  }
60  for (const auto& chamber : super_chamber->chambers()) {
61  Int_t layer_id = chamber->id().layer();
62  ME3IdsKey key3(region_id, station_id, layer_id);
63 
64  const auto& etaPartitionVec = chamber->etaPartitions();
65  if (etaPartitionVec.empty() || etaPartitionVec.front() == nullptr) {
67  << "Eta partition missing or null for region, station, super chamber, chamber = (" << region_id << ", "
68  << station_id << ", " << super_chamber->id() << ", " << chamber->id() << ")";
69  continue;
70  }
71  Int_t num_pads = etaPartitionVec.front()->npads();
72 
73  me_occ_total_pad_[key3] =
74  bookHist1D(booker, key3, "total_pads_per_event", "Number of pad digis per event", 50, 0, 50);
75 
76  me_pad_occ_eta_[key3] = bookHist1D(booker,
77  key3,
78  "sim_matched_occ_eta",
79  "Matched Pad Eta Occupancy",
80  16,
81  eta_range_[station_id * 2 + 0],
82  eta_range_[station_id * 2 + 1],
83  "#eta");
84 
85  me_pad_occ_phi_[key3] =
86  bookHist1D(booker, key3, "sim_matched_occ_phi", "Matched Pad Phi Occupancy", 36, -5, 355, "#phi [degrees]");
87 
88  if (detail_plot_) {
89  me_detail_occ_xy_[key3] = bookXYOccupancy(booker, key3, "pad", "Pad");
90 
91  me_detail_occ_phi_pad_[key3] = bookHist2D(booker,
92  key3,
93  "occ_phi_pad",
94  "Pad Occupancy",
95  280,
96  -M_PI,
97  M_PI,
98  num_pads / 2,
99  0,
100  num_pads,
101  "#phi [rad]",
102  "Pad number");
103 
104  me_detail_occ_pad_[key3] =
105  bookHist1D(booker, key3, "occ_pad", "Pad Occupancy", num_pads, 0, num_pads, "Pad number");
106  }
107  } // layer loop
108  } // station loop
109  } // region loop
110 
111  // NOTE Bunch Crossing
112  if (detail_plot_) {
113  for (const auto& region : gem->regions()) {
114  Int_t region_id = region->region();
115  for (const auto& station : region->stations()) {
116  Int_t station_id = station->station();
117 
118  const auto& superChamberVec = station->superChambers();
119  if (superChamberVec.empty()) {
120  edm::LogError(kLogCategory_) << "Super chambers missing for region = " << region_id
121  << " and station = " << station_id;
122  continue;
123  }
124  const GEMSuperChamber* super_chamber = superChamberVec.front();
125  if (super_chamber == nullptr) {
126  edm::LogError(kLogCategory_) << "Failed to find super chamber for region = " << region_id
127  << " and station = " << station_id;
128  continue;
129  }
130  for (const auto& chamber : super_chamber->chambers()) {
131  Int_t layer_id = chamber->id().layer();
132  ME3IdsKey key3(region_id, station_id, layer_id);
133 
134  me_detail_bx_[key3] = bookHist1D(booker, key3, "bx", "Pad Bunch Crossing", 5, -2, 3, "Bunch crossing");
135  } // chamber loop
136  } // station loop
137  } // region loop
138  } // detail plot
139 }
140 
142 
144  const auto& gemH = setup.getHandle(geomToken_);
145  if (!gemH.isValid()) {
146  edm::LogError(kLogCategory_) << "Failed to initialize GEM geometry.";
147  return;
148  }
149  const GEMGeometry* gem = gemH.product();
150 
152  event.getByToken(pad_token_, collection);
153  if (not collection.isValid()) {
154  edm::LogError(kLogCategory_) << "Cannot get pads by label GEMPadToken.";
155  return;
156  }
157 
159  event.getByToken(digisimlink_token_, digiSimLink);
160  if (not digiSimLink.isValid()) {
161  edm::LogError(kLogCategory_) << "Failed to get GEMDigiSimLink." << std::endl;
162  return;
163  }
164 
165  edm::Handle<edm::PSimHitContainer> simhit_container;
166  event.getByToken(simhit_token_, simhit_container);
167  if (not simhit_container.isValid()) {
168  edm::LogError(kLogCategory_) << "Failed to get PSimHitContainer." << std::endl;
169  return;
170  }
171 
172  std::map<ME3IdsKey, Int_t> total_pad;
173  for (const auto& pad_pair : *collection) {
174  GEMDetId gemid = pad_pair.first;
175  const auto& range = pad_pair.second;
176 
177  if (gem->idToDet(gemid) == nullptr) {
178  edm::LogError(kLogCategory_) << "Getting DetId failed. Discard this gem pad hit. "
179  << "Maybe it comes from unmatched geometry." << std::endl;
180  continue;
181  }
182 
183  const GEMEtaPartition* roll = gem->etaPartition(gemid);
184  const BoundPlane& surface = roll->surface();
185 
186  Int_t region_id = gemid.region();
187  Int_t station_id = gemid.station();
188  Int_t layer_id = gemid.layer();
189  Int_t chamber_id = gemid.chamber();
190  Int_t ieta = gemid.ieta();
191  Int_t num_layers = gemid.nlayers();
192 
193  ME2IdsKey key2(region_id, station_id);
194  ME3IdsKey key3(region_id, station_id, layer_id);
195 
196  for (auto digi = range.first; digi != range.second; ++digi) {
197  total_pad[key3]++;
198 
199  Int_t pad = digi->pad();
200  Int_t bx = digi->bx();
201 
202  const LocalPoint& local_pos = roll->centreOfPad(pad);
203  const GlobalPoint& global_pos = surface.toGlobal(local_pos);
204 
205  Float_t g_r = global_pos.perp();
206  Float_t g_phi = global_pos.phi();
207  Float_t g_x = global_pos.x();
208  Float_t g_y = global_pos.y();
209  Float_t g_abs_z = std::fabs(global_pos.z());
210 
211  Int_t bin_x = getDetOccBinX(num_layers, chamber_id, layer_id);
212 
213  if (detail_plot_) {
214  me_detail_occ_zr_[region_id]->Fill(g_abs_z, g_r);
215  me_detail_occ_xy_[key3]->Fill(g_x, g_y);
216  me_detail_occ_phi_pad_[key3]->Fill(g_phi, pad);
217  me_detail_occ_pad_[key3]->Fill(pad);
218  me_detail_occ_det_[key2]->Fill(bin_x, ieta);
219  me_detail_bx_[key3]->Fill(bx);
220  } // if detail_plot
221  } // digi loop
222  } // range loop
223 
224  for (const auto& region : gem->regions()) {
225  Int_t region_id = region->region();
226  for (const auto& station : region->stations()) {
227  Int_t station_id = station->station();
228  const auto& superChamberVec = station->superChambers();
229  if (superChamberVec.empty()) {
230  edm::LogError(kLogCategory_) << "Super chambers missing for region = " << region_id
231  << " and station = " << station_id;
232  continue;
233  }
234  const GEMSuperChamber* super_chamber = superChamberVec.front();
235  if (super_chamber == nullptr) {
236  edm::LogError(kLogCategory_) << "Failed to find super chamber for region = " << region_id
237  << " and station = " << station_id;
238  continue;
239  }
240  for (const auto& chamber : super_chamber->chambers()) {
241  Int_t layer_id = chamber->id().layer();
242  ME3IdsKey key3{region_id, station_id, layer_id};
243  me_occ_total_pad_[key3]->Fill(total_pad[key3]);
244  }
245  }
246  }
247 
248  // NOTE
249  for (const auto& simhit : *simhit_container.product()) {
250  if (not isMuonSimHit(simhit))
251  continue;
252  if (gem->idToDet(simhit.detUnitId()) == nullptr) {
253  edm::LogError(kLogCategory_) << "SimHit did not match with GEMGeometry." << std::endl;
254  continue;
255  }
256 
257  GEMDetId simhit_gemid(simhit.detUnitId());
258 
259  Int_t region_id = simhit_gemid.region();
260  Int_t station_id = simhit_gemid.station();
261  Int_t layer_id = simhit_gemid.layer();
262  Int_t chamber_id = simhit_gemid.chamber();
263  Int_t ieta = simhit_gemid.ieta();
264  Int_t num_layers = simhit_gemid.nlayers();
265 
266  ME2IdsKey key2{region_id, station_id};
267  ME3IdsKey key3{region_id, station_id, layer_id};
268 
269  const GEMEtaPartition* roll = gem->etaPartition(simhit_gemid);
270 
271  const auto& simhit_local_pos = simhit.localPosition();
272  const auto& simhit_global_pos = roll->surface().toGlobal(simhit_local_pos);
273 
274  Float_t simhit_g_eta = std::abs(simhit_global_pos.eta());
275  Float_t simhit_g_phi = toDegree(simhit_global_pos.phi());
276 
277  auto simhit_trackId = simhit.trackId();
278 
279  Int_t bin_x = getDetOccBinX(num_layers, chamber_id, layer_id);
280 
281  auto links = digiSimLink->find(simhit_gemid);
282  if (links == digiSimLink->end())
283  continue;
284 
285  Int_t simhit_strip = -1;
286  for (const auto& link : *links) {
287  if (simhit_trackId == link.getTrackId()) {
288  simhit_strip = link.getStrip();
289  break;
290  }
291  }
292  Int_t simhit_pad = roll->padOfStrip(simhit_strip);
293  auto range = collection->get(simhit_gemid);
294  for (auto pad = range.first; pad != range.second; ++pad) {
295  if (pad->pad() == simhit_pad) {
296  me_pad_occ_eta_[key3]->Fill(simhit_g_eta);
297  me_pad_occ_phi_[key3]->Fill(simhit_g_phi);
298  if (detail_plot_) {
299  me_detail_pad_occ_det_[key2]->Fill(bin_x, ieta);
300  }
301  break;
302  }
303  }
304  } // simhit_container loop
305 }
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")
constexpr int station() const
Definition: GEMDetId.h:179
T perp() const
Definition: PV3DBase.h:69
constexpr int region() const
Definition: GEMDetId.h:171
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
T z() const
Definition: PV3DBase.h:61
edm::EDGetTokenT< GEMPadDigiCollection > pad_token_
edm::EDGetTokenT< edm::PSimHitContainer > simhit_token_
void analyze(const edm::Event &, const edm::EventSetup &) override
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
Bool_t isMuonSimHit(const PSimHit &)
T const * product() const
Definition: Handle.h:70
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)
constexpr int layer() const
Definition: GEMDetId.h:190
constexpr int chamber() const
Definition: GEMDetId.h:183
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
dqm::impl::MonitorElement * bookXYOccupancy(DQMStore::IBooker &booker, const T &key, const char *name_prefix, const char *title_prefix)
GEMPadDigiValidation(const edm::ParameterSet &)
edm::EDGetTokenT< edm::DetSetVector< GEMDigiSimLink > > digisimlink_token_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< Double_t > eta_range_
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > geomTokenBeginRun_
dqm::impl::MonitorElement * bookHist2D(DQMStore::IBooker &booker, const T &key, const char *name, const char *title, Int_t nbinsx, Double_t xlow, Double_t xup, Int_t nbinsy, Double_t ylow, Double_t yup, const char *x_title="", const char *y_title="")
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
#define M_PI
constexpr int ieta() const
Definition: GEMDetId.h:199
GEMDetId id() const
Return the GEMDetId of this super chamber.
bool isValid() const
Definition: HandleBase.h:70
std::tuple< Int_t, Int_t > ME2IdsKey
Float_t toDegree(Float_t radian)
std::tuple< Int_t, Int_t, Int_t > ME3IdsKey
Int_t getDetOccBinX(Int_t num_layers, Int_t chamber_id, Int_t layer_id)
const std::string kLogCategory_
constexpr int nlayers() const
Definition: GEMDetId.h:213
const std::vector< const GEMChamber * > & chambers() const
Return the chambers in the super chamber.
Definition: event.py:1
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)