// @(#)root/roostats:$Id$
// Author: Sven Kreiss   June 2010
/*************************************************************************
 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

/**
 * Class HypoTestPlot
 * This class provides the plots for the result of a study performed with e.g. the
 * HybridCalculator2 class.
 */


#include "RooStats/HypoTestPlot.h"
#include "TStyle.h"

ClassImp(RooStats::HypoTestPlot)

using namespace RooStats;
using namespace std;

HypoTestPlot::HypoTestPlot(HypoTestResult& result, Int_t bins, Option_t* opt) :
   SamplingDistPlot(bins),
   fHypoTestResult(&result)
{
   ApplyResult(result, opt);
}
HypoTestPlot::HypoTestPlot(HypoTestResult& result, Int_t bins, Double_t min, Double_t max, Option_t* opt) :
   SamplingDistPlot(bins,min,max),
   fHypoTestResult(&result)
{
   ApplyResult(result, opt);
}

void HypoTestPlot::ApplyResult(HypoTestResult& result, Option_t* opt) {
   fLegend = new TLegend(0.55,0.95-0.3*0.66,0.95,0.95);

   const SamplingDistribution *alt = result.GetAltDistribution();
   const SamplingDistribution *null = result.GetNullDistribution();
   if(!result.HasTestStatisticData()) {
      if(alt) AddSamplingDistribution(alt, opt);
      if(null) AddSamplingDistribution(null, opt);
   }else{
      if(result.GetPValueIsRightTail()) {
         if(alt) AddSamplingDistributionShaded(alt, result.GetTestStatisticData(), RooNumber::infinity(), opt);
         if(null) AddSamplingDistributionShaded(null, result.GetTestStatisticData(), RooNumber::infinity() , opt);
      }else{
         if(alt) AddSamplingDistributionShaded(alt, -RooNumber::infinity(), result.GetTestStatisticData(), opt);
         if(null) AddSamplingDistributionShaded(null, - RooNumber::infinity(), result.GetTestStatisticData() , opt);
      }
   }

   if(result.HasTestStatisticData()) {
      Double_t theMin(0.), theMax(0.), theYMax(0.);
      GetAbsoluteInterval(theMin, theMax, theYMax);

      AddLine(result.GetTestStatisticData(), 0, result.GetTestStatisticData(), theYMax*0.66, "test statistic data");
   }

   ApplyDefaultStyle();
}

void HypoTestPlot::ApplyDefaultStyle(void) {
   if(!fHypoTestResult) return;

   const SamplingDistribution *alt = fHypoTestResult->GetAltDistribution();
   const SamplingDistribution *null = fHypoTestResult->GetNullDistribution();

   if(alt) {
      SetLineWidth(2, alt);
      SetLineColor(kBlue, alt);
   }
   if(null) {
      SetLineWidth(2, null);
      SetLineColor(kRed, null);
   }
}
 HypoTestPlot.cxx:1
 HypoTestPlot.cxx:2
 HypoTestPlot.cxx:3
 HypoTestPlot.cxx:4
 HypoTestPlot.cxx:5
 HypoTestPlot.cxx:6
 HypoTestPlot.cxx:7
 HypoTestPlot.cxx:8
 HypoTestPlot.cxx:9
 HypoTestPlot.cxx:10
 HypoTestPlot.cxx:11
 HypoTestPlot.cxx:12
 HypoTestPlot.cxx:13
 HypoTestPlot.cxx:14
 HypoTestPlot.cxx:15
 HypoTestPlot.cxx:16
 HypoTestPlot.cxx:17
 HypoTestPlot.cxx:18
 HypoTestPlot.cxx:19
 HypoTestPlot.cxx:20
 HypoTestPlot.cxx:21
 HypoTestPlot.cxx:22
 HypoTestPlot.cxx:23
 HypoTestPlot.cxx:24
 HypoTestPlot.cxx:25
 HypoTestPlot.cxx:26
 HypoTestPlot.cxx:27
 HypoTestPlot.cxx:28
 HypoTestPlot.cxx:29
 HypoTestPlot.cxx:30
 HypoTestPlot.cxx:31
 HypoTestPlot.cxx:32
 HypoTestPlot.cxx:33
 HypoTestPlot.cxx:34
 HypoTestPlot.cxx:35
 HypoTestPlot.cxx:36
 HypoTestPlot.cxx:37
 HypoTestPlot.cxx:38
 HypoTestPlot.cxx:39
 HypoTestPlot.cxx:40
 HypoTestPlot.cxx:41
 HypoTestPlot.cxx:42
 HypoTestPlot.cxx:43
 HypoTestPlot.cxx:44
 HypoTestPlot.cxx:45
 HypoTestPlot.cxx:46
 HypoTestPlot.cxx:47
 HypoTestPlot.cxx:48
 HypoTestPlot.cxx:49
 HypoTestPlot.cxx:50
 HypoTestPlot.cxx:51
 HypoTestPlot.cxx:52
 HypoTestPlot.cxx:53
 HypoTestPlot.cxx:54
 HypoTestPlot.cxx:55
 HypoTestPlot.cxx:56
 HypoTestPlot.cxx:57
 HypoTestPlot.cxx:58
 HypoTestPlot.cxx:59
 HypoTestPlot.cxx:60
 HypoTestPlot.cxx:61
 HypoTestPlot.cxx:62
 HypoTestPlot.cxx:63
 HypoTestPlot.cxx:64
 HypoTestPlot.cxx:65
 HypoTestPlot.cxx:66
 HypoTestPlot.cxx:67
 HypoTestPlot.cxx:68
 HypoTestPlot.cxx:69
 HypoTestPlot.cxx:70
 HypoTestPlot.cxx:71
 HypoTestPlot.cxx:72
 HypoTestPlot.cxx:73
 HypoTestPlot.cxx:74
 HypoTestPlot.cxx:75
 HypoTestPlot.cxx:76
 HypoTestPlot.cxx:77
 HypoTestPlot.cxx:78
 HypoTestPlot.cxx:79
 HypoTestPlot.cxx:80
 HypoTestPlot.cxx:81