CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DQM/RPCMonitorClient/src/RPCEfficiencyPerRingLayer.cc

Go to the documentation of this file.
00001 //
00002 // Original Author:  Cesare Calabria,161 R-006,
00003 //         Created:  Fri May 13 12:58:43 CEST 2011
00004 
00005 
00006 // user include files
00007 #include "DQM/RPCMonitorClient/interface/RPCEfficiencyPerRingLayer.h"
00008 #include <sstream>
00009 
00010 //CondFormats
00011 //#include "CondFormats/RunInfo/interface/RunInfo.h"
00012 //#include "CondFormats/DataRecord/interface/RunSummaryRcd.h"
00013 // Framework
00014 //#include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 //#include "FWCore/Framework/interface/LuminosityBlock.h"
00016 #include "FWCore/Framework/interface/Event.h"
00017 #include "FWCore/Framework/interface/EventSetup.h"
00018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00019 //DQM Services
00020 
00021 
00022 RPCEfficiencyPerRingLayer::RPCEfficiencyPerRingLayer(const edm::ParameterSet& ps) {
00023 
00024   globalFolder_ = ps.getUntrackedParameter<std::string>("GlobalFolder", "RPC/RPCEfficiency/");
00025   SaveFile  = ps.getUntrackedParameter<bool>("SaveFile", false);
00026   NameFile  = ps.getUntrackedParameter<std::string>("NameFile","RPCEfficiency.root");
00027 }
00028 
00029 
00030 RPCEfficiencyPerRingLayer::~RPCEfficiencyPerRingLayer(){ }
00031 
00032 void RPCEfficiencyPerRingLayer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup){}
00033 
00034 void RPCEfficiencyPerRingLayer::beginJob(){
00035 
00036   dbe_ = edm::Service<DQMStore>().operator->();
00037 }
00038 
00039 void RPCEfficiencyPerRingLayer::beginRun(const edm::Run& r, const edm::EventSetup& c){
00040 
00041   if(dbe_ == 0) return;
00042 
00043   dbe_->setCurrentFolder(globalFolder_);
00044   EfficiencyPerRing = dbe_->book1D("EfficiencyPerRing","Efficiency per Ring",12,0.5,12.5);
00045   EfficiencyPerLayer = dbe_->book1D("EfficiencyPerLayer","Efficiency per Layer",6,0.5,6.5);
00046 
00047 }
00048 
00049 void RPCEfficiencyPerRingLayer::endRun(const edm::Run& r, const edm::EventSetup& c){
00050 
00051    std::stringstream meName1;
00052    MonitorElement * myMe1;
00053 
00054    std::stringstream meName2;
00055    MonitorElement * myMe2;
00056 
00057    std::stringstream binName;
00058    binName.str("");
00059 
00060    meName1.str("");
00061    meName1<<globalFolder_;
00062 
00063    meName2.str("");
00064    meName2<<globalFolder_;
00065 
00066    int k = 0;
00067 
00068    //EfficiencyPerRing
00069 
00070    for(int i=-3; i<=3; i++){
00071         if(i == 0) continue;
00072         for(int j=2; j<=3; j++){
00073                 meName1.str("");
00074                 meName2.str("");
00075                 if(i < 0){
00076                         meName1<<globalFolder_<<"Azimutal/ExGregDistroDm"<<abs(i)<<"R"<<j;
00077                         meName2<<globalFolder_<<"Azimutal/OcGregDistroDm"<<abs(i)<<"R"<<j;
00078                         //std::cout<<meName1.str()<<std::endl;
00079                         //std::cout<<meName2.str()<<std::endl;
00080                         binName.str("");
00081                         binName<<"RE-"<<i<<"/"<<j;
00082                         k++;}
00083                 else if(i >0){
00084                         meName1<<globalFolder_<<"Azimutal/ExGregDistroD"<<abs(i)<<"R"<<j;
00085                         meName2<<globalFolder_<<"Azimutal/OcGregDistroD"<<abs(i)<<"R"<<j;
00086                         //std::cout<<meName1.str()<<std::endl;
00087                         //std::cout<<meName2.str()<<std::endl;
00088                         binName.str("");
00089                         binName<<"RE+"<<abs(i)<<"/"<<j;
00090                         k++;}
00091 
00092                 myMe1 = dbe_->get(meName1.str());
00093                 myMe2 = dbe_->get(meName2.str());
00094                 TH1 * histo1 = myMe1->getTH1();
00095                 TH1 * histo2 = myMe2->getTH1();
00096                 if(myMe1 && myMe2){
00097 
00098                         int exg = histo1->Integral(); 
00099                         int obg = histo2->Integral();
00100                         double eff = 0;
00101                         double err = 0;
00102                         if(exg != 0){ 
00103                                 eff = (double)obg/(double)exg; 
00104                                 err = sqrt(eff*(1-eff)/(double)exg);}
00105                         //std::cout<<exg<<" "<<obg<<" "<<eff<<" "<<err<<" "<<k<<std::endl;
00106                         if(k%2 != 0 && k < 7){ 
00107                                 EfficiencyPerRing->setBinContent(k+1, eff);
00108                                 EfficiencyPerRing->setBinError(k+1, err);
00109                                 EfficiencyPerRing->setBinLabel(k+1, binName.str());}
00110                         else if(k%2 == 0 && k < 7){
00111                                 EfficiencyPerRing->setBinContent(k-1, eff);
00112                                 EfficiencyPerRing->setBinError(k-1, err);
00113                                 EfficiencyPerRing->setBinLabel(k-1, binName.str());}
00114                         else if(k >= 7){
00115                                 EfficiencyPerRing->setBinContent(k, eff);
00116                                 EfficiencyPerRing->setBinError(k, err);
00117                                 EfficiencyPerRing->setBinLabel(k, binName.str());}
00118                 }
00119         }
00120    }
00121 
00122    //EfficiencyPerLayer
00123 
00124    for(int i=1; i<=6; i++){
00125 
00126         int Exp = 0;
00127         int Obs = 0;
00128         double eff = 0;
00129         double err = 0;
00130 
00131         for(int j=-2; j<=2; j++){
00132                 meName1.str("");
00133                 meName2.str("");
00134                 if(j < 0){ 
00135                         meName1<<globalFolder_<<"BarrelPerLayer/ExpLayerWm"<<abs(j);
00136                         meName2<<globalFolder_<<"BarrelPerLayer/ObsLayerWm"<<abs(j);}
00137                 else{
00138                         meName1<<globalFolder_<<"BarrelPerLayer/ExpLayerW"<<j;
00139                         meName2<<globalFolder_<<"BarrelPerLayer/ObsLayerW"<<j;}
00140                 //std::cout<<meName1.str()<<std::endl;
00141                 //std::cout<<meName2.str()<<std::endl;
00142                 myMe1 = dbe_->get(meName1.str());
00143                 myMe2 = dbe_->get(meName2.str());
00144                 if(myMe1 && myMe2){
00145                         Exp += myMe1->getBinContent(i);
00146                         Obs += myMe2->getBinContent(i);
00147                 }
00148         }
00149 
00150         if(Exp != 0){
00151                 eff = (double)Obs/(double)Exp;
00152                 err = sqrt(eff*(1-eff)/(double)Exp);}
00153         EfficiencyPerLayer->setBinContent(i, eff);
00154         EfficiencyPerLayer->setBinError(i, err);
00155         binName.str("");
00156         binName<<"Layer "<<i;
00157         EfficiencyPerLayer->setBinLabel(i, binName.str());
00158         //std::cout<<Exp<<" "<<Obs<<" "<<eff<<" "<<err<<std::endl;
00159   }
00160 
00161    if(SaveFile) dbe_->save(NameFile);
00162 
00163 }
00164