ROOTPWA
convertAmpToTree.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 standard binary PWA2000 .amp 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 "amplitudeTreeHelper.h"
51 
52 
53 using namespace std;
54 using namespace rpwa;
55 
56 
57 bool
58 convertAmpToTree(const string& ampFileName = "1-1++1+rho770_21_pi-.amp",
59  const string& outFileName = "testAmpTree.root",
60  const long int maxNmbEvents = -1,
61  const string& ampLeafName = "amplitude",
62  const bool debug = false)
63 {
64  // create output file
65  printInfo << "creating output file '" << outFileName << "'" << endl;
66  TFile* outFile = TFile::Open(outFileName.c_str(), "RECREATE");
67  if (not outFile) {
68  printErr << "cannot open output file '" << outFileName << "'" << endl;
69  return false;
70  }
71  outFile->SetCompressionLevel(9);
72 
73  // create tree
74  TTree* outTree = new TTree();
75  if (not outTree) {
76  printErr << "problems creating tree in file '" << outFileName << "'" << endl;
77  return false;
78  }
79 
80  // doit
81  const bool success = fillTreeFromAmp(ampFileName, *outTree, maxNmbEvents, ampLeafName, debug);
82  outTree->Write();
83 
84  outFile->Close();
85  if (success)
86  printInfo << "wrote events to file '" << outFileName << "'" << endl;
87  else
88  printWarn << "problems processing events" << endl;
89  return success;
90 }