1 | /*
|
---|
2 | Write this to the Terminal
|
---|
3 | root -l examples/Example2.C'("delphes_output.root")'
|
---|
4 | */
|
---|
5 |
|
---|
6 | #include "TH1.h"
|
---|
7 | #include "TSystem.h"
|
---|
8 |
|
---|
9 | #ifdef __CLING__
|
---|
10 | R__LOAD_LIBRARY(libDelphes)
|
---|
11 | #include "classes/DelphesClasses.h"
|
---|
12 | #include "external/ExRootAnalysis/ExRootTreeReader.h"
|
---|
13 | #include "external/ExRootAnalysis/ExRootResult.h"
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | //------------------------------------------------------------------------------
|
---|
17 |
|
---|
18 | struct MyPlots
|
---|
19 | {
|
---|
20 | TH1 *ParticlePT;
|
---|
21 | };
|
---|
22 |
|
---|
23 | //------------------------------------------------------------------------------
|
---|
24 |
|
---|
25 | class ExRootResult;
|
---|
26 | class ExRootTreeReader;
|
---|
27 |
|
---|
28 | //------------------------------------------------------------------------------
|
---|
29 |
|
---|
30 | void BookHistograms(ExRootResult *result, MyPlots *plots)
|
---|
31 | {
|
---|
32 | THStack *stack;
|
---|
33 | TLegend *legend;
|
---|
34 | TPaveText *comment;
|
---|
35 |
|
---|
36 |
|
---|
37 | // book more histograms
|
---|
38 |
|
---|
39 | plots->fParticlePT = result->AddHist1D(
|
---|
40 | "electron_pt", "electron P_{T}",
|
---|
41 | "electron P_{T}, GeV/c", "number of electrons",
|
---|
42 | 50, 0.0, 100.0);
|
---|
43 |
|
---|
44 | // book general comment
|
---|
45 |
|
---|
46 | comment = result->AddComment(0.64, 0.86, 0.98, 0.98);
|
---|
47 | comment->AddText("demonstration plot");
|
---|
48 | comment->AddText("produced by Example2.C");
|
---|
49 |
|
---|
50 | result->Attach(plots->fParticlePT, comment);
|
---|
51 |
|
---|
52 | }
|
---|
53 |
|
---|
54 | //------------------------------------------------------------------------------
|
---|
55 |
|
---|
56 | void AnalyseEvents(ExRootTreeReader *treeReader, MyPlots *plots)
|
---|
57 | {
|
---|
58 | TClonesArray *branchParticle = treeReader->UseBranch("Particle");
|
---|
59 |
|
---|
60 | Long64_t allEntries = treeReader->GetEntries();
|
---|
61 |
|
---|
62 | cout << "** Chain contains " << allEntries << " events" << endl;
|
---|
63 |
|
---|
64 | Particle *particle;
|
---|
65 |
|
---|
66 | Long64_t entry;
|
---|
67 |
|
---|
68 | Int_t i;
|
---|
69 |
|
---|
70 | // Loop over all events
|
---|
71 | for(entry = 0; entry < allEntries; ++entry)
|
---|
72 | {
|
---|
73 | // Load selected branches with data from specified event
|
---|
74 | treeReader->ReadEntry(entry);
|
---|
75 |
|
---|
76 | // Loop over all electrons in event
|
---|
77 | for(i = 0; i < branchParticle->GetEntriesFast(); ++i)
|
---|
78 | {
|
---|
79 | particle = (Particle*) branchParticle->At(i);
|
---|
80 | plots->fParticlePT->Fill(particle->PT);
|
---|
81 | }
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | //------------------------------------------------------------------------------
|
---|
86 |
|
---|
87 | void PrintHistograms(ExRootResult *result, MyPlots *plots)
|
---|
88 | {
|
---|
89 | result->Print("png");
|
---|
90 | }
|
---|
91 |
|
---|
92 | //------------------------------------------------------------------------------
|
---|
93 |
|
---|
94 | void Example2(const char *inputFile)
|
---|
95 | {
|
---|
96 | gSystem->Load("libDelphes");
|
---|
97 |
|
---|
98 | TChain *chain = new TChain("Delphes");
|
---|
99 | chain->Add(inputFile);
|
---|
100 |
|
---|
101 | ExRootTreeReader *treeReader = new ExRootTreeReader(chain);
|
---|
102 | ExRootResult *result = new ExRootResult();
|
---|
103 |
|
---|
104 | MyPlots *plots = new MyPlots;
|
---|
105 |
|
---|
106 | BookHistograms(result, plots);
|
---|
107 |
|
---|
108 | AnalyseEvents(treeReader, plots);
|
---|
109 |
|
---|
110 | PrintHistograms(result, plots);
|
---|
111 |
|
---|
112 | // write into a root file.
|
---|
113 |
|
---|
114 | result->Write("result.root");
|
---|
115 |
|
---|
116 | cout << "** Exiting..." << endl;
|
---|
117 |
|
---|
118 | delete plots;
|
---|
119 | delete result;
|
---|
120 | delete treeReader;
|
---|
121 | delete chain;
|
---|
122 | }
|
---|
123 |
|
---|
124 | //------------------------------------------------------------------------------
|
---|