00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "DQM/DTMonitorClient/src/DTLocalTriggerTest.h"
00012
00013
00014 #include "FWCore/Framework/interface/EventSetup.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016 #include "DQMServices/Core/interface/MonitorElement.h"
00017 #include "DQMServices/Core/interface/DQMStore.h"
00018
00019
00020 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00021 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00022
00023
00024 #include "TF1.h"
00025 #include "TProfile.h"
00026
00027
00028
00029 #include <iostream>
00030 #include <sstream>
00031
00032 using namespace edm;
00033 using namespace std;
00034
00035
00036 DTLocalTriggerTest::DTLocalTriggerTest(const edm::ParameterSet& ps){
00037
00038 setConfig(ps,"DTLocalTrigger");
00039 baseFolderDCC = "DT/03-LocalTrigger-DCC/";
00040 baseFolderDDU = "DT/04-LocalTrigger-DDU/";
00041 nMinEvts = ps.getUntrackedParameter<int>("nEventsCert", 5000);
00042
00043 }
00044
00045
00046 DTLocalTriggerTest::~DTLocalTriggerTest(){
00047
00048 }
00049
00050 void DTLocalTriggerTest::beginJob(){
00051
00052 DTLocalTriggerBaseTest::beginJob();
00053
00054
00055 vector<string>::const_iterator iTr = trigSources.begin();
00056 vector<string>::const_iterator trEnd = trigSources.end();
00057 vector<string>::const_iterator iHw = hwSources.begin();
00058 vector<string>::const_iterator hwEnd = hwSources.end();
00059
00060
00061
00062 if(parameters.getUntrackedParameter<bool>("staticBooking", true)){
00063 for (; iTr != trEnd; ++iTr){
00064 trigSource = (*iTr);
00065 for (; iHw != hwEnd; ++iHw){
00066 hwSource = (*iHw);
00067
00068 for (int wh=-2; wh<=2; ++wh){
00069 if (hwSource=="COM") {
00070 bookWheelHistos(wh,"MatchingPhi");
00071 }
00072 else {
00073 for (int sect=1; sect<=12; ++sect){
00074 bookSectorHistos(wh,sect,"BXDistribPhi");
00075 bookSectorHistos(wh,sect,"QualDistribPhi");
00076 }
00077 bookWheelHistos(wh,"CorrectBXPhi");
00078 bookWheelHistos(wh,"ResidualBXPhi");
00079 bookWheelHistos(wh,"CorrFractionPhi");
00080 bookWheelHistos(wh,"2ndFractionPhi");
00081 bookWheelHistos(wh,"TriggerInclusivePhi");
00082 bookWheelHistos(wh,"CorrectBXTheta");
00083 if (hwSource=="DDU") {
00084 bookWheelHistos(wh,"HFractionTheta");
00085 }
00086 }
00087 }
00088 }
00089 }
00090 }
00091
00092 for (iTr = trigSources.begin(); iTr != trEnd; ++iTr){
00093 trigSource = (*iTr);
00094 for (iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
00095 hwSource = (*iHw);
00096
00097 for (int wh=-2; wh<=2; ++wh){
00098 if (hwSource=="COM") {
00099 bookWheelHistos(wh,"MatchingSummary","Summaries");
00100 }
00101 else {
00102 bookWheelHistos(wh,"CorrFractionSummary","Summaries");
00103 bookWheelHistos(wh,"2ndFractionSummary","Summaries");
00104 }
00105 }
00106 if (hwSource=="COM") {
00107 bookCmsHistos("MatchingSummary","Summaries");
00108 }
00109 else {
00110 bookCmsHistos("CorrFractionSummary");
00111 bookCmsHistos("2ndFractionSummary");
00112 }
00113 if (hwSource=="DCC") {
00114 bookCmsHistos("TrigGlbSummary","",true);
00115 }
00116
00117 }
00118 }
00119
00120 }
00121
00122
00123 void DTLocalTriggerTest::beginRun(const edm::Run& r, const edm::EventSetup& c){
00124
00125 DTLocalTriggerBaseTest::beginRun(r,c);
00126
00127 }
00128
00129
00130 void DTLocalTriggerTest::runClientDiagnostic() {
00131
00132
00133 for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
00134 trigSource = (*iTr);
00135 for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
00136 hwSource = (*iHw);
00137
00138 for (int stat=1; stat<=4; ++stat){
00139 for (int wh=-2; wh<=2; ++wh){
00140 for (int sect=1; sect<=12; ++sect){
00141 DTChamberId chId(wh,stat,sect);
00142 int sector_id = (wh+3)+(sect-1)*5;
00143
00144
00145 if (hwSource=="COM") {
00146
00147 TH2F * DDUvsDCC = getHisto<TH2F>(dbe->get(getMEName("QualDDUvsQualDCC","LocalTriggerPhi", chId)));
00148 if (DDUvsDCC) {
00149
00150 int matchSummary = 1;
00151
00152 if (DDUvsDCC->GetEntries()>1) {
00153
00154 double entries = DDUvsDCC->GetEntries();
00155 double corrEntries = 0;
00156 for (int ibin=2; ibin<=8; ++ibin) {
00157 corrEntries += DDUvsDCC->GetBinContent(ibin,ibin);
00158 }
00159 double corrRatio = corrEntries/entries;
00160
00161 if (corrRatio < parameters.getUntrackedParameter<double>("matchingFracError",.65)){
00162 matchSummary = 2;
00163 }
00164 else if (corrRatio < parameters.getUntrackedParameter<double>("matchingFracWarning",.85)){
00165 matchSummary = 3;
00166 }
00167 else {
00168 matchSummary = 0;
00169 }
00170
00171 if( whME[wh].find(fullName("MatchingPhi")) == whME[wh].end() ){
00172 bookWheelHistos(wh,"MatchingPhi");
00173 }
00174
00175 whME[wh].find(fullName("MatchingPhi"))->second->setBinContent(sect,stat,corrRatio);
00176
00177 }
00178
00179 whME[wh].find(fullName("MatchingSummary"))->second->setBinContent(sect,stat,matchSummary);
00180
00181 }
00182 }
00183 else {
00184
00185 TH2F * BXvsQual = getHisto<TH2F>(dbe->get(getMEName("BXvsQual","LocalTriggerPhi", chId)));
00186 TH1F * BestQual = getHisto<TH1F>(dbe->get(getMEName("BestQual","LocalTriggerPhi", chId)));
00187 TH2F * Flag1stvsQual = getHisto<TH2F>(dbe->get(getMEName("Flag1stvsQual","LocalTriggerPhi", chId)));
00188 if (BXvsQual && Flag1stvsQual && BestQual) {
00189
00190 int corrSummary = 1;
00191 int secondSummary = 1;
00192
00193 if (BestQual->GetEntries()>1) {
00194
00195 TH1D* BXHH = BXvsQual->ProjectionY("",6,7,"");
00196 TH1D* Flag1st = Flag1stvsQual->ProjectionY();
00197 int BXOK_bin = BXHH->GetEntries()>=1 ? BXHH->GetMaximumBin() : 51;
00198 double BXMean = BXHH->GetEntries()>=1 ? BXHH->GetMean() : 51;
00199 double BX_OK = BXvsQual->GetYaxis()->GetBinCenter(BXOK_bin);
00200 double trigsFlag2nd = Flag1st->GetBinContent(2);
00201 double trigs = Flag1st->GetEntries();
00202 double besttrigs = BestQual->GetEntries();
00203 double besttrigsCorr = BestQual->Integral(5,7,"");
00204 delete BXHH;
00205 delete Flag1st;
00206
00207 double corrFrac = besttrigsCorr/besttrigs;
00208 double secondFrac = trigsFlag2nd/trigs;
00209 if (corrFrac < parameters.getUntrackedParameter<double>("corrFracError",.5)){
00210 corrSummary = 2;
00211 }
00212 else if (corrFrac < parameters.getUntrackedParameter<double>("corrFracWarning",.6)){
00213 corrSummary = 3;
00214 }
00215 else {
00216 corrSummary = 0;
00217 }
00218 if (secondFrac > parameters.getUntrackedParameter<double>("secondFracError",.2)){
00219 secondSummary = 2;
00220 }
00221 else if (secondFrac > parameters.getUntrackedParameter<double>("secondFracWarning",.1)){
00222 secondSummary = 3;
00223 }
00224 else {
00225 secondSummary = 0;
00226 }
00227
00228 if( secME[sector_id].find(fullName("BXDistribPhi")) == secME[sector_id].end() ){
00229 bookSectorHistos(wh,sect,"QualDistribPhi");
00230 bookSectorHistos(wh,sect,"BXDistribPhi");
00231 }
00232
00233 TH1D* BXDistr = BXvsQual->ProjectionY();
00234 TH1D* QualDistr = BXvsQual->ProjectionX();
00235 std::map<std::string,MonitorElement*> *innerME = &(secME[sector_id]);
00236
00237 int nbinsBX = BXDistr->GetNbinsX();
00238 int firstBinCenter = static_cast<int>(BXDistr->GetBinCenter(1));
00239 int lastBinCenter = static_cast<int>(BXDistr->GetBinCenter(nbinsBX));
00240 int iMin = firstBinCenter>-4 ? firstBinCenter : -4;
00241 int iMax = lastBinCenter<20 ? lastBinCenter : 20;
00242 for (int ibin=iMin+5;ibin<=iMax+5; ++ibin) {
00243 innerME->find(fullName("BXDistribPhi"))->second->setBinContent(ibin,stat,BXDistr->GetBinContent(ibin-5-firstBinCenter+1));
00244 }
00245 for (int ibin=1;ibin<=7;++ibin) {
00246 innerME->find(fullName("QualDistribPhi"))->second->setBinContent(ibin,stat,QualDistr->GetBinContent(ibin));
00247 }
00248
00249 delete BXDistr;
00250 delete QualDistr;
00251
00252 if( whME[wh].find(fullName("CorrectBXPhi")) == whME[wh].end() ){
00253 bookWheelHistos(wh,"ResidualBXPhi");
00254 bookWheelHistos(wh,"CorrectBXPhi");
00255 bookWheelHistos(wh,"CorrFractionPhi");
00256 bookWheelHistos(wh,"2ndFractionPhi");
00257 bookWheelHistos(wh,"TriggerInclusivePhi");
00258 }
00259
00260 innerME = &(whME[wh]);
00261 innerME->find(fullName("CorrectBXPhi"))->second->setBinContent(sect,stat,BX_OK+0.00001);
00262 innerME->find(fullName("ResidualBXPhi"))->second->setBinContent(sect,stat,round(25.*(BXMean-BX_OK))+0.00001);
00263 innerME->find(fullName("CorrFractionPhi"))->second->setBinContent(sect,stat,corrFrac);
00264 innerME->find(fullName("TriggerInclusivePhi"))->second->setBinContent(sect,stat,besttrigs);
00265 innerME->find(fullName("2ndFractionPhi"))->second->setBinContent(sect,stat,secondFrac);
00266
00267 }
00268
00269 whME[wh].find(fullName("CorrFractionSummary"))->second->setBinContent(sect,stat,corrSummary);
00270 whME[wh].find(fullName("2ndFractionSummary"))->second->setBinContent(sect,stat,secondSummary);
00271
00272 }
00273
00274 if (hwSource=="DDU") {
00275
00276 TH2F * ThetaBXvsQual = getHisto<TH2F>(dbe->get(getMEName("ThetaBXvsQual","LocalTriggerTheta", chId)));
00277 TH1F * ThetaBestQual = getHisto<TH1F>(dbe->get(getMEName("ThetaBestQual","LocalTriggerTheta", chId)));
00278
00279
00280 if (ThetaBXvsQual && ThetaBestQual && stat<4 && ThetaBestQual->GetEntries()>1) {
00281 TH1D* BXH = ThetaBXvsQual->ProjectionY("",4,4,"");
00282 int BXOK_bin = BXH->GetEffectiveEntries()>=1 ? BXH->GetMaximumBin(): 10;
00283 double BX_OK = ThetaBXvsQual->GetYaxis()->GetBinCenter(BXOK_bin);
00284 double trigs = ThetaBestQual->GetEntries();
00285 double trigsH = ThetaBestQual->GetBinContent(4);
00286 delete BXH;
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296 if( whME[wh].find(fullName("HFractionTheta")) == whME[wh].end() ){
00297 bookWheelHistos(wh,"CorrectBXTheta");
00298 bookWheelHistos(wh,"HFractionTheta");
00299 }
00300 std::map<std::string,MonitorElement*> *innerME = &(whME.find(wh)->second);
00301 innerME->find(fullName("CorrectBXTheta"))->second->setBinContent(sect,stat,BX_OK+0.00001);
00302 innerME->find(fullName("HFractionTheta"))->second->setBinContent(sect,stat,trigsH/trigs);
00303
00304 }
00305 }
00306 else if (hwSource=="DCC") {
00307
00308 TH2F * ThetaPosvsBX = getHisto<TH2F>(dbe->get(getMEName("PositionvsBX","LocalTriggerTheta", chId)));
00309
00310
00311 if (ThetaPosvsBX && stat<4 && ThetaPosvsBX->GetEntries()>1) {
00312 TH1D* BX = ThetaPosvsBX->ProjectionX();
00313 int BXOK_bin = BX->GetEffectiveEntries()>=1 ? BX->GetMaximumBin(): 10;
00314 double BX_OK = ThetaPosvsBX->GetXaxis()->GetBinCenter(BXOK_bin);
00315 delete BX;
00316
00317 if( whME[wh].find(fullName("CorrectBXTheta")) == whME[wh].end() ){
00318 bookWheelHistos(wh,"CorrectBXTheta");
00319 }
00320 std::map<std::string,MonitorElement*> *innerME = &(whME.find(wh)->second);
00321 innerME->find(fullName("CorrectBXTheta"))->second->setBinContent(sect,stat,BX_OK+0.00001);
00322
00323 }
00324 }
00325 }
00326
00327 }
00328 }
00329 }
00330 }
00331 }
00332
00333 for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
00334 trigSource = (*iTr);
00335 for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
00336 hwSource = (*iHw);
00337 for (int wh=-2; wh<=2; ++wh){
00338 std::map<std::string,MonitorElement*> *innerME = &(whME[wh]);
00339 if(hwSource=="COM") {
00340 TH2F* matchWhSummary = getHisto<TH2F>(innerME->find(fullName("MatchingSummary"))->second);
00341 for (int sect=1; sect<=12; ++sect){
00342 int matchErr = 0;
00343 int matchNoData = 0;
00344 for (int stat=1; stat<=4; ++stat){
00345 switch (static_cast<int>(matchWhSummary->GetBinContent(sect,stat))) {
00346 case 1:
00347 matchNoData++;
00348 case 2:
00349 matchErr++;
00350 }
00351 }
00352 if (matchNoData == 4) matchErr = 5;
00353 cmsME.find(fullName("MatchingSummary"))->second->setBinContent(sect,wh+3,matchErr);
00354 }
00355 }
00356 else {
00357 TH2F* corrWhSummary = getHisto<TH2F>(innerME->find(fullName("CorrFractionSummary"))->second);
00358 TH2F* secondWhSummary = getHisto<TH2F>(innerME->find(fullName("2ndFractionSummary"))->second);
00359 for (int sect=1; sect<=12; ++sect){
00360 int corrErr = 0;
00361 int secondErr = 0;
00362 int corrNoData = 0;
00363 int secondNoData = 0;
00364 for (int stat=1; stat<=4; ++stat){
00365 switch (static_cast<int>(corrWhSummary->GetBinContent(sect,stat))) {
00366 case 1:
00367 corrNoData++;
00368 case 2:
00369 corrErr++;
00370 }
00371 switch (static_cast<int>(secondWhSummary->GetBinContent(sect,stat))) {
00372 case 1:
00373 secondNoData++;
00374 case 2:
00375 secondErr++;
00376 }
00377 }
00378 if (corrNoData == 4) corrErr = 5;
00379 if (secondNoData == 4) secondErr = 5;
00380 cmsME.find(fullName("CorrFractionSummary"))->second->setBinContent(sect,wh+3,corrErr);
00381 cmsME.find(fullName("2ndFractionSummary"))->second->setBinContent(sect,wh+3,secondErr);
00382 }
00383 }
00384 }
00385 }
00386 }
00387
00388 fillGlobalSummary();
00389
00390 }
00391
00392 void DTLocalTriggerTest::fillGlobalSummary() {
00393
00394 float glbPerc[5] = { 1., 0.9, 0.6, 0.3, 0.01 };
00395 trigSource = "";
00396 hwSource = "DCC";
00397
00398 int nSecReadout = 0;
00399
00400 for (int wh=-2; wh<=2; ++wh) {
00401 for (int sect=1; sect<=12; ++sect) {
00402
00403 float maxErr = 8.;
00404 int corr = cmsME.find(fullName("CorrFractionSummary"))->second->getBinContent(sect,wh+3);
00405 int second = cmsME.find(fullName("2ndFractionSummary"))->second->getBinContent(sect,wh+3);
00406 int lut=0;
00407 MonitorElement * lutsME = dbe->get(topFolder(hwSource=="DCC") + "Summaries/TrigLutSummary");
00408 if (lutsME) {
00409 lut = lutsME->getBinContent(sect,wh+3);
00410 maxErr+=4;
00411 } else {
00412 LogTrace(category()) << "[" << testName
00413 << "Test]: DCC Lut test Summary histo not found." << endl;
00414 }
00415 (corr <5 || second<5) && nSecReadout++;
00416 int errcode = ((corr<5 ? corr : 4) + (second<5 ? second : 4) + (lut<5 ? lut : 4) );
00417 errcode = min(int((errcode/maxErr + 0.01)*5),5);
00418 cmsME.find("TrigGlbSummary")->second->setBinContent(sect,wh+3,glbPerc[errcode]);
00419
00420 }
00421 }
00422
00423 if (!nSecReadout)
00424 cmsME.find("TrigGlbSummary")->second->Reset();
00425
00426 string nEvtsName = "DT/EventInfo/Counters/nProcessedEventsTrigger";
00427 MonitorElement * meProcEvts = dbe->get(nEvtsName);
00428
00429 if (meProcEvts) {
00430 int nProcEvts = meProcEvts->getFloatValue();
00431 cmsME.find("TrigGlbSummary")->second->setEntries(nProcEvts < nMinEvts ? 10. : nProcEvts);
00432 } else {
00433 cmsME.find("TrigGlbSummary")->second->setEntries(nMinEvts + 1);
00434 LogVerbatim (category()) << "[" << testName
00435 << "Test]: ME: " << nEvtsName << " not found!" << endl;
00436 }
00437
00438 }