ATLAS Offline Software
Loading...
Searching...
No Matches
TH1TrkProp.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3*/
4// $:$Id: TH1TrkProp.cxx, v 1.0 04/17/2006 12:07:07
5// Author: Miguel Angel Olivo Gomez 04/17/06
6
7/*************************************************************************
8 * *
9 * All rights reserved. *
10 * *
11 *************************************************************************/
12
13#include <iostream>
14#include <string.h>
15#include "TStyle.h"
16#include "TFile.h"
17#include "TDirectory.h"
18#include "TTree.h"
19#include "TCanvas.h"
20#include "TH1.h"
21
22#include "TH1TrkProp.h"
23
24
25TH1TrkProp::TH1TrkProp(const char* format, const char* rootFile, const char* dir, const char* ntuple,
26 const char* xvariable, const char* xvariableName, const char* xunit,
27 const char* cut, const char* cutName, const char* title, int nbinsx,
28 double xlow, double xup, bool logy, bool fitGauss
29 ) {
30
31 gROOT->Reset();
32
33 //new style
34 setStyle(fitGauss);
35
36 //read rootFile
37 TFile* f = new TFile(rootFile,"read");
38 if (f->IsZombie()) {
39 cout<<"Error opening file"<<endl;
40 exit(-1);
41 } else {
42
43
44 //get directory
45 TDirectory* directory = (TDirectory*)f->Get(dir);
46
47 //get ntuple (TTree)
48 TTree* tree = (TTree*)directory->Get(ntuple);
49
50 //allocate the necessary memory for string concatenation
51 char* strTitle = new char[200];
52 char* strVarXUnit = new char[200];
53 char* strHist = new char[200];
54 char* strOutput = new char[200];
55 char* strHisto = new char[200];
56
57 //concatenate strings
58 strcat(strcat(strcat(strcpy(strTitle,title)," ("),cutName),")");
59 strcat(strcat(strcpy(strVarXUnit,xvariableName)," "),xunit);
60 strcat(strcpy(strHist,xvariable)," >> histo");
61 strcat(strcat(strcat(strcat(strcpy(strOutput,title),"_"),cutName),"."),format);
62 strcat(strcat(strcpy(strHisto,title),"_"),cutName);
63
64 //book 1D histo from ntuple(TTree)
65 TH1F* histo = new TH1F("histo",strTitle,nbinsx,xlow,xup);
66
67 histo->GetXaxis()->SetTitle(strVarXUnit);
68 histo->GetYaxis()->SetTitle("Entries");
69
70
71 //create new canvas
72 TCanvas* canvas = new TCanvas("canvas",title,700,600);
73 canvas->cd();
74
75 if (logy) {
76 canvas->SetLogy();
77 }
78
79 //fill 1D histo
80 tree->Draw(strHist,cut,"E");
81
82 //clone 1D histo
83 TH1F* hnew = (TH1F*)histo->Clone();
84 //hnew->SetName(strHisto);
85 //hnew->Sumw2();
86
87 if (fitGauss){
88 histo->Fit("gaus");
89 }
90
91 //save 1D-histo to file.format
92 canvas->Print(strOutput);
93
94 //store histograms in root file
95 TFile *histTrkProp = new TFile("histTrkProp.root","update");
96 histTrkProp->cd();
97 hnew->Write(strHisto);
98 histTrkProp->Close();
99
100 //close rootFile
101 f->Close();
102
103 }
104
105}
106
107
108
109//___________________________________________________________________________________
111
112 cout<<"deleting TH1TrkProp object"<<endl;
113
114}
115
116
117
118//____________________________________________________________________________________
119
120void TH1TrkProp::setStyle(bool fitGauss) {
121 TStyle* style1D = new TStyle("style1D","Style for 1D-Histograms");
122 style1D->cd();
123 //pad
124 style1D->SetPadBorderMode(0);
125 style1D->SetPadColor(0);
126 style1D->SetPadTopMargin(0.21);
127 style1D->SetPadBottomMargin(0.12);
128 style1D->SetPadLeftMargin(0.12);
129 style1D->SetPadRightMargin(0.07);
130 //canvas
131 style1D->SetCanvasColor(0);
132 style1D->SetCanvasBorderMode(0);
133 //frame
134 style1D->SetFrameBorderMode(0);
135 //statistics
136 style1D->SetOptStat(1111110);
137 style1D->SetStatBorderSize(3);
138 style1D->SetStatColor(0);
139 style1D->SetStatFont(62);
140 style1D->SetStatFontSize(0.033);
141 style1D->SetStatTextColor(1);
142 style1D->SetStatStyle(1001);
143 style1D->SetStatX(0.993);
144 style1D->SetStatY(0.995);
145 style1D->SetStatW(0.27);
146 //histograms
147 style1D->SetMarkerColor(1);
148 style1D->SetMarkerStyle(20);
149 style1D->SetMarkerSize(0.8);
150 //title
151 style1D->SetTitleX(0.010);
152 style1D->SetTitleY(0.93);
153 style1D->SetTitleW(0.7);
154 style1D->SetTitleBorderSize(3);
155 style1D->SetTitleFont(72,"TITLE");
156 //axes
157 style1D->SetLabelFont(62,"X");
158 style1D->SetLabelFont(62,"Y");
159 style1D->SetTitleOffset(1.3,"Y");
160 //fitGauss
161 if (fitGauss){
162 style1D->SetStatFontSize(0.03);
163 style1D->SetStatW(0.2);
164 style1D->SetTitleW(0.6);
165 style1D->SetOptFit(1111);
166 }
167
168}
169
170
171
172
173
void setStyle(bool fitGauss)
TH1TrkProp(const char *format, const char *rootFile, const char *dir, const char *ntuple, const char *xvariable, const char *xvariableName, const char *xunit, const char *cut, const char *cutName, const char *title, int nbinsx, double xlow, double xup, bool logy, bool fitGaus)
bool logy
Definition listroot.cxx:45
TChain * tree