Sie sind auf Seite 1von 21

PHY310: Lecture 06

The Monte Carlo Method


Road Map
What is a Monte Carlo Monte Carlo integration Monte Carlo Simulation

02/08/07

PHY310: Statistical Data Analysis

The Monte Carlo Method


Legend has it... This was originally called the Vegas method, but then the Europeans got a hold of it...

The Monte Carlo method is a numeric technique using random numbers


Monte Carlo Integration to estimate the value of an integral
Take the function value at random points The area (volume) times the average function value estimates the integral.

Monte Carlo Simulation to predict an expected measurement.


An experimental measurement is split into a sequence of random processes. Use random numbers to decide which processes happen Tabulate the values to estimate the expected P.D.F. for the experiment.

MC Simulation and Integration are mathematically the same thing, but get approached with slightly different biases.

02/08/07

PHY310: Statistical Data Analysis

When is an MC Used?
MC Integration
Used when the function is complicated
There isn't a closed form for most integrals Non-MC numeric techniques depend on the function being smooth MC integration always works, but takes a lot of CPU time to get an accurate answer
But, CPU is CHEAP

MC Simulation
Before an experiment you should understand the expected distributions. It's hard to combine probability distributions MC's provide a simple way to predict the outcome of an experiment
Tells you what the null hypothesis will look like Let's you verify that the experiment is sensitive enough to make the observation

Be careful: Garbage in Garbage out

02/08/07

PHY310: Statistical Data Analysis

Monte Carlo Integration


Recall first year calculus: The mean value theorem

f dV

= fV

The integral of a function, f, over a volume, V, is equal to the mean of f times V.

Monte Carlo integration is done by:


Estimating the mean value of the function Multiplying by the volume

02/08/07

PHY310: Statistical Data Analysis

Estimating the Mean Function Value


The first introduction to Estimators

The mean of a function (e.g. the Expectation Value, E[f(x)], when x follows a uniform p.d.f) is estimated by the sample mean (also called the average)
1 f = f x i N i =1
N

The variance of the sample mean is


V [ f ] = 1 f 2 f 2 = 1 1 f x i 2 12 N 1 N 1 N i = 1 N

]
N 2 j =1

f x j

The estimate the function mean, we generate a large sample of random values, xi, and use them to calculate the sample mean for the function.

f f f = E [ f x ] f N1
02/08/07 PHY310: Statistical Data Analysis

Doing the MC Integral


f f f dV V f V N
Caveats

The uncertainty is an estimate of one standard deviation


This is not a rigorous bound on the value of the integral You should expect the true value to be outside of the interval about 30% of the time.

The uncertainty may not be Gaussian, so the it'sonly a rough estimate of the probable error.
If the function isn't smooth (and it never is) then the uncertainty tends to be underestimated

02/08/07

PHY310: Statistical Data Analysis

MC Integration Example
0.6670 0.0019

1 2 x dx =

1
1

2 3

x x x dx 2 x 2 N 1
2 2

2 2

2 2

Notice how slowly the uncertainty decreases


Trials have to increase by factor of 4 to reduce uncertainty by factor of 2.
02/08/07 PHY310: Statistical Data Analysis 7

Named Macros in ROOT


You can declare functions in ROOT macros
Called named macros
In integrate.C
double integrate(int trials) { return 0.0; }

To use a named macro


Pick a file name that can also be a C function Define a function with the same name as the file

You can define other functions in a named macro.


In integrate.C
double func(double x) { return x*x; } double integrate(int trials) { return func(0.0); } 02/08/07

Notice the missing { and } at the start and end of the file. They are not needed with a named macro.
8

PHY310: Statistical Data Analysis

The Details: MC Integration


The full integrate.C
double func(double x) { return x*x; } // Integrate a function from -1 to 1 double integrate () { double weight = 0.0; double sum = 0.0; double sum2 = 0.0; double volume = 2; for (int i=0; i<100000; ++i) { double x = gRandom->Uniform(-1,1); double f = func(x); sum += f; sum2 += f*f; weight += 1; } double avg = sum/weight; double var = sum2/weight - avg*avg; double value = volume*avg; std::cout << "Value " << value << "+-" << volume*sqrt(var/(weight-1)) << std::endl; return value; } 02/08/07 PHY310: Statistical Data Analysis 9

More Complicated Integration


Integrate f x , y , z =e
x y z

inside the volume V, a torus

1) Pick a volume, W, that encloses the integration volume, V. 1) e.g. 1 < x < 4, -3 < y < 4, and -1 < z < 1 2) The actual volume isn't very important, as long as it is larger than the integration region. 2) Redefine the integration function to include limits and integrate over W
z x y 3 1, x 1 and y 3
2 2 2 2

if z x y 3 1, x 1 and y 3 f x , y , z = e 0, otherwise
1 x y z 2 2 2

f dV = f 1 dW
02/08/07 PHY310: Statistical Data Analysis 10

Implementing the Complicated Integral


Define the integration function to include the limits.
double func(double x, double y, double z) { if (x<1) return 0.0; if (y<-3) return 0.0; double xx = sqrt(x*x+y*y)-3; if (z*z + xx*xx > 1) return 0.0; return exp(x+y+z); }

Change the loop in integrate.C to have three variables, and cover the entire volume.
// The integration loop in integrate.C becomes... double xmin=0; double xmax =4; double ymin=-4; double ymax=4; double zmin=-1; double zmax=1; for (int i=0; i<100000; ++i) { double x = gRandom->Uniform(0,4); double y = gRandom->Uniform(-4,4); double z = gRandom->Uniform(-1,1); double f = func(x,y,z); sum += f; sum2 += f*f; weight += 1; } double value = (xmax-xmin)*(ymax-ymin)*(zmax-zmin)*sum/weight; 02/08/07 PHY310: Statistical Data Analysis 11

Monte Carlo Simulation


It's often fairly easy to understand a physics measurement as a sequence of random processes
e.g. Signal coming out of a photo-detector which we' ll cover in a few minutes

Even if you understand the individual processes, it can be very difficult to fold them together and predict the observed distribution. Monte Carlo simulation provides a way to combine the processes and predict the final measured distribution Big advantages
You know exactly how the final distribution was simulated You can vary physical constants and see the effect You can inject hypothesized processes and see how they effect the data
This is vital when you are looking for things that have never been seen Proton Decay, Super Symmetry, Higgs Particles, Quark-Gluon Plasma

02/08/07

PHY310: Statistical Data Analysis

12

Simulating a Photomultiplier Tube


First Step: Understand how a PMT works
The photocathode is a metal with a small work function

Vhv = 900V, Positive HV

Vo = 0V (Ground) Dynode voltages set at Vo < V1 < V2 < V3 < V4 < V5 < V6 < Vhv 1) A photon strikes the photocathode and may/may-not generate a photo-electron 2) The photoelectron accelerates to the first dynode and generates dynode electrons a) The number of liberated electrons depends on metal (assume lib = E) 3) Electrons from the first dynode accelerate and strike the second dynode. Etc. 4) Final electrons are collected by the anode.

The Problem: What does the output signal look like?


02/08/07 PHY310: Statistical Data Analysis 13

Simulate the Photocathode


The photocathode is described by a quantum efficiency that depends on the photon wavelength

One photon can create one photoelectron. The photoelectron starts at rest.
// Simulate the number of photoelectrons created // by a single photon. double photoElectrons(int photons) { // Assume wave length is 400 nm and QE is 23% double pe = 0; for (int i=0; i<photons; ++i) { if (gRandom->Uniform()<0.23) pe = pe + 1; } return pe; } 02/08/07 PHY310: Statistical Data Analysis 14

Expected Number Dynode Electrons


Incoming electron
double meanDynodeElectrons(double E) { double energyPerElectron = 20; //Volts if (E<0) return 0.0; return E/energyPerElectron; }

Dynode electrons

1)When an electron with energy, E, strikes a dynode it liberates more electrons. a) Mean liberated electrons depends on metal (assume lib = E) b) Liberated electrons start at rest 2) Electrons get energy from the electric field.

02/08/07

PHY310: Statistical Data Analysis

15

Determine the Number of Generated Dynode-Electrons


Incoming electron 1) We are assuming that electrons are always created at rest, a) All electrons accelerating across the same voltage will have the same energy. 2) Estimate the mean number of dynode electrons using meanDynodeElectrons. 3) We are counting electrons so this is a Poisson process.

Dynode electrons

// Simulate the dynodes generated at a single dynode by // a number of incoming electrons with an energy of E. double dynodeElectrons(double incoming, double E) { double mean = incoming*meanDynodeElectrons(E); // This is counting so use Poisson. Use PoissonD since // the number of electrons can be HUGE. return gRandom->PoissonD(mean); }

02/08/07

PHY310: Statistical Data Analysis

16

Putting It All Together

Dynode voltages set at Vo < V1 < V2 < V3 < V4 < V5 < V6 < Vhv
// Simulate a sequence of dynodes. The dynode voltages are // given in V[] double photonToElectrons(int photons, double V[], int dynodes) { double electrons = photoElectrons(photons); double lastVoltage = 0.0; for (int dynode = 0; dynode<dynodes; ++dynode) { double voltDrop = V[dynode] - lastVoltage; electrons += dynodeElectrons(electrons,voltDrop); lastVoltage = V[dynode]; } return electrons; } 02/08/07 PHY310: Statistical Data Analysis 17

Simulate Many Photons and Histogram


void pmtSim() { TH1F* pmtSignal = new TH1F(pmtSignal, Charge from the PMT, 10, 0.0, 2E+6); pmtSignal->SetXTitle(Photo Electrons); int dynodes = 6; double V[6] = {150,300,450,600,750,850}; for (int photon=0; photon<10000; ++photon) { double electrons = photonToElectrons(1,V,dynodes); if (electrons>1) pmtSignal->Fill(electrons); } pmtSignal->Draw(); }

Only 2363 photons made a signal

Mean amplification is 2.6x105 electrons

Use the PMT simulation to learn about what PMT signals look like in a real experiment.
02/08/07 PHY310: Statistical Data Analysis 18

Now What: How to Use the MC Results


The big advantage of an MC, is that you know the true parameter values that generated the data.
What is the expected signal from exactly 4 photons?
Can't be directly measured in an experiment since there's know way to tell exactly how many photons struck the PMT.

What is the expected signal for a mean of 8 photons?


In an experiment, how do you determine that the mean is 8 photons?
It's trivial in an MC.

It's much cheaper to vary the parameters of an MC than it is in a real device


What's the effect of adding an extra dynode? What's the effect of increasing the voltage across the first dynode?

02/08/07

PHY310: Statistical Data Analysis

19

Signal vs Photons

02/08/07

PHY310: Statistical Data Analysis

20

The End
02/08/07 PHY310: Statistical Data Analysis 21

Das könnte Ihnen auch gefallen