#include "Riostream.h" #include "TTimer.h" #include "TROOT.h" #include "TStyle.h" #include "TFile.h" #include "TH1F.h" #include "TH2F.h" #include "TNtuple.h" #include "TCanvas.h" #include "TPad.h" #include "TF1.h" #include "TProfile.h" #include "TLegend.h" Bool_t GetAnswer() { char input; Bool_t done = kFALSE; TTimer *timer = new TTimer("gSystem->ProcessEvents();", 50, kFALSE); //char varin; do { timer->TurnOn(); timer->Reset(); // Now let's read the input, we can use here any // stdio or iostream reading methods. like std::cin >> myinputl; // input = Getline("Type any keys to continue: "); // input = GetLine("Type any keys to continue: "); cout<<"Type c or C keys to continue: "; cin>>input; timer->TurnOff(); // Now usefull stuff with the input! // .... // here were are always done as soon as we get some input! if (input == 'c' || input== 'C' ) done = kTRUE; //if (input) done = kTRUE; } while (!done); return kFALSE; } void ReadNtupleDA() { // Example to read Ntuple and make some selections, it will create some histograms gROOT->Reset(); gStyle->SetOptStat(10); gStyle->SetOptFit(0111); gStyle->SetFrameBorderMode(0); gStyle->SetCanvasBorderMode(0); gStyle->SetPadBorderMode(0); gStyle->SetFrameFillColor(10); gStyle->SetPadColor(10); gStyle->SetCanvasColor(10); gStyle->SetTitleColor(1); gStyle->SetStatColor(10); gStyle->SetFillColor(10); gStyle->SetAxisColor(1); gStyle->SetLabelColor(1); TFile *f = new TFile("run_1.root"); TNtuple *ntuple = (TNtuple*)f->Get("ntuple"); TCanvas * c1 = new TCanvas("c1","The Ntuple canvas",200,10,700,780); // // Inside this canvas, we create 4 pads // TPad * pad1 = new TPad("pad1","This is pad1",0.02,0.52,0.48,0.98,21); TPad * pad2 = new TPad("pad2","This is pad2",0.52,0.52,0.98,0.98,21); TPad * pad3 = new TPad("pad3","This is pad3",0.02,0.02,0.48,0.48,21); TPad * pad4 = new TPad("pad4","This is pad4",0.52,0.02,0.98,0.48,21); pad1->Draw(); pad2->Draw(); pad3->Draw(); pad4->Draw(); c1->Modified(); c1->Update(); // Display adc1 pad1->cd(); pad1->SetGrid(); TH1F *hadc1 = new TH1F("hadc1","hadc1",100,0,255); ntuple->Draw("adc1>>hadc1","adc1>100"); hadc1->SetLineColor(kRed); TH1F *hadc2 = new TH1F("hadc2","hadc2",100,0,255); ntuple->Draw("adc2>>hadc2","adc1>100","same"); TLegend *leg = new TLegend(0.61,0.65,0.99,0.86); leg->AddEntry(hadc1,"adc c1","l"); leg->AddEntry(hadc2,"adc c2","l"); leg->Draw(); c1->Modified(); c1->Update(); GetAnswer(); // Display a scatter plot of two columns (adc1 vs adc2) pad2->cd(); // ntuple->Draw("adc1:adc2>>h1vs2(100,0.,255.,100,0.,255.)","", "lego"); // TH2F *h1vs2 = (TH2F*)gDirectory->Get("h1vs2"); //Alternative way TH2F *h1vs2 = new TH2F("h1vs2","h1vs2",100,0.,255.,100,0.,255.); ntuple->Draw("adc1:adc2>>h1vs2","","lego"); h1vs2->GetXaxis()->SetTitle("adc1"); h1vs2->GetYaxis()->SetTitle("adc2"); h1vs2->GetZaxis()->SetTitle("Counts"); c1->Modified(); c1->Update(); GetAnswer(); // Display a 3D scatter plot of 3 columns pad3->cd(); ntuple->Draw("tdc2:tdc1:tdc3"); c1->Modified(); c1->Update(); GetAnswer(); // Display adc1 and superimpose both a different selection and adc2 pad4->cd(); ntuple->SetLineColor(kRed); ntuple->Draw("adc1"); ntuple->SetLineColor(8); ntuple->Draw("adc1","adc2<100","same"); ntuple->SetLineColor(kBlue+2); ntuple->Draw("adc2","","same"); c1->Modified(); c1->Update(); GetAnswer(); // Display the profile of two columns // The profile histogram produced is saved in the current directory with // the name hprofs TCanvas *c2 = new TCanvas("c2","Profile"); ntuple->Draw("tdc2:tdc1"); c2->Modified(); c2->Update(); GetAnswer(); ntuple->Draw("tdc2:tdc1>>hprofs","","profs"); TProfile *hprofs = (TProfile*)gDirectory->Get("hprofs"); c2->Modified(); c2->Update(); GetAnswer(); hprofs->SetMarkerColor(5); hprofs->SetMarkerSize(0.7); hprofs->SetMarkerStyle(21); hprofs->Fit("pol1","","same"); // //Alternative way // TF1 *f1 = new TF1("f1","[0]+[1]*x",0,500); // f1->SetParameters(1,1); // f1->SetLineWidth(4); // f1->SetLineColor(3); // hprofs->Fit(f1,"","same"); c2->Modified(); c2->Update(); GetAnswer(); // Get pointer to fitted function and modify its attributes TF1 *fpol1 = hprofs->GetFunction("pol1"); fpol1->SetLineWidth(4); fpol1->SetLineColor(3); c2->Modified(); c2->Update(); }