CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/DQM/DTMonitorClient/src/DTLocalTriggerLutTest.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2010/01/05 10:15:46 $
00005  *  $Revision: 1.12 $
00006  *  \author C. Battilana S. Marcellini - INFN Bologna
00007  */
00008 
00009 
00010 // This class header
00011 #include "DQM/DTMonitorClient/src/DTLocalTriggerLutTest.h"
00012 
00013 // Framework headers
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 // Geometry
00020 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00021 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00022 
00023 // Root
00024 #include "TF1.h"
00025 #include "TProfile.h"
00026 
00027 
00028 //C++ headers
00029 #include <iostream>
00030 #include <sstream>
00031 
00032 using namespace edm;
00033 using namespace std;
00034 
00035 
00036 DTLocalTriggerLutTest::DTLocalTriggerLutTest(const edm::ParameterSet& ps){
00037 
00038   setConfig(ps,"DTLocalTriggerLut");
00039   baseFolderDCC = "DT/03-LocalTrigger-DCC/";
00040   baseFolderDDU = "DT/04-LocalTrigger-DDU/";
00041   thresholdPhiMean  = ps.getUntrackedParameter<double>("thresholdPhiMean",1.5);
00042   thresholdPhiRMS   = ps.getUntrackedParameter<double>("thresholdPhiRMS",.5);
00043   thresholdPhibMean = ps.getUntrackedParameter<double>("thresholdPhibMean",1.5);
00044   thresholdPhibRMS  = ps.getUntrackedParameter<double>("thresholdPhibRMS",.8);
00045   doCorrStudy       = ps.getUntrackedParameter<bool>("doCorrelationStudy",false);
00046 
00047 
00048 }
00049 
00050 
00051 DTLocalTriggerLutTest::~DTLocalTriggerLutTest(){
00052 
00053 }
00054 
00055 
00056 void DTLocalTriggerLutTest::beginJob(){
00057   
00058   DTLocalTriggerBaseTest::beginJob();
00059 
00060   vector<string>::const_iterator iTr   = trigSources.begin();
00061   vector<string>::const_iterator trEnd = trigSources.end();
00062   vector<string>::const_iterator iHw   = hwSources.begin();
00063   vector<string>::const_iterator hwEnd = hwSources.end();
00064 
00065   //Booking
00066   if(parameters.getUntrackedParameter<bool>("staticBooking", true)){
00067     for (; iTr != trEnd; ++iTr){
00068       trigSource = (*iTr);
00069       for (; iHw != hwEnd; ++iHw){
00070         hwSource = (*iHw);
00071         // Loop over the TriggerUnits
00072         for (int wh=-2; wh<=2; ++wh){
00073           bookWheelHistos(wh,"PhiResidualMean");  
00074           bookWheelHistos(wh,"PhiResidualRMS");
00075           bookWheelHistos(wh,"PhibResidualMean");  
00076           bookWheelHistos(wh,"PhibResidualRMS");
00077           if (doCorrStudy) {
00078             bookWheelHistos(wh,"PhiTkvsTrigSlope");  
00079             bookWheelHistos(wh,"PhiTkvsTrigIntercept");  
00080             bookWheelHistos(wh,"PhiTkvsTrigCorr");  
00081             bookWheelHistos(wh,"PhibTkvsTrigSlope");  
00082             bookWheelHistos(wh,"PhibTkvsTrigIntercept");  
00083             bookWheelHistos(wh,"PhibTkvsTrigCorr");
00084           }  
00085         }
00086       }
00087     }
00088   }
00089 
00090   // Summary test histo booking (only static)
00091   for (iTr = trigSources.begin(); iTr != trEnd; ++iTr){
00092     trigSource = (*iTr);
00093     for (iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
00094       hwSource = (*iHw);
00095       // Loop over the TriggerUnits
00096       for (int wh=-2; wh<=2; ++wh){
00097         bookWheelHistos(wh,"PhiLutSummary");
00098         bookWheelHistos(wh,"PhibLutSummary");
00099       }
00100       bookCmsHistos("PhiLutSummary");
00101       bookCmsHistos("PhibLutSummary");
00102     }   
00103   }
00104 
00105 }
00106 
00107 
00108 void DTLocalTriggerLutTest::beginRun(const edm::Run& r, const edm::EventSetup& c){
00109   
00110   DTLocalTriggerBaseTest::beginRun(r,c);
00111 
00112 }
00113 
00114 
00115 void DTLocalTriggerLutTest::runClientDiagnostic() {
00116 
00117   // Loop over Trig & Hw sources
00118   for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
00119     trigSource = (*iTr);
00120     for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
00121       hwSource = (*iHw);
00122       vector<DTChamber*>::const_iterator chIt = muonGeom->chambers().begin();
00123       vector<DTChamber*>::const_iterator chEnd = muonGeom->chambers().end();
00124       for (; chIt != chEnd; ++chIt) {
00125         DTChamberId chId((*chIt)->id());
00126         int wh   = chId.wheel();
00127         int sect = chId.sector();
00128         int stat = chId.station();
00129 
00130 
00131         if (doCorrStudy) {
00132           // Perform Correlation Plots analysis (DCC + segment Phi)
00133           TH2F * TrackPhitkvsPhitrig   = getHisto<TH2F>(dbe->get(getMEName("PhitkvsPhitrig","Segment", chId)));
00134         
00135           if (TrackPhitkvsPhitrig && TrackPhitkvsPhitrig->GetEntries()>10) {
00136             
00137             // Fill client histos
00138             if( whME[wh].find(fullName("PhiTkvsTrigCorr")) == whME[wh].end() ){
00139               bookWheelHistos(wh,"PhiTkvsTrigSlope");  
00140               bookWheelHistos(wh,"PhiTkvsTrigIntercept");  
00141               bookWheelHistos(wh,"PhiTkvsTrigCorr");  
00142             }
00143             
00144             TProfile* PhitkvsPhitrigProf = TrackPhitkvsPhitrig->ProfileX();
00145             double phiInt   = 0;
00146             double phiSlope = 0;
00147             double phiCorr  = 0;
00148             try {
00149               PhitkvsPhitrigProf->Fit("pol1","CQO");
00150               TF1 *ffPhi= PhitkvsPhitrigProf->GetFunction("pol1");
00151               if (ffPhi) {
00152                 phiInt   = ffPhi->GetParameter(0);
00153                 phiSlope = ffPhi->GetParameter(1);
00154                 phiCorr  = TrackPhitkvsPhitrig->GetCorrelationFactor();
00155               }
00156             } catch (...) {
00157               edm::LogError(category()) << "[" << testName << "Test]: Error fitting PhitkvsPhitrig for Wheel " << wh 
00158                                         <<" Sector " << sect << " Station " << stat;
00159             }
00160             
00161             std::map<std::string,MonitorElement*> &innerME = whME[wh];
00162             fillWhPlot(innerME.find(fullName("PhiTkvsTrigSlope"))->second,sect,stat,phiSlope-1);
00163             fillWhPlot(innerME.find(fullName("PhiTkvsTrigIntercept"))->second,sect,stat,phiInt);
00164             fillWhPlot(innerME.find(fullName("PhiTkvsTrigCorr"))->second,sect,stat,phiCorr,false);
00165             
00166           }
00167         
00168           // Perform Correlation Plots analysis (DCC + segment Phib)
00169           TH2F * TrackPhibtkvsPhibtrig = getHisto<TH2F>(dbe->get(getMEName("PhibtkvsPhibtrig","Segment", chId)));
00170           
00171           if (stat != 3 && TrackPhibtkvsPhibtrig && TrackPhibtkvsPhibtrig->GetEntries()>10) {// station 3 has no meaningful MB3 phi bending information
00172           
00173             // Fill client histos
00174             if( whME[wh].find(fullName("PhibTkvsTrigCorr")) == whME[wh].end() ){
00175               bookWheelHistos(wh,"PhibTkvsTrigSlope");  
00176               bookWheelHistos(wh,"PhibTkvsTrigIntercept");  
00177               bookWheelHistos(wh,"PhibTkvsTrigCorr");  
00178             }
00179             
00180             TProfile* PhibtkvsPhibtrigProf = TrackPhibtkvsPhibtrig->ProfileX(); 
00181             double phibInt  = 0;
00182             double phibSlope = 0;
00183             double phibCorr  = 0;
00184             try {
00185               PhibtkvsPhibtrigProf->Fit("pol1","CQO");
00186               TF1 *ffPhib= PhibtkvsPhibtrigProf->GetFunction("pol1");
00187               if (ffPhib) {
00188                 phibInt   = ffPhib->GetParameter(0);
00189                 phibSlope = ffPhib->GetParameter(1);
00190                 phibCorr  = TrackPhibtkvsPhibtrig->GetCorrelationFactor();
00191               }
00192             } catch (...) {
00193               edm::LogError(category()) << "[" << testName << "Test]: Error fitting PhibtkvsPhibtrig for Wheel " << wh 
00194                                         <<" Sector " << sect << " Station " << stat;
00195             }
00196             
00197             std::map<std::string,MonitorElement*> &innerME = whME[wh];
00198             fillWhPlot(innerME.find(fullName("PhibTkvsTrigSlope"))->second,sect,stat,phibSlope-1);
00199             fillWhPlot(innerME.find(fullName("PhibTkvsTrigIntercept"))->second,sect,stat,phibInt);
00200             fillWhPlot(innerME.find(fullName("PhibTkvsTrigCorr"))->second,sect,stat,phibCorr,false);
00201             
00202           }
00203 
00204         }
00205         
00206         // Make Phi Residual Summary
00207         TH1F * PhiResidual = getHisto<TH1F>(dbe->get(getMEName("PhiResidual","Segment", chId)));
00208         int phiSummary = 1;
00209         
00210         if (PhiResidual && PhiResidual->GetEffectiveEntries()>10) {
00211           
00212           // Fill client histos
00213           if( whME[wh].find(fullName("PhiResidualMean")) == whME[wh].end() ){
00214             bookWheelHistos(wh,"PhiResidualMean");  
00215             bookWheelHistos(wh,"PhiResidualRMS");  
00216           }
00217           
00218           double peak = PhiResidual->GetBinCenter(PhiResidual->GetMaximumBin());
00219           double phiMean = 0;
00220           double phiRMS  = 0;
00221           try {
00222             PhiResidual->Fit("gaus","CQO","",peak-5,peak+5);
00223             TF1 *ffPhi = PhiResidual->GetFunction("gaus");
00224             if ( ffPhi ) {
00225               phiMean = ffPhi->GetParameter(1);
00226               phiRMS  = ffPhi->GetParameter(2);
00227             }
00228           } catch (...) {
00229             edm::LogError(category()) << "[" << testName << "Test]: Error fitting PhiResidual for Wheel " << wh 
00230                                       <<" Sector " << sect << " Station " << stat;
00231           }
00232           
00233           std::map<std::string,MonitorElement*> &innerME = whME[wh];
00234           fillWhPlot(innerME.find(fullName("PhiResidualMean"))->second,sect,stat,phiMean);
00235           fillWhPlot(innerME.find(fullName("PhiResidualRMS"))->second,sect,stat,phiRMS);
00236           
00237           phiSummary = performLutTest(phiMean,phiRMS,thresholdPhiMean,thresholdPhiRMS);
00238           
00239         }
00240         fillWhPlot(whME[wh].find(fullName("PhiLutSummary"))->second,sect,stat,phiSummary);
00241         
00242         // Make Phib Residual Summary
00243         TH1F * PhibResidual = getHisto<TH1F>(dbe->get(getMEName("PhibResidual","Segment", chId)));
00244         int phibSummary = stat==3 ? 0 : 1; // station 3 has no meaningful MB3 phi bending information
00245         
00246         if (stat != 3 && PhibResidual && PhibResidual->GetEffectiveEntries()>10) {// station 3 has no meaningful MB3 phi bending information
00247           
00248           // Fill client histos
00249           if( whME[wh].find(fullName("PhibResidualMean")) == whME[wh].end() ){
00250             bookWheelHistos(wh,"PhibResidualMean");  
00251             bookWheelHistos(wh,"PhibResidualRMS");  
00252           }
00253           
00254           double peak = PhibResidual->GetBinCenter(PhibResidual->GetMaximumBin());
00255           double phibMean = 0;
00256           double phibRMS  = 0;
00257           try {
00258             PhibResidual->Fit("gaus","CQO","",peak-5,peak+5);
00259             TF1 *ffPhib = PhibResidual->GetFunction("gaus");
00260             if ( ffPhib ) {
00261               phibMean = ffPhib->GetParameter(1);
00262               phibRMS  = ffPhib->GetParameter(2);
00263             }
00264           } catch (...) {
00265             edm::LogError(category()) << "[" << testName << "Test]: Error fitting PhibResidual for Wheel " << wh 
00266                                       <<" Sector " << sect << " Station " << stat;
00267           }
00268           
00269           std::map<std::string,MonitorElement*> &innerME = whME[wh];
00270           fillWhPlot(innerME.find(fullName("PhibResidualMean"))->second,sect,stat,phibMean);
00271           fillWhPlot(innerME.find(fullName("PhibResidualRMS"))->second,sect,stat,phibRMS);
00272           
00273           phibSummary = performLutTest(phibMean,phibRMS,thresholdPhibMean,thresholdPhibRMS);
00274           
00275         }
00276         fillWhPlot(whME[wh].find(fullName("PhibLutSummary"))->second,sect,stat,phibSummary);
00277         
00278       }
00279     }
00280   }
00281   
00282   // Barrel Summary Plots
00283   for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
00284     trigSource = (*iTr);
00285     for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
00286       hwSource = (*iHw);  
00287       for (int wh=-2; wh<=2; ++wh){
00288         std::map<std::string,MonitorElement*> *innerME = &(whME[wh]);
00289         
00290         TH2F* phiWhSummary   = getHisto<TH2F>(innerME->find(fullName("PhiLutSummary"))->second);
00291         TH2F* phibWhSummary  = getHisto<TH2F>(innerME->find(fullName("PhibLutSummary"))->second);
00292         for (int sect=1; sect<=12; ++sect){
00293           int phiErr     = 0;
00294           int phibErr    = 0;
00295           int phiNoData  = 0;
00296           int phibNoData = 0;
00297           for (int stat=1; stat<=4; ++stat){
00298             switch (static_cast<int>(phiWhSummary->GetBinContent(sect,stat))) {
00299             case 1:
00300               phiNoData++;
00301             case 2:
00302             case 3:
00303               phiErr++;
00304             }
00305             switch (static_cast<int>(phibWhSummary->GetBinContent(sect,stat))) {
00306             case 1:
00307               phibNoData++;
00308             case 2:
00309             case 3:
00310               phibErr++;
00311             }
00312           }
00313           if (phiNoData == 4)  phiErr  = 5;
00314           if (phibNoData == 3) phibErr = 5;  // MB3 has no phib information
00315           cmsME.find(fullName("PhiLutSummary"))->second->setBinContent(sect,wh+3,phiErr);
00316           cmsME.find(fullName("PhibLutSummary"))->second->setBinContent(sect,wh+3,phibErr);
00317         }
00318       }
00319     }
00320   }
00321 
00322 }
00323 
00324 int DTLocalTriggerLutTest::performLutTest(double mean,double RMS,double thresholdMean,double thresholdRMS) {
00325 
00326   bool meanErr = fabs(mean)>thresholdMean;
00327   bool rmsErr  = RMS>thresholdRMS;
00328 
00329   return (meanErr || rmsErr) ? 2+(meanErr!=rmsErr) : 0 ;
00330 
00331 }
00332 
00333 void DTLocalTriggerLutTest::fillWhPlot(MonitorElement *plot, int sect, int stat, float value, bool lessIsBest) {
00334 
00335   if (sect>12) {
00336     int scsect = sect==13 ? 4 : 10;
00337     if ( (fabs(value)>fabs(plot->getBinContent(scsect,stat)))==lessIsBest) {
00338       plot->setBinContent(scsect,stat,value);
00339     }
00340   }
00341   else {
00342     plot->setBinContent(sect,stat,value);
00343   }
00344 
00345   return;
00346 
00347 }
00348