ROOTPWA
plot4.C
Go to the documentation of this file.
1 
2 //
3 // Copyright 2009 Sebastian Neubert
4 //
5 // This file is part of rootpwa
6 //
7 // rootpwa is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // rootpwa is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with rootpwa. If not, see <http://www.gnu.org/licenses/>.
19 //
21 //-----------------------------------------------------------
22 // File and Version Information:
23 // $Id$
24 //
25 // Description:
26 // Creates overview plot with intensities, phase, and coherence
27 // for waves A and B from tree.
28 // layout:
29 // intensity A | phase A - B
30 // ------------+----------------
31 // intensity B | coherence A - B
32 //
33 //
34 // Author List:
35 // Sebastian Neubert TUM (original author)
36 //
37 //
38 //-----------------------------------------------------------
39 
40 
41 #include <sstream>
42 #include <string>
43 
44 #include "TTree.h"
45 #include "TCanvas.h"
46 
47 #include "reportingUtils.hpp"
48 #include "plotIntensity.h"
49 #include "plotPhase.h"
50 #include "plotCoherence.h"
51 
52 
53 using namespace std;
54 using namespace rpwa;
55 
56 
57 // .............................................................................
58 // signature with wave indices
59 void
60 plot4(const unsigned int nmbTrees, // number of fitResult trees
61  TTree** trees, // array of fitResult trees
62  const int waveIndexA, // index of first wave
63  const int waveIndexB, // index of second wave
64  const bool saveEps = false, // if set, EPS file with name wave ID is created
65  const int* graphColors = NULL, // array of colors for graph line and marker
66  const double* graphScales = NULL, // array of scale factors that scale all graphs of one tree
67  const bool drawLegend = true, // if set legend is drawn
68  const std::string& graphTitle = "", // name and title of graph (default is wave IDs)
69  const char* drawOption = "AP", // draw option for graph
70  const double massMin = 0, // [GeV/c^2]
71  const double massMax = 0, // [GeV/c^2]
72  const string& branchName = "fitResult_v2",
73  TCanvas* canvas = NULL) // fill a given canvas instead of creating one (name/title will be changed)
74 {
75  for (unsigned int i = 0; i < nmbTrees; ++i)
76  if (!trees[i]) {
77  printErr << "null pointer to tree[" << i << "]. aborting." << endl;
78  return;
79  }
80 
81  // select mass range; convert from GeV/c^2 to MeV/c^2
82  stringstream selectExpr;
83  if ((massMin != 0) || (massMax != 0))
84  selectExpr << "(massBinCenter() >= "<< massMin * 1000 << ") "
85  << "&& (massBinCenter() <= " << massMax * 1000 << ")";
86 
87  stringstream canvName;
88  canvName << "4plot_" << waveIndexA << "_" << waveIndexB;
89  // create a new canvas if no canvas given to draw into
90  if (!canvas){
91  canvas = new TCanvas(canvName.str().c_str(), canvName.str().c_str(), 10, 10, 1000, 800);
92  } else {
93  canvas->SetName(canvName.str().c_str());
94  canvas->SetTitle(canvName.str().c_str());
95  canvas->SetCanvasSize(1000, 800);
96  }
97  canvas->Divide(2, 2);
98 
99  // wave A intensity
100  canvas->cd(1);
101  plotIntensity(nmbTrees, trees, waveIndexA, false, graphColors, graphScales, drawLegend,
102  graphTitle, drawOption, 1, 0, selectExpr.str(), branchName);
103  // wave A - wave B phase angle
104  canvas->cd(2);
105  plotPhase(nmbTrees, trees, waveIndexA, waveIndexB, false, graphColors, drawLegend,
106  graphTitle, drawOption, selectExpr.str(), branchName);
107  // wave B intensity
108  canvas->cd(3);
109  plotIntensity(nmbTrees, trees, waveIndexB, false, graphColors, graphScales, drawLegend,
110  graphTitle, drawOption, 1, 0, selectExpr.str(), branchName);
111  // wave A - wave B coherence
112  canvas->cd(4);
113  plotCoherence(nmbTrees, trees, waveIndexA, waveIndexB, false, graphColors, drawLegend,
114  graphTitle, drawOption, selectExpr.str(), branchName);
115 
116  // create EPS file
117  if (saveEps)
118  gPad->SaveAs(((string)canvas->GetName() + ".eps").c_str());
119 }
120 
121 
122 void
123 plot4(TTree* tree, // fitResult tree
124  const int waveIndexA, // index of first wave
125  const int waveIndexB, // index of second wave
126  const bool saveEps = false, // if set, EPS file with name wave ID is created
127  const int graphColor = kBlack, // array of colors for graph line and marker
128  const bool drawLegend = false, // if set legend is drawn
129  const string& graphTitle = "", // name and title of graph (default is wave IDs)
130  const char* drawOption = "AP", // draw option for graph
131  const double massMin = 0, // [GeV/c^2]
132  const double massMax = 0, // [GeV/c^2]
133  const string& branchName = "fitResult_v2",
134  TCanvas* canvas = NULL) // fill a given canvas instead of creating one (name/title will be changed)
135 {
136  plot4(1, &tree, waveIndexA, waveIndexB, saveEps, &graphColor, NULL, drawLegend,
137  graphTitle, drawOption, massMin, massMax, branchName, canvas);
138 }
139 
140 
141 // .............................................................................
142 // signature with wave names
143 void
144 plot4(const unsigned int nmbTrees, // number of fitResult trees
145  TTree** trees, // array of fitResult trees
146  const string& waveNameA, // name of first wave
147  const string& waveNameB, // name of second wave
148  const bool saveEps = false, // if set, EPS file with name wave ID is created
149  const int* graphColors = NULL, // array of colors for graph line and marker
150  const double* graphScales = NULL, // array of scale factors that scale all graphs of one tree
151  const bool drawLegend = true, // if set legend is drawn
152  const std::string& graphTitle = "", // name and title of graph (default is wave IDs)
153  const char* drawOption = "AP", // draw option for graph
154  const double massMin = 0, // [GeV/c^2]
155  const double massMax = 0, // [GeV/c^2]
156  const string& branchName = "fitResult_v2")
157 {
158  if (!trees[0]) {
159  printErr << "null pointer to tree. exiting." << endl;
160  return;
161  }
162  // get wave indices (assumes same wave set in all trees)
163  fitResult* massBin = new fitResult();
164  trees[0]->SetBranchAddress(branchName.c_str(), &massBin);
165  trees[0]->GetEntry(0);
166  const int indexA = massBin->waveIndex(waveNameA);
167  const int indexB = massBin->waveIndex(waveNameB);
168  if ((indexA >= 0) && (indexB >= 0))
169  return plot4(nmbTrees, trees, indexA, indexB, saveEps, graphColors, graphScales, drawLegend,
170  graphTitle, drawOption, massMin, massMax, branchName);
171  printErr << "cannot find wave(s) in tree '" << trees[0]->GetName() << "'. exiting." << endl;
172 }
173 
174 
175 void
176 plot4(TTree* tree, // fitResult tree
177  const string& waveNameA, // name of first wave
178  const string& waveNameB, // name of second wave
179  const bool saveEps = false, // if set, EPS file with name wave ID is created
180  const int graphColor = kBlack, // array of colors for graph line and marker
181  const bool drawLegend = false, // if set legend is drawn
182  const string& graphTitle = "", // name and title of graph (default is wave IDs)
183  const char* drawOption = "AP", // draw option for graph
184  const double massMin = 0, // [GeV/c^2]
185  const double massMax = 0, // [GeV/c^2]
186  const string& branchName = "fitResult_v2")
187 {
188  plot4(1, &tree, waveNameA, waveNameB, saveEps, &graphColor, NULL, drawLegend,
189  graphTitle, drawOption, massMin, massMax, branchName);
190 }