ROOTPWA
convertEvtToTree.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 <sstream>
41 #include <string>
42 
43 #include "TFile.h"
44 #include "TTree.h"
45 #include "TClonesArray.h"
46 #include "TObjString.h"
47 #include "TVector3.h"
48 
49 #include "reportingUtils.hpp"
50 #include "evtTreeHelper.h"
51 
52 
53 using namespace std;
54 using namespace rpwa;
55 
56 
57 bool
58 convertEvtToTree(const string& evtFileName = "testEvents.evt",
59  const string& outFileName = "testEvents.root",
60  const long int maxNmbEvents = -1,
61  const string& outTreeName = "rootPwaEvtTree",
62  const string& prodKinPartNamesObjName = "prodKinParticles",
63  const string& prodKinMomentaLeafName = "prodKinMomenta",
64  const string& decayKinPartNamesObjName = "decayKinParticles",
65  const string& decayKinMomentaLeafName = "decayKinMomenta",
66  const bool debug = false)
67 {
68  // open input file
69  printInfo << "opening input file '" << evtFileName << "'" << endl;
70  ifstream evtFile(evtFileName.c_str());
71  if (not evtFile or not evtFile.good()) {
72  printWarn << "cannot open input file '" << evtFileName << "'" << endl;
73  return false;
74  }
75 
76  // create output file
77  printInfo << "creating output file '" << outFileName << "'" << endl;
78  TFile* outFile = TFile::Open(outFileName.c_str(), "RECREATE");
79  if (not outFile) {
80  printErr << "cannot open output file '" << outFileName << "'" << endl;
81  return false;
82  }
83 
84  // create tree
85  TTree* tree = new TTree(outTreeName.c_str(), outTreeName.c_str());
86  if (not tree) {
87  printErr << "problems creating tree '" << outTreeName << "' "
88  << "in file '" << outFileName << "'" << endl;
89  return false;
90  }
91 
92  // doit
93  TClonesArray* prodKinPartNames = new TClonesArray("TObjString");
94  TClonesArray* decayKinPartNames = new TClonesArray("TObjString");
95  const bool success = fillTreeFromEvt(evtFile, *tree,
96  *prodKinPartNames, *decayKinPartNames,
97  maxNmbEvents,
98  prodKinMomentaLeafName, decayKinMomentaLeafName,
99  debug);
100  tree->Write();
101  prodKinPartNames->Write (prodKinPartNamesObjName.c_str (), TObject::kSingleKey);
102  decayKinPartNames->Write(decayKinPartNamesObjName.c_str(), TObject::kSingleKey);
103 
104  outFile->Close();
105  if (success)
106  printSucc << "wrote events to file '" << outFileName << "'" << endl;
107  else
108  printWarn << "problems processing events" << endl;
109  return success;
110 }