Get entries from chain

Hi all,
I have a program which fills histograms from data saved in two root file.
My program can not access to the second root file to read.
please help me.
Thanks

Here is the My program;

[code]#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define EventStart ( 1e7 )
#define EventStop ( 1.5e7 ) // 2.8e7

#define psfile “…/prints/BSE_test4.ps”
#define datafile “…/database/pedestalBallshort_test4.dat”

#define rootfile “BSErootFile_test4”

TFile *myrootFile;
void BSEchans ()
{
TStopwatch timer;
timer.Start();

myrootFile=new TFile(rootfile,“RECREATE”);

gStyle->SetOptStat(10);
gStyle->SetOptDate(0);
gROOT->Macro(“openntuple.cxx”);
TPostScript *ps = new TPostScript(psfile,111); ps->Range(19,25); //set x,y of printed page

char name[35][250];
TCanvas *c1= new TCanvas(); c1->Size(19,25); c1->SetFillColor(10); c1->Divide(1,2);

TH1D *BSEraw[155],*BSEpeds[155];
int i,j,k;

TLine *line1[155],*line2[155];

FILE *Bshortpeds;
int peds[150][2], Bindif=1;
/*file of Ball pedestal values */
if ( Bshortpeds=fopen(datafile,“w”)) fprintf(stdout,“Created %s\n “,datafile);
else fprintf(stdout,” error in opening the file %s \n”,datafile);
fprintf(Bshortpeds,"#BallDet pedestal-value \n");

/**************************** Define Histograms ***************************************/
for (j=1; j<=149; j++) // j is detector number //
{
sprintf(name[1],“BSEraw_%d”,j);
sprintf(name[2],“Det. %d ; BSE [chan] ; count”,j);
BSEraw[j]=new TH1D (name[1],name[2],250,0,250);

 sprintf(name[3],"BSEpeds_%d",j);
 sprintf(name[4],"Det. %d ; BSE [chan] ; count",j);
 BSEpeds[j]=new TH1D (name[3],name[4],250,0,250);

}

/***************************************************************************************/
const int arraysize=150;
Double_t BSE[arraysize], Bnr[arraysize], Btheta[arraysize], Bphi[arraysize];
Double_t MWPCphi, MWPCtheta, WDdE, WUdE, WLE, WRE, WLdet, WRdet, WDdet, WUdet, MWPCX, MWPCY, EFW;
Double_t T1, T2, pureT1;
Double_t EventType, ballhits;

int counter=EventStart-1, det, size, Centtheta, Lowtheta;

elasticchain->SetBranchAddress(“b3”,Bnr);
elasticchain->SetBranchAddress(“b5”,BSE);

TBranch *b2 = elasticchain->GetBranch(“b2”);
TLeaf *ballhitsleaf = b2->GetLeaf(“ballhits”);
TLeaf *EventTypeleaf = b2->GetLeaf(“EventType”);

/************************************* loop over events 1 *************************************/

for (Long64_t jentry=EventStart; jentry<EventStop; jentry++)
{
counter++;
fprintf(stdout,"\rEvent No=%d\t",counter); //%2.2e
elasticchain->GetEntry(jentry);
ballhits=ballhitsleaf->GetValue();
EventType=EventTypeleaf->GetValue();

  if ( EventType==1 )
    {
     for (i=1; i<=ballhits; i=i+1)  
        {
          det=(int) Bnr[i];
          if(BSE[i]>0) BSEraw[det]->Fill(BSE[i]);
        }
    }
}

/************************************ end of loop over events 1 *********************************/
fprintf(stdout,"\nevents=%d",counter+1);

for(int Bno=1; Bno<150; Bno=Bno+1)
{
fprintf(Bshortpeds,"%d\t\t%d\n",Bno,BSEraw[Bno]->GetMaximumBin()*Bindif);
peds[Bno][0]=Bno; peds[Bno][1]=BSEraw[Bno]->GetMaximumBin()*Bindif;
}

/************************************* loop over events 2 *************************************/
counter=EventStart-1;
for (Long64_t jentry=EventStart; jentry<EventStop; jentry++)
{
counter++;
fprintf(stdout,"\rEvent No=%d\t",counter); //%2.2e
elasticchain->GetEntry(jentry);
ballhits=ballhitsleaf->GetValue();
EventType=EventTypeleaf->GetValue();

  if ( EventType==1 )
    {
     for (i=1; i<=ballhits; i=i+1)  
        {
          det=(int) Bnr[i];
          if(BSE[i]>0 && BSE[i]-peds[det][1]>10 ) BSEpeds[det]->Fill(BSE[i]);
        }
    }
}

/************************************ end of loop over events 2 /
fprintf(stdout,"\nevents=%d",counter+1);
/
*** Draw Hists *********************************/

for(int Bno=1; Bno<150; Bno=Bno+1)
{
c1->cd(1);
ps->NewPage();
gPad->SetLogy();
BSEraw[Bno]->Draw();
BSEraw[Bno]->Write();
line1[Bno] = new TLine(peds[Bno][1],0,peds[Bno][1],BSEraw[Bno]->GetMaximum());
line2[Bno] = new TLine(peds[Bno][1]+10,0,peds[Bno][1]+10,BSEraw[Bno]->GetMaximum());
line1[Bno]->SetLineWidth(0.2);
line2[Bno]->SetLineWidth(0.2);
line1[Bno]->SetLineColor(2);
line2[Bno]->SetLineColor(2);
line1[Bno]->Draw(“same”);
line2[Bno]->Draw(“same”);

 c1->cd(2);
 gPad->SetLogy();
 BSEpeds[Bno]->Draw();
 BSEpeds[Bno]->Write();
 c1->Update();
}

fprintf(stdout,"\nAll histograms are saved in %s",psfile);
fprintf(stdout,"\nAll pedestals are saved in %s\n",datafile);
ps->Close();
fclose(Bshortpeds);
timer.Stop();
Double_t rtime = timer.RealTime();
Double_t ctime = timer.CpuTime();
printf(“RealTime=%d min, CpuTime=%d min\n”,rtime/60.,ctime/60.);

myrootFile->Write();
myrootFile->Close();
}[/code]

and the “openntuple.cxx” is:

[code]{

Double_t X[64];
Double_t Bnr[150];
Double_t BLE[150];
Double_t BSE[150];
Double_t Bphi[150];
Double_t Btheta[150];

TChain *elasticchain=new TChain(“pdelastic”);
elasticchain->SetBranchAddress(“b2”,X);
elasticchain->SetBranchAddress(“b3”,Bnr);
elasticchain->SetBranchAddress(“b4”,BLE);
elasticchain->SetBranchAddress(“b5”,BSE);
elasticchain->SetBranchAddress(“b6”,Bphi);
elasticchain->SetBranchAddress(“b7”,Btheta);

elasticchain->Add("/media/Transcend/BINA/Ntuples/ElasticLmds/ntupleJun2016_withNosub.root");
elasticchain->Add("/media/Transcend/BINA/Ntuples/ElasticLmds/ntupleJun2016_withNosub_.root");

fprintf(stdout,"\n*********************************\n");
fprintf(stdout,"* OpenExprimentNtuple is loaded \n");
fprintf(stdout,"
********************************\n");
}[/code]

Right before “elasticchain->GetEntry(jentry);”, try to add:
elasticchain->LoadTree(jentry);

If it doesn’t help, see: Create TH2F gamma-gamma matrix from TTree/TChain data