MINT2
DalitzPdfNormChecker.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:02 GMT
4 
5 #include "Mint/IDalitzPdf.h"
6 #include "TRandom.h"
7 
8 using namespace std;
9 using namespace MINT;
10 
12  , const DalitzEventPattern& pat
13  , double prec
14  , TRandom* rnd)
15  : _pdf(pdf)
16  , _rnd(rnd)
17  , _pat(pat)
18  , _t01(2,3,4)
19  , _s12(1,2)
20  , _s23(2,3)
21  , _s34(3,4)
22  , _t40(1,2,3)
23  , _askingPrecision(prec)
24  , _sum(0.0)
25  , _sumsq(0.0)
26  , _NInside(0)
27  , _sumPhaseSpace(0.0)
28  , _sumPhaseSpaceSq(0.0)
29  , _Nevents(0)
30 {
31  makeMiMa();
32 }
33 
35  double safetyFactor=1.001;
36 
37  _s12.setMinMax( _pat.sijMin(1,2)/safetyFactor
38  , _pat.sijMax(1,2)*safetyFactor);
39  _s23.setMinMax( _pat.sijMin(2,3)/safetyFactor
40  , _pat.sijMax(2,3)*safetyFactor);
41  if(_pat.numDaughters() >= 4){
42  _t01.setMinMax( _pat.sijMin(2,3,4)/safetyFactor
43  , _pat.sijMax(2,3,4)*safetyFactor);
44  _s34.setMinMax( _pat.sijMin(3,4)/safetyFactor
45  , _pat.sijMax(3,4)*safetyFactor);
46  _t40.setMinMax( _pat.sijMin(1,2,3)/safetyFactor
47  , _pat.sijMax(1,2,3)*safetyFactor);
48  }
49 
50 }
51 
53  , double scale1
54  , double scale2
55  , double scale3
56  , double scale4
57  ) const{
58  bool dbThis=false;
59 
60  double t01 = _t01.min() + scale0*(_t01.max() - _t01.min());
61  double s12 = _s12.min() + scale1*(_s12.max() - _s12.min());
62  double s23 = _s23.min() + scale2*(_s23.max() - _s23.min());
63  double s34 = _s34.min() + scale3*(_s34.max() - _s34.min());
64  double t40 = _t40.min() + scale4*(_t40.max() - _t40.min());
65 
66  Calculate4BodyProps c4b(t01, s12
67  , s23, s34
68  , t40
69  , _pat[0].mass()
70  , _pat[1].mass(), _pat[2].mass()
71  , _pat[3].mass(), _pat[4].mass()
72  );
73  if(c4b.phaseSpaceFactor() <=0){
74  if(dbThis){
75  cout << " for \n "
76  << t01 << "( " << _t01 << "), \n "
77  << s12 << "( " << _s12 << "), \n "
78  << s23 << "( " << _s23 << "), \n "
79  << s34 << "( " << _s34 << "), \n "
80  << t40 << "( " << _t40 << "), \n "
81  << " outside phase space!! "
82  << endl;
83  }
84  return counted_ptr<DalitzEvent>(0);
85  }
86  counted_ptr<DalitzEvent> evt(new DalitzEvent(_pat, t01, s12, s23, s34, t40));
87  if(0 == evt){
88  cout << "WARNING DalitzPdfNormChecker::make4Event()"
89  << " making the event failed at 'new DalitzEvent(...)'"
90  << " this shouldn't really happen."
91  << endl;
92  return evt;
93  }
94  if(evt->phaseSpace() <= 0){
95  return counted_ptr<DalitzEvent>(0);
96  }
97 
98  return evt;
99 }
100 
102  if(_pat.numDaughters() == 3) return make3Event();
103  if(_pat.numDaughters() == 4) return make4Event();
104  cout << "ERROR in DalitzPdfNormChecker::makeEvent() can only make events"
105  << " with 3 or 4 daughters. You want : " << _pat
106  << endl;
107  return counted_ptr<DalitzEvent>(0);
108 }
109 
111 
112  cout << " ERROR DalitzPdfNormChecker::make3Event(): I don't work, yet. "
113  << "\n Please improve me. Sorry, will have to crash, now"
114  << endl;
115  throw "no making 3 body events in DalitzPdfNormChecker, yet";
116 
117  /*
118  double s12 = _s12.min() + _rnd->Rndm()*(_s12.max() - _s12.min());
119  double s23 = _s23.min() + _rnd->Rndm()*(_s23.max() - _s23.min());
120 
121  _evt = new DalitzEvent(_pat, s12, s23);
122  if(_evt->phaseSpace() <= 0){
123  deleteEvent();
124  return 0;
125  }
126 
127  return _evt;
128  */
129  return counted_ptr<DalitzEvent>(0);
130 }
132  //counted_ptr<DalitzEvent> evtttt(new DalitzEvent(_pat, _rnd));
133  //evtttt->setGeneratorPdfRelativeToPhaseSpace(evtttt->phaseSpace());
134  //return evtttt;
135 
136  return makeEventForOwner( _rnd->Rndm()
137  , _rnd->Rndm()
138  , _rnd->Rndm()
139  , _rnd->Rndm()
140  , _rnd->Rndm()
141  );
142 }
143 
144 
146  if(_Nevents <= 0) return 9999;
147  double dN = (double) _Nevents;
148  double mean = _sum/dN;
149  double meansq = _sumsq/dN;
150  double var = meansq - mean*mean;
151  if(var < 0){
152  cout << "ERROR ind DalitzPdfNormChecker::currentPrecision()"
153  << ". Variance = " << var
154  << ". We have a problem."
155  << endl;
156  return 9999;
157  }
158  return sqrt(var/dN)*boxSize(); // sigma on mean.
159 }
161  if(_Nevents <= 0) return 9999;
162  if(result() == 0.0) return 9999;
163  return currentAbsolutePrecision()/result();
164 }
165 
167  return currentAbsolutePrecision();
168 }
169 
172 }
174 
175  long unsigned int stupidNumber = 2000000000;
176 
177  int printEvery=50000;
178  for(long unsigned int i=0;
179  ( i < stupidNumber && (! sufficientPrecision()));
180  i++
181  ){
183  if(0 == i%printEvery){
184  print();
185  cout << endl;
186  cout << " current ptr " << evtPtr.get() << endl;
187  if(0 != evtPtr){
188  cout << " phase space = " << evtPtr->phaseSpace() << endl;
189  }
190  }
191  _Nevents++;
192  if(0 == evtPtr) continue;
193  if(evtPtr->phaseSpace() <= 0) continue;
194  double val = _pdf->getVal_withPs(*evtPtr);
195  if(_Nevents < 20 || 0 == i%printEvery){
196  cout << " for _Nevents = " << _Nevents << ", current val = " << val << endl;
197  cout << "event: " << *evtPtr << endl;
198  cout << " ------------------ " << endl;
199  }
200 
201  _sum += val;
202  _sumsq += val*val;
203 
204  double ps = evtPtr->phaseSpace();
205  _NInside++;
206  _sumPhaseSpace += ps;
207  _sumPhaseSpaceSq += ps*ps;
208  }
209  if(_Nevents <=0) return -9999;
210 
211  cout << "DalitzPdfNormChecker::checkNorm(): "
212  << "\n\t result: ";
213  print();
214  cout << endl;
215 
216  return result();
217 }
218 
219 void DalitzPdfNormChecker::print(std::ostream& os)const{
220  os << " DalitzPdfNormChecker after " << _Nevents << " events: ";
221  if(_Nevents <= 0) return;
222  os << "\n\t result: " << result() << " +/- " << resultError();
223  double dN = (double) _Nevents;
224  // double shouldBe = dInside/(dN);
225  double shouldBe = _sumPhaseSpace/dN * boxSize();
226  //shouldBe *= _sumPhaseSpace/dN;
227  //shouldBe = boxSize();
228  os << "\n this should be " << shouldBe;
229 }
230 
232  // return 1;
233  double dt01 = (_t01.max() - _t01.min());
234  double ds12 = (_s12.max() - _s12.min());
235  double ds23 = (_s23.max() - _s23.min());
236  double ds34 = (_s34.max() - _s34.min());
237  double dt40 = (_t40.max() - _t40.min());
238 
239  if(_pat.numDaughters() == 3){
240  return ds12*ds23;
241  }else if(_pat.numDaughters() == 4){
242  return dt01*ds12*ds23*ds34*dt40;
243  }else{
244  cout << "ERROR in DalitzPdfNormChecker::boxSize()"
245  << " don't know how to handle "
246  << _pat.numDaughters()
247  << " final state particles. Will return -9999"
248  << endl;
249  return -9999.;
250  }
251 }
252 
254  if(_Nevents <=0 )return -9999;
255  return _sum/((double)_Nevents) * boxSize();
256 }
257 
258 
259 std::ostream& operator<<(std::ostream& os, const DalitzPdfNormChecker& nc){
260  nc.print(os);
261  return os;
262 }
MINT::counted_ptr< DalitzEvent > make3Event() const
double min() const
double sijMax(const MINT::PolymorphVector< int > &indices) const
long unsigned int _Nevents
virtual double phaseSpace() const
double max() const
void print(std::ostream &os=std::cout) const
DalitzPdfNormChecker(IDalitzPdf *pdf, const DalitzEventPattern &pat, double prec=1.0e-2, TRandom *rnd=gRandom)
double currentAbsolutePrecision() const
MINT::counted_ptr< DalitzEvent > make4Event() const
double sijMin(const MINT::PolymorphVector< int > &indices) const
DalitzEventPattern _pat
std::ostream & operator<<(std::ostream &os, const DalitzPdfNormChecker &nc)
MINT::counted_ptr< DalitzEvent > makeEventForOwner() const
virtual double getVal_withPs(IDalitzEvent &evt)=0
double currentRelativePrecision() const
void setMinMax(double min, double max)
X * get() const
Definition: counted_ptr.h:123