00001 #include "TCanvas.h"
00002 #include "TFile.h"
00003 #include "TNtuple.h"
00004 #include "TProfile.h"
00005 #include "TBenchmark.h"
00006 #include "TStyle.h"
00007 #include "TPaveText.h"
00008 #include "TFrame.h"
00009 #include "TF1.h"
00010 #include "TROOT.h"
00011 #include "TSystem.h"
00012 #include "TInterpreter.h"
00013
00014 void ntuple1() {
00015
00016
00017
00018
00019
00020 delete gROOT->GetListOfFiles()->FindObject("hsimple.root");
00021 delete gROOT->GetListOfCanvases()->FindObject("c1");
00022
00023 gBenchmark->Start("ntuple1");
00024
00025
00026
00027 TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
00028 dir.ReplaceAll("ntuple1.C","../hsimple.C");
00029 dir.ReplaceAll("/./","/");
00030 if (gBenchmark->GetBench("hsimple") < 0) gInterpreter->LoadMacro(dir.Data());
00031 TFile *f1 = (TFile*)gROOT->ProcessLineFast("hsimple(1)");
00032 if (!f1) return;
00033
00034
00035
00036 TCanvas *c1 = new TCanvas("c1","The Ntuple canvas",200,10,700,780);
00037 TPad *pad1 = new TPad("pad1","This is pad1",0.02,0.52,0.48,0.98,21);
00038 TPad *pad2 = new TPad("pad2","This is pad2",0.52,0.52,0.98,0.98,21);
00039 TPad *pad3 = new TPad("pad3","This is pad3",0.02,0.02,0.48,0.48,21);
00040 TPad *pad4 = new TPad("pad4","This is pad4",0.52,0.02,0.98,0.48,1);
00041 pad1->Draw();
00042 pad2->Draw();
00043 pad3->Draw();
00044 pad4->Draw();
00045
00046
00047 gStyle->SetStatW(0.30);
00048 gStyle->SetStatH(0.20);
00049 gStyle->SetStatColor(42);
00050
00051
00052
00053 pad1->cd();
00054 pad1->SetGrid();
00055 pad1->SetLogy();
00056 pad1->GetFrame()->SetFillColor(15);
00057 TNtuple *ntuple = (TNtuple*)f1->Get("ntuple");
00058 ntuple->SetLineColor(1);
00059 ntuple->SetFillStyle(1001);
00060 ntuple->SetFillColor(45);
00061 ntuple->Draw("3*px+2","px**2+py**2>1");
00062 ntuple->SetFillColor(38);
00063 ntuple->Draw("2*px+2","pz>2","same");
00064 ntuple->SetFillColor(5);
00065 ntuple->Draw("1.3*px+2","(px^2+py^2>4) && py>0","same");
00066 pad1->RedrawAxis();
00067
00068
00069
00070
00071 pad2->cd();
00072 pad2->SetGrid();
00073 pad2->GetFrame()->SetFillColor(32);
00074 ntuple->Draw("pz:px>>hprofs","","goffprofs");
00075 TProfile *hprofs = (TProfile*)gDirectory->Get("hprofs");
00076 hprofs->SetMarkerColor(5);
00077 hprofs->SetMarkerSize(0.7);
00078 hprofs->SetMarkerStyle(21);
00079 hprofs->Fit("pol2");
00080
00081 TF1 *fpol2 = hprofs->GetFunction("pol2");
00082 fpol2->SetLineWidth(4);
00083 fpol2->SetLineColor(2);
00084
00085
00086
00087 pad3->cd();
00088 pad3->GetFrame()->SetFillColor(38);
00089 pad3->GetFrame()->SetBorderSize(8);
00090 ntuple->SetMarkerColor(1);
00091 ntuple->Draw("py:px","pz>1");
00092 ntuple->SetMarkerColor(2);
00093 ntuple->Draw("py:px","pz<1","same");
00094
00095
00096 pad4->cd();
00097 ntuple->Draw("pz:py:px","(pz<10 && pz>6)+(pz<4 && pz>3)");
00098 ntuple->SetMarkerColor(4);
00099 ntuple->Draw("pz:py:px","pz<6 && pz>4","same");
00100 ntuple->SetMarkerColor(5);
00101 ntuple->Draw("pz:py:px","pz<4 && pz>3","same");
00102 TPaveText *l4 = new TPaveText(-0.9,0.5,0.9,0.95);
00103 l4->SetFillColor(42);
00104 l4->SetTextAlign(12);
00105 l4->AddText("You can interactively rotate this view in 2 ways:");
00106 l4->AddText(" - With the RotateCube in clicking in this pad");
00107 l4->AddText(" - Selecting View with x3d in the View menu");
00108 l4->Draw();
00109
00110 c1->cd();
00111 c1->Update();
00112 gStyle->SetStatColor(19);
00113 gBenchmark->Show("ntuple1");
00114 }