RooEllipse.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooEllipse.cxx 24269 2008-06-13 15:37:03Z wouter $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
00007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
00008  *                                                                           *
00009  * Copyright (c) 2000-2005, Regents of the University of California          *
00010  *                          and Stanford University. All rights reserved.    *
00011  *                                                                           *
00012  * Redistribution and use in source and binary forms,                        *
00013  * with or without modification, are permitted according to the terms        *
00014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00015  *****************************************************************************/
00016 
00017 //////////////////////////////////////////////////////////////////////////////
00018 // 
00019 // BEGIN_HTML
00020 // A RooEllipse is a two-dimensional ellipse that can be used to represent
00021 // an error contour.
00022 // END_HTML
00023 //
00024 
00025 
00026 #include "RooFit.h"
00027 
00028 #include "RooEllipse.h"
00029 #include "RooEllipse.h"
00030 #include "TMath.h"
00031 #include "RooMsgService.h"
00032 
00033 #include "Riostream.h"
00034 #include "TClass.h"
00035 #include <math.h>
00036 #include <assert.h>
00037 
00038 ClassImp(RooEllipse)
00039 
00040 
00041 
00042 //_____________________________________________________________________________
00043 RooEllipse::RooEllipse() 
00044 { 
00045   // Default constructor
00046 }
00047 
00048 
00049 //_____________________________________________________________________________
00050 RooEllipse::~RooEllipse() 
00051 {
00052   // Destructor
00053 }
00054 
00055 
00056 //_____________________________________________________________________________
00057 RooEllipse::RooEllipse(const char *name, Double_t x1, Double_t x2, Double_t s1, Double_t s2, Double_t rho, Int_t points) 
00058 {
00059   // Create a 2-dimensional ellipse centered at (x1,x2) that represents the confidence
00060   // level contour for a measurement with errors (s1,s2) and correlation coefficient rho.
00061   // The resulting curve is defined as the unique ellipse that passes through these points:
00062   //
00063   //   (x1+rho*s1,x2+s2) , (x1-rho*s1,x2-s2) , (x1+s1,x2+rho*s2) , (x1-s1,x2-rho*s2)
00064   //
00065   // and is described by the implicit equation:
00066   //
00067   //   x*x      2*rho*x*y      y*y
00068   //  -----  -  ---------  +  -----  =  1 - rho*rho
00069   //  s1*s1       s1*s2       s2*s2
00070   //
00071   // The input parameters s1,s2 must be > 0 and also |rho| <= 1.
00072   // The degenerate case |rho|=1 corresponds to a straight line and
00073   // is handled as a special case.
00074 
00075   SetName(name);
00076   SetTitle(name);
00077 
00078   if(s1 <= 0 || s2 <= 0) {
00079     coutE(InputArguments) << "RooEllipse::RooEllipse: bad parameter s1 or s2 < 0" << endl;
00080     return;
00081   }
00082   Double_t tmp= 1-rho*rho;
00083   if(tmp < 0) {
00084     coutE(InputArguments) << "RooEllipse::RooEllipse: bad parameter |rho| > 1" << endl;
00085     return;
00086   }
00087 
00088   if(tmp == 0) {
00089     // handle the degenerate case of |rho|=1
00090     SetPoint(0,x1-s1,x2-s2);
00091     SetPoint(1,x1+s1,x2+s2);
00092     setYAxisLimits(x2-s2,x2+s2);
00093   }
00094   else {
00095     Double_t r,psi,phi,u1,u2,xx1,xx2,dphi(2*TMath::Pi()/points);
00096     for(Int_t index= 0; index < points; index++) {
00097       phi= index*dphi;
00098       // adjust the angular spacing of the points for the aspect ratio
00099       psi= atan2(s2*sin(phi),s1*cos(phi));
00100       u1= cos(psi)/s1;
00101       u2= sin(psi)/s2;
00102       r= sqrt(tmp/(u1*u1 - 2*rho*u1*u2 + u2*u2));
00103       xx1= x1 + r*u1*s1;
00104       xx2= x2 + r*u2*s2;
00105       SetPoint(index, xx1, xx2);
00106       if(index == 0) {
00107         setYAxisLimits(xx2,xx2);
00108         // add an extra segment to close the curve
00109         SetPoint(points, xx1, xx2);
00110       }
00111       else {
00112         updateYAxisLimits(xx2);
00113       }
00114     }
00115   }
00116 }
00117 
00118 
00119 
00120 //_____________________________________________________________________________
00121 void RooEllipse::printName(ostream& os) const 
00122 {
00123   // Print name of ellipse on ostream
00124   os << GetName() ;
00125 }
00126 
00127 
00128 //_____________________________________________________________________________
00129 void RooEllipse::printTitle(ostream& os) const 
00130 {
00131   // Print title of ellipse on ostream
00132   os << GetName() ;
00133 }
00134 
00135 
00136 //_____________________________________________________________________________
00137 void RooEllipse::printClassName(ostream& os) const 
00138 {
00139   // Print class name of ellipse on ostream
00140   os << IsA()->GetName() ;
00141 }
00142 
00143 
00144 //_____________________________________________________________________________
00145 void RooEllipse::printMultiline(ostream& os, Int_t contents, Bool_t verbose, TString indent) const
00146 {
00147   // Print detailed multi line information on ellipse on ostreamx
00148   RooPlotable::printMultiline(os,contents,verbose,indent);
00149   for(Int_t index=0; index < fNpoints; index++) {
00150     os << indent << "Point [" << index << "] is at (" << fX[index] << "," << fY[index] << ")" << endl;
00151   }
00152 }

Generated on Tue Jul 5 15:06:28 2011 for ROOT_528-00b_version by  doxygen 1.5.1