53 TMVA::DataInputHandler::DataInputHandler()
54 : fLogger( new MsgLogger(
"DataInputHandler", kINFO) )
56 fExplicitTrainTest[
"Signal"] = fExplicitTrainTest[
"Background"] = kFALSE;
62 TMVA::DataInputHandler::~DataInputHandler()
70 void TMVA::DataInputHandler::AddTree(
const TString& fn,
71 const TString& className,
76 TTree * tr = ReadInputTree(fn);
77 tr->SetName( TString(
"Tree")+className );
78 AddTree( tr, className, weight, cut, tt );
84 void TMVA::DataInputHandler::AddTree( TTree* tree,
85 const TString& className,
90 if (!tree) Log() << kFATAL <<
"Zero pointer for tree of class " << className.Data() << Endl;
91 if (tree->GetEntries()==0) Log() << kFATAL <<
"Encountered empty TTree or TChain of class " << className.Data() << Endl;
92 if (fInputTrees[className.Data()].empty()) {
94 fExplicitTrainTest[className.Data()] = (tt != Types::kMaxTreeType);
98 if (fExplicitTrainTest[className.Data()] != (tt!=Types::kMaxTreeType)) {
99 if (tt==Types::kMaxTreeType)
100 Log() << kFATAL <<
"For the tree " << tree->GetName() <<
" of class " << className.Data()
101 <<
" you did "<< (tt==Types::kMaxTreeType?
"not ":
"") <<
"specify a type,"
102 <<
" while you did "<< (tt==Types::kMaxTreeType?
"":
"not ") <<
"for the first tree "
103 << fInputTrees[className.Data()][0].GetTree()->GetName() <<
" of class " << className.Data()
107 if (cut.GetTitle()[0] != 0) {
108 fInputTrees[className.Data()].push_back(TreeInfo( tree->CopyTree(cut.GetTitle()), className, weight, tt ));
111 fInputTrees[className.Data()].push_back(TreeInfo( tree, className, weight, tt ));
118 void TMVA::DataInputHandler::AddSignalTree( TTree* tr, Double_t weight, Types::ETreeType tt )
120 AddTree( tr,
"Signal", weight,
"", tt );
126 void TMVA::DataInputHandler::AddBackgroundTree( TTree* tr, Double_t weight, Types::ETreeType tt )
128 AddTree( tr,
"Background", weight,
"", tt );
134 void TMVA::DataInputHandler::AddSignalTree(
const TString& fn, Double_t weight, Types::ETreeType tt )
136 TTree * tr = ReadInputTree(fn);
137 tr->SetName(
"TreeS");
138 AddTree( tr,
"Signal", weight,
"", tt );
144 void TMVA::DataInputHandler::AddBackgroundTree(
const TString& fn, Double_t weight, Types::ETreeType tt )
146 TTree * tr = ReadInputTree(fn);
147 tr->SetName(
"TreeB");
148 AddTree( tr,
"Background", weight,
"", tt );
154 TTree* TMVA::DataInputHandler::ReadInputTree(
const TString& dataFile )
156 TTree* tr =
new TTree(
"tmp", dataFile );
157 std::ifstream in(dataFile);
158 tr->SetDirectory(0); Log() << kWARNING <<
"Watch out, I (Helge) made the Tree not associated to the current directory .. Hopefully that does not have unwanted consequences" << Endl;
159 if (!in.good()) Log() << kFATAL <<
"Could not open file: " << dataFile << Endl;
162 tr->ReadFile( dataFile );
172 void TMVA::DataInputHandler::AddInputTrees(TTree* inputTree,
const TCut& SigCut,
const TCut& BgCut)
174 if (!inputTree) Log() << kFATAL <<
"Zero pointer for input tree: " << inputTree << Endl;
176 AddTree( inputTree,
"Signal", 1.0, SigCut );
177 AddTree( inputTree,
"Background", 1.0, BgCut );
183 void TMVA::DataInputHandler::ClearTreeList(
const TString& className )
186 fInputTrees.find(className)->second.clear();
189 Log() << kINFO <<
" Clear treelist for class " << className <<
" failed, since class does not exist." << Endl;
195 std::vector< TString >* TMVA::DataInputHandler::GetClassList()
const
197 std::vector< TString >* ret =
new std::vector< TString >();
198 for ( std::map< TString, std::vector<TreeInfo> >::iterator it = fInputTrees.begin(); it != fInputTrees.end(); ++it ){
199 ret->push_back( it->first );
207 UInt_t TMVA::DataInputHandler::GetEntries(
const std::vector<TreeInfo>& tiV)
const
210 std::vector<TreeInfo>::const_iterator tiIt = tiV.begin();
211 for (;tiIt != tiV.end();++tiIt) entries += tiIt->GetEntries();
218 UInt_t TMVA::DataInputHandler::GetEntries()
const
221 for (std::map< TString, std::vector<TreeInfo> >::iterator it = fInputTrees.begin(); it != fInputTrees.end(); ++it) {
222 number += GetEntries( it->second );