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