Sorry for the late reply.
I have six trees means (different decay channels line D0->Kpi, vpho->e-e+, Ks->pipi, etc.). Each and every decay channel’s information is saved in different trees. That is why they have different entries. I want to bring them in a single tree. That is why I want to write a code which can do this. But As I am filling those variables inside a single tree then entries are getting affected by this.(Actually it taking entries from other variables also that’s why mean is getting affected.)I am attaching the code which I have used. Please have a look at this and sort out the problem.
void pion()
{
TFile *f = new TFile("peter_3.root", "recreate");
TTree* nEmcPhotons = new TTree("nEmcPhotons", "EMC Photons");
float elec1;
float elec2;
float Dmeson;
float pi;
float kshorts;
float gamma;
nEmcPhotons->Branch("elec1", &elec1, "elec1/F");
nEmcPhotons->Branch("elec2", &elec2, "elec2/F");
nEmcPhotons->Branch("Dmeson", &Dmeson, "Dmeson/F");
nEmcPhotons->Branch("pi", &pi, "pi/F");
nEmcPhotons->Branch("kshorts", &kshorts, "kshorts/F");
nEmcPhotons->Branch("gamma", &gamma, "gamma/F");
TFile* f2= new TFile("lfv1.root");
//for electron
TTree* t1=(TTree*)f2->Get("vpho");
float pd1[4];
t1->SetBranchAddress("vpho_e0_P4", &pd1);
TH1F *hist1 = new TH1F("", " ", 50, 0, 10);
Int_t n_tot1 = (int)t1->GetEntries();
for (int i=0;i<100; i++)
{
t1->GetEntry(i);
TLorentzVector D0_fvec(pd1);
elec1 = D0_fvec.M();
nEmcPhotons->Fill(); //you have not added this line..
cout << "mass is that "<< elec1 <<endl;
}
//for positron
TTree* t2=(TTree*)f2->Get("vpho");
float pd2[4];
t2->SetBranchAddress("vpho_e1_P4", &pd2);
TH1F *hist2 = new TH1F("", " ", 50, 0, 10);
Int_t n_tot2 = (int)t2->GetEntries();
for (int i=0;i<100; i++)
{
t2->GetEntry(i);
TLorentzVector D0_fvec(pd2);
elec2 = D0_fvec.M();
nEmcPhotons->Fill(); //you have not added this line..
cout << "mass is that "<< elec2 <<endl;
}
// for D meson
TTree* t3=(TTree*)f2->Get("dklfv");
float pd3[4];
t3->SetBranchAddress("D0_P4", &pd3);
TH1F *hist3 = new TH1F("", " ", 50, 0, 10);
Int_t n_tot3 = (int)t3->GetEntries();
for (int i=0;i<399067; i++)
{
t3->GetEntry(i);
TLorentzVector D0_fvec(pd3);
Dmeson = D0_fvec.M();
nEmcPhotons->Fill(); //you have not added this line..
cout << "mass is that "<< Dmeson <<endl;
}
//for pion
TTree* t4=(TTree*)f2->Get("pion");
float pd4[4];
t4->SetBranchAddress("pi_P4", &pd4);
TH1F *hist4 = new TH1F("", " ", 50, 0, 10);
Int_t n_tot4 = (Int_t)t4->GetEntries();
cout<<"total entries "<< n_tot4 <<endl;
for (int j=0;j<399067; j++)
{
t4->GetEntry(j);
TLorentzVector D0_fvec1(pd4);
float fMomentum = D0_fvec1.M();
pi = D0_fvec1.M();
nEmcPhotons->Fill(); // need to add this line..
cout << " pion mass "<< pi <<endl;
}
//for kshort
TTree* t5=(TTree*)f2->Get("kshort");
float pd5[4];
t5->SetBranchAddress("K_S0_P4", &pd5);
TH1F *hist5 = new TH1F("", " ", 50, 0, 10);
Int_t n_tot5 = (Int_t)t5->GetEntries();
for (int j=0;j<399067; j++)
{
t5->GetEntry(j);
TLorentzVector D0_fvec1(pd5);
float fMomentum = D0_fvec1.M();
kshorts = D0_fvec1.M();
nEmcPhotons->Fill(); // need to add this line..
cout << " pion mass "<< kshorts <<endl;
}
//for gamma
TTree* t6=(TTree*)f2->Get("phot");
float pd6[4];
t6->SetBranchAddress("gamma_P4", &pd6);
TH1F *hist6 = new TH1F("", " ", 50, 0, 10);
Int_t n_tot6 = (Int_t)t6->GetEntries();
for (int j=0;j<399067; j++)
{
t6->GetEntry(j);
TLorentzVector D0_fvec1(pd6);
float fMomentum = D0_fvec1.M();
gamma = D0_fvec1.M();
nEmcPhotons->Fill(); // need to add this line..
cout << " pion mass "<< gamma <<endl;
}
f->Write();
f->Close();
}