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 
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 "TMath.h"
31 #include "RooMsgService.h"
32 
33 #include "Riostream.h"
34 #include "TClass.h"
35 #include <math.h>
36 
37 using 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 {
78  SetName(name);
79  SetTitle(name);
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 {
115  updateYAxisLimits(xx2);
116  }
117  }
118  }
119 }
120 
121 
122 
123 ////////////////////////////////////////////////////////////////////////////////
124 /// Print name of ellipse on ostream
125 
126 void RooEllipse::printName(ostream& os) const
127 {
128  os << GetName() ;
129 }
130 
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// Print title of ellipse on ostream
134 
135 void RooEllipse::printTitle(ostream& os) const
136 {
137  os << GetName() ;
138 }
139 
140 
141 ////////////////////////////////////////////////////////////////////////////////
142 /// Print class name of ellipse on ostream
143 
144 void 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 
153 void 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 }
RooEllipse::printMultiline
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
RooMsgService.h
RooFit.h
RooFit::InputArguments
@ InputArguments
Definition: RooGlobalFunc.h:61
RooPlotable::printMultiline
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Print detailed information.
Definition: RooPlotable.cxx:42
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
r
ROOT::R::TRInterface & r
Definition: Object.C:4
coutE
#define coutE(a)
Definition: RooMsgService.h:33
RooEllipse::printClassName
virtual void printClassName(std::ostream &os) const
Print class name of ellipse on ostream.
Definition: RooEllipse.cxx:144
sin
double sin(double)
cos
double cos(double)
TClass.h
indent
static void indent(ostringstream &buf, int indent_level)
Definition: TClingCallFunc.cxx:87
TString
Basic string class.
Definition: TString.h:136
bool
RooEllipse::RooEllipse
RooEllipse()
Default constructor.
Definition: RooEllipse.cxx:46
RooEllipse::printName
virtual void printName(std::ostream &os) const
Print name of ellipse on ostream.
Definition: RooEllipse.cxx:126
x1
static const double x1[5]
Definition: RooGaussKronrodIntegrator1D.cxx:346
atan2
double atan2(double, double)
TMath::Pi
constexpr Double_t Pi()
Definition: TMath.h:37
RooEllipse
A RooEllipse is a two-dimensional ellipse that can be used to represent an error contour.
Definition: RooEllipse.h:22
s1
#define s1(x)
Definition: RSha256.hxx:91
RooEllipse.h
RooEllipse::printTitle
virtual void printTitle(std::ostream &os) const
Print title of ellipse on ostream.
Definition: RooEllipse.cxx:135
sqrt
double sqrt(double)
Double_t
double Double_t
Definition: RtypesCore.h:59
points
point * points
Definition: X3DBuffer.c:22
name
char name[80]
Definition: TGX11.cxx:110
genreflex::verbose
bool verbose
Definition: rootcling_impl.cxx:133
x2
static const double x2[5]
Definition: RooGaussKronrodIntegrator1D.cxx:364
SetName
gr SetName("gr")
Riostream.h
RooEllipse::~RooEllipse
virtual ~RooEllipse()
Destructor.
Definition: RooEllipse.cxx:54
TMath.h
int