CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/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: 2010/01/26 17:46:03 $
00007  *  $Revision: 1.32 $
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 }
00061 
00062 
00063 DTSegmentAnalysisTest::~DTSegmentAnalysisTest(){
00064 
00065   LogTrace ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "DTSegmentAnalysisTest: analyzed " << nevents << " events";
00066 }
00067 
00068 
00069 void DTSegmentAnalysisTest::beginJob(){
00070 
00071   LogTrace ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") <<"[DTSegmentAnalysisTest]: BeginJob"; 
00072 
00073   nevents = 0;
00074 
00075   // book the histos
00076   bookHistos();  
00077 
00078 }
00079 
00080 
00081 void DTSegmentAnalysisTest::beginRun(const Run& run, const EventSetup& context){
00082 
00083   LogTrace ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") <<"[DTSegmentAnalysisTest]: BeginRun"; 
00084 
00085   context.get<MuonGeometryRecord>().get(muonGeom);
00086 
00087 }
00088 
00089 
00090 void DTSegmentAnalysisTest::beginLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00091 
00092   LogTrace ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") <<"[DTSegmentAnalysisTest]: Begin of LS transition";
00093 
00094 }
00095 
00096 
00097 void DTSegmentAnalysisTest::analyze(const Event& e, const EventSetup& context){
00098  
00099   nevents++;
00100   if(nevents%1000 == 0)
00101     LogTrace ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "[DTSegmentAnalysisTest]: "<<nevents<<" events";
00102 
00103 }
00104 
00105 
00106 void DTSegmentAnalysisTest::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00107 
00108   // counts number of lumiSegs 
00109   nLumiSegs = lumiSeg.id().luminosityBlock();
00110  
00111   if (runOnline) {
00112     LogTrace ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
00113       <<"[DTSegmentAnalysisTest]: End of LS " << nLumiSegs 
00114       << ". Client called in online mode , perform DQM client operation";
00115     performClientDiagnostic();
00116   }
00117 
00118 }
00119 
00120 void DTSegmentAnalysisTest::endRun(Run const& run, EventSetup const& context) {
00121 
00122   if (!runOnline) {
00123     LogTrace ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
00124       <<"[DTSegmentAnalysisTest]: endRun. Client called in offline mode , perform DQM client operation";
00125     performClientDiagnostic();
00126   }
00127 
00128   if(normalizeHistoPlots) {
00129     LogTrace ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << " Performing time-histo normalization" << endl;
00130     MonitorElement* hNevtPerLS = 0;
00131     if(hltDQMMode) hNevtPerLS = dbe->get(topHistoFolder + "/NevtPerLS");
00132     else  hNevtPerLS = dbe->get("DT/EventInfo/NevtPerLS");
00133 
00134     if(hNevtPerLS != 0) {
00135       for(int wheel = -2; wheel != 3; ++wheel) { // loop over wheels
00136         for(int sector = 1; sector <= 12; ++sector) { // loop over sectors
00137           stringstream wheelstr; wheelstr << wheel;     
00138           stringstream sectorstr; sectorstr << sector;
00139           string sectorHistoName = topHistoFolder + "/Wheel" + wheelstr.str() +
00140             "/Sector" + sectorstr.str() +
00141             "/NSegmPerEvent_W" + wheelstr.str() +
00142             "_Sec" + sectorstr.str();
00143           DTTimeEvolutionHisto hNSegmPerLS(&(*dbe), sectorHistoName);
00144           hNSegmPerLS.normalizeTo(hNevtPerLS);
00145         }
00146       }
00147     } else {
00148       LogError ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "Histo NevtPerLS not found!" << endl;
00149     }
00150   }
00151 
00152 }
00153 
00154 void DTSegmentAnalysisTest::performClientDiagnostic() {
00155 
00156   summaryHistos[3]->Reset();
00157   summaryHistos[4]->Reset();
00158   vector<DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
00159   vector<DTChamber*>::const_iterator ch_end = muonGeom->chambers().end();
00160  
00161   for (; ch_it != ch_end; ++ch_it) {
00162     DTChamberId chID = (*ch_it)->id();
00163     
00164     MonitorElement * hNHits = dbe->get(getMEName(chID, "h4DSegmNHits"));
00165     MonitorElement * hSegmOcc = dbe->get(getMEName(chID, "numberOfSegments"));
00166    
00167     if (hNHits && hSegmOcc) {
00168       
00169       TH1F * hNHits_root = hNHits->getTH1F();
00170       TH2F * hSegmOcc_root = hSegmOcc->getTH2F();
00171       TH2F * summary_histo_root = summaryHistos[3]->getTH2F();
00172       
00173       int sector = chID.sector();
00174       if(sector == 13) sector=4;
00175       if(sector == 14) sector=10;
00176       
00177       
00178       if((chID.station()!=4 && hNHits_root->GetMaximumBin() != 12)||
00179          (chID.station()==4 &&  hNHits_root->GetMaximumBin() != 8)){
00180         summaryHistos[chID.wheel()]->setBinContent(sector, chID.station(),1);
00181         if(summary_histo_root->GetBinContent(sector, chID.wheel()+3)<1)
00182           summaryHistos[3]->setBinContent(sector, chID.wheel()+3,1);  
00183       }
00184       else
00185         summaryHistos[chID.wheel()]->setBinContent(sector, chID.station(),0);
00186     
00187       if(detailedAnalysis) {
00188         if(chID.station()!=4)
00189           segmRecHitHistos[make_pair(chID.wheel(),chID.sector())]->Fill(chID.station(),abs(12-hNHits_root->GetMaximumBin()));
00190         else
00191            segmRecHitHistos[make_pair(chID.wheel(),chID.sector())]->Fill(chID.station(),abs(8-hNHits_root->GetMaximumBin()));
00192       }
00193 
00194       TH2F * summary2_histo_root = summaryHistos[3]->getTH2F();
00195       
00196       if(hSegmOcc_root->GetBinContent(sector,chID.station())==0){
00197         summaryHistos[chID.wheel()]->setBinContent(sector, chID.station(),2);
00198         if(summary2_histo_root->GetBinContent(sector, chID.wheel()+3)<2)
00199           summaryHistos[3]->setBinContent(sector, chID.wheel()+3,2);
00200       } else {
00201         // Fill the percentage of segment occupancy
00202         float weight = 1./4.;
00203         if((sector == 4 || sector == 10) && chID.station() == 4) weight = 1./8.;
00204         summaryHistos[4]->Fill(sector, chID.wheel(),weight);
00205       }
00206       
00207     } else {
00208       LogVerbatim ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
00209         << "[DTSegmentAnalysisTest]: histos not found!!"; // FIXME
00210     }
00211 
00212     if(detailedAnalysis){ // switch on detailed analysis
00213    
00214       //test on chi2 segment quality
00215       MonitorElement * chi2_histo = dbe->get(getMEName(chID, "h4DChi2"));
00216       if(chi2_histo) {
00217         TH1F * chi2_histo_root = chi2_histo->getTH1F();
00218         double threshold = parameters.getUntrackedParameter<double>("chi2Threshold", 5);
00219         double maximum = chi2_histo_root->GetXaxis()->GetXmax();
00220         double minimum = chi2_histo_root->GetXaxis()->GetXmin();
00221         int nbins = chi2_histo_root->GetXaxis()->GetNbins();
00222         int thresholdBin = int(threshold/((maximum-minimum)/nbins));
00223         
00224         double badSegments=0;
00225         for(int bin=thresholdBin; bin<=nbins; bin++){
00226           badSegments+=chi2_histo_root->GetBinContent(bin);
00227         }
00228       
00229         if(chi2_histo_root->GetEntries()!=0){
00230           double badSegmentsPercentual= badSegments/double(chi2_histo_root->GetEntries());
00231           chi2Histos[make_pair(chID.wheel(),chID.sector())]->Fill(chID.station(),badSegmentsPercentual);
00232         }
00233       } else {
00234         LogVerbatim ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
00235           <<"[DTSegmentAnalysisTest]: Histo: " << getMEName(chID, "h4DChi2") << " not found!" << endl;
00236       }
00237     } // end of switch for detailed analysis
00238     
00239   } //loop over all the chambers
00240   
00241 
00242   if(detailedAnalysis){
00243     
00244     string chi2CriterionName = parameters.getUntrackedParameter<string>("chi2TestName","chi2InRange");
00245     for(map<pair<int, int>, MonitorElement*> ::const_iterator histo = chi2Histos.begin();
00246         histo != chi2Histos.end();
00247         histo++) {
00248 
00249       const QReport * theChi2QReport = (*histo).second->getQReport(chi2CriterionName);
00250       if(theChi2QReport) {
00251         vector<dqm::me_util::Channel> badChannels = theChi2QReport->getBadChannels();
00252         for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); 
00253              channel != badChannels.end(); channel++) {
00254           // FIXME: log into a ME
00255           LogError ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "Wheel: "<<(*histo).first.first
00256                                                                    << " Sector: "<<(*histo).first.second
00257                                                                    << " Bad stations: "<<(*channel).getBin()
00258                                                                    <<"  Contents : "<<(*channel).getContents();
00259         }
00260       }
00261     }
00262     
00263     string segmRecHitCriterionName = parameters.getUntrackedParameter<string>("segmRecHitTestName","segmRecHitInRange");
00264     for(map<pair<int, int>, MonitorElement*> ::const_iterator histo = segmRecHitHistos.begin();
00265         histo != segmRecHitHistos.end();
00266         histo++) {
00267 
00268       const QReport * theSegmRecHitQReport = (*histo).second->getQReport(segmRecHitCriterionName);
00269       if(theSegmRecHitQReport) {
00270         vector<dqm::me_util::Channel> badChannels = theSegmRecHitQReport->getBadChannels();
00271         for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); 
00272              channel != badChannels.end(); channel++) {
00273           // FIXME: log into a ME
00274           LogError ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "Wheel: "<<(*histo).first.first
00275                                                                    << " Sector: "<<(*histo).first.second
00276                                                                    << " Bad stations on recHit number: "
00277                                                                    <<(*channel).getBin()
00278                                                                    <<"  Contents : "
00279                                                                    <<(*channel).getContents();
00280         }
00281       }
00282     }
00283 
00284   } // end of detailedAnalysis
00285 
00286 }
00287 
00288 
00289 string DTSegmentAnalysisTest::getMEName(const DTChamberId & chID, string histoTag) {
00290   
00291   stringstream wheel; wheel << chID.wheel();    
00292   stringstream station; station << chID.station();      
00293   stringstream sector; sector << chID.sector(); 
00294   
00295   string folderName = 
00296     topHistoFolder + "/Wheel" +  wheel.str() +
00297     "/Sector" + sector.str() +
00298     "/Station" + station.str() + "/";
00299 
00300   string histoname = folderName + histoTag  
00301     + "_W" + wheel.str() 
00302     + "_St" + station.str() 
00303     + "_Sec" + sector.str(); 
00304   
00305   if(histoTag == "numberOfSegments")
00306     histoname = 
00307       topHistoFolder + "/Wheel" +  wheel.str() + "/" +
00308       histoTag  + + "_W" + wheel.str();
00309 
00310   return histoname;
00311   
00312 }
00313 
00314 
00315 void DTSegmentAnalysisTest::bookHistos() {
00316 
00317   for(int wh=-2; wh<=2; wh++){
00318       stringstream wheel; wheel << wh;
00319       string histoName =  "segmentSummary_W" + wheel.str();
00320       dbe->setCurrentFolder(topHistoFolder);
00321       summaryHistos[wh] = dbe->book2D(histoName.c_str(),histoName.c_str(),12,1,13,4,1,5);
00322       summaryHistos[wh]->setAxisTitle("Sector",1);
00323       summaryHistos[wh]->setBinLabel(1,"MB1",2);
00324       summaryHistos[wh]->setBinLabel(2,"MB2",2);
00325       summaryHistos[wh]->setBinLabel(3,"MB3",2);
00326       summaryHistos[wh]->setBinLabel(4,"MB4",2);
00327 
00328       if(detailedAnalysis){
00329         for(int sect=1; sect<=14; sect++){
00330           stringstream sector; sector << sect;
00331           string chi2HistoName =  "chi2BadSegmPercentual_W" + wheel.str() + "_Sec" + sector.str();
00332           dbe->setCurrentFolder(topHistoFolder + "/Wheel" + wheel.str() + "/Tests");
00333           chi2Histos[make_pair(wh,sect)] = dbe->book1D(chi2HistoName.c_str(),chi2HistoName.c_str(),4,1,5);
00334           chi2Histos[make_pair(wh,sect)]->setBinLabel(1,"MB1");
00335           chi2Histos[make_pair(wh,sect)]->setBinLabel(2,"MB2");
00336           chi2Histos[make_pair(wh,sect)]->setBinLabel(3,"MB3");
00337           chi2Histos[make_pair(wh,sect)]->setBinLabel(4,"MB4");
00338           
00339           string segmHistoName =  "residualsOnSegmRecHitNumber_W" + wheel.str() + "_Sec" + sector.str();
00340           segmRecHitHistos[make_pair(wh,sect)] = dbe->book1D(segmHistoName.c_str(),segmHistoName.c_str(),4,1,5);
00341           segmRecHitHistos[make_pair(wh,sect)]->setBinLabel(1,"MB1");
00342           segmRecHitHistos[make_pair(wh,sect)]->setBinLabel(2,"MB2");
00343           segmRecHitHistos[make_pair(wh,sect)]->setBinLabel(3,"MB3");
00344           segmRecHitHistos[make_pair(wh,sect)]->setBinLabel(4,"MB4");
00345           
00346         }
00347       }
00348   }
00349   
00350   string histoName =  "segmentSummary";
00351   dbe->setCurrentFolder(topHistoFolder);
00352   summaryHistos[3] = dbe->book2D(histoName.c_str(),histoName.c_str(),12,1,13,5,-2,3);
00353   summaryHistos[3]->setAxisTitle("Sector",1);
00354   summaryHistos[3]->setAxisTitle("Wheel",2); 
00355 
00356   summaryHistos[4] = dbe->book2D("SegmentGlbSummary",histoName.c_str(),12,1,13,5,-2,3);
00357   summaryHistos[4]->setAxisTitle("Sector",1);
00358   summaryHistos[4]->setAxisTitle("Wheel",2); 
00359 
00360 
00361 }
00362   
00363 
00364   
00365 
00366 void DTSegmentAnalysisTest::endJob() {
00367 }
00368 
00369 
00370