CMS 3D CMS Logo

Functions
TopJetFWLiteAnalyzer.cc File Reference
#include <memory>
#include <string>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <iostream>
#include "FWCore/FWLite/interface/FWLiteEnabler.h"
#include "DataFormats/PatCandidates/interface/Jet.h"
#include "TopQuarkAnalysis/Examples/bin/NiceStyle.cc"
#include "TopQuarkAnalysis/Examples/interface/RootSystem.h"
#include "TopQuarkAnalysis/Examples/interface/RootHistograms.h"
#include "TopQuarkAnalysis/Examples/interface/RootPostScript.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 16 of file TopJetFWLiteAnalyzer.cc.

References beam_dqm_sourceclient-live_cfg::cerr, gather_cfg::cout, FWLiteEnabler::enable(), HCALHighEnergyHPDFilter_cfi::energy, PVValHelper::eta, b2gHadronicHLTEventValidation_cfi::etaJets, training_settings::idx, singleTopDQM_cfi::jets, nevt, L1TdeCSCTF_cfi::outFile, PVValHelper::phi, DiDispStaMuonMonitor_cfi::pt, and setNiceStyle().

16  {
17  if (argc < 3) {
18  // -------------------------------------------------
19  std::cerr << "ERROR:: "
20  << "Wrong number of arguments! Please specify:" << std::endl
21  << " * filepath" << std::endl
22  << " * process name" << std::endl;
23  // -------------------------------------------------
24  return -1;
25  }
26 
27  // load framework libraries
28  gSystem->Load("libFWCoreFWLite");
30 
31  // set nice style for histograms
32  setNiceStyle();
33 
34  // define some histograms
35  TH1I* noJets = new TH1I("noJets", "N_{Jets}", 10, 0, 10);
36  TH1F* ptJets = new TH1F("ptJets", "pt_{Jets}", 100, 0., 300.);
37  TH1F* enJets = new TH1F("enJets", "energy_{Jets}", 100, 0., 300.);
38  TH1F* etaJets = new TH1F("etaJets", "eta_{Jets}", 100, -3., 3.);
39  TH1F* phiJets = new TH1F("phiJets", "phi_{Jets}", 100, -5., 5.);
40 
41  // -------------------------------------------------
42  std::cout << "open file: " << argv[1] << std::endl;
43  // -------------------------------------------------
44  TFile* inFile = TFile::Open(argv[1]);
45  TTree* events_ = nullptr;
46  if (inFile)
47  inFile->GetObject("Events", events_);
48  if (events_ == nullptr) {
49  // -------------------------------------------------
50  std::cerr << "ERROR:: "
51  << "Unable to retrieve TTree Events!" << std::endl
52  << " Eighter wrong file name or the the tree doesn't exists" << std::endl;
53  // -------------------------------------------------
54  return -1;
55  }
56 
57  // acess branch of elecs
58  char jetsName[50];
59  sprintf(jetsName, "patJets_selectedPatJets__%s.obj", argv[2]);
60  TBranch* jets_ = events_->GetBranch(jetsName);
61  assert(jets_ != nullptr);
62 
63  // loop over events and fill histograms
64  std::vector<pat::Jet> jets;
65  int nevt = events_->GetEntries();
66 
67  // -------------------------------------------------
68  std::cout << "start looping " << nevt << " events..." << std::endl;
69  // -------------------------------------------------
70  for (int evt = 0; evt < nevt; ++evt) {
71  // set branch address
72  jets_->SetAddress(&jets);
73  // get event
74  jets_->GetEntry(evt);
75  events_->GetEntry(evt, 0);
76 
77  // -------------------------------------------------
78  if (evt > 0 && !(evt % 10))
79  std::cout << " processing event: " << evt << std::endl;
80  // -------------------------------------------------
81 
82  // fill histograms
83  noJets->Fill(jets.size());
84  for (unsigned idx = 0; idx < jets.size(); ++idx) {
85  // fill histograms
86  ptJets->Fill(jets[idx].pt());
87  enJets->Fill(jets[idx].energy());
88  etaJets->Fill(jets[idx].eta());
89  phiJets->Fill(jets[idx].phi());
90  }
91  }
92  // -------------------------------------------------
93  std::cout << "close file" << std::endl;
94  // -------------------------------------------------
95  inFile->Close();
96 
97  // save histograms to file
98  TFile outFile("analyzeJets.root", "recreate");
99  outFile.mkdir("analyzeJet");
100  outFile.cd("analyzeJet");
101  noJets->Write();
102  ptJets->Write();
103  enJets->Write();
104  etaJets->Write();
105  phiJets->Write();
106  outFile.Close();
107 
108  // free allocated space
109  delete noJets;
110  delete ptJets;
111  delete enJets;
112  delete etaJets;
113  delete phiJets;
114 
115  return 0;
116 }
void setNiceStyle()
Definition: NiceStyle.cc:3
static void enable()
enable automatic library loading