CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/DQM/DTMonitorClient/src/DTTriggerEfficiencyTest.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2010/01/05 10:15:46 $
00005  *  $Revision: 1.4 $
00006  *  \author C. Battilana - CIEMAT
00007  */
00008 
00009 
00010 // This class header
00011 #include "DQM/DTMonitorClient/src/DTTriggerEfficiencyTest.h"
00012 
00013 // Framework headers
00014 #include "FWCore/Framework/interface/EventSetup.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016 #include "DQMServices/Core/interface/MonitorElement.h"
00017 #include "DQMServices/Core/interface/DQMStore.h"
00018 
00019 // Geometry
00020 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00021 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00022 
00023 // Trigger
00024 #include "DQM/DTMonitorModule/interface/DTTrigGeomUtils.h"
00025 
00026 // Root
00027 #include "TF1.h"
00028 #include "TProfile.h"
00029 
00030 
00031 //C++ headers
00032 #include <iostream>
00033 #include <sstream>
00034 
00035 using namespace edm;
00036 using namespace std;
00037 
00038 
00039 DTTriggerEfficiencyTest::DTTriggerEfficiencyTest(const edm::ParameterSet& ps){
00040 
00041   setConfig(ps,"DTTriggerEfficiency");
00042   baseFolderDCC = "DT/03-LocalTrigger-DCC/";
00043   baseFolderDDU = "DT/04-LocalTrigger-DDU/";
00044   detailedPlots = ps.getUntrackedParameter<bool>("detailedAnalysis",true);
00045 
00046 }
00047 
00048 
00049 DTTriggerEfficiencyTest::~DTTriggerEfficiencyTest(){
00050   
00051 }
00052 
00053 
00054 void DTTriggerEfficiencyTest::beginJob(){
00055 
00056   DTLocalTriggerBaseTest::beginJob();
00057 
00058 }
00059 
00060 
00061 void DTTriggerEfficiencyTest::beginRun(const edm::Run& r,const edm::EventSetup& c){
00062   
00063   DTLocalTriggerBaseTest::beginRun(r,c);
00064   trigGeomUtils = new DTTrigGeomUtils(muonGeom);
00065 
00066   vector<string>::const_iterator iTr   = trigSources.begin();
00067   vector<string>::const_iterator trEnd = trigSources.end();
00068   vector<string>::const_iterator iHw   = hwSources.begin();
00069   vector<string>::const_iterator hwEnd = hwSources.end();
00070 
00071 
00072   //Booking
00073   if(parameters.getUntrackedParameter<bool>("staticBooking", true)){
00074     for (; iTr != trEnd; ++iTr){
00075       trigSource = (*iTr);
00076       for (; iHw != hwEnd; ++iHw){
00077         hwSource = (*iHw);
00078         // Loop over the TriggerUnits
00079         for (int wh=-2; wh<=2; ++wh){
00080           if (detailedPlots) {
00081             for (int sect=1; sect<=12; ++sect){
00082               for (int stat=1; stat<=4; ++stat){
00083                 DTChamberId chId(wh,stat,sect);
00084                 bookChambHistos(chId,"TrigEffPosvsAnglePhi","Segment");
00085                 bookChambHistos(chId,"TrigEffPosvsAngleCorrPhi","Segment");
00086               }
00087             }
00088           }
00089           bookWheelHistos(wh,"TrigEffPhi");  
00090           bookWheelHistos(wh,"TrigEffCorrPhi");  
00091         }
00092       }
00093     }
00094   }
00095   
00096 }
00097 
00098 
00099 void DTTriggerEfficiencyTest::runClientDiagnostic() {
00100 
00101   // Loop over Trig & Hw sources
00102   for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
00103     trigSource = (*iTr);
00104     for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
00105       hwSource = (*iHw);
00106       // Loop over the TriggerUnits
00107       for (int wh=-2; wh<=2; ++wh){
00108         
00109         TH2F * TrigEffDenum   = getHisto<TH2F>(dbe->get(getMEName("TrigEffDenum","",wh)));
00110         TH2F * TrigEffNum     = getHisto<TH2F>(dbe->get(getMEName("TrigEffNum","",wh)));
00111         TH2F * TrigEffCorrNum = getHisto<TH2F>(dbe->get(getMEName("TrigEffCorrNum","",wh)));
00112         
00113         if (TrigEffDenum && TrigEffNum && TrigEffCorrNum && TrigEffDenum->GetEntries()>1) {
00114           
00115           if( whME[wh].find(fullName("TrigEffPhi")) == whME[wh].end() ){
00116             bookWheelHistos(wh,"TrigEffPhi");  
00117             bookWheelHistos(wh,"TrigEffCorrPhi");  
00118           }
00119           std::map<std::string,MonitorElement*> *innerME = &(whME[wh]);
00120           makeEfficiencyME2D(TrigEffNum,TrigEffDenum,innerME->find(fullName("TrigEffPhi"))->second);
00121           makeEfficiencyME2D(TrigEffCorrNum,TrigEffDenum,innerME->find(fullName("TrigEffCorrPhi"))->second);
00122           
00123         }
00124 
00125         if (detailedPlots) {
00126           for (int stat=1; stat<=4; ++stat){
00127             for (int sect=1; sect<=12; ++sect){
00128               DTChamberId chId(wh,stat,sect);
00129               uint32_t indexCh = chId.rawId();
00130               
00131               // Perform Efficiency analysis (Phi+Segments 2D)
00132               TH2F * TrackPosvsAngle        = getHisto<TH2F>(dbe->get(getMEName("TrackPosvsAngle","Segment", chId)));
00133               TH2F * TrackPosvsAngleAnyQual = getHisto<TH2F>(dbe->get(getMEName("TrackPosvsAngleAnyQual","Segment", chId)));
00134               TH2F * TrackPosvsAngleCorr    = getHisto<TH2F>(dbe->get(getMEName("TrackPosvsAngleCorr","Segment", chId)));
00135             
00136               if (TrackPosvsAngle && TrackPosvsAngleAnyQual && TrackPosvsAngleCorr && TrackPosvsAngle->GetEntries()>1) {
00137               
00138                 if( chambME[indexCh].find(fullName("TrigEffAnglePhi")) == chambME[indexCh].end()){
00139                   bookChambHistos(chId,"TrigEffPosvsAnglePhi","Segment");
00140                   bookChambHistos(chId,"TrigEffPosvsAngleCorrPhi","Segment");
00141                 }
00142                 
00143                 std::map<std::string,MonitorElement*> *innerME = &(chambME[indexCh]);
00144                 makeEfficiencyME2D(TrackPosvsAngleAnyQual,TrackPosvsAngle,innerME->find(fullName("TrigEffPosvsAnglePhi"))->second);
00145                 makeEfficiencyME2D(TrackPosvsAngleCorr,TrackPosvsAngle,innerME->find(fullName("TrigEffPosvsAngleCorrPhi"))->second);
00146              
00147               }
00148             }
00149           }
00150         }
00151       }
00152 
00153     }
00154   }     
00155 
00156 }
00157 
00158 void DTTriggerEfficiencyTest::makeEfficiencyME2D(TH2F* numerator, TH2F* denominator, MonitorElement* result){
00159   
00160   TH2F* efficiency = result->getTH2F();
00161   efficiency->Divide(numerator,denominator,1,1,"");
00162   
00163   int nbinsx = efficiency->GetNbinsX();
00164   int nbinsy = efficiency->GetNbinsY();
00165   for (int binx=1; binx<=nbinsx; ++binx){
00166     for (int biny=1; biny<=nbinsy; ++biny){
00167       float error = 0;
00168       float bineff = efficiency->GetBinContent(binx,biny);
00169 
00170       if (denominator->GetBinContent(binx,biny)){
00171         error = sqrt(bineff*(1-bineff)/denominator->GetBinContent(binx,biny));
00172       }
00173       else {
00174         error = 1;
00175         efficiency->SetBinContent(binx,biny,0.);
00176       }
00177  
00178       efficiency->SetBinError(binx,biny,error);
00179     }
00180   }
00181 
00182 }    
00183 
00184 
00185 void DTTriggerEfficiencyTest::bookChambHistos(DTChamberId chambId, string htype, string folder) {
00186   
00187   stringstream wheel; wheel << chambId.wheel();
00188   stringstream station; station << chambId.station();   
00189   stringstream sector; sector << chambId.sector();
00190 
00191   string fullType  = fullName(htype);
00192   bool isDCC = hwSource=="DCC" ;
00193   string HistoName = fullType + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
00194 
00195   dbe->setCurrentFolder(topFolder(isDCC) + 
00196                         "Wheel" + wheel.str() +
00197                         "/Sector" + sector.str() +
00198                         "/Station" + station.str() + 
00199                         "/" + folder + "/");
00200   
00201   LogTrace(category()) << "[" << testName << "Test]: booking " + topFolder(isDCC) + "Wheel" << wheel.str() 
00202                        <<"/Sector" << sector.str() << "/Station" << station.str() << "/" + folder + "/" << HistoName;
00203 
00204   
00205   uint32_t indexChId = chambId.rawId();
00206   float min, max;
00207   int nbins;
00208   trigGeomUtils->phiRange(chambId,min,max,nbins,20);
00209   if (htype.find("TrigEffPosvsAnglePhi") == 0 ){
00210     chambME[indexChId][fullType] = dbe->book2D(HistoName.c_str(),"Trigger efficiency (any qual.) position vs angle (Phi)",12,-30.,30.,nbins,min,max);
00211     return;
00212   }
00213   if (htype.find("TrigEffPosvsAngleCorrPhi") == 0 ){
00214     chambME[indexChId][fullType] = dbe->book2D(HistoName.c_str(),"Trigger efficiency (correlated) pos vs angle (Phi)",12,-30.,30.,nbins,min,max);
00215     return;
00216   }
00217 
00218 }