35 const
std::vector<
double> & sb_vals,
36 const
std::vector<
double> & b_vals,
42 fSb_histo_shaded(NULL),
44 fB_histo_shaded(NULL),
45 fData_testStat_line(0),
52 int nToysSB = sb_vals.size();
53 int nToysB = sb_vals.size();
58 double min = *std::min_element(sb_vals.begin(), sb_vals.end());
59 double max = *std::max_element(sb_vals.begin(), sb_vals.end());
61 double min_b = *std::min_element(b_vals.begin(), b_vals.end());
62 double max_b = *std::max_element(b_vals.begin(), b_vals.end());
65 if ( min_b < min) min = min_b;
66 if ( max_b > max) max = max_b;
68 if (testStat_data<min) min = testStat_data;
69 if (testStat_data>max) max = testStat_data;
76 fSb_histo =
new TH1F (
"SB_model",title,n_bins,min,max);
77 fSb_histo->SetTitle(fSb_histo->GetTitle());
78 fSb_histo->SetLineColor(
kBlue);
79 fSb_histo->GetXaxis()->SetTitle(
"test statistics");
80 fSb_histo->SetLineWidth(2);
82 fB_histo =
new TH1F (
"B_model",title,n_bins,min,max);
83 fB_histo->SetTitle(fB_histo->GetTitle());
84 fB_histo->SetLineColor(
kRed);
85 fB_histo->GetXaxis()->SetTitle(
"test statistics");
86 fB_histo->SetLineWidth(2);
88 for (
int i=0;i<nToysSB;++i) fSb_histo->Fill(sb_vals[i]);
89 for (
int i=0;i<nToysB;++i) fB_histo->Fill(b_vals[i]);
91 double histos_max_y = fSb_histo->GetMaximum();
92 double line_hight = histos_max_y/nToysSB;
93 if (histos_max_y<fB_histo->GetMaximum()) histos_max_y = fB_histo->GetMaximum()/nToysB;
96 fData_testStat_line =
new TLine(testStat_data,0,testStat_data,line_hight);
97 fData_testStat_line->SetLineWidth(3);
98 fData_testStat_line->SetLineColor(
kBlack);
101 double golden_section = (
std::sqrt(5.)-1)/2;
103 fLegend =
new TLegend(0.75,0.95-0.2*golden_section,0.95,0.95);
104 TString title_leg=
"test statistics distributions ";
105 title_leg+=sb_vals.size();
107 fLegend->SetName(title_leg.
Data());
108 fLegend->AddEntry(fSb_histo,
"SB toy datasets");
109 fLegend->AddEntry(fB_histo,
"B toy datasets");
110 fLegend->AddEntry((
TLine*)fData_testStat_line,
"test statistics on data",
"L");
111 fLegend->SetFillColor(0);
117 HybridPlot::~HybridPlot()
121 if (fSb_histo)
delete fSb_histo;
122 if (fB_histo)
delete fB_histo;
123 if (fSb_histo_shaded)
delete fSb_histo_shaded;
124 if (fB_histo_shaded)
delete fB_histo_shaded;
125 if (fData_testStat_line)
delete fData_testStat_line;
126 if (fLegend)
delete fLegend;
141 if (fSb_histo->GetMaximum()>fB_histo->GetMaximum()){
142 fSb_histo->DrawNormalized();
143 fB_histo->DrawNormalized(
"same");
146 fB_histo->DrawNormalized();
147 fSb_histo->DrawNormalized(
"same");
151 fB_histo_shaded = (
TH1F*)fB_histo->Clone(
"b_shaded");
152 fB_histo_shaded->SetFillStyle(3005);
153 fB_histo_shaded->SetFillColor(
kRed);
155 fSb_histo_shaded = (
TH1F*)fSb_histo->Clone(
"sb_shaded");
156 fSb_histo_shaded->SetFillStyle(3004);
157 fSb_histo_shaded->SetFillColor(
kBlue);
160 double data_m2lnq= fData_testStat_line->GetX1();
161 for (
int i=1;i<=fSb_histo->GetNbinsX();++i){
162 if (fSb_histo->GetBinCenter(i)<data_m2lnq){
163 fSb_histo_shaded->SetBinContent(i,0);
164 fB_histo_shaded->SetBinContent(i,fB_histo->GetBinContent(i)/fB_histo->GetSumOfWeights());
167 fB_histo_shaded->SetBinContent(i,0);
168 fSb_histo_shaded->SetBinContent(i,fSb_histo->GetBinContent(i)/fSb_histo->GetSumOfWeights());
173 fB_histo_shaded->Draw(
"same");
174 fSb_histo_shaded->Draw(
"same");
177 fData_testStat_line->Draw(
"same");
180 fLegend->Draw(
"same");
183 gPad->SetName(GetName());
184 gPad->SetTitle(GetTitle() );
193 void HybridPlot::DumpToFile (
const char* RootFileName,
const char* options)
197 TFile ofile(RootFileName,options);
205 if (fB_histo_shaded!=
NULL && fSb_histo_shaded!=
NULL){
206 fB_histo_shaded->Write();
207 fSb_histo_shaded->Write();
211 fData_testStat_line->Write(
"Measured test statistics line tag");
220 void HybridPlot::DumpToImage(
const char *
filename) {
222 Error(
"HybridPlot",
"Hybrid plot has not yet been drawn ");
225 fPad->Print(filename);
238 double HybridPlot::GetHistoCenter(
TH1* histo_orig,
double n_rms,
bool display_result){
242 if (display_result) optfit =
"Q";
252 TF1* gaus =
new TF1(
"mygaus",
"gaus", x_min, x_max);
258 histo->
Fit(gaus,optfit);
266 std::cout <<
"Center is 1st pass = " << mean << std::endl;
270 x_min = mean - n_rms*sigma - sigma*skewness/2;
271 x_max = mean + n_rms*sigma - sigma*skewness/2;;
273 TF1* gaus2 =
new TF1(
"mygaus2",
"gaus", x_min, x_max);
278 histo->
Fit(gaus2,optfit,
"", x_min, x_max);
283 if (display_result) {
302 double* HybridPlot::GetHistoPvals (
TH1* histo,
double percentage){
305 std::cerr <<
"Percentage greater or equal to 1!\n";
313 std::map<int,int> extremes_map;
317 double integral = h_integral[j]-h_integral[i];
318 if (integral>percentage){
326 std::map<int,int>::iterator it;
328 double left_bin_center(0.),right_bin_center(0.);
331 for (it = extremes_map.begin();it != extremes_map.end();++it){
335 if (current_diff<diff){
343 double* d =
new double[2];
344 d[0]=left_bin_center;
345 d[1]=right_bin_center;
353 double HybridPlot::GetMedian(
TH1* histo){
366 (0.5-integral[median_i])/(integral[median_i+1]-integral[median_i]);
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
This class displays a legend box (TPaveText) containing several legend entries.
R__EXTERN TStyle * gStyle
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
static const char * filename()
1-D histogram with a float per channel (see TH1 documentation)}
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
virtual Int_t GetNbinsX() const
virtual Double_t GetEntries() const
return the current number of entries
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
const char * Data() const
virtual Double_t GetSkewness(Int_t axis=1) const
For axis = 1, 2 or 3 returns skewness of the histogram along x, y or z axis.
The TNamed class is the base class for all named ROOT classes.
This class provides the plots for the result of a study performed with the HybridCalculatorOriginal c...
ClassImp(RooStats::HybridPlot) using namespace RooStats
void Error(const char *location, const char *msgfmt,...)
virtual Double_t * GetIntegral()
Return a pointer to the array of bins integral.
virtual Double_t GetBinCenter(Int_t bin) const
return bin center for 1D historam Better to use h1.GetXaxis().GetBinCenter(bin)
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
virtual Double_t GetMean(Int_t axis=1) const
For axis = 1,2 or 3 returns the mean value of the histogram along X,Y or Z axis.
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Double_t GetRMS(Int_t axis=1) const
Namespace for the RooStats classes.
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
virtual Double_t GetParameter(Int_t ipar) const
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
virtual void SetParameter(Int_t param, Double_t value)
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
Fit histogram with function fname.
virtual void Close(Option_t *option="")
Close a file.