ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RootMacros/PlottingScript.C
Revision: 1.1
Committed: Sat Sep 6 18:57:17 2008 UTC (16 years, 7 months ago) by anderson
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
Example script of plotting from a TTree

File Contents

# Content
1 {
2 //************************************************
3 // Variables
4
5 TFile *file1 = new TFile("PhotonJet20-200.root");
6 TFile *file2 = new TFile("JetET110.root");
7
8 TTree *tree1, *tree2;
9 file1->GetObject("TreePhotonAndJet",tree1);
10 file2->GetObject("TreePhotonAndJet",tree2);
11
12 TH1F* htemp1 = new TH1F("htemp1","blah",20, 0.0, 1.0);
13 TH1F* htemp2 = new TH1F("htemp2","blah",20, 0.0, 1.0);
14
15 TString thingToDraw1 = "recPhtnMtch.r19";
16 TString thingToDraw2 = thingToDraw1;
17 TString label1 = "#gamma";
18 TString label2 = "jet";
19 TString cutsAll = "recPhtnMtch.et>50&&recPhtnMtch.et<150&&abs(recPhtnMtch.eta)<1.5";
20 TString title = "R19";
21 TString titleX = "E(max) / E(3x3)";
22
23 TString saveFileName = title+".gif";
24 TString saveFileLocation = "/afs/cern.ch/user/a/anderson/www/";
25
26 //************************************************
27
28
29 // Draw from the TTrees
30 tree1->Draw(thingToDraw1+" >> htemp1", cutsAll);
31 tree2->Draw(thingToDraw2+" >> htemp2", cutsAll);
32
33 // Scale the histograms
34 Double_t scale1 = 1/htemp1->Integral();
35 Double_t scale2 = 1/htemp2->Integral();
36 htemp1->Scale(scale1);
37 htemp2->Scale(scale2);
38
39 // Set the histogram colors & lines
40 htemp1->SetLineColor(kRed);
41 htemp2->SetLineColor(kGreen);
42 htemp1->SetLineWidth(2);
43 htemp2->SetLineWidth(2);
44
45 // Turn off Stats Box
46 gStyle->SetOptStat(0);
47
48 // Create TStack but will later draw without stacking
49 THStack *tempStack = new THStack();
50 tempStack->Add(htemp1);
51 tempStack->Add(htemp2);
52
53 // Draw the histogram and titles
54 tempStack->Draw();
55 tempStack->SetTitle(title);
56 tempStack->GetXaxis()->SetTitle(titleX);
57 tempStack->Draw("nostack");
58
59 // Draw the legend
60 TLegend *infoBox = new TLegend(0.74, 0.74, 0.98, 0.98, "");
61 infoBox->AddEntry(htemp1,label1,"L");
62 infoBox->AddEntry(htemp2,label2,"L");
63 infoBox->Draw();
64
65 // Save the canvas
66 c1->SaveAs(saveFileLocation+saveFileName);
67 }