CMS 3D CMS Logo

DTChamberEfficiencyTask.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author G. Mila - INFN Torino
5  */
6 
8 
9 //Framework
13 
16 
17 //Geometry
19 
20 #include <iterator>
21 #include <iostream>
22 #include <cmath>
23 using namespace edm;
24 using namespace std;
25 
27  debug = pset.getUntrackedParameter<bool>("debug", false);
28 
29  edm::LogVerbatim("DTDQM|DTMonitorModule|DTChamberEfficiencyTask") << "[DTChamberEfficiencyTask] Constructor called!";
30 
31  parameters = pset;
32 
33  // the name of the 4D rec hits collection
34  recHits4DToken_ =
35  consumes<DTRecSegment4DCollection>(edm::InputTag(parameters.getParameter<string>("recHits4DLabel")));
36 
37  // parameters to use for the segment quality check
38  theMinHitsSegment = static_cast<unsigned int>(parameters.getParameter<int>("minHitsSegment"));
39  theMinChi2NormSegment = parameters.getParameter<double>("minChi2NormSegment");
40  // parameter to use for the exstrapolated segment check
41  theMinCloseDist = parameters.getParameter<double>("minCloseDist");
42 
43  // the running modality
44  onlineMonitor = parameters.getUntrackedParameter<bool>("onlineMonitor");
45 
46  // the analysis mode
47  detailedAnalysis = parameters.getUntrackedParameter<bool>("detailedAnalysis");
48 }
49 
51  edm::LogVerbatim("DTDQM|DTMonitorModule|DTChamberEfficiencyTask") << "[DTChamberEfficiencyTask] Destructor called!";
52 }
53 
55  edm::LogVerbatim("DTDQM|DTMonitorModule|DTChamberEfficiencyTask")
56  << "[DTChamberEfficiencyTask]: Begin of LS transition";
57 
58  if (lumiSeg.id().luminosityBlock() % parameters.getUntrackedParameter<int>("ResetCycle", 3) == 0 && onlineMonitor) {
59  for (map<DTChamberId, vector<MonitorElement*> >::const_iterator histo = histosPerCh.begin();
60  histo != histosPerCh.end();
61  histo++) {
62  int size = (*histo).second.size();
63  for (int i = 0; i < size; i++) {
64  (*histo).second[i]->Reset();
65  }
66  }
67  }
68 }
69 
71  // Get the DT Geometry
72  setup.get<MuonGeometryRecord>().get(dtGeom);
73 }
74 
76  edm::Run const& iRun,
77  edm::EventSetup const& context) {
78  ibooker.setCurrentFolder("DT/DTChamberEfficiencyTask");
79 
80  // Loop over all the chambers
81  vector<const DTChamber*>::const_iterator ch_it = dtGeom->chambers().begin();
82  vector<const DTChamber*>::const_iterator ch_end = dtGeom->chambers().end();
83  for (; ch_it != ch_end; ++ch_it) {
84  // histo booking
85  bookHistos(ibooker, (*ch_it)->id());
86  }
87 }
88 
89 // Book a set of histograms for a given Layer
91  edm::LogVerbatim("DTDQM|DTMonitorModule|DTChamberEfficiencyTask") << " Booking histos for CH : " << chId;
92 
93  // Compose the chamber name
94  stringstream wheel;
95  wheel << chId.wheel();
96  stringstream station;
97  station << chId.station();
98  stringstream sector;
99  sector << chId.sector();
100 
101  string HistoName = "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str();
102 
103  ibooker.setCurrentFolder("DT/01-DTChamberEfficiency/Task/Wheel" + wheel.str() + "/Sector" + sector.str() +
104  "/Station" + station.str());
105 
106  // Create the monitor elements
107  vector<MonitorElement*> histos;
108 
109  //efficiency selection cuts
110  // a- number of segments of the top chamber > 0 && number of segments of the bottom chamber > 0
111  // b- number of segments of the middle chamber > 0
112  // c- check of the top and bottom segment quality
113  // d- check if interpolation falls inside the middle chamber
114  // e- check of the middle segment quality
115  // f- check if the distance between the reconstructed and the exstrapolated segments is ok
116 
117  // histo for efficiency with cuts a-/c-/d-
118  histos.push_back(ibooker.book2D(
119  "hEffGoodSegVsPosDen" + HistoName, "Eff vs local position (good) ", 25, -250., 250., 25, -250., 250.));
120  // histo for efficiency with cuts a-/b-/c-/d-/e-/f-
121  histos.push_back(ibooker.book2D("hEffGoodCloseSegVsPosNum" + HistoName,
122  "Eff vs local position (good and close segs) ",
123  25,
124  -250.,
125  250.,
126  25,
127  -250.,
128  250.));
129  if (detailedAnalysis) {
130  histos.push_back(
131  ibooker.book1D("hDistSegFromExtrap" + HistoName, "Distance segments from extrap position ", 200, 0., 200.));
132  // histo for efficiency from segment counting
133  histos.push_back(ibooker.book1D("hNaiveEffSeg" + HistoName, "Naive eff ", 10, 0., 10.));
134  // histo for efficiency with cuts a-/c-
135  histos.push_back(ibooker.book2D(
136  "hEffSegVsPosDen" + HistoName, "Eff vs local position (all) ", 25, -250., 250., 25, -250., 250.));
137  // histo for efficiency with cuts a-/b-/c-/d-
138  histos.push_back(
139  ibooker.book2D("hEffSegVsPosNum" + HistoName, "Eff vs local position ", 25, -250., 250., 25, -250., 250.));
140  // histo for efficiency with cuts a-/b-/c-/d-/e-
141  histos.push_back(ibooker.book2D(
142  "hEffGoodSegVsPosNum" + HistoName, "Eff vs local position (good segs) ", 25, -250., 250., 25, -250., 250.));
143  }
144  histosPerCh[chId] = histos;
145 }
146 
148  edm::LogVerbatim("DTDQM|DTMonitorModule|DTChamberEfficiencyTask")
149  << "[DTChamberEfficiencyTask] Analyze #Run: " << event.id().run() << " #Event: " << event.id().event();
150 
151  // Get the 4D rechit collection from the event
152  event.getByToken(recHits4DToken_, segs);
153 
154  int bottom = 0, top = 0;
155 
156  // Loop over all the chambers
157  vector<const DTChamber*>::const_iterator ch_it = dtGeom->chambers().begin();
158  vector<const DTChamber*>::const_iterator ch_end = dtGeom->chambers().end();
159  for (; ch_it != ch_end; ++ch_it) {
160  DTChamberId ch = (*ch_it)->id();
161  int wheel = ch.wheel();
162  int sector = ch.sector();
163  int station = ch.station();
164 
165  DTChamberId MidId(wheel, station, sector);
166 
167  // get efficiency for MB1 using MB2 and MB3
168  if (station == 1) {
169  bottom = 2;
170  top = 3;
171  }
172 
173  // get efficiency for MB2 using MB1 and MB3
174  if (station == 2) {
175  bottom = 1;
176  top = 3;
177  }
178 
179  // get efficiency for MB2 using MB2 and MB4
180  if (station == 3) {
181  bottom = 2;
182  top = 4;
183  }
184 
185  // get efficiency for MB4 using MB2 and MB3
186  if (station == 4) {
187  bottom = 2;
188  top = 3;
189  }
190 
191  // Select events with (good) segments in Bot and Top
192  DTChamberId BotId(wheel, bottom, sector);
193  DTChamberId TopId(wheel, top, sector);
194 
195  // Get segments in the bottom chambers (if any)
196  DTRecSegment4DCollection::range segsBot = segs->get(BotId);
197  int nSegsBot = segsBot.second - segsBot.first;
198  // check if any segments is there
199  if (nSegsBot == 0)
200  continue;
201 
202  vector<MonitorElement*> histos = histosPerCh[MidId];
203 
204  // Get segments in the top chambers (if any)
205  DTRecSegment4DCollection::range segsTop = segs->get(TopId);
206  int nSegsTop = segsTop.second - segsTop.first;
207 
208  // Select one segment for the bottom chamber
209  const DTRecSegment4D& bestBotSeg = getBestSegment(segsBot);
210 
211  // Select one segment for the top chamber
212  DTRecSegment4D* pBestTopSeg = nullptr;
213  if (nSegsTop > 0)
214  pBestTopSeg = const_cast<DTRecSegment4D*>(&getBestSegment(segsTop));
215  //if top chamber is MB4 sector 10, consider also sector 14
216  if (TopId.station() == 4 && TopId.sector() == 10) {
217  DTChamberId TopId14(wheel, top, 14);
218  DTRecSegment4DCollection::range segsTop14 = segs->get(TopId14);
219  int nSegsTop14 = segsTop14.second - segsTop14.first;
220  nSegsTop += nSegsTop14;
221  if (nSegsTop14) {
222  DTRecSegment4D* pBestTopSeg14 = const_cast<DTRecSegment4D*>(&getBestSegment(segsTop14));
223  // get best between sector 10 and 14
224  pBestTopSeg = const_cast<DTRecSegment4D*>(getBestSegment(pBestTopSeg, pBestTopSeg14));
225  }
226  }
227  if (!pBestTopSeg)
228  continue;
229  const DTRecSegment4D& bestTopSeg = *pBestTopSeg;
230 
231  DTRecSegment4DCollection::range segsMid = segs->get(MidId);
232  int nSegsMid = segsMid.second - segsMid.first;
233 
234  if (detailedAnalysis) {
235  // very trivial efficiency, just count segments
236  histos[3]->Fill(0);
237  if (nSegsMid > 0)
238  histos[3]->Fill(1);
239  }
240 
241  // get position at Mid by interpolating the position (not direction) of best
242  // segment in Bot and Top to Mid surface
243  LocalPoint posAtMid = interpolate(bestBotSeg, bestTopSeg, MidId);
244 
245  // is best segment good enough?
246  if (isGoodSegment(bestBotSeg) && isGoodSegment(bestTopSeg)) {
247  if (detailedAnalysis)
248  histos[4]->Fill(posAtMid.x(), posAtMid.y());
249  //check if interpolation fall inside middle chamber
250  if ((dtGeom->chamber(MidId))->surface().bounds().inside(posAtMid)) {
251  histos[0]->Fill(posAtMid.x(), posAtMid.y());
252  if (nSegsMid > 0) {
253  if (detailedAnalysis) {
254  histos[3]->Fill(2);
255  histos[5]->Fill(posAtMid.x(), posAtMid.y());
256  }
257 
258  const DTRecSegment4D& bestMidSeg = getBestSegment(segsMid);
259  // check if middle segments is good enough
260  if (isGoodSegment(bestMidSeg)) {
261  if (detailedAnalysis)
262  histos[6]->Fill(posAtMid.x(), posAtMid.y());
263  LocalPoint midSegPos = bestMidSeg.localPosition();
264 
265  // check if middle segments is also close enough
266  double dist;
267  if (bestMidSeg.hasPhi()) {
268  if (bestTopSeg.hasZed() && bestBotSeg.hasZed() && bestMidSeg.hasZed()) {
269  dist = (midSegPos - posAtMid).mag();
270  } else {
271  dist = fabs((midSegPos - posAtMid).x());
272  }
273  } else {
274  dist = fabs((midSegPos - posAtMid).y());
275  }
276  if (dist < theMinCloseDist) {
277  histos[1]->Fill(posAtMid.x(), posAtMid.y());
278  }
279  if (detailedAnalysis)
280  histos[2]->Fill(dist);
281  }
282  }
283  }
284  }
285  } // loop over stations
286 }
287 
288 // requirements : max number of hits and min chi2
291  unsigned int nHitBest = 0;
292  double chi2Best = 99999.;
293  for (DTRecSegment4DCollection::const_iterator seg = segs.first; seg != segs.second; ++seg) {
294  unsigned int nHits = ((*seg).hasPhi() ? (*seg).phiSegment()->recHits().size() : 0);
295  nHits += ((*seg).hasZed() ? (*seg).zSegment()->recHits().size() : 0);
296 
297  if (nHits == nHitBest) {
298  if ((*seg).chi2() / (*seg).degreesOfFreedom() < chi2Best) {
299  chi2Best = (*seg).chi2() / (*seg).degreesOfFreedom();
300  bestIter = seg;
301  }
302  } else if (nHits > nHitBest) {
303  nHitBest = nHits;
304  bestIter = seg;
305  }
306  }
307  return *bestIter;
308 }
309 
311  const DTRecSegment4D* s2) const {
312  if (!s1)
313  return s2;
314  if (!s2)
315  return s1;
316  unsigned int nHits1 = (s1->hasPhi() ? s1->phiSegment()->recHits().size() : 0);
317  nHits1 += (s1->hasZed() ? s1->zSegment()->recHits().size() : 0);
318 
319  unsigned int nHits2 = (s2->hasPhi() ? s2->phiSegment()->recHits().size() : 0);
320  nHits2 += (s2->hasZed() ? s2->zSegment()->recHits().size() : 0);
321 
322  if (nHits1 == nHits2) {
323  if (s1->chi2() / s1->degreesOfFreedom() < s2->chi2() / s2->degreesOfFreedom())
324  return s1;
325  else
326  return s2;
327  } else if (nHits1 > nHits2)
328  return s1;
329  return s2;
330 }
331 
333  const DTRecSegment4D& seg3,
334  const DTChamberId& id2) const {
335  // Get GlobalPoition of Seg in MB1
336  GlobalPoint gpos1 = (dtGeom->chamber(seg1.chamberId()))->toGlobal(seg1.localPosition());
337 
338  // Get GlobalPoition of Seg in MB3
339  GlobalPoint gpos3 = (dtGeom->chamber(seg3.chamberId()))->toGlobal(seg3.localPosition());
340 
341  // interpolate
342  // get all in MB2 frame
343  LocalPoint pos1 = (dtGeom->chamber(id2))->toLocal(gpos1);
344  LocalPoint pos3 = (dtGeom->chamber(id2))->toLocal(gpos3);
345 
346  // case 1: 1 and 3 has both projection. No problem
347 
348  // case 2: one projection is missing for one of the segments. Keep the other's segment position
349  if (!seg1.hasZed())
350  pos1 = LocalPoint(pos1.x(), pos3.y(), pos1.z());
351  if (!seg3.hasZed())
352  pos3 = LocalPoint(pos3.x(), pos1.y(), pos3.z());
353 
354  if (!seg1.hasPhi())
355  pos1 = LocalPoint(pos3.x(), pos1.y(), pos1.z());
356  if (!seg3.hasPhi())
357  pos3 = LocalPoint(pos1.x(), pos3.y(), pos3.z());
358 
359  // direction
360  LocalVector dir = (pos3 - pos1).unit(); // z points inward!
361  LocalPoint pos2 = pos1 + dir * pos1.z() / (-dir.z());
362 
363  return pos2;
364 }
365 
367  if (seg.chamberId().station() != 4 && !seg.hasZed())
368  return false;
369  unsigned int nHits = (seg.hasPhi() ? seg.phiSegment()->recHits().size() : 0);
370  nHits += (seg.hasZed() ? seg.zSegment()->recHits().size() : 0);
371  return (nHits >= theMinHitsSegment && seg.chi2() / seg.degreesOfFreedom() < theMinChi2NormSegment);
372 }
373 
374 // Local Variables:
375 // show-trailing-whitespace: t
376 // truncate-lines: t
377 // End:
size
Write out results.
LuminosityBlockID id() const
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
Definition: DQMStore.cc:239
T getUntrackedParameter(std::string const &, T const &) const
LocalPoint localPosition() const override
Local position in Chamber frame.
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
double chi2() const override
Chi2 of the segment fit.
T y() const
Definition: PV3DBase.h:60
virtual DTChamberId chamberId() const
The (specific) DetId of the chamber on which the segment resides.
void dqmBeginRun(const edm::Run &run, const edm::EventSetup &setup) override
BeginRun.
LocalVector toLocal(const reco::Track::Vector &v, const Surface &s)
void bookHistos()
Definition: Histogram.h:33
~DTChamberEfficiencyTask() override
Destructor.
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &context) override
To reset the MEs.
T z() const
Definition: PV3DBase.h:61
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
LocalPoint interpolate(const DTRecSegment4D &seg1, const DTRecSegment4D &seg3, const DTChamberId &MB2) const
bool hasPhi() const
Does it have the Phi projection?
DTChamberEfficiencyTask(const edm::ParameterSet &pset)
Constructor.
bool hasZed() const
Does it have the Z projection?
#define debug
Definition: HDRShower.cc:19
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
bool isGoodSegment(const DTRecSegment4D &seg) const
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
LuminosityBlockNumber_t luminosityBlock() const
const DTRecSegment4D & getBestSegment(const DTRecSegment4DCollection::range &segs) const
std::string HistoName
histos
Definition: combine.py:4
HLT enums.
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: DQMStore.cc:266
int sector() const
Definition: DTChamberId.h:49
T get() const
Definition: EventSetup.h:73
std::vector< const TrackingRecHit * > recHits() const override
Access to component RecHits (if any)
int station() const
Return the station number.
Definition: DTChamberId.h:42
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
void bookHistos(DQMStore::IBooker &ibooker, DTChamberId chId)
T x() const
Definition: PV3DBase.h:59
int degreesOfFreedom() const override
Degrees of freedom of the segment fit.
Definition: event.py:1
Definition: Run.h:45
Basic3DVector unit() const