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/ParameterSetReader/interface/ProcessDescImpl.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 21 of file PatBasicFWLiteJetAnalyzer.cc.

References fwlite::Event::atEnd(), gather_cfg::cout, FWLiteEnabler::enable(), PVValHelper::eta, ev, reco::TemplatedSecondaryVertexTagInfo< IPTI, VTX >::flightDistance(), edm::ParameterSet::getParameter(), mps_fire::i, iEvent, commonCuts_cff::jetLabel, singleTopDQM_cfi::jets, TFileDirectory::make(), TFileDirectory::mkdir(), reco::TemplatedSecondaryVertexTagInfo< IPTI, VTX >::nVertices(), PVValHelper::phi, PyBind11ProcessDesc::processDesc(), DiDispStaMuonMonitor_cfi::pt, AlCaHLTBitMon_QueryRunRegistry::string, HLT_2018_cff::svTagInfos, align_cfg::TFileService, fwlite::Event::toBegin(), and Measurement1D::value().

21  {
22  // ----------------------------------------------------------------------
23  // First Part:
24  //
25  // * enable FWLite
26  // * book the histograms of interest
27  // * open the input file
28  // ----------------------------------------------------------------------
29 
30  // load framework libraries
31  gSystem->Load("libFWCoreFWLite");
33 
34  // only allow one argument for this simple example which should be the
35  // the python cfg file
36  if (argc < 2) {
37  std::cout << "Usage : " << argv[0] << " [parameters.py]" << std::endl;
38  return 0;
39  }
40 
41  // get the python configuration
42  ProcessDescImpl builder(argv[1]);
43  const edm::ParameterSet& fwliteParameters =
44  builder.processDesc()->getProcessPSet()->getParameter<edm::ParameterSet>("FWLiteParams");
45 
46  // now get each parameter
47  std::string input_(fwliteParameters.getParameter<std::string>("inputFile"));
48  std::string output_(fwliteParameters.getParameter<std::string>("outputFile"));
49  edm::InputTag jets_(fwliteParameters.getParameter<edm::InputTag>("jets"));
50 
51  // book a set of histograms
53  TFileDirectory theDir = fs.mkdir("analyzeBasicPat");
54  TH1F* jetPt_ = theDir.make<TH1F>("jetPt", "pt", 100, 0., 300.);
55  TH1F* jetEta_ = theDir.make<TH1F>("jetEta", "eta", 100, -3., 3.);
56  TH1F* jetPhi_ = theDir.make<TH1F>("jetPhi", "phi", 100, -5., 5.);
57  TH1F* disc_ = theDir.make<TH1F>("disc", "Discriminant", 100, 0.0, 10.0);
58  TH1F* constituentPt_ = theDir.make<TH1F>("constituentPt", "Constituent pT", 100, 0, 300.0);
59 
60  // open input file (can be located on castor)
61  TFile* inFile = TFile::Open(input_.c_str());
62 
63  // ----------------------------------------------------------------------
64  // Second Part:
65  //
66  // * loop the events in the input file
67  // * receive the collections of interest via fwlite::Handle
68  // * fill the histograms
69  // * after the loop close the input file
70  // ----------------------------------------------------------------------
71 
72  // loop the events
73  unsigned int iEvent = 0;
74  fwlite::Event ev(inFile);
75  for (ev.toBegin(); !ev.atEnd(); ++ev, ++iEvent) {
76  edm::EventBase const& event = ev;
77 
78  // break loop after end of file is reached
79  // or after 1000 events have been processed
80  if (iEvent == 1000)
81  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 != nullptr) {
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(),
109  iend = pfConstituents.end(),
110  iconstituent = ibegin;
111  iconstituent != iend;
112  ++iconstituent) {
113  constituentPt_->Fill((*iconstituent)->pt());
114  }
115  }
116  }
117  // close input file
118  inFile->Close();
119 
120  // ----------------------------------------------------------------------
121  // Third Part:
122  //
123  // * never forget to free the memory of objects you created
124  // ----------------------------------------------------------------------
125 
126  // in this example there is nothing to do
127 
128  // that's it!
129  return 0;
130 }
T getParameter(std::string const &) const
bool ev
int iEvent
Definition: GenABIO.cc:224
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:25
Measurement1D flightDistance(unsigned int index, int dim=0) const