CMS 3D CMS Logo

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