CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/HLTrigger/HLTanalyzers/src/HLTOfflineReproducibility.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    HLTOfflineReproducibility
00004 // Class:      HLTOfflineReproducibility
00005 // 
00013 //
00014 // Original Author:  Juliette Marie Alimena,40 3-A02,+41227671577,
00015 //         Created:  Fri Apr 22 15:46:58 CEST 2011
00016 // $Id: HLTOfflineReproducibility.cc,v 1.10 2012/01/18 08:56:39 jalimena Exp $
00017 //
00018 //
00019 
00020 using namespace std;
00021 
00022 // system include files
00023 #include <memory>
00024 
00025 // user include files
00026 #include "FWCore/Framework/interface/Frameworkfwd.h"
00027 #include "FWCore/Framework/interface/EDAnalyzer.h"
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 #include "FWCore/Framework/interface/TriggerNamesService.h"
00031 #include "FWCore/Common/interface/TriggerNames.h"
00032 #include "FWCore/Common/interface/TriggerResultsByName.h"
00033 #include "FWCore/Utilities/interface/InputTag.h"
00034 #include "FWCore/ServiceRegistry/interface/Service.h"
00035 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00036 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00037 
00038 #include "DataFormats/Common/interface/TriggerResults.h"
00039 #include "DataFormats/Common/interface/HLTGlobalStatus.h"
00040 #include "DataFormats/HLTReco/interface/HLTPrescaleTable.h"
00041 #include "DataFormats/HLTReco/interface/TriggerObject.h"
00042 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
00043 
00044 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00045 
00046 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00047 #include "HLTrigger/HLTcore/interface/HLTConfigData.h"
00048 
00049 #include "DQMServices/Core/interface/DQMStore.h"
00050 #include "DQMServices/Core/interface/MonitorElement.h"
00051 
00052 #include <TMath.h>
00053 #include <TFile.h>
00054 #include <TTree.h>
00055 #include <TH1.h>
00056 #include <TH2.h>
00057 #include <vector>
00058 #include <iostream>
00059 #include <ostream>
00060 //
00061 // class declaration
00062 //
00063 
00064 class HLTOfflineReproducibility : public edm::EDAnalyzer {
00065 public:
00066   explicit HLTOfflineReproducibility(const edm::ParameterSet&);
00067   ~HLTOfflineReproducibility();
00068   
00069   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
00070   
00071   
00072 private:
00073   virtual void beginJob() ;
00074   virtual void analyze(const edm::Event&, const edm::EventSetup&);
00075   virtual void endJob() ;
00076   
00077   virtual void beginRun(edm::Run const&, edm::EventSetup const&);
00078   virtual void endRun(edm::Run const&, edm::EventSetup const&);
00079   virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
00080   virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
00081   
00082   bool check(std::string process, std::string pCheck);
00083 
00084   // ----------member data ---------------------------  
00085   bool dqm_;
00086   DQMStore* dqms_;
00087 
00088   edm::InputTag triggerLabelORIG_;
00089   edm::InputTag triggerLabelNEW_;
00090   
00091   //Trigger Stuff
00092   unsigned int nPaths_, nPathsORIG_, nPathsNEW_, nDatasets_;
00093   vector<string> triggerNames_;
00094   vector< vector<string> > moduleLabel_, moduleLabelORIG_, moduleLabelNEW_;
00095   vector<unsigned int> nModules_, nPaths_PD_;
00096   vector<string> datasetNames_;
00097   vector<vector<string> > datasetContent_;
00098   vector< vector< vector<bool> > > triggerNames_matched_;
00099 
00100   string processNameORIG_;
00101   string processNameNEW_;
00102   HLTConfigProvider hltConfig_;
00103 
00104   int Nfiles_;
00105   double Normalization_;
00106   bool isRealData_;
00107   int LumiSecNumber_; 
00108   vector<int> trigger_ORIG_;
00109   vector<int> trigger_NEW_;
00110 
00111   TH1F* path_ORIG_hist;
00112   TH1F* path_ORIGnotNEW_hist;
00113   TH1F* path_NEWnotORIG_hist;
00114   TH2F* pathmodule_ORIGnotNEW_hist;
00115   TH2F* pathmodule_NEWnotORIG_hist;
00116   
00117   vector<TH1F*> path_ORIG_hist_PD;
00118   vector<TH1F*> path_ORIGnotNEW_hist_PD;
00119   vector<TH1F*> path_NEWnotORIG_hist_PD;
00120   vector<TH2F*> pathmodule_ORIGnotNEW_hist_PD;
00121   vector<TH2F*> pathmodule_NEWnotORIG_hist_PD;
00122 
00123 };
00124 
00125 //
00126 // constants, enums and typedefs
00127 //
00128 
00129 //
00130 // static data member definitions
00131 //
00132 
00133 //
00134 // constructors and destructor
00135 //
00136 HLTOfflineReproducibility::HLTOfflineReproducibility(const edm::ParameterSet& iConfig):  
00137   dqm_                      (iConfig.getUntrackedParameter<bool>("dqm")),
00138   triggerLabelORIG_         (iConfig.getUntrackedParameter<edm::InputTag>("triggerTagORIG")),
00139   triggerLabelNEW_          (iConfig.getUntrackedParameter<edm::InputTag>("triggerTagNEW")), 
00140   nPaths_                   (0),
00141   nDatasets_                (0),
00142   triggerNames_             (),
00143   moduleLabel_              (),
00144   nModules_                 (), 
00145   nPaths_PD_                (),
00146   datasetNames_             (),
00147   datasetContent_           (),
00148   triggerNames_matched_     (),
00149   processNameORIG_          (iConfig.getParameter<std::string>("processNameORIG")),
00150   processNameNEW_           (iConfig.getParameter<std::string>("processNameNEW")),
00151   Nfiles_                   (iConfig.getUntrackedParameter<int>("Nfiles",0)),
00152   Normalization_            (iConfig.getUntrackedParameter<double>("Norm",40.)),
00153   isRealData_               (iConfig.getUntrackedParameter<bool>("isRealData",true)),
00154   LumiSecNumber_            (iConfig.getUntrackedParameter<int>("LumiSecNumber",1)),
00155   path_ORIG_hist            (0),
00156   path_ORIGnotNEW_hist      (0),
00157   path_NEWnotORIG_hist      (0),
00158   pathmodule_ORIGnotNEW_hist(0),
00159   pathmodule_NEWnotORIG_hist(0),
00160   path_ORIG_hist_PD         (),
00161   path_ORIGnotNEW_hist_PD   (),
00162   path_NEWnotORIG_hist_PD   (),
00163   pathmodule_ORIGnotNEW_hist_PD(),
00164   pathmodule_NEWnotORIG_hist_PD()
00165 {
00166   //now do what ever initialization is needed
00167   //define parameters
00168   if (dqm_) dqms_ = edm::Service<DQMStore>().operator->();
00169 }
00170 
00171 
00172 HLTOfflineReproducibility::~HLTOfflineReproducibility()
00173 {
00174  
00175    // do anything here that needs to be done at desctruction time
00176    // (e.g. close files, deallocate resources etc.)
00177 
00178 }
00179 
00180 
00181 //
00182 // member functions
00183 //
00184 
00185 // ------------ method called for each event  ------------
00186 void
00187 HLTOfflineReproducibility::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00188 {
00189   // if DQM was requested, check that the DQMService is available
00190   if (dqm_ and not dqms_) return;
00191 
00192   using namespace edm;
00193   
00194   //Initialize Trigger
00195   TriggerResults trORIG_;
00196   Handle<TriggerResults> h_trigResORIG_;
00197   iEvent.getByLabel(triggerLabelORIG_, h_trigResORIG_);
00198   trORIG_ = *h_trigResORIG_;  
00199   
00200   TriggerResults trNEW_;
00201   Handle<TriggerResults> h_trigResNEW_;
00202   iEvent.getByLabel(triggerLabelNEW_, h_trigResNEW_);  
00203   trNEW_ = *h_trigResNEW_;
00204 
00205   vector<string> triggerListORIG_;
00206   Service<service::TriggerNamesService> tnsORIG_;
00207   bool foundNamesORIG_ = tnsORIG_->getTrigPaths(trORIG_,triggerListORIG_);
00208   if (!foundNamesORIG_) LogError("DataNotFound")<<"Could not get ORIG trigger names!";
00209   if (trORIG_.size()!=triggerListORIG_.size()) LogError("DataNotFound")<<"Length of names and paths not the same: " << triggerListORIG_.size() << "," << trORIG_.size() << endl;  
00210   
00211   vector<string> triggerListNEW_;
00212   Service<service::TriggerNamesService> tnsNEW_;
00213   bool foundNamesNEW_ = tnsNEW_->getTrigPaths(trNEW_,triggerListNEW_);
00214   if (!foundNamesNEW_) LogError("DataNotFound")<<"Could not get trigger names!";
00215   if (trNEW_.size()!=triggerListNEW_.size()) LogError("DataNotFound")<<"Length of names and paths not the same: " << triggerListNEW_.size() << "," << trNEW_.size() << endl;  
00216   
00217 
00218   vector<bool> ORIG_accept_, NEW_accept_, fails_prescaler_; 
00219   vector<int> module_indexORIG_, module_indexNEW_;
00220   vector<string> module_index_labelORIG_, module_index_labelNEW_;
00221   
00222   for (unsigned int x=0; x<nPaths_; x++) {
00223     ORIG_accept_.push_back(false);
00224     NEW_accept_.push_back(false);
00225     module_indexORIG_.push_back(-1);
00226     module_indexNEW_.push_back(-1);
00227     module_index_labelORIG_.push_back(" ");
00228     module_index_labelNEW_.push_back(" ");
00229     fails_prescaler_.push_back(false);
00230   }
00231 
00232   //loop over ORIG trigger paths
00233   for (unsigned int i=0; i<nPathsORIG_; i++) {
00234     for (unsigned int x=0; x<nPaths_; x++) {
00235       //match to list of paths that are in common to both ORIG and NEW
00236       if (triggerListORIG_.at(i)==triggerNames_.at(x)) {
00237         LogDebug("event")<<"triggerListORIG and triggerNames matched for 'global' path "<<x<<", "<<triggerNames_.at(x);
00238 
00239         //if ORIG accepted
00240         if (trORIG_.at(i).wasrun()==1 && trORIG_.at(i).accept()==1 && trORIG_.at(i).error()==0) {
00241           LogDebug("event")<<"ORIG accepted";
00242           ORIG_accept_.at(x) = true;
00243           trigger_ORIG_.at(x)++;
00244           path_ORIG_hist->Fill(x);
00245           for (unsigned int a=0; a<nDatasets_; a++) {
00246             for (unsigned int b=0; b<nPaths_PD_.at(a); b++) {
00247               if (triggerNames_matched_.at(x).at(a).at(b)){
00248                 path_ORIG_hist_PD.at(a)->Fill(b);
00249               }
00250             }
00251           }
00252         }
00253         
00254         //if ORIG failed
00255         if (trORIG_.at(i).accept() == 0){
00256           LogDebug("event")<<"ORIG failed";
00257           module_index_labelORIG_.at(x) = moduleLabelORIG_.at(i)[trORIG_.at(i).index()];
00258           module_indexORIG_.at(x) = hltConfig_.moduleIndex(triggerNames_.at(x),module_index_labelORIG_.at(x));
00259         }
00260         
00261         //for each path, loop over modules and find if a path fails on a prescaler
00262         for (unsigned int j=0; j<nModules_.at(x); ++j) {
00263           //const string& moduleLabel_(moduleLabel.at(j));
00264           const string& moduleType = hltConfig_.moduleType(moduleLabel_.at(x).at(j));
00265           if ( (trORIG_.at(i).accept()==0 && j==trORIG_.at(i).index()) && (moduleType=="HLTPrescaler" || moduleType=="TriggerResultsFilter") ) fails_prescaler_.at(x) = true;
00266         }
00267 
00268       }
00269     }
00270   }
00271 
00272   //loop over NEW trigger paths
00273   for (unsigned int i=0; i<nPathsNEW_; i++) {
00274     for (unsigned int x=0; x<nPaths_; x++) {
00275       if (triggerListNEW_.at(i)==triggerNames_.at(x)) {
00276 
00277         //if NEW accepted
00278         if (trNEW_.at(i).wasrun()==1 && trNEW_.at(i).accept()==1 && trNEW_.at(i).error()==0) {
00279           NEW_accept_.at(x) = true;
00280           trigger_NEW_.at(x)++;
00281         }
00282 
00283         //if NEW failed
00284         if (trNEW_.at(i).accept() == 0) {
00285           module_index_labelNEW_.at(x) = moduleLabelNEW_.at(i)[trNEW_.at(i).index()];
00286           module_indexNEW_.at(x) = hltConfig_.moduleIndex(triggerNames_.at(x),module_index_labelNEW_.at(x));
00287         }
00288         
00289         //for each path, loop over modules and find if a path fails on a prescaler
00290         for (unsigned int j=0; j<nModules_.at(x); ++j) {
00291           //const string& moduleLabel_(moduleLabel.at(j));
00292           const string& moduleType = hltConfig_.moduleType(moduleLabel_.at(x).at(j));
00293           if ( (trNEW_.at(i).accept()==0 && j==trNEW_.at(i).index()) && (moduleType=="HLTPrescaler" || moduleType=="TriggerResultsFilter") ) fails_prescaler_.at(x) = true;
00294         }
00295 
00296       }
00297     }
00298   }
00299 
00300 
00301   //check agreement between ORIG and NEW
00302   //loop over trigger paths (ORIG and NEW)
00303   for (unsigned int x=0; x<nPaths_; x++) {
00304     if (!fails_prescaler_.at(x)){ //ignore paths that fail on a prescale
00305       if(ORIG_accept_.at(x) && !NEW_accept_.at(x)){ //ORIG fires but NEW doesn't
00306         path_ORIGnotNEW_hist->Fill(x);
00307         pathmodule_ORIGnotNEW_hist->Fill(x,module_indexNEW_.at(x)); //module and path for where it fails NEW
00308         LogInfo("EventNotReproduced")<<"Fires in ORIG but not NEW!!"<<" Path is: "<<triggerNames_.at(x)<<", last run module is: "<<module_index_labelNEW_.at(x);
00309         for (unsigned int a=0; a<nDatasets_; a++) {
00310           for (unsigned int b=0; b<nPaths_PD_.at(a); b++) {
00311             if (triggerNames_matched_.at(x).at(a).at(b)){
00312               path_ORIGnotNEW_hist_PD.at(a)->Fill(b);
00313               pathmodule_ORIGnotNEW_hist_PD.at(a)->Fill(b,module_indexNEW_.at(x)); //module and path for where it fails NEW
00314             }
00315           }
00316         }
00317       }
00318       if(!ORIG_accept_.at(x) && NEW_accept_.at(x)){//NEW fires but ORIG doesn't
00319         path_NEWnotORIG_hist->Fill(x);
00320         pathmodule_NEWnotORIG_hist->Fill(x,module_indexORIG_.at(x)); //module and path for where it fails ORIG
00321         LogInfo("EventNotReproduced")<<"Fires in NEW but not ORIG!!"<<" Path is: "<<triggerNames_.at(x)<<", last run module is: "<<module_index_labelORIG_.at(x)<<endl;
00322         for (unsigned int a=0; a<nDatasets_; a++) {
00323           for (unsigned int b=0; b<nPaths_PD_.at(a); b++) {
00324             if (triggerNames_matched_.at(x).at(a).at(b)){
00325               path_NEWnotORIG_hist_PD.at(a)->Fill(b);
00326               pathmodule_NEWnotORIG_hist_PD.at(a)->Fill(b,module_indexORIG_.at(x)); //module and path for where it fails ORIG
00327             }
00328           }
00329         }
00330       }
00331     }
00332   }//end of loop over trigger paths
00333 
00334 }
00335 
00336 
00337 // ------------ method called once each job just before starting event loop  ------------
00338 void 
00339 HLTOfflineReproducibility::beginJob()
00340 {
00341 }
00342 
00343 // ------------ method called once each job just after ending the event loop  ------------
00344 void 
00345 HLTOfflineReproducibility::endJob() 
00346 {
00347 }
00348 
00349 // ------------ method called when starting to processes a run  ------------
00350 void 
00351 HLTOfflineReproducibility::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup)
00352 {
00353   edm::Service<TFileService> fs;  
00354   void init(const edm::TriggerResults &, const edm::TriggerNames & HLTNames);
00355 
00356   bool changed(true);
00357   nPathsORIG_=0, nPathsNEW_=0;
00358   vector<string> triggerNamesORIG_, triggerNamesNEW_;
00359   vector<string> temp_;
00360   unsigned int max_nModules_=0;
00361   vector<unsigned int> max_nModules_PD_, nModules_diff_;
00362   bool TriggerModuleNamesOK_ = true;
00363 
00364   //---------------------------------------hltConfig for ORIG-------------------------------
00365   if (hltConfig_.init(iRun,iSetup,processNameORIG_,changed)) {
00366     // if init returns TRUE, initialisation has succeeded!
00367     if (changed) {
00368       edm::LogInfo("HLTConfigProvider")<<"hlt_Config_.init returns true for ORIG"<<endl;
00369       // The HLT config has actually changed wrt the previous Run, hence rebook your
00370       // histograms or do anything else dependent on the revised HLT config
00371       // check if trigger name in (new) config
00372       triggerNamesORIG_ = hltConfig_.triggerNames();
00373 
00374       //loop over trigger paths
00375       nPathsORIG_ = hltConfig_.size();
00376       for (unsigned int i=0; i<nPathsORIG_; i++) {
00377         temp_.clear();
00378         //const vector<string> & moduleLabelsORIG(hltConfig_.moduleLabels(i));
00379         for (unsigned int j=0; j<hltConfig_.moduleLabels(i).size(); j++) {
00380           temp_.push_back(hltConfig_.moduleLabel(i,j));
00381         }
00382         moduleLabelORIG_.push_back(temp_);
00383       }
00384 
00385     }
00386   } 
00387   else {
00388     // if init returns FALSE, initialisation has NOT succeeded, which indicates a problem
00389     // with the file and/or code and needs to be investigated!
00390     edm::LogError("HLTConfigProvider")<<" HLT config extraction failure with process name " << processNameORIG_;
00391     // In this case, all access methods will return empty values!
00392   }
00393 
00394   //-------------------hltConfig for NEW----------------------------------------
00395   if (hltConfig_.init(iRun,iSetup,processNameNEW_,changed)) {
00396     // if init returns TRUE, initialisation has succeeded!
00397     if (changed) {
00398       edm::LogInfo("HLTConfigProvider")<<"hlt_Config_.init returns true for NEW"<<endl;
00399       // The HLT config has actually changed wrt the previous Run, hence rebook your
00400       // histograms or do anything else dependent on the revised HLT config
00401       // check if trigger name in (new) config
00402       triggerNamesNEW_ = hltConfig_.triggerNames();
00403 
00404       //loop over trigger paths
00405       nPathsNEW_ = hltConfig_.size();
00406       for (unsigned int i=0; i<nPathsNEW_; i++) {
00407         temp_.clear();
00408         for (unsigned int j=0; j<hltConfig_.moduleLabels(i).size(); j++){
00409           temp_.push_back(hltConfig_.moduleLabel(i,j));
00410         }
00411         moduleLabelNEW_.push_back(temp_);
00412       }
00413 
00414     }
00415   } 
00416   else {
00417     // if init returns FALSE, initialisation has NOT succeeded, which indicates a problem
00418     // with the file and/or code and needs to be investigated!
00419     edm::LogError("HLTConfigProvider")<<" HLT config extraction failure with process name " << processNameNEW_;
00420     // In this case, all access methods will return empty values!
00421   }
00422 
00423   //------------------compare ORIG and NEW hltConfig------------------------
00424   if (nPathsORIG_==0 || nPathsNEW_==0){
00425     edm::LogError("TooLittleData")<<"There are 0 paths ORIG or NEW!! There are "<<nPathsORIG_<<" paths ORIG and "<<nPathsNEW_<<" paths NEW!!!";
00426     TriggerModuleNamesOK_ = false;
00427   }
00428   else{
00429     //define nPaths_ as number of paths shared between ORIG and NEW
00430     if (nPathsORIG_<=nPathsNEW_) nPaths_=nPathsORIG_;
00431     else nPaths_=nPathsNEW_;
00432 
00433     for (unsigned int i=0; i<nPathsORIG_; i++) {
00434       for (unsigned int j=0; j<nPathsNEW_; j++) {
00435         if (triggerNamesORIG_.at(i)==triggerNamesNEW_.at(j)){
00436           triggerNames_.push_back(triggerNamesORIG_.at(i));
00437           if (i!=j) edm::LogInfo("PathInfo")<<"Path "<<triggerNamesORIG_.at(i)<<" corresponds to path number "<<i<<" for ORIG and path number "<<j<<" for NEW";
00438 
00439           //define nModules_ as number of modules shared between ORIG and NEW
00440           if (moduleLabelORIG_.at(i).size()<=moduleLabelNEW_.at(j).size()){
00441             nModules_.push_back(moduleLabelORIG_.at(i).size());
00442             LogDebug("")<<"moduleLabelORIG<=moduleLabelNEW, so moduleLabelORIG_.at(i).size() is: "<<moduleLabelORIG_.at(i).size()<<" for ORIG path "<<i;
00443           }
00444           else {
00445             nModules_.push_back(moduleLabelNEW_.at(j).size());
00446             LogDebug("")<<"moduleLabelORIG>moduleLabelNEW, so moduleLabelNEW_.at(j).size() is: "<<moduleLabelNEW_.at(j).size()<<" for NEW path "<<j;
00447           }
00448           int x;
00449           if (i<=j) x=i;
00450           else x=j;
00451           LogDebug("")<<"nModules for 'global' path "<<x<<" is: "<<nModules_.at(x);
00452 
00453           if (nModules_.at(x)>max_nModules_) max_nModules_=nModules_.at(x);
00454           
00455           if (moduleLabelORIG_.at(i).size()>moduleLabelNEW_.at(j).size()) nModules_diff_.push_back(moduleLabelORIG_.at(i).size()-moduleLabelNEW_.at(j).size());
00456           else nModules_diff_.push_back(moduleLabelNEW_.at(j).size()-moduleLabelORIG_.at(i).size());
00457           LogDebug("")<<"nModules_diff is: "<<nModules_diff_.at(x)<<" for 'global' path "<<x;
00458 
00459           temp_.clear();
00460           for (unsigned int a=0; a<moduleLabelORIG_.at(i).size(); a++) {
00461             for (unsigned int b=0; b<moduleLabelNEW_.at(j).size(); b++) {
00462               //match ORIG and NEW module labels
00463               //since a module can be run twice per path, but not usually right after one another,
00464               //require that a and b be fairly close to each other, +/- the difference in the number of modules run NEW vs ORIG,
00465               //to avoid double-counting modules that are repeated later in the path
00466               //also, since we need to work with unsigned ints, a or b could also be 0, ignoring the requirement described above
00467               if ( (moduleLabelORIG_.at(i).at(a)==moduleLabelNEW_.at(j).at(b)) && ( (b<=a+nModules_diff_.at(x) && b>=a-nModules_diff_.at(x)) || (a==0 || b==0) ) ){
00468                 temp_.push_back(moduleLabelORIG_.at(i).at(a));
00469                 if (a!=b){
00470                   edm::LogInfo("PathInfo")<<"For path "<<triggerNamesORIG_.at(i)<<" in ORIG and "<<triggerNamesNEW_.at(j)<<" in NEW:"<<"  module "<<moduleLabelORIG_.at(i).at(a)<<" corresponds to module number "<<a<<" for ORIG and module number "<<b<<" for NEW";
00471                 }
00472               }
00473             }
00474           }
00475           moduleLabel_.push_back(temp_);
00476         }
00477       }
00478     }
00479   }
00480 
00481 
00482   //----------------------------------------------------------------------------------------------------------
00483 
00484   //if everything is good:
00485   //save path and module names to be used in event loop, print out the module names and types for each path
00486   //get paths in each dataset
00487   if (TriggerModuleNamesOK_){
00488 
00489     //------------all paths--------------
00490     edm::LogInfo("PathInfo")<<"There are "<<nPaths_<<" paths in total";
00491     edm::LogInfo("PathInfo")<<"Maximum number of modules over all paths is: "<<max_nModules_;  
00492 
00493     for (unsigned int x=0; x<nPaths_; x++) {
00494       trigger_ORIG_.push_back(0);
00495       trigger_NEW_.push_back(0);
00496       edm::LogInfo("PathInfo")<<"For "<<triggerNames_.at(x)<<" (trigger number "<<x<<"), there are "<<nModules_.at(x)<<" modules:";
00497       for (unsigned int j=0; j<nModules_.at(x); j++) {
00498         const string& moduleType_ = hltConfig_.moduleType(moduleLabel_.at(x).at(j));
00499         edm::LogInfo("PathInfo")<<" module "<<j<<" is "<<moduleLabel_.at(x).at(j)<<" and is of type "<<moduleType_;
00500       }
00501     }
00502 
00503 
00504     //---------paths per dataset-------------------------------------------
00505     //get datasets, initialize max_nModules_PD_
00506     datasetNames_ = hltConfig_.datasetNames();
00507     nDatasets_ = datasetNames_.size();    
00508     for (unsigned int a=0; a<nDatasets_; a++) {
00509       max_nModules_PD_.push_back(0);
00510     }
00511 
00512     //loop over datasets, paths in each dataset
00513     for (unsigned int a=0; a<nDatasets_; a++) {
00514       temp_.clear();
00515       vector<string> datasetcontent_ = hltConfig_.datasetContent(a);
00516       nPaths_PD_.push_back(datasetcontent_.size());
00517       edm::LogInfo("DatasetInfo")<<"For dataset "<<datasetNames_.at(a)<<" (dataset number "<<a<<"), there are "<<nPaths_PD_.at(a)<<" paths:";
00518       for (unsigned int b=0; b<nPaths_PD_.at(a); b++) {
00519         edm::LogInfo("DatasetInfo")<<" path "<<b<<" is "<<datasetcontent_.at(b);
00520         temp_.push_back(datasetcontent_.at(b));
00521       }
00522       datasetContent_.push_back(temp_);
00523     }
00524 
00525     //match trigger names in full list to trigger names per dataset; find max number of modules over all triggers in each dataset
00526     //find matches
00527     vector <vector<bool> > temp1_;
00528     vector<bool> temp2_;
00529     for (unsigned int x=0; x<nPaths_; x++) {
00530       temp1_.clear();
00531       for (unsigned int a=0; a<nDatasets_; a++) {
00532         temp2_.clear();
00533         for (unsigned int b=0; b<nPaths_PD_.at(a); b++) {
00534           if (triggerNames_.at(x)==datasetContent_.at(a).at(b)){
00535             temp2_.push_back(true);         
00536             LogDebug("")<<"Matched trigger name is: "<<datasetContent_.at(a).at(b)<<" for dataset "<<a<<" and dataset path "<<b;
00537           }
00538           else temp2_.push_back(false);
00539         }
00540         temp1_.push_back(temp2_);
00541       }
00542       triggerNames_matched_.push_back(temp1_);
00543     }
00544 
00545     //if matched and # of modules is bigger than all previous ones, take that number as new maximum
00546     for (unsigned int x=0; x<nPaths_; x++) {
00547       for (unsigned int a=0; a<nDatasets_; a++) {
00548         for (unsigned int b=0; b<nPaths_PD_.at(a); b++) {
00549           if (triggerNames_matched_.at(x).at(a).at(b) && nModules_.at(x)>max_nModules_PD_.at(a)) max_nModules_PD_.at(a)=nModules_.at(x);
00550         }
00551       }
00552     }
00553 
00554     //for (unsigned int a=0; a<nDatasets_; a++) {
00555     //LogDebug("")<<"For dataset "<<datasetNames_.at(a)<<", the max number of modules is: "<<max_nModules_PD_.at(a);
00556     //}
00557 
00558   }//end if all triggers and modules match from ORIG to NEW
00559   
00560 
00561   //---------------------------------------------------------------------------------------------------------- 
00562 
00563   //define histograms
00564 
00565   //all paths
00566   if(dqm_){
00567     if (not dqms_) return;
00568     dqms_->setCurrentFolder("DQMExample/DQMSource_HLTOfflineReproducibility");
00569 
00570     path_ORIG_hist = dqms_->book1D("path_ORIG_hist","Total Times Path Fires in ORIG",nPaths_,0,nPaths_)->getTH1F();
00571     path_ORIGnotNEW_hist = dqms_->book1D("path_ORIGnotNEW_hist","Path fires in ORIG but not in NEW",nPaths_,0,nPaths_)->getTH1F();
00572     path_NEWnotORIG_hist = dqms_->book1D("path_NEWnotORIG_hist","Path fires in NEW but not in ORIG",nPaths_,0,nPaths_)->getTH1F();
00573     pathmodule_ORIGnotNEW_hist = dqms_->book2D("pathmodule_ORIGnotNEW_hist","Last run module index vs Path for NEW, when ORIG fired but NEW didn't",nPaths_,0,nPaths_,max_nModules_,0,max_nModules_)->getTH2F();
00574     pathmodule_NEWnotORIG_hist = dqms_->book2D("pathmodule_NEWnotORIG_hist","Last run module index vs Path for ORIG, when NEW fired but ORIG didn't",nPaths_,0,nPaths_,max_nModules_,0,max_nModules_)->getTH2F();
00575   }
00576   else{
00577     path_ORIG_hist = fs->make<TH1F>("path_ORIG_hist", "Total Times ORIG Path Fires in ORIG", nPaths_, 0, nPaths_);
00578     path_ORIGnotNEW_hist = fs->make<TH1F>("path_ORIGnotNEW_hist", "Path fires in ORIG but not in NEW", nPaths_, 0, nPaths_);
00579     path_NEWnotORIG_hist = fs->make<TH1F>("path_NEWnotORIG_hist", "Path fires in NEW but not in ORIG", nPaths_, 0, nPaths_);
00580     pathmodule_ORIGnotNEW_hist = fs->make<TH2F>("pathmodule_ORIGnotNEW_hist", "Last run module index vs Path for NEW, when ORIG fired but NEW didn't", nPaths_, 0, nPaths_, max_nModules_, 0, max_nModules_);
00581     pathmodule_NEWnotORIG_hist = fs->make<TH2F>("pathmodule_NEWnotORIG_hist", "Last run module index vs Path for ORIG, when NEW fired but ORIG didn't", nPaths_, 0, nPaths_, max_nModules_, 0, max_nModules_);
00582   }
00583 
00584   //paths per dataset
00585   char folder_name[500];
00586   char path_ORIG_name[100], path_ORIGnotNEW_name[100], path_NEWnotORIG_name[100], pathmodule_ORIGnotNEW_name[100], pathmodule_NEWnotORIG_name[100];
00587   for (unsigned int a = 0; a < nDatasets_; ++a) {
00588     snprintf(path_ORIG_name,             100, "path_ORIG_hist_%s",              datasetNames_.at(a).c_str());
00589     snprintf(path_ORIGnotNEW_name,       100, "path_ORIGnotNEW_hist_%s",        datasetNames_.at(a).c_str());
00590     snprintf(path_NEWnotORIG_name,       100, "path_NEWnotORIG_hist_%s",        datasetNames_.at(a).c_str());
00591     snprintf(pathmodule_ORIGnotNEW_name, 100, "pathmodule_ORIGnotNEW_hist_%s",  datasetNames_.at(a).c_str());
00592     snprintf(pathmodule_NEWnotORIG_name, 100, "pathmodule_NEWnotORIG_hist_%s",  datasetNames_.at(a).c_str());
00593 
00594     TString path_ORIG_title             = "Total Times Path Fires ORIG (" + datasetNames_.at(a) + " dataset)";
00595     TString path_ORIGnotNEW_title       = "Path fires in ORIG but not in NEW (" + datasetNames_.at(a) + " dataset)";
00596     TString path_NEWnotORIG_title       = "Path fires in NEW but not in ORIG (" + datasetNames_.at(a) + " dataset)";
00597     TString pathmodule_ORIGnotNEW_title = "Last run module index vs Path for NEW, when ORIG fired but NEW didn't (" + datasetNames_.at(a) + " dataset)";
00598     TString pathmodule_NEWnotORIG_title = "Last run module index vs Path for ORIG, when NEW fired but ORIG didn't (" + datasetNames_.at(a) + " dataset)";
00599 
00600     if(dqm_){
00601       sprintf(folder_name,"DQMExample/DQMSource_HLTOfflineReproducibility/%s",datasetNames_.at(a).c_str());
00602       dqms_->setCurrentFolder(folder_name);
00603       
00604       path_ORIG_hist_PD.push_back(dqms_->book1D(path_ORIG_name,path_ORIG_title,nPaths_PD_.at(a),0,nPaths_PD_.at(a))->getTH1F());
00605       path_ORIGnotNEW_hist_PD.push_back(dqms_->book1D(path_ORIGnotNEW_name,path_ORIGnotNEW_title,nPaths_PD_.at(a),0,nPaths_PD_.at(a))->getTH1F());
00606       path_NEWnotORIG_hist_PD.push_back(dqms_->book1D(path_NEWnotORIG_name,path_NEWnotORIG_title,nPaths_PD_.at(a),0,nPaths_PD_.at(a))->getTH1F());
00607       pathmodule_ORIGnotNEW_hist_PD.push_back(dqms_->book2D(pathmodule_ORIGnotNEW_name,pathmodule_ORIGnotNEW_title,nPaths_PD_.at(a),0,nPaths_PD_.at(a),max_nModules_PD_.at(a),0,max_nModules_PD_.at(a))->getTH2F());
00608       pathmodule_NEWnotORIG_hist_PD.push_back(dqms_->book2D(pathmodule_NEWnotORIG_name,pathmodule_NEWnotORIG_title,nPaths_PD_.at(a),0,nPaths_PD_.at(a),max_nModules_PD_.at(a),0,max_nModules_PD_.at(a))->getTH2F());
00609     }
00610     else{
00611       sprintf(folder_name,"%s",datasetNames_.at(a).c_str());
00612       TFileDirectory subDir = fs->mkdir(folder_name);
00613 
00614       path_ORIG_hist_PD.push_back(subDir.make<TH1F>(path_ORIG_name, path_ORIG_title, nPaths_PD_.at(a), 0, nPaths_PD_.at(a)));
00615       path_ORIGnotNEW_hist_PD.push_back(subDir.make<TH1F>(path_ORIGnotNEW_name, path_ORIGnotNEW_title, nPaths_PD_.at(a), 0, nPaths_PD_.at(a)));
00616       path_NEWnotORIG_hist_PD.push_back(subDir.make<TH1F>(path_NEWnotORIG_name, path_NEWnotORIG_title, nPaths_PD_.at(a), 0, nPaths_PD_.at(a)));
00617       pathmodule_ORIGnotNEW_hist_PD.push_back(subDir.make<TH2F>(pathmodule_ORIGnotNEW_name, pathmodule_ORIGnotNEW_title, nPaths_PD_.at(a), 0, nPaths_PD_.at(a), max_nModules_PD_.at(a), 0, max_nModules_PD_.at(a)));
00618       pathmodule_NEWnotORIG_hist_PD.push_back(subDir.make<TH2F>(pathmodule_NEWnotORIG_name, pathmodule_NEWnotORIG_title, nPaths_PD_.at(a), 0, nPaths_PD_.at(a), max_nModules_PD_.at(a), 0, max_nModules_PD_.at(a)));
00619     }
00620 
00621   }
00622   
00623 }
00624 
00625 // ------------ method called when ending the processing of a run  ------------
00626 void 
00627 HLTOfflineReproducibility::endRun(edm::Run const&, edm::EventSetup const&)
00628 {
00629   // if DQM was requested, check that the DQMService is available
00630   if (dqm_ and not dqms_) return;
00631 
00632   //all paths
00633   for (unsigned int x=0; x<nPaths_; x++) {
00634     edm::LogInfo("OrigNewFired")<<triggerNames_.at(x)<<" ORIG accepts: "<<trigger_ORIG_.at(x)<<", NEW accepts: "<<trigger_NEW_.at(x);
00635     path_ORIG_hist->GetXaxis()->SetBinLabel(x+1,triggerNames_.at(x).c_str());
00636     path_ORIGnotNEW_hist->GetXaxis()->SetBinLabel(x+1,triggerNames_.at(x).c_str());
00637     path_NEWnotORIG_hist->GetXaxis()->SetBinLabel(x+1,triggerNames_.at(x).c_str());
00638     pathmodule_ORIGnotNEW_hist->GetXaxis()->SetBinLabel(x+1,triggerNames_.at(x).c_str());
00639     pathmodule_NEWnotORIG_hist->GetXaxis()->SetBinLabel(x+1,triggerNames_.at(x).c_str());
00640   }
00641 
00642   //paths per dataset
00643   for (unsigned int a=0; a<nDatasets_; a++) {
00644     for (unsigned int b=0; b<nPaths_PD_.at(a); b++) {
00645       path_ORIG_hist_PD.at(a)->GetXaxis()->SetBinLabel(b+1,datasetContent_.at(a).at(b).c_str());
00646       path_ORIGnotNEW_hist_PD.at(a)->GetXaxis()->SetBinLabel(b+1,datasetContent_.at(a).at(b).c_str());
00647       path_NEWnotORIG_hist_PD.at(a)->GetXaxis()->SetBinLabel(b+1,datasetContent_.at(a).at(b).c_str());
00648       pathmodule_ORIGnotNEW_hist_PD.at(a)->GetXaxis()->SetBinLabel(b+1,datasetContent_.at(a).at(b).c_str());
00649       pathmodule_NEWnotORIG_hist_PD.at(a)->GetXaxis()->SetBinLabel(b+1,datasetContent_.at(a).at(b).c_str());
00650     }
00651   }
00652 
00653 }
00654 
00655 // ------------ method called when starting to processes a luminosity block  ------------
00656 void 
00657 HLTOfflineReproducibility::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00658 {
00659 }
00660 
00661 // ------------ method called when ending the processing of a luminosity block  ------------
00662 void 
00663 HLTOfflineReproducibility::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00664 {
00665 }
00666 
00667 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
00668 void
00669 HLTOfflineReproducibility::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00670   //The following says we do not know what parameters are allowed so do no validation
00671   // Please change this to state exactly what you do use, even if it is no parameters
00672   edm::ParameterSetDescription desc;
00673   desc.setUnknown();
00674   descriptions.addDefault(desc);
00675 }
00676 
00677 //define this as a plug-in
00678 DEFINE_FWK_MODULE(HLTOfflineReproducibility);