Logo ROOT   6.14/05
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 
38 using namespace std;
39 
41 
42 
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Default constructor
46 
48 {
49 }
50 
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// Destructor
54 
56 {
57 }
58 
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// Create a 2-dimensional ellipse centered at (x1,x2) that represents the confidence
62 /// level contour for a measurement with errors (s1,s2) and correlation coefficient rho.
63 /// The resulting curve is defined as the unique ellipse that passes through these points:
64 ///
65 /// (x1+rho*s1,x2+s2) , (x1-rho*s1,x2-s2) , (x1+s1,x2+rho*s2) , (x1-s1,x2-rho*s2)
66 ///
67 /// and is described by the implicit equation:
68 ///
69 /// x*x 2*rho*x*y y*y
70 /// ----- - --------- + ----- = 1 - rho*rho
71 /// s1*s1 s1*s2 s2*s2
72 ///
73 /// The input parameters s1,s2 must be > 0 and also |rho| <= 1.
74 /// The degenerate case |rho|=1 corresponds to a straight line and
75 /// is handled as a special case.
76 
78 {
79  SetName(name);
80  SetTitle(name);
81 
82  if(s1 <= 0 || s2 <= 0) {
83  coutE(InputArguments) << "RooEllipse::RooEllipse: bad parameter s1 or s2 < 0" << endl;
84  return;
85  }
86  Double_t tmp= 1-rho*rho;
87  if(tmp < 0) {
88  coutE(InputArguments) << "RooEllipse::RooEllipse: bad parameter |rho| > 1" << endl;
89  return;
90  }
91 
92  if(tmp == 0) {
93  // handle the degenerate case of |rho|=1
94  SetPoint(0,x1-s1,x2-s2);
95  SetPoint(1,x1+s1,x2+s2);
96  setYAxisLimits(x2-s2,x2+s2);
97  }
98  else {
99  Double_t r,psi,phi,u1,u2,xx1,xx2,dphi(2*TMath::Pi()/points);
100  for(Int_t index= 0; index < points; index++) {
101  phi= index*dphi;
102  // adjust the angular spacing of the points for the aspect ratio
103  psi= atan2(s2*sin(phi),s1*cos(phi));
104  u1= cos(psi)/s1;
105  u2= sin(psi)/s2;
106  r= sqrt(tmp/(u1*u1 - 2*rho*u1*u2 + u2*u2));
107  xx1= x1 + r*u1*s1;
108  xx2= x2 + r*u2*s2;
109  SetPoint(index, xx1, xx2);
110  if(index == 0) {
111  setYAxisLimits(xx2,xx2);
112  // add an extra segment to close the curve
113  SetPoint(points, xx1, xx2);
114  }
115  else {
116  updateYAxisLimits(xx2);
117  }
118  }
119  }
120 }
121 
122 
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Print name of ellipse on ostream
126 
127 void RooEllipse::printName(ostream& os) const
128 {
129  os << GetName() ;
130 }
131 
132 
133 ////////////////////////////////////////////////////////////////////////////////
134 /// Print title of ellipse on ostream
135 
136 void RooEllipse::printTitle(ostream& os) const
137 {
138  os << GetName() ;
139 }
140 
141 
142 ////////////////////////////////////////////////////////////////////////////////
143 /// Print class name of ellipse on ostream
144 
145 void RooEllipse::printClassName(ostream& os) const
146 {
147  os << IsA()->GetName() ;
148 }
149 
150 
151 ////////////////////////////////////////////////////////////////////////////////
152 /// Print detailed multi line information on ellipse on ostreamx
153 
154 void RooEllipse::printMultiline(ostream& os, Int_t contents, Bool_t verbose, TString indent) const
155 {
156  RooPlotable::printMultiline(os,contents,verbose,indent);
157  for(Int_t index=0; index < fNpoints; index++) {
158  os << indent << "Point [" << index << "] is at (" << fX[index] << "," << fY[index] << ")" << endl;
159  }
160 }
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:55
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:136
constexpr Double_t Pi()
Definition: TMath.h:38
double sin(double)
point * points
Definition: X3DBuffer.c:20
ROOT::R::TRInterface & r
Definition: Object.C:4
#define s1(x)
Definition: RSha256.hxx:91
RooEllipse()
Default constructor.
Definition: RooEllipse.cxx:47
static const double x1[5]
#define ClassImp(name)
Definition: Rtypes.h:359
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:127
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:154
virtual void printClassName(std::ostream &os) const
Print class name of ellipse on ostream.
Definition: RooEllipse.cxx:145
gr SetName("gr")
char name[80]
Definition: TGX11.cxx:109