#ifndef GENERATOR_H #define GENERATOR_H #include #include "TRandom3.h" #include "TF1.h" const int maxIter = 100000000; Double_t Generator (Double_t rho, TRandom3* r){ if (rho < 0 || rho > 1){ std::cout << "[W]: rho is not within [0,1]. Returning dummy value" << std::endl; return -999; } TF1 fun("fun","4*x*x*(3-3*x) + [0]*(8*x*x*(4*x-3)/3)",0,1); fun.SetParameter(0,rho); Double_t maximum = fun.Eval(1.); if (((4*rho - 6) / (8*rho - 9) > 0) && ((4*rho - 6) / (8*rho - 9) < 1)) maximum = fun.Eval((4*rho - 6) / (8*rho - 9)); int iter = 0; while (iter < maxIter){ Double_t val1 = r -> Uniform(1); Double_t val2 = r -> Uniform(maximum); // maximun of the distribution (check this) /* std::cout << "[W]: actually check the max of the distribution" << std::endl; */ if (val2 < fun.Eval(val1)){ return val1; } iter++; } std::cout << "Max iter reached. Returning -999" << std::endl; return -999; } #endif