ROOTPWA
amplitudeTreeLeaf.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 // TTree leaf storage class for amplitude information
29 //
30 // class allows to define named subamplitudes that are summed
31 // incoherently in the intensity formula
32 //
33 //
34 // Author List:
35 // Boris Grube TUM (original author)
36 //
37 //
38 //-------------------------------------------------------------------------
39 
40 
41 #ifndef AMPLITUDETREELEAF_H
42 #define AMPLITUDETREELEAF_H
43 
44 
45 #include <vector>
46 #include <map>
47 #include <complex>
48 
49 #include "TObject.h"
50 
51 
52 namespace rpwa {
53 
54 
55  class amplitudeTreeLeaf : public TObject {
56 
57 
58  typedef std::map<std::string, unsigned int>::const_iterator labelToIndexMapIterator;
59 
60 
61  public:
62 
64  virtual ~amplitudeTreeLeaf();
65 
66  void clear();
67 
69 
70  friend bool operator ==(const amplitudeTreeLeaf& lhsAmp,
71  const amplitudeTreeLeaf& rhsAmp);
72 
73  // arithmetic operators for integrals
76 
77  template<typename T>
78  amplitudeTreeLeaf& operator *=(const T& factor);
79  template<typename T>
80  amplitudeTreeLeaf& operator /=(const T& factor);
81 
82  // accessors
83  unsigned int nmbIncohSubAmps() const { return _incohSubAmps.size(); }
84 
85  bool containsIncohSubAmp(const std::string& subAmpLabel) const;
86  unsigned int incohSubAmpIndex (const std::string& subAmpLabel) const;
87  const std::string& incohSubAmpName (const unsigned int subAmpIndex) const;
88 
89  const std::complex<double>& incohSubAmp(const unsigned int index = 0 ) const
90  { return _incohSubAmps[index]; }
91  const std::complex<double>& incohSubAmp(const std::string& subAmpLabel) const
92  { return _incohSubAmps[incohSubAmpIndex(subAmpLabel)]; }
93 
94  const std::complex<double>& amp() const { return incohSubAmp(0); }
95 
96  void defineIncohSubAmps(const std::vector<std::string>& subAmpLabels);
97 
98  void setIncohSubAmp(const std::complex<double>& amp,
99  const unsigned int index = 0) { _incohSubAmps[index] = amp; }
100 
101  void setAmp (const std::complex<double>& amp) { setIncohSubAmp(amp, 0); }
102 
103  std::ostream& print(std::ostream& out) const;
104 
105  static bool debug() { return _debug; }
106  static void setDebug(const bool debug = true) { _debug = debug; }
107 
108 
109  private:
110 
111  void rebuildSubAmpLabelMap();
112 
113  static bool _debug;
114 
115  std::vector<std::complex<double> > _incohSubAmps;
116  std::vector<std::string> _incohSubAmpLabels;
117  std::map<std::string, unsigned int> _labelToIndexMap;
118 
119 
120 #ifdef USE_STD_COMPLEX_TREE_LEAFS
121  ClassDef(amplitudeTreeLeaf,1)
122 #endif
123 
124  };
125 
126 
127  // comparison operators
128  inline
129  bool
131  const amplitudeTreeLeaf& rhsAmp)
132  {
133  const unsigned int nmbSubAmps = lhsAmp.nmbIncohSubAmps();
134  if (nmbSubAmps != lhsAmp.nmbIncohSubAmps())
135  return false;
136  for (unsigned int i = 0; i < nmbSubAmps; ++i)
137  if (lhsAmp.incohSubAmp(i) != rhsAmp.incohSubAmp(i))
138  return false;
139  return true;
140  }
141 
142  inline
143  bool
145  const amplitudeTreeLeaf& rhsAmp)
146  {
147  return not(lhsAmp == rhsAmp);
148  }
149 
150 
151  // arithmetic operators for integrals
152  template<typename T>
153  inline
154  amplitudeTreeLeaf&
156  {
157  for (unsigned int i = 0; i < nmbIncohSubAmps(); ++i)
158  _incohSubAmps[i] *= factor;
159  return *this;
160  }
161 
162 
163  template<typename T>
164  inline
167  {
168  for (unsigned int i = 0; i < nmbIncohSubAmps(); ++i)
169  _incohSubAmps[i] /= factor;
170  return *this;
171  }
172 
173 
174  inline
177  const amplitudeTreeLeaf& ampB)
178  {
179  amplitudeTreeLeaf result = ampA;
180  result += ampB;
181  return result;
182  }
183 
184  inline
185  amplitudeTreeLeaf
187  const amplitudeTreeLeaf& ampB)
188  {
189  amplitudeTreeLeaf result = ampA;
190  result -= ampB;
191  return result;
192  }
193 
194  template<typename T>
195  inline
196  amplitudeTreeLeaf
198  const T& factor)
199  {
200  amplitudeTreeLeaf result = amp;
201  result *= factor;
202  return result;
203  }
204 
205  template<typename T>
206  inline
207  amplitudeTreeLeaf
208  operator *(const T& factor,
209  const amplitudeTreeLeaf& amp)
210  {
211  return amp * factor;
212  }
213 
214  template<typename T>
215  inline
216  amplitudeTreeLeaf
218  const T& factor)
219  {
220  amplitudeTreeLeaf result = amp;
221  result /= factor;
222  return result;
223  }
224 
225 
226  inline
227  std::ostream&
228  operator <<(std::ostream& out,
229  const amplitudeTreeLeaf& amp)
230  {
231  return amp.print(out);
232  }
233 
234 
235 } // namespace rpwa
236 
237 
238 #endif // AMPLITUDETREELEAF_H