ROOTPWA
convertTreeToEvt.C
Go to the documentation of this file.
1 
2 //
3 // Copyright 2010
4 //
5 // This file is part of rootpwa
6 //
7 // rootpwa is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // rootpwa is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with rootpwa. If not, see <http://www.gnu.org/licenses/>.
19 //
21 //-------------------------------------------------------------------------
22 // File and Version Information:
23 // $Rev:: $: revision of last commit
24 // $Author:: $: author of last commit
25 // $Date:: $: date of last commit
26 //
27 // Description:
28 // program that converts standrad ASCII PWA2000 .evt files into
29 // new ROOT tree format
30 //
31 //
32 // Author List:
33 // Boris Grube TUM (original author)
34 //
35 //
36 //-------------------------------------------------------------------------
37 
38 
39 #include <fstream>
40 #include <string>
41 #include <iomanip>
42 #include <limits>
43 #include <algorithm>
44 
45 #include "TTree.h"
46 #include "TClonesArray.h"
47 #include "TObjString.h"
48 #include "TVector3.h"
49 
50 #include "reportingUtils.hpp"
51 #ifndef __CINT__
52 #include "particleDataTable.h"
53 #endif
54 #include "evtTreeHelper.h"
55 
56 
57 using namespace std;
58 using namespace rpwa;
59 
60 
61 bool
62 convertTreeToEvt(const string& inFileNamePattern = "testEvents.root",
63  const string& outFileName = "testEvents.evt",
64  const string& pdgTableFileName = "./particleDataTable.txt",
65  const long int maxNmbEvents = -1,
66  const string& inTreeName = "rootPwaEvtTree",
67  const string& prodKinPartNamesObjName = "prodKinParticles",
68  const string& prodKinMomentaLeafName = "prodKinMomenta",
69  const string& decayKinPartNamesObjName = "decayKinParticles",
70  const string& decayKinMomentaLeafName = "decayKinMomenta",
71  const bool debug = false)
72 {
73  // open input files
74  TTree* inTree = 0;
75  TClonesArray* prodKinPartNames = 0;
76  TClonesArray* decayKinPartNames = 0;
77  {
78  vector<string> rootFileNames;
79  rootFileNames.push_back(inFileNamePattern);
80  vector<string> evtFileNames;
81  vector<TTree*> inTrees;
82  if (not openRootEvtFiles(inTrees, prodKinPartNames, decayKinPartNames,
83  rootFileNames, evtFileNames,
84  inTreeName, prodKinPartNamesObjName, prodKinMomentaLeafName,
85  decayKinPartNamesObjName, decayKinMomentaLeafName, debug)) {
86  printErr << "problems opening input file(s). exiting." << endl;
87  return false;
88  }
89  inTree = inTrees[0];
90  }
91 
92  // create output file
93  printInfo << "creating output file '" << outFileName << "'" << endl;
94  ofstream outFile(outFileName.c_str());
95  if (!outFile) {
96  printWarn << "cannot open output file '" << outFileName << "'. exiting." << endl;
97  return false;
98  }
99 
101  pdt.readFile(pdgTableFileName);
102 
103  // doit
104  const bool success = writeEvtFromTree(*inTree, outFile, *prodKinPartNames, *decayKinPartNames,
105  maxNmbEvents, inTreeName,
106  prodKinMomentaLeafName, decayKinMomentaLeafName, debug);
107 
108  if (success)
109  printSucc << "wrote events to file '" << outFileName << "'" << endl;
110  else
111  printWarn << "problems processing events" << endl;
112  return success;
113 }