46 #include "reportingUtils.hpp"
56 const int errCode = 0)
58 cerr <<
"usage:" << endl
60 <<
" -w wavelist [-z # val -d amplitude directory -o outfile -s seed -N -n normfile"
61 <<
" [-a normfile] -r rank -q -h]" << endl
63 <<
" -w file path to wavelist file" << endl
64 <<
" -z # number of likelihood values (default: 100)" << endl
65 <<
" -d dir path to directory with decay amplitude files (default: '.')" << endl
66 <<
" -o file path to output file (default: 'testLikelihood.root')" << endl
67 <<
" -s # seed for random start values (default: 1234567)" << endl
68 <<
" -N use normalization of decay amplitudes (default: false)" << endl
69 <<
" -n file path to normalization integral file (default: 'norm.int')" << endl
70 <<
" -a file path to acceptance integral file (default: 'norm.int')" << endl
71 <<
" -A # number of input events to normalize acceptance to" << endl
72 <<
" -r # rank of spin density matrix (default: 1)" << endl
73 <<
" -q run quietly (default: false)" << endl
74 <<
" -h print help" << endl
85 gROOT->ProcessLine(
"#include <map>");
87 const string progName = argv[0];
88 unsigned int nmbLikelihoodVals = 100;
89 int startValSeed = 1234567;
90 string waveListFileName =
"";
91 string ampDirName =
".";
92 string outFileName =
"testLikelihood.root";
93 bool useNormalizedAmps =
false;
94 string normIntFileName =
"";
95 string accIntFileName =
"";
96 unsigned int numbAccEvents = 0;
97 unsigned int rank = 1;
102 while ((c = getopt(argc, argv,
"z:w:d:o:s:Nn:a:A:r:qh")) != -1)
105 nmbLikelihoodVals =
atoi(optarg);
108 waveListFileName = optarg;
114 outFileName = optarg;
117 startValSeed =
atoi(optarg);
120 useNormalizedAmps =
true;
123 normIntFileName = optarg;
126 accIntFileName = optarg;
129 numbAccEvents =
atoi(optarg);
141 if (normIntFileName.length() <= 1) {
142 normIntFileName =
"norm.int";
143 printWarn <<
"using default normalization integral file '" << normIntFileName <<
"'." << endl;
145 if (accIntFileName.length() <= 1) {
146 accIntFileName =
"norm.int";
147 printWarn <<
"using default acceptance normalization integral file '" << accIntFileName <<
"'." << endl;
149 if (waveListFileName.length() <= 1) {
150 printErr <<
"no wavelist file specified! aborting!" << endl;
154 printInfo <<
"running " << progName <<
" with the following parameters:" << endl;
155 cout <<
" # of values to calculate ..................... " << nmbLikelihoodVals << endl
156 <<
" wave list file ............................... '" << waveListFileName <<
"'" << endl
157 <<
" output file .................................. '" << outFileName <<
"'" << endl
158 <<
" seed for random parameters ................... " << startValSeed << endl
159 <<
" use normalization ............................ " << useNormalizedAmps << endl
160 <<
" file with normalization integral ......... '" << normIntFileName <<
"'" << endl
161 <<
" file with acceptance integral ............ '" << accIntFileName <<
"'" << endl
162 <<
" number of acceptance norm. events ........ " << numbAccEvents << endl
163 <<
" rank of spin-density matrix .................. " << rank << endl
164 <<
" quiet ........................................ " << ((quiet) ?
"yes" :
"no") << endl;
167 printInfo <<
"creating and setting up likelihood function" << endl;
176 L.
init(rank, waveListFileName, normIntFileName, accIntFileName, ampDirName, numbAccEvents);
181 TFile& outFile = *TFile::Open(outFileName.c_str(),
"RECREATE");
182 TTree tree(
"testLikelihoodTree",
"testLikelihoodTree");
186 map<string, double> derivatives;
187 tree.Branch(
"logLikelihood", &logLikelihood,
"logLikelihood/D");
188 tree.Branch(
"derivatives", &derivatives);
191 TRandom3 random(startValSeed);
192 list<string> prodAmpNames;
193 const unsigned int nmbPar = L.
NDim();
194 for (
unsigned int i = 0;
i < nmbPar; ++
i)
195 prodAmpNames.push_back(L.
parName(
i));
199 for (
unsigned int i = 0;
i < nmbLikelihoodVals; ++
i) {
201 double prodAmps[nmbPar];
203 for (list<string>::const_iterator j = prodAmpNames.begin(); j != prodAmpNames.end(); ++j) {
205 for (
unsigned int k = 0; k < nmbPar; ++k)
211 cout <<
"cannot find parameter '" << *j <<
"'. skipping." << endl;
215 prodAmps[parIndex] = random.Uniform(0, 10);
219 logLikelihood = L.
DoEval(prodAmps);
221 double gradient[nmbPar];
224 for (
unsigned int j = 0; j < nmbPar; ++j) {
225 const string parName = L.
parName(j);
226 derivatives[parName] = gradient[j];