CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/DQM/DTMonitorClient/src/DTTriggerLutTest.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2011/06/10 13:50:12 $
00005  *  $Revision: 1.1 $
00006  *  \author D. Fasanella - INFN Bologna
00007  */
00008 
00009 
00010 // This class header
00011 #include "DQM/DTMonitorClient/src/DTTriggerLutTest.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 // Geometry
00019 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00020 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00021 
00022 // Root
00023 #include "TF1.h"
00024 //#include "TSpectrum.h"
00025 
00026 
00027 //C++ headers
00028 #include <iostream>
00029 #include <sstream>
00030 
00031 
00032 using namespace edm;
00033 using namespace std;
00034 
00035 
00036 DTTriggerLutTest::DTTriggerLutTest(const edm::ParameterSet& ps){
00037         
00038   setConfig(ps,"DTTriggerLut");
00039   baseFolderDCC = "DT/03-LocalTrigger-DCC/";
00040   baseFolderDDU = "DT/04-LocalTrigger-DDU/";
00041   thresholdWarnPhi  = ps.getUntrackedParameter<double>("thresholdWarnPhi");
00042   thresholdErrPhi   = ps.getUntrackedParameter<double>("thresholdErrPhi");
00043   thresholdWarnPhiB = ps.getUntrackedParameter<double>("thresholdWarnPhiB");
00044   thresholdErrPhiB  = ps.getUntrackedParameter<double>("thresholdErrPhiB");
00045   validRange = ps.getUntrackedParameter<double>("validRange");
00046   detailedAnalysis = ps.getUntrackedParameter<bool>("detailedAnalysis");
00047 
00048 }
00049 
00050 
00051 DTTriggerLutTest::~DTTriggerLutTest(){
00052 
00053 }
00054 
00055 
00056 void DTTriggerLutTest::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")){
00067     
00068     for (; iTr != trEnd; ++iTr){
00069       trigSource = (*iTr);
00070       for (; iHw != hwEnd; ++iHw){
00071         hwSource = (*iHw);
00072         // Loop over the TriggerUnits
00073         for (int wh=-2; wh<=2; ++wh){
00074           if (detailedAnalysis){
00075             bookWheelHistos(wh,"PhiResidualPercentage");  
00076             bookWheelHistos(wh,"PhibResidualPercentage"); 
00077           }
00078 
00079           bookWheelHistos(wh,"PhiLutSummary","Summaries");
00080           bookWheelHistos(wh,"PhibLutSummary","Summaries");      
00081           
00082           if (detailedAnalysis){
00083             bookWheelHistos(wh,"PhiResidualMean");  
00084             bookWheelHistos(wh,"PhiResidualRMS");
00085             bookWheelHistos(wh,"PhibResidualMean");  
00086             bookWheelHistos(wh,"PhibResidualRMS");
00087             bookWheelHistos(wh,"CorrelationFactorPhi");
00088             bookWheelHistos(wh,"CorrelationFactorPhib");
00089             bookWheelHistos(wh,"DoublePeakFlagPhib");
00090           }
00091 
00092         }
00093 
00094         bookCmsHistos("TrigLutSummary","",true);
00095         bookCmsHistos("PhiLutSummary");
00096         bookCmsHistos("PhibLutSummary");
00097         if (detailedAnalysis){
00098           bookCmsHistos1d("PhiPercentageSummary");
00099           bookCmsHistos1d("PhibPercentageSummary");
00100         }
00101       }
00102     }
00103   }     
00104 
00105 }
00106 
00107 
00108 void DTTriggerLutTest::beginRun(const edm::Run& r, const edm::EventSetup& c){
00109         
00110   DTLocalTriggerBaseTest::beginRun(r,c);
00111   
00112 }
00113 
00114 
00115 void DTTriggerLutTest::runClientDiagnostic() {
00116 
00117   // Reset lut percentage 1D summaries
00118   if (detailedAnalysis){
00119     cmsME.find(fullName("PhiPercentageSummary"))->second->Reset();
00120     cmsME.find(fullName("PhibPercentageSummary"))->second->Reset();
00121   }
00122 
00123   // Loop over Trig & Hw sources
00124   for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
00125     trigSource = (*iTr);
00126     for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
00127       hwSource = (*iHw);
00128       vector<DTChamber*>::const_iterator chIt  = muonGeom->chambers().begin();
00129       vector<DTChamber*>::const_iterator chEnd = muonGeom->chambers().end();
00130       for (; chIt != chEnd; ++chIt) {
00131 
00132         DTChamberId chId((*chIt)->id());
00133         int wh   = chId.wheel();
00134         int sect = chId.sector();
00135         int stat = chId.station();
00136         
00137         std::map<std::string,MonitorElement*> &innerME = whME[wh];
00138           
00139         // Make Phi Residual Summary
00140         TH1F * PhiResidual = getHisto<TH1F>(dbe->get(getMEName("PhiResidual","Segment", chId)));
00141         int phiSummary = 1;
00142         if (PhiResidual && PhiResidual->GetEntries()>10) {
00143 
00144           if( innerME.find(fullName("PhiResidualPercentage")) == innerME.end() ){
00145             bookWheelHistos(wh,"PhiResidualPercentage");  
00146           }
00147           
00148           float rangeBin = validRange/(PhiResidual->GetBinWidth(1));
00149           float center   = (PhiResidual->GetNbinsX())/2.;
00150           float perc     = (PhiResidual->Integral(floor(center-rangeBin),ceil(center+rangeBin)))/(PhiResidual->Integral());
00151           fillWhPlot(innerME.find(fullName("PhiResidualPercentage"))->second,sect,stat,perc,false);
00152           phiSummary = performLutTest(perc,thresholdWarnPhi,thresholdErrPhi);
00153           if (detailedAnalysis) cmsME.find(fullName("PhiPercentageSummary"))->second->Fill(perc);
00154 
00155         }
00156 
00157         fillWhPlot(innerME.find(fullName("PhiLutSummary"))->second,sect,stat,phiSummary);
00158         
00159         if (detailedAnalysis){
00160 
00161 //        if ((phiSummary ==0)&& (PhiResidual->GetEntries()>100)) {  //Precision Peak test
00162 
00163 //          Float_t *source = new float[31];
00164 //          Float_t *dest   = new float[31];
00165 //          //TSpectrum *g = new TSpectrum(5);
00166 //          float media  = PhiResidual->GetMean();
00167 //          int   center = PhiResidual->GetXaxis()->FindBin(media);
00168 //          for (int i = 0; i < 30; i++) {
00169 //            source[i]=PhiResidual->GetBinContent(center+i-15);}
00170 //          int nFound = g->SearchHighRes(source, dest, 30, 1, 6, kFALSE, 5, kTRUE,2);
00171 //          /if (nFound>1) { // has more than 1 peak
00172 //            if( innerME.find(fullName("DoublePeakFlagPhi")) == innerME.end() ){
00173 //              bookWheelHistos(wh,"DoublePeakFlagPhi");
00174 //            }
00175 //          }
00176 
00177 //          fillWhPlot(innerME.find(fullName("DoublePeakFlagPhi"))->second,sect,stat,1,false);      
00178 //        }
00179 
00180           if ((phiSummary==0)||(phiSummary==3)){ //Information on the Peak
00181 
00182             if( innerME.find(fullName("PhiResidualMean")) == innerME.end() ){
00183               bookWheelHistos(wh,"PhiResidualMean");  
00184               bookWheelHistos(wh,"PhiResidualRMS");  
00185             }
00186 
00187             float center   = (PhiResidual->GetNbinsX())/2.;                   
00188             float rangeBin = validRange/(PhiResidual->GetBinWidth(1));
00189             PhiResidual->GetXaxis()->SetRange(floor(center-rangeBin),ceil(center+rangeBin));
00190             float max     = PhiResidual->GetMaximumBin();
00191             float maxBin  = PhiResidual->GetXaxis()->FindBin(max);
00192             float nBinMax = 0.5/(PhiResidual->GetBinWidth(1));
00193             PhiResidual->GetXaxis()->SetRange(floor(maxBin-nBinMax),ceil(maxBin+nBinMax));
00194             float Mean = PhiResidual->GetMean();
00195             float rms  = PhiResidual->GetRMS();     
00196 
00197             fillWhPlot(innerME.find(fullName("PhiResidualMean"))->second,sect,stat,Mean);
00198             fillWhPlot(innerME.find(fullName("PhiResidualRMS"))->second,sect,stat,rms);
00199             
00200           }
00201           
00202           TH2F * TrackPhitkvsPhitrig   = getHisto<TH2F>(dbe->get(getMEName("PhitkvsPhitrig","Segment", chId)));
00203 
00204           if (TrackPhitkvsPhitrig && TrackPhitkvsPhitrig->GetEntries()>100) {
00205             float corr = TrackPhitkvsPhitrig->GetCorrelationFactor();
00206             if( innerME.find(fullName("CorrelationFactorPhi")) == innerME.end() ){
00207               bookWheelHistos(wh,"CorrelationFactorPhi");
00208             }
00209             fillWhPlot(innerME.find(fullName("CorrelationFactorPhi"))->second,sect,stat,corr,false);
00210           }
00211           
00212         }
00213         
00214                                 
00215         // Make Phib Residual Summary
00216         TH1F * PhibResidual = getHisto<TH1F>(dbe->get(getMEName("PhibResidual","Segment", chId)));
00217         int phibSummary = stat==3 ? -1 : 1; // station 3 has no meaningful MB3 phi bending information
00218         
00219         if (stat != 3 && PhibResidual && PhibResidual->GetEntries()>10) {// station 3 has no meaningful MB3 phi bending information
00220 
00221           if( innerME.find(fullName("PhibResidualPercentage")) == innerME.end() ){
00222             bookWheelHistos(wh,"PhibResidualPercentage");  
00223           }
00224           
00225           float rangeBin = validRange/(PhibResidual->GetBinWidth(1));
00226           float center   = (PhibResidual->GetNbinsX())/2.;
00227           float perc     = (PhibResidual->Integral(floor(center-rangeBin),ceil(center+rangeBin)))/(PhibResidual->Integral());
00228 
00229           fillWhPlot(innerME.find(fullName("PhibResidualPercentage"))->second,sect,stat,perc,false);
00230           phibSummary = performLutTest(perc,thresholdWarnPhiB,thresholdErrPhiB);
00231           if (detailedAnalysis) cmsME.find(fullName("PhibPercentageSummary"))->second->Fill(perc);
00232 
00233         }
00234 
00235         fillWhPlot(innerME.find(fullName("PhibLutSummary"))->second,sect,stat,phibSummary);
00236         
00237         if (detailedAnalysis){
00238 
00239 //        if ((phibSummary ==0)&& (PhibResidual->GetEntries()>100)) {  //Precision Peak test 
00240 //          Float_t * source = new float[31];
00241 //          Float_t * dest = new float[31];
00242 //          TSpectrum *spec = new TSpectrum(5);
00243 //          float media = PhibResidual->GetMean();
00244 //          int center= PhibResidual->GetXaxis()->FindBin(media);
00245 //          for (int i = 0; i < 30; i++) {
00246 //            source[i]=PhibResidual->GetBinContent(center+i-15);
00247 //          }
00248 //          int nFound = spec->SearchHighRes(source,dest,30,1,6,kFALSE,5,kTRUE,2);
00249 //          if (nFound>1) { // has more than 1 peak
00250 //            if( innerME.find(fullName("DoublePeakFlagPhib")) == innerME.end() ){
00251 //              bookWheelHistos(wh,"DoublePeakFlagPhib");
00252 //            }
00253 //            fillWhPlot(innerME.find(fullName("DoublePeakFlagPhib"))->second,sect,stat,1,false);
00254 //          }
00255 //        }       
00256           
00257           if ((phibSummary==0)||(phibSummary==3)){
00258 
00259             if( innerME.find(fullName("PhibResidualMean")) == innerME.end() ){
00260               bookWheelHistos(wh,"PhibResidualMean");  
00261               bookWheelHistos(wh,"PhibResidualRMS");  
00262             }
00263 
00264             float center   = (PhibResidual->GetNbinsX())/2.;
00265             float rangeBin =  validRange/(PhibResidual->GetBinWidth(1));
00266             PhibResidual->GetXaxis()->SetRange(floor(center-rangeBin),ceil(center+rangeBin));
00267             float max     = PhibResidual->GetMaximumBin();
00268             float maxBin  = PhibResidual->GetXaxis()->FindBin(max);
00269             float nBinMax = 0.5/(PhibResidual->GetBinWidth(1));
00270             PhibResidual->GetXaxis()->SetRange(floor(maxBin-nBinMax),ceil(maxBin+nBinMax));
00271             float Mean = PhibResidual->GetMean();
00272             float rms = PhibResidual->GetRMS();
00273             
00274             fillWhPlot(innerME.find(fullName("PhibResidualMean"))->second,sect,stat,Mean);
00275             fillWhPlot(innerME.find(fullName("PhibResidualRMS"))->second,sect,stat,rms);
00276           }
00277 
00278           TH2F * TrackPhibtkvsPhibtrig   = getHisto<TH2F>(dbe->get(getMEName("PhibtkvsPhibtrig","Segment", chId)));
00279           if (TrackPhibtkvsPhibtrig && TrackPhibtkvsPhibtrig->GetEntries()>100) {
00280 
00281             float corr = TrackPhibtkvsPhibtrig->GetCorrelationFactor();
00282             if( innerME.find(fullName("CorrelationFactorPhib")) == innerME.end() ){
00283               bookWheelHistos(wh,"CorrelationFactorPhib");
00284             }
00285 
00286             fillWhPlot(innerME.find(fullName("CorrelationFactorPhib"))->second,sect,stat,corr,false);
00287 
00288           }       
00289           
00290         }                                               
00291       }
00292     }
00293   }
00294         
00295   // Barrel Summary Plots
00296   for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
00297     trigSource = (*iTr);
00298     for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
00299       hwSource = (*iHw);  
00300       for (int wh=-2; wh<=2; ++wh){
00301 
00302         std::map<std::string,MonitorElement*> *innerME = &(whME[wh]);
00303         
00304         TH2F* phiWhSummary   = getHisto<TH2F>(innerME->find(fullName("PhiLutSummary"))->second);
00305         TH2F* phibWhSummary  = getHisto<TH2F>(innerME->find(fullName("PhibLutSummary"))->second);
00306 
00307         for (int sect=1; sect<=12; ++sect){
00308 
00309           int phiSectorTotal  = 0;   // CB dai 1 occhio a questo
00310           int phibSectorTotal = 0;
00311           int nullphi  = 0;
00312           int nullphib = 0;
00313           int phiStatus  = 5;
00314           int phibStatus = 5;
00315           int glbStatus  = 0;
00316 
00317           for (int stat=1; stat<=4; ++stat){
00318             if (phiWhSummary->GetBinContent(sect,stat)==2){
00319               phiSectorTotal +=1;
00320               glbStatus += 1;
00321             }
00322             if (phiWhSummary->GetBinContent(sect,stat)==1)
00323               nullphi+=1;
00324             if (phibWhSummary->GetBinContent(sect,stat)==2) {
00325               phibSectorTotal+=1;
00326               glbStatus += 1;
00327             }
00328             if (phibWhSummary->GetBinContent(sect,stat)==1)
00329               nullphib+=1;
00330           }
00331           if (nullphi!=4)
00332             phiStatus=phiSectorTotal;
00333           else 
00334             phiStatus=5;
00335           if (nullphib!=3)
00336             phibStatus=phibSectorTotal;
00337           else 
00338             phibStatus=5;
00339           
00340           cmsME.find("TrigLutSummary")->second->setBinContent(sect,wh+3,glbStatus);
00341           cmsME.find(fullName("PhiLutSummary"))->second->setBinContent(sect,wh+3,phiStatus);
00342           cmsME.find(fullName("PhibLutSummary"))->second->setBinContent(sect,wh+3,phibStatus);
00343         }
00344       }
00345     }
00346   }
00347 
00348 }
00349 
00350 int DTTriggerLutTest::performLutTest(double perc,double thresholdWarn ,double thresholdErr) {
00351         
00352   bool isInWarn = perc<thresholdWarn;  
00353   bool isInErr  = perc<thresholdErr;
00354 
00355   int result= isInErr ? 2 : isInWarn ? 3 : 0;
00356 
00357   return result;
00358 
00359 }
00360 
00361 void DTTriggerLutTest::bookCmsHistos1d(string hTag, string folder) {
00362 
00363   string basedir = topFolder(true);
00364   if (folder != "") {
00365     basedir += folder +"/" ;
00366   }
00367   dbe->setCurrentFolder(basedir);
00368 
00369   string hName = fullName(hTag);
00370   LogTrace(category()) << "[" << testName << "Test]: booking " << basedir << hName;
00371 
00372 
00373   MonitorElement* me = dbe->book1D(hName.c_str(),hName.c_str(),101,-0.005,1.005);
00374   me->setAxisTitle("Percentage",1);
00375   cmsME[hName] = me;
00376 
00377 }
00378 
00379 void DTTriggerLutTest::fillWhPlot(MonitorElement *plot, int sect, int stat, float value, bool lessIsBest) {
00380   
00381   if (sect>12) {
00382     int scsect = sect==13 ? 4 : 10;
00383     if ((value>plot->getBinContent(scsect,stat)) == lessIsBest) {
00384       plot->setBinContent(scsect,stat,value);
00385     }
00386   }
00387   else {
00388     plot->setBinContent(sect,stat,value);
00389   }
00390   
00391   return;
00392   
00393 }
00394 
00395