CMS 3D CMS Logo

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