CMS 3D CMS Logo

DTLocalTriggerLutTest.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author C. Battilana S. Marcellini - INFN Bologna
5  *
6  * threadsafe version (//-) oct/nov 2014 - WATWanAbdullah ncpp-um-my
7  *
8  */
9 
10 // This class header
12 
13 // Framework headers
17 
18 // Geometry
21 
22 // Root
23 #include "TF1.h"
24 #include "TProfile.h"
25 
26 //C++ headers
27 #include <iostream>
28 #include <sstream>
29 
30 using namespace edm;
31 using namespace std;
32 
34  setConfig(ps, "DTLocalTriggerLut");
35  baseFolderTM = "DT/03-LocalTrigger-TM/";
36  thresholdPhiMean = ps.getUntrackedParameter<double>("thresholdPhiMean", 1.5);
37  thresholdPhiRMS = ps.getUntrackedParameter<double>("thresholdPhiRMS", .5);
38  thresholdPhibMean = ps.getUntrackedParameter<double>("thresholdPhibMean", 1.5);
39  thresholdPhibRMS = ps.getUntrackedParameter<double>("thresholdPhibRMS", .8);
40  doCorrStudy = ps.getUntrackedParameter<bool>("doCorrelationStudy", false);
41 
42  bookingdone = false;
43 }
44 
46 
48  vector<string>::const_iterator iTr = trigSources.begin();
49  vector<string>::const_iterator trEnd = trigSources.end();
50  vector<string>::const_iterator iHw = hwSources.begin();
51  vector<string>::const_iterator hwEnd = hwSources.end();
52 
53  //Booking
54  if (parameters.getUntrackedParameter<bool>("staticBooking", true)) {
55  for (; iTr != trEnd; ++iTr) {
56  trigSource = (*iTr);
57  for (; iHw != hwEnd; ++iHw) {
58  hwSource = (*iHw);
59  // Loop over the TriggerUnits
60  for (int wh = -2; wh <= 2; ++wh) {
61  bookWheelHistos(ibooker, wh, "PhiResidualMean");
62  bookWheelHistos(ibooker, wh, "PhiResidualRMS");
63  bookWheelHistos(ibooker, wh, "PhibResidualMean");
64  bookWheelHistos(ibooker, wh, "PhibResidualRMS");
65  if (doCorrStudy) {
66  bookWheelHistos(ibooker, wh, "PhiTkvsTrigSlope");
67  bookWheelHistos(ibooker, wh, "PhiTkvsTrigIntercept");
68  bookWheelHistos(ibooker, wh, "PhiTkvsTrigCorr");
69  bookWheelHistos(ibooker, wh, "PhibTkvsTrigSlope");
70  bookWheelHistos(ibooker, wh, "PhibTkvsTrigIntercept");
71  bookWheelHistos(ibooker, wh, "PhibTkvsTrigCorr");
72  }
73  }
74  }
75  }
76  }
77 
78  // Summary test histo booking (only static)
79  for (iTr = trigSources.begin(); iTr != trEnd; ++iTr) {
80  trigSource = (*iTr);
81  for (iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw) {
82  hwSource = (*iHw);
83  // Loop over the TriggerUnits
84  for (int wh = -2; wh <= 2; ++wh) {
85  bookWheelHistos(ibooker, wh, "PhiLutSummary");
86  bookWheelHistos(ibooker, wh, "PhibLutSummary");
87  }
88 
89  bookCmsHistos(ibooker, "PhiLutSummary");
90  bookCmsHistos(ibooker, "PhibLutSummary");
91  }
92  }
93 
94  bookingdone = true;
95 }
96 
99 }
100 
102  if (!bookingdone)
103  Bookings(ibooker, igetter);
104 
105  // Loop over Trig & Hw sources
106  for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr) {
107  trigSource = (*iTr);
108  for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw) {
109  hwSource = (*iHw);
110  vector<const DTChamber*>::const_iterator chIt = muonGeom->chambers().begin();
111  vector<const DTChamber*>::const_iterator chEnd = muonGeom->chambers().end();
112  for (; chIt != chEnd; ++chIt) {
113  DTChamberId chId((*chIt)->id());
114  int wh = chId.wheel();
115  int sect = chId.sector();
116  int stat = chId.station();
117 
118  if (doCorrStudy) {
119  // Perform Correlation Plots analysis (TM + segment Phi)
120 
121  TH2F* TrackPhitkvsPhitrig = getHisto<TH2F>(igetter.get(getMEName("PhitkvsPhitrig", "Segment", chId)));
122 
123  if (TrackPhitkvsPhitrig && TrackPhitkvsPhitrig->GetEntries() > 10) {
124  // Fill client histos
125  if (whME[wh].find(fullName("PhiTkvsTrigCorr")) == whME[wh].end()) {
126  bookWheelHistos(ibooker, wh, "PhiTkvsTrigSlope");
127  bookWheelHistos(ibooker, wh, "PhiTkvsTrigIntercept");
128  bookWheelHistos(ibooker, wh, "PhiTkvsTrigCorr");
129  }
130 
131  TProfile* PhitkvsPhitrigProf = TrackPhitkvsPhitrig->ProfileX();
132  double phiInt = 0;
133  double phiSlope = 0;
134  double phiCorr = 0;
135  try {
136  TF1 ffPhi("mypol1", "pol1");
137  PhitkvsPhitrigProf->Fit(&ffPhi, "CQO");
138  phiInt = ffPhi.GetParameter(0);
139  phiSlope = ffPhi.GetParameter(1);
140  phiCorr = TrackPhitkvsPhitrig->GetCorrelationFactor();
141  } catch (cms::Exception& iException) {
142  edm::LogError(category()) << "[" << testName << "Test]: Error fitting PhitkvsPhitrig for Wheel " << wh
143  << " Sector " << sect << " Station " << stat;
144  }
145 
146  std::map<std::string, MonitorElement*>& innerME = whME[wh];
147  fillWhPlot(innerME.find(fullName("PhiTkvsTrigSlope"))->second, sect, stat, phiSlope - 1);
148  fillWhPlot(innerME.find(fullName("PhiTkvsTrigIntercept"))->second, sect, stat, phiInt);
149  fillWhPlot(innerME.find(fullName("PhiTkvsTrigCorr"))->second, sect, stat, phiCorr, false);
150  }
151 
152  // Perform Correlation Plots analysis (TM + segment Phib)
153  TH2F* TrackPhibtkvsPhibtrig = getHisto<TH2F>(igetter.get(getMEName("PhibtkvsPhibtrig", "Segment", chId)));
154 
155  if (stat != 3 && TrackPhibtkvsPhibtrig &&
156  TrackPhibtkvsPhibtrig->GetEntries() > 10) { // station 3 has no meaningful MB3 phi bending information
157 
158  // Fill client histos
159  if (whME[wh].find(fullName("PhibTkvsTrigCorr")) == whME[wh].end()) {
160  bookWheelHistos(ibooker, wh, "PhibTkvsTrigSlope");
161  bookWheelHistos(ibooker, wh, "PhibTkvsTrigIntercept");
162  bookWheelHistos(ibooker, wh, "PhibTkvsTrigCorr");
163  }
164 
165  TProfile* PhibtkvsPhibtrigProf = TrackPhibtkvsPhibtrig->ProfileX();
166  double phibInt = 0;
167  double phibSlope = 0;
168  double phibCorr = 0;
169  try {
170  TF1 ffPhib("ffPhib", "pol1");
171  PhibtkvsPhibtrigProf->Fit(&ffPhib, "CQO");
172  phibInt = ffPhib.GetParameter(0);
173  phibSlope = ffPhib.GetParameter(1);
174  phibCorr = TrackPhibtkvsPhibtrig->GetCorrelationFactor();
175  } catch (cms::Exception& iException) {
176  edm::LogError(category()) << "[" << testName << "Test]: Error fitting PhibtkvsPhibtrig for Wheel " << wh
177  << " Sector " << sect << " Station " << stat;
178  }
179 
180  std::map<std::string, MonitorElement*>& innerME = whME[wh];
181  fillWhPlot(innerME.find(fullName("PhibTkvsTrigSlope"))->second, sect, stat, phibSlope - 1);
182  fillWhPlot(innerME.find(fullName("PhibTkvsTrigIntercept"))->second, sect, stat, phibInt);
183  fillWhPlot(innerME.find(fullName("PhibTkvsTrigCorr"))->second, sect, stat, phibCorr, false);
184  }
185  }
186 
187  // Make Phi Residual Summary
188 
189  TH1F* PhiResidual = getHisto<TH1F>(igetter.get(getMEName("PhiResidual", "Segment", chId)));
190  int phiSummary = 1;
191 
192  if (PhiResidual && PhiResidual->GetEffectiveEntries() > 10) {
193  // Fill client histos
194  if (whME[wh].find(fullName("PhiResidualMean")) == whME[wh].end()) {
195  bookWheelHistos(ibooker, wh, "PhiResidualMean");
196  bookWheelHistos(ibooker, wh, "PhiResidualRMS");
197  }
198 
199  double peak = PhiResidual->GetBinCenter(PhiResidual->GetMaximumBin());
200  double phiMean = 0;
201  double phiRMS = 0;
202  try {
203  TF1 ffPhi("ffPhi", "gaus");
204  PhiResidual->Fit(&ffPhi, "CQO", "", peak - 5, peak + 5);
205  phiMean = ffPhi.GetParameter(1);
206  phiRMS = ffPhi.GetParameter(2);
207  } catch (cms::Exception& iException) {
208  edm::LogError(category()) << "[" << testName << "Test]: Error fitting PhiResidual for Wheel " << wh
209  << " Sector " << sect << " Station " << stat;
210  }
211 
212  std::map<std::string, MonitorElement*>& innerME = whME[wh];
213  fillWhPlot(innerME.find(fullName("PhiResidualMean"))->second, sect, stat, phiMean);
214  fillWhPlot(innerME.find(fullName("PhiResidualRMS"))->second, sect, stat, phiRMS);
215 
216  phiSummary = performLutTest(phiMean, phiRMS, thresholdPhiMean, thresholdPhiRMS);
217  }
218  fillWhPlot(whME[wh].find(fullName("PhiLutSummary"))->second, sect, stat, phiSummary);
219 
220  // Make Phib Residual Summary
221  TH1F* PhibResidual = getHisto<TH1F>(igetter.get(getMEName("PhibResidual", "Segment", chId)));
222  int phibSummary = stat == 3 ? 0 : 1; // station 3 has no meaningful MB3 phi bending information
223 
224  if (stat != 3 && PhibResidual &&
225  PhibResidual->GetEffectiveEntries() > 10) { // station 3 has no meaningful MB3 phi bending information
226 
227  // Fill client histos
228  if (whME[wh].find(fullName("PhibResidualMean")) == whME[wh].end()) {
229  bookWheelHistos(ibooker, wh, "PhibResidualMean");
230  bookWheelHistos(ibooker, wh, "PhibResidualRMS");
231  }
232 
233  double peak = PhibResidual->GetBinCenter(PhibResidual->GetMaximumBin());
234  double phibMean = 0;
235  double phibRMS = 0;
236  try {
237  TF1 ffPhib("ffPhib", "gaus");
238  PhibResidual->Fit(&ffPhib, "CQO", "", peak - 5, peak + 5);
239  phibMean = ffPhib.GetParameter(1);
240  phibRMS = ffPhib.GetParameter(2);
241  } catch (cms::Exception& iException) {
242  edm::LogError(category()) << "[" << testName << "Test]: Error fitting PhibResidual for Wheel " << wh
243  << " Sector " << sect << " Station " << stat;
244  }
245 
246  std::map<std::string, MonitorElement*>& innerME = whME[wh];
247  fillWhPlot(innerME.find(fullName("PhibResidualMean"))->second, sect, stat, phibMean);
248  fillWhPlot(innerME.find(fullName("PhibResidualRMS"))->second, sect, stat, phibRMS);
249 
250  phibSummary = performLutTest(phibMean, phibRMS, thresholdPhibMean, thresholdPhibRMS);
251  }
252  fillWhPlot(whME[wh].find(fullName("PhibLutSummary"))->second, sect, stat, phibSummary);
253  }
254  }
255  }
256 
257  // Barrel Summary Plots
258  for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr) {
259  trigSource = (*iTr);
260  for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw) {
261  hwSource = (*iHw);
262  for (int wh = -2; wh <= 2; ++wh) {
263  std::map<std::string, MonitorElement*>* innerME = &(whME[wh]);
264 
265  TH2F* phiWhSummary = getHisto<TH2F>(innerME->find(fullName("PhiLutSummary"))->second);
266  TH2F* phibWhSummary = getHisto<TH2F>(innerME->find(fullName("PhibLutSummary"))->second);
267  for (int sect = 1; sect <= 12; ++sect) {
268  int phiErr = 0;
269  int phibErr = 0;
270  int phiNoData = 0;
271  int phibNoData = 0;
272  for (int stat = 1; stat <= 4; ++stat) {
273  switch (static_cast<int>(phiWhSummary->GetBinContent(sect, stat))) {
274  case 1:
275  phiNoData++;
276  [[fallthrough]];
277  case 2:
278  case 3:
279  phiErr++;
280  }
281  switch (static_cast<int>(phibWhSummary->GetBinContent(sect, stat))) {
282  case 1:
283  phibNoData++;
284  [[fallthrough]];
285  case 2:
286  case 3:
287  phibErr++;
288  }
289  }
290  if (phiNoData == 4)
291  phiErr = 5;
292  if (phibNoData == 3)
293  phibErr = 5; // MB3 has no phib information
294  cmsME.find(fullName("PhiLutSummary"))->second->setBinContent(sect, wh + wheelArrayShift, phiErr);
295  cmsME.find(fullName("PhibLutSummary"))->second->setBinContent(sect, wh + wheelArrayShift, phibErr);
296  }
297  }
298  }
299  }
300 }
301 
302 int DTLocalTriggerLutTest::performLutTest(double mean, double RMS, double thresholdMean, double thresholdRMS) {
303  bool meanErr = fabs(mean) > thresholdMean;
304  bool rmsErr = RMS > thresholdRMS;
305 
306  return (meanErr || rmsErr) ? 2 + (meanErr != rmsErr) : 0;
307 }
308 
309 void DTLocalTriggerLutTest::fillWhPlot(MonitorElement* plot, int sect, int stat, float value, bool lessIsBest) {
310  if (sect > 12) {
311  int scsect = sect == 13 ? 4 : 10;
312  if ((fabs(value) > fabs(plot->getBinContent(scsect, stat))) == lessIsBest) {
313  plot->setBinContent(scsect, stat, value);
314  }
315  } else {
316  plot->setBinContent(sect, stat, value);
317  }
318 
319  return;
320 }
int performLutTest(double mean, double RMS, double thresholdMean, double thresholdRMS)
Perform Lut Test logical operations.
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void runClientDiagnostic(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter) override
Run client analysis.
void fillWhPlot(MonitorElement *plot, int sect, int stat, float value, bool lessIsBest=true)
Fill summary plots managing double MB4 chambers.
T getUntrackedParameter(std::string const &, T const &) const
U second(std::pair< T, U > const &p)
Definition: value.py:1
void beginRun(edm::Run const &run, edm::EventSetup const &context) override
BeginRun.
~DTLocalTriggerLutTest() override
Destructor.
void Bookings(DQMStore::IBooker &, DQMStore::IGetter &)
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:712
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:42
HLT enums.
void beginRun(const edm::Run &r, const edm::EventSetup &c) override
BeginRun.
DTLocalTriggerLutTest(const edm::ParameterSet &ps)
Constructor.
Definition: Run.h:45