CMS 3D CMS Logo

GEMCoPadDigiValidation.cc
Go to the documentation of this file.
2 
4  : GEMBaseValidation(pset, "GEMCoPadDigiValidation") {
5  const auto& copad_pset = pset.getParameterSet("gemCoPadDigi");
6 
7  const auto& copad_tag = copad_pset.getParameter<edm::InputTag>("inputTag");
8  copad_token_ = consumes<GEMCoPadDigiCollection>(copad_tag);
9  geomToken_ = esConsumes<GEMGeometry, MuonGeometryRecord>();
10  geomTokenBeginRun_ = esConsumes<GEMGeometry, MuonGeometryRecord, edm::Transition::BeginRun>();
11 
12  gem_bx_min_ = copad_pset.getParameter<int>("minBX");
13  gem_bx_max_ = copad_pset.getParameter<int>("maxBX");
14 }
15 
17  edm::Run const& run,
18  edm::EventSetup const& setup) {
19  const auto& gemH = setup.getHandle(geomTokenBeginRun_);
20  if (!gemH.isValid()) {
21  edm::LogError(kLogCategory_) << "Failed to initialize GEM geometry.";
22  return;
23  }
24  const GEMGeometry* gem = gemH.product();
25 
26  // NOTE Occupancy
27  booker.setCurrentFolder("GEM/CoPad");
28 
29  for (const auto& region : gem->regions()) {
30  Int_t region_id = region->region();
31 
32  if (detail_plot_)
33  me_detail_occ_zr_[region_id] = bookZROccupancy(booker, region_id, "copad", "CoPad");
34 
35  for (const auto& station : region->stations()) {
36  Int_t station_id = station->station();
37  const auto& superChamberVec = station->superChambers();
38  if (superChamberVec.empty() || superChamberVec[0] == nullptr) {
39  edm::LogError(kLogCategory_) << "Super chambers missing or null for region = " << region_id
40  << " and station = " << station_id;
41  continue;
42  }
43  const auto& chamberVec = superChamberVec[0]->chambers();
44  if (chamberVec.empty() || chamberVec[0] == nullptr) {
45  edm::LogError(kLogCategory_) << "Chambers missing or null for region, station, super chamber = (" << region_id
46  << ", " << station_id << ", " << superChamberVec[0]->id() << ")";
47  continue;
48  }
49  const auto& etaPartitionVec = chamberVec[0]->etaPartitions();
50  if (etaPartitionVec.empty() || etaPartitionVec[0] == nullptr) {
51  edm::LogError(kLogCategory_) << "Eta partition missing or null for region, station, super chamber, chamber = ("
52  << region_id << ", " << station_id << ", " << superChamberVec[0]->id() << ", "
53  << chamberVec[0]->id() << ")";
54  continue;
55  }
56  Int_t num_pads = etaPartitionVec[0]->npads();
57  ME2IdsKey key2{region_id, station_id};
58 
59  if (detail_plot_) {
60  me_detail_occ_xy_[key2] = bookXYOccupancy(booker, key2, "copad", "CoPad");
61 
62  me_detail_occ_phi_pad_[key2] = bookHist2D(booker,
63  key2,
64  "copad_occ_phi_pad",
65  "CoPad Occupancy",
66  280,
67  -M_PI,
68  M_PI,
69  num_pads / 2,
70  0,
71  num_pads,
72  "#phi [rad]",
73  "Pad number");
74 
76  booker, key2, "copad_occ_pad", "CoPad Ocupancy per pad number", num_pads, 0.5, num_pads + 0.5, "Pad number");
77 
78  me_detail_occ_det_[key2] = bookDetectorOccupancy(booker, key2, station, "copad", "CoPad");
79  }
80  } // station loop
81  } // region loop
82 
83  // NOTE Bunch Crossing
84  if (detail_plot_) {
85  for (const auto& region : gem->regions()) {
86  Int_t region_id = region->region();
87  for (const auto& station : region->stations()) {
88  Int_t station_id = station->station();
89  ME2IdsKey key2{region_id, station_id};
90 
91  me_detail_bx_[key2] =
92  bookHist1D(booker, key2, "copad_bx", "CoPad Bunch Crossing", 5, -2.5, 2.5, "Bunch crossing");
93  } // station loop
94  } // region loop
95  } // detail plot
96 }
97 
99 
101  const auto& gemH = setup.getHandle(geomToken_);
102  if (!gemH.isValid()) {
103  edm::LogError(kLogCategory_) << "Failed to initialize GEM geometry.";
104  return;
105  }
106  const GEMGeometry* gem = gemH.product();
107 
108  edm::Handle<GEMCoPadDigiCollection> copad_collection;
109  event.getByToken(copad_token_, copad_collection);
110  if (not copad_collection.isValid()) {
111  edm::LogError(kLogCategory_) << "Cannot get pads by token." << std::endl;
112  return;
113  }
114 
115  // GEMCoPadDigiCollection::DigiRangeIterator
116  for (const auto& copad_pair : *copad_collection) {
117  GEMDetId gemid = copad_pair.first;
118  const auto& range = copad_pair.second;
119 
120  Int_t region_id = gemid.region();
121  Int_t station_id = gemid.station();
122  Int_t ring_id = gemid.ring();
123  Int_t layer_id = gemid.layer();
124  Int_t chamber_id = gemid.chamber();
125  Int_t num_layers = gemid.nlayers();
126 
127  ME2IdsKey key2{region_id, station_id};
128 
129  for (auto digi = range.first; digi != range.second; ++digi) {
130  // GEM copads are stored per super chamber!
131  // layer_id = 0, roll_id = 0
132  GEMDetId super_chamber_id{region_id, ring_id, station_id, 0, chamber_id, 0};
133  Int_t roll_id = (*digi).roll();
134 
135  const GeomDet* geom_det = gem->idToDet(super_chamber_id);
136  if (geom_det == nullptr) {
137  edm::LogError(kLogCategory_) << super_chamber_id << " : This detId cannot be "
138  << "loaded from GEMGeometry // Original" << gemid << " station : " << station_id
139  << std::endl
140  << "Getting DetId failed. Discard this gem copad hit." << std::endl;
141  continue;
142  }
143 
144  const BoundPlane& surface = geom_det->surface();
145  const GEMSuperChamber* super_chamber = gem->superChamber(super_chamber_id);
146  if (super_chamber == nullptr) {
147  edm::LogError(kLogCategory_) << "Super chamber is null for super chamber ID = " << super_chamber_id;
148  continue;
149  }
150  Int_t pad1 = digi->pad(1);
151  Int_t pad2 = digi->pad(2);
152  Int_t bx1 = digi->bx(1);
153  Int_t bx2 = digi->bx(2);
154 
155  // Filtered using BX
156  if (bx1 < gem_bx_min_ or bx1 > gem_bx_max_)
157  continue;
158  if (bx2 < gem_bx_min_ or bx2 > gem_bx_max_)
159  continue;
160 
161  const Int_t padArray[] = {pad1, pad2};
162  LocalPoint lpArray[2];
163  int ptCounter = 0;
164  for (; ptCounter < 2; ++ptCounter) {
165  const GEMChamber* const chamber = super_chamber->chamber(ptCounter + 1); // Fetch chambers 1 and 2
166  if (chamber == nullptr) {
167  edm::LogError(kLogCategory_) << "Chamber " << (ptCounter + 1)
168  << " is null for super chamber = " << super_chamber_id;
169  break;
170  }
171  const GEMEtaPartition* const etaPartition = chamber->etaPartition(roll_id);
172  if (etaPartition == nullptr) {
173  edm::LogError(kLogCategory_) << "Eta partition " << roll_id << " is null for chamber, super chamber = ("
174  << (ptCounter + 1) << ", " << super_chamber_id << ")";
175  break;
176  }
177  lpArray[ptCounter] = etaPartition->centreOfPad(padArray[ptCounter]);
178  } // end for
179  if (ptCounter < 2) { // Broke out of "for" loop
180  edm::LogError(kLogCategory_) << "Skipping a digi due to bad chamber " << (ptCounter + 1);
181  continue;
182  }
183  const GlobalPoint& gp1 = surface.toGlobal(lpArray[0]);
184  const GlobalPoint& gp2 = surface.toGlobal(lpArray[1]);
185 
186  Float_t g_r1 = gp1.perp();
187  Float_t g_r2 = gp2.perp();
188 
189  Float_t g_z1 = gp1.z();
190  Float_t g_z2 = gp2.z();
191 
192  Float_t g_phi = gp1.phi();
193  Float_t g_x = gp1.x();
194  Float_t g_y = gp1.y();
195 
196  // Fill normal plots.
197 
198  Int_t bin_x = getDetOccBinX(num_layers, chamber_id, layer_id);
199 
200  // Fill detail plots.
201  if (detail_plot_) {
202  me_detail_occ_zr_[region_id]->Fill(std::fabs(g_z1), g_r1);
203  me_detail_occ_zr_[region_id]->Fill(std::fabs(g_z2), g_r2);
204  me_detail_occ_xy_[key2]->Fill(g_x, g_y);
205  me_detail_occ_det_[key2]->Fill(bin_x, roll_id);
206  me_detail_occ_det_[key2]->Fill(bin_x + 1, roll_id);
207  me_detail_occ_phi_pad_[key2]->Fill(g_phi, pad1);
208  me_detail_occ_pad_[key2]->Fill(pad1);
209  me_detail_bx_[key2]->Fill(bx1);
210  me_detail_bx_[key2]->Fill(bx2);
211  } // detail_plot_
212  } // loop over digis
213  } // loop over range iters
214 }
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")
edm::EDGetTokenT< GEMCoPadDigiCollection > copad_token_
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
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
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
GEMCoPadDigiValidation(const edm::ParameterSet &)
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > geomTokenBeginRun_
dqm::impl::MonitorElement * bookXYOccupancy(DQMStore::IBooker &booker, const T &key, const char *name_prefix, const char *title_prefix)
constexpr int ring() const
Definition: GEMDetId.h:176
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="")
#define M_PI
void analyze(const edm::Event &, const edm::EventSetup &) override
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
bool isValid() const
Definition: HandleBase.h:70
LocalPoint centreOfPad(int pad) const
std::tuple< Int_t, Int_t > ME2IdsKey
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > geomToken_
Int_t getDetOccBinX(Int_t num_layers, Int_t chamber_id, Int_t layer_id)
const GEMChamber * chamber(GEMDetId id) const
Return the chamber corresponding to the given id.
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
const std::string kLogCategory_
constexpr int nlayers() const
Definition: GEMDetId.h:213
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)