15 #include <sys/types.h> 27 ,
const std::string& fastFlexiEventFileName
29 : _Ncalls(0), _NReEvaluations(0), _sumT(0.0), _sumTRe(0.0), _sumTfast(0.0), _db(false)
32 initialise(pattern, amps, generator, rnd, precision);
33 (void)fastFlexiEventFileName;
37 : _sumT(0.0), _sumTRe(0.0), _sumTfast(0.0), _initialised(0), _db(false)
40 (void)fastFlexiEventFileName;
52 sc &= setValues(pattern, amps, generator, rnd, precision);
53 sc &= generateEnoughEvents();
109 if(seed < -9998) seed = time(0);
110 cout <<
"FlexiFastAmplitudeIntegrator::makeNewRnd with seed " << seed << endl;
130 _rnd = makeNewRnd(time(0));
132 _precision = precision;
134 _generator = generator;
143 cout <<
"ERROR in FlexiFastAmplitudeIntegrator::initialise" 144 <<
" amps->makeIntegCalculator()" 145 <<
" return NULL pointer!" << endl;
146 cout <<
"\t This will go wrong." << endl;
160 cout <<
" FlexiFastAmplitudeIntegrator::updateEventSet " 161 <<
" need to know pattern first." << endl;
168 if(missingEvents > 0){
169 cout <<
"missing events: " << missingEvents
175 cout <<
"want " << Nevents
177 <<
", so no more events missing." << endl;
222 if(dbThis) cout <<
"FlexiFastAmplitudeIntegrator::addEvents " 223 <<
" got called " << endl;
227 cout <<
"FlexiFastAmplitudeIntegrator::addEvents " 228 <<
" adding flat events. " << endl;
229 for(
int i=0; i < Nevents; i++){
235 unsigned long int maxTries = (
unsigned long int) Nevents * 1000;
237 if(maxTries < (
unsigned long int) Nevents) maxTries = Nevents * 100;
238 if(maxTries < (
unsigned long int) Nevents) maxTries = Nevents * 10;
239 if(maxTries < (
unsigned long int) Nevents) maxTries = Nevents;
241 time_t startTime = time(0);
242 for(
unsigned long int i=0; i < maxTries && N_success < Nevents; i++){
244 if(dbThis) cout <<
"got event with ptr: " << ptr << endl;
247 cout <<
"ERROR in FlexiFastAmplitudeIntegrator::addEvents" 248 <<
"\n\t Generator exhausted, cannot generate more events." 255 int printEvery = 1000;
256 if(N_success > 1000) printEvery = 50000;
257 if(N_success > 100000) printEvery = 100000;
258 bool printout = (N_success%printEvery == 0);
259 if(dbThis) printout |= (N_success < 20);
262 cout <<
" FlexiFastAmplitudeIntegrator::addEvents: added " << N_success
266 double sigma = -9999;
267 if(v > 0) sigma = sqrt(v);
268 cout <<
"\t integ= " <<
_mean <<
" +/- " << sigma;
278 cout <<
"ERROR in FlexiFastAmplitudeIntegrator::addEvents" 279 <<
"\n\t> I was supposed to add " << Nevents <<
" events," 280 <<
"\n\t> but now the total list size is only " 284 cout <<
" added " << Nevents <<
" _integCalc->numEvents " 295 time_t tstart = time(0);
300 double sigma = -9999;
301 if(v >= 0) sigma = sqrt(v);
302 double actualPrecision = -9999;
303 if(
_mean != 0 && sigma > 0) actualPrecision = sigma/
_mean;
305 double delT = difftime(time(0), tstart);
307 int printEvery = 100;
308 if(
_Ncalls > 1000) printEvery = 1000;
309 if(
_Ncalls > 10000) printEvery = 10000;
310 if(
_Ncalls > 100000) printEvery = 100000;
314 cout <<
" FlexiFastAmplitudeIntegrator::evaluateSum() for " 317 cout <<
"\n\t> getting: " <<
_mean <<
" +/- " << sigma
318 <<
"\n\t> precision: requested: " <<
_precision*100
319 <<
"%, actual: " << actualPrecision*100 <<
"%" 320 <<
"\n\t> This took " << delT <<
" s." 323 cout <<
"checking save and read-back:" << endl;
326 cout <<
" copy values:" 339 double safetyFactor = 1.15;
342 (v*safetyFactor/maxVariance);
346 cout <<
" FlexiFastAmplitudeIntegrator::determineNumEvents():" 347 <<
"\n\t> mean: " <<
_mean <<
", rms " << sqrt(v)
348 <<
"\n\t> currently, our relative precision is " 350 <<
"\n\t> to achieve the requested pecision of " <<
_precision <<
"," 351 <<
"\n\t> (with a safety factor) I think we'll need " 352 << (v*safetyFactor/maxVariance)
353 <<
" times that, i.e. " <<
_numEvents <<
" events" << endl;
362 counter < 10 && _numEvents > 0){
371 time_t tstart = time(0);
372 double delT_slow, delT_fast, delT_total;
376 delT_slow = difftime(time(0), tstart);
379 time_t tstart_2 = time(0);
381 delT_total = difftime(time(0), tstart);
382 delT_fast = difftime(time(0), tstart_2);
386 if(
_Ncalls > 100) printEvery = 100;
387 if(
_Ncalls > 1000) printEvery = 1000;
388 if(
_Ncalls > 10000) printEvery = 10000;
389 if(
_Ncalls > 100000) printEvery = 100000;
393 cout <<
"FlexiFastAmplitudeIntegrator::getVal, " <<
_Ncalls <<
"th call: Returning " <<
_mean 395 <<
"\n\t this call took " << delT_total <<
" s," 400 cout <<
", average call w/o re-integration " <<
_sumTfast / delN;
402 cout <<
" ." << endl;
431 if(dbThis) cout <<
"FlexiFastAmplitudeIntegrator::doFinalStats() called" << endl;
439 if(dbThis) cout <<
"FlexiFastAmplitudeIntegrator::doFinalStats() called" << endl;
virtual bool Add(const EVENT_TYPE &evt)
MINT::counted_ptr< FitAmpPairList > _integCalc
TRandom * makeNewRnd(int seed=-9999)
virtual double getFractionChi2() const
void startReIntegration()
DalitzHistoSet interferenceHistoSet() const
virtual void doFinalStatsAndSave(MINT::Minimiser *min=0, const std::string &fname="FitAmpResults.txt", const std::string &fnameROOT="fitFractions.root")
void addEvent(IDalitzEvent &evt)
virtual bool exhausted() const =0
void startForcedReIntegration()
DalitzEventList _fastFlexiEventList
virtual void reAddEvent(IDalitzEvent &evt, double weight=1)
std::vector< DalitzHistoSet > GetEachAmpsHistograms()
void saveEachAmpsHistograms(const std::string &prefix) const
virtual void doFinalStats(MINT::Minimiser *min=0)
FlexiFastAmplitudeIntegrator(const std::string &fastFlexiEventFileName="fastFlexiEventFileName.root")
virtual double variance() const
int updateEventSet(long int Nevents)
std::vector< DalitzHistoSet > GetInterferenceHistograms()
std::vector< DalitzHistoSet > GetInterferenceHistograms()
static const long int _minEvents
bool setValues(const DalitzEventPattern &pattern, IFastAmplitudeIntegrable *amps=0, MINT::IEventGenerator< IDalitzEvent > *eventGenerator=0, TRandom *rnd=0, double precision=1.e-2)
bool initialise(const DalitzEventPattern &pattern, IFastAmplitudeIntegrable *amps=0, MINT::IEventGenerator< IDalitzEvent > *eventGenerator=0, TRandom *rnd=0, double precision=1.e-2)
virtual bool add(const FitAmpPairList &otherList)
void doFinalStatsAndSave(MINT::Minimiser *min=0, const std::string &fname="FitAmpResults.txt", const std::string &fnameROOT="fitFractions.root")
virtual counted_ptr< RETURN_TYPE > newEvent()=0
bool needToReIntegrate() const
virtual double integral() const
virtual MINT::counted_ptr< FitAmpPairList > makeFitAmpPairList()=0
virtual bool ensureFreshEvents()=0
MINT::IEventGenerator< IDalitzEvent > * _generator
int addEvents(long int Nevents)
DalitzHistoSet histoSet() const
virtual bool save(const std::string &asSubdirOf=".") const
void reAddEvent(DalitzEvent &evt)
IFastAmplitudeIntegrable * _amps
void saveEachAmpsHistograms(const std::string &prefix) const
virtual unsigned int size() const
virtual void doFinalStats(MINT::Minimiser *mini=0)
MINT::counted_ptr< TRandom > _localRnd
double weight(IDalitzEvent *evtPtr)
virtual bool add(const FlexiFastAmplitudeIntegrator &other)
void saveInterferenceHistograms(const std::string &prefix) const
void saveInterferenceHistograms(const std::string &prefix) const
MINT::counted_ptr< FitAmpPairList > _integCalc_copyForDebug
DalitzHistoSet interferenceHistoSet() const
virtual int numEvents() const
virtual void addEvent(IDalitzEvent *evtPtr, double weight=1)
int generateEnoughEvents()
double getFractionChi2() const
virtual DalitzHistoSet histoSet() const
std::string stringtime(double dt)
virtual bool retrieve(const std::string &asSubdirOf=".")
std::vector< DalitzHistoSet > GetEachAmpsHistograms()