All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sim.util.distribution.BreitWignerMeanSquare Maven / Gradle / Ivy

Go to download

MASON is a fast discrete-event multiagent simulation library core in Java, designed to be the foundation for large custom-purpose Java simulations, and also to provide more than enough functionality for many lightweight simulation needs. MASON contains both a model library and an optional suite of visualization tools in 2D and 3D.

The newest version!
/*
  Copyright � 1999 CERN - European Organization for Nuclear Research.
  Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose 
  is hereby granted without fee, provided that the above copyright notice appear in all copies and 
  that both that copyright notice and this permission notice appear in supporting documentation. 
  CERN makes no representations about the suitability of this software for any purpose. 
  It is provided "as is" without expressed or implied warranty.
*/
package sim.util.distribution;
import ec.util.MersenneTwisterFast;

/**
 * Mean-square BreitWigner distribution; See the  math definition.
 * 

* Instance methods operate on a user supplied uniform random number generator; they are unsynchronized. *

* Static methods operate on a default uniform random number generator; they are synchronized. *

* Implementation: This is a port of RandBreitWigner used in CLHEP 1.4.0 (C++). * * @author [email protected] * @version 1.0, 09/24/99 */ public class BreitWignerMeanSquare extends BreitWigner { private static final long serialVersionUID = 1; protected Uniform uniform; // helper /** * Constructs a mean-squared BreitWigner distribution. * @param cut cut==Double.NEGATIVE_INFINITY indicates "don't cut". */ public BreitWignerMeanSquare(double mean, double gamma, double cut, MersenneTwisterFast randomGenerator) { super(mean,gamma,cut,randomGenerator); this.uniform = new Uniform(randomGenerator); } /* * Returns a deep copy of the receiver; the copy will produce identical sequences. * After this call has returned, the copy and the receiver have equal but separate state. * * @return a copy of the receiver. */ /* public Object clone() { BreitWignerMeanSquare copy = (BreitWignerMeanSquare) super.clone(); if (this.uniform != null) copy.uniform = new Uniform(copy.randomGenerator); return copy; } */ /** * Returns a mean-squared random number from the distribution; bypasses the internal state. * @param cut cut==Double.NEGATIVE_INFINITY indicates "don't cut". */ public double nextDouble(double mean,double gamma,double cut) { if (gamma == 0.0) return mean; if (cut==Double.NEGATIVE_INFINITY) { // don't cut double val = Math.atan(-mean/gamma); double rval = this.uniform.nextDoubleFromTo(val, Math.PI/2.0); double displ = gamma*Math.tan(rval); return Math.sqrt(mean*mean + mean*displ); } else { double tmp = Math.max(0.0,mean-cut); double lower = Math.atan( (tmp*tmp-mean*mean)/(mean*gamma) ); double upper = Math.atan( ((mean+cut)*(mean+cut)-mean*mean)/(mean*gamma) ); double rval = this.uniform.nextDoubleFromTo(lower, upper); double displ = gamma*Math.tan(rval); return Math.sqrt(Math.max(0.0, mean*mean + mean*displ)); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy