MINT2
MappedDalitzBWArea.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:58 GMT
4 #include "Mint/Permutator.h"
5 #include <iostream>
6 #include <algorithm>
7 
8 using namespace std;
9 using namespace MINT;
10 /*
11  _mapping
12  'standard' Dalitz variables -----------> Dalitz variables where the
13  box-limits have consecutive
14  indices:
15  t01, s12, s23, s34, t40
16  so that I can use
17  the usual
18  Calculate4BodyProbs etc
19  <-----------
20  _inverseMapping
21 
22 */
23 
25  : _rnd(0)
26  , _pat()
27  , _mappedPat()
28  , _area()
29  , _limits()
30  , _mapping()
31  , _inverseMapping()
32 {
33  setup();
34 }
36  , TRandom* rnd)
37  : _rnd(rnd)
38  , _pat(pat)
39  , _mappedPat(pat)
40  , _area(pat)
41  , _limits()
42  , _mapping(pat.size())
43  , _inverseMapping(pat.size())
44 {
45  setup();
46 }
48  , const counted_ptr<IGenFct>& oneLimit
49  , TRandom* rnd
50  )
51  : _rnd(rnd)
52  , _pat(pat)
53  , _mappedPat(pat)
54  , _limits(1)
55  , _mapping(pat.size())
56  , _inverseMapping(pat.size())
57 {
58  _limits[0] = oneLimit;
59  setup();
60 }
62  , const counted_ptr<IGenFct>& oneLimit
63  , const counted_ptr<IGenFct>& otherLimit
64  , TRandom* rnd
65  )
66  : _rnd(rnd)
67  , _pat(pat)
68  , _mappedPat(pat)
69  , _limits(2)
70  , _mapping(pat.size())
71  , _inverseMapping(pat.size())
72 {
73  _limits[0] = oneLimit;
74  _limits[1] = otherLimit;
75  /*
76  cout << " just made a MappedDalitzBWArea with limits :"
77  << oneLimit << ", " << otherLimit << " or "
78  << _limits[0] << ", " << _limits[1] << endl;
79  */
80  setup();
81  /*
82  cout << " ..after setup: "
83  << _limits[0] << ", " << _limits[1] << endl;
84  */
85 }
86 
88  , const std::vector<counted_ptr<IGenFct> >& lim
89  , TRandom* rnd
90  )
91  : _rnd(rnd)
92  , _pat(pat)
93  , _mappedPat(pat)
94  , _limits(lim)
95  , _mapping(pat.size())
96  , _inverseMapping(pat.size())
97 {
98  setup();
99 }
100 
102  : _rnd(other._rnd)
103  , _pat(other._pat)
104  , _mappedPat(other._mappedPat)
105  , _area(other._area)
106  , _limits(other._limits)
107  , _mapping(other._mapping)
108  , _inverseMapping(other._inverseMapping)
109 {
110 }
111 
113  _rnd = other._rnd;
114  _pat = other._pat;
115  _mappedPat = other._mappedPat;
116  _area = other._area;
117  _limits = other._limits;
118  _mapping = other._mapping;
120  return *this;
121 }
122 
124 }
125 
127  for(unsigned int i=0; i < _limits.size(); i++){
128  DalitzCoordinate newCoordinates = (_limits[i])->getCoordinate().mapMe(_mapping);
129  /*
130  cout << "mapped new coordinates: "
131  << i << ": " << newCoordinates << endl;
132  */
133  if(! (newCoordinates.I_am_Consecutive())) return false;
134  }
135  return true;
136 }
137 
139  // such that only s123, s12,
140  // or s12, s34
141  // are filled (or s123, or s12 for single
142  // limits).
143  // Helps with generating later.
144 
145  if(_limits.size() > 2 || _limits.empty() ){
146  return true; // no standards for that, all OK
147  }
148  DalitzCoordinate s123(1,2,3);
149  DalitzCoordinate s12(1,2);
150  DalitzCoordinate s34(3,4);
151  if(_limits.size() == 1){
152  if(_limits[0]->getCoordinate().mapMe(_mapping).sameIndices(s123)) return true;
153  if(_limits[0]->getCoordinate().mapMe(_mapping).sameIndices(s12)) return true;
154  }
155  if(_limits.size() == 2){
156  if(_limits[0]->getCoordinate().mapMe(_mapping).sameIndices(s123)
157  && _limits[1]->getCoordinate().mapMe(_mapping).sameIndices(s12)) return true;
158  if(_limits[0]->getCoordinate().mapMe(_mapping).sameIndices(s12)
159  && _limits[1]->getCoordinate().mapMe(_mapping).sameIndices(s34)) return true;
160  if(_limits[1]->getCoordinate().mapMe(_mapping).sameIndices(s123)
161  && _limits[0]->getCoordinate().mapMe(_mapping).sameIndices(s12)) return true;
162  if(_limits[1]->getCoordinate().mapMe(_mapping).sameIndices(s12)
163  && _limits[0]->getCoordinate().mapMe(_mapping).sameIndices(s34)) return true;
164  }
165  return false;
166 }
167 
169  bool dbThis=false;
171  if(allConsecutive() && allStandardised()) return;
172 
173  DalitzEventPattern tmpPat(_pat);
174  tmpPat[0] =1;
175  for(unsigned int i=1; i< _pat.size(); i++){
176  tmpPat[i]=0;
177  }
178 
179  Permutator ptor(tmpPat);// this finds all mappings
180  // leaving the 0th particle alone (the mother) and
181  // swapping all the daughters - the pattern
182  // is set up to achieve this ('particles' 1,2,3,4,.. are identical)
183 
184  bool foundOne=false;
185  for(unsigned int i=0; i< ptor.size(); i++){
186  _mapping = ptor[i];
187  if(dbThis) cout << " trying out mapping\n " << _mapping << endl;
188  if(allConsecutive() && allStandardised()){
189  foundOne=true;
190  break;
191  }
192  }
193  if(! foundOne){
194  cout << " MappedDalitzBWArea::findMapping: WARNING!!"
195  << " didn't find a mapping!!!"
196  << endl;
197  throw "shit!";
198  }
200  for(unsigned int i=0; i < _pat.size(); i++){
201  int mappedIndex = _mapping[i];
202  if(mappedIndex < 0 || mappedIndex >= (int) _mappedPat.size()){
203  cout << "ERROR in MappedDalitzBWArea::findMapping()"
204  << "\n Index out of range: " << mappedIndex
205  << " not in [0, " << _mappedPat.size()-1
206  << endl;
207  throw "index out of range.";
208  }
209  if(dbThis) {
210  cout << " mapped index of " << i
211  << " = " << mappedIndex << endl;
212  }
213  _mappedPat[mappedIndex] = _pat[i];
214  }
215 
216  if(dbThis){
217  cout << " using the following mapping:\n "
218  << _mapping << endl;
219  cout << "_mappedPat " << _mappedPat << endl;
220  }
221  return;
222 }
223 
225  bool dbThis=false;
226  sort(_limits.begin(), _limits.end());
227 
228  findMapping();
229  if(dbThis) cout << " mappedPat " << _mappedPat << endl;
231  _area.setRnd(_rnd);
232  applyLimits();
233 }
234 
236  bool dbThis=false;
237  for(unsigned int i=0; i < _limits.size(); i++){
238  if(dbThis){
239  cout << "mapped co-ordinates "
240  << (_limits[i])->getCoordinate().mapMe(_mapping)
241  << endl;
242  }
243  _area.setFcn((_limits[i])->getCoordinate().mapMe(_mapping), _limits[i]);
244  }
245 }
246 
247 /*
248 vector<TLorentzVector> MappedDalitzBWArea::mapP4(const DalitzEvent& evt
249  , const Permutation& mapping
250  ){
251  vector<TLorentzVector> p4(evt.eventPattern().size());
252  return mapP4(evt, mapping, p4);
253 }
254 
255 std::vector<TLorentzVector>&
256 MappedDalitzBWArea::mapP4(const DalitzEvent& evt
257  , const Permutation& mapping
258  , std::vector<TLorentzVector>& p4
259  ){
260 
261  unsigned int n = evt.eventPattern().size();
262  p4.resize(n);
263 
264  for(unsigned int i=0; i < n; i++){
265  int mappedIndex = mapping[i];
266  if(mappedIndex < 0 || mappedIndex + 1 > (int) n){
267  cout << "ERROR in MappedDalitzBWArea::mapP4()"
268  << "\n Index out of range: " << mappedIndex
269  << " not in [0, " << n-1
270  << endl;
271  throw "index out of range.";
272  }
273  p4[mappedIndex] = evt.p(i);
274  }
275  return p4;
276 }
277 */
279  bool dbThis=false;
280  if(dbThis){
281  cout << "Hello from MappedDalitzBWArea::tryEventForOwner()"
282  << endl;
283  }
285 
286  /*
287  if(dbThis && 0 != evt){
288  counted_ptr<DalitzEvent> mappedEvt( _area.tryEventForOwner());
289  if(0 == mappedEvt){
290  return mappedEvt;
291  }
292  static vector<TLorentzVector> p4;
293  mapP4( *mappedEvt, _inverseMapping, p4);
294 
295  counted_ptr<DalitzEvent> evtCheck(new DalitzEvent(_pat, p4));
296  evtCheck->setWeight(mappedEvt->getWeight());
297 
298  cout << "compare new, old event and weight: "
299  << "\n\t new: " << *evt
300  << "\n\t old: " << *evtCheck
301  << endl;
302  }
303  */
304  return evt;
305 }
306 
307 double MappedDalitzBWArea::genValue(const DalitzEvent& evt) const{
308  bool dbThis=false;
309 
310  double returnVal = _area.genValue(&evt, _inverseMapping);
311  if(dbThis){
312  vector<TLorentzVector> p4 = mapP4(evt, _mapping );
313  DalitzEvent mappedEvt(_mappedPat, p4);
314  isInside(evt);
315  cout << " mapping: " << _mapping << endl;
316  cout << "old style: " << _area.genValue(&mappedEvt)
317  << "\n new style: " << _area.genValue(&evt, _inverseMapping)
318  << "\n MappedDalitzBWArea::genValue returning " << returnVal << endl;
319  }
320  return returnVal;
321 }
322 
324  bool dbThis=false;
325 
326  if(dbThis){
327  vector<TLorentzVector> p4 =
328  mapP4(evt, _mapping );
329  DalitzEvent mappedEvt(_mappedPat, p4);
330  cout << " old style: " << _area.isInside(mappedEvt);
331  cout << " new style: " << _area.isInside(evt, _inverseMapping);
332  }
333  return _area.isInside(evt, _inverseMapping);
334 }
335 
337  return _area.isInside(dc.mapMe(_mapping));
338 }
339 bool MappedDalitzBWArea::isInside(const std::vector<DalitzCoordinate>& dcList) const{
340  // cout << " inside this: " << *this << endl;
341  for(unsigned int i=0; i < dcList.size(); i++){
342  if(! isInside(dcList[i])){
343  // cout << "Not inside: " << dcList[i]
344  // << "\n\tmapped: " << dcList[i].mapMe(_mapping)
345  // << endl;
346  return false;
347  }
348  }
349  return true;
350 
351 }
352 
353 void MappedDalitzBWArea::print(std::ostream& os) const{
354  os << " MappedDalitzBWArea "
355  << " limits: ";
356  for(unsigned int i=0; i < _limits.size(); i++){
357  if(0 == _limits[i]){
358  os << "\n ZERO-PTR LIMIT!" << endl;
359  }else{
360  os << "\n " << (_limits[i])->getCoordinate() << endl;
361  }
362  }
363 
364  os << "\n Mapping:\n " << _mapping
365  << "\n area: " << _area;
366 }
367 
368 bool MappedDalitzBWArea::setRnd(TRandom* rnd){
369  _rnd = rnd;
370  _area.setRnd(_rnd);
371  return true;
372 }
373 std::ostream& operator<<(std::ostream& os, const MappedDalitzBWArea& mda){
374  mda.print(os);
375  return os;
376 }
377 //
bool I_am_Consecutive() const
DalitzEventPattern _pat
bool setRnd(TRandom *rnd=gRandom)
std::ostream & operator<<(std::ostream &os, const MappedDalitzBWArea &mda)
MINT::counted_ptr< DalitzEvent > tryEventForOwner(const Permutation &mapping=Permutation::unity()) const
std::vector< TLorentzVector > & mapP4(const DalitzEvent &evt, const Permutation &mapping, std::vector< TLorentzVector > &p4) const
MINT::counted_ptr< DalitzEvent > tryEventForOwner() const
bool setRnd(TRandom *rnd=gRandom)
void setFcn(const DalitzCoordinate &c, const MINT::counted_ptr< IGenFct > &fcn)
DalitzEventPattern _mappedPat
std::vector< MINT::counted_ptr< IGenFct > > _limits
void makeUnity()
Definition: Permutation.cpp:42
bool isInside(const DalitzEvent &evt) const
DalitzCoordinate mapMe(const Permutation &perm) const
double genValue(const IDalitzEvent *evtPtr) const
unsigned int size() const
Permutation _inverseMapping
void setPattern(const DalitzEventPattern &pat)
MappedDalitzBWArea & operator=(const MappedDalitzBWArea &other)
bool isInside(const DalitzEvent &evt) const
double genValue(const DalitzEvent &evt) const
void print(std::ostream &os=std::cout) const
Permutation getInverse() const
Definition: Permutation.cpp:84