source: trunk/test/Example.C@ 8

Last change on this file since 8 was 2, checked in by Pavel Demin, 16 years ago

first commit

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