89 fDataSetManager ( NULL ),
91 fTransformations (
"I" ),
93 fDataAssignType ( kAssignEvents ),
107 std::vector<TMVA::VariableTransformBase*>::iterator trfIt = fDefaultTrfs.begin();
108 for (;trfIt != fDefaultTrfs.end(); ++trfIt)
delete (*trfIt);
110 delete fDataInputHandler;
114 delete fDataSetManager;
128 return fDataSetManager->AddDataSetInfo(dsi);
135 DataSetInfo* dsi = fDataSetManager->GetDataSetInfo(dsiName);
137 if (dsi!=0)
return *dsi;
139 return fDataSetManager->AddDataSetInfo(*(
new DataSetInfo(dsiName)));
146 return DefaultDataSetInfo();
157 if (trafoDefinition.
Contains(
"(")) {
161 Ssiz_t parLen = trafoDefinition.
Index(
")", parStart )-parStart+1;
163 trName = trafoDefinition(0,parStart);
164 trOptions = trafoDefinition(parStart,parLen);
165 trOptions.
Remove(parLen-1,1);
169 trName = trafoDefinition;
173 if (trName ==
"VT") {
178 Log() << kFATAL <<
" VT transformation must be passed a floating threshold value" <<
Endl;
183 threshold = trOptions.
Atof();
186 return transformedLoader;
189 Log() << kFATAL <<
"Incorrect transformation string provided, please check" <<
Endl;
191 Log() << kINFO <<
"No transformation applied, returning original loader" <<
Endl;
205 assignTree->
Branch(
"type", &fATreeType,
"ATreeType/I" );
206 assignTree->
Branch(
"weight", &fATreeWeight,
"ATreeWeight/F" );
208 std::vector<VariableInfo>& vars = DefaultDataSetInfo().GetVariableInfos();
209 std::vector<VariableInfo>& tgts = DefaultDataSetInfo().GetTargetInfos();
210 std::vector<VariableInfo>& spec = DefaultDataSetInfo().GetSpectatorInfos();
212 if (fATreeEvent.size()==0) fATreeEvent.resize(vars.size()+tgts.size()+spec.size());
214 for (
UInt_t ivar=0; ivar<vars.size(); ivar++) {
215 TString vname = vars[ivar].GetExpression();
216 assignTree->
Branch( vname, &fATreeEvent[ivar], vname +
"/F" );
219 for (
UInt_t itgt=0; itgt<tgts.size(); itgt++) {
220 TString vname = tgts[itgt].GetExpression();
221 assignTree->
Branch( vname, &fATreeEvent[vars.size()+itgt], vname +
"/F" );
224 for (
UInt_t ispc=0; ispc<spec.size(); ispc++) {
225 TString vname = spec[ispc].GetExpression();
226 assignTree->
Branch( vname, &fATreeEvent[vars.size()+tgts.size()+ispc], vname +
"/F" );
284 const std::vector<Double_t>& event,
Double_t weight )
286 ClassInfo* theClass = DefaultDataSetInfo().AddClass(className);
295 if (clIndex>=fTrainAssignTree.size()) {
296 fTrainAssignTree.resize(clIndex+1, 0);
297 fTestAssignTree.resize(clIndex+1, 0);
300 if (fTrainAssignTree[clIndex]==0) {
301 fTrainAssignTree[clIndex] = CreateEventAssignTrees(
Form(
"TrainAssignTree_%s", className.
Data()) );
302 fTestAssignTree[clIndex] = CreateEventAssignTrees(
Form(
"TestAssignTree_%s", className.
Data()) );
305 fATreeType = clIndex;
306 fATreeWeight = weight;
307 for (
UInt_t ivar=0; ivar<
event.size(); ivar++) fATreeEvent[ivar] = event[ivar];
310 else fTestAssignTree[clIndex]->Fill();
319 return fTrainAssignTree[clIndex]!=0;
327 UInt_t size = fTrainAssignTree.size();
328 for(
UInt_t i=0; i<size; i++) {
329 if(!UserAssignEvents(i))
continue;
330 const TString& className = DefaultDataSetInfo().GetClassInfo(i)->GetName();
331 SetWeightExpression(
"weight", className );
349 Log() << kFATAL <<
"<AddTree> cannot interpret tree type: \"" << treetype
350 <<
"\" should be \"Training\" or \"Test\" or \"Training and Testing\"" <<
Endl;
352 AddTree(
tree, className, weight, cut,
tt );
361 Log() << kFATAL <<
"Tree does not exist (empty pointer)." <<
Endl;
363 DefaultDataSetInfo().AddClass( className );
369 Log() << kINFO<<
"Add Tree " <<
tree->GetName() <<
" of type " << className
370 <<
" with " <<
tree->GetEntries() <<
" events" <<
Endl;
371 DataInput().AddTree(
tree, className, weight, cut,
tt );
379 AddTree(
signal,
"Signal", weight,
TCut(
""), treetype );
388 TTree* signalTree =
new TTree(
"TreeS",
"Tree (S)" );
391 Log() << kINFO <<
"Create TTree objects from ASCII input files ... \n- Signal file : \""
395 AddTree( signalTree,
"Signal", weight,
TCut(
""), treetype );
402 AddTree(
signal,
"Signal", weight,
TCut(
""), treetype );
410 AddTree(
signal,
"Background", weight,
TCut(
""), treetype );
419 TTree* bkgTree =
new TTree(
"TreeB",
"Tree (B)" );
422 Log() << kINFO <<
"Create TTree objects from ASCII input files ... \n- Background file : \""
426 AddTree( bkgTree,
"Background", weight,
TCut(
""), treetype );
433 AddTree(
signal,
"Background", weight,
TCut(
""), treetype );
440 AddTree(
tree,
"Signal", weight );
447 AddTree(
tree,
"Background", weight );
473 DataInput().AddTree( datFileS,
"Signal", signalWeight );
474 DataInput().AddTree( datFileB,
"Background", backgroundWeight );
494 DefaultDataSetInfo().AddVariable( expression, title, unit, min, max,
type );
503 DefaultDataSetInfo().AddVariable( expression,
"",
"", min, max,
type );
515 DefaultDataSetInfo().AddTarget( expression, title, unit, min, max );
524 DefaultDataSetInfo().AddSpectator( expression, title, unit, min, max );
532 return AddDataSet( fName );
540 for (std::vector<TString>::iterator it=theVariables->begin();
541 it!=theVariables->end(); ++it) AddVariable(*it);
548 DefaultDataSetInfo().SetWeightExpression(variable,
"Signal");
555 DefaultDataSetInfo().SetWeightExpression(variable,
"Background");
564 SetSignalWeightExpression(variable);
565 SetBackgroundWeightExpression(variable);
567 else DefaultDataSetInfo().SetWeightExpression( variable, className );
573 SetCut(
TCut(cut), className );
580 DefaultDataSetInfo().SetCut( cut, className );
587 AddCut(
TCut(cut), className );
593 DefaultDataSetInfo().AddCut( cut, className );
603 SetInputTreesFromEventAssignTrees();
607 DefaultDataSetInfo().SetSplitOptions(
Form(
"nTrain_Signal=%i:nTrain_Background=%i:nTest_Signal=%i:nTest_Background=%i:%s",
608 NsigTrain, NbkgTrain, NsigTest, NbkgTest, otherOpt.
Data()) );
617 SetInputTreesFromEventAssignTrees();
621 DefaultDataSetInfo().SetSplitOptions(
Form(
"nTrain_Signal=%i:nTrain_Background=%i:nTest_Signal=%i:nTest_Background=%i:SplitMode=Random:EqualTrainSample:!V",
622 Ntrain, Ntrain, Ntest, Ntest) );
631 SetInputTreesFromEventAssignTrees();
633 DefaultDataSetInfo().PrintClasses();
635 DefaultDataSetInfo().SetSplitOptions( opt );
644 SetInputTreesFromEventAssignTrees();
647 AddCut( sigcut,
"Signal" );
648 AddCut( bkgcut,
"Background" );
650 DefaultDataSetInfo().SetSplitOptions( splitOpt );
661 s.MakeKFoldDataSet( DefaultDataSetInfo() );
669 s.PrepareFoldDataSet( DefaultDataSetInfo(), foldNumber,
tt );
682 s.RecombineKFoldDataSet( DefaultDataSetInfo(),
tt );
702 des->
AddSignalTree( (*treeinfo).GetTree(), (*treeinfo).GetWeight(),(*treeinfo).GetTreeType());
707 des->
AddBackgroundTree( (*treeinfo).GetTree(), (*treeinfo).GetWeight(),(*treeinfo).GetTreeType());
716 const TMatrixD *
m = DefaultDataSetInfo().CorrelationMatrix(className);
717 return DefaultDataSetInfo().CreateCorrelationMatrixHist(
m,
718 "CorrelationMatrix"+className,
"Correlation Matrix ("+className+
")");
char * Form(const char *fmt,...)
A specialized string object used for TTree selections.
Service class for 2-Dim histogram classes.
Class that contains all the information of a class.
DataInputHandler * fDataInputHandler
TTree * CreateEventAssignTrees(const TString &name)
create the data assignment tree (for event-wise data assignment by user)
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)
set background tree
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
DataInputHandler & DataInput()
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)
fill input variables in data set
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)
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)
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 object has a header with a name and a title.
virtual void SetDirectory(TDirectory *dir)
Change the tree's directory.
virtual Long64_t ReadFile(const char *filename, const char *branchDescriptor="", char delimiter=' ')
Create or simply read branches from filename.
virtual Int_t Branch(TCollection *list, Int_t bufsize=32000, Int_t splitlevel=99, const char *name="")
Create one branch for each element in the collection.
static constexpr double s
void DataLoaderCopy(TMVA::DataLoader *des, TMVA::DataLoader *src)
MsgLogger & Endl(MsgLogger &ml)