CMS 3D CMS Logo

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