Gaussian Smearing of 1cm

Dear Experts

I would like to add a Gaussian Smearing of 1cm to my Energy Distribution filling of Histogram. Please suggest if this is the correct way or not and How to set seed

float dr = rndm->Gaus(0,1);
  float dphi = rndm->Uniform(2 * TMath::Pi());
  float dx = dr * cos(dphi);
  float dy = dr * sin(dphi);

    TRandom3* rndm = new TRandom3(); // outside the loop
    rndm->SetSeed(); // making sure "rndm" picks different seed each time it is called 
    int nev = 0;
    
    while (myReader.Next())
    {
        nev++;
        cout << "Event: " << nev << endl;
        nphoton.push_back(0);
        float tot_e = 0;

        for (int i = 0; i < energy.GetSize(); i++)
        {
            nphoton.back()++;
            tot_e += energy[i];
            float z_shifted = abs(z[i]) - zmin;
            h3["energy"]->Fill(x[i]+rndm->Gaus(0,1) ,y[i] + rndm->Gaus(0,1) , abs(z[i]) - zmin,energy[i] );

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


units are in mm Are the following lines OK? but do I need to set seed or not ? If Yes Please tell How?

TRandom3* rndm = new TRandom3();

h3[“energy”]->Fill(x[i]+rndm->Gaus(0,10) ,y[i] + rndm->Gaus(0,10) , abs(z[i]) - zmin,energy[i] );

If your variables use [mm] units, you need “10.” [mm] Gaussian sigma (note: “v + rndm->Gaus(0., 10.)” = “rndm->Gaus(v, 10.)”).

The “rndm->SetSeed(/*0*/);” statement will make it really random.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.