Plot the variables.
#include <vector>
{
if (!dataFile) {
cout << "ERROR: cannot open file: " << fname << endl;
return;
}
treeS->
Draw(
Form(
"%s:%s>>DataS",var1.Data(),var0.Data()),
"",
"0" );
treeB->
Draw(
Form(
"%s:%s>>DataB",var1.Data(),var0.Data()
), "", "0" );
frameS->
SetTitle( var1+
" versus "+var0+
" for signal and background" );
TLegend *legend =
new TLegend( 1 -
c->GetRightMargin() - 0.32, 1 -
c->GetTopMargin() - 0.12,
1 -
c->GetRightMargin(), 1 -
c->GetTopMargin() );
legend->
AddEntry(frameB,
"Background",
"p");
}
{
for (
Int_t j=0;j< i; j++)
sum += (*sqrtMat)(i,j) * (*sqrtMat)(i,j);
for (
Int_t l=0;
l<i;
l++)
sum += (*sqrtMat)(k,
l) * (*sqrtMat)(i,
l);
(*sqrtMat)(k,i) = (covMat(k,i) -
sum) / (*sqrtMat)(i,i);
}
}
return sqrtMat;
}
{
cout <<
"<getGaussRnd> too short input vector: " <<
size <<
" " <<
v.GetSize() << endl;
}
for (
Int_t j=0; j<=i; j++)
v[i] += sqrtMat(i,j) * tmpVec[j];
}
delete[] tmpVec;
}
void create_lin_Nvar_withFriend(
Int_t N = 2000)
{
for (
Int_t ivar=0; ivar<nvar-nvar2; ivar++) {
cout << "Creating branch var" << ivar+1 << " in signal tree" << endl;
}
TTree* treeSF =
new TTree(
"TreeSF",
"TreeS", 1 );
TTree* treeBF =
new TTree(
"TreeBF",
"TreeB", 1 );
for (
Int_t ivar=nvar-nvar2; ivar<nvar; ivar++) {
}
Float_t xS[nvar] = { 0.2, 0.3, 0.5, 0.9 };
Float_t xB[nvar] = { -0.2, -0.3, -0.5, -0.6 };
Float_t dx[nvar] = { 1.0, 1.0, 1.0, 1.0 };
rho[1*2] = 0.4;
rho[1*3] = 0.6;
rho[1*4] = 0.9;
rho[2*3] = 0.7;
rho[2*4] = 0.8;
rho[3*4] = 0.93;
for (
Int_t ivar=0; ivar<nvar; ivar++) {
(*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
(*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
(*covMatS)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
(*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
(*covMatB)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
(*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
}
}
cout << "signal covariance matrix: " << endl;
cout << "background covariance matrix: " << endl;
TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
for (
Int_t itype=0; itype<2; itype++) {
if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
TTree* treeF = (itype==0) ? treeSF : treeBF;
if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
getGaussRnd( *
v, *
m,
R );
for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
{
for (
Int_t ivar=0; ivar<nvar; ivar++) {
}
rho[1*2] = 0.4;
rho[1*3] = 0.6;
rho[1*4] = 0.9;
rho[2*3] = 0.7;
rho[2*4] = 0.8;
rho[3*4] = 0.93;
for (
Int_t ivar=0; ivar<nvar; ivar++) {
(*covMat)(ivar,ivar) = dx[ivar]*dx[ivar];
for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
(*covMat)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
(*covMat)(jvar,ivar) = (*covMat)(ivar,jvar);
}
}
TMatrixD* sqrtMat = produceSqrtMat( *covMat );
if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
getGaussRnd( *
v, *sqrtMat,
R );
for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
}
cout <<
"created tree: " <<
tree->GetName() << endl;
}
{
for (
Int_t ivar=0; ivar<nvar; ivar++) {
}
Float_t phimin = -70, phimax = 130;
Float_t fnmin = -(radius+4.0*rsig);
Float_t fnmax = +(radius+4.0*rsig);
r3= r1>r2? r1 :r2;
if (distort) phi = r3*(phimax - phimin) + phimin;
else phi =
R.Rndm()*(phimax - phimin) + phimin;
for(
Int_t j = 2; j<nvar; ++j )
xvar[j] = dfn*
R.Rndm()+fnmin;
}
for (
Int_t i=0; i<Nn; i++) {
xvar[0] = dfn*
R.Rndm()+fnmin;
xvar[1] = dfn*
R.Rndm()+fnmin;
for(
Int_t j = 2; j<nvar; ++j )
xvar[j] = dfn*
R.Rndm()+fnmin;
}
cout <<
"created tree: " <<
tree->GetName() << endl;
}
void create_lin_Nvar_2(
Int_t N = 50000)
{
const int nvar = 4;
Float_t xS[nvar] = { 0.2, 0.3, 0.5, 0.9 };
Float_t xB[nvar] = { -0.2, -0.3, -0.5, -0.6 };
Float_t dx[nvar] = { 1.0, 1.0, 1.0, 1.0 };
TTree* treeS = makeTree_lin_Nvar(
"TreeS",
"Signal tree", xS, dx, nvar,
N );
TTree* treeB = makeTree_lin_Nvar(
"TreeB",
"Background tree", xB, dx, nvar,
N );
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
void create_lin_Nvar(
Int_t N = 50000)
{
for (
Int_t ivar=0; ivar<nvar; ivar++) {
}
Float_t xS[nvar] = { 0.2, 0.3, 0.5, 0.9 };
Float_t xB[nvar] = { -0.2, -0.3, -0.5, -0.6 };
Float_t dx[nvar] = { 1.0, 1.0, 1.0, 1.0 };
rho[1*2] = 0.4;
rho[1*3] = 0.6;
rho[1*4] = 0.9;
rho[2*3] = 0.7;
rho[2*4] = 0.8;
rho[3*4] = 0.93;
for (
Int_t ivar=0; ivar<nvar; ivar++) {
(*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
(*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
(*covMatS)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
(*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
(*covMatB)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
(*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
}
}
cout << "signal covariance matrix: " << endl;
cout << "background covariance matrix: " << endl;
TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
for (
Int_t itype=0; itype<2; itype++) {
if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
getGaussRnd( *
v, *
m,
R );
for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
{
for (
Int_t ivar=0; ivar<nvar; ivar++) {
}
treeS->
Branch(
"eta", &eta,
"eta/F" );
treeB->
Branch(
"eta", &eta,
"eta/F" );
Float_t xS[nvar] = { 0.2, 0.3, 0.5, 0.9 };
Float_t xB[nvar] = { -0.2, -0.3, -0.5, -0.6 };
Float_t dx[nvar] = { 1.0, 1.0, 1.0, 1.0 };
rho[1*2] = 0.0;
rho[1*3] = 0.0;
rho[1*4] = 0.0;
rho[2*3] = 0.0;
rho[2*4] = 0.0;
rho[3*4] = 0.0;
rho[1*2] = 0.6;
rho[1*3] = 0.7;
rho[1*4] = 0.9;
rho[2*3] = 0.8;
rho[2*4] = 0.9;
rho[3*4] = 0.93;
}
for (
Int_t ivar=0; ivar<nvar; ivar++) {
(*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
(*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
(*covMatS)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
(*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
(*covMatB)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
(*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
}
}
cout << "signal covariance matrix: " << endl;
cout << "background covariance matrix: " << endl;
TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
for (
Int_t itype=0; itype<2; itype++) {
if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
getGaussRnd( *
v, *
m,
R );
eta = 2.5*2*(
R.Rndm() - 0.5);
for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar] +
offset;
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
void create_lin_Nvar_weighted(
Int_t N = 10000,
int WeightedSignal=0,
int WeightedBkg=1,
Float_t BackgroundContamination=0,
Int_t seed=100)
{
cout << endl << endl << endl;
cout << "please use .L createData.C++ if you want to run this MC geneation" <<endl;
cout << "otherwise you will wait for ages!!! " << endl;
cout << endl << endl << endl;
if (BackgroundContamination) fileName =
Form(
"linCorGauss%d_weighted+background.root",seed);
else fileName =
Form(
"linCorGauss%d_weighted.root",seed);
for (
Int_t ivar=0; ivar<nvar; ivar++) {
}
if (WeightedSignal||BackgroundContamination>0||1) treeS->
Branch(
"weight", &weight,
"weight/F" );
if (WeightedBkg) treeB->
Branch(
"weight", &weight,
"weight/F" );
Float_t xS[nvar] = { 0.2, 0.3, 0.4, 0.8 };
Float_t xB[nvar] = { -0.2, -0.3, -0.4, -0.5 };
Float_t dx[nvar] = { 1.0, 1.0, 1.0, 1.0 };
rho[1*2] = 0.4;
rho[1*3] = 0.6;
rho[1*4] = 0.9;
rho[2*3] = 0.7;
rho[2*4] = 0.8;
rho[3*4] = 0.93;
for (
Int_t ivar=0; ivar<nvar; ivar++) {
(*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
(*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
(*covMatS)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
(*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
(*covMatB)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
(*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
}
}
cout << "signal covariance matrix: " << endl;
cout << "background covariance matrix: " << endl;
TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
for (
Int_t itype=0; itype<2; itype++) {
if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
do {
getGaussRnd( *
v, *
m,
R );
for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
if (itype==0 && !WeightedSignal) {
weight = 1;
i++;
} else if (itype==1 && !WeightedBkg) {
weight = 1;
i++;
}
else {
if (tmp < weight){
weight = 1./weight;
if (i%10 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
i++;
}
}
}
if (BackgroundContamination > 0){
for (
Int_t i=0; i<
N*BackgroundContamination*2; i++) {
if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
getGaussRnd( *
v, *
m,
R );
for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
if (i%2) weight = 1;
else weight = -1;
}
}
char buffer[5];
sprintf(buffer,"h%d",i);
h[i]=
new TH1F(buffer,
"",100,-5,5);
sprintf(buffer,"hw%d",i);
hw[i] =
new TH1F(buffer,
"",100,-5,5);
}
hw[i]->
Fill(xvar[i],weight);
}
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
void create_lin_Nvar_Arr(
Int_t N = 1000)
{
std::vector<float>* xvar[nvar];
for (
Int_t ivar=0; ivar<nvar; ivar++) {
xvar[ivar] = new std::vector<float>();
treeS->
Branch(
TString(
Form(
"var%i", ivar+1 )).Data(),
"vector<float>", &xvar[ivar], 64000, 1 );
treeB->
Branch(
TString(
Form(
"var%i", ivar+1 )).Data(),
"vector<float>", &xvar[ivar], 64000, 1 );
}
Float_t xS[nvar] = { 0.2, 0.3, 0.5, 0.9 };
Float_t xB[nvar] = { -0.2, -0.3, -0.5, -0.6 };
Float_t dx[nvar] = { 1.0, 1.0, 1.0, 1.0 };
rho[1*2] = 0.4;
rho[1*3] = 0.6;
rho[1*4] = 0.9;
rho[2*3] = 0.7;
rho[2*4] = 0.8;
rho[3*4] = 0.93;
for (
Int_t ivar=0; ivar<nvar; ivar++) {
(*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
(*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
(*covMatS)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
(*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
(*covMatB)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
(*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
}
}
cout << "signal covariance matrix: " << endl;
cout << "background covariance matrix: " << endl;
TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
for (
Int_t itype=0; itype<2; itype++) {
if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
if (i%100 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
for (
Int_t ivar=0; ivar<nvar; ivar++) {
xvar[ivar]->clear();
xvar[ivar]->reserve(aSize);
}
for(
Int_t iA = 0; iA<aSize; iA++) {
getGaussRnd( *
v, *
m,
R );
for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar]->push_back((*
v)[ivar] +
x[ivar]);
}
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
void create_lin_Nvar_double()
{
for (
Int_t ivar=0; ivar<nvar; ivar++) {
if (ivar<2) {
}
else {
}
}
Double_t xS[nvar] = { 0.2, 0.3, 0.5, 0.6 };
Double_t xB[nvar] = { -0.2, -0.3, -0.5, -0.6 };
Double_t dx[nvar] = { 1.0, 1.0, 1.0, 1.0 };
rho[1*2] = 0.4;
rho[1*3] = 0.6;
rho[1*4] = 0.9;
rho[2*3] = 0.7;
rho[2*4] = 0.8;
rho[3*4] = 0.93;
for (
Int_t ivar=0; ivar<nvar; ivar++) {
(*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
(*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
(*covMatS)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
(*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
(*covMatB)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
(*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
}
}
cout << "signal covariance matrix: " << endl;
cout << "background covariance matrix: " << endl;
TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
for (
Int_t itype=0; itype<2; itype++) {
if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
getGaussRnd( *
v, *
m,
R );
for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
for (
Int_t ivar=0; ivar<nvar; ivar++) {
if (ivar<2) xvarD[ivar] = xvar[ivar];
else xvarF[ivar] = xvar[ivar];
}
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
void create_lin_Nvar_discrete()
{
for (
Int_t ivar=0; ivar<nvar-2; ivar++) {
}
for (
Int_t ivar=0; ivar<2; ivar++) {
}
Float_t xS[nvar] = { 0.2, 0.3, 1, 2 };
Float_t xB[nvar] = { -0.2, -0.3, 0, 0 };
Float_t dx[nvar] = { 1.0, 1.0, 1, 2 };
rho[1*2] = 0.4;
rho[1*3] = 0.6;
rho[1*4] = 0.9;
rho[2*3] = 0.7;
rho[2*4] = 0.8;
rho[3*4] = 0.93;
for (int i=0; i<20; i++) rho[i] = 0;
for (
Int_t ivar=0; ivar<nvar; ivar++) {
(*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
(*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
(*covMatS)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
(*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
(*covMatB)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
(*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
}
}
cout << "signal covariance matrix: " << endl;
cout << "background covariance matrix: " << endl;
TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
for (
Int_t itype=0; itype<2; itype++) {
if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
getGaussRnd( *
v, *
m,
R );
for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
void create_ManyVars()
{
for (
Int_t ivar=0; ivar<nvar; ivar++) {
}
for (
Int_t ivar=0; ivar<nvar; ivar++) {
xS[ivar] = 0 + ivar*0.05;
xB[ivar] = 0 - ivar*0.05;
dx[ivar] = 1;
}
xS[0] = 0.2;
xB[0] = -0.2;
dx[0] = 1.0;
xS[1] = 0.3;
xB[1] = -0.3;
dx[1] = 1.0;
xS[2] = 0.4;
xB[2] = -0.4;
dx[2] = 1.0 ;
xS[3] = 0.8 ;
xB[3] = -0.5 ;
dx[3] = 1.0 ;
rho[1*2] = 0.4;
rho[1*3] = 0.6;
rho[1*4] = 0.9;
rho[2*3] = 0.7;
rho[2*4] = 0.8;
rho[3*4] = 0.93;
for (
Int_t itype=0; itype<2; itype++) {
if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
for (
Int_t ivar=0; ivar<nvar; ivar++) {
if (ivar == 1500 && itype!=10) xvar[ivar] = 1;
else xvar[ivar] =
x[ivar] +
R.Gaus()*dx[ivar];
}
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
void create_lin_NvarObsolete()
{
for (
Int_t ivar=0; ivar<nvar; ivar++) {
}
Float_t xS[nvar] = { 0.5, 0.5, 0.0, 0.0, 0.0, 0.0 };
Float_t xB[nvar] = { -0.5, -0.5, -0.0, -0.0, -0.0, -0.0 };
Float_t dx[nvar] = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
for (
Int_t i=0; i<50; i++) rho[i] = 0;
rho[1*2] = 0.3;
rho[1*3] = 0.0;
rho[1*4] = 0.0;
rho[2*3] = 0.0;
rho[2*4] = 0.0;
rho[3*4] = 0.0;
for (
Int_t ivar=0; ivar<nvar; ivar++) {
(*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
(*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
(*covMatS)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
(*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
(*covMatB)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
(*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
}
}
cout << "signal covariance matrix: " << endl;
cout << "background covariance matrix: " << endl;
TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
for (
Int_t itype=0; itype<2; itype++) {
if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
getGaussRnd( *
v, *
m,
R );
for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
void create_lin(
Int_t N = 2000)
{
for (
Int_t ivar=0; ivar<nvar; ivar++) {
}
treeS->
Branch(
"weight", &weight,
"weight/F" );
treeB->
Branch(
"weight", &weight,
"weight/F" );
for (
Int_t ivar=0; ivar<nvar; ivar++) {
(*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
(*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
(*covMatS)(ivar,jvar) = rhoS*dx[ivar]*dx[jvar];
(*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
(*covMatB)(ivar,jvar) = rhoB*dx[ivar]*dx[jvar];
(*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
}
}
cout << "signal covariance matrix: " << endl;
cout << "background covariance matrix: " << endl;
TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
for (
Int_t itype=0; itype<2; itype++) {
if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
getGaussRnd( *
v, *
m,
R );
for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
if (itype == 0) weight = 1.0;
else weight = 2.0;
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
void create_fullcirc(
Int_t nmax = 20000,
Bool_t distort=
false)
{
int nvar = 2;
int nsig = 0, nbgd=0;
for (
Int_t ivar=0; ivar<nvar; ivar++) {
}
treeS->
Branch(
"weight", &weight,
"weight/F");
treeB->
Branch(
"weight", &weight,
"weight/F");
do {
for (
Int_t ivar=0; ivar<nvar; ivar++) { xvar[ivar]=2.*
R.Rndm()-1.;}
Float_t xout = xvar[0]*xvar[0]+xvar[1]*xvar[1];
if (nsig<10) cout << "xout = " << xout<<endl;
if (xout < 0.3 || (xout >0.3 && xout<0.5 &&
R.Rndm() > xout)) {
if (distort && xvar[0] < 0 &&
R.Rndm()>0.1)
continue;
nsig++;
}
else {
if (distort && xvar[0] > 0 &&
R.Rndm()>0.1)
continue;
nbgd++;
}
} while ( nsig < nmax || nbgd < nmax);
}
{
for (
Int_t ivar=0; ivar<nvar; ivar++) {
}
Float_t phimin = -70, phimax = 130;
for (
Int_t itype=0; itype<2; itype++) {
if (itype==0) r3= r1>r2? r1 :r2;
else r3= r2;
if (distort) phi = r3*(phimax - phimin) + phimin;
else phi =
R.Rndm()*(phimax - phimin) + phimin;
}
for (
Int_t i=0; i<Nn; i++) {
xvar[0] = dfn*
R.Rndm()+fnmin;
xvar[1] = dfn*
R.Rndm()+fnmin;
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
void create_schachbrett(
Int_t nEvents = 20000) {
for (
Int_t ivar=0; ivar<nvar; ivar++) {
}
while (iev < nEvents){
xtype=1;
for (
Int_t i=-m_nDim; i <= m_nDim; i++){
ytype = 1;
for (
Int_t j=-m_nDim; j <= m_nDim; j++){
iev++;
ytype *= -1;
}
xtype *= -1;
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
void create_schachbrett_5D(
Int_t nEvents = 200000) {
for (
Int_t ivar=0; ivar<nvar; ivar++) {
}
int idx[nvar];
while (iev < nEvents){
itype[0]=1;
for (idx[0]=-m_nDim; idx[0] <= m_nDim; idx[0]++){
itype[1]=1;
for (idx[1]=-m_nDim; idx[1] <= m_nDim; idx[1]++){
itype[2]=1;
for (idx[2]=-m_nDim; idx[2] <= m_nDim; idx[2]++){
itype[3]=1;
for (idx[3]=-m_nDim; idx[3] <= m_nDim; idx[3]++){
itype[4]=1;
for (idx[4]=-m_nDim; idx[4] <= m_nDim; idx[4]++){
for (
Int_t i=0;i<nvar;i++){
if (i>0)
type *= itype[i];
}
iev++;
itype[4] *= -1;
}
itype[3] *= -1;
}
itype[2] *= -1;
}
itype[1] *= -1;
}
itype[0] *= -1;
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
void create_schachbrett_4D(
Int_t nEvents = 200000) {
for (
Int_t ivar=0; ivar<nvar; ivar++) {
}
int idx[nvar];
while (iev < nEvents){
itype[0]=1;
for (idx[0]=-m_nDim; idx[0] <= m_nDim; idx[0]++){
itype[1]=1;
for (idx[1]=-m_nDim; idx[1] <= m_nDim; idx[1]++){
itype[2]=1;
for (idx[2]=-m_nDim; idx[2] <= m_nDim; idx[2]++){
itype[3]=1;
for (idx[3]=-m_nDim; idx[3] <= m_nDim; idx[3]++){
for (
Int_t i=0;i<nvar;i++){
if (i>0)
type *= itype[i];
}
iev++;
itype[3] *= -1;
}
itype[2] *= -1;
}
itype[1] *= -1;
}
itype[0] *= -1;
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
void create_schachbrett_3D(
Int_t nEvents = 20000) {
for (
Int_t ivar=0; ivar<nvar; ivar++) {
}
int idx[nvar];
while (iev < nEvents){
itype[0]=1;
for (idx[0]=-m_nDim; idx[0] <= m_nDim; idx[0]++){
itype[1]=1;
for (idx[1]=-m_nDim; idx[1] <= m_nDim; idx[1]++){
itype[2]=1;
for (idx[2]=-m_nDim; idx[2] <= m_nDim; idx[2]++){
for (
Int_t i=0;i<nvar;i++){
if (i>0)
type *= itype[i];
}
iev++;
itype[2] *= -1;
}
itype[1] *= -1;
}
itype[0] *= -1;
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
void create_schachbrett_2D(
Int_t nEvents = 100000,
Int_t nbumps=2) {
for (
Int_t ivar=0; ivar<nvar; ivar++) {
}
int idx[nvar];
while (iev < nEvents){
itype[0]=1;
for (idx[0]=-m_nDim; idx[0] <= m_nDim; idx[0]++){
itype[1]=1;
for (idx[1]=-m_nDim; idx[1] <= m_nDim; idx[1]++){
for (
Int_t i=0;i<nvar;i++){
if (i>0)
type *= itype[i];
}
iev++;
itype[1] *= -1;
}
itype[0] *= -1;
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
void create_3Bumps(
Int_t nEvents = 5000) {
for (
Int_t ivar=0; ivar<nvar; ivar++) {
}
Double_t Centers[nvar][6] = {{-1,0,0,0,1,1},{0,0,0,0,0,0}};
while (iev < nEvents){
for (int idx=0; idx<6; idx++){
if (idx==1 || idx==2 || idx==3)
type = 0;
for (
Int_t ivar=0;ivar<nvar;ivar++){
xvar[ivar]=m_rand->
Gaus(Centers[ivar][idx],
sigma);
}
iev++;
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
void createOnionData(
Int_t nmax = 50000){
int nvar = 4;
int nsig = 0, nbgd=0;
for (
Int_t ivar=0; ivar<nvar; ivar++) {
}
do {
for (
Int_t ivar=0; ivar<nvar; ivar++) { xvar[ivar]=
R.Rndm();}
Float_t xout =
sin(2.*
acos(-1.)*(xvar[0]*xvar[1]*xvar[2]*xvar[3]+xvar[0]*xvar[1]));
if (nsig<100) cout << "xout = " << xout<<endl;
if (i%2 == 0 && nsig < nmax) {
nsig++;
}
if (i%2 != 0 && nbgd < nmax){
nbgd++;
}
} while ( nsig < nmax || nbgd < nmax);
}
void create_multiclassdata(
Int_t nmax = 20000)
{
int ncls = 3;
int nvar = 4;
int ndat = 0;
{ 0. , 0.3, 0.5, 0.9 },
{ -0.2 , -0.3, 0.5, 0.4 },
{ 0.2 , 0.1, -0.1, 0.7 }} ;
for (
Int_t ivar=0; ivar<nvar; ivar++) {
}
for (
Int_t icls=0; icls<ncls; icls++) {
}
treeR->
Branch(
"cls", &thecls,
"cls/F");
treeR->
Branch(
"weight", &weight,
"weight/F");
do {
for (
Int_t icls=0; icls<ncls; icls++) xcls[icls]=0.;
thecls = cls;
xcls[cls]=1.;
for (
Int_t ivar=0; ivar<nvar; ivar++) {
xvar[ivar]=
R.Gaus(xmean[cls][ivar],1.);
}
if (ndat<30) cout << "cls=" << cls <<" xvar = " << xvar[0]<<" " <<xvar[1]<<" " << xvar[2]<<" " <<xvar[3]<<endl;
ndat++;
} while ( ndat < nmax );
}
void create_array_with_different_lengths(
Int_t N = 100)
{
treeS->
Branch(
"arrSize", &nvarCurrent,
"arrSize/I" );
treeS->
Branch(
"arr", xvar,
"arr[arrSize]/F" );
treeB->
Branch(
"arrSize", &nvarCurrent,
"arrSize/I" );
treeB->
Branch(
"arr", xvar,
"arr[arrSize]/F" );
Float_t xS[nvar] = { 0.2, 0.3, 0.5, 0.9 };
Float_t xB[nvar] = { -0.2, -0.3, -0.5, -0.6 };
Float_t dx[nvar] = { 1.0, 1.0, 1.0, 1.0 };
rho[1*2] = 0.4;
rho[1*3] = 0.6;
rho[1*4] = 0.9;
rho[2*3] = 0.7;
rho[2*4] = 0.8;
rho[3*4] = 0.93;
for (
Int_t ivar=0; ivar<nvar; ivar++) {
(*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
(*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
(*covMatS)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
(*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
(*covMatB)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
(*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
}
}
cout << "signal covariance matrix: " << endl;
cout << "background covariance matrix: " << endl;
TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
for (
Int_t itype=0; itype<2; itype++) {
if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
getGaussRnd( *
v, *
m,
R );
for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
nvarCurrent = (i%4)+1;
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
void create_MultipleBackground(
Int_t N = 50000)
{
const int nvar = 4;
TFile* dataFile =
TFile::Open(
"tmva_example_multiple_background.root",
"RECREATE" );
Float_t xS[nvar] = { 0.2, 0.3, 0.5, 0.9 };
Float_t xB0[nvar] = { -0.2, -0.3, -0.5, -0.6 };
Float_t xB1[nvar] = { -0.2, 0.3, 0.5, -0.6 };
Float_t dx0[nvar] = { 1.0, 1.0, 1.0, 1.0 };
Float_t dx1[nvar] = { -1.0, -1.0, -1.0, -1.0 };
TTree* treeS = makeTree_lin_Nvar(
"TreeS",
"Signal tree", xS, dx0, nvar,
N );
TTree* treeB0 = makeTree_lin_Nvar(
"TreeB0",
"Background 0", xB0, dx0, nvar,
N );
TTree* treeB1 = makeTree_lin_Nvar(
"TreeB1",
"Background 1", xB1, dx1, nvar,
N );
TTree* treeB2 = makeTree_circ(
"TreeB2",
"Background 2", nvar,
N, 1.5,
true);
cout <<
"created data file: " << dataFile->
GetName() << endl;
}
#define R(a, b, c, d, e, f, g, h, i)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
winID h TVirtualViewer3D TVirtualGLPainter char TVirtualGLPainter plot
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 filename
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 offset
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 r
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
TMatrixT< Double_t > TMatrixD
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Array of doubles (64 bits per element).
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsiz=0) override
Write memory objects to this file.
void Close(Option_t *option="") override
Close a file.
1-D histogram with a float per channel (see TH1 documentation)}
virtual void SetTitleSize(Float_t size=0.02, Option_t *axis="X")
Set the axis' title size.
void SetTitle(const char *title) override
Change (i.e.
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
void Draw(Option_t *option="") override
Draw this histogram with options.
virtual void SetLabelSize(Float_t size=0.02, Option_t *axis="X")
Set size of axis' labels.
2-D histogram with a float per channel (see TH1 documentation)}
This class displays a legend box (TPaveText) containing several legend entries.
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
void Draw(Option_t *option="") override
Draw this legend with its current attributes.
void SetMargin(Float_t margin)
void Print(Option_t *name="") const override
Print the matrix as a table of elements.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
virtual void SetBorderSize(Int_t bordersize=4)
This is the base class for the ROOT Random number generators.
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Double_t Rndm() override
Machine independent random number generator.
const char * Data() const
TStyle objects may be created to define special styles.
void SetOptTitle(Int_t tit=1)
void SetPadTopMargin(Float_t margin=0.1)
void SetTitleX(Float_t x=0)
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
void SetPadBottomMargin(Float_t margin=0.1)
void SetPadRightMargin(Float_t margin=0.1)
void SetPadGridX(Bool_t gridx)
void SetPadLeftMargin(Float_t margin=0.1)
void SetPadGridY(Bool_t gridy)
virtual void cd()
Change current style.
void SetTitleW(Float_t w=0)
void SetTitleH(Float_t h=0)
void SetTitleY(Float_t y=0.985)
A TTree represents a columnar dataset.
virtual Int_t Fill()
Fill all branches.
virtual void Show(Long64_t entry=-1, Int_t lenmax=20)
Print values of all active leaves for entry.
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
void Draw(Option_t *opt) override
Default Draw method for all objects.
virtual Double_t GetMaximum(const char *columname)
Return maximum of column with name columname.
virtual Long64_t GetEntries() const
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 Double_t GetMinimum(const char *columname)
Return minimum of column with name columname.
Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0) override
Write this object to the current directory.
RVec< PromoteType< T > > cos(const RVec< T > &v)
RVec< PromoteType< T > > acos(const RVec< T > &v)
RVec< PromoteType< T > > sin(const RVec< T > &v)
Double_t Gaus(Double_t x, Double_t mean=0, Double_t sigma=1, Bool_t norm=kFALSE)
Calculates a gaussian function with mean and sigma.
Int_t Nint(T x)
Round to nearest integer. Rounds half integers to the nearest even integer.
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Double_t Log(Double_t x)
Returns the natural logarithm of x.
constexpr Double_t DegToRad()
Conversion from degree to radian: .
Double_t Sqrt(Double_t x)
Returns the square root of x.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
static uint64_t sum(uint64_t i)