CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DQMOffline/JetMET/src/JetAnalyzer.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2010/10/15 13:49:55 $
00005  *  $Revision: 1.22 $
00006  *  \author F. Chlebana - Fermilab
00007  */
00008 
00009 #include "DQMOffline/JetMET/interface/JetAnalyzer.h"
00010 #include "DataFormats/Common/interface/Handle.h"
00011 
00012 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00013 #include "DataFormats/JetReco/interface/CaloJet.h"
00014 
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016 
00017 
00018 #include <string>
00019 using namespace edm;
00020 
00021 // ***********************************************************
00022 JetAnalyzer::JetAnalyzer(const edm::ParameterSet& pSet) {
00023   
00024   parameters   = pSet;
00025   _leadJetFlag = 0;
00026   _JetLoPass   = 0;
00027   _JetHiPass   = 0;
00028   _ptThreshold = 5.;
00029   _n90HitsMin =0;
00030   _fHPDMax=1.;
00031   _resEMFMin=0.;
00032   _n90HitsMinLoose =0;
00033   _fHPDMaxLoose=1.;
00034   _resEMFMinLoose=0.;
00035   _n90HitsMinTight =0;
00036   _fHPDMaxTight=1.;
00037   _resEMFMinTight=0.;
00038   _sigmaEtaMinTight=-999.;
00039   _sigmaPhiMinTight=-999.;
00040 
00041 } 
00042   
00043 // ***********************************************************
00044 JetAnalyzer::~JetAnalyzer() { }
00045 
00046 
00047 // ***********************************************************
00048 void JetAnalyzer::beginJob(DQMStore * dbe) {
00049   
00050   jetname = "jetAnalyzer";
00051   
00052   LogTrace(jetname)<<"[JetAnalyzer] Parameters initialization";
00053   dbe->setCurrentFolder("JetMET/Jet/"+_source);
00054 
00055   jetME = dbe->book1D("jetReco", "jetReco", 3, 1, 4);
00056   jetME->setBinLabel(1,"CaloJets",1);
00057 
00058   //
00059   jetID = new reco::helper::JetIDHelper(parameters.getParameter<ParameterSet>("JetIDParams"));
00060   //
00061 
00062   fillJIDPassFrac = parameters.getParameter<int>("fillJIDPassFrac");
00063   makedijetselection = parameters.getParameter<int>("makedijetselection");
00064 
00065   // monitoring of eta parameter
00066   etaBin = parameters.getParameter<int>("etaBin");
00067   etaMin = parameters.getParameter<double>("etaMin");
00068   etaMax = parameters.getParameter<double>("etaMax");
00069 
00070   // monitoring of phi paramater
00071   phiBin = parameters.getParameter<int>("phiBin");
00072   phiMin = parameters.getParameter<double>("phiMin");
00073   phiMax = parameters.getParameter<double>("phiMax");
00074 
00075   // monitoring of the transverse momentum
00076   ptBin = parameters.getParameter<int>("ptBin");
00077   ptMin = parameters.getParameter<double>("ptMin");
00078   ptMax = parameters.getParameter<double>("ptMax");
00079 
00080   // 
00081   eBin = parameters.getParameter<int>("eBin");
00082   eMin = parameters.getParameter<double>("eMin");
00083   eMax = parameters.getParameter<double>("eMax");
00084 
00085   // 
00086   pBin = parameters.getParameter<int>("pBin");
00087   pMin = parameters.getParameter<double>("pMin");
00088   pMax = parameters.getParameter<double>("pMax");
00089 
00090   //
00091   _ptThreshold = parameters.getParameter<double>("ptThreshold");
00092   _n90HitsMin = parameters.getParameter<int>("n90HitsMin");
00093   _fHPDMax = parameters.getParameter<double>("fHPDMax");
00094   _resEMFMin = parameters.getParameter<double>("resEMFMin");
00095   _sigmaEtaMinTight = parameters.getParameter<double>("sigmaEtaMinTight");
00096   _sigmaPhiMinTight = parameters.getParameter<double>("sigmaPhiMinTight");
00097 
00098   _n90HitsMinLoose = parameters.getParameter<int>("n90HitsMinLoose");
00099   _fHPDMaxLoose = parameters.getParameter<double>("fHPDMaxLoose");
00100   _resEMFMinLoose = parameters.getParameter<double>("resEMFMinLoose");
00101   _n90HitsMinTight = parameters.getParameter<int>("n90HitsMinTight");
00102   _fHPDMaxTight = parameters.getParameter<double>("fHPDMaxTight");
00103   _resEMFMinTight = parameters.getParameter<double>("resEMFMinTight");
00104 
00105   
00106   // Generic Jet Parameters
00107   mPt                      = dbe->book1D("Pt",  "Pt", ptBin, ptMin, ptMax);
00108   mEta                     = dbe->book1D("Eta", "Eta", etaBin, etaMin, etaMax);
00109   mPhi                     = dbe->book1D("Phi", "Phi", phiBin, phiMin, phiMax);
00110   mConstituents            = dbe->book1D("Constituents", "# of Constituents", 100, 0, 100);
00111   mHFrac                   = dbe->book1D("HFrac", "HFrac", 120, -0.1, 1.1);
00112   mEFrac                   = dbe->book1D("EFrac", "EFrac", 120, -0.1, 1.1);
00113   //
00114   mE                       = dbe->book1D("E", "E", eBin, eMin, eMax);
00115   mP                       = dbe->book1D("P", "P", pBin, pMin, pMax);
00116   mMass                    = dbe->book1D("Mass", "Mass", 100, 0, 25);
00117   //
00118   mPhiVSEta                     = dbe->book2D("PhiVSEta", "PhiVSEta", 50, etaMin, etaMax, 24, phiMin, phiMax);
00119   if(makedijetselection!=1){
00120     mPt_1                    = dbe->book1D("Pt1", "Pt1", 100, 0, 100);
00121     mPt_2                    = dbe->book1D("Pt2", "Pt2", 100, 0, 300);
00122     mPt_3                    = dbe->book1D("Pt3", "Pt3", 100, 0, 5000);
00123     // Low and high pt trigger paths
00124     mPt_Lo                  = dbe->book1D("Pt_Lo", "Pt (Pass Low Pt Jet Trigger)", 100, 0, 100);
00125     mEta_Lo                 = dbe->book1D("Eta_Lo", "Eta (Pass Low Pt Jet Trigger)", etaBin, etaMin, etaMax);
00126     mPhi_Lo                 = dbe->book1D("Phi_Lo", "Phi (Pass Low Pt Jet Trigger)", phiBin, phiMin, phiMax);
00127     
00128     mPt_Hi                  = dbe->book1D("Pt_Hi", "Pt (Pass Hi Pt Jet Trigger)", 100, 0, 300);
00129     mEta_Hi                 = dbe->book1D("Eta_Hi", "Eta (Pass Hi Pt Jet Trigger)", etaBin, etaMin, etaMax);
00130     mPhi_Hi                 = dbe->book1D("Phi_Hi", "Phi (Pass Hi Pt Jet Trigger)", phiBin, phiMin, phiMax);
00131     mNJets                   = dbe->book1D("NJets", "Number of Jets", 100, 0, 100);
00132     mPt_Barrel_Lo            = dbe->book1D("Pt_Barrel_Lo", "Pt Barrel (Pass Low Pt Jet Trigger)", 100, 0, 100);
00133     mPhi_Barrel_Lo           = dbe->book1D("Phi_Barrel_Lo", "Phi Barrel (Pass Low Pt Jet Trigger)", phiBin, phiMin, phiMax);
00134     mConstituents_Barrel_Lo  = dbe->book1D("Constituents_Barrel_Lo", "Constituents Barrel (Pass Low Pt Jet Trigger)", 100, 0, 100);
00135     mHFrac_Barrel_Lo         = dbe->book1D("HFrac_Barrel_Lo", "HFrac Barrel (Pass Low Pt Jet Trigger)", 100, 0, 1);
00136     
00137     mPt_EndCap_Lo            = dbe->book1D("Pt_EndCap_Lo", "Pt EndCap (Pass Low Pt Jet Trigger)", 100, 0, 100);
00138     mPhi_EndCap_Lo           = dbe->book1D("Phi_EndCap_Lo", "Phi EndCap (Pass Low Pt Jet Trigger)", phiBin, phiMin, phiMax);
00139     mConstituents_EndCap_Lo  = dbe->book1D("Constituents_EndCap_Lo", "Constituents EndCap (Pass Low Pt Jet Trigger)", 100, 0, 100);
00140     mHFrac_EndCap_Lo         = dbe->book1D("HFrac_Endcap_Lo", "HFrac EndCap (Pass Low Pt Jet Trigger)", 100, 0, 1);
00141     
00142     mPt_Forward_Lo           = dbe->book1D("Pt_Forward_Lo", "Pt Forward (Pass Low Pt Jet Trigger)", 100, 0, 100);
00143     mPhi_Forward_Lo          = dbe->book1D("Phi_Forward_Lo", "Phi Forward (Pass Low Pt Jet Trigger)", phiBin, phiMin, phiMax);
00144     mConstituents_Forward_Lo = dbe->book1D("Constituents_Forward_Lo", "Constituents Forward (Pass Low Pt Jet Trigger)", 100, 0, 100);
00145     mHFrac_Forward_Lo        = dbe->book1D("HFrac_Forward_Lo", "HFrac Forward (Pass Low Pt Jet Trigger)", 100, 0, 1);
00146     
00147     mPt_Barrel_Hi            = dbe->book1D("Pt_Barrel_Hi", "Pt Barrel (Pass Hi Pt Jet Trigger)", 100, 0, 300);
00148     mPhi_Barrel_Hi           = dbe->book1D("Phi_Barrel_Hi", "Phi Barrel (Pass Hi Pt Jet Trigger)", phiBin, phiMin, phiMax);
00149     mConstituents_Barrel_Hi  = dbe->book1D("Constituents_Barrel_Hi", "Constituents Barrel (Pass Hi Pt Jet Trigger)", 100, 0, 100);
00150     mHFrac_Barrel_Hi         = dbe->book1D("HFrac_Barrel_Hi", "HFrac Barrel (Pass Hi Pt Jet Trigger)", 100, 0, 1);
00151     
00152     mPt_EndCap_Hi            = dbe->book1D("Pt_EndCap_Hi", "Pt EndCap (Pass Hi Pt Jet Trigger)", 100, 0, 300);
00153     mPhi_EndCap_Hi           = dbe->book1D("Phi_EndCap_Hi", "Phi EndCap (Pass Hi Pt Jet Trigger)", phiBin, phiMin, phiMax);
00154     mConstituents_EndCap_Hi  = dbe->book1D("Constituents_EndCap_Hi", "Constituents EndCap (Pass Hi Pt Jet Trigger)", 100, 0, 100);
00155     mHFrac_EndCap_Hi         = dbe->book1D("HFrac_EndCap_Hi", "HFrac EndCap (Pass Hi Pt Jet Trigger)", 100, 0, 1);
00156     
00157     mPt_Forward_Hi           = dbe->book1D("Pt_Forward_Hi", "Pt Forward (Pass Hi Pt Jet Trigger)", 100, 0, 300);
00158     mPhi_Forward_Hi          = dbe->book1D("Phi_Forward_Hi", "Phi Forward (Pass Hi Pt Jet Trigger)", phiBin, phiMin, phiMax);
00159     mConstituents_Forward_Hi = dbe->book1D("Constituents_Forward_Hi", "Constituents Forward (Pass Hi Pt Jet Trigger)", 100, 0, 100);
00160     mHFrac_Forward_Hi        = dbe->book1D("HFrac_Forward_Hi", "HFrac Forward (Pass Hi Pt Jet Trigger)", 100, 0, 1);
00161     
00162     mPhi_Barrel              = dbe->book1D("Phi_Barrel", "Phi_Barrel", phiBin, phiMin, phiMax);
00163     mE_Barrel                = dbe->book1D("E_Barrel", "E_Barrel", eBin, eMin, eMax);
00164     mPt_Barrel               = dbe->book1D("Pt_Barrel", "Pt_Barrel", ptBin, ptMin, ptMax);
00165     
00166     mPhi_EndCap              = dbe->book1D("Phi_EndCap", "Phi_EndCap", phiBin, phiMin, phiMax);
00167     mE_EndCap                = dbe->book1D("E_EndCap", "E_EndCap", eBin, eMin, 2*eMax);
00168     mPt_EndCap               = dbe->book1D("Pt_EndCap", "Pt_EndCap", ptBin, ptMin, ptMax);
00169     
00170     mPhi_Forward             = dbe->book1D("Phi_Forward", "Phi_Forward", phiBin, phiMin, phiMax);
00171     mE_Forward               = dbe->book1D("E_Forward", "E_Forward", eBin, eMin, 4*eMax);
00172     mPt_Forward              = dbe->book1D("Pt_Forward", "Pt_Forward", ptBin, ptMin, ptMax);
00173     
00174     // Leading Jet Parameters
00175     mEtaFirst                = dbe->book1D("EtaFirst", "EtaFirst", 100, -5, 5);
00176     mPhiFirst                = dbe->book1D("PhiFirst", "PhiFirst", 70, -3.5, 3.5);
00177     mEFirst                  = dbe->book1D("EFirst", "EFirst", 100, 0, 1000);
00178     mPtFirst                 = dbe->book1D("PtFirst", "PtFirst", 100, 0, 500);
00179     if(fillJIDPassFrac==1){//fillJIDPassFrac defines a collection of cleaned jets, for which we will want to fill the cleaning passing fraction
00180       mLooseJIDPassFractionVSeta      = dbe->bookProfile("LooseJIDPassFractionVSeta","LooseJIDPassFractionVSeta",etaBin, etaMin, etaMax,0.,1.2);
00181       mLooseJIDPassFractionVSpt       = dbe->bookProfile("LooseJIDPassFractionVSpt","LooseJIDPassFractionVSpt",ptBin, ptMin, ptMax,0.,1.2);
00182       mTightJIDPassFractionVSeta      = dbe->bookProfile("TightJIDPassFractionVSeta","TightJIDPassFractionVSeta",etaBin, etaMin, etaMax,0.,1.2);
00183       mTightJIDPassFractionVSpt       = dbe->bookProfile("TightJIDPassFractionVSpt","TightJIDPassFractionVSpt",ptBin, ptMin, ptMax,0.,1.2);
00184 
00185 
00186     }
00187   }
00188   // CaloJet specific
00189   mMaxEInEmTowers         = dbe->book1D("MaxEInEmTowers", "MaxEInEmTowers", 100, 0, 100);
00190   mMaxEInHadTowers        = dbe->book1D("MaxEInHadTowers", "MaxEInHadTowers", 100, 0, 100);
00191   if(makedijetselection!=1) {
00192     mHadEnergyInHO          = dbe->book1D("HadEnergyInHO", "HadEnergyInHO", 100, 0, 10);
00193     mHadEnergyInHB          = dbe->book1D("HadEnergyInHB", "HadEnergyInHB", 100, 0, 50);
00194     mHadEnergyInHF          = dbe->book1D("HadEnergyInHF", "HadEnergyInHF", 100, 0, 50);
00195     mHadEnergyInHE          = dbe->book1D("HadEnergyInHE", "HadEnergyInHE", 100, 0, 100);
00196     mEmEnergyInEB           = dbe->book1D("EmEnergyInEB", "EmEnergyInEB", 100, 0, 50);
00197     mEmEnergyInEE           = dbe->book1D("EmEnergyInEE", "EmEnergyInEE", 100, 0, 50);
00198     mEmEnergyInHF           = dbe->book1D("EmEnergyInHF", "EmEnergyInHF", 120, -20, 100);
00199   }
00200   mDPhi                   = dbe->book1D("DPhi", "dPhi btw the two leading jets", 100, 0., acos(-1.));
00201   
00202   //JetID variables
00203   
00204   mresEMF                 = dbe->book1D("resEMF", "resEMF", 50, 0., 1.);
00205   mN90Hits                = dbe->book1D("N90Hits", "N90Hits", 50, 0., 50);
00206   mfHPD                   = dbe->book1D("fHPD", "fHPD", 50, 0., 1.);
00207   mfRBX                   = dbe->book1D("fRBX", "fRBX", 50, 0., 1.);
00208 
00209   msigmaEta                   = dbe->book1D("sigmaEta", "sigmaEta", 50, 0., 0.5);
00210   msigmaPhi                   = dbe->book1D("sigmaPhi", "sigmaPhi", 50, 0., 0.5);
00211   
00212   if(makedijetselection==1 && fillJIDPassFrac==1) {
00213     mLooseJIDPassFractionVSeta  = dbe->bookProfile("LooseJIDPassFractionVSeta","LooseJIDPassFractionVSeta",50, -3., 3.,0.,1.2);
00214     mLooseJIDPassFractionVSpt   = dbe->bookProfile("LooseJIDPassFractionVSpt","LooseJIDPassFractionVSpt",ptBin, ptMin, ptMax,0.,1.2);
00215     mTightJIDPassFractionVSeta  = dbe->bookProfile("TightJIDPassFractionVSeta","TightJIDPassFractionVSeta",50, -3., 3.,0.,1.2);
00216     mTightJIDPassFractionVSpt   = dbe->bookProfile("TightJIDPassFractionVSpt","TightJIDPassFractionVSpt",ptBin, ptMin, ptMax,0.,1.2);
00217 
00218   }
00219 }
00220 
00221 
00222 //void JetAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup, 
00223 //                        const edm::TriggerResults& triggerResults,
00224 //                        const reco::CaloJet& jet) {
00225 
00226 
00227 // ***********************************************************
00228 void JetAnalyzer::endJob() {
00229   delete jetID;
00230 }
00231 
00232 
00233 // ***********************************************************
00234 void JetAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup, 
00235                           const reco::CaloJetCollection& caloJets) {
00236   int numofjets=0;
00237   double  fstPhi=0.;
00238   double  sndPhi=0.;
00239   double  diff = 0.;
00240   double  corr = 0.;
00241   double  dphi = -999. ;
00242   bool thiscleaned=false;
00243   bool Loosecleaned=false;
00244   bool Tightcleaned=false;
00245   bool thisemfclean=true;
00246   bool emfcleanLoose=true;
00247   bool emfcleanTight=true;
00248   if(makedijetselection==1){
00249     //Dijet selection - careful: the pT is uncorrected!
00250     if(makedijetselection==1 && caloJets.size()>=2){
00251       double  dphiDJ = -999. ;
00252       bool emfcleanLooseFirstJet=true;
00253       bool emfcleanLooseSecondJet=true;
00254       bool emfcleanTightFirstJet=true;
00255       bool emfcleanTightSecondJet=true;
00256       bool LoosecleanedFirstJet = false;
00257       bool LoosecleanedSecondJet = false;
00258       bool TightcleanedFirstJet = false;
00259       bool TightcleanedSecondJet = false;
00260       //both jets pass pt threshold
00261       if ((caloJets.at(0)).pt() > _ptThreshold && (caloJets.at(1)).pt() > _ptThreshold ) {
00262         if(fabs((caloJets.at(0)).eta())<3. && fabs((caloJets.at(1)).eta())<3. ){
00263           //calculate dphi
00264           dphiDJ = fabs((caloJets.at(0)).phi()-(caloJets.at(1)).phi());
00265           if (dphiDJ > 3.14) dphiDJ=fabs(dphiDJ -6.28 );
00266           //fill DPhi histo (before cutting)
00267           if (mDPhi) mDPhi->Fill (dphiDJ);
00268           //dphi cut
00269           if(fabs(dphiDJ)>2.1){
00270             //JetID 
00271             emfcleanLooseFirstJet=true;
00272             emfcleanTightFirstJet=true;
00273             emfcleanLooseSecondJet=true;
00274             emfcleanTightSecondJet=true;
00275             jetID->calculate(iEvent, (caloJets.at(0)));
00276             if(jetID->restrictedEMF()<_resEMFMinLoose && fabs((caloJets.at(0)).eta())<2.6) emfcleanLooseFirstJet=false;
00277             if(jetID->restrictedEMF()<_resEMFMinTight && fabs((caloJets.at(0)).eta())<2.6) emfcleanTightFirstJet=false;
00278             if(jetID->n90Hits()>=_n90HitsMinLoose && jetID->fHPD()<_fHPDMaxLoose && emfcleanLooseFirstJet) LoosecleanedFirstJet=true;
00279             if(jetID->n90Hits()>=_n90HitsMinTight && jetID->fHPD()<_fHPDMaxTight && sqrt((caloJets.at(0)).etaetaMoment())>_sigmaEtaMinTight && sqrt((caloJets.at(0)).phiphiMoment())>_sigmaPhiMinTight && emfcleanTightFirstJet) TightcleanedFirstJet=true;
00280             //fill the JID variables histograms BEFORE you cut on them
00281             if (mN90Hits)         mN90Hits->Fill (jetID->n90Hits());
00282             if (mfHPD)            mfHPD->Fill (jetID->fHPD());
00283             if (mresEMF)         mresEMF->Fill (jetID->restrictedEMF());
00284             if (mfRBX)            mfRBX->Fill (jetID->fRBX());
00285             jetID->calculate(iEvent, (caloJets.at(1)));
00286             if(jetID->restrictedEMF()<_resEMFMinLoose && fabs((caloJets.at(1)).eta())<2.6) emfcleanLooseSecondJet=false;
00287             if(jetID->restrictedEMF()<_resEMFMinTight && fabs((caloJets.at(1)).eta())<2.6) emfcleanTightSecondJet=false;
00288             if(jetID->n90Hits()>=_n90HitsMinLoose && jetID->fHPD()<_fHPDMaxLoose && emfcleanLooseSecondJet) LoosecleanedSecondJet=true;
00289             if(jetID->n90Hits()>=_n90HitsMinTight && jetID->fHPD()<_fHPDMaxTight && sqrt((caloJets.at(1)).etaetaMoment())>_sigmaEtaMinTight && sqrt((caloJets.at(1)).phiphiMoment())>_sigmaPhiMinTight && emfcleanTightSecondJet) TightcleanedSecondJet=true;
00290             //fill the JID variables histograms BEFORE you cut on them
00291             if (mN90Hits)         mN90Hits->Fill (jetID->n90Hits());
00292             if (mfHPD)            mfHPD->Fill (jetID->fHPD());
00293             if (mresEMF)         mresEMF->Fill (jetID->restrictedEMF());
00294             if (mfRBX)            mfRBX->Fill (jetID->fRBX());
00295             if(LoosecleanedFirstJet && LoosecleanedSecondJet) { //only if both jets are (loose) cleaned
00296               //fill histos for first jet
00297               if (mPt)   mPt->Fill ((caloJets.at(0)).pt());
00298               if (mEta)  mEta->Fill ((caloJets.at(0)).eta());
00299               if (mPhi)  mPhi->Fill ((caloJets.at(0)).phi());
00300               if (mPhiVSEta) mPhiVSEta->Fill((caloJets.at(0)).eta(),(caloJets.at(0)).phi());
00301               if (mConstituents) mConstituents->Fill ((caloJets.at(0)).nConstituents());
00302               if (mHFrac)        mHFrac->Fill ((caloJets.at(0)).energyFractionHadronic());
00303               if (mEFrac)        mEFrac->Fill ((caloJets.at(0)).emEnergyFraction());
00304               if (mE)    mE->Fill ((caloJets.at(0)).energy());
00305               if (mP)    mP->Fill ((caloJets.at(0)).p());
00306               if (mMass) mMass->Fill ((caloJets.at(0)).mass());
00307               if (mMaxEInEmTowers)  mMaxEInEmTowers->Fill ((caloJets.at(0)).maxEInEmTowers());
00308               if (mMaxEInHadTowers) mMaxEInHadTowers->Fill ((caloJets.at(0)).maxEInHadTowers());
00309               if (mN90Hits)         mN90Hits->Fill (jetID->n90Hits());
00310               if (mfHPD)            mfHPD->Fill (jetID->fHPD());
00311               if (mresEMF)         mresEMF->Fill (jetID->restrictedEMF());
00312               if (mfRBX)            mfRBX->Fill (jetID->fRBX());
00313               //sigmaeta and sigmaphi only used in the tight selection.
00314               //fill the histos for them AFTER the loose selection 
00315               if (msigmaEta)  msigmaEta->Fill(sqrt((caloJets.at(0)).etaetaMoment()));
00316               if (msigmaPhi)  msigmaPhi->Fill(sqrt((caloJets.at(0)).phiphiMoment()));
00317               //fill histos for second jet
00318               if (mPt)   mPt->Fill ((caloJets.at(1)).pt());
00319               if (mEta)  mEta->Fill ((caloJets.at(1)).eta());
00320               if (mPhi)  mPhi->Fill ((caloJets.at(1)).phi());
00321               if (mPhiVSEta) mPhiVSEta->Fill((caloJets.at(1)).eta(),(caloJets.at(1)).phi());
00322               if (mConstituents) mConstituents->Fill ((caloJets.at(1)).nConstituents());
00323               if (mHFrac)        mHFrac->Fill ((caloJets.at(1)).energyFractionHadronic());
00324               if (mEFrac)        mEFrac->Fill ((caloJets.at(1)).emEnergyFraction());
00325               if (mE)    mE->Fill ((caloJets.at(1)).energy());
00326               if (mP)    mP->Fill ((caloJets.at(1)).p());
00327               if (mMass) mMass->Fill ((caloJets.at(1)).mass());
00328               if (mMaxEInEmTowers)  mMaxEInEmTowers->Fill ((caloJets.at(1)).maxEInEmTowers());
00329               if (mMaxEInHadTowers) mMaxEInHadTowers->Fill ((caloJets.at(1)).maxEInHadTowers());
00330               //sigmaeta and sigmaphi only used in the tight selection.
00331               //fill the histos for them AFTER the loose selection 
00332               if (msigmaEta)  msigmaEta->Fill(sqrt((caloJets.at(1)).etaetaMoment()));
00333               if (msigmaPhi)  msigmaPhi->Fill(sqrt((caloJets.at(1)).phiphiMoment()));
00334 
00335             }
00336             //let's see how many of these jets passed the JetID cleaning
00337             if(fillJIDPassFrac==1) {
00338               if(LoosecleanedFirstJet) {
00339                 mLooseJIDPassFractionVSeta->Fill((caloJets.at(0)).eta(),1.);
00340                 mLooseJIDPassFractionVSpt->Fill((caloJets.at(0)).pt(),1.);
00341               } else  {
00342                 mLooseJIDPassFractionVSeta->Fill((caloJets.at(0)).eta(),0.);
00343                 mLooseJIDPassFractionVSpt->Fill((caloJets.at(0)).pt(),0.);
00344               }
00345               if(LoosecleanedSecondJet) {
00346                 mLooseJIDPassFractionVSeta->Fill((caloJets.at(1)).eta(),1.);
00347                 mLooseJIDPassFractionVSpt->Fill((caloJets.at(1)).pt(),1.);
00348               } else  {
00349                 mLooseJIDPassFractionVSeta->Fill((caloJets.at(1)).eta(),0.);
00350                 mLooseJIDPassFractionVSpt->Fill((caloJets.at(1)).pt(),0.);
00351               }
00352               //TIGHT JID
00353               if(TightcleanedFirstJet) {
00354                 mTightJIDPassFractionVSeta->Fill((caloJets.at(0)).eta(),1.);
00355                 mTightJIDPassFractionVSpt->Fill((caloJets.at(0)).pt(),1.);
00356               } else  {
00357                 mTightJIDPassFractionVSeta->Fill((caloJets.at(0)).eta(),0.);
00358                 mTightJIDPassFractionVSpt->Fill((caloJets.at(0)).pt(),0.);
00359               }
00360               if(TightcleanedSecondJet) {
00361                 mTightJIDPassFractionVSeta->Fill((caloJets.at(1)).eta(),1.);
00362                 mTightJIDPassFractionVSpt->Fill((caloJets.at(1)).pt(),1.);
00363               } else  {
00364                 mTightJIDPassFractionVSeta->Fill((caloJets.at(1)).eta(),0.);
00365                 mTightJIDPassFractionVSpt->Fill((caloJets.at(1)).pt(),0.);
00366               }
00367 
00368             }//if fillJIDPassFrac
00369           }
00370         }
00371       }
00372     }
00373   } else {
00374     for (reco::CaloJetCollection::const_iterator jet = caloJets.begin(); jet!=caloJets.end(); ++jet) {
00375       LogTrace(jetname)<<"[JetAnalyzer] Analyze Calo Jet";
00376       Loosecleaned=false;
00377       Tightcleaned=false;
00378       if (jet == caloJets.begin()) {
00379         fstPhi = jet->phi();
00380         _leadJetFlag = 1;
00381       } else {
00382         _leadJetFlag = 0;
00383       }
00384       if (jet == (caloJets.begin()+1)) sndPhi = jet->phi();
00385       //jetID
00386       jetID->calculate(iEvent, *jet);
00387       //minimal (uncorrected!) pT cut
00388       if (jet->pt() > _ptThreshold) {
00389         if (msigmaEta)  msigmaEta->Fill(sqrt(jet->etaetaMoment()));
00390         if (msigmaPhi)  msigmaPhi->Fill(sqrt(jet->phiphiMoment()));
00391         //cleaning to use for filling histograms
00392         thisemfclean=true;
00393         if(jetID->restrictedEMF()<_resEMFMin && fabs(jet->eta())<2.6) thisemfclean=false;
00394         if(jetID->n90Hits()>=_n90HitsMin && jetID->fHPD()<_fHPDMax && thisemfclean) thiscleaned=true;
00395         //loose and tight cleaning, used to fill the JetIDPAssFraction histos
00396         if(jetID->n90Hits()>=_n90HitsMinLoose && jetID->fHPD()<_fHPDMaxLoose && emfcleanLoose) Loosecleaned=true;
00397         if(jetID->n90Hits()>=_n90HitsMinTight && jetID->fHPD()<_fHPDMaxTight && sqrt(jet->etaetaMoment())>_sigmaEtaMinTight && sqrt(jet->phiphiMoment())>_sigmaPhiMinTight && emfcleanTight) Tightcleaned=true;
00398 
00399         if(fillJIDPassFrac==1) {
00400           if(Loosecleaned) {
00401             mLooseJIDPassFractionVSeta->Fill(jet->eta(),1.);
00402             mLooseJIDPassFractionVSpt->Fill(jet->pt(),1.);
00403           } else {
00404             mLooseJIDPassFractionVSeta->Fill(jet->eta(),0.);
00405             mLooseJIDPassFractionVSpt->Fill(jet->pt(),0.);
00406           }
00407           //TIGHT
00408           if(Tightcleaned) {
00409             mTightJIDPassFractionVSeta->Fill(jet->eta(),1.);
00410             mTightJIDPassFractionVSpt->Fill(jet->pt(),1.);
00411           } else {
00412             mTightJIDPassFractionVSeta->Fill(jet->eta(),0.);
00413             mTightJIDPassFractionVSpt->Fill(jet->pt(),0.);
00414           }
00415         }
00416         //eventually we could define the "cleaned" flag differently for e.g. HF
00417         if(thiscleaned) {
00418           numofjets++ ;
00419           jetME->Fill(1);      
00420           
00421           // Leading jet
00422           // Histograms are filled once per event
00423           if (_leadJetFlag == 1) { 
00424             if (mEtaFirst) mEtaFirst->Fill (jet->eta());
00425             if (mPhiFirst) mPhiFirst->Fill (jet->phi());
00426             if (mEFirst)   mEFirst->Fill (jet->energy());
00427             if (mPtFirst)  mPtFirst->Fill (jet->pt());
00428           }
00429           // --- Passed the low pt jet trigger
00430           if (_JetLoPass == 1) {
00431             if (fabs(jet->eta()) <= 1.3) {
00432               if (mPt_Barrel_Lo)           mPt_Barrel_Lo->Fill(jet->pt());
00433               if (mEta_Lo)          mEta_Lo->Fill(jet->eta());
00434               if (mPhi_Barrel_Lo)          mPhi_Barrel_Lo->Fill(jet->phi());
00435               if (mConstituents_Barrel_Lo) mConstituents_Barrel_Lo->Fill(jet->nConstituents()); 
00436               if (mHFrac_Barrel_Lo)        mHFrac_Barrel_Lo->Fill(jet->energyFractionHadronic());       
00437             }
00438             if ( (fabs(jet->eta()) > 1.3) && (fabs(jet->eta()) <= 3) ) {
00439               if (mPt_EndCap_Lo)           mPt_EndCap_Lo->Fill(jet->pt());
00440               if (mEta_Lo)          mEta_Lo->Fill(jet->eta());
00441               if (mPhi_EndCap_Lo)          mPhi_EndCap_Lo->Fill(jet->phi());
00442               if (mConstituents_EndCap_Lo) mConstituents_EndCap_Lo->Fill(jet->nConstituents()); 
00443               if (mHFrac_EndCap_Lo)        mHFrac_EndCap_Lo->Fill(jet->energyFractionHadronic());       
00444             }
00445             if (fabs(jet->eta()) > 3.0) {
00446               if (mPt_Forward_Lo)           mPt_Forward_Lo->Fill(jet->pt());
00447               if (mEta_Lo)          mEta_Lo->Fill(jet->eta());
00448               if (mPhi_Forward_Lo)          mPhi_Forward_Lo->Fill(jet->phi());
00449               if (mConstituents_Forward_Lo) mConstituents_Forward_Lo->Fill(jet->nConstituents());       
00450               if (mHFrac_Forward_Lo)        mHFrac_Forward_Lo->Fill(jet->energyFractionHadronic());     
00451             }
00452             if (mEta_Lo) mEta_Lo->Fill (jet->eta());
00453             if (mPhi_Lo) mPhi_Lo->Fill (jet->phi());
00454             if (mPt_Lo)  mPt_Lo->Fill (jet->pt());
00455           }
00456           
00457           // --- Passed the high pt jet trigger
00458           if (_JetHiPass == 1) {
00459             if (fabs(jet->eta()) <= 1.3) {
00460               if (mPt_Barrel_Hi)           mPt_Barrel_Hi->Fill(jet->pt());
00461               if (mEta_Hi)          mEta_Hi->Fill(jet->eta());
00462               if (mPhi_Barrel_Hi)          mPhi_Barrel_Hi->Fill(jet->phi());
00463               if (mConstituents_Barrel_Hi) mConstituents_Barrel_Hi->Fill(jet->nConstituents()); 
00464               if (mHFrac_Barrel_Hi)        mHFrac_Barrel_Hi->Fill(jet->energyFractionHadronic());       
00465             }
00466             if ( (fabs(jet->eta()) > 1.3) && (fabs(jet->eta()) <= 3) ) {
00467               if (mPt_EndCap_Hi)           mPt_EndCap_Hi->Fill(jet->pt());
00468               if (mEta_Hi)          mEta_Hi->Fill(jet->eta());
00469               if (mPhi_EndCap_Hi)          mPhi_EndCap_Hi->Fill(jet->phi());
00470               if (mConstituents_EndCap_Hi) mConstituents_EndCap_Hi->Fill(jet->nConstituents()); 
00471               if (mHFrac_EndCap_Hi)        mHFrac_EndCap_Hi->Fill(jet->energyFractionHadronic());       
00472             }
00473             if (fabs(jet->eta()) > 3.0) {
00474               if (mPt_Forward_Hi)           mPt_Forward_Hi->Fill(jet->pt());
00475               if (mEta_Hi)          mEta_Hi->Fill(jet->eta());
00476               if (mPhi_Forward_Hi)          mPhi_Forward_Hi->Fill(jet->phi());
00477               if (mConstituents_Forward_Hi) mConstituents_Forward_Hi->Fill(jet->nConstituents());       
00478               if (mHFrac_Forward_Hi)        mHFrac_Forward_Hi->Fill(jet->energyFractionHadronic());     
00479             }
00480             
00481             if (mEta_Hi) mEta_Hi->Fill (jet->eta());
00482             if (mPhi_Hi) mPhi_Hi->Fill (jet->phi());
00483             if (mPt_Hi)  mPt_Hi->Fill (jet->pt());
00484           }
00485           
00486           if (mPt)   mPt->Fill (jet->pt());
00487           if (mPt_1) mPt_1->Fill (jet->pt());
00488           if (mPt_2) mPt_2->Fill (jet->pt());
00489           if (mPt_3) mPt_3->Fill (jet->pt());
00490           if (mEta)  mEta->Fill (jet->eta());
00491           if (mPhi)  mPhi->Fill (jet->phi());
00492           
00493           if (mPhiVSEta) mPhiVSEta->Fill(jet->eta(),jet->phi());
00494           
00495           if (mConstituents) mConstituents->Fill (jet->nConstituents());
00496           if (mHFrac)        mHFrac->Fill (jet->energyFractionHadronic());
00497           if (mEFrac)        mEFrac->Fill (jet->emEnergyFraction());
00498           
00499           if (fabs(jet->eta()) <= 1.3) {
00500             if (mPt_Barrel)   mPt_Barrel->Fill (jet->pt());
00501             if (mPhi_Barrel)  mPhi_Barrel->Fill (jet->phi());
00502             if (mE_Barrel)    mE_Barrel->Fill (jet->energy());
00503           }
00504           if ( (fabs(jet->eta()) > 1.3) && (fabs(jet->eta()) <= 3) ) {
00505             if (mPt_EndCap)   mPt_EndCap->Fill (jet->pt());
00506             if (mPhi_EndCap)  mPhi_EndCap->Fill (jet->phi());
00507             if (mE_EndCap)    mE_EndCap->Fill (jet->energy());
00508           }
00509           if (fabs(jet->eta()) > 3.0) {
00510             if (mPt_Forward)   mPt_Forward->Fill (jet->pt());
00511             if (mPhi_Forward)  mPhi_Forward->Fill (jet->phi());
00512             if (mE_Forward)    mE_Forward->Fill (jet->energy());
00513           }
00514           
00515           if (mE)    mE->Fill (jet->energy());
00516           if (mP)    mP->Fill (jet->p());
00517           if (mMass) mMass->Fill (jet->mass());
00518           
00519           if (mMaxEInEmTowers)  mMaxEInEmTowers->Fill (jet->maxEInEmTowers());
00520           if (mMaxEInHadTowers) mMaxEInHadTowers->Fill (jet->maxEInHadTowers());
00521           
00522           if (mHadEnergyInHO)   mHadEnergyInHO->Fill (jet->hadEnergyInHO());
00523           if (mHadEnergyInHB)   mHadEnergyInHB->Fill (jet->hadEnergyInHB());
00524           if (mHadEnergyInHF)   mHadEnergyInHF->Fill (jet->hadEnergyInHF());
00525           if (mHadEnergyInHE)   mHadEnergyInHE->Fill (jet->hadEnergyInHE());
00526           if (mEmEnergyInEB)    mEmEnergyInEB->Fill (jet->emEnergyInEB());
00527           if (mEmEnergyInEE)    mEmEnergyInEE->Fill (jet->emEnergyInEE());
00528           if (mEmEnergyInHF)    mEmEnergyInHF->Fill (jet->emEnergyInHF());
00529           
00530           if (mN90Hits)         mN90Hits->Fill (jetID->n90Hits());
00531           if (mfHPD)            mfHPD->Fill (jetID->fHPD());
00532           if (mresEMF)         mresEMF->Fill (jetID->restrictedEMF());
00533           if (mfRBX)            mfRBX->Fill (jetID->fRBX());
00534           
00535           //calculate correctly the dphi
00536           if(numofjets>1) {
00537             diff = fabs(fstPhi - sndPhi);
00538             corr = 2*acos(-1.) - diff;
00539             if(diff < acos(-1.)) { 
00540               dphi = diff; 
00541             } else { 
00542               dphi = corr;
00543             }
00544           }
00545         }
00546       }//pt cut
00547     }
00548     if (mNJets) mNJets->Fill (numofjets);
00549     if (mDPhi && dphi>-998.) mDPhi->Fill (dphi);
00550   }//not dijet
00551 }
00552