ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/auterman/SusyScan/PlotScript/PlotTools.cc
Revision: 1.4
Committed: Fri Jan 7 17:14:48 2011 UTC (14 years, 4 months ago) by auterman
Content type: text/plain
Branch: MAIN
Changes since 1.3: +18 -6 lines
Log Message:
fixing Profile drawing

File Contents

# User Rev Content
1 auterman 1.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 auterman 1.4 #include "TCanvas.h"
14 auterman 1.1 #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 auterman 1.2 double(*func)(const T*), const double mass, const double diff )
20 auterman 1.1 {
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 auterman 1.2 double(*f)(const T*) )
35 auterman 1.1 {
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 auterman 1.3 std::vector<TGraph*> PlotTools<T>::GetContours(TH2*h, int ncont)
44 auterman 1.1 {
45 auterman 1.3 if (!h) return std::vector<TGraph*>();
46     TH2 * plot = (TH2*)h->Clone();
47     plot->SetContour(ncont);
48    
49 auterman 1.1 plot->SetFillColor(1);
50 auterman 1.4 plot->Draw("CONT Z List");
51 auterman 1.1 gPad->Update();
52     TObjArray *contours = (TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours");
53     int ncontours = contours->GetSize();
54     //std::cout << "N contours = " << ncontours << std::endl;
55 auterman 1.3 std::vector<TGraph*> result;
56     for (int i=0;i<ncontours;++i){
57     TList *list = (TList*)contours->At(i);
58 auterman 1.4 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 auterman 1.3 }
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 auterman 1.4 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 auterman 1.3 if (!h) return 0;
80     TH2 * plot = (TH2*)h->Clone();
81     plot->SetContour(ncont);
82     plot->SetFillColor(1);
83 auterman 1.4 plot->Draw("CONT Z List");
84 auterman 1.3 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 auterman 1.4 //don't delete contours or list: These belongs to gROOT !!!
94 auterman 1.1 return gr1;
95     }
96 auterman 1.4 */
97 auterman 1.1
98     template class PlotTools<SusyScan>;
99     template class PlotTools<GeneratorMasses>;