64 fHasNegativeEventWeights(
kFALSE),
81 for (
Int_t treeIdx = 0; treeIdx < treeNum; treeIdx++) {
113 for (
Int_t treeIdx = 0; treeIdx < treeNum; treeIdx++) {
132 for (std::vector< std::map< TString, Results* > >::iterator it =
fResults.begin(); it !=
fResults.end(); ++it) {
133 for (std::map< TString, Results* >::iterator itMap = (*it).begin(); itMap != (*it).end(); ++itMap) {
134 delete itMap->second;
173 catch (std::out_of_range) {
175 Log() << kFATAL <<
Form(
"Dataset[%s] : ",
fdsi->
GetName()) <<
"No " << (type==0?
"training":(type==1?
"testing":
"_unknown_type_"))
176 <<
" events for class " << (ci==NULL?
"_no_name_known_":ci->
GetName()) <<
" (index # "<<classNumber<<
")" 177 <<
" available. Check if all class names are spelled correctly and if events are" 178 <<
" passing the selection cuts." <<
Endl;
181 Log() << kFATAL <<
Form(
"Dataset[%s] : ",
fdsi->
GetName()) <<
"ERROR/CAUGHT : DataSet/GetNClassEvents, .. unknown error" <<
Endl;
271 const std::map< TString, Results* >& resultsForType =
fResults[t];
272 std::map< TString, Results* >::const_iterator it = resultsForType.find(resultsName);
273 if (it!=resultsForType.end()) {
285 switch(analysistype) {
305 fResults[t][resultsName] = newresults;
323 Log()<<kFATAL<<
Form(
"Dataset[%s] : ",
fdsi->
GetName()) <<
"you asked for an Treetype (training/testing/...)" 324 <<
" whose index " << type <<
" does not exist " <<
Endl;
326 std::map< TString, Results* >& resultsForType =
fResults[
UInt_t(type)];
327 std::map< TString, Results* >::iterator it = resultsForType.find(resultsName);
328 if (it!=resultsForType.end()) {
329 Log() << kDEBUG <<
Form(
"Dataset[%s] : ",
fdsi->
GetName()) <<
" Delete Results previous existing result:" << resultsName
330 <<
" of type " << type <<
Endl;
332 resultsForType.erase(it->first);
335 Log() << kINFO <<
Form(
"Dataset[%s] : ",
fdsi->
GetName()) <<
"could not fine Result class of " << resultsName
336 <<
" of type " << type <<
" which I should have deleted" <<
Endl;
349 Log()<<kFATAL<<
Form(
"Dataset[%s] : ",
fdsi->
GetName()) <<
"you asked for an Treetype (training/testing/...)" 350 <<
" whose index " << type <<
" does not exist " <<
Endl;
353 std::map<TString, Results *> & resultsForType =
fResults[
UInt_t(type)];
355 for (
auto && it : resultsForType) {
356 auto & resultsName = it.first;
359 <<
" DeleteAllResults previous existing result: " 360 << resultsName <<
" of type " << type <<
Endl;
365 resultsForType.clear();
465 std::vector< std::pair< Float_t, Long64_t >* > evtList;
479 if (fraction > 0.999999 || fraction < 0.0000001) {
495 for (
Long64_t ievt=0; ievt<nEvts; ievt++) {
496 std::pair<Float_t,Long64_t> p(1.0,ievt);
516 <<
"no random generator present for creating a random/importance sampling (initialized?)" <<
Endl;
522 std::vector< std::pair< Float_t, Long64_t > > evtList;
523 std::vector< std::pair< Float_t, Long64_t > >::iterator evtListIt;
532 for (evtListIt = evtList.begin(); evtListIt != evtList.end(); ++evtListIt) {
533 sumWeights += (*evtListIt).first;
535 evtListIt = evtList.begin();
538 std::vector< Float_t > rnds;
544 rnds.push_back( pos );
548 std::sort(rnds.begin(),rnds.end());
551 std::vector< Float_t >::iterator rndsIt = rnds.begin();
552 Float_t runningSum = 0.000000001;
553 for (evtListIt = evtList.begin(); evtListIt != evtList.end();) {
554 runningSum += (*evtListIt).first;
555 if (runningSum >= (*rndsIt)) {
557 evtListIt = evtList.erase( evtListIt );
560 if (rndsIt == rnds.end() )
break;
580 if (evtNumber >= 0) {
584 for (
Long64_t iEvt = start; iEvt <= stop; iEvt++ ){
586 Log() << kWARNING <<
Form(
"Dataset[%s] : ",
fdsi->
GetName()) <<
"event number (" << iEvt
587 <<
") larger than number of sampled events (" 595 if (weight > 1.0 ) weight = 1.0;
647 tree->
Branch(
"classID", &cls,
"classID/I" );
648 tree->
Branch(
"className", className,
"className/C" );
656 tree->
Branch( (*itVars).GetInternalName(), &varVals[
n], (*itVars).GetInternalName()+
TString(
"/F") );
661 for (std::vector<VariableInfo>::const_iterator itTgts =
fdsi->
GetTargetInfos().begin();
664 tree->
Branch( (*itTgts).GetInternalName(), &tgtVals[
n], (*itTgts).GetInternalName()+
TString(
"/F") );
672 tree->
Branch( (*itVis).GetInternalName(), &visVals[
n], (*itVis).GetInternalName()+
TString(
"/F") );
676 tree->
Branch(
"weight", &weight,
"weight/F" );
680 for (std::map< TString, Results* >::iterator itMethod =
fResults.at(t).begin();
681 itMethod !=
fResults.at(t).end(); ++itMethod) {
689 tree->
Branch( itMethod->first, &(metVals[n][0]), itMethod->first +
"/F" );
695 if (iCls > 0) leafList.
Append(
":" );
699 Log() << kDEBUG <<
Form(
"Dataset[%s] : ",
fdsi->
GetName()) <<
"itMethod->first " << itMethod->first <<
" LEAFLIST: " 700 << leafList <<
" itMethod->second " << itMethod->second << Endl;
701 tree->
Branch( itMethod->first, (metVals[n]), leafList );
707 if (iTgt > 0) leafList.
Append(
":" );
712 Log() << kDEBUG <<
Form(
"Dataset[%s] : ",
fdsi->
GetName()) <<
"itMethod->first " << itMethod->first <<
" LEAFLIST: " 713 << leafList <<
" itMethod->second " << itMethod->second << Endl;
714 tree->
Branch( itMethod->first, (metVals[n]), leafList );
717 Log() << kWARNING <<
Form(
"Dataset[%s] : ",
fdsi->
GetName()) <<
"Unknown analysis type for result found when writing TestTree." << Endl;
724 for (
auto && itMethod :
fResults.at(t)) {
726 auto results = itMethod.second;
727 auto resultsName = itMethod.first;
730 auto analysisType = results->GetAnalysisType();
738 Log() << kFATAL <<
"Unexpected analysisType." <<
Endl;
741 if (numEventsResults != numEvents) {
742 Log() << kFATAL <<
"An error occurred in DataSet::GetTree. " 743 "Inconsistent size of result for result with name '" 744 << resultsName <<
"'." 745 <<
" Size is '" << std::to_string(numEventsResults)
747 <<
" Expected '" << numEvents <<
"'." <<
Endl;
768 for (
auto && itMethod :
fResults.at(t)) {
769 auto & results = *itMethod.second;
770 auto analysisType = results.GetAnalysisType();
772 auto const & vals = results[iEvt];
775 metVals[iMethod][0] = vals[0];
779 metVals[iMethod][nCls] = val;
784 metVals[iMethod][nTgts] = val;
794 <<
"Created tree '" << tree->
GetName() <<
"' with " << tree->
GetEntries() <<
" events" << Endl <<
Endl;
virtual const char * GetName() const
Returns name of object.
std::string GetName(const std::string &scope_name)
UInt_t GetNVariables() const
Random number generator class based on M.
MsgLogger & Endl(MsgLogger &ml)
Class that is the base-class for a vector of result.
Long64_t fTrainingBlockSize
std::vector< std::vector< std::pair< Float_t, Long64_t > > > fSamplingSelected
const TString & GetInternalName() const
void AddEvent(Event *, Types::ETreeType)
add event to event list after which the event is owned by the dataset
std::vector< VariableInfo > & GetSpectatorInfos()
virtual Double_t Rndm()
Machine independent random number generator.
std::vector< std::vector< std::pair< Float_t, Long64_t > > > fSamplingEventList
std::vector< std::vector< Event * > > fEventCollection
void CreateSampling() const
create an event sampling (random or importance sampling)
virtual Int_t Fill()
Fill all branches.
TRandom3 * fSamplingRandom
UInt_t GetNVariables() const
access the number of variables through the datasetinfo
void SetTreeType(Types::ETreeType type)
std::vector< Char_t > fBlockBelongToTraining
void ClearNClassEvents(Int_t type)
UInt_t GetNClasses() const
Long64_t GetNEvtBkgdTrain()
return number of background training events in dataset
Class that contains all the information of a class.
UInt_t TreeIndex(Types::ETreeType type) const
UInt_t GetNSpectators() const
access the number of targets through the datasetinfo
The TNamed class is the base class for all named ROOT classes.
virtual ~DataSet()
destructor
TTree * GetTree(Types::ETreeType type)
create the test/trainings tree with all the variables, the weights, the classes, the targets...
Types::ETreeType GetCurrentType() const
TString & Append(const char *cs)
Class that contains all the data information.
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not...
std::vector< VariableInfo > & GetTargetInfos()
Bool_t fHasNegativeEventWeights
UInt_t GetNTargets() const
accessor to the number of targets
void MoveTrainingBlock(Int_t blockInd, Types::ETreeType dest, Bool_t applyChanges=kTRUE)
move training block
void ApplyTrainingSetDivision()
apply division of data set
Float_t GetTarget(UInt_t itgt) const
UInt_t GetNTargets() const
Results * GetResults(const TString &, Types::ETreeType type, Types::EAnalysisType analysistype)
std::vector< std::vector< Long64_t > > fClassEvents
Long64_t GetNEvtSigTest()
return number of signal test events in dataset
ClassInfo * GetClassInfo(Int_t clNum) const
VariableInfo & GetTargetInfo(Int_t i)
void DeleteResults(const TString &, Types::ETreeType type, Types::EAnalysisType analysistype)
delete the results stored for this particular Method instance.
UInt_t GetNSpectators() const
accessor to the number of spectators
char * Form(const char *fmt,...)
void DivideTrainingSet(UInt_t blockNum)
divide training set
void DestroyCollection(Types::ETreeType type, Bool_t deleteEvents)
destroys the event collection (events + vector)
UInt_t GetNSpectators(bool all=kTRUE) const
Long64_t GetNEvtBkgdTest()
return number of background test events in dataset
void DeleteAllResults(Types::ETreeType type, Types::EAnalysisType analysistype)
Deletes all results currently in the dataset.
UInt_t GetNVariables() const
accessor to the number of variables
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
void IncrementNClassEvents(Int_t type, UInt_t classNumber)
std::vector< Char_t > fSampling
void EventResult(Bool_t successful, Long64_t evtNumber=-1)
increase the importance sampling weight of the event when not successful and decrease it when success...
std::vector< Float_t > fSamplingWeight
Long64_t fCurrentEventIdx
UInt_t fCurrentTreeIdx
[train/test/...][method-identifier]
Long64_t GetNEvtSigTrain()
return number of signal training events in dataset
MsgLogger & Log() const
message logger
Class which takes the results of a multiclass classification.
void SetCurrentType(Types::ETreeType type) const
void SetEventCollection(std::vector< Event *> *, Types::ETreeType, Bool_t deleteEvents=true)
Sets the event collection (by DataSetFactory)
std::vector< Int_t > fSamplingNEvents
virtual const char * GetName() const
Returns name of object.
virtual Long64_t GetEntries() const
Long64_t GetNClassEvents(Int_t type, UInt_t classNumber)
ostringstream derivative to redirect and format output
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.
#define dest(otri, vertexptr)
Class that is the base-class for a vector of result.
Long64_t GetNEvents(Types::ETreeType type=Types::kMaxTreeType) const
A TTree object has a header with a name and a title.
UInt_t GetNTargets() const
access the number of targets through the datasetinfo
Float_t GetSpectator(UInt_t ivar) const
return spectator content
void InitSampling(Float_t fraction, Float_t weight, UInt_t seed=0)
initialize random or importance sampling
const Event * GetEvent() const
std::vector< VariableInfo > & GetVariableInfos()
Class that is the base-class for a vector of result.
std::vector< std::map< TString, Results *> > fResults