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