CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/DQM/DTMonitorClient/src/DTChamberEfficiencyClient.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2011/10/31 17:22:23 $
00005  *  $Revision: 1.9 $
00006  *  \author M. Pelliccioni - INFN Torino
00007  */
00008 
00009 #include <DQM/DTMonitorClient/src/DTChamberEfficiencyClient.h>
00010 #include <DQMServices/Core/interface/MonitorElement.h>
00011 #include <DQMServices/Core/interface/DQMStore.h>
00012 
00013 #include <FWCore/Framework/interface/EventSetup.h>
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 
00016 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00017 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00018 
00019 #include <stdio.h>
00020 #include <sstream>
00021 #include <math.h>
00022 
00023 using namespace edm;
00024 using namespace std;
00025 
00026 //two words about conventions: "All" histograms are those made for all segments
00027 //while "Qual" histograms are those for segments with at least 12 hits
00028 
00029 DTChamberEfficiencyClient::DTChamberEfficiencyClient(const ParameterSet& pSet)
00030 {
00031 
00032   LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
00033     << "DTChamberEfficiencyClient: Constructor called";
00034 
00035   dbe = Service<DQMStore>().operator->();
00036 
00037   prescaleFactor = pSet.getUntrackedParameter<int>("diagnosticPrescale", 1);
00038 }
00039 
00040 DTChamberEfficiencyClient::~DTChamberEfficiencyClient()
00041 {
00042    LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
00043      << "DTChamberEfficiencyClient: Destructor called";
00044 }
00045 
00046 void DTChamberEfficiencyClient::beginJob()
00047 {
00048   LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
00049     << "DTChamberEfficiencyClient: BeginJob";
00050 
00051   nevents = 0;
00052 
00053   bookHistos();
00054 
00055   return;
00056 }
00057 
00058 void DTChamberEfficiencyClient::beginLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context)
00059 {
00060   LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
00061     << "[DTChamberEfficiencyClient]: Begin of LS transition";
00062 
00063   return;
00064 }
00065 
00066 void DTChamberEfficiencyClient::beginRun(const Run& run, const EventSetup& setup)
00067 {
00068   LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
00069     << "DTChamberEfficiencyClient: beginRun";
00070 
00071   // Get the DT Geometry
00072   setup.get<MuonGeometryRecord>().get(muonGeom);
00073 
00074   return;
00075 }
00076 
00077 void DTChamberEfficiencyClient::analyze(const Event& e, const EventSetup& context)
00078 {
00079 
00080   nevents++;
00081   LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
00082     << "[DTChamberEfficiencyClient]: " << nevents << " events";
00083   return;
00084 }
00085 
00086 void DTChamberEfficiencyClient::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context)
00087 {
00088   LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
00089     << "DTChamberEfficiencyClient: endluminosityBlock";
00090 }  
00091 
00092 
00093 void DTChamberEfficiencyClient::endRun(Run const& run, EventSetup const& context)
00094 {
00095   LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
00096     << "DTChamberEfficiencyClient: endRun";
00097   // reset the global summary
00098   globalEffSummary->Reset();
00099 
00100   //Loop over the wheels
00101   for(int wheel=-2;wheel<=2;wheel++){
00102     stringstream wheel_str; wheel_str << wheel;
00103 
00104     // Get the ME produced by EfficiencyTask Source
00105     // All means no selection on segments, Qual means segments with at least 12 hits
00106     MonitorElement* MECountAll = dbe->get("DT/05-ChamberEff/Task/hCountSectVsChamb_All_W" + wheel_str.str());   
00107     MonitorElement* MECountQual = dbe->get("DT/05-ChamberEff/Task/hCountSectVsChamb_Qual_W" + wheel_str.str()); 
00108     MonitorElement* MEExtrap = dbe->get("DT/05-ChamberEff/Task/hExtrapSectVsChamb_W" + wheel_str.str());        
00109 
00110     //get the TH2F
00111     if(!MECountAll) cout<<"fucking ME is null"<<endl;
00112     if(!(MECountAll->getTH2F())) cout<<"fucking puntator is null!"<<endl;
00113     TH2F* hCountAll = MECountAll->getTH2F();
00114     TH2F* hCountQual = MECountQual->getTH2F();
00115     TH2F* hExtrap = MEExtrap->getTH2F();
00116 
00117 
00118 
00119     const int nBinX = summaryHistos[wheel+2][0]->getNbinsX();
00120     const int nBinY = summaryHistos[wheel+2][0]->getNbinsY();
00121 
00122     for(int j=1;j<=nBinX;j++){
00123       for(int k=1;k<=nBinY;k++){
00124         summaryHistos[wheel+2][0]->setBinContent(j,k,0.);
00125         summaryHistos[wheel+2][1]->setBinContent(j,k,0.);
00126 
00127         const float numerAll = hCountAll->GetBinContent(j,k);
00128         const float numerQual = hCountQual->GetBinContent(j,k);
00129         const float denom = hExtrap->GetBinContent(j,k);
00130 
00131         if(denom != 0.){
00132           const float effAll= numerAll/denom;
00133           const float eff_error_All = sqrt((effAll+effAll*effAll)/denom);
00134 
00135           const float effQual= numerQual/denom;
00136           const float eff_error_Qual = sqrt((effQual+effQual*effQual)/denom);
00137 
00138           //if(wheel == 2 && k == 2 && j == 2) cout << "Eff ch " << effAll << " " << lumiSeg.id() << endl;
00139 
00140           summaryHistos[wheel+2][0]->setBinContent(j,k,effAll);
00141           summaryHistos[wheel+2][0]->setBinError(j,k,eff_error_All);
00142 
00143           summaryHistos[wheel+2][1]->setBinContent(j,k,effQual);
00144           summaryHistos[wheel+2][1]->setBinError(j,k,eff_error_Qual);
00145 
00146         // Fill 1D eff distributions
00147         globalEffDistr -> Fill(effAll);
00148         EffDistrPerWh[wheel+2] -> Fill(effAll);
00149 
00150         }
00151       }
00152     }
00153   }
00154 
00155   // fill the global eff. summary
00156   // problems at a granularity smaller than the chamber are ignored
00157   for(int wheel=-2; wheel<=2; wheel++) { // loop over wheels
00158     // retrieve the chamber efficiency summary
00159     MonitorElement * segmentWheelSummary = summaryHistos[wheel+2][0];
00160     if(segmentWheelSummary != 0) {
00161 
00162       for(int sector=1; sector<=12; sector++) { // loop over sectors
00163         float nFailingChambers = 0.;
00164 
00165         double meaneff = 0.;
00166         double errorsum = 0.;
00167 
00168         for(int station = 1; station != 5; ++station) { // loop over stations
00169           
00170           const double tmpefficiency = segmentWheelSummary->getBinContent(sector, station);
00171           const double tmpvariance = pow(segmentWheelSummary->getBinError(sector, station),2);
00172 
00173           //if(wheel == 2 && sector == 9) cout << "ch " << station << " " << tmpefficiency << " " << tmpvariance << " " << lumiSeg.id() << endl;
00174           
00175           if(tmpefficiency < 0.2 || tmpvariance == 0){
00176             nFailingChambers++;
00177             continue;
00178           }
00179 
00180           meaneff += tmpefficiency/tmpvariance;
00181           errorsum += 1./tmpvariance;
00182 
00183           LogTrace("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
00184             << "Wheel: " << wheel << " Stat: " << station
00185             << " Sect: " << sector << " status: " << meaneff/errorsum << endl;
00186         }
00187 
00188         if(sector == 4 || sector == 10) {
00189           int whichSector = (sector == 4) ? 13 : 14;
00190 
00191           const double tmpefficiency = segmentWheelSummary->getBinContent(whichSector, 4);
00192           const double tmpvariance = pow(segmentWheelSummary->getBinError(whichSector, 4),2);
00193 
00194           if(tmpefficiency > 0.2 && tmpvariance != 0) {
00195             meaneff += tmpefficiency/tmpvariance;
00196             errorsum += 1./tmpvariance;
00197           }
00198           else nFailingChambers++;
00199 
00200         }
00201 
00202         double eff_result = 0;
00203         if(errorsum != 0) eff_result = meaneff/errorsum;
00204 
00205         if(nFailingChambers != 0) {
00206           if(sector != 4 && sector != 10) eff_result = eff_result*(4.-nFailingChambers)/4.;
00207           else eff_result = eff_result*(5.-nFailingChambers)/5.;
00208         }
00209 
00210         if(eff_result > 0.7) globalEffSummary->Fill(sector,wheel,1.);
00211         else if(eff_result < 0.7 && eff_result > 0.5) globalEffSummary->Fill(sector,wheel,0.6);
00212         else if(eff_result < 0.5 && eff_result > 0.3) globalEffSummary->Fill(sector,wheel,0.4);
00213         else if(eff_result < 0.3 && eff_result > 0.) globalEffSummary->Fill(sector,wheel,0.15);
00214 
00215         //if(wheel == 2 && sector == 9) cout << "eff_result " << eff_result << endl;
00216         //if(wheel == 2 && sector == 9) cout << "nfail " << nFailingChambers++ << endl;
00217 
00218       }
00219     }
00220   }
00221   return;
00222 }
00223 
00224 void DTChamberEfficiencyClient::endJob()
00225 {
00226   LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
00227     << "DTChamberEfficiencyClient: endJob";
00228   return;
00229 }
00230 
00231 void DTChamberEfficiencyClient::bookHistos()
00232 {
00233 
00234   dbe->setCurrentFolder("DT/05-ChamberEff");
00235   globalEffSummary = dbe->book2D("EfficiencyGlbSummary","Efficiency Summary",12,1,13,5,-2,3);
00236   globalEffSummary->setAxisTitle("sector",1);
00237   globalEffSummary->setAxisTitle("wheel",2);
00238 
00239   globalEffDistr = dbe->book1D("TotalEfficiency","Total efficiency",51,0.,1.02);
00240   globalEffDistr -> setAxisTitle("Eff",1);
00241 
00242   for(int wh=-2; wh<=2; wh++){
00243     stringstream wheel; wheel << wh;
00244     string histoNameAll =  "EfficiencyMap_All_W" + wheel.str();
00245     string histoTitleAll =  "Efficiency map for all segments for wheel " + wheel.str();
00246 
00247     string histoNameQual =  "EfficiencyMap_Qual_W" + wheel.str();
00248     string histoTitleQual =  "Efficiency map for quality segments for wheel " + wheel.str();
00249 
00250     string histoNameEff =  "Efficiency_W" + wheel.str();
00251     string histoTitleEff =  "Segment efficiency, wheel " + wheel.str();
00252 
00253     dbe->setCurrentFolder("DT/05-ChamberEff");
00254 
00255     summaryHistos[wh+2][0] = dbe->book2D(histoNameAll.c_str(),histoTitleAll.c_str(),14,1.,15.,4,1.,5.);
00256     summaryHistos[wh+2][0]->setAxisTitle("Sector",1);
00257     summaryHistos[wh+2][0]->setBinLabel(1,"MB1",2);
00258     summaryHistos[wh+2][0]->setBinLabel(2,"MB2",2);
00259     summaryHistos[wh+2][0]->setBinLabel(3,"MB3",2);
00260     summaryHistos[wh+2][0]->setBinLabel(4,"MB4",2);
00261 
00262     EffDistrPerWh[wh+2] = dbe -> book1D(histoNameEff.c_str(),histoTitleEff.c_str(),51,0.,1.02);
00263     EffDistrPerWh[wh+2] -> setAxisTitle("Eff",1);
00264 
00265     dbe->setCurrentFolder("DT/05-ChamberEff/HighQual");
00266 
00267     summaryHistos[wh+2][1] = dbe->book2D(histoNameQual.c_str(),histoTitleQual.c_str(),14,1.,15.,4,1.,5.);
00268     summaryHistos[wh+2][1]->setAxisTitle("Sector",1);
00269     summaryHistos[wh+2][1]->setBinLabel(1,"MB1",2);
00270     summaryHistos[wh+2][1]->setBinLabel(2,"MB2",2);
00271     summaryHistos[wh+2][1]->setBinLabel(3,"MB3",2);
00272     summaryHistos[wh+2][1]->setBinLabel(4,"MB4",2);
00273    
00274   }
00275 
00276   return;
00277 }