CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQMOffline/JetMET/src/HTMHTAnalyzer.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2010/03/25 11:02:48 $
00005  *  $Revision: 1.7 $
00006  *  \author K. Hatakeyama - Rockefeller University
00007  */
00008 
00009 #include "DQMOffline/JetMET/interface/HTMHTAnalyzer.h"
00010 #include "DataFormats/Common/interface/Handle.h"
00011 #include "FWCore/Common/interface/TriggerNames.h"
00012 
00013 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00014 #include "DataFormats/JetReco/interface/CaloJet.h"
00015 
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017 
00018 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
00019 #include "DataFormats/CaloTowers/interface/CaloTowerDetId.h"
00020 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00021 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00022 
00023 #include "DataFormats/Math/interface/LorentzVector.h" 
00024 
00025 #include "TVector2.h"
00026 
00027 #include <string>
00028 using namespace edm;
00029 
00030 // ***********************************************************
00031 HTMHTAnalyzer::HTMHTAnalyzer(const edm::ParameterSet& pSet) {
00032 
00033   parameters = pSet;
00034   _ptThreshold = 30.;
00035 
00036 }
00037 
00038 // ***********************************************************
00039 HTMHTAnalyzer::~HTMHTAnalyzer() { }
00040 
00041 void HTMHTAnalyzer::beginJob(DQMStore * dbe) {
00042 
00043   evtCounter = 0;
00044   metname = "HTMHTAnalyzer";
00045 
00046   // PFMET information
00047   theJetCollectionForHTMHTLabel = parameters.getParameter<edm::InputTag>("JetCollectionForHTMHTLabel");
00048   _source                       = parameters.getParameter<std::string>("Source");
00049 
00050   LogTrace(metname)<<"[HTMHTAnalyzer] Parameters initialization";
00051   dbe->setCurrentFolder("JetMET/MET/"+_source);
00052 
00053   HLTPathsJetMBByName_ = parameters.getParameter<std::vector<std::string > >("HLTPathsJetMB");
00054 
00055   // misc
00056   _verbose     = parameters.getParameter<int>("verbose");
00057   _ptThreshold = parameters.getParameter<double>("ptThreshold");
00058 
00059   jetME = dbe->book1D("metReco", "metReco", 4, 1, 5);
00060   jetME->setBinLabel(4,"HTMHT",1);
00061 
00062   hNevents = dbe->book1D("METTask_Nevents",   "METTask_Nevents",   1,0,1);
00063   hNJets   = dbe->book1D("METTask_NJets",     "METTask_NJets",     100, 0, 100);
00064   hMHx     = dbe->book1D("METTask_MHx",       "METTask_MHx",       500,-500,500);
00065   hMHy     = dbe->book1D("METTask_MHy",       "METTask_MHy",       500,-500,500);
00066   hMHT     = dbe->book1D("METTask_MHT",       "METTask_MHT",       500,0,1000);
00067   hMHTPhi  = dbe->book1D("METTask_MhTPhi",    "METTask_MhTPhi",    80,-4,4);
00068   hHT      = dbe->book1D("METTask_HT",        "METTask_HT",        500,0,2000);
00069 
00070 }
00071 
00072  
00073 // ***********************************************************
00074 void HTMHTAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup, 
00075                               const edm::TriggerResults& triggerResults) {
00076 
00077   LogTrace(metname)<<"[HTMHTAnalyzer] Analyze HT & MHT";
00078 
00079   jetME->Fill(4);
00080 
00081   // ==========================================================  
00082   // Trigger information 
00083   //
00084   if(&triggerResults) {   
00085 
00087 
00088     //
00089     //
00090     // Check how many HLT triggers are in triggerResults 
00091     int ntrigs = triggerResults.size();
00092     if (_verbose) std::cout << "ntrigs=" << ntrigs << std::endl;
00093     
00094     //
00095     //
00096     // If index=ntrigs, this HLT trigger doesn't exist in the HLT table for this data.
00097     const edm::TriggerNames & triggerNames = iEvent.triggerNames(triggerResults);
00098     
00099     //
00100     //
00101     // count number of requested Jet or MB HLT paths which have fired
00102     for (unsigned int i=0; i!=HLTPathsJetMBByName_.size(); i++) {
00103       unsigned int triggerIndex = triggerNames.triggerIndex(HLTPathsJetMBByName_[i]);
00104       if (triggerIndex<triggerResults.size()) {
00105         if (triggerResults.accept(triggerIndex)) {
00106           _trig_JetMB++;
00107         }
00108       }
00109     }
00110     // for empty input vectors (n==0), take all HLT triggers!
00111     if (HLTPathsJetMBByName_.size()==0) _trig_JetMB=triggerResults.size()-1;
00112 
00113     if (_trig_JetMB==0) return;
00114 
00115   } else {
00116 
00117     edm::LogInfo("CaloMetAnalyzer") << "TriggerResults::HLT not found, "
00118       "automatically select events"; 
00119     //return;
00120     
00121   }
00122    
00123   // ==========================================================
00124 
00125   // **** Get the Calo Jet container
00126   edm::Handle<reco::CaloJetCollection> jetcoll;
00127 
00128   // **** Get the SISCone Jet container
00129   iEvent.getByLabel(theJetCollectionForHTMHTLabel, jetcoll);
00130 
00131   if(!jetcoll.isValid()) return;
00132 
00133   // ==========================================================
00134   // Reconstructed HT & MHT Information
00135 
00136   int    njet=0;
00137   double MHx=0.;
00138   double MHy=0.;
00139   double MHT=0.;
00140   double MHTPhi=0.;
00141   double HT=0.;
00142 
00143   for (reco::CaloJetCollection::const_iterator calojet = jetcoll->begin(); calojet!=jetcoll->end(); ++calojet){
00144     if (calojet->pt()>_ptThreshold){
00145       njet++;
00146       MHx += -1.*calojet->px();
00147       MHy += -1.*calojet->py();
00148       HT  += calojet->pt();
00149     }
00150   }
00151 
00152   TVector2 *tv2 = new TVector2(MHx,MHy);
00153   MHT   =tv2->Mod();
00154   MHTPhi=tv2->Phi();
00155 
00156   //std::cout << "HTMHT " << MHT << std::endl;
00157 
00158   hNevents->Fill(1.);
00159   hNJets->Fill(njet);
00160   if (njet>0){
00161     hMHx->Fill(MHx);
00162     hMHy->Fill(MHy);
00163     hMHT->Fill(MHT);
00164     hMHTPhi->Fill(MHTPhi);
00165     hHT->Fill(HT);
00166   }
00167 
00168 }