82 fDataSetManager ( NULL ),
84 fTransformations (
"I" ),
86 fDataAssignType ( kAssignEvents ),
100 std::vector<TMVA::VariableTransformBase*>::iterator trfIt = fDefaultTrfs.begin();
101 for (;trfIt != fDefaultTrfs.end(); ++trfIt)
delete (*trfIt);
103 delete fDataInputHandler;
107 delete fDataSetManager;
121 return fDataSetManager->AddDataSetInfo(dsi);
128 DataSetInfo* dsi = fDataSetManager->GetDataSetInfo(dsiName);
130 if (dsi!=0)
return *dsi;
132 return fDataSetManager->AddDataSetInfo(*(
new DataSetInfo(dsiName)));
139 return DefaultDataSetInfo();
150 if (trafoDefinition.
Contains(
"(")) {
154 Ssiz_t parLen = trafoDefinition.
Index(
")", parStart )-parStart+1;
156 trName = trafoDefinition(0,parStart);
157 trOptions = trafoDefinition(parStart,parLen);
158 trOptions.
Remove(parLen-1,1);
162 trName = trafoDefinition;
166 if (trName ==
"VT") {
171 Log() << kFATAL <<
" VT transformation must be passed a floating threshold value" <<
Endl;
176 threshold = trOptions.
Atof();
179 return transformedLoader;
183 Log() << kFATAL <<
"Incorrect transformation string provided, please check" <<
Endl;
185 Log() << kINFO <<
"No transformation applied, returning original loader" <<
Endl;
199 assignTree->
Branch(
"type", &fATreeType,
"ATreeType/I" );
200 assignTree->
Branch(
"weight", &fATreeWeight,
"ATreeWeight/F" );
202 std::vector<VariableInfo>& vars = DefaultDataSetInfo().GetVariableInfos();
203 std::vector<VariableInfo>& tgts = DefaultDataSetInfo().GetTargetInfos();
204 std::vector<VariableInfo>& spec = DefaultDataSetInfo().GetSpectatorInfos();
206 if (fATreeEvent.size()==0) fATreeEvent.resize(vars.size()+tgts.size()+spec.size());
208 for (
UInt_t ivar=0; ivar<vars.size(); ivar++) {
209 TString vname = vars[ivar].GetExpression();
210 assignTree->
Branch( vname, &fATreeEvent[ivar], vname +
"/F" );
213 for (
UInt_t itgt=0; itgt<tgts.size(); itgt++) {
214 TString vname = tgts[itgt].GetExpression();
215 assignTree->
Branch( vname, &fATreeEvent[vars.size()+itgt], vname +
"/F" );
218 for (
UInt_t ispc=0; ispc<spec.size(); ispc++) {
219 TString vname = spec[ispc].GetExpression();
220 assignTree->
Branch( vname, &fATreeEvent[vars.size()+tgts.size()+ispc], vname +
"/F" );
278 const std::vector<Double_t>& event,
Double_t weight )
280 ClassInfo* theClass = DefaultDataSetInfo().AddClass(className);
289 if (clIndex>=fTrainAssignTree.size()) {
290 fTrainAssignTree.resize(clIndex+1, 0);
291 fTestAssignTree.resize(clIndex+1, 0);
294 if (fTrainAssignTree[clIndex]==0) {
295 fTrainAssignTree[clIndex] = CreateEventAssignTrees(
TString::Format(
"TrainAssignTree_%s", className.
Data()).
Data() );
296 fTestAssignTree[clIndex] = CreateEventAssignTrees(
TString::Format(
"TestAssignTree_%s", className.
Data()).
Data() );
299 fATreeType = clIndex;
300 fATreeWeight = weight;
301 if (event.size() > fATreeEvent.size()) {
302 Error(
"TMVA::DataLoader::AddEvent",
"Number of variables defined through DataLoader::AddVariable (%zu) is inconsistent"
303 "with number of variables given to DataLoader::Add*Event (%zu)."
304 "Please check your variable definitions and statement ordering."
305 "This event will not be added.", fATreeEvent.size(), event.size());
308 for (
UInt_t ivar=0; ivar<
event.size(); ivar++) fATreeEvent[ivar] = event[ivar];
311 else fTestAssignTree[clIndex]->Fill();
320 return fTrainAssignTree[clIndex]!=0;
330 if(!UserAssignEvents(i))
continue;
331 const TString& className = DefaultDataSetInfo().GetClassInfo(i)->GetName();
332 SetWeightExpression(
"weight", className );
350 Log() << kFATAL <<
"<AddTree> cannot interpret tree type: \"" << treetype
351 <<
"\" should be \"Training\" or \"Test\" or \"Training and Testing\"" <<
Endl;
353 AddTree( tree, className, weight, cut,
tt );
362 Log() << kFATAL <<
"Tree does not exist (empty pointer)." <<
Endl;
364 DefaultDataSetInfo().AddClass( className );
370 Log() << kINFO<<
"Add Tree " << tree->GetName() <<
" of type " << className
371 <<
" with " << tree->GetEntries() <<
" events" <<
Endl;
372 DataInput().AddTree( tree, className, weight, cut,
tt );
380 AddTree( signal,
"Signal", weight,
TCut(
""), treetype );
389 TTree* signalTree =
new TTree(
"TreeS",
"Tree (S)" );
392 Log() << kINFO <<
"Create TTree objects from ASCII input files ... \n- Signal file : \""
396 AddTree( signalTree,
"Signal", weight,
TCut(
""), treetype );
403 AddTree( signal,
"Signal", weight,
TCut(
""), treetype );
411 AddTree( signal,
"Background", weight,
TCut(
""), treetype );
420 TTree* bkgTree =
new TTree(
"TreeB",
"Tree (B)" );
423 Log() << kINFO <<
"Create TTree objects from ASCII input files ... \n- Background file : \""
427 AddTree( bkgTree,
"Background", weight,
TCut(
""), treetype );
434 AddTree( signal,
"Background", weight,
TCut(
""), treetype );
441 AddTree( tree,
"Signal", weight );
448 AddTree( tree,
"Background", weight );
474 DataInput().AddTree( datFileS,
"Signal", signalWeight );
475 DataInput().AddTree( datFileB,
"Background", backgroundWeight );
495 DefaultDataSetInfo().AddVariable( expression, title, unit, min, max,
type );
504 DefaultDataSetInfo().AddVariable( expression,
"",
"", min, max,
type );
514 DefaultDataSetInfo().AddVariablesArray(expression,
size,
"",
"", min, max,
type);
525 DefaultDataSetInfo().AddTarget( expression, title, unit, min, max );
534 DefaultDataSetInfo().AddSpectator( expression, title, unit, min, max );
542 return AddDataSet( fName );
550 for (std::vector<TString>::iterator it=theVariables->begin();
551 it!=theVariables->end(); ++it) AddVariable(*it);
558 DefaultDataSetInfo().SetWeightExpression(variable,
"Signal");
565 DefaultDataSetInfo().SetWeightExpression(variable,
"Background");
574 SetSignalWeightExpression(variable);
575 SetBackgroundWeightExpression(variable);
577 else DefaultDataSetInfo().SetWeightExpression( variable, className );
583 SetCut(
TCut(cut), className );
590 DefaultDataSetInfo().SetCut( cut, className );
597 AddCut(
TCut(cut), className );
603 DefaultDataSetInfo().AddCut( cut, className );
613 SetInputTreesFromEventAssignTrees();
617 DefaultDataSetInfo().SetSplitOptions(
TString::Format(
"nTrain_Signal=%i:nTrain_Background=%i:nTest_Signal=%i:nTest_Background=%i:%s",
618 NsigTrain, NbkgTrain, NsigTest, NbkgTest, otherOpt.
Data()).
Data() );
627 SetInputTreesFromEventAssignTrees();
631 DefaultDataSetInfo().SetSplitOptions(
TString::Format(
"nTrain_Signal=%i:nTrain_Background=%i:nTest_Signal=%i:nTest_Background=%i:SplitMode=Random:EqualTrainSample:!V",
632 Ntrain, Ntrain, Ntest, Ntest).Data() );
641 SetInputTreesFromEventAssignTrees();
643 DefaultDataSetInfo().PrintClasses();
645 DefaultDataSetInfo().SetSplitOptions( opt );
654 SetInputTreesFromEventAssignTrees();
657 AddCut( sigcut,
"Signal" );
658 AddCut( bkgcut,
"Background" );
660 DefaultDataSetInfo().SetSplitOptions( splitOpt );
710 for( std::vector<TreeInfo>::const_iterator treeinfo=
src->DataInput().Sbegin();treeinfo!=
src->DataInput().Send();++treeinfo)
712 des->
AddSignalTree( (*treeinfo).GetTree(), (*treeinfo).GetWeight(),(*treeinfo).GetTreeType());
715 for( std::vector<TreeInfo>::const_iterator treeinfo=
src->DataInput().Bbegin();treeinfo!=
src->DataInput().Bend();++treeinfo)
717 des->
AddBackgroundTree( (*treeinfo).GetTree(), (*treeinfo).GetWeight(),(*treeinfo).GetTreeType());
726 const TMatrixD *
m = DefaultDataSetInfo().CorrelationMatrix(className);
727 return DefaultDataSetInfo().CreateCorrelationMatrixHist(
m,
728 "CorrelationMatrix"+className,
"Correlation Matrix ("+className+
")");
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
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
A specialized string object used for TTree selections.
Service class for 2-D histogram classes.
Class that contains all the information of a class.
MsgLogger * fLogger
! message logger
virtual void RecombineKFoldDataSet(DataSetInfo &dsi, Types::ETreeType tt=Types::kTraining)
virtual void MakeKFoldDataSet(DataSetInfo &dsi)=0
virtual void PrepareFoldDataSet(DataSetInfo &dsi, UInt_t foldNumber, Types::ETreeType tt)
Set training and test set vectors of dataset described by dsi.
DataInputHandler * fDataInputHandler
->
TTree * CreateEventAssignTrees(const TString &name)
create the data assignment tree (for event-wise data assignment by user)
void AddVariablesArray(const TString &expression, int size, char type='F', Double_t min=0, Double_t max=0)
user inserts discriminating array of variables in data set info in case input tree provides an array ...
void SetBackgroundTree(TTree *background, Double_t weight=1.0)
void AddSignalTree(TTree *signal, Double_t weight=1.0, Types::ETreeType treetype=Types::kMaxTreeType)
number of signal events (used to compute significance)
DataSetInfo & AddDataSet(DataSetInfo &)
void AddSpectator(const TString &expression, const TString &title="", const TString &unit="", Double_t min=0, Double_t max=0)
user inserts target in data set info
void SetInputTreesFromEventAssignTrees()
assign event-wise local trees to data set
void AddTrainingEvent(const TString &className, const std::vector< Double_t > &event, Double_t weight)
add signal training event
void SetTree(TTree *tree, const TString &className, Double_t weight)
deprecated
void AddSignalTestEvent(const std::vector< Double_t > &event, Double_t weight=1.0)
add signal testing event
DataSetInfo & DefaultDataSetInfo()
default creation
void AddBackgroundTestEvent(const std::vector< Double_t > &event, Double_t weight=1.0)
add signal training event
DataSetManager * fDataSetManager
DataLoader * MakeCopy(TString name)
Copy method use in VI and CV.
void SetSignalWeightExpression(const TString &variable)
void MakeKFoldDataSet(CvSplit &s)
Function required to split the training and testing datasets into a number of folds.
void SetWeightExpression(const TString &variable, const TString &className="")
void AddBackgroundTrainingEvent(const std::vector< Double_t > &event, Double_t weight=1.0)
add signal training event
void RecombineKFoldDataSet(CvSplit &s, Types::ETreeType tt=Types::kTraining)
Recombines the dataset.
DataLoader * VarTransform(TString trafoDefinition)
Transforms the variables and return a new DataLoader with the transformed variables.
void SetBackgroundWeightExpression(const TString &variable)
void AddCut(const TString &cut, const TString &className="")
void AddEvent(const TString &className, Types::ETreeType tt, const std::vector< Double_t > &event, Double_t weight)
add event vector event : the order of values is: variables + targets + spectators
DataLoader(TString thedlName="default")
void PrepareTrainingAndTestTree(const TCut &cut, const TString &splitOpt)
prepare the training and test trees -> same cuts for signal and background
void AddBackgroundTree(TTree *background, Double_t weight=1.0, Types::ETreeType treetype=Types::kMaxTreeType)
number of signal events (used to compute significance)
DataSetInfo & GetDataSetInfo()
void AddTarget(const TString &expression, const TString &title="", const TString &unit="", Double_t min=0, Double_t max=0)
user inserts target in data set info
TH2 * GetCorrelationMatrix(const TString &className)
returns the correlation matrix of datasets
Bool_t UserAssignEvents(UInt_t clIndex)
void AddSignalTrainingEvent(const std::vector< Double_t > &event, Double_t weight=1.0)
add signal training event
void AddTestEvent(const TString &className, const std::vector< Double_t > &event, Double_t weight)
add signal test event
void SetSignalTree(TTree *signal, Double_t weight=1.0)
void SetInputTrees(const TString &signalFileName, const TString &backgroundFileName, Double_t signalWeight=1.0, Double_t backgroundWeight=1.0)
void AddTree(TTree *tree, const TString &className, Double_t weight=1.0, const TCut &cut="", Types::ETreeType tt=Types::kMaxTreeType)
void SetInputVariables(std::vector< TString > *theVariables)
deprecated
void SetCut(const TString &cut, const TString &className="")
void AddVariable(const TString &expression, const TString &title, const TString &unit, char type='F', Double_t min=0, Double_t max=0)
user inserts discriminating variable in data set info
void PrepareFoldDataSet(CvSplit &s, UInt_t foldNumber, Types::ETreeType tt=Types::kTraining)
Function for assigning the correct folds to the testing or training set.
Class that contains all the data information.
Class that contains all the data information.
void SetSource(const std::string &source)
@ kMaxTreeType
also used as temporary storage for trees not yet assigned for testing;training...
virtual void SetName(const char *name)
Set the name of the TNamed.
void ToLower()
Change string to lower-case.
Double_t Atof() const
Return floating-point value contained in string.
Bool_t IsFloat() const
Returns kTRUE if string contains a floating point or integer number.
const char * Data() const
TString & Remove(Ssiz_t pos)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
A TTree represents a columnar dataset.
virtual void SetDirectory(TDirectory *dir)
Change the tree's directory.
TBranch * Branch(const char *name, T *obj, Int_t bufsize=32000, Int_t splitlevel=99)
Add a new branch, and infer the data type from the type of obj being passed.
virtual Long64_t ReadFile(const char *filename, const char *branchDescriptor="", char delimiter=' ')
Create or simply read branches from filename.
void DataLoaderCopy(TMVA::DataLoader *des, TMVA::DataLoader *src)
MsgLogger & Endl(MsgLogger &ml)