CMS 3D CMS Logo

DTTnPEfficiencyTask.cc
Go to the documentation of this file.
1 /*
2  * \file DTTnPEfficiencyTask.cc
3  *
4  * \author L. Lunerti - INFN Bologna
5  *
6  */
7 
9 
11 
13 
15 public:
18 
20  ~DTTnPEfficiencyTask() override;
21 
22 protected:
23  std::string topFolder() const override;
24 
25  void bookHistograms(DQMStore::IBooker& iBooker, edm::Run const& run, edm::EventSetup const& context) override;
26 
28  void bookWheelHistos(DQMStore::IBooker& iBooker, int wheel, std::string folder = "");
29 
31  void analyze(const edm::Event& event, const edm::EventSetup& context) override;
32 };
33 
35  LogTrace("DQMOffline|MuonDPG|DTTnPEfficiencyTask") << "[DTTnPEfficiencyTask]: Constructor" << std::endl;
36 }
37 
39  LogTrace("DQMOffline|MuonDPG|DTTnPEfficiencyTask")
40  << "[DTTnPEfficiencyTask]: analyzed " << m_nEvents << " events" << std::endl;
41 }
42 
44  edm::Run const& run,
45  edm::EventSetup const& context) {
47 
48  LogTrace("DQMOffline|MuonDPG|DTTnPEfficiencyTask") << "[DTTnPEfficiencyTask]: bookHistograms" << std::endl;
49 
50  for (int wheel = -2; wheel <= 2; ++wheel) {
51  bookWheelHistos(iBooker, wheel, "Task");
52  }
53  auto baseDir = topFolder() + "Task/";
54  iBooker.setCurrentFolder(baseDir);
55 
56  MonitorElement* me_DT_pass_allCh = iBooker.book1D("DT_nPassingProbe_allCh", "DT_nPassingProbe_allCh", 20, 0.5, 20.5);
57  MonitorElement* me_DT_fail_allCh = iBooker.book1D("DT_nFailingProbe_allCh", "DT_nFailingProbe_allCh", 20, 0.5, 20.5);
58 
59  me_DT_pass_allCh->setBinLabel(1, "MB1/YB-2", 1);
60  me_DT_pass_allCh->setBinLabel(2, "MB2/YB-2", 1);
61  me_DT_pass_allCh->setBinLabel(3, "MB3/YB-2", 1);
62  me_DT_pass_allCh->setBinLabel(4, "MB4/YB-2", 1);
63  me_DT_pass_allCh->setBinLabel(5, "MB1/YB-1", 1);
64  me_DT_pass_allCh->setBinLabel(6, "MB2/YB-1", 1);
65  me_DT_pass_allCh->setBinLabel(7, "MB3/YB-1", 1);
66  me_DT_pass_allCh->setBinLabel(8, "MB4/YB-1", 1);
67  me_DT_pass_allCh->setBinLabel(9, "MB1/YB0", 1);
68  me_DT_pass_allCh->setBinLabel(10, "MB2/YB0", 1);
69  me_DT_pass_allCh->setBinLabel(11, "MB3/YB0", 1);
70  me_DT_pass_allCh->setBinLabel(12, "MB4/YB0", 1);
71  me_DT_pass_allCh->setBinLabel(13, "MB1/YB1", 1);
72  me_DT_pass_allCh->setBinLabel(14, "MB2/YB1", 1);
73  me_DT_pass_allCh->setBinLabel(15, "MB3/YB1", 1);
74  me_DT_pass_allCh->setBinLabel(16, "MB4/YB1", 1);
75  me_DT_pass_allCh->setBinLabel(17, "MB1/YB2", 1);
76  me_DT_pass_allCh->setBinLabel(18, "MB2/YB2", 1);
77  me_DT_pass_allCh->setBinLabel(19, "MB3/YB2", 1);
78  me_DT_pass_allCh->setBinLabel(20, "MB4/YB2", 1);
79  me_DT_pass_allCh->setAxisTitle("Number of passing probes", 2);
80 
81  me_DT_fail_allCh->setBinLabel(1, "MB1/YB-2", 1);
82  me_DT_fail_allCh->setBinLabel(2, "MB2/YB-2", 1);
83  me_DT_fail_allCh->setBinLabel(3, "MB3/YB-2", 1);
84  me_DT_fail_allCh->setBinLabel(4, "MB4/YB-2", 1);
85  me_DT_fail_allCh->setBinLabel(5, "MB1/YB-1", 1);
86  me_DT_fail_allCh->setBinLabel(6, "MB2/YB-1", 1);
87  me_DT_fail_allCh->setBinLabel(7, "MB3/YB-1", 1);
88  me_DT_fail_allCh->setBinLabel(8, "MB4/YB-1", 1);
89  me_DT_fail_allCh->setBinLabel(9, "MB1/YB0", 1);
90  me_DT_fail_allCh->setBinLabel(10, "MB2/YB0", 1);
91  me_DT_fail_allCh->setBinLabel(11, "MB3/YB0", 1);
92  me_DT_fail_allCh->setBinLabel(12, "MB4/YB0", 1);
93  me_DT_fail_allCh->setBinLabel(13, "MB1/YB1", 1);
94  me_DT_fail_allCh->setBinLabel(14, "MB2/YB1", 1);
95  me_DT_fail_allCh->setBinLabel(15, "MB3/YB1", 1);
96  me_DT_fail_allCh->setBinLabel(16, "MB4/YB1", 1);
97  me_DT_fail_allCh->setBinLabel(17, "MB1/YB2", 1);
98  me_DT_fail_allCh->setBinLabel(18, "MB2/YB2", 1);
99  me_DT_fail_allCh->setBinLabel(19, "MB3/YB2", 1);
100  me_DT_fail_allCh->setBinLabel(20, "MB4/YB2", 1);
101  me_DT_fail_allCh->setAxisTitle("Number of failing probes", 2);
102 
103  m_histos["DT_nPassingProbe_allCh"] = me_DT_pass_allCh;
104  m_histos["DT_nFailingProbe_allCh"] = me_DT_fail_allCh;
105 }
106 
109 
111  event.getByToken(m_muToken, muons);
112 
113  //DT variables
114  std::vector<std::vector<int>> probe_coll_DT_wh;
115  std::vector<std::vector<int>> probe_coll_DT_sec;
116  std::vector<std::vector<int>> probe_coll_DT_sta;
117  std::vector<std::vector<float>> probe_coll_DT_dx;
118  std::vector<uint8_t> probe_coll_DT_staMatch;
119 
120  std::vector<unsigned> probe_indices;
121  if (!m_probeIndices.empty())
122  probe_indices = m_probeIndices.back();
123 
124  //Fill probe dx + subdetector coordinates
125  for (const auto i : probe_indices) {
126  //DT variables
127  std::vector<int> probe_DT_wh;
128  std::vector<int> probe_DT_sec;
129  std::vector<int> probe_DT_sta;
130  std::vector<float> probe_DT_dx;
131  uint8_t DT_stationMatching = 0;
132 
133  float dt_matched = false; // fill detailed plots only for probes matching DT
134 
135  for (const auto& chambMatch : (*muons).at(i).matches()) {
136  // look in DTs
137  if (chambMatch.detector() == MuonSubdetId::DT) {
138  if (chambMatch.edgeX < m_borderCut && chambMatch.edgeY < m_borderCut) {
139  dt_matched = true; //fill detailed plots if at least one CSC match
140 
141  DTChamberId chId(chambMatch.id.rawId());
142 
143  int wheel = chId.wheel();
144  int sector = chId.sector();
145  int station = chId.station();
146 
147  reco::MuonSegmentMatch closest_matchedSegment;
148  double smallestDx = 999.;
149 
150  for (auto& seg : chambMatch.segmentMatches) {
151  float dx = std::abs(chambMatch.x - seg.x);
152  if (dx < smallestDx) {
153  smallestDx = dx;
154  closest_matchedSegment = seg;
155  }
156  }
157 
158  DT_stationMatching = DT_stationMatching | (1 << (station - 1));
159 
160  probe_DT_wh.push_back(wheel);
161  probe_DT_sec.push_back(sector);
162  probe_DT_sta.push_back(station);
163  probe_DT_dx.push_back(smallestDx);
164  }
165  } else
166  continue;
167  } //loop over chamber matches
168 
169  //Fill detailed plots
170  if (m_detailedAnalysis && dt_matched) {
171  m_histos.find("probeEta")->second->Fill((*muons).at(i).eta());
172  m_histos.find("probePhi")->second->Fill((*muons).at(i).phi());
173  m_histos.find("probeNumberOfMatchedStations")->second->Fill((*muons).at(i).numberOfMatchedStations());
174  m_histos.find("probePt")->second->Fill((*muons).at(i).pt());
175  }
176 
177  //Fill DT variables
178  probe_coll_DT_wh.push_back(probe_DT_wh);
179  probe_coll_DT_sec.push_back(probe_DT_sec);
180  probe_coll_DT_sta.push_back(probe_DT_sta);
181  probe_coll_DT_dx.push_back(probe_DT_dx);
182  probe_coll_DT_staMatch.push_back(DT_stationMatching);
183  } //loop over probe collection
184 
185  //Loop over probes
186  for (unsigned i = 0; i < probe_indices.size(); ++i) {
187  uint8_t DT_matchPatt = probe_coll_DT_staMatch.at(i);
188 
189  //Loop over DT matches
190  unsigned nDT_matches = probe_coll_DT_wh.at(i).size();
191  for (unsigned j = 0; j < nDT_matches; ++j) {
192  //DT variables
193  int DT_wheel = probe_coll_DT_wh.at(i).at(j);
194  int DT_station = probe_coll_DT_sta.at(i).at(j);
195  int DT_sector = probe_coll_DT_sec.at(i).at(j);
196  float DT_dx = probe_coll_DT_dx.at(i).at(j);
197 
198  //Fill DT plots
199  if ((DT_matchPatt & (1 << (DT_station - 1))) != 0 && //avoids 0 station matching
200  (DT_matchPatt & (1 << (DT_station - 1))) !=
201  DT_matchPatt) //avoids matching with the station under consideration only
202  {
203  if (DT_dx < m_dxCut) {
204  std::string hName = std::string("DT_nPassingProbePerCh_W") + std::to_string(DT_wheel);
205  m_histos.find(hName)->second->Fill(DT_sector, DT_station);
206  m_histos.find("DT_nPassingProbe_allCh")->second->Fill((DT_station) + 4 * (DT_wheel + 2));
207  } else {
208  std::string hName = std::string("DT_nFailingProbePerCh_W") + std::to_string(DT_wheel);
209  m_histos.find(hName)->second->Fill(DT_sector, DT_station);
210  m_histos.find("DT_nFailingProbe_allCh")->second->Fill((DT_station) + 4 * (DT_wheel + 2));
211  }
212  }
213  }
214  }
215 }
216 
218  auto baseDir = topFolder() + folder + "/";
219  iBooker.setCurrentFolder(baseDir);
220 
221  LogTrace("DQMOffline|MuonDPG|DTTnPEfficiencyTask")
222  << "[DTTnPEfficiencyTask]: booking histos in " << baseDir << std::endl;
223 
224  auto hName_DT_pass = std::string("DT_nPassingProbePerCh_W") + std::to_string(wheel);
225  auto hName_DT_fail = std::string("DT_nFailingProbePerCh_W") + std::to_string(wheel);
226 
227  MonitorElement* me_DT_pass = iBooker.book2D(hName_DT_pass.c_str(), hName_DT_pass.c_str(), 14, 0.5, 14.5, 4, 0., 4.5);
228  MonitorElement* me_DT_fail = iBooker.book2D(hName_DT_fail.c_str(), hName_DT_fail.c_str(), 14, 0.5, 14.5, 4, 0., 4.5);
229 
230  me_DT_pass->setBinLabel(1, "MB1", 2);
231  me_DT_pass->setBinLabel(2, "MB2", 2);
232  me_DT_pass->setBinLabel(3, "MB3", 2);
233  me_DT_pass->setBinLabel(4, "MB4", 2);
234  for (int i = 1; i < 15; ++i) {
235  me_DT_pass->setBinLabel(i, std::to_string(i), 1);
236  }
237  me_DT_pass->setAxisTitle("Sector", 1);
238  me_DT_pass->setAxisTitle("Number of passing probes", 3);
239 
240  me_DT_fail->setBinLabel(1, "MB1", 2);
241  me_DT_fail->setBinLabel(2, "MB2", 2);
242  me_DT_fail->setBinLabel(3, "MB3", 2);
243  me_DT_fail->setBinLabel(4, "MB4", 2);
244  for (int i = 1; i < 15; ++i) {
245  me_DT_fail->setBinLabel(i, std::to_string(i), 1);
246  }
247  me_DT_fail->setAxisTitle("Sector", 1);
248  me_DT_fail->setAxisTitle("Number of failing probes", 3);
249 
250  m_histos[hName_DT_pass] = me_DT_pass;
251  m_histos[hName_DT_fail] = me_DT_fail;
252 }
253 
254 std::string DTTnPEfficiencyTask::topFolder() const { return "DT/Segment_TnP/"; };
255 
~DTTnPEfficiencyTask() override
Destructor.
void bookWheelHistos(DQMStore::IBooker &iBooker, int wheel, std::string folder="")
Book wheel granularity histograms.
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void bookHistograms(DQMStore::IBooker &iBooker, edm::Run const &run, edm::EventSetup const &context) override
const edm::EDGetTokenT< reco::MuonCollection > m_muToken
std::string to_string(const V &value)
Definition: OMSAccess.h:71
Definition: config.py:1
#define LogTrace(id)
std::vector< std::vector< unsigned > > m_probeIndices
std::string topFolder() const override
Return the top folder.
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::map< std::string, MonitorElement * > m_histos
void analyze(const edm::Event &event, const edm::EventSetup &context) override
Analyze.
virtual void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
DTTnPEfficiencyTask(const edm::ParameterSet &config)
Constructor.
void bookHistograms(DQMStore::IBooker &iBooker, edm::Run const &run, edm::EventSetup const &context) override
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
void analyze(const edm::Event &event, const edm::EventSetup &context) override
Analyze.
static constexpr int DT
Definition: MuonSubdetId.h:11
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
Definition: event.py:1
Definition: Run.h:45
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)