Logo ROOT   6.10/09
Reference Guide
RooEllipse.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * @(#)root/roofitcore:$Id$
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 
17 /**
18 \file RooEllipse.cxx
19 \class RooEllipse
20 \ingroup Roofitcore
21 
22 A RooEllipse is a two-dimensional ellipse that can be used to represent
23 an error contour.
24 **/
25 
26 
27 #include "RooFit.h"
28 
29 #include "RooEllipse.h"
30 #include "RooEllipse.h"
31 #include "TMath.h"
32 #include "RooMsgService.h"
33 
34 #include "Riostream.h"
35 #include "TClass.h"
36 #include <math.h>
37 #include <assert.h>
38 
39 using namespace std;
40 
42 
43 
44 
45 ////////////////////////////////////////////////////////////////////////////////
46 /// Default constructor
47 
49 {
50 }
51 
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// Destructor
55 
57 {
58 }
59 
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 /// Create a 2-dimensional ellipse centered at (x1,x2) that represents the confidence
63 /// level contour for a measurement with errors (s1,s2) and correlation coefficient rho.
64 /// The resulting curve is defined as the unique ellipse that passes through these points:
65 ///
66 /// (x1+rho*s1,x2+s2) , (x1-rho*s1,x2-s2) , (x1+s1,x2+rho*s2) , (x1-s1,x2-rho*s2)
67 ///
68 /// and is described by the implicit equation:
69 ///
70 /// x*x 2*rho*x*y y*y
71 /// ----- - --------- + ----- = 1 - rho*rho
72 /// s1*s1 s1*s2 s2*s2
73 ///
74 /// The input parameters s1,s2 must be > 0 and also |rho| <= 1.
75 /// The degenerate case |rho|=1 corresponds to a straight line and
76 /// is handled as a special case.
77 
79 {
80  SetName(name);
81  SetTitle(name);
82 
83  if(s1 <= 0 || s2 <= 0) {
84  coutE(InputArguments) << "RooEllipse::RooEllipse: bad parameter s1 or s2 < 0" << endl;
85  return;
86  }
87  Double_t tmp= 1-rho*rho;
88  if(tmp < 0) {
89  coutE(InputArguments) << "RooEllipse::RooEllipse: bad parameter |rho| > 1" << endl;
90  return;
91  }
92 
93  if(tmp == 0) {
94  // handle the degenerate case of |rho|=1
95  SetPoint(0,x1-s1,x2-s2);
96  SetPoint(1,x1+s1,x2+s2);
97  setYAxisLimits(x2-s2,x2+s2);
98  }
99  else {
100  Double_t r,psi,phi,u1,u2,xx1,xx2,dphi(2*TMath::Pi()/points);
101  for(Int_t index= 0; index < points; index++) {
102  phi= index*dphi;
103  // adjust the angular spacing of the points for the aspect ratio
104  psi= atan2(s2*sin(phi),s1*cos(phi));
105  u1= cos(psi)/s1;
106  u2= sin(psi)/s2;
107  r= sqrt(tmp/(u1*u1 - 2*rho*u1*u2 + u2*u2));
108  xx1= x1 + r*u1*s1;
109  xx2= x2 + r*u2*s2;
110  SetPoint(index, xx1, xx2);
111  if(index == 0) {
112  setYAxisLimits(xx2,xx2);
113  // add an extra segment to close the curve
114  SetPoint(points, xx1, xx2);
115  }
116  else {
117  updateYAxisLimits(xx2);
118  }
119  }
120  }
121 }
122 
123 
124 
125 ////////////////////////////////////////////////////////////////////////////////
126 /// Print name of ellipse on ostream
127 
128 void RooEllipse::printName(ostream& os) const
129 {
130  os << GetName() ;
131 }
132 
133 
134 ////////////////////////////////////////////////////////////////////////////////
135 /// Print title of ellipse on ostream
136 
137 void RooEllipse::printTitle(ostream& os) const
138 {
139  os << GetName() ;
140 }
141 
142 
143 ////////////////////////////////////////////////////////////////////////////////
144 /// Print class name of ellipse on ostream
145 
146 void RooEllipse::printClassName(ostream& os) const
147 {
148  os << IsA()->GetName() ;
149 }
150 
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// Print detailed multi line information on ellipse on ostreamx
154 
155 void RooEllipse::printMultiline(ostream& os, Int_t contents, Bool_t verbose, TString indent) const
156 {
157  RooPlotable::printMultiline(os,contents,verbose,indent);
158  for(Int_t index=0; index < fNpoints; index++) {
159  os << indent << "Point [" << index << "] is at (" << fX[index] << "," << fY[index] << ")" << endl;
160  }
161 }
std::string GetName(const std::string &scope_name)
Definition: Cppyy.cxx:145
#define coutE(a)
Definition: RooMsgService.h:34
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Print detailed information.
Definition: RooPlotable.cxx:43
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
STL namespace.
A RooEllipse is a two-dimensional ellipse that can be used to represent an error contour.
Definition: RooEllipse.h:22
virtual ~RooEllipse()
Destructor.
Definition: RooEllipse.cxx:56
double cos(double)
double sqrt(double)
static const double x2[5]
virtual void printTitle(std::ostream &os) const
Print title of ellipse on ostream.
Definition: RooEllipse.cxx:137
constexpr Double_t Pi()
Definition: TMath.h:40
double sin(double)
point * points
Definition: X3DBuffer.c:20
TRandom2 r(17)
bool verbose
RooEllipse()
Default constructor.
Definition: RooEllipse.cxx:48
static const double x1[5]
#define ClassImp(name)
Definition: Rtypes.h:336
double Double_t
Definition: RtypesCore.h:55
double atan2(double, double)
virtual void printName(std::ostream &os) const
Print name of ellipse on ostream.
Definition: RooEllipse.cxx:128
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Print detailed multi line information on ellipse on ostreamx.
Definition: RooEllipse.cxx:155
virtual void printClassName(std::ostream &os) const
Print class name of ellipse on ostream.
Definition: RooEllipse.cxx:146
gr SetName("gr")