rarMinuit.cc

Go to the documentation of this file.
00001 /*****************************************************************************
00002 * Project: BaBar detector at the SLAC PEP-II B-factory
00003 * Package: RooRarFit
00004  *    File: $Id: rarMinuit.cc,v 1.11 2011/06/16 13:18:50 fwilson Exp $
00005  * Author:                                                                   *
00006  *   WTF, Bill Ford, U. of Colorado, wtford@pizero.colorado.edu              *
00007  *                                                                           *
00008  *****************************************************************************/
00009 
00010 // -- CLASS DESCRIPTION [PDF] --
00011 // This class is derived from RooMinuit and overloads the contour() method to
00012 // produce a RooPlot.
00014 //
00015 // BEGIN_HTML
00016 // This class is derived from RooMinuit and overloads the contour() method to
00017 // produce a RooPlot.
00018 // END_HTML
00019 //
00020 
00021 #include "RooRarFit/rarVersion.hh"
00022 
00023 #include "Riostream.h"
00024 #include "TH1.h"
00025 #include "TH2.h"
00026 #include "TMarker.h"
00027 #include "TGraph.h"
00028 #include "TStopwatch.h"
00029 #include "TFitter.h"
00030 #include "TMinuit.h"
00031 #include "TDirectory.h"
00032 #include "RooFitCore/RooMinuit.hh"
00033 #include "RooFitCore/RooArgSet.hh"
00034 #include "RooFitCore/RooArgList.hh"
00035 #include "RooFitCore/RooAbsReal.hh"
00036 #include "RooFitCore/RooRealVar.hh"
00037 #include "RooFitCore/RooPlot.hh"
00038 #include "RooRarFit/rarMinuit.hh"
00039 
00040 rarMinuit::rarMinuit(RooAbsReal& function) : RooMinuit(function)
00041 {
00042   // The following are private in the base class so we have to set them up here
00043   _func = &function ;
00044   // Examine parameter list
00045   RooArgSet* paramSet = function.getParameters(RooArgSet()) ;
00046   RooArgList paramList(*paramSet) ;
00047   delete paramSet ;
00048 
00049   _floatParamList = (RooArgList*) paramList.selectByAttrib("Constant",kFALSE) ;
00050   if (_floatParamList->getSize()>1) {
00051     _floatParamList->sort() ;
00052   }
00053   _floatParamList->setName("floatParamList") ;
00054   
00055 }
00056 
00057 RooPlot* rarMinuit::contour(RooRealVar& var1, RooRealVar& var2,
00058                             Double_t n1, Double_t n2, Double_t n3,
00059                             Double_t n4, Double_t n5, Double_t n6) 
00060 {
00061   // Verify that both variables are floating parameters of PDF
00062   Int_t index1= _floatParamList->index(&var1);
00063   if(index1 < 0) {
00064     cout << "rarMinuit::contour(" << GetName() 
00065          << ") ERROR: " << var1.GetName()
00066          << " is not a floating parameter of " << _func->GetName() << endl ;
00067     return 0;
00068   }
00069   
00070   Int_t index2= _floatParamList->index(&var2);
00071   if(index2 < 0) {
00072     cout << "rarMinuit::contour(" << GetName() 
00073          << ") ERROR: " << var2.GetName()
00074          << " is not a floating parameter of PDF "
00075          << _func->GetName() << endl ;
00076     return 0;
00077   }
00078   
00079   // create and draw a frame
00080   RooPlot *frame = new RooPlot(var1, var2) ;
00081   frame->SetStats(kFALSE);
00082   
00083   // draw a point at the current parameter values
00084   TMarker *point= new TMarker(var1.getVal(), var2.getVal(), 8);
00085   
00086   // remember our original value of ERRDEF
00087   Double_t errdef= gMinuit->fUp;
00088   
00089   TGraph* graph1 = 0;
00090   if(n1 > 0) {
00091     // set the value corresponding to an n1-sigma contour
00092     gMinuit->SetErrorDef(n1*n1*errdef);
00093     // calculate and draw the contour
00094     graph1= (TGraph*)gMinuit->Contour(25, index1, index2);
00095     fixGraph(graph1);
00096   }
00097   
00098   TGraph* graph2 = 0;
00099   if(n2 > 0) {
00100     // set the value corresponding to an n2-sigma contour
00101     gMinuit->SetErrorDef(n2*n2*errdef);
00102     // calculate and draw the contour
00103     graph2= (TGraph*)gMinuit->Contour(25, index1, index2);
00104     fixGraph(graph2,2);
00105   }
00106   
00107   TGraph* graph3 = 0;
00108   if(n3 > 0) {
00109     // set the value corresponding to an n3-sigma contour
00110     gMinuit->SetErrorDef(n3*n3*errdef);
00111     // calculate and draw the contour
00112     graph3= (TGraph*)gMinuit->Contour(25, index1, index2);
00113     fixGraph(graph3,3);
00114   }
00115   
00116   TGraph* graph4 = 0;
00117   if(n4 > 0) {
00118     // set the value corresponding to an n4-sigma contour
00119     gMinuit->SetErrorDef(n4*n4*errdef);
00120     // calculate and draw the contour
00121     graph4= (TGraph*)gMinuit->Contour(25, index1, index2);
00122     fixGraph(graph4,4);
00123   }
00124   
00125   TGraph* graph5 = 0;
00126   if(n5 > 0) {
00127     // set the value corresponding to an n5-sigma contour
00128     gMinuit->SetErrorDef(n5*n5*errdef);
00129     // calculate and draw the contour
00130     graph5= (TGraph*)gMinuit->Contour(25, index1, index2);
00131     fixGraph(graph5,5);
00132   }
00133   
00134   TGraph* graph6 = 0;
00135   if(n6 > 0) {
00136     // set the value corresponding to an n6-sigma contour
00137     gMinuit->SetErrorDef(n6*n6*errdef);
00138     // calculate and draw the contour
00139     graph6= (TGraph*)gMinuit->Contour(25, index1, index2);
00140     fixGraph(graph6,6);
00141   }
00142   // restore the original ERRDEF
00143   gMinuit->SetErrorDef(errdef);
00144   
00145   
00146   // Add all objects to the frame
00147   frame->addObject(point);
00148   if (graph1) frame->addObject(graph1, "C");
00149   if (graph2) frame->addObject(graph2, "C");
00150   if (graph3) frame->addObject(graph3, "C");
00151   if (graph4) frame->addObject(graph4, "C");
00152   if (graph5) frame->addObject(graph5, "C");
00153   if (graph6) frame->addObject(graph6, "C");
00154   
00155   return frame;
00156 }
00157 
00159 void rarMinuit::fixGraph(TGraph *graph, Int_t lineStyle) {
00160   if (!graph) return;
00161   // set line style
00162   graph->SetLineStyle(lineStyle);
00163   // add a point to form closure
00164   Int_t nPoint=graph->GetN();
00165   graph->Set(nPoint+1);
00166   Double_t x, y;
00167   graph->GetPoint(0, x, y);
00168   graph->SetPoint(nPoint, x, y);
00169   return;
00170 }
00171 

Generated on 30 Oct 2013 for RooRarFit by  doxygen 1.4.7