MINT2
CoherenceFactor.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 //
8 #include "Mint/CoherenceFactor.h"
9 #include "Mint/FitAmpSum.h"
13 
14 using namespace std;
15 using namespace MINT;
16 
18  , double CSAbs
19  , double CSPhase
21  , double prec
22  )
23  : _A(&A)
24  , _Abar(&Abar)
25  , _CSAbs(CSAbs)
26  , _CSPhase(CSPhase)
27  , _A_plus_Abar(A+Abar)
28  , _myOwnGenAplusAbar(0)
29  , _eff(eff)
30  , _precision(prec)
31  , _sumASq(0), _sumASqSquared(0)
32  , _sumAbarSq(0), _sumAbarSqSquared(0)
33  , _sumAxAbarStar(0,0), _sumAxAbarStarSquared(0,0)
34  , _Nevents(0)
35 {
36 }
37 
40  bool dbThis=false;
41  if(0 == _myOwnGenAplusAbar){
42  if(dbThis) cout << "CoherenceFactor::getGenerator(): "
43  << "making generator" << endl;
44  if(_A_plus_Abar.size() <= 0) return 0;
47  ptr( new DalitzBWBoxSet(_A_plus_Abar.makeBWBoxes(pat)));
48  if(dbThis) cout << "made generator." << endl;
49  _myOwnGenAplusAbar = ptr;
50  }
51  return _myOwnGenAplusAbar;
52 }
54  return getGenerator()->newEvent();
55 }
56 
58  if(0 == _eff) return 1.0;
59  return _eff->RealVal(evt);
60 }
62  if(_Nevents <= 0) return 9999;
63  double s = sigmaAbs();
64  if(s < 0) s *=-1;
65  return s;
66 }
67 
68 complex<double> CoherenceFactor::integAxAbarStar()const{
69  if(_Nevents <=0) return 0;
70  return _sumAxAbarStar / ((double) _Nevents);
71 }
73  if(_Nevents <=0) return 0;
74  if(_sumASq <=0) return -9999;
75  return sqrt(_sumASq / ((double) _Nevents));
76 }
78  if(_Nevents <=0) return 0;
79  if(_sumAbarSq <=0) return -9999;
80  return sqrt(_sumAbarSq / ((double) _Nevents));
81 }
83  if(_Nevents <=0) return 0;
84  return _sumASq / ((double) _Nevents);
85 }
87  if(_Nevents <=0) return 0;
88  return _sumAbarSq / ((double) _Nevents);
89 }
90 
91 complex<double> CoherenceFactor::cvarAxAbarStar()const{
93 }
94 double CoherenceFactor::realAorAbarVar(double s, double sq)const{
95  if(_Nevents <=0 ) return 0;
96  if(s == 0) return -9999;
97  double m = s/((double) _Nevents);
98  double msq = sq/((double) _Nevents);
99  double varAsq = (msq - m*m)/((double) _Nevents);
100 
101  return 0.5 * varAsq / fabs(s);
102 }
103 double CoherenceFactor::varA()const{
105 }
108 }
109 
110 complex<double> CoherenceFactor::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 
120 
121 complex<double> CoherenceFactor::var()const{
122  bool dbThis=false;
123 
124  complex<double> m = Rval();
125  complex<double> som(m.real()*m.real(), m.imag()*m.imag());
126 
127  double den = integA()*integA() * integAbar()*integAbar();
128  if(den <= 0) return complex<double>(-9999,-9999);
129 
130  double ar = cvarAxAbarStar().real() / den;
131  double ai = cvarAxAbarStar().imag() / den;
132  complex<double> a(ar, ai);
133  complex<double> b = varA()/(integA()*integA()) * som;
134  complex<double> c = varAbar()/(integAbar()*integAbar()) * som;
135 
136  if(dbThis){
137  cout << " cvarAxAbarStar() << " << cvarAxAbarStar() << endl;
138  cout << "var() = " << a << " + " << b << " + " << c
139  << " = " << a + b + c << endl;
140  }
141  return a + b + c;
142 }
143 
144 complex<double> CoherenceFactor::sigma() const{
145  return complex<double>(sqrt(fabs(var().real())), sqrt(fabs(var().imag())));
146 }
148  double a = var().real() * 2*fabs(Rval().real()/norm(Rval()));
149  double b = var().imag() * 2*fabs(Rval().imag()/norm(Rval()));
150  return a+b;
151 }
153  double va = varAbs();
154  if(va < 0) return -9999;
155  return sqrt(va);
156 }
158  double a= fabs(Rval().real());
159  double b= fabs(Rval().imag());
160  double den = a*a + b*b;
161  if(den <= 0)return -9999;
162 
163  return var().real()*b/den + var().imag()*a/den;
164 }
166  double va = varAngle();
167  if(va < 0) return -9999;
168  return sqrt(va);
169 }
170 complex<double> CoherenceFactor::Rval() const{
171  if(_Nevents <= 0 || integA() <= 0 || integAbar() <= 0) return -9999;
172  return integAxAbarStar() / (integA() * integAbar());
173 }
174 
175 void CoherenceFactor::printResult(std::ostream& os) const{
176  os << "Integrals from CoherenceFactor\n"
177  << "\t int |A|^2: " << integASq()
178  << ", int |Abar|^2 " << integAbarSq();
179  double rBSq = _CSAbs*_CSAbs;
180  if(rBSq > 0){
181  os << "\n\t int |Abar|^2/rB^2 " << integAbarSq()/rBSq;
182  }
183  if(integAbarSq() > 0){
184  os << "\n ratio int |A|^2 / int |Abar|^2 = " << integASq()/integAbarSq()
185  << ", ratio * rB^2 = " << rBSq*integASq()/integAbarSq();
186  }
187  os << "\n\n Coherence factor result (same result, different formats):"
188  << "\n\tR exp(i xi) = " << Rval() << " +/- " << sigma()
189  << "\n\tR exp(i xi) = " << abs(Rval())
190  << " * exp( i * " << arg(Rval()) << " )"
191  << "\n\t sig(R) = " << sigmaAbs()
192  << " sig(xi) = " << sigmaAngle()
193  << "\n\tR exp(i xi) = " << abs(Rval())
194  << " * exp( i * " << arg(Rval())*180.0/pi << " deg )"
195  << "\n\t sig(R) = " << sigmaAbs()
196  << " sig(xi) = " << sigmaAngle()*180.0/pi << " deg";
197  if(arg(Rval()) < 0){
198  cout << "\n\tR exp(i xi) = " << abs(Rval())
199  << " * exp( i * " << arg(Rval())*180.0/pi + 360. << " deg )"
200  << "\n\t sig(R) = " << sigmaAbs()
201  << " sig(xi) = " << sigmaAngle()*180.0/pi << " deg";
202  }
203  cout << endl;
204 }
206  // bool dbThis=false;
207  return A()->ComplexVal(evt);
208 }
210  bool dbThis=false;
211  if(dbThis) cout << "CoherenceFactor::Abar_Value" << endl;
212  complex<double> val = Abar()->ComplexVal(evt);
213  if(dbThis) cout << "got value: " << val << endl;
214  return val;
215 }
216 
217 complex<double> CoherenceFactor::getCVal(){
218  bool dbThis=false;
219  if(dbThis) cout << "Hello from CoherenceFactor::getCVal()" << endl;
220  long int rediculousNumber = 1000000000;
221  long int tries=0;
222 
223  int printEvery = 10000;
224 
225  while(estimatedPrecision() > _precision && tries < rediculousNumber){
226  for(int i=0; i < 1000; i++){
227  tries++;
228  bool printout = tries < 10 || (0 == tries%printEvery);
229 
231 
232  if(0 == evtPtr){
233  if(dbThis) cout << "WARNING in CoherenceFactor::getR()"
234  << " got evtPtr = " << evtPtr << endl;
235  continue;
236  }
237  //cout << "evtPtr->phaseSpace() " << evtPtr->phaseSpace() << endl;
238 
239  double w = evtPtr->getWeight()
241 
242  w*= getEff(*evtPtr);
243 
244  w = sqrt(w); // since we apply the weight to the amplitudes,
245  // while the integrals (as one might expect) all
246  // contain terms |A|^2, |Abar|^2, or |A*Abar|.
247 
248  complex<double> c_a=
249  A_Value(*evtPtr) * w;
250 
251  complex<double> c_abar=
252  Abar_Value(*evtPtr) *w*polar(_CSAbs, _CSPhase);
253 
254  double d_a = norm(c_a);
255  double d_abar = norm(c_abar);
256 
257  _sumASq += d_a;
258  _sumASqSquared += d_a*d_a;
259 
260  _sumAbarSq += d_abar;
261  _sumAbarSqSquared += d_abar*d_abar;
262 
263  complex<double> c_prod = c_a * conj(c_abar);
264  _sumAxAbarStar += c_prod;
265  complex<double> c_prodSquared(c_prod.real() * c_prod.real()
266  , c_prod.imag() * c_prod.imag()
267  );
268  _sumAxAbarStarSquared += c_prodSquared;
269 
270  _Nevents++;
271 
272  if(printout){
273  cout << " DalitzEvent::EventCounter() "
275  << endl;
276  cout << "INFO from CoherenceFactor::getR()"
277  << "\n\t tries: " << tries << ", for " << _Nevents << " events."
278  << endl;
279  // << "\n\t c_a, c_abar: " << c_a << ", " << c_abar
280  // << "\n\t value: " << Rval()
281  // << " = " << abs(Rval()) << " * exp( i * " << arg(Rval()) << " )"
282  // << " +/- " << estimatedPrecision()
283  // << endl;
284  printResult();
285  cout << " --------------------------------- " << endl;
286  }
287  }
288  }
289  return Rval();
290 }
MINT::IReturnComplexForEvent< IDalitzEvent > * Abar()
double sigmaAngle() const
DalitzEventPattern getTreePattern() const
Definition: FitAmplitude.h:169
virtual FitAmplitude * getAmpPtr(unsigned int i)
virtual double getWeight() const =0
std::complex< double > _sumAxAbarStarSquared
void printResult(std::ostream &os=std::cout) const
static const double pi
std::complex< double > _sumAxAbarStar
std::complex< double > var() const
static const double s
std::complex< double > cvarAxAbarStar() const
virtual double RealVal(EVENT_TYPE &evt)=0
static long int eventCounter()
Definition: DalitzEvent.h:125
MINT::counted_ptr< IDalitzEvent > newEvent()
std::complex< double > sigma() const
std::complex< double > Rval() const
double integA() const
double sigmaAbs() const
std::complex< double > integAxAbarStar() const
MINT::counted_ptr< MINT::IEventGenerator< IDalitzEvent > > getGenerator()
CoherenceFactor(FitAmpSum &A, FitAmpSum &Abar, double CSAbs=1, double CSPhase=0.0, MINT::IReturnRealForEvent< IDalitzEvent > *eff=0, double prec=1.e-3)
virtual DalitzBWBoxSet makeBWBoxes(const DalitzEventPattern &pat, TRandom *rnd=gRandom)
Definition: FitAmpSum.h:81
double varAbs() const
virtual counted_ptr< RETURN_TYPE > newEvent()=0
static const double m
std::complex< double > complexVar(std::complex< double > s, std::complex< double > s_sq) const
MINT::IReturnRealForEvent< IDalitzEvent > * _eff
virtual double getGeneratorPdfRelativeToPhaseSpace() const =0
double varAngle() const
double realAorAbarVar(double s, double sq) const
double varAbar() const
std::complex< double > getCVal()
MINT::IReturnComplexForEvent< IDalitzEvent > * A()
MINT::counted_ptr< MINT::IEventGenerator< IDalitzEvent > > _myOwnGenAplusAbar
double estimatedPrecision() const
std::complex< double > Abar_Value(IDalitzEvent &evt)
double integAbarSq() const
double _sumAbarSqSquared
virtual std::complex< double > ComplexVal(EVENT_TYPE &evt)=0
double getEff(IDalitzEvent &evt)
std::complex< double > A_Value(IDalitzEvent &evt)
double integAbar() const
virtual unsigned int size() const
FitAmpSum _A_plus_Abar
double varA() const
double integASq() const