Fork me on GitHub

source: git/examples/Example2.C@ 374bbcc

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 374bbcc was d7d2da3, checked in by pavel <pavel@…>, 12 years ago

move branches/ModularDelphes to trunk

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2root -l examples/Example2.C\(\"delphes_output.root\"\)
3*/
4
5#include "TH1.h"
6#include "TSystem.h"
7
8//------------------------------------------------------------------------------
9
10struct MyPlots
11{
12 TH1 *fJetPT[2];
13 TH1 *fMissingET;
14 TH1 *fElectronPT;
15};
16
17//------------------------------------------------------------------------------
18
19class ExRootResult;
20class ExRootTreeReader;
21
22//------------------------------------------------------------------------------
23
24void BookHistograms(ExRootResult *result, MyPlots *plots)
25{
26 THStack *stack;
27 TLegend *legend;
28 TPaveText *comment;
29
30 // book 2 histograms for PT of 1st and 2nd leading jets
31
32 plots->fJetPT[0] = result->AddHist1D(
33 "jet_pt_0", "leading jet P_{T}",
34 "jet P_{T}, GeV/c", "number of jets",
35 50, 0.0, 100.0);
36
37 plots->fJetPT[1] = result->AddHist1D(
38 "jet_pt_1", "2nd leading jet P_{T}",
39 "jet P_{T}, GeV/c", "number of jets",
40 50, 0.0, 100.0);
41
42 plots->fJetPT[0]->SetLineColor(kRed);
43 plots->fJetPT[1]->SetLineColor(kBlue);
44
45 // book 1 stack of 2 histograms
46
47 stack = result->AddHistStack("jet_pt_all", "1st and 2nd jets P_{T}");
48 stack->Add(plots->fJetPT[0]);
49 stack->Add(plots->fJetPT[1]);
50
51 // book legend for stack of 2 histograms
52
53 legend = result->AddLegend(0.72, 0.86, 0.98, 0.98);
54 legend->AddEntry(plots->fJetPT[0], "leading jet", "l");
55 legend->AddEntry(plots->fJetPT[1], "second jet", "l");
56
57 // attach legend to stack (legend will be printed over stack in .eps file)
58
59 result->Attach(stack, legend);
60
61 // book more histograms
62
63 plots->fElectronPT = result->AddHist1D(
64 "electron_pt", "electron P_{T}",
65 "electron P_{T}, GeV/c", "number of electrons",
66 50, 0.0, 100.0);
67
68 plots->fMissingET = result->AddHist1D(
69 "missing_et", "Missing E_{T}",
70 "Missing E_{T}, GeV", "number of events",
71 60, 0.0, 30.0);
72
73 // book general comment
74
75 comment = result->AddComment(0.64, 0.86, 0.98, 0.98);
76 comment->AddText("demonstration plot");
77 comment->AddText("produced by Example2.C");
78
79 // attach comment to single histograms
80
81 result->Attach(plots->fJetPT[0], comment);
82 result->Attach(plots->fJetPT[1], comment);
83 result->Attach(plots->fElectronPT, comment);
84
85 // show histogram statisics for MissingET
86 plots->fMissingET->SetStats();
87}
88
89//------------------------------------------------------------------------------
90
91void AnalyseEvents(ExRootTreeReader *treeReader, MyPlots *plots)
92{
93 TClonesArray *branchJet = treeReader->UseBranch("Jet");
94 TClonesArray *branchElectron = treeReader->UseBranch("Electron");
95 TClonesArray *branchMissingET = treeReader->UseBranch("MissingET");
96
97 Long64_t allEntries = treeReader->GetEntries();
98
99 cout << "** Chain contains " << allEntries << " events" << endl;
100
101 Jet *jet[2];
102 MissingET *met;
103 Electron *electron;
104
105 Long64_t entry;
106
107 Int_t i;
108
109 // Loop over all events
110 for(entry = 0; entry < allEntries; ++entry)
111 {
112 // Load selected branches with data from specified event
113 treeReader->ReadEntry(entry);
114
115 // Analyse two leading jets
116 if(branchJet->GetEntriesFast() >= 2)
117 {
118 jet[0] = (Jet*) branchJet->At(0);
119 jet[1] = (Jet*) branchJet->At(1);
120
121 plots->fJetPT[0]->Fill(jet[0]->PT);
122 plots->fJetPT[1]->Fill(jet[1]->PT);
123 }
124
125 // Analyse missing ET
126 if(branchMissingET->GetEntriesFast() > 0)
127 {
128 met = (MissingET*) branchMissingET->At(0);
129 plots->fMissingET->Fill(met->MET);
130 }
131
132 // Loop over all electrons in event
133 for(i = 0; i < branchElectron->GetEntriesFast(); ++i)
134 {
135 electron = (Electron*) branchElectron->At(i);
136 plots->fElectronPT->Fill(electron->PT);
137 }
138 }
139}
140
141//------------------------------------------------------------------------------
142
143void PrintHistograms(ExRootResult *result, MyPlots *plots)
144{
145 result->Print("png");
146}
147
148//------------------------------------------------------------------------------
149
150void Example2(const char *inputFile)
151{
152 gSystem->Load("libDelphes");
153
154 TChain *chain = new TChain("Delphes");
155 chain->Add(inputFile);
156
157 ExRootTreeReader *treeReader = new ExRootTreeReader(chain);
158 ExRootResult *result = new ExRootResult();
159
160 MyPlots *plots = new MyPlots;
161
162 BookHistograms(result, plots);
163
164 AnalyseEvents(treeReader, plots);
165
166 PrintHistograms(result, plots);
167
168 result->Write("results.root");
169
170 cout << "** Exiting..." << endl;
171
172 delete plots;
173 delete result;
174 delete treeReader;
175 delete chain;
176}
177
178//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.