CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/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: 2011/10/10 14:43:31 $
00005  *  $Revision: 1.62 $
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     bookMonitorElement(DirName+"/"+"HighPtJet",false);
00213     hTriggerName_HighPtJet = _dbe->bookString("triggerName_HighPtJet", highPtJetExpr_[0]);
00214   }  
00215 
00216   if ( _LowPtJetEventFlag->on() ) {
00217     bookMonitorElement(DirName+"/"+"LowPtJet",false);
00218     hTriggerName_LowPtJet = _dbe->bookString("triggerName_LowPtJet", lowPtJetExpr_[0]);
00219   }
00220 
00221   if ( _MinBiasEventFlag->on() ) {
00222     bookMonitorElement(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     bookMonitorElement(DirName+"/"+"HighMET",false);
00229     hTriggerName_HighMET = _dbe->bookString("triggerName_HighMET", highMETExpr_[0]);
00230   }
00231 
00232   if ( _LowMETEventFlag->on() ) {
00233     bookMonitorElement(DirName+"/"+"LowMET",false);
00234     hTriggerName_LowMET = _dbe->bookString("triggerName_LowMET", lowMETExpr_[0]);
00235   }
00236 
00237   if ( _EleEventFlag->on() ) {
00238     bookMonitorElement(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     bookMonitorElement(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   //hNevents                = _dbe->book1D("METTask_Nevents",   "METTask_Nevents"   ,1,0,1);
00257   hCaloMEx                = _dbe->book1D("METTask_CaloMEx",   "METTask_CaloMEx"   ,100,-500,500);
00258   hCaloMEx->setAxisTitle("MEx [GeV]",1);
00259   hCaloMEy                = _dbe->book1D("METTask_CaloMEy",   "METTask_CaloMEy"   ,100,-500,500); 
00260   hCaloMEy->setAxisTitle("MEy [GeV]",1);
00261   hCaloMETSig             = _dbe->book1D("METTask_CaloMETSig","METTask_CaloMETSig",51,0,51);
00262   hCaloMETSig->setAxisTitle("METSig",1);
00263   hCaloMET                = _dbe->book1D("METTask_CaloMET",   "METTask_CaloMET"   ,100,0,1000); 
00264   hCaloMET->setAxisTitle("MET [GeV]",1);
00265   hCaloMET1               = _dbe->book1D("METTask_CaloMET1",  "METTask_CaloMET1"  ,40,0,200);
00266   //meCaloMET->getTH1F()->SetStats(111111);
00267   //meCaloMET->getTH1F()->SetOption("logy");
00268   hCaloMETPhi             = _dbe->book1D("METTask_CaloMETPhi","METTask_CaloMETPhi",60,-TMath::Pi(),TMath::Pi()); 
00269   hCaloMETPhi->setAxisTitle("METPhi [rad]",1);
00270   hCaloSumET              = _dbe->book1D("METTask_CaloSumET", "METTask_CaloSumET" ,400,0,2000); 
00271   hCaloSumET->setAxisTitle("SumET [GeV]",1);
00272 
00273   hCaloMET_logx           = _dbe->book1D("METTask_CaloMET_logx",   "METTask_CaloMET_logx"   ,40,-1.,7.);
00274   hCaloMET_logx->setAxisTitle("log(MET) [GeV]",1);
00275   hCaloSumET_logx         = _dbe->book1D("METTask_CaloSumET_logx", "METTask_CaloSumET_logx" ,40,-1.,7.);
00276   hCaloSumET_logx->setAxisTitle("log(SumET) [GeV]",1);
00277   //  hCaloMETIonFeedbck      = _dbe->book1D("METTask_CaloMETIonFeedbck", "METTask_CaloMETIonFeedbck" ,500,0,1000);
00278   //  hCaloMETIonFeedbck->setAxisTitle("MET [GeV]",1);
00279   //  hCaloMETHPDNoise        = _dbe->book1D("METTask_CaloMETHPDNoise",   "METTask_CaloMETHPDNoise"   ,500,0,1000);
00280   //  hCaloMETHPDNoise->setAxisTitle("MET [GeV]",1);
00281   //  hCaloMETRBXNoise        = _dbe->book1D("METTask_CaloMETRBXNoise",   "METTask_CaloMETRBXNoise"   ,500,0,1000);
00282   //  hCaloMETRBXNoise->setAxisTitle("MET [GeV]",1);
00283 
00284   //  hCaloMETPhi002          = _dbe->book1D("METTask_CaloMETPhi002","METTask_CaloMETPhi002",60,-TMath::Pi(),TMath::Pi());
00285   //  hCaloMETPhi002->setAxisTitle("METPhi [rad] (MET>2 GeV)",1);
00286   //  hCaloMETPhi010          = _dbe->book1D("METTask_CaloMETPhi010","METTask_CaloMETPhi010",60,-TMath::Pi(),TMath::Pi());
00287   //  hCaloMETPhi010->setAxisTitle("METPhi [rad] (MET>10 GeV)",1);
00288   hCaloMETPhi020          = _dbe->book1D("METTask_CaloMETPhi020","METTask_CaloMETPhi020",60,-TMath::Pi(),TMath::Pi());
00289   hCaloMETPhi020->setAxisTitle("METPhi [rad] (MET>20 GeV)",1);
00290 
00291   if (_allhist){
00292     if (bLumiSecPlot){
00293       hCaloMExLS              = _dbe->book2D("METTask_CaloMEx_LS","METTask_CaloMEx_LS",200,-200,200,50,0.,500.);
00294       hCaloMExLS->setAxisTitle("MEx [GeV]",1);
00295       hCaloMExLS->setAxisTitle("Lumi Section",2);
00296       hCaloMEyLS              = _dbe->book2D("METTask_CaloMEy_LS","METTask_CaloMEy_LS",200,-200,200,50,0.,500.);
00297       hCaloMEyLS->setAxisTitle("MEy [GeV]",1);
00298       hCaloMEyLS->setAxisTitle("Lumi Section",2);
00299     }
00300 
00301     hCaloMaxEtInEmTowers    = _dbe->book1D("METTask_CaloMaxEtInEmTowers",   "METTask_CaloMaxEtInEmTowers"   ,100,0,2000);
00302     hCaloMaxEtInEmTowers->setAxisTitle("Et(Max) in EM Tower [GeV]",1);
00303     hCaloMaxEtInHadTowers   = _dbe->book1D("METTask_CaloMaxEtInHadTowers",  "METTask_CaloMaxEtInHadTowers"  ,100,0,2000);
00304     hCaloMaxEtInHadTowers->setAxisTitle("Et(Max) in Had Tower [GeV]",1);
00305     hCaloEtFractionHadronic = _dbe->book1D("METTask_CaloEtFractionHadronic","METTask_CaloEtFractionHadronic",100,0,1);
00306     hCaloEtFractionHadronic->setAxisTitle("Hadronic Et Fraction",1);
00307     hCaloEmEtFraction       = _dbe->book1D("METTask_CaloEmEtFraction",      "METTask_CaloEmEtFraction"      ,100,0,1);
00308     hCaloEmEtFraction->setAxisTitle("EM Et Fraction",1);
00309 
00310     //hCaloEmEtFraction002    = _dbe->book1D("METTask_CaloEmEtFraction002",   "METTask_CaloEmEtFraction002"      ,100,0,1);
00311     //hCaloEmEtFraction002->setAxisTitle("EM Et Fraction (MET>2 GeV)",1);
00312     //hCaloEmEtFraction010    = _dbe->book1D("METTask_CaloEmEtFraction010",   "METTask_CaloEmEtFraction010"      ,100,0,1);
00313     //hCaloEmEtFraction010->setAxisTitle("EM Et Fraction (MET>10 GeV)",1);
00314     hCaloEmEtFraction020    = _dbe->book1D("METTask_CaloEmEtFraction020",   "METTask_CaloEmEtFraction020"      ,100,0,1);
00315     hCaloEmEtFraction020->setAxisTitle("EM Et Fraction (MET>20 GeV)",1);
00316 
00317     hCaloHadEtInHB          = _dbe->book1D("METTask_CaloHadEtInHB","METTask_CaloHadEtInHB",100,0,2000);
00318     hCaloHadEtInHB->setAxisTitle("Had Et [GeV]",1);
00319     hCaloHadEtInHO          = _dbe->book1D("METTask_CaloHadEtInHO","METTask_CaloHadEtInHO",25,0,500);
00320     hCaloHadEtInHO->setAxisTitle("Had Et [GeV]",1);
00321     hCaloHadEtInHE          = _dbe->book1D("METTask_CaloHadEtInHE","METTask_CaloHadEtInHE",100,0,2000);
00322     hCaloHadEtInHE->setAxisTitle("Had Et [GeV]",1);
00323     hCaloHadEtInHF          = _dbe->book1D("METTask_CaloHadEtInHF","METTask_CaloHadEtInHF",50,0,1000);
00324     hCaloHadEtInHF->setAxisTitle("Had Et [GeV]",1);
00325     hCaloEmEtInHF           = _dbe->book1D("METTask_CaloEmEtInHF" ,"METTask_CaloEmEtInHF" ,25,0,500);
00326     hCaloEmEtInHF->setAxisTitle("EM Et [GeV]",1);
00327     hCaloEmEtInEE           = _dbe->book1D("METTask_CaloEmEtInEE" ,"METTask_CaloEmEtInEE" ,50,0,1000);
00328     hCaloEmEtInEE->setAxisTitle("EM Et [GeV]",1);
00329     hCaloEmEtInEB           = _dbe->book1D("METTask_CaloEmEtInEB" ,"METTask_CaloEmEtInEB" ,100,0,2000);
00330     hCaloEmEtInEB->setAxisTitle("EM Et [GeV]",1);
00331 
00332     hCaloEmMEx= _dbe->book1D("METTask_CaloEmMEx","METTask_CaloEmMEx",200,-500,500);
00333     hCaloEmMEx->setAxisTitle("EM MEx [GeV]",1);
00334     hCaloEmMEy= _dbe->book1D("METTask_CaloEmMEy","METTask_CaloEmMEy",200,-500,500);
00335     hCaloEmMEy->setAxisTitle("EM MEy [GeV]",1);
00336     //hCaloEmEz= _dbe->book1D("METTask_CaloEmEz","METTask_CaloEmEz",100,-500,500);
00337     //hCaloEmEz->setAxisTitle("EM Ez [GeV]",1);
00338     hCaloEmMET= _dbe->book1D("METTask_CaloEmMET","METTask_CaloEmMET",200,0,1000);
00339     hCaloEmMET->setAxisTitle("EM MET [GeV]",1);
00340     hCaloEmMETPhi= _dbe->book1D("METTask_CaloEmMETPhi","METTask_CaloEmMETPhi",60,-TMath::Pi(),TMath::Pi());
00341     hCaloEmMETPhi->setAxisTitle("EM METPhi [rad]",1);
00342     //hCaloEmSumET= _dbe->book1D("METTask_CaloEmSumET","METTask_CaloEmSumET",200,0,2000);
00343     //hCaloEmSumET->setAxisTitle("EM SumET [GeV]",1);
00344 
00345     hCaloHaMEx= _dbe->book1D("METTask_CaloHaMEx","METTask_CaloHaMEx",200,-500,500);
00346     hCaloHaMEx->setAxisTitle("HA MEx [GeV]",1);
00347     hCaloHaMEy= _dbe->book1D("METTask_CaloHaMEy","METTask_CaloHaMEy",200,-500,500);
00348     hCaloHaMEy->setAxisTitle("HA MEy [GeV]",1);
00349     //hCaloHaEz= _dbe->book1D("METTask_CaloHaEz","METTask_CaloHaEz",100,-500,500);
00350     //hCaloHaEz->setAxisTitle("HA Ez [GeV]",1);
00351     hCaloHaMET= _dbe->book1D("METTask_CaloHaMET","METTask_CaloHaMET",200,0,1000); 
00352     hCaloHaMET->setAxisTitle("HA MET [GeV]",1);
00353     hCaloHaMETPhi= _dbe->book1D("METTask_CaloHaMETPhi","METTask_CaloHaMETPhi",60,-TMath::Pi(),TMath::Pi());
00354     hCaloHaMETPhi->setAxisTitle("HA METPhi [rad]",1);
00355     //hCaloHaSumET= _dbe->book1D("METTask_CaloHaSumET","METTask_CaloHaSumET",200,0,2000); 
00356     //hCaloHaSumET->setAxisTitle("HA SumET [GeV]",1);
00357   }
00358   
00359   if (theCaloMETCollectionLabel.label() == "corMetGlobalMuons" ) {
00360     hCalomuPt    = _dbe->book1D("METTask_CalomuonPt", "METTask_CalomuonPt", 50, 0, 500);
00361     hCalomuEta   = _dbe->book1D("METTask_CalomuonEta", "METTask_CalomuonEta", 60, -3.0, 3.0);
00362     hCalomuNhits = _dbe->book1D("METTask_CalomuonNhits", "METTask_CalomuonNhits", 50, 0, 50);
00363     hCalomuChi2  = _dbe->book1D("METTask_CalomuonNormalizedChi2", "METTask_CalomuonNormalizedChi2", 20, 0, 20);
00364     hCalomuD0    = _dbe->book1D("METTask_CalomuonD0", "METTask_CalomuonD0", 50, -1, 1);
00365     hCaloMExCorrection       = _dbe->book1D("METTask_CaloMExCorrection", "METTask_CaloMExCorrection", 100, -500.0,500.0);
00366     hCaloMEyCorrection       = _dbe->book1D("METTask_CaloMEyCorrection", "METTask_CaloMEyCorrection", 100, -500.0,500.0);
00367     hCaloMuonCorrectionFlag  = _dbe->book1D("METTask_CaloCorrectionFlag","METTask_CaloCorrectionFlag", 5, -0.5, 4.5);
00368   }
00369 
00370 }
00371 
00372 // ***********************************************************
00373 void CaloMETAnalyzer::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
00374 {
00375   if ( _HighPtJetEventFlag->on() ) _HighPtJetEventFlag->initRun( iRun, iSetup );
00376   if ( _LowPtJetEventFlag ->on() ) _LowPtJetEventFlag ->initRun( iRun, iSetup );
00377   if ( _MinBiasEventFlag  ->on() ) _MinBiasEventFlag  ->initRun( iRun, iSetup );
00378   if ( _HighMETEventFlag  ->on() ) _HighMETEventFlag  ->initRun( iRun, iSetup );
00379   if ( _LowMETEventFlag   ->on() ) _LowMETEventFlag   ->initRun( iRun, iSetup );
00380   if ( _EleEventFlag      ->on() ) _EleEventFlag      ->initRun( iRun, iSetup );
00381   if ( _MuonEventFlag     ->on() ) _MuonEventFlag     ->initRun( iRun, iSetup );
00382 
00383   if (_HighPtJetEventFlag->on() && _HighPtJetEventFlag->expressionsFromDB(_HighPtJetEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00384     highPtJetExpr_ = _HighPtJetEventFlag->expressionsFromDB(_HighPtJetEventFlag->hltDBKey(), iSetup);
00385   if (_LowPtJetEventFlag->on() && _LowPtJetEventFlag->expressionsFromDB(_LowPtJetEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00386     lowPtJetExpr_  = _LowPtJetEventFlag->expressionsFromDB(_LowPtJetEventFlag->hltDBKey(),   iSetup);
00387   if (_HighMETEventFlag->on() && _HighMETEventFlag->expressionsFromDB(_HighMETEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00388     highMETExpr_   = _HighMETEventFlag->expressionsFromDB(_HighMETEventFlag->hltDBKey(),     iSetup);
00389   if (_LowMETEventFlag->on() && _LowMETEventFlag->expressionsFromDB(_LowMETEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00390     lowMETExpr_    = _LowMETEventFlag->expressionsFromDB(_LowMETEventFlag->hltDBKey(),       iSetup);
00391   if (_MuonEventFlag->on() && _MuonEventFlag->expressionsFromDB(_MuonEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00392     muonExpr_      = _MuonEventFlag->expressionsFromDB(_MuonEventFlag->hltDBKey(),           iSetup);
00393   if (_EleEventFlag->on() && _EleEventFlag->expressionsFromDB(_EleEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00394     elecExpr_      = _EleEventFlag->expressionsFromDB(_EleEventFlag->hltDBKey(),             iSetup);
00395   if (_MinBiasEventFlag->on() && _MinBiasEventFlag->expressionsFromDB(_MinBiasEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00396     minbiasExpr_   = _MinBiasEventFlag->expressionsFromDB(_MinBiasEventFlag->hltDBKey(),     iSetup);
00397 
00398 }
00399 
00400 // ***********************************************************
00401 void CaloMETAnalyzer::endRun(const edm::Run& iRun, const edm::EventSetup& iSetup, DQMStore * dbe)
00402 {
00403   
00404   //
00405   //--- Check the time length of the Run from the lumi section plots
00406 
00407   std::string dirName = "JetMET/MET/"+_source+"/";
00408   _dbe->setCurrentFolder(dirName);
00409 
00410   TH1F* tlumisec;
00411 
00412   MonitorElement *meLumiSec = _dbe->get("aaa");
00413   meLumiSec = _dbe->get("JetMET/lumisec");
00414 
00415   int totlsec=0;
00416   double totltime=0.;
00417   if ( meLumiSec->getRootObject() ) {
00418     tlumisec = meLumiSec->getTH1F();
00419     for (int i=0; i<500; i++){
00420       if (tlumisec->GetBinContent(i+1)) totlsec++;
00421     }
00422     totltime = double(totlsec*90); // one lumi sec ~ 90 (sec)
00423   }
00424 
00425   if (totltime==0.) totltime=1.; 
00426 
00427   //
00428   //--- Make the integrated plots with rate (Hz)
00429 
00430   for (std::vector<std::string>::const_iterator ic = _FolderNames.begin(); ic != _FolderNames.end(); ic++)
00431     {
00432 
00433       std::string DirName;
00434       DirName = dirName+*ic;
00435 
00436       makeRatePlot(DirName,totltime);
00437       if ( _HighPtJetEventFlag->on() ) 
00438         makeRatePlot(DirName+"/"+"triggerName_HighJetPt",totltime);
00439       if ( _LowPtJetEventFlag->on() ) 
00440         makeRatePlot(DirName+"/"+"triggerName_LowJetPt",totltime);
00441       if ( _MinBiasEventFlag->on() ) 
00442         makeRatePlot(DirName+"/"+"triggerName_MinBias",totltime);
00443       if ( _HighMETEventFlag->on() ) 
00444         makeRatePlot(DirName+"/"+"triggerName_HighMET",totltime);
00445       if ( _LowMETEventFlag->on() ) 
00446         makeRatePlot(DirName+"/"+"triggerName_LowMET",totltime);
00447       if ( _EleEventFlag->on() ) 
00448         makeRatePlot(DirName+"/"+"triggerName_Ele",totltime);
00449       if ( _MuonEventFlag->on() ) 
00450         makeRatePlot(DirName+"/"+"triggerName_Muon",totltime);
00451     }
00452 
00453 }
00454 
00455 // ***********************************************************
00456 void CaloMETAnalyzer::makeRatePlot(std::string DirName, double totltime)
00457 {
00458 
00459   _dbe->setCurrentFolder(DirName);
00460   MonitorElement *meCaloMET = _dbe->get(DirName+"/"+"METTask_CaloMET");
00461 
00462   TH1F* tCaloMET;
00463   TH1F* tCaloMETRate;
00464 
00465   if ( meCaloMET )
00466     if ( meCaloMET->getRootObject() ) {
00467       tCaloMET     = meCaloMET->getTH1F();
00468       
00469       // Integral plot & convert number of events to rate (hz)
00470       tCaloMETRate = (TH1F*) tCaloMET->Clone("METTask_CaloMETRate");
00471       for (int i = tCaloMETRate->GetNbinsX()-1; i>=0; i--){
00472         tCaloMETRate->SetBinContent(i+1,tCaloMETRate->GetBinContent(i+2)+tCaloMET->GetBinContent(i+1));
00473       }
00474       for (int i = 0; i<tCaloMETRate->GetNbinsX(); i++){
00475         tCaloMETRate->SetBinContent(i+1,tCaloMETRate->GetBinContent(i+1)/double(totltime));
00476       }      
00477 
00478       tCaloMETRate->SetName("METTask_CaloMETRate");
00479       tCaloMETRate->SetTitle("METTask_CaloMETRate");
00480       hCaloMETRate = _dbe->book1D("METTask_CaloMETRate",tCaloMETRate);
00481       hCaloMETRate->setAxisTitle("MET Threshold [GeV]",1);
00482     }
00483 }
00484 
00485 
00486 // ***********************************************************
00487 void CaloMETAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup, 
00488                               const edm::TriggerResults& triggerResults) {
00489 
00490   if (_verbose) std::cout << "CaloMETAnalyzer analyze" << std::endl;
00491 
00492   std::string DirName = "JetMET/MET/"+_source;
00493   if (_print){
00494   std::cout << " " << std::endl;
00495   std::cout << "Event = " << iEvent.id().event() << std::endl;
00496   }
00497 
00498   LogTrace(metname)<<"[CaloMETAnalyzer] Analyze CaloMET";
00499 
00500   hmetME->Fill(1);
00501 
00502   // ==========================================================  
00503   // Trigger information 
00504   //
00505   _trig_JetMB=0;
00506   _trig_HighPtJet=0;
00507   _trig_LowPtJet=0;
00508   _trig_MinBias=0;
00509   _trig_HighMET=0;
00510   _trig_LowMET=0;
00511   _trig_Ele=0;
00512   _trig_Muon=0;
00513   _trig_PhysDec=0;
00514   if(&triggerResults) {   
00515     
00517     
00518     //
00519     //
00520     // Check how many HLT triggers are in triggerResults 
00521     int ntrigs = triggerResults.size();
00522     if (_verbose) std::cout << "ntrigs=" << ntrigs << std::endl;
00523     
00524     //
00525     //
00526     // If index=ntrigs, this HLT trigger doesn't exist in the HLT table for this data.
00527     const edm::TriggerNames & triggerNames = iEvent.triggerNames(triggerResults);
00528 
00529     //
00530     //
00531     const unsigned int nTrig(triggerNames.size());
00532     for (unsigned int i=0;i<nTrig;++i)
00533       {
00534         if (triggerNames.triggerName(i).find(highPtJetExpr_[0].substr(0,highPtJetExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
00535           _trig_HighPtJet=true;
00536         else if (triggerNames.triggerName(i).find(lowPtJetExpr_[0].substr(0,lowPtJetExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
00537           _trig_LowPtJet=true;
00538         else if (triggerNames.triggerName(i).find(highMETExpr_[0].substr(0,highMETExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
00539           _trig_HighMET=true;
00540         else if (triggerNames.triggerName(i).find(lowMETExpr_[0].substr(0,lowMETExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
00541           _trig_LowMET=true;
00542         else if (triggerNames.triggerName(i).find(muonExpr_[0].substr(0,muonExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
00543           _trig_Muon=true;
00544         else if (triggerNames.triggerName(i).find(elecExpr_[0].substr(0,elecExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
00545           _trig_Ele=true;
00546         else if (triggerNames.triggerName(i).find(minbiasExpr_[0].substr(0,minbiasExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
00547           _trig_MinBias=true;
00548       }
00549 
00550     // count number of requested Jet or MB HLT paths which have fired
00551     for (unsigned int i=0; i!=HLTPathsJetMBByName_.size(); i++) {
00552       unsigned int triggerIndex = triggerNames.triggerIndex(HLTPathsJetMBByName_[i]);
00553       if (triggerIndex<triggerResults.size()) {
00554         if (triggerResults.accept(triggerIndex)) {
00555           _trig_JetMB++;
00556         }
00557       }
00558     }
00559     // for empty input vectors (n==0), take all HLT triggers!
00560     if (HLTPathsJetMBByName_.size()==0) _trig_JetMB=triggerResults.size()-1;
00561 
00562     /*
00563       if ( _HighPtJetEventFlag->on() && _HighPtJetEventFlag->accept( iEvent, iSetup) )
00564       _trig_HighPtJet=1;
00565       
00566       if ( _LowPtJetEventFlag->on() && _LowPtJetEventFlag->accept( iEvent, iSetup) )
00567       _trig_LowPtJet=1;
00568       
00569       if ( _MinBiasEventFlag->on() && _MinBiasEventFlag->accept( iEvent, iSetup) )
00570       _trig_MinBias=1;
00571       
00572       if ( _HighMETEventFlag->on() && _HighMETEventFlag->accept( iEvent, iSetup) )
00573       _trig_HighMET=1;
00574       
00575       if ( _LowMETEventFlag->on() && _LowMETEventFlag->accept( iEvent, iSetup) )
00576       _trig_LowMET=1;
00577       
00578       if ( _EleEventFlag->on() && _EleEventFlag->accept( iEvent, iSetup) )
00579       _trig_Ele=1;
00580       
00581       if ( _MuonEventFlag->on() && _MuonEventFlag->accept( iEvent, iSetup) )
00582       _trig_Muon=1;
00583     */
00584       
00585     if (triggerNames.triggerIndex(_hlt_PhysDec)   != triggerNames.size() &&
00586         triggerResults.accept(triggerNames.triggerIndex(_hlt_PhysDec)))   _trig_PhysDec=1;
00587   } else {
00588 
00589     edm::LogInfo("CaloMetAnalyzer") << "TriggerResults::HLT not found, "
00590         "automatically select events"; 
00591     //
00592     // TriggerResults object not found. Look at all events.    
00593     _trig_JetMB=1;
00594     
00595   }
00596   
00597   // ==========================================================  
00598   // CaloMET information
00599 
00600   // **** Get the MET container  
00601   edm::Handle<reco::CaloMETCollection> calometcoll;
00602   iEvent.getByLabel(theCaloMETCollectionLabel, calometcoll);
00603 
00604   if(!calometcoll.isValid()) {
00605     std::cout<<"Unable to find MET results for CaloMET collection "<<theCaloMETCollectionLabel<<std::endl;
00606     return;
00607   }
00608 
00609   const reco::CaloMETCollection *calometcol = calometcoll.product();
00610   const reco::CaloMET *calomet;
00611   calomet = &(calometcol->front());
00612   
00613   LogTrace(metname)<<"[CaloMETAnalyzer] Call to the CaloMET analyzer";
00614 
00615   //Only for corMetGlobalMuons
00616   if (theCaloMETCollectionLabel.label() == "corMetGlobalMuons" ) {
00617     
00618     iEvent.getByLabel("muonMETValueMapProducer" , "muCorrData", corMetGlobalMuons_ValueMap_Handle);
00619     iEvent.getByLabel("muons", muon_h);
00620     iEvent.getByLabel(inputBeamSpotLabel, beamSpot_h);
00621     
00622     if(!beamSpot_h.isValid()) edm::LogInfo("OutputInfo") << "falied to retrieve beam spot data require by MET Task";
00623     
00624     bspot = ( beamSpot_h.isValid() ) ? beamSpot_h->position() : math::XYZPoint(0, 0, 0);
00625     
00626   }
00627 
00628 
00629   // ==========================================================
00630   //
00631   edm::Handle<reco::HcalNoiseRBXCollection> HRBXCollection;
00632   iEvent.getByLabel(HcalNoiseRBXCollectionTag,HRBXCollection);
00633   if (!HRBXCollection.isValid()) {
00634       LogDebug("") << "CaloMETAnalyzer: Could not find HcalNoiseRBX Collection" << std::endl;
00635       if (_verbose) std::cout << "CaloMETAnalyzer: Could not find HcalNoiseRBX Collection" << std::endl;
00636   }
00637   
00638   edm::Handle<HcalNoiseSummary> HNoiseSummary;
00639   iEvent.getByLabel(HcalNoiseSummaryTag,HNoiseSummary);
00640   if (!HNoiseSummary.isValid()) {
00641     LogDebug("") << "CaloMETAnalyzer: Could not find Hcal NoiseSummary product" << std::endl;
00642     if (_verbose) std::cout << "CaloMETAnalyzer: Could not find Hcal NoiseSummary product" << std::endl;
00643   }
00644   
00645   edm::Handle<reco::CaloJetCollection> caloJets;
00646   iEvent.getByLabel(theJetCollectionLabel, caloJets);
00647   if (!caloJets.isValid()) {
00648     LogDebug("") << "CaloMETAnalyzer: Could not find jet product" << std::endl;
00649     if (_verbose) std::cout << "CaloMETAnalyzer: Could not find jet product" << std::endl;
00650   }
00651 
00652   edm::Handle<edm::View<reco::Candidate> > towers;
00653   iEvent.getByLabel(theCaloTowersLabel, towers);
00654   if (!towers.isValid()) {
00655     LogDebug("") << "CaloMETAnalyzer: Could not find caltower product" << std::endl;
00656     if (_verbose) std::cout << "CaloMETAnalyzer: Could not find caltower product" << std::endl;
00657   }
00658  
00659   // ==========================================================
00660   // CaloMET sanity check
00661 
00662   if (_source=="CaloMET") validateMET(*calomet,towers);
00663 
00664   // ==========================================================
00665 
00666   if (_allhist) computeEmHaMET(towers);
00667     
00668   // ==========================================================
00669   // JetID 
00670 
00671   if (_verbose) std::cout << "JetID starts" << std::endl;
00672   
00673   //
00674   // --- Minimal cuts
00675   //
00676   bool bJetIDMinimal=true;
00677   int nj=0;
00678   for (reco::CaloJetCollection::const_iterator cal = caloJets->begin(); 
00679        cal!=caloJets->end(); ++cal){
00680     jetID->calculate(iEvent, *cal);
00681     if (_print && nj<=1) std::cout << "Jet pT = " << cal->pt() << " (GeV) "
00682                                    << " eta = " << cal->eta() << " "
00683                                    << " phi = " << cal->phi() << " "
00684                                    << " emf = " << cal->emEnergyFraction() << std::endl;
00685     nj++;
00686     if (cal->pt()>10.){
00687       if (fabs(cal->eta())<=2.6 && 
00688           cal->emEnergyFraction()<=0.01) bJetIDMinimal=false;
00689     }
00690   }
00691 
00692   //
00693   // --- Loose cuts
00694   //
00695   bool bJetIDLoose=true;
00696   for (reco::CaloJetCollection::const_iterator cal = caloJets->begin(); 
00697        cal!=caloJets->end(); ++cal){
00698     jetID->calculate(iEvent, *cal);
00699     if (_verbose) std::cout << jetID->n90Hits() << " " 
00700                             << jetID->restrictedEMF() << " "
00701                             << cal->pt() << std::endl;
00702     if (cal->pt()>10.){
00703       //
00704       // for all regions
00705       if (jetID->n90Hits()<2)  bJetIDLoose=false; 
00706       if (jetID->fHPD()>=0.98) bJetIDLoose=false; 
00707       //
00708       // for non-forward
00709       if (fabs(cal->eta())<2.55){
00710         if (cal->emEnergyFraction()<=0.01) bJetIDLoose=false; 
00711       }
00712       // for forward
00713       else {
00714         if (cal->emEnergyFraction()<=-0.9) bJetIDLoose=false; 
00715         if (cal->pt()>80.){
00716         if (cal->emEnergyFraction()>= 1.0) bJetIDLoose=false; 
00717         }
00718       } // forward vs non-forward
00719     }   // pt>10 GeV/c
00720   }     // calor-jets loop
00721 
00722   //
00723   // --- Tight cuts
00724   //
00725   bool bJetIDTight=true;
00726   bJetIDTight=bJetIDLoose;
00727   for (reco::CaloJetCollection::const_iterator cal = caloJets->begin(); 
00728        cal!=caloJets->end(); ++cal){
00729     jetID->calculate(iEvent, *cal);
00730     if (cal->pt()>25.){
00731       //
00732       // for all regions
00733       if (jetID->fHPD()>=0.95) bJetIDTight=false; 
00734       //
00735       // for 1.0<|eta|<1.75
00736       if (fabs(cal->eta())>=1.00 && fabs(cal->eta())<1.75){
00737         if (cal->pt()>80. && cal->emEnergyFraction()>=1.) bJetIDTight=false; 
00738       }
00739       //
00740       // for 1.75<|eta|<2.55
00741       else if (fabs(cal->eta())>=1.75 && fabs(cal->eta())<2.55){
00742         if (cal->pt()>80. && cal->emEnergyFraction()>=1.) bJetIDTight=false; 
00743       }
00744       //
00745       // for 2.55<|eta|<3.25
00746       else if (fabs(cal->eta())>=2.55 && fabs(cal->eta())<3.25){
00747         if (cal->pt()< 50.                   && cal->emEnergyFraction()<=-0.3) bJetIDTight=false; 
00748         if (cal->pt()>=50. && cal->pt()< 80. && cal->emEnergyFraction()<=-0.2) bJetIDTight=false; 
00749         if (cal->pt()>=80. && cal->pt()<340. && cal->emEnergyFraction()<=-0.1) bJetIDTight=false; 
00750         if (cal->pt()>=340.                  && cal->emEnergyFraction()<=-0.1 
00751                                              && cal->emEnergyFraction()>=0.95) bJetIDTight=false; 
00752       }
00753       //
00754       // for 3.25<|eta|
00755       else if (fabs(cal->eta())>=3.25){
00756         if (cal->pt()< 50.                   && cal->emEnergyFraction()<=-0.3
00757                                              && cal->emEnergyFraction()>=0.90) bJetIDTight=false; 
00758         if (cal->pt()>=50. && cal->pt()<130. && cal->emEnergyFraction()<=-0.2
00759                                              && cal->emEnergyFraction()>=0.80) bJetIDTight=false; 
00760         if (cal->pt()>=130.                  && cal->emEnergyFraction()<=-0.1 
00761                                              && cal->emEnergyFraction()>=0.70) bJetIDTight=false; 
00762       }
00763     }   // pt>10 GeV/c
00764   }     // calor-jets loop
00765   
00766   if (_verbose) std::cout << "JetID ends" << std::endl;
00767      
00768   // ==========================================================
00769   // HCAL Noise filter
00770   
00771   bool bHcalNoiseFilter      = HNoiseSummary->passLooseNoiseFilter();
00772   bool bHcalNoiseFilterTight = HNoiseSummary->passTightNoiseFilter();
00773 
00774   if (_verbose) std::cout << "HcalNoiseFilter Summary ends" << std::endl;
00775 
00776   // ==========================================================
00777   // Get BeamHaloSummary
00778   edm::Handle<reco::BeamHaloSummary> TheBeamHaloSummary ;
00779   iEvent.getByLabel(BeamHaloSummaryTag, TheBeamHaloSummary) ;
00780 
00781   bool bBeamHaloIDTightPass = true;
00782   bool bBeamHaloIDLoosePass = true;
00783   
00784   if(TheBeamHaloSummary.isValid()) {
00785     
00786     const reco::BeamHaloSummary TheSummary = (*TheBeamHaloSummary.product() );
00787     
00788     //   std::cout << TheSummary.EcalLooseHaloId() << " "
00789     //      << TheSummary.HcalLooseHaloId() << " "
00790     //      << TheSummary.CSCLooseHaloId()  << " "
00791     //      << TheSummary.GlobalLooseHaloId() << std::endl;
00792     
00793     if( TheSummary.EcalLooseHaloId()  || TheSummary.HcalLooseHaloId() || 
00794         TheSummary.CSCLooseHaloId()   || TheSummary.GlobalLooseHaloId() )
00795       bBeamHaloIDLoosePass = false;
00796     
00797     if( TheSummary.EcalTightHaloId()  || TheSummary.HcalTightHaloId() || 
00798         TheSummary.CSCTightHaloId()   || TheSummary.GlobalTightHaloId() )
00799       bBeamHaloIDTightPass = false;
00800     
00801   }
00802   
00803   if (_verbose) std::cout << "BeamHaloSummary ends" << std::endl;
00804   
00805   // ==========================================================
00806   //Vertex information
00807   
00808   bool bPrimaryVertex = true;
00809   if(_doPVCheck){
00810     bPrimaryVertex = false;
00811     Handle<reco::VertexCollection> vertexHandle;
00812 
00813     iEvent.getByLabel(vertexTag, vertexHandle);
00814 
00815     if (!vertexHandle.isValid()) {
00816       LogDebug("") << "CaloMETAnalyzer: Could not find vertex collection" << std::endl;
00817       if (_verbose) std::cout << "CaloMETAnalyzer: Could not find vertex collection" << std::endl;
00818     }
00819     
00820     if ( vertexHandle.isValid() ){
00821       reco::VertexCollection vertexCollection = *(vertexHandle.product());
00822       int vertex_number     = vertexCollection.size();
00823       reco::VertexCollection::const_iterator v = vertexCollection.begin();
00824       for ( ; v != vertexCollection.end(); ++v) {
00825         double vertex_chi2    = v->normalizedChi2();
00826         double vertex_ndof    = v->ndof();
00827         bool   fakeVtx        = v->isFake();
00828         double vertex_Z       = v->z();
00829         
00830         if (  !fakeVtx
00831               && vertex_number>=_nvtx_min
00832               && vertex_ndof   >_vtxndof_min
00833               && vertex_chi2   <_vtxchi2_max
00834               && fabs(vertex_Z)<_vtxz_max ) 
00835           bPrimaryVertex = true;
00836       }
00837     }
00838   }
00839   // ==========================================================
00840 
00841   edm::Handle< L1GlobalTriggerReadoutRecord > gtReadoutRecord;
00842   iEvent.getByLabel( gtTag, gtReadoutRecord);
00843 
00844   if (!gtReadoutRecord.isValid()) {
00845     LogDebug("") << "CaloMETAnalyzer: Could not find GT readout record" << std::endl;
00846     if (_verbose) std::cout << "CaloMETAnalyzer: Could not find GT readout record product" << std::endl;
00847   }
00848   
00849   bool bTechTriggers    = true;
00850   bool bTechTriggersAND = true;
00851   bool bTechTriggersOR  = false;
00852   bool bTechTriggersNOT = false;
00853 
00854   if (gtReadoutRecord.isValid()) {
00855     const TechnicalTriggerWord&  technicalTriggerWordBeforeMask = gtReadoutRecord->technicalTriggerWord();
00856 
00857     if (_techTrigsAND.size() == 0)
00858       bTechTriggersAND = true;
00859     else
00860       for (unsigned ttr = 0; ttr != _techTrigsAND.size(); ttr++) {
00861         bTechTriggersAND = bTechTriggersAND && technicalTriggerWordBeforeMask.at(_techTrigsAND.at(ttr));
00862       }
00863     
00864     if (_techTrigsAND.size() == 0)
00865       bTechTriggersOR = true;
00866     else
00867       for (unsigned ttr = 0; ttr != _techTrigsOR.size(); ttr++) {
00868         bTechTriggersOR = bTechTriggersOR || technicalTriggerWordBeforeMask.at(_techTrigsOR.at(ttr));
00869       }
00870     if (_techTrigsNOT.size() == 0)
00871       bTechTriggersNOT = false;
00872     else
00873       for (unsigned ttr = 0; ttr != _techTrigsNOT.size(); ttr++) {
00874         bTechTriggersNOT = bTechTriggersNOT || technicalTriggerWordBeforeMask.at(_techTrigsNOT.at(ttr));
00875       }
00876   }
00877   else
00878     {
00879       bTechTriggersAND = true;
00880       bTechTriggersOR  = true;
00881       bTechTriggersNOT = false;
00882     }
00883     
00884   if (_techTrigsAND.size()==0)
00885     bTechTriggersAND = true;
00886   if (_techTrigsOR.size()==0)
00887     bTechTriggersOR = true;
00888   if (_techTrigsNOT.size()==0)
00889     bTechTriggersNOT = false;
00890   
00891   bTechTriggers = bTechTriggersAND && bTechTriggersOR && !bTechTriggersNOT;
00892     
00893   // ==========================================================
00894   // Reconstructed MET Information - fill MonitorElements
00895   
00896   bool bHcalNoise   = bHcalNoiseFilter;
00897   bool bBeamHaloID  = bBeamHaloIDLoosePass;
00898   bool bJetID       = bJetIDMinimal;
00899 
00900   bool bPhysicsDeclared = true;
00901   if(_doHLTPhysicsOn) bPhysicsDeclared =_trig_PhysDec;
00902 
00903   if      (_tightHcalFiltering)     bHcalNoise  = bHcalNoiseFilterTight;
00904   if      (_tightBHFiltering)       bBeamHaloID = bBeamHaloIDTightPass;
00905 
00906   if      (_tightJetIDFiltering==1)  bJetID      = bJetIDMinimal;
00907   else if (_tightJetIDFiltering==2)  bJetID      = bJetIDLoose;
00908   else if (_tightJetIDFiltering==3)  bJetID      = bJetIDTight;
00909   else if (_tightJetIDFiltering==-1) bJetID      = true;
00910 
00911   bool bBasicCleanup = bTechTriggers && bPrimaryVertex && bPhysicsDeclared;
00912   bool bExtraCleanup = bBasicCleanup && bHcalNoise && bJetID && bBeamHaloID;
00913 
00914   //std::string DirName = "JetMET/MET/"+_source;
00915   
00916   for (std::vector<std::string>::const_iterator ic = _FolderNames.begin(); 
00917        ic != _FolderNames.end(); ic++){
00918     if (*ic=="All")                                             fillMESet(iEvent, DirName+"/"+*ic, *calomet);
00919     if (DCSFilter->filter(iEvent, iSetup)) {
00920     if (_cleanupSelection){
00921     if (*ic=="BasicCleanup"   && bBasicCleanup)                 fillMESet(iEvent, DirName+"/"+*ic, *calomet);
00922     if (*ic=="ExtraCleanup"   && bExtraCleanup)                 fillMESet(iEvent, DirName+"/"+*ic, *calomet);
00923     }
00924     if (_allSelection) {
00925       if (*ic=="HcalNoiseFilter"      && bHcalNoiseFilter )       fillMESet(iEvent, DirName+"/"+*ic, *calomet);
00926       if (*ic=="HcalNoiseFilterTight" && bHcalNoiseFilterTight )  fillMESet(iEvent, DirName+"/"+*ic, *calomet);
00927       if (*ic=="JetIDMinimal"         && bJetIDMinimal)           fillMESet(iEvent, DirName+"/"+*ic, *calomet);
00928       if (*ic=="JetIDLoose"           && bJetIDLoose)             fillMESet(iEvent, DirName+"/"+*ic, *calomet);
00929       if (*ic=="JetIDTight"           && bJetIDTight)             fillMESet(iEvent, DirName+"/"+*ic, *calomet);
00930       if (*ic=="BeamHaloIDTightPass"  && bBeamHaloIDTightPass)    fillMESet(iEvent, DirName+"/"+*ic, *calomet);
00931       if (*ic=="BeamHaloIDLoosePass"  && bBeamHaloIDLoosePass)    fillMESet(iEvent, DirName+"/"+*ic, *calomet);
00932       if (*ic=="Triggers"             && bTechTriggers)           fillMESet(iEvent, DirName+"/"+*ic, *calomet);
00933       if (*ic=="PV"                   && bPrimaryVertex)          fillMESet(iEvent, DirName+"/"+*ic, *calomet);
00934     }
00935     } // DCS
00936   }
00937 } // CaloMETAnalyzer::analyze
00938 
00939 // ***********************************************************
00940 void CaloMETAnalyzer::computeEmHaMET(edm::Handle<edm::View<reco::Candidate> > towers)
00941 {
00942 
00943   edm::View<reco::Candidate>::const_iterator towerCand = towers->begin();
00944   
00945   double sum_em_et = 0.0;
00946   double sum_em_ex = 0.0;
00947   double sum_em_ey = 0.0;
00948   double sum_em_ez = 0.0;
00949   
00950   double sum_ha_et = 0.0;
00951   double sum_ha_ex = 0.0;
00952   double sum_ha_ey = 0.0;
00953   double sum_ha_ez = 0.0;
00954   
00955   for ( ; towerCand != towers->end(); towerCand++)
00956     {
00957       const reco::Candidate* candidate = &(*towerCand);
00958       if (candidate)
00959         {
00960           const CaloTower* calotower = dynamic_cast<const CaloTower*> (candidate);
00961           if (calotower){
00962             double Tower_ET = calotower->et();
00963             if (Tower_ET>0.3) {
00964               
00965               double phi   = candidate->phi();
00966               double theta = candidate->theta();
00967               //double e     = candidate->energy();
00968               double e_em  = calotower->emEnergy();
00969               double e_ha  = calotower->hadEnergy();
00970               double et_em = e_em*sin(theta);
00971               double et_ha = e_ha*sin(theta);
00972 
00973               sum_em_ez += e_em*cos(theta);
00974               sum_em_et += et_em;
00975               sum_em_ex += et_em*cos(phi);
00976               sum_em_ey += et_em*sin(phi);
00977 
00978               sum_ha_ez += e_ha*cos(theta);
00979               sum_ha_et += et_ha;
00980               sum_ha_ex += et_ha*cos(phi);
00981               sum_ha_ey += et_ha*sin(phi);
00982 
00983             } // Et>0.5
00984           }   // calotower
00985         }     // candidate
00986     }         // loop
00987   
00988   //
00989   _EmMEx = -sum_em_ex;
00990   _EmMEy = -sum_em_ey;
00991   _EmMET = pow(_EmMEx*_EmMEx+_EmMEy*_EmMEy,0.5);
00992   _EmCaloEz = sum_em_ez;
00993   _EmSumEt  = sum_em_et;
00994   _EmMetPhi   = atan2( _EmMEy, _EmMEx ); 
00995   //
00996   _HaMEx = -sum_ha_ex;
00997   _HaMEy = -sum_ha_ey;
00998   _HaMET = pow(_HaMEx*_HaMEx+_HaMEy*_HaMEy,0.5);
00999   _HaCaloEz = sum_ha_ez;
01000   _HaSumEt  = sum_ha_et;
01001   _HaMetPhi   = atan2( _HaMEy, _HaMEx ); 
01002   
01003 }
01004 // ***********************************************************
01005 void CaloMETAnalyzer::validateMET(const reco::CaloMET& calomet, 
01006                                   edm::Handle<edm::View<reco::Candidate> > towers)
01007 {
01008 
01009   edm::View<reco::Candidate>::const_iterator towerCand = towers->begin();
01010   
01011   double sum_et = 0.0;
01012   double sum_ex = 0.0;
01013   double sum_ey = 0.0;
01014   double sum_ez = 0.0;
01015   
01016   for ( ; towerCand != towers->end(); towerCand++)
01017     {
01018       const reco::Candidate* candidate = &(*towerCand);
01019       if (candidate)
01020         {
01021           const CaloTower* calotower = dynamic_cast<const CaloTower*> (candidate);
01022           if (calotower){
01023             double Tower_ET = calotower->et();
01024             if (Tower_ET>0.3) {
01025               
01026               double phi   = candidate->phi();
01027               double theta = candidate->theta();
01028               double e     = candidate->energy();
01029               double et    = e*sin(theta);
01030               sum_ez += e*cos(theta);
01031               sum_et += et;
01032               sum_ex += et*cos(phi);
01033               sum_ey += et*sin(phi);
01034 
01035             } // Et>0.5
01036           }   // calotower
01037         }     // candidate
01038     }         // loop
01039   
01040   double Mex   = -sum_ex;
01041   double Mey   = -sum_ey;
01042   //double Mez   = -sum_ez;
01043   double Met   = sqrt( sum_ex*sum_ex + sum_ey*sum_ey );
01044   double Sumet = sum_et;
01045   //double MetPhi   = atan2( -sum_ey, -sum_ex ); // since MET is now a candidate,
01046   
01047   if (_verbose){
01048     if (Sumet!=calomet.sumEt() || Mex!=calomet.px() || Mey!=calomet.py() || Met!=calomet.pt() ){
01049       std::cout << _source << std::endl;
01050       std::cout << "SUMET" << Sumet << " METBlock" << calomet.sumEt() << std::endl;
01051       std::cout << "MEX"   << Mex   << " METBlock" << calomet.px()    << std::endl;
01052       std::cout << "MEY"   << Mey   << " METBlock" << calomet.py()    << std::endl;
01053       std::cout << "MET"   << Met   << " METBlock" << calomet.pt()    << std::endl;
01054     }
01055   }  
01056 
01057   if (_print){
01058     std::cout << "SUMET = " << calomet.sumEt() << " (GeV) "
01059               << "MEX"   << calomet.px() << " (GeV) "
01060               << "MEY"   << calomet.py() << " (GeV) " 
01061               << "MET"   << calomet.pt() << " (GeV) " << std::endl;
01062   }
01063 
01064 }
01065 
01066 // ***********************************************************
01067 void CaloMETAnalyzer::fillMESet(const edm::Event& iEvent, std::string DirName, 
01068                                 const reco::CaloMET& calomet)
01069 {
01070 
01071   _dbe->setCurrentFolder(DirName);
01072 
01073   bool bLumiSecPlot=false;
01074   if (DirName.find("All")) bLumiSecPlot=true;
01075 
01076   if (_trig_JetMB)
01077     fillMonitorElement(iEvent,DirName,"",calomet, bLumiSecPlot);
01078   if (_trig_HighPtJet)
01079     fillMonitorElement(iEvent,DirName,"HighPtJet",calomet,false);
01080   if (_trig_LowPtJet)
01081     fillMonitorElement(iEvent,DirName,"LowPtJet",calomet,false);
01082   if (_trig_MinBias)
01083     fillMonitorElement(iEvent,DirName,"MinBias",calomet,false);
01084   if (_trig_HighMET)
01085     fillMonitorElement(iEvent,DirName,"HighMET",calomet,false);
01086   if (_trig_LowMET)
01087     fillMonitorElement(iEvent,DirName,"LowMET",calomet,false);
01088   if (_trig_Ele)
01089     fillMonitorElement(iEvent,DirName,"Ele",calomet,false);
01090   if (_trig_Muon) {
01091     fillMonitorElement(iEvent,DirName,"Muon",calomet,false);
01092   }
01093 }
01094 
01095 // ***********************************************************
01096 void CaloMETAnalyzer::fillMonitorElement(const edm::Event& iEvent, std::string DirName, 
01097                                          std::string TriggerTypeName, 
01098                                          const reco::CaloMET& calomet, bool bLumiSecPlot)
01099 {
01100 
01101   if (TriggerTypeName=="HighPtJet") {
01102     if (!selectHighPtJetEvent(iEvent)) return;
01103   }
01104   else if (TriggerTypeName=="LowPtJet") {
01105     if (!selectLowPtJetEvent(iEvent)) return;
01106   }
01107   else if (TriggerTypeName=="HighMET") {
01108     if (calomet.pt()<_highMETThreshold) return;
01109   }
01110   else if (TriggerTypeName=="LowMET") {
01111     if (calomet.pt()<_lowMETThreshold) return;
01112   }
01113   else if (TriggerTypeName=="Ele") {
01114     if (!selectWElectronEvent(iEvent)) return;
01115   }
01116   else if (TriggerTypeName=="Muon") {
01117     if (!selectWMuonEvent(iEvent)) return;
01118   }
01119 
01120   double caloSumET  = calomet.sumEt();
01121   double caloMETSig = calomet.mEtSig();
01122   //double caloEz     = calomet.e_longitudinal();
01123   double caloMET    = calomet.pt();
01124   double caloMEx    = calomet.px();
01125   double caloMEy    = calomet.py();
01126   double caloMETPhi = calomet.phi();
01127 
01128   if (_verbose) std::cout << _source << " " << caloMET << std::endl;
01129 
01130   double caloEtFractionHadronic = calomet.etFractionHadronic();
01131   double caloEmEtFraction       = calomet.emEtFraction();
01132 
01133   double caloMaxEtInEMTowers    = calomet.maxEtInEmTowers();
01134   double caloMaxEtInHadTowers   = calomet.maxEtInHadTowers();
01135 
01136   double caloHadEtInHB = calomet.hadEtInHB();
01137   double caloHadEtInHO = calomet.hadEtInHO();
01138   double caloHadEtInHE = calomet.hadEtInHE();
01139   double caloHadEtInHF = calomet.hadEtInHF();
01140   double caloEmEtInEB  = calomet.emEtInEB();
01141   double caloEmEtInEE  = calomet.emEtInEE();
01142   double caloEmEtInHF  = calomet.emEtInHF();
01143 
01144   //
01145   int myLuminosityBlock;
01146   //  myLuminosityBlock = (evtCounter++)/1000;
01147   myLuminosityBlock = iEvent.luminosityBlock();
01148   //
01149 
01150   if (TriggerTypeName!="") DirName = DirName +"/"+TriggerTypeName;
01151 
01152   if (_verbose) std::cout << "_etThreshold = " << _etThreshold << std::endl;
01153   if (caloSumET>_etThreshold){
01154     hCaloMEx    = _dbe->get(DirName+"/"+"METTask_CaloMEx");    if (hCaloMEx     && hCaloMEx->getRootObject() )    hCaloMEx->Fill(caloMEx);
01155     hCaloMEy    = _dbe->get(DirName+"/"+"METTask_CaloMEy");    if (hCaloMEy     && hCaloMEy->getRootObject() )    hCaloMEy->Fill(caloMEy);
01156     hCaloMET    = _dbe->get(DirName+"/"+"METTask_CaloMET");    if (hCaloMET     && hCaloMET->getRootObject() )    hCaloMET->Fill(caloMET);
01157     hCaloMET1   = _dbe->get(DirName+"/"+"METTask_CaloMET1");   if (hCaloMET1    && hCaloMET1->getRootObject() )   hCaloMET1->Fill(caloMET);
01158     hCaloMETPhi = _dbe->get(DirName+"/"+"METTask_CaloMETPhi"); if (hCaloMETPhi  && hCaloMETPhi->getRootObject() ) hCaloMETPhi->Fill(caloMETPhi);
01159     hCaloSumET  = _dbe->get(DirName+"/"+"METTask_CaloSumET");  if (hCaloSumET   && hCaloSumET->getRootObject() )  hCaloSumET->Fill(caloSumET);
01160     hCaloMETSig = _dbe->get(DirName+"/"+"METTask_CaloMETSig"); if (hCaloMETSig  && hCaloMETSig->getRootObject() ) hCaloMETSig->Fill(caloMETSig);
01161     //hCaloEz     = _dbe->get(DirName+"/"+"METTask_CaloEz");     if (hCaloEz      && hCaloEz->getRootObject() )     hCaloEz->Fill(caloEz);
01162 
01163     hCaloMET_logx   = _dbe->get(DirName+"/"+"METTask_CaloMET_logx");      if (hCaloMET_logx    && hCaloMET_logx->getRootObject() )   hCaloMET_logx->Fill(log10(caloMET));
01164     hCaloSumET_logx = _dbe->get(DirName+"/"+"METTask_CaloSumET_logx");    if (hCaloSumET_logx  && hCaloSumET_logx->getRootObject() ) hCaloSumET_logx->Fill(log10(caloSumET));
01165 
01166     //  hCaloMETIonFeedbck = _dbe->get(DirName+"/"+"METTask_CaloMETIonFeedbck"); if (hCaloMETIonFeedbck  && hCaloMETIonFeedbck->getRootObject() ) hCaloMETIonFeedbck->Fill(caloMET);
01167     //  hCaloMETHPDNoise   = _dbe->get(DirName+"/"+"METTask_CaloMETHPDNoise");   if (hCaloMETHPDNoise    && hCaloMETHPDNoise->getRootObject() )   hCaloMETHPDNoise->Fill(caloMET);
01168 
01169     //hCaloMETPhi002 = _dbe->get(DirName+"/"+"METTask_CaloMETPhi002");    if (caloMET>  2. && hCaloMETPhi002  &&  hCaloMETPhi002->getRootObject()) { hCaloMETPhi002->Fill(caloMETPhi);}
01170     //hCaloMETPhi010 = _dbe->get(DirName+"/"+"METTask_CaloMETPhi010");    if (caloMET> 10. && hCaloMETPhi010  &&  hCaloMETPhi010->getRootObject()) { hCaloMETPhi010->Fill(caloMETPhi);}
01171     hCaloMETPhi020 = _dbe->get(DirName+"/"+"METTask_CaloMETPhi020");    if (caloMET> 20. && hCaloMETPhi020  &&  hCaloMETPhi020->getRootObject()) { hCaloMETPhi020->Fill(caloMETPhi);}
01172 
01173     if (_allhist){
01174       if (bLumiSecPlot){
01175         hCaloMExLS = _dbe->get(DirName+"/"+"METTask_CaloMEx_LS");   if (hCaloMExLS  &&  hCaloMExLS->getRootObject())    hCaloMExLS->Fill(caloMEx,myLuminosityBlock);
01176         hCaloMEyLS = _dbe->get(DirName+"/"+"METTask_CaloMEy_LS");   if (hCaloMEyLS  &&  hCaloMEyLS->getRootObject())    hCaloMEyLS->Fill(caloMEy,myLuminosityBlock);
01177       }
01178       
01179       hCaloEtFractionHadronic = _dbe->get(DirName+"/"+"METTask_CaloEtFractionHadronic"); if (hCaloEtFractionHadronic && hCaloEtFractionHadronic->getRootObject())  hCaloEtFractionHadronic->Fill(caloEtFractionHadronic);
01180       hCaloEmEtFraction       = _dbe->get(DirName+"/"+"METTask_CaloEmEtFraction");       if (hCaloEmEtFraction       && hCaloEmEtFraction->getRootObject())        hCaloEmEtFraction->Fill(caloEmEtFraction);
01181       
01182       //hCaloEmEtFraction002 = _dbe->get(DirName+"/"+"METTask_CaloEmEtFraction002");       if (caloMET>  2.  &&  hCaloEmEtFraction002    && hCaloEmEtFraction002->getRootObject()) hCaloEmEtFraction002->Fill(caloEmEtFraction);
01183       //hCaloEmEtFraction010 = _dbe->get(DirName+"/"+"METTask_CaloEmEtFraction010");       if (caloMET> 10.  &&  hCaloEmEtFraction010    && hCaloEmEtFraction010->getRootObject()) hCaloEmEtFraction010->Fill(caloEmEtFraction);
01184       hCaloEmEtFraction020 = _dbe->get(DirName+"/"+"METTask_CaloEmEtFraction020");       if (caloMET> 20.  &&  hCaloEmEtFraction020    && hCaloEmEtFraction020->getRootObject()) hCaloEmEtFraction020->Fill(caloEmEtFraction);
01185 
01186       hCaloMaxEtInEmTowers  = _dbe->get(DirName+"/"+"METTask_CaloMaxEtInEmTowers");   if (hCaloMaxEtInEmTowers  && hCaloMaxEtInEmTowers->getRootObject())   hCaloMaxEtInEmTowers->Fill(caloMaxEtInEMTowers);
01187       hCaloMaxEtInHadTowers = _dbe->get(DirName+"/"+"METTask_CaloMaxEtInHadTowers");  if (hCaloMaxEtInHadTowers && hCaloMaxEtInHadTowers->getRootObject())  hCaloMaxEtInHadTowers->Fill(caloMaxEtInHadTowers);
01188 
01189       hCaloHadEtInHB = _dbe->get(DirName+"/"+"METTask_CaloHadEtInHB");  if (hCaloHadEtInHB  &&  hCaloHadEtInHB->getRootObject())  hCaloHadEtInHB->Fill(caloHadEtInHB);
01190       hCaloHadEtInHO = _dbe->get(DirName+"/"+"METTask_CaloHadEtInHO");  if (hCaloHadEtInHO  &&  hCaloHadEtInHO->getRootObject())  hCaloHadEtInHO->Fill(caloHadEtInHO);
01191       hCaloHadEtInHE = _dbe->get(DirName+"/"+"METTask_CaloHadEtInHE");  if (hCaloHadEtInHE  &&  hCaloHadEtInHE->getRootObject())  hCaloHadEtInHE->Fill(caloHadEtInHE);
01192       hCaloHadEtInHF = _dbe->get(DirName+"/"+"METTask_CaloHadEtInHF");  if (hCaloHadEtInHF  &&  hCaloHadEtInHF->getRootObject())  hCaloHadEtInHF->Fill(caloHadEtInHF);
01193       hCaloEmEtInEB  = _dbe->get(DirName+"/"+"METTask_CaloEmEtInEB");   if (hCaloEmEtInEB   &&  hCaloEmEtInEB->getRootObject())   hCaloEmEtInEB->Fill(caloEmEtInEB);
01194       hCaloEmEtInEE  = _dbe->get(DirName+"/"+"METTask_CaloEmEtInEE");   if (hCaloEmEtInEE   &&  hCaloEmEtInEE->getRootObject())   hCaloEmEtInEE->Fill(caloEmEtInEE);
01195       hCaloEmEtInHF  = _dbe->get(DirName+"/"+"METTask_CaloEmEtInHF");   if (hCaloEmEtInHF   &&  hCaloEmEtInHF->getRootObject())   hCaloEmEtInHF->Fill(caloEmEtInHF);
01196 
01197       hCaloEmMEx    = _dbe->get(DirName+"/"+"METTask_CaloEmMEx");     if (hCaloEmMEx    && hCaloEmMEx->getRootObject())     hCaloEmMEx->Fill(_EmMEx);
01198       hCaloEmMEy    = _dbe->get(DirName+"/"+"METTask_CaloEmMEy");     if (hCaloEmMEy    && hCaloEmMEy->getRootObject())     hCaloEmMEy->Fill(_EmMEy);
01199       //hCaloEmEz     = _dbe->get(DirName+"/"+"METTask_CaloEmEz");      if (hCaloEmEz     && hCaloEmEz->getRootObject())      hCaloEmEz->Fill(_EmCaloEz);
01200       hCaloEmMET    = _dbe->get(DirName+"/"+"METTask_CaloEmMET");     if (hCaloEmMET    && hCaloEmMET->getRootObject())     hCaloEmMET->Fill(_EmMET);
01201       hCaloEmMETPhi = _dbe->get(DirName+"/"+"METTask_CaloEmMETPhi");  if (hCaloEmMETPhi && hCaloEmMETPhi->getRootObject())  hCaloEmMETPhi->Fill(_EmMetPhi);
01202       //hCaloEmSumET  = _dbe->get(DirName+"/"+"METTask_CaloEmSumET");   if (hCaloEmSumET  && hCaloEmSumET->getRootObject())   hCaloEmSumET->Fill(_EmSumEt);
01203 
01204       hCaloHaMEx    = _dbe->get(DirName+"/"+"METTask_CaloHaMEx");     if (hCaloHaMEx    && hCaloHaMEx->getRootObject())     hCaloHaMEx->Fill(_HaMEx);
01205       hCaloHaMEy    = _dbe->get(DirName+"/"+"METTask_CaloHaMEy");     if (hCaloHaMEy    && hCaloHaMEy->getRootObject())     hCaloHaMEy->Fill(_HaMEy);
01206       //hCaloHaEz     = _dbe->get(DirName+"/"+"METTask_CaloHaEz");      if (hCaloHaEz     && hCaloHaEz->getRootObject())      hCaloHaEz->Fill(_HaCaloEz);
01207       hCaloHaMET    = _dbe->get(DirName+"/"+"METTask_CaloHaMET");     if (hCaloHaMET    && hCaloHaMET->getRootObject())     hCaloHaMET->Fill(_HaMET);
01208       hCaloHaMETPhi = _dbe->get(DirName+"/"+"METTask_CaloHaMETPhi");  if (hCaloHaMETPhi && hCaloHaMETPhi->getRootObject())  hCaloHaMETPhi->Fill(_HaMetPhi);
01209       //hCaloHaSumET  = _dbe->get(DirName+"/"+"METTask_CaloHaSumET");   if (hCaloHaSumET  && hCaloHaSumET->getRootObject())   hCaloHaSumET->Fill(_HaSumEt);
01210 
01211     } // _allhist
01212     if (theCaloMETCollectionLabel.label() == "corMetGlobalMuons" ) {
01213 
01214       for( reco::MuonCollection::const_iterator muonit = muon_h->begin(); muonit != muon_h->end(); muonit++ ) {
01215         const reco::TrackRef siTrack = muonit->innerTrack();
01216         hCalomuPt    = _dbe->get(DirName+"/"+"METTask_CalomuPt");     if (hCalomuPt    && hCalomuPt->getRootObject())     hCalomuPt->Fill( muonit->p4().pt() );
01217         hCalomuEta   = _dbe->get(DirName+"/"+"METTask_CalomuEta");    if (hCalomuEta   && hCalomuEta->getRootObject())    hCalomuEta->Fill( muonit->p4().eta() );
01218         hCalomuNhits = _dbe->get(DirName+"/"+"METTask_CalomuNhits");  if (hCalomuNhits && hCalomuNhits->getRootObject())  hCalomuNhits->Fill( siTrack.isNonnull() ? siTrack->numberOfValidHits() : -999 );
01219         hCalomuChi2  = _dbe->get(DirName+"/"+"METTask_CalomuChi2");   if (hCalomuChi2  && hCalomuChi2->getRootObject())   hCalomuChi2->Fill( siTrack.isNonnull() ? siTrack->chi2()/siTrack->ndof() : -999 );
01220         double d0 = siTrack.isNonnull() ? -1 * siTrack->dxy( bspot) : -999;
01221         hCalomuD0    = _dbe->get(DirName+"/"+"METTask_CalomuD0");     if (hCalomuD0    && hCalomuD0->getRootObject())  hCalomuD0->Fill( d0 );
01222       }
01223       
01224       const unsigned int nMuons = muon_h->size();      
01225       for( unsigned int mus = 0; mus < nMuons; mus++ ) {
01226         reco::MuonRef muref( muon_h, mus);
01227         reco::MuonMETCorrectionData muCorrData = (*corMetGlobalMuons_ValueMap_Handle)[muref];
01228         hCaloMExCorrection      = _dbe->get(DirName+"/"+"METTask_CaloMExCorrection");       if (hCaloMExCorrection      && hCaloMExCorrection->getRootObject())       hCaloMExCorrection-> Fill(muCorrData.corrY());
01229         hCaloMEyCorrection      = _dbe->get(DirName+"/"+"METTask_CaloMEyCorrection");       if (hCaloMEyCorrection      && hCaloMEyCorrection->getRootObject())       hCaloMEyCorrection-> Fill(muCorrData.corrX());
01230         hCaloMuonCorrectionFlag = _dbe->get(DirName+"/"+"METTask_CaloMuonCorrectionFlag");  if (hCaloMuonCorrectionFlag && hCaloMuonCorrectionFlag->getRootObject())  hCaloMuonCorrectionFlag-> Fill(muCorrData.type());
01231       }
01232     }    
01233   } // et threshold cut
01234 
01235 }
01236 
01237 // ***********************************************************
01238 bool CaloMETAnalyzer::selectHighPtJetEvent(const edm::Event& iEvent){
01239 
01240   bool return_value=false;
01241 
01242   edm::Handle<reco::CaloJetCollection> caloJets;
01243   iEvent.getByLabel(theJetCollectionLabel, caloJets);
01244   if (!caloJets.isValid()) {
01245     LogDebug("") << "CaloMETAnalyzer: Could not find jet product" << std::endl;
01246     if (_verbose) std::cout << "CaloMETAnalyzer: Could not find jet product" << std::endl;
01247   }
01248 
01249   for (reco::CaloJetCollection::const_iterator cal = caloJets->begin(); 
01250        cal!=caloJets->end(); ++cal){
01251     if (cal->pt()>_highPtJetThreshold){
01252       return_value=true;
01253     }
01254   }
01255 
01256   return return_value;
01257 
01258 }
01259 
01260 // ***********************************************************
01261 bool CaloMETAnalyzer::selectLowPtJetEvent(const edm::Event& iEvent){
01262 
01263   bool return_value=false;
01264 
01265   edm::Handle<reco::CaloJetCollection> caloJets;
01266   iEvent.getByLabel(theJetCollectionLabel, caloJets);
01267   if (!caloJets.isValid()) {
01268     LogDebug("") << "CaloMETAnalyzer: Could not find jet product" << std::endl;
01269     if (_verbose) std::cout << "CaloMETAnalyzer: Could not find jet product" << std::endl;
01270   }
01271 
01272   for (reco::CaloJetCollection::const_iterator cal = caloJets->begin(); 
01273        cal!=caloJets->end(); ++cal){
01274     if (cal->pt()>_lowPtJetThreshold){
01275       return_value=true;
01276     }
01277   }
01278 
01279   return return_value;
01280 
01281 }
01282 
01283 // ***********************************************************
01284 bool CaloMETAnalyzer::selectWElectronEvent(const edm::Event& iEvent){
01285 
01286   bool return_value=true;
01287 
01288   /*
01289     W-electron event selection comes here
01290    */
01291 
01292   return return_value;
01293 
01294 }
01295 
01296 // ***********************************************************
01297 bool CaloMETAnalyzer::selectWMuonEvent(const edm::Event& iEvent){
01298 
01299   bool return_value=true;
01300 
01301   /*
01302     W-muon event selection comes here
01303    */
01304 
01305   return return_value;
01306 
01307 }
01308