15 #include <sys/types.h> 32 initialise(pattern, amps, generator, rnd, precision);
37 ,
const std::string& fname
42 initialiseFromFile(pattern, amps, fname);
46 : _initialised(0), _db(false)
60 sc &= setValues(pattern, amps, generator, rnd, precision);
61 sc &= generateEnoughEvents();
68 ,
const std::string& commaSeparatedList
70 bool sc = setValues(pattern, amps, 0, 0, 1.e-10);
71 if(! sc)
return false;
72 sc &= _integCalc->retrieve(commaSeparatedList);
93 sc &= setValues(pattern, amps, generator, rnd, precision);
94 if(! sc)
return false;
96 std::stringstream is(commaSeparatedList);
97 getline(is, firstDir,
',');
101 if(firstDir !=
"" && stat(firstDir.c_str(), &buf) == 0){
103 sc &= _integCalc->retrieve(commaSeparatedList);
108 this->ensureFreshEvents();
110 sc &= generateEnoughEvents();
159 if(seed < -9998) seed = time(0);
160 cout <<
"FastAmplitudeIntegrator::makeNewRnd with seed " << seed << endl;
181 _rnd = makeNewRnd(time(0));
183 _precision = precision;
185 _generator = generator;
189 cout <<
"FastAmplitudeIntegrator::setValues: Have _integCalc ptr " << _integCalc
190 <<
", now printing it." << endl;
197 cout <<
"ERROR in FastAmplitudeIntegrator::initialise" 198 <<
" amps->makeIntegCalculator()" 199 <<
" return NULL pointer!" << endl;
200 cout <<
"\t This will go wrong." << endl;
210 cout <<
" FastAmplitudeIntegrator::updateEventSet " 211 <<
" need to know pattern first." << endl;
216 if(missingEvents > 0){
217 cout <<
"missing events: " << missingEvents
223 cout <<
"want " << Nevents
225 <<
", so no more events missing." << endl;
245 cout <<
" FastAmplitudeIntegrator::addEvents " 246 <<
" need to get initialised first." << endl;
249 if(dbThis) cout <<
"FastAmplitudeIntegrator::addEvents " 250 <<
" got called " << endl;
254 cout <<
"FastAmplitudeIntegrator::addEvents " 255 <<
" adding flat events. " << endl;
256 for(
int i=0; i < Nevents; i++){
262 unsigned long int maxTries = (
unsigned long int) Nevents * 1000;
264 if(maxTries < (
unsigned long int) Nevents) maxTries = Nevents * 100;
265 if(maxTries < (
unsigned long int) Nevents) maxTries = Nevents * 10;
266 if(maxTries < (
unsigned long int) Nevents) maxTries = Nevents;
268 time_t startTime = time(0);
269 for(
unsigned long int i=0; i < maxTries && N_success < Nevents; i++){
271 if(dbThis) cout <<
"got event with ptr: " << ptr << endl;
274 cout <<
"ERROR in FastAmplitudeIntegrator::addEvents" 275 <<
"\n\t Generator exhausted, cannot generate more events." 282 int printEvery = 1000;
283 if(N_success > 1000) printEvery = 50000;
284 if(N_success > 100000) printEvery = 100000;
285 bool printout = (N_success%printEvery == 0);
286 if(dbThis) printout |= (N_success < 20);
289 cout <<
" FastAmplitudeIntegrator::addEvents: added " << N_success
293 double sigma = -9999;
294 if(v > 0) sigma = sqrt(v);
295 cout <<
"\t integ= " <<
_mean <<
" +/- " << sigma;
305 cout <<
"ERROR in FastAmplitudeIntegrator::addEvents" 306 <<
"\n\t> I was supposed to add " << Nevents <<
" events," 307 <<
"\n\t> but now the total list size is only " 311 cout <<
" added " << Nevents <<
" _integCalc->numEvents " 320 cout <<
" FastAmplitudeIntegrator::variance " 321 <<
" need to get initialised first." << endl;
328 cout <<
" FastAmplitudeIntegrator::evaluateSum " 329 <<
" need to get initialised first." << endl;
333 time_t tstart = time(0);
338 double sigma = -9999;
339 if(v >= 0) sigma = sqrt(v);
340 double actualPrecision = -9999;
341 if(
_mean != 0 && sigma > 0) actualPrecision = sigma/
_mean;
343 double delT = difftime(time(0), tstart);
345 int printEvery = 100;
346 if(
_Ncalls > 1000) printEvery = 1000;
347 if(
_Ncalls > 10000) printEvery = 10000;
348 if(
_Ncalls > 100000) printEvery = 100000;
352 cout <<
" FastAmplitudeIntegrator::evaluateSum() for " 355 <<
"\n\t> getting: " <<
_mean <<
" +/- " << sigma
356 <<
"\n\t> precision: requested: " <<
_precision*100
357 <<
"%, actual: " << actualPrecision*100 <<
"%" 358 <<
"\n\t> This took " << delT <<
" s." 361 cout <<
"checking save and read-back:" << endl;
364 cout <<
" copy values:" 375 cout <<
" FastAmplitudeIntegrator::determineNumEvents " 376 <<
" need to get initialised first." << endl;
383 double safetyFactor = 1.15;
386 (v*safetyFactor/maxVariance);
390 cout <<
" FastAmplitudeIntegrator::determineNumEvents():" 391 <<
"\n\t> mean: " <<
_mean <<
", rms " << sqrt(v)
392 <<
"\n\t> currently, our relative precision is " 394 <<
"\n\t> to achieve the requested pecision of " <<
_precision <<
"," 395 <<
"\n\t> (with a safety factor) I think we'll need " 396 << (v*safetyFactor/maxVariance)
397 <<
" times that, i.e. " <<
_numEvents <<
" events" << endl;
404 cout <<
" FastAmplitudeIntegrator::generateEnoughEvents " 405 <<
" need to get initialised first." << endl;
412 counter < 10 && _numEvents > 0){
426 cout <<
" FastAmplitudeIntegrator::histoSet " 427 <<
" need to get initialised first." << endl;
435 cout <<
" FastAmplitudeIntegrator::saveEachAmpsHistograms " 436 <<
" need to get initialised first." << endl;
437 cout <<
"So I won't do anything" << endl;
444 cout <<
" FastAmplitudeIntegrator::GetEachAmpsHistograms " 445 <<
" need to get initialised first." << endl;
446 std::vector<DalitzHistoSet> dummy;
454 cout <<
" FastAmplitudeIntegrator::interferenceHistoSet " 455 <<
" need to get initialised first." << endl;
463 cout <<
" FastAmplitudeIntegrator::saveInterferenceAmpsHistograms " 464 <<
" need to get initialised first." << endl;
465 cout <<
"So I won't do anything" << endl;
472 cout <<
" FastAmplitudeIntegrator::GetInterferenceHistograms " 473 <<
" need to get initialised first." << endl;
474 std::vector<DalitzHistoSet> dummy;
484 cout <<
"FastAmplitudeIntegrator::doFinalStats() called" << endl;
486 cout <<
"Got called with these pointers: mini " << mini
487 <<
" and my own _integCalc " <<
_integCalc << endl;
490 cout <<
" FastAmplitudeIntegrator::doFinalStats " 491 <<
" need to get initialised first." << endl;
492 cout <<
" So I won't do anything." << endl;
500 cout <<
" FastAmplitudeIntegrator::getFractionChi2() " 501 <<
" need to get initialised first." << endl;
509 cout <<
" FastAmplitudeIntegrator::save( " << fname <<
" ):" 510 <<
" need to get initialised first." << endl;
511 cout <<
" So I won't do anything." << endl;
std::vector< DalitzHistoSet > GetInterferenceHistograms()
virtual bool retrieve(const std::string &commaSeparatedList)
virtual DalitzHistoSet interferenceHistoSet() const
void saveEachAmpsHistograms(const std::string &prefix) const
virtual void saveInterferenceHistograms(const std::string &prefix) const
virtual bool exhausted() const =0
MINT::IEventGenerator< IDalitzEvent > * _generator
MINT::counted_ptr< IntegCalculator > _integCalc_copyForDebug
virtual DalitzHistoSet histoSet() const
virtual double integral() const
virtual bool save(const std::string &dirname) const
bool initialise(const DalitzEventPattern &pattern, IFastAmplitudeIntegrable *amps=0, MINT::IEventGenerator< IDalitzEvent > *eventGenerator=0, TRandom *rnd=0, double precision=1.e-2)
bool initialiseFromFile(const DalitzEventPattern &pattern, IFastAmplitudeIntegrable *amps, const std::string &commaSeparatedList)
virtual void print(std::ostream &os=std::cout) const
virtual std::vector< DalitzHistoSet > GetInterferenceHistograms()
double getFractionChi2() const
virtual bool add(const FastAmplitudeIntegrator &other)
bool setValues(const DalitzEventPattern &pattern, IFastAmplitudeIntegrable *amps=0, MINT::IEventGenerator< IDalitzEvent > *eventGenerator=0, TRandom *rnd=0, double precision=1.e-2)
DalitzHistoSet histoSet() const
MINT::counted_ptr< TRandom > _localRnd
IFastAmplitudeIntegrable * _amps
virtual std::vector< DalitzHistoSet > GetEachAmpsHistograms()
bool save(const std::string &fname) const
virtual bool add(const IntegCalculator &other)
virtual counted_ptr< RETURN_TYPE > newEvent()=0
virtual void doFinalStats(MINT::Minimiser *mini=0)
virtual bool ensureFreshEvents()=0
virtual int numEvents() const
TRandom * makeNewRnd(int seed=-9999)
virtual double variance() const
virtual void doFinalStats(MINT::Minimiser *mini=0)
virtual void addEvent(IDalitzEvent *evtPtr, double weight=1)
int addEvents(long int Nevents)
virtual void saveEachAmpsHistograms(const std::string &prefix) const
std::vector< DalitzHistoSet > GetEachAmpsHistograms()
virtual double getFractionChi2() const
static const long int _minEvents
FastAmplitudeIntegrator()
int updateEventSet(long int Nevents)
std::string stringtime(double dt)
MINT::counted_ptr< IntegCalculator > _integCalc
int generateEnoughEvents()
virtual MINT::counted_ptr< IntegCalculator > makeIntegCalculator()=0
double weight(IDalitzEvent *evtPtr)
DalitzHistoSet interferenceHistoSet() const
void saveInterferenceHistograms(const std::string &prefix) const