Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
22Two-dimensional ellipse that can be used to represent an error contour.
23**/
24
25#include "RooEllipse.h"
26#include "TMath.h"
27#include "RooMsgService.h"
28
29#include "Riostream.h"
30#include "TClass.h"
31#include <cmath>
32
34
35////////////////////////////////////////////////////////////////////////////////
36/// Create a 2-dimensional ellipse centered at (x1,x2) that represents the confidence
37/// level contour for a measurement with errors (s1,s2) and correlation coefficient rho.
38/// The resulting curve is defined as the unique ellipse that passes through these points:
39///
40/// (x1+rho*s1,x2+s2) , (x1-rho*s1,x2-s2) , (x1+s1,x2+rho*s2) , (x1-s1,x2-rho*s2)
41///
42/// and is described by the implicit equation:
43///
44/// x*x 2*rho*x*y y*y
45/// ----- - --------- + ----- = 1 - rho*rho
46/// s1*s1 s1*s2 s2*s2
47///
48/// The input parameters s1,s2 must be > 0 and also |rho| <= 1.
49/// The degenerate case |rho|=1 corresponds to a straight line and
50/// is handled as a special case.
51
52RooEllipse::RooEllipse(const char *name, double x1, double x2, double s1, double s2, double rho, Int_t points)
53{
56
57 if(s1 <= 0 || s2 <= 0) {
58 coutE(InputArguments) << "RooEllipse::RooEllipse: bad parameter s1 or s2 < 0" << std::endl;
59 return;
60 }
61 double tmp= 1-rho*rho;
62 if(tmp < 0) {
63 coutE(InputArguments) << "RooEllipse::RooEllipse: bad parameter |rho| > 1" << std::endl;
64 return;
65 }
66
67 if(tmp == 0) {
68 // handle the degenerate case of |rho|=1
69 SetPoint(0,x1-s1,x2-s2);
70 SetPoint(1,x1+s1,x2+s2);
71 setYAxisLimits(x2-s2,x2+s2);
72 }
73 else {
74 double r;
75 double psi;
76 double phi;
77 double u1;
78 double u2;
79 double xx1;
80 double xx2;
81 double dphi(2 * TMath::Pi() / points);
82 for(Int_t index= 0; index < points; index++) {
83 phi= index*dphi;
84 // adjust the angular spacing of the points for the aspect ratio
85 psi= atan2(s2*sin(phi),s1*cos(phi));
86 u1= cos(psi)/s1;
87 u2= sin(psi)/s2;
88 r= sqrt(tmp/(u1*u1 - 2*rho*u1*u2 + u2*u2));
89 xx1= x1 + r*u1*s1;
90 xx2= x2 + r*u2*s2;
91 SetPoint(index, xx1, xx2);
92 if(index == 0) {
93 setYAxisLimits(xx2,xx2);
94 // add an extra segment to close the curve
95 SetPoint(points, xx1, xx2);
96 }
97 else {
99 }
100 }
101 }
102}
103
104
105
106////////////////////////////////////////////////////////////////////////////////
107/// Print name of ellipse on ostream
108
109void RooEllipse::printName(std::ostream& os) const
110{
111 os << GetName() ;
112}
113
114
115////////////////////////////////////////////////////////////////////////////////
116/// Print title of ellipse on ostream
117
118void RooEllipse::printTitle(std::ostream& os) const
119{
120 os << GetName() ;
121}
122
123
124////////////////////////////////////////////////////////////////////////////////
125/// Print class name of ellipse on ostream
126
127void RooEllipse::printClassName(std::ostream& os) const
128{
129 os << ClassName() ;
130}
131
132
133////////////////////////////////////////////////////////////////////////////////
134/// Print detailed multi line information on ellipse on ostreamx
135
136void RooEllipse::printMultiline(std::ostream& os, Int_t contents, bool verbose, TString indent) const
137{
138 RooPlotable::printMultiline(os,contents,verbose,indent);
139 for(Int_t index=0; index < fNpoints; index++) {
140 os << indent << "Point [" << index << "] is at (" << fX[index] << "," << fY[index] << ")" << std::endl;
141 }
142}
#define s1(x)
Definition RSha256.hxx:91
#define coutE(a)
#define ClassImp(name)
Definition Rtypes.h:377
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
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.
RooEllipse()=default
void printClassName(std::ostream &os) const override
Print class name of ellipse on ostream.
void printName(std::ostream &os) const override
Print name of ellipse on ostream.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Print detailed multi line information on ellipse on ostreamx.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Print detailed information.
void updateYAxisLimits(double y)
Definition RooPlotable.h:30
void setYAxisLimits(double ymin, double ymax)
Definition RooPlotable.h:34
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:2325
Double_t * fY
[fNpoints] array of Y points
Definition TGraph.h:48
void SetName(const char *name="") override
Set graph name.
Definition TGraph.cxx:2364
Double_t * fX
[fNpoints] array of X points
Definition TGraph.h:47
void SetTitle(const char *title="") override
Change (i.e.
Definition TGraph.cxx:2380
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:207
Basic string class.
Definition TString.h:139
constexpr Double_t Pi()
Definition TMath.h:37