41 if(db) cout <<
" called getVal() " << endl;
43 if(db) cout <<
" got event Ptr " << evtPtr << endl;
44 if(0 == evtPtr)
return 0;
47 if(db) cout <<
" evtPtr->print() ";
48 if(db)evtPtr->print();
49 if(db) cout <<
" that worked " << endl;
51 if(db) cout <<
" got val " << val << endl;
52 if(db) cout <<
" returning " << -val << endl;
77 : _max_s0(-1), _max_s1(-1), _max_s2(-1), _max_s3(-1), _max_s4(-1)
78 , _maxPhaseSpace(-9999)
91 , _guessedHeight(-9999)
100 : _max_s0(-1), _max_s1(-1), _max_s2(-1), _max_s3(-1), _max_s4(-1)
101 , _maxPhaseSpace(-9999)
112 , _nEventsForTries(0)
114 , _guessedHeight(-9999)
125 : _max_s0(-1), _max_s1(-1), _max_s2(-1), _max_s3(-1), _max_s4(-1)
126 , _maxPhaseSpace(-9999)
130 , _area(pat, limit, rnd)
137 , _nEventsForTries(0)
139 , _guessedHeight(-9999)
147 ,
const std::vector<DalitzCoordinate>& limits
150 : _max_s0(-1), _max_s1(-1), _max_s2(-1), _max_s3(-1), _max_s4(-1)
151 , _maxPhaseSpace(-9999)
155 , _area(pat, limits, rnd)
162 , _nEventsForTries(0)
164 , _guessedHeight(-9999)
172 : _max_s0(other._max_s0)
173 , _max_s1(other._max_s1)
174 , _max_s2(other._max_s2)
175 , _max_s3(other._max_s3)
176 , _max_s4(other._max_s4)
177 , _maxPhaseSpace(other._maxPhaseSpace)
178 , _number(other._number)
180 , _ready(other._ready)
185 , _height(other._height)
186 , _eventList(other._eventList)
187 , _nTries(other._nTries)
188 , _nEventsForTries(other._nEventsForTries)
189 , _daddy(other._daddy)
190 , _guessedHeight(other._guessedHeight)
191 , _heightProblems(other._heightProblems)
192 , _flatPhaseSpace(other._flatPhaseSpace)
202 if(0 ==
_amps)
return false;
233 if(0 ==
_daddy)
return false;
242 cout <<
"making " << N <<
" flat event" << endl;
244 int guessedWasteFactor = 110*5;
245 if(
fastTest) guessedWasteFactor = 150;
247 for(
int i=0; i< N*guessedWasteFactor; i++){
250 if(printdbg) cout <<
" nTries " <<
_nTries << endl;
253 if(printdbg) cout <<
" made event" << endl;
256 if(printdbg)cout <<
" area OK " << endl;
258 if(printdbg)cout <<
" added event" << endl;
260 if(++counter >= N)
break;
271 if(0 ==
_amps)
return 1;
272 if(dbThis) cout <<
" the event: " << endl;
273 if(dbThis) evt.
print();
274 if(dbThis) cout <<
" ... now getting RealVal() " << endl;
276 if(dbThis) cout <<
" all done, returning " << val << endl;
288 double a =
amps(evt_in);
289 if(dbThis) cout <<
"amps " << a << endl;
291 if(dbThis) cout <<
"ps " << ps << endl;
394 mini.Command(
"Simplex 10000000");
395 mini.Command(
"MIGRAD");
397 double safetyMargin = 0;
402 cout <<
" setting height to " <<
_height << endl;
409 int maxEvents = 100000;
410 int maxTries = 10000000;
411 double meanPhaseSpaceSum = 0;
428 cout <<
"DalitzBox::estimateHeight" << endl;
433 int numEvents=0, counter=0;
434 while(numEvents < maxEvents && counter < maxTries){
436 double tmp_s0 =
_rnd->Rndm();
437 double tmp_s1 =
_rnd->Rndm();
438 double tmp_s2 =
_rnd->Rndm();
439 double tmp_s3 =
_rnd->Rndm();
440 double tmp_s4 =
_rnd->Rndm();
442 if(0 == tmpEvtPtr)
continue;
443 if(dbThis) cout <<
"estimate height got event " 444 <<
" printing it: " << endl;
445 if(dbThis) cout << *tmpEvtPtr << endl;
466 meanPhaseSpaceSum += p;
472 double meanPhaseSpace = meanPhaseSpaceSum/((double)numEvents);
473 cout <<
"mean phase space " << meanPhaseSpace
478 double CL = 1.0 - 1.e-7;
479 std::cout <<
"actual max = " << max << std::endl;
483 <<
" events. Taking 5*max = 5*" << max
485 <<
" and return false." << endl;
490 double actualMax=-1, paretoMax=-1;
498 std::cout <<
" Pareto max " << paretoMax << std::endl;
511 cout <<
"compare to guessed height: " 515 if(fabs( (paretoMax - actualMax)/actualMax) > 0.3 ){
524 double saveFactor = 2.0;
526 cout <<
"DalitzBox::estimateHeight" << endl;
536 time_t startTime = time(0);
538 unsigned int counter=0;
546 double maxPhaseSpace = -9999;
551 if(p > maxPhaseSpace || 0 == counter){
556 if(d > max || 0 == counter){
562 std::cout <<
" calculated amps for event " 564 <<
", its value is " << d
566 double deltaT = difftime(time(0), startTime);
567 std::cout <<
" this took " << deltaT <<
" s";
569 std::cout <<
"; rate (before throwing away) = " 573 std::cout << std::endl;
577 cout <<
" max phase space: " << maxPhaseSpace << endl;
579 double epsilon = 0.25;
582 std::cout <<
"actual max = " << max << std::endl;
586 <<
" events. Taking 5*max = 5*" << max
588 <<
" and return false." << endl;
593 double actualMax=-1, paretoMax=-1;
601 std::cout <<
" Pareto max " << paretoMax << std::endl;
602 max *= 1.0 + epsilon;
603 std::cout <<
"Now added " << epsilon * 100 <<
"% for safety " 608 std::cout <<
"and multiplied by safety factor " 612 cout <<
"compare to guessed height: " 616 if(fabs( (paretoMax - actualMax)/actualMax) > 0.3 ){
624 double safetyFactor = 2.5;
626 time_t startTime = time(0);
627 cout <<
"making starter set" << endl;
629 int NperLoop = 20000;
641 bool successfulHeightEstimate =
false;
642 std::vector<double> vals;
645 double prevHeight = -0.1;
646 double heightErrorEstimate = 0.1;
649 bool doMinuitHeight=
false;
655 = fabs(prevHeight -
_height)/( 0.5*(fabs(prevHeight) + fabs(
_height) ));
663 successfulHeightEstimate &= heightErrorEstimate < 0.25;
667 double deltaT = difftime(time(0), startTime);
668 cout <<
" making " << counter
669 <<
" " << NperLoop <<
"-events starter set(s)" 670 <<
" took " << deltaT/60 <<
" min" << endl;
671 cout <<
" current heightErrorEstimate: " << heightErrorEstimate << endl;
675 }
while(counter < maxLoop
676 && (! successfulHeightEstimate)
679 cout <<
" DONE \"old\" height guess, now MINUIT " << endl;
681 double search_height =
_height;
682 double minuit_height = -1;
689 _height = ( search_height > minuit_height ? search_height : minuit_height);
692 cout <<
"Different Heights:" 693 <<
"\n\t search_height " << search_height
694 <<
"\n\t minuit_height " << minuit_height
696 <<
"\n\t chosen height " <<
_height 699 if(! successfulHeightEstimate){
700 cout <<
"DalitzBox::makeStarterSet " 701 <<
"WARNING - no reliable estimate of box-height" 703 cout <<
" I'll multiply it by " << 1.0 + 2*heightErrorEstimate
704 <<
", and continue..." << endl;
707 cout <<
"DalitzBox::makeStarterSet " 708 <<
"I think I found a reliable Height Estimate of " 718 cout <<
" appliying safety factor of " << safetyFactor << endl;
720 cout <<
"final height " <<
_height << endl;
729 time_t startTime = time(0);
732 cout <<
" ERROR in DalitzBox::throwAwayData: " 733 <<
" vals.size()=" << vals.size()
734 <<
", but _eventList.size()=" 737 throw "this is bad.";
744 unsigned int counter=0;
756 std::cout <<
" remembering amps for event " 758 <<
", its value is " << d
767 std::cout <<
" So the waste factor for \n" << this->
name() <<
" is ";
769 else std::cout <<
" infinity! - that's big!";
770 std::cout << std::endl;
773 double deltaTFinal = difftime(time(0), startTime);
774 std::cout <<
" this took " << deltaTFinal/60.0 <<
" min";
776 std::cout <<
" rate = " << (
_eventList.
size()/deltaTFinal) <<
" evts/s" 781 std::cout << std::endl;
783 std::cout <<
" ---------------\n " << std::endl;
790 cout <<
" volume: returning area " << a
797 time_t startTime = time(0);
799 cout <<
" DalitzBox::getReady() " << *
this << endl;
808 double deltaT = difftime(time(0), startTime);
809 cout <<
" DalitzBox::getRead(): am ready. This took " 810 << deltaT/60 <<
" min" << endl;
853 cout <<
"ERROR in DalitzBox::tryNewEvent()\n" << (*this)
854 <<
"\n val > _height: " << val <<
" > " <<
_height 855 <<
"\n (for phase space = " << evt->
phaseSpace() <<
")." 856 <<
"\n if _height had been correctly estimated," 857 <<
" this should not be possible." << endl;
859 <<
" times in this box " << endl;
878 if(dbThis)cout <<
" DalitzBox::tryWeightedEventForOwner() " 879 <<
" got event with ptr " 881 <<
", setting val: " << endl;
882 if(dbThis)cout <<
" now printing event: " 886 if(dbThis)cout <<
" val = " << val <<
", now setting weight " << endl;
888 if(dbThis)cout <<
" done weight, now generator..." << endl;
890 if(dbThis)cout <<
" all OK, returning " << evt << endl;
919 std::vector<MappedDalitzArea> areaList(
_area.
split(nWays));
921 std::vector<DalitzBox> newSet;
922 if(areaList.empty())
return newSet;
924 for(
unsigned int i=0; i < areaList.size(); i++){
926 newBox.
area() = areaList[i];
933 newSet.push_back(newBox);
935 if(
false && (! foundCtr)){
936 cout <<
"ERROR split box " << *
this <<
" " << nWays <<
" ways," 937 <<
" but center: is gone." << endl;
938 cout <<
"newSet\n: " << newSet << endl;
947 std::vector<DalitzBox> newSet;
948 if(areaList.empty())
return newSet;
949 for(
unsigned int i=0; i < areaList.size(); i++){
951 newBox.
area() = areaList[i];
956 newSet.push_back(newBox);
962 os <<
"DalitzBox: " <<
name() <<
" number " <<
number()
963 <<
"\n area " <<
area()
965 <<
"\n height " <<
height()
double amps(IDalitzEvent &ep)
virtual bool Add(const EVENT_TYPE &evt)
virtual void setWeight(double w)
void resize(unsigned int N)
double ampsWithPhaseSpace(IDalitzEvent &ep)
void print(std::ostream &os=std::cout) const
virtual double phaseSpace() const =0
virtual double phaseSpace() const
double generalisedPareto_estimateMaximum(const std::vector< double > &input, double CL=0.001)
virtual double RealVal(EVENT_TYPE &evt)=0
virtual void print(std::ostream &os=std::cout) const =0
std::vector< MappedDalitzArea > split(unsigned int nWays) const
std::vector< MappedDalitzArea > splitIfWiderThan(double maxWidth) const
bool estimateHeight(std::vector< double > &vals)
void setGuessedHeight(double h)
MINT::counted_ptr< DalitzEvent > tryWeightedEventForOwner()
DalitzEventList _eventList
double phaseSpace(IDalitzEvent &ep)
bool estimateHeight_old(std::vector< double > &vals)
bool insideArea(const DalitzEvent &evt) const
bool setRnd(TRandom *rnd=gRandom)
double guessedHeight() const
MINT::counted_ptr< DalitzEvent > makeEventForOwner() const
const std::string & name() const
MINT::IReturnRealForEvent< IDalitzEvent > * _amps
const MappedDalitzArea & area() const
double getEventsPdf(DalitzEvent &evt)
std::vector< DalitzBox > splitIfWiderThan(double maxWidth) const
int throwAwayData(const std::vector< double > &vals)
bool setRnd(TRandom *rnd=gRandom)
virtual unsigned int size() const
FindMaxFCN(FitParameter &s0, FitParameter &s1, FitParameter &s2, FitParameter &s3, FitParameter &s4, DalitzBox *box, MinuitParameterSet *mps)
ostream & operator<<(ostream &os, const DalitzBox &box)
MINT::counted_ptr< DalitzEvent > tryNewEvent()
int makeFlatEventsKeepAll(int N)
MINT::counted_ptr< DalitzEvent > popEventFromList()
virtual void setGeneratorPdfRelativeToPhaseSpace(double gpdf)
unsigned int _heightProblems
bool estimateHeightMinuit()
bool isInside(const DalitzEvent &evt) const
MINT::counted_ptr< DalitzEvent > tryEventForOwner()
bool insideMyOrDaddysArea(const DalitzEvent &evt) const
std::vector< DalitzBox > split(unsigned int nWays) const
MINT::counted_ptr< DalitzEvent > tryEventFromList()
bool setAmps(MINT::IReturnRealForEvent< IDalitzEvent > *amps)
void setDaddy(const DalitzBox *daddy)
bool insideDaddysArea(const DalitzEvent &evt) const