41 #include <boost/progress.hpp>
45 #include "TTreeFormula.h"
47 #include "TDirectory.h"
51 #include "reportingUtils.hpp"
55 using namespace boost;
61 const string& outFileName =
"ampDiffPlots.root",
62 const long int maxNmbEvents = -1,
63 const string& inTreeName =
"ampDiffTree")
66 printInfo <<
"opening input file(s) '" << inFileNamePattern <<
"'" << endl;
67 TChain inTree(inTreeName.c_str());
68 if (inTree.Add(inFileNamePattern.c_str()) < 1) {
69 printWarn <<
"no events in input file(s) '" << inFileNamePattern <<
"'" << endl;
72 inTree.GetListOfFiles()->ls();
76 if (outFileName !=
"") {
77 printInfo <<
"writing difference plots to '" << outFileName <<
"'" << endl;
78 outFile = TFile::Open(outFileName.c_str(),
"RECREATE");
82 TObjString* ampName = 0;
84 UInt_t massBinMin, massBinMax;
88 inTree.SetBranchAddress(
"ampName", &Name);
89 inTree.SetBranchAddress(
"eventNmb", &eventNmb);
90 inTree.SetBranchAddress(
"massBinMin", &massBinMin);
91 inTree.SetBranchAddress(
"massBinMax", &massBinMax);
92 inTree.SetBranchAddress(
"valReal", valReal);
93 inTree.SetBranchAddress(
"valImag", valImag);
94 inTree.SetBranchAddress(
"absDiffReal", &absDiffReal);
95 inTree.SetBranchAddress(
"absDiffImag", &absDiffImag);
96 inTree.SetBranchAddress(
"relDiffReal", &relDiffReal);
97 inTree.SetBranchAddress(
"relDiffImag", &relDiffImag);
100 const long int nmbEventsTree = inTree.GetEntries();
101 const long int nmbEvents = ((maxNmbEvents > 0) ? min(maxNmbEvents, nmbEventsTree)
107 TH1F* hAbsDiffRe =
new TH1F(
"absDiffReal",
"absDiffReal;#Rgothic[Amp 1 - Amp 2];Count", 1000000, -1e-9, 1e-9);
108 TH1F* hAbsDiffIm =
new TH1F(
"absDiffImag",
"absDiffImag;#Jgothic[Amp 1 - Amp 2];Count", 1000000, -1e-8, 1e-8);
109 TH1F* hRelDiffRe =
new TH1F(
"relDiffReal",
"relDiffReal;(#Rgothic[Ampl 1] - #Rgothic[Ampl 2]) / #Rgothic[Ampl 1];Count", 1000000, -1e-4, 1e-4);
110 TH1F* hRelDiffIm =
new TH1F(
"relDiffImag",
"relDiffImag;(#Jgothic[Ampl 1] - #Jgothic[Ampl 2]) / #Jgothic[Ampl 1];Count", 1000000, -1e-4, 1e-4);
115 set<string> ampNames;
116 double maxAbsDiff = 0;
117 long int maxAbsDiffIndex = -1;
118 double maxRelDiff = 0;
119 long int maxRelDiffIndex = -1;
121 for (
long int eventIndex = 0; eventIndex < nmbEvents; ++eventIndex) {
124 if (inTree.LoadTree(eventIndex) < 0)
126 inTree.GetEntry(eventIndex);
128 ampNames.insert(ampName->GetString().Data());
134 hAbsDiffRe->Fill(absDiffReal);
135 hAbsDiffIm->Fill(absDiffImag);
136 hRelDiffRe->Fill(relDiffReal);
137 hRelDiffIm->Fill(relDiffImag);
141 const double absMax = max(fabs(absDiffReal), fabs(absDiffImag));
142 const double relMax = max(fabs(relDiffReal), fabs(relDiffImag));
143 if (absMax > maxAbsDiff) {
145 maxAbsDiffIndex = eventIndex;
147 if (relMax > maxRelDiff) {
149 maxRelDiffIndex = eventIndex;
152 printInfo <<
"maximum observed deviations: absolute = " << maxPrecision(maxAbsDiff) <<
" "
153 <<
"(event " << maxAbsDiffIndex <<
"), relative = " << maxPrecision(maxRelDiff) <<
" "
154 <<
"(event " << maxRelDiffIndex <<
")" << endl;
157 inTree.GetEntry(maxAbsDiffIndex);
158 printInfo <<
"event[" << maxAbsDiffIndex <<
"]:" << endl
159 <<
" ampName ....... " << ampName->GetString() << endl
160 <<
" eventNmb ...... " << eventNmb << endl
161 <<
" massBinMin .... " << massBinMin << endl
162 <<
" massBinMax .... " << massBinMax << endl
163 <<
" valReal[0] .... " << maxPrecision(valReal[0] ) << endl
164 <<
" valReal[1] .... " << maxPrecision(valReal[1] ) << endl
165 <<
" valImag[0] .... " << maxPrecision(valImag[0] ) << endl
166 <<
" valImag[1] .... " << maxPrecision(valImag[1] ) << endl
167 <<
" absDiffReal ... " << maxPrecision(absDiffReal) << endl
168 <<
" absDiffImag ... " << maxPrecision(absDiffImag) << endl
169 <<
" relDiffReal ... " << maxPrecision(relDiffReal) << endl
170 <<
" relDiffImag ... " << maxPrecision(relDiffImag) << endl;
171 inTree.GetEntry(maxRelDiffIndex);
172 printInfo <<
"event[" << maxRelDiffIndex <<
"]:" << endl
173 <<
" ampName ....... " << ampName->GetString() << endl
174 <<
" eventNmb ...... " << eventNmb << endl
175 <<
" massBinMin .... " << massBinMin << endl
176 <<
" massBinMax .... " << massBinMax << endl
177 <<
" valReal[0] .... " << maxPrecision(valReal[0] ) << endl
178 <<
" valReal[1] .... " << maxPrecision(valReal[1] ) << endl
179 <<
" valImag[0] .... " << maxPrecision(valImag[0] ) << endl
180 <<
" valImag[1] .... " << maxPrecision(valImag[1] ) << endl
181 <<
" absDiffReal ... " << maxPrecision(absDiffReal) << endl
182 <<
" absDiffImag ... " << maxPrecision(absDiffImag) << endl
183 <<
" relDiffReal ... " << maxPrecision(relDiffReal) << endl
184 <<
" relDiffImag ... " << maxPrecision(relDiffImag) << endl;
186 const string leafsToDraw[] = {
"absDiffReal",
190 const unsigned int nmbLeafs =
sizeof(leafsToDraw) /
sizeof(leafsToDraw[0]);
191 TH2F* hLeafs[nmbLeafs];
192 for (
unsigned int i = 0;
i < nmbLeafs; ++
i) {
193 printInfo <<
"filling histogram for leaf '" << leafsToDraw[
i] <<
"'" << endl;
194 const double min = inTree.GetMinimum(leafsToDraw[
i].c_str());
195 const double max = inTree.GetMaximum(leafsToDraw[
i].c_str());
196 hLeafs[
i] =
new TH2F((leafsToDraw[
i] +
"Wave").c_str(),
197 (leafsToDraw[
i] +
" vs. Wave;Wave;" + leafsToDraw[
i]).c_str(),
198 1, 0, 1, 100000, min - 0.1 * fabs(min), max + 0.1 * fabs(max));
199 hLeafs[
i]->SetBit(TH1::kCanRebin);
200 TTreeFormula* leafVal =
new TTreeFormula(
"", leafsToDraw[i].c_str(), &inTree);
202 for (
long int eventIndex = 0; eventIndex < nmbEvents; ++eventIndex) {
204 if (inTree.LoadTree(eventIndex) < 0)
206 inTree.GetEntry(eventIndex);
207 leafVal->UpdateFormulaLeaves();
208 hLeafs[
i]->Fill(ampName->GetString().Data(), leafVal->EvalInstance(), 1.);
210 hLeafs[
i]->LabelsDeflate(
"X");
211 hLeafs[
i]->SetLabelSize(0.02,
"X");
212 hLeafs[
i]->SetDrawOption(
"COLZ");
219 printInfo <<
"wrote difference plots to '" << outFileName <<
"'" << endl;