Logo ROOT   6.16/01
Reference Guide
hist2image.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_image
3/// \notebook
4/// Create an image from a 2-D histogram and manipulate it.
5///
6/// \image html image_hist2image.png
7/// \macro_code
8///
9/// \author Valeriy Onuchin
10
11#include <TAttImage.h>
12
13void hist2image()
14{
15
16 TCanvas *canv = new TCanvas("image", "xygaus + xygaus(5) + xylandau(10)");
17 canv->ToggleEventStatus();
18 canv->SetRightMargin(0.2);
19 canv->SetLeftMargin(0.01);
20 canv->SetTopMargin(0.01);
21 canv->SetBottomMargin(0.01);
22
23 // histogram as image (hist taken from draw2dopt.C)
24 TImage *img = TImage::Create();
25
26 TF2 *f2 = new TF2("f2","(xygaus + xygaus(5) + xylandau(10))",-4,4,-4,4);
27 Double_t params[] = {130,-1.4,1.8,1.5,1, 150,2,0.5,-2,0.5, 3600,-2,0.7,-3,0.3};
28 f2->SetParameters(params);
29 TH2D *h2 = new TH2D("h2","xygaus + xygaus(5) + xylandau(10)",100,-4,4,100,-4,4);
30 h2->FillRandom("f2",40000);
31 img->SetImage((const Double_t *)h2->GetArray(), h2->GetNbinsX() + 2,
32 h2->GetNbinsY() + 2, gHistImagePalette);
33 img->Draw();
34 img->StartPaletteEditor();
35}
double Double_t
Definition: RtypesCore.h:55
R__EXTERN TImagePalette * gHistImagePalette
Definition: TAttImage.h:109
const Double_t * GetArray() const
Definition: TArrayD.h:43
virtual void StartPaletteEditor()
Opens a GUI to edit the color palette.
Definition: TAttImage.cxx:780
virtual void SetBottomMargin(Float_t bottommargin)
Set Pad bottom margin in fraction of the pad height.
Definition: TAttPad.cxx:100
virtual void SetLeftMargin(Float_t leftmargin)
Set Pad left margin in fraction of the pad width.
Definition: TAttPad.cxx:110
virtual void SetRightMargin(Float_t rightmargin)
Set Pad right margin in fraction of the pad width.
Definition: TAttPad.cxx:120
virtual void SetTopMargin(Float_t topmargin)
Set Pad top margin in fraction of the pad height.
Definition: TAttPad.cxx:130
The Canvas class.
Definition: TCanvas.h:31
virtual void ToggleEventStatus()
Toggle event statusbar.
Definition: TCanvas.cxx:2228
virtual void SetParameters(const Double_t *params)
Definition: TF1.h:628
A 2-Dim function with parameters.
Definition: TF2.h:29
virtual Int_t GetNbinsY() const
Definition: TH1.h:293
virtual Int_t GetNbinsX() const
Definition: TH1.h:292
2-D histogram with a double per channel (see TH1 documentation)}
Definition: TH2.h:291
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH2.cxx:597
An abstract interface to image processing library.
Definition: TImage.h:29
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=0)
Definition: TImage.h:116
static TImage * Create()
Create an image.
Definition: TImage.cxx:36
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:195