MINT2
Amplitude.cpp
Go to the documentation of this file.
1 // author: Jonas Rademacker (Jonas.Rademacker@bristol.ac.uk)
2 // status: Mon 9 Feb 2009 19:17:57 GMT
3 #include "Mint/Amplitude.h"
4 #include "Mint/SpinFactorMaker.h"
5 #include "Mint/LineshapeMaker.h"
6 #include "Mint/Utils.h"
7 
8 #include "Mint/Permutator.h"
9 
10 #include <algorithm>
11 
12 using namespace std;
13 using namespace MINT;
14 
15 Amplitude::Amplitude( const DecayTree& decay
16  , const std::string& namePrefix
17  , const std::string& lineshapePrefix
18  , char SPD_Wave
19  , const std::string& lopt
20  , const std::vector<double>& numOpts
21  , IFitParRegister* daddy
22  )
23  : FitParDependent(daddy)
24  , _associatingDecayTree(decay)
25  , _spinFactor(0)
26  , _prefix(namePrefix)
27  , _lsPrefix(lineshapePrefix)
28  , _spd(SPD_Wave)
29  , _lopt(lopt)
30  , _numOpts(numOpts)
31  , _pat()
32  , _init(false)
33 {
34  //createDependants();
35 }
36 
38  , IFitParRegister* daddy
39  )
40  : FitParDependent(daddy)
41  , _associatingDecayTree(ampInit.tree())
42  , _spinFactor(0)
43  , _prefix(ampInit.prefix())
44  , _lsPrefix(ampInit.lsPrefix())
45  , _spd(ampInit.SPD())
46  , _lopt(ampInit.lopt())
47  , _numOpts(ampInit.numOpts())
48  , _pat()
49  , _init(false)
50 {
51  //createDependants();
52 }
53 
54 Amplitude::Amplitude( const Amplitude& other
55  , IFitParRegister* newDaddy)
56 //: IReturnRealForEvent<IDalitzEvent>()
58  , CachedByEvent(other)
59  , FitParDependent(other, newDaddy)
60  , _associatingDecayTree(other._associatingDecayTree)
61  , _spinFactor(0)
62  , _prefix(other._prefix)
63  , _lsPrefix(other._lsPrefix)
64  , _spd(other._spd)
65  , _lopt(other._lopt)
66  , _numOpts(other._numOpts)
67  , _pat(other._pat)
68  , _init(false)
69 {
70  // association is done, rest needs to be re-done.
71  deleteDependants();
72 }
73 
76 }
77 
79  bool dbThis=false;
80  if(dbThis) cout << "Amplitude::deleteDependants()" << endl;
81  _init=false;
82  this->removeAllFitParDependencies(); // risky
84  if(0 != _spinFactor) delete _spinFactor;
85  _spinFactor=0;
86  if(dbThis) cout << "Amplitude::deleteDependants() done" << endl;
87  return true;
88 }
90  bool dbThis=false;
91  if(dbThis){
92  cout << "Amplitude::createDependants, for " << name()
93  << ". Calling SpinFactorMake with _spd = " << _spd
94  << " and _lopt = " << _lopt << endl;
95  }
96  //_spinFactor = SpinFactorMaker(theBareDecay(), _spd, _lopt);
98  if(dbThis) cout << "got this spin factor: " << _spinFactor->name() << endl;
99  if(0 == _spinFactor) return false;
100  bool cl = createLineshapes();
101 
102  cout << "Amplitude::createDependants() after creating lineshape, I depend on these fitParameters:"
103  << endl;
104  this->listFitParDependencies(cout);
105 
106  if(0 == cl) return false;
107  return true;
108 }
112  if(! _init){
113  cout << "ERROR: Amplitude::renew() failed" << endl;
114  }
115  return _init;
116 }
118  AssociatingDecayTree newTree(dt);
119  _associatingDecayTree = newTree;
120  return renew();
121  //return deleteDependants();
122 }
124  DecayTree dt = theBareDecay();
125  anti(dt);
126  return resetTree(dt);
127 }
128 
130  DecayTree dt = theBareDecay();
131  anti(dt);
132  dt.getVal().antiThis();
133  return resetTree(dt);
134 }
135 
137  DecayTree dt = theBareDecay();
138  dt.getVal().antiThis();
139  return resetTree(dt);
140 }
141 
142 bool Amplitude::setL(int L){
143  DecayTree dt = theBareDecay();
144  dt.getVal().setL(L);
145  return resetTree(dt);
146 }
147 
149  if(0 == lsPtr) return false;
150  this->registerFitParDependence(*lsPtr);
151  _LineshapeList.push_back(lsPtr);
152  return true;
153 }
154 
156  counted_tree_ptr){
157  return createLineshapes(counted_tree_ptr.get());
158 }
160  bool dbThis=false;
161  if(0==treePtr) {
162  /*
163  cout << "Amplitude::createLineshapes for treePtr: \n"
164  << theDecay()
165  << "\n first call in recursive operation" << endl;
166  */
167  if(_pat.empty()){
168  cout << "Amplitude::createLineshapes: cannot create line-shapes"
169  << " unless _pat is set. Bailing out."
170  << endl;
171  throw "no lineshapes without pattern";
172  }
173  return createLineshapes(& theDecay(_pat));
174  }
175  // cout << " >> " << treePtr->oneLiner() << endl;
176 
177  bool success=true;
178  if(treePtr->nDgtr() >= 2){
180  // LineshapeList.push_back(LineshapeMaker(treePtr, _lopt));
181  if(dbThis){
182  cout << "Amplitude::createLineshapes: just added lineshape: ";
183  _LineshapeList.back()->print(cout);
184  cout << endl;
185  }
186  }
187  for(int i=0; i< treePtr->nDgtr(); i++){
188  success &= createLineshapes(treePtr->getDgtrTreePtr(i));
189  }
190  return success;
191 }
193  bool dbThis=false;
194  if(dbThis) cout << "Amplitude::deleteLineshapes()" << endl;
195  for(std::vector<ILineshape*>::iterator it = _LineshapeList.begin();
196  it != _LineshapeList.end(); it++){
197  if(0 != *it) delete (*it);
198  }
199  _LineshapeList.clear();
200 
201  if(dbThis) cout << "Amplitude::deleteLineshapes() done" << endl;
202  return true;
203 }
204 
205 std::complex<double> Amplitude::SpinFactorValue(IDalitzEvent& evt){
206  // bool dbThis=true;
207  /*
208  if(dbThis) {
209  cout << "amplitude " << name()
210  << " calling spin factor: "
211  << spinFactor()->name() << endl;
212  }
213  */
214  if(0 == spinFactor()) initialise(evt.eventPattern());
215  /*
216  if(dbThis){
217  cout << " spin factor value is: "
218  << spinFactor()->getVal(evt) << endl;
219  }
220  */
221  return spinFactor()->ComplexVal(evt);
222 }
223 
224 std::complex<double> Amplitude::LineshapeProduct(IDalitzEvent& evt){
225  //bool dbThis=false;
226  std::complex<double> prod(1.,0.);
227  /*
228  if(dbThis){
229  cout << "Amplitude::LineshapeProduct() for " << name() << endl;
230  cout << " ...calling lineshapes: " << endl;
231  }
232  */
233  for(std::vector<ILineshape*>::iterator it = _LineshapeList.begin();
234  it != _LineshapeList.end(); it++){
235  //if(dbThis && 0 != *it) cout << (*it)->name() << ", " << (*it)->getVal(evt);
236  if(0 != *it) prod *= (*it)->getVal(evt);
237  }
238  //if(dbThis) cout << " done. Returning " << prod << endl;
239  return prod;
240 }
241 
243  , double nSigma){
244  Permutator perms(pat);
245  DalitzBoxSet v;
246 
247 
248  for(unsigned int i=0; i < perms.size(); i++){
249  v.add(MakeBox(pat, perms[i], nSigma));
250  }
251 
252  return v;
253 }
254 
256  , const Permutation& perm
257  , double nSigma
258  ){
259  cout << "making box for " << (*this) << endl;
260  DalitzBoxSet v;
261  double maxHeight = 1;// norm(this->getValAtResonance());
262  double maxHeight_2 = maxHeight;
263  if(_LineshapeList.size() >= 2){
264  maxHeight_2 *= exp(-0.5*(nSigma*nSigma*0.75));
265  }
266  std::vector<DalitzCoordinate> limits;
267  for(std::vector<ILineshape*>::iterator it = _LineshapeList.begin();
268  it != _LineshapeList.end(); it++){
269  DalitzCoordinate coord ((*it)->getDalitzCoordinate(nSigma).mapMe(perm) );
270  if(coord.size() <= 3){ // otherwise it's the D itself
271  DalitzBox box(pat, coord);
272  box.setName(this->theBareDecay().oneLiner()
273  + " limit: " + coord.name()
274  + " " + anythingToString((int)nSigma) + " sigma");
276  box.setGuessedHeight(maxHeight_2);
277  v.push_back(box);
278 
279  limits.push_back( coord );
280  }
281  }
282  DalitzBox lastBox(pat, limits);
283  lastBox.setGuessedHeight(1);//norm(this->getValAtResonance()));
284  cout << " just set box height, it's " << lastBox.guessedHeight() << endl;
285  lastBox.setName(this->theBareDecay().oneLiner()
286  + " all limits"
287  + " " + anythingToString((int)nSigma) + " sigma");
288  cout << " .. now it is " << lastBox.guessedHeight() << endl;
289  lastBox.encloseInPhaseSpaceArea();
290  cout << "Amp " << name() << " made box with guessed height "
291  << 1//norm(1)//this->getValAtResonance())
292  << " = " << lastBox.guessedHeight()
293  << "\n that's the one" << lastBox
294  << endl;
295  v.push_back(lastBox);
296  return v;
297 }
298 
299 
301  , TRandom* rnd
302  ){
303  bool dbThis=false;
304  Permutator perms(pat);
305  DalitzBWBoxSet v(rnd);
306 
307  for(unsigned int i=0; i < perms.size(); i++){
308  DalitzBWBox box(MakeBWBox(pat, perms[i], rnd));
309  box.height() = boxFactor()/perms.size();
310  if(dbThis){
311  cout << "setting boxHeight to " << box.height()
312  << " = " << boxFactor() << " / " << perms.size()
313  << endl;
314  }
315  v.add(box);
316  }
317 
318  return v;
319 }
320 
322  , const Permutation& perm
323  , TRandom* rnd
324  ){
325  bool dbThis=false;
326  if(dbThis) cout << "making bw-box for " << (*this) << endl;
327 
328  std::vector<counted_ptr<IGenFct> > limits;
329  for(std::vector<ILineshape*>::iterator it = _LineshapeList.begin();
330  it != _LineshapeList.end(); it++){
331  if(dbThis){
332  cout << "adding co-ordinate "
333  << (*it)->getDalitzCoordinate()
334  << " to box." << endl;
335  }
336  DalitzCoordinate coord ((*it)->getDalitzCoordinate().mapMe(perm) );
337  counted_ptr<IGenFct> fct( (*it)->generatingFunction() );
338  fct->setCoordinate(coord);
339  if((int) coord.size() < pat.numDaughters()){
340  // otherwise it's the D itself (coord.size is the number of
341  // indices in s_ij..)
342  // so s12 or s23 have 2, s123 has 3, s1234 has 4.)
343  limits.push_back(fct);
344  }
345  }
346  DalitzBWBox box(pat, limits, 0, rnd);
347  box.setName(this->theBareDecay().oneLiner()
348  + " BW");
349  return box;
350 }
351 
352 
353 /*
354 double Amplitude::LineshapeGaussProduct(){
355  // return 1;//
356  double prod=1;
357 
358  for(std::vector<ILineshape*>::iterator it = LineshapeList.begin();
359  it != LineshapeList.end(); it++){
360  if(0 != *it) prod *= (*it)->gaussianApprox().getVal();
361  }
362  return prod;
363 }
364 */
365 
367  //bool dbThis=false;
368 
369  std::complex<double> sf = SpinFactorValue(evt);
370  complex<double> ls = LineshapeProduct(evt);
371 
372  /*
373  complex<double> returnVal = sf*ls;
374  if(dbThis){
375  //if(LineshapeList.size() >=2){
376  // complex<double> evtGen = LineshapeList[1]->EvtGenValue();
377  // complex<double> diff = returnVal - evtGen;
378  // if(abs(diff) > 1.e-10){
379  // cout << " EvtGenCheck: " << returnVal << " - " << evtGen
380  // << " = " << diff << endl;
381  // }
382  // }
383 
384  cout << theBareDecay().oneLiner() << ":"
385  << "\n > spinFactor " << sf
386  << "\n > LineshapeProduct " << ls
387  << "\n > Returning: " << returnVal
388  << endl;
389  cout << "-----------------------------------------" << endl;
390  }
391  return returnVal;
392  */
393  return sf*ls;
394 }
395 
396 std::complex<double> Amplitude::getVal(IDalitzEvent* evt){
397  if(0 == evt) return 0;
398  return this->getVal(*evt);
399 }
400 
401 std::complex<double> Amplitude::getNewVal(IDalitzEvent& evt){
402  //bool dbThis=false;
403 
404  //initialiseIfNeeded(evt.eventPattern());
406  complex<double> sum=0;
407 
408  //if(! evt.eventPattern().compatibleWithFinalState(getTreePattern())) return 0;
409 
410 // if(dbThis) cout << "num permutations: " << evt.numPermutations() << endl;
411  for(int i=0; i < evt.numPermutations(); i++){
412  evt.setPermutationIndex(i);
413  //complex<double> thisVal= getOnePermutationsVal(evt);
414 
415 /* if(dbThis){
416  cout << " permutation " << i
417  << " makes event look like this: ";
418  evt.print();
419  cout << "\n gets thisVal " << thisVal << endl;
420  }*/
421 
422  sum += getOnePermutationsVal(evt);
423  }
424  evt.setPermutationIndex(0);
425  sum /= sqrt((double) evt.numPermutations());
426 
427 // if(dbThis) cout << "returning " << sum << endl;
428  /*
429  if(dbThis && abs(sum) > sqrt((double) 1000)){
430  cout << " Amplitude : " << (*this)
431  << " returning a large value: " << sum
432  << endl;
433  }
434 
435  if(dbThis){
436  cout << "Amplitude::getVal() for "
437  << name() << endl;
438  cout << " returning " << sum << endl;
439  cout << "==========================================" << endl;
440  }
441  */
442  return sum;
443 }
444 
445 
446 std::string Amplitude::name() const{
447  return (std::string) "("
448  + _spd
449  + " wave) with opt " + _lopt + "; "
450  + theBareDecay().oneLiner();
451 }
452 
453 void Amplitude::print(std::ostream& out) const{
454  out << "(" << _spd << " wave)\n" << theBareDecay();
455 }
456 
457 std::ostream& operator<<(std::ostream& out, const Amplitude& amp){
458  amp.print(out);
459  return out;
460 }
461 
462 //
virtual std::complex< double > getNewVal(IDalitzEvent &evt)
Definition: Amplitude.cpp:401
double & height()
Definition: DalitzBWBox.h:36
std::complex< double > getOnePermutationsVal(IDalitzEvent &evt)
Definition: Amplitude.cpp:366
bool deleteDependants()
Definition: Amplitude.cpp:78
void anti(DecayTree &dt)
Definition: DecayTree.cpp:16
std::string name() const
Definition: Amplitude.cpp:446
const X * get() const
Definition: counted_ptr.h:217
virtual DalitzBoxSet MakeBox(const DalitzEventPattern &pat, const Permutation &perm, double nSigma=3)
Definition: Amplitude.cpp:255
void push_back(const T &c)
bool createDependants()
Definition: Amplitude.cpp:89
DalitzEventPattern _pat
Definition: Amplitude.h:55
virtual ~Amplitude()
Definition: Amplitude.cpp:74
ISpinFactor * spinFactor()
Definition: Amplitude.h:169
virtual void setPermutationIndex(int i)=0
virtual DalitzBoxSet MakeBoxes(const DalitzEventPattern &pat, double nSigma=3)
Definition: Amplitude.cpp:242
void encloseInPhaseSpaceArea()
Definition: DalitzBox.h:128
std::ostream & operator<<(std::ostream &out, const Amplitude &amp)
Definition: Amplitude.cpp:457
AssociatingDecayTree _associatingDecayTree
Definition: Amplitude.h:47
virtual std::string name() const =0
virtual int numPermutations() const =0
char _spd
Definition: Amplitude.h:51
bool createLineshapes(const MINT::const_counted_ptr< AssociatedDecayTree > &counted_tree_ptr)
Definition: Amplitude.cpp:155
virtual void setCoordinate(const DalitzCoordinate &c)=0
const ValueType & getVal() const
Definition: DDTree.h:102
void setGuessedHeight(double h)
Definition: DalitzBox.h:100
std::vector< ILineshape * > _LineshapeList
Definition: Amplitude.h:58
bool _init
Definition: Amplitude.h:56
const std::string & lsPrefix() const
Definition: Amplitude.h:62
bool CConjugateFinalState()
Definition: Amplitude.cpp:129
virtual std::complex< double > getVal(IDalitzEvent &evt)
Definition: Amplitude.h:122
virtual std::complex< double > ComplexVal(IDalitzEvent &evt)=0
ILineshape * LineshapeMaker(const AssociatedDecayTree *tree, const std::string &lineshapePrefix, const std::string &lopt, const std::vector< double > &numOptions=std::vector< double >())
virtual double boxFactor()
Definition: Amplitude.h:68
double guessedHeight() const
Definition: DalitzBox.h:101
bool CPConjugate()
Definition: Amplitude.cpp:123
virtual bool registerFitParDependence(const IFitParDependent &fpd)
bool setL(int L)
Definition: Amplitude.cpp:142
bool resetTree(const DecayTree &dt)
Definition: Amplitude.cpp:117
bool addLineshape(ILineshape *ls)
Definition: Amplitude.cpp:148
MINT::const_counted_ptr< DDTree< ValueType > > getDgtrTreePtr(int i) const
Definition: DDTree.h:114
void add(const DalitzBox &box)
bool initialise(const DalitzEventPattern &pat)
Definition: Amplitude.h:85
void setL(int l)
Definition: DecayTreeItem.h:61
Amplitude(const DecayTree &decay, const std::string &namePrefix="", const std::string &lineshapePrefix="", char SPD_Wave='?', const std::string &opt="", const std::vector< double > &numOpt=std::vector< double >(), IFitParRegister *daddy=0)
std::vector< double > _numOpts
Definition: Amplitude.h:53
virtual const DalitzEventPattern & eventPattern() const =0
const AssociatedDecayTree & theDecay(const DalitzEventPattern &pat) const
Definition: Amplitude.h:143
void setName(const std::string &name)
Definition: DalitzBox.h:97
bool deleteLineshapes()
Definition: Amplitude.cpp:192
unsigned int size() const
std::string anythingToString(const T &anything)
Definition: Utils.h:62
virtual DalitzBWBox MakeBWBox(const DalitzEventPattern &pat, const Permutation &perm, TRandom *rnd=gRandom)
Definition: Amplitude.cpp:321
void print(std::ostream &out=std::cout) const
Definition: Amplitude.cpp:453
std::string _lopt
Definition: Amplitude.h:52
int nDgtr() const
Definition: DDTree.h:96
void setName(const std::string &name)
Definition: DalitzBWBox.h:62
void oneLiner(std::stringstream &seam, int generation=0) const
Definition: DDTree.h:375
DecayTree theBareDecay() const
Definition: Amplitude.h:157
bool renew()
Definition: Amplitude.cpp:109
ISpinFactor * _spinFactor
Definition: Amplitude.h:48
void CheckAndMatchPattern(const DalitzEventPattern &pat) const
Definition: Amplitude.h:149
ISpinFactor * SpinFactorMaker(const AssociatedDecayTree &thisDcy, char SPD_Wave='?', const std::string &lopt="")
std::complex< double > SpinFactorValue(IDalitzEvent &evt)
Definition: Amplitude.cpp:205
virtual DalitzBWBoxSet MakeBWBoxes(const DalitzEventPattern &pat, TRandom *rnd=gRandom)
Definition: Amplitude.cpp:300
void add(DalitzBWBox &box)
bool CConjugateInitialState()
Definition: Amplitude.cpp:136
std::complex< double > LineshapeProduct(IDalitzEvent &evt)
Definition: Amplitude.cpp:224
void listFitParDependencies(std::ostream &os=std::cout) const