79 CleanUpCumulativeArrays();
95 if (!IsEnabled() || IsCreated())
return kTRUE;
97 Log() << kINFO <<
"Preparing the Gaussian transformation..." <<
Endl;
99 UInt_t inputSize = fGet.size();
100 SetNVariables(inputSize);
102 if (inputSize > 200) {
103 Log() << kWARNING <<
"----------------------------------------------------------------------------"
106 <<
": More than 200 variables, I hope you have enough memory!!!!" <<
Endl;
107 Log() << kWARNING <<
"----------------------------------------------------------------------------"
112 GetCumulativeDist(
events );
124 if (!IsCreated()) Log() << kFATAL <<
"Transformation not yet created" <<
Endl;
134 UInt_t inputSize = fGet.size();
136 std::vector<Float_t>
input(0);
137 std::vector<Float_t>
output(0);
139 std::vector<Char_t>
mask;
142 std::vector<Char_t>::iterator
itMask =
mask.begin();
155 if (0 != fCumulativePDF[
ivar][
cls]) {
178 if (fTransformedEvent==0 || fTransformedEvent->GetNVariables()!=
ev->GetNVariables()) {
179 if (fTransformedEvent!=0) {
delete fTransformedEvent; fTransformedEvent = 0; }
180 fTransformedEvent =
new Event();
185 return fTransformedEvent;
193 if (!IsCreated()) Log() << kFATAL <<
"Transformation not yet created" <<
Endl;
203 UInt_t inputSize = fGet.size();
205 std::vector<Float_t>
input(0);
206 std::vector<Float_t>
output(0);
208 std::vector<Char_t>
mask;
211 std::vector<Char_t>::iterator
itMask =
mask.begin();
224 if (0 != fCumulativePDF[
ivar][
cls]) {
235 Log() << kFATAL <<
"Inverse Uniform/Gauss transformation not implemented for TMVA versions before 4.1.0" <<
Endl;
241 if (fBackTransformedEvent==0) fBackTransformedEvent =
new Event( *
ev );
245 return fBackTransformedEvent;
253 const UInt_t inputSize = fGet.size();
271 nbins[i] =
new UInt_t[inputSize];
274 std::vector<Float_t>
input;
275 std::vector<Char_t>
mask;
297 Log() << kWARNING <<
"Incomplete event" <<
Endl;
298 std::ostringstream
oss;
301 Log() << kFATAL <<
"Targets or variables masked by transformation. Apparently (a) value(s) is/are missing in this event." <<
Endl;
327 std::list< TMVA::TMVAGaussPair >::iterator it;
338 sum+= it->GetWeight();
358 fCumulativeDist.resize(inputSize);
374 fCumulativeDist[
ivar][
icls]->SetDirectory(
nullptr);
410 CleanUpCumulativeArrays(
"PDF");
414 fCumulativePDF.resize(inputSize);
418 (fCumulativeDist[
ivar][
icls])->Smooth();
423 if (val>0)
total += val;
427 if (val>0)
sum += val;
440 Log() << kFATAL <<
"VariableGaussTransform::WriteTransformationToStream is obsolete" <<
Endl;
447 if (opt ==
"ALL" || opt ==
"PDF"){
453 fCumulativePDF.clear();
455 if (opt ==
"ALL" || opt ==
"Dist"){
461 fCumulativeDist.clear();
474 UInt_t nvar = fGet.size();
480 if ( fCumulativePDF[
ivar][0]==0 ||
481 (fCumulativePDF[
ivar].
size()>1 && fCumulativePDF[
ivar][1]==0 ))
482 Log() << kFATAL <<
"Cumulative histograms for variable " <<
ivar <<
" don't exist, can't write it to weight file" <<
Endl;
496 CleanUpCumulativeArrays();
502 else fFlatNotGauss =
kFALSE;
538 fCumulativePDF.resize(
ivar+1 );
556 istr.getline(buf,512);
560 while (!(buf[0]==
'#'&& buf[1]==
'#')) {
562 while (*
p==
' ' || *
p==
'\t')
p++;
563 if (*
p==
'#' || *
p==
'\0') {
564 istr.getline(buf,512);
567 std::stringstream
sstr(buf);
570 if (
strvar==
"CumulativeHistogram") {
586 if(
ivar>=fCumulativeDist.size()) fCumulativeDist.resize(
ivar+1);
604 fCumulativePDF.resize(
ivar+1);
605 fCumulativePDF[
ivar].resize(
type+1);
612 sstr >> fFlatNotGauss;
613 istr.getline(buf,512);
617 istr.getline(buf,512);
658 if (bin >
h->GetNbinsX()) {
662 if (bin ==
h->GetNbinsX()) {
675 if (
x >=
h->GetBinLowEdge(
h->GetNbinsX()+1)){
687 Log() << kINFO <<
"I do not know yet how to print this... look in the weight file " <<
cls <<
":" <<
Endl;
698 const UInt_t nvar = fGet.size();
711 fout <<
" int nvar;" << std::endl;
714 fout <<
" double cumulativeDist["<<nvar<<
"]["<<
numDist<<
"]["<<nBins+1<<
"];"<<std::endl;
715 fout <<
" double X["<<nvar<<
"]["<<
numDist<<
"]["<<nBins+1<<
"];"<<std::endl;
716 fout <<
" double xMin["<<nvar<<
"]["<<
numDist<<
"];"<<std::endl;
717 fout <<
" double xMax["<<nvar<<
"]["<<
numDist<<
"];"<<std::endl;
718 fout <<
" int nbins["<<nvar<<
"]["<<
numDist<<
"];"<<std::endl;
722 fout <<
"#include \"math.h\"" << std::endl;
724 fout <<
"//_______________________________________________________________________" << std::endl;
726 fout <<
"{" << std::endl;
727 fout <<
" // Gauss/Uniform transformation, initialisation" << std::endl;
728 fout <<
" nvar=" << nvar <<
";" << std::endl;
746 Log() << kWARNING <<
"MakeClass for the Gauss transformation works only for the transformation of variables. The transformation of targets/spectators is not implemented." <<
Endl;
748 }
catch( std::out_of_range &){
749 Log() << kWARNING <<
"MakeClass for the Gauss transformation searched for a non existing variable index (" <<
ivar <<
")" <<
Endl;
766 fout <<
"}" << std::endl;
768 fout <<
"//_______________________________________________________________________" << std::endl;
769 fout <<
"inline void " <<
fcncName <<
"::Transform_"<<
trCounter<<
"( std::vector<double>& iv, int clsIn) const" << std::endl;
770 fout <<
"{" << std::endl;
771 fout <<
" // Gauss/Uniform transformation" << std::endl;
772 fout <<
" int cls=clsIn;" << std::endl;
773 fout <<
" if (cls < 0 || cls > "<<GetNClasses()<<
") {"<< std::endl;
774 fout <<
" if ("<<GetNClasses()<<
" > 1 ) cls = "<<GetNClasses()<<
";"<< std::endl;
775 fout <<
" else cls = "<<(fCumulativePDF[0].size()==1?0:2)<<
";"<< std::endl;
776 fout <<
" }"<< std::endl;
778 fout <<
" // copy the variables which are going to be transformed "<< std::endl;
780 fout <<
" static std::vector<double> dv; "<< std::endl;
781 fout <<
" dv.resize(nvar); "<< std::endl;
782 fout <<
" for (int ivar=0; ivar<nvar; ivar++) dv[ivar] = iv[indicesGet.at(ivar)]; "<< std::endl;
783 fout <<
" "<< std::endl;
784 fout <<
" bool FlatNotGauss = "<< (fFlatNotGauss?
"true":
"false") <<
"; "<< std::endl;
785 fout <<
" double cumulant; "<< std::endl;
786 fout <<
" //const int nvar = "<<nvar<<
"; "<< std::endl;
787 fout <<
" for (int ivar=0; ivar<nvar; ivar++) { "<< std::endl;
788 fout <<
" int nbin = nbins[ivar][cls]; "<< std::endl;
789 fout <<
" int ibin=0; "<< std::endl;
790 fout <<
" while (dv[ivar] > X[ivar][cls][ibin]) ibin++; "<< std::endl;
791 fout <<
" "<< std::endl;
792 fout <<
" if (ibin<0) { ibin=0;} "<< std::endl;
793 fout <<
" if (ibin>=nbin) { ibin=nbin-1;} "<< std::endl;
794 fout <<
" int nextbin = ibin; "<< std::endl;
795 fout <<
" if ((dv[ivar] > X[ivar][cls][ibin] && ibin !=nbin-1) || ibin==0) "<< std::endl;
796 fout <<
" nextbin++; "<< std::endl;
797 fout <<
" else "<< std::endl;
798 fout <<
" nextbin--; "<< std::endl;
799 fout <<
" "<< std::endl;
800 fout <<
" double dx = X[ivar][cls][ibin]- X[ivar][cls][nextbin]; "<< std::endl;
801 fout <<
" double dy = cumulativeDist[ivar][cls][ibin] - cumulativeDist[ivar][cls][nextbin]; "<< std::endl;
802 fout <<
" cumulant = cumulativeDist[ivar][cls][ibin] + (dv[ivar] - X[ivar][cls][ibin])* dy/dx;"<< std::endl;
803 fout <<
" "<< std::endl;
804 fout <<
" "<< std::endl;
805 fout <<
" if (cumulant>1.-10e-10) cumulant = 1.-10e-10; "<< std::endl;
806 fout <<
" if (cumulant<10e-10) cumulant = 10e-10; "<< std::endl;
807 fout <<
" if (FlatNotGauss) dv[ivar] = cumulant; "<< std::endl;
808 fout <<
" else { "<< std::endl;
809 fout <<
" double maxErfInvArgRange = 0.99999999; "<< std::endl;
810 fout <<
" double arg = 2.0*cumulant - 1.0; "<< std::endl;
811 fout <<
" if (arg > maxErfInvArgRange) arg= maxErfInvArgRange; "<< std::endl;
812 fout <<
" if (arg < -maxErfInvArgRange) arg=-maxErfInvArgRange; "<< std::endl;
813 fout <<
" double inverf=0., stp=1. ; "<< std::endl;
814 fout <<
" while (stp >1.e-10){; "<< std::endl;
815 fout <<
" if (erf(inverf)>arg) inverf -=stp ; "<< std::endl;
816 fout <<
" else if (erf(inverf)<=arg && erf(inverf+stp)>=arg) stp=stp/5. ; "<< std::endl;
817 fout <<
" else inverf += stp; "<< std::endl;
818 fout <<
" } ; "<< std::endl;
819 fout <<
" //dv[ivar] = 1.414213562*TMath::ErfInverse(arg); "<< std::endl;
820 fout <<
" dv[ivar] = 1.414213562* inverf; "<< std::endl;
821 fout <<
" } "<< std::endl;
822 fout <<
" } "<< std::endl;
823 fout <<
" // copy the transformed variables back "<< std::endl;
824 fout <<
" for (int ivar=0; ivar<nvar; ivar++) iv[indicesPut.at(ivar)] = dv[ivar]; "<< std::endl;
825 fout <<
"} "<< std::endl;
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
static unsigned int total
winID h TVirtualViewer3D TVirtualGLPainter p
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 value
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
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 type
Option_t Option_t TPoint TPoint const char y1
#define TMVA_VERSION(a, b, c)
const_iterator begin() const
const_iterator end() const
1-D histogram with a float per channel (see TH1 documentation)
TH1 is the base class of all histogram classes in ROOT.
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
static Bool_t AddDirectoryStatus()
Static function: cannot be inlined on Windows/NT.
Class that contains all the data information.
PDF wrapper for histograms; uses user-defined spline interpolation.
Singleton class for Global types used by TMVA.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
MsgLogger & Endl(MsgLogger &ml)
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Double_t Erf(Double_t x)
Computation of the error function erf(x).
Double_t ErfInverse(Double_t x)
Returns the inverse error function.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
static uint64_t sum(uint64_t i)