CMS 3D CMS Logo

GEMStripDigiValidation.cc
Go to the documentation of this file.
3 
5  : GEMBaseValidation(pset, "GEMStripDigiValidation") {
6  const auto& strip_pset = pset.getParameterSet("gemStripDigi");
7  const auto& strip_tag = strip_pset.getParameter<edm::InputTag>("inputTag");
8  strip_token_ = consumes<GEMDigiCollection>(strip_tag);
9 
10  const auto& simhit_pset = pset.getParameterSet("gemSimHit");
11  const auto& simhit_tag = simhit_pset.getParameter<edm::InputTag>("inputTag");
12  simhit_token_ = consumes<edm::PSimHitContainer>(simhit_tag);
13 
14  const auto& digisimlink_tag = pset.getParameter<edm::InputTag>("gemDigiSimLink");
15  digisimlink_token_ = consumes<edm::DetSetVector<GEMDigiSimLink>>(digisimlink_tag);
16 
17  geomToken_ = esConsumes<GEMGeometry, MuonGeometryRecord>();
18  geomTokenBeginRun_ = esConsumes<GEMGeometry, MuonGeometryRecord, edm::Transition::BeginRun>();
19 }
20 
22  edm::Run const& run,
23  edm::EventSetup const& setup) {
24  const auto gemH = setup.getHandle(geomTokenBeginRun_);
25  if (!gemH.isValid()) {
26  edm::LogError(kLogCategory_) << "Failed to initialize GEM geometry.";
27  return;
28  }
29  const GEMGeometry* gem = gemH.product();
30 
31  // NOTE Bunch Crossing
32  booker.setCurrentFolder("GEM/Digis");
33 
34  if (detail_plot_) {
35  me_detail_bx_ = booker.book1D("bx", "Strip Digi Bunch Crossing", 5, -2.5, 2.5);
36 
37  for (const auto& region : gem->regions()) {
38  if (region == nullptr) {
39  edm::LogError(kLogCategory_) << "Null region";
40  continue;
41  }
42  Int_t region_id = region->region();
43  for (const auto& station : region->stations()) {
44  if (station == nullptr) {
45  edm::LogError(kLogCategory_) << "Null station for region = " << region_id;
46  continue;
47  }
48  Int_t station_id = station->station();
49 
50  const auto& superChamberVec = station->superChambers();
51  if (superChamberVec.empty()) {
52  edm::LogError(kLogCategory_) << "Super chambers missing for region = " << region_id
53  << " and station = " << station_id;
54  continue;
55  }
56  const GEMSuperChamber* super_chamber = superChamberVec.front();
57  if (super_chamber == nullptr) {
58  edm::LogError(kLogCategory_) << "Failed to find super chamber for region = " << region_id
59  << " and station = " << station_id;
60  continue;
61  }
62  for (const auto& chamber : super_chamber->chambers()) {
63  Int_t layer_id = chamber->id().layer();
64  ME3IdsKey key3(region_id, station_id, layer_id);
65 
66  me_detail_bx_layer_[key3] =
67  bookHist1D(booker, key3, "bx", "Strip Digi Bunch Crossing", 5, -2.5, 2.5, "Bunch crossing");
68  } // chamber loop
69  } // station loop
70  } // region loop
71  }
72 
73  // NOTE Occupancy
74  if (detail_plot_)
76  booker.book1D("total_strips_per_event", "Number of strip digi per event", 50, -0.5, 395.5);
77 
78  for (const auto& region : gem->regions()) {
79  Int_t region_id = region->region();
80 
81  if (detail_plot_)
82  me_detail_occ_zr_[region_id] = bookZROccupancy(booker, region_id, "strip", "Strip Digi");
83 
84  for (const auto& station : region->stations()) {
85  Int_t station_id = station->station();
86  ME2IdsKey key2{region_id, station_id};
87 
88  me_occ_pid_[key2] = bookPIDHist(booker, key2, "sim_occ_pid", "Particle population");
89 
90  if (detail_plot_) {
92  bookHist1D(booker, key2, "total_strips_per_event", "Number of strip digs per event", 50, -0.5, 99.5);
93 
94  me_detail_occ_det_[key2] = bookDetectorOccupancy(booker, key2, station, "strip", "Strip Digi");
95 
97  bookDetectorOccupancy(booker, key2, station, "sim_matched_strip", "Matched Strip Digi");
98  }
99 
100  const auto& superChamberVec = station->superChambers();
101  if (superChamberVec.empty() || superChamberVec[0] == nullptr) {
102  edm::LogError(kLogCategory_) << "Super chambers missing or null for region = " << region_id
103  << " and station = " << station_id;
104  } else {
105  for (const auto& etaPart : superChamberVec[0]->chambers()[0]->etaPartitions()) {
106  Int_t ieta = etaPart->id().ieta();
107  ME3IdsKey key{region_id, station_id, ieta};
108  me_occ_pid_eta_[key] = bookPIDHist(booker, key2, ieta, "sim_occ_pid", "Particle population");
109  }
110  for (const auto& chamber : superChamberVec[0]->chambers()) {
111  if (chamber == nullptr) {
112  edm::LogError(kLogCategory_) << "Null chamber for region, station, super chamber = (" << region_id << ", "
113  << station_id << ", " << superChamberVec[0]->id() << ")";
114  continue;
115  }
116  Int_t layer_id = chamber->id().layer();
117  ME3IdsKey key3{region_id, station_id, layer_id};
118 
119  const auto& etaPartitionsVec = chamber->etaPartitions();
120  if (etaPartitionsVec.empty() || etaPartitionsVec.front() == nullptr) {
122  << "Eta partition missing or null for region, station, super chamber, chamber = (" << region_id << ", "
123  << station_id << ", " << superChamberVec[0]->id() << ", " << chamber->id() << ")";
124  continue;
125  }
126 
127  if (detail_plot_) {
128  Int_t num_strips = etaPartitionsVec.front()->nstrips();
129 
130  me_detail_strip_occ_eta_[key3] = bookHist1D(booker,
131  key3,
132  "sim_matched_occ_eta",
133  "Matched Strip Eta Occupancy",
134  16,
135  eta_range_[station_id * 2 + 0],
136  eta_range_[station_id * 2 + 1],
137  "#eta");
138 
140  booker, key3, "sim_matched_occ_phi", "Matched Strip Phi Occupancy", 36, -5, 355, "#phi [degrees]");
141 
142  me_detail_occ_xy_[key3] = bookXYOccupancy(booker, key3, "strip", "Strip Digi");
143 
144  me_detail_occ_strip_[key3] = bookHist1D(booker,
145  key3,
146  "occ_strip",
147  "Strip Digi Occupancy per strip number",
148  num_strips,
149  0.5,
150  num_strips + 0.5,
151  "strip number");
152  }
153  } // chamber
154  } // end else
155  } // station looop
156  } // region loop
157 }
158 
160 
162  const auto& gemH = setup.getHandle(geomToken_);
163  if (!gemH.isValid()) {
164  edm::LogError(kLogCategory_) << "Failed to initialize GEM geometry.";
165  return;
166  }
167  const GEMGeometry* gem = gemH.product();
168 
170  event.getByToken(digisimlink_token_, digiSimLink);
171  if (not digiSimLink.isValid()) {
172  edm::LogError(kLogCategory_) << "Failed to get GEMDigiSimLink." << std::endl;
173  return;
174  }
175 
176  edm::Handle<edm::PSimHitContainer> simhit_container;
177  event.getByToken(simhit_token_, simhit_container);
178  if (not simhit_container.isValid()) {
179  edm::LogError(kLogCategory_) << "Failed to get PSimHitContainer." << std::endl;
180  return;
181  }
182 
183  edm::Handle<GEMDigiCollection> digi_collection;
184  event.getByToken(strip_token_, digi_collection);
185  if (not digi_collection.isValid()) {
186  edm::LogError(kLogCategory_) << "Cannot get strips by Token stripToken." << std::endl;
187  return;
188  }
189 
190  // NOTE
191  Int_t total_strip = 0;
192  std::map<ME2IdsKey, Int_t> total_strip_2IdsMap;
193  for (const auto digi_pair : *digi_collection) {
194  GEMDetId id = digi_pair.first;
195  if (gem->idToDet(id) == nullptr) {
196  edm::LogError(kLogCategory_) << "Getting DetId failed. Discard this gem strip hit. Maybe it comes "
197  << "from unmatched geometry." << std::endl;
198  continue;
199  }
200 
201  Int_t region_id = id.region();
202  Int_t layer_id = id.layer();
203  Int_t station_id = id.station();
204  Int_t chamber_id = id.chamber();
205  Int_t ieta = id.ieta();
206  Int_t num_layers = id.nlayers();
207 
208  ME2IdsKey key2{region_id, station_id};
209  ME3IdsKey key3{region_id, station_id, layer_id};
210  Int_t bin_x = getDetOccBinX(num_layers, chamber_id, layer_id);
211 
212  const BoundPlane& surface = gem->idToDet(id)->surface();
213  const GEMEtaPartition* roll = gem->etaPartition(id);
214 
215  const GEMDigiCollection::Range& range = digi_pair.second;
216  auto links = digiSimLink->find(id);
217  if (links == digiSimLink->end())
218  continue;
219 
220  for (auto digi = range.first; digi != range.second; ++digi) {
221  total_strip++;
222  total_strip_2IdsMap[key2]++;
223  Int_t strip = digi->strip();
224  Int_t bx = digi->bx();
225  bx = bx < -10 ? -10 : bx;
226  bx = bx > 10 ? 10 : bx;
227 
228  GlobalPoint strip_global_pos = surface.toGlobal(roll->centreOfStrip(strip));
229 
230  Float_t digi_g_x = strip_global_pos.x();
231  Float_t digi_g_y = strip_global_pos.y();
232  Float_t digi_g_r = strip_global_pos.perp();
233  Float_t digi_g_abs_z = std::abs(strip_global_pos.z());
234 
235  if (detail_plot_) {
237  me_detail_bx_layer_[key3]->Fill(bx);
238 
239  me_detail_occ_zr_[region_id]->Fill(digi_g_abs_z, digi_g_r);
240  me_detail_occ_det_[key2]->Fill(bin_x, ieta);
241  me_detail_occ_xy_[key3]->Fill(digi_g_x, digi_g_y);
242  me_detail_occ_strip_[key3]->Fill(strip);
243  }
244  }
245  } // range loop
246  if (detail_plot_) {
247  me_detail_total_strip_all_->Fill(total_strip);
248  for (const auto& region : gem->regions()) {
249  Int_t region_id = region->region();
250  for (const auto& station : region->stations()) {
251  Int_t station_id = station->station();
252  ME2IdsKey key2{region_id, station_id};
253  me_detail_total_strip_[key2]->Fill(total_strip_2IdsMap[key2]);
254  }
255  }
256  }
257 
258  // NOTE
259  for (const auto& simhit : *simhit_container.product()) {
260  if (gem->idToDet(simhit.detUnitId()) == nullptr) {
261  edm::LogError(kLogCategory_) << "SimHit did not match with GEMGeometry." << std::endl;
262  continue;
263  }
264 
265  GEMDetId simhit_gemid(simhit.detUnitId());
266 
267  Int_t region_id = simhit_gemid.region();
268  Int_t station_id = simhit_gemid.station();
269  Int_t layer_id = simhit_gemid.layer();
270  Int_t chamber_id = simhit_gemid.chamber();
271  Int_t ieta = simhit_gemid.ieta();
272  Int_t num_layers = simhit_gemid.nlayers();
273 
274  ME3IdsKey key{region_id, station_id, ieta};
275  ME2IdsKey key2{region_id, station_id};
276  ME3IdsKey key3{region_id, station_id, layer_id};
277 
278  const GEMEtaPartition* roll = gem->etaPartition(simhit_gemid);
279 
280  const auto& simhit_local_pos = simhit.localPosition();
281  const auto& simhit_global_pos = roll->surface().toGlobal(simhit_local_pos);
282 
283  Float_t simhit_g_eta = std::abs(simhit_global_pos.eta());
284  Float_t simhit_g_phi = toDegree(simhit_global_pos.phi());
285 
286  auto simhit_trackId = simhit.trackId();
287 
288  Int_t bin_x = getDetOccBinX(num_layers, chamber_id, layer_id);
289 
290  auto links = digiSimLink->find(simhit_gemid);
291  if (links == digiSimLink->end())
292  continue;
293 
294  for (const auto& link : *links) {
295  if (simhit_trackId == link.getTrackId()) {
296  Int_t pid = simhit.particleType();
297  Int_t pid_idx = getPidIdx(pid);
298 
299  me_occ_pid_[key2]->Fill(pid_idx);
300  me_occ_pid_eta_[key]->Fill(pid_idx);
301 
302  if (detail_plot_) {
303  if (isMuonSimHit(simhit)) {
304  me_detail_strip_occ_eta_[key3]->Fill(simhit_g_eta);
305  me_detail_strip_occ_phi_[key3]->Fill(simhit_g_phi);
306  me_detail_strip_occ_det_[key2]->Fill(bin_x, ieta);
307  }
308  }
309  break;
310  }
311  }
312  } // simhit_container loop
313 }
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")
T perp() const
Definition: PV3DBase.h:69
constexpr int region() const
Definition: GEMDetId.h:171
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
T z() const
Definition: PV3DBase.h:61
Bool_t isMuonSimHit(const PSimHit &)
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > geomTokenBeginRun_
T const * product() const
Definition: Handle.h:70
MonitorElement * me_detail_total_strip_all_
GEMStripDigiValidation(const edm::ParameterSet &)
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::ESGetToken< GEMGeometry, MuonGeometryRecord > geomToken_
void Fill(long long x)
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)
edm::EDGetTokenT< edm::DetSetVector< GEMDigiSimLink > > digisimlink_token_
void analyze(const edm::Event &, const edm::EventSetup &) override
Int_t getPidIdx(Int_t pid)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< Double_t > eta_range_
key
prepare the HTCondor submission files and eventually submit them
edm::EDGetTokenT< GEMDigiCollection > strip_token_
std::pair< const_iterator, const_iterator > Range
bool isValid() const
Definition: HandleBase.h:70
edm::EDGetTokenT< edm::PSimHitContainer > simhit_token_
std::tuple< Int_t, Int_t > ME2IdsKey
Float_t toDegree(Float_t radian)
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
static char chambers[264][20]
Definition: ReadPGInfo.cc:243
Int_t getDetOccBinX(Int_t num_layers, Int_t chamber_id, Int_t layer_id)
dqm::impl::MonitorElement * bookPIDHist(DQMStore::IBooker &booker, const T &key, const char *name, const char *title)
const std::string kLogCategory_
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)