Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

DataPoint.java

Go to the documentation of this file.
00001 package cedar.jetweb.model.plots;
00002 
00003 import cedar.jetweb.JetWebException;
00004 
00020 public class DataPoint implements Cloneable, Comparable {
00021 
00022     private double x_;// = null;
00023     private double y_;// = null;
00024     private double yUp_;// = null;
00025     private double yDown_;// = null;
00026     private double binWidth_;// = null;
00027     private double chi2_;// = null;
00028     private Integer pointNumber_;
00029 
00046     public DataPoint(){
00047     return;
00048     }
00049 
00056     public int compareTo(Object dpo)
00057     throws ClassCastException{
00058     
00059     if(! (dpo instanceof DataPoint)) {
00060         throw new ClassCastException
00061         ("DataPoint.compareTo: cannot compare object " + dpo + 
00062          " with DataPoint "+this.toString());
00063     }
00064 
00065     DataPoint dp = (DataPoint) dpo;
00066 
00067     if(pointNumber_ < dp.getNumber()) return -1;
00068     if(pointNumber_ > dp.getNumber()) return 1;
00069 
00070     if(x_<dp.getX()) return -1;
00071     if(x_>dp.getX()) return 1;
00072     return 0;
00073     } 
00074 
00087     public double[] toArray(){
00088     double[] array = {x_, y_, yUp_, yDown_, binWidth_, chi2_};
00089     return array;
00090     }
00092     public double getX(){
00093     return x_;
00094     }
00096     public double getY(){
00097     return y_;
00098     }
00100     public double getYUp(){
00101     return yUp_;
00102     }
00104     public double getYDown(){
00105     return yDown_;
00106     }
00108     public double getBinWidth(){
00109     return binWidth_;
00110     }
00112     public double getChi2(){
00113     return chi2_;
00114     }
00116     public DataPoint setX(double d){
00117         x_ = d;
00118     return this;
00119     }
00121     public DataPoint setY(double d){
00122     y_ = d;
00123     return this;
00124     }
00126     public DataPoint setYUp(double d){
00127     yUp_ = d;
00128     return this;
00129     }
00131     public DataPoint  setYDown(double d){
00132     yDown_ = d;
00133     return this;
00134     }
00136     public DataPoint  setBinWidth(double d){
00137     binWidth_ = d;
00138     return this;
00139     }
00140 
00141     public Integer getNumber(){
00142     return pointNumber_;
00143     }
00144 
00145     public DataPoint setNumber(Integer number){
00146     pointNumber_ = number;
00147     return this;
00148     }
00149 
00151     public DataPoint setChi2(double d){
00152     chi2_ = d;
00153     return this;
00154     }
00155 
00156 
00157     
00158 
00159     public Object clone(){
00160 
00161     DataPoint newPoint=new DataPoint();
00162     newPoint.setX(getX());
00163     newPoint.setY(getY());
00164     newPoint.setYUp(getYUp());
00165     newPoint.setYDown(getYDown());
00166     newPoint.setBinWidth(getBinWidth());
00167     newPoint.setChi2(getChi2());
00168 
00169     return newPoint;
00170     }
00174     public double getXMax(){
00175     return getX() + 0.5*getBinWidth();
00176     }
00180     public double getXMin(){
00181     return getX() - 0.5*getBinWidth();
00182     }
00186     public String toString(){
00187     StringBuffer b = new StringBuffer("DataPoint");
00188     b.append("\nX:");b.append(x_);
00189     b.append("\nY:");b.append(y_);
00190     b.append("\nY ERROR UP:");b.append(yUp_);
00191     b.append("\nY ERROR DOWN:");b.append(yDown_);
00192     b.append("\nBINWIDTH:");b.append(binWidth_);
00193     b.append("\nCHI2:");b.append(chi2_);
00194     return b.toString();
00195     }
00196 
00207     public void add(DataPoint p2){
00208 
00209     if (Math.abs(getX()-p2.getX())/(getX()+p2.getX())>0.001 ){
00210         System.out.println("x values not equal "+getX()+","+p2.getX());
00211     } else if (p2.getYUp()==0.0 && p2.getYDown()==0.0) {
00212     // No errors on new data - do nothing
00213     } else if (getYUp()==0.0 && getYDown()==0.0) {
00214         // No data in this point. Replace it by the new one
00215         setX(p2.getX());
00216         setY(p2.getY());
00217         setYUp(p2.getYUp());
00218         setYDown(p2.getYDown());
00219 
00220     } else {
00221         double sig1 = 0.5*(getYUp()+getYDown());
00222         //      double sig1sq = Math.pow( (getYUp()+getYDown())/2.0, 2);
00223         double sig1sq = sig1*sig1;
00224         double sig2 = 0.5 *(p2.getYUp()+p2.getYDown());
00225         double sig2sq = sig2 * sig2;;
00226         
00227         double w1 = 1.0/sig1sq;
00228         double w2 = 1.0/sig2sq;
00229 
00230         double invW1W2 = 1.0/(w1+w2);
00231 
00232         // Contents.
00233         double tmp1 = (getY()*w1+p2.getY()*w2) * invW1W2;
00234         // Errors
00235         //setYUp(1.0/Math.sqrt(w1+w2));
00236         setYUp(Math.sqrt(invW1W2));
00237         setYDown(getYUp());
00238         setY(tmp1);
00239     }                
00240 
00241     }
00249     public void fixZeroError(double lumi){
00250 
00251     if (lumi<=0.0) {
00252         System.out.println("DataPoint: attempt to fix errors with illegal lumi value="+lumi);
00253         return;
00254     }
00255 
00256     if (getY()==0.0 && getYUp()==0.0 && getYDown()==0.0) {
00257         setYUp(1.3/(getBinWidth()*lumi));
00258         setYDown(1.3/(getBinWidth()*lumi));
00259     }
00260     }
00261 }
00262 
00263 
00264 
00265 
00266 
00267 
00268 
00269 
00270 
00271 
00272 
00273 
00274 
00275 
00276 
00277 
00278 

Generated Wed Jan 17 09:14:27 GMT 2007