MINT2
DalitzBoxSet_Method2.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:57 GMT
4 #include <iostream>
5 
6 using namespace std;
7 using namespace MINT;
8 
11  , DalitzBoxSet(other)
12  , _pat(other._pat)
13 {
14 }
15 
17  , TRandom* rnd)
18  : DalitzBoxSet(rnd)
19  , _pat(pat)
20 {
21 }
22 
24  , const DalitzEventPattern& pat
25  )
26  : DalitzBoxSet(boxSet)
27  , _pat(pat)
28 {
29  cout << " DalitzBoxSet_Method2 from DalitzBoxSet, and pattern "
30  << pat
31  << ", ready? " << _ready
32  << "; this is me:\n" << (*this)
33  << endl;
34  _ready = false;
35 }
36 
37 
39  for(unsigned int i=0; i < this->size(); i++){
40  (*this)[i].setFlatPhaseSpace();
41  }
42 }
43 
45  _maxHeight=-1;
46  for(unsigned int i=0; i < this->size(); i++){
47  double thisHeight = (*this)[i].height();
48  if(thisHeight > _maxHeight) _maxHeight = thisHeight;
49  }
50 }
51 
53  for(unsigned int i=0; i < this->size(); i++){
54  double thisHeight = (*this)[i].height();
55  if(thisHeight < 0){
56  (*this)[i].setHeight(_maxHeight);
57  }
58  }
59 }
60 
62  return _maxHeight;
63 }
64 
66  cout << " getting ready " << endl;
69  getMaxHeight();
71  cout << "DalitzBoxSet_Method2: I am ready.\n" << (*this) << endl;
72 }
73 
75 
76  if(0 == _amps ) return 0;
77  double val = _amps->RealVal(evt);
78  return val;
79 }
80 
82  if(! _ready) getReady();
83  int boxIndex = pickRandomVolume();
84  //cout << "DalitzBoxSet::tryEvent() in volume " << boxIndex << endl;
85  return (*this)[boxIndex].tryWeightedEventForOwner();
86 }
87 
89  bool dbThis=false;
90  if(dbThis)cout << "_ready = " << _ready << endl;
91  if(dbThis)cout << " maxHeight " << maxHeight() << endl;
92  if(maxHeight() < -9998 || ! _ready) getReady();
93  if(dbThis)cout << " DalitzBoxSet_Method2::newEvent "
94  << " getting event " << endl;
96  while(0 == ptr){
97  ptr = tryWeightedEvent();
98  }
99  if(dbThis) cout << "got event, returning " << ptr << endl;
100  return ptr;
101 }
102 
104  if(! _ready) getReady();
106  int boxIndex=-1;
107  /*
108  cout << "Hello from DalitzBoxSet_Method2::tryEvent()"
109  << endl;
110  cout << "I've got an event to try " << *evtPtr << endl;
111  */
112  for(unsigned int i=0; i< this->size(); i++){
113  bool isIn = (*this)[i].insideArea(*evtPtr);
114  /*
115  cout << "Is event in box " << i << " ? " << endl;
116  cout << "\t" << (isIn? "yes" : "no")
117  << endl;
118  */
119  if(isIn){
120  boxIndex=i;
121  break;
122  }
123  }
124  if(boxIndex < 0 || boxIndex >= (int) this->size()){
125  cout << "ERROR in DalitzBoxSet_Method2::tryEvent()"
126  << " boxIndex = " << boxIndex
127  << ", outside [" << 0 << ", " << this->size() << "]"
128  << endl;
129  return counted_ptr<DalitzEvent>(0);
130  }
131 
132  double thisHeight = (*this)[boxIndex].height();
133  if(_rnd->Rndm()*maxHeight() >= thisHeight){
134  return counted_ptr<DalitzEvent>(0);
135  }
136  // OK, so it passed the box stage, now internal:
137  double pdf = eventsPDF(*evtPtr);
138  if(pdf > thisHeight){
139  cout << "ERROR, underestimated box height [" << boxIndex << "]"
140  << "\n\t\t thisHeight = " << thisHeight
141  << "\n\t\t < pdf = " << pdf
142  << "\n\t\t (maxHeight = " << maxHeight() << ")" << endl;
143  (*this)[boxIndex].setHeight(3*pdf);
144  getMaxHeight();
145  }
146  if(_rnd->Rndm()* thisHeight >= pdf) {
147  return counted_ptr<DalitzEvent>(0);
148  }
149 
150  return evtPtr;
151 }
MINT::IReturnRealForEvent< IDalitzEvent > * _amps
Definition: DalitzBoxSet.h:25
DalitzEventPattern _pat
virtual double RealVal(EVENT_TYPE &evt)=0
virtual MINT::counted_ptr< DalitzEvent > tryEvent()
DalitzBoxSet_Method2(const DalitzEventPattern &pat, TRandom *rnd=gRandom)
TRandom * _rnd
Definition: DalitzBoxSet.h:27
virtual void getReady()
virtual MINT::counted_ptr< DalitzEvent > tryWeightedEvent()
int pickRandomVolume()
double eventsPDF(DalitzEvent &evt)
virtual MINT::counted_ptr< IDalitzEvent > newEvent()