MINT2
MappedDalitzArea.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 "Mint/Permutator.h"
5 #include <iostream>
6 #include <algorithm>
7 
8 using namespace std;
9 using namespace MINT;
10 
11 /*
12  _mapping
13  'standard' Dalitz variables -----------> Dalitz variables where the
14  box-limits have consecutive
15  indices:
16  t01, s12, s23, s34, t40
17  so that I can use
18  the usual
19  Calculate4BodyProbs etc
20  <-----------
21  _inverseMapping
22 
23 */
24 
26  : _rnd(0)
27  , _pat()
28  , _mappedPat()
29  , _area()
30  , _limits()
31  , _mapping()
32  , _inverseMapping()
33 {
34  setup();
35 }
37  , TRandom* rnd)
38  : _rnd(rnd)
39  , _pat(pat)
40  , _mappedPat(pat)
41  , _area(pat)
42  , _limits()
43  , _mapping(pat.size())
44  , _inverseMapping(pat.size())
45 {
46  setup();
47 }
49  , const DalitzCoordinate& oneLimit
50  , TRandom* rnd
51  )
52  : _rnd(rnd)
53  , _pat(pat)
54  , _mappedPat(pat)
55  , _limits(1)
56  , _mapping(pat.size())
57  , _inverseMapping(pat.size())
58 {
59  _limits[0] = oneLimit;
60  setup();
61 }
63  , const DalitzCoordinate& oneLimit
64  , const DalitzCoordinate& otherLimit
65  , TRandom* rnd
66  )
67  : _rnd(rnd)
68  , _pat(pat)
69  , _mappedPat(pat)
70  , _limits(2)
71  , _mapping(pat.size())
72  , _inverseMapping(pat.size())
73 {
74  _limits[0] = oneLimit;
75  _limits[1] = otherLimit;
76  /*
77  cout << " just made a MappedDalitzArea with limits :"
78  << oneLimit << ", " << otherLimit << " or "
79  << _limits[0] << ", " << _limits[1] << endl;
80  */
81  setup();
82  /*
83  cout << " ..after setup: "
84  << _limits[0] << ", " << _limits[1] << endl;
85  */
86 }
87 
89  , const std::vector<DalitzCoordinate>& lim
90  , TRandom* rnd
91  )
92  : _rnd(rnd)
93  , _pat(pat)
94  , _mappedPat(pat)
95  , _limits(lim)
96  , _mapping(pat.size())
97  , _inverseMapping(pat.size())
98 {
99  setup();
100 }
101 
103  : _rnd(other._rnd)
104  , _pat(other._pat)
105  , _mappedPat(other._mappedPat)
106  , _area(other._area)
107  , _limits(other._limits)
108  , _mapping(other._mapping)
109  , _inverseMapping(other._inverseMapping)
110 {
111 }
112 
114  _rnd = other._rnd;
115  _pat = other._pat;
116  _mappedPat = other._mappedPat;
117  _area = other._area;
118  _limits = other._limits;
119  _mapping = other._mapping;
121  return *this;
122 }
123 
125 }
126 
128  for(unsigned int i=0; i < _limits.size(); i++){
129  DalitzCoordinate newCoordinates = (_limits[i]).mapMe(_mapping);
130  /*
131  cout << "mapped new coordinates: "
132  << i << ": " << newCoordinates << endl;
133  */
134  if(! (newCoordinates.I_am_Consecutive())) return false;
135  }
136  return true;
137 }
138 
141  if(allConsecutive()) return;
142 
143  DalitzEventPattern tmpPat(_pat);
144  tmpPat[0] =1;
145  for(unsigned int i=1; i< _pat.size(); i++){
146  tmpPat[i]=0;
147  }
148 
149  Permutator ptor(tmpPat);// this finds all mappings
150  // leaving the 0th particle alone (the mother) and
151  // swapping all the daughters - the pattern
152  // is set up to achieve this ('particles' 1,2,3,4,.. are identical)
153 
154  for(unsigned int i=0; i< ptor.size(); i++){
155  _mapping = ptor[i];
156  cout << " trying out mapping\n " << _mapping << endl;
157  if(allConsecutive()){
158  break;
159  }
160  }
162  for(unsigned int i=0; i < _pat.size(); i++){
163  int mappedIndex = _mapping[i];
164  if(mappedIndex < 0 || mappedIndex >= (int) _mappedPat.size()){
165  cout << "ERROR in MappedDalitzArea::findMapping()"
166  << "\n Index out of range: " << mappedIndex
167  << " not in [0, " << _mappedPat.size()-1
168  << endl;
169  throw "index out of range.";
170  }
171  cout << " mapped index of " << i << " = " << mappedIndex << endl;
172  _mappedPat[mappedIndex] = _pat[i];
173  }
174 
175  cout << " using the following mapping:\n "
176  << _mapping << endl;
177  cout << "_mappedPat " << _mappedPat << endl;
178 }
179 
181  sort(_limits.begin(), _limits.end());
182 
183  findMapping();
184  cout << " mappedPat " << _mappedPat << endl;
186  _area.setRnd(_rnd);
187  applyLimits();
188 }
189 
191 
192  for(unsigned int i=0; i < _limits.size(); i++){
193  cout << "mapped co-ordinates " << _limits[i].mapMe(_mapping) << endl;
194  _area.setCoordinate(_limits[i].mapMe(_mapping));
195  }
197 }
198 
199 vector<TLorentzVector> MappedDalitzArea::mapP4(const DalitzEvent& evt
200  , const Permutation& mapping
201  ){
202  vector<TLorentzVector> p4(evt.eventPattern().size());
203  return mapP4(evt, mapping, p4);
204 }
205 
206 vector<TLorentzVector>& MappedDalitzArea::mapP4(const DalitzEvent& evt
207  , const Permutation& mapping
208  , vector<TLorentzVector>& p4
209  ){
210 
211  unsigned int n = evt.eventPattern().size();
212  p4.resize(n);
213 
214  for(unsigned int i=0; i < n; i++){
215  int mappedIndex = mapping[i];
216  if(mappedIndex < 0 || mappedIndex + 1 > (int) n){
217  cout << "ERROR in MappedDalitzArea::mapP4()"
218  << "\n Index out of range: " << mappedIndex
219  << " not in [0, " << n-1
220  << endl;
221  throw "index out of range.";
222  }
223  p4[mappedIndex] = evt.p(i);
224  }
225  return p4;
226 }
227 
230  if(0 == mappedEvt){
231  return mappedEvt;
232  }
233  static vector<TLorentzVector> p4;
234  mapP4( *mappedEvt, _inverseMapping, p4 );
235 
237  return evt;
238 }
239 
240 std::vector<DalitzCoordinate> MappedDalitzArea::centre() const{
241  std::vector<DalitzCoordinate> c(_limits);
242  for(unsigned int i=0; i < c.size(); i++){
243  c[i].setVal(0.5*(c[i].min() + c[i].max()));
244  }
245  return c;
246 }
248  , double scale1
249  , double scale2
250  , double scale3
251  , double scale4
252  ) const{
254  , scale1
255  , scale2
256  , scale3
257  , scale4
258  )
259  );
260  if(0 == mappedEvt){
261  return mappedEvt;
262  }
263  vector<TLorentzVector> p4 =
264  mapP4( *mappedEvt, _inverseMapping );
265 
267  return evt;
268 }
269 
271 
272  vector<TLorentzVector> p4 =
273  mapP4(evt, _mapping );
274 
275  DalitzEvent mappedEvt(_mappedPat, p4);
276  return _area.isInside(mappedEvt);
277 }
278 
280  return _area.isInside(dc.mapMe(_mapping));
281 }
282 bool MappedDalitzArea::isInside(const std::vector<DalitzCoordinate>& dcList) const{
283  // cout << " inside this: " << *this << endl;
284  for(unsigned int i=0; i < dcList.size(); i++){
285  if(! isInside(dcList[i])){
286  // cout << "Not inside: " << dcList[i]
287  // << "\n\tmapped: " << dcList[i].mapMe(_mapping)
288  // << endl;
289  return false;
290  }
291  }
292  return true;
293 
294 }
295 
296 
297 std::vector<MappedDalitzArea>
298 MappedDalitzArea::split(unsigned LimitIndex, unsigned int n) const{
299 
300  std::vector<MappedDalitzArea> newList;
301  if(n <=0 || LimitIndex >= _limits.size()){
302  newList.push_back(*this);
303  return newList;
304  }
305 
306  std::vector<DalitzCoordinate> splitLimits(_limits[LimitIndex].split(n));
307  for(unsigned int i=0; i< splitLimits.size(); i++){
308  MappedDalitzArea newArea(*this);
309  newArea._limits[LimitIndex] = splitLimits[i];
310  newArea.applyLimits();
311  newList.push_back(newArea);
312  }
313 
314  return newList;
315 }
316 
317 std::vector<MappedDalitzArea>
318 MappedDalitzArea::split(unsigned int n) const{
319  std::vector<MappedDalitzArea> returnList;
320  if(n ==0 ) return returnList;
321 
322  std::vector<MappedDalitzArea> newList;
323  returnList.push_back(*this);
324  for(unsigned int limitIndex=0; limitIndex< _limits.size(); limitIndex++){
325  std::vector<MappedDalitzArea> thisIterationsList;
326  for(unsigned int j=0; j < returnList.size(); j++){
327  std::vector<MappedDalitzArea> tempList =
328  returnList[j].split(limitIndex, n);
329  thisIterationsList.insert(thisIterationsList.end()
330  , tempList.begin(), tempList.end()
331  );
332  }
333  returnList = thisIterationsList;
334  }
335 
336  return returnList;
337 }
338 
339 std::vector<MappedDalitzArea>
340 MappedDalitzArea::splitIfWiderThan(unsigned LimitIndex, double maxWidth) const{
341 
342  std::vector<MappedDalitzArea> newList;
343  if(maxWidth <=0) return newList;
344  if(LimitIndex >= _limits.size()) return newList;
345 
346  double width = 0.5*(_limits[LimitIndex].max() - _limits[LimitIndex].min());
347  // width in the sigma sense
348 
349  cout << " MappedDalitzArea::splitIfWiderThan: splitting "
350  << _limits[LimitIndex]
351  << " into...";
352  unsigned int n = 2*((unsigned int) fabs(width/maxWidth)) + 1;
353  cout << n << " pieces." << endl;
354 
355  std::vector<DalitzCoordinate> splitLimits(_limits[LimitIndex].split(n));
356  for(unsigned int i=0; i< splitLimits.size(); i++){
357  MappedDalitzArea newArea(*this);
358  newArea._limits[LimitIndex] = splitLimits[i];
359  newArea.applyLimits();
360  newList.push_back(newArea);
361  }
362 
363  return newList;
364 }
365 
366 std::vector<MappedDalitzArea>
367 MappedDalitzArea::splitIfWiderThan(double maxWidth) const{
368  std::vector<MappedDalitzArea> returnList;
369  if(maxWidth <= 0 ) return returnList;
370 
371  std::vector<MappedDalitzArea> newList;
372  returnList.push_back(*this);
373  for(unsigned int limitIndex=0; limitIndex< _limits.size(); limitIndex++){
374  std::vector<MappedDalitzArea> thisIterationsList;
375  for(unsigned int j=0; j < returnList.size(); j++){
376  std::vector<MappedDalitzArea> tempList =
377  returnList[j].splitIfWiderThan(limitIndex, maxWidth);
378  thisIterationsList.insert(thisIterationsList.end()
379  , tempList.begin(), tempList.end()
380  );
381  }
382  returnList = thisIterationsList;
383  }
384 
385  return returnList;
386 }
387 
388 DalitzCoordinate MappedDalitzArea::limit_s(const std::vector<int>& indices) const{
389  DalitzCoordinate dc(indices);
390 
391  for(unsigned int i=0; i < _limits.size(); i++){
392  if(_limits[i].size() != dc.size()) continue;
393  for(unsigned int j=0; j < dc.size(); j++){
394  if(_limits[i][j] != dc[j]){
395  continue;
396  }
397  }
398  return _limits[i];
399  }
400  return dc;
401 }
402 DalitzCoordinate MappedDalitzArea::limit_s(int i, int j, int k) const{
403  std::vector<int> v;
404  v.push_back(i);
405  v.push_back(j);
406  if(k >=0)v.push_back(k);
407  return limit_s(v);
408 }
409 
411  // doesn't work, don't know why.
412  if(_limits.size() != rhs._limits.size()) return false;
413  double epsilon = 1.e-4;
414  for(unsigned int i=0; i < _limits.size(); i++){
415  if(_limits[i].size() != rhs._limits[i].size()) return false;
416  for(unsigned int j=0; j < _limits[i].size(); j++){
417  if( (_limits[i])[j] != (rhs._limits[i])[j]) return false;
418  }
419 
420  if( (_limits[i].min() - rhs._limits[i].min())
421  > epsilon * (_limits[i].min() + rhs._limits[i].min())
422  ) return false;
423  if( (_limits[i].max() - rhs._limits[i].max())
424  > epsilon * (_limits[i].max() + rhs._limits[i].max())
425  ) return false;
426  }
427  return true;
428 }
429 
431  if(_limits.size() < rhs._limits.size()) return true;
432  if(_limits.size() > rhs._limits.size()) return false;
433 
434  for(unsigned int i=0; i < _limits.size(); i++){
435  if(_limits[i].size() < rhs._limits[i].size()) return true;
436  if(_limits[i].size() > rhs._limits[i].size()) return false;
437  for(unsigned int j=0; j < _limits[i].size(); j++){
438  if( (_limits[i])[j] < (rhs._limits[i])[j]) return true;
439  if( (_limits[i])[j] > (rhs._limits[i])[j]) return false;
440  }
441 
442  if( (_limits[i].min() < rhs._limits[i].min()) ) return true;
443  if( (_limits[i].min() > rhs._limits[i].min()) ) return false;
444 
445  if( (_limits[i].max() < rhs._limits[i].max()) ) return true;
446  if( (_limits[i].max() > rhs._limits[i].max()) ) return false;
447  }
448  return false;
449 }
450 
452  return this->less(rhs);
453 }
455  return (this->less(rhs) || (*this) == rhs);
456 }
458  return ! ((*this) < rhs || (*this) == rhs);
459 }
461  return ! ((*this) < rhs);
462 }
463 
465  if(_limits.size() != rhs._limits.size()) return false;
466  for(unsigned int i=0; i < _limits.size(); i++){
467  if(_limits[i] != rhs._limits[i]) return false;
468  }
469  return true;
470 }
471 
473  return ! ( (*this) == rhs);
474 }
475 
476 
477 void MappedDalitzArea::print(std::ostream& os) const{
478  os << " MappedDalitzArea "
479  << " limits: ";
480  for(unsigned int i=0; i < _limits.size(); i++){
481  os << "\n " << _limits[i] << endl;
482  }
483 
484  os << "\n Mapping:\n " << _mapping
485  << "\n area: " << _area;
486 }
487 
488 bool MappedDalitzArea::setRnd(TRandom* rnd){
489  _rnd = rnd;
490  _area.setRnd(rnd);
491  return true;
492 }
493 std::ostream& operator<<(std::ostream& os, const MappedDalitzArea& mda){
494  mda.print(os);
495  return os;
496 }
497 //
bool operator<=(const MappedDalitzArea &rhs) const
void setPattern(const DalitzEventPattern &pat)
Definition: DalitzArea.cpp:89
static std::vector< TLorentzVector > mapP4(const DalitzEvent &evt, const Permutation &mapping)
bool I_am_Consecutive() const
bool operator<(const MappedDalitzArea &rhs) const
void push_back(const T &c)
bool setRnd(TRandom *rnd=gRandom)
Definition: DalitzArea.cpp:105
bool isInside(const IDalitzEvent &evt) const
Definition: DalitzArea.cpp:214
virtual const DalitzEventPattern & eventPattern() const
Definition: DalitzEvent.h:173
bool operator>(const MappedDalitzArea &rhs) const
bool operator>=(const MappedDalitzArea &rhs) const
std::vector< DalitzCoordinate > _limits
std::vector< MappedDalitzArea > split(unsigned int nWays) const
MINT::counted_ptr< DalitzEvent > makeEventForOwner() const
Definition: DalitzArea.cpp:319
std::vector< MappedDalitzArea > splitIfWiderThan(double maxWidth) const
DalitzEventPattern _pat
bool allConsecutive() const
void encloseInPhaseSpaceArea(double safetyFactor=1.0)
Definition: DalitzArea.cpp:147
bool setCoordinate(const DalitzCoordinate &c)
Definition: DalitzArea.cpp:358
DalitzEventPattern _mappedPat
std::ostream & operator<<(std::ostream &os, const MappedDalitzArea &mda)
void makeUnity()
Definition: Permutation.cpp:42
MINT::counted_ptr< DalitzEvent > makeEventForOwner() const
std::vector< DalitzCoordinate > centre() const
DalitzCoordinate mapMe(const Permutation &perm) const
bool operator==(const MappedDalitzArea &ma) const
bool similar(const MappedDalitzArea &ma) const
virtual const TLorentzVector & p(unsigned int i) const
MappedDalitzArea & operator=(const MappedDalitzArea &other)
bool setRnd(TRandom *rnd=gRandom)
unsigned int size() const
bool operator!=(const MappedDalitzArea &ma) const
bool less(const MappedDalitzArea &ma) const
double size() const
bool isInside(const DalitzEvent &evt) const
Permutation _mapping
DalitzCoordinate limit_s(const std::vector< int > &indices) const
Permutation _inverseMapping
void print(std::ostream &os=std::cout) const
Permutation getInverse() const
Definition: Permutation.cpp:84