29 cout <<
"ERROR: cannot open file: " << fname << endl;
67 treeS->
Draw(
Form(
"%s:%s>>DataS",var1.Data(),var0.Data()),
"",
"0" );
68 treeB->
Draw(
Form(
"%s:%s>>DataB",var1.Data(),var0.Data()
79 frameS->
SetTitle( var1+
" versus "+var0+
" for signal and background" );
90 frameB->
Draw(
"same" );
93 TLegend *legend =
new TLegend( 1 -
c->GetRightMargin() - 0.32, 1 -
c->GetTopMargin() - 0.12,
94 1 -
c->GetRightMargin(), 1 -
c->GetTopMargin() );
96 legend->
AddEntry(frameS,
"Signal",
"p");
97 legend->
AddEntry(frameB,
"Background",
"p");
110 for (
Int_t i=0; i< size; i++) {
113 for (
Int_t j=0;j< i; j++)
sum += (*sqrtMat)(i,j) * (*sqrtMat)(i,j);
117 for (
Int_t k=i+1 ;k<size; k++) {
120 for (
Int_t l=0;
l<i;
l++)
sum += (*sqrtMat)(k,
l) * (*sqrtMat)(i,
l);
122 (*sqrtMat)(k,i) = (covMat(k,i) -
sum) / (*sqrtMat)(i,i);
135 if (size !=
v.GetSize())
136 cout <<
"<getGaussRnd> too short input vector: " << size <<
" " <<
v.GetSize() << endl;
140 for (
Int_t i=0; i<size; i++) {
148 for (
Int_t i=0; i<size; i++) {
150 for (
Int_t j=0; j<=i; j++)
v[i] += sqrtMat(i,j) * tmpVec[j];
157void create_lin_Nvar_withFriend(
Int_t N = 2000)
159 const Int_t nvar = 4;
160 const Int_t nvar2 = 1;
167 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
168 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
169 for (
Int_t ivar=0; ivar<nvar-nvar2; ivar++) {
170 cout <<
"Creating branch var" << ivar+1 <<
" in signal tree" << endl;
174 TTree* treeSF =
new TTree(
"TreeSF",
"TreeS", 1 );
175 TTree* treeBF =
new TTree(
"TreeBF",
"TreeB", 1 );
176 for (
Int_t ivar=nvar-nvar2; ivar<nvar; ivar++) {
183 Float_t xS[nvar] = { 0.2, 0.3, 0.5, 0.9 };
184 Float_t xB[nvar] = { -0.2, -0.3, -0.5, -0.6 };
185 Float_t dx[nvar] = { 1.0, 1.0, 1.0, 1.0 };
198 for (
Int_t ivar=0; ivar<nvar; ivar++) {
199 (*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
200 (*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
201 for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
202 (*covMatS)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
203 (*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
205 (*covMatB)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
206 (*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
210 cout <<
"signal covariance matrix: " << endl;
212 cout <<
"background covariance matrix: " << endl;
216 TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
217 TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
220 for (
Int_t itype=0; itype<2; itype++) {
224 if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
225 else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
228 TTree*
tree = (itype==0) ? treeS : treeB;
229 TTree* treeF = (itype==0) ? treeSF : treeBF;
230 for (
Int_t i=0; i<
N; i++) {
232 if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
233 getGaussRnd( *
v, *
m,
R );
235 for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
255 cout <<
"created data file: " << dataFile->
GetName() << endl;
269 for (
Int_t ivar=0; ivar<nvar; ivar++) {
285 for (
Int_t ivar=0; ivar<nvar; ivar++) {
286 (*covMat)(ivar,ivar) = dx[ivar]*dx[ivar];
287 for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
288 (*covMat)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
289 (*covMat)(jvar,ivar) = (*covMat)(ivar,jvar);
296 TMatrixD* sqrtMat = produceSqrtMat( *covMat );
299 for (
Int_t i=0; i<
N; i++) {
301 if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
302 getGaussRnd( *
v, *sqrtMat,
R );
304 for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
314 cout <<
"created tree: " <<
tree->GetName() << endl;
327 for (
Int_t ivar=0; ivar<nvar; ivar++) {
333 Float_t phimin = -70, phimax = 130;
336 Float_t fnmin = -(radius+4.0*rsig);
337 Float_t fnmax = +(radius+4.0*rsig);
341 for (
Int_t i=0; i<
N; i++) {
345 if (distort) phi = r3*(phimax - phimin) + phimin;
346 else phi =
R.Rndm()*(phimax - phimin) + phimin;
347 phi +=
R.Gaus()*phisig;
355 for(
Int_t j = 2; j<nvar; ++j )
356 xvar[j] = dfn*
R.Rndm()+fnmin;
361 for (
Int_t i=0; i<Nn; i++) {
363 xvar[0] = dfn*
R.Rndm()+fnmin;
364 xvar[1] = dfn*
R.Rndm()+fnmin;
366 for(
Int_t j = 2; j<nvar; ++j )
367 xvar[j] = dfn*
R.Rndm()+fnmin;
375 cout <<
"created tree: " <<
tree->GetName() << endl;
382void create_lin_Nvar_2(
Int_t N = 50000)
390 Float_t xS[nvar] = { 0.2, 0.3, 0.5, 0.9 };
391 Float_t xB[nvar] = { -0.2, -0.3, -0.5, -0.6 };
392 Float_t dx[nvar] = { 1.0, 1.0, 1.0, 1.0 };
395 TTree* treeS = makeTree_lin_Nvar(
"TreeS",
"Signal tree", xS, dx, nvar,
N );
396 TTree* treeB = makeTree_lin_Nvar(
"TreeB",
"Background tree", xB, dx, nvar,
N );
405 cout <<
"created data file: " << dataFile->
GetName() << endl;
412void create_lin_Nvar(
Int_t N = 50000)
414 const Int_t nvar = 4;
421 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
422 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
423 for (
Int_t ivar=0; ivar<nvar; ivar++) {
429 Float_t xS[nvar] = { 0.2, 0.3, 0.5, 0.9 };
430 Float_t xB[nvar] = { -0.2, -0.3, -0.5, -0.6 };
431 Float_t dx[nvar] = { 1.0, 1.0, 1.0, 1.0 };
444 for (
Int_t ivar=0; ivar<nvar; ivar++) {
445 (*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
446 (*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
447 for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
448 (*covMatS)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
449 (*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
451 (*covMatB)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
452 (*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
455 cout <<
"signal covariance matrix: " << endl;
457 cout <<
"background covariance matrix: " << endl;
461 TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
462 TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
465 for (
Int_t itype=0; itype<2; itype++) {
469 if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
470 else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
473 TTree*
tree = (itype==0) ? treeS : treeB;
474 for (
Int_t i=0; i<
N; i++) {
476 if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
477 getGaussRnd( *
v, *
m,
R );
479 for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
493 cout <<
"created data file: " << dataFile->
GetName() << endl;
500 const Int_t nvar = 4;
508 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
509 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
510 for (
Int_t ivar=0; ivar<nvar; ivar++) {
516 treeS->
Branch(
"eta", &eta,
"eta/F" );
517 treeB->
Branch(
"eta", &eta,
"eta/F" );
520 Float_t xS[nvar] = { 0.2, 0.3, 0.5, 0.9 };
521 Float_t xB[nvar] = { -0.2, -0.3, -0.5, -0.6 };
522 Float_t dx[nvar] = { 1.0, 1.0, 1.0, 1.0 };
543 for (
Int_t ivar=0; ivar<nvar; ivar++) {
544 (*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
545 (*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
546 for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
547 (*covMatS)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
548 (*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
550 (*covMatB)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
551 (*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
554 cout <<
"signal covariance matrix: " << endl;
556 cout <<
"background covariance matrix: " << endl;
560 TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
561 TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
564 for (
Int_t itype=0; itype<2; itype++) {
568 if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
569 else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
572 TTree*
tree = (itype==0) ? treeS : treeB;
573 for (
Int_t i=0; i<
N; i++) {
575 if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
576 getGaussRnd( *
v, *
m,
R );
578 eta = 2.5*2*(
R.Rndm() - 0.5);
581 for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar] + offset;
596 cout <<
"created data file: " << dataFile->
GetName() << endl;
601void create_lin_Nvar_weighted(
Int_t N = 10000,
int WeightedSignal=0,
int WeightedBkg=1,
Float_t BackgroundContamination=0,
Int_t seed=100)
603 const Int_t nvar = 4;
608 cout << endl << endl << endl;
609 cout <<
"please use .L createData.C++ if you want to run this MC geneation" <<endl;
610 cout <<
"otherwise you will wait for ages!!! " << endl;
611 cout << endl << endl << endl;
616 if (BackgroundContamination) fileName =
Form(
"linCorGauss%d_weighted+background.root",seed);
617 else fileName =
Form(
"linCorGauss%d_weighted.root",seed);
622 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
623 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
624 for (
Int_t ivar=0; ivar<nvar; ivar++) {
628 if (WeightedSignal||BackgroundContamination>0||1) treeS->
Branch(
"weight", &weight,
"weight/F" );
629 if (WeightedBkg) treeB->
Branch(
"weight", &weight,
"weight/F" );
632 Float_t xS[nvar] = { 0.2, 0.3, 0.4, 0.8 };
633 Float_t xB[nvar] = { -0.2, -0.3, -0.4, -0.5 };
634 Float_t dx[nvar] = { 1.0, 1.0, 1.0, 1.0 };
647 for (
Int_t ivar=0; ivar<nvar; ivar++) {
648 (*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
649 (*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
650 for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
651 (*covMatS)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
652 (*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
654 (*covMatB)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
655 (*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
658 cout <<
"signal covariance matrix: " << endl;
660 cout <<
"background covariance matrix: " << endl;
664 TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
665 TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
668 for (
Int_t itype=0; itype<2; itype++) {
672 if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
673 else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
676 TTree*
tree = (itype==0) ? treeS : treeB;
679 getGaussRnd( *
v, *
m,
R );
681 for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
686 weight = 0.8 / (
TMath::Gaus( ((*
v)[nvar-1]), 0, 1.09) );
688 if (itype==0 && !WeightedSignal) {
692 }
else if (itype==1 && !WeightedBkg) {
701 if (i%10 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
709 if (BackgroundContamination > 0){
714 for (
Int_t i=0; i<
N*BackgroundContamination*2; i++) {
715 if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
716 getGaussRnd( *
v, *
m,
R );
717 for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
738 for (
Int_t i=0;i<4;i++){
740 sprintf(buffer,
"h%d",i);
741 h[i]=
new TH1F(buffer,
"",100,-5,5);
742 sprintf(buffer,
"hw%d",i);
743 hw[i] =
new TH1F(buffer,
"",100,-5,5);
749 for (
Int_t i=0;i<4;i++){
751 hw[i]->
Fill(xvar[i],weight);
758 for (
Int_t i=0;i<4;i++){
766 cout <<
"created data file: " << dataFile->
GetName() << endl;
772void create_lin_Nvar_Arr(
Int_t N = 1000)
774 const Int_t nvar = 4;
775 std::vector<float>* xvar[nvar];
781 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
782 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
783 for (
Int_t ivar=0; ivar<nvar; ivar++) {
784 xvar[ivar] =
new std::vector<float>();
785 treeS->
Branch(
TString(
Form(
"var%i", ivar+1 )).Data(),
"vector<float>", &xvar[ivar], 64000, 1 );
786 treeB->
Branch(
TString(
Form(
"var%i", ivar+1 )).Data(),
"vector<float>", &xvar[ivar], 64000, 1 );
790 Float_t xS[nvar] = { 0.2, 0.3, 0.5, 0.9 };
791 Float_t xB[nvar] = { -0.2, -0.3, -0.5, -0.6 };
792 Float_t dx[nvar] = { 1.0, 1.0, 1.0, 1.0 };
805 for (
Int_t ivar=0; ivar<nvar; ivar++) {
806 (*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
807 (*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
808 for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
809 (*covMatS)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
810 (*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
812 (*covMatB)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
813 (*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
816 cout <<
"signal covariance matrix: " << endl;
818 cout <<
"background covariance matrix: " << endl;
822 TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
823 TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
826 for (
Int_t itype=0; itype<2; itype++) {
830 if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
831 else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
834 TTree*
tree = (itype==0) ? treeS : treeB;
835 for (
Int_t i=0; i<
N; i++) {
837 if (i%100 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
840 for (
Int_t ivar=0; ivar<nvar; ivar++) {
842 xvar[ivar]->reserve(aSize);
844 for(
Int_t iA = 0; iA<aSize; iA++) {
846 getGaussRnd( *
v, *
m,
R );
847 for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar]->push_back((*
v)[ivar] +
x[ivar]);
862 cout <<
"created data file: " << dataFile->
GetName() << endl;
870void create_lin_Nvar_double()
873 const Int_t nvar = 4;
882 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
883 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
884 for (
Int_t ivar=0; ivar<nvar; ivar++) {
896 Double_t xS[nvar] = { 0.2, 0.3, 0.5, 0.6 };
897 Double_t xB[nvar] = { -0.2, -0.3, -0.5, -0.6 };
898 Double_t dx[nvar] = { 1.0, 1.0, 1.0, 1.0 };
911 for (
Int_t ivar=0; ivar<nvar; ivar++) {
912 (*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
913 (*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
914 for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
915 (*covMatS)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
916 (*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
918 (*covMatB)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
919 (*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
922 cout <<
"signal covariance matrix: " << endl;
924 cout <<
"background covariance matrix: " << endl;
928 TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
929 TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
932 for (
Int_t itype=0; itype<2; itype++) {
936 if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
937 else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
940 TTree*
tree = (itype==0) ? treeS : treeB;
941 for (
Int_t i=0; i<
N; i++) {
943 if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
944 getGaussRnd( *
v, *
m,
R );
946 for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
947 for (
Int_t ivar=0; ivar<nvar; ivar++) {
948 if (ivar<2) xvarD[ivar] = xvar[ivar];
949 else xvarF[ivar] = xvar[ivar];
964 cout <<
"created data file: " << dataFile->
GetName() << endl;
970void create_lin_Nvar_discrete()
973 const Int_t nvar = 4;
981 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
982 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
983 for (
Int_t ivar=0; ivar<nvar-2; ivar++) {
987 for (
Int_t ivar=0; ivar<2; ivar++) {
993 Float_t xS[nvar] = { 0.2, 0.3, 1, 2 };
994 Float_t xB[nvar] = { -0.2, -0.3, 0, 0 };
995 Float_t dx[nvar] = { 1.0, 1.0, 1, 2 };
1005 for (
int i=0; i<20; i++) rho[i] = 0;
1010 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1011 (*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
1012 (*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
1013 for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
1014 (*covMatS)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
1015 (*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
1017 (*covMatB)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
1018 (*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
1021 cout <<
"signal covariance matrix: " << endl;
1023 cout <<
"background covariance matrix: " << endl;
1027 TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
1028 TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
1031 for (
Int_t itype=0; itype<2; itype++) {
1035 if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
1036 else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
1039 TTree*
tree = (itype==0) ? treeS : treeB;
1040 for (
Int_t i=0; i<
N; i++) {
1042 if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
1043 getGaussRnd( *
v, *
m,
R );
1045 for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
1062 cout <<
"created data file: " << dataFile->
GetName() << endl;
1068void create_ManyVars()
1071 const Int_t nvar = 20;
1078 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
1079 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
1080 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1088 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1089 xS[ivar] = 0 + ivar*0.05;
1090 xB[ivar] = 0 - ivar*0.05;
1118 for (
Int_t itype=0; itype<2; itype++) {
1120 Float_t*
x = (itype == 0) ? xS : xB;
1123 TTree*
tree = (itype == 0) ? treeS : treeB;
1124 for (
Int_t i=0; i<
N; i++) {
1126 if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
1127 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1128 if (ivar == 1500 && itype!=10) xvar[ivar] = 1;
1129 else xvar[ivar] =
x[ivar] +
R.Gaus()*dx[ivar];
1145 cout <<
"created data file: " << dataFile->
GetName() << endl;
1149void create_lin_NvarObsolete()
1152 const Int_t nvar = 20;
1159 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
1160 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
1161 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1167 Float_t xS[nvar] = { 0.5, 0.5, 0.0, 0.0, 0.0, 0.0 };
1168 Float_t xB[nvar] = { -0.5, -0.5, -0.0, -0.0, -0.0, -0.0 };
1169 Float_t dx[nvar] = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
1172 for (
Int_t i=0; i<50; i++) rho[i] = 0;
1183 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1184 (*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
1185 (*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
1186 for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
1187 (*covMatS)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
1188 (*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
1190 (*covMatB)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
1191 (*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
1194 cout <<
"signal covariance matrix: " << endl;
1196 cout <<
"background covariance matrix: " << endl;
1200 TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
1201 TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
1204 for (
Int_t itype=0; itype<2; itype++) {
1208 if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
1209 else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
1212 TTree*
tree = (itype==0) ? treeS : treeB;
1213 for (
Int_t i=0; i<
N; i++) {
1215 if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
1216 getGaussRnd( *
v, *
m,
R );
1218 for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
1232 cout <<
"created data file: " << dataFile->
GetName() << endl;
1238void create_lin(
Int_t N = 2000)
1240 const Int_t nvar = 2;
1248 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
1249 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
1250 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1254 treeS->
Branch(
"weight", &weight,
"weight/F" );
1255 treeB->
Branch(
"weight", &weight,
"weight/F" );
1258 Float_t xS[nvar] = { 0.0, 0.0 };
1259 Float_t xB[nvar] = { -0.0, -0.0 };
1260 Float_t dx[nvar] = { 1.0, 1.0 };
1268 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1269 (*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
1270 (*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
1271 for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
1272 (*covMatS)(ivar,jvar) = rhoS*dx[ivar]*dx[jvar];
1273 (*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
1275 (*covMatB)(ivar,jvar) = rhoB*dx[ivar]*dx[jvar];
1276 (*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
1279 cout <<
"signal covariance matrix: " << endl;
1281 cout <<
"background covariance matrix: " << endl;
1285 TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
1286 TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
1289 for (
Int_t itype=0; itype<2; itype++) {
1293 if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
1294 else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
1297 TTree*
tree = (itype==0) ? treeS : treeB;
1298 for (
Int_t i=0; i<
N; i++) {
1300 if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
1301 getGaussRnd( *
v, *
m,
R );
1302 for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
1305 if (itype == 0) weight = 1.0;
1320 cout <<
"created data file: " << dataFile->
GetName() << endl;
1327void create_fullcirc(
Int_t nmax = 20000,
Bool_t distort=
false)
1331 int nsig = 0, nbgd=0;
1335 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
1336 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
1337 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1341 treeS->
Branch(
"weight", &weight,
"weight/F");
1342 treeB->
Branch(
"weight", &weight,
"weight/F");
1346 for (
Int_t ivar=0; ivar<nvar; ivar++) { xvar[ivar]=2.*
R.Rndm()-1.;}
1347 Float_t xout = xvar[0]*xvar[0]+xvar[1]*xvar[1];
1348 if (nsig<10) cout <<
"xout = " << xout<<endl;
1349 if (xout < 0.3 || (xout >0.3 && xout<0.5 &&
R.Rndm() > xout)) {
1350 if (distort && xvar[0] < 0 &&
R.Rndm()>0.1)
continue;
1355 if (distort && xvar[0] > 0 &&
R.Rndm()>0.1)
continue;
1359 }
while ( nsig < nmax || nbgd < nmax);
1367void create_circ(
Int_t N = 6000,
Bool_t distort =
false)
1370 const Int_t nvar = 2;
1377 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
1378 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
1379 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1393 Float_t phimin = -70, phimax = 130;
1398 Float_t fnmin = -(rS+4.0*rsig);
1399 Float_t fnmax = +(rS+4.0*rsig);
1402 for (
Int_t itype=0; itype<2; itype++) {
1405 TTree*
tree = (itype==0) ? treeS : treeB;
1406 for (
Int_t i=0; i<
N; i++) {
1408 if (itype==0) r3= r1>r2? r1 :r2;
1411 if (distort) phi = r3*(phimax - phimin) + phimin;
1412 else phi =
R.Rndm()*(phimax - phimin) + phimin;
1413 phi +=
R.Gaus()*phisig;
1424 for (
Int_t i=0; i<Nn; i++) {
1426 xvar[0] = dfn*
R.Rndm()+fnmin;
1427 xvar[1] = dfn*
R.Rndm()+fnmin;
1441 cout <<
"created data file: " << dataFile->
GetName() << endl;
1447void create_schachbrett(
Int_t nEvents = 20000) {
1449 const Int_t nvar = 2;
1456 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
1457 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
1458 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1463 Int_t nSeed = 12345;
1468 Int_t xtype=1, ytype=1;
1472 while (iev < nEvents){
1474 for (
Int_t i=-m_nDim; i <= m_nDim; i++){
1476 for (
Int_t j=-m_nDim; j <= m_nDim; j++){
1500 cout <<
"created data file: " << dataFile->
GetName() << endl;
1507void create_schachbrett_5D(
Int_t nEvents = 200000) {
1508 const Int_t nvar = 5;
1515 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
1516 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
1517 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1522 Int_t nSeed = 12345;
1531 while (iev < nEvents){
1533 for (idx[0]=-m_nDim; idx[0] <= m_nDim; idx[0]++){
1535 for (idx[1]=-m_nDim; idx[1] <= m_nDim; idx[1]++){
1537 for (idx[2]=-m_nDim; idx[2] <= m_nDim; idx[2]++){
1539 for (idx[3]=-m_nDim; idx[3] <= m_nDim; idx[3]++){
1541 for (idx[4]=-m_nDim; idx[4] <= m_nDim; idx[4]++){
1543 for (
Int_t i=0;i<nvar;i++){
1545 if (i>0)
type *= itype[i];
1570 cout <<
"created data file: " << dataFile->
GetName() << endl;
1577void create_schachbrett_4D(
Int_t nEvents = 200000) {
1579 const Int_t nvar = 4;
1586 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
1587 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
1588 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1593 Int_t nSeed = 12345;
1602 while (iev < nEvents){
1604 for (idx[0]=-m_nDim; idx[0] <= m_nDim; idx[0]++){
1606 for (idx[1]=-m_nDim; idx[1] <= m_nDim; idx[1]++){
1608 for (idx[2]=-m_nDim; idx[2] <= m_nDim; idx[2]++){
1610 for (idx[3]=-m_nDim; idx[3] <= m_nDim; idx[3]++){
1612 for (
Int_t i=0;i<nvar;i++){
1614 if (i>0)
type *= itype[i];
1637 cout <<
"created data file: " << dataFile->
GetName() << endl;
1644void create_schachbrett_3D(
Int_t nEvents = 20000) {
1646 const Int_t nvar = 3;
1653 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
1654 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
1655 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1660 Int_t nSeed = 12345;
1669 while (iev < nEvents){
1671 for (idx[0]=-m_nDim; idx[0] <= m_nDim; idx[0]++){
1673 for (idx[1]=-m_nDim; idx[1] <= m_nDim; idx[1]++){
1675 for (idx[2]=-m_nDim; idx[2] <= m_nDim; idx[2]++){
1677 for (
Int_t i=0;i<nvar;i++){
1679 if (i>0)
type *= itype[i];
1700 cout <<
"created data file: " << dataFile->
GetName() << endl;
1707void create_schachbrett_2D(
Int_t nEvents = 100000,
Int_t nbumps=2) {
1709 const Int_t nvar = 2;
1716 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
1717 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
1718 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1728 Int_t m_nDim = nbumps;
1732 while (iev < nEvents){
1734 for (idx[0]=-m_nDim; idx[0] <= m_nDim; idx[0]++){
1736 for (idx[1]=-m_nDim; idx[1] <= m_nDim; idx[1]++){
1738 for (
Int_t i=0;i<nvar;i++){
1740 if (i>0)
type *= itype[i];
1759 cout <<
"created data file: " << dataFile->
GetName() << endl;
1767void create_3Bumps(
Int_t nEvents = 5000) {
1773 const Int_t nvar = 2;
1777 TString filename =
"data_3Bumps.root";
1781 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
1782 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
1783 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1788 Int_t nSeed = 12345;
1793 Double_t Centers[nvar][6] = {{-1,0,0,0,1,1},{0,0,0,0,0,0}};
1796 while (iev < nEvents){
1797 for (
int idx=0; idx<6; idx++){
1798 if (idx==1 || idx==2 || idx==3)
type = 0;
1800 for (
Int_t ivar=0;ivar<nvar;ivar++){
1801 xvar[ivar]=m_rand->
Gaus(Centers[ivar][idx],
sigma);
1817 cout <<
"created data file: " << dataFile->
GetName() << endl;
1823void createOnionData(
Int_t nmax = 50000){
1827 int nsig = 0, nbgd=0;
1830 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
1831 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
1832 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1839 for (
Int_t ivar=0; ivar<nvar; ivar++) { xvar[ivar]=
R.Rndm();}
1840 Float_t xout =
sin(2.*
acos(-1.)*(xvar[0]*xvar[1]*xvar[2]*xvar[3]+xvar[0]*xvar[1]));
1841 if (nsig<100) cout <<
"xout = " << xout<<endl;
1843 if (i%2 == 0 && nsig < nmax) {
1847 if (i%2 != 0 && nbgd < nmax){
1851 }
while ( nsig < nmax || nbgd < nmax);
1857void create_multiclassdata(
Int_t nmax = 20000)
1868 { 0. , 0.3, 0.5, 0.9 },
1869 { -0.2 , -0.3, 0.5, 0.4 },
1870 { 0.2 , 0.1, -0.1, 0.7 }} ;
1874 TTree* treeR =
new TTree(
"TreeR",
"TreeR", 1 );
1875 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1878 for (
Int_t icls=0; icls<ncls; icls++) {
1882 treeR->
Branch(
"cls", &thecls,
"cls/F");
1883 treeR->
Branch(
"weight", &weight,
"weight/F");
1887 for (
Int_t icls=0; icls<ncls; icls++) xcls[icls]=0.;
1888 cls =
R.Integer(ncls);
1891 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1892 xvar[ivar]=
R.Gaus(xmean[cls][ivar],1.);
1895 if (ndat<30) cout <<
"cls=" << cls <<
" xvar = " << xvar[0]<<
" " <<xvar[1]<<
" " << xvar[2]<<
" " <<xvar[3]<<endl;
1899 }
while ( ndat < nmax );
1912void create_array_with_different_lengths(
Int_t N = 100)
1914 const Int_t nvar = 4;
1915 Int_t nvarCurrent = 4;
1922 TTree* treeS =
new TTree(
"TreeS",
"TreeS", 1 );
1923 TTree* treeB =
new TTree(
"TreeB",
"TreeB", 1 );
1924 treeS->
Branch(
"arrSize", &nvarCurrent,
"arrSize/I" );
1925 treeS->
Branch(
"arr", xvar,
"arr[arrSize]/F" );
1926 treeB->
Branch(
"arrSize", &nvarCurrent,
"arrSize/I" );
1927 treeB->
Branch(
"arr", xvar,
"arr[arrSize]/F" );
1930 Float_t xS[nvar] = { 0.2, 0.3, 0.5, 0.9 };
1931 Float_t xB[nvar] = { -0.2, -0.3, -0.5, -0.6 };
1932 Float_t dx[nvar] = { 1.0, 1.0, 1.0, 1.0 };
1945 for (
Int_t ivar=0; ivar<nvar; ivar++) {
1946 (*covMatS)(ivar,ivar) = dx[ivar]*dx[ivar];
1947 (*covMatB)(ivar,ivar) = dx[ivar]*dx[ivar];
1948 for (
Int_t jvar=ivar+1; jvar<nvar; jvar++) {
1949 (*covMatS)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
1950 (*covMatS)(jvar,ivar) = (*covMatS)(ivar,jvar);
1952 (*covMatB)(ivar,jvar) = rho[(ivar+1)*(jvar+1)]*dx[ivar]*dx[jvar];
1953 (*covMatB)(jvar,ivar) = (*covMatB)(ivar,jvar);
1956 cout <<
"signal covariance matrix: " << endl;
1958 cout <<
"background covariance matrix: " << endl;
1962 TMatrixD* sqrtMatS = produceSqrtMat( *covMatS );
1963 TMatrixD* sqrtMatB = produceSqrtMat( *covMatB );
1966 for (
Int_t itype=0; itype<2; itype++) {
1970 if (itype == 0) {
x = xS;
m = sqrtMatS; cout <<
"- produce signal" << endl; }
1971 else {
x = xB;
m = sqrtMatB; cout <<
"- produce background" << endl; }
1974 TTree*
tree = (itype==0) ? treeS : treeB;
1975 for (
Int_t i=0; i<
N; i++) {
1977 if (i%1000 == 0) cout <<
"... event: " << i <<
" (" <<
N <<
")" << endl;
1978 getGaussRnd( *
v, *
m,
R );
1980 for (
Int_t ivar=0; ivar<nvar; ivar++) xvar[ivar] = (*
v)[ivar] +
x[ivar];
1983 nvarCurrent = (i%4)+1;
1997 cout <<
"created data file: " << dataFile->
GetName() << endl;
2003void create_MultipleBackground(
Int_t N = 50000)
2008 TFile* dataFile =
TFile::Open(
"tmva_example_multiple_background.root",
"RECREATE" );
2011 Float_t xS[nvar] = { 0.2, 0.3, 0.5, 0.9 };
2012 Float_t xB0[nvar] = { -0.2, -0.3, -0.5, -0.6 };
2013 Float_t xB1[nvar] = { -0.2, 0.3, 0.5, -0.6 };
2014 Float_t dx0[nvar] = { 1.0, 1.0, 1.0, 1.0 };
2015 Float_t dx1[nvar] = { -1.0, -1.0, -1.0, -1.0 };
2018 TTree* treeS = makeTree_lin_Nvar(
"TreeS",
"Signal tree", xS, dx0, nvar,
N );
2019 TTree* treeB0 = makeTree_lin_Nvar(
"TreeB0",
"Background 0", xB0, dx0, nvar,
N );
2020 TTree* treeB1 = makeTree_lin_Nvar(
"TreeB1",
"Background 1", xB1, dx1, nvar,
N );
2021 TTree* treeB2 = makeTree_circ(
"TreeB2",
"Background 2", nvar,
N, 1.5,
true);
2034 cout <<
"created data file: " << dataFile->
GetName() << endl;
#define R(a, b, c, d, e, f, g, h, i)
TMatrixT< Double_t > TMatrixD
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
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.
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
virtual void Close(Option_t *option="")
Close a file.
virtual Int_t Write(const char *name=0, Int_t opt=0, Int_t bufsiz=0)
Write memory objects to this file.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose, Int_t netopt=0)
Create / open a file.
1-D histogram with a float per channel (see TH1 documentation)}
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
virtual void SetTitleSize(Float_t size=0.02, Option_t *axis="X")
Set the axis' title size.
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
virtual void Draw(Option_t *option="")
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.
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
void SetMargin(Float_t margin)
void Print(Option_t *name="") const
Print the matrix as a table of elements.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
virtual const char * GetName() const
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...
virtual Double_t Rndm()
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 Double_t GetMaximum(const char *columname)
Return maximum of column with name columname.
virtual Long64_t GetEntries() const
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
virtual Double_t GetMinimum(const char *columname)
Return minimum of column with name columname.
virtual void Draw(Option_t *opt)
Default Draw method for all objects.
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.
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Double_t Gaus(Double_t x, Double_t mean=0, Double_t sigma=1, Bool_t norm=kFALSE)
Calculate 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)
constexpr Double_t DegToRad()
Conversion from degree to radian:
Double_t Sqrt(Double_t x)
Short_t Min(Short_t a, Short_t b)
static long int sum(long int i)