Random number generator

Hi,

So I’ve written this code with the intention of it generating 10000 random numbers to 2dp between 0 and 360 degrees and recording how many of these random numbers are above 0.05. This will be coupled with another bit of code later that has already been written. However, while I have been assured elsewhere that what I have written should work, it doesn’t do any of the things I want it to, it just successfully doesn’t create errors which of course doesn’t mean that its working either. Can you please advise me on how to get it working? I’m at a bit of an impasse and still new to this.

This is the code in question:

void test6(UInt_t NrOfEvents = 1000000) {
if (!gROOT->GetClass(“TGenPhaseSpace”)) gSystem->Load(“libPhysics”);

TLorentzVector target(0.0, 0.0, 0.0, 1.879);
TLorentzVector beam(0.0, 0.0, 2.2, 2.2);
TLorentzVector W = beam + target;

//(Momentum, Energy units are Gev/C, GeV)
Double_t masses[4] = {0.938, 0.493, 0.493, 0.938} ;

//int detectn = 100000; //detect n will eventually be an output based on detector efficiency and angle p
//void doit(UInt_t NrOfEvents = 1000000) //Number of events can be changed here or when you want to run by “doit(…)”
//{
//if (TRandom3
p) delete TRandom3
;
int c=0;
TRandom3
p = new TRandom3(-1);
Double_t num = p-> Uniform(0,360);
cout << “p=”<< p << endl; //used as a test to ensure it is working
if (p < 0.05){
c=c+1;
}
cout << “c=”<< c << endl;

(this is just a section of a larger code however later bits have no bearing on the section in question. Further, the target and beam are also irrelevant for this question, sorry if I’ve left things without much clarity!)

This is the relevant output I get:

root [0]
Processing test6.C…
p=0x12f80c0
c=0

Thanks in advance!

Hi,

With ROOT6 it’s easy:

f22806.C:19:10: error: invalid operands to binary expression ('TRandom3 *' and 'double')
   if (p < 0.05){
       ~ ^ ~~~~

I called the file f22806.C. See attachment for a fixed version.

Axel.
f22806.C (800 Bytes)

TRandom3 *p = new TRandom3(0);
// …
if (p->Uniform(0, 360) < 0.05) c++;

[quote=“Axel”]Hi,

With ROOT6 it’s easy:

f22806.C:19:10: error: invalid operands to binary expression ('TRandom3 *' and 'double')
   if (p < 0.05){
       ~ ^ ~~~~

I called the file f22806.C. See attachment for a fixed version.

Axel.[/quote]

This works now thank you!