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