CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Validation/RecoMET/src/METTester.cc

Go to the documentation of this file.
00001 #include "Validation/RecoMET/interface/METTester.h"
00002 // author: Mike Schmitt, University of Florida
00003 // first version 8/24/2006
00004 // modification: Bobby Scurlock
00005 // date:  03.11.2006
00006 // note:  added RMS(METx) vs SumET capability
00007 // modification: Rick Cavanaugh
00008 // date:  05.11.2006
00009 // note:  cleaned up constructor and beginJob, removed int conv. warning
00010 //        added configuration params
00011 // modification: Mike Schmitt
00012 // date:  02.28.2007
00013 // note:  code rewrite. Now uses STL map for monitoring element container. 
00014 // modification: Bobby Scurlock
00015 // date:  04.03.2007
00016 // note:  Eliminated automated resolution fitting. This is now done in a ROOT script.
00017 
00018 // date:  02.04.2009 
00019 // note:  Added option to use fine binning or course binning for histos
00020 
00021 #include "FWCore/PluginManager/interface/ModuleDef.h"
00022 #include "FWCore/Framework/interface/MakerMacros.h"
00023 
00024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00025 #include "FWCore/ServiceRegistry/interface/Service.h"
00026 
00027 #include "FWCore/Framework/interface/Event.h"
00028 #include "DataFormats/Common/interface/Handle.h"
00029 #include "FWCore/Framework/interface/ESHandle.h"
00030 
00031 #include "DataFormats/METReco/interface/CaloMET.h"
00032 #include "DataFormats/METReco/interface/CaloMETCollection.h"
00033 #include "DataFormats/METReco/interface/GenMET.h"
00034 #include "DataFormats/METReco/interface/GenMETCollection.h"
00035 #include "DataFormats/METReco/interface/MET.h"
00036 #include "DataFormats/METReco/interface/METFwd.h"
00037 #include "DataFormats/METReco/interface/PFMET.h"
00038 #include "DataFormats/METReco/interface/PFMETCollection.h"
00039 #include "DataFormats/MuonReco/interface/MuonMETCorrectionData.h"
00040 #include "DataFormats/Common/interface/ValueMap.h"  
00041 #include "DataFormats/MuonReco/interface/Muon.h"
00042 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00043 #include "DataFormats/MuonReco/interface/MuonMETCorrectionData.h"
00044 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00045 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00046 #include "DataFormats/TrackReco/interface/Track.h"
00047 
00048 #include <vector>
00049 #include <utility>
00050 #include <ostream>
00051 #include <fstream>
00052 #include <iostream>
00053 #include <algorithm>
00054 #include <cmath>
00055 #include <memory>
00056 #include "DQMServices/Core/interface/DQMStore.h"
00057 #include "TMath.h"
00058 
00059 METTester::METTester(const edm::ParameterSet& iConfig)
00060 {
00061   METType_                 = iConfig.getUntrackedParameter<std::string>("METType");
00062   inputMETLabel_           = iConfig.getParameter<edm::InputTag>("InputMETLabel");
00063   if(METType_ == "TCMET") {
00064        inputCaloMETLabel_       = iConfig.getParameter<edm::InputTag>("InputCaloMETLabel");     
00065   inputTrackLabel_         = iConfig.getParameter<edm::InputTag>("InputTrackLabel");    
00066   inputMuonLabel_          = iConfig.getParameter<edm::InputTag>("InputMuonLabel");
00067   inputElectronLabel_      = iConfig.getParameter<edm::InputTag>("InputElectronLabel");
00068   inputBeamSpotLabel_      = iConfig.getParameter<edm::InputTag>("InputBeamSpotLabel");
00069   minhits_                 = iConfig.getParameter<int>("minhits");
00070   maxd0_                   = iConfig.getParameter<double>("maxd0");
00071   maxchi2_                 = iConfig.getParameter<double>("maxchi2");
00072   maxeta_                  = iConfig.getParameter<double>("maxeta");
00073   maxpt_                   = iConfig.getParameter<double>("maxpt");
00074   maxPtErr_                = iConfig.getParameter<double>("maxPtErr");
00075   trkQuality_              = iConfig.getParameter<std::vector<int> >("trkQuality");
00076   trkAlgos_                = iConfig.getParameter<std::vector<int> >("trkAlgos");
00077   }
00078   finebinning_             = iConfig.getUntrackedParameter<bool>("FineBinning");
00079   FolderName_              = iConfig.getUntrackedParameter<std::string>("FolderName");
00080 }
00081 
00082 
00083 void METTester::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
00084 {
00085   // get ahold of back-end interface
00086   dbe_ = edm::Service<DQMStore>().operator->();
00087   
00088   if (dbe_) {
00089     //    TString dirName = "RecoMETV/METTask/MET/";
00090     //TString dirName = "JetMET/EventInfo/CertificationSummary/MET_Global/";
00091     //    TString dirName = "RecoMETV/MET_Global/";
00092     TString dirName(FolderName_.c_str()); 
00093     TString label(inputMETLabel_.label());
00094     dirName += label;
00095     dbe_->setCurrentFolder((std::string)dirName);
00096     
00097     if (METType_ == "CaloMET")
00098       { 
00099         // CaloMET Histograms
00100         if(!finebinning_)
00101           {
00102             me["hNevents"]                = dbe_->book1D("METTask_Nevents","METTask_Nevents",1,-0.5,1); 
00103             me["hCaloMEx"]                = dbe_->book1D("METTask_CaloMEx","METTask_CaloMEx",500,-999.5,499.5); 
00104             me["hCaloMEy"]                = dbe_->book1D("METTask_CaloMEy","METTask_CaloMEy",500,-999.5,499.5);
00105             //        me["hCaloEz"]                 = dbe_->book1D("METTask_CaloEz","METTask_CaloEz",2001,-500,501);
00106             me["hCaloMETSig"]             = dbe_->book1D("METTask_CaloMETSig","METTask_CaloMETSig",25,-0.5,24.5);
00107             me["hCaloMET"]                = dbe_->book1D("METTask_CaloMET","METTask_CaloMET",1000,-0.5,1999.5);
00108             me["hCaloMETPhi"]             = dbe_->book1D("METTask_CaloMETPhi","METTask_CaloMETPhi",80,-4,4);
00109             me["hCaloSumET"]              = dbe_->book1D("METTask_CaloSumET","METTask_CaloSumET",800,-0.5,7999.5);   //10GeV
00110             me["hCaloMaxEtInEmTowers"]    = dbe_->book1D("METTask_CaloMaxEtInEmTowers","METTask_CaloMaxEtInEmTowers",600,-0.5,2999.5);   //5GeV
00111             me["hCaloMaxEtInHadTowers"]   = dbe_->book1D("METTask_CaloMaxEtInHadTowers","METTask_CaloMaxEtInHadTowers",600,-.05,2999.5);  //5GeV
00112             me["hCaloEtFractionHadronic"] = dbe_->book1D("METTask_CaloEtFractionHadronic","METTask_CaloEtFractionHadronic",100,0,1);
00113             me["hCaloEmEtFraction"]       = dbe_->book1D("METTask_CaloEmEtFraction","METTask_CaloEmEtFraction",100,0,1);
00114             me["hCaloHadEtInHB"]          = dbe_->book1D("METTask_CaloHadEtInHB","METTask_CaloHadEtInHB",1000, -0.5, 4999.5);  //5GeV  
00115             me["hCaloHadEtInHO"]          = dbe_->book1D("METTask_CaloHadEtInHO","METTask_CaloHadEtInHO",250, -0.5, 499.5);  //5GeV
00116             me["hCaloHadEtInHE"]          = dbe_->book1D("METTask_CaloHadEtInHE","METTask_CaloHadEtInHE",200, -0.5, 399.5);  //5GeV
00117             me["hCaloHadEtInHF"]          = dbe_->book1D("METTask_CaloHadEtInHF","METTask_CaloHadEtInHF",100, -0.5, 199.5);  //5GeV
00118             me["hCaloEmEtInHF"]           = dbe_->book1D("METTask_CaloEmEtInHF","METTask_CaloEmEtInHF",100, -0.5, 99.5);   //5GeV
00119             me["hCaloEmEtInEE"]           = dbe_->book1D("METTask_CaloEmEtInEE","METTask_CaloEmEtInEE",100,0,199.5);    //5GeV
00120             me["hCaloEmEtInEB"]           = dbe_->book1D("METTask_CaloEmEtInEB","METTask_CaloEmEtInEB",1200,0, 5999.5);   //5GeV
00121 
00122 
00123             
00124             me["hCaloMETResolution_GenMETTrue"]      = dbe_->book1D("METTask_CaloMETResolution_GenMETTrue","METTask_CaloMETResolution_GenMETTrue", 500,-500,500); 
00125             me["hCaloMETResolution_GenMETCalo"]      = dbe_->book1D("METTask_CaloMETResolution_GenMETCalo","METTask_CaloMETResolution_GenMETCalo", 500,-500,500); 
00126 
00127             me["hCaloMETPhiResolution_GenMETTrue"] = dbe_->book1D("METTask_CaloMETPhiResolution_GenMETTrue","METTask_CaloMETPhiResolution_GenMETTrue", 80,0,4); 
00128             me["hCaloMETPhiResolution_GenMETCalo"] = dbe_->book1D("METTask_CaloMETPhiResolution_GenMETCalo","METTask_CaloMETPhiResolution_GenMETCalo", 80,0,4); 
00129             
00130           }
00131         else
00132           {
00133             //FineBinnning
00134             me["hNevents"]                = dbe_->book1D("METTask_Nevents","METTask_Nevents",1,-0.5,1);
00135             me["hCaloMEx"]                = dbe_->book1D("METTask_CaloMEx","METTask_CaloMEx",4001,-1000,1001);
00136             me["hCaloMEy"]                = dbe_->book1D("METTask_CaloMEy","METTask_CaloMEy",4001,-1000,1001);
00137             //me["hCaloEz"]                 = dbe_->book1D("METTask_CaloEz","METTask_CaloEz",2001,-500,501);
00138             me["hCaloMETSig"]             = dbe_->book1D("METTask_CaloMETSig","METTask_CaloMETSig",51,0,51);
00139             me["hCaloMET"]                = dbe_->book1D("METTask_CaloMET","METTask_CaloMET",2001,0,2001);
00140             me["hCaloMETPhi"]             = dbe_->book1D("METTask_CaloMETPhi","METTask_CaloMETPhi",80,-4,4);
00141             me["hCaloSumET"]              = dbe_->book1D("METTask_CaloSumET","METTask_CaloSumET",10001,0,10001);
00142             me["hCaloMaxEtInEmTowers"]    = dbe_->book1D("METTask_CaloMaxEtInEmTowers","METTask_CaloMaxEtInEmTowers",4001,0,4001);
00143             me["hCaloMaxEtInHadTowers"]   = dbe_->book1D("METTask_CaloMaxEtInHadTowers","METTask_CaloMaxEtInHadTowers",4001,0,4001);
00144             me["hCaloEtFractionHadronic"] = dbe_->book1D("METTask_CaloEtFractionHadronic","METTask_CaloEtFractionHadronic",100,0,1);
00145             me["hCaloEmEtFraction"]       = dbe_->book1D("METTask_CaloEmEtFraction","METTask_CaloEmEtFraction",100,0,1);
00146             me["hCaloHadEtInHB"]          = dbe_->book1D("METTask_CaloHadEtInHB","METTask_CaloHadEtInHB",8001,0,8001);
00147             me["hCaloHadEtInHO"]          = dbe_->book1D("METTask_CaloHadEtInHO","METTask_CaloHadEtInHO",4001,0,4001);
00148             me["hCaloHadEtInHE"]          = dbe_->book1D("METTask_CaloHadEtInHE","METTask_CaloHadEtInHE",4001,0,4001);
00149             me["hCaloHadEtInHF"]          = dbe_->book1D("METTask_CaloHadEtInHF","METTask_CaloHadEtInHF",4001,0,4001);
00150             me["hCaloHadEtInEB"]          = dbe_->book1D("METTask_CaloHadEtInEB","METTask_CaloHadEtInEB",8001,0,8001);
00151             me["hCaloHadEtInEE"]          = dbe_->book1D("METTask_CaloHadEtInEE","METTask_CaloHadEtInEE",4001,0,4001);
00152             me["hCaloEmEtInHF"]           = dbe_->book1D("METTask_CaloEmEtInHF","METTask_CaloEmEtInHF",4001,0,4001);
00153             me["hCaloEmEtInEE"]           = dbe_->book1D("METTask_CaloEmEtInEE","METTask_CaloEmEtInEE",4001,0,4001);
00154             me["hCaloEmEtInEB"]           = dbe_->book1D("METTask_CaloEmEtInEB","METTask_CaloEmEtInEB",8001,0,8001);
00155 
00156             me["hCaloMETResolution_GenMETTrue"]      = dbe_->book1D("METTask_CaloMETResolution_GenMETTrue","METTask_CaloMETResolution_GenMETTrue", 2000,-1000,1000); 
00157             me["hCaloMETResolution_GenMETCalo"]      = dbe_->book1D("METTask_CaloMETResolution_GenMETCalo","METTask_CaloMETResolution_GenMETCalo", 2000,-1000,1000); 
00158             
00159             me["hCaloMETPhiResolution_GenMETTrue"] = dbe_->book1D("METTask_CaloMETPhiResolution_GenMETTrue","METTask_CaloMETPhiResolution_GenMETTrue", 80,0,4); 
00160             me["hCaloMETPhiResolution_GenMETCalo"] = dbe_->book1D("METTask_CaloMETPhiResolution_GenMETCalo","METTask_CaloMETPhiResolution_GenMETCalo", 80,0,4); 
00161           }
00162       }
00163     
00164     else if (METType_ == "GenMET")
00165       {
00166         // GenMET Histograms
00167         
00168         if(!finebinning_)
00169           {
00170             me["hNevents"]                = dbe_->book1D("METTask_Nevents","METTask_Nevents",1,0,1); 
00171             me["hGenMEx"]                 = dbe_->book1D("METTask_GenMEx","METTask_GenMEx",1000,-999.5,999.5);
00172             me["hGenMEy"]                 = dbe_->book1D("METTask_GenMEy","METTask_GenMEy",1000,-999.5,999.5);
00173             //        me["hGenEz"]                  = dbe_->book1D("METTask_GenEz","METTask_GenEz",2001,-500,501);
00174             me["hGenMETSig"]              = dbe_->book1D("METTask_GenMETSig","METTask_GenMETSig",51,0,51);
00175             me["hGenMET"]                 = dbe_->book1D("METTask_GenMET","METTask_GenMET", 2000,-0.5,1999.5);
00176             me["hGenMETPhi"]              = dbe_->book1D("METTask_GenMETPhi","METTask_GenMETPhi",80,-4,4);
00177             me["hGenSumET"]               = dbe_->book1D("METTask_GenSumET","METTask_GenSumET",1000,-0.5,9999.5);
00178 
00179             me["hNeutralEMEtFraction"]    = dbe_->book1D("METTask_GenNeutralEMEtFraction", "METTask_GenNeutralEMEtFraction", 120, 0.0, 1.2 );
00180             me["hNeutralHadEtFraction"]   = dbe_->book1D("METTask_GenNeutralHadEtFraction", "METTask_GenNeutralHadEtFraction", 120, 0.0, 1.2 );
00181             me["hChargedEMEtFraction"]    = dbe_->book1D("METTask_GenChargedEMEtFraction", "METTask_GenChargedEMEtFraction", 120, 0.0, 1.2);
00182             me["hChargedHadEtFraction"]   = dbe_->book1D("METTask_GenChargedHadEtFraction", "METTask_GenChargedHadEtFraction", 120, 0.0,1.2);
00183             me["hMuonEtFraction"]         = dbe_->book1D("METTask_GenMuonEtFraction", "METTask_GenMuonEtFraction", 120, 0.0, 1.2 );
00184             me["hInvisibleEtFraction"]    = dbe_->book1D("METTask_GenInvisibleEtFraction", "METTask_GenInvisibleEtFraction", 120, 0.0, 1.2 );
00185             
00186           }
00187         else
00188           {
00189                me["hNevents"]                = dbe_->book1D("METTask_Nevents","METTask_Nevents",1,0,1);
00190                me["hGenMEx"]                 = dbe_->book1D("METTask_GenMEx","METTask_GenMEx",4001,-1000,1001);
00191                me["hGenMEy"]                 = dbe_->book1D("METTask_GenMEy","METTask_GenMEy",4001,-1000,1001);
00192                //me["hGenEz"]                  = dbe_->book1D("METTask_GenEz","METTask_GenEz",2001,-500,501);
00193                me["hGenMETSig"]              = dbe_->book1D("METTask_GenMETSig","METTask_GenMETSig",51,0,51);
00194                me["hGenMET"]                 = dbe_->book1D("METTask_GenMET","METTask_GenMET",2001,0,2001);
00195                me["hGenMETPhi"]              = dbe_->book1D("METTask_GenMETPhi","METTask_GenMETPhi",80,-4,4);
00196                me["hGenSumET"]               = dbe_->book1D("METTask_GenSumET","METTask_GenSumET",10001,0,10001);
00197                me["hNeutralEMEtFraction"]    = dbe_->book1D("METTask_GenNeutralEMEtFraction", "METTask_GenNeutralEMEtFraction", 120, 0.0, 1.2 );
00198                me["hNeutralHadEtFraction"]   = dbe_->book1D("METTask_GenNeutralHadEtFraction", "METTask_GenNeutralHadEtFraction", 120, 0.0, 1.2 );
00199                me["hChargedEMEtFraction"]    = dbe_->book1D("METTask_GenChargedEMEtFraction", "METTask_GenChargedEMEtFraction", 120, 0.0, 1.2);
00200                me["hChargedHadEtFraction"]   = dbe_->book1D("METTask_GenChargedHadEtFraction", "METTask_GenChargedHadEtFraction", 120, 0.0,1.2);
00201                me["hMuonEtFraction"]         = dbe_->book1D("METTask_GenMuonEtFraction", "METTask_GenMuonEtFraction", 120, 0.0, 1.2 );
00202                me["hInvisibleEtFraction"]    = dbe_->book1D("METTask_GenInvisibleEtFraction", "METTask_GenInvisibleEtFraction", 120, 0.0, 1.2 );
00203 
00204           }
00205       }
00206     else if (METType_ == "MET")
00207       {
00208         // MET Histograms
00209         if(!finebinning_)
00210           {
00211             me["hNevents"]                = dbe_->book1D("METTask_Nevents","METTask_Nevents",1,0,1); 
00212             me["hMEx"]                = dbe_->book1D("METTask_MEx","METTask_MEx",1000,-999.5,999.5);
00213             me["hMEy"]                = dbe_->book1D("METTask_MEy","METTask_MEy",1000,-999.5,999.5);
00214             //me["hEz"]                 = dbe_->book1D("METTask_Ez","METTask_Ez",1000,-999.5,999.5);
00215             me["hMETSig"]             = dbe_->book1D("METTask_METSig","METTask_METSig",50,-0.5,49.5);
00216             me["hMET"]                = dbe_->book1D("METTask_MET","METTask_MET",1000,-0.5,1999.5);
00217             me["hMETPhi"]             = dbe_->book1D("METTask_METPhi","METTask_METPhi",80,-4,4);
00218             me["hSumET"]              = dbe_->book1D("METTask_SumET","METTask_SumET",1000,0,9999.5);   
00219             
00220           }
00221         else
00222           {
00223             me["hNevents"]                = dbe_->book1D("METTask_Nevents","METTask_Nevents",1,0,1);
00224             me["hMEx"]                = dbe_->book1D("METTask_MEx","METTask_MEx",2001,-500,501);
00225             me["hMEy"]                = dbe_->book1D("METTask_MEy","METTask_MEy",2001,-500,501);
00226             //me["hEz"]                 = dbe_->book1D("METTask_Ez","METTask_Ez",2001,-500,501);
00227             me["hMETSig"]             = dbe_->book1D("METTask_METSig","METTask_METSig",51,0,51);
00228             me["hMET"]                = dbe_->book1D("METTask_MET","METTask_MET",2001,0,2001);
00229             me["hMETPhi"]             = dbe_->book1D("METTask_METPhi","METTask_METPhi",80,-4,4);
00230             me["hSumET"]              = dbe_->book1D("METTask_SumET","METTask_SumET",4001,0,4001);
00231 
00232           }
00233       }
00234     else if (METType_ == "PFMET")
00235       {
00236         // PFMET Histograms                                                                                                                  
00237         if(!finebinning_)
00238           {
00239             me["hNevents"]                = dbe_->book1D("METTask_Nevents","METTask_Nevents",1,0,1);   
00240             me["hMEx"]                = dbe_->book1D("METTask_MEx","METTask_MEx",1000,-999.5,999.5);
00241             me["hMEy"]                = dbe_->book1D("METTask_MEy","METTask_MEy",1000,-999.5,999.5);
00242             //        me["hEz"]                 = dbe_->book1D("METTask_Ez","METTask_Ez",2001,-500,501);
00243             me["hMETSig"]             = dbe_->book1D("METTask_METSig","METTask_METSig",51,0,51);
00244             me["hMET"]                = dbe_->book1D("METTask_MET","METTask_MET",1000,-0.5,1999.5);
00245             me["hMETPhi"]             = dbe_->book1D("METTask_METPhi","METTask_METPhi",80,-4,4);
00246             me["hSumET"]              = dbe_->book1D("METTask_SumET","METTask_SumET",1000,-0.50,9999.5);     
00247             
00248             me["hMETResolution_GenMETTrue"]      = dbe_->book1D("METTask_METResolution_GenMETTrue","METTask_METResolution_GenMETTrue", 500,-500,500); 
00249             me["hMETResolution_GenMETCalo"]      = dbe_->book1D("METTask_METResolution_GenMETCalo","METTask_METResolution_GenMETCalo", 500,-500,500); 
00250 
00251             me["hMETPhiResolution_GenMETTrue"] = dbe_->book1D("METTask_METPhiResolution_GenMETTrue","METTask_METPhiResolution_GenMETTrue", 80,0,4); 
00252             me["hMETPhiResolution_GenMETCalo"] = dbe_->book1D("METTask_METPhiResolution_GenMETCalo","METTask_METPhiResolution_GenMETCalo", 80,0,4); 
00253 
00254            }
00255         else
00256           {
00257             //FineBin
00258             me["hNevents"]                = dbe_->book1D("METTask_Nevents","METTask_Nevents",1,0,1);
00259             me["hMEx"]                = dbe_->book1D("METTask_MEx","METTask_MEx",2001,-500,501);
00260             me["hMEy"]                = dbe_->book1D("METTask_MEy","METTask_MEy",2001,-500,501);
00261             //me["hEz"]                 = dbe_->book1D("METTask_Ez","METTask_Ez",2001,-500,501);
00262             me["hMETSig"]             = dbe_->book1D("METTask_METSig","METTask_METSig",51,0,51);
00263             me["hMET"]                = dbe_->book1D("METTask_MET","METTask_MET",2001,0,2001);
00264             me["hMETPhi"]             = dbe_->book1D("METTask_METPhi","METTask_METPhi",80,-4,4);
00265             me["hSumET"]              = dbe_->book1D("METTask_SumET","METTask_SumET",4001,0,4001);
00266 
00267             me["hMETResolution_GenMETTrue"]      = dbe_->book1D("METTask_METResolution_GenMETTrue","METTask_METResolution_GenMETTrue",2000,-1000,1000);
00268             me["hMETResolution_GenMETCalo"]      = dbe_->book1D("METTask_METResolution_GenMETCalo","METTask_METResolution_GenMETCalo",2000,-1000,1000);
00269 
00270             me["hMETPhiResolution_GenMETTrue"] = dbe_->book1D("METTask_METPhiResolution_GenMETTrue","METTask_METPhiResolution_GenMETTrue", 80,0,4); 
00271             me["hMETPhiResolution_GenMETCalo"] = dbe_->book1D("METTask_METPhiResolution_GenMETCalo","METTask_METPhiResolution_GenMETCalo", 80,0,4); 
00272 
00273             
00274           }
00275       }
00276     else if (METType_ == "TCMET" || inputMETLabel_.label() == "corMetGlobalMuons")
00277       {
00278         //TCMET or MuonCorrectedCaloMET Histograms                                                                                                                  
00279         if(!finebinning_)
00280           {
00281             me["hNevents"]                = dbe_->book1D("METTask_Nevents","METTask_Nevents",1,0,1);   
00282             me["hMEx"]                = dbe_->book1D("METTask_MEx","METTask_MEx",1000,-999.5,999.5);
00283             me["hMEy"]                = dbe_->book1D("METTask_MEy","METTask_MEy",1000,-999.5,999.5);
00284             me["hMETSig"]             = dbe_->book1D("METTask_METSig","METTask_METSig",51,0,51);
00285             me["hMET"]                = dbe_->book1D("METTask_MET","METTask_MET",1000,-0.5,1999.5);
00286             me["hMETPhi"]             = dbe_->book1D("METTask_METPhi","METTask_METPhi",80,-4,4);
00287             me["hSumET"]              = dbe_->book1D("METTask_SumET","METTask_SumET",1000,-0.50,9999.5);     
00288            
00289             me["hMExCorrection"]       = dbe_->book1D("METTask_MExCorrection","METTask_MExCorrection", 1000, -500.0,500.0);
00290             me["hMEyCorrection"]       = dbe_->book1D("METTask_MEyCorrection","METTask_MEyCorrection", 1000, -500.0,500.0);
00291             me["hMuonCorrectionFlag"]      = dbe_->book1D("METTask_CorrectionFlag", "METTask_CorrectionFlag", 6, -0.5, 5.5);
00292 
00293             me["hMETResolution_GenMETTrue"]      = dbe_->book1D("METTask_METResolution_GenMETTrue","METTask_METResolution_GenMETTrue", 500,-500,500); 
00294             me["hMETResolution_GenMETCalo"]      = dbe_->book1D("METTask_METResolution_GenMETCalo","METTask_METResolution_GenMETCalo", 500,-500,500); 
00295 
00296             me["hMETPhiResolution_GenMETTrue"] = dbe_->book1D("METTask_METPhiResolution_GenMETTrue","METTask_METPhiResolution_GenMETTrue", 80,0,4); 
00297             me["hMETPhiResolution_GenMETCalo"] = dbe_->book1D("METTask_METPhiResolution_GenMETCalo","METTask_METPhiResolution_GenMETCalo", 80,0,4); 
00298 
00299             if( METType_ == "TCMET" ) {
00300               me["htrkPt"] = dbe_->book1D("METTask_trackPt", "METTask_trackPt", 50, 0, 500);
00301               me["htrkEta"] = dbe_->book1D("METTask_trackEta", "METTask_trackEta", 50, -2.5, 2.5);
00302               me["htrkNhits"] = dbe_->book1D("METTask_trackNhits", "METTask_trackNhits", 50, 0, 50);
00303               me["htrkChi2"] = dbe_->book1D("METTask_trackNormalizedChi2", "METTask_trackNormalizedChi2", 20, 0, 20);
00304               me["htrkD0"] = dbe_->book1D("METTask_trackD0", "METTask_trackd0", 50, -1, 1);
00305               me["htrkQuality"] = dbe_->book1D("METTask_trackQuality", "METTask_trackQuality", 30, -0.5, 29.5);
00306               me["htrkAlgo"] = dbe_->book1D("METTask_trackAlgo", "METTask_trackAlgo", 6, 3.5, 9.5);
00307               me["htrkPtErr"] = dbe_->book1D("METTask_trackPtErr", "METTask_trackPtErr", 200, 0, 2);
00308               me["helePt"] = dbe_->book1D("METTask_electronPt", "METTask_electronPt", 50, 0, 500);
00309               me["heleEta"] = dbe_->book1D("METTask_electronEta", "METTask_electronEta", 50, -2.5, 2.5);
00310               me["heleHoE"] = dbe_->book1D("METTask_electronHoverE", "METTask_electronHoverE", 25, 0, 0.5);
00311               me["hmuPt"] = dbe_->book1D("METTask_muonPt", "METTask_muonPt", 50, 0, 500);
00312               me["hmuEta"] = dbe_->book1D("METTask_muonEta", "METTask_muonEta", 50, -2.5, 2.5);
00313               me["hmuNhits"] = dbe_->book1D("METTask_muonNhits", "METTask_muonNhits", 50, 0, 50);
00314               me["hmuChi2"] = dbe_->book1D("METTask_muonNormalizedChi2", "METTask_muonNormalizedChi2", 20, 0, 20);
00315               me["hmuD0"] = dbe_->book1D("METTask_muonD0", "METTask_muonD0", 50, -1, 1);
00316               me["hnMus"] = dbe_->book1D("METTask_nMus", "METTask_nMus", 5, -0.5, 4.5);
00317               me["hnMusPis"] = dbe_->book1D("METTask_nMusAsPis", "METTask_nMusAsPis", 5, -0.5, 4.5);
00318               me["hmuSAhits"] = dbe_->book1D("METTask_muonSAhits", "METTask_muonSAhits", 51, -0.5, 50.5);
00319               me["hnEls"] = dbe_->book1D("METTask_nEls", "METTask_nEls", 5, -0.5, 4.5);
00320               me["hfracTrks"] = dbe_->book1D("METTask_fracTracks", "METTask_fracTracks", 100, 0, 1);
00321               me["hdMETx"] = dbe_->book1D("METTask_dMETx", "METTask_dMETx", 500, -250, 250);
00322               me["hdMETy"] = dbe_->book1D("METTask_dMETy", "METTask_dMETy", 500, -250, 250);
00323               me["hdMET"] = dbe_->book1D("METTask_dMET", "METTask_dMET", 500, -250, 250);
00324               me["hdMUx"] = dbe_->book1D("METTask_dMUx", "METTask_dMUx", 500, -250, 250);
00325               me["hdMUy"] = dbe_->book1D("METTask_dMUy", "METTask_dMUy", 500, -250, 250);
00326             }
00327             else if( inputMETLabel_.label() == "corMetGlobalMuons" ) {
00328               me["hmuPt"] = dbe_->book1D("METTask_muonPt", "METTask_muonPt", 50, 0, 500);
00329               me["hmuEta"] = dbe_->book1D("METTask_muonEta", "METTask_muonEta", 50, -2.5, 2.5);
00330               me["hmuNhits"] = dbe_->book1D("METTask_muonNhits", "METTask_muonNhits", 50, 0, 50);
00331               me["hmuChi2"] = dbe_->book1D("METTask_muonNormalizedChi2", "METTask_muonNormalizedChi2", 20, 0, 20);
00332               me["hmuD0"] = dbe_->book1D("METTask_muonD0", "METTask_muonD0", 50, -1, 1);
00333               me["hmuSAhits"] = dbe_->book1D("METTask_muonSAhits", "METTask_muonSAhits", 51, -0.5, 50.5);
00334             }
00335           }
00336         else
00337           {
00338             //FineBin
00339             me["hNevents"]            = dbe_->book1D("METTask_Nevents","METTask_Nevents",1,0,1);
00340             me["hMEx"]                = dbe_->book1D("METTask_MEx","METTask_MEx",2001,-500,501);
00341             me["hMEy"]                = dbe_->book1D("METTask_MEy","METTask_MEy",2001,-500,501);
00342             me["hMETSig"]             = dbe_->book1D("METTask_METSig","METTask_METSig",51,0,51);
00343             me["hMET"]                = dbe_->book1D("METTask_MET","METTask_MET",2001,0,2001);
00344             me["hMETPhi"]             = dbe_->book1D("METTask_METPhi","METTask_METPhi",80,-4,4);
00345             me["hSumET"]              = dbe_->book1D("METTask_SumET","METTask_SumET",4001,0,4001);
00346             me["hMExCorrection"]      = dbe_->book1D("METTask_MExCorrection","METTask_MExCorrection", 2000, -500.0,500.0);
00347             me["hMEyCorrection"]      = dbe_->book1D("METTask_MEyCorrection","METTask_MEyCorrection", 2000, -500.0,500.0);
00348             me["hMuonCorrectionFlag"]     = dbe_->book1D("METTask_CorrectionFlag", "METTask_CorrectionFlag", 6, -0.5, 5.5);                
00349 
00350             me["hMETResolution_GenMETTrue"]      = dbe_->book1D("METTask_METResolution_GenMETTrue","METTask_METResolution_GenMETTrue",2000,-1000,1000);
00351             me["hMETResolution_GenMETCalo"]      = dbe_->book1D("METTask_METResolution_GenMETCalo","METTask_METResolution_GenMETCalo",2000,-1000,1000);
00352             
00353             me["hMETPhiResolution_GenMETTrue"] = dbe_->book1D("METTask_METPhiResolution_GenMETTrue","METTask_METPhiResolution_GenMETTrue", 80,0,4); 
00354             me["hMETPhiResolution_GenMETCalo"] = dbe_->book1D("METTask_METPhiResolution_GenMETCalo","METTask_METPhiResolution_GenMETCalo", 80,0,4); 
00355 
00356             if( METType_ == "TCMET" ) {
00357               me["htrkPt"] = dbe_->book1D("METTask_trackPt", "METTask_trackPt", 250, 0, 500);
00358               me["htrkEta"] = dbe_->book1D("METTask_trackEta", "METTask_trackEta", 250, -2.5, 2.5);
00359               me["htrkNhits"] = dbe_->book1D("METTask_trackNhits", "METTask_trackNhits", 50, 0, 50);
00360               me["htrkChi2"] = dbe_->book1D("METTask_trackNormalizedChi2", "METTask_trackNormalizedChi2", 100, 0, 20);
00361               me["htrkD0"] = dbe_->book1D("METTask_trackD0", "METTask_trackd0", 200, -1, 1);
00362               me["htrkQuality"] = dbe_->book1D("METTask_trackQuality", "METTask_trackQuality", 30, -0.5, 29.5);
00363               me["htrkAlgo"] = dbe_->book1D("METTask_trackAlgo", "METTask_trackAlgo", 6, 3.5, 9.5);
00364               me["htrkPtErr"] = dbe_->book1D("METTask_trackPtErr", "METTask_trackPtErr", 200, 0, 2);
00365               me["helePt"] = dbe_->book1D("METTask_electronPt", "METTask_electronPt", 250, 0, 500);
00366               me["heleEta"] = dbe_->book1D("METTask_electronEta", "METTask_electronEta", 250, -2.5, 2.5);
00367               me["heleHoE"] = dbe_->book1D("METTask_electronHoverE", "METTask_electronHoverE", 100, 0, 0.5);
00368               me["hmuPt"] = dbe_->book1D("METTask_muonPt", "METTask_muonPt", 250, 0, 500);
00369               me["hmuEta"] = dbe_->book1D("METTask_muonEta", "METTask_muonEta", 250, -2.5, 2.5);
00370               me["hmuNhits"] = dbe_->book1D("METTask_muonNhits", "METTask_muonNhits", 50, 0, 50);
00371               me["hmuChi2"] = dbe_->book1D("METTask_muonNormalizedChi2", "METTask_muonNormalizedChi2", 100, 0, 20);
00372               me["hmuD0"] = dbe_->book1D("METTask_muonD0", "METTask_muonD0", 200, -1, 1);
00373               me["hnMus"] = dbe_->book1D("METTask_nMus", "METTask_nMus", 5, -0.5, 4.5);
00374               me["hnMusPis"] = dbe_->book1D("METTask_nMusAsPis", "METTask_nMusAsPis", 5, -0.5, 4.5);
00375               me["hmuSAhits"] = dbe_->book1D("METTask_muonSAhits", "METTask_muonSAhits", 51, -0.5, 50.5);
00376               me["hnEls"] = dbe_->book1D("METTask_nEls", "METTask_nEls", 5, -0.5, 4.5);
00377               me["hfracTrks"] = dbe_->book1D("METTask_fracTracks", "METTask_fracTracks", 100, 0, 1);
00378               me["hdMETx"] = dbe_->book1D("METTask_dMETx", "METTask_dMETx", 500, -250, 250);
00379               me["hdMETy"] = dbe_->book1D("METTask_dMETy", "METTask_dMETy", 500, -250, 250);
00380               me["hdMET"] = dbe_->book1D("METTask_dMET", "METTask_dMET", 500, -250, 250);
00381               me["hdMUx"] = dbe_->book1D("METTask_dMUx", "METTask_dMUx", 500, -250, 250);
00382               me["hdMUy"] = dbe_->book1D("METTask_dMUy", "METTask_dMUy", 500, -250, 250);
00383             }
00384             else if( inputMETLabel_.label() == "corMetGlobalMuons" ) {
00385               me["hmuPt"] = dbe_->book1D("METTask_muonPt", "METTask_muonPt", 250, 0, 500);
00386               me["hmuEta"] = dbe_->book1D("METTask_muonEta", "METTask_muonEta", 250, -2.5, 2.5);
00387               me["hmuNhits"] = dbe_->book1D("METTask_muonNhits", "METTask_muonNhits", 50, 0, 50);
00388               me["hmuChi2"] = dbe_->book1D("METTask_muonNormalizedChi2", "METTask_muonNormalizedChi2", 100, 0, 20);
00389               me["hmuD0"] = dbe_->book1D("METTask_muonD0", "METTask_muonD0", 200, -1, 1);
00390               me["hmuSAhits"] = dbe_->book1D("METTask_muonSAhits", "METTask_muonSAhits", 51, -0.5, 50.5);
00391             }
00392           }
00393         
00394         if(METType_ == "TCMET")
00395           {
00396             me["hMuonCorrectionFlag"]->setBinLabel(1,"Not Corrected");
00397             me["hMuonCorrectionFlag"]->setBinLabel(2,"Global Fit");
00398             me["hMuonCorrectionFlag"]->setBinLabel(3,"Tracker Fit");
00399             me["hMuonCorrectionFlag"]->setBinLabel(4,"SA Fit");
00400             me["hMuonCorrectionFlag"]->setBinLabel(5,"Treated as Pion");
00401             me["hMuonCorrectionFlag"]->setBinLabel(6,"Default fit");
00402           }
00403         else if( inputMETLabel_.label() == "corMetGlobalMuons") 
00404           {
00405             me["hMuonCorrectionFlag"]->setBinLabel(1,"Not Corrected");
00406             me["hMuonCorrectionFlag"]->setBinLabel(2,"Global Fit");
00407             me["hMuonCorrectionFlag"]->setBinLabel(3,"Tracker Fit");
00408             me["hMuonCorrectionFlag"]->setBinLabel(4,"SA Fit");
00409             me["hMuonCorrectionFlag"]->setBinLabel(5,"Treated as Pion");
00410             me["hMuonCorrectionFlag"]->setBinLabel(6,"Default fit");
00411           }
00412       }
00413     else
00414       {
00415         edm::LogInfo("OutputInfo") << " METType not correctly specified!'";// << outputFile_.c_str();
00416       }
00417   }
00418 }
00419 
00420 void METTester::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00421 {
00422     using namespace reco;
00423     if (METType_ == "CaloMET")
00424     { 
00425       const CaloMET *calomet;
00426       // Get CaloMET
00427       edm::Handle<CaloMETCollection> calo;
00428       iEvent.getByLabel(inputMETLabel_, calo);
00429       if (!calo.isValid()) {
00430         edm::LogInfo("OutputInfo") << " failed to retrieve data required by MET Task";
00431         edm::LogInfo("OutputInfo") << " MET Task cannot continue...!";
00432         return;
00433       } else {
00434         const CaloMETCollection *calometcol = calo.product();
00435         calomet = &(calometcol->front());
00436       }
00437 
00438 
00439       // ==========================================================
00440       // Reconstructed MET Information
00441       double caloSumET = calomet->sumEt();
00442       double caloMETSig = calomet->mEtSig();
00443       double caloMET = calomet->pt();
00444       double caloMEx = calomet->px();
00445       double caloMEy = calomet->py();
00446       double caloMETPhi = calomet->phi();
00447       double caloMaxEtInEMTowers = calomet->maxEtInEmTowers();
00448       double caloMaxEtInHadTowers = calomet->maxEtInHadTowers();
00449       double caloEtFractionHadronic = calomet->etFractionHadronic();
00450       double caloEmEtFraction = calomet->emEtFraction();
00451       double caloHadEtInHB = calomet->hadEtInHB();
00452       double caloHadEtInHO = calomet->hadEtInHO();
00453       double caloHadEtInHE = calomet->hadEtInHE();
00454       double caloHadEtInHF = calomet->hadEtInHF();
00455       double caloEmEtInEB = calomet->emEtInEB();
00456       double caloEmEtInEE = calomet->emEtInEE();
00457       double caloEmEtInHF = calomet->emEtInHF();
00458 
00459       edm::LogInfo("OutputInfo") << caloMET << " " << caloSumET << std::endl;
00460       me["hNevents"]->Fill(0.5);
00461       me["hCaloMEx"]->Fill(caloMEx);
00462       me["hCaloMEy"]->Fill(caloMEy);
00463       me["hCaloMET"]->Fill(caloMET);
00464       me["hCaloMETPhi"]->Fill(caloMETPhi);
00465       me["hCaloSumET"]->Fill(caloSumET);
00466       me["hCaloMETSig"]->Fill(caloMETSig);
00467       me["hCaloMaxEtInEmTowers"]->Fill(caloMaxEtInEMTowers);
00468       me["hCaloMaxEtInHadTowers"]->Fill(caloMaxEtInHadTowers);
00469       me["hCaloEtFractionHadronic"]->Fill(caloEtFractionHadronic);
00470       me["hCaloEmEtFraction"]->Fill(caloEmEtFraction);
00471       me["hCaloHadEtInHB"]->Fill(caloHadEtInHB);
00472       me["hCaloHadEtInHO"]->Fill(caloHadEtInHO);
00473       me["hCaloHadEtInHE"]->Fill(caloHadEtInHE);
00474       me["hCaloHadEtInHF"]->Fill(caloHadEtInHF);
00475       me["hCaloEmEtInEB"]->Fill(caloEmEtInEB);
00476       me["hCaloEmEtInEE"]->Fill(caloEmEtInEE);
00477       me["hCaloEmEtInHF"]->Fill(caloEmEtInHF);
00478 
00479       
00480       // Get Generated MET for Resolution plots
00481 
00482       edm::Handle<GenMETCollection> genTrue;
00483       iEvent.getByLabel("genMetTrue", genTrue);
00484       if (genTrue.isValid()) {
00485         const GenMETCollection *genmetcol = genTrue.product();
00486         const GenMET *genMetTrue = &(genmetcol->front());
00487         double genMET = genMetTrue->pt();
00488         double genMETPhi = genMetTrue->phi();
00489         
00490         me["hCaloMETResolution_GenMETTrue"]->Fill( caloMET - genMET );
00491         me["hCaloMETPhiResolution_GenMETTrue"]->Fill( TMath::ACos( TMath::Cos( caloMETPhi - genMETPhi ) ) );
00492       } else {
00493         edm::LogInfo("OutputInfo") << " failed to retrieve data required by MET Task:  genMetTrue";
00494       }    
00495 
00496 
00497       edm::Handle<GenMETCollection> genCalo;
00498       iEvent.getByLabel("genMetCalo", genCalo);
00499       if (genCalo.isValid()) {
00500         const GenMETCollection *genmetcol = genCalo.product();
00501         const GenMET  *genMetCalo = &(genmetcol->front());
00502         double genMET = genMetCalo->pt();
00503         double genMETPhi = genMetCalo->phi();
00504         
00505         me["hCaloMETResolution_GenMETCalo"]->Fill( caloMET - genMET );
00506         me["hCaloMETPhiResolution_GenMETCalo"]->Fill( TMath::ACos( TMath::Cos( caloMETPhi - genMETPhi ) ) );
00507       } else {
00508         edm::LogInfo("OutputInfo") << " failed to retrieve data required by MET Task:  genMetCalo";
00509       }    
00510 
00511 
00512     }
00513 
00514   
00515   else if (METType_ == "GenMET")
00516     {
00517       const GenMET *genmet;
00518       // Get Generated MET
00519       edm::Handle<GenMETCollection> gen;
00520       iEvent.getByLabel(inputMETLabel_, gen);
00521       if (!gen.isValid()) {
00522         edm::LogInfo("OutputInfo") << " failed to retrieve data required by MET Task";
00523         edm::LogInfo("OutputInfo") << " MET Task cannot continue...!";
00524         return;
00525       } else {
00526         const GenMETCollection *genmetcol = gen.product();
00527         genmet = &(genmetcol->front());
00528       }    
00529       
00530       // ==========================================================
00531       // Genenerated MET Information  
00532       double genSumET = genmet->sumEt();
00533       double genMET = genmet->pt();
00534       double genMEx = genmet->px();
00535       double genMEy = genmet->py();
00536       double genMETPhi = genmet->phi();
00537       double genMETSig = genmet->mEtSig();
00538       /*
00539       double genEmEnergy = genmet->emEnergy();
00540       double genHadEnergy = genmet->hadEnergy();
00541       double genInvisibleEnergy= genmet->invisibleEnergy();
00542       double genAuxiliaryEnergy= genmet->auxiliaryEnergy();
00543       */
00544 
00545       double NeutralEMEtFraction = genmet->NeutralEMEtFraction() ;
00546       double NeutralHadEtFraction = genmet->NeutralHadEtFraction() ;
00547       double ChargedEMEtFraction = genmet->ChargedEMEtFraction () ;
00548       double ChargedHadEtFraction = genmet->ChargedHadEtFraction();
00549       double MuonEtFraction = genmet->MuonEtFraction() ;
00550       double InvisibleEtFraction = genmet->InvisibleEtFraction() ;
00551 
00552       me["hNevents"]->Fill(0);
00553       me["hGenMEx"]->Fill(genMEx);
00554       me["hGenMEy"]->Fill(genMEy);
00555       me["hGenMET"]->Fill(genMET);
00556       me["hGenMETPhi"]->Fill(genMETPhi);
00557       me["hGenSumET"]->Fill(genSumET);
00558       me["hGenMETSig"]->Fill(genMETSig);
00559       //me["hGenEz"]->Fill(genEz);
00560 
00561       me["hNeutralEMEtFraction"]->Fill( NeutralEMEtFraction );
00562       me["hNeutralHadEtFraction"]->Fill( NeutralHadEtFraction );
00563       me["hChargedEMEtFraction"]->Fill( ChargedEMEtFraction );
00564       me["hChargedHadEtFraction"]->Fill( ChargedHadEtFraction );
00565       me["hMuonEtFraction"]->Fill( MuonEtFraction );
00566       me["hInvisibleEtFraction"]->Fill( InvisibleEtFraction );
00567 
00568       me["hNevents"]->Fill(0.5);
00569     }
00570   else if( METType_ == "PFMET")
00571     {
00572       const PFMET *pfmet;
00573       edm::Handle<PFMETCollection> hpfmetcol;
00574       iEvent.getByLabel(inputMETLabel_,hpfmetcol);
00575       if(!hpfmetcol.isValid()){
00576         edm::LogInfo("OutputInfo") << "falied to retrieve data require by MET Task";
00577         edm::LogInfo("OutputInfo") << "MET Taks cannot continue...!";
00578         return;
00579       }
00580       else
00581         {
00582           const PFMETCollection *pfmetcol = hpfmetcol.product();
00583           pfmet = &(pfmetcol->front());
00584         }
00585       // Reconstructed MET Information                                                                                                     
00586       double SumET = pfmet->sumEt();
00587       double MET = pfmet->pt();
00588       double MEx = pfmet->px();
00589       double MEy = pfmet->py();
00590       double METPhi = pfmet->phi();
00591       double METSig = pfmet->mEtSig();
00592       me["hMEx"]->Fill(MEx);
00593       me["hMEy"]->Fill(MEy);
00594       me["hMET"]->Fill(MET);
00595       me["hMETPhi"]->Fill(METPhi);
00596       me["hSumET"]->Fill(SumET);
00597       me["hMETSig"]->Fill(METSig);
00598       me["hNevents"]->Fill(0.5);
00599 
00600       edm::Handle<GenMETCollection> genTrue;
00601       iEvent.getByLabel("genMetTrue", genTrue);
00602       if (genTrue.isValid()) {
00603         const GenMETCollection *genmetcol = genTrue.product();
00604         const GenMET *genMetTrue = &(genmetcol->front());
00605         double genMET = genMetTrue->pt();
00606         double genMETPhi = genMetTrue->phi();
00607         
00608         me["hMETResolution_GenMETTrue"]->Fill( MET - genMET );
00609         me["hMETPhiResolution_GenMETTrue"]->Fill( TMath::ACos( TMath::Cos( METPhi - genMETPhi ) ) );
00610       } else {
00611         edm::LogInfo("OutputInfo") << " failed to retrieve data required by MET Task:  genMetTrue";
00612       }    
00613 
00614 
00615       edm::Handle<GenMETCollection> genCalo;
00616       iEvent.getByLabel("genMetCalo", genCalo);
00617       if (genCalo.isValid()) {
00618         const GenMETCollection *genmetcol = genCalo.product();
00619         const GenMET  *genMetCalo = &(genmetcol->front());
00620         double genMET = genMetCalo->pt();
00621         double genMETPhi = genMetCalo->phi();
00622         
00623         me["hMETResolution_GenMETCalo"]->Fill( MET - genMET );
00624         me["hMETPhiResolution_GenMETCalo"]->Fill( TMath::ACos( TMath::Cos( METPhi - genMETPhi ) ) );
00625       } else {
00626         edm::LogInfo("OutputInfo") << " failed to retrieve data required by MET Task:  genMetCalo";
00627       }    
00628       
00629 
00630 
00631     }
00632   else if (METType_ == "MET")
00633     {
00634       const MET *met;
00635       // Get Generated MET
00636       edm::Handle<METCollection> hmetcol;
00637       iEvent.getByLabel(inputMETLabel_, hmetcol);
00638       if (!hmetcol.isValid()) {
00639         edm::LogInfo("OutputInfo") << " failed to retrieve data required by MET Task";
00640         edm::LogInfo("OutputInfo") << " MET Task cannot continue...!";
00641         return;
00642       } else {
00643         const METCollection *metcol = hmetcol.product();
00644         met = &(metcol->front());
00645       }   
00646 
00647       // Reconstructed MET Information
00648       double SumET = met->sumEt();
00649       double MET = met->pt();
00650       double MEx = met->px();
00651       double MEy = met->py();
00652       double METPhi = met->phi();
00653       double METSig = met->mEtSig();
00654 
00655       me["hMEx"]->Fill(MEx);
00656       me["hMEy"]->Fill(MEy);
00657       me["hMET"]->Fill(MET);
00658       me["hMETPhi"]->Fill(METPhi);
00659       me["hSumET"]->Fill(SumET);
00660       me["hMETSig"]->Fill(METSig);
00661       me["hNevents"]->Fill(0.5);
00662 
00663     }
00664   else if( METType_ == "TCMET" )
00665     {
00666       const MET *tcMet;
00667       edm::Handle<METCollection> htcMetcol;
00668       iEvent.getByLabel(inputMETLabel_, htcMetcol);
00669 
00670       const CaloMET *caloMet;
00671       edm::Handle<CaloMETCollection> hcaloMetcol;
00672       iEvent.getByLabel(inputCaloMETLabel_, hcaloMetcol);
00673 
00674       edm::Handle< reco::MuonCollection > muon_h;
00675       iEvent.getByLabel(inputMuonLabel_, muon_h);
00676       
00677 //      edm::Handle< edm::View<reco::Track> > track_h;
00678       edm::Handle<reco::TrackCollection> track_h;
00679       iEvent.getByLabel(inputTrackLabel_, track_h);
00680       
00681       edm::Handle< edm::View<reco::GsfElectron > > electron_h;
00682       iEvent.getByLabel(inputElectronLabel_, electron_h);
00683       
00684       edm::Handle< reco::BeamSpot > beamSpot_h;
00685       iEvent.getByLabel(inputBeamSpotLabel_, beamSpot_h);
00686       
00687       if(!htcMetcol.isValid()){
00688         edm::LogInfo("OutputInfo") << "falied to retrieve data require by MET Task";
00689         edm::LogInfo("OutputInfo") << "MET Taks cannot continue...!";
00690         return;
00691       }
00692       else
00693         {
00694           const METCollection *tcMetcol = htcMetcol.product();
00695           tcMet = &(tcMetcol->front());
00696         }
00697 
00698       if(!hcaloMetcol.isValid()){
00699         edm::LogInfo("OutputInfo") << "falied to retrieve data require by MET Task";
00700         edm::LogInfo("OutputInfo") << "MET Taks cannot continue...!";
00701         return;
00702       }
00703       else
00704         {
00705           const CaloMETCollection *caloMetcol = hcaloMetcol.product();
00706           caloMet = &(caloMetcol->front());
00707         }
00708       
00709       if(!muon_h.isValid()){
00710         edm::LogInfo("OutputInfo") << "falied to retrieve muon data require by MET Task";
00711         edm::LogInfo("OutputInfo") << "MET Taks cannot continue...!";
00712         return;
00713       }
00714       
00715       if(!track_h.isValid()){
00716         edm::LogInfo("OutputInfo") << "falied to retrieve track data require by MET Task";
00717         edm::LogInfo("OutputInfo") << "MET Taks cannot continue...!";
00718         return;
00719       }
00720       
00721       if(!electron_h.isValid()){
00722         edm::LogInfo("OutputInfo") << "falied to retrieve electron data require by MET Task";
00723         edm::LogInfo("OutputInfo") << "MET Taks cannot continue...!";
00724         return;
00725       }
00726       
00727       if(!beamSpot_h.isValid()){
00728         edm::LogInfo("OutputInfo") << "falied to retrieve beam spot data require by MET Task";
00729         edm::LogInfo("OutputInfo") << "MET Taks cannot continue...!";
00730         return;
00731       }
00732 
00733       math::XYZPoint bspot = ( beamSpot_h.isValid() ) ? beamSpot_h->position() : math::XYZPoint(0, 0, 0);
00734       
00735       // Reconstructed TCMET Information                                                                                                     
00736       double SumET = tcMet->sumEt();
00737       double MET = tcMet->pt();
00738       double MEx = tcMet->px();
00739       double MEy = tcMet->py();
00740       double METPhi = tcMet->phi();
00741       double METSig = tcMet->mEtSig();
00742 
00743       me["hMEx"]->Fill(MEx);
00744       me["hMEy"]->Fill(MEy);
00745       me["hMET"]->Fill(MET);
00746       me["hMETPhi"]->Fill(METPhi);
00747       me["hSumET"]->Fill(SumET);
00748       me["hMETSig"]->Fill(METSig);
00749       me["hNevents"]->Fill(0.5);
00750 
00751       double caloMET = caloMet->pt();
00752       double caloMEx = caloMet->px();
00753       double caloMEy = caloMet->py();
00754 
00755       me["hdMETx"]->Fill(caloMEx-MEx);
00756       me["hdMETy"]->Fill(caloMEy-MEy);
00757       me["hdMET"]->Fill(caloMET-MET);
00758       
00759       unsigned int nTracks = track_h->size();
00760       unsigned int nCorrTracks = 0;
00761       unsigned int trackCount = 0;
00762 //      for( edm::View<reco::Track>::const_iterator trkit = track_h->begin(); trkit != track_h->end(); trkit++ ) {
00763       for( reco::TrackCollection::const_iterator trkit = track_h->begin(); trkit != track_h->end(); trkit++ ) {
00764            ++trackCount;
00765         me["htrkPt"]->Fill( trkit->pt() );
00766         me["htrkEta"]->Fill( trkit->eta() );
00767         me["htrkNhits"]->Fill( trkit->numberOfValidHits() );
00768         me["htrkChi2"]->Fill( trkit->chi2() / trkit->ndof() );
00769 
00770         double d0 = -1 * trkit->dxy( bspot );
00771  
00772         me["htrkD0"]->Fill( d0 );
00773 
00774         me["htrkQuality"]->Fill( trkit->qualityMask() );
00775         me["htrkAlgo"]->Fill( trkit->algo() );
00776         me["htrkPtErr"]->Fill( trkit->ptError() / trkit->pt() );
00777 
00778         reco::TrackRef trkref( track_h, trackCount );
00779 
00780         if( isGoodTrack( trkref, d0) ) ++nCorrTracks;
00781       }
00782 
00783       float frac = (float)nCorrTracks / (float)nTracks;
00784       me["hfracTrks"]->Fill(frac);
00785 
00786       int nEls = 0;
00787       for( edm::View<reco::GsfElectron>::const_iterator eleit = electron_h->begin(); eleit != electron_h->end(); eleit++ ) {
00788         me["helePt"]->Fill( eleit->p4().pt() );  
00789         me["heleEta"]->Fill( eleit->p4().eta() );
00790         me["heleHoE"]->Fill( eleit->hadronicOverEm() );
00791 
00792         reco::TrackRef el_track = eleit->closestCtfTrackRef();
00793 
00794         unsigned int ele_idx = el_track.isNonnull() ? el_track.key() : 99999;
00795 
00796         if( eleit->hadronicOverEm() < 0.1 && ele_idx < nTracks )
00797              ++nEls;
00798       }
00799       
00800       me["hnEls"]->Fill(nEls);
00801 
00802       for( reco::MuonCollection::const_iterator muonit = muon_h->begin(); muonit != muon_h->end(); muonit++ ) {
00803 
00804         const reco::TrackRef siTrack = muonit->innerTrack();
00805 
00806         me["hmuPt"]->Fill( muonit->p4().pt() );
00807         me["hmuEta"]->Fill( muonit->p4().eta() );
00808         me["hmuNhits"]->Fill( siTrack.isNonnull() ? siTrack->numberOfValidHits() : -999 );
00809         me["hmuChi2"]->Fill( siTrack.isNonnull() ? siTrack->chi2()/siTrack->ndof() : -999 );
00810 
00811         double d0 = siTrack.isNonnull() ? -1 * siTrack->dxy( bspot) : -999;
00812 
00813         me["hmuD0"]->Fill( d0 );
00814       }
00815 
00816       edm::Handle< edm::ValueMap<reco::MuonMETCorrectionData> > tcMet_ValueMap_Handle;
00817       iEvent.getByLabel("muonTCMETValueMapProducer" , "muCorrData", tcMet_ValueMap_Handle);
00818 
00819       edm::Handle< edm::ValueMap<reco::MuonMETCorrectionData> > muon_ValueMap_Handle;
00820       iEvent.getByLabel("muonMETValueMapProducer" , "muCorrData", muon_ValueMap_Handle);
00821       
00822       const unsigned int nMuons = muon_h->size();      
00823 
00824       int nMus = 0;
00825       int nMusPis = 0;
00826       double muDx = 0;
00827       double muDy = 0;
00828       for( unsigned int mus = 0; mus < nMuons; mus++ ) 
00829         {
00830           reco::MuonRef muref( muon_h, mus);
00831           reco::MuonMETCorrectionData muCorrData = (*tcMet_ValueMap_Handle)[muref];
00832           reco::MuonMETCorrectionData muonCorrData = (*muon_ValueMap_Handle)[muref];
00833 
00834           me["hMExCorrection"] -> Fill(muCorrData.corrX());
00835           me["hMEyCorrection"] -> Fill(muCorrData.corrY());
00836 
00837           int type = muCorrData.type();
00838           me["hMuonCorrectionFlag"]-> Fill(type);
00839 
00840           if( type == 1 || type == 2 || type == 5 ) {
00841                ++nMus;
00842                
00843                if( type == 1 ) {
00844                     muDx += muonCorrData.corrX() - muref->globalTrack()->px();
00845                     muDy += muonCorrData.corrY() - muref->globalTrack()->py();
00846                }
00847                else if( type == 2 ) {
00848                     muDx += muonCorrData.corrX() - muref->innerTrack()->px();
00849                     muDy += muonCorrData.corrY() - muref->innerTrack()->py();
00850                }
00851                else if( type == 5 ) {
00852                     muDx += muonCorrData.corrX() - muref->px();
00853                     muDy += muonCorrData.corrY() - muref->py();
00854                }
00855           }
00856           else if( type == 4 )
00857                ++nMusPis;
00858         }
00859 
00860       me["hnMus"]->Fill(nMus);
00861       me["hnMusPis"]->Fill(nMusPis);
00862       me["hdMUx"]->Fill(muDx);
00863       me["hdMUy"]->Fill(muDy);
00864 
00865       edm::Handle<GenMETCollection> genTrue;
00866       iEvent.getByLabel("genMetTrue", genTrue);
00867       if (genTrue.isValid()) {
00868         const GenMETCollection *genmetcol = genTrue.product();
00869         const GenMET *genMetTrue = &(genmetcol->front());
00870         double genMET = genMetTrue->pt();
00871         double genMETPhi = genMetTrue->phi();
00872         
00873         me["hMETResolution_GenMETTrue"]->Fill( MET - genMET );
00874         me["hMETPhiResolution_GenMETTrue"]->Fill( TMath::ACos( TMath::Cos( METPhi - genMETPhi ) ) );
00875       } else {
00876         edm::LogInfo("OutputInfo") << " failed to retrieve data required by MET Task:  genMetTrue";
00877       }    
00878 
00879 
00880       edm::Handle<GenMETCollection> genCalo;
00881       iEvent.getByLabel("genMetCalo", genCalo);
00882       if (genCalo.isValid()) {
00883         const GenMETCollection *genmetcol = genCalo.product();
00884         const GenMET  *genMetCalo = &(genmetcol->front());
00885         double genMET = genMetCalo->pt();
00886         double genMETPhi = genMetCalo->phi();
00887         
00888         me["hMETResolution_GenMETCalo"]->Fill( MET - genMET );
00889         me["hMETPhiResolution_GenMETCalo"]->Fill( TMath::ACos( TMath::Cos( METPhi - genMETPhi ) ) );
00890       } else {
00891         edm::LogInfo("OutputInfo") << " failed to retrieve data required by MET Task:  genMetCalo";
00892       }          
00893     }
00894 
00895   else if( inputMETLabel_.label() == "corMetGlobalMuons" )
00896     {
00897       const CaloMET *corMetGlobalMuons = 0;
00898       edm::Handle<CaloMETCollection> hcorMetGlobalMuonscol;
00899       iEvent.getByLabel(inputMETLabel_, hcorMetGlobalMuonscol );
00900       if(! hcorMetGlobalMuonscol.isValid()){
00901         edm::LogInfo("OutputInfo") << "hcorMetGlobalMuonscol is NOT Valid";
00902         edm::LogInfo("OutputInfo") << "MET Taks continues anyway...!";
00903       }
00904       else
00905         {        
00906           const CaloMETCollection *corMetGlobalMuonscol = hcorMetGlobalMuonscol.product();
00907           corMetGlobalMuons = &(corMetGlobalMuonscol->front());
00908         }
00909 
00910       // Reconstructed TCMET Information                                                                                                     
00911       double SumET = corMetGlobalMuons->sumEt();
00912       double MET = corMetGlobalMuons->pt();
00913       double MEx = corMetGlobalMuons->px();
00914       double MEy = corMetGlobalMuons->py();
00915       double METPhi = corMetGlobalMuons->phi();
00916       double METSig = corMetGlobalMuons->mEtSig();
00917       me["hMEx"]->Fill(MEx);
00918       me["hMEy"]->Fill(MEy);
00919       me["hMET"]->Fill(MET);
00920       me["hMETPhi"]->Fill(METPhi);
00921       me["hSumET"]->Fill(SumET);
00922       me["hMETSig"]->Fill(METSig);
00923       me["hNevents"]->Fill(0.5);
00924 
00925       edm::Handle< edm::ValueMap<reco::MuonMETCorrectionData> > corMetGlobalMuons_ValueMap_Handle;
00926       iEvent.getByLabel("muonMETValueMapProducer" , "muCorrData", corMetGlobalMuons_ValueMap_Handle);
00927       
00928       edm::Handle< reco::MuonCollection > muon_Handle;
00929       iEvent.getByLabel("muons", muon_Handle);
00930 
00931       edm::Handle< reco::BeamSpot > beamSpot_h;
00932       iEvent.getByLabel(inputBeamSpotLabel_, beamSpot_h);
00933 
00934       if(!beamSpot_h.isValid()){
00935         edm::LogInfo("OutputInfo") << "beamSpot is NOT Valid";
00936         edm::LogInfo("OutputInfo") << "MET Taks continues anyway...!";
00937       }
00938 
00939       math::XYZPoint bspot = ( beamSpot_h.isValid() ) ? beamSpot_h->position() : math::XYZPoint(0, 0, 0);
00940 
00941       for( reco::MuonCollection::const_iterator muonit = muon_Handle->begin(); muonit != muon_Handle->end(); muonit++ ) {
00942 
00943         const reco::TrackRef siTrack = muonit->innerTrack();
00944         const reco::TrackRef globalTrack = muonit->globalTrack();
00945 
00946         me["hmuPt"]->Fill( muonit->p4().pt() );
00947         me["hmuEta"]->Fill( muonit->p4().eta() );
00948         me["hmuNhits"]->Fill( siTrack.isNonnull() ? siTrack->numberOfValidHits() : -999 );
00949         me["hmuChi2"]->Fill( siTrack.isNonnull() ? siTrack->chi2()/siTrack->ndof() : -999 );
00950 
00951         double d0 = siTrack.isNonnull() ? -1 * siTrack->dxy( bspot) : -999;
00952 
00953         me["hmuD0"]->Fill( d0 );
00954 
00955         int nHits = globalTrack.isNonnull() ? globalTrack->hitPattern().numberOfValidMuonHits() : -999;
00956 
00957         me["hmuSAhits"]->Fill( nHits );
00958       }
00959 
00960       const unsigned int nMuons = muon_Handle->size();      
00961       for( unsigned int mus = 0; mus < nMuons; mus++ ) 
00962         {
00963           reco::MuonRef muref( muon_Handle, mus);
00964           reco::MuonMETCorrectionData muCorrData = (*corMetGlobalMuons_ValueMap_Handle)[muref];
00965           
00966           me["hMExCorrection"] -> Fill(muCorrData.corrY());
00967           me["hMEyCorrection"] -> Fill(muCorrData.corrX());
00968           me["hMuonCorrectionFlag"]-> Fill(muCorrData.type());
00969         }
00970 
00971            edm::Handle<GenMETCollection> genTrue;
00972       iEvent.getByLabel("genMetTrue", genTrue);
00973       if (genTrue.isValid()) {
00974         const GenMETCollection *genmetcol = genTrue.product();
00975         const GenMET *genMetTrue = &(genmetcol->front());
00976         double genMET = genMetTrue->pt();
00977         double genMETPhi = genMetTrue->phi();
00978         
00979         me["hMETResolution_GenMETTrue"]->Fill( MET - genMET );
00980         me["hMETPhiResolution_GenMETTrue"]->Fill( TMath::ACos( TMath::Cos( METPhi - genMETPhi ) ) );
00981       } else {
00982         edm::LogInfo("OutputInfo") << " failed to retrieve data required by MET Task:  genMetTrue";
00983       }    
00984 
00985 
00986       edm::Handle<GenMETCollection> genCalo;
00987       iEvent.getByLabel("genMetCalo", genCalo);
00988       if (genCalo.isValid()) {
00989         const GenMETCollection *genmetcol = genCalo.product();
00990         const GenMET  *genMetCalo = &(genmetcol->front());
00991         double genMET = genMetCalo->pt();
00992         double genMETPhi = genMetCalo->phi();
00993         
00994         me["hMETResolution_GenMETCalo"]->Fill( MET - genMET );
00995         me["hMETPhiResolution_GenMETCalo"]->Fill( TMath::ACos( TMath::Cos( METPhi - genMETPhi ) ) );
00996       } else {
00997         edm::LogInfo("OutputInfo") << " failed to retrieve data required by MET Task:  genMetCalo";
00998       }    
00999       
01000 
01001 
01002     }
01003 
01004 }
01005 
01006 void METTester::endJob() 
01007 { 
01008 }
01009 
01010 //determines if track is "good" - i.e. passes quality and kinematic cuts
01011 bool METTester::isGoodTrack( const reco::TrackRef track, float d0corr ) {
01012 
01013      if( fabs( d0corr ) > maxd0_ ) return false;
01014      if( track->numberOfValidHits() < minhits_ ) return false;
01015      if( track->normalizedChi2() > maxchi2_ ) return false;
01016      if( fabs( track->eta() ) > maxeta_ ) return false;
01017      if( track->pt() > maxpt_ ) return false;
01018      if( (track->ptError() / track->pt()) > maxPtErr_ ) return false;
01019 
01020      int cut = 0;
01021      for( unsigned int i = 0; i < trkQuality_.size(); i++ ) {
01022        
01023           cut |= (1 << trkQuality_.at(i));
01024      }
01025 
01026      if( !( ( track->qualityMask() & cut ) == cut ) ) return false;
01027 
01028      bool isGoodAlgo = false;
01029      if( trkAlgos_.size() == 0 ) isGoodAlgo = true;
01030      for( unsigned int i = 0; i < trkAlgos_.size(); i++ ) {
01031        
01032           if( track->algo() == trkAlgos_.at(i) ) isGoodAlgo = true;
01033      }
01034 
01035      if( !isGoodAlgo ) return false;
01036 
01037      return true;
01038 }