CMS 3D CMS Logo

GEMRecHitsValidation.cc
Go to the documentation of this file.
5 #include <iomanip>
6 
7 using namespace std;
8 
10  InputTagToken_ = consumes<edm::PSimHitContainer>(cfg.getParameter<edm::InputTag>("simInputLabel"));
11  InputTagToken_RH = consumes<GEMRecHitCollection>(cfg.getParameter<edm::InputTag>("recHitsInputLabel"));
12  detailPlot_ = cfg.getParameter<bool>("detailPlot");
13 }
14 
16  const char *name,
17  const char *label,
18  unsigned int region_num,
19  unsigned int station_num,
20  unsigned int layer_num,
21  const unsigned int Nbin,
22  const Float_t xMin,
23  const Float_t xMax) {
24  string hist_name = name + getSuffixName(region_num, station_num + 1, layer_num + 1);
25  string hist_label = label + string(" : ") + getSuffixTitle(region_num, station_num + 1, layer_num + 1);
26  return ibooker.book1D(hist_name, hist_label, Nbin, xMin, xMax);
27 }
28 
30  const char *name,
31  const char *label,
32  unsigned int region_num,
33  const unsigned int Nbin,
34  const Float_t xMin,
35  const Float_t xMax) {
36  string hist_name = name + getSuffixName(region_num);
37  string hist_label = label + string(" : ") + getSuffixName(region_num);
38  return ibooker.book1D(hist_name, hist_label, Nbin, xMin, xMax);
39 }
40 
42  edm::Run const &Run,
43  edm::EventSetup const &iSetup) {
44  const GEMGeometry *GEMGeometry_ = initGeometry(iSetup);
45  if (GEMGeometry_ == nullptr)
46  return;
47 
48  LogDebug("GEMRecHitsValidation") << "Geometry is acquired from MuonGeometryRecord\n";
49  ibooker.setCurrentFolder("MuonGEMRecHitsV/GEMRecHitsTask");
50  LogDebug("GEMRecHitsValidation") << "ibooker set current folder\n";
51 
52  gem_cls_tot = ibooker.book1D("gem_cls_tot", "ClusterSize Distribution", 11, -0.5, 10.5);
53  for (auto &region : GEMGeometry_->regions()) {
54  int re = region->region();
55  TString title_suffix = getSuffixTitle(re);
56  TString histname_suffix = getSuffixName(re);
57  TString simpleZR_title = TString::Format("ZR Occupancy%s; |Z|(cm) ; R(cm)", title_suffix.Data());
58  TString simpleZR_histname = TString::Format("rh_simple_zr%s", histname_suffix.Data());
59  auto *simpleZR = getSimpleZR(ibooker, simpleZR_title, simpleZR_histname);
60  if (simpleZR != nullptr) {
61  recHits_simple_zr[simpleZR_histname.Hash()] = simpleZR;
62  }
63 
64  for (auto &station : region->stations()) {
65  int station_num = station->station();
66  TString title_suffix2 = title_suffix + TString::Format(" Station%d", station_num);
67  TString histname_suffix2 = histname_suffix + TString::Format("_st%d", station_num);
68 
69  TString dcEta_title =
70  TString::Format("Occupancy for detector component %s;;#eta-partition", title_suffix2.Data());
71  TString dcEta_histname = TString::Format("rh_dcEta%s", histname_suffix2.Data());
72  auto *dcEta = getDCEta(ibooker, station, dcEta_title, dcEta_histname);
73  if (dcEta != nullptr) {
74  recHits_dcEta[dcEta_histname.Hash()] = dcEta;
75  }
76  int idx = 0;
77  for (unsigned int sCh = 1; sCh <= station->superChambers().size(); sCh++) {
78  for (unsigned int Ch = 1; Ch <= 2; Ch++) {
79  idx++;
80  TString label = TString::Format("ch%d_la%d", sCh, Ch);
81  recHits_dcEta[dcEta_histname.Hash()]->setBinLabel(idx, label.Data());
82  }
83  }
84  }
85  }
86 
87  for (unsigned int region_num = 0; region_num < nRegion(); region_num++) {
88  gem_region_pullX[region_num] = BookHist1D(ibooker, "pullX", "Pull Of X", region_num, 100, -50, 50);
89  gem_region_pullY[region_num] = BookHist1D(ibooker, "pullY", "Pull Of Y", region_num, 100, -50, 50);
90  }
91 
92  if (detailPlot_) {
93  for (unsigned int region_num = 0; region_num < nRegion(); region_num++) {
94  for (int layer_num = 0; layer_num < 2; layer_num++) {
95  for (unsigned int station_num = 0; station_num < nStation(); station_num++) {
96  gem_cls[region_num][station_num][layer_num] = BookHist1D(
97  ibooker, "cls", "ClusterSize Distribution", region_num, station_num, layer_num, 11, -0.5, 10.5);
98  gem_pullX[region_num][station_num][layer_num] =
99  BookHist1D(ibooker, "pullX", "Pull Of X", region_num, station_num, layer_num, 100, -50, 50);
100  gem_pullY[region_num][station_num][layer_num] =
101  BookHist1D(ibooker, "pullY", "Pull Of Y", region_num, station_num, layer_num, 100, -50, 50);
102  gem_rh_zr[region_num][station_num][layer_num] =
103  BookHistZR(ibooker, "rh", "RecHits", region_num, station_num, layer_num);
104  gem_rh_xy[region_num][station_num][layer_num] =
105  BookHistXY(ibooker, "rh", "RecHits", region_num, station_num, layer_num);
106  }
107  }
108  }
109  }
110  LogDebug("GEMRecHitsValidation") << "Booking End.\n";
111 }
112 
114 
116  const GEMGeometry *GEMGeometry_ = initGeometry(iSetup);
117  if (GEMGeometry_ == nullptr)
118  return;
119 
122  e.getByToken(this->InputTagToken_, gemSimHits);
123  e.getByToken(this->InputTagToken_RH, gemRecHits);
124  if (!gemRecHits.isValid()) {
125  edm::LogError("GEMRecHitsValidation") << "Cannot get strips by Token RecHits Token.\n";
126  return;
127  }
128 
129  for (edm::PSimHitContainer::const_iterator hits = gemSimHits->begin(); hits != gemSimHits->end(); ++hits) {
130  const GEMDetId id(hits->detUnitId());
131 
132  Int_t sh_region = id.region();
133  // Int_t sh_ring = id.ring();
134  Int_t sh_roll = id.roll();
135  Int_t sh_station = id.station();
136  Int_t sh_layer = id.layer();
137  Int_t sh_chamber = id.chamber();
138 
139  if (GEMGeometry_->idToDet(hits->detUnitId()) == nullptr) {
140  std::cout << "simHit did not matched with GEMGeometry." << std::endl;
141  continue;
142  }
143 
144  if (!(abs(hits->particleType()) == 13))
145  continue;
146 
147  // const LocalPoint p0(0., 0., 0.);
148  // const GlobalPoint
149  // Gp0(GEMGeometry_->idToDet(hits->detUnitId())->surface().toGlobal(p0));
150  const LocalPoint hitLP(hits->localPosition());
151 
152  const LocalPoint hitEP(hits->entryPoint());
153  Int_t sh_strip = GEMGeometry_->etaPartition(hits->detUnitId())->strip(hitEP);
154 
155  // const GlobalPoint
156  // hitGP(GEMGeometry_->idToDet(hits->detUnitId())->surface().toGlobal(hitLP));
157  // Float_t sh_l_r = hitLP.perp();
158  Float_t sh_l_x = hitLP.x();
159  Float_t sh_l_y = hitLP.y();
160  // Float_t sh_l_z = hitLP.z();
161 
162  for (GEMRecHitCollection::const_iterator recHit = gemRecHits->begin(); recHit != gemRecHits->end(); ++recHit) {
163  Float_t rh_l_x = recHit->localPosition().x();
164  Float_t rh_l_xErr = recHit->localPositionError().xx();
165  Float_t rh_l_y = recHit->localPosition().y();
166  Float_t rh_l_yErr = recHit->localPositionError().yy();
167  // Int_t detId = (Short_t) (*recHit).gemId();
168  // Int_t bx = recHit->BunchX();
169  Int_t clusterSize = recHit->clusterSize();
170  Int_t firstClusterStrip = recHit->firstClusterStrip();
171 
172  GEMDetId id((*recHit).gemId());
173 
174  Short_t rh_region = (Short_t)id.region();
175  // Int_t rh_ring = (Short_t) id.ring();
176  Short_t rh_station = (Short_t)id.station();
177  Short_t rh_layer = (Short_t)id.layer();
178  Short_t rh_chamber = (Short_t)id.chamber();
179  Short_t rh_roll = (Short_t)id.roll();
180 
181  LocalPoint recHitLP = recHit->localPosition();
182  if (GEMGeometry_->idToDet((*recHit).gemId()) == nullptr) {
183  std::cout << "This gem recHit did not matched with GEMGeometry." << std::endl;
184  continue;
185  }
186  GlobalPoint recHitGP = GEMGeometry_->idToDet((*recHit).gemId())->surface().toGlobal(recHitLP);
187 
188  Float_t rh_g_R = recHitGP.perp();
189  // Float_t rh_g_Eta = recHitGP.eta();
190  // Float_t rh_g_Phi = recHitGP.phi();
191  Float_t rh_g_X = recHitGP.x();
192  Float_t rh_g_Y = recHitGP.y();
193  Float_t rh_g_Z = recHitGP.z();
194  Float_t rh_pullX = (Float_t)(rh_l_x - sh_l_x) / (rh_l_xErr);
195  Float_t rh_pullY = (Float_t)(rh_l_y - sh_l_y) / (rh_l_yErr);
196 
197  std::vector<int> stripsFired;
198  for (int i = firstClusterStrip; i < (firstClusterStrip + clusterSize); i++) {
199  stripsFired.push_back(i);
200  }
201 
202  const bool cond1(sh_region == rh_region and sh_layer == rh_layer and sh_station == rh_station);
203  const bool cond2(sh_chamber == rh_chamber and sh_roll == rh_roll);
204  const bool cond3(std::find(stripsFired.begin(), stripsFired.end(), (sh_strip + 1)) != stripsFired.end());
205 
206  if (cond1 and cond2 and cond3) {
207  LogDebug("GEMRecHitsValidation") << " Region : " << rh_region << "\t Station : " << rh_station
208  << "\t Layer : " << rh_layer << "\n Radius: " << rh_g_R << "\t X : " << rh_g_X
209  << "\t Y : " << rh_g_Y << "\t Z : " << rh_g_Z << std::endl;
210 
211  int region_num = 0;
212  if (rh_region == -1)
213  region_num = 0;
214  else if (rh_region == 1)
215  region_num = 1;
216  int layer_num = rh_layer - 1;
217  int binX = (rh_chamber - 1) * 2 + layer_num;
218  int binY = rh_roll;
219  int station_num = rh_station - 1;
220 
221  // Fill normal plots.
222  TString histname_suffix = TString::Format("_r%d", rh_region);
223  TString simple_zr_histname = TString::Format("rh_simple_zr%s", histname_suffix.Data());
224  LogDebug("GEMRecHitsValidation") << " simpleZR!\n";
225  recHits_simple_zr[simple_zr_histname.Hash()]->Fill(fabs(rh_g_Z), rh_g_R);
226 
227  histname_suffix = TString::Format("_r%d_st%d", rh_region, rh_station);
228  TString dcEta_histname = TString::Format("rh_dcEta%s", histname_suffix.Data());
229  LogDebug("GEMRecHitsValidation") << " dcEta\n";
230  recHits_dcEta[dcEta_histname.Hash()]->Fill(binX, binY);
231 
232  gem_cls_tot->Fill(clusterSize);
233  gem_region_pullX[region_num]->Fill(rh_pullX);
234  gem_region_pullY[region_num]->Fill(rh_pullY);
235  LogDebug("GEMRecHitsValidation") << " Begin detailPlot!\n";
236 
237  if (detailPlot_) {
238  gem_cls[region_num][station_num][layer_num]->Fill(clusterSize);
239  gem_pullX[region_num][station_num][layer_num]->Fill(rh_pullX);
240  gem_pullY[region_num][station_num][layer_num]->Fill(rh_pullY);
241  gem_rh_zr[region_num][station_num][layer_num]->Fill(rh_g_Z, rh_g_R);
242  gem_rh_xy[region_num][station_num][layer_num]->Fill(rh_g_X, rh_g_Y);
243  }
244  }
245  } // End loop on RecHits
246  } // End loop on SimHits
247 }
#define LogDebug(id)
unsigned int nRegion()
T getParameter(std::string const &) const
MonitorElement * gem_pullX[2][3][2]
unsigned int nStation()
T perp() const
Definition: PV3DBase.h:72
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
MonitorElement * BookHistZR(DQMStore::IBooker &, const char *name, const char *label, unsigned int region_num, unsigned int station_num, unsigned int layer_num=99)
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
T y() const
Definition: PV3DBase.h:63
MonitorElement * gem_region_pullY[2]
MonitorElement * getSimpleZR(DQMStore::IBooker &, TString, TString)
MonitorElement * BookHistXY(DQMStore::IBooker &, const char *name, const char *label, unsigned int region_num, unsigned int station_num, unsigned int layer_num=99)
MonitorElement * gem_rh_xy[2][3][2]
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
std::string getSuffixTitle(int region, int station, int layer)
MonitorElement * gem_rh_zr[2][3][2]
const GEMEtaPartition * etaPartition(GEMDetId id) const
Return a GEMEtaPartition given its id.
Definition: GEMGeometry.cc:99
const GEMGeometry * initGeometry(const edm::EventSetup &)
MonitorElement * gem_cls[2][3][2]
void Fill(long long x)
std::string getSuffixName(int region, int station, int layer)
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
char const * label
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
MonitorElement * gem_cls_tot
edm::EDGetToken InputTagToken_
const std::vector< const GEMRegion * > & regions() const
Return a vector of all GEM regions.
Definition: GEMGeometry.cc:43
T z() const
Definition: PV3DBase.h:64
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
std::unordered_map< UInt_t, MonitorElement * > recHits_simple_zr
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
MonitorElement * BookHist1D(DQMStore::IBooker &, const char *name, const char *label, unsigned int region_num, unsigned int station_num, unsigned int layer_num, const unsigned int Nbin, const Float_t xMin, const Float_t xMax)
GEMRecHitsValidation(const edm::ParameterSet &)
void analyze(const edm::Event &e, const edm::EventSetup &) override
bool isValid() const
Definition: HandleBase.h:74
const GeomDet * idToDet(DetId) const override
Definition: GEMGeometry.cc:38
MonitorElement * getDCEta(DQMStore::IBooker &, const GEMStation *, TString, TString)
MonitorElement * gem_pullY[2][3][2]
std::unordered_map< UInt_t, MonitorElement * > recHits_dcEta
MonitorElement * gem_region_pullX[2]
T x() const
Definition: PV3DBase.h:62
edm::EDGetToken InputTagToken_RH
Definition: Run.h:45