{
"cells": [
{
"cell_type": "markdown",
"id": "b8480e9c",
"metadata": {},
"source": [
"# testUnfold7a\n",
"Test program for the classes TUnfoldDensity and TUnfoldBinning.\n",
"\n",
"A toy test of the TUnfold package\n",
"\n",
"This example is documented in conference proceedings:\n",
"\n",
" arXiv:1611.01927\n",
" 12th Conference on Quark Confinement and the Hadron Spectrum (Confinement XII)\n",
"\n",
"This is an example of unfolding a two-dimensional distribution\n",
"also using an auxiliary measurement to constrain some background\n",
"\n",
"The example comprises several macros\n",
" - testUnfold7a.C create root files with TTree objects for\n",
" signal, background and data\n",
" - write files testUnfold7_signal.root\n",
" testUnfold7_background.root\n",
" testUnfold7_data.root\n",
"\n",
" - testUnfold7b.C loop over trees and fill histograms based on the\n",
" TUnfoldBinning objects\n",
" - read testUnfold7binning.xml\n",
" testUnfold7_signal.root\n",
" testUnfold7_background.root\n",
" testUnfold7_data.root\n",
"\n",
" - write testUnfold7_histograms.root\n",
"\n",
" - testUnfold7c.C run the unfolding\n",
" - read testUnfold7_histograms.root\n",
" - write testUnfold7_result.root\n",
" testUnfold7_result.ps\n",
"\n",
"\n",
" **Version 17.6, in parallel to changes in TUnfold**\n",
"\n",
" This file is part of TUnfold.\n",
"\n",
" TUnfold is free software: you can redistribute it and/or modify\n",
" it under the terms of the GNU General Public License as published by\n",
" the Free Software Foundation, either version 3 of the License, or\n",
" (at your option) any later version.\n",
"\n",
" TUnfold is distributed in the hope that it will be useful,\n",
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n",
" GNU General Public License for more details.\n",
"\n",
" You should have received a copy of the GNU General Public License\n",
" along with TUnfold. If not, see .\n",
"\n",
"\n",
"\n",
"**Author:** Stefan Schmitt DESY, 14.10.2008 \n",
"This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, March 19, 2024 at 07:22 PM."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "545d911c",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:22:11.152385Z",
"iopub.status.busy": "2024-03-19T19:22:11.151969Z",
"iopub.status.idle": "2024-03-19T19:22:11.276387Z",
"shell.execute_reply": "2024-03-19T19:22:11.265762Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"\n",
"#include \n",
"#include \n",
"#include \n",
"#include \n",
"#include \n",
"#include \n",
"#include \n",
"\n",
"#define MASS1 0.511E-3\n",
"\n",
"using std::cout;\n",
"\n",
"TRandom *g_rnd=nullptr;\n",
"\n",
"class ToyEvent7 {\n",
"public:\n",
" void GenerateDataEvent(TRandom *rnd);\n",
" void GenerateSignalEvent(TRandom *rnd);\n",
" void GenerateBgrEvent(TRandom *rnd);\n",
" // reconstructed quantities\n",
" inline Double_t GetMRec(int i) const { return fMRec[i]; }\n",
" inline Double_t GetPtRec(int i) const { return fPtRec[i]; }\n",
" inline Double_t GetEtaRec(int i) const { return fEtaRec[i]; }\n",
" inline Double_t GetDiscriminator(void) const {return fDiscriminator; }\n",
" inline Double_t GetPhiRec(int i) const { return fPhiRec[i]; }\n",
" inline Bool_t IsTriggered(void) const { return fIsTriggered; }\n",
"\n",
" // generator level quantities\n",
" inline Double_t GetMGen(int i) const {\n",
" if(IsSignal()) return fMGen[i];\n",
" else return -1.0;\n",
" }\n",
" inline Double_t GetPtGen(int i) const {\n",
" if(IsSignal()) return fPtGen[i];\n",
" else return -1.0;\n",
" }\n",
" inline Double_t GetEtaGen(int i) const {\n",
" if(IsSignal()) return fEtaGen[i];\n",
" else return 999.0;\n",
" }\n",
" inline Double_t GetPhiGen(int i) const {\n",
" if(IsSignal()) return fPhiGen[i];\n",
" else return 999.0;\n",
" }\n",
" inline Bool_t IsSignal(void) const { return fIsSignal; }\n",
"protected:\n",
"\n",
" void GenerateSignalKinematics(TRandom *rnd,Bool_t isData);\n",
" void GenerateBgrKinematics(TRandom *rnd,Bool_t isData);\n",
" void GenerateReco(TRandom *rnd);\n",
"\n",
" // reconstructed quantities\n",
" Double_t fMRec[3];\n",
" Double_t fPtRec[3];\n",
" Double_t fEtaRec[3];\n",
" Double_t fPhiRec[3];\n",
" Double_t fDiscriminator;\n",
" Bool_t fIsTriggered;\n",
" // generated quantities\n",
" Double_t fMGen[3];\n",
" Double_t fPtGen[3];\n",
" Double_t fEtaGen[3];\n",
" Double_t fPhiGen[3];\n",
" Bool_t fIsSignal;\n",
"public:\n",
" static Double_t kDataSignalFraction;\n",
" static Double_t kMCSignalFraction;\n",
"\n",
"};\n",
"Double_t ToyEvent7::kDataSignalFraction=0.75;\n",
"Double_t ToyEvent7::kMCSignalFraction=0.75;"
]
},
{
"cell_type": "markdown",
"id": "0ef737b4",
"metadata": {},
"source": [
" Definition of a helper function: "
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "aa0da649",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:22:11.293501Z",
"iopub.status.busy": "2024-03-19T19:22:11.293117Z",
"iopub.status.idle": "2024-03-19T19:22:11.309021Z",
"shell.execute_reply": "2024-03-19T19:22:11.306667Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"void ToyEvent7::GenerateDataEvent(TRandom *rnd) {\n",
" fIsSignal=rnd->Uniform()BreitWigner(M0,Gamma);\n",
" } while(fMGen[2]<=0.0);\n",
"\n",
" double N_ETA=3.0;\n",
" double MU_PT=5.;\n",
" double SIGMA_PT=2.0;\n",
" double DECAY_A=0.2;\n",
" if(isData) {\n",
" //N_ETA=2.5;\n",
" MU_PT=6.;\n",
" SIGMA_PT=1.8;\n",
" //DECAY_A=0.5;\n",
" }\n",
" fEtaGen[2]=TMath::Power(rnd->Uniform(0,1.5),N_ETA);\n",
" if(rnd->Uniform(-1.,1.)<0.) fEtaGen[2] *= -1.;\n",
" fPhiGen[2]=rnd->Uniform(-M_PI,M_PI);\n",
" do {\n",
" fPtGen[2]=rnd->Landau(MU_PT,SIGMA_PT);\n",
" } while((fPtGen[2]<=0.0)||(fPtGen[2]>500.));\n",
" //========================== decay\n",
" TLorentzVector sum;\n",
" sum.SetPtEtaPhiM(fPtGen[2],fEtaGen[2],fPhiGen[2],fMGen[2]);\n",
" // boost into lab-frame\n",
" TVector3 boost=sum.BoostVector();\n",
" // decay in rest-frame\n",
"\n",
" TLorentzVector p[3];\n",
" double m=MASS1;\n",
" double costh;\n",
" do {\n",
" double r=rnd->Uniform(-1.,1.);\n",
" costh=r*(1.+DECAY_A*r*r);\n",
" } while(fabs(costh)>=1.0);\n",
" double phi=rnd->Uniform(-M_PI,M_PI);\n",
" double e=0.5*sum.M();\n",
" double ptot=TMath::Sqrt(e+m)*TMath::Sqrt(e-m);\n",
" double pz=ptot*costh;\n",
" double pt=TMath::Sqrt(ptot+pz)*TMath::Sqrt(ptot-pz);\n",
" double px=pt*cos(phi);\n",
" double py=pt*sin(phi);\n",
" p[0].SetXYZT(px,py,pz,e);\n",
" p[1].SetXYZT(-px,-py,-pz,e);\n",
" for(int i=0;i<2;i++) {\n",
" p[i].Boost(boost);\n",
" }\n",
" p[2]=p[0]+p[1];\n",
" for(int i=0;i<3;i++) {\n",
" fPtGen[i]=p[i].Pt();\n",
" fEtaGen[i]=p[i].Eta();\n",
" fPhiGen[i]=p[i].Phi();\n",
" fMGen[i]=p[i].M();\n",
" }\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "23f333c0",
"metadata": {},
"source": [
" Definition of a helper function: "
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "a03ae731",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:22:11.465669Z",
"iopub.status.busy": "2024-03-19T19:22:11.465306Z",
"iopub.status.idle": "2024-03-19T19:22:11.491395Z",
"shell.execute_reply": "2024-03-19T19:22:11.490147Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"void ToyEvent7::GenerateBgrKinematics(TRandom *rnd,Bool_t isData) {\n",
" for(int i=0;i<3;i++) {\n",
" fPtGen[i]=0.0;\n",
" fEtaGen[i]=0.0;\n",
" fPhiGen[i]=0.0;\n",
" }\n",
" TLorentzVector p[3];\n",
" for(int i=0;i<2;i++) {\n",
" p[i].SetPtEtaPhiM(rnd->Exp(15.0),rnd->Uniform(-3.,3.),\n",
" rnd->Uniform(-M_PI,M_PI),isData ? MASS1 : MASS1);\n",
" }\n",
" p[2]=p[0]+p[1];\n",
" for(int i=0;i<3;i++) {\n",
" fPtRec[i]=p[i].Pt();\n",
" fEtaRec[i]=p[i].Eta();\n",
" fPhiRec[i]=p[i].Phi();\n",
" fMRec[i]=p[i].M();\n",
" }\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "422f3fd6",
"metadata": {},
"source": [
" Definition of a helper function: "
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "2370dcb9",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:22:11.499782Z",
"iopub.status.busy": "2024-03-19T19:22:11.499421Z",
"iopub.status.idle": "2024-03-19T19:22:11.528952Z",
"shell.execute_reply": "2024-03-19T19:22:11.527889Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"void ToyEvent7::GenerateReco(TRandom *rnd) {\n",
" if(fIsSignal) {\n",
" TLorentzVector p[3];\n",
" for(int i=0;i<2;i++) {\n",
" Double_t expEta=TMath::Exp(fEtaGen[i]);\n",
" Double_t coshEta=(expEta+1./expEta);\n",
" Double_t eGen=fPtGen[i]*coshEta;\n",
" Double_t sigmaE=\n",
" 0.1*TMath::Sqrt(eGen)\n",
" +1.0*coshEta\n",
" +0.01*eGen;\n",
" Double_t eRec;\n",
" do {\n",
" eRec=rnd->Gaus(eGen,sigmaE);\n",
" } while(eRec<=0.0);\n",
" Double_t sigmaEta=0.1+0.02*TMath::Abs(fEtaGen[i]);\n",
" p[i].SetPtEtaPhiM(eRec/(expEta+1./expEta),\n",
" rnd->Gaus(fEtaGen[i],sigmaEta),\n",
" remainder(rnd->Gaus(fPhiGen[i],0.03),2.*M_PI),\n",
" MASS1);\n",
" }\n",
" p[2]=p[0]+p[1];\n",
" for(int i=0;i<3;i++) {\n",
" fPtRec[i]=p[i].Pt();\n",
" fEtaRec[i]=p[i].Eta();\n",
" fPhiRec[i]=p[i].Phi();\n",
" fMRec[i]=p[i].M();\n",
" }\n",
" }\n",
" if(fIsSignal) {\n",
" do {\n",
" Double_t tauDiscr=0.08-0.04/(1.+fPtRec[2]/10.0);\n",
" Double_t sigmaDiscr=0.01;\n",
" fDiscriminator=1.0-rnd->Exp(tauDiscr)+rnd->Gaus(0.,sigmaDiscr);\n",
" } while((fDiscriminator<=0.)||(fDiscriminator>=1.));\n",
" } else {\n",
" do {\n",
" Double_t tauDiscr=0.15-0.05/(1.+fPtRec[2]/5.0)+0.1*fEtaRec[2];\n",
" Double_t sigmaDiscr=0.02+0.01*fEtaRec[2];\n",
" fDiscriminator=rnd->Exp(tauDiscr)+rnd->Gaus(0.,sigmaDiscr);\n",
" } while((fDiscriminator<=0.)||(fDiscriminator>=1.));\n",
" }\n",
" fIsTriggered=false;\n",
" for(int i=0;i<2;i++) {\n",
" if(rnd->Uniform()<0.92/(TMath::Exp(-(fPtRec[i]-15.5)/2.5)+1.)) fIsTriggered=true;\n",
" }\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "db7b3136",
"metadata": {},
"source": [
"random generator"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "ba74dc65",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:22:11.536009Z",
"iopub.status.busy": "2024-03-19T19:22:11.535641Z",
"iopub.status.idle": "2024-03-19T19:22:12.195750Z",
"shell.execute_reply": "2024-03-19T19:22:12.194446Z"
}
},
"outputs": [],
"source": [
"g_rnd=new TRandom3(4711);"
]
},
{
"cell_type": "markdown",
"id": "f9be05a6",
"metadata": {},
"source": [
"data and MC number of events"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "3b98e024",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:22:12.201156Z",
"iopub.status.busy": "2024-03-19T19:22:12.200770Z",
"iopub.status.idle": "2024-03-19T19:22:12.420405Z",
"shell.execute_reply": "2024-03-19T19:22:12.419358Z"
}
},
"outputs": [],
"source": [
"Double_t muData0=5000.;"
]
},
{
"cell_type": "markdown",
"id": "9dbc3f4f",
"metadata": {},
"source": [
"luminosity error"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "4c5a3c39",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:22:12.425145Z",
"iopub.status.busy": "2024-03-19T19:22:12.424784Z",
"iopub.status.idle": "2024-03-19T19:22:12.645760Z",
"shell.execute_reply": "2024-03-19T19:22:12.644381Z"
}
},
"outputs": [],
"source": [
"Double_t muData=muData0*g_rnd->Gaus(1.0,0.03);"
]
},
{
"cell_type": "markdown",
"id": "1a6a1ced",
"metadata": {},
"source": [
"stat error"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "f3dd25de",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:22:12.650535Z",
"iopub.status.busy": "2024-03-19T19:22:12.650152Z",
"iopub.status.idle": "2024-03-19T19:22:12.871493Z",
"shell.execute_reply": "2024-03-19T19:22:12.870262Z"
}
},
"outputs": [],
"source": [
"Int_t neventData = g_rnd->Poisson( muData);"
]
},
{
"cell_type": "markdown",
"id": "8a829716",
"metadata": {},
"source": [
"generated number of MC events"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "4fb57cea",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:22:12.876524Z",
"iopub.status.busy": "2024-03-19T19:22:12.876172Z",
"iopub.status.idle": "2024-03-19T19:22:13.098829Z",
"shell.execute_reply": "2024-03-19T19:22:13.096938Z"
}
},
"outputs": [],
"source": [
"Int_t neventSigmc = 250000;\n",
"Int_t neventBgrmc = 100000;\n",
"\n",
"Float_t etaRec[3],ptRec[3],phiRec[3],mRec[3],discr;\n",
"Float_t etaGen[3],ptGen[3],phiGen[3],mGen[3];\n",
"Float_t weight;\n",
"Int_t istriggered,issignal;"
]
},
{
"cell_type": "markdown",
"id": "943d5f68",
"metadata": {},
"source": [
"==================================================================\n",
"Step 1: generate data TTree"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "6d6a04a6",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:22:13.106459Z",
"iopub.status.busy": "2024-03-19T19:22:13.106045Z",
"iopub.status.idle": "2024-03-19T19:22:13.317200Z",
"shell.execute_reply": "2024-03-19T19:22:13.316068Z"
}
},
"outputs": [],
"source": [
"TFile *dataFile=new TFile(\"testUnfold7_data.root\",\"recreate\");\n",
"TTree *dataTree=new TTree(\"data\",\"event\");\n",
"\n",
"dataTree->Branch(\"etarec\",etaRec,\"etarec[3]/F\");\n",
"dataTree->Branch(\"ptrec\",ptRec,\"ptrec[3]/F\");\n",
"dataTree->Branch(\"phirec\",phiRec,\"phirec[3]/F\");\n",
"dataTree->Branch(\"mrec\",mRec,\"mrec[3]/F\");\n",
"dataTree->Branch(\"discr\",&discr,\"discr/F\");"
]
},
{
"cell_type": "markdown",
"id": "3ca83a61",
"metadata": {},
"source": [
"for real data, only the triggered events are available"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "f280a49e",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:22:13.323201Z",
"iopub.status.busy": "2024-03-19T19:22:13.322680Z",
"iopub.status.idle": "2024-03-19T19:22:13.529484Z",
"shell.execute_reply": "2024-03-19T19:22:13.528263Z"
}
},
"outputs": [],
"source": [
"dataTree->Branch(\"istriggered\",&istriggered,\"istriggered/I\");"
]
},
{
"cell_type": "markdown",
"id": "65c0fd15",
"metadata": {},
"source": [
"data truth parameters"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "332a83d9",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:22:13.534587Z",
"iopub.status.busy": "2024-03-19T19:22:13.534186Z",
"iopub.status.idle": "2024-03-19T19:22:13.746732Z",
"shell.execute_reply": "2024-03-19T19:22:13.745837Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"fill data tree\n"
]
}
],
"source": [
"dataTree->Branch(\"etagen\",etaGen,\"etagen[3]/F\");\n",
"dataTree->Branch(\"ptgen\",ptGen,\"ptgen[3]/F\");\n",
"dataTree->Branch(\"phigen\",phiGen,\"phigen[3]/F\");\n",
"dataTree->Branch(\"mgen\",mGen,\"mgen[3]/F\");\n",
"dataTree->Branch(\"issignal\",&issignal,\"issignal/I\");\n",
"\n",
"cout<<\"fill data tree\\n\";"
]
},
{
"cell_type": "markdown",
"id": "6b80e1a5",
"metadata": {},
"source": [
"Int_t nEvent=0,nTriggered=0;"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "96864b53",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:22:13.750870Z",
"iopub.status.busy": "2024-03-19T19:22:13.750570Z",
"iopub.status.idle": "2024-03-19T19:22:14.269225Z",
"shell.execute_reply": "2024-03-19T19:22:14.268239Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" data event 0\n"
]
}
],
"source": [
"for(int ievent=0;ieventFill();\n",
"\n",
" if(!(ievent%100000)) cout<<\" data event \"<Write();\n",
"delete dataTree;\n",
"delete dataFile;"
]
},
{
"cell_type": "markdown",
"id": "9c746797",
"metadata": {},
"source": [
"==================================================================\n",
"Step 2: generate signal TTree"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "0f331287",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:22:14.273844Z",
"iopub.status.busy": "2024-03-19T19:22:14.273514Z",
"iopub.status.idle": "2024-03-19T19:22:14.477738Z",
"shell.execute_reply": "2024-03-19T19:22:14.476700Z"
}
},
"outputs": [],
"source": [
"TFile *signalFile=new TFile(\"testUnfold7_signal.root\",\"recreate\");\n",
"TTree *signalTree=new TTree(\"signal\",\"event\");\n",
"\n",
"signalTree->Branch(\"etarec\",etaRec,\"etarec[3]/F\");\n",
"signalTree->Branch(\"ptrec\",ptRec,\"ptrec[3]/F\");\n",
"signalTree->Branch(\"phirec\",ptRec,\"phirec[3]/F\");\n",
"signalTree->Branch(\"mrec\",mRec,\"mrec[3]/F\");\n",
"signalTree->Branch(\"discr\",&discr,\"discr/F\");"
]
},
{
"cell_type": "markdown",
"id": "25fe4521",
"metadata": {},
"source": [
"for real data, only the triggered events are available"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "9a63c593",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:22:14.482788Z",
"iopub.status.busy": "2024-03-19T19:22:14.482443Z",
"iopub.status.idle": "2024-03-19T19:22:14.700404Z",
"shell.execute_reply": "2024-03-19T19:22:14.699120Z"
}
},
"outputs": [],
"source": [
"signalTree->Branch(\"istriggered\",&istriggered,\"istriggered/I\");"
]
},
{
"cell_type": "markdown",
"id": "782c9d25",
"metadata": {},
"source": [
"data truth parameters"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "79b6dbdb",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:22:14.714573Z",
"iopub.status.busy": "2024-03-19T19:22:14.714188Z",
"iopub.status.idle": "2024-03-19T19:22:16.831789Z",
"shell.execute_reply": "2024-03-19T19:22:16.828371Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"fill signal tree\n",
" signal event 0\n",
" signal event 100000\n",
" signal event 200000\n"
]
}
],
"source": [
"signalTree->Branch(\"etagen\",etaGen,\"etagen[3]/F\");\n",
"signalTree->Branch(\"ptgen\",ptGen,\"ptgen[3]/F\");\n",
"signalTree->Branch(\"phigen\",phiGen,\"phigen[3]/F\");\n",
"signalTree->Branch(\"weight\",&weight,\"weight/F\");\n",
"signalTree->Branch(\"mgen\",mGen,\"mgen[3]/F\");\n",
"\n",
"cout<<\"fill signal tree\\n\";\n",
"\n",
"weight=ToyEvent7::kMCSignalFraction*muData0/neventSigmc;\n",
"\n",
"for(int ievent=0;ieventFill();\n",
"}\n",
"\n",
"signalTree->Write();\n",
"delete signalTree;\n",
"delete signalFile;"
]
},
{
"cell_type": "markdown",
"id": "dcb872fd",
"metadata": {},
"source": [
"==============================================================\n",
"Step 3: generate background MC TTree"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "4f5ddbb3",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:22:16.837387Z",
"iopub.status.busy": "2024-03-19T19:22:16.837023Z",
"iopub.status.idle": "2024-03-19T19:22:17.738066Z",
"shell.execute_reply": "2024-03-19T19:22:17.737091Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"fill background tree\n",
" background event 0\n"
]
}
],
"source": [
"TFile *bgrFile=new TFile(\"testUnfold7_background.root\",\"recreate\");\n",
"TTree *bgrTree=new TTree(\"background\",\"event\");\n",
"\n",
"bgrTree->Branch(\"etarec\",&etaRec,\"etarec[3]/F\");\n",
"bgrTree->Branch(\"ptrec\",&ptRec,\"ptrec[3]/F\");\n",
"bgrTree->Branch(\"phirec\",&phiRec,\"phirec[3]/F\");\n",
"bgrTree->Branch(\"mrec\",&mRec,\"mrec[3]/F\");\n",
"bgrTree->Branch(\"discr\",&discr,\"discr/F\");\n",
"bgrTree->Branch(\"istriggered\",&istriggered,\"istriggered/I\");\n",
"bgrTree->Branch(\"weight\",&weight,\"weight/F\");\n",
"\n",
"cout<<\"fill background tree\\n\";\n",
"\n",
"weight=(1.-ToyEvent7::kMCSignalFraction)*muData0/neventBgrmc;\n",
"\n",
"for(int ievent=0;ieventFill();\n",
"}\n",
"\n",
"bgrTree->Write();\n",
"delete bgrTree;\n",
"delete bgrFile;"
]
},
{
"cell_type": "markdown",
"id": "d09bb970",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "a3b7c9b6",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:22:17.749039Z",
"iopub.status.busy": "2024-03-19T19:22:17.748658Z",
"iopub.status.idle": "2024-03-19T19:22:17.969963Z",
"shell.execute_reply": "2024-03-19T19:22:17.968655Z"
}
},
"outputs": [],
"source": [
"gROOT->GetListOfCanvases()->Draw()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ROOT C++",
"language": "c++",
"name": "root"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".C",
"mimetype": " text/x-c++src",
"name": "c++"
}
},
"nbformat": 4,
"nbformat_minor": 5
}