ROOTPWA
testAmplitudeTree.cc
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 // test program for amplitude persistency class
29 //
30 //
31 // Author List:
32 // Boris Grube TUM (original author)
33 //
34 //
35 //-------------------------------------------------------------------------
36 
37 
38 #include <boost/assign/list_of.hpp>
39 
40 #include "TROOT.h"
41 #include "TFile.h"
42 #include "TTree.h"
43 #include "TRandom3.h"
44 
45 #include "reportingUtils.hpp"
46 #include "amplitudeTreeLeaf.h"
47 
48 
49 using namespace std;
50 using namespace boost::assign;
51 using namespace rpwa;
52 
53 
54 int
55 main(int argc, char** argv)
56 {
57  printCompilerInfo();
58  printSvnVersion();
59 
60 #ifdef USE_STD_COMPLEX_TREE_LEAFS
61 
62  const unsigned int nmbEvents = 1000000;
63  const unsigned int nmbIncohSubAmps = 3;
64  gRandom->SetSeed(123456789);
65 
66  // force loading predefined std::complex dictionary
67  // see http://root.cern.ch/phpBB3/viewtopic.php?f=5&t=9618&p=50164
68  gROOT->ProcessLine("#include <complex>");
69 
70  if (1) {
71  TFile* outFile = TFile::Open("testAmplitudeTree.root", "RECREATE");
72  amplitudeTreeLeaf* ampLeaf = new amplitudeTreeLeaf();
73  const vector<string> subAmpLabels = list_of("lambda=-1")("lambda=0")("lambda=+1");
74  TTree* tree = new TTree("test", "test");
75 
76  tree->Branch("amp", &ampLeaf);
77  for (unsigned int i = 0; i < nmbEvents; ++i) {
78  ampLeaf->clear();
79  ampLeaf->defineIncohSubAmps(subAmpLabels);
80  for (unsigned int j = 0; j < nmbIncohSubAmps; ++j)
81  // ampLeaf->setIncohSubAmp(complex<double>(i, -(double)j), j);
82  ampLeaf->setIncohSubAmp(complex<double>(gRandom->Rndm(), gRandom->Rndm()), j);
83  tree->Fill();
84  if (i < 5)
85  cout << "written event " << i << ": " << *ampLeaf;
86  }
87  cout << endl;
88  tree->Write();
89  outFile->Close();
90  for (unsigned int i = 0; i < subAmpLabels.size(); ++i)
91  cout << subAmpLabels[i] << ": [" << ampLeaf->incohSubAmpIndex(subAmpLabels[i]) << "]" << endl;
92  cout << endl;
93  }
94 
95  if (1) {
96  TFile* inFile = TFile::Open("testAmplitudeTree.root", "READ");
97  TTree* tree;
98  inFile->GetObject("test", tree);
99  amplitudeTreeLeaf* ampLeaf = 0;
100  tree->SetBranchAddress("amp", &ampLeaf);
101  for (unsigned int i = 0; i < tree->GetEntriesFast(); ++i) {
102  tree->GetEntry(i);
103  if (i < 5)
104  cout << "read event " << i << ": " << *ampLeaf;
105  }
106  cout << endl;
107 
108  // test arthmetic functions
109  printInfo << "original: " << *ampLeaf << endl;
110  amplitudeTreeLeaf ampLeaf2(*ampLeaf);
111  printInfo << "copy: "<< ampLeaf2 << endl;
112  if (ampLeaf2 != *ampLeaf)
113  printErr << "problem with assignment" << endl;
114  amplitudeTreeLeaf ampLeaf3 = 0.1 * (*ampLeaf) + 0.9 * ampLeaf2;
115  printInfo << "arithmetic test: " << ampLeaf3 << endl;
116  if (ampLeaf3 != *ampLeaf)
117  printErr << "problem with arithmetic" << endl;
118  }
119 
120 #endif // USE_STD_COMPLEX_TREE_LEAFS
121 
122 }