Set bin width defined by user in TH1

I have data which I want to represent by a histogram.

Two notes before question:

  1. I do not know the range in that data in advance. So I would like to not specify ranges of a histogram.
  2. In order to further analysis, for example, to compare this data with other which is also represented by a similar histogram, I want histograms to have the same bin width. And I know this value of desired width in advance.
  3. All histograms are TH1I integer type.

Taking into account the first note I create a histogram as follows:

TH1I hist = new TH1I( name, title, Nbins, 0, 0);

On the other hand it fixes bin width implicitly (by specifying number of bins) which is not desired.

Question: How to set fixed bin width without knowing range of a histogram in advance? If possible.

Do you have your data stored in an array?

It is in separate files. Actually it is .dat files from CAEN ADC. Few lines of such a file are (in this case 2nd column is ADC channel, 3rd - base line):

0 1115 1100
1 1116 1100
2 1116 1100
...

I.e. I read these files line by line in a loop and fill histograms each iteration.

What if it would be in an array? What solution would you provide in that case?

{
  TTree *t = new TTree("t", "a temporary tree");
  t->ReadFile("CAEN_ADC.dat", "i/I:a:b");
  Double_t xmin = t->GetMinimum("i");
  Double_t xmax = t->GetMaximum("i") + 1.;
  Int_t n = Int_t(xmax - xmin + 0.5);
  TH1D *h = new TH1D("h", "CAEN ADC", n, xmin, xmax);
#if 0 /* 0 or 1 */
  t->Project("h", "i + 0.5", "a"); // "raw" ADC
#else /* 0 or 1 */
  t->Project("h", "i + 0.5", "a - b"); // ADC - base_line
#endif /* 0 or 1 */
  delete t; // no longer needed
  h->Draw("");
}

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.