Logo ROOT  
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
22A RooEllipse is a two-dimensional ellipse that can be used to represent
23an error contour.
24**/
25
26
27#include "RooFit.h"
28
29#include "RooEllipse.h"
30#include "TMath.h"
31#include "RooMsgService.h"
32
33#include "Riostream.h"
34#include "TClass.h"
35#include <math.h>
36
37using namespace std;
38
40
41
42
43////////////////////////////////////////////////////////////////////////////////
44/// Default constructor
45
47{
48}
49
50
51////////////////////////////////////////////////////////////////////////////////
52/// Destructor
53
55{
56}
57
58
59////////////////////////////////////////////////////////////////////////////////
60/// Create a 2-dimensional ellipse centered at (x1,x2) that represents the confidence
61/// level contour for a measurement with errors (s1,s2) and correlation coefficient rho.
62/// The resulting curve is defined as the unique ellipse that passes through these points:
63///
64/// (x1+rho*s1,x2+s2) , (x1-rho*s1,x2-s2) , (x1+s1,x2+rho*s2) , (x1-s1,x2-rho*s2)
65///
66/// and is described by the implicit equation:
67///
68/// x*x 2*rho*x*y y*y
69/// ----- - --------- + ----- = 1 - rho*rho
70/// s1*s1 s1*s2 s2*s2
71///
72/// The input parameters s1,s2 must be > 0 and also |rho| <= 1.
73/// The degenerate case |rho|=1 corresponds to a straight line and
74/// is handled as a special case.
75
77{
80
81 if(s1 <= 0 || s2 <= 0) {
82 coutE(InputArguments) << "RooEllipse::RooEllipse: bad parameter s1 or s2 < 0" << endl;
83 return;
84 }
85 Double_t tmp= 1-rho*rho;
86 if(tmp < 0) {
87 coutE(InputArguments) << "RooEllipse::RooEllipse: bad parameter |rho| > 1" << endl;
88 return;
89 }
90
91 if(tmp == 0) {
92 // handle the degenerate case of |rho|=1
93 SetPoint(0,x1-s1,x2-s2);
94 SetPoint(1,x1+s1,x2+s2);
95 setYAxisLimits(x2-s2,x2+s2);
96 }
97 else {
98 Double_t r,psi,phi,u1,u2,xx1,xx2,dphi(2*TMath::Pi()/points);
99 for(Int_t index= 0; index < points; index++) {
100 phi= index*dphi;
101 // adjust the angular spacing of the points for the aspect ratio
102 psi= atan2(s2*sin(phi),s1*cos(phi));
103 u1= cos(psi)/s1;
104 u2= sin(psi)/s2;
105 r= sqrt(tmp/(u1*u1 - 2*rho*u1*u2 + u2*u2));
106 xx1= x1 + r*u1*s1;
107 xx2= x2 + r*u2*s2;
108 SetPoint(index, xx1, xx2);
109 if(index == 0) {
110 setYAxisLimits(xx2,xx2);
111 // add an extra segment to close the curve
112 SetPoint(points, xx1, xx2);
113 }
114 else {
116 }
117 }
118 }
119}
120
121
122
123////////////////////////////////////////////////////////////////////////////////
124/// Print name of ellipse on ostream
125
126void RooEllipse::printName(ostream& os) const
127{
128 os << GetName() ;
129}
130
131
132////////////////////////////////////////////////////////////////////////////////
133/// Print title of ellipse on ostream
134
135void RooEllipse::printTitle(ostream& os) const
136{
137 os << GetName() ;
138}
139
140
141////////////////////////////////////////////////////////////////////////////////
142/// Print class name of ellipse on ostream
143
144void RooEllipse::printClassName(ostream& os) const
145{
146 os << IsA()->GetName() ;
147}
148
149
150////////////////////////////////////////////////////////////////////////////////
151/// Print detailed multi line information on ellipse on ostreamx
152
153void RooEllipse::printMultiline(ostream& os, Int_t contents, Bool_t verbose, TString indent) const
154{
156 for(Int_t index=0; index < fNpoints; index++) {
157 os << indent << "Point [" << index << "] is at (" << fX[index] << "," << fY[index] << ")" << endl;
158 }
159}
ROOT::R::TRInterface & r
Definition: Object.C:4
#define s1(x)
Definition: RSha256.hxx:91
static const double x2[5]
static const double x1[5]
#define coutE(a)
Definition: RooMsgService.h:33
int Int_t
Definition: RtypesCore.h:43
bool Bool_t
Definition: RtypesCore.h:61
double Double_t
Definition: RtypesCore.h:57
#define ClassImp(name)
Definition: Rtypes.h:361
static void indent(ostringstream &buf, int indent_level)
char name[80]
Definition: TGX11.cxx:109
double atan2(double, double)
double cos(double)
double sqrt(double)
double sin(double)
point * points
Definition: X3DBuffer.c:22
A RooEllipse is a two-dimensional ellipse that can be used to represent an error contour.
Definition: RooEllipse.h:22
virtual void printTitle(std::ostream &os) const
Print title of ellipse on ostream.
Definition: RooEllipse.cxx:135
virtual void printName(std::ostream &os) const
Print name of ellipse on ostream.
Definition: RooEllipse.cxx:126
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:153
virtual ~RooEllipse()
Destructor.
Definition: RooEllipse.cxx:54
RooEllipse()
Default constructor.
Definition: RooEllipse.cxx:46
virtual void printClassName(std::ostream &os) const
Print class name of ellipse on ostream.
Definition: RooEllipse.cxx:144
void updateYAxisLimits(Double_t y)
Definition: RooPlotable.h:33
void setYAxisLimits(Double_t ymin, Double_t ymax)
Definition: RooPlotable.h:37
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Print detailed information.
Definition: RooPlotable.cxx:42
Int_t fNpoints
Number of points <= fMaxSize.
Definition: TGraph.h:46
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Definition: TGraph.cxx:2269
virtual void SetName(const char *name="")
Set graph name.
Definition: TGraph.cxx:2308
virtual void SetTitle(const char *title="")
Change (i.e.
Definition: TGraph.cxx:2324
Double_t * fY
[fNpoints] array of Y points
Definition: TGraph.h:48
Double_t * fX
[fNpoints] array of X points
Definition: TGraph.h:47
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Basic string class.
Definition: TString.h:131
@ InputArguments
Definition: RooGlobalFunc.h:68
constexpr Double_t Pi()
Definition: TMath.h:38