// random generator trouble (TRandom2 or TRandom3 have no such trouble) /* * Compile with g++ -v -o example `rootconfig --cflags --libs` example.C */ using namespace std; #include #include #include #include #include #include #include #include #include #include // Constants const int NEvt = 100000; float seed = 0; //seed for random generators float GetBe11State(float E, float Width); TRandom *rootrand = new TRandom(); // Main Program int main(unsigned int argc, char **argv) { int Evt; float EBe11; // Reading argc and argv if (argc!=2) { printf("(only) one argument needed... \n"); //exit(0); } seed = atof(argv[1]); seed = fmod(seed,RAND_MAX); printf("Random seed = %f \n",seed); rootrand->SetSeed((int)seed); //gRandom->SetSeed((int)seed); //this produces the same bad results, of course srand((int)seed); TFile *f = new TFile("filesave.root","RECREATE"); TTree *mc = new TTree("mc","MonteCarlo Simulation"); mc->Branch("EBe11",&EBe11,"EBe11/F"); /************************************ Start of the Monte-Carlo **************************/ for (Evt=1 ; Evt<=NEvt ; Evt++) { if (Evt%(NEvt/20)==0) printf("Treated Events: %d %% \n",(100*Evt/NEvt)); EBe11 = GetBe11State(8.816,0.2); mc->Fill(); } f->Write(); return 1; } float GetBe11State(float E, float Width) { float EState = (float)rootrand->BreitWigner(E,Width); //rootrand is our TRandom object #ifdef EDEBUG cout << "GetBe11State w/index=" << index << "EBe11= " << E << " EState= " << EState << endl; #endif return ( EState ); }