MINT2
FitAmpIncoherentSum.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
4 
5 #include "Mint/FitAmplitude.h"
8 #include "Mint/FitAmplitude.h"
9 #include "Mint/IntegCalculator.h"
10 
11 #include <iostream>
12 #include <complex>
13 
14 using namespace std;
15 using namespace MINT;
16 
18  return "Inco_";
19 }
20 
22  , const char* fname
23  , MinuitParameterSet* pset
24  , const std::string& prefix
25  , const std::string& lineshapePrefix
26  , const std::string& opt
27  )
28  : FitAmpList(pat, fname, pset, FitAmpIncoherentSum::IncPrefix()+ prefix, lineshapePrefix, opt)
29  , _useAnalyticGradient("useAnalyticGradient",0)
30 {
31  /*
32  //Important! Ensures everything is initialised
33  DalitzEventList eventTest;
34  eventTest.generatePhaseSpaceEvents(1,pat);
35  this->getVal(eventTest[0]);
36  */
37 }
38 
40  , MinuitParameterSet* pset
41  , const std::string& prefix
42  , const std::string& lineshapePrefix
43  , const std::string& opt
44  )
45  : FitAmpList(pat, pset, FitAmpIncoherentSum::IncPrefix() + prefix, lineshapePrefix, opt)
46  , _useAnalyticGradient("useAnalyticGradient",0)
47 {
48  /*
49  //Important! Ensures everything is initialised
50  DalitzEventList eventTest;
51  eventTest.generatePhaseSpaceEvents(1,pat);
52  this->getVal(eventTest[0]);
53  */
54 }
56  , const std::string& prefix
57  , const std::string& lineshapePrefix
58  , const std::string& opt
59  )
60  : FitAmpList(pat, FitAmpIncoherentSum::IncPrefix() + prefix, lineshapePrefix, opt)
61  , _useAnalyticGradient("useAnalyticGradient",0)
62 {
63  /*
64  //Important! Ensures everything is initialised
65  DalitzEventList eventTest;
66  eventTest.generatePhaseSpaceEvents(1,pat);
67  this->getVal(eventTest[0]);
68  */
69 }
70 
75  , FitAmpList(other), _useAnalyticGradient("useAnalyticGradient",0)
76 {
77  /*
78  //Important! Ensures everything is initialised
79  DalitzEventList eventTest;
80  eventTest.generatePhaseSpaceEvents(1,_pat);
81  this->getVal(eventTest[0]);
82  */
83 }
84 
89  , FitAmpList(other), _useAnalyticGradient("useAnalyticGradient",0)
90 {
91  /*
92  //Important! Ensures everything is initialised
93  DalitzEventList eventTest;
94  eventTest.generatePhaseSpaceEvents(1,_pat);
95  this->getVal(eventTest[0]);
96  */
97 }
99 // need to reform these one day...
100 // ... it all relies on the copy-constructur/=operator in FitAmpitude
101 // not copying the fit parameters, but just their pointers
102 // which will need to be reviewed.
103 //
104  bool dbThis=false;
105  if(dbThis) cout << "FitAmpSum::GetCloneSameFitParameters()" << endl;
106  /*
107  There'll be 'physical' copies of all Amplitudes, but the
108  FitParameters remain the same (pointers to the same
109  FitParameter Object). This is useful for the CP-con coding
110  as it is now, but perhaps a bit counter-intuitive. needs to
111  be reviewed at some point. This behaviour is defined in the
112  copy constructor of the FitAmplitude class.
113  */
114 
115  /*
116  counted_ptr<FitAmpIncoherentSum>
117  newList(new FitAmpIncoherentSum((IDalitzEventList*) this->getEventRecord()
118  , _paraFName.c_str(), _minuitParaSet));
119  */
121  newList->deleteAll();
122 
123  newList->add(*this);
124  if(dbThis) cout << "cloning FitAmpIncoherentSum " << newList->size() << endl;
125  return newList;
126 }
127 
129  if(&other == this) return *this;
130  (FitAmpList)(*this) = (FitAmpList) (other);
131  return *this;
132 }
134  if(&other == this) return *this;
135  (FitAmpIncoherentSum)(*this) = other;
136  return *this;
137 }
138 
140  bool dbthis=false;
141 
142  double sum(0);
143 
144  if(0 == this->size()){
147  }
148 
149  for(unsigned int i=0; i< this->size(); i++){
150  if(dbthis){
151  cout << "FitAmpIncoherentSum::getVal()"
152  << "\n > for " << getAmpPtr(i)->theBareDecay().oneLiner()
153  << "\n > I get " << getAmpPtr(i)->getVal(evt)
154  << endl;
155  }
156  sum += norm(this->getAmpPtr(i)->getVal(evt));
157  }
158 
159  if(dbthis) cout << "FitAmpIncoherentSum::getVal(evt):"
160  << " returning this: " << sum
161  << endl;
162 
163  if(false && sum > 200){
164  cout << "large FitAmpIncoherentSum " << sum
165  << " the largest amplitude is: "
166  << endl;
167  printLargestAmp();
168  }
169 
170  return efficiency(evt)*sum;
171 
172 }
173 
174 void FitAmpIncoherentSum::Gradient(IDalitzEvent& evt,vector<double>& grad,MinuitParameterSet* mps){
175 
176  for (unsigned int i=0; i<mps->size(); i++) {
177  if(mps->getParPtr(i)->hidden())continue;
178 
179  string name_i= mps->getParPtr(i)->name();
180  if(name_i.find("Inco")==std::string::npos)continue;
181  if(name_i.find("_Re")!=std::string::npos){
182  if(mps->getParPtr(i)->iFixInit() && mps->getParPtr(i+1)->iFixInit()){
183  i++;
184  continue;
185  }
186  //name_i.replace(name_i.find("Inco_"),5,"");
187  name_i.replace(name_i.find("_Re"),3,"");
188  for(unsigned int j=0; j< this->size(); j++){
189  if(A_is_in_B(name_i, this->getAmpPtr(j)->name())){
190  if(i+1 >= grad.size()){
191  cout << "WARNING in FitAmpIncoherentSum::Gradient"
192  << " have to increase size of grad to avoid memory issues" << endl;
193  grad.resize(i+2);
194  }
195  double tmp = 2.*std::norm(this->getAmpPtr(j)->getValWithoutFitParameters(evt));
196  grad[i]= tmp * this->getAmpPtr(j)->AmpPhase().real();
197  grad[i+1]= tmp * this->getAmpPtr(j)->AmpPhase().imag();
198  i++;
199  break;
200  }
201  }
202  }
203  else if(mps->getParPtr(i)->iFixInit())continue;
204  else {
205  std::cout << "FitAmpIncoherentSum::Gradient() called. Sorry, I don't know how to calculate the derivative with respect to the fit parameter " << mps->getParPtr(i)->name() << " ! Please implement me or set useAnalytic Gradient to 0 in your options file. I'll crash now. " << std::endl;
206  throw "crash";
207  }
208 
209  }
210 
211 }
212 
216 }
220  for(unsigned int i=0; i < _fitAmps.size(); i++){
221  if(_fitAmps[i]->canBeIgnored()) continue;
222  l->addAmps( (_fitAmps[i]), (_fitAmps[i]));
223  }
224 
225  for(unsigned int i=0; i < _fitAmpLists.size(); i++){
227  }
228 
229  cout << "FitAmpIncoherentSum: setting efficiency POINTER "
230  << " in integCalculator to "
231  << _efficiency.get();
232  if(0 == _efficiency.get()){
233  cout << " (0 means no pointer, 100% efficiency).";
234  }
235  cout << endl;
236 
238  return l;
239 }
240 
244  for(unsigned int i=0; i < _fitAmps.size(); i++){
245  if(_fitAmps[i]->canBeIgnored()) continue;
246  l->addAmps( (_fitAmps[i]), (_fitAmps[i]));
247  }
248 
249  for(unsigned int i=0; i < _fitAmpLists.size(); i++){
251  }
252 
253  cout << "FitAmpIncoherentSum: setting efficiency POINTER "
254  << " in integCalculator to "
255  << _efficiency.get();
256  if(0 == _efficiency.get()){
257  cout << " (0 means no pointer, 100% efficiency).";
258  }
259  cout << endl;
260 
262  return l;
263 }
264 
265 void FitAmpIncoherentSum::print(std::ostream& os) const{
266  os << "FitAmpIncoherentSum::print\n====================";
267 
268  for(unsigned int i=0; i< this->size(); i++){
269  os << "\n\t" << this->getAmpPtr(i)->theBareDecay().oneLiner()
270  << endl;
271  }
272 }
273 void FitAmpIncoherentSum::printNonZero(std::ostream& os) const{
274  os << "FitAmpSum::print\n====================";
275 
276  for(unsigned int i=0; i < this->size(); i++){
277  if(this->getAmpPtr(i)->isZero()) continue;
278  os << "\n\t" << this->getAmpPtr(i)->theBareDecay().oneLiner()
279  << endl;
280  }
281 }
282 
283 
285  deleteAll();
286 }
287 
290  add(other);
291  return *this;
292 }
295  FitAmpIncoherentSum fas(*this);
296  fas.add(rhs);
297  return fas;
298 }
299 
300 
302  multiply(r);
303  return *this;
304 }
305 FitAmpIncoherentSum& FitAmpIncoherentSum::operator*=(const complex<double>& z){
306  multiply(z);
307  return *this;
308 }
310  multiply(irc);
311  return *this;
312 }
313 
315  FitAmpIncoherentSum fas(*this);
316  fas.multiply(r);
317  return fas;
318 }
319 FitAmpIncoherentSum FitAmpIncoherentSum::operator*(const complex<double>& z) const{
320  FitAmpIncoherentSum fas(*this);
321  fas.multiply(z);
322  return fas;
323 }
325  FitAmpIncoherentSum fas(*this);
326  fas.multiply(irc);
327  return fas;
328 }
329 
330 
332  FitAmpIncoherentSum fas(rhs);
333  fas.multiply(r);
334  return fas;
335 }
336 FitAmpIncoherentSum operator*(const complex<double>& z, const FitAmpIncoherentSum& rhs){
337  FitAmpIncoherentSum fas(rhs);
338  fas.multiply(z);
339  return fas;
340 }
342  , const FitAmpIncoherentSum& rhs){
343  FitAmpIncoherentSum fas(rhs);
344  fas.multiply(irc);
345  return fas;
346 }
347 
348 
349 
350 //
std::complex< double > AmpPhase() const
Definition: FitAmplitude.h:153
virtual bool append(const IntegCalculator &other)
virtual MINT::counted_ptr< FitAmpListBase > GetCloneSameFitParameters() const
FitAmpIncoherentSum operator *(double r) const
bool isZero() const
Definition: FitAmplitude.h:98
virtual bool append(const FitAmpPairList &otherListPtr)
virtual int add(const FitAmpListBase &other, double factor=1)
void printLargestAmp(std::ostream &os=std::cout)
virtual MINT::counted_ptr< IIntegrationCalculator > makeIntegrationCalculator()
virtual FitAmplitude * getAmpPtr(unsigned int i)
FitAmpIncoherentSum & operator+=(const FitAmpIncoherentSum &other)
virtual int iFixInit() const =0
virtual std::complex< double > getVal(IDalitzEvent &evt)
virtual void addAmps(FitAmplitude *a1, FitAmplitude *a2)
IMinuitParameter * getParPtr(unsigned int i)
static std::string IncPrefix()
unsigned int size() const
DecayTree theBareDecay() const
Definition: FitAmplitude.h:166
virtual const std::string & name() const =0
virtual void deleteAll()
virtual void printNonZero(std::ostream &os=std::cout) const
MINT::counted_ptr< MINT::IReturnRealForEvent< IDalitzEvent > > _efficiency
FitAmpIncoherentSum & operator *=(double r)
bool A_is_in_B(const std::string &a, const std::string &b)
Definition: Utils.cpp:34
virtual void Gradient(IDalitzEvent &evt, std::vector< double > &grad, MINT::MinuitParameterSet *mps)
std::vector< FitAmplitude * > _fitAmps
FitAmpIncoherentSum operator *(double r, const FitAmpIncoherentSum &rhs)
double getVal(IDalitzEvent &evt)
void setEfficiency(MINT::counted_ptr< MINT::IReturnRealForEvent< IDalitzEvent > > eff)
double efficiency(IDalitzEvent &evt)
virtual void addAmps(FitAmplitude *a1, FitAmplitude *a2)
FitAmpIncoherentSum & operator=(const FitAmpIncoherentSum &other)
virtual bool hidden() const =0
virtual MINT::counted_ptr< IntegCalculator > makeIntegCalculator()
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
std::vector< MINT::counted_ptr< FitAmpListBase > > _fitAmpLists
FitAmpIncoherentSum operator+(const FitAmpIncoherentSum &other) const
virtual MINT::counted_ptr< FitAmpPairList > makeFitAmpPairList()
virtual void print(std::ostream &os=std::cout) const
void oneLiner(std::stringstream &seam, int generation=0) const
Definition: DDTree.h:375
FitAmpIncoherentSum(const DalitzEventPattern &pat, const char *fname=0, MINT::MinuitParameterSet *pset=0, const std::string &prefix="", const std::string &lineshapePrefix="", const std::string &opt="")
virtual unsigned int size() const
void setEfficiency(MINT::counted_ptr< MINT::IReturnRealForEvent< IDalitzEvent > > eff)
virtual bool createAllAmps(const DalitzEventPattern &thePattern, const std::string &prefix="", const std::string &lineshapePrefix="")
Definition: FitAmpList.cpp:125
X * get() const
Definition: counted_ptr.h:123
virtual void multiply(double r)