CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTLocalTriggerTest.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,"DTLocalTrigger");
40  baseFolderTM = "DT/03-LocalTrigger-TM/";
41  baseFolderDDU = "DT/04-LocalTrigger-DDU/";
42  nMinEvts = ps.getUntrackedParameter<int>("nEventsCert", 5000);
43 
44  bookingdone = 0;
45 
46 }
47 
48 
50 
51 }
52 
53 
55 
56  vector<string>::const_iterator iTr = trigSources.begin();
57  vector<string>::const_iterator trEnd = trigSources.end();
58  vector<string>::const_iterator iHw = hwSources.begin();
59  vector<string>::const_iterator hwEnd = hwSources.end();
60 
61  //Booking
62  if(parameters.getUntrackedParameter<bool>("staticBooking", true)){
63  for (; iTr != trEnd; ++iTr){
64  trigSource = (*iTr);
65  for (; iHw != hwEnd; ++iHw){
66  hwSource = (*iHw);
67  // Loop over the TriggerUnits
68  for (int wh=-2; wh<=2; ++wh){
69  if (hwSource=="COM") {
70 
71  bookWheelHistos(ibooker,wh,"MatchingPhi");
72  }
73  else {
74  for (int sect=1; sect<=12; ++sect){
75 
76  bookSectorHistos(ibooker,wh,sect,"BXDistribPhi");
77  bookSectorHistos(ibooker,wh,sect,"QualDistribPhi");
78  }
79 
80  bookWheelHistos(ibooker,wh,"CorrectBXPhi");
81  bookWheelHistos(ibooker,wh,"ResidualBXPhi");
82  bookWheelHistos(ibooker,wh,"CorrFractionPhi");
83  bookWheelHistos(ibooker,wh,"2ndFractionPhi");
84  bookWheelHistos(ibooker,wh,"TriggerInclusivePhi");
85  bookWheelHistos(ibooker,wh,"CorrectBXTheta");
86  // Changed after TM implementation, now we have always Theta information
87  // Changed 11/10/2916 M.C Fouz
88  /*
89  if (hwSource=="DDU") {
90  bookWheelHistos(ibooker,wh,"HFractionTheta");
91  }
92  */
93  bookWheelHistos(ibooker,wh,"HFractionTheta");
94  }
95  }
96  }
97  }
98  }
99  // Summary test histo booking (only static)
100  for (iTr = trigSources.begin(); iTr != trEnd; ++iTr){
101  trigSource = (*iTr);
102  for (iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
103  hwSource = (*iHw);
104  // Loop over the TriggerUnits
105  for (int wh=-2; wh<=2; ++wh){
106  if (hwSource=="COM") {
107 
108  bookWheelHistos(ibooker,wh,"MatchingSummary","Summaries");
109  }
110  else {
111 
112  bookWheelHistos(ibooker,wh,"CorrFractionSummary","Summaries");
113  bookWheelHistos(ibooker,wh,"2ndFractionSummary","Summaries");
114  }
115  }
116  if (hwSource=="COM") {
117 
118  bookCmsHistos(ibooker,"MatchingSummary","Summaries");
119  }
120  else {
121 
122  bookCmsHistos(ibooker,"CorrFractionSummary");
123  bookCmsHistos(ibooker,"2ndFractionSummary");
124  }
125  if (hwSource=="TM") {
126 
127  bookCmsHistos(ibooker,"TrigGlbSummary","",true);
128  bookCmsHistos(ibooker,"TrigGlbSummary","",true);
129  }
130 
131  }
132  }
133 
134  bookingdone = 1;
135 }
136 
137 
139 
141 
142 }
143 
145 
146  if (!bookingdone) Bookings(ibooker,igetter);
147 
148  // Loop over Trig & Hw sources
149  for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
150  trigSource = (*iTr);
151 
152  for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
153  hwSource = (*iHw);
154  // Loop over the TriggerUnits
155  for (int stat=1; stat<=4; ++stat){
156  for (int wh=-2; wh<=2; ++wh){
157  for (int sect=1; sect<=12; ++sect){
158  DTChamberId chId(wh,stat,sect);
159  int sector_id = (wh+3)+(sect-1)*5;
160 
161  if (hwSource=="COM") {
162  // Perform TM-DDU matching test and generates summaries (Phi view)
163  TH2F * DDUvsTM = getHisto<TH2F>(igetter.get(getMEName("QualDDUvsQualTM","LocalTriggerPhiIn", chId)));
164  if (DDUvsTM) {
165 
166  int matchSummary = 1;
167 
168  if (DDUvsTM->GetEntries()>1) {
169 
170  double entries = DDUvsTM->GetEntries();
171  double corrEntries = 0;
172  for (int ibin=2; ibin<=8; ++ibin) {
173  corrEntries += DDUvsTM->GetBinContent(ibin,ibin);
174  }
175  double corrRatio = corrEntries/entries;
176 
177  if (corrRatio < parameters.getUntrackedParameter<double>("matchingFracError",.65)){
178  matchSummary = 2;
179  }
180  else if (corrRatio < parameters.getUntrackedParameter<double>("matchingFracWarning",.85)){
181  matchSummary = 3;
182  }
183  else {
184  matchSummary = 0;
185  }
186 
187  if( whME[wh].find(fullName("MatchingPhi")) == whME[wh].end() ){
188  bookWheelHistos(ibooker,wh,"MatchingPhi");
189  }
190 
191  whME[wh].find(fullName("MatchingPhi"))->second->setBinContent(sect,stat,corrRatio);
192 
193  }
194 
195  whME[wh].find(fullName("MatchingSummary"))->second->setBinContent(sect,stat,matchSummary);
196 
197  }
198  }
199  else {
200  // Changed by M.C.Fouz (11/10/2016)
201  // Perform TM/DDU common plot analysis (Phi ones)
202  // This was changed for DQM after TM IN but, in the Modules Source part, they are not defined as *_In
203  // and the histograms are not being filled, renamed with the same names as the modules
204  /*
205  TH2F * BXvsQual = getHisto<TH2F>(igetter.get(getMEName("BXvsQual_In","LocalTriggerPhiIn", chId)));
206  TH1F * BestQual = getHisto<TH1F>(igetter.get(getMEName("BestQual_In","LocalTriggerPhiIn", chId)));
207  TH2F * Flag1stvsQual = getHisto<TH2F>(igetter.get(getMEName("Flag1stvsQual_In","LocalTriggerPhiIn", chId)));
208  */
209  TH2F * BXvsQual = getHisto<TH2F>(igetter.get(getMEName("BXvsQual","LocalTriggerPhiIn", chId)));
210  TH1F * BestQual = getHisto<TH1F>(igetter.get(getMEName("BestQual","LocalTriggerPhiIn", chId)));
211  TH2F * Flag1stvsQual = getHisto<TH2F>(igetter.get(getMEName("Flag1stvsQual","LocalTriggerPhiIn", chId)));
212  if (BXvsQual && Flag1stvsQual && BestQual) {
213 
214  int corrSummary = 1;
215  int secondSummary = 1;
216 
217  if (BestQual->GetEntries()>1) {
218 
219  TH1D* BXHH = BXvsQual->ProjectionY("",6,7,"");
220  TH1D* Flag1st = Flag1stvsQual->ProjectionY();
221  int BXOK_bin = BXHH->GetEntries()>=1 ? BXHH->GetMaximumBin() : 51;
222  double BXMean = BXHH->GetEntries()>=1 ? BXHH->GetMean() : 51;
223  double BX_OK = BXvsQual->GetYaxis()->GetBinCenter(BXOK_bin);
224  double trigsFlag2nd = Flag1st->GetBinContent(2);
225  double trigs = Flag1st->GetEntries();
226  double besttrigs = BestQual->GetEntries();
227  double besttrigsCorr = BestQual->Integral(5,7,"");
228  delete BXHH;
229  delete Flag1st;
230 
231  double corrFrac = besttrigsCorr/besttrigs;
232  double secondFrac = trigsFlag2nd/trigs;
233  if (corrFrac < parameters.getUntrackedParameter<double>("corrFracError",.5)){
234  corrSummary = 2;
235  }
236  else if (corrFrac < parameters.getUntrackedParameter<double>("corrFracWarning",.6)){
237  corrSummary = 3;
238  }
239  else {
240  corrSummary = 0;
241  }
242  if (secondFrac > parameters.getUntrackedParameter<double>("secondFracError",.2)){
243  secondSummary = 2;
244  }
245  else if (secondFrac > parameters.getUntrackedParameter<double>("secondFracWarning",.1)){
246  secondSummary = 3;
247  }
248  else {
249  secondSummary = 0;
250  }
251 
252  if( secME[sector_id].find(fullName("BXDistribPhi")) == secME[sector_id].end() ){
253  bookSectorHistos(ibooker,wh,sect,"QualDistribPhi");
254  bookSectorHistos(ibooker,wh,sect,"BXDistribPhi");
255  }
256 
257  TH1D* BXDistr = BXvsQual->ProjectionY();
258  TH1D* QualDistr = BXvsQual->ProjectionX();
259  std::map<std::string,MonitorElement*> *innerME = &(secME[sector_id]);
260 
261  int nbinsBX = BXDistr->GetNbinsX();
262  int firstBinCenter = static_cast<int>(BXDistr->GetBinCenter(1));
263  int lastBinCenter = static_cast<int>(BXDistr->GetBinCenter(nbinsBX));
264  int iMin = firstBinCenter>-4 ? firstBinCenter : -4;
265  int iMax = lastBinCenter<20 ? lastBinCenter : 20;
266  for (int ibin=iMin+5;ibin<=iMax+5; ++ibin) {
267  innerME->find(fullName("BXDistribPhi"))->second->setBinContent(ibin,stat,BXDistr->GetBinContent(ibin-5-firstBinCenter+1));
268  }
269  for (int ibin=1;ibin<=7;++ibin) {
270  innerME->find(fullName("QualDistribPhi"))->second->setBinContent(ibin,stat,QualDistr->GetBinContent(ibin));
271  }
272 
273  delete BXDistr;
274  delete QualDistr;
275 
276  if( whME[wh].find(fullName("CorrectBXPhi")) == whME[wh].end() ){
277  bookWheelHistos(ibooker,wh,"ResidualBXPhi");
278  bookWheelHistos(ibooker,wh,"CorrectBXPhi");
279  bookWheelHistos(ibooker,wh,"CorrFractionPhi");
280  bookWheelHistos(ibooker,wh,"2ndFractionPhi");
281  bookWheelHistos(ibooker,wh,"TriggerInclusivePhi");
282  }
283 
284  innerME = &(whME[wh]);
285  innerME->find(fullName("CorrectBXPhi"))->second->setBinContent(sect,stat,BX_OK+0.00001);
286  innerME->find(fullName("ResidualBXPhi"))->second->setBinContent(sect,stat,round(25.*(BXMean-BX_OK))+0.00001);
287  innerME->find(fullName("CorrFractionPhi"))->second->setBinContent(sect,stat,corrFrac);
288  innerME->find(fullName("TriggerInclusivePhi"))->second->setBinContent(sect,stat,besttrigs);
289  innerME->find(fullName("2ndFractionPhi"))->second->setBinContent(sect,stat,secondFrac);
290 
291  }
292 
293  whME[wh].find(fullName("CorrFractionSummary"))->second->setBinContent(sect,stat,corrSummary);
294  whME[wh].find(fullName("2ndFractionSummary"))->second->setBinContent(sect,stat,secondSummary);
295 
296  }
297 
298  if (hwSource=="DDU") {
299  TH2F * ThetaBXvsQual = getHisto<TH2F>(igetter.get(getMEName("ThetaBXvsQual","LocalTriggerTheta", chId)));
300  TH1F * ThetaBestQual = getHisto<TH1F>(igetter.get(getMEName("ThetaBestQual","LocalTriggerTheta", chId)));
301 
302  // no theta triggers in stat 4!
303  if (ThetaBXvsQual && ThetaBestQual && stat<4 && ThetaBestQual->GetEntries()>1) {
304  TH1D* BXH = ThetaBXvsQual->ProjectionY("",4,4,"");
305  int BXOK_bin = BXH->GetEffectiveEntries()>=1 ? BXH->GetMaximumBin(): 10;
306  double BX_OK = ThetaBXvsQual->GetYaxis()->GetBinCenter(BXOK_bin);
307  double trigs = ThetaBestQual->GetEntries();
308  double trigsH = ThetaBestQual->GetBinContent(4);
309  delete BXH;
310 
311  if( whME[wh].find(fullName("HFractionTheta")) == whME[wh].end() ){
312  bookWheelHistos(ibooker,wh,"CorrectBXTheta");
313  bookWheelHistos(ibooker,wh,"HFractionTheta");
314  }
315  std::map<std::string,MonitorElement*> *innerME = &(whME.find(wh)->second);
316  innerME->find(fullName("CorrectBXTheta"))->second->setBinContent(sect,stat,BX_OK+0.00001);
317  innerME->find(fullName("HFractionTheta"))->second->setBinContent(sect,stat,trigsH/trigs);
318 
319  }
320  }
321  else if (hwSource=="TM") {
322  // Perform TM plot analysis (Theta ones)
323  TH2F * ThetaPosvsBX = getHisto<TH2F>(igetter.get(getMEName("PositionvsBX","LocalTriggerTheta", chId)));
324 
325  // no theta triggers in stat 4!
326  if (ThetaPosvsBX && stat<4 && ThetaPosvsBX->GetEntries()>1) {
327  TH1D* BX = ThetaPosvsBX->ProjectionX();
328  int BXOK_bin = BX->GetEffectiveEntries()>=1 ? BX->GetMaximumBin(): 10;
329  double BX_OK = ThetaPosvsBX->GetXaxis()->GetBinCenter(BXOK_bin);
330  delete BX;
331 
332  if( whME[wh].find(fullName("CorrectBXTheta")) == whME[wh].end() ){
333  bookWheelHistos(ibooker,wh,"CorrectBXTheta");
334  }
335  std::map<std::string,MonitorElement*> *innerME = &(whME.find(wh)->second);
336  innerME->find(fullName("CorrectBXTheta"))->second->setBinContent(sect,stat,BX_OK+0.00001);
337  }
338  // After TM the DDU is not used and the TM has information on the Theta Quality
339  // Adding trigger info to compute H fraction (11/10/2016) M.C.Fouz
340  TH2F * ThetaBXvsQual = getHisto<TH2F>(igetter.get(getMEName("ThetaBXvsQual","LocalTriggerTheta", chId)));
341  TH1F * ThetaBestQual = getHisto<TH1F>(igetter.get(getMEName("ThetaBestQual","LocalTriggerTheta", chId)));
342  if (ThetaBXvsQual && ThetaBestQual && stat<4 && ThetaBestQual->GetEntries()>1) {
343  double trigs = ThetaBestQual->GetEntries();
344  double trigsH = ThetaBestQual->GetBinContent(2); // Note that for the new plots H is at bin=2 and not 4 as in DDU!!!!
345  if( whME[wh].find(fullName("HFractionTheta")) == whME[wh].end() ){
346  bookWheelHistos(ibooker,wh,"HFractionTheta");
347  }
348  std::map<std::string,MonitorElement*> *innerME = &(whME.find(wh)->second);
349  innerME->find(fullName("HFractionTheta"))->second->setBinContent(sect,stat,trigsH/trigs);
350  }
351  // END ADDING H Fraction info
352  }
353  }
354 
355  }
356  }
357  }
358  }
359  }
360 
361 
362  for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
363  trigSource = (*iTr);
364  for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
365  hwSource = (*iHw);
366  for (int wh=-2; wh<=2; ++wh){
367  std::map<std::string,MonitorElement*> *innerME = &(whME[wh]);
368  if(hwSource=="COM") {
369  TH2F* matchWhSummary = getHisto<TH2F>(innerME->find(fullName("MatchingSummary"))->second);
370  for (int sect=1; sect<=12; ++sect){
371  int matchErr = 0;
372  int matchNoData = 0;
373  for (int stat=1; stat<=4; ++stat){
374  switch (static_cast<int>(matchWhSummary->GetBinContent(sect,stat))) {
375  case 1:
376  matchNoData++;
377  case 2:
378  matchErr++;
379  }
380  }
381  if (matchNoData == 4) matchErr = 5;
382  cmsME.find(fullName("MatchingSummary"))->second->setBinContent(sect,wh+3,matchErr);
383  }
384  }
385  else {
386  TH2F* corrWhSummary = getHisto<TH2F>(innerME->find(fullName("CorrFractionSummary"))->second);
387  TH2F* secondWhSummary = getHisto<TH2F>(innerME->find(fullName("2ndFractionSummary"))->second);
388  for (int sect=1; sect<=12; ++sect){
389  int corrErr = 0;
390  int secondErr = 0;
391  int corrNoData = 0;
392  int secondNoData = 0;
393  for (int stat=1; stat<=4; ++stat){
394  switch (static_cast<int>(corrWhSummary->GetBinContent(sect,stat))) {
395  case 1:
396  corrNoData++;
397  case 2:
398  corrErr++;
399  }
400  switch (static_cast<int>(secondWhSummary->GetBinContent(sect,stat))) {
401  case 1:
402  secondNoData++;
403  case 2:
404  secondErr++;
405  }
406  }
407  if (corrNoData == 4) corrErr = 5;
408  if (secondNoData == 4) secondErr = 5;
409  cmsME.find(fullName("CorrFractionSummary"))->second->setBinContent(sect,wh+3,corrErr);
410  cmsME.find(fullName("2ndFractionSummary"))->second->setBinContent(sect,wh+3,secondErr);
411  }
412  }
413  }
414  }
415  }
416 
417  fillGlobalSummary(igetter);
418 
419 }
420 
422 
423  float glbPerc[5] = { 1., 0.9, 0.6, 0.3, 0.01 };
424  trigSource = "";
425  hwSource = "TM";
426 
427  int nSecReadout = 0;
428 
429  for (int wh=-2; wh<=2; ++wh) {
430  for (int sect=1; sect<=12; ++sect) {
431 
432  float maxErr = 8.;
433  int corr = cmsME.find(fullName("CorrFractionSummary"))->second->getBinContent(sect,wh+3);
434  int second = cmsME.find(fullName("2ndFractionSummary"))->second->getBinContent(sect,wh+3);
435  int lut=0;
436  MonitorElement * lutsME = igetter.get(topFolder(hwSource=="TM") + "Summaries/TrigLutSummary");
437  if (lutsME) {
438  lut = lutsME->getBinContent(sect,wh+3);
439  maxErr+=4;
440  } else {
441  LogTrace(category()) << "[" << testName
442  << "Test]: TM Lut test Summary histo not found." << endl;
443  }
444  (corr <5 || second<5) && nSecReadout++;
445  int errcode = ((corr<5 ? corr : 4) + (second<5 ? second : 4) + (lut<5 ? lut : 4) );
446  errcode = min(int((errcode/maxErr + 0.01)*5),5);
447  cmsME.find("TrigGlbSummary")->second->setBinContent(sect,wh+3,glbPerc[errcode]);
448 
449  }
450  }
451 
452  if (!nSecReadout)
453  cmsME.find("TrigGlbSummary")->second->Reset(); // white histo id TM is not RO
454 
455  string nEvtsName = "DT/EventInfo/Counters/nProcessedEventsTrigger";
456  MonitorElement * meProcEvts = igetter.get(nEvtsName);
457 
458  if (meProcEvts) {
459  int nProcEvts = meProcEvts->getFloatValue();
460  cmsME.find("TrigGlbSummary")->second->setEntries(nProcEvts < nMinEvts ? 10. : nProcEvts);
461  } else {
462  cmsME.find("TrigGlbSummary")->second->setEntries(nMinEvts + 1);
463  LogVerbatim (category()) << "[" << testName
464  << "Test]: ME: " << nEvtsName << " not found!" << endl;
465  }
466 
467 }
468 
469 
470 
T getUntrackedParameter(std::string const &, T const &) const
void Bookings(DQMStore::IBooker &, DQMStore::IGetter &)
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:304
void runClientDiagnostic(DQMStore::IBooker &, DQMStore::IGetter &)
Run client analysis.
void beginRun(edm::Run const &run, edm::EventSetup const &context)
BeginRun.
virtual ~DTLocalTriggerTest()
Destructor.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
U second(std::pair< T, U > const &p)
void fillGlobalSummary(DQMStore::IGetter &)
double getFloatValue(void) const
EventID const & min(EventID const &lh, EventID const &rh)
Definition: EventID.h:137
tuple lut
Definition: lumiPlot.py:244
#define end
Definition: vmac.h:37
#define LogTrace(id)
JetCorrectorParameters corr
Definition: classes.h:5
string fullName
DTLocalTriggerTest(const edm::ParameterSet &ps)
Constructor.
double getBinContent(int binx) const
get content of bin (1-D)
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
Definition: Run.h:43