Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Tools.cxx
Go to the documentation of this file.
1// @(#)root/tmva $Id$
2// Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss, Jan Therhaag
3
4/**********************************************************************************
5 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6 * Package: TMVA *
7 * Class : Tools *
8 * Web : http://tmva.sourceforge.net *
9 * *
10 * Description: *
11 * Implementation (see header for description) *
12 * *
13 * Authors (alphabetical): *
14 * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15 * Peter Speckmayer <Peter.Speckmayer@cern.ch> - CERN, Switzerland *
16 * Jan Therhaag <Jan.Therhaag@cern.ch> - U of Bonn, Germany *
17 * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
18 * Kai Voss <Kai.Voss@cern.ch> - U. of Victoria, Canada *
19 * *
20 * Copyright (c) 2005-2011: *
21 * CERN, Switzerland *
22 * U. of Victoria, Canada *
23 * MPI-K Heidelberg, Germany *
24 * U. of Bonn, Germany *
25 * *
26 * Redistribution and use in source and binary forms, with or without *
27 * modification, are permitted according to the terms listed in LICENSE *
28 * (http://tmva.sourceforge.net/LICENSE) *
29 **********************************************************************************/
30
31/*! \class TMVA::Tools
32\ingroup TMVA
33Global auxiliary applications and data treatment routines.
34*/
35
36#include "TMVA/Tools.h"
37
38#include "TMVA/Config.h"
39#include "TMVA/Event.h"
40#include "TMVA/Version.h"
41#include "TMVA/PDF.h"
42#include "TMVA/MsgLogger.h"
43#include "TMVA/Types.h"
44
45#include "TObjString.h"
46#include "TMath.h"
47#include "TString.h"
48#include "TTree.h"
49#include "TLeaf.h"
50#include "TH1.h"
51#include "TH2.h"
52#include "TList.h"
53#include "TSpline.h"
54#include "TVector.h"
55#include "TMatrixD.h"
56#include "TMatrixDSymEigen.h"
57#include "TVectorD.h"
58#include "TTreeFormula.h"
59#include "TXMLEngine.h"
60#include "TROOT.h"
61
62#include <algorithm>
63#include <cstdlib>
64#include <iomanip>
65
66using namespace std;
67
68std::atomic<TMVA::Tools*> TMVA::Tools::fgTools{0};
69
72 if(!fgTools) {
73 Tools* tmp = new Tools();
74 Tools* expected = 0;
75 if(! fgTools.compare_exchange_strong(expected,tmp)) {
76 //another thread beat us
77 delete tmp;
78 }
79 }
80 return *fgTools;
81}
83 //NOTE: there is no thread safe way to do this so
84 // one must only call this method ones in an executable
85 if (fgTools != 0) { delete fgTools.load(); fgTools=0; }
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// constructor
90
92 fRegexp("$&|!%^&()'<>?= "),
93 fLogger(new MsgLogger("Tools")),
94 fXMLEngine(new TXMLEngine())
95{
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// destructor
100
102{
103 delete fLogger;
104 delete fXMLEngine;
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// normalise to output range: [-1, 1]
109
111{
112 return 2*(x - xmin)/(xmax - xmin) - 1.0;
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// compute "separation" defined as
117/// \f[
118/// <s2> = \frac{1}{2} \int_{-\infty}^{+\infty} \frac{(S(x) - B(x))^2}{(S(x) + B(x))} dx
119/// \f]
120
122{
123 Double_t separation = 0;
124
125 // sanity checks
126 // signal and background histograms must have same number of bins and
127 // same limits
128 if ((S->GetNbinsX() != B->GetNbinsX()) || (S->GetNbinsX() <= 0)) {
129 Log() << kFATAL << "<GetSeparation> signal and background"
130 << " histograms have different number of bins: "
131 << S->GetNbinsX() << " : " << B->GetNbinsX() << Endl;
132 }
133
134 if (S->GetXaxis()->GetXmin() != B->GetXaxis()->GetXmin() ||
135 S->GetXaxis()->GetXmax() != B->GetXaxis()->GetXmax() ||
136 S->GetXaxis()->GetXmax() <= S->GetXaxis()->GetXmin()) {
137 Log() << kINFO << S->GetXaxis()->GetXmin() << " " << B->GetXaxis()->GetXmin()
138 << " " << S->GetXaxis()->GetXmax() << " " << B->GetXaxis()->GetXmax()
139 << " " << S->GetXaxis()->GetXmax() << " " << S->GetXaxis()->GetXmin() << Endl;
140 Log() << kFATAL << "<GetSeparation> signal and background"
141 << " histograms have different or invalid dimensions:" << Endl;
142 }
143
144 Int_t nstep = S->GetNbinsX();
145 Double_t intBin = (S->GetXaxis()->GetXmax() - S->GetXaxis()->GetXmin())/nstep;
146 Double_t nS = S->GetSumOfWeights()*intBin;
147 Double_t nB = B->GetSumOfWeights()*intBin;
148
149 if (nS > 0 && nB > 0) {
150 for (Int_t bin=0; bin<nstep; bin++) {
151 Double_t s = S->GetBinContent( bin+1 )/Double_t(nS);
152 Double_t b = B->GetBinContent( bin+1 )/Double_t(nB);
153 // separation
154 if (s + b > 0) separation += (s - b)*(s - b)/(s + b);
155 }
156 separation *= (0.5*intBin);
157 }
158 else {
159 Log() << kWARNING << "<GetSeparation> histograms with zero entries: "
160 << nS << " : " << nB << " cannot compute separation"
161 << Endl;
162 separation = 0;
163 }
164
165 return separation;
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// compute "separation" defined as
170/// \f[
171/// <s2> = \frac{1}{2} \int_{-\infty}^{+\infty} \frac{(S(x) - B(x))^2}{(S(x) + B(x))} dx
172/// \f]
173
174Double_t TMVA::Tools::GetSeparation( const PDF& pdfS, const PDF& pdfB ) const
175{
176 Double_t xmin = pdfS.GetXmin();
177 Double_t xmax = pdfS.GetXmax();
178 // sanity check
179 if (xmin != pdfB.GetXmin() || xmax != pdfB.GetXmax()) {
180 Log() << kFATAL << "<GetSeparation> Mismatch in PDF limits: "
181 << xmin << " " << pdfB.GetXmin() << xmax << " " << pdfB.GetXmax() << Endl;
182 }
183
184 Double_t separation = 0;
185 Int_t nstep = 100;
186 Double_t intBin = (xmax - xmin)/Double_t(nstep);
187 for (Int_t bin=0; bin<nstep; bin++) {
188 Double_t x = (bin + 0.5)*intBin + xmin;
189 Double_t s = pdfS.GetVal( x );
190 Double_t b = pdfB.GetVal( x );
191 // separation
192 if (s + b > 0) separation += (s - b)*(s - b)/(s + b);
193 }
194 separation *= (0.5*intBin);
195
196 return separation;
197}
198
199////////////////////////////////////////////////////////////////////////////////
200/// sanity check
201
202void TMVA::Tools::ComputeStat( const std::vector<TMVA::Event*>& events, std::vector<Float_t>* valVec,
203 Double_t& meanS, Double_t& meanB,
204 Double_t& rmsS, Double_t& rmsB,
206 Int_t signalClass, Bool_t norm )
207{
208 if (0 == valVec)
209 Log() << kFATAL << "<Tools::ComputeStat> value vector is zero pointer" << Endl;
210
211 if ( events.size() != valVec->size() )
212 Log() << kWARNING << "<Tools::ComputeStat> event and value vector have different lengths "
213 << events.size() << "!=" << valVec->size() << Endl;
214
215 Long64_t entries = valVec->size();
216
217 // first fill signal and background in arrays before analysis
218 Double_t* varVecS = new Double_t[entries];
219 Double_t* varVecB = new Double_t[entries];
220 Double_t* wgtVecS = new Double_t[entries];
221 Double_t* wgtVecB = new Double_t[entries];
222 xmin = +DBL_MAX;
223 xmax = -DBL_MAX;
224 Long64_t nEventsS = 0;
225 Long64_t nEventsB = 0;
226 Double_t xmin_ = 0, xmax_ = 0;
227
228 if (norm) {
229 xmin_ = *std::min( valVec->begin(), valVec->end() );
230 xmax_ = *std::max( valVec->begin(), valVec->end() );
231 }
232
233 for (Int_t ievt=0; ievt<entries; ievt++) {
234 Double_t theVar = (*valVec)[ievt];
235 if (norm) theVar = Tools::NormVariable( theVar, xmin_, xmax_ );
236
237 if (Int_t(events[ievt]->GetClass()) == signalClass ){
238 wgtVecS[nEventsS] = events[ievt]->GetWeight(); // this is signal
239 varVecS[nEventsS++] = theVar; // this is signal
240 }
241 else {
242 wgtVecB[nEventsB] = events[ievt]->GetWeight(); // this is signal
243 varVecB[nEventsB++] = theVar; // this is background
244 }
245
246 if (theVar > xmax) xmax = theVar;
247 if (theVar < xmin) xmin = theVar;
248 }
249 // ++nEventsS;
250 // ++nEventsB;
251
252 // basic statistics
253 // !!! TMath::Mean allows for weights, but NOT for negative weights
254 // and TMath::RMS doesn't allow for weights all together...
255 meanS = TMVA::Tools::Mean( nEventsS, varVecS, wgtVecS );
256 meanB = TMVA::Tools::Mean( nEventsB, varVecB, wgtVecB );
257 rmsS = TMVA::Tools::RMS ( nEventsS, varVecS, wgtVecS );
258 rmsB = TMVA::Tools::RMS ( nEventsB, varVecB, wgtVecB );
259
260 delete [] varVecS;
261 delete [] varVecB;
262 delete [] wgtVecS;
263 delete [] wgtVecB;
264}
265
266////////////////////////////////////////////////////////////////////////////////
267/// square-root of symmetric matrix
268/// of course the resulting sqrtMat is also symmetric, but it's easier to
269/// treat it as a general matrix
270
272{
273 Int_t n = symMat->GetNrows();
274
275 // compute eigenvectors
276 TMatrixDSymEigen* eigen = new TMatrixDSymEigen( *symMat );
277
278 // D = ST C S
279 TMatrixD* si = new TMatrixD( eigen->GetEigenVectors() );
280 TMatrixD* s = new TMatrixD( *si ); // copy
281 si->Transpose( *si ); // invert (= transpose)
282
283 // diagonal matrices
284 TMatrixD* d = new TMatrixD( n, n);
285 d->Mult( (*si), (*symMat) ); (*d) *= (*s);
286
287 // sanity check: matrix must be diagonal and positive definit
288 Int_t i, j;
289 Double_t epsilon = 1.0e-8;
290 for (i=0; i<n; i++) {
291 for (j=0; j<n; j++) {
292 if ((i != j && TMath::Abs((*d)(i,j))/TMath::Sqrt((*d)(i,i)*(*d)(j,j)) > epsilon) ||
293 (i == j && (*d)(i,i) < 0)) {
294 //d->Print();
295 Log() << kWARNING << "<GetSQRootMatrix> error in matrix diagonalization; printed S and B" << Endl;
296 }
297 }
298 }
299
300 // make exactly diagonal
301 for (i=0; i<n; i++) for (j=0; j<n; j++) if (j != i) (*d)(i,j) = 0;
302
303 // compute the square-root C' of covariance matrix: C = C'*C'
304 for (i=0; i<n; i++) (*d)(i,i) = TMath::Sqrt((*d)(i,i));
305
306 TMatrixD* sqrtMat = new TMatrixD( n, n );
307 sqrtMat->Mult( (*s), (*d) );
308 (*sqrtMat) *= (*si);
309
310 // invert square-root matrices
311 sqrtMat->Invert();
312
313 delete eigen;
314 delete s;
315 delete si;
316 delete d;
317
318 return sqrtMat;
319}
320
321////////////////////////////////////////////////////////////////////////////////
322/// turns covariance into correlation matrix
323
325{
326
327 if (covMat == 0) return 0;
328 // sanity check
329 Int_t nvar = covMat->GetNrows();
330 if (nvar != covMat->GetNcols())
331 Log() << kFATAL << "<GetCorrelationMatrix> input matrix not quadratic" << Endl;
332
333 Log() << kWARNING;
334 TMatrixD* corrMat = new TMatrixD( nvar, nvar );
335 for (Int_t ivar=0; ivar<nvar; ivar++) {
336 for (Int_t jvar=0; jvar<nvar; jvar++) {
337 if (ivar != jvar) {
338 Double_t d = (*covMat)(ivar, ivar)*(*covMat)(jvar, jvar);
339 if (d > 1E-20) {
340 (*corrMat)(ivar, jvar) = (*covMat)(ivar, jvar)/TMath::Sqrt(d);
341 } else {
342 Log() << "<GetCorrelationMatrix> zero variances for variables "
343 << "(" << ivar << ", " << jvar << ")" << Endl;
344 (*corrMat)(ivar, jvar) = 0;
345 }
346 if (TMath::Abs( (*corrMat)(ivar,jvar)) > 1){
347 Log() << kWARNING
348 << " Element corr("<<ivar<<","<<ivar<<")=" << (*corrMat)(ivar,jvar)
349 << " sigma2="<<d
350 << " cov("<<ivar<<","<<ivar<<")=" <<(*covMat)(ivar, ivar)
351 << " cov("<<jvar<<","<<jvar<<")=" <<(*covMat)(jvar, jvar)
352 << Endl;
353
354 }
355 }
356 else (*corrMat)(ivar, ivar) = 1.0;
357 }
358 }
359 Log() << Endl;
360 return corrMat;
361}
362
363////////////////////////////////////////////////////////////////////////////////
364/// projects variable from tree into normalised histogram
365
366TH1* TMVA::Tools::projNormTH1F( TTree* theTree, const TString& theVarName,
367 const TString& name, Int_t nbins,
368 Double_t xmin, Double_t xmax, const TString& cut )
369{
370 // needed because of ROOT bug (feature) that excludes events that have value == xmax
371 xmax += 0.00001;
372
373 TH1* hist = new TH1F( name, name, nbins, xmin, xmax );
374 hist->Sumw2(); // enable quadratic errors
375 theTree->Project( name, theVarName, cut );
376 NormHist( hist );
377 return hist;
378}
379
380////////////////////////////////////////////////////////////////////////////////
381/// normalises histogram
382
384{
385 if (!theHist) return 0;
386
387 if (theHist->GetSumw2N() == 0) theHist->Sumw2();
388 if (theHist->GetSumOfWeights() != 0) {
389 Double_t w = ( theHist->GetSumOfWeights()
390 *(theHist->GetXaxis()->GetXmax() - theHist->GetXaxis()->GetXmin())/theHist->GetNbinsX() );
391 if (w > 0) theHist->Scale( norm/w );
392 return w;
393 }
394
395 return 1.0;
396}
397
398////////////////////////////////////////////////////////////////////////////////
399/// Parse the string and cut into labels separated by ":"
400
401TList* TMVA::Tools::ParseFormatLine( TString formatString, const char* sep )
402{
403 TList* labelList = new TList();
404 labelList->SetOwner();
405 while (formatString.First(sep)==0) formatString.Remove(0,1); // remove initial separators
406
407 while (formatString.Length()>0) {
408 if (formatString.First(sep) == -1) { // no more separator
409 labelList->Add(new TObjString(formatString.Data()));
410 formatString="";
411 break;
412 }
413
414 Ssiz_t posSep = formatString.First(sep);
415 labelList->Add(new TObjString(TString(formatString(0,posSep)).Data()));
416 formatString.Remove(0,posSep+1);
417
418 while (formatString.First(sep)==0) formatString.Remove(0,1); // remove additional separators
419
420 }
421 return labelList;
422}
423
424////////////////////////////////////////////////////////////////////////////////
425/// parse option string for ANN methods
426/// default settings (should be defined in theOption string)
427///
428/// format and syntax of option string: "3000:N:N+2:N-3:6"
429///
430/// where:
431/// - 3000 - number of training cycles (epochs)
432/// - N - number of nodes in first hidden layer, where N is the number
433/// of discriminating variables used (note that the first ANN
434/// layer necessarily has N nodes, and hence is not given).
435/// - N+2 - number of nodes in 2nd hidden layer (2 nodes more than
436/// number of variables)
437/// - N-3 - number of nodes in 3rd hidden layer (3 nodes less than
438/// number of variables)
439/// - 6 - 6 nodes in last (4th) hidden layer (note that the last ANN
440/// layer in MVA has 2 nodes, each one for signal and background
441/// classes)
442
443vector<Int_t>* TMVA::Tools::ParseANNOptionString( TString theOptions, Int_t nvar,
444 vector<Int_t>* nodes )
445{
446 TList* list = TMVA::Tools::ParseFormatLine( theOptions, ":" );
447
448
449 // sanity check
450 if (list->GetSize() < 1) {
451 Log() << kFATAL << "<ParseANNOptionString> unrecognized option string: " << theOptions << Endl;
452 }
453
454 // add number of cycles
455 nodes->push_back( atoi( ((TObjString*)list->At(0))->GetString() ) );
456
457 Int_t a;
458 if (list->GetSize() > 1) {
459 for (Int_t i=1; i<list->GetSize(); i++) {
460 TString s = ((TObjString*)list->At(i))->GetString();
461 s.ToUpper();
462 if (s(0) == 'N') {
463 if (s.Length() > 1) nodes->push_back( nvar + atoi(&s[1]) );
464 else nodes->push_back( nvar );
465 }
466 else if ((a = atoi( s )) > 0) nodes->push_back( atoi(s ) );
467 else {
468 Log() << kFATAL << "<ParseANNOptionString> unrecognized option string: " << theOptions << Endl;
469 }
470 }
471 }
472
473 return nodes;
474}
475
476////////////////////////////////////////////////////////////////////////////////
477/// check quality of splining by comparing splines and histograms in each bin
478
479Bool_t TMVA::Tools::CheckSplines( const TH1* theHist, const TSpline* theSpline )
480{
481 const Double_t sanityCrit = 0.01; // relative deviation
482
483 Bool_t retval = kTRUE;
484 for (Int_t ibin=1; ibin<=theHist->GetNbinsX(); ibin++) {
485 Double_t x = theHist->GetBinCenter( ibin );
486 Double_t yh = theHist->GetBinContent( ibin ); // the histogram output
487 Double_t ys = theSpline->Eval( x ); // the spline output
488
489 if (ys + yh > 0) {
490 Double_t dev = 0.5*(ys - yh)/(ys + yh);
491 if (TMath::Abs(dev) > sanityCrit) {
492 Log() << kFATAL << "<CheckSplines> Spline failed sanity criterion; "
493 << " relative deviation from histogram: " << dev
494 << " in (bin, value): (" << ibin << ", " << x << ")" << Endl;
495 retval = kFALSE;
496 }
497 }
498 }
499
500 return retval;
501}
502
503////////////////////////////////////////////////////////////////////////////////
504/// computes difference between two vectors
505
506std::vector<Double_t> TMVA::Tools::MVADiff( std::vector<Double_t>& a, std::vector<Double_t>& b )
507{
508 if (a.size() != b.size()) {
509 throw;
510 }
511 vector<Double_t> result(a.size());
512 for (UInt_t i=0; i<a.size();i++) result[i]=a[i]-b[i];
513 return result;
514}
515
516////////////////////////////////////////////////////////////////////////////////
517/// scales double vector
518
519void TMVA::Tools::Scale( std::vector<Double_t>& v, Double_t f )
520{
521 for (UInt_t i=0; i<v.size();i++) v[i]*=f;
522}
523
524////////////////////////////////////////////////////////////////////////////////
525/// scales float vector
526
527void TMVA::Tools::Scale( std::vector<Float_t>& v, Float_t f )
528{
529 for (UInt_t i=0; i<v.size();i++) v[i]*=f;
530}
531
532////////////////////////////////////////////////////////////////////////////////
533/// sort 2D vector (AND in parallel a TString vector) in such a way
534/// that the "first vector is sorted" and the other vectors are reshuffled
535/// in the same way as necessary to have the first vector sorted.
536/// I.e. the correlation between the elements is kept.
537
538void TMVA::Tools::UsefulSortAscending( std::vector<vector<Double_t> >& v, std::vector<TString>* vs ){
539 UInt_t nArrays=v.size();
540 Double_t temp;
541 if (nArrays > 0) {
542 UInt_t sizeofarray=v[0].size();
543 for (UInt_t i=0; i<sizeofarray; i++) {
544 for (UInt_t j=sizeofarray-1; j>i; j--) {
545 if (v[0][j-1] > v[0][j]) {
546 for (UInt_t k=0; k< nArrays; k++) {
547 temp = v[k][j-1]; v[k][j-1] = v[k][j]; v[k][j] = temp;
548 }
549 if (nullptr != vs) {
550 TString temps = (*vs)[j-1]; (*vs)[j-1] = (*vs)[j]; (*vs)[j] = temps;
551 }
552 }
553 }
554 }
555 }
556}
557
558////////////////////////////////////////////////////////////////////////////////
559/// sort 2D vector (AND in parallel a TString vector) in such a way
560/// that the "first vector is sorted" and the other vectors are reshuffled
561/// in the same way as necessary to have the first vector sorted.
562/// I.e. the correlation between the elements is kept.
563
564void TMVA::Tools::UsefulSortDescending( std::vector<std::vector<Double_t> >& v, std::vector<TString>* vs )
565{
566 UInt_t nArrays=v.size();
567 Double_t temp;
568 if (nArrays > 0) {
569 UInt_t sizeofarray=v[0].size();
570 for (UInt_t i=0; i<sizeofarray; i++) {
571 for (UInt_t j=sizeofarray-1; j>i; j--) {
572 if (v[0][j-1] < v[0][j]) {
573 for (UInt_t k=0; k< nArrays; k++) {
574 temp = v[k][j-1]; v[k][j-1] = v[k][j]; v[k][j] = temp;
575 }
576 if (nullptr != vs) {
577 TString temps = (*vs)[j-1]; (*vs)[j-1] = (*vs)[j]; (*vs)[j] = temps;
578 }
579 }
580 }
581 }
582 }
583}
584
585////////////////////////////////////////////////////////////////////////////////
586/// Mutual Information method for non-linear correlations estimates in 2D histogram
587/// Author: Moritz Backes, Geneva (2009)
588
590{
591 Double_t hi = h_.Integral();
592 if (hi == 0) return -1;
593
594 // copy histogram and rebin to speed up procedure
595 TH2F h( h_ );
596 h.RebinX(2);
597 h.RebinY(2);
598
599 Double_t mutualInfo = 0.;
600 Int_t maxBinX = h.GetNbinsX();
601 Int_t maxBinY = h.GetNbinsY();
602 for (Int_t x = 1; x <= maxBinX; x++) {
603 for (Int_t y = 1; y <= maxBinY; y++) {
604 Double_t p_xy = h.GetBinContent(x,y)/hi;
605 Double_t p_x = h.Integral(x,x,1,maxBinY)/hi;
606 Double_t p_y = h.Integral(1,maxBinX,y,y)/hi;
607 if (p_x > 0. && p_y > 0. && p_xy > 0.){
608 mutualInfo += p_xy*TMath::Log(p_xy / (p_x * p_y));
609 }
610 }
611 }
612
613 return mutualInfo;
614}
615
616////////////////////////////////////////////////////////////////////////////////
617/// Compute Correlation Ratio of 2D histogram to estimate functional dependency between two variables
618/// Author: Moritz Backes, Geneva (2009)
619
621{
622 Double_t hi = h_.Integral();
623 if (hi == 0.) return -1;
624
625 // copy histogram and rebin to speed up procedure
626 TH2F h( h_ );
627 h.RebinX(2);
628 h.RebinY(2);
629
630 Double_t corrRatio = 0.;
631 Double_t y_mean = h.ProjectionY()->GetMean();
632 for (Int_t ix=1; ix<=h.GetNbinsX(); ix++) {
633 corrRatio += (h.Integral(ix,ix,1,h.GetNbinsY())/hi)*pow((GetYMean_binX(h,ix)-y_mean),2);
634 }
635 corrRatio /= pow(h.ProjectionY()->GetRMS(),2);
636 return corrRatio;
637}
638
639////////////////////////////////////////////////////////////////////////////////
640/// Compute the mean in Y for a given bin X of a 2D histogram
641
643{
644 if (h.Integral(bin_x,bin_x,1,h.GetNbinsY()) == 0.) {return 0;}
645 Double_t y_bin_mean = 0.;
646 TH1* py = h.ProjectionY();
647 for (Int_t y = 1; y <= h.GetNbinsY(); y++){
648 y_bin_mean += h.GetBinContent(bin_x,y)*py->GetBinCenter(y);
649 }
650 y_bin_mean /= h.Integral(bin_x,bin_x,1,h.GetNbinsY());
651 return y_bin_mean;
652}
653
654////////////////////////////////////////////////////////////////////////////////
655/// Transpose quadratic histogram
656
658{
659 // sanity check
660 if (h.GetNbinsX() != h.GetNbinsY()) {
661 Log() << kFATAL << "<TransposeHist> cannot transpose non-quadratic histogram" << Endl;
662 }
663
664 TH2F *transposedHisto = new TH2F( h );
665 for (Int_t ix=1; ix <= h.GetNbinsX(); ix++){
666 for (Int_t iy=1; iy <= h.GetNbinsY(); iy++){
667 transposedHisto->SetBinContent(iy,ix,h.GetBinContent(ix,iy));
668 }
669 }
670
671 // copy stats (thanks to Swagato Banerjee for pointing out the missing stats information)
672 Double_t stats_old[7];
673 Double_t stats_new[7];
674
675 h.GetStats(stats_old);
676 stats_new[0] = stats_old[0];
677 stats_new[1] = stats_old[1];
678 stats_new[2] = stats_old[4];
679 stats_new[3] = stats_old[5];
680 stats_new[4] = stats_old[2];
681 stats_new[5] = stats_old[3];
682 stats_new[6] = stats_old[6];
683 transposedHisto->PutStats(stats_new);
684
685 return transposedHisto; // ownership returned
686}
687
688////////////////////////////////////////////////////////////////////////////////
689/// check for "silence" option in configuration option string
690
692{
693 Bool_t isSilent = kFALSE;
694
695 TString s( cs );
696 s.ToLower();
697 s.ReplaceAll(" ","");
698 if (s.Contains("silent") && !s.Contains("silent=f")) {
699 if (!s.Contains("!silent") || s.Contains("silent=t")) isSilent = kTRUE;
700 }
701
702 return isSilent;
703}
704
705////////////////////////////////////////////////////////////////////////////////
706/// check if verbosity "V" set in option
707
709{
710 Bool_t isVerbose = kFALSE;
711
712 TString s( cs );
713 s.ToLower();
714 s.ReplaceAll(" ","");
715 std::vector<TString> v = SplitString( s, ':' );
716 for (std::vector<TString>::iterator it = v.begin(); it != v.end(); ++it) {
717 if ((*it == "v" || *it == "verbose") && !it->Contains("!")) isVerbose = kTRUE;
718 }
719
720 return isVerbose;
721}
722
723////////////////////////////////////////////////////////////////////////////////
724/// sort vector
725
726void TMVA::Tools::UsefulSortDescending( std::vector<Double_t>& v )
727{
728 vector< vector<Double_t> > vtemp;
729 vtemp.push_back(v);
730 UsefulSortDescending(vtemp);
731 v = vtemp[0];
732}
733
734////////////////////////////////////////////////////////////////////////////////
735/// sort vector
736
737void TMVA::Tools::UsefulSortAscending( std::vector<Double_t>& v )
738{
739 vector<vector<Double_t> > vtemp;
740 vtemp.push_back(v);
741 UsefulSortAscending(vtemp);
742 v = vtemp[0];
743}
744
745////////////////////////////////////////////////////////////////////////////////
746/// find index of maximum entry in vector
747
748Int_t TMVA::Tools::GetIndexMaxElement( std::vector<Double_t>& v )
749{
750 if (v.empty()) return -1;
751
752 Int_t pos=0; Double_t mx=v[0];
753 for (UInt_t i=0; i<v.size(); i++){
754 if (v[i] > mx){
755 mx=v[i];
756 pos=i;
757 }
758 }
759 return pos;
760}
761
762////////////////////////////////////////////////////////////////////////////////
763/// find index of minimum entry in vector
764
765Int_t TMVA::Tools::GetIndexMinElement( std::vector<Double_t>& v )
766{
767 if (v.empty()) return -1;
768
769 Int_t pos=0; Double_t mn=v[0];
770 for (UInt_t i=0; i<v.size(); i++){
771 if (v[i] < mn){
772 mn=v[i];
773 pos=i;
774 }
775 }
776 return pos;
777}
778
779
780////////////////////////////////////////////////////////////////////////////////
781/// check if regular expression
782/// helper function to search for "$!%^&()'<>?= " in a string
783
785{
786 Bool_t regular = kFALSE;
787 for (Int_t i = 0; i < Tools::fRegexp.Length(); i++)
788 if (s.Contains( Tools::fRegexp[i] )) { regular = kTRUE; break; }
789
790 return regular;
791}
792
793////////////////////////////////////////////////////////////////////////////////
794/// replace regular expressions
795/// helper function to remove all occurrences "$!%^&()'<>?= " from a string
796/// and replace all ::,$,*,/,+,- with _M_,_S_,_T_,_D_,_P_,_M_ respectively
797
799{
800 TString snew = s;
801 for (Int_t i = 0; i < Tools::fRegexp.Length(); i++)
802 snew.ReplaceAll( Tools::fRegexp[i], r );
803
804 snew.ReplaceAll( "::", r );
805 snew.ReplaceAll( "$", "_S_" );
806 snew.ReplaceAll( "&", "_A_" );
807 snew.ReplaceAll( "%", "_MOD_" );
808 snew.ReplaceAll( "|", "_O_" );
809 snew.ReplaceAll( "*", "_T_" );
810 snew.ReplaceAll( "/", "_D_" );
811 snew.ReplaceAll( "+", "_P_" );
812 snew.ReplaceAll( "-", "_M_" );
813 snew.ReplaceAll( " ", "_" );
814 snew.ReplaceAll( "[", "_" );
815 snew.ReplaceAll( "]", "_" );
816 snew.ReplaceAll( "=", "_E_" );
817 snew.ReplaceAll( ">", "_GT_" );
818 snew.ReplaceAll( "<", "_LT_" );
819 snew.ReplaceAll( "(", "_" );
820 snew.ReplaceAll( ")", "_" );
821
822 return snew;
823}
824
825////////////////////////////////////////////////////////////////////////////////
826/// human readable color strings
827
829{
830 static const TString gClr_none = "" ;
831 static const TString gClr_white = "\033[1;37m"; // white
832 static const TString gClr_black = "\033[30m"; // black
833 static const TString gClr_blue = "\033[34m"; // blue
834 static const TString gClr_red = "\033[1;31m" ; // red
835 static const TString gClr_yellow = "\033[1;33m"; // yellow
836 static const TString gClr_darkred = "\033[31m"; // dark red
837 static const TString gClr_darkgreen = "\033[32m"; // dark green
838 static const TString gClr_darkyellow = "\033[33m"; // dark yellow
839
840 static const TString gClr_bold = "\033[1m" ; // bold
841 static const TString gClr_black_b = "\033[30m" ; // bold black
842 static const TString gClr_lblue_b = "\033[1;34m" ; // bold light blue
843 static const TString gClr_cyan_b = "\033[0;36m" ; // bold cyan
844 static const TString gClr_lgreen_b = "\033[1;32m"; // bold light green
845
846 static const TString gClr_blue_bg = "\033[44m"; // blue background
847 static const TString gClr_red_bg = "\033[1;41m"; // white on red background
848 static const TString gClr_whiteonblue = "\033[1;44m"; // white on blue background
849 static const TString gClr_whiteongreen = "\033[1;42m"; // white on green background
850 static const TString gClr_grey_bg = "\033[47m"; // grey background
851
852 static const TString gClr_reset = "\033[0m"; // reset
853
854 if (!gConfig().UseColor()) return gClr_none;
855
856 if (c == "white" ) return gClr_white;
857 if (c == "blue" ) return gClr_blue;
858 if (c == "black" ) return gClr_black;
859 if (c == "lightblue") return gClr_cyan_b;
860 if (c == "yellow") return gClr_yellow;
861 if (c == "red" ) return gClr_red;
862 if (c == "dred" ) return gClr_darkred;
863 if (c == "dgreen") return gClr_darkgreen;
864 if (c == "lgreenb") return gClr_lgreen_b;
865 if (c == "dyellow") return gClr_darkyellow;
866
867 if (c == "bold") return gClr_bold;
868 if (c == "bblack") return gClr_black_b;
869
870 if (c == "blue_bgd") return gClr_blue_bg;
871 if (c == "red_bgd" ) return gClr_red_bg;
872
873 if (c == "white_on_blue" ) return gClr_whiteonblue;
874 if (c == "white_on_green") return gClr_whiteongreen;
875
876 if (c == "reset") return gClr_reset;
877
878 std::cout << "Unknown color " << c << std::endl;
879 exit(1);
880
881 return gClr_none;
882}
883
884////////////////////////////////////////////////////////////////////////////////
885/// formatted output of simple table
886
887void TMVA::Tools::FormattedOutput( const std::vector<Double_t>& values, const std::vector<TString>& V,
888 const TString titleVars, const TString titleValues, MsgLogger& logger,
890{
891 // sanity check
892 UInt_t nvar = V.size();
893 if ((UInt_t)values.size() != nvar) {
894 logger << kFATAL << "<FormattedOutput> fatal error with dimensions: "
895 << values.size() << " OR " << " != " << nvar << Endl;
896 }
897
898 // find maximum length in V (and column title)
899 UInt_t maxL = 7;
900 std::vector<UInt_t> vLengths;
901 for (UInt_t ivar=0; ivar<nvar; ivar++) maxL = TMath::Max( (UInt_t)V[ivar].Length(), maxL );
902 maxL = TMath::Max( (UInt_t)titleVars.Length(), maxL );
903
904 // column length
905 UInt_t maxV = 7;
906 maxV = TMath::Max( (UInt_t)titleValues.Length() + 1, maxL );
907
908 // full column length
909 UInt_t clen = maxL + maxV + 3;
910
911 // bar line
912 for (UInt_t i=0; i<clen; i++) logger << "-";
913 logger << Endl;
914
915 // title bar
916 logger << setw(maxL) << titleVars << ":";
917 logger << setw(maxV+1) << titleValues << ":";
918 logger << Endl;
919 for (UInt_t i=0; i<clen; i++) logger << "-";
920 logger << Endl;
921
922 // the numbers
923 for (UInt_t irow=0; irow<nvar; irow++) {
924 logger << setw(maxL) << V[irow] << ":";
925 logger << setw(maxV+1) << Form( format.Data(), values[irow] );
926 logger << Endl;
927 }
928
929 // bar line
930 for (UInt_t i=0; i<clen; i++) logger << "-";
931 logger << Endl;
932}
933
934////////////////////////////////////////////////////////////////////////////////
935/// formatted output of matrix (with labels)
936
937void TMVA::Tools::FormattedOutput( const TMatrixD& M, const std::vector<TString>& V, MsgLogger& logger )
938{
939 // sanity check: matrix must be quadratic
940 UInt_t nvar = V.size();
941 if ((UInt_t)M.GetNcols() != nvar || (UInt_t)M.GetNrows() != nvar) {
942 logger << kFATAL << "<FormattedOutput> fatal error with dimensions: "
943 << M.GetNcols() << " OR " << M.GetNrows() << " != " << nvar << " ==> abort" << Endl;
944 }
945
946 // get length of each variable, and maximum length
947 UInt_t minL = 7;
948 UInt_t maxL = minL;
949 std::vector<UInt_t> vLengths;
950 for (UInt_t ivar=0; ivar<nvar; ivar++) {
951 vLengths.push_back(TMath::Max( (UInt_t)V[ivar].Length(), minL ));
952 maxL = TMath::Max( vLengths.back(), maxL );
953 }
954
955 // count column length
956 UInt_t clen = maxL+1;
957 for (UInt_t icol=0; icol<nvar; icol++) clen += vLengths[icol]+1;
958
959 // bar line
960 for (UInt_t i=0; i<clen; i++) logger << "-";
961 logger << Endl;
962
963 // title bar
964 logger << setw(maxL+1) << " ";
965 for (UInt_t icol=0; icol<nvar; icol++) logger << setw(vLengths[icol]+1) << V[icol];
966 logger << Endl;
967
968 // the numbers
969 for (UInt_t irow=0; irow<nvar; irow++) {
970 logger << setw(maxL) << V[irow] << ":";
971 for (UInt_t icol=0; icol<nvar; icol++) {
972 logger << setw(vLengths[icol]+1) << Form( "%+1.3f", M(irow,icol) );
973 }
974 logger << Endl;
975 }
976
977 // bar line
978 for (UInt_t i=0; i<clen; i++) logger << "-";
979 logger << Endl;
980}
981
982////////////////////////////////////////////////////////////////////////////////
983/// formatted output of matrix (with labels)
984
986 const std::vector<TString>& vert, const std::vector<TString>& horiz,
987 MsgLogger& logger )
988{
989 // sanity check: matrix must be quadratic
990 UInt_t nvvar = vert.size();
991 UInt_t nhvar = horiz.size();
992
993 // get length of each variable, and maximum length
994 UInt_t minL = 7;
995 UInt_t maxL = minL;
996 std::vector<UInt_t> vLengths;
997 for (UInt_t ivar=0; ivar<nvvar; ivar++) {
998 vLengths.push_back(TMath::Max( (UInt_t)vert[ivar].Length(), minL ));
999 maxL = TMath::Max( vLengths.back(), maxL );
1000 }
1001
1002 // count column length
1003 UInt_t minLh = 7;
1004 UInt_t maxLh = minLh;
1005 std::vector<UInt_t> hLengths;
1006 for (UInt_t ivar=0; ivar<nhvar; ivar++) {
1007 hLengths.push_back(TMath::Max( (UInt_t)horiz[ivar].Length(), minL ));
1008 maxLh = TMath::Max( hLengths.back(), maxLh );
1009 }
1010
1011 UInt_t clen = maxLh+1;
1012 for (UInt_t icol=0; icol<nhvar; icol++) clen += hLengths[icol]+1;
1013
1014 // bar line
1015 for (UInt_t i=0; i<clen; i++) logger << "-";
1016 logger << Endl;
1017
1018 // title bar
1019 logger << setw(maxL+1) << " ";
1020 for (UInt_t icol=0; icol<nhvar; icol++) logger << setw(hLengths[icol]+1) << horiz[icol];
1021 logger << Endl;
1022
1023 // the numbers
1024 for (UInt_t irow=0; irow<nvvar; irow++) {
1025 logger << setw(maxL) << vert[irow] << ":";
1026 for (UInt_t icol=0; icol<nhvar; icol++) {
1027 logger << setw(hLengths[icol]+1) << Form( "%+1.3f", M(irow,icol) );
1028 }
1029 logger << Endl;
1030 }
1031
1032 // bar line
1033 for (UInt_t i=0; i<clen; i++) logger << "-";
1034 logger << Endl;
1035}
1036
1037////////////////////////////////////////////////////////////////////////////////
1038/// histogramming utility
1039
1041{
1042 return ( unit == "" ? title : ( title + " [" + unit + "]" ) );
1043}
1044
1045////////////////////////////////////////////////////////////////////////////////
1046/// histogramming utility
1047
1048TString TMVA::Tools::GetYTitleWithUnit( const TH1& h, const TString& unit, Bool_t normalised )
1049{
1050 TString retval = ( normalised ? "(1/N) " : "" );
1051 retval += Form( "dN_{ }/^{ }%.3g %s", h.GetXaxis()->GetBinWidth(1), unit.Data() );
1052 return retval;
1053}
1054
1055////////////////////////////////////////////////////////////////////////////////
1056/// writes a float value with the available precision to a stream
1057
1059{
1060 os << val << " :: ";
1061 void * c = &val;
1062 for (int i=0; i<4; i++) {
1063 Int_t ic = *((char*)c+i)-'\0';
1064 if (ic<0) ic+=256;
1065 os << ic << " ";
1066 }
1067 os << ":: ";
1068}
1069
1070////////////////////////////////////////////////////////////////////////////////
1071/// reads a float value with the available precision from a stream
1072
1074{
1075 Float_t a = 0;
1076 is >> a;
1077 TString dn;
1078 is >> dn;
1079 Int_t c[4];
1080 void * ap = &a;
1081 for (int i=0; i<4; i++) {
1082 is >> c[i];
1083 *((char*)ap+i) = '\0'+c[i];
1084 }
1085 is >> dn;
1086 val = a;
1087}
1088
1089// XML file reading/writing helper functions
1090
1091////////////////////////////////////////////////////////////////////////////////
1092/// add attribute from xml
1093
1094Bool_t TMVA::Tools::HasAttr( void* node, const char* attrname )
1095{
1096 return xmlengine().HasAttr(node, attrname);
1097}
1098
1099////////////////////////////////////////////////////////////////////////////////
1100/// add attribute from xml
1101
1102void TMVA::Tools::ReadAttr( void* node, const char* attrname, TString& value )
1103{
1104 if (!HasAttr(node, attrname)) {
1105 const char * nodename = xmlengine().GetNodeName(node);
1106 Log() << kFATAL << "Trying to read non-existing attribute '" << attrname << "' from xml node '" << nodename << "'" << Endl;
1107 }
1108 const char* val = xmlengine().GetAttr(node, attrname);
1109 value = TString(val);
1110}
1111
1112////////////////////////////////////////////////////////////////////////////////
1113/// add attribute to node
1114
1115void TMVA::Tools::AddAttr( void* node, const char* attrname, const char* value )
1116{
1117 if( !node ) return;
1118 gTools().xmlengine().NewAttr(node, nullptr, attrname, value );
1119}
1120
1121////////////////////////////////////////////////////////////////////////////////
1122/// add child node
1123
1124void* TMVA::Tools::AddChild( void* parent, const char* childname, const char* content, bool isRootNode )
1125{
1126 if( !isRootNode && parent == 0 ) return 0;
1127 return gTools().xmlengine().NewChild(parent, 0, childname, content);
1128}
1129
1130////////////////////////////////////////////////////////////////////////////////
1131
1132Bool_t TMVA::Tools::AddComment( void* node, const char* comment ) {
1133 if( node == 0 ) return kFALSE;
1134 return gTools().xmlengine().AddComment(node, comment);
1135}
1136
1137////////////////////////////////////////////////////////////////////////////////
1138/// get parent node
1139
1141{
1142 void* par = xmlengine().GetParent(child);
1143
1144 return par;
1145}
1146
1147////////////////////////////////////////////////////////////////////////////////
1148/// get child node
1149
1150void* TMVA::Tools::GetChild( void* parent, const char* childname )
1151{
1152 void* ch = xmlengine().GetChild(parent);
1153 if (childname != 0) {
1154 while (ch!=0 && strcmp(xmlengine().GetNodeName(ch),childname) != 0) ch = xmlengine().GetNext(ch);
1155 }
1156 return ch;
1157}
1158
1159////////////////////////////////////////////////////////////////////////////////
1160/// XML helpers
1161
1162void* TMVA::Tools::GetNextChild( void* prevchild, const char* childname )
1163{
1164 void* ch = xmlengine().GetNext(prevchild);
1165 if (childname != 0) {
1166 while (ch!=0 && strcmp(xmlengine().GetNodeName(ch),childname)!=0) ch = xmlengine().GetNext(ch);
1167 }
1168 return ch;
1169}
1170
1171////////////////////////////////////////////////////////////////////////////////
1172/// XML helpers
1173
1174const char* TMVA::Tools::GetContent( void* node )
1175{
1176 return xmlengine().GetNodeContent(node);
1177}
1178
1179////////////////////////////////////////////////////////////////////////////////
1180/// XML helpers
1181
1182const char* TMVA::Tools::GetName( void* node )
1183{
1184 return xmlengine().GetNodeName(node);
1185}
1186
1187////////////////////////////////////////////////////////////////////////////////
1188/// XML helpers
1189
1190Bool_t TMVA::Tools::AddRawLine( void* node, const char * raw )
1191{
1192 return xmlengine().AddRawLine( node, raw );
1193}
1194
1195////////////////////////////////////////////////////////////////////////////////
1196/// splits the option string at 'separator' and fills the list
1197/// 'splitV' with the primitive strings
1198
1199std::vector<TString> TMVA::Tools::SplitString(const TString& theOpt, const char separator ) const
1200{
1201 std::vector<TString> splitV;
1202 TString splitOpt(theOpt);
1203 splitOpt.ReplaceAll("\n"," ");
1204 splitOpt = splitOpt.Strip(TString::kBoth,separator);
1205 while (splitOpt.Length()>0) {
1206 if ( !splitOpt.Contains(separator) ) {
1207 splitV.push_back(splitOpt);
1208 break;
1209 }
1210 else {
1211 TString toSave = splitOpt(0,splitOpt.First(separator));
1212 splitV.push_back(toSave);
1213 splitOpt = splitOpt(splitOpt.First(separator),splitOpt.Length());
1214 }
1215 splitOpt = splitOpt.Strip(TString::kLeading,separator);
1216 }
1217 return splitV;
1218}
1219
1220////////////////////////////////////////////////////////////////////////////////
1221/// string tools
1222
1224{
1225 std::stringstream s;
1226 s << i;
1227 return TString(s.str().c_str());
1228}
1229
1230////////////////////////////////////////////////////////////////////////////////
1231/// string tools
1232
1234{
1235 std::stringstream s;
1236 s << Form( "%5.8e", d );
1237 return TString(s.str().c_str());
1238}
1239
1240////////////////////////////////////////////////////////////////////////////////
1241/// XML helpers
1242
1243void TMVA::Tools::WriteTMatrixDToXML( void* node, const char* name, TMatrixD* mat )
1244{
1245 void* matnode = xmlengine().NewChild(node, 0, name);
1246 xmlengine().NewAttr(matnode,0,"Rows", StringFromInt(mat->GetNrows()) );
1247 xmlengine().NewAttr(matnode,0,"Columns", StringFromInt(mat->GetNcols()) );
1248 std::stringstream s;
1249 for (Int_t row = 0; row<mat->GetNrows(); row++) {
1250 for (Int_t col = 0; col<mat->GetNcols(); col++) {
1251 s << Form( "%5.15e ", (*mat)[row][col] );
1252 }
1253 }
1254 xmlengine().AddRawLine( matnode, s.str().c_str() );
1255}
1256
1257////////////////////////////////////////////////////////////////////////////////
1258
1259void TMVA::Tools::WriteTVectorDToXML( void* node, const char* name, TVectorD* vec )
1260{
1261 TMatrixD mat(1,vec->GetNoElements(),&((*vec)[0]));
1262 WriteTMatrixDToXML( node, name, &mat );
1263}
1264
1265////////////////////////////////////////////////////////////////////////////////
1266
1267void TMVA::Tools::ReadTVectorDFromXML( void* node, const char* name, TVectorD* vec )
1268{
1269 TMatrixD mat(1,vec->GetNoElements(),&((*vec)[0]));
1270 ReadTMatrixDFromXML( node, name, &mat );
1271 for (int i=0;i<vec->GetNoElements();++i) (*vec)[i] = mat[0][i];
1272}
1273
1274////////////////////////////////////////////////////////////////////////////////
1275
1276void TMVA::Tools::ReadTMatrixDFromXML( void* node, const char* name, TMatrixD* mat )
1277{
1278 if (strcmp(xmlengine().GetNodeName(node),name)!=0){
1279 Log() << kWARNING << "Possible Error: Name of matrix in weight file"
1280 << " does not match name of matrix passed as argument!" << Endl;
1281 }
1282 Int_t nrows, ncols;
1283 ReadAttr( node, "Rows", nrows );
1284 ReadAttr( node, "Columns", ncols );
1285 if (mat->GetNrows() != nrows || mat->GetNcols() != ncols){
1286 Log() << kWARNING << "Possible Error: Dimension of matrix in weight file"
1287 << " does not match dimension of matrix passed as argument!" << Endl;
1288 mat->ResizeTo(nrows,ncols);
1289 }
1290 const char* content = xmlengine().GetNodeContent(node);
1291 std::stringstream s(content);
1292 for (Int_t row = 0; row<nrows; row++) {
1293 for (Int_t col = 0; col<ncols; col++) {
1294 s >> (*mat)[row][col];
1295 }
1296 }
1297}
1298
1299////////////////////////////////////////////////////////////////////////////////
1300/// direct output, eg, when starting ROOT session -> no use of Logger here
1301
1303{
1304 std::cout << std::endl;
1305 std::cout << Color("bold") << "TMVA -- Toolkit for Multivariate Data Analysis" << Color("reset") << std::endl;
1306 std::cout << " " << "Version " << TMVA_RELEASE << ", " << TMVA_RELEASE_DATE << std::endl;
1307 std::cout << " " << "Copyright (C) 2005-2010 CERN, MPI-K Heidelberg, Us of Bonn and Victoria" << std::endl;
1308 std::cout << " " << "Home page: http://tmva.sf.net" << std::endl;
1309 std::cout << " " << "Citation info: http://tmva.sf.net/citeTMVA.html" << std::endl;
1310 std::cout << " " << "License: http://tmva.sf.net/LICENSE" << std::endl << std::endl;
1311}
1312
1313////////////////////////////////////////////////////////////////////////////////
1314/// prints the TMVA release number and date
1315
1317{
1318 logger << "___________TMVA Version " << TMVA_RELEASE << ", " << TMVA_RELEASE_DATE
1319 << "" << Endl;
1320}
1321
1322////////////////////////////////////////////////////////////////////////////////
1323/// prints the ROOT release number and date
1324
1326{
1327 static const char * const months[] = { "Jan","Feb","Mar","Apr","May",
1328 "Jun","Jul","Aug","Sep","Oct",
1329 "Nov","Dec" };
1330 Int_t idatqq = gROOT->GetVersionDate();
1331 Int_t iday = idatqq%100;
1332 Int_t imonth = (idatqq/100)%100;
1333 Int_t iyear = (idatqq/10000);
1334 TString versionDate = Form("%s %d, %4d",months[imonth-1],iday,iyear);
1335
1336 logger << kHEADER ;
1337 logger << "You are running ROOT Version: " << gROOT->GetVersion() << ", " << versionDate << Endl;
1338}
1339
1340////////////////////////////////////////////////////////////////////////////////
1341/// various kinds of welcome messages
1342/// ASCII text generated by this site: http://www.network-science.de/ascii/
1343
1345{
1346 switch (msgType) {
1347
1348 case kStandardWelcomeMsg:
1349 logger << Color("white") << "TMVA -- Toolkit for Multivariate Analysis" << Color("reset") << Endl;
1350 logger << "Copyright (C) 2005-2006 CERN, LAPP & MPI-K Heidelberg and Victoria U." << Endl;
1351 logger << "Home page http://tmva.sourceforge.net" << Endl;
1352 logger << "All rights reserved, please read http://tmva.sf.net/license.txt" << Endl << Endl;
1353 break;
1354
1355 case kIsometricWelcomeMsg:
1356 logger << " ___ ___ ___ ___ " << Endl;
1357 logger << " /\\ \\ /\\__\\ /\\__\\ /\\ \\ " << Endl;
1358 logger << " \\:\\ \\ /::| | /:/ / /::\\ \\ " << Endl;
1359 logger << " \\:\\ \\ /:|:| | /:/ / /:/\\:\\ \\ " << Endl;
1360 logger << " /::\\ \\ /:/|:|__|__ /:/__/ ___ /::\\~\\:\\ \\ " << Endl;
1361 logger << " /:/\\:\\__\\ /:/ |::::\\__\\ |:| | /\\__\\ /:/\\:\\ \\:\\__\\ " << Endl;
1362 logger << " /:/ \\/__/ \\/__/~~/:/ / |:| |/:/ / \\/__\\:\\/:/ / " << Endl;
1363 logger << "/:/ / /:/ / |:|__/:/ / \\::/ / " << Endl;
1364 logger << "\\/__/ /:/ / \\::::/__/ /:/ / " << Endl;
1365 logger << " /:/ / ~~~~ /:/ / " << Endl;
1366 logger << " \\/__/ \\/__/ " << Endl << Endl;
1367 break;
1368
1369 case kBlockWelcomeMsg:
1370 logger << Endl;
1371 logger << "_|_|_|_|_| _| _| _| _| _|_| " << Endl;
1372 logger << " _| _|_| _|_| _| _| _| _| " << Endl;
1373 logger << " _| _| _| _| _| _| _|_|_|_| " << Endl;
1374 logger << " _| _| _| _| _| _| _| " << Endl;
1375 logger << " _| _| _| _| _| _| " << Endl << Endl;
1376 break;
1377
1378 case kLeanWelcomeMsg:
1379 logger << Endl;
1380 logger << "_/_/_/_/_/ _/ _/ _/ _/ _/_/ " << Endl;
1381 logger << " _/ _/_/ _/_/ _/ _/ _/ _/ " << Endl;
1382 logger << " _/ _/ _/ _/ _/ _/ _/_/_/_/ " << Endl;
1383 logger << " _/ _/ _/ _/ _/ _/ _/ " << Endl;
1384 logger << "_/ _/ _/ _/ _/ _/ " << Endl << Endl;
1385 break;
1386
1387 case kLogoWelcomeMsg:
1388 logger << Endl;
1389 logger << "_/_/_/_/_/ _| _| _| _| _|_| " << Endl;
1390 logger << " _/ _|_| _|_| _| _| _| _| " << Endl;
1391 logger << " _/ _| _| _| _| _| _|_|_|_| " << Endl;
1392 logger << " _/ _| _| _| _| _| _| " << Endl;
1393 logger << "_/ _| _| _| _| _| " << Endl << Endl;
1394 break;
1395
1396 case kSmall1WelcomeMsg:
1397 logger << " _____ __ ____ ___ " << Endl;
1398 logger << "|_ _| \\/ \\ \\ / /_\\ " << Endl;
1399 logger << " | | | |\\/| |\\ V / _ \\ " << Endl;
1400 logger << " |_| |_| |_| \\_/_/ \\_\\" << Endl << Endl;
1401 break;
1402
1403 case kSmall2WelcomeMsg:
1404 logger << " _____ __ ____ ___ " << Endl;
1405 logger << "|_ _| \\/ \\ \\ / / \\ " << Endl;
1406 logger << " | | | |\\/| |\\ \\ / / _ \\ " << Endl;
1407 logger << " | | | | | | \\ V / ___ \\ " << Endl;
1408 logger << " |_| |_| |_| \\_/_/ \\_\\ " << Endl << Endl;
1409 break;
1410
1411 case kOriginalWelcomeMsgColor:
1412 logger << kINFO << "" << Color("red")
1413 << "_______________________________________" << Color("reset") << Endl;
1414 logger << kINFO << "" << Color("blue")
1415 << Color("red_bgd") << Color("bwhite") << " // " << Color("reset")
1416 << Color("white") << Color("blue_bgd")
1417 << "|\\ /|| \\ // /\\\\\\\\\\\\\\\\\\\\\\\\ \\ \\ \\ " << Color("reset") << Endl;
1418 logger << kINFO << ""<< Color("blue")
1419 << Color("red_bgd") << Color("white") << "// " << Color("reset")
1420 << Color("white") << Color("blue_bgd")
1421 << "| \\/ || \\// /--\\\\\\\\\\\\\\\\\\\\\\\\ \\ \\ \\" << Color("reset") << Endl;
1422 break;
1423
1424 case kOriginalWelcomeMsgBW:
1425 logger << kINFO << ""
1426 << "_______________________________________" << Endl;
1427 logger << kINFO << " // "
1428 << "|\\ /|| \\ // /\\\\\\\\\\\\\\\\\\\\\\\\ \\ \\ \\ " << Endl;
1429 logger << kINFO << "// "
1430 << "| \\/ || \\// /--\\\\\\\\\\\\\\\\\\\\\\\\ \\ \\ \\" << Endl;
1431 break;
1432
1433 default:
1434 logger << kFATAL << "unknown message type: " << msgType << Endl;
1435 }
1436}
1437
1438////////////////////////////////////////////////////////////////////////////////
1439/// kinds of TMVA citation
1440
1442{
1443 switch (citType) {
1444
1445 case kPlainText:
1446 logger << "A. Hoecker, P. Speckmayer, J. Stelzer, J. Therhaag, E. von Toerne, H. Voss" << Endl;
1447 logger << "\"TMVA - Toolkit for Multivariate Data Analysis\" PoS ACAT:040,2007. e-Print: physics/0703039" << Endl;
1448 break;
1449
1450 case kBibTeX:
1451 logger << "@Article{TMVA2007," << Endl;
1452 logger << " author = \"Hoecker, Andreas and Speckmayer, Peter and Stelzer, Joerg " << Endl;
1453 logger << " and Therhaag, Jan and von Toerne, Eckhard and Voss, Helge\"," << Endl;
1454 logger << " title = \"{TMVA: Toolkit for multivariate data analysis}\"," << Endl;
1455 logger << " journal = \"PoS\"," << Endl;
1456 logger << " volume = \"ACAT\"," << Endl;
1457 logger << " year = \"2007\"," << Endl;
1458 logger << " pages = \"040\"," << Endl;
1459 logger << " eprint = \"physics/0703039\"," << Endl;
1460 logger << " archivePrefix = \"arXiv\"," << Endl;
1461 logger << " SLACcitation = \"%%CITATION = PHYSICS/0703039;%%\"" << Endl;
1462 logger << "}" << Endl;
1463 break;
1464
1465 case kLaTeX:
1466 logger << "%\\cite{TMVA2007}" << Endl;
1467 logger << "\\bibitem{TMVA2007}" << Endl;
1468 logger << " A.~Hoecker, P.~Speckmayer, J.~Stelzer, J.~Therhaag, E.~von Toerne, H.~Voss" << Endl;
1469 logger << " %``TMVA: Toolkit for multivariate data analysis,''" << Endl;
1470 logger << " PoS A {\\bf CAT} (2007) 040" << Endl;
1471 logger << " [arXiv:physics/0703039]." << Endl;
1472 logger << " %%CITATION = POSCI,ACAT,040;%%" << Endl;
1473 break;
1474
1475 case kHtmlLink:
1476 // logger << kINFO << " " << Endl;
1477 logger << kHEADER << gTools().Color("bold")
1478 << "Thank you for using TMVA!" << gTools().Color("reset") << Endl;
1479 logger << kINFO << gTools().Color("bold")
1480 << "For citation information, please visit: http://tmva.sf.net/citeTMVA.html"
1481 << gTools().Color("reset") << Endl;
1482 }
1483}
1484
1485////////////////////////////////////////////////////////////////////////////////
1486
1488{
1489 return !(h.GetXaxis()->GetXbins()->fN);
1490}
1491
1492////////////////////////////////////////////////////////////////////////////////
1493
1494std::vector<TMatrixDSym*>*
1495TMVA::Tools::CalcCovarianceMatrices( const std::vector<const Event*>& events, Int_t maxCls, VariableTransformBase* transformBase )
1496{
1497 std::vector<Event*> eventVector;
1498 for (std::vector<const Event*>::const_iterator it = events.begin(), itEnd = events.end(); it != itEnd; ++it)
1499 {
1500 eventVector.push_back (new Event(*(*it)));
1501 }
1502 std::vector<TMatrixDSym*>* returnValue = CalcCovarianceMatrices (eventVector, maxCls, transformBase);
1503 for (std::vector<Event*>::const_iterator it = eventVector.begin(), itEnd = eventVector.end(); it != itEnd; ++it)
1504 {
1505 delete (*it);
1506 }
1507 return returnValue;
1508}
1509
1510////////////////////////////////////////////////////////////////////////////////
1511/// compute covariance matrices
1512
1513std::vector<TMatrixDSym*>*
1514TMVA::Tools::CalcCovarianceMatrices( const std::vector<Event*>& events, Int_t maxCls, VariableTransformBase* transformBase )
1515{
1516 if (events.empty()) {
1517 Log() << kWARNING << " Asked to calculate a covariance matrix for an empty event vectors.. sorry cannot do that -> return NULL"<<Endl;
1518 return 0;
1519 }
1520
1521 UInt_t nvars=0, ntgts=0, nspcts=0;
1522 if (transformBase)
1523 transformBase->CountVariableTypes( nvars, ntgts, nspcts );
1524 else {
1525 nvars =events.at(0)->GetNVariables ();
1526 ntgts =events.at(0)->GetNTargets ();
1527 nspcts=events.at(0)->GetNSpectators();
1528 }
1529
1530
1531 // init matrices
1532 Int_t matNum = maxCls;
1533 if (maxCls > 1 ) matNum++; // if more than one classes, then produce one matrix for all events as well (beside the matrices for each class)
1534
1535 std::vector<TVectorD*>* vec = new std::vector<TVectorD*>(matNum);
1536 std::vector<TMatrixD*>* mat2 = new std::vector<TMatrixD*>(matNum);
1537 std::vector<Double_t> count(matNum);
1538 count.assign(matNum,0);
1539
1540 Int_t cls = 0;
1541 TVectorD* v;
1542 TMatrixD* m;
1543 UInt_t ivar=0, jvar=0;
1544 for (cls = 0; cls < matNum ; cls++) {
1545 vec->at(cls) = new TVectorD(nvars);
1546 mat2->at(cls) = new TMatrixD(nvars,nvars);
1547 v = vec->at(cls);
1548 m = mat2->at(cls);
1549
1550 for (ivar=0; ivar<nvars; ivar++) {
1551 (*v)(ivar) = 0;
1552 for (jvar=0; jvar<nvars; jvar++) {
1553 (*m)(ivar, jvar) = 0;
1554 }
1555 }
1556 }
1557
1558 // perform event loop
1559 for (UInt_t i=0; i<events.size(); i++) {
1560
1561 // fill the event
1562 const Event * ev = events[i];
1563 cls = ev->GetClass();
1564 Double_t weight = ev->GetWeight();
1565
1566 std::vector<Float_t> input;
1567 std::vector<Char_t> mask; // entries with kTRUE must not be transformed
1568 // Bool_t hasMaskedEntries = kFALSE;
1569 if (transformBase) {
1570 /* hasMaskedEntries = */ transformBase->GetInput (ev, input, mask);
1571 } else {
1572 for (ivar=0; ivar<nvars; ++ivar) {
1573 input.push_back (ev->GetValue(ivar));
1574 }
1575 }
1576
1577 if (maxCls > 1) {
1578 v = vec->at(matNum-1);
1579 m = mat2->at(matNum-1);
1580
1581 count.at(matNum-1)+=weight; // count used events
1582 for (ivar=0; ivar<nvars; ivar++) {
1583
1584 Double_t xi = input.at (ivar);
1585 (*v)(ivar) += xi*weight;
1586 (*m)(ivar, ivar) += (xi*xi*weight);
1587
1588 for (jvar=ivar+1; jvar<nvars; jvar++) {
1589 Double_t xj = input.at (jvar);
1590 (*m)(ivar, jvar) += (xi*xj*weight);
1591 (*m)(jvar, ivar) = (*m)(ivar, jvar); // symmetric matrix
1592 }
1593 }
1594 }
1595
1596 count.at(cls)+=weight; // count used events
1597 v = vec->at(cls);
1598 m = mat2->at(cls);
1599 for (ivar=0; ivar<nvars; ivar++) {
1600 Double_t xi = input.at (ivar);
1601 (*v)(ivar) += xi*weight;
1602 (*m)(ivar, ivar) += (xi*xi*weight);
1603
1604 for (jvar=ivar+1; jvar<nvars; jvar++) {
1605 Double_t xj = input.at (jvar);
1606 (*m)(ivar, jvar) += (xi*xj*weight);
1607 (*m)(jvar, ivar) = (*m)(ivar, jvar); // symmetric matrix
1608 }
1609 }
1610 }
1611
1612 // variance-covariance
1613 std::vector<TMatrixDSym*>* mat = new std::vector<TMatrixDSym*>(matNum);
1614 for (cls = 0; cls < matNum; cls++) {
1615 v = vec->at(cls);
1616 m = mat2->at(cls);
1617
1618 mat->at(cls) = new TMatrixDSym(nvars);
1619
1620 Double_t n = count.at(cls);
1621 for (ivar=0; ivar<nvars; ivar++) {
1622 for (jvar=0; jvar<nvars; jvar++) {
1623 (*(mat->at(cls)))(ivar, jvar) = (*m)(ivar, jvar)/n - (*v)(ivar)*(*v)(jvar)/(n*n);
1624 }
1625 }
1626 delete v;
1627 delete m;
1628 }
1629
1630 delete mat2;
1631 delete vec;
1632
1633 return mat;
1634}
1635
1636////////////////////////////////////////////////////////////////////////////////
1637/// Return the weighted mean of an array defined by the first and
1638/// last iterators. The w iterator should point to the first element
1639/// of a vector of weights of the same size as the main array.
1640
1641template <typename Iterator, typename WeightIterator>
1642Double_t TMVA::Tools::Mean ( Iterator first, Iterator last, WeightIterator w)
1643{
1644 Double_t sum = 0;
1645 Double_t sumw = 0;
1646 if (w==NULL)
1647 {
1648 while ( first != last )
1649 {
1650 // if ( *w < 0) {
1651 // ::Error("TMVA::Tools::Mean","w[%d] = %.4e < 0 ?!",i,*w);
1652 // return 0;
1653 // } // SURE, why wouldn't you allow for negative event weights here ?? :)
1654 sum += (*first);
1655 sumw += 1.0 ;
1656 ++first;
1657 }
1658 if (sumw <= 0) {
1659 ::Error("TMVA::Tools::Mean","sum of weights <= 0 ?! that's a bit too much of negative event weights :) ");
1660 return 0;
1661 }
1662 }
1663 else
1664 {
1665 while ( first != last )
1666 {
1667 // if ( *w < 0) {
1668 // ::Error("TMVA::Tools::Mean","w[%d] = %.4e < 0 ?!",i,*w);
1669 // return 0;
1670 // } // SURE, why wouldn't you allow for negative event weights here ?? :)
1671 sum += (*w) * (*first);
1672 sumw += (*w) ;
1673 ++w;
1674 ++first;
1675 }
1676 if (sumw <= 0) {
1677 ::Error("TMVA::Tools::Mean","sum of weights <= 0 ?! that's a bit too much of negative event weights :) ");
1678 return 0;
1679 }
1680 }
1681 return sum/sumw;
1682}
1683
1684////////////////////////////////////////////////////////////////////////////////
1685/// Return the weighted mean of an array a with length n.
1686
1687template <typename T>
1689{
1690 if (w) {
1691 return TMVA::Tools::Mean(a, a+n, w);
1692 } else {
1693 return TMath::Mean(a, a+n);
1694 }
1695}
1696
1697////////////////////////////////////////////////////////////////////////////////
1698/// Return the Standard Deviation of an array defined by the iterators.
1699/// Note that this function returns the sigma(standard deviation) and
1700/// not the root mean square of the array.
1701
1702template <typename Iterator, typename WeightIterator>
1703Double_t TMVA::Tools::RMS(Iterator first, Iterator last, WeightIterator w)
1704{
1705
1706 Double_t sum = 0;
1707 Double_t sum2 = 0;
1708 Double_t sumw = 0;
1709
1710 Double_t adouble;
1711 if (w==NULL)
1712 {
1713 while ( first != last ) {
1714 adouble=Double_t(*first);
1715 sum += adouble;
1716 sum2 += adouble*adouble;
1717 sumw += 1.0;
1718 ++first;
1719 }
1720 }
1721 else
1722 {
1723 while ( first != last ) {
1724 adouble=Double_t(*first);
1725 sum += adouble * (*w);
1726 sum2 += adouble*adouble * (*w);
1727 sumw += (*w);
1728 ++first;
1729 ++w;
1730 }
1731 }
1732 Double_t norm = 1./sumw;
1733 Double_t mean = sum*norm;
1734 Double_t rms = TMath::Sqrt(TMath::Abs(sum2*norm -mean*mean));
1735 return rms;
1736}
1737
1738////////////////////////////////////////////////////////////////////////////////
1739/// Return the Standard Deviation of an array a with length n.
1740/// Note that this function returns the sigma(standard deviation) and
1741/// not the root mean square of the array.
1742
1743template <typename T>
1745{
1746
1747 if (w) {
1748 return TMVA::Tools::RMS(a, a+n, w);
1749 } else {
1750 return TMath::RMS(a, a+n);
1751 }
1752}
1753
1754////////////////////////////////////////////////////////////////////////////////
1755/// get the cumulative distribution of a histogram
1756
1758{
1759 TH1* cumulativeDist= (TH1*) h->Clone(Form("%sCumul",h->GetTitle()));
1760 //cumulativeDist->Smooth(5); // with this, I get less beautiful ROC curves, hence out!
1761
1762 Float_t partialSum = 0;
1763 Float_t inverseSum = 0.;
1764
1765 Float_t val;
1766 for (Int_t ibinEnd=1, ibin=cumulativeDist->GetNbinsX(); ibin >=ibinEnd ; ibin--){
1767 val = cumulativeDist->GetBinContent(ibin);
1768 if (val>0) inverseSum += val;
1769 }
1770 inverseSum = 1/inverseSum; // as I learned multiplications are much faster than division, and later I need one per bin. Well, not that it would really matter here I guess :)
1771
1772 for (Int_t ibinEnd=1, ibin=cumulativeDist->GetNbinsX(); ibin >=ibinEnd ; ibin--){
1773 val = cumulativeDist->GetBinContent(ibin);
1774 if (val>0) partialSum += val;
1775 cumulativeDist->SetBinContent(ibin,partialSum*inverseSum);
1776 }
1777 return cumulativeDist;
1778}
1779
1780void TMVA::Tools::ReadAttr(void *node, const char *attrname, float &value)
1781{
1782 // read attribute from xml
1783 const char *val = xmlengine().GetAttr(node, attrname);
1784 if (val == nullptr) {
1785 const char *nodename = xmlengine().GetNodeName(node);
1786 Log() << kFATAL << "Trying to read non-existing attribute '" << attrname << "' from xml node '" << nodename << "'"
1787 << Endl;
1788 } else
1789 value = atof(val);
1790}
1791
1792void TMVA::Tools::ReadAttr(void *node, const char *attrname, int &value)
1793{
1794 // read attribute from xml
1795 const char *val = xmlengine().GetAttr(node, attrname);
1796 if (val == nullptr) {
1797 const char *nodename = xmlengine().GetNodeName(node);
1798 Log() << kFATAL << "Trying to read non-existing attribute '" << attrname << "' from xml node '" << nodename << "'"
1799 << Endl;
1800 } else
1801 value = atoi(val);
1802}
1803
1804void TMVA::Tools::ReadAttr(void *node, const char *attrname, short &value)
1805{
1806 // read attribute from xml
1807 const char *val = xmlengine().GetAttr(node, attrname);
1808 if (val == nullptr) {
1809 const char *nodename = xmlengine().GetNodeName(node);
1810 Log() << kFATAL << "Trying to read non-existing attribute '" << attrname << "' from xml node '" << nodename << "'"
1811 << Endl;
1812 } else
1813 value = atoi(val);
1814}
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
long Long_t
Definition RtypesCore.h:54
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
long long Long64_t
Definition RtypesCore.h:80
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:197
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t child
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char mx
char name[80]
Definition TGX11.cxx:110
float xmin
#define hi
float xmax
TMatrixTSym< Double_t > TMatrixDSym
TMatrixT< Double_t > TMatrixD
Definition TMatrixDfwd.h:23
#define gROOT
Definition TROOT.h:405
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2467
TVectorT< Double_t > TVectorD
Definition TVectorDfwd.h:23
#define TMVA_RELEASE
Definition Version.h:44
#define TMVA_RELEASE_DATE
Definition Version.h:45
Double_t GetXmax() const
Definition TAxis.h:135
Double_t GetXmin() const
Definition TAxis.h:134
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
1-D histogram with a float per channel (see TH1 documentation)}
Definition TH1.h:577
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
Definition TH1.cxx:9007
TAxis * GetXaxis()
Definition TH1.h:322
virtual Int_t GetNbinsX() const
Definition TH1.h:295
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
Definition TH1.cxx:9088
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:5025
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
Definition TH1.cxx:6586
virtual Int_t GetSumw2N() const
Definition TH1.h:313
TObject * Clone(const char *newname="") const override
Make a complete copy of the underlying object.
Definition TH1.cxx:2727
virtual Double_t GetSumOfWeights() const
Return the sum of weights excluding under/overflows.
Definition TH1.cxx:7827
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition TH1.cxx:8886
2-D histogram with a float per channel (see TH1 documentation)}
Definition TH2.h:257
Service class for 2-D histogram classes.
Definition TH2.h:30
void SetBinContent(Int_t bin, Double_t content) override
Set bin content.
Definition TH2.cxx:2554
Double_t Integral(Option_t *option="") const override
Return integral of bin contents.
Definition TH2.cxx:1270
void PutStats(Double_t *stats) override
Replace current statistics with the values in array stats.
Definition TH2.cxx:2423
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:357
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
Definition Event.cxx:236
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not.
Definition Event.cxx:389
UInt_t GetClass() const
Definition Event.h:86
ostringstream derivative to redirect and format output
Definition MsgLogger.h:57
PDF wrapper for histograms; uses user-defined spline interpolation.
Definition PDF.h:63
Double_t GetXmin() const
Definition PDF.h:104
Double_t GetXmax() const
Definition PDF.h:105
Double_t GetVal(Double_t x) const
returns value PDF(x)
Definition PDF.cxx:701
Global auxiliary applications and data treatment routines.
Definition Tools.h:76
void ComputeStat(const std::vector< TMVA::Event * > &, std::vector< Float_t > *, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Int_t signalClass, Bool_t norm=kFALSE)
sanity check
Definition Tools.cxx:202
void * GetParent(void *child)
get parent node
Definition Tools.cxx:1140
void FormattedOutput(const std::vector< Double_t > &, const std::vector< TString > &, const TString titleVars, const TString titleValues, MsgLogger &logger, TString format="%+1.3f")
formatted output of simple table
Definition Tools.cxx:887
Bool_t HistoHasEquidistantBins(const TH1 &h)
Definition Tools.cxx:1487
TList * ParseFormatLine(TString theString, const char *sep=":")
Parse the string and cut into labels separated by ":".
Definition Tools.cxx:401
Double_t NormVariable(Double_t x, Double_t xmin, Double_t xmax)
normalise to output range: [-1, 1]
Definition Tools.cxx:110
void WriteFloatArbitraryPrecision(Float_t val, std::ostream &os)
writes a float value with the available precision to a stream
Definition Tools.cxx:1058
TString GetYTitleWithUnit(const TH1 &h, const TString &unit, Bool_t normalised)
histogramming utility
Definition Tools.cxx:1048
Double_t GetSeparation(TH1 *S, TH1 *B) const
compute "separation" defined as
Definition Tools.cxx:121
static Tools & Instance()
Definition Tools.cxx:71
TMatrixD * GetSQRootMatrix(TMatrixDSym *symMat)
square-root of symmetric matrix of course the resulting sqrtMat is also symmetric,...
Definition Tools.cxx:271
std::vector< Double_t > MVADiff(std::vector< Double_t > &, std::vector< Double_t > &)
computes difference between two vectors
Definition Tools.cxx:506
Int_t GetIndexMinElement(std::vector< Double_t > &)
find index of minimum entry in vector
Definition Tools.cxx:765
TH1 * projNormTH1F(TTree *theTree, const TString &theVarName, const TString &name, Int_t nbins, Double_t xmin, Double_t xmax, const TString &cut)
projects variable from tree into normalised histogram
Definition Tools.cxx:366
void ROOTVersionMessage(MsgLogger &logger)
prints the ROOT release number and date
Definition Tools.cxx:1325
TString ReplaceRegularExpressions(const TString &s, const TString &replace="+")
replace regular expressions helper function to remove all occurrences "$!%^&()'<>?...
Definition Tools.cxx:798
void ReadTVectorDFromXML(void *node, const char *name, TVectorD *vec)
Definition Tools.cxx:1267
TH1 * GetCumulativeDist(TH1 *h)
get the cumulative distribution of a histogram
Definition Tools.cxx:1757
void ReadFloatArbitraryPrecision(Float_t &val, std::istream &is)
reads a float value with the available precision from a stream
Definition Tools.cxx:1073
Bool_t AddRawLine(void *node, const char *raw)
XML helpers.
Definition Tools.cxx:1190
~Tools()
destructor
Definition Tools.cxx:101
Bool_t ContainsRegularExpression(const TString &s)
check if regular expression helper function to search for "$!%^&()'<>?= " in a string
Definition Tools.cxx:784
void UsefulSortDescending(std::vector< std::vector< Double_t > > &, std::vector< TString > *vs=nullptr)
sort 2D vector (AND in parallel a TString vector) in such a way that the "first vector is sorted" and...
Definition Tools.cxx:564
static void DestroyInstance()
Definition Tools.cxx:82
Double_t Mean(Long64_t n, const T *a, const Double_t *w=0)
Return the weighted mean of an array a with length n.
Definition Tools.cxx:1688
Double_t GetMutualInformation(const TH2F &)
Mutual Information method for non-linear correlations estimates in 2D histogram Author: Moritz Backes...
Definition Tools.cxx:589
std::vector< TString > SplitString(const TString &theOpt, const char separator) const
splits the option string at 'separator' and fills the list 'splitV' with the primitive strings
Definition Tools.cxx:1199
const TString & Color(const TString &)
human readable color strings
Definition Tools.cxx:828
TString StringFromDouble(Double_t d)
string tools
Definition Tools.cxx:1233
Bool_t CheckForVerboseOption(const TString &) const
check if verbosity "V" set in option
Definition Tools.cxx:708
Double_t RMS(Long64_t n, const T *a, const Double_t *w=0)
Return the Standard Deviation of an array a with length n.
Definition Tools.cxx:1744
const char * GetContent(void *node)
XML helpers.
Definition Tools.cxx:1174
void WriteTVectorDToXML(void *node, const char *name, TVectorD *vec)
Definition Tools.cxx:1259
TXMLEngine & xmlengine()
Definition Tools.h:262
void Scale(std::vector< Double_t > &, Double_t)
scales double vector
Definition Tools.cxx:519
Bool_t CheckSplines(const TH1 *, const TSpline *)
check quality of splining by comparing splines and histograms in each bin
Definition Tools.cxx:479
const char * GetName(void *node)
XML helpers.
Definition Tools.cxx:1182
const TMatrixD * GetCorrelationMatrix(const TMatrixD *covMat)
turns covariance into correlation matrix
Definition Tools.cxx:324
void WriteTMatrixDToXML(void *node, const char *name, TMatrixD *mat)
XML helpers.
Definition Tools.cxx:1243
Double_t GetCorrelationRatio(const TH2F &)
Compute Correlation Ratio of 2D histogram to estimate functional dependency between two variables Aut...
Definition Tools.cxx:620
void ReadAttr(void *node, const char *, T &value)
read attribute from xml
Definition Tools.h:329
static std::atomic< Tools * > fgTools
Definition Tools.h:229
Bool_t AddComment(void *node, const char *comment)
Definition Tools.cxx:1132
void ReadTMatrixDFromXML(void *node, const char *name, TMatrixD *mat)
Definition Tools.cxx:1276
TString GetXTitleWithUnit(const TString &title, const TString &unit)
histogramming utility
Definition Tools.cxx:1040
void * GetChild(void *parent, const char *childname=nullptr)
get child node
Definition Tools.cxx:1150
void AddAttr(void *node, const char *, const T &value, Int_t precision=16)
add attribute to xml
Definition Tools.h:347
TString StringFromInt(Long_t i)
string tools
Definition Tools.cxx:1223
Tools()
constructor
Definition Tools.cxx:91
Double_t NormHist(TH1 *theHist, Double_t norm=1.0)
normalises histogram
Definition Tools.cxx:383
void * AddChild(void *parent, const char *childname, const char *content=nullptr, bool isRootNode=false)
add child node
Definition Tools.cxx:1124
void UsefulSortAscending(std::vector< std::vector< Double_t > > &, std::vector< TString > *vs=nullptr)
sort 2D vector (AND in parallel a TString vector) in such a way that the "first vector is sorted" and...
Definition Tools.cxx:538
Double_t GetYMean_binX(const TH2 &, Int_t bin_x)
Compute the mean in Y for a given bin X of a 2D histogram.
Definition Tools.cxx:642
std::vector< TMatrixDSym * > * CalcCovarianceMatrices(const std::vector< Event * > &events, Int_t maxCls, VariableTransformBase *transformBase=nullptr)
compute covariance matrices
Definition Tools.cxx:1514
void TMVACitation(MsgLogger &logger, ECitation citType=kPlainText)
kinds of TMVA citation
Definition Tools.cxx:1441
void TMVAVersionMessage(MsgLogger &logger)
prints the TMVA release number and date
Definition Tools.cxx:1316
void TMVAWelcomeMessage()
direct output, eg, when starting ROOT session -> no use of Logger here
Definition Tools.cxx:1302
std::vector< Int_t > * ParseANNOptionString(TString theOptions, Int_t nvar, std::vector< Int_t > *nodes)
parse option string for ANN methods default settings (should be defined in theOption string)
Definition Tools.cxx:443
Int_t GetIndexMaxElement(std::vector< Double_t > &)
find index of maximum entry in vector
Definition Tools.cxx:748
TH2F * TransposeHist(const TH2F &)
Transpose quadratic histogram.
Definition Tools.cxx:657
EWelcomeMessage
Definition Tools.h:198
Bool_t HasAttr(void *node, const char *attrname)
add attribute from xml
Definition Tools.cxx:1094
void * GetNextChild(void *prevchild, const char *childname=nullptr)
XML helpers.
Definition Tools.cxx:1162
const TString fRegexp
Definition Tools.h:226
Bool_t CheckForSilentOption(const TString &) const
check for "silence" option in configuration option string
Definition Tools.cxx:691
Linear interpolation class.
virtual Bool_t GetInput(const Event *event, std::vector< Float_t > &input, std::vector< Char_t > &mask, Bool_t backTransform=kFALSE) const
select the values from the event
virtual void CountVariableTypes(UInt_t &nvars, UInt_t &ntgts, UInt_t &nspcts) const
count variables, targets and spectators
TMatrixDSymEigen.
const TMatrixD & GetEigenVectors() const
Int_t GetNrows() const
Int_t GetNcols() const
TMatrixT< Element > & Transpose(const TMatrixT< Element > &source)
Transpose matrix source.
TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1) override
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
TMatrixT< Element > & Invert(Double_t *det=nullptr)
Invert the matrix and calculate its determinant.
void Mult(const TMatrixT< Element > &a, const TMatrixT< Element > &b)
General matrix multiplication. Create a matrix C such that C = A * B.
Definition TMatrixT.cxx:649
Collectable string class.
Definition TObjString.h:28
Base class for spline implementation containing the Draw/Paint methods.
Definition TSpline.h:31
virtual Double_t Eval(Double_t x) const =0
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:421
void ToLower()
Change string to lower-case.
Definition TString.cxx:1170
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition TString.cxx:1151
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition TString.cxx:531
const char * Data() const
Definition TString.h:380
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:704
@ kLeading
Definition TString.h:278
@ kBoth
Definition TString.h:278
void ToUpper()
Change string to upper case.
Definition TString.cxx:1183
TString & Remove(Ssiz_t pos)
Definition TString.h:685
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:636
A TTree represents a columnar dataset.
Definition TTree.h:79
virtual Long64_t Project(const char *hname, const char *varexp, const char *selection="", Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0)
Make a projection of a tree using selections.
Definition TTree.cxx:7489
XMLNodePointer_t NewChild(XMLNodePointer_t parent, XMLNsPointer_t ns, const char *name, const char *content=nullptr)
create new child element for parent node
XMLAttrPointer_t NewAttr(XMLNodePointer_t xmlnode, XMLNsPointer_t, const char *name, const char *value)
creates new attribute for xmlnode, namespaces are not supported for attributes
Bool_t AddComment(XMLNodePointer_t parent, const char *comment)
Adds comment line to the node.
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Config & gConfig()
Tools & gTools()
MsgLogger & Endl(MsgLogger &ml)
Definition MsgLogger.h:148
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:250
Double_t Log(Double_t x)
Returns the natural logarithm of x.
Definition TMath.h:754
Double_t Mean(Long64_t n, const T *a, const Double_t *w=0)
Returns the weighted mean of an array a with length n.
Definition TMath.h:1087
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:660
Double_t RMS(Long64_t n, const T *a, const Double_t *w=0)
Returns the Standard Deviation of an array a with length n.
Definition TMath.h:1186
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123
Definition first.py:1
TMarker m
Definition textangle.C:8
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2345
double epsilon
Definition triangle.c:618