ROOTPWA
amplitudeTreeLeaf.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 // TTree leaf persistency storage class for amplitude information
29 // needed by fit program
30 //
31 //
32 // Author List:
33 // Boris Grube TUM (original author)
34 //
35 //
36 //-------------------------------------------------------------------------
37 
38 
39 #include <algorithm>
40 
41 #include "TClass.h"
42 
43 #include "reportingUtils.hpp"
44 #include "amplitudeTreeLeaf.h"
45 
46 
47 using namespace std;
48 using namespace rpwa;
49 
50 
51 #ifdef USE_STD_COMPLEX_TREE_LEAFS
53 #endif
54 
55 
56 bool amplitudeTreeLeaf::_debug = false;
57 
58 
59 amplitudeTreeLeaf::amplitudeTreeLeaf()
60  : TObject (),
61  _incohSubAmps (1, 0),
62  _incohSubAmpLabels(),
63  _labelToIndexMap ()
64 {
65  amplitudeTreeLeaf::Class()->IgnoreTObjectStreamer(); // don't store TObject's fBits and fUniqueID
66 }
67 
68 
70 { }
71 
72 
74 {
75  _incohSubAmps.clear ();
76  _incohSubAmps.resize (1, 0);
77  _incohSubAmpLabels.clear();
78  _labelToIndexMap.clear ();
79 }
80 
81 
84 {
85  if (this != &amp) {
90  }
91  return *this;
92 }
93 
94 
97 {
99  printErr << "cannot add " << *this << endl
100  << "and " << amp << endl
101  << "because the two amplitudes have different incoherent sub-amplitudes. "
102  << "aborting." << endl;
103  throw;
104  }
105  for (unsigned int i = 0; i < nmbIncohSubAmps(); ++i)
106  _incohSubAmps[i] += amp.incohSubAmp(i);
107  return *this;
108 }
109 
110 
113 {
115  printErr << "cannot subtract " << amp << endl
116  << "from " << *this << endl
117  << "because the two amplitudes have different incoherent sub-amplitudes. "
118  << "aborting." << endl;
119  throw;
120  }
121  for (unsigned int i = 0; i < nmbIncohSubAmps(); ++i)
122  _incohSubAmps[i] -= amp.incohSubAmp(i);
123  return *this;
124 }
125 
126 
127 bool
128 amplitudeTreeLeaf::containsIncohSubAmp(const string& subAmpLabel) const
129 {
130  labelToIndexMapIterator entry = _labelToIndexMap.find(subAmpLabel);
131  if (entry == _labelToIndexMap.end())
132  return false;
133  return true;
134 }
135 
136 
137 unsigned int
138 amplitudeTreeLeaf::incohSubAmpIndex(const string& subAmpLabel) const
139 {
140  labelToIndexMapIterator entry = _labelToIndexMap.find(subAmpLabel);
141  if (entry == _labelToIndexMap.end()) {
142  printErr << "cannot find subamp '" << subAmpLabel << "'. aborting." << endl;
143  throw;
144  }
145  return entry->second;
146 }
147 
148 
149 const string&
150 amplitudeTreeLeaf::incohSubAmpName(const unsigned int subAmpIndex) const
151 {
152  if (subAmpIndex < _incohSubAmpLabels.size())
153  return _incohSubAmpLabels[subAmpIndex];
154  else {
155  printErr << "subamp index " << subAmpIndex << " is out of range. aborting." << endl;
156  throw;
157  }
158 }
159 
160 
161 void
162 amplitudeTreeLeaf::defineIncohSubAmps(const vector<string>& subAmpLabels)
163 {
164  const unsigned int nmbSubAmps = subAmpLabels.size();
165  if (nmbSubAmps < 2)
166  printWarn << "vector with subamp labels '" << subAmpLabels << "' has less than 2 entries. "
167  << "using single amplitude value." << endl;
168  // make sure labels are unique
169  vector<string> uniqueLabels = subAmpLabels;
170  sort(uniqueLabels.begin(), uniqueLabels.end());
171  uniqueLabels.erase(unique(uniqueLabels.begin(), uniqueLabels.end()), uniqueLabels.end());
172  if (uniqueLabels.size() < nmbSubAmps) {
173  printErr << "vector with subamp labels '" << subAmpLabels << "' contains dublicate entries. "
174  << "aborting." << endl;
175  throw;
176  }
177  _incohSubAmps.resize(nmbSubAmps, 0);
178  _incohSubAmpLabels = subAmpLabels;
180 }
181 
182 
183 ostream&
184 amplitudeTreeLeaf::print(ostream& out) const
185 {
186  out << "amplitude tree leaf:" << endl;
187  const unsigned int nmbSubAmps = nmbIncohSubAmps();
188  if (nmbSubAmps > 1) {
189  out << " number of incoherent sub-amps ... " << nmbSubAmps << endl;
190  out << " amplitude value(s):" << endl;
191  for (unsigned int i = 0; i < nmbSubAmps; ++i)
192  out << " [" << setw(4) << i << "] = '" << _incohSubAmpLabels[i]
193  << "' = " << maxPrecisionDouble(_incohSubAmps[i]) << endl;
194  } else if (nmbSubAmps == 1)
195  out << " amplitude ... " << _incohSubAmps[0] << endl;
196  else
197  out << " no amplitude value" << endl;
198  return out;
199 }
200 
201 
202 void
204 {
205  _labelToIndexMap.clear();
206  for (unsigned int i = 0; i < _incohSubAmpLabels.size(); ++i)
208 }