CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/DQM/DTMonitorClient/src/DTChamberEfficiencyTest.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/05 10:15:45 $
00007  *  $Revision: 1.15 $
00008  *  \author G. Mila - INFN Torino
00009  */
00010 
00011 
00012 #include <DQM/DTMonitorClient/src/DTChamberEfficiencyTest.h>
00013 #include "DQMServices/Core/interface/MonitorElement.h"
00014 #include "DQMServices/Core/interface/DQMStore.h"
00015 
00016 // Framework
00017 #include <FWCore/Framework/interface/EventSetup.h>
00018 
00019 
00020 // Geometry
00021 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00022 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00023 
00024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00025 
00026 #include <stdio.h>
00027 #include <sstream>
00028 #include <math.h>
00029 
00030 
00031 using namespace edm;
00032 using namespace std;
00033 
00034 
00035 
00036 DTChamberEfficiencyTest::DTChamberEfficiencyTest(const edm::ParameterSet& ps){
00037 
00038   edm::LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyTest") << "[DTChamberEfficiencyTest]: Constructor";
00039 
00040   parameters = ps;
00041 
00042   dbe = edm::Service<DQMStore>().operator->();
00043 
00044   prescaleFactor = parameters.getUntrackedParameter<int>("diagnosticPrescale", 1);
00045 
00046 }
00047 
00048 
00049 
00050 DTChamberEfficiencyTest::~DTChamberEfficiencyTest(){
00051 
00052   edm::LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyTest") << "DTChamberEfficiencyTest: analyzed " << nevents << " events";
00053 
00054 }
00055 
00056 
00057 void DTChamberEfficiencyTest::beginJob(){
00058 
00059   edm::LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyTest") <<"[DTChamberEfficiencyTest]: BeginJob"; 
00060 
00061   nevents = 0;
00062 
00063 }
00064 
00065 
00066 void DTChamberEfficiencyTest::beginLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00067 
00068   edm::LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyTest") <<"[DTChamberEfficiencyTest]: Begin of LS transition";
00069 
00070   // Get the run number
00071   run = lumiSeg.run();
00072 
00073 }
00074 
00075 
00076 void DTChamberEfficiencyTest::beginRun(const edm::Run& run, const edm::EventSetup& setup){
00077   
00078   // Get the DT Geometry
00079   setup.get<MuonGeometryRecord>().get(muonGeom);
00080 
00081   // Loop over all the chambers
00082   vector<DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
00083   vector<DTChamber*>::const_iterator ch_end = muonGeom->chambers().end();
00084   for (; ch_it != ch_end; ++ch_it) {
00085     // histo booking
00086     bookHistos((*ch_it)->id());
00087   }
00088 
00089   //summary histo booking
00090   bookHistos();
00091 }
00092 
00093 void DTChamberEfficiencyTest::analyze(const edm::Event& e, const edm::EventSetup& context){
00094 
00095   nevents++;
00096   edm::LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyTest") << "[DTChamberEfficiencyTest]: "<<nevents<<" events";
00097 
00098 }
00099 
00100 
00101 void DTChamberEfficiencyTest::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00102   
00103   // counts number of updats (online mode) or number of events (standalone mode)
00104   //nevents++;
00105   // if running in standalone perform diagnostic only after a reasonalbe amount of events
00106   //if ( parameters.getUntrackedParameter<bool>("runningStandalone", false) && 
00107   //     nevents%parameters.getUntrackedParameter<int>("diagnosticPrescale", 1000) != 0 ) return;  
00108   //edm::LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyTest") << "[DTChamberEfficiencyTest]: "<<nevents<<" updates";
00109   
00110   edm::LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyTest") <<"[DTChamberEfficiencyTest]: End of LS transition, performing the DQM client operation";
00111 
00112   // counts number of lumiSegs 
00113   nLumiSegs = lumiSeg.id().luminosityBlock();
00114 
00115   // prescale factor
00116   if ( nLumiSegs%prescaleFactor != 0 ) return;
00117 
00118   edm::LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyTest") <<"[DTChamberEfficiencyTest]: "<<nLumiSegs<<" updates";
00119   
00120 
00121   vector<DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
00122   vector<DTChamber*>::const_iterator ch_end = muonGeom->chambers().end();
00123 
00124   edm::LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyTest") << "[DTChamberEfficiencyTest]: ChamberEfficiency tests results"; 
00125   
00126   // Loop over the chambers
00127   for (; ch_it != ch_end; ++ch_it) {
00128     DTChamberId chID = (*ch_it)->id();
00129     
00130     stringstream wheel; wheel << chID.wheel();
00131     stringstream station; station << chID.station();
00132     stringstream sector; sector << chID.sector();
00133     
00134     string HistoName = "W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str();
00135     
00136     // Get the ME produced by EfficiencyTask Source
00137     MonitorElement * GoodSegDen_histo = dbe->get(getMEName("hEffGoodSegVsPosDen", chID));       
00138     MonitorElement * GoodCloseSegNum_histo = dbe->get(getMEName("hEffGoodCloseSegVsPosNum", chID));
00139     
00140     // ME -> TH1F
00141     if(GoodSegDen_histo && GoodCloseSegNum_histo) {       
00142       TH2F * GoodSegDen_histo_root = GoodSegDen_histo->getTH2F();
00143       TH2F * GoodCloseSegNum_histo_root = GoodCloseSegNum_histo->getTH2F();
00144         
00145       int lastBinX=(*GoodSegDen_histo_root).GetNbinsX();
00146       TH1D* proxN=GoodCloseSegNum_histo_root->ProjectionX();
00147       TH1D* proxD=GoodSegDen_histo_root->ProjectionX();
00148 
00149       int lastBinY=(*GoodSegDen_histo_root).GetNbinsY();
00150       TH1D* proyN=GoodCloseSegNum_histo_root->ProjectionY();
00151       TH1D* proyD=GoodSegDen_histo_root->ProjectionY();
00152           
00153       for(int xBin=1; xBin<=lastBinX; xBin++) {
00154         if(proxD->GetBinContent(xBin)!=0){
00155           float Xefficiency = proxN->GetBinContent(xBin) / proxD->GetBinContent(xBin);
00156           xEfficiencyHistos.find(HistoName)->second->setBinContent(xBin, Xefficiency);
00157         }
00158 
00159         for(int yBin=1; yBin<=lastBinY; yBin++) {
00160           if(GoodSegDen_histo_root->GetBinContent(xBin, yBin)!=0){
00161             float XvsYefficiency = GoodCloseSegNum_histo_root->GetBinContent(xBin, yBin) / GoodSegDen_histo_root->GetBinContent(xBin, yBin);
00162             xVSyEffHistos.find(HistoName)->second->setBinContent(xBin, yBin, XvsYefficiency);
00163           }
00164         }
00165             
00166       }
00167           
00168       for(int yBin=1; yBin<=lastBinY; yBin++) {
00169         if(proyD->GetBinContent(yBin)!=0){
00170           float Yefficiency = proyN->GetBinContent(yBin) / proyD->GetBinContent(yBin);
00171           yEfficiencyHistos.find(HistoName)->second->setBinContent(yBin, Yefficiency);
00172         }
00173       }
00174     }
00175   } // loop on chambers
00176   
00177   
00178   // ChamberEfficiency test on X axis
00179   string XEfficiencyCriterionName = parameters.getUntrackedParameter<string>("XEfficiencyTestName","ChEfficiencyInRangeX"); 
00180   for(map<string, MonitorElement*>::const_iterator hXEff = xEfficiencyHistos.begin();
00181       hXEff != xEfficiencyHistos.end();
00182       hXEff++) {
00183     const QReport * theXEfficiencyQReport = (*hXEff).second->getQReport(XEfficiencyCriterionName);
00184     if(theXEfficiencyQReport) {
00185       vector<dqm::me_util::Channel> badChannels = theXEfficiencyQReport->getBadChannels();
00186       for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); 
00187            channel != badChannels.end(); channel++) {
00188         edm::LogError ("DTDQM|DTMonitorClient|DTChamberEfficiencyTest") << "Chamber : " << (*hXEff).first << " Bad XChamberEfficiency channels: "<<(*channel).getBin()<<"  Contents : "<<(*channel).getContents();
00189       }
00190       // FIXME: getMessage() sometimes returns and invalid string (null pointer inside QReport data member)
00191       // edm::LogWarning ("DTDQM|DTMonitorClient|DTChamberEfficiencyTest") << "-------- Chamber : "<<(*hXEff).first<<"  "<<theXEfficiencyQReport->getMessage()<<" ------- "<<theXEfficiencyQReport->getStatus();
00192     }
00193   }
00194 
00195 
00196   // ChamberEfficiency test on Y axis
00197   string YEfficiencyCriterionName = parameters.getUntrackedParameter<string>("YEfficiencyTestName","ChEfficiencyInRangeY"); 
00198   for(map<string, MonitorElement*>::const_iterator hYEff = yEfficiencyHistos.begin();
00199       hYEff != yEfficiencyHistos.end();
00200       hYEff++) {
00201     const QReport * theYEfficiencyQReport = (*hYEff).second->getQReport(YEfficiencyCriterionName);
00202     if(theYEfficiencyQReport) {
00203       vector<dqm::me_util::Channel> badChannels = theYEfficiencyQReport->getBadChannels();
00204       for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); 
00205            channel != badChannels.end(); channel++) {
00206         edm::LogError ("DTDQM|DTMonitorClient|DTChamberEfficiencyTest") << "Chamber : " << (*hYEff).first <<" Bad YChamberEfficiency channels: "<<(*channel).getBin()<<"  Contents : "<<(*channel).getContents();
00207       }
00208       // FIXME: getMessage() sometimes returns and invalid string (null pointer inside QReport data member)
00209       // edm::LogWarning ("DTDQM|DTMonitorClient|DTChamberEfficiencyTest") << "-------- Chamber : "<<(*hYEff).first<<"  "<<theYEfficiencyQReport->getMessage()<<" ------- "<<theYEfficiencyQReport->getStatus();
00210     }
00211   }
00212 
00213   //Fill the report summary histos
00214   for(int wh=-2; wh<=2; wh++){
00215     for(int sec=1; sec<=12; sec++){
00216       for(int st=1; st<=4; st++){
00217 
00218         summaryHistos[wh]->Fill(sec,st,1);
00219       
00220       }
00221     }
00222   }
00223 
00224 }
00225 
00226 
00227 
00228 void DTChamberEfficiencyTest::endJob(){
00229 
00230   edm::LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyTest") << "[DTChamberEfficiencyTest] endjob called!";
00231 
00232 }
00233 
00234 
00235 
00236 
00237 string DTChamberEfficiencyTest::getMEName(string histoTag, const DTChamberId & chID) {
00238 
00239   stringstream wheel; wheel << chID.wheel();
00240   stringstream station; station << chID.station();
00241   stringstream sector; sector << chID.sector();
00242  
00243   string folderRoot = parameters.getUntrackedParameter<string>("folderRoot", "Collector/FU0/");
00244   string folderName = 
00245     folderRoot + "DT/01-DTChamberEfficiency/Task/Wheel" +  wheel.str() +
00246     "/Sector" + sector.str() +
00247     "/Station" + station.str() + "/";
00248 
00249   string histoname = folderName + histoTag  
00250     + "_W" + wheel.str() 
00251     + "_St" + station.str() 
00252     + "_Sec" + sector.str();
00253   
00254   return histoname;
00255   
00256 }
00257 
00258 
00259 void DTChamberEfficiencyTest::bookHistos(const DTChamberId & chId) {
00260 
00261   stringstream wheel; wheel << chId.wheel();
00262   stringstream station; station << chId.station();      
00263   stringstream sector; sector << chId.sector();
00264 
00265   string HistoName = "W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str();
00266   string xEfficiencyHistoName =  "xEfficiency_" + HistoName; 
00267   string yEfficiencyHistoName =  "yEfficiency_" + HistoName; 
00268   string xVSyEffHistoName =  "xVSyEff_" + HistoName; 
00269 
00270   dbe->setCurrentFolder("DT/01-DTChamberEfficiency/Wheel" + wheel.str() +
00271                         "/Sector" + sector.str() +
00272                         "/Station" + station.str());
00273 
00274   xEfficiencyHistos[HistoName] = dbe->book1D(xEfficiencyHistoName.c_str(),xEfficiencyHistoName.c_str(),25,-250.,250.);
00275   yEfficiencyHistos[HistoName] = dbe->book1D(yEfficiencyHistoName.c_str(),yEfficiencyHistoName.c_str(),25,-250.,250.);
00276   xVSyEffHistos[HistoName] = dbe->book2D(xVSyEffHistoName.c_str(),xVSyEffHistoName.c_str(),25,-250.,250., 25,-250.,250.);
00277 
00278 }
00279 
00280 
00281 void DTChamberEfficiencyTest::bookHistos() {
00282 
00283   for(int wh=-2; wh<=2; wh++){
00284     stringstream wheel; wheel << wh;
00285     string histoName =  "chEfficiencySummary_W" + wheel.str();
00286     dbe->setCurrentFolder("DT/01-DTChamberEfficiency");
00287     summaryHistos[wh] = dbe->book2D(histoName.c_str(),histoName.c_str(),12,1,13,4,1,5);
00288     summaryHistos[wh]->setAxisTitle("Sector",1);
00289     summaryHistos[wh]->setBinLabel(1,"MB1",2);
00290     summaryHistos[wh]->setBinLabel(2,"MB2",2);
00291     summaryHistos[wh]->setBinLabel(3,"MB3",2);
00292     summaryHistos[wh]->setBinLabel(4,"MB4",2);
00293   }
00294 
00295 }