CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQMOffline/JetMET/src/JetMETAnalyzer.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2012/05/20 13:12:05 $
00005  *  $Revision: 1.82 $
00006  *  \author F. Chlebana - Fermilab
00007  *          K. Hatakeyama - Rockefeller University
00008  */
00009 
00010 #include "DQMOffline/JetMET/interface/JetMETAnalyzer.h"
00011 
00012 #include "FWCore/Framework/interface/Event.h"
00013 #include "FWCore/Framework/interface/EventSetup.h"
00014 #include "FWCore/Common/interface/TriggerNames.h"
00015 
00016 #include "DataFormats/METReco/interface/CaloMETFwd.h"
00017 #include "DataFormats/METReco/interface/METFwd.h"
00018 #include "DataFormats/METReco/interface/PFMETFwd.h"
00019 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00020 #include "DataFormats/JetReco/interface/CaloJet.h"
00021 #include "DataFormats/JetReco/interface/JPTJetCollection.h"
00022 #include "DataFormats/JetReco/interface/PFJetCollection.h"
00023 #include "DataFormats/JetReco/interface/PFJet.h"
00024 
00025 #include "DataFormats/Common/interface/Handle.h"
00026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00027 
00028 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
00029 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetup.h"
00030 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00031 
00032 #include <string>
00033 using namespace edm;
00034 
00035 #define DEBUG 0
00036 
00037 // ***********************************************************
00038 JetMETAnalyzer::JetMETAnalyzer(const edm::ParameterSet& pSet) {
00039 
00040   parameters = pSet;
00041   
00042   // Jet Collection Label 
00043   theAKJetCollectionLabel       = parameters.getParameter<edm::InputTag>("AKJetsCollectionLabel");
00044   theSCJetCollectionLabel       = parameters.getParameter<edm::InputTag>("SCJetsCollectionLabel");
00045   theICJetCollectionLabel       = parameters.getParameter<edm::InputTag>("ICJetsCollectionLabel");
00046   theJPTJetCollectionLabel      = parameters.getParameter<edm::InputTag>("JPTJetsCollectionLabel");
00047   thePFJetCollectionLabel       = parameters.getParameter<edm::InputTag>("PFJetsCollectionLabel");
00048 
00049   theTriggerResultsLabel        = parameters.getParameter<edm::InputTag>("TriggerResultsLabel");
00050   
00051   theJetAnalyzerFlag            = parameters.getUntrackedParameter<bool>("DoJetAnalysis",    true);
00052   theJetCleaningFlag            = parameters.getUntrackedParameter<bool>("DoJetCleaning",    true);
00053   theIConeJetAnalyzerFlag       = parameters.getUntrackedParameter<bool>("DoIterativeCone",  false);
00054   theSConeJetAnalyzerFlag       = parameters.getUntrackedParameter<bool>("DoSisCone",  false);
00055   theJetPtAnalyzerFlag          = parameters.getUntrackedParameter<bool>("DoJetPtAnalysis",  false);
00056   theJetPtCleaningFlag          = parameters.getUntrackedParameter<bool>("DoJetPtCleaning",  false);
00057   theJPTJetAnalyzerFlag         = parameters.getUntrackedParameter<bool>("DoJPTJetAnalysis", false);
00058   theJPTJetCleaningFlag         = parameters.getUntrackedParameter<bool>("DoJPTJetCleaning", true);
00059   thePFJetAnalyzerFlag          = parameters.getUntrackedParameter<bool>("DoPFJetAnalysis",  false);
00060   thePFJetCleaningFlag          = parameters.getUntrackedParameter<bool>("DoPFJetCleaning",  true);
00061   //
00062   theDiJetSelectionFlag         = parameters.getUntrackedParameter<bool>("DoDiJetSelection", true);
00063   //
00064   theCaloMETAnalyzerFlag        = parameters.getUntrackedParameter<bool>("DoCaloMETAnalysis",true);
00065   theTcMETAnalyzerFlag          = parameters.getUntrackedParameter<bool>("DoTcMETAnalysis",  true);
00066   theMuCorrMETAnalyzerFlag      = parameters.getUntrackedParameter<bool>("DoMuCorrMETAnalysis",  true);
00067   thePfMETAnalyzerFlag          = parameters.getUntrackedParameter<bool>("DoPfMETAnalysis",  true);
00068   theHTMHTAnalyzerFlag          = parameters.getUntrackedParameter<bool>("DoHTMHTAnalysis",  true);
00069 
00070   // ==========================================================
00071   //DCS information
00072   // ==========================================================
00073   DCSFilterCalo = new JetMETDQMDCSFilter(parameters.getParameter<ParameterSet>("DCSFilterCalo"));
00074   DCSFilterPF   = new JetMETDQMDCSFilter(parameters.getParameter<ParameterSet>("DCSFilterPF"));
00075   DCSFilterJPT  = new JetMETDQMDCSFilter(parameters.getParameter<ParameterSet>("DCSFilterJPT"));
00076   DCSFilterAll  = new JetMETDQMDCSFilter(parameters.getParameter<ParameterSet>("DCSFilterAll"));
00077   // Used for Jet DQM - For MET DQM, DCS selection applied in ***METAnalyzer
00078 
00079   // --- do the analysis on the Jets
00080   if(theJetAnalyzerFlag) {
00081     theAKJetAnalyzer  = new JetAnalyzer(parameters.getParameter<ParameterSet>("jetAnalysis"));
00082     theAKJetAnalyzer->setSource("AntiKtJets");    
00083     if(theSConeJetAnalyzerFlag) {
00084       theSCJetAnalyzer  = new JetAnalyzer(parameters.getParameter<ParameterSet>("jetAnalysis"));
00085       theSCJetAnalyzer->setSource("SISConeJets");
00086     }
00087     if(theIConeJetAnalyzerFlag){
00088       theICJetAnalyzer  = new JetAnalyzer(parameters.getParameter<ParameterSet>("jetAnalysis"));
00089       theICJetAnalyzer->setSource("IterativeConeJets");  
00090     }
00091   }
00092 
00093   if(theJetCleaningFlag) {
00094     theCleanedAKJetAnalyzer  = new JetAnalyzer(parameters.getParameter<ParameterSet>("CleanedjetAnalysis"));
00095     theCleanedAKJetAnalyzer->setSource("CleanedAntiKtJets");
00096     if(theSConeJetAnalyzerFlag){
00097       theCleanedSCJetAnalyzer  = new JetAnalyzer(parameters.getParameter<ParameterSet>("CleanedjetAnalysis"));
00098       theCleanedSCJetAnalyzer->setSource("CleanedSISConeJets");
00099     }
00100     if(theIConeJetAnalyzerFlag){
00101       theCleanedICJetAnalyzer  = new JetAnalyzer(parameters.getParameter<ParameterSet>("CleanedjetAnalysis"));
00102       theCleanedICJetAnalyzer->setSource("CleanedIterativeConeJets");
00103     }
00104   }
00105 
00106   if(theDiJetSelectionFlag){
00107     theDiJetAnalyzer  = new JetAnalyzer(parameters.getParameter<ParameterSet>("DijetAnalysis"));
00108     theDiJetAnalyzer->setSource("DiJets");
00109   }
00110 
00111   // Do Pt analysis
00112   if(theJetPtAnalyzerFlag ) {
00113     thePtAKJetAnalyzer  = new JetPtAnalyzer(parameters.getParameter<ParameterSet>("PtAnalysis"));
00114     thePtAKJetAnalyzer->setSource("PtAnalysisAntiKtJets");
00115     if(theSConeJetAnalyzerFlag){
00116       thePtSCJetAnalyzer  = new JetPtAnalyzer(parameters.getParameter<ParameterSet>("PtAnalysis"));
00117       thePtSCJetAnalyzer->setSource("PtAnalysisSISConeJets");
00118     }
00119     if(theIConeJetAnalyzerFlag){
00120       thePtICJetAnalyzer  = new JetPtAnalyzer(parameters.getParameter<ParameterSet>("PtAnalysis"));
00121       thePtICJetAnalyzer->setSource("PtAnalysisIterativeConeJets");
00122     }
00123   }
00124   // Do Cleaned Pt analysis
00125   if(theJetPtCleaningFlag ) {
00126     theCleanedPtAKJetAnalyzer  = new JetPtAnalyzer(parameters.getParameter<ParameterSet>("CleanedPtAnalysis"));
00127     theCleanedPtAKJetAnalyzer->setSource("PtAnalysisCleanedAntiKtJets");
00128     if(theSConeJetAnalyzerFlag){
00129       theCleanedPtSCJetAnalyzer  = new JetPtAnalyzer(parameters.getParameter<ParameterSet>("CleanedPtAnalysis"));
00130       theCleanedPtSCJetAnalyzer->setSource("PtAnalysisCleanedSISConeJets");
00131     }
00132     if(theIConeJetAnalyzerFlag){
00133       theCleanedPtICJetAnalyzer  = new JetPtAnalyzer(parameters.getParameter<ParameterSet>("CleanedPtAnalysis"));
00134       theCleanedPtICJetAnalyzer->setSource("PtAnalysisCleanedIterativeConeJets");
00135     }
00136   }
00137 
00138   // --- do the analysis on JPT Jets
00139   if(theJPTJetAnalyzerFlag) {
00140     theJPTJetAnalyzer  = new JPTJetAnalyzer(parameters.getParameter<ParameterSet>("JPTJetAnalysis"));
00141   }
00142   // --- do the analysis on JPT Cleaned Jets
00143   if(theJPTJetCleaningFlag) {
00144     theCleanedJPTJetAnalyzer  = new JPTJetAnalyzer(parameters.getParameter<ParameterSet>("CleanedJPTJetAnalysis"));
00145   }
00146 
00147   // --- do the analysis on the PFJets
00148   if(thePFJetAnalyzerFlag){ 
00149     thePFJetAnalyzer = new PFJetAnalyzer(parameters.getParameter<ParameterSet>("pfJetAnalysis"));
00150     thePFJetAnalyzer->setSource("uncPFJets");
00151   }
00152   // --- do the analysis on the CleanedPFJets
00153   if(thePFJetCleaningFlag) {
00154     theCleanedPFJetAnalyzer = new PFJetAnalyzer(parameters.getParameter<ParameterSet>("CleanedpfJetAnalysis"));
00155     theCleanedPFJetAnalyzer->setSource("PFJets");
00156   }
00157 
00158   if(theDiJetSelectionFlag){
00159     thePFDiJetAnalyzer  = new PFJetAnalyzer(parameters.getParameter<ParameterSet>("PFDijetAnalysis"));
00160     thePFDiJetAnalyzer->setSource("PFDiJets");
00161   }
00162   //Trigger selectoin
00163   edm::ParameterSet highptjetparms = parameters.getParameter<edm::ParameterSet>("highPtJetTrigger");
00164   edm::ParameterSet lowptjetparms  = parameters.getParameter<edm::ParameterSet>("lowPtJetTrigger" );
00165 
00166   _HighPtJetEventFlag = new GenericTriggerEventFlag( highptjetparms );
00167   _LowPtJetEventFlag  = new GenericTriggerEventFlag( lowptjetparms  );
00168 
00169   highPtJetExpr_ = highptjetparms.getParameter<std::vector<std::string> >("hltPaths");
00170   lowPtJetExpr_  = lowptjetparms .getParameter<std::vector<std::string> >("hltPaths");
00171 
00172   // --- do the analysis on the MET
00173   if(theCaloMETAnalyzerFlag){
00174     theCaloMETAnalyzer       = new CaloMETAnalyzer(parameters.getParameter<ParameterSet>("caloMETAnalysis"));
00175     //theCaloMETNoHFAnalyzer   = new CaloMETAnalyzer(parameters.getParameter<ParameterSet>("caloMETNoHFAnalysis"));
00176     //theCaloMETHOAnalyzer     = new CaloMETAnalyzer(parameters.getParameter<ParameterSet>("caloMETHOAnalysis"));
00177     //theCaloMETNoHFHOAnalyzer = new CaloMETAnalyzer(parameters.getParameter<ParameterSet>("caloMETNoHFHOAnalysis"));
00178   }
00179   if(theTcMETAnalyzerFlag){
00180     theTcMETAnalyzer = new METAnalyzer(parameters.getParameter<ParameterSet>("tcMETAnalysis"));
00181   }
00182   if(theMuCorrMETAnalyzerFlag){
00183     theMuCorrMETAnalyzer = new CaloMETAnalyzer(parameters.getParameter<ParameterSet>("mucorrMETAnalysis"));
00184   }
00185   if(thePfMETAnalyzerFlag){
00186     thePfMETAnalyzer = new PFMETAnalyzer(parameters.getParameter<ParameterSet>("pfMETAnalysis"));
00187   }
00188   if(theHTMHTAnalyzerFlag){
00189     theHTMHTAnalyzer         = new HTMHTAnalyzer(parameters.getParameter<ParameterSet>("HTMHTAnalysis"));
00190   }
00191 
00192   _LSBegin     = parameters.getParameter<int>("LSBegin");
00193   _LSEnd       = parameters.getParameter<int>("LSEnd");
00194 
00195   processname_ = parameters.getParameter<std::string>("processname");
00196 
00197   //jet cleanup parameters
00198   theCleaningParameters = parameters.getParameter<ParameterSet>("CleaningParameters"),
00199 
00200   _hlt_PhysDec   = theCleaningParameters.getParameter<std::string>("HLT_PhysDec");
00201 
00202   _techTrigsAND  = theCleaningParameters.getParameter<std::vector<unsigned > >("techTrigsAND");
00203   _techTrigsOR   = theCleaningParameters.getParameter<std::vector<unsigned > >("techTrigsOR");
00204   _techTrigsNOT  = theCleaningParameters.getParameter<std::vector<unsigned > >("techTrigsNOT");
00205 
00206   _doPVCheck          = theCleaningParameters.getParameter<bool>("doPrimaryVertexCheck");
00207   _doHLTPhysicsOn     = theCleaningParameters.getParameter<bool>("doHLTPhysicsOn");
00208 
00209   _tightBHFiltering   = theCleaningParameters.getParameter<bool>("tightBHFiltering");
00210 
00211   _theVertexLabel     = theCleaningParameters.getParameter<edm::InputTag>("vertexLabel");
00212   _theGTLabel         = theCleaningParameters.getParameter<edm::InputTag>("gtLabel");
00213 
00214   //Vertex requirements
00215   if (_doPVCheck) {
00216     _nvtx_min        = theCleaningParameters.getParameter<int>("nvtx_min");
00217     _nvtxtrks_min    = theCleaningParameters.getParameter<int>("nvtxtrks_min");
00218     _vtxndof_min     = theCleaningParameters.getParameter<int>("vtxndof_min");
00219     _vtxchi2_max     = theCleaningParameters.getParameter<double>("vtxchi2_max");
00220     _vtxz_max        = theCleaningParameters.getParameter<double>("vtxz_max");
00221   }
00222 
00223 }
00224 
00225 // ***********************************************************
00226 JetMETAnalyzer::~JetMETAnalyzer() {   
00227 
00228   if(theJetAnalyzerFlag) {
00229     delete theAKJetAnalyzer;
00230     if(theSConeJetAnalyzerFlag) delete theSCJetAnalyzer;    
00231     if(theIConeJetAnalyzerFlag) delete theICJetAnalyzer;
00232   }
00233   if(theJetCleaningFlag) {
00234     delete theCleanedAKJetAnalyzer;
00235     if(theSConeJetAnalyzerFlag) delete theCleanedSCJetAnalyzer;
00236     if(theIConeJetAnalyzerFlag) delete theCleanedICJetAnalyzer;
00237   }
00238   if(theDiJetSelectionFlag) {
00239     delete theDiJetAnalyzer;
00240   }
00241   if(theJetPtAnalyzerFlag) {
00242     delete thePtAKJetAnalyzer;
00243     if(theSConeJetAnalyzerFlag) delete thePtSCJetAnalyzer;
00244     if(theIConeJetAnalyzerFlag) delete thePtICJetAnalyzer;
00245   }
00246 
00247   if(theJetPtCleaningFlag) {
00248     delete theCleanedPtAKJetAnalyzer;
00249     if(theSConeJetAnalyzerFlag) delete theCleanedPtSCJetAnalyzer;
00250     if(theIConeJetAnalyzerFlag) delete theCleanedPtICJetAnalyzer;
00251   }
00252 
00253   if(theJPTJetAnalyzerFlag)        delete theJPTJetAnalyzer;
00254   if(theJPTJetCleaningFlag)        delete theCleanedJPTJetAnalyzer;
00255 
00256   if(thePFJetAnalyzerFlag)       delete thePFJetAnalyzer;
00257   if(thePFJetCleaningFlag)       delete theCleanedPFJetAnalyzer;
00258   if(theDiJetSelectionFlag)      delete thePFDiJetAnalyzer;
00259 
00260   delete _HighPtJetEventFlag;
00261   delete _LowPtJetEventFlag;
00262 
00263   if(theCaloMETAnalyzerFlag){
00264     delete theCaloMETAnalyzer;
00265     //delete theCaloMETNoHFAnalyzer;
00266     //delete theCaloMETHOAnalyzer;
00267     //delete theCaloMETNoHFHOAnalyzer;
00268   }
00269   if(theTcMETAnalyzerFlag)         delete theTcMETAnalyzer;
00270   if(theMuCorrMETAnalyzerFlag)     delete theMuCorrMETAnalyzer;
00271   if(thePfMETAnalyzerFlag)         delete thePfMETAnalyzer;
00272   if(theHTMHTAnalyzerFlag)         delete theHTMHTAnalyzer;
00273 
00274   delete DCSFilterCalo;
00275   delete DCSFilterPF;
00276   delete DCSFilterJPT;
00277   delete DCSFilterAll;
00278 
00279 }
00280 
00281 // ***********************************************************
00282 void JetMETAnalyzer::beginJob(void) {
00283 
00284   metname = "JetMETAnalyzer";
00285 
00286   LogTrace(metname)<<"[JetMETAnalyzer] Parameters initialization";
00287   dbe = edm::Service<DQMStore>().operator->();
00288 
00289   //
00290   //--- Jet
00291   if(theJetAnalyzerFlag) { 
00292     theAKJetAnalyzer->beginJob(dbe);
00293     if(theSConeJetAnalyzerFlag) theSCJetAnalyzer->beginJob(dbe); 
00294     if(theIConeJetAnalyzerFlag) theICJetAnalyzer->beginJob(dbe);
00295   }
00296   if(theJetCleaningFlag) {
00297     theCleanedAKJetAnalyzer->beginJob(dbe);
00298     if(theSConeJetAnalyzerFlag) theCleanedSCJetAnalyzer->beginJob(dbe); 
00299     if(theIConeJetAnalyzerFlag) theCleanedICJetAnalyzer->beginJob(dbe);
00300   }
00301   if(theDiJetSelectionFlag) theDiJetAnalyzer->beginJob(dbe); 
00302   if(theJetPtAnalyzerFlag ) {
00303     thePtAKJetAnalyzer->beginJob(dbe);
00304     if(theSConeJetAnalyzerFlag) thePtSCJetAnalyzer->beginJob(dbe);
00305     if(theIConeJetAnalyzerFlag) thePtICJetAnalyzer->beginJob(dbe);
00306   }
00307   if(theJetPtCleaningFlag ) {
00308     theCleanedPtAKJetAnalyzer->beginJob(dbe);
00309     if(theSConeJetAnalyzerFlag) theCleanedPtSCJetAnalyzer->beginJob(dbe);
00310     if(theIConeJetAnalyzerFlag) theCleanedPtICJetAnalyzer->beginJob(dbe);
00311   }
00312 
00313   if(theJPTJetAnalyzerFlag) theJPTJetAnalyzer->beginJob(dbe);
00314   if(theJPTJetCleaningFlag) theCleanedJPTJetAnalyzer->beginJob(dbe);
00315 
00316   if(thePFJetAnalyzerFlag)  thePFJetAnalyzer->beginJob(dbe);
00317   if(thePFJetCleaningFlag)  theCleanedPFJetAnalyzer->beginJob(dbe);
00318   if(theDiJetSelectionFlag) thePFDiJetAnalyzer->beginJob(dbe); 
00319 
00320   //
00321   //--- MET
00322   if(theCaloMETAnalyzerFlag){
00323     theCaloMETAnalyzer->beginJob(dbe);
00324     //theCaloMETNoHFAnalyzer->beginJob(dbe);
00325     //theCaloMETHOAnalyzer->beginJob(dbe);
00326     //theCaloMETNoHFHOAnalyzer->beginJob(dbe);
00327   }
00328   if(theTcMETAnalyzerFlag) theTcMETAnalyzer->beginJob(dbe);
00329   if(theMuCorrMETAnalyzerFlag) theMuCorrMETAnalyzer->beginJob(dbe);
00330   if(thePfMETAnalyzerFlag) thePfMETAnalyzer->beginJob(dbe);
00331   if(theHTMHTAnalyzerFlag) theHTMHTAnalyzer->beginJob(dbe);
00332   
00333   dbe->setCurrentFolder("JetMET");
00334   lumisecME = dbe->book1D("lumisec", "lumisec", 500, 0., 500.);
00335   cleanupME = dbe->book1D("cleanup", "cleanup", 10, 0., 10.);
00336   cleanupME->setBinLabel(1,"Primary Vertex");
00337   cleanupME->setBinLabel(2,"DCS::Pixel");
00338   cleanupME->setBinLabel(3,"DCS::SiStrip");
00339   cleanupME->setBinLabel(4,"DCS::ECAL");
00340   cleanupME->setBinLabel(5,"DCS::ES");
00341   cleanupME->setBinLabel(6,"DCS::HBHE");
00342   cleanupME->setBinLabel(7,"DCS::HF");
00343   cleanupME->setBinLabel(8,"DCS::HO");
00344   cleanupME->setBinLabel(9,"DCS::Muon");
00345 
00346   verticesME = dbe->book1D("vertices", "vertices", 50, 0, 50);
00347 }
00348 
00349 // ***********************************************************
00350 void JetMETAnalyzer::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
00351 {
00352   //LogDebug("JetMETAnalyzer") << "beginRun, run " << run.id();
00353   //
00354 
00355   if ( _HighPtJetEventFlag->on() ) _HighPtJetEventFlag->initRun( iRun, iSetup );
00356   if ( _LowPtJetEventFlag ->on() ) _LowPtJetEventFlag ->initRun( iRun, iSetup );
00357 
00358   if (_HighPtJetEventFlag->on() && _HighPtJetEventFlag->expressionsFromDB(_HighPtJetEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00359     highPtJetExpr_ = _HighPtJetEventFlag->expressionsFromDB(_HighPtJetEventFlag->hltDBKey(), iSetup);
00360   if (_LowPtJetEventFlag->on() && _LowPtJetEventFlag->expressionsFromDB(_LowPtJetEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00361     lowPtJetExpr_  = _LowPtJetEventFlag->expressionsFromDB(_LowPtJetEventFlag->hltDBKey(),   iSetup);
00362 
00363   //--- htlConfig_
00364   //processname_="HLT";
00365   bool changed(true);
00366   _hlt_initialized = hltConfig_.init(iRun,iSetup,processname_,changed);
00367   if (!_hlt_initialized) {
00368   //if (!hltConfig_.init(iRun,iSetup,processname_,changed)) {
00369     processname_ = "FU";
00370     _hlt_initialized = hltConfig_.init(iRun,iSetup,processname_,changed);
00371     if(!_hlt_initialized){
00372       //if (!hltConfig_.init(iRun,iSetup,processname_,changed)){
00373       LogDebug("JetMETAnalyzer") << "HLTConfigProvider failed to initialize.";
00374     }
00375   }
00376   
00377   /*
00378   hltpathME = 0;
00379   if (_hlt_initialized) {
00380     //if (hltConfig_.init(iRun,iSetup,processname_,changed)) {
00381     if (hltConfig_.size()){
00382       dbe->setCurrentFolder("JetMET");
00383       hltpathME = dbe->book1D("hltpath", "hltpath", 300, 0., 300.);
00384     }
00385     
00386     for (unsigned int j=0; j!=hltConfig_.size(); ++j) {
00387       if (hltpathME) hltpathME->setBinLabel(j+1,hltConfig_.triggerName(j));
00388       // if (hltConfig_.triggerName(j)=="HLT_PhysicsDeclared") 
00389     }
00390   }
00391   */ 
00392   //
00393   //--- Jet
00394 
00395   //
00396   //--- MET
00397   if(theCaloMETAnalyzerFlag){
00398     theCaloMETAnalyzer->beginRun(iRun, iSetup);
00399     //theCaloMETNoHFAnalyzer->beginRun(iRun, iSetup);
00400     //theCaloMETHOAnalyzer->beginRun(iRun, iSetup);
00401     //theCaloMETNoHFHOAnalyzer->beginRun(iRun, iSetup);
00402   }
00403   if(theTcMETAnalyzerFlag) theTcMETAnalyzer->beginRun(iRun, iSetup);
00404   if(theMuCorrMETAnalyzerFlag) theMuCorrMETAnalyzer->beginRun(iRun, iSetup);
00405   if(thePfMETAnalyzerFlag) thePfMETAnalyzer->beginRun(iRun, iSetup);
00406   //if(theHTMHTAnalyzerFlag) theHTMHTAnalyzer->beginRun(iRun, iSetup);
00407 
00408 }
00409 
00410 // ***********************************************************
00411 void JetMETAnalyzer::endRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
00412 {
00413   //
00414   //--- Jet
00415 
00416   //
00417   //--- MET
00418   if(theCaloMETAnalyzerFlag){
00419     theCaloMETAnalyzer->endRun(iRun, iSetup, dbe);
00420     //theCaloMETNoHFAnalyzer->endRun(iRun, iSetup, dbe);
00421     //theCaloMETHOAnalyzer->endRun(iRun, iSetup, dbe);
00422     //theCaloMETNoHFHOAnalyzer->endRun(iRun, iSetup, dbe);
00423   }
00424   if(theTcMETAnalyzerFlag)     theTcMETAnalyzer->endRun(iRun, iSetup, dbe);
00425   if(theMuCorrMETAnalyzerFlag) theMuCorrMETAnalyzer->endRun(iRun, iSetup, dbe);
00426   if(thePfMETAnalyzerFlag)     thePfMETAnalyzer->endRun(iRun, iSetup, dbe);
00427   //if(theHTMHTAnalyzerFlag)    theHTMHTAnalyzer->endRun(iRun, iSetup, dbe);
00428 
00429 }
00430 
00431 // ***********************************************************
00432 void JetMETAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00433 
00434   LogTrace(metname)<<"[JetMETAnalyzer] Analysis of event # ";
00435 
00436   // *** Fill lumisection ME
00437   int myLuminosityBlock;
00438   myLuminosityBlock = iEvent.luminosityBlock();
00439   lumisecME->Fill(myLuminosityBlock);
00440 
00441   if (myLuminosityBlock<_LSBegin) return;
00442   if (myLuminosityBlock>_LSEnd && _LSEnd>0) return;
00443 
00444   // **** Get the TriggerResults container
00445   edm::Handle<TriggerResults> triggerResults;
00446   iEvent.getByLabel(theTriggerResultsLabel, triggerResults);
00447 
00448   bool bPhysicsDeclared = false;
00449   if(!_doHLTPhysicsOn) bPhysicsDeclared = true;
00450 
00451   Int_t JetLoPass = 0;
00452   Int_t JetHiPass = 0;
00453 
00454   if (triggerResults.isValid()){
00455     const edm::TriggerNames & triggerNames = iEvent.triggerNames(*triggerResults);
00456     
00457     if( triggerNames.triggerIndex("HLT_PhysicsDeclared") != triggerNames.size() )
00458       if (triggerResults->accept(triggerNames.triggerIndex("HLT_PhysicsDeclared"))) {
00459         if(_doHLTPhysicsOn) bPhysicsDeclared = true;
00460       }
00461 
00462     /*
00463     //sanity check
00464     if (_hlt_initialized && hltConfig_.size() && triggerResults->size()==hltConfig_.size()){
00465       //check the trigger results
00466       for (unsigned int j=0; j!=hltConfig_.size(); ++j) {
00467         if (triggerResults->accept(j)){
00468           if (hltpathME) hltpathME->Fill(j);
00469         }
00470       }
00471     }
00472     */
00473     const unsigned int nTrig(triggerNames.size());
00474     for (unsigned int i=0;i<nTrig;++i)
00475       {
00476         if (triggerNames.triggerName(i).find(highPtJetExpr_[0].substr(0,highPtJetExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults->accept(i))
00477           JetHiPass=1;
00478         else if (triggerNames.triggerName(i).find(lowPtJetExpr_[0].substr(0,lowPtJetExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults->accept(i))
00479           JetLoPass=1;
00480       }
00481     
00482   }
00483   
00484   if (DEBUG)  std::cout << "trigger label " << theTriggerResultsLabel << std::endl;
00485 
00486   /*
00487     if ( _HighPtJetEventFlag->on() && _HighPtJetEventFlag->accept( iEvent, iSetup) )
00488     JetHiPass=1;
00489     
00490     if ( _LowPtJetEventFlag->on() && _LowPtJetEventFlag->accept( iEvent, iSetup) )
00491     JetLoPass=1;
00492   */
00493   
00494   if (DEBUG) {
00495     std::cout << ">>> Trigger  Lo = " <<  JetLoPass
00496               <<             " Hi = " <<  JetHiPass
00497               << std::endl;
00498   }
00499 
00500   // ==========================================================
00501   //Vertex information
00502 
00503   int _numPV = 0;
00504   bool bPrimaryVertex = true;
00505   if(_doPVCheck){
00506     bPrimaryVertex = false;
00507     Handle<reco::VertexCollection> vertexHandle;
00508 
00509     iEvent.getByLabel(_theVertexLabel, vertexHandle);
00510 
00511     if (!vertexHandle.isValid()) {
00512       LogInfo("JetMETAnalyzer") << "JetMETAnalyzer: Could not find vertex collection" << std::endl;
00513       if (DEBUG) std::cout << "JetMETAnalyzer: Could not find vertex collection" << std::endl;
00514     }
00515     
00516     if ( vertexHandle.isValid() ){
00517       reco::VertexCollection vertexCollection = *(vertexHandle.product());
00518       int vertex_number     = vertexCollection.size();
00519       reco::VertexCollection::const_iterator v = vertexCollection.begin();
00520       for ( ; v != vertexCollection.end(); ++v) {
00521         double vertex_chi2    = v->normalizedChi2();
00522         double vertex_ndof    = v->ndof();
00523         bool   fakeVtx        = v->isFake();
00524         double vertex_Z       = v->z();
00525         
00526         if (  !fakeVtx
00527               && vertex_number>=_nvtx_min
00528               && vertex_ndof   >_vtxndof_min
00529               && vertex_chi2   <_vtxchi2_max
00530               && fabs(vertex_Z)<_vtxz_max ) {
00531           bPrimaryVertex = true;
00532           ++_numPV;
00533         }
00534       }
00535     }
00536   }
00537   verticesME->Fill(_numPV);
00538   // ==========================================================
00539 
00540   edm::Handle< L1GlobalTriggerReadoutRecord > gtReadoutRecord;
00541   iEvent.getByLabel( _theGTLabel, gtReadoutRecord);
00542 
00543   if (!gtReadoutRecord.isValid()) {
00544     LogInfo("JetMETAnalyzer") << "JetMETAnalyzer: Could not find GT readout record" << std::endl;
00545     if (DEBUG) std::cout << "JetMETAnalyzer: Could not find GT readout record product" << std::endl;
00546   }
00547   
00548   bool bTechTriggers    = true;
00549   bool bTechTriggersAND = true;
00550   bool bTechTriggersOR  = false;
00551   bool bTechTriggersNOT = false;
00552 
00553   if (gtReadoutRecord.isValid()) {
00554     const TechnicalTriggerWord&  technicalTriggerWordBeforeMask = gtReadoutRecord->technicalTriggerWord();
00555 
00556     if (_techTrigsAND.size() == 0)
00557       bTechTriggersAND = true;
00558     else
00559       for (unsigned ttr = 0; ttr != _techTrigsAND.size(); ttr++) {
00560         bTechTriggersAND = bTechTriggersAND && technicalTriggerWordBeforeMask.at(_techTrigsAND.at(ttr));
00561       }
00562     
00563     if (_techTrigsAND.size() == 0)
00564       bTechTriggersOR = true;
00565     else
00566       for (unsigned ttr = 0; ttr != _techTrigsOR.size(); ttr++) {
00567         bTechTriggersOR = bTechTriggersOR || technicalTriggerWordBeforeMask.at(_techTrigsOR.at(ttr));
00568       }
00569     if (_techTrigsNOT.size() == 0)
00570       bTechTriggersNOT = false;
00571     else
00572       for (unsigned ttr = 0; ttr != _techTrigsNOT.size(); ttr++) {
00573         bTechTriggersNOT = bTechTriggersNOT || technicalTriggerWordBeforeMask.at(_techTrigsNOT.at(ttr));
00574       }
00575   }
00576   else
00577     {
00578       bTechTriggersAND = true;
00579       bTechTriggersOR  = true;
00580       bTechTriggersNOT = false;
00581     }  
00582 
00583   if (_techTrigsAND.size()==0)
00584     bTechTriggersAND = true;
00585   if (_techTrigsOR.size()==0)
00586     bTechTriggersOR = true;
00587   if (_techTrigsNOT.size()==0)
00588     bTechTriggersNOT = false;
00589   
00590   bTechTriggers = bTechTriggersAND && bTechTriggersOR && !bTechTriggersNOT;
00591     
00592   bool bJetCleanup = bTechTriggers && bPrimaryVertex && bPhysicsDeclared;
00593   
00594   DCSFilterAll->filter(iEvent, iSetup);
00595   if (bPrimaryVertex) cleanupME->Fill(0.5);
00596   if ( DCSFilterAll->passPIX      ) cleanupME->Fill(1.5);
00597   if ( DCSFilterAll->passSiStrip  ) cleanupME->Fill(2.5);
00598   if ( DCSFilterAll->passECAL     ) cleanupME->Fill(3.5);
00599   if ( DCSFilterAll->passES       ) cleanupME->Fill(4.5);
00600   if ( DCSFilterAll->passHBHE     ) cleanupME->Fill(5.5);
00601   if ( DCSFilterAll->passHF       ) cleanupME->Fill(6.5);
00602   if ( DCSFilterAll->passHO       ) cleanupME->Fill(7.5);
00603   if ( DCSFilterAll->passMuon     ) cleanupME->Fill(8.5);
00604 
00605   // **** Get the Calo Jet container
00606   edm::Handle<reco::CaloJetCollection> caloJets;
00607   
00608 
00609   // **** Get the AntiKt Jet container
00610   iEvent.getByLabel(theAKJetCollectionLabel, caloJets);    
00611   if(caloJets.isValid()) {
00612 
00613   if(theJetAnalyzerFlag){
00614     theAKJetAnalyzer->setJetHiPass(JetHiPass);
00615     theAKJetAnalyzer->setJetLoPass(JetLoPass);
00616     theAKJetAnalyzer->analyze(iEvent, iSetup, *caloJets, _numPV);
00617   }
00618   if(theJetPtAnalyzerFlag){
00619     LogTrace(metname)<<"[JetMETAnalyzer] Call to the Jet Pt anti-Kt analyzer";
00620     thePtAKJetAnalyzer->analyze(iEvent, iSetup, *caloJets);
00621   }
00622 
00623   }
00624 
00625   if(caloJets.isValid() && bJetCleanup) {
00626   if(DCSFilterCalo->filter(iEvent, iSetup)){
00627   if(theJetCleaningFlag){
00628     theCleanedAKJetAnalyzer->setJetHiPass(JetHiPass);
00629     theCleanedAKJetAnalyzer->setJetLoPass(JetLoPass);
00630     theCleanedAKJetAnalyzer->analyze(iEvent, iSetup, *caloJets, _numPV);
00631   }
00632   if(theJetPtCleaningFlag){
00633     LogTrace(metname)<<"[JetMETAnalyzer] Call to the Cleaned Jet Pt anti-Kt analyzer";
00634     theCleanedPtAKJetAnalyzer->analyze(iEvent, iSetup, *caloJets);
00635   }
00636   } // DCS
00637   } // caloJets.isValid()
00638 
00639   if(caloJets.isValid() && bJetCleanup){
00640   if(DCSFilterCalo->filter(iEvent, iSetup)){
00641     if(theDiJetSelectionFlag){
00642       theDiJetAnalyzer->analyze(iEvent, iSetup, *caloJets, _numPV);
00643     }
00644   } // DCS
00645   } // caloJets.isValid()
00646 
00647 
00648   if(caloJets.isValid()){
00649     if(theJetPtAnalyzerFlag){
00650       LogTrace(metname)<<"[JetMETAnalyzer] Call to the Jet Pt anti-Kt analyzer";
00651       thePtAKJetAnalyzer->analyze(iEvent, iSetup, *caloJets);
00652     }
00653   }
00654 
00655   if(caloJets.isValid() && bJetCleanup){
00656   if(DCSFilterCalo->filter(iEvent, iSetup)){
00657     if(theJetPtCleaningFlag){
00658       LogTrace(metname)<<"[JetMETAnalyzer] Call to the Cleaned Jet Pt anti-Kt analyzer";
00659       theCleanedPtAKJetAnalyzer->analyze(iEvent, iSetup, *caloJets);
00660     }
00661   } // DCS
00662   } // caloJets.isValid() 
00663   
00664   // **** Get the SISCone Jet container
00665   iEvent.getByLabel(theSCJetCollectionLabel, caloJets);    
00666   if(theSConeJetAnalyzerFlag){
00667     if(caloJets.isValid()){
00668       if(theJetAnalyzerFlag){
00669         theSCJetAnalyzer->setJetHiPass(JetHiPass);
00670         theSCJetAnalyzer->setJetLoPass(JetLoPass);
00671         theSCJetAnalyzer->analyze(iEvent, iSetup, *caloJets, _numPV);
00672       }
00673       if(theJetPtAnalyzerFlag){
00674         LogTrace(metname)<<"[JetMETAnalyzer] Call to the Jet Pt SisCone analyzer";
00675         thePtSCJetAnalyzer->analyze(iEvent, iSetup, *caloJets);
00676       }
00677     }
00678     
00679     if(caloJets.isValid() && bJetCleanup){
00680     if(DCSFilterCalo->filter(iEvent, iSetup)){
00681       if(theJetCleaningFlag){
00682         theCleanedSCJetAnalyzer->setJetHiPass(JetHiPass);
00683         theCleanedSCJetAnalyzer->setJetLoPass(JetLoPass);
00684         theCleanedSCJetAnalyzer->analyze(iEvent, iSetup, *caloJets, _numPV);
00685       }
00686       if(theJetPtCleaningFlag){
00687         LogTrace(metname)<<"[JetMETAnalyzer] Call to the Cleaned Jet Pt SisCone analyzer";
00688         theCleanedPtSCJetAnalyzer->analyze(iEvent, iSetup, *caloJets);
00689       }
00690     } // DCS
00691     } // caloJets.isValid()
00692   }
00693   // **** Get the Iterative Cone Jet container  
00694   iEvent.getByLabel(theICJetCollectionLabel, caloJets);
00695   if(theIConeJetAnalyzerFlag) {
00696     if(caloJets.isValid()){
00697       if(theJetAnalyzerFlag){
00698         theICJetAnalyzer->setJetHiPass(JetHiPass);
00699         theICJetAnalyzer->setJetLoPass(JetLoPass);
00700         theICJetAnalyzer->analyze(iEvent, iSetup, *caloJets, _numPV);   
00701       }
00702       if(theJetPtAnalyzerFlag){
00703         LogTrace(metname)<<"[JetMETAnalyzer] Call to the Jet Pt ICone analyzer";
00704         thePtICJetAnalyzer->analyze(iEvent, iSetup, *caloJets);
00705       }
00706     }
00707     
00708     if(caloJets.isValid() && bJetCleanup){
00709     if(DCSFilterCalo->filter(iEvent, iSetup)){
00710       if(theJetCleaningFlag){
00711         theCleanedICJetAnalyzer->setJetHiPass(JetHiPass);
00712         theCleanedICJetAnalyzer->setJetLoPass(JetLoPass);
00713         theCleanedICJetAnalyzer->analyze(iEvent, iSetup, *caloJets, _numPV);
00714       }
00715       if(theJetPtCleaningFlag){
00716         LogTrace(metname)<<"[JetMETAnalyzer] Call to the Cleaned Jet Pt ICone analyzer";
00717         theCleanedPtICJetAnalyzer->analyze(iEvent, iSetup, *caloJets);
00718       }
00719     } // DCS
00720     } // isValid
00721   }
00722 
00723   // **** Get the JPT Jet container
00724   edm::Handle<reco::JPTJetCollection> jptJets;
00725   iEvent.getByLabel(theJPTJetCollectionLabel, jptJets);
00726   if(jptJets.isValid() && theJPTJetAnalyzerFlag){
00727     //theJPTJetAnalyzer->setJetHiPass(JetHiPass);
00728     //theJPTJetAnalyzer->setJetLoPass(JetLoPass);
00729     theJPTJetAnalyzer->analyze(iEvent, iSetup, *jptJets, _numPV);
00730   }
00731   
00732   if(jptJets.isValid() && bJetCleanup && theJPTJetCleaningFlag){
00733     if(DCSFilterJPT->filter(iEvent, iSetup)){
00734     //theCleanedJPTJetAnalyzer->setJetHiPass(JetHiPass);
00735     //theCleanedJPTJetAnalyzer->setJetLoPass(JetLoPass);
00736       theCleanedJPTJetAnalyzer->analyze(iEvent, iSetup, *jptJets, _numPV);
00737     }
00738   }
00739   
00740   // **** Get the PFlow Jet container
00741   edm::Handle<reco::PFJetCollection> pfJets;
00742   iEvent.getByLabel(thePFJetCollectionLabel, pfJets);
00743 
00744   if(pfJets.isValid()){
00745     if(thePFJetAnalyzerFlag){
00746       thePFJetAnalyzer->setJetHiPass(JetHiPass);
00747       thePFJetAnalyzer->setJetLoPass(JetLoPass);
00748       LogTrace(metname)<<"[JetMETAnalyzer] Call to the PFJet analyzer";
00749       thePFJetAnalyzer->analyze(iEvent, iSetup, *pfJets, _numPV);
00750       }
00751     if(thePFJetCleaningFlag){
00752       if(DCSFilterPF->filter(iEvent, iSetup)){
00753         theCleanedPFJetAnalyzer->setJetHiPass(JetHiPass);
00754         theCleanedPFJetAnalyzer->setJetLoPass(JetLoPass);
00755         LogTrace(metname)<<"[JetMETAnalyzer] Call to the Cleaned PFJet analyzer";
00756         theCleanedPFJetAnalyzer->analyze(iEvent, iSetup, *pfJets, _numPV);
00757         if(theDiJetSelectionFlag){
00758           thePFDiJetAnalyzer->analyze(iEvent, iSetup, *pfJets, _numPV);
00759         }
00760       } // DCS
00761     }  
00762   } else {
00763     if (DEBUG) LogTrace(metname)<<"[JetMETAnalyzer] pfjets NOT VALID!!";
00764   }
00765    
00766   //
00767   // **** CaloMETAnalyzer **** //
00768   //
00769   if(theCaloMETAnalyzerFlag){
00770      
00771     theCaloMETAnalyzer->analyze(iEvent,       iSetup, *triggerResults);
00772     //theCaloMETNoHFAnalyzer->analyze(iEvent,   iSetup, *triggerResults);
00773     //theCaloMETHOAnalyzer->analyze(iEvent,     iSetup, *triggerResults);
00774     //theCaloMETNoHFHOAnalyzer->analyze(iEvent, iSetup, *triggerResults);
00775   }
00776 
00777   //
00778   // **** TcMETAnalyzer **** //
00779   //
00780   if(theTcMETAnalyzerFlag){
00781      
00782     theTcMETAnalyzer->analyze(iEvent, iSetup, *triggerResults);
00783      
00784   }
00785 
00786   //
00787   // **** MuCorrMETAnalyzer **** //
00788   //
00789   if(theMuCorrMETAnalyzerFlag){
00790      
00791     theMuCorrMETAnalyzer->analyze(iEvent, iSetup, *triggerResults);
00792      
00793   }
00794    
00795   //
00796   // **** PfMETAnalyzer **** //
00797   //
00798   if(thePfMETAnalyzerFlag){
00799      
00800     thePfMETAnalyzer->analyze(iEvent, iSetup, *triggerResults);
00801      
00802   }
00803    
00804   //
00805   // **** HTMHTAnalyzer **** //
00806   //
00807   if(theHTMHTAnalyzerFlag){
00808     
00809     theHTMHTAnalyzer->analyze(iEvent, iSetup, *triggerResults);
00810     
00811   }
00812 
00813 }
00814 
00815 // ***********************************************************
00816 void JetMETAnalyzer::endJob(void) {
00817   LogTrace(metname)<<"[JetMETAnalyzer] Saving the histos";
00818   bool outputMEsInRootFile   = parameters.getParameter<bool>("OutputMEsInRootFile");
00819   std::string outputFileName = parameters.getParameter<std::string>("OutputFileName");
00820 
00821 
00822   //--- MET
00823   if(theCaloMETAnalyzerFlag){
00824     theCaloMETAnalyzer->endJob();
00825     //theCaloMETNoHFAnalyzer->endJob();
00826     //theCaloMETHOAnalyzer->endJob();
00827     //theCaloMETNoHFHOAnalyzer->endJob();
00828   }
00829   if(theTcMETAnalyzerFlag) theTcMETAnalyzer->endJob();
00830   if(theMuCorrMETAnalyzerFlag) theMuCorrMETAnalyzer->endJob();
00831   if(thePfMETAnalyzerFlag)   thePfMETAnalyzer->endJob();
00832   //if(theHTMHTAnalyzerFlag) theHTMHTAnalyzer->endJob();
00833   
00834   //--- Jet
00835   if(theJetAnalyzerFlag) { 
00836     theAKJetAnalyzer->endJob();
00837     if(theSConeJetAnalyzerFlag) theSCJetAnalyzer->endJob(); 
00838     if(theIConeJetAnalyzerFlag) theICJetAnalyzer->endJob();
00839   }
00840 
00841   if(theJetCleaningFlag) {
00842     theCleanedAKJetAnalyzer->endJob();
00843     if(theSConeJetAnalyzerFlag) theCleanedSCJetAnalyzer->endJob(); 
00844     if(theIConeJetAnalyzerFlag) theCleanedICJetAnalyzer->endJob();
00845   }
00846 
00847   if(theDiJetSelectionFlag) theDiJetAnalyzer->endJob();
00848 
00849   if(theJetPtAnalyzerFlag ) {
00850     thePtAKJetAnalyzer->endJob();
00851     if(theSConeJetAnalyzerFlag) thePtSCJetAnalyzer->endJob();
00852     if(theIConeJetAnalyzerFlag) thePtICJetAnalyzer->endJob();
00853   }
00854 
00855   if(theJetPtCleaningFlag ) {
00856     theCleanedPtAKJetAnalyzer->endJob();
00857     if(theSConeJetAnalyzerFlag) theCleanedPtSCJetAnalyzer->endJob();
00858     if(theIConeJetAnalyzerFlag) theCleanedPtICJetAnalyzer->endJob();
00859   }
00860 
00861   if(theJPTJetAnalyzerFlag)   theJPTJetAnalyzer->endJob();
00862   if(theJPTJetCleaningFlag)   theCleanedJPTJetAnalyzer->endJob();
00863 
00864   if(thePFJetAnalyzerFlag)  thePFJetAnalyzer->endJob();
00865   if(thePFJetCleaningFlag)  theCleanedPFJetAnalyzer->endJob();
00866   if(theDiJetSelectionFlag) thePFDiJetAnalyzer->endJob();
00867 
00868   if(outputMEsInRootFile){
00869     dbe->save(outputFileName);
00870   }
00871   
00872 }
00873 
00874