Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:09:41

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  \author D. Fasanella - INFN Bologna
0005  *
0006  *  threadsafe version (//-) oct/nov 2014 - WATWanAbdullah -ncpp-um-my
0007  *
0008  */
0009 
0010 // This class header
0011 #include "DQM/DTMonitorClient/src/DTTriggerLutTest.h"
0012 
0013 // Framework headers
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 #include "DQMServices/Core/interface/DQMStore.h"
0017 // Geometry
0018 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0019 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0020 
0021 // Root
0022 #include "TF1.h"
0023 //#include "TSpectrum.h"
0024 
0025 //C++ headers
0026 #include <iostream>
0027 #include <sstream>
0028 
0029 using namespace edm;
0030 using namespace std;
0031 
0032 DTTriggerLutTest::DTTriggerLutTest(const edm::ParameterSet& ps) {
0033   setConfig(ps, "DTTriggerLut");
0034   baseFolderTM = "DT/03-LocalTrigger-TM/";
0035   thresholdWarnPhi = ps.getUntrackedParameter<double>("thresholdWarnPhi");
0036   thresholdErrPhi = ps.getUntrackedParameter<double>("thresholdErrPhi");
0037   thresholdWarnPhiB = ps.getUntrackedParameter<double>("thresholdWarnPhiB");
0038   thresholdErrPhiB = ps.getUntrackedParameter<double>("thresholdErrPhiB");
0039   validRange = ps.getUntrackedParameter<double>("validRange");
0040   detailedAnalysis = ps.getUntrackedParameter<bool>("detailedAnalysis");
0041 
0042   bookingdone = false;
0043 }
0044 
0045 DTTriggerLutTest::~DTTriggerLutTest() {}
0046 
0047 void DTTriggerLutTest::Bookings(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0048   bookingdone = true;
0049 
0050   vector<string>::const_iterator iTr = trigSources.begin();
0051   vector<string>::const_iterator trEnd = trigSources.end();
0052   vector<string>::const_iterator iHw = hwSources.begin();
0053   vector<string>::const_iterator hwEnd = hwSources.end();
0054 
0055   //Booking
0056   if (parameters.getUntrackedParameter<bool>("staticBooking")) {
0057     for (; iTr != trEnd; ++iTr) {
0058       trigSource = (*iTr);
0059       for (; iHw != hwEnd; ++iHw) {
0060         hwSource = (*iHw);
0061         // Loop over the TriggerUnits
0062         for (int wh = -2; wh <= 2; ++wh) {
0063           if (detailedAnalysis) {
0064             bookWheelHistos(ibooker, wh, "PhiResidualPercentage");
0065             bookWheelHistos(ibooker, wh, "PhibResidualPercentage");
0066           }
0067 
0068           bookWheelHistos(ibooker, wh, "PhiLutSummary", "Summaries");
0069           bookWheelHistos(ibooker, wh, "PhibLutSummary", "Summaries");
0070 
0071           if (detailedAnalysis) {
0072             bookWheelHistos(ibooker, wh, "PhiResidualMean");
0073             bookWheelHistos(ibooker, wh, "PhiResidualRMS");
0074             bookWheelHistos(ibooker, wh, "PhibResidualMean");
0075             bookWheelHistos(ibooker, wh, "PhibResidualRMS");
0076             bookWheelHistos(ibooker, wh, "CorrelationFactorPhi");
0077             bookWheelHistos(ibooker, wh, "CorrelationFactorPhib");
0078             bookWheelHistos(ibooker, wh, "DoublePeakFlagPhib");
0079           }
0080         }
0081 
0082         bookCmsHistos(ibooker, "TrigLutSummary", "", true);
0083         bookCmsHistos(ibooker, "PhiLutSummary");
0084         bookCmsHistos(ibooker, "PhibLutSummary");
0085         if (detailedAnalysis) {
0086           bookCmsHistos1d(ibooker, "PhiPercentageSummary");
0087           bookCmsHistos1d(ibooker, "PhibPercentageSummary");
0088         }
0089       }
0090     }
0091   }
0092 }
0093 
0094 void DTTriggerLutTest::beginRun(const edm::Run& r, const edm::EventSetup& c) { DTLocalTriggerBaseTest::beginRun(r, c); }
0095 
0096 void DTTriggerLutTest::runClientDiagnostic(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0097   if (!bookingdone)
0098     Bookings(ibooker, igetter);
0099 
0100   // Reset lut percentage 1D summaries
0101   if (detailedAnalysis) {
0102     cmsME.find(fullName("PhiPercentageSummary"))->second->Reset();
0103     cmsME.find(fullName("PhibPercentageSummary"))->second->Reset();
0104   }
0105 
0106   // Loop over Trig & Hw sources
0107   for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr) {
0108     trigSource = (*iTr);
0109     for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw) {
0110       hwSource = (*iHw);
0111       vector<const DTChamber*>::const_iterator chIt = muonGeom->chambers().begin();
0112       vector<const DTChamber*>::const_iterator chEnd = muonGeom->chambers().end();
0113       for (; chIt != chEnd; ++chIt) {
0114         DTChamberId chId((*chIt)->id());
0115         int wh = chId.wheel();
0116         int sect = chId.sector();
0117         int stat = chId.station();
0118 
0119         std::map<std::string, MonitorElement*>& innerME = whME[wh];
0120 
0121         // Make Phi Residual Summary
0122         TH1F* PhiResidual = getHisto<TH1F>(igetter.get(getMEName("PhiResidual", "Segment", chId)));
0123         int phiSummary = 1;
0124         if (PhiResidual && PhiResidual->GetEntries() > 10) {
0125           if (innerME.find(fullName("PhiResidualPercentage")) == innerME.end()) {
0126             bookWheelHistos(ibooker, wh, "PhiResidualPercentage");
0127           }
0128 
0129           float rangeBin = validRange / (PhiResidual->GetBinWidth(1));
0130           float center = (PhiResidual->GetNbinsX()) / 2.;
0131           float perc =
0132               (PhiResidual->Integral(floor(center - rangeBin), ceil(center + rangeBin))) / (PhiResidual->Integral());
0133           fillWhPlot(innerME.find(fullName("PhiResidualPercentage"))->second, sect, stat, perc, false);
0134           phiSummary = performLutTest(perc, thresholdWarnPhi, thresholdErrPhi);
0135           if (detailedAnalysis)
0136             cmsME.find(fullName("PhiPercentageSummary"))->second->Fill(perc);
0137         }
0138 
0139         fillWhPlot(innerME.find(fullName("PhiLutSummary"))->second, sect, stat, phiSummary);
0140 
0141         if (detailedAnalysis) {
0142           if ((phiSummary == 0) || (phiSummary == 3)) {  //Information on the Peak
0143 
0144             if (innerME.find(fullName("PhiResidualMean")) == innerME.end()) {
0145               bookWheelHistos(ibooker, wh, "PhiResidualMean");
0146               bookWheelHistos(ibooker, wh, "PhiResidualRMS");
0147             }
0148 
0149             float center = (PhiResidual->GetNbinsX()) / 2.;
0150             float rangeBin = validRange / (PhiResidual->GetBinWidth(1));
0151             PhiResidual->GetXaxis()->SetRange(floor(center - rangeBin), ceil(center + rangeBin));
0152             float max = PhiResidual->GetMaximumBin();
0153             float maxBin = PhiResidual->GetXaxis()->FindBin(max);
0154             float nBinMax = 0.5 / (PhiResidual->GetBinWidth(1));
0155             PhiResidual->GetXaxis()->SetRange(floor(maxBin - nBinMax), ceil(maxBin + nBinMax));
0156             float Mean = PhiResidual->GetMean();
0157             float rms = PhiResidual->GetRMS();
0158 
0159             fillWhPlot(innerME.find(fullName("PhiResidualMean"))->second, sect, stat, Mean);
0160             fillWhPlot(innerME.find(fullName("PhiResidualRMS"))->second, sect, stat, rms);
0161           }
0162 
0163           TH2F* TrackPhitkvsPhitrig = getHisto<TH2F>(igetter.get(getMEName("PhitkvsPhitrig", "Segment", chId)));
0164 
0165           if (TrackPhitkvsPhitrig && TrackPhitkvsPhitrig->GetEntries() > 100) {
0166             float corr = TrackPhitkvsPhitrig->GetCorrelationFactor();
0167             if (innerME.find(fullName("CorrelationFactorPhi")) == innerME.end()) {
0168               bookWheelHistos(ibooker, wh, "CorrelationFactorPhi");
0169             }
0170             fillWhPlot(innerME.find(fullName("CorrelationFactorPhi"))->second, sect, stat, corr, false);
0171           }
0172         }
0173 
0174         // Make Phib Residual Summary
0175         TH1F* PhibResidual = getHisto<TH1F>(igetter.get(getMEName("PhibResidual", "Segment", chId)));
0176         int phibSummary = stat == 3 ? -1 : 1;  // station 3 has no meaningful MB3 phi bending information
0177 
0178         if (stat != 3 && PhibResidual &&
0179             PhibResidual->GetEntries() > 10) {  // station 3 has no meaningful MB3 phi bending information
0180 
0181           if (innerME.find(fullName("PhibResidualPercentage")) == innerME.end()) {
0182             bookWheelHistos(ibooker, wh, "PhibResidualPercentage");
0183           }
0184 
0185           float rangeBin = validRange / (PhibResidual->GetBinWidth(1));
0186           float center = (PhibResidual->GetNbinsX()) / 2.;
0187           float perc =
0188               (PhibResidual->Integral(floor(center - rangeBin), ceil(center + rangeBin))) / (PhibResidual->Integral());
0189 
0190           fillWhPlot(innerME.find(fullName("PhibResidualPercentage"))->second, sect, stat, perc, false);
0191           phibSummary = performLutTest(perc, thresholdWarnPhiB, thresholdErrPhiB);
0192           if (detailedAnalysis)
0193             cmsME.find(fullName("PhibPercentageSummary"))->second->Fill(perc);
0194         }
0195 
0196         fillWhPlot(innerME.find(fullName("PhibLutSummary"))->second, sect, stat, phibSummary);
0197 
0198         if (detailedAnalysis) {
0199           if ((phibSummary == 0) || (phibSummary == 3)) {
0200             if (innerME.find(fullName("PhibResidualMean")) == innerME.end()) {
0201               bookWheelHistos(ibooker, wh, "PhibResidualMean");
0202               bookWheelHistos(ibooker, wh, "PhibResidualRMS");
0203             }
0204 
0205             float center = (PhibResidual->GetNbinsX()) / 2.;
0206             float rangeBin = validRange / (PhibResidual->GetBinWidth(1));
0207             PhibResidual->GetXaxis()->SetRange(floor(center - rangeBin), ceil(center + rangeBin));
0208             float max = PhibResidual->GetMaximumBin();
0209             float maxBin = PhibResidual->GetXaxis()->FindBin(max);
0210             float nBinMax = 0.5 / (PhibResidual->GetBinWidth(1));
0211             PhibResidual->GetXaxis()->SetRange(floor(maxBin - nBinMax), ceil(maxBin + nBinMax));
0212             float Mean = PhibResidual->GetMean();
0213             float rms = PhibResidual->GetRMS();
0214 
0215             fillWhPlot(innerME.find(fullName("PhibResidualMean"))->second, sect, stat, Mean);
0216             fillWhPlot(innerME.find(fullName("PhibResidualRMS"))->second, sect, stat, rms);
0217           }
0218 
0219           TH2F* TrackPhibtkvsPhibtrig = getHisto<TH2F>(igetter.get(getMEName("PhibtkvsPhibtrig", "Segment", chId)));
0220           if (TrackPhibtkvsPhibtrig && TrackPhibtkvsPhibtrig->GetEntries() > 100) {
0221             float corr = TrackPhibtkvsPhibtrig->GetCorrelationFactor();
0222             if (innerME.find(fullName("CorrelationFactorPhib")) == innerME.end()) {
0223               bookWheelHistos(ibooker, wh, "CorrelationFactorPhib");
0224             }
0225 
0226             fillWhPlot(innerME.find(fullName("CorrelationFactorPhib"))->second, sect, stat, corr, false);
0227           }
0228         }
0229       }
0230     }
0231   }
0232 
0233   // Barrel Summary Plots
0234   for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr) {
0235     trigSource = (*iTr);
0236     for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw) {
0237       hwSource = (*iHw);
0238       for (int wh = -2; wh <= 2; ++wh) {
0239         std::map<std::string, MonitorElement*>* innerME = &(whME[wh]);
0240 
0241         TH2F* phiWhSummary = getHisto<TH2F>(innerME->find(fullName("PhiLutSummary"))->second);
0242         TH2F* phibWhSummary = getHisto<TH2F>(innerME->find(fullName("PhibLutSummary"))->second);
0243 
0244         for (int sect = 1; sect <= 12; ++sect) {
0245           int phiSectorTotal = 0;  // CB dai 1 occhio a questo
0246           int phibSectorTotal = 0;
0247           int nullphi = 0;
0248           int nullphib = 0;
0249           int phiStatus = 5;
0250           int phibStatus = 5;
0251           int glbStatus = 0;
0252 
0253           for (int stat = 1; stat <= 4; ++stat) {
0254             if (phiWhSummary->GetBinContent(sect, stat) == 2) {
0255               phiSectorTotal += 1;
0256               glbStatus += 1;
0257             }
0258             if (phiWhSummary->GetBinContent(sect, stat) == 1)
0259               nullphi += 1;
0260             if (phibWhSummary->GetBinContent(sect, stat) == 2) {
0261               phibSectorTotal += 1;
0262               glbStatus += 1;
0263             }
0264             if (phibWhSummary->GetBinContent(sect, stat) == 1)
0265               nullphib += 1;
0266           }
0267           if (nullphi != 4)
0268             phiStatus = phiSectorTotal;
0269           else
0270             phiStatus = 5;
0271           if (nullphib != 3)
0272             phibStatus = phibSectorTotal;
0273           else
0274             phibStatus = 5;
0275 
0276           cmsME.find("TrigLutSummary")->second->setBinContent(sect, wh + wheelArrayShift, glbStatus);
0277           cmsME.find(fullName("PhiLutSummary"))->second->setBinContent(sect, wh + wheelArrayShift, phiStatus);
0278           cmsME.find(fullName("PhibLutSummary"))->second->setBinContent(sect, wh + wheelArrayShift, phibStatus);
0279         }
0280       }
0281     }
0282   }
0283 }
0284 
0285 int DTTriggerLutTest::performLutTest(double perc, double thresholdWarn, double thresholdErr) {
0286   bool isInWarn = perc < thresholdWarn;
0287   bool isInErr = perc < thresholdErr;
0288 
0289   int result = isInErr ? 2 : isInWarn ? 3 : 0;
0290 
0291   return result;
0292 }
0293 
0294 void DTTriggerLutTest::bookCmsHistos1d(DQMStore::IBooker& ibooker, string hTag, string folder) {
0295   string basedir = topFolder();
0296   if (!folder.empty()) {
0297     basedir += folder + "/";
0298   }
0299   ibooker.setCurrentFolder(basedir);
0300 
0301   string hName = fullName(hTag);
0302   LogTrace(category()) << "[" << testName << "Test]: booking " << basedir << hName;
0303 
0304   MonitorElement* me = ibooker.book1D(hName.c_str(), hName.c_str(), 101, -0.005, 1.005);
0305   me->setAxisTitle("Percentage", 1);
0306   cmsME[hName] = me;
0307 }
0308 
0309 void DTTriggerLutTest::fillWhPlot(MonitorElement* plot, int sect, int stat, float value, bool lessIsBest) {
0310   if (sect > 12) {
0311     int scsect = sect == 13 ? 4 : 10;
0312     if ((value > plot->getBinContent(scsect, stat)) == lessIsBest) {
0313       plot->setBinContent(scsect, stat, value);
0314     }
0315   } else {
0316     plot->setBinContent(sect, stat, value);
0317   }
0318 
0319   return;
0320 }