ATLAS Offline Software
Loading...
Searching...
No Matches
TH2TrkProp Class Reference

#include <TH2TrkProp.h>

Collaboration diagram for TH2TrkProp:

Public Member Functions

 TH2TrkProp (const char *format, const char *rootFile, const char *dir, const char *ntuple, const char *xvariable, const char *xvariableName, const char *xunit, const char *yvariable, const char *yvariableName, const char *yunit, const char *cut, const char *cutName, const char *title, int nbinsx, double xlow, double xup, int nbinsy, double ylow, double yup, bool logx, bool logy)
 ~TH2TrkProp ()

Private Member Functions

void setStyle ()

Detailed Description

Definition at line 15 of file TH2TrkProp.h.

Constructor & Destructor Documentation

◆ TH2TrkProp()

TH2TrkProp::TH2TrkProp ( const char * format,
const char * rootFile,
const char * dir,
const char * ntuple,
const char * xvariable,
const char * xvariableName,
const char * xunit,
const char * yvariable,
const char * yvariableName,
const char * yunit,
const char * cut,
const char * cutName,
const char * title,
int nbinsx,
double xlow,
double xup,
int nbinsy,
double ylow,
double yup,
bool logx,
bool logy )

Definition at line 26 of file TH2TrkProp.cxx.

33 {
34
35 gROOT->Reset();
36
37 //new style
38 setStyle();
39
40 //read rootFile
41 TFile* f = new TFile(rootFile,"read");
42 if (f->IsZombie()) {
43 cout<<"Error opening file"<<endl;
44 exit(-1);
45 } else {
46
47
48 //get directory
49 TDirectory* directory = (TDirectory*)f->Get(dir);
50
51 //get ntuple (TTree)
52 TTree* tree = (TTree*)directory->Get(ntuple);
53
54
55 //allocate the necessary memory for string concatenation
56 char* strTitle = new char[200];
57 char* strVarXUnit = new char[200];
58 char* strVarYUnit = new char[200];
59 char* strHist = new char[200];
60 char* strOutput = new char[200];
61 char* strHisto = new char[200];
62
63 //concatenate strings
64 strcat(strcat(strcat(strcpy(strTitle,title)," ("),cutName),")");
65 strcat(strcat(strcpy(strVarXUnit,xvariableName)," "),xunit);
66 strcat(strcat(strcpy(strVarYUnit,yvariableName)," "),yunit);
67 strcat(strcat(strcat(strcpy(strHist,yvariable),":"),xvariable)," >> histo");
68 strcat(strcat(strcat(strcat(strcpy(strOutput,title),"_"),cutName),"."),format);
69 strcat(strcat(strcpy(strHisto,title),"_"),cutName);
70
71 //book 2D-histo from ntuple(TTree)
72 TH2F* histo = new TH2F("histo",strTitle,nbinsx,xlow,xup,nbinsy,ylow,yup);
73
74 histo->GetXaxis()->SetTitle(strVarXUnit);
75 histo->GetYaxis()->SetTitle(strVarYUnit);
76
77
78 //create new canvas
79 TCanvas* canvas = new TCanvas("canvas",title,700,600);
80 canvas->cd();
81
82 if (logx) {
83 canvas->SetLogx();
84 }
85 if (logy) {
86 canvas->SetLogy();
87 }
88
89 //fill 2D-histo
90 tree->Draw(strHist,cut,"colz");
91
92 //clone 1D-histo
93 TH2F* hnew = (TH2F*)histo->Clone();
94 //hnew->SetName(strHisto);
95
96
97 //save 2D-histo to file.format
98 canvas->Print(strOutput);
99
100 //store histograms in root file
101 TFile *histTrkProp = new TFile("histTrkProp.root","update");
102 histTrkProp->cd();
103 hnew->Write(strHisto);
104 histTrkProp->Close();
105
106 //close rootFile
107 f->Close();
108
109 }
110
111}
void setStyle()
bool logy
Definition listroot.cxx:45
str directory
Definition DeMoScan.py:78
TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
TChain * tree

◆ ~TH2TrkProp()

TH2TrkProp::~TH2TrkProp ( )

Definition at line 116 of file TH2TrkProp.cxx.

116 {
117
118 cout<<"deleting TH2TrkProp object"<<endl;
119
120}

Member Function Documentation

◆ setStyle()

void TH2TrkProp::setStyle ( )
private

Definition at line 126 of file TH2TrkProp.cxx.

126 {
127
128 TStyle* style2D = new TStyle("style2D","Style for 2D-Histograms");
129 style2D->cd();
130 //pad
131 style2D->SetPadBorderMode(0);
132 style2D->SetPadColor(0);
133 style2D->SetPadTopMargin(0.21);
134 style2D->SetPadBottomMargin(0.12);
135 style2D->SetPadLeftMargin(0.12);
136 style2D->SetPadRightMargin(0.16);
137 //canvas
138 style2D->SetCanvasColor(0);
139 style2D->SetCanvasBorderMode(0);
140 //frame
141 style2D->SetFrameBorderMode(0);
142 //statistics
143 style2D->SetOptStat(1001110);
144 style2D->SetStatBorderSize(3);
145 style2D->SetStatColor(0);
146 style2D->SetStatFont(62);
147 style2D->SetStatFontSize(0.033);
148 style2D->SetStatTextColor(1);
149 style2D->SetStatStyle(1001);
150 style2D->SetStatX(0.993);
151 style2D->SetStatY(0.995);
152 style2D->SetStatW(0.27);
153 //histograms
154 style2D->SetMarkerColor(1);
155 style2D->SetMarkerStyle(6);
156 //title
157 style2D->SetTitleX(0.010);
158 style2D->SetTitleY(0.93);
159 style2D->SetTitleW(0.7);
160 style2D->SetTitleBorderSize(3);
161 style2D->SetTitleFont(72,"TITLE");
162 //axes
163 style2D->SetLabelFont(62,"X");
164 style2D->SetLabelFont(62,"Y");
165 style2D->SetTitleOffset(1.4,"Y");
166 //palette
167 style2D->SetPalette(1,0);
168
169}

The documentation for this class was generated from the following files: