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