1 |
kukartse |
1.1 |
#include "tmvaglob.C"
|
2 |
|
|
|
3 |
|
|
// this macro plots the mu-transformation results of the MVA output
|
4 |
|
|
// variables from the various MVA methods run in TMVA (e.g. running
|
5 |
|
|
// TMVAnalysis.C). Since the mu-transform is flat for background, only
|
6 |
|
|
// signal is shown. The more signal ispeaked towards one, the better is
|
7 |
|
|
// the discrimination of the MVA method. See this reference for more
|
8 |
|
|
// information (in French):
|
9 |
|
|
// http://tel.archives-ouvertes.fr/documents/archives0/00/00/29/91/index_fr.html
|
10 |
|
|
//
|
11 |
|
|
// input: - Input file (result from TMVA),
|
12 |
|
|
// - use log/lin scale
|
13 |
|
|
// - use of TMVA plotting TStyle
|
14 |
|
|
void mutransform( TString fin = "TMVA.root", Bool_t logy = kFALSE, Bool_t useTMVAStyle = kTRUE )
|
15 |
|
|
{
|
16 |
|
|
// set style and remove existing canvas'
|
17 |
|
|
TMVAGlob::Initialize( useTMVAStyle );
|
18 |
|
|
|
19 |
|
|
// checks if file with name "fin" is already open, and if not opens one
|
20 |
|
|
TFile* file = TMVAGlob::OpenFile( fin );
|
21 |
|
|
|
22 |
|
|
// the coordinates
|
23 |
|
|
Float_t x1 = 0.0;
|
24 |
|
|
Float_t x2 = 1;
|
25 |
|
|
Float_t y1 = 0;
|
26 |
|
|
Float_t y2 = -1;
|
27 |
|
|
Float_t ys = 1.08;
|
28 |
|
|
|
29 |
|
|
enum { nskip = 1 };
|
30 |
|
|
TString hskip[nskip] = { "Variable" };
|
31 |
|
|
|
32 |
|
|
// loop over all histograms with that name
|
33 |
|
|
// search for maximum ordinate
|
34 |
|
|
TIter next(file->GetListOfKeys());
|
35 |
|
|
TKey *key, *hkey;
|
36 |
|
|
Int_t nmva = 0;
|
37 |
|
|
TString hName = "muTransform_S"; // ignore background
|
38 |
|
|
while (key = (TKey*)next()) {
|
39 |
|
|
|
40 |
|
|
if (TString(key->GetClassName()) != "TDirectory" && TString(key->GetClassName()) != "TDirectoryFile") continue;
|
41 |
|
|
if(! TString(key->GetName()).BeginsWith("Method_") ) continue;
|
42 |
|
|
|
43 |
|
|
TDirectory * mDir = (TDirectory*)key->ReadObj();
|
44 |
|
|
TIter nextInMDir(mDir->GetListOfKeys());
|
45 |
|
|
while (hkey = (TKey*)nextInMDir()) {
|
46 |
|
|
TClass *cl = gROOT->GetClass(hkey->GetClassName());
|
47 |
|
|
if (!cl->InheritsFrom("TH1")) continue;
|
48 |
|
|
TH1 *h = (TH1*)hkey->ReadObj();
|
49 |
|
|
Bool_t skip = !TString(h->GetName()).Contains( hName );
|
50 |
|
|
for (Int_t iskip=0; iskip<nskip; iskip++)
|
51 |
|
|
if (TString(h->GetName()).Contains( hskip[iskip] )) skip = kTRUE;
|
52 |
|
|
if (!skip) {
|
53 |
|
|
if (h->GetMaximum() > y2) y2 = h->GetMaximum()*ys;
|
54 |
|
|
nmva++;
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
|
|
}
|
58 |
|
|
if (y2 == -1) {
|
59 |
|
|
cout << "No mu-transforms found" << endl;
|
60 |
|
|
return;
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
// create canvas
|
64 |
|
|
TCanvas* c = new TCanvas( "c", "the canvas", 150, 0, 650, 500 );
|
65 |
|
|
|
66 |
|
|
// global style settings
|
67 |
|
|
c->SetTicks();
|
68 |
|
|
if (logy) {
|
69 |
|
|
y1 = 0.1;
|
70 |
|
|
ys = 2.0;
|
71 |
|
|
c->SetLogy();
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
// legend
|
75 |
|
|
Float_t x0L = 0.140, y0H = 0.86;
|
76 |
|
|
Float_t dxL = 0.48, dyH = 0.22;
|
77 |
|
|
TLegend *legend = new TLegend( x0L, y0H-dyH, x0L+dxL, y0H );
|
78 |
|
|
legend->SetTextSize( 0.05 );
|
79 |
|
|
legend->SetHeader( "TMVA Classifier:" );
|
80 |
|
|
legend->SetMargin( 0.4 );
|
81 |
|
|
|
82 |
|
|
TString xtit = "mu-transform";
|
83 |
|
|
TString ytit = "";
|
84 |
|
|
TString ftit = "Signal " + xtit;
|
85 |
|
|
|
86 |
|
|
cout << "--- set frame maximum to: " << y2 << endl;
|
87 |
|
|
next.Reset();
|
88 |
|
|
|
89 |
|
|
// rescale legend box size
|
90 |
|
|
// current box size has been tuned for 3 MVAs + 1 title
|
91 |
|
|
dyH *= (1.0 + Float_t(nmva - 3.0)/4.0);
|
92 |
|
|
legend->SetY1( y0H - dyH );
|
93 |
|
|
|
94 |
|
|
// draw empty frame
|
95 |
|
|
TH2F* frame = new TH2F( "frame", ftit, 500, x1, x2, 500, y1, y2 );
|
96 |
|
|
frame->GetXaxis()->SetTitle( xtit );
|
97 |
|
|
frame->GetYaxis()->SetTitle( ytit );
|
98 |
|
|
TMVAGlob::SetFrameStyle( frame, 1.0 );
|
99 |
|
|
|
100 |
|
|
frame->Draw();
|
101 |
|
|
|
102 |
|
|
// loop over all histograms with that name
|
103 |
|
|
// plot
|
104 |
|
|
Int_t color = 1;
|
105 |
|
|
while (key = (TKey*)next()) {
|
106 |
|
|
if( TString(key->GetClassName()) != "TDirectory" ) continue;
|
107 |
|
|
if(! TString(key->GetName()).BeginsWith("Method_") ) continue;
|
108 |
|
|
|
109 |
|
|
TDirectory * mDir = (TDirectory*)key->ReadObj();
|
110 |
|
|
TIter nextInMDir(mDir->GetListOfKeys());
|
111 |
|
|
while (hkey = (TKey*)nextInMDir()) {
|
112 |
|
|
TClass *cl = gROOT->GetClass(hkey->GetClassName());
|
113 |
|
|
if (!cl->InheritsFrom("TH1")) continue;
|
114 |
|
|
TH1 *h = (TH1*)hkey->ReadObj();
|
115 |
|
|
Bool_t skip = !TString(h->GetName()).Contains( hName );
|
116 |
|
|
for (Int_t iskip=0; iskip<nskip; iskip++)
|
117 |
|
|
if (TString(h->GetName()).Contains( hskip[iskip] )) skip = kTRUE;
|
118 |
|
|
if (!skip) {
|
119 |
|
|
// signal or background ?
|
120 |
|
|
if (TString(h->GetName()).Contains( "_S" )) {
|
121 |
|
|
h->SetLineStyle( 1 );
|
122 |
|
|
h->SetLineWidth( 3 );
|
123 |
|
|
}
|
124 |
|
|
else {
|
125 |
|
|
h->SetLineStyle( 2 );
|
126 |
|
|
h->SetLineWidth( 3 );
|
127 |
|
|
}
|
128 |
|
|
h->SetLineColor(color);
|
129 |
|
|
color++;
|
130 |
|
|
TString tit = h->GetTitle();
|
131 |
|
|
tit.ReplaceAll( "mu-Transform", "" );
|
132 |
|
|
tit.ReplaceAll( "(S)", "" );
|
133 |
|
|
tit.ReplaceAll( ":", "" );
|
134 |
|
|
legend->AddEntry( h, tit, "l" );
|
135 |
|
|
h->Draw("same");
|
136 |
|
|
}
|
137 |
|
|
}
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
// redraw axes
|
141 |
|
|
frame->Draw("sameaxis");
|
142 |
|
|
|
143 |
|
|
legend->Draw("same");
|
144 |
|
|
c->Update();
|
145 |
|
|
|
146 |
|
|
TString fname = "plots/mutransform";
|
147 |
|
|
TMVAGlob::imgconv( c, fname );
|
148 |
|
|
}
|
149 |
|
|
|