CMS 3D CMS Logo

Functions
PatBasicFWLiteJetAnalyzer.cc File Reference
#include <memory>
#include <string>
#include <vector>
#include <sstream>
#include <fstream>
#include <iostream>
#include <TH1F.h>
#include <TROOT.h>
#include <TFile.h>
#include <TSystem.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[] 
)

Definition at line 22 of file PatBasicFWLiteJetAnalyzer.cc.

References fwlite::Event::atEnd(), gather_cfg::cout, FWLiteEnabler::enable(), stringResolutionProvider_cfi::eta, ev, reco::TemplatedSecondaryVertexTagInfo< IPTI, VTX >::flightDistance(), edm::ParameterSet::getParameter(), mps_fire::i, iEvent, BoostedTopProducer_cfi::jetLabel, fwrapper::jets, TFileDirectory::make(), TFileDirectory::mkdir(), reco::TemplatedSecondaryVertexTagInfo< IPTI, VTX >::nVertices(), stringResolutionProvider_cfi::phi, PythonProcessDesc::processDesc(), EnergyCorrector::pt, AlCaHLTBitMon_QueryRunRegistry::string, caloDeepCSVTagInfos_cfi::svTagInfos, align_cfg::TFileService, fwlite::Event::toBegin(), and Measurement1D::value().

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  edm::InputTag jets_ ( fwliteParameters.getParameter<edm::InputTag>("jets") );
51 
52  // book a set of histograms
53  fwlite::TFileService fs = fwlite::TFileService(output_.c_str());
54  TFileDirectory theDir = fs.mkdir("analyzeBasicPat");
55  TH1F* jetPt_ = theDir.make<TH1F>("jetPt", "pt", 100, 0.,300.);
56  TH1F* jetEta_ = theDir.make<TH1F>("jetEta","eta", 100, -3., 3.);
57  TH1F* jetPhi_ = theDir.make<TH1F>("jetPhi","phi", 100, -5., 5.);
58  TH1F* disc_ = theDir.make<TH1F>("disc", "Discriminant", 100, 0.0, 10.0);
59  TH1F* constituentPt_ = theDir.make<TH1F>("constituentPt", "Constituent pT", 100, 0, 300.0);
60 
61  // open input file (can be located on castor)
62  TFile* inFile = TFile::Open(input_.c_str());
63 
64  // ----------------------------------------------------------------------
65  // Second Part:
66  //
67  // * loop the events in the input file
68  // * receive the collections of interest via fwlite::Handle
69  // * fill the histograms
70  // * after the loop close the input file
71  // ----------------------------------------------------------------------
72 
73  // loop the events
74  unsigned int iEvent=0;
75  fwlite::Event ev(inFile);
76  for(ev.toBegin(); !ev.atEnd(); ++ev, ++iEvent){
77  edm::EventBase const & event = ev;
78 
79  // break loop after end of file is reached
80  // or after 1000 events have been processed
81  if( iEvent==1000 ) break;
82 
83  // simple event counter
84  if(iEvent>0 && iEvent%1==0){
85  std::cout << " processing event: " << iEvent << std::endl;
86  }
87 
88  // Handle to the jet collection
91  event.getByLabel(jets_, jets);
92 
93  // loop jet collection and fill histograms
94  for(unsigned i=0; i<jets->size(); ++i){
95  // basic kinematics
96  jetPt_ ->Fill( (*jets)[i].pt() );
97  jetEta_->Fill( (*jets)[i].eta() );
98  jetPhi_->Fill( (*jets)[i].phi() );
99  // access tag infos
100  reco::SecondaryVertexTagInfo const *svTagInfos = (*jets)[i].tagInfoSecondaryVertex("secondaryVertex");
101  if( svTagInfos != 0 ) {
102  if( svTagInfos->nVertices() > 0 ){
103  disc_->Fill( svTagInfos->flightDistance(0).value() );
104  }
105  }
106  // access calo towers
107  std::vector<reco::PFCandidatePtr> const & pfConstituents = (*jets)[i].getPFConstituents();
108  for( std::vector<reco::PFCandidatePtr>::const_iterator ibegin=pfConstituents.begin(), iend=pfConstituents.end(), iconstituent=ibegin; iconstituent!=iend; ++iconstituent){
109  constituentPt_->Fill( (*iconstituent)->pt() );
110  }
111  }
112  }
113  // close input file
114  inFile->Close();
115 
116  // ----------------------------------------------------------------------
117  // Third Part:
118  //
119  // * never forget to free the memory of objects you created
120  // ----------------------------------------------------------------------
121 
122  // in this example there is nothing to do
123 
124  // that's it!
125  return 0;
126 }
T getParameter(std::string const &) const
bool ev
int iEvent
Definition: GenABIO.cc:230
vector< PseudoJet > jets
static void enable()
enable automatic library loading
T * make(const Args &...args) const
make new ROOT object
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
double value() const
Definition: Measurement1D.h:28
Measurement1D flightDistance(unsigned int index, int dim=0) const