CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
PatCleaningExercise.cc File Reference
#include <vector>
#include "TH1.h"
#include "TFile.h"
#include <TROOT.h>
#include <TSystem.h>
#include "DataFormats/Math/interface/deltaR.h"
#include "DataFormats/FWLite/interface/Event.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/PatCandidates/interface/Jet.h"
#include "FWCore/ParameterSet/interface/ProcessDesc.h"
#include "FWCore/FWLite/interface/FWLiteEnabler.h"
#include "PhysicsTools/FWLite/interface/TFileService.h"
#include "FWCore/PythonParameterSet/interface/PythonProcessDesc.h"

Go to the source code of this file.

Functions

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

Function Documentation

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

CALO JETS


PF JETS

Definition at line 23 of file PatCleaningExercise.cc.

References fwlite::Event::atEnd(), edm::PtrVector< T >::begin(), gather_cfg::cout, deltaR(), reco::deltaR(), FWLiteEnabler::enable(), edm::PtrVector< T >::end(), ev, edm::ParameterSet::getParameter(), iEvent, metsig::jet, fwrapper::jets, TFileDirectory::make(), TFileDirectory::mkdir(), muon::overlap(), analyzePatCleaning_cfg::overlaps, PythonProcessDesc::processDesc(), edm::PtrVectorBase::size(), AlCaHLTBitMon_QueryRunRegistry::string, TrackerOfflineValidation_Standalone_cff::TFileService, and fwlite::Event::toBegin().

23  {
24  // ----------------------------------------------------------------------
25  // First Part:
26  //
27  // * enable FWLite
28  // * book the histograms of interest
29  // * open the input file
30  // ----------------------------------------------------------------------
31 
32  // load framework libraries
33  gSystem->Load( "libFWCoreFWLite" );
35 
36  // only allow one argument for this simple example which should be the
37  // the python cfg file
38  if ( argc < 2 ) {
39  std::cout << "Usage : " << argv[0] << " [parameters.py]" << std::endl;
40  return 0;
41  }
42 
43  // get the python configuration
44  PythonProcessDesc builder(argv[1]);
45  const edm::ParameterSet& fwliteParameters = builder.processDesc()->getProcessPSet()->getParameter<edm::ParameterSet>("FWLiteParams");
46 
47  // now get each parameter
48  std::string input_ ( fwliteParameters.getParameter<std::string >("inputFile" ) );
49  std::string output_ ( fwliteParameters.getParameter<std::string >("outputFile" ) );
50  std::string overlaps_( fwliteParameters.getParameter<std::string >("overlaps") );
51  edm::InputTag jets_ ( fwliteParameters.getParameter<edm::InputTag>("jets" ) );
52 
53  // book a set of histograms
54  fwlite::TFileService fs = fwlite::TFileService(output_.c_str());
55  TFileDirectory theDir = fs.mkdir("analyzePatCleaning");
56  TH1F* emfAllJets_ = theDir.make<TH1F>("emfAllJets" , "f_{emf}(All Jets)" , 20, 0., 1.);
57  TH1F* emfCleanJets_ = theDir.make<TH1F>("emfCleanJets" , "f_{emf}(Clean Jets)" , 20, 0., 1.);
58  TH1F* emfOverlapJets_= theDir.make<TH1F>("emfOverlapJets", "f_{emf}(Overlap Jets)", 20, 0., 1.);
59  TH1F* deltaRElecJet_ = theDir.make<TH1F>("deltaRElecJet" , "#DeltaR (elec, jet)" , 10, 0., 0.5);
60  TH1F* elecOverJet_ = theDir.make<TH1F>("elecOverJet" , "E_{elec}/E_{jet}" , 100, 0., 2.);
61  TH1F* nOverlaps_ = theDir.make<TH1F>("nOverlaps" , "Number of overlaps" , 5, 0., 5.);
62 
63  // open input file (can be located on castor)
64  TFile* inFile = TFile::Open(input_.c_str());
65 
66  // ----------------------------------------------------------------------
67  // Second Part:
68  //
69  // * loop the events in the input file
70  // * receive the collections of interest via fwlite::Handle
71  // * fill the histograms
72  // * after the loop close the input file
73  // ----------------------------------------------------------------------
74 
75  // loop the events
76  unsigned int iEvent=0;
77  fwlite::Event ev(inFile);
78  for(ev.toBegin(); !ev.atEnd(); ++ev, ++iEvent){
79  edm::EventBase const & event = ev;
80 
81  // break loop after end of file is reached
82  // or after 1000 events have been processed
83  if( iEvent==1000 ) break;
84 
85  // simple event counter
86  if(iEvent>0 && iEvent%1==0){
87  std::cout << " processing event: " << iEvent << std::endl;
88  }
89 
90  // handle to jet collection
92  event.getByLabel(jets_, jets);
93 
94  // loop over the jets in the event
95  for( std::vector<pat::Jet>::const_iterator jet = jets->begin(); jet != jets->end(); jet++ ){
96  if(jet->pt()>20 && jet==jets->begin()){
97  emfAllJets_->Fill( jet->emEnergyFraction() );
98  if(! jet->hasOverlaps(overlaps_)){
99  emfCleanJets_->Fill( jet->emEnergyFraction() );
100  }
101  else{
102  //get all overlaps
103  const reco::CandidatePtrVector overlaps = jet->overlaps(overlaps_);
104  nOverlaps_->Fill( overlaps.size() );
105  emfOverlapJets_->Fill( jet->emEnergyFraction() );
106  //loop over the overlaps
107  for( reco::CandidatePtrVector::const_iterator overlap = overlaps.begin(); overlap != overlaps.end(); overlap++){
108  float deltaR = reco::deltaR( (*overlap)->eta(), (*overlap)->phi(), jet->eta(), jet->phi() );
109  deltaRElecJet_->Fill( deltaR );
110  elecOverJet_->Fill( (*overlap)->energy()/jet->energy() );
111  }
112  }
113  }
114  }
115  }
116  inFile->Close();
117  return 0;
118 }
T getParameter(std::string const &) const
size_type size() const
Size of the RefVector.
Definition: PtrVectorBase.h:78
bool ev
double deltaR(const T1 &t1, const T2 &t2)
Definition: deltaR.h:48
const_iterator begin() const
Definition: PtrVector.h:130
bool overlap(const reco::Muon &muon1, const reco::Muon &muon2, double pullX=1.0, double pullY=1.0, bool checkAdjacentChambers=false)
int iEvent
Definition: GenABIO.cc:230
vector< PseudoJet > jets
static void enable()
enable automatic library loading
const_iterator end() const
Definition: PtrVector.h:135
T * make(const Args &...args) const
make new ROOT object
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
tuple argc
Definition: dir2webdir.py:38
tuple cout
Definition: gather_cfg.py:121