package jhpro.upropog;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

import jhplot.FNon;
import jhplot.H1D;
import jhplot.P0D;

/**
 * Propagation of uncertainties (or errors) for a complex function using a Monte
 * Carlo method. We assume uncertainties are distributed according to a normal distribution (Gaussian).
 * 
 * 
 * @author S.Chekanov
 * 
 */
public class UPropogate {

	
	 private double error;
	 private double[] vec;
	 
	/**
	 * Initialize propagation of uncertainties (or errors). The list with errors include uncertainties on the parameters plus on the function avariable.
	 * They can be zero if you do not want any uncertainties.
	 * 
	 * @param f
	 *            input function
	 * @param par
	 *            a list with parameters values         
	 *            
	 * @param  par_err
	 *            a list with uncertainties for parameters
	 * @param var
	 *            a list with variables around which function should be evaluated
	 *             
	 * @param  var_err
	 *             a list with uncertainties for variables (can be zero)         
	 *             (can be all zero)
	 * @param NTOT
	 *            total number of Monte Carlo events. the more is the better.
	 */

	public UPropogate (FNon f, double[] par, double[] par_err, double[] var, double[] var_err, int NTOT){
		
		if (NTOT<=0){
			System.err.println("Number of Monte Carlo events cannot be zero or negative");
			return;
		}
		
		if (f.dimension() != var.length){
			System.err.println("Dimension of the input function is different than the dimension of input values");
			return;
		}
		
		if (f.dimension() != var_err.length){
			System.err.println("Dimension of the input function is different than the dimension of input errors on values");
			return;
		}
		
		if (f.dimension() != var.length){
			System.err.println("Dimension of the input function is different than the dimension of input values");
			return;
		}
		
		if (f.numberOfParameters() != par.length){
			System.err.println("Number of  parameters is different than the dimension of input parameters");
			return;
		}
		
		if (f.numberOfParameters() != par_err.length){
			System.err.println("Number of  parameters is different than the dimension of input parameter errors");
			return;
		}
		
		
		
		
		Random rdm = new Random();
		vec = new double[NTOT];
		
		for (int i=0; i arr){   
	    double[] result = new double[arr.size()];
	    int i = 0;
	    for(Double d : arr) {
	        result[i++] = d.doubleValue();
	    }
	    return result;
	}



	
	
	
	
	
	
	
	/**
	 * Get total uncertainty as standard deviation.
	 * @return total uncertainty 
	 */
	
	public double getStd(){
		
     error=jhplot.stat.Statistics.stddeviation(vec);		
	 return error;
	 
	}
	
	
	
	
	/**
	 * Get a histogram representing a spread of the final function from Monte Carlo simulation.
	 * 
	 * @return histogram from Monte Carlo simulation 
	 */
	
	public H1D getHisto(){
		
     P0D p = new P0D(vec);
     
     H1D tmp = new H1D("uncertainty",100,p.getMin(),p.getMax());
	 tmp.fill(vec);
	 return tmp;
	 
	}
	
	
	
	
	
	
	
	
	
	
	
}

 

Ads help maintain this website.