25 , _maxWeightEstimate(-9999.0)
26 , _maxWeightInSample(-9999.0)
32 , _phaseSpaceIntegral(-9999)
34 , _pick_ps_prob(-9999)
38 , _maxWeightEstimate(-9999.0)
39 , _maxWeightInSample(-9999.0)
45 , _phaseSpaceIntegral(-9999)
47 , _pick_ps_prob(-9999)
54 , _eventPtrList(other._eventPtrList)
55 , _maxWeightEstimate(other._maxWeightEstimate)
56 , _maxWeightInSample(other._maxWeightInSample)
57 , _ampSum(other._ampSum)
58 , _ready(other._ready)
59 , _volumeProbs(other._volumeProbs)
61 , _phaseSpaceFrac(other._phaseSpaceFrac)
62 , _phaseSpaceIntegral(other._phaseSpaceIntegral)
63 , _psbox(other._psbox)
64 , _pick_ps_prob(other._pick_ps_prob)
69 if(dbThis) cout <<
"DalitzBWBoxSet::fullPdf called" << endl;
72 if(dbThis) cout <<
"DalitzBWBoxSet::fullPdf result: " 85 for(
unsigned int i=0; i<boxes.
size(); i++){
90 if(0 == rnd)
_rnd = gRandom;
92 for(
unsigned int i=0; i< this->
size(); i++){
93 (*this)[i].setRnd(
_rnd);
100 _rnd->SetSeed(time(0)*2);
107 for(
unsigned int i=0; i< this->
size(); i++){
110 cout <<
"checking integration for box " 111 << (*this)[i].name() << endl;
112 s &= (*this)[i].checkIntegration();
113 cout <<
"=============================" 120 cout <<
"Hello from DalitzBWBoxSet::am_I_generating_what_I_think_I_am_generating" 121 <<
" with " << Nevents <<
" events to generate for each case" << endl;
125 DiskResidentEventList generatedFlat_weighted_approxPDF_events(
"generatedFlat_weighted_approxPDF_events.root" 128 int printEvery = min(Nevents/10, 10000);
130 for(
int i=0; i < Nevents; i++){
132 if(0 == i%printEvery) cout <<
"done event " << i << endl;
134 cout <<
"generated approxPDF_events"<< endl;
136 generated_approxPDF_events.
save();
138 datGen.
save(
"generated_approxPDF_histos.root");
139 datGen.
draw(
"generated_approxPDF_histos");
142 for(
int i=0; i < Nevents*rwfactor; i++){
145 generatedFlat_weighted_approxPDF_events.
Add(*evtPtr);
146 if(0 == i%(printEvery*rwfactor)) cout <<
"done event " << i << endl;
148 cout <<
"generated generatedFlat_weighted_approxPDF_events" << endl;
149 generatedFlat_weighted_approxPDF_events.
save();;
151 datWeight.
save(
"generatedFlat_weighted_approxPDF_histos.root");
152 datWeight.
draw(
"generatedFlat_weighted_approxPDF_histos");
153 datGen.
drawWithFitNorm(datWeight,
"genDotsWeightLine_",
"eps",
"E1 SAME");
157 ratio.
save(
"ratio_full_by_weight.root");
158 ratio.
draw(
"ratio_full_by_weight");
161 cout <<
"DalitzBWBoxSet::am_I_generating_what_I_think_I_am_generating:" 162 <<
" all done" << endl;
167 cout <<
"Hello from DalitzBWBoxSet::compareGenerationMethodsForFullPDF" 168 <<
" (with " << this->
size() <<
" boxes)" 169 <<
" with " << Nevents <<
" events to generate for each case" << endl;
171 DiskResidentEventList generated_fullPDF_efficient_weighted_events(
"generated_fullPDF_efficient_weighted_events.root" 173 DiskResidentEventList generatedFlat_fullPDF_flat_weighted_events(
"generated_fullPDF_flat_weighted_events.root" 176 bool unweightFull =
false;
178 int printEvery = min(Nevents/10, 10000);
180 for(
int i=0; i < Nevents; i++){
186 if(0 == i%printEvery) cout <<
"done event " << i << endl;
188 cout <<
"generated approxPDF_events"<< endl;
190 generated_fullPDF_efficient_weighted_events.
save();
192 datGen.
save(
"generated_fullPDF_efficient_weighted_histos.root");
193 datGen.
draw(
"generated_fullPDF_efficient_weighted");
196 for(
int i=0; i < Nevents*rwfactor; i++){
199 generatedFlat_fullPDF_flat_weighted_events.
Add(*evtPtr);
200 if(0 == i%(printEvery*rwfactor)) cout <<
"done event " << i << endl;
202 cout <<
"generated generatedFlat_fullPDF_flat_weighted_events" << endl;
203 generatedFlat_fullPDF_flat_weighted_events.
save();;
205 datWeight.
save(
"generated_fullPDF_efficient_weighted_histos.root");
206 datWeight.
draw(
"generated_fullPDF_efficient_weighted_events");
207 datGen.
drawWithFitNorm(datWeight,
"efficientBlue_FlatRed_",
"eps",
"E1 SAME");
211 ratio.
save(
"ratio_full_by_weight.root");
212 ratio.
draw(
"ratio_full_by_weight");
214 cout <<
"DalitzBWBoxSet::compareGenerationMethodsForFullPDF:" 215 <<
" all done" << endl;
242 cout <<
"calc_pick_ps_prob() = " 245 <<
" = " << returnVal << endl;
255 cout <<
" DalitzBWBoxSet::pick_ps_prob() = " <<
_pick_ps_prob << endl;
266 for(
int i=0; i < 100; i++){
274 if(this->
empty())
return;
283 cout <<
"DalitzBWBoxSet::getReady() - got ready, result is this: " 284 << (*this) <<
"\n ======= OK, no? ====== " << endl;
294 time_t startTime = time(0);
296 int maxEvents = 60000;
299 bool speedupabit=
true;
304 bool speedupalot=
false;
317 cout <<
"DalitzBWBoxSet::findMax making starter set with " 318 << maxEvents <<
" events." << endl;
325 && numTries < maxTries
329 cout <<
" DalitzBWBoxSet::findMax(): iteration number " << numTries
333 for(
int i=0; i < maxEvents; i++){
336 unsigned int printEvery = 100000;
337 if(i <= 10) printEvery=10;
338 else if(i <= 100) printEvery=100;
339 else if(i <= 1000) printEvery=1000;
340 else if(i <= 100000) printEvery=10000;
341 else if(i <= 1000000) printEvery=500000;
343 if(i < 1 || i%printEvery == 0){
344 cout <<
"DalitzBWBoxSet::findMax() " 345 <<
"made event number " << i
346 <<
"\t (" << difftime(time(0), startTime) <<
" sec)" 349 if(dbThis && (0 != evt)) {
350 cout <<
"DalitzBWBoxSet::findMax(): made event with weight " 356 cout <<
"DalitzBWBoxSet::findMax() starter set took " 357 << difftime(time(0), startTime) <<
" s." << endl;
371 cout <<
"DalitzBWBoxSet::findMax(): I have now " 373 <<
" events in the eventPtrList." << endl;
385 cout <<
"DalitzBWBoxSet::findMax(): AFTER unweighting I have " 387 <<
" events in the eventPtrList." << endl;
404 cout <<
"DalitzBWBoxSet::findMax() after throw away I have " 408 cout <<
"DalitzBWBoxSet::findMax() done after " 409 << difftime(time(0), startTime) <<
" s." << endl;
417 time_t startTime = time(0);
420 std::vector<double> vals;
429 if(dbThis) cout <<
"w = " << w << endl;
431 if(d > sampleMax || 0 == i) sampleMax=d;
436 if(printEvery <=0) printEvery = 5;
437 if(i <= 2) printEvery=1;
438 else if(i <= 200) printEvery=100;
440 if(i < 5 || 0 == i%(printEvery)){
441 std::cout <<
"DalitzBWBoxSet::findMaxInList() calculated " 442 <<
"_ampSum for event " 444 <<
", its value is " << d
446 double deltaT = difftime(time(0), startTime);
447 std::cout <<
" DalitzBWBoxSet::findMaxInList()this took " 450 std::cout <<
"; rate (before throwing away) = " 454 std::cout << std::endl;
459 double epsilon = 0.2;
463 std::cout <<
"sampleMax = " << sampleMax << std::endl;
466 std::cout <<
" maxValue after " << maxValue << std::endl;
467 maxValue *= 1.0 + epsilon;
468 std::cout <<
"DalitzBWBoxSet::findMaxInList():: Now added " 469 << epsilon * 100 <<
"% for safety. Returning " 470 << maxValue << std::endl;
479 std::cout <<
"EventPtrList::justThrowAwayData:" 480 <<
" before throwing away data, my size is " 483 time_t startTime = time(0);
486 unsigned int counter=0;
492 if(
_rnd->Rndm()*maxValue < d){
496 unsigned int printEvery = 10000;
501 if(counter < 1 || 0 == counter%(printEvery)){
502 std::cout <<
" amps for event " 505 <<
". " << newList.
size()
506 <<
" events passed ";
507 double deltaT = difftime(time(0), startTime);
508 std::cout <<
". Took " << deltaT <<
" s";
511 std::cout <<
"; rate (before/after throwing away) = " 513 <<
" / " << newList.
size()/deltaT
516 std::cout << std::endl;
524 std::cout <<
" So the waste factor is ";
526 else std::cout <<
" infinity! - that's big!";
527 std::cout << std::endl;
530 double deltaTFinal = difftime(time(0), startTime);
531 std::cout <<
" this took " << deltaTFinal/60.0 <<
" min" << std::endl;
542 for(
unsigned int i=0; i< this->
size(); i++){
543 if(dbThis)cout <<
" height number " << i <<
") " 544 << (*this)[i].height()
546 sum += (*this)[i].height();
549 if(dbThis)cout <<
" Volume sum: " << sum;
556 for(
unsigned int i=0; i< this->
size(); i++){
557 if(dbThis)cout <<
" volume number " << i <<
") " 558 << (*this)[i].volume()
560 sum += (*this)[i].volume();
563 if(dbThis)cout <<
" Volume sum: " << sum;
568 for(
unsigned int i=0; i< this->
size(); i++){
569 (*this)[i].setUnWeightPs(doSo);
576 if(this->
empty())
return;
587 for(
unsigned int i=0; i < this->
size(); i++){
589 sum += (*this)[i].volume()/totalVolume;
592 cout <<
" + " << (*this)[i].volume()/totalVolume;
593 cout <<
" = \t volume probs [" << i <<
"] = " << sum << endl;
606 double rndNumber =
_rnd->Rndm();
610 cout <<
"WARNING in DalitzBWBoxSet::pickRandomVolume():" 611 <<
" How odd - should never have gotten here." 612 <<
" rndNumber = " << rndNumber
613 <<
", _volumeProbs[this->size()-1] = " 616 return this->
size()-1;
629 cout <<
"DalitzBWBoxSet::tryEventForOwner ERROR: " 630 <<
" you called me, but there are no boxes" 631 <<
"\n\t returning 0-ptr" << endl;
644 evtPtr = ((*this)[vol].tryEventForOwner());
676 static unsigned int Ncalls=0;
677 static unsigned int printEveryNthCall = 10000;
680 bool printThis = Ncalls < 3 || (0 == Ncalls%printEveryNthCall);
694 int maxCount = 1000000;
695 int countProblems = 0;
699 if(counter > maxCount){
700 cout <<
"DalitzBWBoxSet::makeEventForOwner tried " 701 << counter <<
" times unsuccessfully. Giving up" 712 cout <<
"DalitzBWBoxSet::makeEventForOwner ERROR!!! " 713 <<
" for the " << countProblems <<
" th time. " 714 <<
"\n\t This event's weight > max Weight: " 718 cout <<
"\n\t...increased _maxWeightEstimate to: " 725 cout <<
"DalitzBWBoxSet::makeEventForOwner INFO after " 726 << Ncalls <<
" calls." 767 if(! ptr)
return ptr;
792 int maxTries = 10000000;
794 while((! ptr) && NTries < maxTries){
799 cout <<
"ERROR in DalitzBWBoxSet::makeWeightedEventForOwner() " 800 <<
" failed to make event after " << maxTries
814 if(this->
empty())
return -9999;
816 if(dbThis) cout <<
" calculating phaseSpaceIntegral " << endl;
821 cout <<
"compare to " << p4.
getVal(pat) << endl;
823 int maxEvents = 10000;
824 int maxTries = 10000 * maxEvents;
826 double sum=0, sumsq=0;
827 for(
int i=0; i < maxEvents && nTries < maxTries; i++){
828 int triesForThisEvent=0;
830 nTries += triesForThisEvent;
832 double val = ptr->phaseSpace();
835 if(dbThis && (0 == i%1000 || i < 100)){
836 cout <<
" i = " << i <<
", nTries = " << nTries
837 <<
" val = " << val <<
" sum " << sum << endl;
840 double mean = sum/((double)nTries);
841 double meanOfSq = sumsq/((double)nTries);
842 double variance = meanOfSq - mean*mean;
843 double error = sqrt(variance)/sqrt((
double)nTries);
851 <<
" relativeError: " << error/mean * 100 <<
"%" << endl;
860 cout <<
"DalitzBWBoxSet::genValueNoPs called with " << evt
864 if(this->
empty())
return 0;
866 for(
unsigned int i=0; i<this->
size(); i++){
867 double val = (*this)[i].genValue(evt);
869 cout <<
"DalitzBWBoxSet::genValueNoPs adding " << (*this)[i].name()
870 <<
" with " << val << endl;
877 cout <<
"DalitzBWBoxSet::genValueNoPs returning " << sum << endl;
905 if(dbThis) cout <<
"DalitzBWBoxSet::genValue sum before phase space " 908 if(dbThis) cout <<
"DalitzBWBoxSet::genValue adding ps = " 911 if(dbThis) cout <<
"DalitzBWBoxSet::genValue sum after phase space " 916 for(
unsigned int i=0; i < this->
size(); i++){
917 os <<
" box " << i <<
" )" << (*this)[i] <<
"\n";
virtual const EVENT_TYPE & getEventRef(unsigned int i) const
virtual void setWeight(double w)
void setPattern(const DalitzEventPattern &pat)
void makeVolumeProbIntervals()
std::vector< double > _volumeProbs
bool am_I_generating_what_I_think_I_am_generating(int Nevents=1000000)
double calc_pick_ps_prob() const
DalitzHistoSet weightedHistoSet() const
int numPermutations() const
double fullPdf(DalitzEvent &evt)
void push_back(const DalitzBWBox &c)
virtual bool Add(const EVENT_TYPE &evt)
virtual MINT::counted_ptr< DalitzEvent > makeEventForOwner()
bool drawWithFitNorm(const DalitzHistoSet &fit, const std::string &baseName="", const std::string &format="eps", const std::string &fitDrawOpt="HIST C SAME") const
DalitzEventPtrList _eventPtrList
double genValue(const DalitzEvent &evt) const
virtual double phaseSpace() const
void set_psbox_height_and_weight()
virtual MINT::counted_ptr< DalitzEvent > makeWeightedEventForOwner()
virtual MINT::counted_ptr< IDalitzEvent > newEvent()
double generalisedPareto_estimateMaximum(const std::vector< double > &input, double CL=0.001)
virtual double RealVal(EVENT_TYPE &evt)=0
double genValuePs(const DalitzEvent &evt) const
double _phaseSpaceIntegral
double findMaxInList(double &sampleMax)
virtual bool Add(const DalitzEvent &evt)
double _maxWeightInSample
bool compareGenerationMethodsForFullPDF(int Nevents=1000000)
void setUnWeightPs(bool doSo=true)
MINT::counted_ptr< DalitzEvent > makeEventForOwner()
void setPermutationIndex(int i)
virtual MINT::counted_ptr< DalitzEvent > phaseSpaceEvent()
bool setRnd(TRandom *rnd=gRandom)
virtual unsigned int size() const
ostream & operator<<(ostream &os, const DalitzBWBoxSet &box)
virtual double getWeight() const
bool setRnd(TRandom *rnd=gRandom)
bool draw(const std::string &baseName="", const std::string &drawOpt="", const std::string &format="eps") const
std::vector< DalitzBWBox >::iterator begin()
virtual MINT::counted_ptr< IDalitzEvent > newUnweightedEvent()
DalitzBWBoxSet(MINT::IReturnRealForEvent< IDalitzEvent > *amps=0, TRandom *r=gRandom)
DalitzPhaseSpaceBox _psbox
MINT::counted_ptr< DalitzEvent > popEventFromList()
bool checkIntegration() const
static double __phaseSpaceFracDefaultValue
unsigned int size() const
const MappedDalitzBWArea & area() const
double genValueWithLoop(DalitzEvent &evt) const
MINT::counted_ptr< DalitzEvent > makeEventForOwner()
virtual MINT::counted_ptr< DalitzEvent > tryEventForOwner()
int justThrowAwayData(double maxValue, MINT::IReturnRealForEvent< IDalitzEvent > *amps)
double _maxWeightEstimate
double getVal(const DalitzEventPattern &_pat)
virtual void setGeneratorPdfRelativeToPhaseSpace(double gpdf)
virtual MINT::counted_ptr< EVENT_TYPE > popLastEventPtr()
double phaseSpaceFrac() const
virtual MINT::counted_ptr< DalitzEvent > makeWeightedApproxEventForOwner()
void print(std::ostream &os) const
double phaseSpaceIntegral() const
double genValueNoPs(const DalitzEvent &evt) const
bool save(const std::string &filename="DalitzHistos.root") const
MINT::IReturnRealForEvent< IDalitzEvent > * _ampSum
void add(DalitzBWBox &box)