45 #include "TMultiGraph.h"
46 #include "TGraphErrors.h"
51 #include "reportingUtils.hpp"
60 vector<pair<string, TVirtualPad*> >
64 const double yAxisRangeMax,
65 const bool drawLegend,
66 const string& outFileName,
67 const string& branchName)
69 vector<pair<string, TVirtualPad*> > wavePads;
71 for (
unsigned int i = 0;
i < nmbTrees; ++
i)
73 printErr <<
"null pointer to tree " << i <<
". exiting." << endl;
77 TFile* outFile = NULL;
78 if (outFileName !=
"")
79 outFile = TFile::Open(outFileName.c_str(),
"RECREATE");
80 if (!outFile || outFile->IsZombie()) {
81 printErr <<
"could not create file '" << outFileName <<
"'. exiting." << endl;
85 const unsigned int nmbPadsPerCanvMin = 6;
87 const string waves[] = {
"logLikelihood",
154 const unsigned int nmbWaves =
sizeof(waves) /
sizeof(
string);
155 printInfo <<
"plotting spin totals for:" << endl;
156 for (
unsigned int i = 0; i < nmbWaves; ++
i)
157 cout <<
" " << ((waves[i] !=
"") ? waves[
i] :
"total") << endl;
160 gStyle->SetOptStat(0);
161 gStyle->SetFillColor(0);
162 gStyle->SetPadColor(0);
165 const unsigned int nmbPadsVert = (
int)ceil(sqrt(nmbPadsPerCanvMin));
166 const unsigned int nmbPadsHor = (
int)ceil((
double)nmbPadsPerCanvMin / (double)nmbPadsVert);
167 const unsigned int nmbPadsPerCanv = nmbPadsHor * nmbPadsVert;
170 wavePads.resize(nmbWaves, pair<string, TVirtualPad*>(
"", NULL));
171 unsigned int countPad = 0;
172 unsigned int countCanv = 0;
175 for (
unsigned int i = 0; i < nmbWaves; ++
i) {
179 stringstream canvName;
180 canvName <<
"spinTotals" << countCanv;
181 canv =
static_cast<TCanvas*
>(gROOT->FindObject(canvName.str().c_str()));
183 canv =
new TCanvas(canvName.str().c_str(),
"Spin Totals", 10, 10, 1000, 900);
184 canv->Divide(nmbPadsHor, nmbPadsVert);
191 TMultiGraph* graph =
new TMultiGraph();
193 for (
unsigned int j = 0; j < nmbTrees; ++j) {
196 if (waves[i] ==
"logLikelihood")
197 drawExpr =
"-" + branchName +
".logLikelihood() / " + branchName +
".nmbEvents():0:"
198 + branchName +
".massBinCenter()";
200 drawExpr = branchName +
".intensity(\"" + waves[
i] +
"\"):"
201 + branchName +
".intensityErr(\"" + waves[
i] +
"\"):"
202 + branchName +
".massBinCenter()";
203 cout <<
" running TTree::Draw() expression '" << drawExpr <<
"' "
204 <<
"on tree '" << trees[j]->GetName() <<
"', '" << trees[j]->GetTitle() <<
"'" << endl;
205 trees[j]->Draw(drawExpr.c_str(),
"",
"goff");
208 const int nmbBins = trees[j]->GetSelectedRows();
209 vector<double> x(nmbBins), xErr(nmbBins);
210 vector<double> y(nmbBins), yErr(nmbBins);
211 for (
int k = 0; k < nmbBins; ++k) {
212 x [k] = trees[j]->GetV3()[k] * 0.001;
214 y [k] = trees[j]->GetV1()[k];
215 yErr[k] = (waves[
i] ==
"logLikelihood") ? 0 : trees[j]->GetV2()[k];
217 TGraphErrors* g =
new TGraphErrors(nmbBins,
224 stringstream graphName;
225 graphName << waveName <<
"_" << j;
226 g->SetName (graphName.str().c_str());
227 g->SetTitle(graphName.str().c_str());
229 g->SetMarkerStyle(21);
230 g->SetMarkerSize(0.5);
232 g->SetMarkerColor(colors[j]);
233 g->SetLineColor (colors[j]);
238 for (
int k = 0; k < nmbBins; ++k) {
239 const double val = y[k] + yErr[k];
244 cout <<
" maximum intensity for graph " << graph->GetName() <<
" is " << maxY << endl;
246 canv->cd(++countPad);
247 graph->SetTitle(waveName);
248 graph->SetName(waveName);
249 if ((yAxisRangeMax > 0) && (maxY > yAxisRangeMax))
250 maxY = yAxisRangeMax;
251 graph->SetMinimum(-maxY * 0.1);
252 graph->SetMaximum( maxY * 1.1);
254 graph->Draw(drawOpt.c_str());
255 graph->GetXaxis()->SetTitle(
"Mass [GeV]");
256 if (waves[i] ==
"logLikelihood")
257 graph->GetYaxis()->SetTitle(
"ln(Likelihood)");
259 graph->GetYaxis()->SetTitle(
"Intensity");
260 TLine* line =
new TLine(graph->GetXaxis()->GetXmin(), 0, graph->GetXaxis()->GetXmax(), 0);
261 line->SetLineStyle(3);
262 graph->GetListOfFunctions()->Add(line);
264 if (drawLegend && (nmbTrees > 1)) {
265 TLegend* legend =
new TLegend(0.65,0.80,0.99,0.99);
266 legend->SetFillColor(10);
267 legend->SetBorderSize(1);
268 legend->SetMargin(0.2);
269 for (
unsigned int j = 0; j < nmbTrees; ++j) {
270 TGraph* g =
static_cast<TGraph*
>(graph->GetListOfGraphs()->At(j));
271 legend->AddEntry(g, trees[j]->GetTitle(),
"LPE");
273 graph->GetListOfFunctions()->Add(legend);
277 wavePads[
i].first = waves[
i];
278 wavePads[
i].second = gPad;
283 if (countPad == nmbPadsPerCanv) {