Logo ROOT   6.07/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 
26 
27 #include "TMVA/DataSet.h"
28 #include "TMVA/Event.h"
29 #include "TMVA/MsgLogger.h"
30 #include "TMVA/Tools.h"
31 #include "TMVA/Types.h"
32 
33 #include <iostream>
34 #include <iomanip>
35 #include <stdexcept>
36 
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// constructor
41 
43 : VariableTransformBase( dsi, Types::kRearranged, "Rearrange" )
44 {
45 }
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 
50 }
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// initialization of the rearrangement transformation
54 /// (nothing to do)
55 
57 {
58 }
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// prepare transformation --> (nothing to do)
62 
63 Bool_t TMVA::VariableRearrangeTransform::PrepareTransformation (const std::vector<Event*>& /*events*/)
64 {
65  if (!IsEnabled() || IsCreated()) return kTRUE;
66 
67  UInt_t nvars = 0, ntgts = 0, nspcts = 0;
68  CountVariableTypes( nvars, ntgts, nspcts );
69  if (ntgts>0) Log() << kFATAL << "Targets used in Rearrange-transformation." << Endl;
70 
71  SetCreated( kTRUE );
72  return kTRUE;
73 }
74 
75 ////////////////////////////////////////////////////////////////////////////////
76 
78 {
79  if (!IsEnabled()) return ev;
80 
81  // apply the normalization transformation
82  if (!IsCreated()) Log() << kFATAL << "Transformation not yet created" << Endl;
83 
85 
86  FloatVector input; // will be filled with the selected variables, (targets)
87  std::vector<Char_t> mask; // masked variables
88  GetInput( ev, input, mask );
89  SetOutput( fTransformedEvent, input, mask, ev );
90 
91  return fTransformedEvent;
92 }
93 
94 ////////////////////////////////////////////////////////////////////////////////
95 
97 {
98  if (!IsEnabled()) return ev;
99 
100  // apply the inverse transformation
101  if (!IsCreated()) Log() << kFATAL << "Transformation not yet created" << Endl;
102 
104 
105  FloatVector input; // will be filled with the selected variables, targets, (spectators)
106  std::vector<Char_t> mask; // masked variables
107  GetInput( ev, input, mask, kTRUE );
108  SetOutput( fBackTransformedEvent, input, mask, ev, kTRUE );
109 
110  return fBackTransformedEvent;
111 }
112 
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 /// creates string with variable transformations applied
116 
118 {
119  const UInt_t size = fGet.size();
120  std::vector<TString>* strVec = new std::vector<TString>(size);
121 
122  return strVec;
123 }
124 
125 ////////////////////////////////////////////////////////////////////////////////
126 /// // create XML description of Rearrange transformation
127 
129 {
130  void* trfxml = gTools().AddChild(parent, "Transform");
131  gTools().AddAttr(trfxml, "Name", "Rearrange");
132 
134 }
135 
136 ////////////////////////////////////////////////////////////////////////////////
137 /// // Read the transformation matrices from the xml node
138 
140 {
141 
142  void* inpnode = NULL;
143 
144  inpnode = gTools().GetChild(trfnode, "Selection"); // new xml format
145  if(inpnode == NULL)
146  Log() << kFATAL << "Unknown weight file format for transformations. (tried to read in 'rearrange' transform)" << Endl;
147 
149 
150  SetCreated();
151 }
152 
153 ////////////////////////////////////////////////////////////////////////////////
154 /// prints the transformation ranges
155 
157 {
158 }
159 
160 ////////////////////////////////////////////////////////////////////////////////
161 /// creates a normalizing function
162 
163 void TMVA::VariableRearrangeTransform::MakeFunction( std::ostream& /*fout*/, const TString& /*fcncName*/,
164  Int_t /*part*/, UInt_t /*trCounter*/, Int_t )
165 {
166 }
virtual void CountVariableTypes(UInt_t &nvars, UInt_t &ntgts, UInt_t &nspcts) const
count variables, targets and spectators
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:309
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 SetOutput(Event *event, std::vector< Float_t > &output, std::vector< Char_t > &mask, const Event *oldEvent=0, Bool_t backTransform=kFALSE) const
select the values from the event
virtual void ReadFromXML(void *trfnode)
// Read the transformation matrices from the xml node
unsigned int UInt_t
Definition: RtypesCore.h:42
#define ClassImp(name)
Definition: Rtypes.h:279
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
Abstract ClassifierFactory template that handles arbitrary types.
#define NULL
Definition: Rtypes.h:82
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void AttachXMLTo(void *parent)
// create XML description of Rearrange transformation