CMS 3D CMS Logo

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