MINT2
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
DalitzBoxSet Class Reference

#include <DalitzBoxSet.h>

Inheritance diagram for DalitzBoxSet:
MINT::PolymorphVector< DalitzBox > MINT::IEventGenerator< IDalitzEvent > DalitzBoxSet_Method2

Public Member Functions

void makeRelations ()
 
void removeDuplicates ()
 
void sortYourself ()
 
void callSortYourselfForDebug ()
 
 DalitzBoxSet (TRandom *rnd=gRandom)
 
 DalitzBoxSet (const DalitzBoxSet &other)
 
void add (const DalitzBox &box)
 
void add (const MINT::PolymorphVector< DalitzBox > &boxes)
 
void add (const DalitzBoxSet &boxes)
 
void setPDF (MINT::IReturnRealForEvent< IDalitzEvent > *amps)
 
DalitzBoxSet split (unsigned int nWays) const
 
DalitzBoxSet splitIfWiderThan (double maxWidth) const
 
virtual MINT::counted_ptr< DalitzEventtryEvent ()
 
virtual MINT::counted_ptr< DalitzEventtryWeightedEvent ()
 
virtual MINT::counted_ptr< DalitzEventgenerateEventForOwner ()
 
virtual DalitzEvent generateEvent ()
 
virtual MINT::counted_ptr< IDalitzEventnewEvent ()
 
virtual void print (std::ostream &os=std::cout) const
 
virtual bool exhausted () const
 
bool setRnd (TRandom *rnd)
 
virtual bool ensureFreshEvents ()
 
virtual ~DalitzBoxSet ()
 
- Public Member Functions inherited from MINT::PolymorphVector< DalitzBox >
 PolymorphVector ()
 
 PolymorphVector (unsigned int N)
 
 PolymorphVector (unsigned int N, const DalitzBox &c)
 
 PolymorphVector (const PolymorphVector &other)
 
 PolymorphVector (const typename std::vector< DalitzBox > &other)
 
virtual ~PolymorphVector ()
 
std::vector< DalitzBox > & theVector ()
 
const std::vector< DalitzBox > & theVector () const
 
DalitzBoxoperator[] (unsigned int i)
 
const DalitzBoxoperator[] (unsigned int i) const
 
DalitzBoxat (unsigned int i)
 
const DalitzBoxat (unsigned int i) const
 
std::vector< DalitzBox >::iterator begin ()
 
std::vector< DalitzBox >::const_iterator begin () const
 
std::vector< DalitzBox >::iterator end ()
 
std::vector< DalitzBox >::const_iterator end () const
 
std::vector< DalitzBox >::iterator find (const DalitzBox &c)
 
std::vector< DalitzBox >::const_iterator find (const DalitzBox &c) const
 
DalitzBoxfront ()
 
const DalitzBoxfront () const
 
DalitzBoxback ()
 
const DalitzBoxback () const
 
unsigned int size () const
 
bool empty () const
 
void push_back (const DalitzBox &c)
 
void pop_back ()
 
void erase (typename std::vector< DalitzBox >::iterator pos)
 
void erase (typename std::vector< DalitzBox >::iterator first, typename std::vector< DalitzBox >::iterator last)
 
PolymorphVector< DalitzBox > & operator= (const PolymorphVector< DalitzBox > &other)
 
void clear ()
 
void resize (unsigned int N)
 
void resize (unsigned int N, const DalitzBox &c)
 
 operator const typename std::vector< DalitzBox > & () const
 
 operator typename std::vector< DalitzBox > & ()
 
bool operator== (const MINT::PolymorphVector< DalitzBox > &v2) const
 
bool operator!= (const MINT::PolymorphVector< DalitzBox > &v2) const
 
bool operator< (const MINT::PolymorphVector< DalitzBox > &v2) const
 
bool operator> (const MINT::PolymorphVector< DalitzBox > &v2) const
 
- Public Member Functions inherited from MINT::IEventGenerator< IDalitzEvent >
virtual ~IEventGenerator ()
 

Protected Member Functions

double VolumeSum () const
 
double AreaSum () const
 
void makeVolumeProbIntervals ()
 
int pickRandomVolume ()
 
void setBoxPDFs ()
 
void setBoxRnds ()
 
void getBoxesReady ()
 
virtual void getReady ()
 

Protected Attributes

bool _ready
 
MINT::PolymorphVector< double > _volumeProbs
 
MINT::IReturnRealForEvent< IDalitzEvent > * _amps
 
TRandom * _rnd
 
- Protected Attributes inherited from MINT::PolymorphVector< DalitzBox >
std::vector< DalitzBox_vec
 

Detailed Description

Definition at line 17 of file DalitzBoxSet.h.

Constructor & Destructor Documentation

◆ DalitzBoxSet() [1/2]

DalitzBoxSet::DalitzBoxSet ( TRandom *  rnd = gRandom)

Definition at line 68 of file DalitzBoxSet.cpp.

69  : _ready(false)
70 {
71  _rnd = rnd;
72 }
TRandom * _rnd
Definition: DalitzBoxSet.h:27

◆ DalitzBoxSet() [2/2]

DalitzBoxSet::DalitzBoxSet ( const DalitzBoxSet other)

Definition at line 74 of file DalitzBoxSet.cpp.

77  , _ready(other._ready)
78  , _volumeProbs(other._volumeProbs)
79  , _amps(other._amps)
80  , _rnd(other._rnd)
81 {
82  if(_ready) makeRelations();
83 }
void makeRelations()
MINT::IReturnRealForEvent< IDalitzEvent > * _amps
Definition: DalitzBoxSet.h:25
TRandom * _rnd
Definition: DalitzBoxSet.h:27
MINT::PolymorphVector< double > _volumeProbs
Definition: DalitzBoxSet.h:24

◆ ~DalitzBoxSet()

virtual DalitzBoxSet::~DalitzBoxSet ( )
inlinevirtual

Definition at line 73 of file DalitzBoxSet.h.

73 {}

Member Function Documentation

◆ add() [1/3]

void DalitzBoxSet::add ( const DalitzBox box)

Definition at line 218 of file DalitzBoxSet.cpp.

218  {
219  _ready = false;
220  cout << " DalitzBoxSet::addBox: adding box "
221  << " with " << box.eventList().size()
222  << " events in it."
223  << endl;
224  this->push_back(box);
225  cout << " done that." << endl;
226 }
void push_back(const DalitzBox &c)
virtual unsigned int size() const
Definition: EventList.h:59
DalitzEventList & eventList()
Definition: DalitzBox.h:112

◆ add() [2/3]

void DalitzBoxSet::add ( const MINT::PolymorphVector< DalitzBox > &  boxes)

Definition at line 228 of file DalitzBoxSet.cpp.

228  {
229  _ready = false;
230  for(unsigned int i=0; i<boxes.size(); i++){
231  this->push_back(boxes[i]);
232  }
233 }
void push_back(const DalitzBox &c)
unsigned int size() const

◆ add() [3/3]

void DalitzBoxSet::add ( const DalitzBoxSet boxes)

Definition at line 235 of file DalitzBoxSet.cpp.

235  {
236  _ready = false;
237  for(unsigned int i=0; i<boxes.size(); i++){
238  this->push_back(boxes[i]);
239  }
240 }
void push_back(const DalitzBox &c)
unsigned int size() const

◆ AreaSum()

double DalitzBoxSet::AreaSum ( ) const
protected

Definition at line 170 of file DalitzBoxSet.cpp.

170  {
171  double sum = 0;
172  for(unsigned int i=0; i< this->size(); i++){
173  sum += (*this)[i].area().size();
174  }
175  return sum;
176 }

◆ callSortYourselfForDebug()

void DalitzBoxSet::callSortYourselfForDebug ( )

Definition at line 265 of file DalitzBoxSet.cpp.

265  {
266  sortYourself();
267 }
void sortYourself()

◆ ensureFreshEvents()

bool DalitzBoxSet::ensureFreshEvents ( )
virtual

Implements MINT::IEventGenerator< IDalitzEvent >.

Definition at line 391 of file DalitzBoxSet.cpp.

391  {
392  _rnd->SetSeed(time(0)*4);
393  setRnd(_rnd);
394  return true;
395 }
bool setRnd(TRandom *rnd)
TRandom * _rnd
Definition: DalitzBoxSet.h:27

◆ exhausted()

virtual bool DalitzBoxSet::exhausted ( ) const
inlinevirtual

Implements MINT::IEventGenerator< IDalitzEvent >.

Reimplemented in DalitzBoxSet_Method2.

Definition at line 70 of file DalitzBoxSet.h.

70 {return false;}

◆ generateEvent()

DalitzEvent DalitzBoxSet::generateEvent ( )
virtual

Definition at line 369 of file DalitzBoxSet.cpp.

369  {
371  if(0==evtPtr){
372  cout << "WARNING: DalitzBoxSet::generateEvent()"
373  << " failed to generate event despite LARGE"
374  << " number of tries." << endl;
375  DalitzEvent event;
376  }
377  DalitzEvent evt(*evtPtr);
378  // delete evtPtr;
379  return evt;
380 }
virtual MINT::counted_ptr< DalitzEvent > generateEventForOwner()

◆ generateEventForOwner()

counted_ptr< DalitzEvent > DalitzBoxSet::generateEventForOwner ( )
virtual

Definition at line 358 of file DalitzBoxSet.cpp.

358  {
360  unsigned int counter=0;
361  unsigned int veryLargeNumber = 1000000000;
362  do{
363  newEvent = tryEvent();
364  counter++;
365  }while(0==newEvent && counter < veryLargeNumber);
366 
367  return newEvent;
368 }
virtual MINT::counted_ptr< DalitzEvent > tryEvent()
virtual MINT::counted_ptr< IDalitzEvent > newEvent()

◆ getBoxesReady()

void DalitzBoxSet::getBoxesReady ( )
protected

Definition at line 257 of file DalitzBoxSet.cpp.

257  {
258  for(unsigned int i=0; i < this->size(); i++){
259  cout << " getting box " << i << " ready." << endl;
260  (*this)[i].getReady();
261  cout << " got it." << endl;
262  }
263 }

◆ getReady()

void DalitzBoxSet::getReady ( )
protectedvirtual

Reimplemented in DalitzBoxSet_Method2.

Definition at line 268 of file DalitzBoxSet.cpp.

268  {
269  time_t startTime = time(0);
270 
271  cout << "DalitzBoxSet::getReady()" << endl;
272  cout << "before removing dupliates: "
273  << this->size() << " boxes." << endl;
275  cout << "after removing dupliates: "
276  << this->size() << " boxes." << endl;
277  sortYourself();
278  cout << " sorted" << endl;
279  makeRelations();
280  cout << " made relations" << endl;
281  cout << "I have the following " << this->size() << " boxes: " << endl;
282  cout << *this << endl;
283 
284  setBoxPDFs();
285  cout << " set the pdfs " << endl;
286  setBoxRnds();
287  cout << " set the rnds" << endl;
288  getBoxesReady();
289  cout << " got Boxes ready" << endl;
291  cout << " made the intervalse " << endl;
292 
293  double deltaT = difftime(time(0), startTime);
294  cout << "DalitzBoxSet: after only:" << deltaT/60 << " min" << endl;
295  cout << "DalitzBoxSet: I am ready." << endl;
296  _ready = true;
297 }
void makeRelations()
void getBoxesReady()
void makeVolumeProbIntervals()
void sortYourself()
void removeDuplicates()

◆ makeRelations()

void DalitzBoxSet::makeRelations ( )

Definition at line 147 of file DalitzBoxSet.cpp.

147  {
148  if(this->empty()) return;
149  (*this)[0].setDaddy(0);
150 
151  if(this->size() <=1) return;
152  // sortYourself();
153  for(unsigned int i=1; i< this->size(); i++){
154  (*this)[i].setDaddy(&((*this)[i-1]));
155  }
156 }

◆ makeVolumeProbIntervals()

void DalitzBoxSet::makeVolumeProbIntervals ( )
protected

Definition at line 178 of file DalitzBoxSet.cpp.

178  {
179  bool dbThis=false;
180  if(this->empty()) return;
181  // intervals each with a length proportional
182  // to the volume of the corresponding box.
183  // All put together add up to one.
184  // For random number generation.
185 
187  _volumeProbs.resize(this->size());
188 
189  double totalVolume = VolumeSum();
190  double sum=0;
191  for(unsigned int i=0; i < this->size(); i++){
192  sum += (*this)[i].volume()/totalVolume;
193  if(dbThis) cout << " volume probs [" << i <<"] = " << sum << endl;
194  _volumeProbs[i] = sum;
195  }
196 }
void resize(unsigned int N)
double VolumeSum() const
MINT::PolymorphVector< double > _volumeProbs
Definition: DalitzBoxSet.h:24

◆ newEvent()

counted_ptr< IDalitzEvent > DalitzBoxSet::newEvent ( )
virtual

Implements MINT::IEventGenerator< IDalitzEvent >.

Reimplemented in DalitzBoxSet_Method2.

Definition at line 345 of file DalitzBoxSet.cpp.

345  {
346  bool dbThis = false;
347  if(! _ready) getReady();
348  if(dbThis)cout << " DalitzBoxSet::newEvent "
349  << " getting event " << endl;
351  while(0 == ptr){
352  ptr = tryWeightedEvent();
353  }
354  if(dbThis) cout << "got event, returning " << ptr << endl;
355  return ptr;
356 }
virtual void getReady()
virtual MINT::counted_ptr< DalitzEvent > tryWeightedEvent()

◆ pickRandomVolume()

int DalitzBoxSet::pickRandomVolume ( )
protected

Definition at line 198 of file DalitzBoxSet.cpp.

198  {
199  if(! _ready) getReady();
200 
201  if(_volumeProbs.size() != this->size()){
203  }
204 
205  double rndNumber = _rnd->Rndm();
206  for(unsigned int i=0; i< _volumeProbs.size(); i++){
207  if(_volumeProbs[i] > rndNumber) return i;
208  }
209  cout << "WARNING in DalitzBoxSet::pickRandomVolume():"
210  << " How odd - should never have gotten here."
211  << " rndNumber = " << rndNumber
212  << ", _volumeProbs[this->size()-1] = "
213  << _volumeProbs[this->size()-1]
214  << endl;
215  return this->size()-1;
216 }
void makeVolumeProbIntervals()
TRandom * _rnd
Definition: DalitzBoxSet.h:27
virtual void getReady()
unsigned int size() const
MINT::PolymorphVector< double > _volumeProbs
Definition: DalitzBoxSet.h:24

◆ print()

void DalitzBoxSet::print ( std::ostream &  os = std::cout) const
virtual

Definition at line 396 of file DalitzBoxSet.cpp.

396  {
397  os << " DalitzBoxSet with " << this->size() << " boxes:"
398  << "\n======================================";
399  for(unsigned int i=0; i< this->size(); i++){
400  os << "\n box " << i << "\n" << (*this)[i];
401  os << "\n--------------------------------------";
402  }
403 }

◆ removeDuplicates()

void DalitzBoxSet::removeDuplicates ( )

Definition at line 85 of file DalitzBoxSet.cpp.

85  {
86 
87  // lessBoxBySimilarMappedArea lesser;
88  lesserBoxByMappedArea lesserArea;
90  moreBoxByGuessedHeight moreHeight;
91  //sameBoxBySimilarMappedArea same;
92 
93  sort(this->begin(), this->end(), moreHeight);
94  stable_sort(this->begin(), this->end(), lesserArea);
95 
96  std::vector<DalitzBox>::iterator
97  uniqueEnd = unique(this->begin(), this->end(), same);
98 
99 
100  cout << "removeDuplicates: after sorting: " << endl;
101  for(unsigned int i=0; i< this->size(); i++){
102  bool equalToPrevious = false;
103  if(i >= 1) equalToPrevious = same((*this)[i], (*this)[i-1]);
104  cout << " " << i << ") "
105  << (*this)[i]
106  << "\n is equal to previous? "
107  << equalToPrevious
108  << '\n' << endl;
109  }
110 
111  // sameBoxBySimilarMappedArea same;
112  /*
113  this->erase( (unique(this->begin(), this->end(), same))
114  , this->end());
115  */
116  this->erase(uniqueEnd, this->end());
117 
118  cout << "removeDuplicates: after removing: " << endl;
119  for(unsigned int i=0; i< this->size(); i++){
120  cout << " " << i << ") "
121  << (*this)[i]
122  << '\n' << endl;
123  }
124 }
std::vector< DalitzBox >::iterator end()
void erase(typename std::vector< DalitzBox >::iterator pos)
std::vector< DalitzBox >::iterator begin()

◆ setBoxPDFs()

void DalitzBoxSet::setBoxPDFs ( )
protected

Definition at line 247 of file DalitzBoxSet.cpp.

247  {
248  for(unsigned int i=0; i < this->size(); i++){
249  (*this)[i].setAmps(_amps);
250  }
251 }
MINT::IReturnRealForEvent< IDalitzEvent > * _amps
Definition: DalitzBoxSet.h:25

◆ setBoxRnds()

void DalitzBoxSet::setBoxRnds ( )
protected

Definition at line 252 of file DalitzBoxSet.cpp.

252  {
253  for(unsigned int i=0; i < this->size(); i++){
254  (*this)[i].setRnd(_rnd);
255  }
256 }
TRandom * _rnd
Definition: DalitzBoxSet.h:27

◆ setPDF()

void DalitzBoxSet::setPDF ( MINT::IReturnRealForEvent< IDalitzEvent > *  amps)

Definition at line 242 of file DalitzBoxSet.cpp.

242  {
243  _ready = false;
244  _amps = amps;
245 }
MINT::IReturnRealForEvent< IDalitzEvent > * _amps
Definition: DalitzBoxSet.h:25

◆ setRnd()

bool DalitzBoxSet::setRnd ( TRandom *  rnd)

Definition at line 382 of file DalitzBoxSet.cpp.

382  {
383  _ready = false;
384  if(0 == rnd) _rnd = gRandom;
385  else _rnd = rnd; // this *should* do it, but for safety:
386  for(unsigned int i=0; this->size(); i++){
387  (*this)[i].setRnd(_rnd);
388  }
389  return true;
390 }
TRandom * _rnd
Definition: DalitzBoxSet.h:27

◆ sortYourself()

void DalitzBoxSet::sortYourself ( )

Definition at line 125 of file DalitzBoxSet.cpp.

125  {
126  cout << " DalitzBoxSet::sortYourself() " << endl;
127 
128  if(this->size() <= 1) return;
129  cout << " creating sba" << endl;
130  //sortBoxByAreaSize sba;
131  moreBoxByGuessedHeight moreHeight;
132 
133  /*
134  if(is_sorted(this->begin(), this->end(), sba)){
135  return;
136  }
137  */
138  stable_sort(this->begin(), this->end(), moreHeight);
139  // stable_sort(this->begin(), this->end(), sba);
140 
141  for(unsigned int i=0; i< this->size(); i++){
142  (*this)[i].setNumber(i);
143  }
144  cout << " done sorting " << endl;
145 }
std::vector< DalitzBox >::iterator end()
std::vector< DalitzBox >::iterator begin()

◆ split()

DalitzBoxSet DalitzBoxSet::split ( unsigned int  nWays) const

Definition at line 300 of file DalitzBoxSet.cpp.

300  {
301  if(nWays == 1) return (*this);
302 
303  DalitzBoxSet newSet;
304  if(nWays == 0) return newSet;
305 
306  cout << " DalitzBoxSet: before splitting I have "
307  << this->size() << " boxes"
308  << endl;
309  for(unsigned int i=0; i< this->size(); i++){
310  newSet.add((*this)[i].split(nWays));
311  }
312  cout << "after, it's " << newSet.size() << endl;
313  return newSet;
314 }
DalitzBoxSet split(unsigned int nWays) const
void add(const DalitzBox &box)

◆ splitIfWiderThan()

DalitzBoxSet DalitzBoxSet::splitIfWiderThan ( double  maxWidth) const

Definition at line 316 of file DalitzBoxSet.cpp.

316  {
317 
318  DalitzBoxSet newSet;
319 
320  cout << " DalitzBoxSet: before splitting I have "
321  << this->size() << " boxes"
322  << endl;
323  for(unsigned int i=0; i< this->size(); i++){
324  newSet.add((*this)[i].splitIfWiderThan(maxWidth));
325  }
326  cout << "after, it's " << newSet.size() << endl;
327  return newSet;
328 }
DalitzBoxSet splitIfWiderThan(double maxWidth) const
void add(const DalitzBox &box)

◆ tryEvent()

counted_ptr< DalitzEvent > DalitzBoxSet::tryEvent ( )
virtual

Reimplemented in DalitzBoxSet_Method2.

Definition at line 331 of file DalitzBoxSet.cpp.

331  {
332  if(! _ready) getReady();
333  int boxIndex = pickRandomVolume();
334  //cout << "DalitzBoxSet::tryEvent() in volume " << boxIndex << endl;
335  return (*this)[boxIndex].tryEventForOwner();
336 }
virtual void getReady()
int pickRandomVolume()

◆ tryWeightedEvent()

counted_ptr< DalitzEvent > DalitzBoxSet::tryWeightedEvent ( )
virtual

Reimplemented in DalitzBoxSet_Method2.

Definition at line 338 of file DalitzBoxSet.cpp.

338  {
339  if(! _ready) getReady();
340  int boxIndex = pickRandomVolume();
341  //cout << "DalitzBoxSet::tryEvent() in volume " << boxIndex << endl;
342  return (*this)[boxIndex].tryWeightedEventForOwner();
343 }
virtual void getReady()
int pickRandomVolume()

◆ VolumeSum()

double DalitzBoxSet::VolumeSum ( ) const
protected

Definition at line 158 of file DalitzBoxSet.cpp.

158  {
159  double sum = 0;
160  for(unsigned int i=0; i< this->size(); i++){
161  cout << " volume number " << i << ") "
162  << (*this)[i].volume()
163  << endl;
164  sum += (*this)[i].volume();
165  }
166  cout << " Volume sum: " << sum;
167  return sum;
168 }

Member Data Documentation

◆ _amps

MINT::IReturnRealForEvent<IDalitzEvent>* DalitzBoxSet::_amps
protected

Definition at line 25 of file DalitzBoxSet.h.

◆ _ready

bool DalitzBoxSet::_ready
protected

Definition at line 23 of file DalitzBoxSet.h.

◆ _rnd

TRandom* DalitzBoxSet::_rnd
protected

Definition at line 27 of file DalitzBoxSet.h.

◆ _volumeProbs

MINT::PolymorphVector<double> DalitzBoxSet::_volumeProbs
protected

Definition at line 24 of file DalitzBoxSet.h.


The documentation for this class was generated from the following files: