CMS 3D CMS Logo

FourVectorHLTClient.cc

Go to the documentation of this file.
00001 /*
00002 
00003    FourVectorHLTClient.cc
00004    author:  Vladimir Rekovic, U Minn. 
00005    date of first version: Sept 2008
00006 
00007 */
00008 //$Id: FourVectorHLTClient.cc,v 1.4 2008/11/01 19:19:47 rekovic Exp $
00009 
00010 #include "DQMOffline/Trigger/interface/FourVectorHLTClient.h"
00011 
00012 #include "DQMServices/Core/interface/QTest.h"
00013 #include "FWCore/ServiceRegistry/interface/Service.h"
00014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "FWCore/Framework/interface/EventSetup.h"
00017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00018 #include "DQMServices/Core/interface/QReport.h"
00019 #include "DQMServices/Core/interface/DQMStore.h"
00020 #include "DQMServices/Core/interface/MonitorElement.h"
00021 #include "TRandom.h"
00022 #include <TF1.h>
00023 #include <stdio.h>
00024 #include <sstream>
00025 #include <math.h>
00026 #include <TProfile.h>
00027 #include <TProfile2D.h>
00028 #include <memory>
00029 #include <iostream>
00030 #include <iomanip>
00031 #include <map>
00032 #include <vector>
00033 #include <string>
00034 #include <fstream>
00035 #include "TROOT.h"
00036 
00037 
00038 using namespace edm;
00039 using namespace std;
00040 
00041 FourVectorHLTClient::FourVectorHLTClient(const edm::ParameterSet& ps)
00042 {
00043   parameters_=ps;
00044   initialize();
00045 
00046 }
00047 
00048 FourVectorHLTClient::~FourVectorHLTClient(){
00049   LogDebug("FourVectorHLTClient")<< "FourVectorHLTClient: ending...." ;
00050 }
00051 
00052 //--------------------------------------------------------
00053 void FourVectorHLTClient::initialize(){ 
00054 
00055   counterLS_=0; 
00056   counterEvt_=0; 
00057   
00058   // get back-end interface
00059   dbe_ = Service<DQMStore>().operator->();
00060   
00061 
00062   // base folder for the contents of this job
00063   sourceDir_ = TString(parameters_.getUntrackedParameter<string>("hltSourceDir",""));
00064   LogDebug("FourVectorHLTClient")<< "Monitor dir = " << sourceDir_ << endl;
00065     
00066   clientDir_ = TString(parameters_.getUntrackedParameter<string>("hltClientDir",""));
00067   LogDebug("FourVectorHLTClient")<< "Client dir = " << clientDir_ << endl;
00068     
00069   prescaleLS_ = parameters_.getUntrackedParameter<int>("prescaleLS", -1);
00070   LogDebug("FourVectorHLTClient")<< "DQM lumi section prescale = " << prescaleLS_ << " lumi section(s)"<< endl;
00071   
00072   prescaleEvt_ = parameters_.getUntrackedParameter<int>("prescaleEvt", -1);
00073   LogDebug("FourVectorHLTClient")<< "DQM event prescale = " << prescaleEvt_ << " events(s)"<< endl;
00074   
00075 
00076       
00077 }
00078 
00079 //--------------------------------------------------------
00080 void FourVectorHLTClient::beginJob(const EventSetup& context){
00081 
00082 
00083   LogDebug("FourVectorHLTClient")<<"[FourVectorHLTClient]: beginJob" << endl;
00084   // get backendinterface  
00085   dbe_ = Service<DQMStore>().operator->();
00086 
00087 
00088 
00089   
00090 
00091 }
00092 
00093 //--------------------------------------------------------
00094 void FourVectorHLTClient::beginRun(const Run& r, const EventSetup& context) {
00095 
00096   LogDebug("FourVectorHLTClient")<<"[FourVectorHLTClient]: beginRun" << endl;
00097         /*
00098   TString summaryFolder = clientDir_ + TString("/reportSummaryContents/");
00099   TString summaryPath = summaryFolder + TString("reportSummary");
00100 
00101   dbe_->setCurrentFolder(summaryFolder.Data());
00102   
00103 
00104   reportSummary_ = dbe_->get(summaryPath.Data());
00105   if ( reportSummary_ ) {
00106       dbe_->removeElement(reportSummary_->getName()); 
00107   }
00108 
00109   reportSummary_ = dbe_->bookFloat("reportSummary");
00110 
00111   //initialize reportSummary to 1
00112   if (reportSummary_) reportSummary_->Fill(-999);
00113         */
00114 
00115 }
00116 
00117 //--------------------------------------------------------
00118 void FourVectorHLTClient::beginLuminosityBlock(const LuminosityBlock& lumiSeg, const EventSetup& context) {
00119    // optionally reset histograms here
00120 }
00121 
00122 void FourVectorHLTClient::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& c){   
00123 
00124 
00125 } 
00126 
00127 
00128 
00129 //--------------------------------------------------------
00130 void FourVectorHLTClient::analyze(const Event& e, const EventSetup& context){
00131    
00132   counterEvt_++;
00133   if (prescaleEvt_<1) return;
00134   if (prescaleEvt_>0 && counterEvt_%prescaleEvt_ != 0) return;
00135   
00136   LogDebug("FourVectorHLTClient")<<"analyze..." << endl;
00137 
00138   
00139 
00140 
00141   //reportSummary = average of report summaries of each system
00142   
00143  
00144 }
00145 
00146 //--------------------------------------------------------
00147 void FourVectorHLTClient::endRun(const Run& r, const EventSetup& context){
00148  LogDebug("FourVectorHLTClient")<<"FourVectorHLTClient:: endLuminosityBlock "  << endl;
00149 
00150  // QTests
00152  Comp2RefKolmogorov * kl_test_ = new Comp2RefKolmogorov("my_kolm");
00153 
00154  // HLT paths
00155  TObjArray *hltPathNameColl = new TObjArray(100);
00156  hltPathNameColl->SetOwner();
00157 
00158  if(! dbe_->containsAnyMonitorable(sourceDir_.Data())) {
00159 
00160    LogDebug("FourVectorHLTClient")<<"[FourVectorHLTClient] endLuminosityBlock: sourceDir_(" << sourceDir_.Data() << ") has no MEs " << endl;
00161     return;
00162  }
00163 
00164  LogDebug("FourVectorHLTClient")<<"[FourVectorHLTClient] endLuminosityBlock: Interesting dir has MEs " << endl;
00165 
00166   hltMEs = dbe_->getContents(sourceDir_.Data());
00167   
00168  // For easier work, build vector<TString> to hold HLT ME names
00169  for(unsigned int i=0;i<hltMEs.size();i++) {
00170 
00171    if(hltMEs[i]->getName().find("HLT") == 0) hltMEName.push_back(TString(hltMEs[i]->getName()));
00172 
00173  }
00174 
00175  // loop over all HLT DQM MEs to get HLT path names
00177  LogDebug("FourVectorHLTClient")<<"[FourVectorHLTClient] HLT DQM MEs are: "  << endl;
00178 
00179  for(unsigned int i=0;i<hltMEName.size();i++) {
00180 
00181    LogDebug("FourVectorHLTClient")<< hltMEName[i]  << endl;
00182 
00183    // collect HLT path names from MEs names, removing "_*" from the end
00185    TString tempName = hltMEName[i];
00186    tempName.Remove(tempName.Last('_'),tempName.Length());
00187    hltPathName.push_back(tempName);
00188 
00189    TObjString *tempHltName = new TObjString(tempName.Data());
00190 
00191    if( !hltPathNameColl->Contains(tempHltName)) {
00192 
00193      hltPathNameColl->Add(tempHltName);
00194 
00195    } 
00196 
00197  } //end for
00198   
00199  LogDebug("FourVectorHLTClient")<< "Number of derived HLT paths from DQM source directory: " << hltPathNameColl->GetEntriesFast()  << endl;
00200  
00202  // Loop over all path names
00204  for (int j=0;j<hltPathNameColl->GetEntriesFast();j++) {
00205 
00206 
00207    TObjString *curHltPath = (TObjString*)hltPathNameColl->At(j);
00208    TString pathPrefis = curHltPath->String() + TString("_");
00209     LogDebug("FourVectorHLTClient")<< " path " << curHltPath->String() << endl;
00210 
00211    TString pathFolder = clientDir_ + TString("/paths/") + curHltPath->String() + TString("/distributions");
00212 
00213    dbe_->setCurrentFolder(pathFolder.Data());
00214 
00216    // KolmogorovTest for each DQM histogram
00218    for(unsigned int i=0;i<hltMEName.size();i++) {
00219 
00220      TString tempHistName = hltMEName[i];
00221 
00222      // only consider histos belonging to current HLT path
00223      if( !tempHistName.Contains(curHltPath->String()) ) continue;
00224 
00225      // Some string gymnastics:
00226      //
00227      // there are paths like HLT_Jet180 and HLT_Jet180_MET60
00228      // make sure we dont cross use histograms of such paths
00229      // histogram name can only have one character "_" in addition to the pathname
00230      TString radical = tempHistName;
00231      radical.ReplaceAll(curHltPath->String()+"_","");
00232       LogDebug("FourVectorHLTClient")<< " tempHistName is " << tempHistName << "     radical is: " << radical << endl;
00233 
00234      if(radical.CountChar('_')>0) continue;
00235      
00236      TString histName = sourceDir_+TString("/")+tempHistName;
00237      TString klmgrvName = tempHistName+TString("_klmgrTest");
00238 
00239      //klmgrvTest_ = dbe_->bookFloat(klmgrvName.Data());
00240      //if (klmgrvTest_) klmgrvTest_->Fill(-999);
00241 
00242      MonitorElement *histME = dbe_->get(histName.Data());
00243 
00244 
00245      //std::cout << " Running test " << chi2_test_->getName() 
00246                //<< " (Algorithm: " << chi2_test_->getAlgoName() << ") "
00247                //<< std::endl;
00248      //float prob = chi2_test_->runTest(my_test);
00249 
00250 
00251       LogDebug("FourVectorHLTClient")<< " histME pathName:" << histME->getPathname() << ",   kind: " << histME->kind() << "  (TH1F=" << MonitorElement::DQM_KIND_TH1F << ")" << endl;
00252 
00253      if(histME->kind() == MonitorElement::DQM_KIND_TH1F) {
00254 
00255        TH1F *hist = new TH1F();
00256        hist = histME->getTH1F();
00257        dbe_->book1D(hist->GetName(),hist);
00258 
00259        // must be non empty hist to do KolmogorovTest
00260        if(hist->GetEntries() == 0) continue;
00261        if(hist->Integral() == 0) continue;
00262 
00263        LogDebug("FourVectorHLTClient")<< "endRun:   histName " << hist->GetName() << endl;
00264        LogDebug("FourVectorHLTClient")<< "endRun:   hist entries:" << hist->GetEntries() << endl;
00265 
00266        float kl_prob = kl_test_->runTest(histME);
00267 
00268        LogDebug("FourVectorHLTClient")<< "endRun:   KLMGRV test = " << kl_prob << endl;
00269      
00270        //if (klmgrvTest_) klmgrvTest_->Fill(kl_prob);
00271 
00272                  }
00273 
00274      if(histME->kind() == MonitorElement::DQM_KIND_TH2F) {
00275 
00276        TH2F *hist = new TH2F();
00277        hist = histME->getTH2F();
00278        dbe_->book2D(hist->GetName(),hist);
00279 
00280                          /*
00281        // must be non empty hist to do KolmogorovTest
00282        if(hist->GetEntries() == 0) continue;
00283        if(hist->Integral() == 0) continue;
00284 
00285        LogDebug("FourVectorHLTClient")<< "endRun:   histName " << hist->GetName() << endl;
00286        LogDebug("FourVectorHLTClient")<< "endRun:   hist entries:" << hist->GetEntries() << endl;
00287 
00288        float kl_prob = kl_test_->runTest(histME);
00289 
00290        LogDebug("FourVectorHLTClient")<< "endRun:   KLMGRV test = " << kl_prob << endl;
00291      
00292        if (klmgrvTest_) klmgrvTest_->Fill(kl_prob);
00293                          */
00294 
00295                  }
00296 
00297 
00298 
00299    } // end for
00300 
00302     // Efficiencies
00304     pathFolder = clientDir_ + TString("/paths/") + curHltPath->String() + TString("/efficiencies");
00305 
00306     dbe_->setCurrentFolder(pathFolder.Data());
00307 
00308     vector<TString> vObj;
00309     vObj.push_back(TString("phi"));
00310     vObj.push_back(TString("eta"));
00311 
00312     for (unsigned int k=0; k<vObj.size();k++) {
00313 
00314 
00315       TString oldHistPathNum = sourceDir_+TString("/")+curHltPath->String()+TString("_")+vObj[k]+TString("On"); 
00316       TString oldHistPathDen = sourceDir_+TString("/")+curHltPath->String()+TString("_")+vObj[k]+TString("L1"); 
00317   
00318   
00319       TString newHistName = curHltPath->String()+TString("_"+vObj[k]+"_Eff-OnToL1");
00320       TString newHistPath = pathFolder+newHistName;
00321   
00322       MonitorElement *numME = dbe_->get(oldHistPathNum.Data());
00323       MonitorElement *denME = dbe_->get(oldHistPathDen.Data());
00324   
00325       //check if HLTOffline histogram exist
00326       if ( numME &&  denME ) {
00327       
00328         //check if booked HLTClient histogram exist
00329         if ( dbe_->get(newHistPath.Data()) ) {
00330           dbe_->removeElement(newHistPath.Data());
00331         }
00332       
00333       
00334         TH1F* numHist = numME->getTH1F();
00335         TH1F* denHist = denME->getTH1F();
00336   
00337         TH1F* effHist = (TH1F*) numHist->Clone(newHistName.Data());
00338         effHist->SetTitle(newHistName.Data());
00339         effHist->Sumw2();
00340         effHist->Divide(denHist);
00341         
00342   
00343         //reportSummaryMap_ = dbe_->book1D(numHist->Divide(denHist));
00344         
00345         dbe_->book1D(newHistName.Data(), effHist);
00346   
00347       } // end if
00348       else {
00349   
00350         LogWarning("FourVectorHLTClient")<< "Cannot find NUM and DEN histograms to derive " << newHistName <<  "."<< endl;
00351   
00352 
00353       }
00354     } //end for obj k
00355 
00356   } //end for 
00357 
00358   hltPathNameColl->Delete();
00359   delete kl_test_;
00360 
00361 
00362 }
00363 
00364 //--------------------------------------------------------
00365 void FourVectorHLTClient::endJob(){
00366 }
00367 
00368 
00369 
00370 TH1F * FourVectorHLTClient::get1DHisto(string meName, DQMStore * dbi)
00371 {
00372 
00373   MonitorElement * me_ = dbi->get(meName);
00374 
00375   if (!me_) { 
00376     LogDebug("FourVectorHLTClient")<< "ME NOT FOUND." << endl;
00377     return NULL;
00378   }
00379 
00380   return me_->getTH1F();
00381 }
00382 
00383 TH2F * FourVectorHLTClient::get2DHisto(string meName, DQMStore * dbi)
00384 {
00385 
00386 
00387   MonitorElement * me_ = dbi->get(meName);
00388 
00389   if (!me_) { 
00390     LogDebug("FourVectorHLTClient")<< "ME NOT FOUND." << endl;
00391     return NULL;
00392   }
00393 
00394   return me_->getTH2F();
00395 }
00396 
00397 
00398 
00399 TProfile2D *  FourVectorHLTClient::get2DProfile(string meName, DQMStore * dbi)
00400 {
00401 
00402 
00403   MonitorElement * me_ = dbi->get(meName);
00404 
00405   if (!me_) { 
00406     LogDebug("FourVectorHLTClient")<< "ME NOT FOUND." << endl;
00407    return NULL;
00408   }
00409 
00410   return me_->getTProfile2D();
00411 }
00412 
00413 
00414 TProfile *  FourVectorHLTClient::get1DProfile(string meName, DQMStore * dbi)
00415 {
00416 
00417 
00418   MonitorElement * me_ = dbi->get(meName);
00419 
00420   if (!me_) { 
00421     LogDebug("FourVectorHLTClient")<< "ME NOT FOUND." << endl;
00422     return NULL;
00423   }
00424 
00425   return me_->getTProfile();
00426 }
00427 
00428 
00429 
00430 
00431 
00432 
00433 
00434 

Generated on Tue Jun 9 17:34:10 2009 for CMSSW by  doxygen 1.5.4