hello
I have plotted Pt Vs mass projections and i have used an array to fill the canvas. code runs fine but when i used more than one loop, in my case i have used three loops for three canvas. The problem I’m facing is the last plot in the loop gets plotted on all the previous canvas at the last position. how can i avoid this problem.
thanks
taushy
here is the code:
TCanvas *c1 = new TCanvas();
c1->Divide(3,2);
TH1F * mpt = (TH1F*)h7->ProjectionY();
"mpt"
const Int_t npt =6;
Double_t pt[npt+1] ={0,1,2,3,4,6,10};
TH1F *mpthisto[npt];
for(int n=0;n<npt;n++)
{
c1->cd(n+1);
Int_t bin1 = mpt->FindBin(pt[n]);
Int_t bin2 = mpt->FindBin(pt[n+1]);
cout << bin1 <<"--------"<<bin2<<endl;
mpthisto[n] = (TH1F*)h7->ProjectionX("",bin1,bin2);
mpthisto[n]->SetTitle(Form("pt-%.1f--%.1f",pt[n],pt[n+1]));
mpthisto[n]->Draw();
c1->Update();
}
//////////***************************/////////////////////
TCanvas *c2 = new TCanvas();
c2->Divide(2,2);
TH1F * mptx = (TH1F*)h7->ProjectionX();
const Int_t x=4;
Double_t ptx[x+1]={0,1,1.7,1.9,2.1};
TH1F *pthist[x];
for(int i=0;i<x;i++)
{
c2->cd(i+1);
Int_t bn1 = mptx->FindBin(ptx[i]);
Int_t bn2 = mptx->FindBin(ptx[i+1]);
cout << bn1 <<"--------"<<bn2<<endl;
pthist[i] = (TH1F*)h7->ProjectionY("",bn1,bn2);
pthist[i]->SetTitle(Form("pt-%.2f-%.2f",ptx[i],ptx[i+1]));
pthist[i]->Draw();
c2->Update();
}
//////////////////////*****************////////////////
TCanvas *c3=new TCanvas();
c3->Divide();
TH1F *myhist=(TH1F*)h7->ProjectionY();
const int y=1;
double ar[y+1]={1,3};
TH1F *prjct[y];
for(int z=0;z<y;z++)
{
c3->Divide(z+1);
int bn_1 = myhist->FindBin(ar[z]);
int bn_2 = myhist->FindBin(ar[z+1]);
prjct[z]=(TH1F*)h7->ProjectionX("",bn_1,bn_2);
prjct[z]->SetTitle(Form("pt-%.2f--%.2f",ar[z],ar[z+1]));
prjct[z]->Draw();
c3->Update();
}