CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PatBasicFWLiteJetUnitTest.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <string>
3 #include <vector>
4 #include <sstream>
5 #include <fstream>
6 #include <iostream>
7 
8 #include <TH1F.h>
9 #include <TROOT.h>
10 #include <TFile.h>
11 #include <TSystem.h>
12 
18 #include "TStopwatch.h"
19 
20 int main(int argc, char* argv[]) {
21  // ----------------------------------------------------------------------
22  // First Part:
23  //
24  // * enable FWLite
25  // * book the histograms of interest
26  // * open the input file
27  // ----------------------------------------------------------------------
28 
29  if (argc < 4)
30  return 0;
31 
32  // load framework libraries
33  gSystem->Load("libFWCoreFWLite");
35 
36  // book a set of histograms
38  TFileDirectory theDir = fs.mkdir("analyzeBasicPat");
39  TH1F* jetPt_ = theDir.make<TH1F>("jetPt", "pt", 100, 0., 300.);
40  TH1F* jetEta_ = theDir.make<TH1F>("jetEta", "eta", 100, -3., 3.);
41  TH1F* jetPhi_ = theDir.make<TH1F>("jetPhi", "phi", 100, -5., 5.);
42  TH1F* disc_ = theDir.make<TH1F>("disc", "Discriminant", 100, 0.0, 10.0);
43  TH1F* constituentPt_ = theDir.make<TH1F>("constituentPt", "Constituent pT", 100, 0, 300.0);
44 
45  // open input file (can be located on castor)
46  TFile* inFile = TFile::Open(argv[1]);
47 
48  // ----------------------------------------------------------------------
49  // Second Part:
50  //
51  // * loop the events in the input file
52  // * receive the collections of interest via fwlite::Handle
53  // * fill the histograms
54  // * after the loop close the input file
55  // ----------------------------------------------------------------------
56 
57  // loop the events
58  unsigned int iEvent = 0;
60  TStopwatch timer;
61  timer.Start();
62 
63  unsigned int nEventsAnalyzed = 0;
64  for (ev.toBegin(); !ev.atEnd(); ++ev, ++iEvent) {
65  edm::EventBase const& event = ev;
66 
67  // Handle to the jet collection
70  event.getByLabel(jetLabel, jets);
71 
72  // loop jet collection and fill histograms
73  for (unsigned i = 0; i < jets->size(); ++i) {
74  jetPt_->Fill((*jets)[i].pt());
75  jetEta_->Fill((*jets)[i].eta());
76  jetPhi_->Fill((*jets)[i].phi());
77  reco::SecondaryVertexTagInfo const* svTagInfos = (*jets)[i].tagInfoSecondaryVertex("secondaryVertex");
78  if (svTagInfos != nullptr) {
79  if (svTagInfos->nVertices() > 0)
80  disc_->Fill(svTagInfos->flightDistance(0).value());
81  }
82  std::vector<CaloTowerPtr> const& caloConstituents = (*jets)[i].getCaloConstituents();
83  for (std::vector<CaloTowerPtr>::const_iterator ibegin = caloConstituents.begin(),
84  iend = caloConstituents.end(),
85  iconstituent = ibegin;
86  iconstituent != iend;
87  ++iconstituent) {
88  constituentPt_->Fill((*iconstituent)->pt());
89  }
90  }
91  ++nEventsAnalyzed;
92  }
93  // close input file
94  inFile->Close();
95 
96  timer.Stop();
97 
98  // print some timing statistics
99  Double_t rtime = timer.RealTime();
100  Double_t ctime = timer.CpuTime();
101  printf("Analyzed events: %d \n", nEventsAnalyzed);
102  printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime);
103  printf("%4.2f events / RealTime second .\n", (double)nEventsAnalyzed / rtime);
104  printf("%4.2f events / CpuTime second .\n", (double)nEventsAnalyzed / ctime);
105 
106  // ----------------------------------------------------------------------
107  // Third Part:
108  //
109  // * never forget to free the memory of objects you created
110  // ----------------------------------------------------------------------
111 
112  // in this example there is nothing to do
113 
114  // that's it!
115  return 0;
116 }
T * make(const Args &...args) const
make new ROOT object
int iEvent
Definition: GenABIO.cc:224
static void enable()
enable automatic library loading
int main(int argc, char *argv[])