MINT2
CoherenceFactorStoreAndEvaluate.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:59 GMT
3 //
4 // Using Equations 5 (and around that) in
5 // Phys. Rev. D 68, 033003 (2003),
6 // http://prola.aps.org/abstract/PRD/v68/i3/e033003
7 //
9 #include "Mint/FitAmpSum.h"
13 
14 using namespace std;
15 using namespace MINT;
16 
19  , FitAmpSum& Abar
20  , double CSAbs
21  , double CSPhase
23  , double prec
24  )
25  : _A(&A)
26  , _Abar(&Abar)
27  , _CSAbs(CSAbs)
28  , _CSPhase(CSPhase)
29  , _A_plus_Abar(A+Abar)
30  , _eff(eff)
31  , _precision(prec)
32  , _sumASq(0), _sumASqSquared(0)
33  , _sumAbarSq(0), _sumAbarSqSquared(0)
34  , _sumAxAbarStar(0,0), _sumAxAbarStarSquared(0,0)
35  , _histoA(), _histoAbar(), _histoBoth()
36  , _tries(0)
37  , _Nevents(0)
38 {
39 }
40 
42  if(0 == _eff) return 1.0;
43  return _eff->RealVal(evt);
44 }
46  if(_Nevents <= 0) return 9999;
47  double s = sigmaAbs();
48  if(s < 0) s *= -1;
49  return s;
50 }
51 
53  if(_Nevents <=0) return 0;
54  return _sumAxAbarStar / ((double) _Nevents);
55 }
57  if(_Nevents <=0) return 0;
58  if(_sumASq <=0) return -9999;
59  return sqrt(_sumASq / ((double) _Nevents));
60 }
62  if(_Nevents <=0) return 0;
63  if(_sumAbarSq <=0) return -9999;
64  return sqrt(_sumAbarSq / ((double) _Nevents));
65 }
67  if(_Nevents <=0) return 0;
68  return _sumASq / ((double) _Nevents);
69 }
71  if(_Nevents <=0) return 0;
72  return _sumAbarSq / ((double) _Nevents);
73 }
74 
77 }
78 double CoherenceFactorStoreAndEvaluate::realAorAbarVar(double s, double sq)const{
79  if(_Nevents <=0 ) return 0;
80  if(s == 0) return -9999;
81  double m = s/((double) _Nevents);
82  double msq = sq/((double) _Nevents);
83  double varAsq = (msq - m*m)/((double) _Nevents);
84 
85  return 0.5 * varAsq / fabs(s);
86 }
89 }
92 }
93 
94 
96  if(_Nevents <=0) return -1;
97  double mean = _sumASq/_Nevents;
98  double meanOfSq = _sumASqSquared/_Nevents;
99  double v = meanOfSq - mean*mean;
100  return v/_Nevents;
101 }
103  if(_Nevents <=0) return -1;
104  double mean = _sumAbarSq/_Nevents;
105  double meanOfSq = _sumAbarSqSquared/_Nevents;
106  double v = meanOfSq - mean*mean;
107  return v/_Nevents;
108 }
109 
110 complex<double> CoherenceFactorStoreAndEvaluate::complexVar(complex<double> s
111  , complex<double> s_sq
112  )const{
113  if(_Nevents <=0) return 0;
114  complex<double> m = s / ((double) _Nevents);
115  complex<double> mos = s_sq / ((double) _Nevents);
116  complex<double> som(m.real()*m.real(), m.imag()*m.imag());
117  return (mos - som)/((double)_Nevents);
118 }
119 
121  bool dbThis=false;
122 
123  complex<double> m = Rval();
124  complex<double> som(m.real()*m.real(), m.imag()*m.imag());
125 
126  double den = integA()*integA() * integAbar()*integAbar();
127  if(den <= 0) return complex<double>(-9999,-9999);
128 
129  double ar = cvarAxAbarStar().real() / den;
130  double ai = cvarAxAbarStar().imag() / den;
131  complex<double> a(ar, ai);
132  complex<double> b = varA()/(integA()*integA()) * som;
133  complex<double> c = varAbar()/(integAbar()*integAbar()) * som;
134 
135  if(dbThis){
136  cout << " cvarAxAbarStar() << " << cvarAxAbarStar() << endl;
137  cout << "var() = " << a << " + " << b << " + " << c
138  << " = " << a + b + c << endl;
139  }
140  return a + b + c;
141 }
142 
144  return complex<double>(sqrt(fabs(var().real())), sqrt(fabs(var().imag())));
145 }
147  double a = var().real() * 2*fabs(Rval().real()/norm(Rval()));
148  double b = var().imag() * 2*fabs(Rval().imag()/norm(Rval()));
149  return a+b;
150 }
152  double va = varAbs();
153  if(va < 0) return -9999;
154  return sqrt(va);
155 }
157  double a= fabs(Rval().real());
158  double b= fabs(Rval().imag());
159  double den = a*a + b*b;
160  if(den <= 0)return -9999;
161 
162  return var().real()*b/den + var().imag()*a/den;
163 }
165  return varAngle() * 180*180/(pi*pi);
166 }
168  double va = varAngle();
169  if(va < 0) return -9999;
170  return sqrt(va);
171 }
173  double va = varAngleDeg();
174  if(va < 0) return -9999;
175  return sqrt(va);
176 }
178  if(_Nevents <= 0 || integA() <= 0 || integAbar() <= 0) return -9999;
179  return integAxAbarStar() / (integA() * integAbar());
180 }
181 
182 void CoherenceFactorStoreAndEvaluate::printLong(std::ostream& os) const{
183  os << "Integrals from CoherenceFactorStoreAndEvaluate\n"
184  << "\t int |A|^2: " << integASq()
185  << ", int |Abar|^2 " << integAbarSq();
186  double rBSq = _CSAbs*_CSAbs;
187  if(rBSq > 0){
188  os << "\n\t int |Abar|^2/rB^2 " << integAbarSq()/rBSq;
189  }
190  if(integAbarSq() > 0){
191  os << "\n ratio int |A|^2 / int |Abar|^2 = " << integASq()/integAbarSq()
192  << ", ratio * rB^2 = " << rBSq*integASq()/integAbarSq();
193  }
194  os << "\n\n Coherence factor result (same result, different formats):"
195  << "\n\tR exp(i xi) = " << Rval() << " +/- " << sigma()
196  << "\n\tR exp(i xi) = " << abs(Rval())
197  << " * exp( i * " << arg(Rval()) << " )"
198  << "\n\t sig(R) = " << sigmaAbs()
199  << " sig(xi) = " << sigmaAngle()
200  << "\n\tR exp(i xi) = " << abs(Rval())
201  << " * exp( i * " << arg(Rval())*180.0/pi << " deg )"
202  << "\n\t sig(R) = " << sigmaAbs()
203  << " sig(xi) = " << sigmaAngle()*180.0/pi << " deg";
204  if(arg(Rval()) < 0){
205  cout << "\n\tR exp(i xi) = " << abs(Rval())
206  << " * exp( i * " << arg(Rval())*180.0/pi + 360. << " deg )"
207  << "\n\t sig(R) = " << sigmaAbs()
208  << " sig(xi) = " << sigmaAngle()*180.0/pi << " deg";
209  }
210  cout << endl;
211 }
213  , const std::string& pref)const{
214  os << pref << "\t int |A| = " << this->integA()
215  << "\t int |Abar| = " << this->integAbar()
216  << "\n" << pref << "\t int (A Abar*) = " << this->integAxAbarStar()
217  << '\n' << pref << "\tR exp(i xi) = " << abs(Rval())
218  << " * exp( i * " << arg(Rval())*180.0/pi << " deg )"
219  << "\n" << pref << "\t sig(R) = " << sigmaAbs()
220  << " sig(xi) = " << sigmaAngle()*180.0/pi << " deg";
221 }
223  return abs(Rval());
224 }
226  return arg(Rval());
227 }
229  return arg(Rval())*180.0/pi;
230 }
232  return A()->ComplexVal(evt);
233 }
235  evt){
236  bool dbThis=false;
237  if(dbThis) cout << "CoherenceFactorStoreAndEvaluate::Abar_Value" << endl;
238  complex<double> val = Abar()->ComplexVal(evt);
239  if(dbThis) cout << "got value: " << val << endl;
240  return val;
241 }
242 
244  evtPtr){
245  bool dbThis=false;
246  if(dbThis) cout << "Hello from CoherenceFactorStoreAndEvaluate::getCVal()"
247  << endl;
248 
249  // int printEvery = 10000;
250 
251  _tries++;
252  bool printout = false;//_tries < 10 || (0 == _tries%printEvery);
253 
254  if(0 == evtPtr){
255  if(dbThis) cout << "WARNING in CoherenceFactorStoreAndEvaluate::getR()"
256  << " got evtPtr = " << evtPtr << endl;
257  return false;
258  }
259 
260  if(10 == _tries){
261  cout << "=======================\n";
262  cout << "all A amplitudes\n";
263  _A->printAllAmps();
264  cout << "all Abar ampltiudes\n";
265  _Abar->printAllAmps();
266  cout <<endl;
267  }
268  double w = evtPtr->getWeight()
270 
271  w*= getEff(evtPtr);
272 
273  w = sqrt(w); // sqrt because we apply the weight to the amplitudes,
274  // while the integrals (as one might expect) all
275  // contain terms |A|^2, |Abar|^2, or |A*Abar|.
276 
277  complex<double> c_a=
278  A_Value(evtPtr.get()) * w;
279 
280  complex<double> c_abar=
281  Abar_Value(evtPtr.get()) *w*polar(_CSAbs, _CSPhase);
282 
283  double d_a = norm(c_a);
284  double d_abar = norm(c_abar);
285 
286  _histoA.addEvent(*evtPtr, d_a);
287  _histoAbar.addEvent(*evtPtr, d_abar);
288  _histoBoth.addEvent(*evtPtr, norm(c_a + c_abar));
289 
290  _sumASq += d_a;
291  _sumASqSquared += d_a*d_a;
292 
293  _sumAbarSq += d_abar;
294  _sumAbarSqSquared += d_abar*d_abar;
295 
296  complex<double> c_prod = c_a * conj(c_abar);
297  _sumAxAbarStar += c_prod;
298  complex<double> c_prodSquared(c_prod.real() * c_prod.real()
299  , c_prod.imag() * c_prod.imag()
300  );
301  _sumAxAbarStarSquared += c_prodSquared;
302 
303  _Nevents++;
304 
305  if(printout){
306  cout << " DalitzEvent::EventCounter() "
308  << endl;
309  cout << "INFO from CoherenceFactorStoreAndEvaluate::getR()"
310  << "\n\t _tries: " << _tries << ", for " << _Nevents << " events."
311  << endl;
312  // << "\n\t c_a, c_abar: " << c_a << ", " << c_abar
313  // << "\n\t value: " << Rval()
314  // << " = " << abs(Rval()) << " * exp( i * " << arg(Rval()) << " )"
315  // << " +/- " << estimatedPrecision()
316  // << endl;
317  print();
318  cout << " --------------------------------- " << endl;
319  }
320  return true;
321 }
322 
324  return _histoA;}
326  return _histoAbar;}
328  return _histoBoth;}
329 
330 
332 saveHistos(const std::string& fname) const{
333  bool s = true;
334  s &= _histoA.save(fname + "_A.root");
335  s &= _histoAbar.save(fname + "_Abar.root");
336  s &= _histoBoth.save(fname + "_Both.root");
337  return s;
338 }
339 
341 drawHistos(const std::string& fname) const{
342  bool s=true;
343  s &= _histoA.draw(fname + "_A");
344  s &= _histoAbar.draw(fname + "_Abar");
345  s &= _histoBoth.draw(fname + "_Both");
346  return s;
347 }
350  , const std::string& fname
351  , double sf
352  ) const{
353  bool s=true;
354  s &= _histoA.drawWithFit(other._histoA * sf, fname + "_A");
355  s &= _histoAbar.drawWithFit(other._histoAbar * sf, fname + "_Abar");
356  s &= _histoBoth.drawWithFit(other._histoBoth * sf, fname + "_Both");
357  return s;
358 }
361  , const std::string& fname
362  , double sf
363  ) const{
364  bool s=true;
365  s &= (_histoA / (other._histoA * sf)).draw(fname + "_ARatio");
366  s &= (_histoAbar / (other._histoAbar * sf)).draw(fname + "_AbarRatio");
367  s &= (_histoBoth / (other._histoBoth * sf)).draw(fname + "_BothRatio");
368  return s;
369 }
371 scaleHistos(double sf){
372  _histoA.scale(sf);
373  _histoAbar.scale(sf);
374  _histoBoth.scale(sf);
375 }
std::complex< double > Abar_Value(IDalitzEvent &evt)
std::complex< double > complexVar(std::complex< double > s, std::complex< double > s_sq) const
virtual double getWeight() const =0
void scale(double sf)
bool drawHistoRatios(const CoherenceFactorStoreAndEvaluate &other, const std::string &fname="CoherenceFactorHistosWith", double sf=1) const
void printLong(std::ostream &os=std::cout) const
MINT::IReturnComplexForEvent< IDalitzEvent > * A()
static const double pi
virtual void printAllAmps(std::ostream &os=std::cout) const
Definition: FitAmpList.h:93
static const double s
virtual double RealVal(EVENT_TYPE &evt)=0
static long int eventCounter()
Definition: DalitzEvent.h:125
bool drawWithFit(const DalitzHistoSet &fit, const std::string &baseName="", const std::string &format="eps", const std::string &fitDrawOpt="HIST C SAME") const
std::complex< double > cvarAxAbarStar() const
bool draw(const std::string &baseName="", const std::string &drawOpt="", const std::string &format="eps") const
std::complex< double > integAxAbarStar() const
void print(std::ostream &os=std::cout, const std::string &pref="") const
static const double m
std::complex< double > A_Value(IDalitzEvent &evt)
virtual double getGeneratorPdfRelativeToPhaseSpace() const =0
void addEvent(const IDalitzEvent &evt, double weight=1)
double realAorAbarVar(double s, double sq) const
CoherenceFactorStoreAndEvaluate(FitAmpSum &A, FitAmpSum &Abar, double CSAbs=1, double CSPhase=0.0, MINT::IReturnRealForEvent< IDalitzEvent > *eff=0, double prec=1.e-3)
bool addEvent(MINT::counted_ptr< IDalitzEvent > &evtPtr)
MINT::IReturnRealForEvent< IDalitzEvent > * _eff
virtual std::complex< double > ComplexVal(EVENT_TYPE &evt)=0
MINT::IReturnComplexForEvent< IDalitzEvent > * Abar()
bool drawHistosWith(const CoherenceFactorStoreAndEvaluate &other, const std::string &fname="CoherenceFactorHistosWith", double sf=1) const
bool save(const std::string &filename="DalitzHistos.root") const
bool saveHistos(const std::string &fname="CoherenceFactorHistos") const
X * get() const
Definition: counted_ptr.h:123
bool drawHistos(const std::string &fname="CoherenceFactorHistos") const