CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/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: 2011/10/28 08:12:44 $
00005  *  $Revision: 1.6 $
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         bookHistos("TrigEffPhi","");
00080         bookHistos("TrigEffCorrPhi","");
00081         for (int wh=-2; wh<=2; ++wh){
00082           if (detailedPlots) {
00083             for (int sect=1; sect<=12; ++sect){
00084               for (int stat=1; stat<=4; ++stat){
00085                 DTChamberId chId(wh,stat,sect);
00086                 bookChambHistos(chId,"TrigEffPosvsAnglePhi","Segment");
00087                 bookChambHistos(chId,"TrigEffPosvsAngleCorrPhi","Segment");
00088               }
00089             }
00090           }
00091           bookWheelHistos(wh,"TrigEffPhi","");  
00092           bookWheelHistos(wh,"TrigEffCorrPhi","");  
00093         }
00094       }
00095     }
00096   }
00097 
00098 }
00099 
00100 
00101 void DTTriggerEfficiencyTest::runClientDiagnostic() {
00102 
00103   // Loop over Trig & Hw sources
00104   for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
00105     trigSource = (*iTr);
00106     for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
00107       hwSource = (*iHw);
00108       // Loop over the TriggerUnits
00109       if( globalEffDistr.find(fullName("TrigEffPhi")) == globalEffDistr.end() ){
00110         bookHistos("TrigEffPhi","");
00111         bookHistos("TrigEffCorrPhi","");
00112       }
00113       for (int wh=-2; wh<=2; ++wh){
00114 
00115         TH2F * TrigEffDenum   = getHisto<TH2F>(dbe->get(getMEName("TrigEffDenum","Task",wh)));
00116         TH2F * TrigEffNum     = getHisto<TH2F>(dbe->get(getMEName("TrigEffNum","Task",wh)));
00117         TH2F * TrigEffCorrNum = getHisto<TH2F>(dbe->get(getMEName("TrigEffCorrNum","Task",wh)));
00118 
00119         if (TrigEffDenum && TrigEffNum && TrigEffCorrNum && TrigEffDenum->GetEntries()>1) {
00120 
00121           if( whME[wh].find(fullName("TrigEffPhi")) == whME[wh].end() ){
00122             bookWheelHistos(wh,"TrigEffPhi","");  
00123             bookWheelHistos(wh,"TrigEffCorrPhi","");  
00124           }
00125 
00126           MonitorElement* Eff1DAll_TrigEffPhi = (&globalEffDistr)->find(fullName("TrigEffPhi"))->second;
00127           MonitorElement* Eff1DAll_TrigEffCorrPhi = (&globalEffDistr)->find(fullName("TrigEffCorrPhi"))->second;
00128 
00129           MonitorElement* Eff1DWh_TrigEffPhi = (&(EffDistrPerWh[wh]))->find(fullName("TrigEffPhi"))->second;
00130           MonitorElement* Eff1DWh_TrigEffCorrPhi = (&(EffDistrPerWh[wh]))->find(fullName("TrigEffCorrPhi"))->second;
00131 
00132           MonitorElement* Eff2DWh_TrigEffPhi = (&(whME[wh]))->find(fullName("TrigEffPhi"))->second;
00133           MonitorElement* Eff2DWh_TrigEffCorrPhi = (&(whME[wh]))->find(fullName("TrigEffCorrPhi"))->second;
00134 
00135           makeEfficiencyME(TrigEffNum,TrigEffDenum,Eff2DWh_TrigEffPhi,Eff1DWh_TrigEffPhi,Eff1DAll_TrigEffPhi);
00136           makeEfficiencyME(TrigEffCorrNum,TrigEffDenum,Eff2DWh_TrigEffCorrPhi,Eff1DWh_TrigEffCorrPhi,Eff1DAll_TrigEffCorrPhi);
00137 
00138         }
00139 
00140         if (detailedPlots) {
00141           for (int stat=1; stat<=4; ++stat){
00142             for (int sect=1; sect<=12; ++sect){
00143               DTChamberId chId(wh,stat,sect);
00144               uint32_t indexCh = chId.rawId();
00145 
00146               // Perform Efficiency analysis (Phi+Segments 2D)
00147               TH2F * TrackPosvsAngle        = getHisto<TH2F>(dbe->get(getMEName("TrackPosvsAngle","Segment", chId)));
00148               TH2F * TrackPosvsAngleAnyQual = getHisto<TH2F>(dbe->get(getMEName("TrackPosvsAngleAnyQual","Segment", chId)));
00149               TH2F * TrackPosvsAngleCorr    = getHisto<TH2F>(dbe->get(getMEName("TrackPosvsAngleCorr","Segment", chId)));
00150 
00151               if (TrackPosvsAngle && TrackPosvsAngleAnyQual && TrackPosvsAngleCorr && TrackPosvsAngle->GetEntries()>1) {
00152 
00153                 if( chambME[indexCh].find(fullName("TrigEffAnglePhi")) == chambME[indexCh].end()){
00154                   bookChambHistos(chId,"TrigEffPosvsAnglePhi","Segment");
00155                   bookChambHistos(chId,"TrigEffPosvsAngleCorrPhi","Segment");
00156                 }
00157 
00158                 std::map<std::string,MonitorElement*> *innerME = &(chambME[indexCh]);
00159                 makeEfficiencyME(TrackPosvsAngleAnyQual,TrackPosvsAngle,innerME->find(fullName("TrigEffPosvsAnglePhi"))->second);
00160                 makeEfficiencyME(TrackPosvsAngleCorr,TrackPosvsAngle,innerME->find(fullName("TrigEffPosvsAngleCorrPhi"))->second);
00161 
00162               }
00163             }
00164           }
00165         }
00166       }
00167 
00168     }
00169   }     
00170 
00171 }
00172 
00173 void DTTriggerEfficiencyTest::makeEfficiencyME(TH2F* numerator, TH2F* denominator, MonitorElement* result2DWh, MonitorElement* result1DWh, MonitorElement* result1D){
00174 
00175   TH2F* efficiency = result2DWh->getTH2F();
00176   efficiency->Divide(numerator,denominator,1,1,"");
00177 
00178   int nbinsx = efficiency->GetNbinsX();
00179   int nbinsy = efficiency->GetNbinsY();
00180   for (int binx=1; binx<=nbinsx; ++binx){
00181     for (int biny=1; biny<=nbinsy; ++biny){
00182       float error = 0;
00183       float bineff = efficiency->GetBinContent(binx,biny);
00184 
00185       result1DWh->Fill(bineff);
00186       result1D->Fill(bineff);
00187 
00188       if (denominator->GetBinContent(binx,biny)){
00189         error = sqrt(bineff*(1-bineff)/denominator->GetBinContent(binx,biny));
00190       }
00191       else {
00192         error = 1;
00193         efficiency->SetBinContent(binx,biny,0.);
00194       }
00195 
00196       efficiency->SetBinError(binx,biny,error);
00197     }
00198   }
00199 
00200 }
00201 
00202 void DTTriggerEfficiencyTest::makeEfficiencyME(TH2F* numerator, TH2F* denominator, MonitorElement* result2DWh){
00203 
00204   TH2F* efficiency = result2DWh->getTH2F();
00205   efficiency->Divide(numerator,denominator,1,1,"");
00206 
00207   int nbinsx = efficiency->GetNbinsX();
00208   int nbinsy = efficiency->GetNbinsY();
00209   for (int binx=1; binx<=nbinsx; ++binx){
00210     for (int biny=1; biny<=nbinsy; ++biny){
00211       float error = 0;
00212       float bineff = efficiency->GetBinContent(binx,biny);
00213 
00214       if (denominator->GetBinContent(binx,biny)){
00215         error = sqrt(bineff*(1-bineff)/denominator->GetBinContent(binx,biny));
00216       }
00217       else {
00218         error = 1;
00219         efficiency->SetBinContent(binx,biny,0.);
00220       }
00221 
00222       efficiency->SetBinError(binx,biny,error);
00223     }
00224   }
00225 
00226 }    
00227 
00228 string DTTriggerEfficiencyTest::getMEName(string histoTag, string folder, int wh) {
00229 
00230   stringstream wheel; wheel << wh;
00231 
00232   string folderName =  topFolder(hwSource=="DCC") + folder + "/";
00233 
00234   string histoname = sourceFolder + folderName 
00235     + fullName(histoTag) + "_W" + wheel.str();
00236 
00237   return histoname;
00238 
00239 }
00240 
00241 void DTTriggerEfficiencyTest::bookHistos(string hTag,string folder) {
00242 
00243   string basedir;  
00244   bool isDCC = hwSource=="DCC" ;  
00245   basedir = topFolder(isDCC);   //Book summary histo outside Task directory 
00246 
00247   if (folder != "") {
00248     basedir += folder +"/" ;
00249   }
00250   dbe->setCurrentFolder(basedir);
00251 
00252   string fullTag = fullName(hTag);
00253   string hname = fullTag + "_All";
00254 
00255   globalEffDistr[fullTag] = dbe->book1D(hname.c_str(),hname.c_str(),51,0.,1.02);
00256   globalEffDistr[fullTag] ->setAxisTitle("Trig Eff",1);
00257 
00258 }
00259 
00260 void DTTriggerEfficiencyTest::bookWheelHistos(int wheel,string hTag,string folder) {
00261 
00262   stringstream wh; wh << wheel;
00263   string basedir;  
00264   bool isDCC = hwSource=="DCC" ;  
00265   if (hTag.find("Summary") != string::npos) {
00266     basedir = topFolder(isDCC);   //Book summary histo outside wheel directories
00267   } else {
00268     basedir = topFolder(isDCC) + "Wheel" + wh.str() + "/" ;
00269 
00270   }
00271   if (folder != "") {
00272     basedir += folder +"/" ;
00273   }
00274   dbe->setCurrentFolder(basedir);
00275 
00276   string fullTag = fullName(hTag);
00277   string hname    = fullTag+ "_W" + wh.str();
00278 
00279   string hnameAll = fullTag+ "_All_W" + wh.str();
00280 
00281   LogTrace(category()) << "[" << testName << "Test]: booking "<< basedir << hname;
00282 
00283   (EffDistrPerWh[wheel])[fullTag] = dbe->book1D(hnameAll.c_str(),hnameAll.c_str(),51,0.,1.02);
00284 
00285   if (hTag.find("Phi")!= string::npos ||
00286       hTag.find("Summary") != string::npos ){    
00287     MonitorElement* me = dbe->book2D(hname.c_str(),hname.c_str(),12,1,13,4,1,5);
00288 
00289     //     setLabelPh(me);
00290     me->setBinLabel(1,"MB1",2);
00291     me->setBinLabel(2,"MB2",2);
00292     me->setBinLabel(3,"MB3",2);
00293     me->setBinLabel(4,"MB4",2);
00294     me->setAxisTitle("Sector",1);
00295 
00296     whME[wheel][fullTag] = me;
00297     return;
00298   }
00299 
00300   if (hTag.find("Theta") != string::npos){
00301     MonitorElement* me =dbe->book2D(hname.c_str(),hname.c_str(),12,1,13,3,1,4);
00302 
00303     //     setLabelTh(me);
00304     me->setBinLabel(1,"MB1",2);
00305     me->setBinLabel(2,"MB2",2);
00306     me->setBinLabel(3,"MB3",2);
00307     me->setAxisTitle("Sector",1);
00308 
00309     whME[wheel][fullTag] = me;
00310     return;
00311   }
00312 
00313 }
00314 
00315 void DTTriggerEfficiencyTest::bookChambHistos(DTChamberId chambId, string htype, string folder) {
00316 
00317   stringstream wheel; wheel << chambId.wheel();
00318   stringstream station; station << chambId.station();   
00319   stringstream sector; sector << chambId.sector();
00320 
00321   string fullType  = fullName(htype);
00322   bool isDCC = hwSource=="DCC" ;
00323   string HistoName = fullType + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
00324 
00325   dbe->setCurrentFolder(topFolder(isDCC) + 
00326       "Wheel" + wheel.str() +
00327       "/Sector" + sector.str() +
00328       "/Station" + station.str() + 
00329       "/" + folder + "/");
00330 
00331   LogTrace(category()) << "[" << testName << "Test]: booking " + topFolder(isDCC) + "Wheel" << wheel.str() 
00332     <<"/Sector" << sector.str() << "/Station" << station.str() << "/" + folder + "/" << HistoName;
00333 
00334 
00335   uint32_t indexChId = chambId.rawId();
00336   float min, max;
00337   int nbins;
00338   trigGeomUtils->phiRange(chambId,min,max,nbins,20);
00339   if (htype.find("TrigEffPosvsAnglePhi") == 0 ){
00340     chambME[indexChId][fullType] = dbe->book2D(HistoName.c_str(),"Trigger efficiency (any qual.) position vs angle (Phi)",12,-30.,30.,nbins,min,max);
00341     return;
00342   }
00343   if (htype.find("TrigEffPosvsAngleCorrPhi") == 0 ){
00344     chambME[indexChId][fullType] = dbe->book2D(HistoName.c_str(),"Trigger efficiency (correlated) pos vs angle (Phi)",12,-30.,30.,nbins,min,max);
00345     return;
00346   }
00347 
00348 }