39 #include "TGraphErrors.h"
46 #include "reportingUtils.hpp"
61 const int* graphColors,
62 const bool drawLegend,
63 const string& graphTitle,
64 const char* drawOption,
65 const string& selectExpr,
66 const string& branchName)
68 for (
unsigned int i = 0;
i < nmbTrees; ++
i)
70 printErr <<
"null pointer to tree[" << i <<
"]. aborting." << endl;
73 string waveNameA, waveNameB;
77 trees[0]->SetBranchAddress(branchName.c_str(), &massBin);
78 trees[0]->GetEntry(0);
79 waveNameA = massBin->
waveName(waveIndexA).Data();
80 waveNameB = massBin->
waveName(waveIndexB).Data();
82 printInfo <<
"plotting coherence of waves '" << waveNameA <<
"' [" << waveIndexA <<
"] "
83 <<
"and '" << waveNameB <<
"' [" << waveIndexB <<
"]" << endl;
85 cout <<
" using selection criterion '" << selectExpr <<
"'" << endl;
88 TMultiGraph* graph =
new TMultiGraph();
90 if (graphTitle !=
"") {
91 graph->SetName (graphTitle.c_str());
92 graph->SetTitle(graphTitle.c_str());
95 name <<
"coherence_" << waveNameA <<
"_" << waveNameB;
97 title <<
"Coherence(" << waveNameA <<
" [" << waveIndexA <<
"], "
98 << waveNameB <<
" [" << waveIndexB <<
"])";
99 graph->SetName(name.str().c_str());
100 graph->SetTitle(title.str().c_str());
105 for (
unsigned int i = 0; i < nmbTrees; ++
i) {
109 trees[
i]->SetBranchAddress(branchName.c_str(), &massBin);
110 trees[
i]->GetEntry(0);
111 const int waveIndexAThisTree = massBin->
waveIndex(waveNameA);
112 const int waveIndexBThisTree = massBin->
waveIndex(waveNameB);
113 if (waveIndexAThisTree < 0) {
114 printInfo <<
"cannot find wave '" << waveNameA <<
"' in tree '" << trees[
i]->GetTitle() <<
"'. "
115 <<
"skipping." << endl;
118 if (waveIndexBThisTree < 0) {
119 printInfo <<
"cannot find wave '" << waveNameB <<
"' in tree '" << trees[
i]->GetTitle() <<
"'. "
120 <<
"skipping." << endl;
125 stringstream drawExpr;
126 drawExpr << branchName <<
".coherence(" << waveIndexAThisTree <<
","
127 << waveIndexBThisTree <<
"):"
128 << branchName <<
".coherenceErr(" << waveIndexAThisTree <<
","
129 << waveIndexBThisTree <<
"):"
130 << branchName <<
".massBinCenter() >> h" << waveIndexAThisTree <<
"_"
131 << waveIndexBThisTree <<
"_" <<
i;
132 cout <<
" running TTree::Draw() expression '" << drawExpr.str() <<
"' "
133 <<
"on tree '" << trees[
i]->GetName() <<
"', '" << trees[
i]->GetTitle() <<
"'" << endl;
134 trees[
i]->Draw(drawExpr.str().c_str(), selectExpr.c_str(),
"goff");
137 const int nmbBins = trees[
i]->GetSelectedRows();
138 vector<double> x(nmbBins), xErr(nmbBins);
139 vector<double> y(nmbBins), yErr(nmbBins);
140 for (
int j = 0; j < nmbBins; ++j) {
141 x [j] = trees[
i]->GetV3()[j] * 0.001;
143 const double val = trees[
i]->GetV1()[j];
144 const double valErr = trees[
i]->GetV2()[j];
145 y [j] = (isnan(val)) ? 0 : val;
146 yErr[j] = (isnan(valErr)) ? 0 : valErr;
148 TGraphErrors* g =
new TGraphErrors(nmbBins,
155 stringstream graphName;
156 graphName << graph->GetName() <<
"_" <<
i;
157 g->SetName (graphName.str().c_str());
158 g->SetTitle(graphName.str().c_str());
159 g->SetMarkerStyle(21);
160 g->SetMarkerSize(0.5);
162 g->SetMarkerColor(graphColors[i]);
163 g->SetLineColor (graphColors[i]);
169 graph->Draw(drawOption);
170 graph->GetXaxis()->SetTitle(
"Mass [GeV]");
171 graph->GetYaxis()->SetTitle(
"Coherence");
172 graph->SetMinimum(-0.2);
173 graph->SetMaximum( 1.2);
176 line.SetLineStyle(3);
177 line.DrawLine(graph->GetXaxis()->GetXmin(), 0, graph->GetXaxis()->GetXmax(), 0);
180 if (drawLegend && (nmbTrees > 1)) {
181 TLegend* legend =
new TLegend(0.65, 0.80, 0.99, 0.99);
182 legend->SetFillColor(10);
183 legend->SetBorderSize(1);
184 legend->SetMargin(0.2);
185 for (
unsigned int i = 0; i < nmbTrees; ++
i) {
186 TGraph* g =
static_cast<TGraph*
>(graph->GetListOfGraphs()->At(i));
187 legend->AddEntry(g, trees[i]->GetTitle(),
"LPE");
194 gPad->SaveAs(((
string)graph->GetName() +
".eps").c_str());