41 #include <boost/progress.hpp>
44 #include "TClonesArray.h"
48 #include "TStopwatch.h"
56 #include "mathUtils.hpp"
57 #include "fileUtils.hpp"
65 using namespace boost;
71 const string& keyFileName,
72 vector<complex<double> >& amps,
73 const long int maxNmbEvents)
78 printErr <<
"problems constructing amplitude. returning 0." << endl;
86 vector<TTree*> inTrees;
87 TClonesArray* prodKinPartNames = 0;
88 TClonesArray* decayKinPartNames = 0;
89 const vector<string> rootFileNames(1, rootInFileName);
90 const vector<string> evtFileNames;
91 const string& inTreeName =
"rootPwaEvtTree";
92 const string& prodKinPartNamesObjName =
"prodKinParticles";
93 const string& prodKinMomentaLeafName =
"prodKinMomenta";
94 const string& decayKinPartNamesObjName =
"decayKinParticles";
95 const string& decayKinMomentaLeafName =
"decayKinMomenta";
97 rootFileNames, evtFileNames,
98 inTreeName, prodKinPartNamesObjName, prodKinMomentaLeafName,
99 decayKinPartNamesObjName, decayKinMomentaLeafName,
true)) {
100 printErr <<
"problems opening input files. returning 0." << endl;
103 const long int nmbEventsChain = inTrees[0]->GetEntries();
106 TBranch* prodKinMomentaBr = 0;
107 TBranch* decayKinMomentaBr = 0;
108 TClonesArray* prodKinMomenta = 0;
109 TClonesArray* decayKinMomenta = 0;
112 inTrees[0]->SetBranchAddress(prodKinMomentaLeafName.c_str(), &prodKinMomenta, &prodKinMomentaBr );
113 inTrees[0]->SetBranchAddress(decayKinMomentaLeafName.c_str(), &decayKinMomenta, &decayKinMomentaBr);
116 if (not topo->initKinematicsData(*prodKinPartNames, *decayKinPartNames)) {
117 printErr <<
"problems initializing input data. returning 0." << endl;
120 const long int nmbEvents = ((maxNmbEvents > 0) ? min(maxNmbEvents, nmbEventsChain)
123 for (
long int eventIndex = 0; eventIndex < nmbEvents; ++eventIndex) {
126 if (inTrees[0]->LoadTree(eventIndex) < 0)
129 prodKinMomentaBr->GetEntry (eventIndex);
130 decayKinMomentaBr->GetEntry(eventIndex);
132 if (not prodKinMomenta or not decayKinMomenta) {
133 printWarn <<
"at least one data array is null pointer: "
134 <<
"prodKinMomenta = " << prodKinMomenta <<
", "
135 <<
"decayKinMomenta = " << decayKinMomenta <<
". "
136 <<
"skipping event." << endl;
140 if (topo->readKinematicsData(*prodKinMomenta, *decayKinMomenta)) {
141 amps.push_back((*amp)());
142 if ((amps.back().real() == 0) or (amps.back().imag() == 0))
143 printWarn <<
"event " << eventIndex <<
": " << amps.back() << endl;
153 const string& keyFileName,
154 vector<complex<double> >& amps,
155 const long int maxNmbEvents)
158 ifstream eventData(evtInFileName.c_str());
161 key.
open(keyFileName);
163 long int countEvent = 0;
164 const long int logInterval = 1000;
165 while ((countEvent < maxNmbEvents) and (not (eventData >> ev).eof())) {
167 key.
run(ev, amp,
true);
171 if (countEvent % logInterval == 0)
172 cout <<
" " << countEvent << endl;
177 printWarn <<
"code disabled, because compilation of PWA2000 is disabled" << endl;
192 const bool debug =
false)
194 ifstream datFile(fileName.c_str());
195 vector<symInfo> symInfos;
196 while (datFile.good()) {
202 getline(datFile, phi);
203 if ((phi ==
"pi") or (phi ==
"3.1416") or (phi ==
"1"))
206 s.
phi = atof(phi.c_str());
208 getline(datFile, ratio);
209 s.
ratio = atof(ratio.c_str());
210 symInfos.push_back(s);
213 printDebug <<
"read " << symInfos.size() <<
". symInfo from file '" << fileName <<
"'" << endl
214 <<
" name1 = '" << s.
waveNames[0] <<
"'" << endl
215 <<
" name1 = '" << s.
waveNames[1] <<
"'" << endl
217 <<
" phi = " << maxPrecision(s.
phi) << endl
218 <<
" ratio = " << maxPrecision(s.
ratio) << endl;
231 const long int maxNmbEvents = 1000;
245 const string newKeyFileName =
"test5pi/charly/sym/1-1+00+f11285=a11260-=rho770_01_pi-_11_pi+_11_pi-.key";
253 const string pwa2kKeyFileName[2] = {
258 "test5pi/sebastian/sym/1-1++0+pi-_11_f11285=pi-_11_a11269=pi+_0_rho770.key",
259 "test5pi/sebastian/sym/1-1++0+pi-_11_f11285=pi+_11_a11269=pi-_0_rho770.key"
267 vector<string> datFiles = filesMatchingGlobPattern(
"test5pi/sebastian/sym/*.dat");
268 vector<symInfo> symInfos;
269 for (
unsigned int i = 0;
i < datFiles.size(); ++
i) {
271 symInfos.insert(symInfos.end(), s.begin(), s.end());
276 for (
unsigned int i = 0;
i < symInfos.size(); ++
i) {
277 const string waveName = fileNameNoExtFromPath(pwa2kKeyFileName[0]) +
".amp";
278 if ( (symInfos[
i].waveNames[0] == waveName)
279 or (symInfos[
i].waveNames[1] == waveName)) {
280 phi = symInfos[
i].phi;
281 ratio = symInfos[
i].ratio;
285 printInfo <<
"using phi = " << maxPrecision(phi) <<
" and ratio = " << maxPrecision(ratio)
286 <<
" for symmetrization" << endl;
288 const string evtInFileName =
"test5pi/1900.1960.genbod.regen.evt";
289 const string rootInFileName =
"test5pi/1900.1960.genbod.root";
301 vector<complex<double> > newAmps;
302 calcNewAmps(rootInFileName, newKeyFileName, newAmps, maxNmbEvents);
304 printSucc <<
"read " << newAmps.size() <<
" events from file(s) "
305 <<
"'" << rootInFileName <<
"' and calculated amplitudes" << endl;
307 printInfo <<
"newAmps[0] = " << maxPrecisionDouble(newAmps[0]) << endl;
311 PDGtable.initialize(
"../../keyfiles/key5pi/pdgTable.txt");
315 vector<complex<double> > pwa2kAmps;
317 vector<complex<double> > amps[2];
318 calcPwa2kAmps(evtInFileName, pwa2kKeyFileName[0], amps[0], maxNmbEvents);
319 calcPwa2kAmps(evtInFileName, pwa2kKeyFileName[1], amps[1], maxNmbEvents);
320 const unsigned int nmbAmps = amps[0].size();
321 assert(amps[1].size() == nmbAmps);
322 pwa2kAmps.resize(nmbAmps);
323 complex<double> phase(ratio * cos(phi), ratio * sin(phi));
324 printInfo <<
"PWA2000 term[0] = " << maxPrecisionDouble(amps[0][0])
325 <<
", term[1] = " << maxPrecisionDouble(amps[1][0])
326 <<
", phase = " << phase << endl;
327 for (
unsigned int i = 0;
i < nmbAmps; ++
i)
328 pwa2kAmps[
i] = (1 / sqrt(1 + ratio)) * (amps[0][
i] + phase * amps[1][
i]);
331 printSucc <<
"read " << pwa2kAmps.size() <<
" events from file(s) "
332 <<
"'" << evtInFileName <<
"' and calculated amplitudes" << endl;
336 double relDiff[2] = {(pwa2kAmps[0].real() - newAmps[0].real()) / pwa2kAmps[0].real(),
337 (pwa2kAmps[0].imag() - newAmps[0].imag()) / pwa2kAmps[0].imag()};
338 for (
unsigned int i = 0;
i < 2; ++
i) {
341 else if (relDiff[
i] > 1)
344 printInfo <<
"newAmps[0] = " << maxPrecisionDouble(newAmps[0]) <<
" vs. pwa2kAmps[0] = "
345 << maxPrecisionDouble(pwa2kAmps[0]) <<
", abs. delta = "
346 << maxPrecisionDouble(newAmps[0] - pwa2kAmps[0]) <<
", rel. delta = "
347 <<
"(" << maxPrecision(relDiff[0]) <<
", " << maxPrecision(relDiff[1]) <<
")" << endl;
351 const string outFileName =
"testAmplitudeDiff.root";
352 printInfo <<
"writing comparison plots to " << outFileName << endl;
353 TFile* f = TFile::Open(outFileName.c_str(),
"RECREATE");
354 TH1D* hMyAmpsReal =
new TH1D(
"hMyAmpsReal",
"hMyAmpsReal;Event Number;#Rgothic[Amplitude]", newAmps.size(), -0.5, newAmps.size() - 0.5);
355 TH1D* hMyAmpsImag =
new TH1D(
"hMyAmpsImag",
"hMyAmpsImag;Event Number;#Jgothic[Amplitude]", newAmps.size(), -0.5, newAmps.size() - 0.5);
356 TH1D* hPwa2kAmpsReal =
new TH1D(
"hPwa2kAmpsReal",
"hPwa2kAmpsReal;Event Number;#Rgothic[Amplitude]", pwa2kAmps.size(), -0.5, pwa2kAmps.size() - 0.5);
357 TH1D* hPwa2kAmpsImag =
new TH1D(
"hPwa2kAmpsImag",
"hPwa2kAmpsImag;Event Number;#Jgothic[Amplitude]", pwa2kAmps.size(), -0.5, pwa2kAmps.size() - 0.5);
358 TH1D* hDiffReal =
new TH1D(
"hDiffReal",
"hDiffReal;#Rgothic[Amplitude] Difference;Count", 100000, -1e-7, 1e-7);
359 TH1D* hDiffImag =
new TH1D(
"hDiffImag",
"hDiffImag;#Jgothic[Amplitude] Difference;Count", 100000, -1e-7, 1e-7);
360 TH2D* hCorrReal =
new TH2D(
"hCorrReal",
"hCorrReal;#Rgothic[My Amp];#Rgothic[PWA2000 Amp]", 1000, -2, 2, 1000, -2, 2);
361 TH2D* hCorrImag =
new TH2D(
"hCorrImag",
"hCorrImag;#Jgothic[My Amp];#Jgothic[PWA2000 Amp]", 1000, -2, 2, 1000, -2, 2);
362 for (
unsigned int i = 0;
i < newAmps.size(); ++
i) {
363 double relDiff[2] = {(pwa2kAmps[
i].real() - newAmps[
i].real()) / pwa2kAmps[
i].real(),
364 (pwa2kAmps[
i].imag() - newAmps[
i].imag()) / pwa2kAmps[
i].imag()};
365 for (
unsigned int j = 0; j < 2; ++j) {
368 else if (relDiff[j] > 1)
371 hMyAmpsReal->SetBinContent (
i + 1, newAmps[
i].real());
372 hMyAmpsImag->SetBinContent (
i + 1, newAmps[
i].imag());
373 hPwa2kAmpsReal->SetBinContent(
i + 1, pwa2kAmps[
i].real());
374 hPwa2kAmpsImag->SetBinContent(
i + 1, pwa2kAmps[
i].imag());
375 hDiffReal->Fill(relDiff[0]);
376 hDiffImag->Fill(relDiff[1]);
379 hCorrReal->Fill(newAmps[
i].real(), pwa2kAmps[
i].real());
380 hCorrImag->Fill(newAmps[
i].imag(), pwa2kAmps[
i].imag());
386 printWarn <<
"code disabled, because compilation of PWA2000 is disabled" << endl;