Dear Rene,
Thanks a lot! Now the problem of the total number of the entries is fixed. But Now I have another problem: If I compare the number of entries I expect (in this case, 256 for each bin) with the number I obtain from the loop, I obtain less effective entries. How can I resolve it?
#if !defined(__CINT__) || defined(__MAKECINT__)
#include <TH2F.h>
#include <TCanvas.h>
#include <TStyle.h>
#include <TFile.h>
#include <TRandom3.>
#endif
void prova1(Int_t seed)
{
TH2F *histo = new TH2F("histo","histo",256,-.5,255.5,256,-0.5,255.5);
TRandom3 *random= new TRandom3(seed);
histo->Sumw2();
Double_t number=0;
for(Int_t i=1;i<=256;i++)
{
for(Int_t j=1;j<=256;j++)
{
while(number==0){
number= 10*random->Rndm();
cout<<number<<endl;
}
histo->Fill(i-1.5,j-1.5,number);
number=0;
}
Int_t countentx=0;
//Int_t countenty=0;
Int_t countenty=0;
Int_t count0=0;
for(Int_t i=1;i<=histo->GetXaxis()->GetNbins();i++){
if(countenty!=0) countenty=0;
for(Int_t j=1;j<=histo->GetYaxis()->GetNbins();j++)
{
Double_t content=histo->GetBinContent(i,j);
if(content!=0)
{
countenty=countenty+1;
//countentx=countentx+countenty;
}
else
if(content==0)
{
countenty=countenty+0;
count0++;
//countentx=countentx+0;
}
}
TH1D *px = histo->ProjectionX();
Double_t nentries =px->GetEntries();
TCanvas *canvas2 =new TCanvas("canvas2","canvas2");
canvas2->cd();
px->Draw();
canvas2->Update();
//TH1D *histo2=new TH1D("histo2","histo2",256,-0.5,255.5 );
Int_t nbins = px->GetXaxis()->GetNbins();
for (Int_t bin=1;bin<=nbins;bin++) {
double y = px->GetBinContent(bin);
double e = px->GetBinError(bin);
double effe = 0;
if (e != 0) effe = (y*y)/(e*e);
cout<<"bin= "<<bin<<"\ty= "<<y <<"\te= "<<e <<"\teffe= "<<effe<<endl;
px->SetBinContent(bin,effe);
px->SetBinError(bin,0);
//histo2->Fill(double(bin)-1.5,effe);
//histo2->SetBinError(bin,0);
}
px->SetEntries(nentries);
/*
TCanvas *canvas3 =new TCanvas("canvas3","canvas3");
canvas3->cd();
histo2->Draw();
canvas3->Update();
*/
TCanvas *canvas4 =new TCanvas("canvas4","canvas4");
canvas4->cd();
px->Draw();
canvas4->Update();
}
Thanks,
Melinda
On Thu, Mar 13, 2008 at 8:34 AM, Rene Brun <Rene.Brun_at_cern.ch> wrote:
> Melinda,
>
> The call to hist.SetBinContent increases the number of entries by 1. In
> your case your call this
> function 256 times, so you get 256 additional entries. See the fix below
>
> Rene Brun
>
> TCanvas *canvas =new TCanvas("canvas","canvas");
> canvas->cd();
> histo->Draw("colz");
> canvas->Update();
> gStyle->SetPalette(1);
> TH1D *px = histo->ProjectionX();
> Double_t nentries = px->GetEntries(); //<==================
> Int_t nbins = px->GetXaxis()->GetNbins();
> for (Int_t bin=1;bin<=nbins;bin++) {
> double y = px->GetBinContent(bin);
> double e = px->GetBinError(bin);
> double effe = 0;
> if (e != 0) effe = (y*y)/(e*e);
> px->SetBinContent(bin,effe);
> px->SetBinError(bin,0);
> }
> px->SetEntries(nentries); //<===================
>
> TCanvas *canvas2 =new TCanvas("canvas2","canvas2");
> canvas2->cd();
> px->Draw();
> canvas2->Update();
>
>
> Melinda Siciliano wrote:
> > Hi,
> >
> > I make an error copying effe=(y*y)/(e*e), but the problem of the
> > entries remain......Sorry....
> >
> > Melinda
> >
> > #if !defined(__CINT__) || defined(__MAKECINT__)
> > #include <TH2F.h>
> > #include <TCanvas.h>
> > #include <TStyle.h>
> > #include <TFile.h>
> > #include <TRandom3.>
> > #endif
> >
> > void prova1(Int_t seed)
> > {
> >
> >
> > TH2F *histo = new TH2F("histo","histo",256,-.5,255.5,256,-0.5,255.5);
> > TRandom3 *random= new TRandom3(seed);
> > histo->Sumw2();
> > for(Int_t i=1;i<=256;i++)
> > {
> > for(Int_t j=1;j<=256;j++)
> > {
> > histo->Fill(i-1.5,j-1.5,random->Rndm());//in order to fill the
> > first bin
> >
> > }
> >
> > }
> >
> > TCanvas *canvas =new TCanvas("canvas","canvas");
> > canvas->cd();
> > histo->Draw("colz");
> > canvas->Update();
> > gStyle->SetPalette(1);
> > TH1D *px = histo->ProjectionX();
> > Int_t nbins = px->GetXaxis()->GetNbins();
> > for (Int_t bin=1;bin<=nbins;bin++) {
> > double y = px->GetBinContent(bin);
> > double e = px->GetBinError(bin);
> > double effe = 0;
> > if (e != 0) effe = (y*y)/(e*e);
> > px->SetBinContent(bin,effe);
> > px->SetBinError(bin,0);
> > }
> >
> > TCanvas *canvas2 =new TCanvas("canvas2","canvas2");
> > canvas2->cd();
> > px->Draw();
> > canvas2->Update();
> >
> > }
> >
> >
> >
> > On Wed, Mar 12, 2008 at 11:15 AM, Melinda Siciliano
> > <mellybinda_at_gmail.com <mailto:mellybinda_at_gmail.com>> wrote:
> >
> > Hello all,
> >
> > I have problem with the effective entries. I don't think to have
> > changed nothing, but now it seems to not work and I have that the
> > effective entries are bigger than I expect of a quantity like the
> > number of bin in the x axis.
> >
> > Melinda
> >
> > #if !defined(__CINT__) || defined(__MAKECINT__)
> > #include <TH2F.h>
> > #include <TCanvas.h>
> > #include <TStyle.h>
> > #include <TFile.h>
> > #include <TRandom3.>
> > #endif
> >
> > void prova1(Int_t seed)
> > {
> >
> >
> > TH2F *histo = new TH2F("histo","histo",256,-.5,255.5,256,-0.5,255.5
> );
> > TRandom3 *random= new TRandom3(seed);
> > histo->Sumw2();
> > for(Int_t i=1;i<=256;i++)
> > {
> > for(Int_t j=1;j<=256;j++)
> > {
> > histo->Fill(i-1.5,j-1.5,random->Rndm());//in order to fill
> > the first bin
> >
> > }
> >
> > }
> >
> > TCanvas *canvas =new TCanvas("canvas","canvas");
> > canvas->cd();
> > histo->Draw("colz");
> > canvas->Update();
> > gStyle->SetPalette(1);
> > TH1D *px = histo->ProjectionX();
> > Int_t nbins = px->GetXaxis()->GetNbins();
> > for (Int_t bin=1;bin<=nbins;bin++) {
> > double y = px->GetBinContent(bin);
> > double e = px->GetBinError(bin);
> > double effe = 0;
> > if (e != 0) effe = y*y/e*e;
> > px->SetBinContent(bin,effe);
> > px->SetBinError(bin,0);
> > }
> >
> > TCanvas *canvas2 =new TCanvas("canvas2","canvas2");
> > canvas2->cd();
> > px->Draw();
> > canvas2->Update();
> >
> > }
> >
> >
> >
> >
> > On Mon, Mar 10, 2008 at 5:23 PM, Lorenzo Moneta
> > <lorenzo.moneta_at_cern.ch <mailto:lorenzo.moneta_at_cern.ch>> wrote:
> >
> > Hello Melinda,
> >
> > we will plan to add this new functionality as an option for
> > all the histogram projected functions, not as a new method.
> > It is expected to have this implemented for the development
> > release schedule for April. Anyway I will let you know when it
> > will be in the SVN trunk,
> >
> > Best Regards
> >
> > Lorenzo
> >
> > On Mar 5, 2008, at 6:25 PM, Melinda Siciliano wrote:
> >
> >> Hi Rene and Lorenzo,
> >>
> >> I tried as Rene suggested me and it works! Thanks a lot!!!!
> >>
> >> May I ask you if when you put the new function in ROOT ,
> >> could you tell me then the name of the function in the way to
> >> substite it in my gui?
> >>
> >> Thanks,
> >>
> >> Melinda
> >>
> >> On Tue, Mar 4, 2008 at 5:24 PM, Rene Brun <Rene.Brun_at_cern.ch
> >> <mailto:Rene.Brun_at_cern.ch>> wrote:
> >>
> >> Hi Melinda,
> >>
> >> The projection of the effective entries is currently not
> >> implemented.
> >> It is not too complex to obtain what you want if you have
> >> called Sumw2
> >> on your TH2 object.
> >> In this case, make the projection using TH2::ProjectionX
> >> (or Y) and
> >> compute the effective entries
> >> with a code looking like
> >> TH2 *h2; //your Th2 object where Sumw2 has been
> >> called before filling
> >> TH1D *px = h2->ProjectionX();
> >> Int_t nbins = px->GetXaxis()->GetNbins();
> >> for (Int_t bin=1;bin<=nbins;bin++) {
> >> double y = px->GetBinContent(bin);
> >> double e = px->GetBinError(bin);
> >> double effe = 0;
> >> if (e != 0) effe = y*y/e*e;
> >> px->SetBinContent(bin,effe);
> >> px->SetBinError(bin,0);
> >> }
> >>
> >> This could be an option when calling TH2::ProjectionX,Y.
> >> Lorenzo, could you implement this code in all Projection
> >> functions?
> >>
> >> Rene Brun
> >>
> >> Melinda Siciliano wrote:
> >> > Dear all,
> >> >
> >> > I have an 2D-histogram filled using the weight. I would
> >> like to ask
> >> > you if there a way to make the projection of the
> >> effective entries of
> >> > the histogram.
> >> >
> >> > Thanks,
> >> >
> >> > Melinda
> >>
> >>
> >
> >
> >
>
>
Received on Thu Mar 13 2008 - 10:17:13 CET
This archive was generated by hypermail 2.2.0 : Thu Mar 13 2008 - 17:50:02 CET