MINT2
DalitzPdfBaseFlexiFastInteg.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:01 GMT
4 #include "Mint/FitAmpSum.h"
5 #include "Mint/DalitzBWBoxSet.h"
6 #include "Mint/Minimiser.h"
7 
8 #include <iostream>
9 
10 using namespace std;
11 using namespace MINT;
12 
14  return (0 == _mps ? MinuitParameterSet::getDefaultSet() : _mps);
15 }
17  return (0 == _mps ? MinuitParameterSet::getDefaultSet() : _mps);
18 }
19 
20 
22  _integrating = true;
23  if( ! _faint.initialised()){
24  if(_pat.empty()){
25  cout << "DalitzPdfBaseFlexiFastInteg::getNorm: don't know event pattern!"
26  << endl;
27  _integrating = false;
28  return false;
29  }
30  if(0 == getAmps()){
31  cout << "DalitzPdfBaseFlexiFastInteg::getNorm: don't have amps!"
32  << endl;
33  _integrating = false;
34  return false;
35  }
36 
37  /*
38  if("" != _commaSepList_of_SavedIntegrators){
39  _faint.initialiseFromFile(evtPtr->eventPattern()
40  , _amps
41  , _commaSepList_of_SavedIntegrators);
42  }else{
43  */
44  _faint.initialise( _pat
45  , getAmps()
46  //, _efficiency
47  , getEventGenerator()
48  , gRandom
49  , _precision
50  );
51  //}
52 
53 #ifdef CHECK_INTEGRATOR
54  cout << "WARNING in DalitzPdfBaseFlexiFastInteg::getNorm!!!"
55  << " using old, inefficient integrator."
56  << " Won't work for efficiencies!!"
57  << endl;
58  _mcint.initialise(evtPtr->eventPattern()
59  , getAmps()//this
60  , getEventGenerator()
61  , gRandom
62  , _precision
63  );
64 #endif
65  }
66 
67  _norm = _faint.getVal();
68 
69 
70 #ifdef CHECK_INTEGRATOR
71  double fastVal = _norm;
72  double oldVal = _mcint.getVal();
73  cout << "DalitzPdfBaseFlexiFastInteg::getNorm:"
74  << " compare mcint integral with fast: "
75  << "\n\t old: " << oldVal << " , fast: " << fastVal
76  << ", ratio " << oldVal/fastVal
77  << endl;
78  _norm = oldVal;
79 #endif
80 
81 
82  _integrating = false;
83  return _norm > 0;
84 }
86  if(_pat.empty()) return 0;
87  if(0 == getAmps()) return 0;
89  ptr(getAmps()->makeEventGenerator(_pat));
90  _defaultGenerator = ptr;
91  return _defaultGenerator.get();
92 }
93 
95  if(0 == _generator) makeDefaultGenerator();
96  return _generator;
97 }
99  if(0 == _generator){
100  cout << "WARNING in DalitzPdfBaseFlexiFastInteg::getEventGenerator() const"
101  << " returning 0 pointer." << endl;
102  }
103  return _generator;
104 }
105 
107  _precision = prec;
108 #ifdef CHECK_INTEGRATOR
109  _mcint.setPrecision(_precision);
110 #endif
111  _faint.setPrecision(_precision);
112 }
113 
115  getNorm();
116 }
119  generator
121  , double prec
122  , MinuitParameterSet* mps
123  )
124  : PdfBase<IDalitzEvent>()
125  , _mps(mps)
126  , _pat(pat)
127  , _norm(-1)
128  , _precision(prec)
129  , _amps(amps)
130  , _countedAmps(0)
131  //, _efficiency(0)
132  , _generator(generator)
133  , _integrating(0)
134  , _defaultGenerator(0)
135  , _commaSepList_of_SavedIntegrators("")
136 {
137  setup();
138 }
139 
142  generator
143  //, counted_ptr<IGetDalitzEvent> eff
144  , MinuitParameterSet* mps
145  , double prec
146  )
147  : PdfBase<IDalitzEvent>()
148  , _mps(mps)
149  , _pat(pat)
150  , _norm(-1)
151  , _precision(prec)
152  , _amps(0)
153  , _countedAmps(0)
154  // , _efficiency(eff)
155  , _generator(generator)
156  , _integrating(0)
157  , _defaultGenerator(0)
158  , _commaSepList_of_SavedIntegrators("")
159 {
160  setup();
161  //cout << "pset pointer in DalitzPdfBaseFlexiFastInteg " << _mps << " = " << getMPS() << endl;
162 }
163 
166  , IPdf<IDalitzEvent>()
167  , IDalitzPdf()
168  , PdfBase<IDalitzEvent>(other)
169  , _mps(other._mps)
170  , _pat(other._pat)
171  , _norm(other._norm)
172  , _precision(other._precision)
173  , _amps(other._amps)
174  , _countedAmps(other._countedAmps)
175  //, _efficiency(other._efficiency)
176  , _generator(other._generator)
177  , _integrating(other._integrating)
178  , _defaultGenerator(other._defaultGenerator)
179  , _commaSepList_of_SavedIntegrators(other._commaSepList_of_SavedIntegrators)
180 {
181  setup();
182 }
183 
185 }
186 
188  makeAmps(); // it's important to do this at construction time, otherwise the MinuitParameterSet will be empty.
189 }
191  cout << "DalitzPdfBaseFlexiFastInteg::makeAmps() with MPS pointer " << getMPS()
192  << " and _amps pointer " << _amps << endl;
193  if(0 == _amps && (! _pat.empty())){
194  cout << "DalitzPdfBaseFlexiFastInteg::getAmps() making _amps with pointer " << getMPS()
195  << endl;
196  _amps = new FitAmpSum(_pat, getMPS());
198  _countedAmps = cp;
199  }
200  return (bool) _amps;
201 }
202 
204  return _integrating;
205 }
206 
208  return evt.phaseSpace();
209 }
211  //if(_pat.empty()) _pat = evt.eventPattern();
212  if(_integrating) return getVal_withPs(evt);
213  else return getVal_noPs(evt);
214 }
216  //bool dbThis = false;
217  //static double maxVal=0;
218  if(_pat.empty()) _pat = evt.eventPattern();
219 
220  if(_integrating){
221  // shouldn't really do that - use getVal or getVal_withPs
222  // when you integrate (automatically done in getVal()):
223  return un_normalised_noPs(evt);
224  }else{
225  if(_norm == -1){
226  cout << "DalitzPdfBaseFlexiFastInteg::getVal_noPs: _norm = "
227  << _norm
228  << " should not have happened." << endl;
229  throw "can't deal with that";
230  }
231 
232  double num = un_normalised_noPs(evt);
233  /*if(dbThis){
234  double val=num/_norm;
235  if(fabs(val) > maxVal){
236  maxVal=fabs(val);
237  if(dbThis){
238  cout << "biggest un_normalised / norm, yet: "
239  << num << " / " <<_norm
240  << " = " << num/_norm
241  << ". ps = " << phaseSpace(evt)
242  << endl;
243  cout << "for event: "; evt.print(); cout << endl;
244  }
245  }
246  }*/
247 
248  /*
249  cout << "\n DalitzPdfBaseFlexiFastInteg::getVal_noPs():"
250  << " for event ptr " << getEvent()
251  << " returning "
252  << num << " / " << _norm << endl;
253  */
254  return num/_norm;
255  }
256 }
258  if(_pat.empty()) _pat = evt.eventPattern();
259 
260  if(_integrating){
261  return un_normalised_noPs(evt)*phaseSpace(evt);
262  }else{
263  if(_norm == -1) getNorm();
264  double num = un_normalised_noPs(evt)*phaseSpace(evt);
265  return num/_norm;
266  }
267 }
268 
269 bool DalitzPdfBaseFlexiFastInteg::makePlots(const std::string& filename) const{
270  return histoSet().save(filename);
271 }
273  return (_faint.histoSet());
274 }
276  // non-const version to satisfy IDalitzPdf
277  return (_faint.histoSet());
278 }
279 
280 void DalitzPdfBaseFlexiFastInteg::saveEachAmpsHistograms(const std::string& prefix) const{
282  return;
283 }
284 
286  return _faint.GetEachAmpsHistograms();
287 }
288 
290  return (_faint.interferenceHistoSet());
291 }
293  // non-const version to satisfy IDalitzPdf
294  return (_faint.interferenceHistoSet());
295 }
296 void DalitzPdfBaseFlexiFastInteg::saveInterferenceHistograms(const std::string& prefix) const{
298  return;
299 }
302 }
303 
304 
306  //getNorm();
307 }
308 
310 
311  //_faint.doFinalStats();
312 }
313 
315  _faint.doFinalStats(mini);
316 }
317 
318 void DalitzPdfBaseFlexiFastInteg::doFinalStatsAndSave(Minimiser* mini0,const std::string& fname, const std::string& fnameROOT){
319  _faint.doFinalStatsAndSave(mini0,fname,fnameROOT);
320 }
321 
322 
323 
324 
325 //
virtual double phaseSpace(IDalitzEvent &evt)
virtual double phaseSpace() const =0
std::vector< DalitzHistoSet > GetEachAmpsHistograms()
std::vector< DalitzHistoSet > GetInterferenceHistograms()
MINT::counted_ptr< IFastAmplitudeIntegrable > _countedAmps
void doFinalStats(MINT::Minimiser *mini=0)
std::vector< DalitzHistoSet > GetInterferenceHistograms()
virtual double getVal_noPs(IDalitzEvent &evt)
virtual double un_normalised_noPs(IDalitzEvent &evt)=0
void saveEachAmpsHistograms(const std::string &prefix) const
MINT::MinuitParameterSet * getMPS()
virtual double getVal(IDalitzEvent &evt)
void doFinalStatsAndSave(MINT::Minimiser *min=0, const std::string &fname="FitAmpResults.txt", const std::string &fnameROOT="fitFractions.root")
DalitzPdfBaseFlexiFastInteg(const DalitzEventPattern &pat, MINT::IEventGenerator< IDalitzEvent > *generator, IFastAmplitudeIntegrable *amps, double precision=1.e-3, MINT::MinuitParameterSet *mps=0)
FlexiFastAmplitudeIntegrator _faint
void saveInterferenceHistograms(const std::string &prefix) const
virtual const DalitzEventPattern & eventPattern() const =0
virtual DalitzHistoSet interferenceHistoSet() const
void saveEachAmpsHistograms(const std::string &prefix) const
virtual DalitzHistoSet histoSet() const
bool makePlots(const std::string &filename) const
virtual void doFinalStats(MINT::Minimiser *mini=0)
void saveInterferenceHistograms(const std::string &prefix) const
void doFinalStatsAndSave(MINT::Minimiser *min=0, const std::string &fname="FitAmpResults.txt", const std::string &fnameROOT="fitFractions.root")
MINT::IEventGenerator< IDalitzEvent > * getEventGenerator()
IFastAmplitudeIntegrable * _amps
bool save(const std::string &filename="DalitzHistos.root") const
virtual double getVal_withPs(IDalitzEvent &evt)
MINT::IEventGenerator< IDalitzEvent > * makeDefaultGenerator()
X * get() const
Definition: counted_ptr.h:123
std::vector< DalitzHistoSet > GetEachAmpsHistograms()