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