CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DQMOffline/JetMET/src/CaloMETAnalyzer.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2012/04/12 15:42:57 $
00005  *  $Revision: 1.66 $
00006  *  \author F. Chlebana - Fermilab
00007  *          K. Hatakeyama - Rockefeller University
00008  */
00009 
00010 #include "DQMOffline/JetMET/interface/CaloMETAnalyzer.h"
00011 #include "DataFormats/Common/interface/Handle.h"
00012 
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 #include "FWCore/Common/interface/TriggerNames.h"
00015 
00016 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
00017 #include "DataFormats/CaloTowers/interface/CaloTowerDetId.h"
00018 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00019 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00020 
00021 #include "DataFormats/Math/interface/LorentzVector.h"
00022 
00023 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
00024 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetup.h"
00025 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00026 
00027 #include "TLorentzVector.h"
00028 
00029 #include <string>
00030 using namespace edm;
00031 
00032 // ***********************************************************
00033 CaloMETAnalyzer::CaloMETAnalyzer(const edm::ParameterSet& pSet) {
00034 
00035   parameters = pSet;
00036 
00037   edm::ParameterSet highptjetparms = parameters.getParameter<edm::ParameterSet>("highPtJetTrigger");
00038   edm::ParameterSet lowptjetparms  = parameters.getParameter<edm::ParameterSet>("lowPtJetTrigger" );
00039   edm::ParameterSet minbiasparms   = parameters.getParameter<edm::ParameterSet>("minBiasTrigger"  );
00040   edm::ParameterSet highmetparms   = parameters.getParameter<edm::ParameterSet>("highMETTrigger"  );
00041   edm::ParameterSet lowmetparms    = parameters.getParameter<edm::ParameterSet>("lowMETTrigger"   );
00042   edm::ParameterSet eleparms       = parameters.getParameter<edm::ParameterSet>("eleTrigger"      );
00043   edm::ParameterSet muonparms      = parameters.getParameter<edm::ParameterSet>("muonTrigger"     );
00044 
00045   //genericTriggerEventFlag_( new GenericTriggerEventFlag( conf_ ) );
00046   _HighPtJetEventFlag = new GenericTriggerEventFlag( highptjetparms );
00047   _LowPtJetEventFlag  = new GenericTriggerEventFlag( lowptjetparms  );
00048   _MinBiasEventFlag   = new GenericTriggerEventFlag( minbiasparms   );
00049   _HighMETEventFlag   = new GenericTriggerEventFlag( highmetparms   );
00050   _LowMETEventFlag    = new GenericTriggerEventFlag( lowmetparms    );
00051   _EleEventFlag       = new GenericTriggerEventFlag( eleparms       );
00052   _MuonEventFlag      = new GenericTriggerEventFlag( muonparms      );
00053 
00054   highPtJetExpr_ = highptjetparms.getParameter<std::vector<std::string> >("hltPaths");
00055   lowPtJetExpr_  = lowptjetparms .getParameter<std::vector<std::string> >("hltPaths");
00056   highMETExpr_   = highmetparms  .getParameter<std::vector<std::string> >("hltPaths");
00057   lowMETExpr_    = lowmetparms   .getParameter<std::vector<std::string> >("hltPaths");
00058   muonExpr_      = muonparms     .getParameter<std::vector<std::string> >("hltPaths");
00059   elecExpr_      = eleparms      .getParameter<std::vector<std::string> >("hltPaths");
00060   minbiasExpr_   = minbiasparms  .getParameter<std::vector<std::string> >("hltPaths");
00061 
00062 }
00063 
00064 // ***********************************************************
00065 CaloMETAnalyzer::~CaloMETAnalyzer() { 
00066 
00067   delete _HighPtJetEventFlag;
00068   delete _LowPtJetEventFlag;
00069   delete _MinBiasEventFlag;
00070   delete _HighMETEventFlag;
00071   delete _LowMETEventFlag;
00072   delete _EleEventFlag;
00073   delete _MuonEventFlag;
00074 
00075 }
00076 
00077 // ***********************************************************
00078 void CaloMETAnalyzer::beginJob(DQMStore * dbe) {
00079 
00080   evtCounter = 0;
00081   metname = "caloMETAnalyzer";
00082 
00083   // trigger information
00084   HLTPathsJetMBByName_ = parameters.getParameter<std::vector<std::string > >("HLTPathsJetMB");
00085 
00086   theCleaningParameters = parameters.getParameter<ParameterSet>("CleaningParameters"),
00087 
00088   //Trigger parameters
00089   gtTag          = theCleaningParameters.getParameter<edm::InputTag>("gtLabel");
00090   _techTrigsAND  = theCleaningParameters.getParameter<std::vector<unsigned > >("techTrigsAND");
00091   _techTrigsOR   = theCleaningParameters.getParameter<std::vector<unsigned > >("techTrigsOR");
00092   _techTrigsNOT  = theCleaningParameters.getParameter<std::vector<unsigned > >("techTrigsNOT");
00093 
00094   _doHLTPhysicsOn = theCleaningParameters.getParameter<bool>("doHLTPhysicsOn");
00095   _hlt_PhysDec    = theCleaningParameters.getParameter<std::string>("HLT_PhysDec");
00096 
00097   _tightBHFiltering     = theCleaningParameters.getParameter<bool>("tightBHFiltering");
00098   _tightJetIDFiltering  = theCleaningParameters.getParameter<int>("tightJetIDFiltering");
00099   _tightHcalFiltering   = theCleaningParameters.getParameter<bool>("tightHcalFiltering");
00100 
00101   // ==========================================================
00102   //DCS information
00103   // ==========================================================
00104   DCSFilter = new JetMETDQMDCSFilter(parameters.getParameter<ParameterSet>("DCSFilter"));
00105 
00106   //Vertex requirements
00107   _doPVCheck          = theCleaningParameters.getParameter<bool>("doPrimaryVertexCheck");
00108   vertexTag  = theCleaningParameters.getParameter<edm::InputTag>("vertexLabel");
00109 
00110   if (_doPVCheck) {
00111     _nvtx_min        = theCleaningParameters.getParameter<int>("nvtx_min");
00112     _nvtxtrks_min    = theCleaningParameters.getParameter<int>("nvtxtrks_min");
00113     _vtxndof_min     = theCleaningParameters.getParameter<int>("vtxndof_min");
00114     _vtxchi2_max     = theCleaningParameters.getParameter<double>("vtxchi2_max");
00115     _vtxz_max        = theCleaningParameters.getParameter<double>("vtxz_max");
00116   }
00117 
00118 
00119   // CaloMET information
00120   theCaloMETCollectionLabel       = parameters.getParameter<edm::InputTag>("METCollectionLabel");
00121   _source                         = parameters.getParameter<std::string>("Source");
00122 
00123   if (theCaloMETCollectionLabel.label() == "corMetGlobalMuons" ) {
00124     inputBeamSpotLabel      = parameters.getParameter<edm::InputTag>("InputBeamSpotLabel");
00125   }
00126   
00127   // Other data collections
00128   theCaloTowersLabel          = parameters.getParameter<edm::InputTag>("CaloTowersLabel");
00129   theJetCollectionLabel       = parameters.getParameter<edm::InputTag>("JetCollectionLabel");
00130   HcalNoiseRBXCollectionTag   = parameters.getParameter<edm::InputTag>("HcalNoiseRBXCollection");
00131   HcalNoiseSummaryTag         = parameters.getParameter<edm::InputTag>("HcalNoiseSummary");
00132   BeamHaloSummaryTag          = parameters.getParameter<edm::InputTag>("BeamHaloSummaryLabel");
00133 
00134   // misc
00135   _verbose     = parameters.getParameter<int>("verbose");
00136   _print       = parameters.getParameter<int>("printOut");
00137   _etThreshold = parameters.getParameter<double>("etThreshold"); // MET threshold
00138   _allhist     = parameters.getParameter<bool>("allHist");       // Full set of monitoring histograms
00139   _allSelection= parameters.getParameter<bool>("allSelection");  // Plot with all sets of event selection
00140   _cleanupSelection= parameters.getParameter<bool>("cleanupSelection");  // Plot with all sets of event selection
00141 
00142   _highPtJetThreshold = parameters.getParameter<double>("HighPtJetThreshold"); // High Pt Jet threshold
00143   _lowPtJetThreshold = parameters.getParameter<double>("LowPtJetThreshold"); // Low Pt Jet threshold
00144   _highMETThreshold = parameters.getParameter<double>("HighMETThreshold"); // High MET threshold
00145   _lowMETThreshold = parameters.getParameter<double>("LowMETThreshold"); // Low MET threshold
00146 
00147   //
00148   jetID = new reco::helper::JetIDHelper(parameters.getParameter<ParameterSet>("JetIDParams"));
00149 
00150   // DQStore stuff
00151   LogTrace(metname)<<"[CaloMETAnalyzer] Parameters initialization";
00152   std::string DirName = "JetMET/MET/"+_source;
00153   dbe->setCurrentFolder(DirName);
00154 
00155   hmetME = dbe->book1D("metReco", "metReco", 4, 1, 5);
00156   hmetME->setBinLabel(1,"CaloMET",1);
00157 
00158   _dbe = dbe;
00159 
00160   _FolderNames.push_back("All");
00161   _FolderNames.push_back("BasicCleanup");
00162   _FolderNames.push_back("ExtraCleanup");
00163   _FolderNames.push_back("HcalNoiseFilter");
00164   _FolderNames.push_back("HcalNoiseFilterTight");
00165   _FolderNames.push_back("JetIDMinimal");
00166   _FolderNames.push_back("JetIDLoose");
00167   _FolderNames.push_back("JetIDTight");
00168   _FolderNames.push_back("BeamHaloIDTightPass");
00169   _FolderNames.push_back("BeamHaloIDLoosePass");
00170   _FolderNames.push_back("Triggers");
00171   _FolderNames.push_back("PV");
00172 
00173   for (std::vector<std::string>::const_iterator ic = _FolderNames.begin(); 
00174        ic != _FolderNames.end(); ic++){
00175     if (*ic=="All")             bookMESet(DirName+"/"+*ic);
00176     if (_cleanupSelection){
00177     if (*ic=="BasicCleanup")    bookMESet(DirName+"/"+*ic);
00178     if (*ic=="ExtraCleanup")    bookMESet(DirName+"/"+*ic);
00179     }
00180     if (_allSelection){
00181     if (*ic=="HcalNoiseFilter")      bookMESet(DirName+"/"+*ic);
00182     if (*ic=="HcalNoiseFilterTight") bookMESet(DirName+"/"+*ic);
00183     if (*ic=="JetIDMinimal")         bookMESet(DirName+"/"+*ic);
00184     if (*ic=="JetIDLoose")           bookMESet(DirName+"/"+*ic);
00185     if (*ic=="JetIDTight")           bookMESet(DirName+"/"+*ic);
00186     if (*ic=="BeamHaloIDTightPass")  bookMESet(DirName+"/"+*ic);
00187     if (*ic=="BeamHaloIDLoosePass")  bookMESet(DirName+"/"+*ic);
00188     if (*ic=="Triggers")             bookMESet(DirName+"/"+*ic);
00189     if (*ic=="PV")                   bookMESet(DirName+"/"+*ic);
00190     }
00191   }
00192 
00193 }
00194 
00195 // ***********************************************************
00196 void CaloMETAnalyzer::endJob() {
00197 
00198   delete jetID;
00199   delete DCSFilter;
00200 
00201 }
00202 
00203 // ***********************************************************
00204 void CaloMETAnalyzer::bookMESet(std::string DirName)
00205 {
00206   bool bLumiSecPlot=false;
00207   if (DirName.find("All")!=std::string::npos) bLumiSecPlot=true;
00208 
00209   bookMonitorElement(DirName,bLumiSecPlot);
00210 
00211   if ( _HighPtJetEventFlag->on() ) {
00212     bookMonitorElementTriggered(DirName+"/"+"HighPtJet",false);
00213     hTriggerName_HighPtJet = _dbe->bookString("triggerName_HighPtJet", highPtJetExpr_[0]);
00214   }  
00215 
00216   if ( _LowPtJetEventFlag->on() ) {
00217     bookMonitorElementTriggered(DirName+"/"+"LowPtJet",false);
00218     hTriggerName_LowPtJet = _dbe->bookString("triggerName_LowPtJet", lowPtJetExpr_[0]);
00219   }
00220 
00221   if ( _MinBiasEventFlag->on() ) {
00222     bookMonitorElementTriggered(DirName+"/"+"MinBias",false);
00223     hTriggerName_MinBias = _dbe->bookString("triggerName_MinBias", minbiasExpr_[0]);
00224     if (_verbose) std::cout << "_MinBiasEventFlag is on, folder created\n";
00225   }
00226 
00227   if ( _HighMETEventFlag->on() ) {
00228     bookMonitorElementTriggered(DirName+"/"+"HighMET",false);
00229     hTriggerName_HighMET = _dbe->bookString("triggerName_HighMET", highMETExpr_[0]);
00230   }
00231 
00232   if ( _LowMETEventFlag->on() ) {
00233     bookMonitorElementTriggered(DirName+"/"+"LowMET",false);
00234     hTriggerName_LowMET = _dbe->bookString("triggerName_LowMET", lowMETExpr_[0]);
00235   }
00236 
00237   if ( _EleEventFlag->on() ) {
00238     bookMonitorElementTriggered(DirName+"/"+"Ele",false);
00239     hTriggerName_Ele = _dbe->bookString("triggerName_Ele", elecExpr_[0]);
00240     if (_verbose) std::cout << "_EleEventFlag is on, folder created\n";
00241   }
00242 
00243   if ( _MuonEventFlag->on() ) {
00244     bookMonitorElementTriggered(DirName+"/"+"Muon",false);
00245     hTriggerName_Muon = _dbe->bookString("triggerName_Muon", muonExpr_[0]);
00246     if (_verbose) std::cout << "_MuonEventFlag is on, folder created\n";
00247   }
00248 }  
00249 
00250 // ***********************************************************
00251 void CaloMETAnalyzer::bookMonitorElement(std::string DirName, bool bLumiSecPlot=false)
00252 {
00253   if (_verbose) std::cout << "bookMonitorElement " << DirName << std::endl;
00254   _dbe->setCurrentFolder(DirName);
00255 
00256   bookMonitorElementTriggered(DirName, bLumiSecPlot);
00257   /*
00258   //hNevents                = _dbe->book1D("METTask_Nevents",   "METTask_Nevents"   ,1,0,1);
00259   hCaloMEx                = _dbe->book1D("METTask_CaloMEx",   "METTask_CaloMEx"   ,100,-500,500);
00260   hCaloMEx->setAxisTitle("MEx [GeV]",1);
00261   hCaloMEy                = _dbe->book1D("METTask_CaloMEy",   "METTask_CaloMEy"   ,100,-500,500); 
00262   hCaloMEy->setAxisTitle("MEy [GeV]",1);
00263   hCaloMETSig             = _dbe->book1D("METTask_CaloMETSig","METTask_CaloMETSig",51,0,51);
00264   hCaloMETSig->setAxisTitle("METSig",1);
00265   hCaloMET                = _dbe->book1D("METTask_CaloMET",   "METTask_CaloMET"   ,100,0,1000); 
00266   hCaloMET->setAxisTitle("MET [GeV]",1);
00267   hCaloMET1               = _dbe->book1D("METTask_CaloMET1",  "METTask_CaloMET1"  ,40,0,200);
00268   //meCaloMET->getTH1F()->SetStats(111111);
00269   //meCaloMET->getTH1F()->SetOption("logy");
00270   hCaloMETPhi             = _dbe->book1D("METTask_CaloMETPhi","METTask_CaloMETPhi",60,-TMath::Pi(),TMath::Pi()); 
00271   hCaloMETPhi->setAxisTitle("METPhi [rad]",1);
00272   hCaloSumET              = _dbe->book1D("METTask_CaloSumET", "METTask_CaloSumET" ,400,0,2000); 
00273   hCaloSumET->setAxisTitle("SumET [GeV]",1);
00274 
00275   hCaloMETNoHF                = _dbe->book1D("METTask_CaloMETNoHF",   "METTask_CaloMETNoHF"   ,100,0,1000); 
00276   hCaloMETNoHF->setAxisTitle("MET (No HF) [GeV]",1);
00277 
00278   hCaloMET_logx           = _dbe->book1D("METTask_CaloMET_logx",   "METTask_CaloMET_logx"   ,40,-1.,7.);
00279   hCaloMET_logx->setAxisTitle("log(MET) [GeV]",1);
00280   hCaloSumET_logx         = _dbe->book1D("METTask_CaloSumET_logx", "METTask_CaloSumET_logx" ,40,-1.,7.);
00281   hCaloSumET_logx->setAxisTitle("log(SumET) [GeV]",1);
00282   //  hCaloMETIonFeedbck      = _dbe->book1D("METTask_CaloMETIonFeedbck", "METTask_CaloMETIonFeedbck" ,500,0,1000);
00283   //  hCaloMETIonFeedbck->setAxisTitle("MET [GeV]",1);
00284   //  hCaloMETHPDNoise        = _dbe->book1D("METTask_CaloMETHPDNoise",   "METTask_CaloMETHPDNoise"   ,500,0,1000);
00285   //  hCaloMETHPDNoise->setAxisTitle("MET [GeV]",1);
00286   //  hCaloMETRBXNoise        = _dbe->book1D("METTask_CaloMETRBXNoise",   "METTask_CaloMETRBXNoise"   ,500,0,1000);
00287   //  hCaloMETRBXNoise->setAxisTitle("MET [GeV]",1);
00288 
00289   //  hCaloMETPhi002          = _dbe->book1D("METTask_CaloMETPhi002","METTask_CaloMETPhi002",60,-TMath::Pi(),TMath::Pi());
00290   //  hCaloMETPhi002->setAxisTitle("METPhi [rad] (MET>2 GeV)",1);
00291   //  hCaloMETPhi010          = _dbe->book1D("METTask_CaloMETPhi010","METTask_CaloMETPhi010",60,-TMath::Pi(),TMath::Pi());
00292   //  hCaloMETPhi010->setAxisTitle("METPhi [rad] (MET>10 GeV)",1);
00293   hCaloMETPhi020          = _dbe->book1D("METTask_CaloMETPhi020","METTask_CaloMETPhi020",60,-TMath::Pi(),TMath::Pi());
00294   hCaloMETPhi020->setAxisTitle("METPhi [rad] (MET>20 GeV)",1);
00295   */
00296   if (_allhist){
00297     /*
00298     if (bLumiSecPlot){
00299       hCaloMExLS              = _dbe->book2D("METTask_CaloMEx_LS","METTask_CaloMEx_LS",200,-200,200,50,0.,500.);
00300       hCaloMExLS->setAxisTitle("MEx [GeV]",1);
00301       hCaloMExLS->setAxisTitle("Lumi Section",2);
00302       hCaloMEyLS              = _dbe->book2D("METTask_CaloMEy_LS","METTask_CaloMEy_LS",200,-200,200,50,0.,500.);
00303       hCaloMEyLS->setAxisTitle("MEy [GeV]",1);
00304       hCaloMEyLS->setAxisTitle("Lumi Section",2);
00305     }
00306     */
00307     hCaloMaxEtInEmTowers    = _dbe->book1D("METTask_CaloMaxEtInEmTowers",   "METTask_CaloMaxEtInEmTowers"   ,100,0,2000);
00308     hCaloMaxEtInEmTowers->setAxisTitle("Et(Max) in EM Tower [GeV]",1);
00309     hCaloMaxEtInHadTowers   = _dbe->book1D("METTask_CaloMaxEtInHadTowers",  "METTask_CaloMaxEtInHadTowers"  ,100,0,2000);
00310     hCaloMaxEtInHadTowers->setAxisTitle("Et(Max) in Had Tower [GeV]",1);
00311     /*
00312     hCaloEtFractionHadronic = _dbe->book1D("METTask_CaloEtFractionHadronic","METTask_CaloEtFractionHadronic",100,0,1);
00313     hCaloEtFractionHadronic->setAxisTitle("Hadronic Et Fraction",1);
00314     hCaloEmEtFraction       = _dbe->book1D("METTask_CaloEmEtFraction",      "METTask_CaloEmEtFraction"      ,100,0,1);
00315     hCaloEmEtFraction->setAxisTitle("EM Et Fraction",1);
00316 
00317     //hCaloEmEtFraction002    = _dbe->book1D("METTask_CaloEmEtFraction002",   "METTask_CaloEmEtFraction002"      ,100,0,1);
00318     //hCaloEmEtFraction002->setAxisTitle("EM Et Fraction (MET>2 GeV)",1);
00319     //hCaloEmEtFraction010    = _dbe->book1D("METTask_CaloEmEtFraction010",   "METTask_CaloEmEtFraction010"      ,100,0,1);
00320     //hCaloEmEtFraction010->setAxisTitle("EM Et Fraction (MET>10 GeV)",1);
00321     hCaloEmEtFraction020    = _dbe->book1D("METTask_CaloEmEtFraction020",   "METTask_CaloEmEtFraction020"      ,100,0,1);
00322     hCaloEmEtFraction020->setAxisTitle("EM Et Fraction (MET>20 GeV)",1);
00323     */
00324     hCaloHadEtInHB          = _dbe->book1D("METTask_CaloHadEtInHB","METTask_CaloHadEtInHB",100,0,2000);
00325     hCaloHadEtInHB->setAxisTitle("Had Et [GeV]",1);
00326     hCaloHadEtInHO          = _dbe->book1D("METTask_CaloHadEtInHO","METTask_CaloHadEtInHO",25,0,500);
00327     hCaloHadEtInHO->setAxisTitle("Had Et [GeV]",1);
00328     hCaloHadEtInHE          = _dbe->book1D("METTask_CaloHadEtInHE","METTask_CaloHadEtInHE",100,0,2000);
00329     hCaloHadEtInHE->setAxisTitle("Had Et [GeV]",1);
00330     hCaloHadEtInHF          = _dbe->book1D("METTask_CaloHadEtInHF","METTask_CaloHadEtInHF",50,0,1000);
00331     hCaloHadEtInHF->setAxisTitle("Had Et [GeV]",1);
00332     hCaloEmEtInHF           = _dbe->book1D("METTask_CaloEmEtInHF" ,"METTask_CaloEmEtInHF" ,25,0,500);
00333     hCaloEmEtInHF->setAxisTitle("EM Et [GeV]",1);
00334     hCaloEmEtInEE           = _dbe->book1D("METTask_CaloEmEtInEE" ,"METTask_CaloEmEtInEE" ,50,0,1000);
00335     hCaloEmEtInEE->setAxisTitle("EM Et [GeV]",1);
00336     hCaloEmEtInEB           = _dbe->book1D("METTask_CaloEmEtInEB" ,"METTask_CaloEmEtInEB" ,100,0,2000);
00337     hCaloEmEtInEB->setAxisTitle("EM Et [GeV]",1);
00338 
00339     hCaloEmMEx= _dbe->book1D("METTask_CaloEmMEx","METTask_CaloEmMEx",200,-500,500);
00340     hCaloEmMEx->setAxisTitle("EM MEx [GeV]",1);
00341     hCaloEmMEy= _dbe->book1D("METTask_CaloEmMEy","METTask_CaloEmMEy",200,-500,500);
00342     hCaloEmMEy->setAxisTitle("EM MEy [GeV]",1);
00343     //hCaloEmEz= _dbe->book1D("METTask_CaloEmEz","METTask_CaloEmEz",100,-500,500);
00344     //hCaloEmEz->setAxisTitle("EM Ez [GeV]",1);
00345     hCaloEmMET= _dbe->book1D("METTask_CaloEmMET","METTask_CaloEmMET",200,0,1000);
00346     hCaloEmMET->setAxisTitle("EM MET [GeV]",1);
00347     hCaloEmMETPhi= _dbe->book1D("METTask_CaloEmMETPhi","METTask_CaloEmMETPhi",60,-TMath::Pi(),TMath::Pi());
00348     hCaloEmMETPhi->setAxisTitle("EM METPhi [rad]",1);
00349     //hCaloEmSumET= _dbe->book1D("METTask_CaloEmSumET","METTask_CaloEmSumET",200,0,2000);
00350     //hCaloEmSumET->setAxisTitle("EM SumET [GeV]",1);
00351 
00352     hCaloHaMEx= _dbe->book1D("METTask_CaloHaMEx","METTask_CaloHaMEx",200,-500,500);
00353     hCaloHaMEx->setAxisTitle("HA MEx [GeV]",1);
00354     hCaloHaMEy= _dbe->book1D("METTask_CaloHaMEy","METTask_CaloHaMEy",200,-500,500);
00355     hCaloHaMEy->setAxisTitle("HA MEy [GeV]",1);
00356     //hCaloHaEz= _dbe->book1D("METTask_CaloHaEz","METTask_CaloHaEz",100,-500,500);
00357     //hCaloHaEz->setAxisTitle("HA Ez [GeV]",1);
00358     hCaloHaMET= _dbe->book1D("METTask_CaloHaMET","METTask_CaloHaMET",200,0,1000); 
00359     hCaloHaMET->setAxisTitle("HA MET [GeV]",1);
00360     hCaloHaMETPhi= _dbe->book1D("METTask_CaloHaMETPhi","METTask_CaloHaMETPhi",60,-TMath::Pi(),TMath::Pi());
00361     hCaloHaMETPhi->setAxisTitle("HA METPhi [rad]",1);
00362     //hCaloHaSumET= _dbe->book1D("METTask_CaloHaSumET","METTask_CaloHaSumET",200,0,2000); 
00363     //hCaloHaSumET->setAxisTitle("HA SumET [GeV]",1);
00364   }
00365   /*  
00366   if (theCaloMETCollectionLabel.label() == "corMetGlobalMuons" ) {
00367     hCalomuPt    = _dbe->book1D("METTask_CalomuonPt", "METTask_CalomuonPt", 50, 0, 500);
00368     hCalomuEta   = _dbe->book1D("METTask_CalomuonEta", "METTask_CalomuonEta", 60, -3.0, 3.0);
00369     hCalomuNhits = _dbe->book1D("METTask_CalomuonNhits", "METTask_CalomuonNhits", 50, 0, 50);
00370     hCalomuChi2  = _dbe->book1D("METTask_CalomuonNormalizedChi2", "METTask_CalomuonNormalizedChi2", 20, 0, 20);
00371     hCalomuD0    = _dbe->book1D("METTask_CalomuonD0", "METTask_CalomuonD0", 50, -1, 1);
00372     hCaloMExCorrection       = _dbe->book1D("METTask_CaloMExCorrection", "METTask_CaloMExCorrection", 100, -500.0,500.0);
00373     hCaloMEyCorrection       = _dbe->book1D("METTask_CaloMEyCorrection", "METTask_CaloMEyCorrection", 100, -500.0,500.0);
00374     hCaloMuonCorrectionFlag  = _dbe->book1D("METTask_CaloCorrectionFlag","METTask_CaloCorrectionFlag", 5, -0.5, 4.5);
00375   }
00376   */
00377 }
00378 
00379 // ***********************************************************
00380 void CaloMETAnalyzer::bookMonitorElementTriggered(std::string DirName, bool bLumiSecPlot=false)
00381 {
00382   if (_verbose) std::cout << "bookMonitorElementTriggered " << DirName << std::endl;
00383   _dbe->setCurrentFolder(DirName);
00384  
00385   //hNevents                = _dbe->book1D("METTask_Nevents",   "METTask_Nevents"   ,1,0,1);
00386   hCaloMEx                = _dbe->book1D("METTask_CaloMEx",   "METTask_CaloMEx"   ,100,-500,500);
00387   hCaloMEx->setAxisTitle("MEx [GeV]",1);
00388   hCaloMEy                = _dbe->book1D("METTask_CaloMEy",   "METTask_CaloMEy"   ,100,-500,500); 
00389   hCaloMEy->setAxisTitle("MEy [GeV]",1);
00390   hCaloMETSig             = _dbe->book1D("METTask_CaloMETSig","METTask_CaloMETSig",51,0,51);
00391   hCaloMETSig->setAxisTitle("METSig",1);
00392   hCaloMET                = _dbe->book1D("METTask_CaloMET",   "METTask_CaloMET"   ,100,0,1000); 
00393   hCaloMET->setAxisTitle("MET [GeV]",1);
00394   hCaloMET1               = _dbe->book1D("METTask_CaloMET1",  "METTask_CaloMET1"  ,40,0,200);
00395   //meCaloMET->getTH1F()->SetStats(111111);
00396   //meCaloMET->getTH1F()->SetOption("logy");
00397   hCaloMETPhi             = _dbe->book1D("METTask_CaloMETPhi","METTask_CaloMETPhi",60,-TMath::Pi(),TMath::Pi()); 
00398   hCaloMETPhi->setAxisTitle("METPhi [rad]",1);
00399   hCaloSumET              = _dbe->book1D("METTask_CaloSumET", "METTask_CaloSumET" ,400,0,2000); 
00400   hCaloSumET->setAxisTitle("SumET [GeV]",1);
00401 
00402   hCaloMETNoHF                = _dbe->book1D("METTask_CaloMETNoHF",   "METTask_CaloMETNoHF"   ,100,0,1000); 
00403   hCaloMETNoHF->setAxisTitle("MET (No HF) [GeV]",1);
00404 
00405 
00406   // Book NPV profiles
00407   //----------------------------------------------------------------------------
00408   hCaloMEx_profile     = _dbe->bookProfile("METTask_CaloMEx_profile",     "MEx [GeV]",     nbinsPV, PVlow, PVup, 100, -500,  500);
00409   hCaloMEy_profile     = _dbe->bookProfile("METTask_CaloMEy_profile",     "MEy [GeV]",     nbinsPV, PVlow, PVup, 100, -500,  500); 
00410   hCaloMET_profile     = _dbe->bookProfile("METTask_CaloMET_profile",     "MET [GeV]",     nbinsPV, PVlow, PVup, 100,    0, 1000); 
00411   hCaloMETNoHF_profile = _dbe->bookProfile("METTask_CaloMETNoHF_profile", "METNoHF [GeV]", nbinsPV, PVlow, PVup, 100,    0, 1000); 
00412   hCaloSumET_profile   = _dbe->bookProfile("METTask_CaloSumET_profile",   "SumET [GeV]",   nbinsPV, PVlow, PVup, 200,    0, 2000); 
00413 
00414 
00415   // Set NPV profiles x-axis title
00416   //----------------------------------------------------------------------------
00417   hCaloMEx_profile    ->setAxisTitle("nvtx",1);
00418   hCaloMEy_profile    ->setAxisTitle("nvtx",1);
00419   hCaloMET_profile    ->setAxisTitle("nvtx",1);
00420   hCaloMETNoHF_profile->setAxisTitle("nvtx",1);
00421   hCaloSumET_profile  ->setAxisTitle("nvtx",1);
00422 
00423 
00424   hCaloMET_logx   = _dbe->book1D("METTask_CaloMET_logx",   "log(MET) [GeV]",   40, -1, 7);
00425   hCaloSumET_logx = _dbe->book1D("METTask_CaloSumET_logx", "log(SumET) [GeV]", 40, -1, 7);
00426 
00427 
00428   //  hCaloMETIonFeedbck      = _dbe->book1D("METTask_CaloMETIonFeedbck", "METTask_CaloMETIonFeedbck" ,500,0,1000);
00429   //  hCaloMETIonFeedbck->setAxisTitle("MET [GeV]",1);
00430   //  hCaloMETHPDNoise        = _dbe->book1D("METTask_CaloMETHPDNoise",   "METTask_CaloMETHPDNoise"   ,500,0,1000);
00431   //  hCaloMETHPDNoise->setAxisTitle("MET [GeV]",1);
00432   //  hCaloMETRBXNoise        = _dbe->book1D("METTask_CaloMETRBXNoise",   "METTask_CaloMETRBXNoise"   ,500,0,1000);
00433   //  hCaloMETRBXNoise->setAxisTitle("MET [GeV]",1);
00434 
00435   //  hCaloMETPhi002          = _dbe->book1D("METTask_CaloMETPhi002","METTask_CaloMETPhi002",60,-TMath::Pi(),TMath::Pi());
00436   //  hCaloMETPhi002->setAxisTitle("METPhi [rad] (MET>2 GeV)",1);
00437   //  hCaloMETPhi010          = _dbe->book1D("METTask_CaloMETPhi010","METTask_CaloMETPhi010",60,-TMath::Pi(),TMath::Pi());
00438   //  hCaloMETPhi010->setAxisTitle("METPhi [rad] (MET>10 GeV)",1);
00439   hCaloMETPhi020          = _dbe->book1D("METTask_CaloMETPhi020","METTask_CaloMETPhi020",60,-TMath::Pi(),TMath::Pi());
00440   hCaloMETPhi020->setAxisTitle("METPhi [rad] (MET>20 GeV)",1);
00441 
00442   if (_allhist){
00443     if (bLumiSecPlot){
00444       hCaloMExLS              = _dbe->book2D("METTask_CaloMEx_LS","METTask_CaloMEx_LS",200,-200,200,50,0.,500.);
00445       hCaloMExLS->setAxisTitle("MEx [GeV]",1);
00446       hCaloMExLS->setAxisTitle("Lumi Section",2);
00447       hCaloMEyLS              = _dbe->book2D("METTask_CaloMEy_LS","METTask_CaloMEy_LS",200,-200,200,50,0.,500.);
00448       hCaloMEyLS->setAxisTitle("MEy [GeV]",1);
00449       hCaloMEyLS->setAxisTitle("Lumi Section",2);
00450     }
00451 
00452     //hCaloMaxEtInEmTowers    = _dbe->book1D("METTask_CaloMaxEtInEmTowers",   "METTask_CaloMaxEtInEmTowers"   ,100,0,2000);
00453     //hCaloMaxEtInEmTowers->setAxisTitle("Et(Max) in EM Tower [GeV]",1);
00454     //hCaloMaxEtInHadTowers   = _dbe->book1D("METTask_CaloMaxEtInHadTowers",  "METTask_CaloMaxEtInHadTowers"  ,100,0,2000);
00455     //hCaloMaxEtInHadTowers->setAxisTitle("Et(Max) in Had Tower [GeV]",1);
00456     hCaloEtFractionHadronic = _dbe->book1D("METTask_CaloEtFractionHadronic","METTask_CaloEtFractionHadronic",100,0,1);
00457     hCaloEtFractionHadronic->setAxisTitle("Hadronic Et Fraction",1);
00458     hCaloEmEtFraction       = _dbe->book1D("METTask_CaloEmEtFraction",      "METTask_CaloEmEtFraction"      ,100,0,1);
00459     hCaloEmEtFraction->setAxisTitle("EM Et Fraction",1);
00460 
00461     //hCaloEmEtFraction002    = _dbe->book1D("METTask_CaloEmEtFraction002",   "METTask_CaloEmEtFraction002"      ,100,0,1);
00462     //hCaloEmEtFraction002->setAxisTitle("EM Et Fraction (MET>2 GeV)",1);
00463     //hCaloEmEtFraction010    = _dbe->book1D("METTask_CaloEmEtFraction010",   "METTask_CaloEmEtFraction010"      ,100,0,1);
00464     //hCaloEmEtFraction010->setAxisTitle("EM Et Fraction (MET>10 GeV)",1);
00465     hCaloEmEtFraction020    = _dbe->book1D("METTask_CaloEmEtFraction020",   "METTask_CaloEmEtFraction020"      ,100,0,1);
00466     hCaloEmEtFraction020->setAxisTitle("EM Et Fraction (MET>20 GeV)",1);
00467 
00468     //hCaloHadEtInHB          = _dbe->book1D("METTask_CaloHadEtInHB","METTask_CaloHadEtInHB",100,0,2000);
00469     //hCaloHadEtInHB->setAxisTitle("Had Et [GeV]",1);
00470     //hCaloHadEtInHO          = _dbe->book1D("METTask_CaloHadEtInHO","METTask_CaloHadEtInHO",25,0,500);
00471     //hCaloHadEtInHO->setAxisTitle("Had Et [GeV]",1);
00472     //hCaloHadEtInHE          = _dbe->book1D("METTask_CaloHadEtInHE","METTask_CaloHadEtInHE",100,0,2000);
00473     //hCaloHadEtInHE->setAxisTitle("Had Et [GeV]",1);
00474     //hCaloHadEtInHF          = _dbe->book1D("METTask_CaloHadEtInHF","METTask_CaloHadEtInHF",50,0,1000);
00475     //hCaloHadEtInHF->setAxisTitle("Had Et [GeV]",1);
00476     //hCaloEmEtInHF           = _dbe->book1D("METTask_CaloEmEtInHF" ,"METTask_CaloEmEtInHF" ,25,0,500);
00477     //hCaloEmEtInHF->setAxisTitle("EM Et [GeV]",1);
00478     //hCaloEmEtInEE           = _dbe->book1D("METTask_CaloEmEtInEE" ,"METTask_CaloEmEtInEE" ,50,0,1000);
00479     //hCaloEmEtInEE->setAxisTitle("EM Et [GeV]",1);
00480     //hCaloEmEtInEB           = _dbe->book1D("METTask_CaloEmEtInEB" ,"METTask_CaloEmEtInEB" ,100,0,2000);
00481     //hCaloEmEtInEB->setAxisTitle("EM Et [GeV]",1);
00482     //
00483     //hCaloEmMEx= _dbe->book1D("METTask_CaloEmMEx","METTask_CaloEmMEx",200,-500,500);
00484     //hCaloEmMEx->setAxisTitle("EM MEx [GeV]",1);
00485     //hCaloEmMEy= _dbe->book1D("METTask_CaloEmMEy","METTask_CaloEmMEy",200,-500,500);
00486     //hCaloEmMEy->setAxisTitle("EM MEy [GeV]",1);
00489     //hCaloEmMET= _dbe->book1D("METTask_CaloEmMET","METTask_CaloEmMET",200,0,1000);
00490     //hCaloEmMET->setAxisTitle("EM MET [GeV]",1);
00491     //hCaloEmMETPhi= _dbe->book1D("METTask_CaloEmMETPhi","METTask_CaloEmMETPhi",60,-TMath::Pi(),TMath::Pi());
00492     //hCaloEmMETPhi->setAxisTitle("EM METPhi [rad]",1);
00495     //
00496     //hCaloHaMEx= _dbe->book1D("METTask_CaloHaMEx","METTask_CaloHaMEx",200,-500,500);
00497     //hCaloHaMEx->setAxisTitle("HA MEx [GeV]",1);
00498     //hCaloHaMEy= _dbe->book1D("METTask_CaloHaMEy","METTask_CaloHaMEy",200,-500,500);
00499     //hCaloHaMEy->setAxisTitle("HA MEy [GeV]",1);
00502     //hCaloHaMET= _dbe->book1D("METTask_CaloHaMET","METTask_CaloHaMET",200,0,1000); 
00503     //hCaloHaMET->setAxisTitle("HA MET [GeV]",1);
00504     //hCaloHaMETPhi= _dbe->book1D("METTask_CaloHaMETPhi","METTask_CaloHaMETPhi",60,-TMath::Pi(),TMath::Pi());
00505     //hCaloHaMETPhi->setAxisTitle("HA METPhi [rad]",1);
00508   }
00509   
00510   if (theCaloMETCollectionLabel.label() == "corMetGlobalMuons" ) {
00511     hCalomuPt    = _dbe->book1D("METTask_CalomuonPt", "METTask_CalomuonPt", 50, 0, 500);
00512     hCalomuEta   = _dbe->book1D("METTask_CalomuonEta", "METTask_CalomuonEta", 60, -3.0, 3.0);
00513     hCalomuNhits = _dbe->book1D("METTask_CalomuonNhits", "METTask_CalomuonNhits", 50, 0, 50);
00514     hCalomuChi2  = _dbe->book1D("METTask_CalomuonNormalizedChi2", "METTask_CalomuonNormalizedChi2", 20, 0, 20);
00515     hCalomuD0    = _dbe->book1D("METTask_CalomuonD0", "METTask_CalomuonD0", 50, -1, 1);
00516     hCaloMExCorrection       = _dbe->book1D("METTask_CaloMExCorrection", "METTask_CaloMExCorrection", 100, -500.0,500.0);
00517     hCaloMEyCorrection       = _dbe->book1D("METTask_CaloMEyCorrection", "METTask_CaloMEyCorrection", 100, -500.0,500.0);
00518     hCaloMuonCorrectionFlag  = _dbe->book1D("METTask_CaloCorrectionFlag","METTask_CaloCorrectionFlag", 5, -0.5, 4.5);
00519   }
00520 
00521 }
00522 
00523 // ***********************************************************
00524 void CaloMETAnalyzer::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
00525 {
00526   if ( _HighPtJetEventFlag->on() ) _HighPtJetEventFlag->initRun( iRun, iSetup );
00527   if ( _LowPtJetEventFlag ->on() ) _LowPtJetEventFlag ->initRun( iRun, iSetup );
00528   if ( _MinBiasEventFlag  ->on() ) _MinBiasEventFlag  ->initRun( iRun, iSetup );
00529   if ( _HighMETEventFlag  ->on() ) _HighMETEventFlag  ->initRun( iRun, iSetup );
00530   if ( _LowMETEventFlag   ->on() ) _LowMETEventFlag   ->initRun( iRun, iSetup );
00531   if ( _EleEventFlag      ->on() ) _EleEventFlag      ->initRun( iRun, iSetup );
00532   if ( _MuonEventFlag     ->on() ) _MuonEventFlag     ->initRun( iRun, iSetup );
00533 
00534   if (_HighPtJetEventFlag->on() && _HighPtJetEventFlag->expressionsFromDB(_HighPtJetEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00535     highPtJetExpr_ = _HighPtJetEventFlag->expressionsFromDB(_HighPtJetEventFlag->hltDBKey(), iSetup);
00536   if (_LowPtJetEventFlag->on() && _LowPtJetEventFlag->expressionsFromDB(_LowPtJetEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00537     lowPtJetExpr_  = _LowPtJetEventFlag->expressionsFromDB(_LowPtJetEventFlag->hltDBKey(),   iSetup);
00538   if (_HighMETEventFlag->on() && _HighMETEventFlag->expressionsFromDB(_HighMETEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00539     highMETExpr_   = _HighMETEventFlag->expressionsFromDB(_HighMETEventFlag->hltDBKey(),     iSetup);
00540   if (_LowMETEventFlag->on() && _LowMETEventFlag->expressionsFromDB(_LowMETEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00541     lowMETExpr_    = _LowMETEventFlag->expressionsFromDB(_LowMETEventFlag->hltDBKey(),       iSetup);
00542   if (_MuonEventFlag->on() && _MuonEventFlag->expressionsFromDB(_MuonEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00543     muonExpr_      = _MuonEventFlag->expressionsFromDB(_MuonEventFlag->hltDBKey(),           iSetup);
00544   if (_EleEventFlag->on() && _EleEventFlag->expressionsFromDB(_EleEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00545     elecExpr_      = _EleEventFlag->expressionsFromDB(_EleEventFlag->hltDBKey(),             iSetup);
00546   if (_MinBiasEventFlag->on() && _MinBiasEventFlag->expressionsFromDB(_MinBiasEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00547     minbiasExpr_   = _MinBiasEventFlag->expressionsFromDB(_MinBiasEventFlag->hltDBKey(),     iSetup);
00548 
00549 }
00550 
00551 // ***********************************************************
00552 void CaloMETAnalyzer::endRun(const edm::Run& iRun, const edm::EventSetup& iSetup, DQMStore * dbe)
00553 {
00554   
00555   //
00556   //--- Check the time length of the Run from the lumi section plots
00557 
00558   std::string dirName = "JetMET/MET/"+_source+"/";
00559   _dbe->setCurrentFolder(dirName);
00560 
00561   TH1F* tlumisec;
00562 
00563   MonitorElement *meLumiSec = _dbe->get("aaa");
00564   meLumiSec = _dbe->get("JetMET/lumisec");
00565 
00566   int totlsec=0;
00567   double totltime=0.;
00568   if ( meLumiSec->getRootObject() ) {
00569     tlumisec = meLumiSec->getTH1F();
00570     for (int i=0; i<500; i++){
00571       if (tlumisec->GetBinContent(i+1)) totlsec++;
00572     }
00573     totltime = double(totlsec*90); // one lumi sec ~ 90 (sec)
00574   }
00575 
00576   if (totltime==0.) totltime=1.; 
00577 
00578   //
00579   //--- Make the integrated plots with rate (Hz)
00580 
00581   for (std::vector<std::string>::const_iterator ic = _FolderNames.begin(); ic != _FolderNames.end(); ic++)
00582     {
00583 
00584       std::string DirName;
00585       DirName = dirName+*ic;
00586 
00587       makeRatePlot(DirName,totltime);
00588       if ( _HighPtJetEventFlag->on() ) 
00589         makeRatePlot(DirName+"/"+"triggerName_HighJetPt",totltime);
00590       if ( _LowPtJetEventFlag->on() ) 
00591         makeRatePlot(DirName+"/"+"triggerName_LowJetPt",totltime);
00592       if ( _MinBiasEventFlag->on() ) 
00593         makeRatePlot(DirName+"/"+"triggerName_MinBias",totltime);
00594       if ( _HighMETEventFlag->on() ) 
00595         makeRatePlot(DirName+"/"+"triggerName_HighMET",totltime);
00596       if ( _LowMETEventFlag->on() ) 
00597         makeRatePlot(DirName+"/"+"triggerName_LowMET",totltime);
00598       if ( _EleEventFlag->on() ) 
00599         makeRatePlot(DirName+"/"+"triggerName_Ele",totltime);
00600       if ( _MuonEventFlag->on() ) 
00601         makeRatePlot(DirName+"/"+"triggerName_Muon",totltime);
00602     }
00603 
00604 }
00605 
00606 // ***********************************************************
00607 void CaloMETAnalyzer::makeRatePlot(std::string DirName, double totltime)
00608 {
00609 
00610   _dbe->setCurrentFolder(DirName);
00611   MonitorElement *meCaloMET = _dbe->get(DirName+"/"+"METTask_CaloMET");
00612 
00613   TH1F* tCaloMET;
00614   TH1F* tCaloMETRate;
00615 
00616   if ( meCaloMET )
00617     if ( meCaloMET->getRootObject() ) {
00618       tCaloMET     = meCaloMET->getTH1F();
00619       
00620       // Integral plot & convert number of events to rate (hz)
00621       tCaloMETRate = (TH1F*) tCaloMET->Clone("METTask_CaloMETRate");
00622       for (int i = tCaloMETRate->GetNbinsX()-1; i>=0; i--){
00623         tCaloMETRate->SetBinContent(i+1,tCaloMETRate->GetBinContent(i+2)+tCaloMET->GetBinContent(i+1));
00624       }
00625       for (int i = 0; i<tCaloMETRate->GetNbinsX(); i++){
00626         tCaloMETRate->SetBinContent(i+1,tCaloMETRate->GetBinContent(i+1)/double(totltime));
00627       }      
00628 
00629       tCaloMETRate->SetName("METTask_CaloMETRate");
00630       tCaloMETRate->SetTitle("METTask_CaloMETRate");
00631       hCaloMETRate = _dbe->book1D("METTask_CaloMETRate",tCaloMETRate);
00632       hCaloMETRate->setAxisTitle("MET Threshold [GeV]",1);
00633     }
00634 }
00635 
00636 
00637 // ***********************************************************
00638 void CaloMETAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup, 
00639                               const edm::TriggerResults& triggerResults) {
00640 
00641   if (_verbose) std::cout << "CaloMETAnalyzer analyze" << std::endl;
00642 
00643   std::string DirName = "JetMET/MET/"+_source;
00644   if (_print){
00645   std::cout << " " << std::endl;
00646   std::cout << "Event = " << iEvent.id().event() << std::endl;
00647   }
00648 
00649   LogTrace(metname)<<"[CaloMETAnalyzer] Analyze CaloMET";
00650 
00651   hmetME->Fill(1);
00652 
00653   // ==========================================================  
00654   // Trigger information 
00655   //
00656   _trig_JetMB=0;
00657   _trig_HighPtJet=0;
00658   _trig_LowPtJet=0;
00659   _trig_MinBias=0;
00660   _trig_HighMET=0;
00661   _trig_LowMET=0;
00662   _trig_Ele=0;
00663   _trig_Muon=0;
00664   _trig_PhysDec=0;
00665   if(&triggerResults) {   
00666     
00668     
00669     //
00670     //
00671     // Check how many HLT triggers are in triggerResults 
00672     int ntrigs = triggerResults.size();
00673     if (_verbose) std::cout << "ntrigs=" << ntrigs << std::endl;
00674     
00675     //
00676     //
00677     // If index=ntrigs, this HLT trigger doesn't exist in the HLT table for this data.
00678     const edm::TriggerNames & triggerNames = iEvent.triggerNames(triggerResults);
00679 
00680     //
00681     //
00682     const unsigned int nTrig(triggerNames.size());
00683     for (unsigned int i=0;i<nTrig;++i)
00684       {
00685         if (triggerNames.triggerName(i).find(highPtJetExpr_[0].substr(0,highPtJetExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
00686           _trig_HighPtJet=true;
00687         else if (triggerNames.triggerName(i).find(lowPtJetExpr_[0].substr(0,lowPtJetExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
00688           _trig_LowPtJet=true;
00689         else if (triggerNames.triggerName(i).find(highMETExpr_[0].substr(0,highMETExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
00690           _trig_HighMET=true;
00691         else if (triggerNames.triggerName(i).find(lowMETExpr_[0].substr(0,lowMETExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
00692           _trig_LowMET=true;
00693         else if (triggerNames.triggerName(i).find(muonExpr_[0].substr(0,muonExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
00694           _trig_Muon=true;
00695         else if (triggerNames.triggerName(i).find(elecExpr_[0].substr(0,elecExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
00696           _trig_Ele=true;
00697         else if (triggerNames.triggerName(i).find(minbiasExpr_[0].substr(0,minbiasExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
00698           _trig_MinBias=true;
00699       }
00700 
00701     // count number of requested Jet or MB HLT paths which have fired
00702     for (unsigned int i=0; i!=HLTPathsJetMBByName_.size(); i++) {
00703       unsigned int triggerIndex = triggerNames.triggerIndex(HLTPathsJetMBByName_[i]);
00704       if (triggerIndex<triggerResults.size()) {
00705         if (triggerResults.accept(triggerIndex)) {
00706           _trig_JetMB++;
00707         }
00708       }
00709     }
00710     // for empty input vectors (n==0), take all HLT triggers!
00711     if (HLTPathsJetMBByName_.size()==0) _trig_JetMB=triggerResults.size()-1;
00712 
00713     /*
00714       if ( _HighPtJetEventFlag->on() && _HighPtJetEventFlag->accept( iEvent, iSetup) )
00715       _trig_HighPtJet=1;
00716       
00717       if ( _LowPtJetEventFlag->on() && _LowPtJetEventFlag->accept( iEvent, iSetup) )
00718       _trig_LowPtJet=1;
00719       
00720       if ( _MinBiasEventFlag->on() && _MinBiasEventFlag->accept( iEvent, iSetup) )
00721       _trig_MinBias=1;
00722       
00723       if ( _HighMETEventFlag->on() && _HighMETEventFlag->accept( iEvent, iSetup) )
00724       _trig_HighMET=1;
00725       
00726       if ( _LowMETEventFlag->on() && _LowMETEventFlag->accept( iEvent, iSetup) )
00727       _trig_LowMET=1;
00728       
00729       if ( _EleEventFlag->on() && _EleEventFlag->accept( iEvent, iSetup) )
00730       _trig_Ele=1;
00731       
00732       if ( _MuonEventFlag->on() && _MuonEventFlag->accept( iEvent, iSetup) )
00733       _trig_Muon=1;
00734     */
00735       
00736     if (triggerNames.triggerIndex(_hlt_PhysDec)   != triggerNames.size() &&
00737         triggerResults.accept(triggerNames.triggerIndex(_hlt_PhysDec)))   _trig_PhysDec=1;
00738   } else {
00739 
00740     edm::LogInfo("CaloMetAnalyzer") << "TriggerResults::HLT not found, "
00741         "automatically select events"; 
00742     //
00743     // TriggerResults object not found. Look at all events.    
00744     _trig_JetMB=1;
00745     
00746   }
00747   
00748   // ==========================================================  
00749   // CaloMET information
00750 
00751   // **** Get the MET container  
00752   edm::Handle<reco::CaloMETCollection> calometcoll;
00753   iEvent.getByLabel(theCaloMETCollectionLabel, calometcoll);
00754 
00755   if(!calometcoll.isValid()) {
00756     std::cout<<"Unable to find MET results for CaloMET collection "<<theCaloMETCollectionLabel<<std::endl;
00757     return;
00758   }
00759 
00760   const reco::CaloMETCollection *calometcol = calometcoll.product();
00761   const reco::CaloMET *calomet;
00762   calomet = &(calometcol->front());
00763   
00764   LogTrace(metname)<<"[CaloMETAnalyzer] Call to the CaloMET analyzer";
00765 
00766   // **** Get the MET no HF container  
00767   edm::Handle<reco::CaloMETCollection> calometnohfcoll;
00768   iEvent.getByLabel("metNoHF", calometnohfcoll);
00769 
00770   if(!calometnohfcoll.isValid()) {
00771     std::cout<<"Unable to find MET results for CaloMETNoHF collection metNoHF"<<std::endl;
00772     return;
00773   }
00774 
00775   const reco::CaloMETCollection *calometnohfcol = calometnohfcoll.product();
00776   const reco::CaloMET *calometnohf;
00777   calometnohf = &(calometnohfcol->front());
00778   
00779   //LogTrace(metname)<<"[CaloMETAnalyzer] Call to the CaloMET analyzer";
00780 
00781   //Only for corMetGlobalMuons
00782   if (theCaloMETCollectionLabel.label() == "corMetGlobalMuons" ) {
00783     
00784     iEvent.getByLabel("muonMETValueMapProducer" , "muCorrData", corMetGlobalMuons_ValueMap_Handle);
00785     iEvent.getByLabel("muons", muon_h);
00786     iEvent.getByLabel(inputBeamSpotLabel, beamSpot_h);
00787     
00788     if(!beamSpot_h.isValid()) edm::LogInfo("OutputInfo") << "falied to retrieve beam spot data require by MET Task";
00789     
00790     bspot = ( beamSpot_h.isValid() ) ? beamSpot_h->position() : math::XYZPoint(0, 0, 0);
00791     
00792   }
00793 
00794 
00795   // ==========================================================
00796   //
00797   edm::Handle<reco::HcalNoiseRBXCollection> HRBXCollection;
00798   iEvent.getByLabel(HcalNoiseRBXCollectionTag,HRBXCollection);
00799   if (!HRBXCollection.isValid()) {
00800       LogDebug("") << "CaloMETAnalyzer: Could not find HcalNoiseRBX Collection" << std::endl;
00801       if (_verbose) std::cout << "CaloMETAnalyzer: Could not find HcalNoiseRBX Collection" << std::endl;
00802   }
00803   
00804   edm::Handle<HcalNoiseSummary> HNoiseSummary;
00805   iEvent.getByLabel(HcalNoiseSummaryTag,HNoiseSummary);
00806   if (!HNoiseSummary.isValid()) {
00807     LogDebug("") << "CaloMETAnalyzer: Could not find Hcal NoiseSummary product" << std::endl;
00808     if (_verbose) std::cout << "CaloMETAnalyzer: Could not find Hcal NoiseSummary product" << std::endl;
00809   }
00810   
00811   edm::Handle<reco::CaloJetCollection> caloJets;
00812   iEvent.getByLabel(theJetCollectionLabel, caloJets);
00813   if (!caloJets.isValid()) {
00814     LogDebug("") << "CaloMETAnalyzer: Could not find jet product" << std::endl;
00815     if (_verbose) std::cout << "CaloMETAnalyzer: Could not find jet product" << std::endl;
00816   }
00817 
00818   edm::Handle<edm::View<reco::Candidate> > towers;
00819   iEvent.getByLabel(theCaloTowersLabel, towers);
00820   if (!towers.isValid()) {
00821     LogDebug("") << "CaloMETAnalyzer: Could not find caltower product" << std::endl;
00822     if (_verbose) std::cout << "CaloMETAnalyzer: Could not find caltower product" << std::endl;
00823   }
00824  
00825   // ==========================================================
00826   // CaloMET sanity check
00827 
00828   if (_source=="CaloMET") validateMET(*calomet,towers);
00829 
00830   // ==========================================================
00831 
00832   if (_allhist) computeEmHaMET(towers);
00833     
00834   // ==========================================================
00835   // JetID 
00836 
00837   if (_verbose) std::cout << "JetID starts" << std::endl;
00838   
00839   //
00840   // --- Minimal cuts
00841   //
00842   bool bJetIDMinimal=true;
00843   int nj=0;
00844   for (reco::CaloJetCollection::const_iterator cal = caloJets->begin(); 
00845        cal!=caloJets->end(); ++cal){
00846     jetID->calculate(iEvent, *cal);
00847     if (_print && nj<=1) std::cout << "Jet pT = " << cal->pt() << " (GeV) "
00848                                    << " eta = " << cal->eta() << " "
00849                                    << " phi = " << cal->phi() << " "
00850                                    << " emf = " << cal->emEnergyFraction() << std::endl;
00851     nj++;
00852     if (cal->pt()>10.){
00853       if (fabs(cal->eta())<=2.6 && 
00854           cal->emEnergyFraction()<=0.01) bJetIDMinimal=false;
00855     }
00856   }
00857 
00858   //
00859   // --- Loose cuts
00860   //
00861   bool bJetIDLoose=true;
00862   for (reco::CaloJetCollection::const_iterator cal = caloJets->begin(); 
00863        cal!=caloJets->end(); ++cal){
00864     jetID->calculate(iEvent, *cal);
00865     if (_verbose) std::cout << jetID->n90Hits() << " " 
00866                             << jetID->restrictedEMF() << " "
00867                             << cal->pt() << std::endl;
00868     if (cal->pt()>10.){
00869       //
00870       // for all regions
00871       if (jetID->n90Hits()<2)  bJetIDLoose=false; 
00872       if (jetID->fHPD()>=0.98) bJetIDLoose=false; 
00873       //
00874       // for non-forward
00875       if (fabs(cal->eta())<2.55){
00876         if (cal->emEnergyFraction()<=0.01) bJetIDLoose=false; 
00877       }
00878       // for forward
00879       else {
00880         if (cal->emEnergyFraction()<=-0.9) bJetIDLoose=false; 
00881         if (cal->pt()>80.){
00882         if (cal->emEnergyFraction()>= 1.0) bJetIDLoose=false; 
00883         }
00884       } // forward vs non-forward
00885     }   // pt>10 GeV/c
00886   }     // calor-jets loop
00887 
00888   //
00889   // --- Tight cuts
00890   //
00891   bool bJetIDTight=true;
00892   bJetIDTight=bJetIDLoose;
00893   for (reco::CaloJetCollection::const_iterator cal = caloJets->begin(); 
00894        cal!=caloJets->end(); ++cal){
00895     jetID->calculate(iEvent, *cal);
00896     if (cal->pt()>25.){
00897       //
00898       // for all regions
00899       if (jetID->fHPD()>=0.95) bJetIDTight=false; 
00900       //
00901       // for 1.0<|eta|<1.75
00902       if (fabs(cal->eta())>=1.00 && fabs(cal->eta())<1.75){
00903         if (cal->pt()>80. && cal->emEnergyFraction()>=1.) bJetIDTight=false; 
00904       }
00905       //
00906       // for 1.75<|eta|<2.55
00907       else if (fabs(cal->eta())>=1.75 && fabs(cal->eta())<2.55){
00908         if (cal->pt()>80. && cal->emEnergyFraction()>=1.) bJetIDTight=false; 
00909       }
00910       //
00911       // for 2.55<|eta|<3.25
00912       else if (fabs(cal->eta())>=2.55 && fabs(cal->eta())<3.25){
00913         if (cal->pt()< 50.                   && cal->emEnergyFraction()<=-0.3) bJetIDTight=false; 
00914         if (cal->pt()>=50. && cal->pt()< 80. && cal->emEnergyFraction()<=-0.2) bJetIDTight=false; 
00915         if (cal->pt()>=80. && cal->pt()<340. && cal->emEnergyFraction()<=-0.1) bJetIDTight=false; 
00916         if (cal->pt()>=340.                  && cal->emEnergyFraction()<=-0.1 
00917                                              && cal->emEnergyFraction()>=0.95) bJetIDTight=false; 
00918       }
00919       //
00920       // for 3.25<|eta|
00921       else if (fabs(cal->eta())>=3.25){
00922         if (cal->pt()< 50.                   && cal->emEnergyFraction()<=-0.3
00923                                              && cal->emEnergyFraction()>=0.90) bJetIDTight=false; 
00924         if (cal->pt()>=50. && cal->pt()<130. && cal->emEnergyFraction()<=-0.2
00925                                              && cal->emEnergyFraction()>=0.80) bJetIDTight=false; 
00926         if (cal->pt()>=130.                  && cal->emEnergyFraction()<=-0.1 
00927                                              && cal->emEnergyFraction()>=0.70) bJetIDTight=false; 
00928       }
00929     }   // pt>10 GeV/c
00930   }     // calor-jets loop
00931   
00932   if (_verbose) std::cout << "JetID ends" << std::endl;
00933      
00934   // ==========================================================
00935   // HCAL Noise filter
00936   
00937   bool bHcalNoiseFilter      = HNoiseSummary->passLooseNoiseFilter();
00938   bool bHcalNoiseFilterTight = HNoiseSummary->passTightNoiseFilter();
00939 
00940   if (_verbose) std::cout << "HcalNoiseFilter Summary ends" << std::endl;
00941 
00942   // ==========================================================
00943   // Get BeamHaloSummary
00944   edm::Handle<reco::BeamHaloSummary> TheBeamHaloSummary ;
00945   iEvent.getByLabel(BeamHaloSummaryTag, TheBeamHaloSummary) ;
00946 
00947   bool bBeamHaloIDTightPass = true;
00948   bool bBeamHaloIDLoosePass = true;
00949   
00950   if(TheBeamHaloSummary.isValid()) {
00951     
00952     const reco::BeamHaloSummary TheSummary = (*TheBeamHaloSummary.product() );
00953     
00954     //   std::cout << TheSummary.EcalLooseHaloId() << " "
00955     //      << TheSummary.HcalLooseHaloId() << " "
00956     //      << TheSummary.CSCLooseHaloId()  << " "
00957     //      << TheSummary.GlobalLooseHaloId() << std::endl;
00958     
00959     if( TheSummary.EcalLooseHaloId()  || TheSummary.HcalLooseHaloId() || 
00960         TheSummary.CSCLooseHaloId()   || TheSummary.GlobalLooseHaloId() )
00961       bBeamHaloIDLoosePass = false;
00962     
00963     if( TheSummary.EcalTightHaloId()  || TheSummary.HcalTightHaloId() || 
00964         TheSummary.CSCTightHaloId()   || TheSummary.GlobalTightHaloId() )
00965       bBeamHaloIDTightPass = false;
00966     
00967   }
00968   
00969   if (_verbose) std::cout << "BeamHaloSummary ends" << std::endl;
00970   
00971   // ==========================================================
00972   //Vertex information
00973 
00974   _numPV = 0;
00975   bool bPrimaryVertex = true;
00976   if(_doPVCheck){
00977     bPrimaryVertex = false;
00978     Handle<reco::VertexCollection> vertexHandle;
00979 
00980     iEvent.getByLabel(vertexTag, vertexHandle);
00981 
00982     if (!vertexHandle.isValid()) {
00983       LogDebug("") << "CaloMETAnalyzer: Could not find vertex collection" << std::endl;
00984       if (_verbose) std::cout << "CaloMETAnalyzer: Could not find vertex collection" << std::endl;
00985     }
00986     
00987     if ( vertexHandle.isValid() ){
00988       reco::VertexCollection vertexCollection = *(vertexHandle.product());
00989       int vertex_number     = vertexCollection.size();
00990       reco::VertexCollection::const_iterator v = vertexCollection.begin();
00991       for ( ; v != vertexCollection.end(); ++v) {
00992         double vertex_chi2    = v->normalizedChi2();
00993         double vertex_ndof    = v->ndof();
00994         bool   fakeVtx        = v->isFake();
00995         double vertex_Z       = v->z();
00996         
00997         if (  !fakeVtx
00998               && vertex_number>=_nvtx_min
00999               && vertex_ndof   >_vtxndof_min
01000               && vertex_chi2   <_vtxchi2_max
01001               && fabs(vertex_Z)<_vtxz_max ) {
01002           bPrimaryVertex = true;
01003           ++_numPV;
01004         }
01005       }
01006     }
01007   }
01008   // ==========================================================
01009 
01010   edm::Handle< L1GlobalTriggerReadoutRecord > gtReadoutRecord;
01011   iEvent.getByLabel( gtTag, gtReadoutRecord);
01012 
01013   if (!gtReadoutRecord.isValid()) {
01014     LogDebug("") << "CaloMETAnalyzer: Could not find GT readout record" << std::endl;
01015     if (_verbose) std::cout << "CaloMETAnalyzer: Could not find GT readout record product" << std::endl;
01016   }
01017   
01018   bool bTechTriggers    = true;
01019   bool bTechTriggersAND = true;
01020   bool bTechTriggersOR  = false;
01021   bool bTechTriggersNOT = false;
01022 
01023   if (gtReadoutRecord.isValid()) {
01024     const TechnicalTriggerWord&  technicalTriggerWordBeforeMask = gtReadoutRecord->technicalTriggerWord();
01025 
01026     if (_techTrigsAND.size() == 0)
01027       bTechTriggersAND = true;
01028     else
01029       for (unsigned ttr = 0; ttr != _techTrigsAND.size(); ttr++) {
01030         bTechTriggersAND = bTechTriggersAND && technicalTriggerWordBeforeMask.at(_techTrigsAND.at(ttr));
01031       }
01032     
01033     if (_techTrigsAND.size() == 0)
01034       bTechTriggersOR = true;
01035     else
01036       for (unsigned ttr = 0; ttr != _techTrigsOR.size(); ttr++) {
01037         bTechTriggersOR = bTechTriggersOR || technicalTriggerWordBeforeMask.at(_techTrigsOR.at(ttr));
01038       }
01039     if (_techTrigsNOT.size() == 0)
01040       bTechTriggersNOT = false;
01041     else
01042       for (unsigned ttr = 0; ttr != _techTrigsNOT.size(); ttr++) {
01043         bTechTriggersNOT = bTechTriggersNOT || technicalTriggerWordBeforeMask.at(_techTrigsNOT.at(ttr));
01044       }
01045   }
01046   else
01047     {
01048       bTechTriggersAND = true;
01049       bTechTriggersOR  = true;
01050       bTechTriggersNOT = false;
01051     }
01052     
01053   if (_techTrigsAND.size()==0)
01054     bTechTriggersAND = true;
01055   if (_techTrigsOR.size()==0)
01056     bTechTriggersOR = true;
01057   if (_techTrigsNOT.size()==0)
01058     bTechTriggersNOT = false;
01059   
01060   bTechTriggers = bTechTriggersAND && bTechTriggersOR && !bTechTriggersNOT;
01061     
01062   // ==========================================================
01063   // Reconstructed MET Information - fill MonitorElements
01064   
01065   bool bHcalNoise   = bHcalNoiseFilter;
01066   bool bBeamHaloID  = bBeamHaloIDLoosePass;
01067   bool bJetID       = bJetIDMinimal;
01068 
01069   bool bPhysicsDeclared = true;
01070   if(_doHLTPhysicsOn) bPhysicsDeclared =_trig_PhysDec;
01071 
01072   if      (_tightHcalFiltering)     bHcalNoise  = bHcalNoiseFilterTight;
01073   if      (_tightBHFiltering)       bBeamHaloID = bBeamHaloIDTightPass;
01074 
01075   if      (_tightJetIDFiltering==1)  bJetID      = bJetIDMinimal;
01076   else if (_tightJetIDFiltering==2)  bJetID      = bJetIDLoose;
01077   else if (_tightJetIDFiltering==3)  bJetID      = bJetIDTight;
01078   else if (_tightJetIDFiltering==-1) bJetID      = true;
01079 
01080   bool bBasicCleanup = bTechTriggers && bPrimaryVertex && bPhysicsDeclared;
01081   bool bExtraCleanup = bBasicCleanup && bHcalNoise && bJetID && bBeamHaloID;
01082 
01083   //std::string DirName = "JetMET/MET/"+_source;
01084   
01085   for (std::vector<std::string>::const_iterator ic = _FolderNames.begin(); 
01086        ic != _FolderNames.end(); ic++){
01087     if (*ic=="All")                                             fillMESet(iEvent, DirName+"/"+*ic, *calomet, *calometnohf);
01088     if (DCSFilter->filter(iEvent, iSetup)) {
01089       if (_cleanupSelection){
01090         if (*ic=="BasicCleanup"   && bBasicCleanup)                 fillMESet(iEvent, DirName+"/"+*ic, *calomet, *calometnohf);
01091         if (*ic=="ExtraCleanup"   && bExtraCleanup)                 fillMESet(iEvent, DirName+"/"+*ic, *calomet, *calometnohf);
01092       }
01093       if (_allSelection) {
01094         if (*ic=="HcalNoiseFilter"      && bHcalNoiseFilter )       fillMESet(iEvent, DirName+"/"+*ic, *calomet, *calometnohf);
01095         if (*ic=="HcalNoiseFilterTight" && bHcalNoiseFilterTight )  fillMESet(iEvent, DirName+"/"+*ic, *calomet, *calometnohf);
01096         if (*ic=="JetIDMinimal"         && bJetIDMinimal)           fillMESet(iEvent, DirName+"/"+*ic, *calomet, *calometnohf);
01097         if (*ic=="JetIDLoose"           && bJetIDLoose)             fillMESet(iEvent, DirName+"/"+*ic, *calomet, *calometnohf);
01098         if (*ic=="JetIDTight"           && bJetIDTight)             fillMESet(iEvent, DirName+"/"+*ic, *calomet, *calometnohf);
01099         if (*ic=="BeamHaloIDTightPass"  && bBeamHaloIDTightPass)    fillMESet(iEvent, DirName+"/"+*ic, *calomet, *calometnohf);
01100         if (*ic=="BeamHaloIDLoosePass"  && bBeamHaloIDLoosePass)    fillMESet(iEvent, DirName+"/"+*ic, *calomet, *calometnohf);
01101         if (*ic=="Triggers"             && bTechTriggers)           fillMESet(iEvent, DirName+"/"+*ic, *calomet, *calometnohf);
01102         if (*ic=="PV"                   && bPrimaryVertex)          fillMESet(iEvent, DirName+"/"+*ic, *calomet, *calometnohf);
01103       }
01104     } // DCS
01105   }
01106 } // CaloMETAnalyzer::analyze
01107 
01108 // ***********************************************************
01109 void CaloMETAnalyzer::computeEmHaMET(edm::Handle<edm::View<reco::Candidate> > towers)
01110 {
01111 
01112   edm::View<reco::Candidate>::const_iterator towerCand = towers->begin();
01113   
01114   double sum_em_et = 0.0;
01115   double sum_em_ex = 0.0;
01116   double sum_em_ey = 0.0;
01117   double sum_em_ez = 0.0;
01118   
01119   double sum_ha_et = 0.0;
01120   double sum_ha_ex = 0.0;
01121   double sum_ha_ey = 0.0;
01122   double sum_ha_ez = 0.0;
01123   
01124   for ( ; towerCand != towers->end(); towerCand++)
01125     {
01126       const reco::Candidate* candidate = &(*towerCand);
01127       if (candidate)
01128         {
01129           const CaloTower* calotower = dynamic_cast<const CaloTower*> (candidate);
01130           if (calotower){
01131             double Tower_ET = calotower->et();
01132             if (Tower_ET>0.3) {
01133               
01134               double phi   = candidate->phi();
01135               double theta = candidate->theta();
01136               //double e     = candidate->energy();
01137               double e_em  = calotower->emEnergy();
01138               double e_ha  = calotower->hadEnergy();
01139               double et_em = e_em*sin(theta);
01140               double et_ha = e_ha*sin(theta);
01141 
01142               sum_em_ez += e_em*cos(theta);
01143               sum_em_et += et_em;
01144               sum_em_ex += et_em*cos(phi);
01145               sum_em_ey += et_em*sin(phi);
01146 
01147               sum_ha_ez += e_ha*cos(theta);
01148               sum_ha_et += et_ha;
01149               sum_ha_ex += et_ha*cos(phi);
01150               sum_ha_ey += et_ha*sin(phi);
01151 
01152             } // Et>0.5
01153           }   // calotower
01154         }     // candidate
01155     }         // loop
01156   
01157   //
01158   _EmMEx = -sum_em_ex;
01159   _EmMEy = -sum_em_ey;
01160   _EmMET = pow(_EmMEx*_EmMEx+_EmMEy*_EmMEy,0.5);
01161   _EmCaloEz = sum_em_ez;
01162   _EmSumEt  = sum_em_et;
01163   _EmMetPhi   = atan2( _EmMEy, _EmMEx ); 
01164   //
01165   _HaMEx = -sum_ha_ex;
01166   _HaMEy = -sum_ha_ey;
01167   _HaMET = pow(_HaMEx*_HaMEx+_HaMEy*_HaMEy,0.5);
01168   _HaCaloEz = sum_ha_ez;
01169   _HaSumEt  = sum_ha_et;
01170   _HaMetPhi   = atan2( _HaMEy, _HaMEx ); 
01171   
01172 }
01173 // ***********************************************************
01174 void CaloMETAnalyzer::validateMET(const reco::CaloMET& calomet, 
01175                                   edm::Handle<edm::View<reco::Candidate> > towers)
01176 {
01177 
01178   edm::View<reco::Candidate>::const_iterator towerCand = towers->begin();
01179   
01180   double sum_et = 0.0;
01181   double sum_ex = 0.0;
01182   double sum_ey = 0.0;
01183   double sum_ez = 0.0;
01184   
01185   for ( ; towerCand != towers->end(); towerCand++)
01186     {
01187       const reco::Candidate* candidate = &(*towerCand);
01188       if (candidate)
01189         {
01190           const CaloTower* calotower = dynamic_cast<const CaloTower*> (candidate);
01191           if (calotower){
01192             double Tower_ET = calotower->et();
01193             if (Tower_ET>0.3) {
01194               
01195               double phi   = candidate->phi();
01196               double theta = candidate->theta();
01197               double e     = candidate->energy();
01198               double et    = e*sin(theta);
01199               sum_ez += e*cos(theta);
01200               sum_et += et;
01201               sum_ex += et*cos(phi);
01202               sum_ey += et*sin(phi);
01203 
01204             } // Et>0.5
01205           }   // calotower
01206         }     // candidate
01207     }         // loop
01208   
01209   double Mex   = -sum_ex;
01210   double Mey   = -sum_ey;
01211   //double Mez   = -sum_ez;
01212   double Met   = sqrt( sum_ex*sum_ex + sum_ey*sum_ey );
01213   double Sumet = sum_et;
01214   //double MetPhi   = atan2( -sum_ey, -sum_ex ); // since MET is now a candidate,
01215   
01216   if (_verbose){
01217     if (Sumet!=calomet.sumEt() || Mex!=calomet.px() || Mey!=calomet.py() || Met!=calomet.pt() ){
01218       std::cout << _source << std::endl;
01219       std::cout << "SUMET" << Sumet << " METBlock" << calomet.sumEt() << std::endl;
01220       std::cout << "MEX"   << Mex   << " METBlock" << calomet.px()    << std::endl;
01221       std::cout << "MEY"   << Mey   << " METBlock" << calomet.py()    << std::endl;
01222       std::cout << "MET"   << Met   << " METBlock" << calomet.pt()    << std::endl;
01223     }
01224   }  
01225 
01226   if (_print){
01227     std::cout << "SUMET = " << calomet.sumEt() << " (GeV) "
01228               << "MEX"   << calomet.px() << " (GeV) "
01229               << "MEY"   << calomet.py() << " (GeV) " 
01230               << "MET"   << calomet.pt() << " (GeV) " << std::endl;
01231   }
01232 
01233 }
01234 
01235 // ***********************************************************
01236 void CaloMETAnalyzer::fillMESet(const edm::Event& iEvent, std::string DirName, 
01237                                 const reco::CaloMET& calomet,
01238                                 const reco::CaloMET& calometnohf)
01239 {
01240 
01241   _dbe->setCurrentFolder(DirName);
01242 
01243   bool bLumiSecPlot=false;
01244   if (DirName.find("All")) bLumiSecPlot=true;
01245 
01246   if (_trig_JetMB)
01247     fillMonitorElement(iEvent,DirName,"",calomet,calometnohf, bLumiSecPlot);
01248   if (_trig_HighPtJet)
01249     fillMonitorElementTriggered(iEvent,DirName,"HighPtJet",calomet,calometnohf,false);
01250   if (_trig_LowPtJet)
01251     fillMonitorElementTriggered(iEvent,DirName,"LowPtJet",calomet,calometnohf,false);
01252   if (_trig_MinBias)
01253     fillMonitorElementTriggered(iEvent,DirName,"MinBias",calomet,calometnohf,false);
01254   if (_trig_HighMET)
01255     fillMonitorElementTriggered(iEvent,DirName,"HighMET",calomet,calometnohf,false);
01256   if (_trig_LowMET)
01257     fillMonitorElementTriggered(iEvent,DirName,"LowMET",calomet,calometnohf,false);
01258   if (_trig_Ele)
01259     fillMonitorElementTriggered(iEvent,DirName,"Ele",calomet,calometnohf,false);
01260   if (_trig_Muon) {
01261     fillMonitorElementTriggered(iEvent,DirName,"Muon",calomet,calometnohf,false);
01262   }
01263 }
01264 
01265 // ***********************************************************
01266 void CaloMETAnalyzer::fillMonitorElement(const edm::Event& iEvent, std::string DirName, 
01267                                          std::string TriggerTypeName, 
01268                                          const reco::CaloMET& calomet,
01269                                          const reco::CaloMET& calometnohf,
01270                                          bool bLumiSecPlot)
01271 {
01272   fillMonitorElementTriggered(iEvent, DirName, TriggerTypeName, calomet, calometnohf, bLumiSecPlot);
01273 
01274   /*
01275   if (TriggerTypeName=="HighPtJet") {
01276     if (!selectHighPtJetEvent(iEvent)) return;
01277   }
01278   else if (TriggerTypeName=="LowPtJet") {
01279     if (!selectLowPtJetEvent(iEvent)) return;
01280   }
01281   else if (TriggerTypeName=="HighMET") {
01282     if (calomet.pt()<_highMETThreshold) return;
01283   }
01284   else if (TriggerTypeName=="LowMET") {
01285     if (calomet.pt()<_lowMETThreshold) return;
01286   }
01287   else if (TriggerTypeName=="Ele") {
01288     if (!selectWElectronEvent(iEvent)) return;
01289   }
01290   else if (TriggerTypeName=="Muon") {
01291     if (!selectWMuonEvent(iEvent)) return;
01292   }
01293   */
01294   double caloSumET  = calomet.sumEt();
01295   /*
01296   double caloMETSig = calomet.mEtSig();
01297   //double caloEz     = calomet.e_longitudinal();
01298   double caloMET    = calomet.pt();
01299   double caloMEx    = calomet.px();
01300   double caloMEy    = calomet.py();
01301   double caloMETPhi = calomet.phi();
01302 
01303   double caloMETNoHF    = calometnohf.pt();
01304   //double caloMETNoHFPhi = calometnohf.phi();
01305 
01306   if (_verbose) std::cout << _source << " " << caloMET << std::endl;
01307 
01308   double caloEtFractionHadronic = calomet.etFractionHadronic();
01309   double caloEmEtFraction       = calomet.emEtFraction();
01310   */
01311   double caloMaxEtInEMTowers    = calomet.maxEtInEmTowers();
01312   double caloMaxEtInHadTowers   = calomet.maxEtInHadTowers();
01313 
01314   double caloHadEtInHB = calomet.hadEtInHB();
01315   double caloHadEtInHO = calomet.hadEtInHO();
01316   double caloHadEtInHE = calomet.hadEtInHE();
01317   double caloHadEtInHF = calomet.hadEtInHF();
01318   double caloEmEtInEB  = calomet.emEtInEB();
01319   double caloEmEtInEE  = calomet.emEtInEE();
01320   double caloEmEtInHF  = calomet.emEtInHF();
01321   //
01322   //  int myLuminosityBlock;
01323   //  myLuminosityBlock = (evtCounter++)/1000;
01324   //  myLuminosityBlock = iEvent.luminosityBlock();
01325   //
01326 
01327   if (TriggerTypeName!="") DirName = DirName +"/"+TriggerTypeName;
01328 
01329   if (_verbose) std::cout << "_etThreshold = " << _etThreshold << std::endl;
01330   if (caloSumET>_etThreshold){
01331   /*
01332     hCaloMEx    = _dbe->get(DirName+"/"+"METTask_CaloMEx");    if (hCaloMEx     && hCaloMEx->getRootObject() )    hCaloMEx->Fill(caloMEx);
01333     hCaloMEy    = _dbe->get(DirName+"/"+"METTask_CaloMEy");    if (hCaloMEy     && hCaloMEy->getRootObject() )    hCaloMEy->Fill(caloMEy);
01334     hCaloMET    = _dbe->get(DirName+"/"+"METTask_CaloMET");    if (hCaloMET     && hCaloMET->getRootObject() )    hCaloMET->Fill(caloMET);
01335     hCaloMET1   = _dbe->get(DirName+"/"+"METTask_CaloMET1");   if (hCaloMET1    && hCaloMET1->getRootObject() )   hCaloMET1->Fill(caloMET);
01336     hCaloMETPhi = _dbe->get(DirName+"/"+"METTask_CaloMETPhi"); if (hCaloMETPhi  && hCaloMETPhi->getRootObject() ) hCaloMETPhi->Fill(caloMETPhi);
01337     hCaloSumET  = _dbe->get(DirName+"/"+"METTask_CaloSumET");  if (hCaloSumET   && hCaloSumET->getRootObject() )  hCaloSumET->Fill(caloSumET);
01338     hCaloMETSig = _dbe->get(DirName+"/"+"METTask_CaloMETSig"); if (hCaloMETSig  && hCaloMETSig->getRootObject() ) hCaloMETSig->Fill(caloMETSig);
01339     //hCaloEz     = _dbe->get(DirName+"/"+"METTask_CaloEz");     if (hCaloEz      && hCaloEz->getRootObject() )     hCaloEz->Fill(caloEz);
01340     
01341     hCaloMETNoHF    = _dbe->get(DirName+"/"+"METTask_CaloMETNoHF");    if (hCaloMETNoHF     && hCaloMETNoHF->getRootObject() )    hCaloMETNoHF->Fill(caloMETNoHF);
01342     
01343     hCaloMET_logx   = _dbe->get(DirName+"/"+"METTask_CaloMET_logx");      if (hCaloMET_logx    && hCaloMET_logx->getRootObject() )   hCaloMET_logx->Fill(log10(caloMET));
01344     hCaloSumET_logx = _dbe->get(DirName+"/"+"METTask_CaloSumET_logx");    if (hCaloSumET_logx  && hCaloSumET_logx->getRootObject() ) hCaloSumET_logx->Fill(log10(caloSumET));
01345     
01346     //  hCaloMETIonFeedbck = _dbe->get(DirName+"/"+"METTask_CaloMETIonFeedbck"); if (hCaloMETIonFeedbck  && hCaloMETIonFeedbck->getRootObject() ) hCaloMETIonFeedbck->Fill(caloMET);
01347     //  hCaloMETHPDNoise   = _dbe->get(DirName+"/"+"METTask_CaloMETHPDNoise");   if (hCaloMETHPDNoise    && hCaloMETHPDNoise->getRootObject() )   hCaloMETHPDNoise->Fill(caloMET);
01348 
01349     //hCaloMETPhi002 = _dbe->get(DirName+"/"+"METTask_CaloMETPhi002");    if (caloMET>  2. && hCaloMETPhi002  &&  hCaloMETPhi002->getRootObject()) { hCaloMETPhi002->Fill(caloMETPhi);}
01350     //hCaloMETPhi010 = _dbe->get(DirName+"/"+"METTask_CaloMETPhi010");    if (caloMET> 10. && hCaloMETPhi010  &&  hCaloMETPhi010->getRootObject()) { hCaloMETPhi010->Fill(caloMETPhi);}
01351     hCaloMETPhi020 = _dbe->get(DirName+"/"+"METTask_CaloMETPhi020");    if (caloMET> 20. && hCaloMETPhi020  &&  hCaloMETPhi020->getRootObject()) { hCaloMETPhi020->Fill(caloMETPhi);}
01352   */
01353   
01354     if (_allhist){
01355       /*
01356       if (bLumiSecPlot){
01357         hCaloMExLS = _dbe->get(DirName+"/"+"METTask_CaloMEx_LS");   if (hCaloMExLS  &&  hCaloMExLS->getRootObject())    hCaloMExLS->Fill(caloMEx,myLuminosityBlock);
01358         hCaloMEyLS = _dbe->get(DirName+"/"+"METTask_CaloMEy_LS");   if (hCaloMEyLS  &&  hCaloMEyLS->getRootObject())    hCaloMEyLS->Fill(caloMEy,myLuminosityBlock);
01359       }
01360       hCaloEtFractionHadronic = _dbe->get(DirName+"/"+"METTask_CaloEtFractionHadronic"); if (hCaloEtFractionHadronic && hCaloEtFractionHadronic->getRootObject())  hCaloEtFractionHadronic->Fill(caloEtFractionHadronic);
01361       hCaloEmEtFraction       = _dbe->get(DirName+"/"+"METTask_CaloEmEtFraction");       if (hCaloEmEtFraction       && hCaloEmEtFraction->getRootObject())        hCaloEmEtFraction->Fill(caloEmEtFraction);
01362       
01363       //hCaloEmEtFraction002 = _dbe->get(DirName+"/"+"METTask_CaloEmEtFraction002");       if (caloMET>  2.  &&  hCaloEmEtFraction002    && hCaloEmEtFraction002->getRootObject()) hCaloEmEtFraction002->Fill(caloEmEtFraction);
01364       //hCaloEmEtFraction010 = _dbe->get(DirName+"/"+"METTask_CaloEmEtFraction010");       if (caloMET> 10.  &&  hCaloEmEtFraction010    && hCaloEmEtFraction010->getRootObject()) hCaloEmEtFraction010->Fill(caloEmEtFraction);
01365       hCaloEmEtFraction020 = _dbe->get(DirName+"/"+"METTask_CaloEmEtFraction020");       if (caloMET> 20.  &&  hCaloEmEtFraction020    && hCaloEmEtFraction020->getRootObject()) hCaloEmEtFraction020->Fill(caloEmEtFraction);
01366       */
01367 
01368       hCaloMaxEtInEmTowers  = _dbe->get(DirName+"/"+"METTask_CaloMaxEtInEmTowers");   if (hCaloMaxEtInEmTowers  && hCaloMaxEtInEmTowers->getRootObject())   hCaloMaxEtInEmTowers->Fill(caloMaxEtInEMTowers);
01369       hCaloMaxEtInHadTowers = _dbe->get(DirName+"/"+"METTask_CaloMaxEtInHadTowers");  if (hCaloMaxEtInHadTowers && hCaloMaxEtInHadTowers->getRootObject())  hCaloMaxEtInHadTowers->Fill(caloMaxEtInHadTowers);
01370 
01371       hCaloHadEtInHB = _dbe->get(DirName+"/"+"METTask_CaloHadEtInHB");  if (hCaloHadEtInHB  &&  hCaloHadEtInHB->getRootObject())  hCaloHadEtInHB->Fill(caloHadEtInHB);
01372       hCaloHadEtInHO = _dbe->get(DirName+"/"+"METTask_CaloHadEtInHO");  if (hCaloHadEtInHO  &&  hCaloHadEtInHO->getRootObject())  hCaloHadEtInHO->Fill(caloHadEtInHO);
01373       hCaloHadEtInHE = _dbe->get(DirName+"/"+"METTask_CaloHadEtInHE");  if (hCaloHadEtInHE  &&  hCaloHadEtInHE->getRootObject())  hCaloHadEtInHE->Fill(caloHadEtInHE);
01374       hCaloHadEtInHF = _dbe->get(DirName+"/"+"METTask_CaloHadEtInHF");  if (hCaloHadEtInHF  &&  hCaloHadEtInHF->getRootObject())  hCaloHadEtInHF->Fill(caloHadEtInHF);
01375       hCaloEmEtInEB  = _dbe->get(DirName+"/"+"METTask_CaloEmEtInEB");   if (hCaloEmEtInEB   &&  hCaloEmEtInEB->getRootObject())   hCaloEmEtInEB->Fill(caloEmEtInEB);
01376       hCaloEmEtInEE  = _dbe->get(DirName+"/"+"METTask_CaloEmEtInEE");   if (hCaloEmEtInEE   &&  hCaloEmEtInEE->getRootObject())   hCaloEmEtInEE->Fill(caloEmEtInEE);
01377       hCaloEmEtInHF  = _dbe->get(DirName+"/"+"METTask_CaloEmEtInHF");   if (hCaloEmEtInHF   &&  hCaloEmEtInHF->getRootObject())   hCaloEmEtInHF->Fill(caloEmEtInHF);
01378 
01379       hCaloEmMEx    = _dbe->get(DirName+"/"+"METTask_CaloEmMEx");     if (hCaloEmMEx    && hCaloEmMEx->getRootObject())     hCaloEmMEx->Fill(_EmMEx);
01380       hCaloEmMEy    = _dbe->get(DirName+"/"+"METTask_CaloEmMEy");     if (hCaloEmMEy    && hCaloEmMEy->getRootObject())     hCaloEmMEy->Fill(_EmMEy);
01381       //hCaloEmEz     = _dbe->get(DirName+"/"+"METTask_CaloEmEz");      if (hCaloEmEz     && hCaloEmEz->getRootObject())      hCaloEmEz->Fill(_EmCaloEz);
01382       hCaloEmMET    = _dbe->get(DirName+"/"+"METTask_CaloEmMET");     if (hCaloEmMET    && hCaloEmMET->getRootObject())     hCaloEmMET->Fill(_EmMET);
01383       hCaloEmMETPhi = _dbe->get(DirName+"/"+"METTask_CaloEmMETPhi");  if (hCaloEmMETPhi && hCaloEmMETPhi->getRootObject())  hCaloEmMETPhi->Fill(_EmMetPhi);
01384       //hCaloEmSumET  = _dbe->get(DirName+"/"+"METTask_CaloEmSumET");   if (hCaloEmSumET  && hCaloEmSumET->getRootObject())   hCaloEmSumET->Fill(_EmSumEt);
01385 
01386       hCaloHaMEx    = _dbe->get(DirName+"/"+"METTask_CaloHaMEx");     if (hCaloHaMEx    && hCaloHaMEx->getRootObject())     hCaloHaMEx->Fill(_HaMEx);
01387       hCaloHaMEy    = _dbe->get(DirName+"/"+"METTask_CaloHaMEy");     if (hCaloHaMEy    && hCaloHaMEy->getRootObject())     hCaloHaMEy->Fill(_HaMEy);
01388       //hCaloHaEz     = _dbe->get(DirName+"/"+"METTask_CaloHaEz");      if (hCaloHaEz     && hCaloHaEz->getRootObject())      hCaloHaEz->Fill(_HaCaloEz);
01389       hCaloHaMET    = _dbe->get(DirName+"/"+"METTask_CaloHaMET");     if (hCaloHaMET    && hCaloHaMET->getRootObject())     hCaloHaMET->Fill(_HaMET);
01390       hCaloHaMETPhi = _dbe->get(DirName+"/"+"METTask_CaloHaMETPhi");  if (hCaloHaMETPhi && hCaloHaMETPhi->getRootObject())  hCaloHaMETPhi->Fill(_HaMetPhi);
01391       //hCaloHaSumET  = _dbe->get(DirName+"/"+"METTask_CaloHaSumET");   if (hCaloHaSumET  && hCaloHaSumET->getRootObject())   hCaloHaSumET->Fill(_HaSumEt);
01392 
01393     } // _allhist
01394     /*
01395     if (theCaloMETCollectionLabel.label() == "corMetGlobalMuons" ) {
01396 
01397       for( reco::MuonCollection::const_iterator muonit = muon_h->begin(); muonit != muon_h->end(); muonit++ ) {
01398         const reco::TrackRef siTrack = muonit->innerTrack();
01399         hCalomuPt    = _dbe->get(DirName+"/"+"METTask_CalomuPt");     if (hCalomuPt    && hCalomuPt->getRootObject())     hCalomuPt->Fill( muonit->p4().pt() );
01400         hCalomuEta   = _dbe->get(DirName+"/"+"METTask_CalomuEta");    if (hCalomuEta   && hCalomuEta->getRootObject())    hCalomuEta->Fill( muonit->p4().eta() );
01401         hCalomuNhits = _dbe->get(DirName+"/"+"METTask_CalomuNhits");  if (hCalomuNhits && hCalomuNhits->getRootObject())  hCalomuNhits->Fill( siTrack.isNonnull() ? siTrack->numberOfValidHits() : -999 );
01402         hCalomuChi2  = _dbe->get(DirName+"/"+"METTask_CalomuChi2");   if (hCalomuChi2  && hCalomuChi2->getRootObject())   hCalomuChi2->Fill( siTrack.isNonnull() ? siTrack->chi2()/siTrack->ndof() : -999 );
01403         double d0 = siTrack.isNonnull() ? -1 * siTrack->dxy( bspot) : -999;
01404         hCalomuD0    = _dbe->get(DirName+"/"+"METTask_CalomuD0");     if (hCalomuD0    && hCalomuD0->getRootObject())  hCalomuD0->Fill( d0 );
01405       }
01406       
01407       const unsigned int nMuons = muon_h->size();      
01408       for( unsigned int mus = 0; mus < nMuons; mus++ ) {
01409         reco::MuonRef muref( muon_h, mus);
01410         reco::MuonMETCorrectionData muCorrData = (*corMetGlobalMuons_ValueMap_Handle)[muref];
01411         hCaloMExCorrection      = _dbe->get(DirName+"/"+"METTask_CaloMExCorrection");       if (hCaloMExCorrection      && hCaloMExCorrection->getRootObject())       hCaloMExCorrection-> Fill(muCorrData.corrY());
01412         hCaloMEyCorrection      = _dbe->get(DirName+"/"+"METTask_CaloMEyCorrection");       if (hCaloMEyCorrection      && hCaloMEyCorrection->getRootObject())       hCaloMEyCorrection-> Fill(muCorrData.corrX());
01413         hCaloMuonCorrectionFlag = _dbe->get(DirName+"/"+"METTask_CaloMuonCorrectionFlag");  if (hCaloMuonCorrectionFlag && hCaloMuonCorrectionFlag->getRootObject())  hCaloMuonCorrectionFlag-> Fill(muCorrData.type());
01414       }
01415     }    
01416     */
01417   } // et threshold cut
01418 
01419 }
01420 
01421 // ***********************************************************
01422 void CaloMETAnalyzer::fillMonitorElementTriggered(const edm::Event& iEvent, std::string DirName, 
01423                                                   std::string TriggerTypeName, 
01424                                                   const reco::CaloMET& calomet,
01425                                                   const reco::CaloMET& calometnohf,
01426                                                   bool bLumiSecPlot)
01427 {
01428 
01429   if (TriggerTypeName=="HighPtJet") {
01430     if (!selectHighPtJetEvent(iEvent)) return;
01431   }
01432   else if (TriggerTypeName=="LowPtJet") {
01433     if (!selectLowPtJetEvent(iEvent)) return;
01434   }
01435   else if (TriggerTypeName=="HighMET") {
01436     if (calomet.pt()<_highMETThreshold) return;
01437   }
01438   else if (TriggerTypeName=="LowMET") {
01439     if (calomet.pt()<_lowMETThreshold) return;
01440   }
01441   else if (TriggerTypeName=="Ele") {
01442     if (!selectWElectronEvent(iEvent)) return;
01443   }
01444   else if (TriggerTypeName=="Muon") {
01445     if (!selectWMuonEvent(iEvent)) return;
01446   }
01447 
01448   double caloSumET  = calomet.sumEt();
01449   double caloMETSig = calomet.mEtSig();
01450   //double caloEz     = calomet.e_longitudinal();
01451   double caloMET    = calomet.pt();
01452   double caloMEx    = calomet.px();
01453   double caloMEy    = calomet.py();
01454   double caloMETPhi = calomet.phi();
01455 
01456   double caloMETNoHF    = calometnohf.pt();
01457   //double caloMETNoHFPhi = calometnohf.phi();
01458 
01459   if (_verbose) std::cout << _source << " " << caloMET << std::endl;
01460 
01461   double caloEtFractionHadronic = calomet.etFractionHadronic();
01462   double caloEmEtFraction       = calomet.emEtFraction();
01463 
01464   //double caloMaxEtInEMTowers    = calomet.maxEtInEmTowers();
01465   //double caloMaxEtInHadTowers   = calomet.maxEtInHadTowers();
01466 
01467   //double caloHadEtInHB = calomet.hadEtInHB();
01468   //double caloHadEtInHO = calomet.hadEtInHO();
01469   //double caloHadEtInHE = calomet.hadEtInHE();
01470   //double caloHadEtInHF = calomet.hadEtInHF();
01471   //double caloEmEtInEB  = calomet.emEtInEB();
01472   //double caloEmEtInEE  = calomet.emEtInEE();
01473   //double caloEmEtInHF  = calomet.emEtInHF();
01474 
01475   //
01476   int myLuminosityBlock;
01477   //  myLuminosityBlock = (evtCounter++)/1000;
01478   myLuminosityBlock = iEvent.luminosityBlock();
01479   //
01480 
01481   if (TriggerTypeName!="") DirName = DirName +"/"+TriggerTypeName;
01482 
01483   if (_verbose) std::cout << "_etThreshold = " << _etThreshold << std::endl;
01484   if (caloSumET>_etThreshold){
01485     hCaloMEx    = _dbe->get(DirName+"/"+"METTask_CaloMEx");    if (hCaloMEx     && hCaloMEx->getRootObject() )    hCaloMEx->Fill(caloMEx);
01486     hCaloMEy    = _dbe->get(DirName+"/"+"METTask_CaloMEy");    if (hCaloMEy     && hCaloMEy->getRootObject() )    hCaloMEy->Fill(caloMEy);
01487     hCaloMET    = _dbe->get(DirName+"/"+"METTask_CaloMET");    if (hCaloMET     && hCaloMET->getRootObject() )    hCaloMET->Fill(caloMET);
01488     hCaloMET1   = _dbe->get(DirName+"/"+"METTask_CaloMET1");   if (hCaloMET1    && hCaloMET1->getRootObject() )   hCaloMET1->Fill(caloMET);
01489     hCaloMETPhi = _dbe->get(DirName+"/"+"METTask_CaloMETPhi"); if (hCaloMETPhi  && hCaloMETPhi->getRootObject() ) hCaloMETPhi->Fill(caloMETPhi);
01490     hCaloSumET  = _dbe->get(DirName+"/"+"METTask_CaloSumET");  if (hCaloSumET   && hCaloSumET->getRootObject() )  hCaloSumET->Fill(caloSumET);
01491     hCaloMETSig = _dbe->get(DirName+"/"+"METTask_CaloMETSig"); if (hCaloMETSig  && hCaloMETSig->getRootObject() ) hCaloMETSig->Fill(caloMETSig);
01492     //hCaloEz     = _dbe->get(DirName+"/"+"METTask_CaloEz");     if (hCaloEz      && hCaloEz->getRootObject() )     hCaloEz->Fill(caloEz);
01493 
01494     hCaloMETNoHF    = _dbe->get(DirName+"/"+"METTask_CaloMETNoHF");    if (hCaloMETNoHF     && hCaloMETNoHF->getRootObject() )    hCaloMETNoHF->Fill(caloMETNoHF);
01495 
01496     hCaloMET_logx   = _dbe->get(DirName+"/"+"METTask_CaloMET_logx");      if (hCaloMET_logx    && hCaloMET_logx->getRootObject() )   hCaloMET_logx->Fill(log10(caloMET));
01497     hCaloSumET_logx = _dbe->get(DirName+"/"+"METTask_CaloSumET_logx");    if (hCaloSumET_logx  && hCaloSumET_logx->getRootObject() ) hCaloSumET_logx->Fill(log10(caloSumET));
01498 
01499 
01500     // Fill NPV profiles
01501     //--------------------------------------------------------------------------
01502     hCaloMEx_profile     = _dbe->get(DirName + "/METTask_CaloMEx_profile");
01503     hCaloMEy_profile     = _dbe->get(DirName + "/METTask_CaloMEy_profile");
01504     hCaloMET_profile     = _dbe->get(DirName + "/METTask_CaloMET_profile");
01505     hCaloMETNoHF_profile = _dbe->get(DirName + "/METTask_CaloMETNoHF_profile");
01506     hCaloSumET_profile   = _dbe->get(DirName + "/METTask_CaloSumET_profile");
01507     
01508     if (hCaloMEx_profile     && hCaloMEx_profile    ->getRootObject()) hCaloMEx_profile    ->Fill(_numPV, caloMEx);
01509     if (hCaloMEy_profile     && hCaloMEy_profile    ->getRootObject()) hCaloMEy_profile    ->Fill(_numPV, caloMEy);
01510     if (hCaloMET_profile     && hCaloMET_profile    ->getRootObject()) hCaloMET_profile    ->Fill(_numPV, caloMET);
01511     if (hCaloMETNoHF_profile && hCaloMETNoHF_profile->getRootObject()) hCaloMETNoHF_profile->Fill(_numPV, caloMETNoHF);
01512     if (hCaloSumET_profile   && hCaloSumET_profile  ->getRootObject()) hCaloSumET_profile  ->Fill(_numPV, caloSumET);
01513 
01514 
01515     //hCaloEz     = _dbe->get(DirName+"/"+"METTask_CaloEz_profile");     if (hCaloEz      && hCaloEz_profile->getRootObject() )     hCaloEz_profile->Fill(caloEz);
01516     //  hCaloMETIonFeedbck = _dbe->get(DirName+"/"+"METTask_CaloMETIonFeedbck"); if (hCaloMETIonFeedbck  && hCaloMETIonFeedbck->getRootObject() ) hCaloMETIonFeedbck->Fill(caloMET);
01517     //  haloMETHPDNoise   = _dbe->get(DirName+"/"+"METTask_CaloMETHPDNoise");   if (hCaloMETHPDNoise    && hCaloMETHPDNoise->getRootObject() )   hCaloMETHPDNoise->Fill(caloMET);
01518 
01519     //hCaloMETPhi002 = _dbe->get(DirName+"/"+"METTask_CaloMETPhi002");    if (caloMET>  2. && hCaloMETPhi002  &&  hCaloMETPhi002->getRootObject()) { hCaloMETPhi002->Fill(caloMETPhi);}
01520     //hCaloMETPhi010 = _dbe->get(DirName+"/"+"METTask_CaloMETPhi010");    if (caloMET> 10. && hCaloMETPhi010  &&  hCaloMETPhi010->getRootObject()) { hCaloMETPhi010->Fill(caloMETPhi);}
01521     hCaloMETPhi020 = _dbe->get(DirName+"/"+"METTask_CaloMETPhi020");    if (caloMET> 20. && hCaloMETPhi020  &&  hCaloMETPhi020->getRootObject()) { hCaloMETPhi020->Fill(caloMETPhi);}
01522 
01523     if (_allhist){
01524       if (bLumiSecPlot){
01525         hCaloMExLS = _dbe->get(DirName+"/"+"METTask_CaloMEx_LS");   if (hCaloMExLS  &&  hCaloMExLS->getRootObject())    hCaloMExLS->Fill(caloMEx,myLuminosityBlock);
01526         hCaloMEyLS = _dbe->get(DirName+"/"+"METTask_CaloMEy_LS");   if (hCaloMEyLS  &&  hCaloMEyLS->getRootObject())    hCaloMEyLS->Fill(caloMEy,myLuminosityBlock);
01527       }
01528       
01529       hCaloEtFractionHadronic = _dbe->get(DirName+"/"+"METTask_CaloEtFractionHadronic"); if (hCaloEtFractionHadronic && hCaloEtFractionHadronic->getRootObject())  hCaloEtFractionHadronic->Fill(caloEtFractionHadronic);
01530       hCaloEmEtFraction       = _dbe->get(DirName+"/"+"METTask_CaloEmEtFraction");       if (hCaloEmEtFraction       && hCaloEmEtFraction->getRootObject())        hCaloEmEtFraction->Fill(caloEmEtFraction);
01531       
01532       //hCaloEmEtFraction002 = _dbe->get(DirName+"/"+"METTask_CaloEmEtFraction002");       if (caloMET>  2.  &&  hCaloEmEtFraction002    && hCaloEmEtFraction002->getRootObject()) hCaloEmEtFraction002->Fill(caloEmEtFraction);
01533       //hCaloEmEtFraction010 = _dbe->get(DirName+"/"+"METTask_CaloEmEtFraction010");       if (caloMET> 10.  &&  hCaloEmEtFraction010    && hCaloEmEtFraction010->getRootObject()) hCaloEmEtFraction010->Fill(caloEmEtFraction);
01534       hCaloEmEtFraction020 = _dbe->get(DirName+"/"+"METTask_CaloEmEtFraction020");       if (caloMET> 20.  &&  hCaloEmEtFraction020    && hCaloEmEtFraction020->getRootObject()) hCaloEmEtFraction020->Fill(caloEmEtFraction);
01535 
01536       //hCaloMaxEtInEmTowers  = _dbe->get(DirName+"/"+"METTask_CaloMaxEtInEmTowers");   if (hCaloMaxEtInEmTowers  && hCaloMaxEtInEmTowers->getRootObject())   hCaloMaxEtInEmTowers->Fill(caloMaxEtInEMTowers);
01537       //hCaloMaxEtInHadTowers = _dbe->get(DirName+"/"+"METTask_CaloMaxEtInHadTowers");  if (hCaloMaxEtInHadTowers && hCaloMaxEtInHadTowers->getRootObject())  hCaloMaxEtInHadTowers->Fill(caloMaxEtInHadTowers);
01538       //
01539       //hCaloHadEtInHB = _dbe->get(DirName+"/"+"METTask_CaloHadEtInHB");  if (hCaloHadEtInHB  &&  hCaloHadEtInHB->getRootObject())  hCaloHadEtInHB->Fill(caloHadEtInHB);
01540       //hCaloHadEtInHO = _dbe->get(DirName+"/"+"METTask_CaloHadEtInHO");  if (hCaloHadEtInHO  &&  hCaloHadEtInHO->getRootObject())  hCaloHadEtInHO->Fill(caloHadEtInHO);
01541       //hCaloHadEtInHE = _dbe->get(DirName+"/"+"METTask_CaloHadEtInHE");  if (hCaloHadEtInHE  &&  hCaloHadEtInHE->getRootObject())  hCaloHadEtInHE->Fill(caloHadEtInHE);
01542       //hCaloHadEtInHF = _dbe->get(DirName+"/"+"METTask_CaloHadEtInHF");  if (hCaloHadEtInHF  &&  hCaloHadEtInHF->getRootObject())  hCaloHadEtInHF->Fill(caloHadEtInHF);
01543       //hCaloEmEtInEB  = _dbe->get(DirName+"/"+"METTask_CaloEmEtInEB");   if (hCaloEmEtInEB   &&  hCaloEmEtInEB->getRootObject())   hCaloEmEtInEB->Fill(caloEmEtInEB);
01544       //hCaloEmEtInEE  = _dbe->get(DirName+"/"+"METTask_CaloEmEtInEE");   if (hCaloEmEtInEE   &&  hCaloEmEtInEE->getRootObject())   hCaloEmEtInEE->Fill(caloEmEtInEE);
01545       //hCaloEmEtInHF  = _dbe->get(DirName+"/"+"METTask_CaloEmEtInHF");   if (hCaloEmEtInHF   &&  hCaloEmEtInHF->getRootObject())   hCaloEmEtInHF->Fill(caloEmEtInHF);
01546       //
01547       //hCaloEmMEx    = _dbe->get(DirName+"/"+"METTask_CaloEmMEx");     if (hCaloEmMEx    && hCaloEmMEx->getRootObject())     hCaloEmMEx->Fill(_EmMEx);
01548       //hCaloEmMEy    = _dbe->get(DirName+"/"+"METTask_CaloEmMEy");     if (hCaloEmMEy    && hCaloEmMEy->getRootObject())     hCaloEmMEy->Fill(_EmMEy);
01550       //hCaloEmMET    = _dbe->get(DirName+"/"+"METTask_CaloEmMET");     if (hCaloEmMET    && hCaloEmMET->getRootObject())     hCaloEmMET->Fill(_EmMET);
01551       //hCaloEmMETPhi = _dbe->get(DirName+"/"+"METTask_CaloEmMETPhi");  if (hCaloEmMETPhi && hCaloEmMETPhi->getRootObject())  hCaloEmMETPhi->Fill(_EmMetPhi);
01553       //
01554       //hCaloHaMEx    = _dbe->get(DirName+"/"+"METTask_CaloHaMEx");     if (hCaloHaMEx    && hCaloHaMEx->getRootObject())     hCaloHaMEx->Fill(_HaMEx);
01555       //hCaloHaMEy    = _dbe->get(DirName+"/"+"METTask_CaloHaMEy");     if (hCaloHaMEy    && hCaloHaMEy->getRootObject())     hCaloHaMEy->Fill(_HaMEy);
01557       //hCaloHaMET    = _dbe->get(DirName+"/"+"METTask_CaloHaMET");     if (hCaloHaMET    && hCaloHaMET->getRootObject())     hCaloHaMET->Fill(_HaMET);
01558       //hCaloHaMETPhi = _dbe->get(DirName+"/"+"METTask_CaloHaMETPhi");  if (hCaloHaMETPhi && hCaloHaMETPhi->getRootObject())  hCaloHaMETPhi->Fill(_HaMetPhi);
01560 
01561     } // _allhist
01562     if (theCaloMETCollectionLabel.label() == "corMetGlobalMuons" ) {
01563 
01564       for( reco::MuonCollection::const_iterator muonit = muon_h->begin(); muonit != muon_h->end(); muonit++ ) {
01565         const reco::TrackRef siTrack = muonit->innerTrack();
01566         hCalomuPt    = _dbe->get(DirName+"/"+"METTask_CalomuPt");     if (hCalomuPt    && hCalomuPt->getRootObject())     hCalomuPt->Fill( muonit->p4().pt() );
01567         hCalomuEta   = _dbe->get(DirName+"/"+"METTask_CalomuEta");    if (hCalomuEta   && hCalomuEta->getRootObject())    hCalomuEta->Fill( muonit->p4().eta() );
01568         hCalomuNhits = _dbe->get(DirName+"/"+"METTask_CalomuNhits");  if (hCalomuNhits && hCalomuNhits->getRootObject())  hCalomuNhits->Fill( siTrack.isNonnull() ? siTrack->numberOfValidHits() : -999 );
01569         hCalomuChi2  = _dbe->get(DirName+"/"+"METTask_CalomuChi2");   if (hCalomuChi2  && hCalomuChi2->getRootObject())   hCalomuChi2->Fill( siTrack.isNonnull() ? siTrack->chi2()/siTrack->ndof() : -999 );
01570         double d0 = siTrack.isNonnull() ? -1 * siTrack->dxy( bspot) : -999;
01571         hCalomuD0    = _dbe->get(DirName+"/"+"METTask_CalomuD0");     if (hCalomuD0    && hCalomuD0->getRootObject())  hCalomuD0->Fill( d0 );
01572       }
01573       
01574       const unsigned int nMuons = muon_h->size();      
01575       for( unsigned int mus = 0; mus < nMuons; mus++ ) {
01576         reco::MuonRef muref( muon_h, mus);
01577         reco::MuonMETCorrectionData muCorrData = (*corMetGlobalMuons_ValueMap_Handle)[muref];
01578         hCaloMExCorrection      = _dbe->get(DirName+"/"+"METTask_CaloMExCorrection");       if (hCaloMExCorrection      && hCaloMExCorrection->getRootObject())       hCaloMExCorrection-> Fill(muCorrData.corrY());
01579         hCaloMEyCorrection      = _dbe->get(DirName+"/"+"METTask_CaloMEyCorrection");       if (hCaloMEyCorrection      && hCaloMEyCorrection->getRootObject())       hCaloMEyCorrection-> Fill(muCorrData.corrX());
01580         hCaloMuonCorrectionFlag = _dbe->get(DirName+"/"+"METTask_CaloMuonCorrectionFlag");  if (hCaloMuonCorrectionFlag && hCaloMuonCorrectionFlag->getRootObject())  hCaloMuonCorrectionFlag-> Fill(muCorrData.type());
01581       }
01582     }    
01583   } // et threshold cut
01584 
01585 }
01586 
01587 // ***********************************************************
01588 bool CaloMETAnalyzer::selectHighPtJetEvent(const edm::Event& iEvent){
01589 
01590   bool return_value=false;
01591 
01592   edm::Handle<reco::CaloJetCollection> caloJets;
01593   iEvent.getByLabel(theJetCollectionLabel, caloJets);
01594   if (!caloJets.isValid()) {
01595     LogDebug("") << "CaloMETAnalyzer: Could not find jet product" << std::endl;
01596     if (_verbose) std::cout << "CaloMETAnalyzer: Could not find jet product" << std::endl;
01597   }
01598 
01599   for (reco::CaloJetCollection::const_iterator cal = caloJets->begin(); 
01600        cal!=caloJets->end(); ++cal){
01601     if (cal->pt()>_highPtJetThreshold){
01602       return_value=true;
01603     }
01604   }
01605 
01606   return return_value;
01607 
01608 }
01609 
01610 // ***********************************************************
01611 bool CaloMETAnalyzer::selectLowPtJetEvent(const edm::Event& iEvent){
01612 
01613   bool return_value=false;
01614 
01615   edm::Handle<reco::CaloJetCollection> caloJets;
01616   iEvent.getByLabel(theJetCollectionLabel, caloJets);
01617   if (!caloJets.isValid()) {
01618     LogDebug("") << "CaloMETAnalyzer: Could not find jet product" << std::endl;
01619     if (_verbose) std::cout << "CaloMETAnalyzer: Could not find jet product" << std::endl;
01620   }
01621 
01622   for (reco::CaloJetCollection::const_iterator cal = caloJets->begin(); 
01623        cal!=caloJets->end(); ++cal){
01624     if (cal->pt()>_lowPtJetThreshold){
01625       return_value=true;
01626     }
01627   }
01628 
01629   return return_value;
01630 
01631 }
01632 
01633 // ***********************************************************
01634 bool CaloMETAnalyzer::selectWElectronEvent(const edm::Event& iEvent){
01635 
01636   bool return_value=true;
01637 
01638   /*
01639     W-electron event selection comes here
01640    */
01641 
01642   return return_value;
01643 
01644 }
01645 
01646 // ***********************************************************
01647 bool CaloMETAnalyzer::selectWMuonEvent(const edm::Event& iEvent){
01648 
01649   bool return_value=true;
01650 
01651   /*
01652     W-muon event selection comes here
01653    */
01654 
01655   return return_value;
01656 
01657 }
01658