MINT2
FitAmpList.cpp
Go to the documentation of this file.
1 // author: Jonas Rademacker (Jonas.Rademacker@bristol.ac.uk)
2 // status: Mon 9 Feb 2009 19:18:03 GMT
3 #include "Mint/FitAmpList.h"
4 
5 #include "Mint/FitAmplitude.h"
8 #include "Mint/FitAmplitude.h"
9 #include "Mint/FitAmpSum.h"
11 #include "Mint/FitAmpPairList.h"
12 #include "Mint/MultiTopHat.h"
13 
14 #include <iostream>
15 
16 using namespace std;
17 using namespace MINT;
18 
20  , const char* fname
21  , MinuitParameterSet* pset
22  , const std::string& prefix
23  , const std::string& lineshapePrefix
24  , const std::string& opt
25  )
26  : FitAmpListBase()
27  , _pat(pat)
28  , _minuitParaSet(pset)
29  , _opt(opt)
30 {
31  if(0 != fname){
32  _paraFName = fname;
33  }else{
34  _paraFName.clear();
35  }
36 
37  createAllAmps(pat, prefix, lineshapePrefix);
38 }
39 
41  , MinuitParameterSet* pset
42  , const std::string& prefix
43  , const std::string& lineshapePrefix
44  , const std::string& opt
45  )
46  : FitAmpListBase()
47  , _pat(pat)
48  , _minuitParaSet(pset)
49  , _opt(opt)
50 {
51 
52  cout << "pset pointer in FitAmpList::FitAmpList " << getMPS() << endl;
53 
54  _paraFName.clear();
55 
56  createAllAmps(pat, prefix, lineshapePrefix);
57 }
59  , const std::string& prefix
60  , const std::string& lineshapePrefix
61  , const std::string& opt
62  )
63  : FitAmpListBase()
64  , _pat(pat)
65  , _minuitParaSet(0)
66  , _opt(opt)
67 {
68 
69  _paraFName.clear();
70 
71  createAllAmps(pat, prefix, lineshapePrefix);
72 }
73 
75  : FitAmpListBase(other)
76  , _pat(other._pat)
77  , _paraFName(other._paraFName)
78  , _minuitParaSet(other._minuitParaSet)
79  , _opt(other._opt)
80 {
81 }
82 
84  if(&other == this) return *this;
85 
86  (FitAmpListBase)(*this) = (FitAmpListBase) (other);
87  _pat = other._pat;
88  _paraFName = other._paraFName;
90  _opt = other._opt;
91  return *this;
92 }
93 
94 
96  if(0 == _minuitParaSet) _minuitParaSet = MinuitParameterSet::getDefaultSet();
97  return _minuitParaSet;
98 }
99 
101  bool dbThis=false;
102  if(dbThis) cout << "FitAmpList::GetCloneSameFitParameters()" << endl;
103  /*
104  There'll be 'physical' copies of all Amplitudes, but the
105  FitParameters remain the same (pointers to the same
106  FitParameter Object). This is useful for the CP-con coding
107  as it is now, but perhaps a bit counter-intuitive. needs to
108  be reviewed at some point. This behaviour is defined in the
109  copy constructor of the FitAmplitude class.
110  */
111 
112  counted_ptr<FitAmpList> newList(new FitAmpList(*this));
113  return newList;
114 }
115 
117  bool dbThis=false;
118  if(dbThis) cout << "FitAmpList::GetCPConjugateSameFitParameters()" << endl;
119 
121  newList->CPConjugateSameFitParameters();
122  return newList;
123 }
124 
126  , const std::string& prefix
127  , const std::string& lineshapePrefix
128  ){
129  bool dbThis=false;
130 
131  // cout << "pset pointer in FitAmpList::createAllAmps " << getMPS() << endl;
132 
134 
135  if(! ndl){
136  cout << "ERROR in FitAmpList::createAllAmps!"
137  << "\n > Can't get NamedDecayTreeList."
138  << endl;
139  return false;
140  }
141 
142  if(ndl->size() == 0){
143  cout << "ERROR in FitAmpList::createAllAmps!"
144  << "\n > NamedDecayTreeList is empty."
145  << endl;
146  return false;
147  }
148 
149  bool success=true;
150  const char* fnamePtr = 0;
151  if( ! _paraFName.empty()){
152  fnamePtr = _paraFName.c_str();
153  }
154  for(AmpInitMap::const_iterator it= ndl->trees(_opt).begin();
155  it != ndl->trees(_opt).end();
156  it++){
157 
158  const DecayTree& theTree = it->second.tree();
159  if(! thePattern.compatibleWith(theTree)) continue;
160  if(dbThis) cout << "making amplitude " << prefix + it->first << endl;
161 
162  if(A_is_in_B("TopHats", it->second.lopt())){
163  cout << "making TopHats" << endl;
164  NamedParameter<double> TopHatsLimits("TopHatsLimits");
165  if(TopHatsLimits.size() < 2){
166  cout << "error when setting TopHatsLimits: need at least 2 limits, have "
167  << TopHatsLimits.size() << endl;
168  continue;
169  }
170  MultiTopHat mth;
171  for( int i=1; i < TopHatsLimits.size(); i++){
172  double lo = TopHatsLimits.getVal(i-1);
173  double hi = TopHatsLimits.getVal(i);
174 
175  cout << "TopHatLimits: " << lo << ", " << hi << endl;
176  AmpInitialiser ai(it->second, prefix, lineshapePrefix);
177  ai.setNumOpts(lo, hi);
178  ai.setIndex(i);
179 
180  cout << "ai set " << endl;
181  //success &= addAmplitude(new FitAmplitude(prefix + it->first + "_" + anythingToString(i)
182 
183  FitAmplitude* famp(new FitAmplitude(ai
184  , fnamePtr
185  , getMPS()
186  )
187  );
188  if(! famp->canBeIgnored()){
189  if(dbThis) cout << "adding this: " << *famp << endl;
190  success &= mth.addAmplitude(famp);
191  }else{
192  if(dbThis) cout << "ignoring this: " << *famp << endl;
193  delete famp;
194  }
195  }
196  addAsList(mth);
197  }else{
198  if(dbThis)cout << "making a normal amplitude " << it->first << endl;
199  if(dbThis)cout << "with prefix: " << prefix << endl;
200  if(dbThis)cout << "lopt: " << it->second.lopt() << endl;
201  AmpInitialiser ai(it->second, prefix, lineshapePrefix);
202  if(dbThis)cout << "lopt2 " << ai.lopt() <<endl;
203  if(dbThis)cout << "at FitAmpList: lineshapePrefix " << lineshapePrefix << endl;
204  FitAmplitude* famp(new FitAmplitude( ai
205  , fnamePtr
206  , getMPS()
207  )
208  );
209  if(! famp->canBeIgnored()){
210  if(dbThis)cout << "adding this: " << *famp << endl;
211  success &= this->addAmplitude(famp);
212  }else{
213  if(dbThis) cout << "ignoring this: " << *famp << endl;
214  delete famp;
215  }
216  }
217  if(! success){
218  cout << "ERROR in FitAmpList::createAllAmps!"
219  << "\n > failed to create FitAmplitude"
220  << "\n > for decay name " << it->first
221  << "\n > \"new\" returned zero."
222  << "\n > I'll keep going and try to"
223  << "\n > create the other amplitudes."
224  << endl;
225  }
226 
227  }
228  return success;
229 }
230 
231 void FitAmpList::printLargestAmp(IDalitzEvent& evt, std::ostream& os){
232  bool dbthis=false;
233  if(_fitAmps.empty()) createAllAmps(evt.eventPattern());
235  (void)dbthis;
236 }
237 
238 
239 void FitAmpList::printAllAmps(IDalitzEvent& evt, std::ostream& os){
240  bool dbThis=false;
241  if(_fitAmps.empty()) createAllAmps(evt.eventPattern());
243  (void)dbThis;
244 }
245 
246 void FitAmpList::printNonZeroWithValue(IDalitzEvent& evt, std::ostream& os){
247  bool dbThis=false;
248  if(_fitAmps.empty()) createAllAmps(evt.eventPattern());
250  (void)dbThis;
251 }
252 
254  bool dbThis=false;
255  if(dbThis) cout << "FitAmpList::~FitAmpList()" << endl;
256  deleteAll();
257  if(dbThis) cout << "FitAmpList::~FitAmpList() done" << endl;
258 }
259 
261  add(other);
262  return *this;
263 }
265  FitAmpList fas(*this);
266  fas.add(rhs);
267  return fas;
268 }
269 
270 
272  multiply(r);
273  return *this;
274 }
275 FitAmpList& FitAmpList::operator*=(const complex<double>& z){
276  multiply(z);
277  return *this;
278 }
280  multiply(irc);
281  return *this;
282 }
283 
285  FitAmpList fas(*this);
286  fas.multiply(r);
287  return fas;
288 }
289 FitAmpList FitAmpList::operator*(const complex<double>& z) const{
290  FitAmpList fas(*this);
291  fas.multiply(z);
292  return fas;
293 }
295  FitAmpList fas(*this);
296  fas.multiply(irc);
297  return fas;
298 }
299 
300 
301 FitAmpList operator*(double r, const FitAmpList& rhs){
302  FitAmpList fas(rhs);
303  fas.multiply(r);
304  return fas;
305 }
306 FitAmpList operator*(const complex<double>& z, const FitAmpList& rhs){
307  FitAmpList fas(rhs);
308  fas.multiply(z);
309  return fas;
310 }
312  , const FitAmpList& rhs){
313  FitAmpList fas(rhs);
314  fas.multiply(irc);
315  return fas;
316 }
317 
318 std::ostream& operator<<(std::ostream& os, const FitAmpList& fal){
319  fal.print(os);
320  return os;
321 }
322 
323 //
FitAmpList & operator+=(const FitAmpList &other)
Definition: FitAmpList.cpp:260
friend class FitAmplitude
Definition: FitAmpList.h:102
virtual int add(const FitAmpListBase &other, double factor=1)
virtual int size() const
virtual bool addAmplitude(FitAmplitude *fa)
virtual void printLargestAmp(IDalitzEvent &evt, std::ostream &os=std::cout)
Definition: FitAmpList.cpp:231
const std::string & lopt() const
FitAmpList & operator *=(double r)
Definition: FitAmpList.cpp:271
void setIndex(int index)
virtual bool CPConjugateSameFitParameters()
bool canBeIgnored() const
virtual void printAllAmps(std::ostream &os=std::cout) const
Definition: FitAmpList.h:93
bool compatibleWith(const DecayTree &tree) const
std::ostream & operator<<(std::ostream &os, const FitAmpList &fal)
Definition: FitAmpList.cpp:318
std::string _opt
Definition: FitAmpList.h:37
FitAmpList operator+(const FitAmpList &other) const
Definition: FitAmpList.cpp:264
FitAmpList operator *(double r, const FitAmpList &rhs)
Definition: FitAmpList.cpp:301
virtual void printLargestAmp(IDalitzEvent &evt, std::ostream &os=std::cout)
virtual void deleteAll()
virtual int addAsList(const FitAmpListBase &other, double factor=1)
bool A_is_in_B(const std::string &a, const std::string &b)
Definition: Utils.cpp:34
virtual void printNonZeroWithValue(IDalitzEvent &evt, std::ostream &os=std::cout)
std::vector< FitAmplitude * > _fitAmps
virtual void printNonZeroWithValue(IDalitzEvent &evt, std::ostream &os=std::cout)
Definition: FitAmpList.cpp:246
FitAmpList operator *(double r) const
Definition: FitAmpList.cpp:284
DalitzEventPattern _pat
Definition: FitAmpList.h:32
virtual MINT::MinuitParameterSet * getMPS()
Definition: FitAmpList.cpp:95
static NamedDecayTreeList * getMe(const std::string &printopt="printNever")
FitAmpList(const DalitzEventPattern &pat, const char *fname=0, MINT::MinuitParameterSet *pset=0, const std::string &prefix="", const std::string &lineshapePrefix="", const std::string &opt="")
Definition: FitAmpList.cpp:19
virtual const DalitzEventPattern & eventPattern() const =0
virtual MINT::counted_ptr< FitAmpListBase > GetCPConjugateSameFitParameters() const
Definition: FitAmpList.cpp:116
const AmpInitMap & trees(const std::string &opt="ALL") const
unsigned int size(const std::string &opt="ALL") const
std::string _paraFName
Definition: FitAmpList.h:33
virtual MINT::counted_ptr< FitAmpListBase > GetCloneSameFitParameters() const
Definition: FitAmpList.cpp:100
virtual const T & getVal(int i=0) const
virtual void print(std::ostream &os=std::cout) const
virtual bool createAllAmps(const DalitzEventPattern &thePattern, const std::string &prefix="", const std::string &lineshapePrefix="")
Definition: FitAmpList.cpp:125
MINT::MinuitParameterSet * _minuitParaSet
Definition: FitAmpList.h:35
virtual void printAllAmps(std::ostream &os=std::cout) const
void setNumOpts(const std::vector< double > &numOpts_in=std::vector< double >())
virtual void multiply(double r)
virtual ~FitAmpList()
Definition: FitAmpList.cpp:253
FitAmpList & operator=(const FitAmpList &other)
Definition: FitAmpList.cpp:83