Double_t val01(Double_t *val)
{
TRandom3 r;
Double_t rdm = r.Rndm();
Double_t val;
if (rdm < 0.25)
{
val = gRandom->Gaus(0.0017,0.0008);
}
else if (rdm > 0.75)
{
val = gRandom->Gaus(0.0033,0.0008);
}
else
{
val = (gRandom->Gaus(0.0017,0.0008)+gRandom->Gaus(0.0033,0.0008))/2.0;
}
return val;
}
and this is the error message:
root [2] .x DataPointsCode.C++
Info in <TUnixSystem::ACLiC>: creating shared library /home/jbmagallanes/./DataPointsCode_C.so
In file included from /home/jbmagallanes/DataPointsCode_C_ACLiC_dict.h:34,
from /home/jbmagallanes/DataPointsCode_C_ACLiC_dict.cxx:17:
/home/jbmagallanes/./DataPointsCode.C: In function 'Double_t val01(Double_t*)':
/home/jbmagallanes/./DataPointsCode.C:36: error: declaration of 'Double_t val' shadows a parameter
g++: /home/jbmagallanes/DataPointsCode_C_ACLiC_dict.o: No such file or directory
Error in <ACLiC>: Compilation failed!
Error: Function DataPointsCode() is not defined in current scope :0:
*** Interpreter error recovered ***
I don’t understand what you try to do. I can guess - tell me whether I guessed right or wrong.
Depending on rdm you want to return a different value, sampling from different random number distributions. You code looks good - the only issue is that your have a local variable val and you have a parameter of the same name. What’s your plan with the parameter Double_t *val - what do you need it for? Either way, this will fix the mechanical issue of the same-named variable:
TRandom3 r; // don't construct for each call!
Double_t val01(Double_t * /*val*/)
{
Double_t rdm = r.Rndm(); // why do you use `r` here, not `gRandom`?
auto lowGauss[] { return gRandom->Gaus(0.0017,0.0008); };
auto highGauss[] { return gRandom->Gaus(0.0033,0.0008); };
if (rdm < 0.25)
return lowGauss();
if (rdm > 0.75)
return highGaus();
return (lowGaus() + highGaus()) / 2.;
}