CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTTriggerLutTest.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author D. Fasanella - INFN Bologna
5  */
6 
7 
8 // This class header
10 
11 // Framework headers
16 // Geometry
19 
20 // Root
21 #include "TF1.h"
22 //#include "TSpectrum.h"
23 
24 
25 //C++ headers
26 #include <iostream>
27 #include <sstream>
28 
29 
30 using namespace edm;
31 using namespace std;
32 
33 
35 
36  setConfig(ps,"DTTriggerLut");
37  baseFolderDCC = "DT/03-LocalTrigger-DCC/";
38  baseFolderDDU = "DT/04-LocalTrigger-DDU/";
39  thresholdWarnPhi = ps.getUntrackedParameter<double>("thresholdWarnPhi");
40  thresholdErrPhi = ps.getUntrackedParameter<double>("thresholdErrPhi");
41  thresholdWarnPhiB = ps.getUntrackedParameter<double>("thresholdWarnPhiB");
42  thresholdErrPhiB = ps.getUntrackedParameter<double>("thresholdErrPhiB");
43  validRange = ps.getUntrackedParameter<double>("validRange");
44  detailedAnalysis = ps.getUntrackedParameter<bool>("detailedAnalysis");
45 
46 }
47 
48 
50 
51 }
52 
53 
55 
57 
58  vector<string>::const_iterator iTr = trigSources.begin();
59  vector<string>::const_iterator trEnd = trigSources.end();
60  vector<string>::const_iterator iHw = hwSources.begin();
61  vector<string>::const_iterator hwEnd = hwSources.end();
62 
63  //Booking
64  if(parameters.getUntrackedParameter<bool>("staticBooking")){
65 
66  for (; iTr != trEnd; ++iTr){
67  trigSource = (*iTr);
68  for (; iHw != hwEnd; ++iHw){
69  hwSource = (*iHw);
70  // Loop over the TriggerUnits
71  for (int wh=-2; wh<=2; ++wh){
72  if (detailedAnalysis){
73  bookWheelHistos(wh,"PhiResidualPercentage");
74  bookWheelHistos(wh,"PhibResidualPercentage");
75  }
76 
77  bookWheelHistos(wh,"PhiLutSummary","Summaries");
78  bookWheelHistos(wh,"PhibLutSummary","Summaries");
79 
80  if (detailedAnalysis){
81  bookWheelHistos(wh,"PhiResidualMean");
82  bookWheelHistos(wh,"PhiResidualRMS");
83  bookWheelHistos(wh,"PhibResidualMean");
84  bookWheelHistos(wh,"PhibResidualRMS");
85  bookWheelHistos(wh,"CorrelationFactorPhi");
86  bookWheelHistos(wh,"CorrelationFactorPhib");
87  bookWheelHistos(wh,"DoublePeakFlagPhib");
88  }
89 
90  }
91 
92  bookCmsHistos("TrigLutSummary","",true);
93  bookCmsHistos("PhiLutSummary");
94  bookCmsHistos("PhibLutSummary");
95  if (detailedAnalysis){
96  bookCmsHistos1d("PhiPercentageSummary");
97  bookCmsHistos1d("PhibPercentageSummary");
98  }
99  }
100  }
101  }
102 
103 }
104 
105 
107 
109 
110 }
111 
112 
114 
115  // Reset lut percentage 1D summaries
116  if (detailedAnalysis){
117  cmsME.find(fullName("PhiPercentageSummary"))->second->Reset();
118  cmsME.find(fullName("PhibPercentageSummary"))->second->Reset();
119  }
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 
130  DTChamberId chId((*chIt)->id());
131  int wh = chId.wheel();
132  int sect = chId.sector();
133  int stat = chId.station();
134 
135  std::map<std::string,MonitorElement*> &innerME = whME[wh];
136 
137  // Make Phi Residual Summary
138  TH1F * PhiResidual = getHisto<TH1F>(dbe->get(getMEName("PhiResidual","Segment", chId)));
139  int phiSummary = 1;
140  if (PhiResidual && PhiResidual->GetEntries()>10) {
141 
142  if( innerME.find(fullName("PhiResidualPercentage")) == innerME.end() ){
143  bookWheelHistos(wh,"PhiResidualPercentage");
144  }
145 
146  float rangeBin = validRange/(PhiResidual->GetBinWidth(1));
147  float center = (PhiResidual->GetNbinsX())/2.;
148  float perc = (PhiResidual->Integral(floor(center-rangeBin),ceil(center+rangeBin)))/(PhiResidual->Integral());
149  fillWhPlot(innerME.find(fullName("PhiResidualPercentage"))->second,sect,stat,perc,false);
150  phiSummary = performLutTest(perc,thresholdWarnPhi,thresholdErrPhi);
151  if (detailedAnalysis) cmsME.find(fullName("PhiPercentageSummary"))->second->Fill(perc);
152 
153  }
154 
155  fillWhPlot(innerME.find(fullName("PhiLutSummary"))->second,sect,stat,phiSummary);
156 
157  if (detailedAnalysis){
158 
159 // if ((phiSummary ==0)&& (PhiResidual->GetEntries()>100)) { //Precision Peak test
160 
161 // Float_t *source = new float[31];
162 // Float_t *dest = new float[31];
163 // //TSpectrum *g = new TSpectrum(5);
164 // float media = PhiResidual->GetMean();
165 // int center = PhiResidual->GetXaxis()->FindBin(media);
166 // for (int i = 0; i < 30; i++) {
167 // source[i]=PhiResidual->GetBinContent(center+i-15);}
168 // int nFound = g->SearchHighRes(source, dest, 30, 1, 6, kFALSE, 5, kTRUE,2);
169 // /if (nFound>1) { // has more than 1 peak
170 // if( innerME.find(fullName("DoublePeakFlagPhi")) == innerME.end() ){
171 // bookWheelHistos(wh,"DoublePeakFlagPhi");
172 // }
173 // }
174 
175 // fillWhPlot(innerME.find(fullName("DoublePeakFlagPhi"))->second,sect,stat,1,false);
176 // }
177 
178  if ((phiSummary==0)||(phiSummary==3)){ //Information on the Peak
179 
180  if( innerME.find(fullName("PhiResidualMean")) == innerME.end() ){
181  bookWheelHistos(wh,"PhiResidualMean");
182  bookWheelHistos(wh,"PhiResidualRMS");
183  }
184 
185  float center = (PhiResidual->GetNbinsX())/2.;
186  float rangeBin = validRange/(PhiResidual->GetBinWidth(1));
187  PhiResidual->GetXaxis()->SetRange(floor(center-rangeBin),ceil(center+rangeBin));
188  float max = PhiResidual->GetMaximumBin();
189  float maxBin = PhiResidual->GetXaxis()->FindBin(max);
190  float nBinMax = 0.5/(PhiResidual->GetBinWidth(1));
191  PhiResidual->GetXaxis()->SetRange(floor(maxBin-nBinMax),ceil(maxBin+nBinMax));
192  float Mean = PhiResidual->GetMean();
193  float rms = PhiResidual->GetRMS();
194 
195  fillWhPlot(innerME.find(fullName("PhiResidualMean"))->second,sect,stat,Mean);
196  fillWhPlot(innerME.find(fullName("PhiResidualRMS"))->second,sect,stat,rms);
197 
198  }
199 
200  TH2F * TrackPhitkvsPhitrig = getHisto<TH2F>(dbe->get(getMEName("PhitkvsPhitrig","Segment", chId)));
201 
202  if (TrackPhitkvsPhitrig && TrackPhitkvsPhitrig->GetEntries()>100) {
203  float corr = TrackPhitkvsPhitrig->GetCorrelationFactor();
204  if( innerME.find(fullName("CorrelationFactorPhi")) == innerME.end() ){
205  bookWheelHistos(wh,"CorrelationFactorPhi");
206  }
207  fillWhPlot(innerME.find(fullName("CorrelationFactorPhi"))->second,sect,stat,corr,false);
208  }
209 
210  }
211 
212 
213  // Make Phib Residual Summary
214  TH1F * PhibResidual = getHisto<TH1F>(dbe->get(getMEName("PhibResidual","Segment", chId)));
215  int phibSummary = stat==3 ? -1 : 1; // station 3 has no meaningful MB3 phi bending information
216 
217  if (stat != 3 && PhibResidual && PhibResidual->GetEntries()>10) {// station 3 has no meaningful MB3 phi bending information
218 
219  if( innerME.find(fullName("PhibResidualPercentage")) == innerME.end() ){
220  bookWheelHistos(wh,"PhibResidualPercentage");
221  }
222 
223  float rangeBin = validRange/(PhibResidual->GetBinWidth(1));
224  float center = (PhibResidual->GetNbinsX())/2.;
225  float perc = (PhibResidual->Integral(floor(center-rangeBin),ceil(center+rangeBin)))/(PhibResidual->Integral());
226 
227  fillWhPlot(innerME.find(fullName("PhibResidualPercentage"))->second,sect,stat,perc,false);
228  phibSummary = performLutTest(perc,thresholdWarnPhiB,thresholdErrPhiB);
229  if (detailedAnalysis) cmsME.find(fullName("PhibPercentageSummary"))->second->Fill(perc);
230 
231  }
232 
233  fillWhPlot(innerME.find(fullName("PhibLutSummary"))->second,sect,stat,phibSummary);
234 
235  if (detailedAnalysis){
236 
237 // if ((phibSummary ==0)&& (PhibResidual->GetEntries()>100)) { //Precision Peak test
238 // Float_t * source = new float[31];
239 // Float_t * dest = new float[31];
240 // TSpectrum *spec = new TSpectrum(5);
241 // float media = PhibResidual->GetMean();
242 // int center= PhibResidual->GetXaxis()->FindBin(media);
243 // for (int i = 0; i < 30; i++) {
244 // source[i]=PhibResidual->GetBinContent(center+i-15);
245 // }
246 // int nFound = spec->SearchHighRes(source,dest,30,1,6,kFALSE,5,kTRUE,2);
247 // if (nFound>1) { // has more than 1 peak
248 // if( innerME.find(fullName("DoublePeakFlagPhib")) == innerME.end() ){
249 // bookWheelHistos(wh,"DoublePeakFlagPhib");
250 // }
251 // fillWhPlot(innerME.find(fullName("DoublePeakFlagPhib"))->second,sect,stat,1,false);
252 // }
253 // }
254 
255  if ((phibSummary==0)||(phibSummary==3)){
256 
257  if( innerME.find(fullName("PhibResidualMean")) == innerME.end() ){
258  bookWheelHistos(wh,"PhibResidualMean");
259  bookWheelHistos(wh,"PhibResidualRMS");
260  }
261 
262  float center = (PhibResidual->GetNbinsX())/2.;
263  float rangeBin = validRange/(PhibResidual->GetBinWidth(1));
264  PhibResidual->GetXaxis()->SetRange(floor(center-rangeBin),ceil(center+rangeBin));
265  float max = PhibResidual->GetMaximumBin();
266  float maxBin = PhibResidual->GetXaxis()->FindBin(max);
267  float nBinMax = 0.5/(PhibResidual->GetBinWidth(1));
268  PhibResidual->GetXaxis()->SetRange(floor(maxBin-nBinMax),ceil(maxBin+nBinMax));
269  float Mean = PhibResidual->GetMean();
270  float rms = PhibResidual->GetRMS();
271 
272  fillWhPlot(innerME.find(fullName("PhibResidualMean"))->second,sect,stat,Mean);
273  fillWhPlot(innerME.find(fullName("PhibResidualRMS"))->second,sect,stat,rms);
274  }
275 
276  TH2F * TrackPhibtkvsPhibtrig = getHisto<TH2F>(dbe->get(getMEName("PhibtkvsPhibtrig","Segment", chId)));
277  if (TrackPhibtkvsPhibtrig && TrackPhibtkvsPhibtrig->GetEntries()>100) {
278 
279  float corr = TrackPhibtkvsPhibtrig->GetCorrelationFactor();
280  if( innerME.find(fullName("CorrelationFactorPhib")) == innerME.end() ){
281  bookWheelHistos(wh,"CorrelationFactorPhib");
282  }
283 
284  fillWhPlot(innerME.find(fullName("CorrelationFactorPhib"))->second,sect,stat,corr,false);
285 
286  }
287 
288  }
289  }
290  }
291  }
292 
293  // Barrel Summary Plots
294  for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
295  trigSource = (*iTr);
296  for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
297  hwSource = (*iHw);
298  for (int wh=-2; wh<=2; ++wh){
299 
300  std::map<std::string,MonitorElement*> *innerME = &(whME[wh]);
301 
302  TH2F* phiWhSummary = getHisto<TH2F>(innerME->find(fullName("PhiLutSummary"))->second);
303  TH2F* phibWhSummary = getHisto<TH2F>(innerME->find(fullName("PhibLutSummary"))->second);
304 
305  for (int sect=1; sect<=12; ++sect){
306 
307  int phiSectorTotal = 0; // CB dai 1 occhio a questo
308  int phibSectorTotal = 0;
309  int nullphi = 0;
310  int nullphib = 0;
311  int phiStatus = 5;
312  int phibStatus = 5;
313  int glbStatus = 0;
314 
315  for (int stat=1; stat<=4; ++stat){
316  if (phiWhSummary->GetBinContent(sect,stat)==2){
317  phiSectorTotal +=1;
318  glbStatus += 1;
319  }
320  if (phiWhSummary->GetBinContent(sect,stat)==1)
321  nullphi+=1;
322  if (phibWhSummary->GetBinContent(sect,stat)==2) {
323  phibSectorTotal+=1;
324  glbStatus += 1;
325  }
326  if (phibWhSummary->GetBinContent(sect,stat)==1)
327  nullphib+=1;
328  }
329  if (nullphi!=4)
330  phiStatus=phiSectorTotal;
331  else
332  phiStatus=5;
333  if (nullphib!=3)
334  phibStatus=phibSectorTotal;
335  else
336  phibStatus=5;
337 
338  cmsME.find("TrigLutSummary")->second->setBinContent(sect,wh+3,glbStatus);
339  cmsME.find(fullName("PhiLutSummary"))->second->setBinContent(sect,wh+3,phiStatus);
340  cmsME.find(fullName("PhibLutSummary"))->second->setBinContent(sect,wh+3,phibStatus);
341  }
342  }
343  }
344  }
345 
346 }
347 
348 int DTTriggerLutTest::performLutTest(double perc,double thresholdWarn ,double thresholdErr) {
349 
350  bool isInWarn = perc<thresholdWarn;
351  bool isInErr = perc<thresholdErr;
352 
353  int result= isInErr ? 2 : isInWarn ? 3 : 0;
354 
355  return result;
356 
357 }
358 
359 void DTTriggerLutTest::bookCmsHistos1d(string hTag, string folder) {
360 
361  string basedir = topFolder(true);
362  if (folder != "") {
363  basedir += folder +"/" ;
364  }
365  dbe->setCurrentFolder(basedir);
366 
367  string hName = fullName(hTag);
368  LogTrace(category()) << "[" << testName << "Test]: booking " << basedir << hName;
369 
370 
371  MonitorElement* me = dbe->book1D(hName.c_str(),hName.c_str(),101,-0.005,1.005);
372  me->setAxisTitle("Percentage",1);
373  cmsME[hName] = me;
374 
375 }
376 
377 void DTTriggerLutTest::fillWhPlot(MonitorElement *plot, int sect, int stat, float value, bool lessIsBest) {
378 
379  if (sect>12) {
380  int scsect = sect==13 ? 4 : 10;
381  if ((value>plot->getBinContent(scsect,stat)) == lessIsBest) {
382  plot->setBinContent(scsect,stat,value);
383  }
384  }
385  else {
386  plot->setBinContent(sect,stat,value);
387  }
388 
389  return;
390 
391 }
392 
393 
T getUntrackedParameter(std::string const &, T const &) const
dictionary parameters
Definition: Parameters.py:2
void setBinContent(int binx, double content)
set content of bin (1-D)
void bookCmsHistos1d(std::string hTag, std::string folder="")
DTTriggerLutTest(const edm::ParameterSet &ps)
Constructor.
virtual ~DTTriggerLutTest()
Destructor.
int performLutTest(double perc, double threshold1, double threshold2)
Perform Lut Test logical operations.
void beginRun(edm::Run const &run, edm::EventSetup const &context)
BeginRun.
void fillWhPlot(MonitorElement *plot, int sect, int stat, float value, bool lessIsBest=true)
Fill summary plots managing double MB4 chambers.
void beginJob()
BeginJob.
tuple result
Definition: query.py:137
#define LogTrace(id)
JetCorrectorParameters corr
Definition: classes.h:5
string fullName
void runClientDiagnostic()
Run client analysis.
double getBinContent(int binx) const
get content of bin (1-D)
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
Definition: Run.h:41
EventID const & max(EventID const &lh, EventID const &rh)
Definition: EventID.h:142