1 |
#include "PlotTools.h"
|
2 |
#include "SusyScan.h"
|
3 |
#include "GeneratorMasses.h"
|
4 |
|
5 |
#include <cmath>
|
6 |
#include <algorithm>
|
7 |
|
8 |
#include "TGraph.h"
|
9 |
#include "TH2.h"
|
10 |
#include "TH2F.h"
|
11 |
#include "TObjArray.h"
|
12 |
#include "TPad.h"
|
13 |
#include "TCanvas.h"
|
14 |
#include "TRint.h"
|
15 |
#include "TROOT.h"
|
16 |
|
17 |
template<class T>
|
18 |
TGraph * PlotTools<T>::Line( double(*x)(const T*), double(*y)(const T*),
|
19 |
double(*func)(const T*), const double mass, const double diff )
|
20 |
{
|
21 |
TGraph * result = new TGraph(1);
|
22 |
std::sort(_scan->begin(),_scan->end(),sort_by(x));
|
23 |
int i=0;
|
24 |
for (typename std::vector<T*>::const_iterator it=_scan->begin();it!=_scan->end();++it){
|
25 |
if ( fabs(func( *it)-mass)<diff )
|
26 |
result->SetPoint(i++, x(*it), y(*it));
|
27 |
}
|
28 |
return result;
|
29 |
}
|
30 |
|
31 |
|
32 |
template<class T>
|
33 |
void PlotTools<T>::Area( TH2*h, double(*x)(const T*), double(*y)(const T*),
|
34 |
double(*f)(const T*) )
|
35 |
{
|
36 |
for (typename std::vector<T*>::const_iterator it=_scan->begin();it!=_scan->end();++it){
|
37 |
h->SetBinContent( h->GetXaxis()->FindBin(x(*it)),
|
38 |
h->GetYaxis()->FindBin(y(*it)), f(*it) );
|
39 |
}
|
40 |
}
|
41 |
|
42 |
template<class T>
|
43 |
std::vector<TGraph*> PlotTools<T>::GetContours(TH2*h, int ncont)
|
44 |
{
|
45 |
if (!h) return std::vector<TGraph*>();
|
46 |
TH2 * plot = (TH2*)h->Clone();
|
47 |
plot->SetContour(ncont);
|
48 |
|
49 |
plot->SetFillColor(1);
|
50 |
plot->Draw("CONT Z List");
|
51 |
gPad->Update();
|
52 |
TObjArray *contours = (TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours");
|
53 |
int ncontours = contours->GetSize();
|
54 |
//std::cout << "N contours = " << ncontours << std::endl;
|
55 |
std::vector<TGraph*> result;
|
56 |
for (int i=0;i<ncontours;++i){
|
57 |
TList *list = (TList*)contours->At(i);
|
58 |
TGraph* curv = (TGraph*)list->First();
|
59 |
if (curv) result.push_back( curv );
|
60 |
for(int j = 0; j < list->GetSize(); j++){
|
61 |
curv = (TGraph*)list->After(curv); // Get Next graph
|
62 |
if (curv) result.push_back( curv );
|
63 |
}
|
64 |
}
|
65 |
delete plot;
|
66 |
return result;
|
67 |
}
|
68 |
|
69 |
template<class T>
|
70 |
TGraph * PlotTools<T>::GetContour(TH2*h, int ncont, int flag)
|
71 |
{
|
72 |
return (TGraph*)GetContours(h, ncont).at(flag)->Clone();
|
73 |
}
|
74 |
|
75 |
/*
|
76 |
template<class T>
|
77 |
TGraph * PlotTools<T>::GetContour(TH2*h, int ncont, int flag)
|
78 |
{
|
79 |
if (!h) return 0;
|
80 |
TH2 * plot = (TH2*)h->Clone();
|
81 |
plot->SetContour(ncont);
|
82 |
plot->SetFillColor(1);
|
83 |
plot->Draw("CONT Z List");
|
84 |
gPad->Update();
|
85 |
TObjArray *contours = (TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours");
|
86 |
int ncontours = contours->GetSize();
|
87 |
TList *list = 0;
|
88 |
TGraph *gr1 = 0;
|
89 |
if (flag<ncontours) list = (TList*)contours->At(flag);
|
90 |
if (list) gr1 = (TGraph*)list->First()->Clone();
|
91 |
if (gr1) gr1->SetLineWidth(2);
|
92 |
if (plot) delete plot;
|
93 |
//don't delete contours or list: These belongs to gROOT !!!
|
94 |
return gr1;
|
95 |
}
|
96 |
*/
|
97 |
|
98 |
template class PlotTools<SusyScan>;
|
99 |
template class PlotTools<GeneratorMasses>;
|