Fork me on GitHub

source: git/examples/Example1.C@ f25215c

ImprovedOutputFile Timing dual_readout llp
Last change on this file since f25215c was c9803f7, checked in by Pavel Demin <pavel.demin@…>, 9 years ago

adapt examples to ROOT 6.04

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/*
2Simple macro showing how to access branches from the delphes output root file,
3loop over events, and plot simple quantities such as the jet pt and the di-electron invariant
4mass.
5
6root -l examples/Example1.C'("delphes_output.root")'
7*/
8
9#ifdef __CLING__
10R__LOAD_LIBRARY(libDelphes)
11#include "classes/DelphesClasses.h"
12#include "external/ExRootAnalysis/ExRootTreeReader.h"
13#endif
14
15//------------------------------------------------------------------------------
16
17void Example1(const char *inputFile)
18{
19 gSystem->Load("libDelphes");
20
21 // Create chain of root trees
22 TChain chain("Delphes");
23 chain.Add(inputFile);
24
25 // Create object of class ExRootTreeReader
26 ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
27 Long64_t numberOfEntries = treeReader->GetEntries();
28
29 // Get pointers to branches used in this analysis
30 TClonesArray *branchJet = treeReader->UseBranch("Jet");
31 TClonesArray *branchElectron = treeReader->UseBranch("Electron");
32
33 // Book histograms
34 TH1 *histJetPT = new TH1F("jet_pt", "jet P_{T}", 100, 0.0, 100.0);
35 TH1 *histMass = new TH1F("mass", "M_{inv}(e_{1}, e_{2})", 100, 40.0, 140.0);
36
37 // Loop over all events
38 for(Int_t entry = 0; entry < numberOfEntries; ++entry)
39 {
40 // Load selected branches with data from specified event
41 treeReader->ReadEntry(entry);
42
43 // If event contains at least 1 jet
44 if(branchJet->GetEntries() > 0)
45 {
46 // Take first jet
47 Jet *jet = (Jet*) branchJet->At(0);
48
49 // Plot jet transverse momentum
50 histJetPT->Fill(jet->PT);
51
52 // Print jet transverse momentum
53 cout << "Jet pt: "<<jet->PT << endl;
54 }
55
56 Electron *elec1, *elec2;
57
58 // If event contains at least 2 electrons
59 if(branchElectron->GetEntries() > 1)
60 {
61 // Take first two electrons
62 elec1 = (Electron *) branchElectron->At(0);
63 elec2 = (Electron *) branchElectron->At(1);
64
65 // Plot their invariant mass
66 histMass->Fill(((elec1->P4()) + (elec2->P4())).M());
67 }
68 }
69
70 // Show resulting histograms
71 histJetPT->Draw();
72 histMass->Draw();
73}
74
Note: See TracBrowser for help on using the repository browser.