MINT2
DalitzArea.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
3 #include "Mint/DalitzArea.h"
4 
5 #include "Mint/DalitzEvent.h"
7 
8 #include "TRandom.h"
9 
10 #include <iostream>
11 #include <cmath>
12 
13 using namespace std;
14 using namespace MINT;
15 
17  : _pat()
18  , _rnd(gRandom)
19  , _madeCMap(false)
20  , _coords()
21  , _t01(2,3,4)
22  , _s12(1,2)
23  , _s23(2,3)
24  , _s34(3,4)
25  , _t40(1,2,3)
26 {
28 }
29 
31  : _pat(other._pat)
32  , _rnd(other._rnd)
33  , _madeCMap(false)
34  , _coords()
35  , _t01(other._t01)
36  , _s12(other._s12)
37  , _s23(other._s23)
38  , _s34(other._s34)
39  , _t40(other._t40)
40 {
41  // cout << "copying area" << endl;
43 
44  // cout << " size before copy: " << other.size() << endl;
45  // cout << " size after copy: " << this->size() << endl;
46 
47 }
48 
50  _pat = other._pat;
51  _rnd = other._rnd;
52  _madeCMap = false;
53  _coords.clear();
54  _t01 = other._t01;
55  _s12 = other._s12;
56  _s23 = other._s23;
57  _s34 = other._s34;
58  _t40 = other._t40;
60  return (*this);
61 }
62 
63 DalitzArea::DalitzArea(const DalitzEventPattern& pat, TRandom* rnd)
64  : _pat(pat)
65  , _rnd(rnd)
66  , _madeCMap(false)
67  , _coords()
68  , _t01(2,3,4)
69  , _s12(1,2)
70  , _s23(2,3)
71  , _s34(3,4)
72  , _t40(1,2,3)
73 {
74 
75  if(_pat.numDaughters() != 4
76  && _pat.numDaughters() != 3
77  ){
78  cout << "DalitzArea::DalitzArea:"
79  << "\n Sorry, can only deal with 3 and 4 body decays. "
80  << "\n Please improve me so I can deal with decays like this: "
81  << pat << endl;
82  cout << " I'll crash now." << endl;
83  throw "DalitzArea: \"I'm no superman\"";
84  }
86  makeMiMa();
87 }
88 
90  _pat = pat;
91  if(_pat.numDaughters() != 4
92  && _pat.numDaughters() != 3
93  ){
94  cout << "DalitzArea::DalitzArea:"
95  << "\n Sorry, can only deal with 3 or 4 body decays. "
96  << "\n Please improve me so I can deal with decays like this: "
97  << pat << endl;
98  cout << " I'll crash now." << endl;
99  throw "DalitzArea: \"I'm no superman\"";
100  }
102  makeMiMa();
103 }
104 
105 bool DalitzArea::setRnd(TRandom* rnd){
106  _rnd = rnd;
107  return true;
108 }
109 
111  //cout << " Hi, this is DalitzArea::makeCoordinateMap()" << endl;
112  _coords.clear();
113  if(_pat.numDaughters() < 3) return;
114 
115  _coords[_s12] = &_s12;
116  _coords[_s23] = &_s23;
117 
118  if(_pat.numDaughters() >= 4){
119  _coords[_t01] = &_t01;
120  _coords[_s34] = &_s34;
121  _coords[_t40] = &_t40;
122 
123  }
124  //cout << "DalitzArea::makeCoordinateMap() made map, returning true" << endl;
125  _madeCMap = true;
126 }
127 
128 
130  double safetyFactor=1; // for debug only - otherwise 1
131  //double safetyFactor=1.3;
132  _s12.setMinMax( _pat.sijMin(1,2)/safetyFactor
133  , _pat.sijMax(1,2)*safetyFactor);
134  _s23.setMinMax( _pat.sijMin(2,3)/safetyFactor
135  , _pat.sijMax(2,3)*safetyFactor);
136  if(_pat.numDaughters() >= 4){
137  _t01.setMinMax( _pat.sijMin(2,3,4)/safetyFactor
138  , _pat.sijMax(2,3,4)*safetyFactor);
139  _s34.setMinMax( _pat.sijMin(3,4)/safetyFactor
140  , _pat.sijMax(3,4)*safetyFactor);
141  _t40.setMinMax( _pat.sijMin(1,2,3)/safetyFactor
142  , _pat.sijMax(1,2,3)*safetyFactor);
143  }
144 
145 }
146 
147 void DalitzArea::encloseInPhaseSpaceArea(double safetyFactor){
149  for(map<DalitzCoordKey, DalitzCoordinate*>::const_iterator
150  it = _coords.begin();
151  it != _coords.end(); it++){
152  double psMin = _pat.sijMin(it->first)/safetyFactor;
153  double psMax = _pat.sijMax(it->first)*safetyFactor;
154 
155  if(it->second->min() < psMin){
156  it->second->setMin(psMin);
157  }
158  if(it->second->max() > psMax){
159  it->second->setMax(psMax);
160  }
161  }
162 
163 }
164 
167  for(map<DalitzCoordKey, DalitzCoordinate*>::const_iterator
168  it = _coords.begin();
169  it != _coords.end(); it++){
170  double psMin = _pat.sijMin(it->first)/safetyFactor;
171  double psMax = _pat.sijMax(it->first)*safetyFactor;
172 
173  it->second->setMin(psMin);
174  it->second->setMax(psMax);
175 
176  }
177 
178 }
179 
180 
181 
183 }
184 
186  if(_pat.size() != p.size()) return false;
187 
188  for(unsigned int i=0; i < _pat.size(); i++){
189  if( abs(_pat[i]) != abs(p[i])) return false;
190  }
191 
192  return true;
193 }
194 
195 /*
196 bool DalitzArea::isInside(const DalitzEvent& evt) const{
197  //cout << "Hello from DalitzArea::isInside" << endl;
198  if(! compatiblePattern(evt.eventPattern()){
199  return false;
200  }
201  makeCoordinateMap();
202  //cout << " Made Coordinate map " << endl;
203  for(map<vector<int>, DalitzCoordinate*>::const_iterator
204  it = _coords.begin();
205  it != _coords.end(); it++){
206  double val = evt.sij(it->first);
207  if(val < it->second->min() || val >= it->second->max()) return false;
208  }
209  //cout << "returning true" << endl;
210  return true;
211 }
212 */
213 
214 bool DalitzArea::isInside(const IDalitzEvent& evt) const{
215  //cout << "Hello from DalitzArea::isInside" << endl;
216  if(! compatiblePattern(evt.eventPattern())){
217  return false;
218  }
220  //cout << " Made Coordinate map " << endl;
221  for(map<DalitzCoordKey, DalitzCoordinate* >::const_iterator
222  it = _coords.begin();
223  it != _coords.end(); it++){
224  double val = evt.sij(it->first);
225  if(val < it->second->min() || val >= it->second->max()) return false;
226  }
227  //cout << "returning true" << endl;
228  return true;
229 }
231 
233  //cout << " Made Coordinate map " << endl;
234  double val = dc.val();
235  if(_coords[dc]->min() <= val && _coords[dc]->max() > val){
236  return true;
237  }else{
238  return false;
239  }
240 }
241 bool DalitzArea::isInside(const std::vector<DalitzCoordinate>& dcList) const{
242  for(unsigned int i=0; i < dcList.size(); i++){
243  if(! isInside(dcList[i])){
244  return false;
245  }
246  }
247  return true;
248 
249 }
250 
251 double DalitzArea::size() const{
252  if(_pat.size() < 3) return 0;
253 
254  double p=1;
255 
256  /* cout << " DalitzArea::size(): returning..." << endl;
257  cout << " e.g. _t01 " << _t01 << endl;
258  cout << " e.g. _s12 " << _s12 << endl;
259  cout << "_madeCMap = " << _madeCMap << endl;
260  */
262  for(map<DalitzCoordKey, DalitzCoordinate*>::const_iterator it = _coords.begin();
263  it != _coords.end(); it++){
264  //cout << "num indices " << it->second->size() << endl;
265  //cout << " co-ordinate " << *(it->second) << endl;
266  //cout << "( " << it->second->max() << " - " << it->second->min() << " ) * ";
267  p *= (it->second->max() - it->second->min());
268  }
269  // cout << " = " << p << endl;
270  return fabs(p);
271 }
272 
274  , double scale1
275  , double scale2
276  , double scale3
277  , double scale4
278  ) const{
279 
280  double t01 = _t01.min() + scale0*(_t01.max() - _t01.min());
281  double s12 = _s12.min() + scale1*(_s12.max() - _s12.min());
282  double s23 = _s23.min() + scale2*(_s23.max() - _s23.min());
283  double s34 = _s34.min() + scale3*(_s34.max() - _s34.min());
284  double t40 = _t40.min() + scale4*(_t40.max() - _t40.min());
285 
286  Calculate4BodyProps c4b(t01, s12
287  , s23, s34
288  , t40
289  , _pat[0].mass()
290  , _pat[1].mass(), _pat[2].mass()
291  , _pat[3].mass(), _pat[4].mass()
292  );
293  if(c4b.phaseSpaceFactor() <=0){
294  if(false)cout << " for \n "
295  << t01 << "( " << _t01 << "), \n "
296  << s12 << "( " << _s12 << "), \n "
297  << s23 << "( " << _s23 << "), \n "
298  << s34 << "( " << _s34 << "), \n "
299  << t40 << "( " << _t40 << "), \n "
300  << " outside phase space!! "
301  << endl;
302  return counted_ptr<DalitzEvent>(0);
303  }
304  counted_ptr<DalitzEvent> evt(new DalitzEvent(_pat, t01, s12, s23, s34, t40));
305  if(0 == evt){
306  cout << "WARNING DalitzArea::make4Event()"
307  << " making the event failed at 'new DalitzEvent(...)'"
308  << " this shouldn't really happen."
309  << endl;
310  return evt;
311  }
312  if(evt->phaseSpace() <= 0){
313  return counted_ptr<DalitzEvent>(0);
314  }
315 
316  return evt;
317 }
318 
320  if(_pat.numDaughters() == 3) return make3Event();
321  if(_pat.numDaughters() == 4) return make4Event();
322  cout << "ERROR in DalitzArea::makeEvent() can only make events"
323  << " with 3 or 4 daughters. You want : " << _pat
324  << endl;
325  return counted_ptr<DalitzEvent>(0);
326 }
327 
329 
330  cout << " ERROR DalitzArea::make3Event(): I don't work, yet. "
331  << "\n Please improve me. Sorry, will have to crash, now"
332  << endl;
333  throw "no making 3 body events in DalitzArea, yet";
334 
335  /*
336  double s12 = _s12.min() + _rnd->Rndm()*(_s12.max() - _s12.min());
337  double s23 = _s23.min() + _rnd->Rndm()*(_s23.max() - _s23.min());
338 
339  _evt = new DalitzEvent(_pat, s12, s23);
340  if(_evt->phaseSpace() <= 0){
341  deleteEvent();
342  return 0;
343  }
344 
345  return _evt;
346  */
347  return counted_ptr<DalitzEvent>(0);
348 }
350  return makeEventForOwner( _rnd->Rndm()
351  , _rnd->Rndm()
352  , _rnd->Rndm()
353  , _rnd->Rndm()
354  , _rnd->Rndm()
355  );
356 }
357 
359  //cout << " size before setting c = " << c << " : " << size();
360  map<DalitzCoordKey, DalitzCoordinate*>::iterator it = _coords.find(c);
361  if(it == _coords.end()){
362  cout << "ERROR: DalitzArea::setCoordinate failed to set coordinate "
363  << c << endl;
364  return false;
365  }
366  *(it->second) = c;
367  //cout << " size after: " << size() << endl;
368  return true;
369 }
370 
371 std::vector<DalitzArea> DalitzArea::split_in_all_dimensions(int n) const{
372  std::vector<DalitzArea> v;
373  if(n == 1){
374  v.push_back(*this);
375  return v;
376  }
377  if(_pat.numDaughters() == 3) return split_in_all_dim_3body(n);
378  else if(_pat.numDaughters() == 4) return split_in_all_dim_4body(n);
379  else{
380  cout << "ERROR in DalitzArea::split_in_all_dimensions"
381  << " can't handle " << _pat.numDaughters() << " body decays."
382  << "\n\t Won't split, will return original box."
383  << endl;
384  v.push_back(*this);
385  return v;
386  }
387 }
388 
389 std::vector<DalitzArea> DalitzArea::split_in_all_dim_3body(int n) const{
390  std::vector<DalitzArea> v;
391  if(n <= 1){
392  v.push_back(*this);
393  return v;
394  }
395  std::vector<DalitzCoordinate> vs12 = _s12.split(n);
396  std::vector<DalitzCoordinate> vs23 = _s23.split(n);
397 
398  for(unsigned int i12 = 0; i12 < vs12.size(); i12++){
399  for(unsigned int i23 = 0; i23 < vs23.size(); i23++){
400 
401  DalitzArea na(*this);
402  na.setCoordinate(vs12[i12]);
403  na.setCoordinate(vs23[i23]);
404 
405  v.push_back(na);
406  }
407  }
408  return v;
409 }
410 
411 std::vector<DalitzArea> DalitzArea::split_in_all_dim_4body(int n) const{
412  bool dbThis=false;
413 
414  std::vector<DalitzArea> v;
415  if(n <= 1){
416  v.push_back(*this);
417  return v;
418  }
419 
420  std::vector<DalitzCoordinate> vt01 = _t01.split(n);
421  std::vector<DalitzCoordinate> vs12 = _s12.split(n);
422  std::vector<DalitzCoordinate> vs23 = _s23.split(n);
423  std::vector<DalitzCoordinate> vs34 = _s34.split(n);
424  std::vector<DalitzCoordinate> vt40 = _t40.split(n);
425 
426  for(unsigned int i01 = 0; i01 < vt01.size(); i01++){
427  for(unsigned int i12 = 0; i12 < vs12.size(); i12++){
428  for(unsigned int i23 = 0; i23 < vs23.size(); i23++){
429  for(unsigned int i34 = 0; i34 < vs34.size(); i34++){
430  for(unsigned int i40 = 0; i40 < vt40.size(); i40++){
431 
432  DalitzArea na(*this);
433  na.setCoordinate(vt01[i01]);
434  na.setCoordinate(vs12[i12]);
435  na.setCoordinate(vs23[i23]);
436  na.setCoordinate(vs34[i34]);
437  na.setCoordinate(vt40[i40]);
438 
439  v.push_back(na);
440  }
441  }
442  }
443  }
444  }
445  if(dbThis){
446  cout << "after splitting, n = " << v.size() << endl;
447  }
448  return v;
449 }
450 
451 
452 void DalitzArea::print(std::ostream& os) const{
454  os << "Area size: " << size();
455  for(std::map<DalitzCoordKey, DalitzCoordinate*>::const_iterator
456  it =_coords.begin();
457  it != _coords.end();
458  it++){
459  os << "\n " << *(it->second);
460  }
461 }
462 
463 
464 std::ostream& operator<<(std::ostream& os, const DalitzArea& da){
465  da.print(os);
466  return os;
467 }
468 //
std::vector< DalitzArea > split_in_all_dimensions(int n=2) const
Definition: DalitzArea.cpp:371
double min() const
double sijMax(const MINT::PolymorphVector< int > &indices) const
void setPattern(const DalitzEventPattern &pat)
Definition: DalitzArea.cpp:89
std::ostream & operator<<(std::ostream &os, const DalitzArea &da)
Definition: DalitzArea.cpp:464
virtual ~DalitzArea()
Definition: DalitzArea.cpp:182
bool setRnd(TRandom *rnd=gRandom)
Definition: DalitzArea.cpp:105
void setAllLimitsToPhaseSpaceArea(double safetyFactor=1.0)
Definition: DalitzArea.cpp:165
bool isInside(const IDalitzEvent &evt) const
Definition: DalitzArea.cpp:214
virtual double phaseSpace() const
std::vector< DalitzArea > split_in_all_dim_4body(int n=2) const
Definition: DalitzArea.cpp:411
double max() const
std::vector< DalitzCoordinate > split(int n) const
double size() const
Definition: DalitzArea.cpp:251
virtual double sij(const MINT::PolymorphVector< int > &indices) const =0
MINT::counted_ptr< DalitzEvent > makeEventForOwner() const
Definition: DalitzArea.cpp:319
void makeCoordinateMap() const
Definition: DalitzArea.cpp:110
DalitzEventPattern _pat
Definition: DalitzArea.h:23
void encloseInPhaseSpaceArea(double safetyFactor=1.0)
Definition: DalitzArea.cpp:147
bool setCoordinate(const DalitzCoordinate &c)
Definition: DalitzArea.cpp:358
MINT::counted_ptr< DalitzEvent > make3Event() const
Definition: DalitzArea.cpp:328
bool compatiblePattern(const DalitzEventPattern &p) const
Definition: DalitzArea.cpp:185
std::map< DalitzCoordKey, DalitzCoordinate * > _coords
Definition: DalitzArea.h:50
double sijMin(const MINT::PolymorphVector< int > &indices) const
DalitzCoordinate _t40
Definition: DalitzArea.h:51
DalitzCoordinate _t01
Definition: DalitzArea.h:51
static const double second
virtual const DalitzEventPattern & eventPattern() const =0
DalitzCoordinate _s12
Definition: DalitzArea.h:51
bool _madeCMap
Definition: DalitzArea.h:29
unsigned int size() const
std::vector< DalitzArea > split_in_all_dim_3body(int n=2) const
Definition: DalitzArea.cpp:389
double val() const
TRandom * _rnd
Definition: DalitzArea.h:25
DalitzArea & operator=(const DalitzArea &other)
Definition: DalitzArea.cpp:49
void print(std::ostream &os=std::cout) const
Definition: DalitzArea.cpp:452
void makeMiMa()
Definition: DalitzArea.cpp:129
void setMinMax(double min, double max)
MINT::counted_ptr< DalitzEvent > make4Event() const
Definition: DalitzArea.cpp:349
DalitzCoordinate _s23
Definition: DalitzArea.h:51
DalitzCoordinate _s34
Definition: DalitzArea.h:51