1cm Smeared Distributions

Dear Experts

I want to make X Y and Z distributions with 1cm smearing. Please check if this code and plots are correct if not Please suggest changes. Thanks

#include <TCanvas.h>
#include <TH1F.h>
#include <TRandom3.h>

void BS() {
  // Parameters
  const int numEntries = 1000;   // Number of entries
  const double mean = 0.0;       // Mean value
  const double smear = 1.0;      // Smearing value (in cm)

  // Create histograms to store the smeared distributions for x, y, and z
  TH1F* hSmearedX = new TH1F("hSmearedX", "Smeared Distribution (X);x (cm);Counts", 100, -10.0, 10.0);
  TH1F* hSmearedY = new TH1F("hSmearedY", "Smeared Distribution (Y);y (cm);Counts", 100, -10.0, 10.0);
  TH1F* hSmearedZ = new TH1F("hSmearedZ", "Smeared Distribution (Z);z (cm);Counts", 100, -10.0, 10.0);

  // Set up the random number generator for smearing
  TRandom3 randSmeared;

  // Fill the smeared histograms by adding Gaussian noise to the mean values for x, y, and z
  for (int i = 0; i < numEntries; i++) {
    double xSmeared = mean + randSmeared.Gaus(0.0, smear);
    double ySmeared = mean + randSmeared.Gaus(0.0, smear);
    double zSmeared = mean + randSmeared.Gaus(0.0, smear);

    hSmearedX->Fill(xSmeared);
    hSmearedY->Fill(ySmeared);
    hSmearedZ->Fill(zSmeared);
  }

  // Create a canvas and draw the histograms for x
  TCanvas* canvasX = new TCanvas("canvasX", "Distribution (X)", 800, 600);
  hSmearedX->Draw();
  canvasX->SaveAs("distributionX.png");

  // Create a canvas and draw the histograms for y
  TCanvas* canvasY = new TCanvas("canvasY", "Distribution (Y)", 800, 600);
  hSmearedY->Draw();
  canvasY->SaveAs("distributionY.png");

  // Create a canvas and draw the histograms for z
  TCanvas* canvasZ = new TCanvas("canvasZ", "Distribution (Z)", 800, 600);
  hSmearedZ->Draw();
  canvasZ->SaveAs("distributionZ.png");
}



May be @moneta can help.

@moneta and @Wile_E_Coyote Please guide me to check if the above code is correct to make random gaussian distribution with smearing of 1cm

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