MINT2
CoherenceFactorCalculator.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 //
10 #include "Mint/FitAmpSum.h"
14 
15 #include <cstdio>
16 
17 using namespace std;
18 using namespace MINT;
19 
22  , double CSAbs
23  , double CSPhase
25  , double prec
26  , const std::string& name
27  )
28  : _A_plus_Abar(A+Abar)
29  , _myOwnGenAplusAbar(0)
30  , _precision(prec)
31  , _name(name)
32 {
34  ptr_flat(new CoherenceFactorStoreAndEvaluate(A, Abar
35  , CSAbs, CSPhase
36  , 0, prec));
37  _cfList.push_back(ptr_flat);
38 
40  ptr_eff(new CoherenceFactorStoreAndEvaluate(A, Abar
41  , CSAbs, CSPhase
42  , eff, prec));
43  _cfList.push_back(ptr_eff);
44 
45 }
46 
49  bool dbThis=false;
50  if(0 == _myOwnGenAplusAbar){
51  if(dbThis) cout << "CoherenceFactorCalculator::getGenerator(): "
52  << "making generator" << endl;
53  if(_A_plus_Abar.size() <= 0) return 0;
56  ptr( new DalitzBWBoxSet(_A_plus_Abar.makeBWBoxes(pat)));
57  if(dbThis) cout << "made generator." << endl;
58  _myOwnGenAplusAbar = ptr;
59  }
60  return _myOwnGenAplusAbar;
61 }
63  return getGenerator()->newEvent();
64 }
65 
67  if(_cfList.size() < 2) return 1;
68  double d = _cfList[0]->integASq();
69  if(d <=0){
70  return -1;
71  }else{
72  return _cfList[1]->integASq()/d;
73  }
74 }
76  if(_cfList.size() < 2) return 1;
77  double d = _cfList[0]->integAbarSq();
78  if(d <=0){
79  return -1;
80  }else{
81  return _cfList[1]->integAbarSq()/d;
82  }
83 }
84 
86  double d = _cfList[0]->integASq();
87  if(d <=0){
88  return -1;
89  }else{
90  double vn = _cfList[1]->varASq();
91  double vd = _cfList[0]->varASq();
92  return vn/(d*d) + effA()*effA()*vd/(d*d);
93  }
94 }
96  double d = _cfList[0]->integAbarSq();
97  if(d <=0){
98  return -1;
99  }else{
100  double vn = _cfList[1]->varAbarSq();
101  double vd = _cfList[0]->varAbarSq();
102  return vn/(d*d) + effAbar()*effAbar()*vd/(d*d);
103  }
104 }
106  double v = effAVar();
107  if(v < 0) return -1;
108  return sqrt(v);
109 }
111  double v = effAbarVar();
112  if(v < 0) return -1;
113  return sqrt(v);
114 }
115 void CoherenceFactorCalculator::printResult(std::ostream& os) const{
116  double R0 = -9999;
117  if(_cfList.size() >=2){
118  R0 = _cfList[0]->absR();
119  os << "Efficiencies from CoherenceFactorCalculater\n";
120  os << " A: " << effA() << " +/- " << effASigma();
121  os << ", Abar: " << effAbar() << " +/- " << effAbarSigma();
122  }
123  os << "\n Coherence Factors";
124  for(unsigned int i=0; i < _cfList.size(); i++){
125  if(0 == i){
126  os << "\n * No efficiency effects "
127  << " - 100% efficient detector\n";
128  }else{
129  os << "\n * Including efficiency effects\n";
130  }
131  _cfList[i]->print(os, "\t" + anythingToString((int) i) + ")");
132  if(i > 0){
133  os << "\n ....difference..relative..to..no..efficiency..effects:....";
134  os << "\n diff R= " << _cfList[i]->absR() - R0
135  << " +/- " << sqrt(_cfList[i]->varAbs() + _cfList[0]->varAbs());
136  if(R0 > 0){
137  os << "\n relative diff R= "
138  << ((_cfList[i]->absR() - _cfList[0]->absR())/R0)
139  << " +/- " << (sqrt(_cfList[i]->varAbs() + _cfList[0]->varAbs())/R0);
140  os << "\n diff phase= "
141  << _cfList[i]->phaseRdeg() - _cfList[0]->phaseRdeg()
142  << " +/- " << sqrt(_cfList[i]->varAngleDeg() + _cfList[0]->varAngleDeg())
143  << "\n";
144  }
145  }
146  }
147  os << endl;
148 }
149 
151  bool dbThis=false;
152  if(dbThis) cout << "Hello from CoherenceFactorCalculator::evaluate()" << endl;
153 
154  long int rediculousNumber = 1000000000;
155  int tries=0;
156  int printEvery = 10000;
157  int makeHistosEvery = 100000;
158  while(estimatedPrecision() > _precision && tries < rediculousNumber){
159  for(int i=0; i < 1000; i++){
160  tries++;
161  bool printout = tries < 10 || (0 == tries%printEvery);
162  bool makeHistos = (0 == tries%makeHistosEvery);
164  if(0 == evtPtr){
165  if(dbThis) cout << "WARNING in CoherenceFactor::getR()"
166  << " got evtPtr = " << evtPtr << endl;
167  continue;
168  }
169 
170  for(unsigned int i=0; i < _cfList.size(); i++){
171  _cfList[i]->addEvent(evtPtr);
172  }
173 
174  if(printout){
175  cout << " DalitzEvent::EventCounter() "
177  << endl;
178  cout << "INFO from CoherenceFactor::getR()"
179  << "\n\t tries: " << tries
180  << endl;
181  // << "\n\t c_a, c_abar: " << c_a << ", " << c_abar
182  // << "\n\t value: " << Rval()
183  // << " = " << abs(Rval()) << " * exp( i * " << arg(Rval()) << " )"
184  // << " +/- " << estimatedPrecision()
185  // << endl;
186  printResult();
187  cout << " --------------------------------- " << endl;
188  }
189  if(makeHistos){
190  /*
191  for(unsigned int i=0; i < _cfList.size(); i++){
192  char fname[1000];
193  sprintf(fname, "%s_%d", _name.c_str(), i);
194  _cfList[i]->saveHistos(fname);
195  _cfList[i]->drawHistos(fname);
196  }
197  */
198  if(_cfList.size() >=2){
199  _cfList[1]->drawHistosWith(*_cfList[0], _name + "AmpCompare", effA());
200  _cfList[1]->drawHistoRatios(*_cfList[0], _name + "Eff");
201  }
202  }
203  }
204  }
205  return _cfList[1]->Rval();
206 }
207 
209  _precision = prec;
210  for(unsigned int i=0; i < _cfList.size(); i++){
211  _cfList[i]->setPrecision(prec);
212  }
213 }
215  double prec = -9999;
216  for(unsigned int i=0; i < _cfList.size(); i++){
217  double tp = _cfList[i]->estimatedPrecision();
218  if(tp > prec) prec = tp;
219  }
220  return prec;
221 }
MINT::counted_ptr< MINT::IEventGenerator< IDalitzEvent > > _myOwnGenAplusAbar
DalitzEventPattern getTreePattern() const
Definition: FitAmplitude.h:169
virtual FitAmplitude * getAmpPtr(unsigned int i)
MINT::counted_ptr< IDalitzEvent > newEvent()
std::vector< MINT::counted_ptr< CoherenceFactorStoreAndEvaluate > > _cfList
static long int eventCounter()
Definition: DalitzEvent.h:125
void printResult(std::ostream &os=std::cout) const
virtual DalitzBWBoxSet makeBWBoxes(const DalitzEventPattern &pat, TRandom *rnd=gRandom)
Definition: FitAmpSum.h:81
virtual counted_ptr< RETURN_TYPE > newEvent()=0
std::string anythingToString(const T &anything)
Definition: Utils.h:62
virtual unsigned int size() const
CoherenceFactorCalculator(FitAmpSum &A, FitAmpSum &Abar, double CSAbs=1, double CSPhase=0.0, MINT::IReturnRealForEvent< IDalitzEvent > *eff=0, double prec=1.e-3, const std::string &name="coherenceFactorC")
MINT::counted_ptr< MINT::IEventGenerator< IDalitzEvent > > getGenerator()