ROOTPWA
ampIntegralMatrix.h
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 // container class for complex amplitude integral matrices
29 //
30 //
31 // Author List:
32 // Boris Grube TUM (original author)
33 //
34 //
35 //-------------------------------------------------------------------------
36 
37 
38 #ifndef AMPINTEGRALMATRIX_H
39 #define AMPINTEGRALMATRIX_H
40 
41 
42 #include <vector>
43 #include <map>
44 #include <complex>
45 #include <string>
46 #include <iostream>
47 #include <fstream>
48 
49 
50 #ifndef __CINT__
51 #define BOOST_DISABLE_ASSERTS
52 #include <boost/multi_array.hpp>
53 #endif
54 
55 #include "TObject.h"
56 
57 #include "waveDescription.h"
58 
59 
60 class TTree;
61 namespace rpwa {
62  class amplitudeTreeLeaf;
63 }
64 
65 
66 namespace rpwa {
67 
68 
69  class ampIntegralMatrix : public TObject {
70 
71 
72  typedef std::map<std::string, unsigned int>::const_iterator waveNameToIndexMapIterator;
73 
74 
75  public:
76 
77 
78 #ifndef __CINT__
79  typedef boost::multi_array<std::complex<double>, 2> integralMatrixType;
80  private:
81  typedef integralMatrixType::size_type sizeType;
82  public:
83 #endif
84 
85 
88  virtual ~ampIntegralMatrix();
89 
90  void clear();
91 
93 
94  friend bool operator ==(const ampIntegralMatrix& lhsInt,
95  const ampIntegralMatrix& rhsInt);
96 
97  // arithmetic operators for integrals
100  ampIntegralMatrix& operator *=(const double factor);
101  ampIntegralMatrix& operator /=(const double factor);
102 
103  // accessors
104  unsigned int nmbWaves () const { return _nmbWaves; }
105  unsigned long nmbEvents() const { return _nmbEvents; }
106 
107  void setNmbEvents(const unsigned long nmbEvents) { _nmbEvents = nmbEvents; }
108 
109  bool containsWave(const std::string& waveName ) const;
110  unsigned int waveIndex (const std::string& waveName ) const;
111  const std::string& waveName (const unsigned int waveIndex) const;
112 
113  const std::vector<rpwa::waveDescription>& waveDescriptions() const { return _waveDescriptions; }
114  const waveDescription* waveDesc(const unsigned int waveIndex) const;
115  const waveDescription* waveDesc(const std::string& waveName ) const { return waveDesc(waveIndex(waveName)); }
116  bool allWavesHaveDesc() const;
117 
118 #ifndef __CINT__
120  const integralMatrixType& matrix() const { return _integrals; }
121 #endif
122 
123  std::complex<double> element(const unsigned int waveIndexI,
124  const unsigned int waveIndexJ) const;
125  std::complex<double> element(const std::string& waveNameI,
126  const std::string& waveNameJ) const
127  { return element(waveIndex(waveNameI), waveIndex(waveNameJ)); }
128 
129 
130  bool integrate(const std::vector<std::string>& binAmpFileNames,
131  const std::vector<std::string>& rootAmpFileNames,
132  const unsigned long maxNmbEvents = 0,
133  const std::string& weightFileName = "");
134 
135  void renormalize(const unsigned long nmbEventsRenorm);
136 
137  bool writeAscii(std::ostream& out = std::cout) const;
138  bool readAscii (std::istream& in = std::cin );
139  bool writeAscii(const std::string& outFileName) const;
140  bool readAscii (const std::string& inFileName );
141 
142  std::ostream& print(std::ostream& out,
143  const bool printIntegralValues = false) const;
144 
145  static bool debug() { return _debug; }
146  static void setDebug(const bool debug = true) { _debug = debug; }
147 
148 
149  private:
150 
151  unsigned long openBinAmpFiles(std::vector<std::ifstream*>& ampFiles,
152  const std::vector<std::string>& ampFileNames,
153  const unsigned int waveIndexOffset = 0);
154 
155  unsigned long openRootAmpFiles(std::vector<TTree*>& ampTrees,
156  std::vector<rpwa::amplitudeTreeLeaf*>& ampTreeLeafs,
157  const std::vector<std::string>& ampFileNames,
158  const unsigned int waveIndexOffset = 0,
159  const std::string& ampLeafName = "amplitude");
160 
162 
163  bool hasIdenticalWaveSet(const ampIntegralMatrix& integral) const;
164 
165 
166  static bool _debug;
167 
168  unsigned int _nmbWaves;
169  std::map<std::string, unsigned int> _waveNameToIndexMap;
170  std::vector<std::string> _waveNames;
171  unsigned long _nmbEvents;
172 
173  void storeMultiArray();
174  void readMultiArray ();
175 #ifndef __CINT__
177 #endif
178  std::vector<unsigned int> _intStorageShape;
179  unsigned int _intStorageNmbElements;
180  std::complex<double>* _intStorageData; //[_intStorageNmbElements]
181 
182  std::vector<rpwa::waveDescription> _waveDescriptions;
183 
184 
185 #ifdef USE_STD_COMPLEX_TREE_LEAFS
186  ClassDef(ampIntegralMatrix,1)
187 #endif
188 
189  };
190 
191 
192  // comparison operators
193  inline
194  bool
196  const ampIntegralMatrix& rhsInt)
197  {
198  if (not lhsInt.hasIdenticalWaveSet(rhsInt)
199  or (lhsInt.nmbEvents() != rhsInt.nmbEvents()))
200  return false;
201  for (unsigned int i = 0; i < lhsInt.nmbWaves(); ++i) {
202  const std::string waveNameI = lhsInt.waveName(i);
203  for (unsigned int j = 0; j < lhsInt.nmbWaves(); ++j) {
204  const std::string waveNameJ = lhsInt.waveName(j);
205  if (lhsInt.matrix()[i][j]
206  != rhsInt.matrix()[rhsInt.waveIndex(waveNameI)][rhsInt.waveIndex(waveNameJ)])
207  return false;
208  }
209  }
210  return true;
211  }
212 
213  inline
214  bool
216  const ampIntegralMatrix& rhsInt)
217  {
218  return not(lhsInt == rhsInt);
219  }
220 
221 
222  // arithmetic operators for integrals
223  inline
224  ampIntegralMatrix
225  operator +(const ampIntegralMatrix& integralA,
226  const ampIntegralMatrix& integralB)
227  {
228  ampIntegralMatrix result = integralA;
229  result += integralB;
230  return result;
231  }
232 
233  inline
234  ampIntegralMatrix
235  operator -(const ampIntegralMatrix& integralA,
236  const ampIntegralMatrix& integralB)
237  {
238  ampIntegralMatrix result = integralA;
239  result -= integralB;
240  return result;
241  }
242 
243  inline
244  ampIntegralMatrix
246  const double factor)
247  {
248  ampIntegralMatrix result = integral;
249  result *= factor;
250  return result;
251  }
252 
253  inline
254  ampIntegralMatrix
255  operator *(const double factor,
257  {
258  return integral * factor;
259  }
260 
261  inline
262  ampIntegralMatrix
264  const double factor)
265  {
266  ampIntegralMatrix result = integral;
267  result /= factor;
268  return result;
269  }
270 
271 
272  inline
273  std::ostream&
274  operator <<(std::ostream& out,
276  {
277  return integral.print(out);
278  }
279 
280 
281 } // namespace rpwa
282 
283 
284 #endif // AMPINTEGRALMATRIX_H