[ROOT] Automatic constructor with bin centers beeing interger values.

From: ANCIANT E. (eric.anciant@sodern.fr)
Date: Tue Nov 23 2004 - 11:20:37 MET


Hello rooters,

I often create histograms whose axis correspond to integer values,
(for example a Number of tracks per event)
When doing so, I like to have the "integer" values centered in the bin
(for exemple TH1F hNbTrack("NbTracks","Number of Tracks",100,-0.5,99.5);
Because :
- I find it visually more clear (not ambiguous)
- I am always scared that some manipulation (to name it TAxis::SetRange
) ends up recomputing Mean using center of bin, thus I feel more relaxed
if the centers of the bins are the real "integer" value (see below
little exemple of possible problem ):
{
TH1F hNbTrackCentered("NbTracksCentered","Number of Tracks
centered",100,-0.5,99.5);
TH1F hNbTrackNotCentered("NbTracksNotCentered","Number of Tracks not
centered",100,0,100);

hNbTrackCentered.Fill(50);
hNbTrackNotCentered.Fill(50);
TCanvas canvas;
canvas.Divide(1,2);
canvas.cd(1);
hNbTrackCentered.Draw();
canvas.cd(2);
hNbTrackNotCentered.Draw();

// now zoom graphically on X axis arround bin 50 and look at displayed
Mean ..
//
}

This is a known 'feature', already discussed in this mailing list ...

I wonder if it would not be worth adding to the TH1 ( 2 / 3 ) classes,
dedicated constructors for this special
Case (possibly inline) something like :

TH1(const char* name, const char* title, Int_t firstBin, Int_t lastBin )
{
   Build();
   if (nbins <= 0) nbins = 1;
   if (lastBin < firstBin ) { }; // Don't know what would be best in
that case ..
   TH1(lastBin - firstBin + 1,((Axis_t)firstBin
-0.5),((Axis_t)lastBin+0.5));
   fNcells = fXaxis.GetNbins()+2;
}

Or this property could be implemented in TAxis::Set( ...) ...

This would allow fast, easy, bias free creation of histograms whose axis
are meant as integer values ...
Another advantage I see is that I remember seing some people confused in
creating "integer"/discrete axis bin
Histograms, like the typical :

root [3] TH1D hTypeOfSomething("type","type",10,1,10);
root [4] hTypeOfSomething.GetBinWidth(1)
(const Axis_t)9.00000000000000020e-001

The automatic bin creation would prevent some mistakes ..

eric




***********
Ce message et eventuellement les pieces jointes sont exclusivement transmis a l'usage de leur destinataire. Leur contenu est confidentiel. Si vous n etes pas le bon destinataire nous vous demandons de ne pas conserver, copier, utiliser ou divulguer cette communication. Merci de le detruire et de me notifier cette erreur.

INTERNET ne permettant pas d assurer l integrite de ce message, SODERN decline toute responsabilite au cas ou il aurait ete intercepte ou modifie.


This message and possibly any attachments are transmitted for the exclusive use of their addressee. Their content is confidential. If you are not the intended recipient please do not keep, copy, use or disclose this communication to others. Also Please delete it and notify the sender at once.

Because of the nature of INTERNET the sender is not in a position to ensure the integrity of this message, therefore SODERN disclaims any liability whatsoever in the event of this message having been intercepted and/or altered.



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:10 MET