CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/DQM/DTMonitorClient/src/DTSegmentAnalysisTest.cc

Go to the documentation of this file.
00001 
00002 
00003 /*
00004  *  See header file for a description of this class.
00005  *
00006  *  $Date: 2011/06/14 08:53:04 $
00007  *  $Revision: 1.34 $
00008  *  \author G. Mila - INFN Torino
00009  */
00010 
00011 
00012 #include <DQM/DTMonitorClient/src/DTSegmentAnalysisTest.h>
00013 
00014 // Framework
00015 #include <FWCore/Framework/interface/Event.h>
00016 #include "DataFormats/Common/interface/Handle.h" 
00017 #include <FWCore/Framework/interface/ESHandle.h>
00018 #include <FWCore/Framework/interface/EventSetup.h>
00019 #include <FWCore/ParameterSet/interface/ParameterSet.h>
00020 
00021 
00022 // Geometry
00023 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00024 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00025 #include "Geometry/DTGeometry/interface/DTLayer.h"
00026 #include "Geometry/DTGeometry/interface/DTTopology.h"
00027 
00028 #include "DQMServices/Core/interface/DQMStore.h"
00029 #include "DQMServices/Core/interface/MonitorElement.h"
00030 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00031 
00032 #include "DQM/DTMonitorModule/interface/DTTimeEvolutionHisto.h"
00033 
00034 #include <iostream>
00035 #include <stdio.h>
00036 #include <string>
00037 #include <sstream>
00038 #include <math.h>
00039 
00040 
00041 using namespace edm;
00042 using namespace std;
00043 
00044 
00045 DTSegmentAnalysisTest::DTSegmentAnalysisTest(const ParameterSet& ps){
00046 
00047   LogTrace ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "[DTSegmentAnalysisTest]: Constructor";
00048   parameters = ps;
00049 
00050   dbe = Service<DQMStore>().operator->();
00051 
00052   // get the cfi parameters
00053   detailedAnalysis = parameters.getUntrackedParameter<bool>("detailedAnalysis",false);
00054   normalizeHistoPlots  = parameters.getUntrackedParameter<bool>("normalizeHistoPlots",false);
00055   runOnline  = parameters.getUntrackedParameter<bool>("runOnline",true);
00056   // top folder for the histograms in DQMStore
00057   topHistoFolder = ps.getUntrackedParameter<string>("topHistoFolder","DT/02-Segments");
00058   // hlt DQM mode
00059   hltDQMMode = ps.getUntrackedParameter<bool>("hltDQMMode",false);
00060   nMinEvts  = ps.getUntrackedParameter<int>("nEventsCert", 5000);
00061 
00062 }
00063 
00064 
00065 DTSegmentAnalysisTest::~DTSegmentAnalysisTest(){
00066 
00067   LogTrace ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "DTSegmentAnalysisTest: analyzed " << nevents << " events";
00068 }
00069 
00070 
00071 void DTSegmentAnalysisTest::beginJob(){
00072 
00073   LogTrace ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") <<"[DTSegmentAnalysisTest]: BeginJob"; 
00074 
00075   nevents = 0;
00076 
00077   // book the histos
00078   bookHistos();  
00079 
00080 }
00081 
00082 
00083 void DTSegmentAnalysisTest::beginRun(const Run& run, const EventSetup& context){
00084 
00085   LogTrace ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") <<"[DTSegmentAnalysisTest]: BeginRun"; 
00086 
00087   context.get<MuonGeometryRecord>().get(muonGeom);
00088 
00089 }
00090 
00091 
00092 void DTSegmentAnalysisTest::beginLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00093 
00094   LogTrace ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") <<"[DTSegmentAnalysisTest]: Begin of LS transition";
00095 
00096 }
00097 
00098 
00099 void DTSegmentAnalysisTest::analyze(const Event& e, const EventSetup& context){
00100  
00101   nevents++;
00102   if(nevents%1000 == 0)
00103     LogTrace ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "[DTSegmentAnalysisTest]: "<<nevents<<" events";
00104 
00105 }
00106 
00107 
00108 void DTSegmentAnalysisTest::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00109 
00110   // counts number of lumiSegs 
00111   nLumiSegs = lumiSeg.id().luminosityBlock();
00112  
00113   if (runOnline) {
00114     LogTrace ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
00115       <<"[DTSegmentAnalysisTest]: End of LS " << nLumiSegs 
00116       << ". Client called in online mode , perform DQM client operation";
00117     performClientDiagnostic();
00118   }
00119 
00120 }
00121 
00122 void DTSegmentAnalysisTest::endRun(Run const& run, EventSetup const& context) {
00123 
00124   if (!runOnline) {
00125     LogTrace ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
00126       <<"[DTSegmentAnalysisTest]: endRun. Client called in offline mode , perform DQM client operation";
00127     performClientDiagnostic();
00128   }
00129 
00130   if(normalizeHistoPlots) {
00131     LogTrace ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << " Performing time-histo normalization" << endl;
00132     MonitorElement* hNevtPerLS = 0;
00133     if(hltDQMMode) hNevtPerLS = dbe->get(topHistoFolder + "/NevtPerLS");
00134     else  hNevtPerLS = dbe->get("DT/EventInfo/NevtPerLS");
00135 
00136     if(hNevtPerLS != 0) {
00137       for(int wheel = -2; wheel != 3; ++wheel) { // loop over wheels
00138         for(int sector = 1; sector <= 12; ++sector) { // loop over sectors
00139           stringstream wheelstr; wheelstr << wheel;     
00140           stringstream sectorstr; sectorstr << sector;
00141           string sectorHistoName = topHistoFolder + "/Wheel" + wheelstr.str() +
00142             "/Sector" + sectorstr.str() +
00143             "/NSegmPerEvent_W" + wheelstr.str() +
00144             "_Sec" + sectorstr.str();
00145           DTTimeEvolutionHisto hNSegmPerLS(&(*dbe), sectorHistoName);
00146           hNSegmPerLS.normalizeTo(hNevtPerLS);
00147         }
00148       }
00149     } else {
00150       LogError ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "Histo NevtPerLS not found!" << endl;
00151     }
00152   }
00153 
00154 }
00155 
00156 void DTSegmentAnalysisTest::performClientDiagnostic() {
00157 
00158   summaryHistos[3]->Reset();
00159   summaryHistos[4]->Reset();
00160   vector<DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
00161   vector<DTChamber*>::const_iterator ch_end = muonGeom->chambers().end();
00162  
00163   for (; ch_it != ch_end; ++ch_it) {
00164     DTChamberId chID = (*ch_it)->id();
00165     
00166     MonitorElement * hNHits = dbe->get(getMEName(chID, "h4DSegmNHits"));
00167     MonitorElement * hSegmOcc = dbe->get(getMEName(chID, "numberOfSegments"));
00168    
00169     if (hNHits && hSegmOcc) {
00170       
00171       TH1F * hNHits_root = hNHits->getTH1F();
00172       TH2F * hSegmOcc_root = hSegmOcc->getTH2F();
00173       TH2F * summary_histo_root = summaryHistos[3]->getTH2F();
00174       
00175       int sector = chID.sector();
00176       if(sector == 13) sector=4;
00177       if(sector == 14) sector=10;
00178       
00179       
00180       if((chID.station()!=4 && hNHits_root->GetMaximumBin() != 12)||
00181          (chID.station()==4 &&  hNHits_root->GetMaximumBin() != 8)){
00182         summaryHistos[chID.wheel()]->setBinContent(sector, chID.station(),1);
00183         if(summary_histo_root->GetBinContent(sector, chID.wheel()+3)<1)
00184           summaryHistos[3]->setBinContent(sector, chID.wheel()+3,1);  
00185       }
00186       else
00187         summaryHistos[chID.wheel()]->setBinContent(sector, chID.station(),0);
00188     
00189       if(detailedAnalysis) {
00190         if(chID.station()!=4)
00191           segmRecHitHistos[make_pair(chID.wheel(),chID.sector())]->Fill(chID.station(),abs(12-hNHits_root->GetMaximumBin()));
00192         else
00193            segmRecHitHistos[make_pair(chID.wheel(),chID.sector())]->Fill(chID.station(),abs(8-hNHits_root->GetMaximumBin()));
00194       }
00195 
00196       TH2F * summary2_histo_root = summaryHistos[3]->getTH2F();
00197       
00198       if(hSegmOcc_root->GetBinContent(sector,chID.station())==0){
00199         summaryHistos[chID.wheel()]->setBinContent(sector, chID.station(),2);
00200         if(summary2_histo_root->GetBinContent(sector, chID.wheel()+3)<2)
00201           summaryHistos[3]->setBinContent(sector, chID.wheel()+3,2);
00202       } else {
00203         // Fill the percentage of segment occupancy
00204         float weight = 1./4.;
00205         if((sector == 4 || sector == 10) && chID.station() == 4) weight = 1./8.;
00206         summaryHistos[4]->Fill(sector, chID.wheel(),weight);
00207       }
00208       
00209     } else {
00210       LogVerbatim ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
00211         << "[DTSegmentAnalysisTest]: histos not found!!"; // FIXME
00212     }
00213 
00214     if(detailedAnalysis){ // switch on detailed analysis
00215    
00216       //test on chi2 segment quality
00217       MonitorElement * chi2_histo = dbe->get(getMEName(chID, "h4DChi2"));
00218       if(chi2_histo) {
00219         TH1F * chi2_histo_root = chi2_histo->getTH1F();
00220         double threshold = parameters.getUntrackedParameter<double>("chi2Threshold", 5);
00221         double maximum = chi2_histo_root->GetXaxis()->GetXmax();
00222         double minimum = chi2_histo_root->GetXaxis()->GetXmin();
00223         int nbins = chi2_histo_root->GetXaxis()->GetNbins();
00224         int thresholdBin = int(threshold/((maximum-minimum)/nbins));
00225         
00226         double badSegments=0;
00227         for(int bin=thresholdBin; bin<=nbins; bin++){
00228           badSegments+=chi2_histo_root->GetBinContent(bin);
00229         }
00230       
00231         if(chi2_histo_root->GetEntries()!=0){
00232           double badSegmentsPercentual= badSegments/double(chi2_histo_root->GetEntries());
00233           chi2Histos[make_pair(chID.wheel(),chID.sector())]->Fill(chID.station(),badSegmentsPercentual);
00234         }
00235       } else {
00236         LogVerbatim ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
00237           <<"[DTSegmentAnalysisTest]: Histo: " << getMEName(chID, "h4DChi2") << " not found!" << endl;
00238       }
00239     } // end of switch for detailed analysis
00240     
00241   } //loop over all the chambers
00242 
00243   string nEvtsName = "DT/EventInfo/Counters/nProcessedEventsSegment";
00244   MonitorElement * meProcEvts = dbe->get(nEvtsName);
00245 
00246   if (meProcEvts) {
00247     int nProcEvts = meProcEvts->getFloatValue();
00248     summaryHistos[4]->setEntries(nProcEvts < nMinEvts ? 10. : nProcEvts);
00249   } else {
00250     summaryHistos[4]->setEntries(nMinEvts + 1);
00251     LogVerbatim ("DTDQM|DTMonitorClient|DTOccupancyTest") << "[DTOccupancyTest] ME: "
00252                        <<  nEvtsName << " not found!" << endl;
00253   }
00254 
00255   if(detailedAnalysis){
00256     
00257     string chi2CriterionName = parameters.getUntrackedParameter<string>("chi2TestName","chi2InRange");
00258     for(map<pair<int, int>, MonitorElement*> ::const_iterator histo = chi2Histos.begin();
00259         histo != chi2Histos.end();
00260         histo++) {
00261 
00262       const QReport * theChi2QReport = (*histo).second->getQReport(chi2CriterionName);
00263       if(theChi2QReport) {
00264         vector<dqm::me_util::Channel> badChannels = theChi2QReport->getBadChannels();
00265         for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); 
00266              channel != badChannels.end(); channel++) {
00267           // FIXME: log into a ME
00268           LogError ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "Wheel: "<<(*histo).first.first
00269                                                                    << " Sector: "<<(*histo).first.second
00270                                                                    << " Bad stations: "<<(*channel).getBin()
00271                                                                    <<"  Contents : "<<(*channel).getContents();
00272         }
00273       }
00274     }
00275     
00276     string segmRecHitCriterionName = parameters.getUntrackedParameter<string>("segmRecHitTestName","segmRecHitInRange");
00277     for(map<pair<int, int>, MonitorElement*> ::const_iterator histo = segmRecHitHistos.begin();
00278         histo != segmRecHitHistos.end();
00279         histo++) {
00280 
00281       const QReport * theSegmRecHitQReport = (*histo).second->getQReport(segmRecHitCriterionName);
00282       if(theSegmRecHitQReport) {
00283         vector<dqm::me_util::Channel> badChannels = theSegmRecHitQReport->getBadChannels();
00284         for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); 
00285              channel != badChannels.end(); channel++) {
00286           // FIXME: log into a ME
00287           LogError ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "Wheel: "<<(*histo).first.first
00288                                                                    << " Sector: "<<(*histo).first.second
00289                                                                    << " Bad stations on recHit number: "
00290                                                                    <<(*channel).getBin()
00291                                                                    <<"  Contents : "
00292                                                                    <<(*channel).getContents();
00293         }
00294       }
00295     }
00296 
00297   } // end of detailedAnalysis
00298 
00299 }
00300 
00301 
00302 string DTSegmentAnalysisTest::getMEName(const DTChamberId & chID, string histoTag) {
00303   
00304   stringstream wheel; wheel << chID.wheel();    
00305   stringstream station; station << chID.station();      
00306   stringstream sector; sector << chID.sector(); 
00307   
00308   string folderName = 
00309     topHistoFolder + "/Wheel" +  wheel.str() +
00310     "/Sector" + sector.str() +
00311     "/Station" + station.str() + "/";
00312 
00313   string histoname = folderName + histoTag  
00314     + "_W" + wheel.str() 
00315     + "_St" + station.str() 
00316     + "_Sec" + sector.str(); 
00317   
00318   if(histoTag == "numberOfSegments")
00319     histoname = 
00320       topHistoFolder + "/Wheel" +  wheel.str() + "/" +
00321       histoTag  + + "_W" + wheel.str();
00322 
00323   return histoname;
00324   
00325 }
00326 
00327 
00328 void DTSegmentAnalysisTest::bookHistos() {
00329 
00330   for(int wh=-2; wh<=2; wh++){
00331       stringstream wheel; wheel << wh;
00332       string histoName =  "segmentSummary_W" + wheel.str();
00333       dbe->setCurrentFolder(topHistoFolder);
00334       summaryHistos[wh] = dbe->book2D(histoName.c_str(),histoName.c_str(),12,1,13,4,1,5);
00335       summaryHistos[wh]->setAxisTitle("Sector",1);
00336       summaryHistos[wh]->setBinLabel(1,"MB1",2);
00337       summaryHistos[wh]->setBinLabel(2,"MB2",2);
00338       summaryHistos[wh]->setBinLabel(3,"MB3",2);
00339       summaryHistos[wh]->setBinLabel(4,"MB4",2);
00340 
00341       if(detailedAnalysis){
00342         for(int sect=1; sect<=14; sect++){
00343           stringstream sector; sector << sect;
00344           string chi2HistoName =  "chi2BadSegmPercentual_W" + wheel.str() + "_Sec" + sector.str();
00345           dbe->setCurrentFolder(topHistoFolder + "/Wheel" + wheel.str() + "/Tests");
00346           chi2Histos[make_pair(wh,sect)] = dbe->book1D(chi2HistoName.c_str(),chi2HistoName.c_str(),4,1,5);
00347           chi2Histos[make_pair(wh,sect)]->setBinLabel(1,"MB1");
00348           chi2Histos[make_pair(wh,sect)]->setBinLabel(2,"MB2");
00349           chi2Histos[make_pair(wh,sect)]->setBinLabel(3,"MB3");
00350           chi2Histos[make_pair(wh,sect)]->setBinLabel(4,"MB4");
00351           
00352           string segmHistoName =  "residualsOnSegmRecHitNumber_W" + wheel.str() + "_Sec" + sector.str();
00353           segmRecHitHistos[make_pair(wh,sect)] = dbe->book1D(segmHistoName.c_str(),segmHistoName.c_str(),4,1,5);
00354           segmRecHitHistos[make_pair(wh,sect)]->setBinLabel(1,"MB1");
00355           segmRecHitHistos[make_pair(wh,sect)]->setBinLabel(2,"MB2");
00356           segmRecHitHistos[make_pair(wh,sect)]->setBinLabel(3,"MB3");
00357           segmRecHitHistos[make_pair(wh,sect)]->setBinLabel(4,"MB4");
00358           
00359         }
00360       }
00361   }
00362   
00363   string histoName =  "segmentSummary";
00364   dbe->setCurrentFolder(topHistoFolder);
00365   summaryHistos[3] = dbe->book2D(histoName.c_str(),histoName.c_str(),12,1,13,5,-2,3);
00366   summaryHistos[3]->setAxisTitle("Sector",1);
00367   summaryHistos[3]->setAxisTitle("Wheel",2); 
00368 
00369   summaryHistos[4] = dbe->book2D("SegmentGlbSummary",histoName.c_str(),12,1,13,5,-2,3);
00370   summaryHistos[4]->setAxisTitle("Sector",1);
00371   summaryHistos[4]->setAxisTitle("Wheel",2); 
00372 
00373 
00374 }
00375   
00376 
00377   
00378 
00379 void DTSegmentAnalysisTest::endJob() {
00380 }
00381 
00382 
00383