ROOT  6.06/09
Reference Guide
VariableRearrangeTransform.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Peter Speckmayer
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : VariableRearrangeTransform *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Implementation (see header for description) *
12  * *
13  * Authors (alphabetical): *
14  * Peter Speckmayer <Peter.Speckmayer@cern.ch> - CERN, Switzerland *
15  * *
16  * Copyright (c) 2005: *
17  * CERN, Switzerland *
18  * MPI-K Heidelberg, Germany *
19  * *
20  * Redistribution and use in source and binary forms, with or without *
21  * modification, are permitted according to the terms listed in LICENSE *
22  * (http://tmva.sourceforge.net/LICENSE) *
23  **********************************************************************************/
24 
25 #include <iostream>
26 #include <iomanip>
27 #include <stdexcept>
28 
29 #ifndef ROOT_TMVA_MsgLogger
30 #include "TMVA/MsgLogger.h"
31 #endif
32 #ifndef ROOT_TMVA_VariableRearrangeTransform
34 #endif
35 #ifndef ROOT_TMVA_Tools
36 #include "TMVA/Tools.h"
37 #endif
38 #ifndef ROOT_TMVA_DataSet
39 #include "TMVA/DataSet.h"
40 #endif
41 
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// constructor
46 
47 TMVA::VariableRearrangeTransform::VariableRearrangeTransform( DataSetInfo& dsi )
48 : VariableTransformBase( dsi, Types::kRearranged, "Rearrange" )
49 {
50 }
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 
55 }
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// initialization of the rearrangement transformation
59 /// (nothing to do)
60 
62 {
63 }
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// prepare transformation --> (nothing to do)
67 
68 Bool_t TMVA::VariableRearrangeTransform::PrepareTransformation (const std::vector<Event*>& /*events*/)
69 {
70  if (!IsEnabled() || IsCreated()) return kTRUE;
71 
72  UInt_t nvars = 0, ntgts = 0, nspcts = 0;
73  CountVariableTypes( nvars, ntgts, nspcts );
74  if (ntgts>0) Log() << kFATAL << "Targets used in Rearrange-transformation." << Endl;
75 
76  SetCreated( kTRUE );
77  return kTRUE;
78 }
79 
80 ////////////////////////////////////////////////////////////////////////////////
81 
83 {
84  if (!IsEnabled()) return ev;
85 
86  // apply the normalization transformation
87  if (!IsCreated()) Log() << kFATAL << "Transformation not yet created" << Endl;
88 
89  if (fTransformedEvent==0) fTransformedEvent = new Event();
90 
91  FloatVector input; // will be filled with the selected variables, (targets)
92  std::vector<Char_t> mask; // masked variables
93  GetInput( ev, input, mask );
94  SetOutput( fTransformedEvent, input, mask, ev );
95 
96  return fTransformedEvent;
97 }
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 
102 {
103  if (!IsEnabled()) return ev;
104 
105  // apply the inverse transformation
106  if (!IsCreated()) Log() << kFATAL << "Transformation not yet created" << Endl;
107 
108  if (fBackTransformedEvent==0) fBackTransformedEvent = new Event( *ev );
109 
110  FloatVector input; // will be filled with the selected variables, targets, (spectators)
111  std::vector<Char_t> mask; // masked variables
112  GetInput( ev, input, mask, kTRUE );
113  SetOutput( fBackTransformedEvent, input, mask, ev, kTRUE );
114 
115  return fBackTransformedEvent;
116 }
117 
118 
119 ////////////////////////////////////////////////////////////////////////////////
120 /// creates string with variable transformations applied
121 
123 {
124  const UInt_t size = fGet.size();
125  std::vector<TString>* strVec = new std::vector<TString>(size);
126 
127  return strVec;
128 }
129 
130 ////////////////////////////////////////////////////////////////////////////////
131 /// // create XML description of Rearrange transformation
132 
134 {
135  void* trfxml = gTools().AddChild(parent, "Transform");
136  gTools().AddAttr(trfxml, "Name", "Rearrange");
137 
139 }
140 
141 ////////////////////////////////////////////////////////////////////////////////
142 /// // Read the transformation matrices from the xml node
143 
145 {
146 
147  void* inpnode = NULL;
148 
149  inpnode = gTools().GetChild(trfnode, "Selection"); // new xml format
150  if(inpnode == NULL)
151  Log() << kFATAL << "Unknown weight file format for transformations. (tried to read in 'rearrange' transform)" << Endl;
152 
154 
155  SetCreated();
156 }
157 
158 ////////////////////////////////////////////////////////////////////////////////
159 /// prints the transformation ranges
160 
162 {
163 }
164 
165 ////////////////////////////////////////////////////////////////////////////////
166 /// creates a normalizing function
167 
168 void TMVA::VariableRearrangeTransform::MakeFunction( std::ostream& /*fout*/, const TString& /*fcncName*/,
169  Int_t /*part*/, UInt_t /*trCounter*/, Int_t )
170 {
171 }
void Initialize()
initialization of the rearrangement transformation (nothing to do)
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
virtual void MakeFunction(std::ostream &fout, const TString &fncName, Int_t part, UInt_t trCounter, Int_t cls)
creates a normalizing function
virtual const Event * InverseTransform(const Event *const, Int_t cls) const
virtual void AttachXMLTo(void *parent)=0
create XML description the transformation (write out info of selected variables)
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Bool_t PrepareTransformation(const std::vector< Event * > &)
prepare transformation –> (nothing to do)
void AddAttr(void *node, const char *, const T &value, Int_t precision=16)
Definition: Tools.h:308
void * AddChild(void *parent, const char *childname, const char *content=0, bool isRootNode=false)
add child node
Definition: Tools.cxx:1134
Tools & gTools()
Definition: Tools.cxx:79
virtual const Event * Transform(const Event *const, Int_t cls) const
virtual void PrintTransformation(std::ostream &o)
prints the transformation ranges
void * GetChild(void *parent, const char *childname=0)
get child node
Definition: Tools.cxx:1158
std::vector< TString > * GetTransformationStrings(Int_t cls) const
creates string with variable transformations applied
virtual void ReadFromXML(void *trfnode)=0
Read the input variables from the XML node.
virtual void ReadFromXML(void *trfnode)
// Read the transformation matrices from the xml node
unsigned int UInt_t
Definition: RtypesCore.h:42
Abstract ClassifierFactory template that handles arbitrary types.
#define NULL
Definition: Rtypes.h:82
const Bool_t kTRUE
Definition: Rtypes.h:91
ClassImp(TMVA::VariableRearrangeTransform) TMVA
constructor
virtual void AttachXMLTo(void *parent)
// create XML description of Rearrange transformation
Definition: math.cpp:60