#include "TMVA/Event.h"
#include "TMVA/Tools.h"
#include "TTree.h"
#include "TBranch.h"
#include <iostream>
#include <iomanip>
Int_t TMVA::Event::fgCount = 0;
TMVA::Event::Event(const std::vector<TMVA:: VariableInfo>& varinfo, Bool_t AllowExternalLinks)
: fVariables(varinfo),
fVarPtr(new void*[varinfo.size()]),
fVarPtrF(0),
fType(0),
fWeight(0),
fBoostWeight(1.0),
fCountI(0),
fCountF(0)
{
fgCount++;
fCountF = fVariables.size();
InitPointers(AllowExternalLinks);
}
TMVA::Event::Event( const Event& event )
: fVariables(event.fVariables),
fVarPtr(new void*[event.fVariables.size()]),
fVarPtrF(0),
fType(event.fType),
fWeight(event.fWeight),
fBoostWeight(event.fBoostWeight),
fCountI(event.fCountI),
fCountF(event.fCountF)
{
fgCount++;
InitPointers(kFALSE);
for (UInt_t ivar=0; ivar<GetNVars(); ivar++) {
*(Float_t*)fVarPtr[ivar] = *(Float_t*)event.fVarPtr[ivar];
}
}
TMVA::Event::~Event()
{
delete[] fVarPtr;
delete[] fVarPtrF;
fgCount--;
}
void TMVA::Event::InitPointers(bool AllowExternalLink)
{
fVarPtrF = new Float_t[fCountF];
UInt_t ivar(0), ivarF(0);
std::vector<VariableInfo>::const_iterator varIt = fVariables.begin();
for (; varIt != fVariables.end(); varIt++, ivar++) {
const VariableInfo& var = *varIt;
if (AllowExternalLink && var.GetExternalLink()!=0) {
fVarPtr[ivar] = var.GetExternalLink();
}
else {
fVarPtr[ivar] = fVarPtrF+ivarF++;
}
}
}
void TMVA::Event::SetBranchAddresses(TTree *tr)
{
fBranches.clear();
Int_t ivar(0);
TBranch * br(0);
std::vector<VariableInfo>::const_iterator varIt;
for (varIt = fVariables.begin(); varIt != fVariables.end(); varIt++) {
const VariableInfo& var = *varIt;
br = tr->GetBranch(var.GetInternalVarName());
br->SetAddress(fVarPtr[ivar++]);
fBranches.push_back(br);
}
br = tr->GetBranch("type"); br->SetAddress(&fType); fBranches.push_back(br);
br = tr->GetBranch("weight"); br->SetAddress(&fWeight); fBranches.push_back(br);
br = tr->GetBranch("boostweight"); br->SetAddress(&fBoostWeight); fBranches.push_back(br);
}
void TMVA::Event::CopyVarValues( const Event& other )
{
for (UInt_t ivar=0; ivar<GetNVars(); ivar++)
SetVal(ivar, other.GetVal(ivar));
SetType(other.Type());
SetWeight(other.GetWeight());
SetBoostWeight(other.GetBoostWeight());
}
void TMVA::Event::SetVal(UInt_t ivar, Float_t val)
{
Bool_t isInternallyLinked = (fVarPtr[ivar] >= fVarPtrF && fVarPtr[ivar] < fVarPtrF+fCountF);
if(isInternallyLinked) {
fVarPtrF[ivar] = val;
} else {
if(fVariables[ivar].GetVarType()=='F') {
*(Float_t*)fVarPtr[ivar] = val;
} else {
*(Int_t*)fVarPtr[ivar] = (Int_t)val;
}
}
}
Float_t TMVA::Event::GetVal(UInt_t ivar) const
{
Bool_t isInternallyLinked = (fVarPtr[ivar] >= fVarPtrF && fVarPtr[ivar] < fVarPtrF+fCountF);
if(isInternallyLinked) {
return fVarPtrF[ivar];
} else {
if(fVariables[ivar].GetVarType()=='F') {
return *(Float_t*)fVarPtr[ivar];
} else {
return *(Int_t*)fVarPtr[ivar];
}
}
}
Float_t TMVA::Event::GetValueNormalized(UInt_t ivar) const
{
return gTools().NormVariable(GetVal(ivar),fVariables[ivar].GetMin(),fVariables[ivar].GetMax());
}
void TMVA::Event::Print(std::ostream& o) const
{
o << fVariables.size() << " variables: ";
for (UInt_t ivar=0; ivar<fVariables.size(); ivar++)
o << " " << std::setw(10) << GetVal(ivar) << '(' << fVariables[ivar].GetVarType() << ')';
o << " weight = " << GetWeight();
o << std::setw(10) << (IsSignal()?" signal":" background");
o << std::endl;
}
ostream& TMVA::operator<<(ostream& os, const TMVA::Event& event)
{
event.Print(os);
return os;
}
ostream& TMVA::operator<<(ostream& os, const TMVA::Event* event)
{
return os << *event;
}
Last change: Thu Dec 18 10:00:42 2008
Last generated: 2008-12-18 10:00
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.