Re: Projection of a histograms.....again...

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Thu, 13 Mar 2008 08:34:34 +0100


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 - 08:31:43 CET

This archive was generated by hypermail 2.2.0 : Thu Mar 13 2008 - 11:50:02 CET