51 #include "TClonesArray.h"
52 #include "TStopwatch.h"
54 #include "fileUtils.hpp"
67 const int errCode = 0)
70 cerr <<
"calculates decay amplitudes for given wave for events in input data files and" << endl
71 <<
"writes amplitudes to file" << endl
75 <<
" -k key file [-n max. # of events -p PDG file -o output file -m amplitude leaf name "
76 <<
"-a -t tree name -l leaf names -r target particle name -v -h] "
77 <<
"input data file(s) (.evt or .root format)" << endl
79 <<
" -k file path to key file" << endl
80 <<
" -n # maximum number of events to read (default: all)" << endl
81 <<
" -p file path to particle data table file (default: ./particleDataTable.txt)" << endl
82 <<
" -o file path to amplitude file (.amp or .root format; default: ./out.root)" << endl
83 <<
" -m amplitude leaf name (default: 'amplitude')" << endl
84 <<
" -a write .amp files in ASCII format (default: binary)" << endl
85 <<
" -t name name of tree in ROOT data files (default: rootPwaEvtTree)" << endl
86 <<
" -l names semicolon separated object/leaf names in input data" << endl
87 <<
" (default: 'prodKinParticles;prodKinMomenta;decayKinParticles;decayKinMomenta')" << endl
88 <<
" -v verbose; print debug output (default: false)" << endl
89 <<
" -h print help" << endl
104 #ifdef USE_STD_COMPLEX_TREE_LEAFS
107 gROOT->ProcessLine(
"#include <complex>");
111 const string progName = argv[0];
112 string keyFileName =
"";
113 long int maxNmbEvents = -1;
114 string pdgFileName =
"./particleDataTable.txt";
115 string ampFileName =
"./out.root";
116 string ampLeafName =
"amplitude";
117 bool asciiOutput =
false;
118 string inTreeName =
"rootPwaEvtTree";
119 string leafNames =
"prodKinParticles;prodKinMomenta;decayKinParticles;decayKinMomenta";
120 bool newKeyFileNameConvention =
false;
122 const long int treeCacheSize = 1000000;
126 while ((c = getopt(argc, argv,
"k:n:p:o:m:at:l:r:vh")) != -1)
129 keyFileName = optarg;
132 maxNmbEvents = atol(optarg);
135 pdgFileName = optarg;
138 ampFileName = optarg;
141 ampLeafName = optarg;
161 if (optind >= argc) {
162 printErr <<
"you need to specify at least one data file to process. aborting." << endl;;
165 vector<string> rootFileNames;
166 vector<string> evtFileNames;
167 while (optind < argc) {
168 const string fileName = argv[optind++];
169 const string fileExt = extensionFromPath(fileName);
170 if (fileExt ==
"root")
171 rootFileNames.push_back(fileName);
172 else if (fileExt ==
"evt")
173 evtFileNames.push_back(fileName);
175 printWarn <<
"input file '" << fileName <<
"' is neither a .root nor a .evt file. "
176 <<
"skipping." << endl;
178 if ((rootFileNames.size() == 0) and (evtFileNames.size() == 0)) {
179 printErr <<
"none of the specified input files is a .root or .evt file. aborting.";
184 string prodKinPartNamesObjName, prodKinMomentaLeafName;
185 string decayKinPartNamesObjName, decayKinMomentaLeafName;
187 decayKinPartNamesObjName, decayKinMomentaLeafName);
190 vector<TTree*> inTrees;
191 TClonesArray* prodKinPartNames = 0;
192 TClonesArray* decayKinPartNames = 0;
194 rootFileNames, evtFileNames,
195 inTreeName, prodKinPartNamesObjName, prodKinMomentaLeafName,
196 decayKinPartNamesObjName, decayKinMomentaLeafName, debug)) {
197 printErr <<
"problems opening input file(s). aborting." << endl;
202 particleDataTable::readFile(pdgFileName);
205 if (keyFileName ==
"") {
206 printErr <<
"no key file specified. aborting." << endl;
213 printErr <<
"problems constructing decay topology from key file '" << keyFileName <<
"'. "
214 <<
"aborting." << endl;
217 printInfo << *amplitude;
220 bool writeRootFormat =
false;
221 #ifdef USE_STD_COMPLEX_TREE_LEAFS
222 const string ampFileExt = extensionFromPath(ampFileName);
223 if (ampFileExt ==
"root")
224 writeRootFormat =
true;
225 else if (ampFileExt ==
"amp")
226 writeRootFormat =
false;
228 printErr <<
"specified amplitude file '" << ampFileName <<
"' is neither a .root "
229 <<
"nor a .amp file. aborting." << endl;
233 printInfo <<
"creating amplitude file '" << ampFileName <<
"'";
234 ofstream* ampFilePlain = 0;
235 TFile* ampFileRoot = 0;
236 #ifdef USE_STD_COMPLEX_TREE_LEAFS
239 if (writeRootFormat) {
241 ampFileRoot = TFile::Open(ampFileName.c_str(),
"RECREATE");
244 newKeyFileNameConvention);
245 waveDesc.Write((waveName +
".key").c_str());
248 const string ampTreeName = waveName +
".amp";
249 ampTree =
new TTree(ampTreeName.c_str(), ampTreeName.c_str());
250 const int splitLevel = 99;
251 const int bufSize = 256000;
252 ampTree->Branch(ampLeafName.c_str(), &TreeLeaf, bufSize, splitLevel);
256 cout <<
"; " << ((asciiOutput) ?
"ASCII" :
"binary") <<
" mode" << endl;
257 ampFilePlain =
new ofstream(ampFileName.c_str());
259 if ( (writeRootFormat and not ampFileRoot)
260 or (not writeRootFormat and not ampFilePlain and not *ampFilePlain)) {
261 printErr <<
"cannot create amplitude file '" << ampFileName <<
"'. aborting." << endl;
269 vector<complex<double> > ampValues;
270 for (
unsigned int i = 0;
i < inTrees.size(); ++
i) {
271 printInfo <<
"processing ";
272 if ((rootFileNames.size() > 0) and (
i == 0))
273 cout <<
"chain of .root files";
275 cout <<
".evt tree[" << ((rootFileNames.size() > 0) ?
i :
i + 1) <<
"]";
277 if (not
processTree(*inTrees[
i], *prodKinPartNames, *decayKinPartNames,
278 amplitude, ampValues, maxNmbEvents - ampValues.size(),
279 prodKinMomentaLeafName, decayKinMomentaLeafName))
280 printWarn <<
"problems reading tree" << endl;
282 printSucc <<
"calculated amplitudes for " << ampValues.size() <<
" events" << endl;
284 printInfo <<
"this job consumed: ";
288 for (
unsigned int i = 0;
i < ampValues.size(); ++
i) {
289 #ifdef USE_STD_COMPLEX_TREE_LEAFS
291 ampTreeLeaf->
setAmp(ampValues[
i]);
297 *ampFilePlain << setprecision(numeric_limits<double>::digits10 + 1) << ampValues[
i] << endl;
299 ampFilePlain->write((
char*)(&Values[
i]),
sizeof(complex<double>));
302 #ifdef USE_STD_COMPLEX_TREE_LEAFS
304 printInfo <<
"optimizing tree" << endl;
306 ampTree->OptimizeBaskets(treeCacheSize, 1,
"d");
309 ampFileRoot->Close();
314 ampFilePlain->close();
317 printSucc <<
"wrote " << ampValues.size() <<
" amplitude values to "
318 <<
"'" << ampFileName <<
"'";
319 if (not writeRootFormat)
320 cout <<
" in " << ((asciiOutput) ?
"ASCII" :
"binary")
325 for (
unsigned int i = 0;
i < inTrees.size(); ++
i)