CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/Validation/RecoJets/plugins/CaloJetTester.cc

Go to the documentation of this file.
00001 // Producer for validation histograms for CaloJet objects
00002 // F. Ratnikov, Sept. 7, 2006
00003 // Modified by J F Novak July 10, 2008
00004 // $Id: CaloJetTester.cc,v 1.44 2013/04/10 12:05:57 eron Exp $
00005 
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "DataFormats/Common/interface/Handle.h"
00009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00010 #include "FWCore/ServiceRegistry/interface/Service.h"
00011 
00012 #include "DataFormats/Math/interface/deltaR.h"
00013 
00014 #include "DQMServices/Core/interface/DQMStore.h"
00015 #include "DQMServices/Core/interface/MonitorElement.h"
00016 
00017 #include "DataFormats/JetReco/interface/CaloJet.h"
00018 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00019 #include "DataFormats/JetReco/interface/GenJet.h"
00020 #include "DataFormats/JetReco/interface/GenJetCollection.h"
00021 
00022 //I don't know which of these I actually need yet
00023 #include "DataFormats/METReco/interface/CaloMET.h"
00024 #include "DataFormats/METReco/interface/CaloMETCollection.h"
00025 #include "DataFormats/METReco/interface/GenMET.h"
00026 #include "DataFormats/METReco/interface/GenMETCollection.h"
00027 #include "DataFormats/METReco/interface/MET.h"
00028 #include "DataFormats/METReco/interface/METCollection.h"
00029 
00030 #include "RecoJets/JetProducers/interface/JetMatchingTools.h"
00031 
00032 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00033 
00034 #include "CaloJetTester.h"
00035 
00036 #include <cmath>
00037 
00038 #include "JetMETCorrections/Objects/interface/JetCorrector.h"
00039 
00040 
00041 using namespace edm;
00042 using namespace reco;
00043 using namespace std;
00044 
00045 namespace {
00046   bool is_B (const reco::Jet& fJet) {return fabs (fJet.eta()) < 1.3;}
00047   bool is_E (const reco::Jet& fJet) {return fabs (fJet.eta()) >= 1.3 && fabs (fJet.eta()) < 3.;}
00048   bool is_F (const reco::Jet& fJet) {return fabs (fJet.eta()) >= 3.;}
00049 }
00050 
00051 
00052 
00053 CaloJetTester::CaloJetTester(const edm::ParameterSet& iConfig)
00054   : mInputCollection (iConfig.getParameter<edm::InputTag>( "src" )),
00055     mInputGenCollection (iConfig.getParameter<edm::InputTag>( "srcGen" )),
00056     mOutputFile (iConfig.getUntrackedParameter<std::string>("outputFile", "")),
00057     mMatchGenPtThreshold (iConfig.getParameter<double>("genPtThreshold")),
00058     mGenEnergyFractionThreshold (iConfig.getParameter<double>("genEnergyFractionThreshold")),
00059     mReverseEnergyFractionThreshold (iConfig.getParameter<double>("reverseEnergyFractionThreshold")),
00060     mRThreshold (iConfig.getParameter<double>("RThreshold")),
00061     //    JetCorrectionService  (iConfig.getParameter<std::string>  ("JetCorrectionService"  )),
00062     mTurnOnEverything (iConfig.getUntrackedParameter<std::string>("TurnOnEverything","")){
00063 
00064 
00065   // Protection against missing corrections
00066   doJetCorrection=false;
00067   if (iConfig.tbl().find("JetCorrectionService")!=iConfig.tbl().end()){
00068     doJetCorrection=true;
00069     JetCorrectionService =iConfig.getParameter<std::string>("JetCorrectionService");
00070   } 
00071   numberofevents
00072     = mEta = mEtaFineBin = mPhi = mPhiFineBin = mE = mE_80 
00073     = mP = mP_80  = mPt = mPt_80 
00074     = mMass = mMass_80  = mConstituents = mConstituents_80
00075     = mEtaFirst = mPhiFirst  = mPtFirst = mPtFirst_80 = mPtFirst_3000
00076     = mMjj = mMjj_3000 = mDelEta = mDelPhi = mDelPt 
00077     = mMaxEInEmTowers = mMaxEInHadTowers 
00078     = mHadEnergyInHO = mHadEnergyInHB = mHadEnergyInHF = mHadEnergyInHE 
00079     = mHadEnergyInHO_80 = mHadEnergyInHB_80 = mHadEnergyInHE_80 
00080     = mHadEnergyInHO_3000 
00081     = mEmEnergyInEB = mEmEnergyInEE = mEmEnergyInHF 
00082     = mEmEnergyInEB_80 = mEmEnergyInEE_80
00083     = mEnergyFractionHadronic_B = mEnergyFractionHadronic_E = mEnergyFractionHadronic_F
00084     = mEnergyFractionEm_B = mEnergyFractionEm_E = mEnergyFractionEm_F
00085     = mHFLong = mHFTotal = mHFLong_80  = mHFShort = mHFShort_80 
00086     = mN90
00087    
00088     = mHadTiming = mEmTiming 
00089     = mNJetsEtaC = mNJetsEtaF = mNJets1 = mNJets2
00090     = mNJetsEtaF_30
00091     = mDeltaEta = mDeltaPhi
00092     = mEScale_pt10 = mEScaleFineBin
00093      
00094     = mpTScaleB_d = mpTScaleE_d = mpTScaleF_d
00095     = mpTScalePhiB_d = mpTScalePhiE_d = mpTScalePhiF_d
00096 
00097     = mpTScale_30_200_d = mpTScale_200_600_d = mpTScale_600_1500_d = mpTScale_1500_3500_d
00098       
00099     = mpTScale1DB_30_200    = mpTScale1DE_30_200    = mpTScale1DF_30_200 
00100     = mpTScale1DB_200_600   = mpTScale1DE_200_600   = mpTScale1DF_200_600 
00101     = mpTScale1DB_600_1500   = mpTScale1DE_600_1500   = mpTScale1DF_600_1500 
00102     = mpTScale1DB_1500_3500 = mpTScale1DE_1500_3500 = mpTScale1DF_1500_3500
00103       
00104     = mPthat_80 = mPthat_3000
00105       
00106     //Corr Jet
00107     = mCorrJetPt =mCorrJetPt_80 =mCorrJetEta =mCorrJetPhi =mpTRatio =mpTResponse 
00108     = mpTRatioB_d = mpTRatioE_d = mpTRatioF_d
00109     = mpTRatio_30_200_d = mpTRatio_200_600_d = mpTRatio_600_1500_d = mpTRatio_1500_3500_d
00110     = mpTResponseB_d = mpTResponseE_d = mpTResponseF_d
00111     = mpTResponse_30_200_d = mpTResponse_200_600_d = mpTResponse_600_1500_d = mpTResponse_1500_3500_d
00112     = mpTResponse_30_d =mjetArea
00113      
00114     = nvtx_0_30 = nvtx_0_60 = mpTResponse_nvtx_0_5 = mpTResponse_nvtx_5_10 =mpTResponse_nvtx_10_15 = mpTResponse_nvtx_15_20 = mpTResponse_nvtx_20_30 = mpTResponse_nvtx_30_inf  
00115     = mpTScale_a_nvtx_0_5 = mpTScale_b_nvtx_0_5 = mpTScale_c_nvtx_0_5 
00116     = mpTScale_a_nvtx_5_10 = mpTScale_b_nvtx_5_10 = mpTScale_c_nvtx_5_10
00117     = mpTScale_a_nvtx_10_15 = mpTScale_b_nvtx_10_15 = mpTScale_c_nvtx_10_15
00118     = mpTScale_a_nvtx_15_20 = mpTScale_b_nvtx_15_20 = mpTScale_c_nvtx_15_20
00119     = mpTScale_a_nvtx_20_30 = mpTScale_b_nvtx_20_30 = mpTScale_c_nvtx_20_30
00120     = mpTScale_a_nvtx_30_inf = mpTScale_b_nvtx_30_inf = mpTScale_c_nvtx_30_inf
00121     = mpTScale_nvtx_0_5 
00122     = mpTScale_nvtx_5_10 = mpTScale_nvtx_10_15 = mpTScale_nvtx_15_20 = mpTScale_nvtx_20_30 
00123     = mpTScale_nvtx_30_inf
00124     = mpTScale_a = mpTScale_b = mpTScale_c = mpTScale_pT
00125     =0;
00126     
00127 
00128 
00129   DQMStore* dbe = &*edm::Service<DQMStore>();
00130   if (dbe) {
00131     dbe->setCurrentFolder("JetMET/RecoJetsV/CaloJetTask_" + mInputCollection.label());
00132     //
00133     numberofevents    = dbe->book1D("numberofevents","numberofevents", 3, 0 , 2);
00134     //
00135     mEta              = dbe->book1D("Eta", "Eta", 120, -6, 6); 
00136     mEtaFineBin       = dbe->book1D("EtaFineBin_Pt10", "EtaFineBin_Pt10", 600, -6, 6);
00137 
00138     //
00139     mPhi              = dbe->book1D("Phi", "Phi", 70, -3.5, 3.5); 
00140     mPhiFineBin       = dbe->book1D("PhiFineBin_Pt10", "PhiFineBin_Pt10", 350, -3.5, 3.5); 
00141     //
00142     mE                = dbe->book1D("E", "E", 100, 0, 500); 
00143     mE_80             = dbe->book1D("E_80", "E_80", 100, 0, 5000);  
00144     //
00145     mP                = dbe->book1D("P", "P", 100, 0, 500); 
00146     mP_80             = dbe->book1D("P_80", "P_80", 100, 0, 5000);  
00147     //
00148     mPt               = dbe->book1D("Pt", "Pt", 100, 0, 150); 
00149     mPt_80            = dbe->book1D("Pt_80", "Pt_80", 100, 0, 4000); 
00150     //
00151     mMass             = dbe->book1D("Mass", "Mass", 100, 0, 200); 
00152     mMass_80          = dbe->book1D("Mass_80", "Mass_80", 100, 0, 500);  
00153     //
00154     mConstituents     = dbe->book1D("Constituents", "# of Constituents", 100, 0, 100); 
00155     mConstituents_80  = dbe->book1D("Constituents_80", "# of Constituents_80", 40, 0, 40); 
00156     //
00157     mEtaFirst         = dbe->book1D("EtaFirst", "EtaFirst", 120, -6, 6); 
00158     mPhiFirst         = dbe->book1D("PhiFirst", "PhiFirst", 70, -3.5, 3.5);      
00159     mPtFirst          = dbe->book1D("PtFirst", "PtFirst", 100, 0, 50); 
00160     mPtFirst_80       = dbe->book1D("PtFirst_80", "PtFirst_80", 100, 0, 140);
00161     mPtFirst_3000     = dbe->book1D("PtFirst_3000", "PtFirst_3000", 100, 0, 4000);
00162     //
00163     mMjj              = dbe->book1D("Mjj", "Mjj", 100, 0, 2000); 
00164     mMjj_3000         = dbe->book1D("Mjj_3000", "Mjj_3000", 100, 0, 10000); 
00165     mDelEta           = dbe->book1D("DelEta", "DelEta", 100, -.5, .5); 
00166     mDelPhi           = dbe->book1D("DelPhi", "DelPhi", 100, -.5, .5); 
00167     mDelPt            = dbe->book1D("DelPt", "DelPt", 100, -1, 1); 
00168     //
00169     mMaxEInEmTowers   = dbe->book1D("MaxEInEmTowers", "MaxEInEmTowers", 100, 0, 100); 
00170     mMaxEInHadTowers  = dbe->book1D("MaxEInHadTowers", "MaxEInHadTowers", 100, 0, 100); 
00171     mHadEnergyInHO    = dbe->book1D("HadEnergyInHO", "HadEnergyInHO", 100, 0, 10); 
00172     mHadEnergyInHB    = dbe->book1D("HadEnergyInHB", "HadEnergyInHB", 100, 0, 150); 
00173     mHadEnergyInHF    = dbe->book1D("HadEnergyInHF", "HadEnergyInHF", 100, 0, 50); 
00174     mHadEnergyInHE    = dbe->book1D("HadEnergyInHE", "HadEnergyInHE", 100, 0, 150); 
00175     //
00176     mHadEnergyInHO_80    = dbe->book1D("HadEnergyInHO_80", "HadEnergyInHO_80", 100, 0, 50); 
00177     mHadEnergyInHB_80    = dbe->book1D("HadEnergyInHB_80", "HadEnergyInHB_80", 100, 0, 3000); 
00178     mHadEnergyInHE_80    = dbe->book1D("HadEnergyInHE_80", "HadEnergyInHE_80", 100, 0, 3000); 
00179     mHadEnergyInHO_3000  = dbe->book1D("HadEnergyInHO_3000", "HadEnergyInHO_3000", 100, 0, 500); 
00180     //
00181     mEmEnergyInEB     = dbe->book1D("EmEnergyInEB", "EmEnergyInEB", 100, 0, 50); 
00182     mEmEnergyInEE     = dbe->book1D("EmEnergyInEE", "EmEnergyInEE", 100, 0, 50); 
00183     mEmEnergyInHF     = dbe->book1D("EmEnergyInHF", "EmEnergyInHF", 120, -20, 100); 
00184     mEmEnergyInEB_80  = dbe->book1D("EmEnergyInEB_80", "EmEnergyInEB_80", 100, 0, 200); 
00185     mEmEnergyInEE_80  = dbe->book1D("EmEnergyInEE_80", "EmEnergyInEE_80", 100, 0, 1000); 
00186     mEnergyFractionHadronic_B = dbe->book1D("EnergyFractionHadronic_B", "EnergyFractionHadronic_B", 120, -0.1, 1.1);
00187     mEnergyFractionHadronic_E = dbe->book1D("EnergyFractionHadronic_E", "EnergyFractionHadronic_E", 120, -0.1, 1.1);
00188     mEnergyFractionHadronic_F = dbe->book1D("EnergyFractionHadronic_F", "EnergyFractionHadronic_F", 120, -0.1, 1.1); 
00189     mEnergyFractionEm_B = dbe->book1D("EnergyFractionEm_B", "EnergyFractionEm_B", 120, -0.1, 1.1); 
00190     mEnergyFractionEm_E = dbe->book1D("EnergyFractionEm_E", "EnergyFractionEm_E", 120, -0.1, 1.1);
00191     mEnergyFractionEm_F = dbe->book1D("EnergyFractionEm_F", "EnergyFractionEm_F", 120, -0.1, 1.1);
00192     //
00193     mHFTotal          = dbe->book1D("HFTotal", "HFTotal", 100, 0, 150);
00194     mHFTotal_80       = dbe->book1D("HFTotal_80", "HFTotal_80", 100, 0, 3000);
00195 
00196     mHFLong           = dbe->book1D("HFLong", "HFLong", 100, 0, 150);
00197     mHFLong_80        = dbe->book1D("HFLong_80", "HFLong_80", 100, 0, 3000);
00198 
00199     mHFShort          = dbe->book1D("HFShort", "HFShort", 100, 0, 150);
00200     mHFShort_80       = dbe->book1D("HFShort_80", "HFShort_80", 100, 0, 3000);
00201 
00202     //
00203     mN90              = dbe->book1D("N90", "N90", 50, 0, 50); 
00204     //
00205     mGenEta           = dbe->book1D("GenEta", "GenEta", 120, -6, 6);
00206     mGenPhi           = dbe->book1D("GenPhi", "GenPhi", 70, -3.5, 3.5);
00207     mGenPt            = dbe->book1D("GenPt", "GenPt", 100, 0, 150);
00208     mGenPt_80         = dbe->book1D("GenPt_80", "GenPt_80", 100, 0, 1500);
00209     //
00210     mGenEtaFirst      = dbe->book1D("GenEtaFirst", "GenEtaFirst", 100, -5, 5);
00211     mGenPhiFirst      = dbe->book1D("GenPhiFirst", "GenPhiFirst", 70, -3.5, 3.5);
00212     //
00213  
00214  
00215     //
00216     mHadTiming        = dbe->book1D("HadTiming", "HadTiming", 75, -50, 100);
00217     mEmTiming         = dbe->book1D("EMTiming", "EMTiming", 75, -50, 100);
00218     //
00219     mNJetsEtaC        = dbe->book1D("NJetsEtaC_Pt10", "NJetsEtaC_Pt10", 15, 0, 15);
00220     mNJetsEtaF        = dbe->book1D("NJetsEtaF_Pt10", "NJetsEtaF_Pt10", 15, 0, 15);
00221     mNJetsEtaF_30        = dbe->book1D("NJetsEtaF_Pt30", "NJetsEtaF_Pt30", 15, 0, 15);
00222 
00223     //
00224     mNJets1           = dbe->bookProfile("NJets1", "NJets1", 100, 0, 200,  100, 0, 50, "s");
00225     mNJets2           = dbe->bookProfile("NJets2", "NJets2", 100, 0, 4000, 100, 0, 50, "s");
00226     //
00227 
00228     //
00229     mPthat_80            = dbe->book1D("Pthat_80", "Pthat_80", 100, 0.0, 1000.0); 
00230     mPthat_3000          = dbe->book1D("Pthat_3000", "Pthat_3000", 100, 1000.0, 4000.0); 
00231 
00232     //Corr
00233     mCorrJetPt  = dbe->book1D("CorrPt", "CorrPt", 100, 0, 150);
00234     mCorrJetPt_80 = dbe->book1D("CorrPt_80", "CorrPt_80", 100, 0, 4000); 
00235  
00236     mCorrJetEta = dbe->book1D("CorrEta", "CorrEta", 120, -6, 6);
00237     mCorrJetPhi = dbe->book1D("CorrPhi", "CorrPhi", 70, -3.5, 3.5);
00238     mjetArea = dbe->book1D("jetArea","jetArea",26,-0.5,12.5);
00239 
00240     //nvtx
00241     nvtx_0_30 = dbe->book1D("nvtx_0_30","nvtx_0_30",31,-0.5,30.5);
00242     nvtx_0_60 = dbe->book1D("nvtx_0_60","nvtx_0_60",61,-0.5,60.5);
00243 
00244     //pT scale with nvtx
00245     mpTScale_a_nvtx_0_5 = dbe->book1D("mpTScale_a_nvtx_0_5", "pTScale_a_nvtx_0_5_0<|eta|<1.3_60_120",100, 0, 2);
00246     mpTScale_b_nvtx_0_5 = dbe->book1D("mpTScale_b_nvtx_0_5", "pTScale_b_nvtx_0_5_0<|eta|<1.3_200_300",100, 0, 2);
00247     mpTScale_c_nvtx_0_5 = dbe->book1D("mpTScale_c_nvtx_0_5", "pTScale_c_nvtx_0_5_0<|eta|<1.3_600_900",100, 0, 2);
00248     mpTScale_a_nvtx_5_10 = dbe->book1D("mpTScale_a_nvtx_5_10", "pTScale_a_nvtx_5_10_0<|eta|<1.3_60_120",100, 0, 2);
00249     mpTScale_b_nvtx_5_10 = dbe->book1D("mpTScale_b_nvtx_5_10", "pTScale_b_nvtx_5_10_0<|eta|<1.3_200_300",100, 0, 2);
00250     mpTScale_c_nvtx_5_10 = dbe->book1D("mpTScale_c_nvtx_5_10", "pTScale_c_nvtx_5_10_0<|eta|<1.3_600_900",100, 0, 2);
00251     mpTScale_a_nvtx_10_15 = dbe->book1D("mpTScale_a_nvtx_10_15", "pTScale_a_nvtx_10_15_0<|eta|<1.3_60_120",100, 0, 2);
00252     mpTScale_b_nvtx_10_15 = dbe->book1D("mpTScale_b_nvtx_10_15", "pTScale_b_nvtx_10_15_0<|eta|<1.3_200_300",100, 0, 2);
00253     mpTScale_c_nvtx_10_15 = dbe->book1D("mpTScale_c_nvtx_10_15", "pTScale_c_nvtx_10_15_0<|eta|<1.3_600_900",100, 0, 2);
00254     mpTScale_a_nvtx_15_20 = dbe->book1D("mpTScale_a_nvtx_15_20", "pTScale_a_nvtx_15_20_0<|eta|<1.3_60_120",100, 0, 2);
00255     mpTScale_b_nvtx_15_20 = dbe->book1D("mpTScale_b_nvtx_15_20", "pTScale_b_nvtx_15_20_0<|eta|<1.3_200_300",100, 0, 2);
00256     mpTScale_c_nvtx_15_20 = dbe->book1D("mpTScale_c_nvtx_15_20", "pTScale_c_nvtx_15_20_0<|eta|<1.3_600_900",100, 0, 2);
00257     mpTScale_a_nvtx_20_30 = dbe->book1D("mpTScale_a_nvtx_20_30", "pTScale_a_nvtx_20_30_0<|eta|<1.3_60_120",100, 0, 2);
00258     mpTScale_b_nvtx_20_30 = dbe->book1D("mpTScale_b_nvtx_20_30", "pTScale_b_nvtx_20_30_0<|eta|<1.3_200_300",100, 0, 2);
00259     mpTScale_c_nvtx_20_30 = dbe->book1D("mpTScale_c_nvtx_20_30", "pTScale_c_nvtx_20_30_0<|eta|<1.3_600_900",100, 0, 2);
00260     mpTScale_a_nvtx_30_inf = dbe->book1D("mpTScale_a_nvtx_30_inf", "pTScale_a_nvtx_30_inf_0<|eta|<1.3_60_120",100, 0, 2);
00261     mpTScale_b_nvtx_30_inf = dbe->book1D("mpTScale_b_nvtx_30_inf", "pTScale_b_nvtx_30_inf_0<|eta|<1.3_200_300",100, 0, 2);
00262     mpTScale_c_nvtx_30_inf = dbe->book1D("mpTScale_c_nvtx_30_inf", "pTScale_c_nvtx_30_inf_0<|eta|<1.3_600_900",100, 0, 2);
00263     mpTScale_a = dbe->book1D("pTScale_a", "pTScale_a_60_120",100, 0, 2);
00264     mpTScale_b = dbe->book1D("pTScale_b", "pTScale_b_200_300",100, 0, 2);
00265     mpTScale_c = dbe->book1D("pTScale_c", "pTScale_c_600_900",100, 0, 2);
00266 
00267 
00268     //
00269     double log10PtMin = 0.5; //=3.1622766
00270     double log10PtMax = 3.75; //=5623.41325
00271     int log10PtBins = 26; 
00272     double etaRange[91] = {-6.0,-5.8,-5.6,-5.4,-5.2,-5.0,-4.8,-4.6,-4.4,-4.2,-4.0,-3.8,-3.6,-3.4,-3.2,-3.0,-2.9,-2.8,-2.7,-2.6,-2.5,-2.4,-2.3,-2.2,-2.1,-2.0,-1.9,-1.8,-1.7,-1.6,-1.5,-1.4,-1.3,-1.2,-1.1,-1.0,-0.9,-0.8,-0.7,-0.6,-0.5,-0.4,-0.3,-0.2,-0.1,0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3.0,3.2,3.4,3.6,3.8,4.0,4.2,4.4,4.6,4.8,5.0,5.2,5.4,5.6,5.8,6.0};
00273 
00274     //int log10PtFineBins = 50;
00275 
00276     //
00277     if (mTurnOnEverything.compare("yes")==0) {
00278 
00279     }
00280 
00281     mpTScaleB_d = dbe->bookProfile("pTScaleB_d", "pTScale_d_0<|eta|<1.5",
00282                                    log10PtBins, log10PtMin, log10PtMax, 0, 2, " ");
00283     mpTScaleE_d = dbe->bookProfile("pTScaleE_d", "pTScale_d_1.5<|eta|<3.0",
00284                                    log10PtBins, log10PtMin, log10PtMax, 0, 2, " ");
00285     mpTScaleF_d = dbe->bookProfile("pTScaleF_d", "pTScale_d_3.0<|eta|<6.0",
00286                                    log10PtBins, log10PtMin, log10PtMax, 0, 2, " ");
00287     
00288     mpTScalePhiB_d = dbe->bookProfile("pTScalePhiB_d", "pTScalePhi_d_0<|eta|<1.5",
00289                                       70, -3.5, 3.5, 0, 2, " ");
00290     mpTScalePhiE_d = dbe->bookProfile("pTScalePhiE_d", "pTScalePhi_d_1.5<|eta|<3.0",
00291                                       70, -3.5, 3.5, 0, 2, " ");
00292     mpTScalePhiF_d = dbe->bookProfile("pTScalePhiF_d", "pTScalePhi_d_3.0<|eta|<6.0",
00293                                       70, -3.5, 3.5, 0, 2, " ");
00294 
00295 
00296     mpTScale_30_200_d    = dbe->bookProfile("pTScale_30_200_d", "pTScale_d_30<pT<200",
00297                                             90,etaRange, 0., 2., " ");
00298     mpTScale_200_600_d   = dbe->bookProfile("pTScale_200_600_d", "pTScale_d_200<pT<600",
00299                                             90,etaRange, 0., 2., " ");
00300     mpTScale_600_1500_d   = dbe->bookProfile("pTScale_600_1500_d", "pTScale_d_600<pT<1500",
00301                                              90,etaRange, 0., 2., " ");
00302     mpTScale_1500_3500_d = dbe->bookProfile("pTScale_1500_3500_d", "pTScale_d_1500<pt<3500",
00303                                             90,etaRange, 0., 2., " ");
00304     
00305     mpTScale1DB_30_200 = dbe->book1D("pTScale1DB_30_200", "pTScale_distribution_for_0<|eta|<1.5_30_200",
00306                                      100, 0, 2);
00307     mpTScale1DE_30_200 = dbe->book1D("pTScale1DE_30_200", "pTScale_distribution_for_1.5<|eta|<3.0_30_200",
00308                                      50, 0, 2);
00309     mpTScale1DF_30_200 = dbe->book1D("pTScale1DF_30_200", "pTScale_distribution_for_3.0<|eta|<6.0_30_200",
00310                                      50, 0, 2);
00311 
00312     mpTScale1DB_200_600 = dbe->book1D("pTScale1DB_200_600", "pTScale_distribution_for_0<|eta|<1.5_200_600",
00313                                       100, 0, 2);
00314     mpTScale1DE_200_600 = dbe->book1D("pTScale1DE_200_600", "pTScale_distribution_for_1.5<|eta|<3.0_200_600",
00315                                       50, 0, 2);
00316     mpTScale1DF_200_600 = dbe->book1D("pTScale1DF_200_600", "pTScale_distribution_for_3.0<|eta|<6.0_200_600",
00317                                       50, 0, 2);
00318 
00319     mpTScale1DB_600_1500 = dbe->book1D("pTScale1DB_600_1500", "pTScale_distribution_for_0<|eta|<1.5_600_1500",
00320                                        100, 0, 2);
00321     mpTScale1DE_600_1500 = dbe->book1D("pTScale1DE_600_1500", "pTScale_distribution_for_1.5<|eta|<3.0_600_1500",
00322                                        50, 0, 2);
00323     mpTScale1DF_600_1500 = dbe->book1D("pTScale1DF_600_1500", "pTScale_distribution_for_3.0<|eta|<6.0_600_1500",
00324                                        50, 0, 2);
00325 
00326     mpTScale1DB_1500_3500 = dbe->book1D("pTScale1DB_1500_3500", "pTScale_distribution_for_0<|eta|<1.5_1500_3500",
00327                                         100, 0, 2);
00328     mpTScale1DE_1500_3500 = dbe->book1D("pTScale1DE_1500_3500", "pTScale_distribution_for_1.5<|eta|<3.0_1500_3500",
00329                                         50, 0, 2);
00330     mpTScale1DF_1500_3500 = dbe->book1D("pTScale1DF_1500_3500", "pTScale_distribution_for_3.0<|eta|<6.0_1500_3500",
00331                                         50, 0, 2);
00332 
00333 
00334     mpTScale_nvtx_0_5  = dbe->bookProfile("pTScale_nvtx_0_5", "pTScale_nvtx_0_5_0<|eta|<1.3",
00335                                           log10PtBins, log10PtMin, log10PtMax, 0, 2, " ");
00336     mpTScale_nvtx_5_10  = dbe->bookProfile("pTScale_nvtx_5_10", "pTScale_nvtx_5_10_0<|eta|<1.3",
00337                                            log10PtBins, log10PtMin, log10PtMax, 0, 2, " ");
00338     mpTScale_nvtx_10_15  = dbe->bookProfile("pTScale_nvtx_10_15", "pTScale_nvtx_10_15_0<|eta|<1.3",
00339                                             log10PtBins, log10PtMin, log10PtMax, 0, 2, " ");
00340     mpTScale_nvtx_15_20  = dbe->bookProfile("pTScale_nvtx_15_20", "pTScale_nvtx_15_20_0<|eta|<1.3",
00341                                             log10PtBins, log10PtMin, log10PtMax, 0, 2, " ");
00342     mpTScale_nvtx_20_30  = dbe->bookProfile("pTScale_nvtx_20_30", "pTScale_nvtx_20_30_0<|eta|<1.3",
00343                                             log10PtBins, log10PtMin, log10PtMax, 0, 2, " ");
00344     mpTScale_nvtx_30_inf  = dbe->bookProfile("pTScale_nvtx_30_inf", "pTScale_nvtx_30_inf_0<|eta|<1.3",
00345                                              log10PtBins, log10PtMin, log10PtMax, 0, 2, " ");
00346     mpTScale_pT = dbe->bookProfile("pTScale_pT", "pTScale_vs_pT",
00347                                    log10PtBins, log10PtMin, log10PtMax, 0, 2, " ");
00349     mpTRatio = dbe->bookProfile("pTRatio", "pTRatio",
00350                                 log10PtBins, log10PtMin, log10PtMax, 100, 0.,5., " ");
00351     mpTRatioB_d = dbe->bookProfile("pTRatioB_d", "pTRatio_d_0<|eta|<1.5",
00352                                    log10PtBins, log10PtMin, log10PtMax, 0, 5, " ");
00353     mpTRatioE_d = dbe->bookProfile("pTRatioE_d", "pTRatio_d_1.5<|eta|<3.0",
00354                                    log10PtBins, log10PtMin, log10PtMax, 0, 5, " ");
00355     mpTRatioF_d = dbe->bookProfile("pTRatioF_d", "pTRatio_d_3.0<|eta|<6.0",
00356                                    log10PtBins, log10PtMin, log10PtMax, 0, 5, " ");
00357     mpTRatio_30_200_d    = dbe->bookProfile("pTRatio_30_200_d", "pTRatio_d_30<pT<200",
00358                                             90,etaRange, 0., 5., " ");
00359     mpTRatio_200_600_d   = dbe->bookProfile("pTRatio_200_600_d", "pTRatio_d_200<pT<600",
00360                                             90,etaRange, 0., 5., " ");
00361     mpTRatio_600_1500_d   = dbe->bookProfile("pTRatio_600_1500_d", "pTRatio_d_600<pT<1500",
00362                                              90,etaRange, 0., 5., " ");
00363     mpTRatio_1500_3500_d = dbe->bookProfile("pTRatio_1500_3500_d", "pTRatio_d_1500<pt<3500",
00364                                             90,etaRange, 0., 5., " "); 
00365     mpTResponse = dbe->bookProfile("pTResponse", "pTResponse",
00366                                    log10PtBins, log10PtMin, log10PtMax, 100, 0.8,1.2, " ");
00367     mpTResponseB_d = dbe->bookProfile("pTResponseB_d", "pTResponse_d_0<|eta|<1.5",
00368                                       log10PtBins, log10PtMin, log10PtMax, 0.8, 1.2, " ");
00369     mpTResponseE_d = dbe->bookProfile("pTResponseE_d", "pTResponse_d_1.5<|eta|<3.0",
00370                                       log10PtBins, log10PtMin, log10PtMax, 0.8, 1.2, " ");
00371     mpTResponseF_d = dbe->bookProfile("pTResponseF_d", "pTResponse_d_3.0<|eta|<6.0",
00372                                       log10PtBins, log10PtMin, log10PtMax, 0.8, 1.2, " ");
00373     mpTResponse_30_200_d    = dbe->bookProfile("pTResponse_30_200_d", "pTResponse_d_30<pT<200",
00374                                                90,etaRange, 0.8, 1.2, " ");
00375     mpTResponse_200_600_d   = dbe->bookProfile("pTResponse_200_600_d", "pTResponse_d_200<pT<600",
00376                                                90,etaRange, 0.8, 1.2, " ");
00377     mpTResponse_600_1500_d   = dbe->bookProfile("pTResponse_600_1500_d", "pTResponse_d_600<pT<1500",
00378                                                 90,etaRange, 0.8, 1.2, " ");
00379     mpTResponse_1500_3500_d = dbe->bookProfile("pTResponse_1500_3500_d", "pTResponse_d_1500<pt<3500",
00380                                                90,etaRange, 0.8, 1.2, " ");
00381     mpTResponse_30_d = dbe->bookProfile("pTResponse_30_d", "pTResponse_d_pt>30",
00382                                         90,etaRange, 0.8, 1.2, " ");
00383 
00384 
00385     mpTResponse_nvtx_0_5 = dbe->bookProfile("pTResponse_nvtx_0_5", "pTResponse_nvtx_0_5", log10PtBins, log10PtMin, log10PtMax, 100, 0.8,1.2, " ");
00386     mpTResponse_nvtx_5_10 = dbe->bookProfile("pTResponse_nvtx_5_10", "pTResponse_nvtx_5_10", log10PtBins, log10PtMin, log10PtMax, 100, 0.8,1.2, " ");
00387     mpTResponse_nvtx_10_15 = dbe->bookProfile("pTResponse_nvtx_10_15", "pTResponse_nvtx_10_15", log10PtBins, log10PtMin, log10PtMax, 100, 0.8,1.2, " ");
00388     mpTResponse_nvtx_15_20 = dbe->bookProfile("pTResponse_nvtx_15_20", "pTResponse_nvtx_15_20", log10PtBins, log10PtMin, log10PtMax, 100, 0.8,1.2, " ");
00389     mpTResponse_nvtx_20_30 = dbe->bookProfile("pTResponse_nvtx_20_30", "pTResponse_nvtx_20_30", log10PtBins, log10PtMin, log10PtMax, 100, 0.8,1.2, " ");
00390     mpTResponse_nvtx_30_inf = dbe->bookProfile("pTResponse_nvtx_30_inf", "pTResponse_nvtx_30_inf", log10PtBins, log10PtMin, log10PtMax, 100, 0.8,1.2, " ");
00391   }
00392 
00393   if (mOutputFile.empty ()) {
00394     LogInfo("OutputInfo") << " CaloJet histograms will NOT be saved";
00395   } 
00396   else {
00397     LogInfo("OutputInfo") << " CaloJethistograms will be saved to file:" << mOutputFile;
00398   }
00399 }
00400    
00401 CaloJetTester::~CaloJetTester()
00402 {
00403 }
00404 
00405 void CaloJetTester::beginJob(){
00406 }
00407 
00408 void CaloJetTester::endJob() {
00409   if (!mOutputFile.empty() && &*edm::Service<DQMStore>()) edm::Service<DQMStore>()->save (mOutputFile);
00410 }
00411 
00412 
00413 void CaloJetTester::analyze(const edm::Event& mEvent, const edm::EventSetup& mSetup)
00414 {
00415   double countsfornumberofevents = 1;
00416   numberofevents->Fill(countsfornumberofevents);
00417 
00418   //get primary vertices
00419   edm::Handle<vector<reco::Vertex> >pvHandle;
00420 
00421   //E.Ron elias.ron@cern.ch at 10-4-13
00422   //the vertices are only taken if they exist in the event
00423   bool offlinePrimaryVerticesPresent=mEvent.getByLabel( "offlinePrimaryVertices",pvHandle);
00424 
00425 
00426   //  try {
00427   //    mEvent.getByLabel( "offlinePrimaryVertices", pvHandle );
00428   //  } catch ( cms::Exception& e) {
00429     //    cout <<"error: " << e.what() << endl;
00430   //  } 
00431   vector<reco::Vertex> goodVertices;
00432 
00433   if(offlinePrimaryVerticesPresent){
00434     for (unsigned i = 0; i < pvHandle->size(); i++) {
00435       if ( (*pvHandle)[i].ndof() > 4 &&
00436            ( fabs((*pvHandle)[i].z()) <= 24. ) &&
00437            ( fabs((*pvHandle)[i].position().rho()) <= 2.0 ) )
00438         goodVertices.push_back((*pvHandle)[i]);
00439     }
00440   }
00441   nvtx_0_30->Fill(goodVertices.size());
00442   nvtx_0_60->Fill(goodVertices.size());
00443 
00444   // *********************************
00445   // *** Get pThat
00446   // *********************************
00447   if (!mEvent.isRealData()){
00448     edm::Handle<HepMCProduct> evt;
00449     mEvent.getByLabel("generator", evt);
00450     if (evt.isValid()) {
00451       HepMC::GenEvent * myGenEvent = new HepMC::GenEvent(*(evt->GetEvent()));
00452   
00453       double pthat = myGenEvent->event_scale();
00454 
00455       mPthat_80->Fill(pthat);
00456       mPthat_3000->Fill(pthat);
00457 
00458       delete myGenEvent; 
00459     }
00460   }
00461   // ***********************************
00462   // *** Get CaloMET
00463   // ***********************************
00464   /*
00465     const CaloMET *calomet;
00466     edm::Handle<CaloMETCollection> calo;
00467     mEvent.getByLabel("met", calo);
00468     if (!calo.isValid()) {
00469     edm::LogInfo("OutputInfo") << " failed to retrieve data required by MET Task";
00470     edm::LogInfo("OutputInfo") << " MET Task cannot continue...!";
00471     } else {
00472     const CaloMETCollection *calometcol = calo.product();
00473     calomet = &(calometcol->front());
00474     
00475     }
00476   */
00477   // ***********************************
00478   // *** Get the CaloTower collection
00479   // ***********************************
00480   Handle<CaloTowerCollection> caloTowers;
00481   mEvent.getByLabel( "towerMaker", caloTowers );
00482   if (caloTowers.isValid()) {
00483     for( CaloTowerCollection::const_iterator cal = caloTowers->begin(); cal != caloTowers->end(); ++ cal ){
00484 
00485       //To compensate for the index
00486       if (mTurnOnEverything.compare("yes")==0) {
00487       }
00488       
00489       mHadTiming->Fill (cal->hcalTime());
00490       mEmTiming->Fill (cal->ecalTime());    
00491     }
00492   }
00493   
00494   // ***********************************
00495   // *** Get the RecHits collection
00496   // ***********************************
00497   try {
00498     std::vector<edm::Handle<HBHERecHitCollection> > colls;
00499     mEvent.getManyByType(colls);
00500     std::vector<edm::Handle<HBHERecHitCollection> >::iterator i;
00501     for (i=colls.begin(); i!=colls.end(); i++) {
00502       for (HBHERecHitCollection::const_iterator j=(*i)->begin(); j!=(*i)->end(); j++) {
00503         //      std::cout << *j << std::endl;
00504       }
00505     }
00506   } catch (...) {
00507     edm::LogInfo("OutputInfo") << " No HB/HE RecHits.";
00508   }
00509 
00510   try {
00511     std::vector<edm::Handle<HFRecHitCollection> > colls;
00512     mEvent.getManyByType(colls);
00513     std::vector<edm::Handle<HFRecHitCollection> >::iterator i;
00514     for (i=colls.begin(); i!=colls.end(); i++) {
00515       for (HFRecHitCollection::const_iterator j=(*i)->begin(); j!=(*i)->end(); j++) {
00516         //      std::cout << *j << std::endl;
00517       }
00518     }
00519   } catch (...) {
00520     edm::LogInfo("OutputInfo") << " No HF RecHits.";
00521   }
00522 
00523   try {
00524     std::vector<edm::Handle<HORecHitCollection> > colls;
00525     mEvent.getManyByType(colls);
00526     std::vector<edm::Handle<HORecHitCollection> >::iterator i;
00527     for (i=colls.begin(); i!=colls.end(); i++) {
00528       for (HORecHitCollection::const_iterator j=(*i)->begin(); j!=(*i)->end(); j++) {
00529       }
00530     }
00531   } catch (...) {
00532     edm::LogInfo("OutputInfo") << " No HO RecHits.";
00533   }
00534   try {
00535     std::vector<edm::Handle<EBRecHitCollection> > colls;
00536     mEvent.getManyByType(colls);
00537     std::vector<edm::Handle<EBRecHitCollection> >::iterator i;
00538     for (i=colls.begin(); i!=colls.end(); i++) {
00539       for (EBRecHitCollection::const_iterator j=(*i)->begin(); j!=(*i)->end(); j++) {
00540       }
00541     }
00542   } catch (...) {
00543     edm::LogInfo("OutputInfo") << " No EB RecHits.";
00544   }
00545 
00546   try {
00547     std::vector<edm::Handle<EERecHitCollection> > colls;
00548     mEvent.getManyByType(colls);
00549     std::vector<edm::Handle<EERecHitCollection> >::iterator i;
00550     for (i=colls.begin(); i!=colls.end(); i++) {
00551       for (EERecHitCollection::const_iterator j=(*i)->begin(); j!=(*i)->end(); j++) {
00552       }
00553     }
00554   } catch (...) {
00555     edm::LogInfo("OutputInfo") << " No EE RecHits.";
00556   }
00557 
00558 
00559   //***********************************
00560   //*** Get the Jet collection
00561   //***********************************
00562   math::XYZTLorentzVector p4tmp[2];
00563   Handle<CaloJetCollection> caloJets;
00564   mEvent.getByLabel(mInputCollection, caloJets);
00565   if (!caloJets.isValid()) return;
00566   CaloJetCollection::const_iterator jet = caloJets->begin ();
00567   int jetIndex = 0;
00568   int nJet = 0;
00569   int nJetF = 0;
00570   int nJetC = 0;
00571   int nJetF_30 =0;
00572   for (; jet != caloJets->end (); jet++, jetIndex++) {
00573 
00574     if (jet->pt() > 10.) {
00575       if (fabs(jet->eta()) > 1.5) 
00576         nJetF++;
00577       else 
00578         nJetC++;          
00579     }
00580     if (jet->pt() > 30.) nJetF_30++;
00581     if (jet->pt() > 10.) {
00582       if (mEta) mEta->Fill (jet->eta());
00583       if (mEtaFineBin) mEtaFineBin->Fill (jet->eta());
00584       if (mPhiFineBin) mPhiFineBin->Fill (jet->phi());
00585     }
00586     if (mjetArea) mjetArea->Fill(jet->jetArea());
00587     if (mPhi) mPhi->Fill (jet->phi());
00588     if (mE) mE->Fill (jet->energy());
00589     if (mE_80) mE_80->Fill (jet->energy());
00590     if (mP) mP->Fill (jet->p());
00591     if (mP_80) mP_80->Fill (jet->p());
00592     if (mPt) mPt->Fill (jet->pt());
00593     if (mPt_80) mPt_80->Fill (jet->pt());
00594     if (mMass) mMass->Fill (jet->mass());
00595     if (mMass_80) mMass_80->Fill (jet->mass());
00596     if (mConstituents) mConstituents->Fill (jet->nConstituents());
00597     if (mConstituents_80) mConstituents_80->Fill (jet->nConstituents());
00598     if (jet == caloJets->begin ()) { // first jet
00599       if (mEtaFirst) mEtaFirst->Fill (jet->eta());
00600       if (mPhiFirst) mPhiFirst->Fill (jet->phi());
00601       if (mPtFirst) mPtFirst->Fill (jet->pt());
00602       if (mPtFirst_80) mPtFirst_80->Fill (jet->pt());
00603       if (mPtFirst_3000) mPtFirst_3000->Fill (jet->pt());
00604     }
00605     if (jetIndex == 0) {
00606       nJet++;
00607       p4tmp[0] = jet->p4();     
00608     }
00609     if (jetIndex == 1) {
00610       nJet++;
00611       p4tmp[1] = jet->p4();     
00612     }
00613 
00614     if (mMaxEInEmTowers) mMaxEInEmTowers->Fill (jet->maxEInEmTowers());
00615     if (mMaxEInHadTowers) mMaxEInHadTowers->Fill (jet->maxEInHadTowers());
00616     if (mHadEnergyInHO) mHadEnergyInHO->Fill (jet->hadEnergyInHO());
00617     if (mHadEnergyInHO_80)   mHadEnergyInHO_80->Fill (jet->hadEnergyInHO());
00618     if (mHadEnergyInHO_3000) mHadEnergyInHO_3000->Fill (jet->hadEnergyInHO());
00619     if (mHadEnergyInHB) mHadEnergyInHB->Fill (jet->hadEnergyInHB());
00620     if (mHadEnergyInHB_80)   mHadEnergyInHB_80->Fill (jet->hadEnergyInHB());
00621     if (mHadEnergyInHF) mHadEnergyInHF->Fill (jet->hadEnergyInHF());
00622     if (mHadEnergyInHE) mHadEnergyInHE->Fill (jet->hadEnergyInHE());
00623     if (mHadEnergyInHE_80)   mHadEnergyInHE_80->Fill (jet->hadEnergyInHE());
00624     if (mEmEnergyInEB) mEmEnergyInEB->Fill (jet->emEnergyInEB());
00625     if (mEmEnergyInEB_80)   mEmEnergyInEB_80->Fill (jet->emEnergyInEB());
00626     if (mEmEnergyInEE) mEmEnergyInEE->Fill (jet->emEnergyInEE());
00627     if (mEmEnergyInEE_80)   mEmEnergyInEE_80->Fill (jet->emEnergyInEE());
00628     if (mEmEnergyInHF) mEmEnergyInHF->Fill (jet->emEnergyInHF());
00629     if (fabs(jet->eta())<1.5) mEnergyFractionHadronic_B->Fill (jet->energyFractionHadronic());
00630     if (fabs(jet->eta())>1.5 && fabs(jet->eta())<3.0) mEnergyFractionHadronic_E->Fill (jet->energyFractionHadronic());
00631     if (fabs(jet->eta())>3.0 && fabs(jet->eta())<6.0) mEnergyFractionHadronic_F->Fill (jet->energyFractionHadronic());
00632     if (fabs(jet->eta())<1.5) mEnergyFractionEm_B->Fill (jet->emEnergyFraction());
00633     if (fabs(jet->eta())>1.5 && fabs(jet->eta())<3.0) mEnergyFractionEm_E->Fill (jet->emEnergyFraction());
00634     if (fabs(jet->eta())>3.0 && fabs(jet->eta())<6.0) mEnergyFractionEm_F->Fill (jet->emEnergyFraction());
00635     if (mHFTotal)      mHFTotal->Fill (jet->hadEnergyInHF()+jet->emEnergyInHF());
00636     if (mHFTotal_80)   mHFTotal_80->Fill (jet->hadEnergyInHF()+jet->emEnergyInHF());
00637     if (mHFLong)       mHFLong->Fill (jet->hadEnergyInHF()*0.5+jet->emEnergyInHF());
00638     if (mHFLong_80)    mHFLong_80->Fill (jet->hadEnergyInHF()*0.5+jet->emEnergyInHF());
00639     if (mHFShort)      mHFShort->Fill (jet->hadEnergyInHF()*0.5);
00640     if (mHFShort_80)   mHFShort_80->Fill (jet->hadEnergyInHF()*0.5);
00641 
00642 
00643 
00644     if (mN90) mN90->Fill (jet->n90());
00645   }
00646 
00647 
00648 
00649   if (mNJetsEtaC) mNJetsEtaC->Fill( nJetC );
00650   if (mNJetsEtaF) mNJetsEtaF->Fill( nJetF );
00651   if (mNJetsEtaF_30) mNJetsEtaF_30->Fill( nJetF_30 );
00652   if (nJet == 2) {
00653     if (mMjj) mMjj->Fill( (p4tmp[0]+p4tmp[1]).mass() );
00654     if (mMjj_3000) mMjj_3000->Fill( (p4tmp[0]+p4tmp[1]).mass() );
00655   }
00656 
00657   // Count Jets above Pt cut
00658   for (int istep = 0; istep < 100; ++istep) {
00659     int     njet = 0;
00660     float ptStep = (istep * (200./100.));
00661 
00662     for ( CaloJetCollection::const_iterator cal = caloJets->begin(); cal != caloJets->end(); ++ cal ) {
00663       if ( cal->pt() > ptStep ) njet++;
00664     }
00665     mNJets1->Fill( ptStep, njet );
00666   }
00667 
00668   for (int istep = 0; istep < 100; ++istep) {
00669     int     njet = 0;
00670     float ptStep = (istep * (4000./100.));
00671     for ( CaloJetCollection::const_iterator cal = caloJets->begin(); cal != caloJets->end(); ++ cal ) {
00672       if ( cal->pt() > ptStep ) njet++;
00673     }
00674     mNJets2->Fill( ptStep, njet );
00675   }
00676 
00677         
00678   const JetCorrector* corrector=0;
00679   if(doJetCorrection){
00680     corrector = JetCorrector::getJetCorrector (JetCorrectionService,mSetup);
00681   }
00682   for (CaloJetCollection::const_iterator jet = caloJets->begin(); jet !=caloJets ->end(); jet++){
00683     //const math::XYZTLorentzVector theJet = jet->p4();c
00684     CaloJet  correctedJet = *jet;
00685     //double scale = corrector->correction(jet->p4());
00686     double scale=1.0;
00687     if(doJetCorrection){
00688       scale = corrector->correction(*jet,mEvent,mSetup); 
00689     }
00690     correctedJet.scaleEnergy(scale); 
00691     if(correctedJet.pt()>30){
00692       mCorrJetPt->Fill(correctedJet.pt());
00693       mCorrJetPt_80->Fill(correctedJet.pt());
00694       if(correctedJet.pt() >10) mCorrJetEta->Fill(correctedJet.eta());
00695       mCorrJetPhi->Fill(correctedJet.phi());
00696       mpTRatio->Fill(log10(jet->pt()),correctedJet.pt()/jet->pt());
00697       
00698       if (fabs(jet->eta())<1.5) {
00699         mpTRatioB_d->Fill(log10(jet->pt()), correctedJet.pt()/jet->pt());
00700       } 
00701 
00702       if (fabs(jet->eta())>1.5 && fabs(jet->eta())<3.0) {
00703         mpTRatioE_d->Fill (log10(jet->pt()), correctedJet.pt()/jet->pt());   
00704       }
00705       if (fabs(jet->eta())>3.0 && fabs(jet->eta())<6.0) {
00706         mpTRatioF_d->Fill (log10(jet->pt()), correctedJet.pt()/jet->pt());
00707       }
00708       if (jet->pt()>30.0 && jet->pt()<200.0) {
00709         mpTRatio_30_200_d->Fill (jet->eta(),correctedJet.pt()/jet->pt());
00710       }
00711       if (jet->pt()>200.0 && jet->pt()<600.0) {
00712         mpTRatio_200_600_d->Fill (jet->eta(),correctedJet.pt()/jet->pt());
00713       }
00714       if (jet->pt()>600.0 && jet->pt()<1500.0) {
00715         mpTRatio_600_1500_d->Fill (jet->eta(),correctedJet.pt()/jet->pt());
00716       }
00717       if (jet->pt()>1500.0 && jet->pt()<3500.0) {
00718         mpTRatio_1500_3500_d->Fill (jet->eta(),correctedJet.pt()/jet->pt());
00719       }
00720     }
00721   }
00722 
00723   
00724 
00725   if (!mEvent.isRealData()){
00726     // Gen jet analysis
00727     Handle<GenJetCollection> genJets;
00728     mEvent.getByLabel(mInputGenCollection, genJets);
00729     if (!genJets.isValid()) return;
00730     GenJetCollection::const_iterator gjet = genJets->begin ();
00731     int gjetIndex = 0;
00732     for (; gjet != genJets->end (); gjet++, gjetIndex++) {
00733       if (mGenEta) mGenEta->Fill (gjet->eta());
00734       if (mGenPhi) mGenPhi->Fill (gjet->phi());
00735       if (mGenPt) mGenPt->Fill (gjet->pt());
00736       if (mGenPt_80) mGenPt_80->Fill (gjet->pt());
00737       if (gjet == genJets->begin ()) { // first jet
00738         if (mGenEtaFirst) mGenEtaFirst->Fill (gjet->eta());
00739         if (mGenPhiFirst) mGenPhiFirst->Fill (gjet->phi());
00740       }
00741     }
00742   
00743 
00744     // now match CaloJets to GenJets
00745     JetMatchingTools jetMatching (mEvent);
00746     if (!(mInputGenCollection.label().empty())) {
00747       //    Handle<GenJetCollection> genJets;
00748       //    mEvent.getByLabel(mInputGenCollection, genJets);
00749 
00750       std::vector <std::vector <const reco::GenParticle*> > genJetConstituents (genJets->size());
00751       std::vector <std::vector <const reco::GenParticle*> > caloJetConstituents (caloJets->size());
00752       if (mRThreshold > 0) { 
00753       }
00754       else {
00755         for (unsigned iGenJet = 0; iGenJet < genJets->size(); ++iGenJet) {
00756           genJetConstituents [iGenJet] = jetMatching.getGenParticles ((*genJets) [iGenJet]);
00757         }
00758       
00759         for (unsigned iCaloJet = 0; iCaloJet < caloJets->size(); ++iCaloJet) {
00760           caloJetConstituents [iCaloJet] = jetMatching.getGenParticles ((*caloJets) [iCaloJet], false);
00761         }
00762       }
00763 
00764       for (unsigned iGenJet = 0; iGenJet < genJets->size(); ++iGenJet) {               //****************************************************************
00765         //for (unsigned iGenJet = 0; iGenJet < 1; ++iGenJet) {                           // only FIRST Jet !!!!
00766         const GenJet& genJet = (*genJets) [iGenJet];
00767         double genJetPt = genJet.pt();
00768 
00769         //std::cout << iGenJet <<". Genjet: pT = " << genJetPt << "GeV" << std::endl;  //  *****************************************************
00770 
00771         if (fabs(genJet.eta()) > 6.) continue; // out of detector 
00772         if (genJetPt < mMatchGenPtThreshold) continue; // no low momentum 
00773         //double logPtGen = log10 (genJetPt);
00774         //mAllGenJetsPt->Fill (logPtGen);
00775         //mAllGenJetsEta->Fill (logPtGen, genJet.eta());
00776         if (caloJets->size() <= 0) continue; // no CaloJets - nothing to match
00777         if (mRThreshold > 0) {
00778           unsigned iCaloJetBest = 0;
00779           double deltaRBest = 999.;
00780           for (unsigned iCaloJet = 0; iCaloJet < caloJets->size(); ++iCaloJet) {
00781             double dR = deltaR (genJet.eta(), genJet.phi(), (*caloJets) [iCaloJet].eta(), (*caloJets) [iCaloJet].phi());
00782             if (deltaRBest < mRThreshold && dR < mRThreshold && genJet.pt() > 5.) {
00783               /*
00784                 std::cout << "Yet another matched jet for GenJet pt=" << genJet.pt()
00785                 << " previous CaloJet pt/dr: " << (*caloJets) [iCaloJetBest].pt() << '/' << deltaRBest
00786                 << " new CaloJet pt/dr: " << (*caloJets) [iCaloJet].pt() << '/' << dR
00787                 << std::endl;
00788               */
00789             }
00790             if (dR < deltaRBest) {
00791               iCaloJetBest = iCaloJet;
00792               deltaRBest = dR;
00793             }
00794           }
00795           if (mTurnOnEverything.compare("yes")==0) {
00796             //mRMatch->Fill (logPtGen, genJet.eta(), deltaRBest);
00797           }
00798           if (deltaRBest < mRThreshold) { // Matched
00799             fillMatchHists (genJet, (*caloJets) [iCaloJetBest],goodVertices);
00800           }
00801 
00803           double CorrdeltaRBest = 999.;
00804           double CorrJetPtBest = 0;
00805           for (CaloJetCollection::const_iterator jet = caloJets->begin(); jet !=caloJets ->end(); jet++) {
00806             CaloJet  correctedJet = *jet;
00807             //double scale = corrector->correction(jet->p4());
00808             double scale=1.0;
00809             if (doJetCorrection){ 
00810               scale = corrector->correction(*jet,mEvent,mSetup);
00811             }
00812             correctedJet.scaleEnergy(scale);
00813             double CorrJetPt = correctedJet.pt();
00814             if(CorrJetPt>30){
00815               double CorrdR = deltaR (genJet.eta(), genJet.phi(), correctedJet.eta(), correctedJet.phi());
00816               if (CorrdR < CorrdeltaRBest) {
00817                 CorrdeltaRBest = CorrdR;
00818                 CorrJetPtBest = CorrJetPt;
00819               }
00820             }
00821           }
00822           if (deltaRBest < mRThreshold) { // Matched
00823             mpTResponse->Fill(log10(genJet.pt()),CorrJetPtBest/genJet.pt());
00824 
00825             if(goodVertices.size()<=5) mpTResponse_nvtx_0_5->Fill(log10(genJet.pt()),CorrJetPtBest/genJet.pt());
00826             if(goodVertices.size()>5 && goodVertices.size()<=10) mpTResponse_nvtx_5_10->Fill(log10(genJet.pt()),CorrJetPtBest/genJet.pt());
00827             if(goodVertices.size()>10 && goodVertices.size()<=15) mpTResponse_nvtx_10_15->Fill(log10(genJet.pt()),CorrJetPtBest/genJet.pt());     
00828             if(goodVertices.size()>15 && goodVertices.size()<=20) mpTResponse_nvtx_15_20->Fill(log10(genJet.pt()),CorrJetPtBest/genJet.pt());
00829             if(goodVertices.size()>20 && goodVertices.size()<=30) mpTResponse_nvtx_20_30->Fill(log10(genJet.pt()),CorrJetPtBest/genJet.pt());
00830             if(goodVertices.size()>30) mpTResponse_nvtx_30_inf->Fill(log10(genJet.pt()),CorrJetPtBest/genJet.pt());
00831 
00832             if (fabs(genJet.eta())<1.5) {
00833               mpTResponseB_d->Fill(log10(genJet.pt()), CorrJetPtBest/genJet.pt());
00834             }   
00835           
00836             if (fabs(genJet.eta())>1.5 && fabs(genJet.eta())<3.0) {
00837               mpTResponseE_d->Fill (log10(genJet.pt()), CorrJetPtBest/genJet.pt());   
00838             }
00839             if (fabs(genJet.eta())>3.0 && fabs(genJet.eta())<6.0) {
00840               mpTResponseF_d->Fill (log10(genJet.pt()), CorrJetPtBest/genJet.pt());
00841             }
00842             if (genJet.pt()>30.0 && genJet.pt()<200.0) {
00843               mpTResponse_30_200_d->Fill (genJet.eta(),CorrJetPtBest/genJet.pt());
00844             }
00845             if (genJet.pt()>200.0 && genJet.pt()<600.0) {
00846               mpTResponse_200_600_d->Fill (genJet.eta(),CorrJetPtBest/genJet.pt());
00847             }
00848             if (genJet.pt()>600.0 && genJet.pt()<1500.0) {
00849               mpTResponse_600_1500_d->Fill (genJet.eta(),CorrJetPtBest/genJet.pt());
00850             }
00851             if (genJet.pt()>1500.0 && genJet.pt()<3500.0) {
00852               mpTResponse_1500_3500_d->Fill (genJet.eta(),CorrJetPtBest/genJet.pt());
00853             }
00854             if (genJet.pt()>30.0) {
00855               mpTResponse_30_d->Fill (genJet.eta(),CorrJetPtBest/genJet.pt());
00856             } 
00857           }
00859 
00860         }
00861         else {
00862           unsigned iCaloJetBest = 0;
00863           double energyFractionBest = 0.;
00864           for (unsigned iCaloJet = 0; iCaloJet < caloJets->size(); ++iCaloJet) {
00865             double energyFraction = jetMatching.overlapEnergyFraction (genJetConstituents [iGenJet], 
00866                                                                        caloJetConstituents [iCaloJet]);
00867             if (energyFraction > energyFractionBest) {
00868               iCaloJetBest = iCaloJet;
00869               energyFractionBest = energyFraction;
00870             }
00871           }
00872           if (mTurnOnEverything.compare("yes")==0) {
00873             //mGenJetMatchEnergyFraction->Fill (logPtGen, genJet.eta(), energyFractionBest);
00874           }
00875           if (energyFractionBest > mGenEnergyFractionThreshold) { // good enough
00876             double reverseEnergyFraction = jetMatching.overlapEnergyFraction (caloJetConstituents [iCaloJetBest], 
00877                                                                               genJetConstituents [iGenJet]);
00878             if (mTurnOnEverything.compare("yes")==0) {
00879               //mReverseMatchEnergyFraction->Fill (logPtGen, genJet.eta(), reverseEnergyFraction);
00880             }
00881             if (reverseEnergyFraction > mReverseEnergyFractionThreshold) { // Matched
00882               fillMatchHists (genJet, (*caloJets) [iCaloJetBest], goodVertices);
00883             }
00884           }
00885         }
00886       }
00887     }
00888   }
00889 
00890 }
00891 
00892 void CaloJetTester::fillMatchHists (const reco::GenJet& fGenJet, const reco::CaloJet& fCaloJet, std::vector<reco::Vertex> goodVertices) {
00893   double logPtGen = log10 (fGenJet.pt());
00894   double PtGen = fGenJet.pt();
00895   double PtCalo = fCaloJet.pt();
00896   //mMatchedGenJetsPt->Fill (logPtGen);
00897   //mMatchedGenJetsEta->Fill (logPtGen, fGenJet.eta());
00898 
00899   double PtThreshold = 10.;
00900 
00901   if (mTurnOnEverything.compare("yes")==0) {
00902     mDeltaEta->Fill (logPtGen, fGenJet.eta(), fCaloJet.eta()-fGenJet.eta());
00903     mDeltaPhi->Fill (logPtGen, fGenJet.eta(), fCaloJet.phi()-fGenJet.phi());
00904 
00905     mEScaleFineBin->Fill (logPtGen, fGenJet.eta(), fCaloJet.energy()/fGenJet.energy());
00906   
00907     if (fGenJet.pt()>PtThreshold) {
00908       mEScale_pt10->Fill (logPtGen, fGenJet.eta(), fCaloJet.energy()/fGenJet.energy());
00909 
00910     }
00911 
00912   }
00913   if (fCaloJet.pt() > PtThreshold) {
00914     mDelEta->Fill (fGenJet.eta()-fCaloJet.eta());
00915     mDelPhi->Fill (fGenJet.phi()-fCaloJet.phi());
00916     mDelPt->Fill  ((fGenJet.pt()-fCaloJet.pt())/fGenJet.pt());
00917   }
00918 
00919   if (fabs(fGenJet.eta())<1.5) {
00920 
00921     //mpTScaleB_s->Fill (log10(PtGen), PtCalo/PtGen);
00922     mpTScaleB_d->Fill (log10(PtGen), PtCalo/PtGen);
00923     mpTScalePhiB_d->Fill (fGenJet.phi(), PtCalo/PtGen);
00924     
00925     if (PtGen>30.0 && PtGen<200.0) {
00926       mpTScale1DB_30_200->Fill (fCaloJet.pt()/fGenJet.pt());
00927     }
00928     if (PtGen>200.0 && PtGen<600.0) {
00929       mpTScale1DB_200_600->Fill (fCaloJet.pt()/fGenJet.pt());
00930     }
00931     if (PtGen>300.0 && PtGen<1500.0) {
00932       mpTScale1DB_600_1500->Fill (fCaloJet.pt()/fGenJet.pt());
00933     }
00934     if (PtGen>1500.0 && PtGen<3500.0) {
00935       mpTScale1DB_1500_3500->Fill (fCaloJet.pt()/fGenJet.pt());
00936     }
00937     
00938   }
00939 
00940   if (fabs(fGenJet.eta())>1.5 && fabs(fGenJet.eta())<3.0) {
00941 
00942     //mpTScaleE_s->Fill (log10(PtGen), PtCalo/PtGen);
00943     mpTScaleE_d->Fill (log10(PtGen), PtCalo/PtGen);
00944     mpTScalePhiE_d->Fill (fGenJet.phi(), PtCalo/PtGen);
00945     
00946     if (PtGen>30.0 && PtGen<200.0) {
00947       mpTScale1DE_30_200->Fill (fCaloJet.pt()/fGenJet.pt());
00948     }
00949     if (PtGen>200.0 && PtGen<600.0) {
00950       mpTScale1DE_200_600->Fill (fCaloJet.pt()/fGenJet.pt());
00951     }
00952     if (PtGen>600.0 && PtGen<1500.0) {
00953       mpTScale1DE_600_1500->Fill (fCaloJet.pt()/fGenJet.pt());
00954     }
00955     if (PtGen>1500.0 && PtGen<3500.0) {
00956       mpTScale1DE_1500_3500->Fill (fCaloJet.pt()/fGenJet.pt());
00957     }
00958     
00959   }
00960 
00961   if (fabs(fGenJet.eta())>3.0 && fabs(fGenJet.eta())<6.0) {
00962 
00963     //mpTScaleF_s->Fill (log10(PtGen), PtCalo/PtGen);
00964     mpTScaleF_d->Fill (log10(PtGen), PtCalo/PtGen);
00965     mpTScalePhiF_d->Fill (fGenJet.phi(), PtCalo/PtGen);
00966     
00967     if (PtGen>30.0 && PtGen<200.0) {
00968       mpTScale1DF_30_200->Fill (fCaloJet.pt()/fGenJet.pt());
00969     }
00970     if (PtGen>200.0 && PtGen<600.0) {
00971       mpTScale1DF_200_600->Fill (fCaloJet.pt()/fGenJet.pt());
00972     }
00973     if (PtGen>600.0 && PtGen<1500.0) {
00974       mpTScale1DF_600_1500->Fill (fCaloJet.pt()/fGenJet.pt());
00975     }
00976     if (PtGen>1500.0 && PtGen<3500.0) {
00977       mpTScale1DF_1500_3500->Fill (fCaloJet.pt()/fGenJet.pt());
00978     }
00979     
00980   }
00981 
00982   if (fGenJet.pt()>30.0 && fGenJet.pt()<200.0) {
00983     mpTScale_30_200_d->Fill (fGenJet.eta(),fCaloJet.pt()/fGenJet.pt());
00984   }
00985 
00986   if (fGenJet.pt()>200.0 && fGenJet.pt()<600.0) {
00987     mpTScale_200_600_d->Fill (fGenJet.eta(),fCaloJet.pt()/fGenJet.pt());
00988   }
00989 
00990   if (fGenJet.pt()>600.0 && fGenJet.pt()<1500.0) {
00991     mpTScale_600_1500_d->Fill (fGenJet.eta(),fCaloJet.pt()/fGenJet.pt());
00992   }
00993 
00994   if (fGenJet.pt()>1500.0 && fGenJet.pt()<3500.0) {
00995     mpTScale_1500_3500_d->Fill (fGenJet.eta(),fCaloJet.pt()/fGenJet.pt());
00996   }
00997 
00998   if (fabs(fGenJet.eta())<1.3) {
00999     if(fGenJet.pt()>60.0 && fGenJet.pt()<120.0) {
01000       if(goodVertices.size()<=5) mpTScale_a_nvtx_0_5->Fill( PtCalo/PtGen); 
01001     }
01002     if(fGenJet.pt()>200.0 && fGenJet.pt()<300.0) {
01003       if(goodVertices.size()<=5) mpTScale_b_nvtx_0_5->Fill( PtCalo/PtGen); 
01004     }
01005     if(fGenJet.pt()>600.0 && fGenJet.pt()<900.0) {
01006       if(goodVertices.size()<=5) mpTScale_c_nvtx_0_5->Fill( PtCalo/PtGen); 
01007     }
01008     
01009     if(fGenJet.pt()>60.0 && fGenJet.pt()<120.0) {
01010       if(goodVertices.size()>5 && goodVertices.size()<=10) mpTScale_a_nvtx_5_10->Fill( PtCalo/PtGen); 
01011     }
01012     if(fGenJet.pt()>200.0 && fGenJet.pt()<300.0) {
01013       if(goodVertices.size()>5 && goodVertices.size()<=10) mpTScale_b_nvtx_5_10->Fill( PtCalo/PtGen); 
01014     }
01015     if(fGenJet.pt()>600.0 && fGenJet.pt()<900.0) {
01016       if(goodVertices.size()>5 && goodVertices.size()<=10) mpTScale_c_nvtx_5_10->Fill( PtCalo/PtGen); 
01017     }
01018 
01019     if(fGenJet.pt()>60.0 && fGenJet.pt()<120.0) {
01020       if(goodVertices.size()>10 && goodVertices.size()<=15) mpTScale_a_nvtx_10_15->Fill( PtCalo/PtGen); 
01021     }
01022     if(fGenJet.pt()>200.0 && fGenJet.pt()<300.0) {
01023       if(goodVertices.size()>10 && goodVertices.size()<=15) mpTScale_b_nvtx_10_15->Fill( PtCalo/PtGen); 
01024     }
01025     if(fGenJet.pt()>600.0 && fGenJet.pt()<900.0) {
01026       if(goodVertices.size()>10 && goodVertices.size()<=15) mpTScale_c_nvtx_10_15->Fill( PtCalo/PtGen); 
01027     }
01028 
01029     if(fGenJet.pt()>60.0 && fGenJet.pt()<120.0) {
01030       if(goodVertices.size()>15 && goodVertices.size()<=20) mpTScale_a_nvtx_15_20->Fill( PtCalo/PtGen); 
01031     }
01032     if(fGenJet.pt()>200.0 && fGenJet.pt()<300.0) {
01033       if(goodVertices.size()>15 && goodVertices.size()<=20) mpTScale_b_nvtx_15_20->Fill( PtCalo/PtGen); 
01034     }
01035     if(fGenJet.pt()>600.0 && fGenJet.pt()<900.0) {
01036       if(goodVertices.size()>15 && goodVertices.size()<=20) mpTScale_c_nvtx_15_20->Fill( PtCalo/PtGen); 
01037     }
01038 
01039     if(fGenJet.pt()>60.0 && fGenJet.pt()<120.0) {
01040       if(goodVertices.size()>20 && goodVertices.size()<=30) mpTScale_a_nvtx_20_30->Fill( PtCalo/PtGen); 
01041     }
01042     if(fGenJet.pt()>200.0 && fGenJet.pt()<300.0) {
01043       if(goodVertices.size()>20 && goodVertices.size()<=30) mpTScale_b_nvtx_20_30->Fill( PtCalo/PtGen); 
01044     }
01045     if(fGenJet.pt()>600.0 && fGenJet.pt()<900.0) {
01046       if(goodVertices.size()>20 && goodVertices.size()<=30) mpTScale_c_nvtx_20_30->Fill( PtCalo/PtGen); 
01047     }
01048  
01049     if(fGenJet.pt()>60.0 && fGenJet.pt()<120.0) {
01050       if(goodVertices.size()>30) mpTScale_a_nvtx_30_inf->Fill( PtCalo/PtGen); 
01051     }
01052     if(fGenJet.pt()>200.0 && fGenJet.pt()<300.0) {
01053       if(goodVertices.size()>30) mpTScale_b_nvtx_30_inf->Fill( PtCalo/PtGen); 
01054     }
01055     if(fGenJet.pt()>600.0 && fGenJet.pt()<900.0) {
01056       if(goodVertices.size()>30) mpTScale_c_nvtx_30_inf->Fill( PtCalo/PtGen); 
01057     }
01059     if(goodVertices.size()<=5) mpTScale_nvtx_0_5->Fill(log10(PtGen),PtCalo/PtGen);  
01060     if(goodVertices.size()>5 && goodVertices.size()<=10) mpTScale_nvtx_5_10->Fill(log10(PtGen),PtCalo/PtGen);
01061     if(goodVertices.size()>10 && goodVertices.size()<=15) mpTScale_nvtx_10_15->Fill(log10(PtGen),PtCalo/PtGen);
01062     if(goodVertices.size()>15 && goodVertices.size()<=20) mpTScale_nvtx_15_20->Fill(log10(PtGen), PtCalo/PtGen);
01063     if(goodVertices.size()>20 && goodVertices.size()<=30) mpTScale_nvtx_20_30->Fill(log10(PtGen), PtCalo/PtGen);
01064     if(goodVertices.size()>30) mpTScale_nvtx_30_inf->Fill(log10(PtGen), PtCalo/PtGen);
01065   }
01066   if (fabs(fGenJet.eta())<1.3) {
01067     if(fGenJet.pt()>60.0 && fGenJet.pt()<120.0) mpTScale_a->Fill(PtCalo/PtGen);
01068     if(fGenJet.pt()>200.0 && fGenJet.pt()<300.0) mpTScale_b->Fill(PtCalo/PtGen);
01069     if(fGenJet.pt()>600.0 && fGenJet.pt()<900.0) mpTScale_c->Fill(PtCalo/PtGen);
01070   }
01071   mpTScale_pT->Fill (log10(PtGen), PtCalo/PtGen);
01072 }
01073