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