CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/HLTriggerOffline/SUSYBSM/src/TriggerValidator.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    TriggerValidator
00004 // Class:      TriggerValidator
00005 // 
00013 //
00014 // Original Author:  Massimiliano Chiorboli
00015 //                   Maurizio Pierini
00016 //                   Maria Spiropulu
00017 //         Created:  Wed Aug 29 15:10:56 CEST 2007
00018 //  Philip Hebda, July 2009
00019 // $Id: TriggerValidator.cc,v 1.24 2010/12/14 17:20:35 vlimant Exp $
00020 //
00021 //
00022 
00023 
00024 // system include files
00025 #include <memory>
00026 #include <stdio.h>
00027 #include <iomanip>
00028 
00029 #include "HLTriggerOffline/SUSYBSM/interface/TriggerValidator.h"
00030 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00031 
00032 
00033 // user include files
00034 #include "FWCore/Framework/interface/Frameworkfwd.h"
00035 #include "FWCore/Framework/interface/EDAnalyzer.h"
00036 #include "FWCore/Framework/interface/Event.h"
00037 #include "FWCore/Framework/interface/MakerMacros.h"
00038 #include "FWCore/Common/interface/TriggerNames.h"
00039 #include "DataFormats/Common/interface/Handle.h"
00040 
00041 
00042 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00043 
00044 //Added by Max for the Trigger
00045 #include "DataFormats/HLTReco/interface/TriggerEventWithRefs.h"
00046 #include "DataFormats/Common/interface/TriggerResults.h"
00047 //#include "DataFormats/L1Trigger/interface/L1ParticleMap.h"
00048 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00049 
00050 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00051 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMapRecord.h"
00052 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMap.h"
00053 
00054 
00055 //Added for the DQM
00056 #include "DQMServices/Core/interface/MonitorElement.h"
00057 #include "FWCore/Framework/interface/Run.h"
00058 
00059 #include "TFile.h"
00060 #include "TDirectory.h"
00061 #include "TH1.h"
00062 #include "TH2.h"
00063 #include "TList.h"
00064 #include "TObjString.h"
00065 #include "TString.h"
00066 #include "TObject.h"
00067 
00068 //
00069 // constants, enums and typedefs
00070 //
00071 
00072 //
00073 // static data member definitions
00074 //
00075 
00076 
00077 
00078 //
00079 // constructors and destructor
00080 //
00081 
00082 using namespace edm;
00083 using namespace std;
00084 
00085 TriggerValidator::TriggerValidator(const edm::ParameterSet& iConfig):
00086   dirname_(iConfig.getUntrackedParameter("dirname",
00087                                               std::string("HLT/SusyExo"))),
00088   HistoFileName(iConfig.getUntrackedParameter("histoFileName",
00089                                               std::string("SusyBsmTriggerValidation.root"))),
00090   StatFileName(iConfig.getUntrackedParameter("statFileName",
00091                                               std::string("SusyBsmTriggerValidation.stat"))),
00092   l1Label(iConfig.getParameter<edm::InputTag>("L1Label")),
00093   hltLabel(iConfig.getParameter<edm::InputTag>("HltLabel")),
00094   mcFlag(iConfig.getUntrackedParameter<bool>("mc_flag",false)),
00095   l1Flag(iConfig.getUntrackedParameter<bool>("l1_flag",false)),
00096   reco_parametersets(iConfig.getParameter<VParameterSet>("reco_parametersets")),
00097   mc_parametersets(iConfig.getParameter<VParameterSet>("mc_parametersets")),
00098   turnOn_params(iConfig.getParameter<ParameterSet>("TurnOnParams")),
00099   plotMakerL1Input(iConfig.getParameter<ParameterSet>("PlotMakerL1Input")),
00100   plotMakerRecoInput(iConfig.getParameter<ParameterSet>("PlotMakerRecoInput")),
00101   muonTag_(iConfig.getParameter<edm::InputTag>("muonTag")),
00102   triggerTag_(iConfig.getParameter<edm::InputTag>("triggerTag")),
00103   processName_(iConfig.getParameter<std::string>("hltConfigName")),
00104   triggerName_(iConfig.getParameter<std::string>("triggerName"))
00105 {
00106   //now do what ever initialization is needed
00107   theHistoFile = 0;
00108   nEvTot = 0;
00109   for(unsigned int i=0; i<reco_parametersets.size(); ++i) nEvRecoSelected.push_back(0);
00110   for(unsigned int i=0; i<mc_parametersets.size(); ++i) nEvMcSelected.push_back(0);
00111 
00112   nHltPaths = 0;
00113   nL1Bits = 0;
00114 
00115 
00116   // --- set the names in the dbe folders ---
00117   triggerBitsDir = "/TriggerBits";
00118   recoSelBitsDir = "/RecoSelection"; 
00119   mcSelBitsDir = "/McSelection";      
00120 
00121 
00122   LogDebug("TriggerValidator") << "constructor...." ;
00123 
00124   dbe_ = Service < DQMStore > ().operator->();
00125   if ( ! dbe_ ) {
00126     LogInfo("TriggerValidator") << "unabel to get DQMStore service?";
00127   }
00128   if (iConfig.getUntrackedParameter < bool > ("DQMStore", false)) {
00129     dbe_->setVerbose(0);
00130   }
00131 
00132   
00133 
00134   
00135   if (dbe_ != 0 ) {
00136     dbe_->setCurrentFolder(dirname_);
00137   }
00138 
00139 
00140    plotMakerL1Input.addParameter<std::string>("dirname",dirname_);
00141    plotMakerRecoInput.addParameter<std::string>("dirname",dirname_);
00142 
00143 }
00144 
00145 
00146 TriggerValidator::~TriggerValidator()
00147 {
00148  
00149   // do anything here that needs to be done at desctruction time
00150   // (e.g. close files, deallocate resources etc.)
00151 
00152 }
00153 
00154 
00155 //
00156 // member functions
00157 //
00158 
00159 // ------------ method called to for each event  ------------
00160 void
00161 TriggerValidator::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00162 {
00163 
00164   using namespace edm;
00165   
00166   nEvTot++;
00167   
00168   vector<bool> eventRecoSelected, eventMcSelected;
00169   eventRecoSelected.resize(reco_parametersets.size());
00170   eventMcSelected.resize(mc_parametersets.size());
00171   for(unsigned int i=0; i<eventRecoSelected.size(); ++i) eventRecoSelected[i] =  myRecoSelector[i]->isSelected(iEvent);
00172   for(unsigned int i=0; i<eventMcSelected.size(); ++i) eventMcSelected[i] = mcFlag ? myMcSelector[i]->isSelected(iEvent) : false;
00173 
00174   for(unsigned int i=0; i<nEvRecoSelected.size(); ++i) if(eventRecoSelected[i]) nEvRecoSelected[i]++;
00175   for(unsigned int i=0; i<nEvMcSelected.size(); ++i) if(eventMcSelected[i]) nEvMcSelected[i]++;
00176   
00177   
00178   // ******************************************************** 
00179   // Get the L1 Info
00180   // ********************************************************    
00181   Handle<L1GlobalTriggerReadoutRecord> L1GTRR;
00182   //  try {iEvent.getByType(L1GTRR);} catch (...) {;}
00183   iEvent.getByLabel("gtDigis",L1GTRR);
00184   if (!L1GTRR.isValid()) {edm::LogWarning("Readout Error|L1") << "L1ParticleMapCollection Not Valid!";}
00185   int nL1size = L1GTRR->decisionWord().size();
00186   if(firstEvent) {
00187 
00188     //this piece of code concerns efficiencies
00189     //it must be moved to the client
00190 
00191 //     //resize the eff and overlap vectors ccording to the number of L1 paths
00192 //     effL1BeforeCuts.resize(L1GTRR->decisionWord().size()+1);
00193 //     effL1AfterRecoCuts.resize(L1GTRR->decisionWord().size()+1);
00194 //     effL1AfterMcCuts.resize(L1GTRR->decisionWord().size()+1);
00195      vCorrL1.resize(L1GTRR->decisionWord().size());
00196     for(unsigned int i=0; i<L1GTRR->decisionWord().size(); i++) {vCorrL1[i].resize(L1GTRR->decisionWord().size());}
00197     vCorrNormL1.resize(L1GTRR->decisionWord().size());
00198     for(unsigned int i=0; i<L1GTRR->decisionWord().size(); i++) {vCorrNormL1[i].resize(L1GTRR->decisionWord().size());}
00199 
00200 
00201     //Get the names of the L1 paths
00202     //for the moment the names are not included in L1GlobalTriggerReadoutRecord
00203     //we need to use L1GlobalTriggerObjectMapRecord
00204     edm::Handle<L1GlobalTriggerObjectMapRecord> gtObjectMapRecord;
00205     //    iEvent.getByLabel("l1GtEmulDigis", gtObjectMapRecord);
00206     //    iEvent.getByLabel("hltL1GtObjectMap", gtObjectMapRecord);
00207     iEvent.getByLabel(l1Label, gtObjectMapRecord);
00208      const std::vector<L1GlobalTriggerObjectMap>& objMapVec =
00209       gtObjectMapRecord->gtObjectMap();
00210      for (std::vector<L1GlobalTriggerObjectMap>::const_iterator itMap = objMapVec.begin();
00211          itMap != objMapVec.end(); ++itMap) {
00212       int algoBit = (*itMap).algoBitNumber();
00213        std::string algoNameStr = (*itMap).algoName();
00214        l1NameMap[algoBit] = algoNameStr;
00215     }
00216     //resize the name vector and get the names
00217     l1Names_.resize(L1GTRR->decisionWord().size()+1);
00218     for (unsigned int i=0; i!=L1GTRR->decisionWord().size(); i++) {    
00219       l1Names_[i]=l1NameMap[i];
00220     }
00221     l1Names_[L1GTRR->decisionWord().size()] = "Total";
00222     
00223     //set the names of the bins for the "path" histos
00224     for(unsigned int i=0; i<l1Names_.size(); ++i) {
00225       hL1PathsBeforeCuts->setBinLabel(i+1,l1Names_[i].c_str(),1);
00226       for(unsigned int j=0; j<hL1PathsAfterRecoCuts.size(); ++j) hL1PathsAfterRecoCuts[j]->setBinLabel(i+1,l1Names_[i].c_str(),1);
00227       for(unsigned int j=0; j<hL1PathsAfterMcCuts.size(); ++j) hL1PathsAfterMcCuts[j]->setBinLabel(i+1,l1Names_[i].c_str(),1);
00228     }
00229   }
00230   
00231  //fill the eff vectors and histos for L1
00232   for (int i=0; i<nL1size; ++i) {
00233     l1bits.push_back(L1GTRR->decisionWord()[i]);
00234     if(L1GTRR->decisionWord()[i]) {
00235       numTotL1BitsBeforeCuts[i]++;
00236       hL1BitsBeforeCuts->Fill(i);
00237       hL1PathsBeforeCuts->Fill(i);
00238       for(unsigned int j=0; j<eventRecoSelected.size(); ++j)
00239         if(eventRecoSelected[j]) {
00240           numTotL1BitsAfterRecoCuts[j][i]++;
00241           hL1BitsAfterRecoCuts[j]->Fill(i);
00242           hL1PathsAfterRecoCuts[j]->Fill(i);
00243         }
00244       for(unsigned int j=0; j<eventMcSelected.size(); ++j)
00245         if(eventMcSelected[j]) {
00246           numTotL1BitsAfterMcCuts[j][i]++;
00247           hL1BitsAfterMcCuts[j]->Fill(i);
00248           hL1PathsAfterMcCuts[j]->Fill(i);
00249         }
00250     }      
00251   }
00252 
00253   //Calculate the overlap among l1 bits
00254   for(int i=0; i<nL1size; ++i) {
00255     for(int j=0; j<nL1size; ++j) {
00256       if(l1bits[i]*l1bits[j]) vCorrL1[i][j]++;
00257     }
00258   }
00259 
00260   //fill the last bin with the total of events
00261   numTotL1BitsBeforeCuts[nL1size]++;
00262   hL1BitsBeforeCuts->Fill(nL1size);
00263   hL1PathsBeforeCuts->Fill(nL1size);
00264   for(unsigned int i=0; i<eventRecoSelected.size(); ++i)
00265     if(eventRecoSelected[i]) {
00266       numTotL1BitsAfterRecoCuts[i][nL1size]++;
00267       hL1BitsAfterRecoCuts[i]->Fill(nL1size);
00268       hL1PathsAfterRecoCuts[i]->Fill(nL1size);
00269     }
00270   for(unsigned int i=0; i<eventMcSelected.size(); ++i)
00271     if(eventMcSelected[i]) {
00272       numTotL1BitsAfterMcCuts[i][nL1size]++;
00273       hL1BitsAfterMcCuts[i]->Fill(nL1size);
00274       hL1PathsAfterMcCuts[i]->Fill(nL1size);
00275     }
00276 
00277 
00278   // ******************************************************** 
00279   // Get the HLT Info
00280   // ******************************************************** 
00281   edm::Handle<TriggerResults> trhv;
00282   iEvent.getByLabel(hltLabel,trhv);
00283   if( ! trhv.isValid() ) {
00284     LogDebug("") << "HL TriggerResults with label ["+hltLabel.encode()+"] not found!";
00285     return;
00286   }  
00287 
00288 
00289 //   if(!trhv.isValid()) {
00290 //     std::cout << "invalid handle for HLT TriggerResults" << std::endl;
00291 //   } 
00292 
00293 
00294   if(firstEvent) {
00295 
00296 
00297  
00298     //
00299     // The following piece of code concerns efficiencies and so must be moved to the client
00300     //
00301 
00302 
00303 //     //resize the eff and overlap vectors ccording to the number of L1 paths
00304 //     effHltBeforeCuts.resize(trhv->size()+1);
00305 //     effHltAfterRecoCuts.resize(trhv->size()+1);
00306 //     effHltAfterMcCuts.resize(trhv->size()+1);
00307      vCorrHlt.resize(trhv->size());
00308     for(unsigned int i=0; i<trhv->size(); i++) {vCorrHlt[i].resize(trhv->size());}
00309     vCorrNormHlt.resize(trhv->size());
00310     for(unsigned int i=0; i<trhv->size(); i++) {vCorrNormHlt[i].resize(trhv->size());}
00311 
00312 
00313     //resize the name vector and get the names
00314     const edm::TriggerNames & triggerNames = iEvent.triggerNames(*trhv);
00315     hlNames_=triggerNames.triggerNames();
00316     hlNames_.push_back("Total");
00317 
00318     //set the bin names for the "path" histos
00319     for (unsigned int i=0; i<hlNames_.size(); ++i) {
00320       hHltPathsBeforeCuts->setBinLabel(i+1,hlNames_[i].c_str(),1);
00321       for(unsigned int j=0; j<hHltPathsAfterRecoCuts.size(); ++j) hHltPathsAfterRecoCuts[j]->setBinLabel(i+1,hlNames_[i].c_str(),1);
00322       for(unsigned int j=0; j<hHltPathsAfterMcCuts.size(); ++j) hHltPathsAfterMcCuts[j]->setBinLabel(i+1,hlNames_[i].c_str(),1);
00323     }
00324   }
00325 
00326   //fill the eff vectors and histos for HLT
00327   for(unsigned int i=0; i< trhv->size(); i++) {
00328     hltbits.push_back(trhv->at(i).accept());
00329     if(trhv->at(i).accept()) {
00330       numTotHltBitsBeforeCuts[i]++;
00331       hHltBitsBeforeCuts->Fill(i);
00332       hHltPathsBeforeCuts->Fill(i);
00333       for(unsigned int j=0; j<eventRecoSelected.size(); ++j)
00334         if(eventRecoSelected[j]) {
00335           numTotHltBitsAfterRecoCuts[j][i]++;
00336           hHltBitsAfterRecoCuts[j]->Fill(i);
00337           hHltPathsAfterRecoCuts[j]->Fill(i);
00338         }
00339       for(unsigned int j=0; j<eventMcSelected.size(); ++j)
00340         if(eventMcSelected[j]) {
00341           numTotHltBitsAfterMcCuts[j][i]++;
00342           hHltBitsAfterMcCuts[j]->Fill(i);
00343           hHltPathsAfterMcCuts[j]->Fill(i);
00344         }
00345     }      
00346   }
00347 
00348   //Calculate the overlap among HLT paths
00349  for(unsigned int i=0; i< trhv->size(); i++) {
00350    for(unsigned int j=0; j< trhv->size(); j++) {
00351 //      cout << "trhv->size() = " << trhv->size() << endl;
00352 //      cout << "hltbits["<< i << "] = " << hltbits[i] << endl;
00353 //      cout << "hltbits["<< j << "] = " << hltbits[j] << endl;
00354      if(hltbits[i]*hltbits[j]) vCorrHlt[i][j]++;
00355    }
00356  }
00357 
00358 
00359   //The overlap histos are filled in the endJob() method
00360 
00361   //fill the last bin with the total of events
00362   numTotHltBitsBeforeCuts[trhv->size()]++;
00363   hHltBitsBeforeCuts->Fill(trhv->size());
00364   hHltPathsBeforeCuts->Fill(trhv->size());
00365   for(unsigned int i=0; i<eventRecoSelected.size(); ++i)
00366     if(eventRecoSelected[i]) {
00367       numTotHltBitsAfterRecoCuts[i][trhv->size()]++;
00368       hHltBitsAfterRecoCuts[i]->Fill(trhv->size());
00369       hHltPathsAfterRecoCuts[i]->Fill(trhv->size());
00370     }
00371   for(unsigned int i=0; i<eventMcSelected.size(); ++i)
00372     if(eventMcSelected[i]) {
00373       numTotHltBitsAfterMcCuts[i][trhv->size()]++;
00374       hHltBitsAfterMcCuts[i]->Fill(trhv->size());
00375       hHltPathsAfterMcCuts[i]->Fill(trhv->size());
00376     }
00377 
00378 
00379 
00380   if(firstEvent) {
00381     if(l1Flag) myPlotMakerL1->bookHistos(dbe_,&l1bits,&hltbits,&l1Names_,&hlNames_);
00382     myPlotMakerReco->bookHistos(dbe_,&l1bits,&hltbits,&l1Names_,&hlNames_);
00383     //    myTurnOnMaker->bookHistos();
00384   }
00385   if(l1Flag) myPlotMakerL1->fillPlots(iEvent);
00386   myPlotMakerReco->fillPlots(iEvent);
00387   //  myTurnOnMaker->fillPlots(iEvent);
00388 
00389   firstEvent = false;
00390 
00391   myMuonAnalyzer->FillPlots(iEvent, iSetup);
00392   l1bits.clear();
00393   hltbits.clear();
00394 }
00395 
00396 
00397 void TriggerValidator::beginJob(){
00398 }
00399 
00400 
00401 
00402 // ------------ method called once each job just before starting event loop  ------------
00403 void TriggerValidator::beginRun(const edm::Run& run, const edm::EventSetup& c)
00404 {
00405 
00406 
00407   DQMStore *dbe_ = 0;
00408   dbe_ = Service<DQMStore>().operator->();
00409   
00410   if (dbe_) {
00411     dbe_->setCurrentFolder(dirname_);
00412     dbe_->rmdir(dirname_);
00413   }
00414   
00415   if (dbe_) {
00416     dbe_->setCurrentFolder(dirname_);
00417   }  
00418   
00419   
00420   bool changed(true);
00421   //  cout << "hltConfig_.init(run,c,processName_,changed) = " << (int) hltConfig_.init(run,c,processName_,changed) << endl;
00422   //  cout << "changed = " << (int) changed << endl;
00423   if (hltConfig_.init(run,c,processName_,changed)) {
00424     //    cout << "AAAA" << endl;
00425     if (changed) {
00426       //     cout << "BBBBBBB" << endl;
00427      // check if trigger name in (new) config
00428       if (triggerName_!="@") { // "@" means: analyze all triggers in config
00429         //      cout << "hltConfig_.size() = " << hltConfig_.size() << endl;
00430         nHltPaths = hltConfig_.size();
00431         const unsigned int triggerIndex(hltConfig_.triggerIndex(triggerName_));
00432         if (triggerIndex>=nHltPaths) {
00433 //        cout << "HLTriggerOffline/SUSYBSM"
00434 //             << " TriggerName " << triggerName_ 
00435 //             << " not available in (new) config!" << endl;
00436 //        cout << "Available TriggerNames are: " << endl;
00437           hltConfig_.dump("Triggers");
00438         }
00439       }
00440       else {
00441         //     cout << "CCCCCCCC" << endl;
00442         nHltPaths = hltConfig_.size();
00443       }
00444     }
00445   } else {
00446 //     cout << "HLTriggerOffline/SUSYBSM"
00447 //       << " config extraction failure with process name "
00448 //       << processName_ << endl;
00449   }
00450 
00451   //  cout << "nHltPaths = " << nHltPaths << endl;
00452   nL1Bits = 128; 
00453 
00454   
00455 
00456   for(unsigned int i=0; i<reco_parametersets.size(); ++i) myRecoSelector.push_back(new RecoSelector(reco_parametersets[i]));
00457   if(mcFlag) for(unsigned int i=0; i<mc_parametersets.size(); ++i) myMcSelector.push_back(new McSelector(mc_parametersets[i]));
00458   if(l1Flag) myPlotMakerL1     = new PlotMakerL1(plotMakerL1Input);
00459   myPlotMakerReco   = new PlotMakerReco(plotMakerRecoInput);
00460 //   myTurnOnMaker = new TurnOnMaker(turnOn_params);
00461   firstEvent = true;
00462 
00463   //resize the vectors ccording to the number of L1 paths
00464   numTotL1BitsBeforeCuts.resize(nL1Bits+1);
00465   numTotL1BitsAfterRecoCuts.resize(reco_parametersets.size());
00466   for(unsigned int i=0; i<numTotL1BitsAfterRecoCuts.size(); ++i) numTotL1BitsAfterRecoCuts[i].resize(nL1Bits+1);
00467   numTotL1BitsAfterMcCuts.resize(mc_parametersets.size());
00468   for(unsigned int i=0; i<numTotL1BitsAfterMcCuts.size(); ++i) numTotL1BitsAfterMcCuts[i].resize(nL1Bits+1);
00469 
00470   //resize the vectors ccording to the number of HLT paths
00471   numTotHltBitsBeforeCuts.resize(nHltPaths+1);
00472   numTotHltBitsAfterRecoCuts.resize(reco_parametersets.size());
00473   for(unsigned int i=0; i<numTotHltBitsAfterRecoCuts.size(); ++i) numTotHltBitsAfterRecoCuts[i].resize(nHltPaths+1);
00474   numTotHltBitsAfterMcCuts.resize(mc_parametersets.size());
00475   for(unsigned int i=0; i<numTotHltBitsAfterMcCuts.size(); ++i) numTotHltBitsAfterMcCuts[i].resize(nHltPaths+1);
00476   
00477   if (dbe_) {
00478     dbe_->setCurrentFolder(dirname_);
00479     dbe_->rmdir(dirname_);
00480   }
00481   
00482   
00483   if (dbe_) {
00484     dbe_->setCurrentFolder(dirname_);
00485     }
00486   
00487   dbe_->setCurrentFolder(dirname_+triggerBitsDir);
00488   //add 1 bin for the Total
00489   hL1BitsBeforeCuts  = dbe_->book1D("L1Bits", "L1 Trigger Bits",nL1Bits+1, 0, nL1Bits+1);    
00490   hHltBitsBeforeCuts = dbe_->book1D("HltBits","HL Trigger Bits",nHltPaths+1, 0, nHltPaths+1);
00491 //   hL1OverlapNormToTotal        = dbe_->book2D("L1OverlapNormToTotal"       ,"Overlap among L1 paths, norm to the Total number of Events", 1, 0, 1, 1, 0, 1);
00492 //   hHltOverlapNormToTotal       = dbe_->book2D("HltOverlapNormToTotal"      ,"Overlap among Hlt paths, norm to the Total number of Events ", 1, 0, 1, 1, 0, 1);
00493 //   hL1OverlapNormToLargestPath  = dbe_->book2D("L1OverlapNormToLargestPath" ,"Overlap among L1 paths, norm to the Largest of the couple ", 1, 0, 1, 1, 0, 1);
00494 //   hHltOverlapNormToLargestPath = dbe_->book2D("HltOverlapNormToLargestPath","Overlap among Hlt paths, norm to the Largest of the couple ", 1, 0, 1, 1, 0, 1);
00495 
00496   for(unsigned int i=0; i<myRecoSelector.size(); ++i)
00497     {
00498       string path_name = myRecoSelector[i]->GetName();
00499       char histo_name[256], histo_title[256];
00500       //sprintf(histo_name, "L1Bits");
00501       sprintf(histo_name, "L1Bits_%s", path_name.c_str());
00502       sprintf(histo_title, "L1 Trigger Bits for %s Selection", path_name.c_str());
00503       dbe_->setCurrentFolder(dirname_+recoSelBitsDir+"/"+path_name);   
00504       hL1BitsAfterRecoCuts.push_back(dbe_->book1D(histo_name, histo_title, nL1Bits+1, 0, nL1Bits+1));   
00505       //sprintf(histo_name, "HltBits");
00506       sprintf(histo_name, "HltBits_%s", path_name.c_str());
00507       sprintf(histo_title, "HL Trigger Bits for %s Selection", path_name.c_str()); 
00508       hHltBitsAfterRecoCuts.push_back(dbe_->book1D(histo_name, histo_title, nHltPaths+1, 0, nHltPaths+1));
00509     }
00510   for(unsigned int i=0; i<myMcSelector.size(); ++i)
00511     {
00512       string path_name = myMcSelector[i]->GetName();
00513       char histo_name[256], histo_title[256];
00514       //sprintf(histo_name, "L1Bits");
00515       sprintf(histo_name, "L1Bits_%s", path_name.c_str());
00516       sprintf(histo_title, "L1 Trigger Bits for %s Selection", path_name.c_str());
00517       dbe_->setCurrentFolder(dirname_+mcSelBitsDir+"/"+path_name);   
00518       hL1BitsAfterMcCuts.push_back(dbe_->book1D(histo_name, histo_title, nL1Bits+1, 0, nL1Bits+1));
00519       //sprintf(histo_name, "HltBits");
00520       sprintf(histo_name, "HltBits_%s", path_name.c_str());
00521       sprintf(histo_title, "HL Trigger Bits for %s Selection", path_name.c_str()); 
00522       hHltBitsAfterMcCuts.push_back(dbe_->book1D(histo_name, histo_title, nHltPaths+1, 0, nHltPaths+1));
00523     }
00524 
00525   //create the histos with paths
00526   //identical to the ones with "bits"
00527   //but with the names in the x axis
00528   //instead of the numbers
00529 
00530   dbe_->setCurrentFolder(dirname_+triggerBitsDir);
00531   TH1F* hTemp = (TH1F*) (hL1BitsBeforeCuts->getTH1F())->Clone("L1Paths");
00532   hL1PathsBeforeCuts  = dbe_->book1D("L1Paths", hTemp);
00533   //  hL1PathsBeforeCuts  = dbe_->book1D("L1Paths", hL1BitsBeforeCuts->getTH1F());
00534   hTemp = (TH1F*) (hHltBitsBeforeCuts->getTH1F())->Clone("HltPaths");
00535   hHltPathsBeforeCuts = dbe_->book1D("HltPaths", hTemp);
00536 
00537   for(unsigned int i=0; i<myRecoSelector.size(); ++i)
00538     {
00539       string path_name = myRecoSelector[i]->GetName();
00540       char histo_name[256];
00541       //sprintf(histo_name, "L1Paths");
00542       sprintf(histo_name, "L1Paths_%s", path_name.c_str());
00543       dbe_->setCurrentFolder(dirname_+recoSelBitsDir+"/"+path_name);
00544       hTemp = (TH1F*) (hL1BitsAfterRecoCuts[i]->getTH1F())->Clone(histo_name);
00545       hL1PathsAfterRecoCuts.push_back(dbe_->book1D(histo_name, hTemp));
00546       //sprintf(histo_name, "HltPaths");
00547       sprintf(histo_name, "HltPaths_%s", path_name.c_str());
00548       hTemp = (TH1F*) (hHltBitsAfterRecoCuts[i]->getTH1F())->Clone(histo_name);
00549       hHltPathsAfterRecoCuts.push_back(dbe_->book1D(histo_name, hTemp));
00550     }
00551 
00552   for(unsigned int i=0; i<myMcSelector.size(); ++i)
00553     {
00554       string path_name = myMcSelector[i]->GetName();
00555       char histo_name[256];
00556       //sprintf(histo_name, "L1Paths");
00557       sprintf(histo_name, "L1Paths_%s", path_name.c_str());
00558       dbe_->setCurrentFolder(dirname_+mcSelBitsDir+"/"+path_name);
00559       hTemp = (TH1F*) (hL1BitsAfterMcCuts[i]->getTH1F())->Clone(histo_name);
00560       hL1PathsAfterMcCuts.push_back(dbe_->book1D(histo_name, hTemp));
00561       //sprintf(histo_name, "HltPaths");
00562       sprintf(histo_name, "HltPaths_%s", path_name.c_str());
00563       hTemp = (TH1F*) (hHltBitsAfterMcCuts[i]->getTH1F())->Clone(histo_name);
00564       hHltPathsAfterMcCuts.push_back(dbe_->book1D(histo_name, hTemp));
00565     }
00566 
00567   myMuonAnalyzer = new MuonAnalyzerSBSM(triggerTag_, muonTag_);
00568   myMuonAnalyzer->InitializePlots(dbe_, dirname_);
00569 }
00570 
00571 
00572 
00573 
00574 // ------------ method called once each job just after ending the event loop  ------------
00575 void 
00576 TriggerValidator::endRun(const edm::Run& run, const edm::EventSetup& c)
00577 {
00578 
00579   //  myTurnOnMaker->finalOperations();
00580 
00581   //This piece of code concerns efficiencies
00582   //it must be moved to the client
00583   
00584 
00585 
00586 //   //calculate the final efficiencies and the normalizations
00587 //   for(unsigned int i=0; i<numTotL1BitsBeforeCuts.size()-1; i++) {
00588 //     effL1BeforeCuts[i] = (double)numTotL1BitsBeforeCuts[i]/(double)nEvTot;
00589 //     for(unsigned int j=0; j<numTotL1BitsBeforeCuts.size()-1; j++) {
00590 //       vCorrNormL1[i][j] = (double)vCorrL1[i][j]/(double)nEvTot;
00591 //     }
00592 //   }
00593 
00594 //   for(unsigned int i=0; i<numTotHltBitsBeforeCuts.size()-1; i++) {
00595 //     effHltBeforeCuts[i] = (double)numTotHltBitsBeforeCuts[i]/(double)nEvTot;
00596 //     for(unsigned int j=0; j<numTotHltBitsBeforeCuts.size()-1; j++) {
00597 //       vCorrNormHlt[i][j] = (double)vCorrHlt[i][j]/(double)nEvTot;
00598 //     }
00599 //   }
00600 
00601 //   //after the reco cuts
00602 
00603 //   if(nEvRecoSelected) {
00604 //     for(unsigned int i=0; i<numTotL1BitsAfterRecoCuts.size()-1; i++) {
00605 //       effL1AfterRecoCuts[i] = (double)numTotL1BitsAfterRecoCuts[i]/(double)nEvRecoSelected;
00606 //     }
00607     
00608 //     for(unsigned int i=0; i<numTotHltBitsAfterRecoCuts.size()-1; i++) {
00609 //       effHltAfterRecoCuts[i] = (double)numTotHltBitsAfterRecoCuts[i]/(double)nEvRecoSelected;
00610 //     }
00611 //   } else {
00612     
00613 //     for(unsigned int i=0; i<numTotL1BitsAfterRecoCuts.size()-1; i++) {
00614 //       effL1AfterRecoCuts[i] = -1;
00615 //     }
00616     
00617 //     for(unsigned int i=0; i<numTotHltBitsAfterRecoCuts.size()-1; i++) {
00618 //       effHltAfterRecoCuts[i] = -1;
00619 //     }
00620 //   }
00621 
00622 
00623 //   //after the mc cuts
00624 //   if(nEvMcSelected) {
00625 //     for(unsigned int i=0; i<numTotL1BitsAfterMcCuts.size()-1; i++) {
00626 //       effL1AfterMcCuts[i] = (double)numTotL1BitsAfterMcCuts[i]/(double)nEvMcSelected;
00627 //     }
00628     
00629 //     for(unsigned int i=0; i<numTotHltBitsAfterMcCuts.size()-1; i++) {
00630 //       effHltAfterMcCuts[i] = (double)numTotHltBitsAfterMcCuts[i]/(double)nEvMcSelected;
00631 //     }
00632 //   } else {
00633 //     for(unsigned int i=0; i<numTotL1BitsAfterMcCuts.size()-1; i++) {
00634 //       effL1AfterMcCuts[i] = -1;
00635 //     }
00636     
00637 //     for(unsigned int i=0; i<numTotHltBitsAfterMcCuts.size()-1; i++) {
00638 //       effHltAfterMcCuts[i] = -1;
00639 //     }
00640 //   }    
00641 
00642 
00643 
00644 
00645 
00646 
00647 
00648 
00649 //   myPlotMaker->writeHistos();
00650 //   myTurnOnMaker->writeHistos();
00651 
00652 
00653   //  using namespace std;
00654 
00655   unsigned int n(l1Names_.size());
00656 
00657   n = l1Names_.size();
00658   edm::LogInfo("L1TableSummary") << endl;
00659   edm::LogVerbatim("L1TableSummary") << "L1T-Table "
00660        << right << setw(10) << "L1T  Bit#" << " "
00661        << "Name" << "\n";
00662   for (unsigned int i=0; i!=n; i++) {
00663     edm::LogVerbatim("L1TableSummary") << right << setw(20) << i << " "
00664          << l1Names_[i] << "\n";
00665   }
00666   
00667   
00668   n = hlNames_.size();
00669   edm::LogInfo("HltTableSummary") << endl;
00670   edm::LogVerbatim("HltTableSummary") << "HLT-Table "
00671        << right << setw(10) << "HLT  Bit#" << " "
00672        << "Name" << "\n";
00673   
00674   for (unsigned int i=0; i!=n; i++) {
00675      edm::LogVerbatim("HltTableSummary") << right << setw(20) << i << " "
00676          << hlNames_[i] << "\n";
00677   }
00678   
00679   edm::LogVerbatim("HltTableSummary") << endl;
00680   edm::LogVerbatim("HltTableSummary") << "HLT-Table end!" << endl;
00681   edm::LogVerbatim("HltTableSummary") << endl;
00682   
00683 
00684  
00685   //the stat file with the efficiecies has to be moved to the client
00686 
00687 
00688 
00689 //  //Print in a stat file the efficiencies and the overlaps
00690  
00691  
00692 //   ofstream statFile(StatFileName.c_str(),ios::out);
00693 
00694 
00695 //   statFile << "*********************************************************************************" << endl;
00696 //   statFile << "*********************************************************************************" << endl;
00697 //   statFile << "                                   L1 Efficiencies                               " << endl;
00698 //   statFile << "*********************************************************************************" << endl;
00699 //   statFile << "*********************************************************************************" << endl;
00700 //   statFile << endl;
00701 //   statFile << "---------------------------------------------------------------------------------" << endl;
00702 //   statFile << "---------------------------------------------------------------------------------" << endl;
00703 //   statFile << "|           L1 Path             |   eff (Tot)    | eff (Reco Sel)|  eff (Mc Sel) |" << endl;
00704 //   statFile << "---------------------------------------------------------------------------------" << endl;
00705 //   statFile << "---------------------------------------------------------------------------------" << endl;
00706 //   for(unsigned int i=0; i<numTotL1BitsBeforeCuts.size()-1; i++) {
00707 //     statFile << "|  " << left << setw(29) << l1Names_[i] << "|" << setprecision(3) << showpoint << right << setw(13) << effL1BeforeCuts[i]    << "  |" <<
00708 //                                                                                                             setw(13) << effL1AfterRecoCuts[i] << "  |" <<
00709 //                                                                                                             setw(13) << effL1AfterMcCuts[i]   << "  |" << endl;
00710 //   }
00711 //   statFile << "---------------------------------------------------------------------------------" << endl;
00712 //   statFile << "---------------------------------------------------------------------------------" << endl;
00713 //   statFile << endl;
00714 //   statFile << endl;
00715 //   statFile << endl;
00716 //   statFile << endl;
00717 //   statFile << endl;
00718 //   statFile << endl;
00719 
00720 
00721 
00722 //   statFile << "**********************************************************************************" << endl;
00723 //   statFile << "**********************************************************************************" << endl;
00724 //   statFile << "                                  Hlt Efficiencies                                " << endl;
00725 //   statFile << "**********************************************************************************" << endl;
00726 //   statFile << "**********************************************************************************" << endl;
00727 //   statFile << endl;
00728 //   statFile << "----------------------------------------------------------------------------------" << endl;
00729 //   statFile << "----------------------------------------------------------------------------------" << endl;
00730 //   statFile << "|           Hlt Path             |   eff (Tot)    | eff (Reco Sel)|  eff (Mc Sel) |" << endl;
00731 //   statFile << "----------------------------------------------------------------------------------" << endl;
00732 //   statFile << "----------------------------------------------------------------------------------" << endl;
00733 //   for(unsigned int i=0; i<numTotHltBitsBeforeCuts.size()-1; i++) {
00734 //     statFile << "|  " << left << setw(29) << hlNames_[i] << "|" << setprecision(3) << showpoint << right << setw(13) << effHltBeforeCuts[i]    << "  |" << 
00735 //                                                                                                             setw(13) << effHltAfterRecoCuts[i] << "  |" << 
00736 //                                                                                                             setw(13) << effHltAfterMcCuts[i]   << "  |" <<endl;
00737 //   }
00738 //   statFile << "----------------------------------------------------------------------------------" << endl;
00739 //   statFile << "----------------------------------------------------------------------------------" << endl;
00740 //   statFile << endl;
00741 //   statFile << endl;
00742 //   statFile << endl;
00743 //   statFile << endl;
00744 //   statFile << endl;
00745 //   statFile << endl;
00746 
00747 
00748 
00749 
00750 
00751 //   statFile << "****************************************************************************************************************************************************" << endl; 
00752 //   statFile << "****************************************************************************************************************************************************" << endl; 
00753 //   statFile << "                                                      L1 Correlations   (only overlaps >5% are shown, and only without any selection)                                               " << endl;
00754 //   statFile << "****************************************************************************************************************************************************" << endl; 
00755 //   statFile << "****************************************************************************************************************************************************" << endl;
00756 //   statFile << endl;
00757 //   statFile << "----------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
00758 //   statFile << "----------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
00759 //   statFile << "|           L1 Path 1           |           L1 Path 2           |  Overlap Norm to Total  |  Overlap Norm to Path  |         Path of Norm          |" << endl;
00760 //   statFile << "----------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
00761 //   statFile << "----------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
00762 //   statFile << endl;
00763 //   for(unsigned int i=0; i<numTotL1BitsBeforeCuts.size()-1; i++) {
00764 //     for(unsigned int j=0; j<numTotL1BitsBeforeCuts.size()-1; j++) {
00765 //       if(vCorrNormL1[i][j]>0.05) {
00766 //      int iNorm = 0;
00767 //      if(effL1BeforeCuts[i] > effL1BeforeCuts[j]) {iNorm  = i;}
00768 //      else {iNorm = j;}
00769 //      double effNorm  =  vCorrNormL1[i][j] / effL1BeforeCuts[iNorm];
00770 //      statFile << "|  " << left << setw(29) << l1Names_[i] << "|  " << setw(29) <<  left << l1Names_[j] << "|"
00771 //               << setprecision(3) << showpoint << right  << setw(22) << vCorrNormL1[i][j] << "   |"
00772 //               << setprecision(3) << showpoint << right  << setw(21) << effNorm           << "   |  "
00773 //               << left << setw(29) << l1Names_[iNorm] << "|" << endl;
00774 //       }
00775 //     }
00776 //   statFile << "----------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
00777 //   }
00778 //   statFile << "----------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
00779 //   statFile << "----------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
00780 //   statFile << endl;
00781 //   statFile << endl;
00782 //   statFile << endl;
00783 //   statFile << endl;
00784 //   statFile << endl;
00785 //   statFile << endl;
00786 
00787 
00788 //   statFile << "****************************************************************************************************************************************************" << endl; 
00789 //   statFile << "****************************************************************************************************************************************************" << endl; 
00790 //   statFile << "                                                     Hlt Correlations   (only overlaps >5% are shown, and only without any selection)                                               " << endl;
00791 //   statFile << "****************************************************************************************************************************************************" << endl; 
00792 //   statFile << "****************************************************************************************************************************************************" << endl;
00793 //   statFile << endl;
00794 //   statFile << "----------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
00795 //   statFile << "----------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
00796 //   statFile << "|           Hlt Path 1          |           Hlt Path 2          |  Overlap Norm to Total  |  Overlap Norm to Path  |         Path of Norm          |" << endl;
00797 //   statFile << "----------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
00798 //   statFile << "----------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
00799 //   statFile << endl;
00800 //   for(unsigned int i=0; i<numTotHltBitsBeforeCuts.size()-1; i++) {
00801 //     for(unsigned int j=0; j<numTotHltBitsBeforeCuts.size()-1; j++) {
00802 //       if(vCorrNormHlt[i][j]>0.05) {
00803 //      int iNorm = 0;
00804 //      if(effHltBeforeCuts[i] > effHltBeforeCuts[j]) {iNorm  = i;}
00805 //      else {iNorm = j;}
00806 //      double effNorm  = vCorrNormHlt[i][j]/effHltBeforeCuts[iNorm];
00807 //      statFile << "|  " << left << setw(29) << hlNames_[i] << "|  " << setw(29) <<  left << hlNames_[j] << "|"
00808 //               << setprecision(3) << showpoint << right  << setw(22) << vCorrNormHlt[i][j] << "   |"
00809 //               << setprecision(3) << showpoint << right  << setw(21) << effNorm            << "   |  "
00810 //               << left << setw(29) << hlNames_[iNorm] << "|" << endl;
00811 //       }
00812 //     }
00813 //   statFile << "----------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
00814 //   }
00815 //   statFile << "----------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
00816 //   statFile << "----------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
00817 //   statFile << endl;
00818 //   statFile << endl;
00819 //   statFile << endl;
00820 //   statFile << endl;
00821 //   statFile << endl;
00822 //   statFile << endl;
00823 
00824 
00825 
00826 
00827 //   statFile.close();
00828 
00829 
00830   for(unsigned int i=0; i<myRecoSelector.size(); ++i) delete myRecoSelector[i];
00831   myRecoSelector.clear();
00832   if(mcFlag) 
00833     {
00834       for(unsigned int i=0; i<myMcSelector.size(); ++i) delete myMcSelector[i];
00835       myMcSelector.clear();
00836     }
00837      
00838   if(l1Flag) delete myPlotMakerL1;
00839   delete myPlotMakerReco;
00840 //   delete myTurnOnMaker;
00841   return;
00842 }
00843 
00844 
00845 // - method called once each job just after ending the event loop  ------------
00846 void 
00847 TriggerValidator::endJob() 
00848 {
00849   LogInfo("TriggerValidator") << "endJob";
00850    return;
00851 }
00852 
00853 
00854 
00855 
00856 
00857 
00858 //define this as a plug-in
00859 DEFINE_FWK_MODULE(TriggerValidator);