CMS 3D CMS Logo

CSCTnPEfficiencyTask.cc
Go to the documentation of this file.
1 /*
2  * \file CSCTnPEfficiencyTask.cc
3  *
4  * \author L. Lunerti - INFN Bologna
5  *
6  */
7 
9 
11 
13 
15 public:
18 
20  ~CSCTnPEfficiencyTask() 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 analyze(const edm::Event& event, const edm::EventSetup& context) override;
29 };
30 
32  LogTrace("DQMOffline|MuonDPG|CSCTnPEfficiencyTask") << "[CSCTnPEfficiencyTask]: Constructor" << std::endl;
33 }
34 
36  LogTrace("DQMOffline|MuonDPG|CSCTnPEfficiencyTask")
37  << "[CSCTnPEfficiencyTask]: analyzed " << m_nEvents << " events" << std::endl;
38 }
39 
41  edm::Run const& run,
42  edm::EventSetup const& context) {
44 
45  LogTrace("DQMOffline|MuonDPG|CSCTnPEfficiencyTask") << "[CSCTnPEfficiencyTask]: bookHistograms" << std::endl;
46 
47  auto baseDir = topFolder() + "Task/";
48  iBooker.setCurrentFolder(baseDir);
49 
50  MonitorElement* me_CSC_pass_allCh =
51  iBooker.book2D("CSC_nPassingProbe_allCh", "CSC_nPassingProbe_allCh", 9, -4., 5., 4, 0., 4.5);
52  MonitorElement* me_CSC_fail_allCh =
53  iBooker.book2D("CSC_nFailingProbe_allCh", "CSC_nFailingProbe_allCh", 9, -4., 5., 4, 0., 4.5);
54 
55  MonitorElement* me_CSC_pass_allCh_1D =
56  iBooker.book1D("CSC_nPassingProbe_allCh_1D", "CSC_nPassingProbe_allCh_1D", 9, -4., 5.);
57  MonitorElement* me_CSC_fail_allCh_1D =
58  iBooker.book1D("CSC_nFailingProbe_allCh_1D", "CSC_nFailingProbe_allCh_1D", 9, -4., 5.);
59 
60  me_CSC_pass_allCh->setBinLabel(1, "ME-4", 1);
61  me_CSC_pass_allCh->setBinLabel(2, "ME-3", 1);
62  me_CSC_pass_allCh->setBinLabel(3, "ME-2", 1);
63  me_CSC_pass_allCh->setBinLabel(4, "ME-1", 1);
64  me_CSC_pass_allCh->setBinLabel(6, "ME1", 1);
65  me_CSC_pass_allCh->setBinLabel(7, "ME2", 1);
66  me_CSC_pass_allCh->setBinLabel(8, "ME3", 1);
67  me_CSC_pass_allCh->setBinLabel(9, "ME4", 1);
68  for (int i = 1; i < 5; ++i) {
69  me_CSC_pass_allCh->setBinLabel(i, std::to_string(i), 2);
70  }
71  me_CSC_pass_allCh->setAxisTitle("Ring", 2);
72  me_CSC_pass_allCh->setAxisTitle("Number of passing probes", 3);
73 
74  me_CSC_fail_allCh->setBinLabel(1, "ME-4", 1);
75  me_CSC_fail_allCh->setBinLabel(2, "ME-3", 1);
76  me_CSC_fail_allCh->setBinLabel(3, "ME-2", 1);
77  me_CSC_fail_allCh->setBinLabel(4, "ME-1", 1);
78  me_CSC_fail_allCh->setBinLabel(6, "ME1", 1);
79  me_CSC_fail_allCh->setBinLabel(7, "ME2", 1);
80  me_CSC_fail_allCh->setBinLabel(8, "ME3", 1);
81  me_CSC_fail_allCh->setBinLabel(9, "ME4", 1);
82  for (int i = 1; i < 5; ++i) {
83  me_CSC_fail_allCh->setBinLabel(i, std::to_string(i), 2);
84  }
85  me_CSC_fail_allCh->setAxisTitle("Ring", 2);
86  me_CSC_fail_allCh->setAxisTitle("Number of failing probes", 3);
87 
88  me_CSC_pass_allCh_1D->setBinLabel(1, "ME-4", 1);
89  me_CSC_pass_allCh_1D->setBinLabel(2, "ME-3", 1);
90  me_CSC_pass_allCh_1D->setBinLabel(3, "ME-2", 1);
91  me_CSC_pass_allCh_1D->setBinLabel(4, "ME-1", 1);
92  me_CSC_pass_allCh_1D->setBinLabel(6, "ME1", 1);
93  me_CSC_pass_allCh_1D->setBinLabel(7, "ME2", 1);
94  me_CSC_pass_allCh_1D->setBinLabel(8, "ME3", 1);
95  me_CSC_pass_allCh_1D->setBinLabel(9, "ME4", 1);
96  me_CSC_pass_allCh_1D->setAxisTitle("Number of passing probes", 2);
97 
98  me_CSC_fail_allCh_1D->setBinLabel(1, "ME-4", 1);
99  me_CSC_fail_allCh_1D->setBinLabel(2, "ME-3", 1);
100  me_CSC_fail_allCh_1D->setBinLabel(3, "ME-2", 1);
101  me_CSC_fail_allCh_1D->setBinLabel(4, "ME-1", 1);
102  me_CSC_fail_allCh_1D->setBinLabel(6, "ME1", 1);
103  me_CSC_fail_allCh_1D->setBinLabel(7, "ME2", 1);
104  me_CSC_fail_allCh_1D->setBinLabel(8, "ME3", 1);
105  me_CSC_fail_allCh_1D->setBinLabel(9, "ME4", 1);
106  me_CSC_fail_allCh_1D->setAxisTitle("Number of failing probes", 2);
107 
108  m_histos["CSC_nPassingProbe_allCh"] = me_CSC_pass_allCh;
109  m_histos["CSC_nFailingProbe_allCh"] = me_CSC_fail_allCh;
110 
111  m_histos["CSC_nPassingProbe_allCh_1D"] = me_CSC_pass_allCh_1D;
112  m_histos["CSC_nFailingProbe_allCh_1D"] = me_CSC_fail_allCh_1D;
113 }
114 
117 
119  event.getByToken(m_muToken, muons);
120 
121  //CSC variables
122  std::vector<std::vector<int>> probe_coll_CSC_zend;
123  std::vector<std::vector<int>> probe_coll_CSC_ring;
124  std::vector<std::vector<int>> probe_coll_CSC_sta;
125  std::vector<std::vector<float>> probe_coll_CSC_dx;
126  std::vector<uint8_t> probe_coll_CSC_staMatch;
127 
128  std::vector<unsigned> probe_indices;
129  if (!m_probeIndices.empty())
130  probe_indices = m_probeIndices.back();
131 
132  //Fill probe dx + subdetector coordinates
133  for (const auto i : probe_indices) {
134  //CSC variables
135  std::vector<int> probe_CSC_zend;
136  std::vector<int> probe_CSC_ring;
137  std::vector<int> probe_CSC_sta;
138  std::vector<float> probe_CSC_dx;
139  uint8_t CSC_stationMatching = 0;
140 
141  float csc_matched = false; // fill detailed plots only for probes matching CSC
142 
143  for (const auto& chambMatch : (*muons).at(i).matches()) {
144  // look in CSCs
145  if (chambMatch.detector() == MuonSubdetId::CSC) {
146  if (chambMatch.edgeX < m_borderCut && chambMatch.edgeY < m_borderCut) {
147  csc_matched = true; //fill detailed plots if at least one CSC match
148 
149  CSCDetId chId(chambMatch.id.rawId());
150 
151  int zendcap = chId.zendcap();
152  int ring = chId.ring();
153  int station = chId.station();
154 
155  reco::MuonSegmentMatch closest_matchedSegment;
156  double smallestDx = 99999.;
157  for (auto& seg : chambMatch.segmentMatches) {
158  float dx = std::abs(chambMatch.x - seg.x);
159  if (dx < smallestDx) {
160  smallestDx = dx;
161  closest_matchedSegment = seg;
162  }
163  }
164 
165  CSC_stationMatching = CSC_stationMatching | (1 << (station - 1));
166 
167  if (station == 1 && ring == 4 && chambMatch.y < -31.5) {
168  probe_CSC_zend.push_back(zendcap);
169  probe_CSC_ring.push_back(ring);
170  probe_CSC_sta.push_back(station);
171  probe_CSC_dx.push_back(smallestDx);
172  } else if (station == 1 && ring == 1 && chambMatch.y > -31.5) {
173  probe_CSC_zend.push_back(zendcap);
174  probe_CSC_ring.push_back(ring);
175  probe_CSC_sta.push_back(station);
176  probe_CSC_dx.push_back(smallestDx);
177  } else if (station > 1 || ring == 2 || ring == 3) {
178  probe_CSC_zend.push_back(zendcap);
179  probe_CSC_ring.push_back(ring);
180  probe_CSC_sta.push_back(station);
181  probe_CSC_dx.push_back(smallestDx);
182  }
183  }
184  } else
185  continue;
186  } //loop over chamber matches
187 
188  //Fill detailed plots
189  if (m_detailedAnalysis && csc_matched) {
190  m_histos.find("probeEta")->second->Fill((*muons).at(i).eta());
191  m_histos.find("probePhi")->second->Fill((*muons).at(i).phi());
192  m_histos.find("probeNumberOfMatchedStations")->second->Fill((*muons).at(i).numberOfMatchedStations());
193  m_histos.find("probePt")->second->Fill((*muons).at(i).pt());
194  }
195 
196  //Fill CSC variables
197  probe_coll_CSC_zend.push_back(probe_CSC_zend);
198  probe_coll_CSC_ring.push_back(probe_CSC_ring);
199  probe_coll_CSC_sta.push_back(probe_CSC_sta);
200  probe_coll_CSC_dx.push_back(probe_CSC_dx);
201  probe_coll_CSC_staMatch.push_back(CSC_stationMatching);
202  } //loop over probe collection
203 
204  //Loop over probes
205  for (unsigned i = 0; i < probe_indices.size(); ++i) {
206  uint8_t CSC_matchPatt = probe_coll_CSC_staMatch.at(i);
207 
208  //Loop over CSC matches
209  unsigned nCSC_matches = probe_coll_CSC_zend.at(i).size();
210  for (unsigned j = 0; j < nCSC_matches; ++j) {
211  int CSC_zendcap = probe_coll_CSC_zend.at(i).at(j);
212  int CSC_sta = probe_coll_CSC_sta.at(i).at(j);
213  int CSC_ring = probe_coll_CSC_ring.at(i).at(j);
214  float CSC_dx = probe_coll_CSC_dx.at(i).at(j);
215 
216  //Fill CSC plots
217  if ((CSC_matchPatt & (1 << (CSC_sta - 1))) != 0 && //avoids 0 station matching
218  (CSC_matchPatt & (1 << (CSC_sta - 1))) !=
219  CSC_matchPatt) //avoids matching with the station under consideration only
220  {
221  if (CSC_dx < m_dxCut) {
222  m_histos.find("CSC_nPassingProbe_allCh")->second->Fill(CSC_zendcap * CSC_sta, CSC_ring);
223  m_histos.find("CSC_nPassingProbe_allCh_1D")->second->Fill(CSC_zendcap * CSC_sta);
224  } else {
225  m_histos.find("CSC_nFailingProbe_allCh")->second->Fill(CSC_zendcap * CSC_sta, CSC_ring);
226  m_histos.find("CSC_nFailingProbe_allCh_1D")->second->Fill(CSC_zendcap * CSC_sta);
227  }
228  }
229  }
230  }
231 }
232 
233 std::string CSCTnPEfficiencyTask::topFolder() const { return "CSC/Segment_TnP/"; };
234 
short int zendcap() const
Definition: CSCDetId.h:91
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
~CSCTnPEfficiencyTask() override
Destructor.
const edm::EDGetTokenT< reco::MuonCollection > m_muToken
Definition: config.py:1
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:212
static std::string to_string(const XMLCh *ch)
#define LogTrace(id)
void bookHistograms(DQMStore::IBooker &iBooker, edm::Run const &run, edm::EventSetup const &context) override
std::string topFolder() const override
Return the top folder.
std::vector< std::vector< unsigned > > m_probeIndices
void analyze(const edm::Event &event, const edm::EventSetup &context) override
Analyze.
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::map< std::string, MonitorElement * > m_histos
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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)
CSCTnPEfficiencyTask(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
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
static constexpr int CSC
Definition: MuonSubdetId.h:12
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)