Plot the variables.
#include <vector>
{
if (!dataFile) {
cout << "ERROR: cannot open file: " << fname << endl;
return;
}
TH2F* frameS =
new TH2F(
"DataS",
"DataS", nbin, xmin, xmax, nbin, ymin, ymax );
TH2F* frameB =
new TH2F(
"DataB",
"DataB", nbin, xmin, xmax, nbin, ymin, ymax );
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" );
legend->
AddEntry(frameB,
"Background",
"p");
}
{
for (
Int_t i=0; i< size; i++) {
sum = 0;
for (
Int_t j=0;j< i; j++) sum += (*sqrtMat)(i,j) * (*sqrtMat)(i,j);
for (
Int_t k=i+1 ;k<size; k++) {
sum = 0;
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 i=0; i<size; i++) {
}
for (
Int_t i=0; i<size; i++) {
v[i] = 0;
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* tree = (itype==0) ? treeS : treeB;
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;
}
{
TTree* tree =
new TTree( treeName, treeTitle, 1 );
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; }
TTree* tree = (itype==0) ? treeS : treeB;
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_Nvar_categories(
Int_t N = 10000,
Int_t type = 2)
{
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;
if (type != 1) {
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; }
TTree* tree = (itype==0) ? treeS : treeB;
if (i%1000 == 0) cout << "... event: " << i << " (" << N << ")" << endl;
getGaussRnd( *v, *m, R );
eta = 2.5*2*(R.
Rndm() - 0.5);
if (type == 1) offset =
TMath::Abs(eta) > 1.3 ? 0.8 : -0.8;
for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*v)[ivar] + x[ivar] + offset;
if (type != 1 &&
TMath::Abs(eta) > 1.3) xvar[nvar-1] = -5;
}
}
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++) {
treeS->Branch(
TString(
Form(
"var%i", ivar+1 )).Data(), &xvar[ivar],
TString(
Form(
"var%i/F", ivar+1 )).Data() );
}
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; }
TTree* tree = (itype==0) ? treeS : treeB;
do {
getGaussRnd( *v, *m, R );
for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*v)[ivar] + x[ivar];
weight = 0.8 / (
TMath::Gaus( ((*v)[nvar-1]), 0, 1.09) );
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++;
}
}
} while (i<N);
}
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;
}
}
treeS->Write();
treeS->Show(0);
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);
}
for (int ie=0;ie<treeS->GetEntries();ie++){
treeS->GetEntry(ie);
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; }
TTree* tree = (itype==0) ? treeS : treeB;
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; }
TTree* tree = (itype==0) ? treeS : treeB;
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;
plot();
}
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; }
TTree* tree = (itype==0) ? treeS : treeB;
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;
plot();
}
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++) {
Float_t* x = (itype == 0) ? xS : xB;
TTree* tree = (itype == 0) ? treeS : treeB;
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];
}
}
}
plot();
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; }
TTree* tree = (itype==0) ? treeS : treeB;
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;
plot();
}
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; }
TTree* tree = (itype==0) ? treeS : treeB;
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;
plot();
}
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);
}
void create_circ(
Int_t N = 6000,
Bool_t distort =
false)
{
for (
Int_t ivar=0; ivar<nvar; ivar++) {
}
Float_t phimin = -70, phimax = 130;
for (
Int_t itype=0; itype<2; itype++) {
TTree* tree = (itype==0) ? treeS : treeB;
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;
plot();
}
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++){
xvar[0]=m_rand->
Gaus(meanY,sigma);
xvar[1]=m_rand->
Gaus(meanX,sigma);
Int_t type = xtype*ytype;
TTree* tree = (type==1) ? treeS : treeB;
iev++;
ytype *= -1;
}
xtype *= -1;
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
plot();
}
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];
}
TTree* tree = (type==1) ? treeS : treeB;
iev++;
itype[4] *= -1;
}
itype[3] *= -1;
}
itype[2] *= -1;
}
itype[1] *= -1;
}
itype[0] *= -1;
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
plot();
}
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];
}
TTree* tree = (type==1) ? treeS : treeB;
iev++;
itype[3] *= -1;
}
itype[2] *= -1;
}
itype[1] *= -1;
}
itype[0] *= -1;
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
plot();
}
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];
}
TTree* tree = (type==1) ? treeS : treeB;
iev++;
itype[2] *= -1;
}
itype[1] *= -1;
}
itype[0] *= -1;
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
plot();
}
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];
}
TTree* tree = (type==1) ? treeS : treeB;
iev++;
itype[1] *= -1;
}
itype[0] *= -1;
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
plot();
}
void create_3Bumps(
Int_t nEvents = 5000) {
TString filename =
"data_3Bumps.root";
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;
else type=1;
for (
Int_t ivar=0;ivar<nvar;ivar++){
xvar[ivar]=m_rand->
Gaus(Centers[ivar][idx],sigma);
}
TTree* tree = (type==1) ? treeS : treeB;
iev++;
}
}
cout <<
"created data file: " << dataFile->
GetName() << endl;
plot(filename);
}
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; }
TTree* tree = (itype==0) ? treeS : treeB;
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;
}