CMS 3D CMS Logo

Classes | Functions

/data/refman/pasoursint/CMSSW_5_2_9/src/PhysicsTools/PatExamples/bin/PatBasicFWLiteJetAnalyzer_Selector.cc File Reference

#include "TFile.h"
#include "TH1.h"
#include "TH2.h"
#include "TCanvas.h"
#include "TLegend.h"
#include "TSystem.h"
#include "TLorentzVector.h"
#include "PhysicsTools/SelectorUtils/interface/strbitset.h"
#include "DataFormats/PatCandidates/interface/Jet.h"
#include "DataFormats/PatCandidates/interface/MET.h"
#include "DataFormats/PatCandidates/interface/Photon.h"
#include "DataFormats/PatCandidates/interface/Muon.h"
#include "DataFormats/PatCandidates/interface/Electron.h"
#include "DataFormats/PatCandidates/interface/Tau.h"
#include "PhysicsTools/SelectorUtils/interface/Selector.h"
#include "PhysicsTools/SelectorUtils/interface/JetIDSelectionFunctor.h"
#include "PhysicsTools/SelectorUtils/interface/PFJetIDSelectionFunctor.h"
#include "PhysicsTools/SelectorUtils/interface/RunLumiSelector.h"
#include "FWCore/FWLite/interface/AutoLibraryLoader.h"
#include "PhysicsTools/FWLite/interface/TFileService.h"
#include "DataFormats/FWLite/interface/ChainEvent.h"
#include "FWCore/PythonParameterSet/interface/PythonProcessDesc.h"
#include "FWCore/ParameterSet/interface/ProcessDesc.h"
#include <iostream>
#include <cmath>
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Common/interface/Ptr.h"
#include "PhysicsTools/SelectorUtils/interface/EventSelector.h"
#include "TROOT.h"

Go to the source code of this file.

Classes

class  JetIDStudiesSelector

Functions

int main (int argc, char *argv[])

Function Documentation

int main ( int  argc,
char *  argv[] 
)

------------------ CALO JETS ------------------

------------------ PF JETS ------------------

Definition at line 232 of file PatBasicFWLiteJetAnalyzer_Selector.cc.

References JetIDStudiesSelector::allCaloJets(), JetIDStudiesSelector::allPFJets(), pat::Jet::associatedTracks(), fwlite::ChainEvent::atEnd(), b, edm::RefVector< C, T, F >::begin(), JetIDStudiesSelector::caloDeltaPhi(), JetIDStudiesSelector::caloJet0(), JetIDStudiesSelector::caloJet1(), JetIDStudiesSelector::caloJetID(), JetIDStudiesSelector::caloKin(), pat::Jet::chargedEmEnergyFraction(), pat::Jet::chargedHadronEnergyFraction(), gather_cfg::cout, PatBasicFWLiteJetAnalyzer_Selector_cfg::doTracks, reco::GenJet::emEnergy(), pat::Jet::emEnergyFraction(), AutoLibraryLoader::enable(), edm::RefVector< C, T, F >::end(), reco::LeafCandidate::energy(), reco::LeafCandidate::eta(), event(), funct::false, reco::JetID::fHPD, pat::Jet::genJet(), edm::ParameterSet::getParameter(), reco::GenJet::hadEnergy(), SiPixelRawToDigiRegional_cfi::inputs, pat::Jet::jecFactor(), metsig::jet, pat::Jet::jetID(), TFileDirectory::make(), TFileDirectory::mkdir(), reco::JetID::n90Hits, reco::Jet::nConstituents(), pat::Jet::neutralEmEnergyFraction(), pat::Jet::neutralHadronEnergyFraction(), Parameters::parameters, JetIDStudiesSelector::pfDeltaPhi(), JetIDStudiesSelector::pfJet0(), JetIDStudiesSelector::pfJet1(), JetIDStudiesSelector::pfJetID(), reco::LeafCandidate::phi(), Pi, PythonProcessDesc::processDesc(), reco::LeafCandidate::pt(), reco::LeafCandidate::px(), reco::LeafCandidate::py(), reco::LeafCandidate::pz(), edm::RefVector< C, T, F >::size(), pat::strbitset::test(), TrackerOfflineValidation_Standalone_cff::TFileService, fwlite::ChainEvent::toBegin(), TwoPi, and PatBasicFWLiteJetAnalyzer_Selector_cfg::useMC.

{


  if ( argc < 2 ) {
    std::cout << "Usage : " << argv[0] << " [parameters.py]" << std::endl;
    return 0;
  }

  cout << "Hello from " << argv[0] << "!" << endl;


  // load framework libraries
  gSystem->Load( "libFWCoreFWLite" );
  AutoLibraryLoader::enable();


  cout << "Getting parameters" << endl;
  // Get the python configuration
  PythonProcessDesc builder(argv[1]);
  boost::shared_ptr<edm::ProcessDesc> b = builder.processDesc();
  boost::shared_ptr<edm::ParameterSet> parameters = b->getProcessPSet();
  parameters->registerIt(); 

  edm::ParameterSet const& jetStudiesParams    = parameters->getParameter<edm::ParameterSet>("jetStudies");
  edm::ParameterSet const& pfJetStudiesParams  = parameters->getParameter<edm::ParameterSet>("pfJetStudies");
  edm::ParameterSet const& caloJetIDParameters = parameters->getParameter<edm::ParameterSet>("jetIDSelector");
  edm::ParameterSet const& pfJetIDParameters   = parameters->getParameter<edm::ParameterSet>("pfJetIDSelector");
  edm::ParameterSet const& plotParameters      = parameters->getParameter<edm::ParameterSet>("plotParameters");
  edm::ParameterSet const& inputs              = parameters->getParameter<edm::ParameterSet>("inputs");
  edm::ParameterSet const& outputs             = parameters->getParameter<edm::ParameterSet>("outputs");

  cout << "Making RunLumiSelector" << endl;
  RunLumiSelector runLumiSel( inputs );
  
  cout << "setting up TFileService" << endl;
  // book a set of histograms
  fwlite::TFileService fs = fwlite::TFileService( outputs.getParameter<std::string>("outputName") );
  TFileDirectory theDir = fs.mkdir( "histos" ); 
    
  cout << "Setting up chain event" << endl;
  // This object 'event' is used both to get all information from the
  // event as well as to store histograms, etc.
  fwlite::ChainEvent ev ( inputs.getParameter<std::vector<std::string> > ("fileNames") );


  cout << "Booking histograms" << endl;
   // Book histograms

  std::map<std::string, TH1*> hists;

   hists["hist_nJet"                     ] = theDir.make<TH1D>( "hist_nJet"                    ,"Number of Calo Jets", 10, 0, 10 ) ;
   hists["hist_nPFJet"                   ] = theDir.make<TH1D>( "hist_nPFJet"                  ,"Number of PF Jets", 10, 0, 10 ) ;

   hists["hist_jetPt"                    ] = theDir.make<TH1D>( "hist_jetPt"                   , "Jet p_{T}", 400, 0, 400 ) ;
   hists["hist_jetEtaVsPhi"              ] = theDir.make<TH2D>( "hist_jetEtaVsPhi"             , "Jet #phi versus #eta;#eta;#phi", 50, -5.0, 5.0, 50, -TMath::Pi(), TMath::Pi() ) ;
   hists["hist_jetNTracks"               ] = theDir.make<TH1D>( "hist_jetNTracks"              , "Jet N_{TRACKS}", 20, 0, 20 ) ;
   hists["hist_jetNTracksVsPt"           ] = theDir.make<TH2D>( "hist_jetNTracksVsPt"          , "Number of Tracks versus Jet p_{T};Jet p_{T}(GeV/c) ;N_{Tracks}",20, 0, 200, 20, 0, 20 ) ;
   hists["hist_jetEMF"                   ] = theDir.make<TH1D>( "hist_jetEMF"                  , "Jet EMF", 200, 0, 1) ;
   hists["hist_jetPdgID"                 ] = theDir.make<TH1D>( "hist_jetPdgID"                , "PDG Id of Jet Constituents", 10000, 0, 10000 ) ;
   hists["hist_jetGenEmE"                ] = theDir.make<TH1D>( "hist_jetGenEmE"               , "Gen Jet EM Energy", 200, 0, 200 ) ;
   hists["hist_jetGenHadE"               ] = theDir.make<TH1D>( "hist_jetGenHadE"              , "Gen Jet HAD Energy", 200, 0, 200 ) ;
   hists["hist_jetGenEMF"                ] = theDir.make<TH1D>( "hist_jetGenEMF"               , "Gen Jet EMF", 200, 0, 1) ;
   hists["hist_jetEoverGenE"             ] = theDir.make<TH1D>( "hist_jetEoverGenE"            , "Energy of reco Jet / Energy of gen Jet", 200, 0, 2.0) ;
   hists["hist_jetCorr"                  ] = theDir.make<TH1D>( "hist_jetCorr"                 , "Jet Correction Factor", 200, 0, 1.0 ) ;
   hists["hist_n90Hits"                  ] = theDir.make<TH1D>( "hist_n90Hits"                 , "Jet n90Hits", 20, 0, 20) ;
   hists["hist_fHPD"                     ] = theDir.make<TH1D>( "hist_fHPD"                    , "Jet fHPD", 200, 0, 1) ;
   hists["hist_nConstituents"            ] = theDir.make<TH1D>( "hist_nConstituents"           , "Jet nConstituents", 20, 0, 20 ) ;
   hists["hist_jetCHF"                   ] = theDir.make<TH1D>( "hist_jetCHF"                  , "Jet Charged Hadron Fraction", 200, 0, 1.0) ;
                                              
   hists["hist_good_jetPt"             ] = theDir.make<TH1D>( "hist_good_jetPt"            , "Jet p_{T}", 400, 0, 400 ) ;
   hists["hist_good_jetEtaVsPhi"       ] = theDir.make<TH2D>( "hist_good_jetEtaVsPhi"      , "Jet #phi versus #eta;#eta;#phi", 50, -5.0, 5.0, 50, -TMath::Pi(), TMath::Pi() ) ;
   hists["hist_good_jetNTracks"        ] = theDir.make<TH1D>( "hist_good_jetNTracks"       , "Jet N_{TRACKS}", 20, 0, 20 ) ;
   hists["hist_good_jetNTracksVsPt"    ] = theDir.make<TH2D>( "hist_good_jetNTracksVsPt"   , "Number of Tracks versus Jet p_{T};Jet p_{T}(GeV/c) ;N_{Tracks}",20, 0, 200, 20, 0, 20 ) ;
   hists["hist_good_jetEMF"            ] = theDir.make<TH1D>( "hist_good_jetEMF"           , "Jet EMF", 200, 0, 1) ;
   hists["hist_good_jetPdgID"          ] = theDir.make<TH1D>( "hist_good_jetPdgID"         , "PDG Id of Jet Constituents", 10000, 0, 10000 ) ;
   hists["hist_good_jetGenEmE"         ] = theDir.make<TH1D>( "hist_good_jetGenEmE"        , "Gen Jet EM Energy", 200, 0, 200 ) ;
   hists["hist_good_jetGenHadE"        ] = theDir.make<TH1D>( "hist_good_jetGenHadE"       , "Gen Jet HAD Energy", 200, 0, 200 ) ;
   hists["hist_good_jetGenEMF"         ] = theDir.make<TH1D>( "hist_good_jetGenEMF"        , "Gen Jet EMF", 200, 0, 1) ;
   hists["hist_good_jetEoverGenE"      ] = theDir.make<TH1D>( "hist_good_jetEoverGenE"     , "Energy of reco Jet / Energy of gen Jet", 200, 0, 2.0) ;
   hists["hist_good_jetCorr"           ] = theDir.make<TH1D>( "hist_good_jetCorr"          , "Jet Correction Factor", 200, 0, 1.0 ) ;
   hists["hist_good_n90Hits"           ] = theDir.make<TH1D>( "hist_good_n90Hits"          , "Jet n90Hits", 20, 0, 20) ;
   hists["hist_good_fHPD"              ] = theDir.make<TH1D>( "hist_good_fHPD"             , "Jet fHPD", 200, 0, 1) ;
   hists["hist_good_nConstituents"     ] = theDir.make<TH1D>( "hist_good_nConstituents"    , "Jet nConstituents", 20, 0, 20 ) ;
   hists["hist_good_jetCHF"            ] = theDir.make<TH1D>( "hist_good_jetCHF"           , "Jet Charged Hadron Fraction", 200, 0, 1.0) ;
                                                          
                                              
   hists["hist_pf_jetPt"                 ] = theDir.make<TH1D>( "hist_pf_jetPt"                , "PFJet p_{T}", 400, 0, 400 ) ;
   hists["hist_pf_jetEtaVsPhi"           ] = theDir.make<TH2D>( "hist_pf_jetEtaVsPhi"          , "PFJet #phi versus #eta;#eta;#phi", 50, -5.0, 5.0, 50, -TMath::Pi(), TMath::Pi() ) ;
   hists["hist_pf_jetNTracks"            ] = theDir.make<TH1D>( "hist_pf_jetNTracks"           , "PFJet N_{TRACKS}", 20, 0, 20 ) ;
   hists["hist_pf_jetNTracksVsPt"        ] = theDir.make<TH2D>( "hist_pf_jetNTracksVsPt"       , "Number of Tracks versus Jet p_{T};Jet p_{T}(GeV/c) ;N_{Tracks}",20, 0, 200, 20, 0, 20 ) ;
   hists["hist_pf_jetEMF"                ] = theDir.make<TH1D>( "hist_pf_jetEMF"               , "PFJet EMF", 200, 0, 1) ;
   hists["hist_pf_jetCHF"                ] = theDir.make<TH1D>( "hist_pf_jetCHF"               , "PFJet CHF", 200, 0, 1) ;
   hists["hist_pf_jetNHF"                ] = theDir.make<TH1D>( "hist_pf_jetNHF"               , "PFJet NHF", 200, 0, 1) ;
   hists["hist_pf_jetCEF"                ] = theDir.make<TH1D>( "hist_pf_jetCEF"               , "PFJet CEF", 200, 0, 1) ;
   hists["hist_pf_jetNEF"                ] = theDir.make<TH1D>( "hist_pf_jetNEF"               , "PFJet NEF", 200, 0, 1) ;
   hists["hist_pf_jetPdgID"              ] = theDir.make<TH1D>( "hist_pf_jetPdgID"             , "PDG Id of Jet Constituents", 10000, 0, 10000 ) ;
   hists["hist_pf_jetGenEmE"             ] = theDir.make<TH1D>( "hist_pf_jetGenEmE"            , "Gen Jet EM Energy", 200, 0, 200 ) ;
   hists["hist_pf_jetGenHadE"            ] = theDir.make<TH1D>( "hist_pf_jetGenHadE"           , "Gen Jet HAD Energy", 200, 0, 200 ) ;
   hists["hist_pf_jetGenEMF"             ] = theDir.make<TH1D>( "hist_pf_jetGenEMF"            , "Gen Jet EMF", 200, 0, 1) ;
   hists["hist_pf_jetEoverGenE"          ] = theDir.make<TH1D>( "hist_pf_jetEoverGenE"         , "Energy of reco Jet / Energy of gen Jet", 200, 0, 2.0) ;
   hists["hist_pf_jetCorr"               ] = theDir.make<TH1D>( "hist_pf_jetCorr"              , "PFJet Correction Factor", 200, 0, 1.0 ) ;
   hists["hist_pf_nConstituents"         ] = theDir.make<TH1D>( "hist_pf_nConstituents"        , "PFJet nConstituents", 20, 0, 20 ) ;
                                              
   hists["hist_pf_good_jetPt"          ] = theDir.make<TH1D>( "hist_pf_good_jetPt"         , "PFJet p_{T}", 400, 0, 400 ) ;
   hists["hist_pf_good_jetEtaVsPhi"    ] = theDir.make<TH2D>( "hist_pf_good_jetEtaVsPhi"   , "PFJet #phi versus #eta;#eta;#phi", 50, -5.0, 5.0, 50, -TMath::Pi(), TMath::Pi() ) ;
   hists["hist_pf_good_jetNTracks"     ] = theDir.make<TH1D>( "hist_pf_good_jetNTracks"    , "PFJet N_{TRACKS}", 20, 0, 20 ) ;
   hists["hist_pf_good_jetNTracksVsPt" ] = theDir.make<TH2D>( "hist_pf_good_jetNTracksVsPt", "Number of Tracks versus Jet p_{T};Jet p_{T}(GeV/c) ;N_{Tracks}",20, 0, 200, 20, 0, 20 ) ;
   hists["hist_pf_good_jetEMF"         ] = theDir.make<TH1D>( "hist_pf_good_jetEMF"        , "PFJet EMF", 200, 0, 1) ;
   hists["hist_pf_good_jetCHF"         ] = theDir.make<TH1D>( "hist_pf_good_jetCHF"        , "PFJet CHF", 200, 0, 1) ;
   hists["hist_pf_good_jetNHF"         ] = theDir.make<TH1D>( "hist_pf_good_jetNHF"        , "PFJet NHF", 200, 0, 1) ;
   hists["hist_pf_good_jetCEF"         ] = theDir.make<TH1D>( "hist_pf_good_jetCEF"        , "PFJet CEF", 200, 0, 1) ;
   hists["hist_pf_good_jetNEF"         ] = theDir.make<TH1D>( "hist_pf_good_jetNEF"        , "PFJet NEF", 200, 0, 1) ;
   hists["hist_pf_good_jetPdgID"       ] = theDir.make<TH1D>( "hist_pf_good_jetPdgID"      , "PDG Id of Jet Constituents", 10000, 0, 10000 ) ;
   hists["hist_pf_good_jetGenEmE"      ] = theDir.make<TH1D>( "hist_pf_good_jetGenEmE"     , "Gen Jet EM Energy", 200, 0, 200 ) ;
   hists["hist_pf_good_jetGenHadE"     ] = theDir.make<TH1D>( "hist_pf_good_jetGenHadE"    , "Gen Jet HAD Energy", 200, 0, 200 ) ;
   hists["hist_pf_good_jetGenEMF"      ] = theDir.make<TH1D>( "hist_pf_good_jetGenEMF"     , "Gen Jet EMF", 200, 0, 1) ;
   hists["hist_pf_good_jetEoverGenE"   ] = theDir.make<TH1D>( "hist_pf_good_jetEoverGenE"  , "Energy of reco Jet / Energy of gen Jet", 200, 0, 2.0) ;
   hists["hist_pf_good_jetCorr"        ] = theDir.make<TH1D>( "hist_pf_good_jetCorr"       , "PFJet Correction Factor", 200, 0, 1.0 ) ;
   hists["hist_pf_good_nConstituents"  ] = theDir.make<TH1D>( "hist_pf_good_nConstituents" , "PFJet nConstituents", 20, 0, 20 ) ;

   hists["hist_mjj"                           ] = theDir.make<TH1D>( "hist_mjj"                          , "Dijet mass", 300, 0, 300 ) ;
   hists["hist_dR_jj"                         ] = theDir.make<TH1D>( "hist_dR_jj"                        , "#Delta R_{JJ}", 200, 0, TMath::TwoPi() ) ;
   hists["hist_imbalance_jj"                  ] = theDir.make<TH1D>( "hist_imbalance_jj"                 , "Dijet imbalance", 200, -1.0, 1.0 )  ;
                                              
   hists["hist_pf_mjj"                        ] = theDir.make<TH1D>( "hist_pf_mjj"                       , "Dijet mass", 300, 0, 300 ) ;
   hists["hist_pf_dR_jj"                      ] = theDir.make<TH1D>( "hist_pf_dR_jj"                     , "#Delta R_{JJ}", 200, 0, TMath::TwoPi() ) ;
   hists["hist_pf_imbalance_jj"               ] = theDir.make<TH1D>( "hist_pf_imbalance_jj"              , "Dijet imbalance", 200, -1.0, 1.0 )  ;


   
   cout << "Making functors" << endl;
   JetIDStudiesSelector caloSelector( caloJetIDParameters,
                                      pfJetIDParameters,
                                      jetStudiesParams );

   JetIDStudiesSelector pfSelector( caloJetIDParameters,
                                    pfJetIDParameters,
                                    pfJetStudiesParams );

   bool doTracks = plotParameters.getParameter<bool>("doTracks");
   bool useMC    = plotParameters.getParameter<bool>("useMC");

   cout << "About to begin looping" << endl;

  int nev = 0;
  //loop through each event
  for (ev.toBegin(); ! ev.atEnd(); ++ev, ++nev) {


    edm::EventBase const & event = ev;

    if ( runLumiSel(ev) == false ) continue;

    if ( nev % 100 == 0 ) cout << "Processing run " << event.id().run() << ", lumi " << event.id().luminosityBlock() << ", event " << event.id().event() << endl;




    pat::strbitset retCalo = caloSelector.getBitTemplate();
    caloSelector( event, retCalo );


    pat::strbitset retPF = pfSelector.getBitTemplate();
    pfSelector( event, retPF );

    if ( retCalo.test( caloSelector.caloKin() ) ) {
      if ( retCalo.test( caloSelector.caloDeltaPhi() ) ) {
        vector<pat::Jet>  const & allCaloJets = caloSelector.allCaloJets();

        for ( std::vector<pat::Jet>::const_iterator jetBegin = allCaloJets.begin(),
                jetEnd = jetBegin + 2, ijet = jetBegin;
              ijet != jetEnd; ++ijet ) {
        
          const pat::Jet & jet = *ijet;

          double pt = jet.pt();

          const reco::TrackRefVector & jetTracks = jet.associatedTracks();

          hists["hist_jetPt"]->Fill( pt );
          hists["hist_jetEtaVsPhi"]->Fill( jet.eta(), jet.phi() );
          hists["hist_jetNTracks"]->Fill( jetTracks.size() );
          hists["hist_jetNTracksVsPt"]->Fill( pt, jetTracks.size() );
          hists["hist_jetEMF"]->Fill( jet.emEnergyFraction() ); 
          hists["hist_jetCorr"]->Fill( jet.jecFactor("Uncorrected") );
          hists["hist_n90Hits"]->Fill( static_cast<int>(jet.jetID().n90Hits) );
          hists["hist_fHPD"]->Fill( jet.jetID().fHPD );
          hists["hist_nConstituents"]->Fill( jet.nConstituents() );

          if ( useMC && jet.genJet() != 0 ) {
            hists["hist_jetGenEmE"]->Fill( jet.genJet()->emEnergy() );
            hists["hist_jetGenHadE"]->Fill( jet.genJet()->hadEnergy() );
            hists["hist_jetEoverGenE"]->Fill( jet.energy() / jet.genJet()->energy() );
            hists["hist_jetGenEMF"]->Fill( jet.genJet()->emEnergy() / jet.genJet()->energy() );
          }
          if ( doTracks ) {
            TLorentzVector p4_tracks(0,0,0,0);
            for ( reco::TrackRefVector::const_iterator itrk = jetTracks.begin(),
                    itrkEnd = jetTracks.end();
                  itrk != itrkEnd; ++itrk ) {
              TLorentzVector p4_trk;
              double M_PION = 0.140;
              p4_trk.SetPtEtaPhiM( (*itrk)->pt(), (*itrk)->eta(), (*itrk)->phi(), M_PION );
              p4_tracks += p4_trk;
            }
            hists["hist_jetCHF"]->Fill( p4_tracks.Energy() / jet.energy() );
          }

      
        } // end loop over jets

    

        if ( retCalo.test( caloSelector.caloJetID() ) ) {
          pat::Jet const & jet0 = caloSelector.caloJet0();
          pat::Jet const & jet1 = caloSelector.caloJet1();

          TLorentzVector p4_j0( jet0.px(), jet0.py(), jet0.pz(), jet0.energy() );
          TLorentzVector p4_j1( jet1.px(), jet1.py(), jet1.pz(), jet1.energy() );

          TLorentzVector p4_jj = p4_j0 + p4_j1;

          hists["hist_mjj"]->Fill( p4_jj.M() );
          hists["hist_dR_jj"]->Fill( p4_j0.DeltaR( p4_j1 ) );
          hists["hist_imbalance_jj"]->Fill( (p4_j0.Perp() - p4_j1.Perp() ) /
                                                     (p4_j0.Perp() + p4_j1.Perp() ) );

          hists["hist_good_jetPt"]->Fill( jet0.pt() );
          hists["hist_good_jetEtaVsPhi"]->Fill( jet0.eta(), jet0.phi() );
          hists["hist_good_jetNTracks"]->Fill( jet0.associatedTracks().size() );
          hists["hist_good_jetNTracksVsPt"]->Fill( jet0.pt(), jet0.associatedTracks().size() );
          hists["hist_good_jetEMF"]->Fill( jet0.emEnergyFraction() );   
          hists["hist_good_jetCorr"]->Fill( jet0.jecFactor("Uncorrected") );
          hists["hist_good_n90Hits"]->Fill( static_cast<int>(jet0.jetID().n90Hits) );
          hists["hist_good_fHPD"]->Fill( jet0.jetID().fHPD );
          hists["hist_good_nConstituents"]->Fill( jet0.nConstituents() );


          hists["hist_good_jetPt"]->Fill( jet1.pt() );
          hists["hist_good_jetEtaVsPhi"]->Fill( jet1.eta(), jet1.phi() );
          hists["hist_good_jetNTracks"]->Fill( jet1.associatedTracks().size() );
          hists["hist_good_jetNTracksVsPt"]->Fill( jet1.pt(), jet1.associatedTracks().size() );
          hists["hist_good_jetEMF"]->Fill( jet1.emEnergyFraction() );   
          hists["hist_good_jetCorr"]->Fill( jet1.jecFactor("Uncorrected") );
          hists["hist_good_n90Hits"]->Fill( static_cast<int>(jet1.jetID().n90Hits) );
          hists["hist_good_fHPD"]->Fill( jet1.jetID().fHPD );
          hists["hist_good_nConstituents"]->Fill( jet1.nConstituents() );

        }// end if passed calo jet id
      }// end if passed dphi cuts
    }// end if passed kin cuts


    if ( retPF.test( pfSelector.pfDeltaPhi() ) ) {

      vector<pat::Jet> const & allPFJets = pfSelector.allPFJets();

      for ( std::vector<pat::Jet>::const_iterator jetBegin = allPFJets.begin(),
              jetEnd = jetBegin + 2, ijet = jetBegin;
            ijet != jetEnd; ++ijet ) {
        
        const pat::Jet & jet = *ijet;
        
        double pt = jet.pt();
      
        hists["hist_pf_jetPt"]->Fill( pt );
        hists["hist_pf_jetEtaVsPhi"]->Fill( jet.eta(), jet.phi() );
        hists["hist_pf_nConstituents"]->Fill( jet.nConstituents() );
        hists["hist_pf_jetCEF"]->Fill( jet.chargedEmEnergyFraction()  );
        hists["hist_pf_jetNEF"]->Fill( jet.neutralEmEnergyFraction()  );
        hists["hist_pf_jetCHF"]->Fill( jet.chargedHadronEnergyFraction()  );
        hists["hist_pf_jetNHF"]->Fill( jet.neutralHadronEnergyFraction()  );


        if ( useMC && jet.genJet() != 0 ) {
          hists["hist_pf_jetGenEmE"]->Fill( jet.genJet()->emEnergy() );
          hists["hist_pf_jetGenHadE"]->Fill( jet.genJet()->hadEnergy() );
          hists["hist_pf_jetEoverGenE"]->Fill( jet.energy() / jet.genJet()->energy() );

          hists["hist_pf_jetGenEMF"]->Fill( jet.genJet()->emEnergy() / jet.genJet()->energy() );
        }
 
      } // end loop over jets

    

      if ( retPF.test( pfSelector.pfJetID() ) ) {
        pat::Jet const & jet0 = pfSelector.pfJet0();
        pat::Jet const & jet1 = pfSelector.pfJet1();

        TLorentzVector p4_j0( jet0.px(), jet0.py(), jet0.pz(), jet0.energy() );
        TLorentzVector p4_j1( jet1.px(), jet1.py(), jet1.pz(), jet1.energy() );

        TLorentzVector p4_jj = p4_j0 + p4_j1;

        hists["hist_pf_mjj"]->Fill( p4_jj.M() );
        hists["hist_pf_dR_jj"]->Fill( p4_j0.DeltaR( p4_j1 ) );
        hists["hist_pf_imbalance_jj"]->Fill( (p4_j0.Perp() - p4_j1.Perp() ) /
                                                      (p4_j0.Perp() + p4_j1.Perp() ) );

        hists["hist_pf_good_jetPt"]->Fill( jet0.pt() );
        hists["hist_pf_good_jetEtaVsPhi"]->Fill( jet0.eta(), jet0.phi() );
        hists["hist_pf_good_nConstituents"]->Fill( jet0.nConstituents() );
        hists["hist_pf_good_jetCEF"]->Fill( jet0.chargedEmEnergyFraction()  );
        hists["hist_pf_good_jetNEF"]->Fill( jet0.neutralEmEnergyFraction()  );
        hists["hist_pf_good_jetCHF"]->Fill( jet0.chargedHadronEnergyFraction()  );
        hists["hist_pf_good_jetNHF"]->Fill( jet0.neutralHadronEnergyFraction()  );


        hists["hist_pf_good_jetPt"]->Fill( jet1.pt() );
        hists["hist_pf_good_jetEtaVsPhi"]->Fill( jet1.eta(), jet1.phi() );
        hists["hist_pf_good_nConstituents"]->Fill( jet1.nConstituents() );
        hists["hist_pf_good_jetCEF"]->Fill( jet1.chargedEmEnergyFraction()  );
        hists["hist_pf_good_jetNEF"]->Fill( jet1.neutralEmEnergyFraction()  );
        hists["hist_pf_good_jetCHF"]->Fill( jet1.chargedHadronEnergyFraction()  );
        hists["hist_pf_good_jetNHF"]->Fill( jet1.neutralHadronEnergyFraction()  );

      } // end if 2 good PF jets
    
    }// end if delta phi pf cuts
    
  } // end loop over events
    
  cout << "Calo jet selection" << endl;
  caloSelector.print(std::cout);
  cout << "PF jet selection" << endl;
  pfSelector.print(std::cout);




  return 0;
}