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  }
86  }
87  }
88  }
89  }
90  // Summary test histo booking (only static)
91  for (iTr = trigSources.begin(); iTr != trEnd; ++iTr){
92  trigSource = (*iTr);
93  for (iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
94  hwSource = (*iHw);
95  // Loop over the TriggerUnits
96  for (int wh=-2; wh<=2; ++wh){
97  if (hwSource=="COM") {
98 
99  bookWheelHistos(ibooker,wh,"MatchingSummary","Summaries");
100  }
101  else {
102 
103  bookWheelHistos(ibooker,wh,"CorrFractionSummary","Summaries");
104  bookWheelHistos(ibooker,wh,"2ndFractionSummary","Summaries");
105  }
106  }
107  if (hwSource=="COM") {
108 
109  bookCmsHistos(ibooker,"MatchingSummary","Summaries");
110  }
111  else {
112 
113  bookCmsHistos(ibooker,"CorrFractionSummary");
114  bookCmsHistos(ibooker,"2ndFractionSummary");
115  }
116  if (hwSource=="TM") {
117 
118  bookCmsHistos(ibooker,"TrigGlbSummary","",true);
119  bookCmsHistos(ibooker,"TrigGlbSummary","",true);
120  }
121 
122  }
123  }
124 
125  bookingdone = 1;
126 }
127 
128 
130 
132 
133 }
134 
136 
137  if (!bookingdone) Bookings(ibooker,igetter);
138 
139  // Loop over Trig & Hw sources
140  for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
141  trigSource = (*iTr);
142 
143  for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
144  hwSource = (*iHw);
145  // Loop over the TriggerUnits
146  for (int stat=1; stat<=4; ++stat){
147  for (int wh=-2; wh<=2; ++wh){
148  for (int sect=1; sect<=12; ++sect){
149  DTChamberId chId(wh,stat,sect);
150  int sector_id = (wh+3)+(sect-1)*5;
151 
152  if (hwSource=="COM") {
153  // Perform TM-DDU matching test and generates summaries (Phi view)
154  TH2F * DDUvsTM = getHisto<TH2F>(igetter.get(getMEName("QualDDUvsQualTM","LocalTriggerPhiIn", chId)));
155  if (DDUvsTM) {
156 
157  int matchSummary = 1;
158 
159  if (DDUvsTM->GetEntries()>1) {
160 
161  double entries = DDUvsTM->GetEntries();
162  double corrEntries = 0;
163  for (int ibin=2; ibin<=8; ++ibin) {
164  corrEntries += DDUvsTM->GetBinContent(ibin,ibin);
165  }
166  double corrRatio = corrEntries/entries;
167 
168  if (corrRatio < parameters.getUntrackedParameter<double>("matchingFracError",.65)){
169  matchSummary = 2;
170  }
171  else if (corrRatio < parameters.getUntrackedParameter<double>("matchingFracWarning",.85)){
172  matchSummary = 3;
173  }
174  else {
175  matchSummary = 0;
176  }
177 
178  if( whME[wh].find(fullName("MatchingPhi")) == whME[wh].end() ){
179  bookWheelHistos(ibooker,wh,"MatchingPhi");
180  }
181 
182  whME[wh].find(fullName("MatchingPhi"))->second->setBinContent(sect,stat,corrRatio);
183 
184  }
185 
186  whME[wh].find(fullName("MatchingSummary"))->second->setBinContent(sect,stat,matchSummary);
187 
188  }
189  }
190  else {
191  TH2F * BXvsQual = getHisto<TH2F>(igetter.get(getMEName("BXvsQual_In","LocalTriggerPhiIn", chId)));
192  TH1F * BestQual = getHisto<TH1F>(igetter.get(getMEName("BestQual_In","LocalTriggerPhiIn", chId)));
193  TH2F * Flag1stvsQual = getHisto<TH2F>(igetter.get(getMEName("Flag1stvsQual_In","LocalTriggerPhiIn", chId)));
194  if (BXvsQual && Flag1stvsQual && BestQual) {
195  int corrSummary = 1;
196  int secondSummary = 1;
197 
198  if (BestQual->GetEntries()>1) {
199  TH1D* BXHH = BXvsQual->ProjectionY("",6,7,"");
200  TH1D* Flag1st = Flag1stvsQual->ProjectionY();
201  int BXOK_bin = BXHH->GetEntries()>=1 ? BXHH->GetMaximumBin() : 51;
202  double BXMean = BXHH->GetEntries()>=1 ? BXHH->GetMean() : 51;
203  double BX_OK = BXvsQual->GetYaxis()->GetBinCenter(BXOK_bin);
204  double trigsFlag2nd = Flag1st->GetBinContent(2);
205  double trigs = Flag1st->GetEntries();
206  double besttrigs = BestQual->GetEntries();
207  double besttrigsCorr = BestQual->Integral(5,7,"");
208  delete BXHH;
209  delete Flag1st;
210 
211  double corrFrac = besttrigsCorr/besttrigs;
212  double secondFrac = trigsFlag2nd/trigs;
213  if (corrFrac < parameters.getUntrackedParameter<double>("corrFracError",.5)){
214  corrSummary = 2;
215  }
216  else if (corrFrac < parameters.getUntrackedParameter<double>("corrFracWarning",.6)){
217  corrSummary = 3;
218  }
219  else {
220  corrSummary = 0;
221  }
222  if (secondFrac > parameters.getUntrackedParameter<double>("secondFracError",.2)){
223  secondSummary = 2;
224  }
225  else if (secondFrac > parameters.getUntrackedParameter<double>("secondFracWarning",.1)){
226  secondSummary = 3;
227  }
228  else {
229  secondSummary = 0;
230  }
231 
232  if( secME[sector_id].find(fullName("BXDistribPhi")) == secME[sector_id].end() ){
233  bookSectorHistos(ibooker,wh,sect,"QualDistribPhi");
234  bookSectorHistos(ibooker,wh,sect,"BXDistribPhi");
235  }
236 
237  TH1D* BXDistr = BXvsQual->ProjectionY();
238  TH1D* QualDistr = BXvsQual->ProjectionX();
239  std::map<std::string,MonitorElement*> *innerME = &(secME[sector_id]);
240 
241  int nbinsBX = BXDistr->GetNbinsX();
242  int firstBinCenter = static_cast<int>(BXDistr->GetBinCenter(1));
243  int lastBinCenter = static_cast<int>(BXDistr->GetBinCenter(nbinsBX));
244  int iMin = firstBinCenter>-4 ? firstBinCenter : -4;
245  int iMax = lastBinCenter<20 ? lastBinCenter : 20;
246  for (int ibin=iMin+5;ibin<=iMax+5; ++ibin) {
247  innerME->find(fullName("BXDistribPhi"))->second->setBinContent(ibin,stat,BXDistr->GetBinContent(ibin-5-firstBinCenter+1));
248  }
249  for (int ibin=1;ibin<=7;++ibin) {
250  innerME->find(fullName("QualDistribPhi"))->second->setBinContent(ibin,stat,QualDistr->GetBinContent(ibin));
251  }
252 
253  delete BXDistr;
254  delete QualDistr;
255 
256  if( whME[wh].find(fullName("CorrectBXPhi")) == whME[wh].end() ){
257  bookWheelHistos(ibooker,wh,"ResidualBXPhi");
258  bookWheelHistos(ibooker,wh,"CorrectBXPhi");
259  bookWheelHistos(ibooker,wh,"CorrFractionPhi");
260  bookWheelHistos(ibooker,wh,"2ndFractionPhi");
261  bookWheelHistos(ibooker,wh,"TriggerInclusivePhi");
262  }
263 
264  innerME = &(whME[wh]);
265  innerME->find(fullName("CorrectBXPhi"))->second->setBinContent(sect,stat,BX_OK+0.00001);
266  innerME->find(fullName("ResidualBXPhi"))->second->setBinContent(sect,stat,round(25.*(BXMean-BX_OK))+0.00001);
267  innerME->find(fullName("CorrFractionPhi"))->second->setBinContent(sect,stat,corrFrac);
268  innerME->find(fullName("TriggerInclusivePhi"))->second->setBinContent(sect,stat,besttrigs);
269  innerME->find(fullName("2ndFractionPhi"))->second->setBinContent(sect,stat,secondFrac);
270  }
271 
272  whME[wh].find(fullName("CorrFractionSummary"))->second->setBinContent(sect,stat,corrSummary);
273  whME[wh].find(fullName("2ndFractionSummary"))->second->setBinContent(sect,stat,secondSummary);
274 
275  }
276 
277  if (hwSource=="DDU") {
278  TH2F * ThetaBXvsQual = getHisto<TH2F>(igetter.get(getMEName("ThetaBXvsQual","LocalTriggerTheta", chId)));
279  TH1F * ThetaBestQual = getHisto<TH1F>(igetter.get(getMEName("ThetaBestQual","LocalTriggerTheta", chId)));
280 
281  // no theta triggers in stat 4!
282  if (ThetaBXvsQual && ThetaBestQual && stat<4 && ThetaBestQual->GetEntries()>1) {
283  TH1D* BXH = ThetaBXvsQual->ProjectionY("",4,4,"");
284  int BXOK_bin = BXH->GetEffectiveEntries()>=1 ? BXH->GetMaximumBin(): 10;
285  double BX_OK = ThetaBXvsQual->GetYaxis()->GetBinCenter(BXOK_bin);
286  double trigs = ThetaBestQual->GetEntries();
287  double trigsH = ThetaBestQual->GetBinContent(4);
288  delete BXH;
289 
290  if( whME[wh].find(fullName("HFractionTheta")) == whME[wh].end() ){
291  bookWheelHistos(ibooker,wh,"CorrectBXTheta");
292  bookWheelHistos(ibooker,wh,"HFractionTheta");
293  }
294  std::map<std::string,MonitorElement*> *innerME = &(whME.find(wh)->second);
295  innerME->find(fullName("CorrectBXTheta"))->second->setBinContent(sect,stat,BX_OK+0.00001);
296  innerME->find(fullName("HFractionTheta"))->second->setBinContent(sect,stat,trigsH/trigs);
297 
298  }
299  }
300  else if (hwSource=="TM") {
301  // Perform TM plot analysis (Theta ones)
302  TH2F * ThetaPosvsBX = getHisto<TH2F>(igetter.get(getMEName("PositionvsBX","LocalTriggerTheta", chId)));
303 
304  // no theta triggers in stat 4!
305  if (ThetaPosvsBX && stat<4 && ThetaPosvsBX->GetEntries()>1) {
306  TH1D* BX = ThetaPosvsBX->ProjectionX();
307  int BXOK_bin = BX->GetEffectiveEntries()>=1 ? BX->GetMaximumBin(): 10;
308  double BX_OK = ThetaPosvsBX->GetXaxis()->GetBinCenter(BXOK_bin);
309  delete BX;
310 
311  if( whME[wh].find(fullName("CorrectBXTheta")) == whME[wh].end() ){
312  bookWheelHistos(ibooker,wh,"CorrectBXTheta");
313  }
314  std::map<std::string,MonitorElement*> *innerME = &(whME.find(wh)->second);
315  innerME->find(fullName("CorrectBXTheta"))->second->setBinContent(sect,stat,BX_OK+0.00001);
316  }
317  // After TM the DDU is not used and the TM has information on the Theta Quality
318  // Adding trigger info to compute H fraction (11/10/2016) M.C.Fouz
319  TH2F * ThetaBXvsQual = getHisto<TH2F>(igetter.get(getMEName("ThetaBXvsQual","LocalTriggerTheta", chId)));
320  TH1F * ThetaBestQual = getHisto<TH1F>(igetter.get(getMEName("ThetaBestQual","LocalTriggerTheta", chId)));
321  if (ThetaBXvsQual && ThetaBestQual && stat<4 && ThetaBestQual->GetEntries()>1) {
322  double trigs = ThetaBestQual->GetEntries();
323  double trigsH = ThetaBestQual->GetBinContent(2); // Note that for the new plots H is at bin=2 and not 4 as in DDU!!!!
324  if( whME[wh].find(fullName("HFractionTheta")) == whME[wh].end() ){
325  bookWheelHistos(ibooker,wh,"HFractionTheta");
326  }
327  std::map<std::string,MonitorElement*> *innerME = &(whME.find(wh)->second);
328  innerME->find(fullName("HFractionTheta"))->second->setBinContent(sect,stat,trigsH/trigs);
329  }
330  // END ADDING H Fraction info
331  }
332  }
333 
334  }
335  }
336  }
337  }
338  }
339 
340 
341  for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
342  trigSource = (*iTr);
343  for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
344  hwSource = (*iHw);
345  for (int wh=-2; wh<=2; ++wh){
346  std::map<std::string,MonitorElement*> *innerME = &(whME[wh]);
347  if(hwSource=="COM") {
348  TH2F* matchWhSummary = getHisto<TH2F>(innerME->find(fullName("MatchingSummary"))->second);
349  for (int sect=1; sect<=12; ++sect){
350  int matchErr = 0;
351  int matchNoData = 0;
352  for (int stat=1; stat<=4; ++stat){
353  switch (static_cast<int>(matchWhSummary->GetBinContent(sect,stat))) {
354  case 1:
355  matchNoData++;
356  case 2:
357  matchErr++;
358  }
359  }
360  if (matchNoData == 4) matchErr = 5;
361  cmsME.find(fullName("MatchingSummary"))->second->setBinContent(sect,wh+3,matchErr);
362  }
363  }
364  else {
365  TH2F* corrWhSummary = getHisto<TH2F>(innerME->find(fullName("CorrFractionSummary"))->second);
366  TH2F* secondWhSummary = getHisto<TH2F>(innerME->find(fullName("2ndFractionSummary"))->second);
367  for (int sect=1; sect<=12; ++sect){
368  int corrErr = 0;
369  int secondErr = 0;
370  int corrNoData = 0;
371  int secondNoData = 0;
372  for (int stat=1; stat<=4; ++stat){
373  switch (static_cast<int>(corrWhSummary->GetBinContent(sect,stat))) {
374  case 1:
375  corrNoData++;
376  case 2:
377  corrErr++;
378  }
379  switch (static_cast<int>(secondWhSummary->GetBinContent(sect,stat))) {
380  case 1:
381  secondNoData++;
382  case 2:
383  secondErr++;
384  }
385  }
386  if (corrNoData == 4) corrErr = 5;
387  if (secondNoData == 4) secondErr = 5;
388  cmsME.find(fullName("CorrFractionSummary"))->second->setBinContent(sect,wh+3,corrErr);
389  cmsME.find(fullName("2ndFractionSummary"))->second->setBinContent(sect,wh+3,secondErr);
390  }
391  }
392  }
393  }
394  }
395 
396  fillGlobalSummary(igetter);
397 
398 }
399 
401 
402  float glbPerc[5] = { 1., 0.9, 0.6, 0.3, 0.01 };
403  trigSource = "";
404  hwSource = "TM";
405 
406  int nSecReadout = 0;
407 
408  for (int wh=-2; wh<=2; ++wh) {
409  for (int sect=1; sect<=12; ++sect) {
410 
411  float maxErr = 8.;
412  int corr = cmsME.find(fullName("CorrFractionSummary"))->second->getBinContent(sect,wh+3);
413  int second = cmsME.find(fullName("2ndFractionSummary"))->second->getBinContent(sect,wh+3);
414  int lut=0;
415  MonitorElement * lutsME = igetter.get(topFolder(hwSource=="TM") + "Summaries/TrigLutSummary");
416  if (lutsME) {
417  lut = lutsME->getBinContent(sect,wh+3);
418  maxErr+=4;
419  } else {
420  LogTrace(category()) << "[" << testName
421  << "Test]: TM Lut test Summary histo not found." << endl;
422  }
423  (corr <5 || second<5) && nSecReadout++;
424  int errcode = ((corr<5 ? corr : 4) + (second<5 ? second : 4) + (lut<5 ? lut : 4) );
425  errcode = min(int((errcode/maxErr + 0.01)*5),5);
426  cmsME.find("TrigGlbSummary")->second->setBinContent(sect,wh+3,glbPerc[errcode]);
427 
428  }
429  }
430 
431  if (!nSecReadout)
432  cmsME.find("TrigGlbSummary")->second->Reset(); // white histo id TM is not RO
433 
434  string nEvtsName = "DT/EventInfo/Counters/nProcessedEventsTrigger";
435  MonitorElement * meProcEvts = igetter.get(nEvtsName);
436 
437  if (meProcEvts) {
438  int nProcEvts = meProcEvts->getFloatValue();
439  cmsME.find("TrigGlbSummary")->second->setEntries(nProcEvts < nMinEvts ? 10. : nProcEvts);
440  } else {
441  cmsME.find("TrigGlbSummary")->second->setEntries(nMinEvts + 1);
442  LogVerbatim (category()) << "[" << testName
443  << "Test]: ME: " << nEvtsName << " not found!" << endl;
444  }
445 
446 }
447 
448 
449 
T getUntrackedParameter(std::string const &, T const &) const
void Bookings(DQMStore::IBooker &, DQMStore::IGetter &)
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:305
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:42