CMS 3D CMS Logo

ME0SegmentsValidation.cc
Go to the documentation of this file.
3 #include <TMath.h>
4 
6  InputTagToken_Segments = consumes<ME0SegmentCollection>(cfg.getParameter<edm::InputTag>("segmentInputLabel"));
7  InputTagToken_Digis = consumes<ME0DigiPreRecoCollection>(cfg.getParameter<edm::InputTag>("digiInputLabel"));
8  InputTagToken_ = consumes<edm::PSimHitContainer>(cfg.getParameter<edm::InputTag>("simInputLabel"));
9  InputTagTokenST_ = consumes<edm::SimTrackContainer>(cfg.getParameter<edm::InputTag>("simInputLabelST"));
10  sigma_x_ = cfg.getParameter<double>("sigma_x");
11  sigma_y_ = cfg.getParameter<double>("sigma_y");
12  eta_max_ = cfg.getParameter<double>("eta_max");
13  eta_min_ = cfg.getParameter<double>("eta_min");
14  pt_min_ = cfg.getParameter<double>("pt_min");
15  isMuonGun_ = cfg.getParameter<bool>("isMuonGun");
16 }
17 
19  edm::Run const &Run,
20  edm::EventSetup const &iSetup) {
21  LogDebug("MuonME0SegmentsValidation") << "Info : Loading Geometry information\n";
22  ibooker.setCurrentFolder("MuonME0RecHitsV/ME0SegmentsTask");
23 
24  unsigned int nregion = 2;
25 
26  edm::LogInfo("MuonME0SegmentsValidation") << "+++ Info : # of region : " << nregion << std::endl;
27 
28  LogDebug("MuonME0SegmentsValidation") << "+++ Info : finish to get geometry information from ES.\n";
29 
30  me0_simsegment_eta = ibooker.book1D("me0_simsegment_eta", "SimSegment Eta Distribution; #eta; entries", 8, 2.0, 2.8);
31  me0_simsegment_pt = ibooker.book1D("me0_simsegment_pt", "SimSegment pT Distribution; p_{T}; entries", 20, 0.0, 100.0);
33  ibooker.book1D("me0_simsegment_phi", "SimSegments phi Distribution; #phi; entries", 18, -M_PI, +M_PI);
34 
36  ibooker.book1D("me0_matchedsimsegment_eta", "Matched SimSegment Eta Distribution; #eta; entries", 8, 2.0, 2.8);
38  ibooker.book1D("me0_matchedsimsegment_pt", "Matched SimSegment pT Distribution; p_{T}; entries", 20, 0.0, 100.0);
40  "me0_matchedsimsegment_phi", "Matched SimSegments phi Distribution; #phi; entries", 18, -M_PI, +M_PI);
41 
42  me0_segment_chi2 = ibooker.book1D("me0_seg_Chi2", "#chi^{2}; #chi^{2}; # Segments", 100, 0, 100);
43  me0_segment_redchi2 = ibooker.book1D("me0_seg_ReducedChi2", "#chi^{2}/ndof; #chi^{2}/ndof; # Segments", 100, 0, 5);
44  me0_segment_ndof = ibooker.book1D("me0_seg_ndof", "ndof; ndof; #Segments", 50, 0, 50);
46  ibooker.book1D("me0_seg_NumberRH", "Number of fitted RecHits; # RecHits; entries", 11, -0.5, 10.5);
48  ibooker.book1D("me0_seg_NumberRHSig", "Number of fitted Signal RecHits; # RecHits; entries", 11, -0.5, 10.5);
50  ibooker.book1D("me0_seg_NumberRHBkg", "Number of fitted BKG RecHits; # RecHits; entries", 11, -0.5, 10.5);
51  // me0_segment_EtaRH = ibooker.book1D("me0_specRH_globalEta","Fitted RecHits
52  // Eta Distribution; #eta; entries",200,-4.0,4.0); me0_segment_PhiRH =
53  // ibooker.book1D("me0_specRH_globalPhi","Fitted RecHits Phi Distribution;
54  // #eta; entries",18,-3.14,3.14);
55  me0_segment_time = ibooker.book1D("me0_seg_time", "Segment Timing; ns; entries", 300, -150, 150);
56  me0_segment_timeErr = ibooker.book1D("me0_seg_timErr", "Segment Timing Error; ns; entries", 50, 0, 0.5);
58  ibooker.book1D("me0_seg_size", "Segment Multiplicity; Number of ME0 segments; entries", 200, 0, 200);
59 
60  for (unsigned int region_num = 0; region_num < nregion; region_num++) {
61  me0_specRH_zr[region_num] = BookHistZR(ibooker, "me0_specRH_tot", "Segment RecHits", region_num);
62  for (unsigned int layer_num = 0; layer_num < 6; layer_num++) {
63  // me0_strip_dg_zr[region_num][layer_num] =
64  // BookHistZR(ibooker,"me0_strip_dg","SimHit",region_num,layer_num);
65  me0_specRH_xy[region_num][layer_num] =
66  BookHistXY(ibooker, "me0_specRH", "Segment RecHits", region_num, layer_num);
67  // me0_rh_xy_Muon[region_num][layer_num] =
68  // BookHistXY(ibooker,"me0_rh","RecHit Muon",region_num,layer_num);
69 
70  std::string histo_name_DeltaX =
71  std::string("me0_specRH_DeltaX_r") + regionLabel[region_num] + "_l" + layerLabel[layer_num];
72  std::string histo_name_DeltaY =
73  std::string("me0_specRH_DeltaY_r") + regionLabel[region_num] + "_l" + layerLabel[layer_num];
74  std::string histo_label_DeltaX = "Segment RecHits Delta X : region" + regionLabel[region_num] + " layer " +
75  layerLabel[layer_num] + " " + " ; x_{SimHit} - x_{Segment RecHits} ; entries";
76  std::string histo_label_DeltaY = "Segment RecHits Delta Y : region" + regionLabel[region_num] + " layer " +
77  layerLabel[layer_num] + " " + " ; y_{SimHit} - y_{Segment RecHit} ; entries";
78 
79  me0_specRH_DeltaX[region_num][layer_num] =
80  ibooker.book1D(histo_name_DeltaX.c_str(), histo_label_DeltaX.c_str(), 100, -10, 10);
81  me0_specRH_DeltaY[region_num][layer_num] =
82  ibooker.book1D(histo_name_DeltaY.c_str(), histo_label_DeltaY.c_str(), 100, -10, 10);
83 
84  std::string histo_name_PullX =
85  std::string("me0_specRH_PullX_r") + regionLabel[region_num] + "_l" + layerLabel[layer_num];
86  std::string histo_name_PullY =
87  std::string("me0_specRH_PullY_r") + regionLabel[region_num] + "_l" + layerLabel[layer_num];
88  std::string histo_label_PullX = "Segment RecHits Pull X : region" + regionLabel[region_num] + " layer " +
89  layerLabel[layer_num] + " " +
90  " ; #frac{x_{SimHit} - x_{Segment "
91  "RecHit}}{#sigma_{x,RecHit}} ; entries";
92  std::string histo_label_PullY = "Segment RecHits Pull Y : region" + regionLabel[region_num] + " layer " +
93  layerLabel[layer_num] + " " +
94  " ; #frac{y_{SimHit} - y_{Segment "
95  "RecHit}}{#sigma_{y,RecHit}} ; entries";
96 
97  me0_specRH_PullX[region_num][layer_num] =
98  ibooker.book1D(histo_name_PullX.c_str(), histo_label_DeltaX.c_str(), 100, -10, 10);
99  me0_specRH_PullY[region_num][layer_num] =
100  ibooker.book1D(histo_name_PullY.c_str(), histo_label_DeltaY.c_str(), 100, -10, 10);
101  }
102  }
103 }
104 
106 
108  const ME0Geometry *ME0Geometry_ = &iSetup.getData(geomToken_);
109 
111  e.getByToken(InputTagToken_, ME0Hits);
112 
114  e.getByToken(InputTagTokenST_, simTracks);
115 
117  e.getByToken(InputTagToken_Segments, ME0Segments);
118 
120  e.getByToken(InputTagToken_Digis, ME0Digis);
121 
122  if (!ME0Digis.isValid()) {
123  edm::LogError("ME0SegmentsValidation") << "Cannot get ME0Digis by Token InputTagToken";
124  return;
125  }
126 
127  if (!ME0Segments.isValid()) {
128  edm::LogError("ME0SegmentsValidation") << "Cannot get ME0RecHits/ME0Segments by Token InputTagToken";
129  return;
130  }
131 
132  if (!ME0Hits.isValid()) {
133  edm::LogError("ME0HitsValidation") << "Cannot get ME0Hits by Token simInputTagToken";
134  return;
135  }
136 
137  MapTypeSim myMap;
138  MapTypeSeg myMapSeg;
139 
140  edm::SimTrackContainer::const_iterator simTrack;
141  for (simTrack = simTracks->begin(); simTrack != simTracks->end(); ++simTrack) {
142  edm::PSimHitContainer selectedME0Hits;
143 
144  if (!isSimTrackGood(simTrack))
145  continue;
146 
147  for (edm::PSimHitContainer::const_iterator itHit = ME0Hits->begin(); itHit != ME0Hits->end(); ++itHit) {
148  int particleType_sh = itHit->particleType();
149  int evtId_sh = itHit->eventId().event();
150  int bx_sh = itHit->eventId().bunchCrossing();
151  int procType_sh = itHit->processType();
152  if (!(abs(particleType_sh) == 13 && evtId_sh == 0 && bx_sh == 0 && procType_sh == 0))
153  continue;
154 
155  if (isSimMatched(simTrack, itHit)) {
156  selectedME0Hits.push_back(*itHit);
157  ;
158  }
159 
160  } // End loop SHs
161 
162  if (selectedME0Hits.size() >= 3) {
163  myMap.insert(MapTypeSim::value_type(simTrack, selectedME0Hits));
164  me0_simsegment_eta->Fill(std::abs((*simTrack).momentum().eta()));
165  me0_simsegment_pt->Fill((*simTrack).momentum().pt());
166  me0_simsegment_phi->Fill((*simTrack).momentum().phi());
167  }
168  }
169 
170  me0_segment_size->Fill(ME0Segments->size());
171 
172  for (auto me0s = ME0Segments->begin(); me0s != ME0Segments->end(); me0s++) {
173  // The ME0 Ensamble DetId refers to layer = 1
174  ME0DetId id = me0s->me0DetId();
175  auto chamber = ME0Geometry_->chamber(id);
176  auto segLP = me0s->localPosition();
177  auto segLD = me0s->localDirection();
178  auto me0rhs = me0s->specificRecHits();
179 
180  // float localX = segLP.x();
181  // float localY = segLP.y();
182  // float dirTheta = segLD.theta();
183  // float dirPhi = segLD.phi();
184  int numberRH = me0rhs.size();
185  float chi2 = (float)me0s->chi2();
186  float ndof = me0s->degreesOfFreedom();
187  double time = me0s->time();
188  double timeErr = me0s->timeErr();
189 
190  float reducedChi2 = chi2 / ndof;
191 
193  me0_segment_redchi2->Fill(reducedChi2);
195  me0_segment_numRH->Fill(numberRH);
196 
198  me0_segment_timeErr->Fill(timeErr);
199 
200  int numberRHSig = 0;
201  int numberRHBkg = 0;
202  std::vector<ME0RecHit> selectedME0RecHits;
203 
204  for (auto rh = me0rhs.begin(); rh != me0rhs.end(); rh++) {
205  auto me0id = rh->me0Id();
206  auto rhr = ME0Geometry_->etaPartition(me0id);
207  auto rhLP = rh->localPosition();
208 
209  auto result = isMatched(me0id, rhLP, ME0Digis);
210  if (result.second == 1) {
211  ++numberRHSig;
212  selectedME0RecHits.push_back(*rh);
213 
214  } else
215  ++numberRHBkg;
216 
217  auto erhLEP = rh->localPositionError();
218  auto rhGP = rhr->toGlobal(rhLP);
219  auto rhLPSegm = chamber->toLocal(rhGP);
220  float xe = segLP.x() + segLD.x() * rhLPSegm.z() / segLD.z();
221  float ye = segLP.y() + segLD.y() * rhLPSegm.z() / segLD.z();
222  float ze = rhLPSegm.z();
223  LocalPoint extrPoint(xe, ye, ze); // in segment rest frame
224  auto extSegm = rhr->toLocal(chamber->toGlobal(extrPoint)); // in layer restframe
225 
226  int region = me0id.region();
227  int layer = me0id.layer();
228  // int chamber = me0id.chamber();
229 
230  float x = rhLP.x();
231  float xErr = erhLEP.xx();
232  float y = rhLP.y();
233  float yErr = erhLEP.yy();
234 
235  float globalR = rhGP.perp();
236  float globalX = rhGP.x();
237  float globalY = rhGP.y();
238  float globalZ = rhGP.z();
239 
240  float xExt = extSegm.x();
241  float yExt = extSegm.y();
242 
243  float pull_x = (x - xExt) / sqrt(xErr);
244  float pull_y = (y - yExt) / sqrt(yErr);
245 
246  int region_num = 0;
247  if (region == -1)
248  region_num = 0;
249  else if (region == 1)
250  region_num = 1;
251  int layer_num = layer - 1;
252 
253  me0_specRH_xy[region_num][layer_num]->Fill(globalX, globalY);
254  me0_specRH_zr[region_num]->Fill(globalZ, globalR);
255 
256  me0_specRH_DeltaX[region_num][layer_num]->Fill(x - xExt);
257  me0_specRH_DeltaY[region_num][layer_num]->Fill(y - yExt);
258  me0_specRH_PullX[region_num][layer_num]->Fill(pull_x);
259  me0_specRH_PullY[region_num][layer_num]->Fill(pull_y);
260  }
261 
262  me0_segment_numRHSig->Fill(numberRHSig);
263  me0_segment_numRHBkg->Fill(numberRHBkg);
264  myMapSeg.insert(MapTypeSeg::value_type(me0s, selectedME0RecHits));
265  }
266 
267  //------------------- SimToReco -------------------
268 
269  for (auto const &st : myMap) { // loop over the signal simTracks
270 
271  int num_sh = st.second.size();
272  bool isThereOneSegmentMatched = false;
273 
274  for (auto const &seg : myMapSeg) { // loop over the reconstructed me0 segments
275 
276  int num_sh_matched = 0;
277  if (seg.second.empty())
278  continue;
279 
280  for (auto const &sh : st.second) { // loop over the me0 simHits left by
281  // the signal simTracks
282 
283  for (auto const &rh : seg.second) { // loop over the tracking recHits
284  // already matched to signal digis
285 
286  auto me0id = rh.me0Id();
287  int region_rh = (int)me0id.region();
288  int layer_rh = (int)me0id.layer();
289  int chamber_rh = (int)me0id.chamber();
290  int roll_rh = (int)me0id.roll();
291 
292  const ME0DetId id(sh.detUnitId());
293  int region_sh = id.region();
294  int layer_sh = id.layer();
295  int chamber_sh = id.chamber();
296  int roll_sh = id.roll();
297 
298  if (!(region_sh == region_rh && chamber_sh == chamber_rh && layer_sh == layer_rh && roll_sh == roll_rh))
299  continue;
300 
301  LocalPoint lp_sh = sh.localPosition();
302  LocalPoint lp_rh = rh.localPosition();
303 
304  GlobalPoint gp_sh = ME0Geometry_->idToDet(id)->surface().toGlobal(lp_sh);
305  GlobalPoint gp = ME0Geometry_->idToDet((rh).me0Id())->surface().toGlobal(lp_rh);
306  float dphi_glob = gp_sh.phi() - gp.phi();
307  float deta_glob = gp_sh.eta() - gp.eta();
308 
309  if (fabs(dphi_glob) < 3 * sigma_x_ && fabs(deta_glob) < 3 * sigma_y_)
310  ++num_sh_matched;
311 
312  } // End loop over RHs
313 
314  } // End loop over SHs
315 
316  float quality = 0;
317  if (num_sh != 0)
318  quality = num_sh_matched / (1.0 * num_sh);
319  if (quality > 0)
320  isThereOneSegmentMatched = true;
321 
322  } // End loop over segments
323 
324  // Fill hsitograms
325  if (isThereOneSegmentMatched) {
326  me0_matchedsimsegment_eta->Fill(std::abs((*(st.first)).momentum().eta()));
327  me0_matchedsimsegment_pt->Fill((*(st.first)).momentum().pt());
328  me0_matchedsimsegment_phi->Fill((*(st.first)).momentum().phi());
329  }
330 
331  } // End loop over STs
332 }
333 
334 std::pair<int, int> ME0SegmentsValidation::isMatched(ME0DetId me0id,
335  LocalPoint rhLP,
337  int region_rh = (int)me0id.region();
338  int layer_rh = (int)me0id.layer();
339  int roll_rh = (int)me0id.roll();
340  int chamber_rh = (int)me0id.chamber();
341 
342  float l_x_rh = rhLP.x();
343  float l_y_rh = rhLP.y();
344 
345  int particleType = 0;
346  int isPrompt = -1;
347 
348  for (ME0DigiPreRecoCollection::DigiRangeIterator cItr = ME0Digis->begin(); cItr != ME0Digis->end(); cItr++) {
349  ME0DetId id = (*cItr).first;
350 
351  int region_dg = (int)id.region();
352  int layer_dg = (int)id.layer();
353  int roll_dg = (int)id.roll();
354  int chamber_dg = (int)id.chamber();
355 
356  if (region_rh != region_dg)
357  continue;
358  if (layer_rh != layer_dg)
359  continue;
360  if (chamber_rh != chamber_dg)
361  continue;
362  if (roll_rh != roll_dg)
363  continue;
364 
366  for (digiItr = (*cItr).second.first; digiItr != (*cItr).second.second; ++digiItr) {
367  float l_x_dg = digiItr->x();
368  float l_y_dg = digiItr->y();
369 
370  if (l_x_rh != l_x_dg)
371  continue;
372  if (l_y_rh != l_y_dg)
373  continue;
374 
375  particleType = digiItr->pdgid();
376  isPrompt = digiItr->prompt();
377  }
378  }
379 
380  std::pair<int, int> result;
381  result = std::make_pair(particleType, isPrompt);
382 
383  return result;
384 }
385 
386 bool ME0SegmentsValidation::isSimTrackGood(edm::SimTrackContainer::const_iterator t) {
387  if ((*t).noVertex() && !isMuonGun_)
388  return false;
389  if ((*t).noGenpart() && !isMuonGun_)
390  return false;
391  if (std::abs((*t).type()) != 13)
392  return false; // only interested in direct muon simtracks
393  if ((*t).momentum().pt() < pt_min_)
394  return false;
395  const float eta(std::abs((*t).momentum().eta()));
396  if (eta < eta_min_ || eta > eta_max_)
397  return false; // no GEMs could be in such eta
398  return true;
399 }
400 
401 bool ME0SegmentsValidation::isSimMatched(edm::SimTrackContainer::const_iterator simTrack,
402  edm::PSimHitContainer::const_iterator itHit) {
403  bool result = false;
404  int trackId = simTrack->trackId();
405  int trackId_sim = itHit->trackId();
406  if (trackId == trackId_sim)
407  result = true;
408  return result;
409 }
bool isSimTrackGood(edm::SimTrackContainer::const_iterator simTrack)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
MonitorElement * me0_segment_redchi2
MonitorElement * me0_simsegment_pt
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
void analyze(const edm::Event &e, const edm::EventSetup &) override
edm::ESGetToken< ME0Geometry, MuonGeometryRecord > geomToken_
std::vector< std::string > regionLabel
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
T eta() const
Definition: PV3DBase.h:73
edm::EDGetToken InputTagToken_Segments
Log< level::Error, false > LogError
std::map< edm::SimTrackContainer::const_iterator, edm::PSimHitContainer > MapTypeSim
MonitorElement * BookHistZR(DQMStore::IBooker &, const char *name, const char *label, unsigned int region_num, unsigned int layer_num=99)
MonitorElement * me0_specRH_xy[2][6]
const GeomDet * idToDet(DetId) const override
Definition: ME0Geometry.cc:24
MonitorElement * me0_segment_ndof
void Fill(long long x)
ME0SegmentsValidation(const edm::ParameterSet &)
MonitorElement * BookHistXY(DQMStore::IBooker &, const char *name, const char *label, unsigned int region_num, unsigned int layer_num=99)
string quality
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
int layer() const
Layer id: each chamber has six layers of chambers: layer 1 is the inner layer and layer 6 is the oute...
Definition: ME0DetId.h:44
MonitorElement * me0_segment_numRH
MonitorElement * me0_specRH_DeltaX[2][6]
T sqrt(T t)
Definition: SSEVec.h:23
const ME0Chamber * chamber(ME0DetId id) const
Return a chamber given its id.
Definition: ME0Geometry.cc:43
MonitorElement * me0_segment_time
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
MonitorElement * me0_specRH_PullX[2][6]
MonitorElement * me0_segment_numRHBkg
edm::EDGetToken InputTagTokenST_
std::map< ME0SegmentCollection::const_iterator, std::vector< ME0RecHit > > MapTypeSeg
MonitorElement * me0_matchedsimsegment_phi
edm::EDGetToken InputTagToken_
MonitorElement * me0_segment_timeErr
#define M_PI
int region() const
Region id: 0 for Barrel Not in use, +/-1 For +/- Endcap.
Definition: ME0DetId.h:38
edm::EDGetToken InputTagToken_Digis
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
MonitorElement * me0_specRH_PullY[2][6]
Log< level::Info, false > LogInfo
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
MonitorElement * me0_matchedsimsegment_pt
int chamber() const
Chamber id: it identifies a chamber in a ring it goes from 1 to 36.
Definition: ME0DetId.h:41
std::pair< int, int > isMatched(ME0DetId, LocalPoint, edm::Handle< ME0DigiPreRecoCollection >)
MonitorElement * me0_segment_size
std::vector< DigiType >::const_iterator const_iterator
const ME0EtaPartition * etaPartition(ME0DetId id) const
Return a etaPartition given its id.
Definition: ME0Geometry.cc:35
bool isValid() const
Definition: HandleBase.h:70
MonitorElement * me0_segment_chi2
std::vector< std::string > layerLabel
MonitorElement * me0_simsegment_eta
int roll() const
Definition: ME0DetId.h:48
MonitorElement * me0_segment_numRHSig
MonitorElement * me0_specRH_DeltaY[2][6]
std::vector< PSimHit > PSimHitContainer
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
MonitorElement * me0_simsegment_phi
MonitorElement * me0_matchedsimsegment_eta
bool isSimMatched(edm::SimTrackContainer::const_iterator, edm::PSimHitContainer::const_iterator)
MonitorElement * me0_specRH_zr[2]
Definition: Run.h:45
#define LogDebug(id)