CMS 3D CMS Logo

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;
59  fwlite::Event ev(inFile);
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 }
TFileService.h
TFileDirectory::mkdir
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileDirectory.cc:112
Handle.h
cmsBatch.argv
argv
Definition: cmsBatch.py:279
mps_fire.i
i
Definition: mps_fire.py:428
dir2webdir.argc
argc
Definition: dir2webdir.py:39
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
TFileDirectory::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileDirectory.h:53
reco::TemplatedSecondaryVertexTagInfo
Definition: TemplatedSecondaryVertexTagInfo.h:47
singleTopDQM_cfi.jets
jets
Definition: singleTopDQM_cfi.py:42
TFileDirectory
Definition: TFileDirectory.h:24
align_cfg.TFileService
TFileService
Definition: align_cfg.py:143
edm::Handle
Definition: AssociativeIterator.h:50
HLT_FULL_cff.svTagInfos
svTagInfos
Definition: HLT_FULL_cff.py:52116
commonCuts_cff.jetLabel
jetLabel
Definition: commonCuts_cff.py:15
PVValHelper::eta
Definition: PVValidationHelpers.h:69
FWLiteEnabler::enable
static void enable()
enable automatic library loading
Definition: FWLiteEnabler.cc:46
PVValHelper::phi
Definition: PVValidationHelpers.h:68
iEvent
int iEvent
Definition: GenABIO.cc:224
Jet.h
fwlite::Event
Definition: Event.h:87
Event.h
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
edm::EventBase
Definition: EventBase.h:46
fwlite::TFileService
Definition: TFileService.h:12
main
int main(int argc, char *argv[])
Definition: PatBasicFWLiteJetUnitTest.cc:20
edm::InputTag
Definition: InputTag.h:15
FWLiteEnabler.h