CMS 3D CMS Logo

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