CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/HLTrigger/HLTanalyzers/src/HLTOfflineReproducibilityDQM.cc

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