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