ATLAS Offline Software
TH2TrkProp.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: TH2TrkProp.cxx, v 1.0 04/17/2006 17: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 #include "TH2.h"
22 
23 #include "TH2TrkProp.h"
24 
25 
26 TH2TrkProp::TH2TrkProp(const char* format, const char* rootFile, const char* dir, const char* ntuple,
27  const char* xvariable, const char* xvariableName, const char* xunit,
28  const char* yvariable, const char* yvariableName, const char* yunit,
29  const char* cut, const char* cutName, const char* title,
30  int nbinsx, double xlow, double xup,
31  int nbinsy, double ylow, double yup,
32  bool logx, bool logy
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 }
112 
113 
114 
115 //___________________________________________________________________________________
117 
118  cout<<"deleting TH2TrkProp object"<<endl;
119 
120 }
121 
122 
123 
124 //____________________________________________________________________________________
125 
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 }
170 
171 
172 
173 
174 
175 
176 
vtune_athena.format
format
Definition: vtune_athena.py:14
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: TH2TrkProp.cxx:26
tree
TChain * tree
Definition: tile_monitor.h:30
TH2TrkProp::~TH2TrkProp
~TH2TrkProp()
Definition: TH2TrkProp.cxx:116
TH2TrkProp.h
python.TrigEgammaMonitorHelper.TH2F
def TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:45
logy
bool logy
Definition: listroot.cxx:45
DeMoScan.directory
string directory
Definition: DeMoScan.py:80
DeMoAtlasDataLoss.canvas
dictionary canvas
Definition: DeMoAtlasDataLoss.py:187
covarianceTool.title
title
Definition: covarianceTool.py:542
BindingsTest.cut
cut
This script demonstrates how to call a C++ class from Python Also how to use PyROOT is shown.
Definition: BindingsTest.py:13
makeComparison.rootFile
rootFile
Definition: makeComparison.py:27
hist_file_dump.f
f
Definition: hist_file_dump.py:135
calibdata.exit
exit
Definition: calibdata.py:236
beamspotman.dir
string dir
Definition: beamspotman.py:623
TH2TrkProp::setStyle
void setStyle()
Definition: TH2TrkProp.cxx:126
plotBeamSpotCompare.histo
histo
Definition: plotBeamSpotCompare.py:415