Basic q: fill histo from branch & add histo w expression

Hello,

My root files consist of 4 Branches: TimeStamp, ADC1, ADC2, ADC3 and ADC4 (with events from 24 hours).
I have many of these root files and would like to add for example ADC1 in several root files.

I have made some print outs from root to show how the tree looks (see also in nicer organized form in the attached file):

data.Print()


*Tree :data : Hades Data *
*Entries : 81254 : Total = 980789 bytes File Size = 529771 *

  •    :          : Tree compression factor =   1.85                       *
    

*Br 0 :TimeStamp : TimeStamp/i *
*Entries : 81254 : Total Size= 326486 bytes File Size = 311481 *
*Baskets : 10 : Basket Size= 32000 bytes Compression= 1.03 *

*Br 1 :ADC1 : ADC1/s *
*Entries : 81254 : Total Size= 163499 bytes File Size = 35589 *
*Baskets : 5 : Basket Size= 32000 bytes Compression= 4.50 *

*Br 2 :ADC2 : ADC2/s *
*Entries : 81254 : Total Size= 163499 bytes File Size = 86185 *
*Baskets : 5 : Basket Size= 32000 bytes Compression= 1.86 *

*Br 3 :ADC3 : ADC3/s *
*Entries : 81254 : Total Size= 163499 bytes File Size = 84447 *
*Baskets : 5 : Basket Size= 32000 bytes Compression= 1.89 *

*Br 4 :ADC4 : ADC4/s *
*Entries : 81254 : Total Size= 163499 bytes File Size = 1215 *
*Baskets : 5 : Basket Size= 32000 bytes Compression= 131.68 *

so the variables are:
TTree : data
Br : TimeStamp, ADC1, ADC2, ADC3 (Br= Branches)

The command below shows the data of the chosen variables

data->Scan("TimeStamp:ADC1:ADC2:ADC3")

  • Row * TimeStamp * ADC1 * ADC2 * ADC3 *

  •    0 *   2495966 *         0 *         0 *       169 *
    
  •    1 *   7521115 *         0 *         0 *      2061 *
    
  •    2 *  14389177 *         0 *         0 *       613 *
    
  •    3 *  16308387 *         0 *       250 *         0 *
    
  •    4 *  82182597 *         0 *         0 *       119 *
    
  •    5 * 104654444 *         0 *       650 *         0 *
    
  •    6 * 108552198 *         0 *      2497 *         0 *
    
  •    7 * 125267814 *         0 *      1822 *         0 *
    
  •    8 * 141802437 *         0 *         0 *       832 *
    
  •    9 * 158192311 *         0 *         0 *       364 *
    
  •   10 * 160741608 *         0 *         0 *      1969 *
    
  •   11 * 162137955 *      1882 *         0 *         0 *
    
  •   12 * 163241243 *         0 *         0 *      2330 *
    
  •   13 * 165688062 *         0 *      2505 *         0 *
    
  •   14 * 167783339 *       304 *         0 *         0 *
    
  •   15 * 180723842 *         0 *         0 *       192 *
    

To show the first event, use the command

data->Show(24)

======> EVENT:24
TimeStamp = 248791530
ADC1 = 0
ADC2 = 1011
ADC3 = 0
ADC4 = 0

After a lot of searching and reading of the documentation, I still don’t know how to start - it’s just such an immense lot of information for a beginner :frowning: I need to do the following things:

  1. Access the branches and energy calibrate with the expressions below + then make histograms:
  • konst2 * ADC2 + M2
  • konst3 * ADC3 + M3
  1. Save the histograms (i guess?).

  2. Do the same for all my root-files in the same folder (from the same week of measurements). They are called for example s00074_001, s00074_002 etc which data from 24h in each.

  3. Add all the ADC1 histograms from all consequtive days together and do the same for ADC2 and ADC3. This should now be OK since they are energy calibrated with the expressions above (in 1) so the peaks should end up on the same places. Is that correct?

How do I go about this?
Should I create a new tree called for example s00074 with all the summed histos in?
Or should I just save the histos in the first tree (data in s00074_001.root)?
How do I in the smartest way fill a histo with a branch and use the expression at the same time so it’s calibrated?
I guess I should be able to use an “add” function on the histos, to add all together?

Sorry for all the basics, but I hope to learn something from this (in combination with the continous reading of the documentation, since I have no one around to ask) :slight_smile:
root_commands_&_specs.cpp (4.38 KB)

Hi,

Can’t you “chain” the files and then calibrate using time-dependent parameters (since you have the TimeStamp)?

I’m not sure I understand what you mean, since the timestamp has nothing to do with the energy calibration that I have to do for the x-axis. The timestamp is given because I would later on want to look for coincidences, but to get the peak areas and energy right for the peak analysis of my samples - which is the task at hand - I must use normal histograms, as far as I know.

Also, I’ll need to “fix” the timestamp since it’s cyclic and i need to use another “expression” on that one (and probably make another branch called TimeStampFixed or something).

I suggest creating a chain of files and generate the calibrated histograms
like shown below. You can also merge the resulting histogram files using, eg

hadd -f all.root histos1.root histos2.root histosN.root

[code]void mycalib() {
//Create the calibrated histograms
Int_t ADCmax = 1000; //maximum value for calibrated ADC1
Int_t nbins = 1000; // or whatever you want, eg ADCmax
TFile *fout = new TFile(“histos.root”,“recreate”);
TH1F *hADC1 = new TH1F(“hADC1”,“calibrated ADC1”,nbins,0,ADCmax);
TH1F *hADC2 = new TH1F(“hADC2”,“calibrated ADC2”,nbins,0,ADCmax);
TH1F *hADC3 = new TH1F(“hADC3”,“calibrated ADC3”,nbins,0,ADCmax);
TH1F *hADC4 = new TH1F(“hADC4”,“calibrated ADC4”,nbins,0,ADCmax);

//set your calibration consdtants
Double_t konst1 = ???
Double_t M1 = ???, etc
TChain *chain = new TChain(“data”);
chain->Add(“data1.root”);
chain->Add(“data2.root”);
chain->Add(“dataN.root”);
Int_t TimeStamp;
Short_t ADC1, ADC2, ADC3, ADC4;
chain->SetBranchAddress(“TimeStamp”,&TimeStamp);
chain->SetBranchAddress(“ADC1”,&ADC1);
chain->SetBranchAddress(“ADC2”,&ADC2);
chain->SetBranchAddress(“ADC3”,&ADC3);
chain->SetBranchAddress(“ADC4”,&ADC4);

//loop on all entries and fill the calibrated histograms
Long64_t nentries = chain->GetEntries();
for (Long64_t i=0;i<nentries;i++) {
chain->GetEntry(i);
hADC1->Fill(konst1ADC1+M1);
hADC2->Fill(konst2
ADC2+M2);
hADC3->Fill(konst3ADC3+M3);
hADC4->Fill(konst4
ADC4+M4);
}

//save in memory histograms to their host file
fout->Write();
delete fout;
}
[/code]

Rene

Hello!
Thanks for the help! I’m very happy with the chained data and now all files are chained and histos filled. There is only one problem with the calibration.

In the attached file you can see the entire code. I make the histos with:

Int_t nbins = 8192; // or whatever you want, eg ADCmax
TFile *fout = new TFile("/Users/ew/AProg/ROOT1/Data/s00074/SUMhistos74.root",“recreate”);

TH1F *hADC1 = new TH1F(“hADC1”,“calibrated ADC1”,nbins, 0, nbins);
TH1F *hADC2 = new TH1F(“hADC2”,“calibrated ADC2”,nbins, 0, nbins);
TH1F *hADC3 = new TH1F(“hADC3”,“calibrated ADC3”,nbins, 0, nbins);

I would like to use my energy calibration to have energy on the x-axis (expression of the type “konst1*ADC2+konst2”).

As you can see in the code above I have used nbins twice, since when I used a limit xup of 2700 keV, I got a lot of zeroes on equidistant distances… It seems that then the x-axis (0 to 2700 keV) is divided into 8192 bins, and that is not at all what I wanted.

I would just like to have a histogram that shows the energy 0 to 2700 keV on the x-axis and that is then filled with the 8192 bins it has (recalculated to energy via the expression). This means that for example ADC2 might always fill up to almost 2700 keV, while ADC3 never does, or it could change slightly over time… It’s just the setting of the upper limit of the histograms so they all look the same… But I don’t want to take the upper limit and divide it by the bins, it’s always supposed to be 8192 bins and what energy it ends up with will be different depending on the calibration expression. Maybe this is a silly question?

Thanks for all the help so far :slight_smile:
addspecs2.C (2 KB)

Elizabeth,

I am not sure to understand your question. What about reducing the number of bins and specify your maximum value along x to be 2700?, eg

TH1F *hADC1 = new TH1F("hADC1","calibrated ADC1",100,0,2700);
Rene

Hello again,
I wanted to test a few things before I posted again.

Attached you can se a screen shot with 2 histograms. The only difference between them is that I have added the (calibration) expression: 0,3348*ADC3+30,086 to get the x-axis in keV. The No bins (=No channels) is 8192 in both and works fine with the raw data (and I supposed that it would with the converted data too since I should have 8192 data-points, so to say).

It is obvious that suddenly there’s something wrong and on equidistandt distances there are new “mini-peaks” (you could say that the top graph suddenly got hairy :smiley: ). I don’t get it. What happened?

Maybe I can’t use the expression to calibrate the x-axis like that? I’m suspecting that when using the expression mentioned above, I also change the y-values, which is of course not what I aimed for.

Any ideas? Am I using the expression boxes wrong? Or is there something fundamental here that I haven’t understood?


Elizabeth,

What you observe are simple binning effects due to the fact that your bin edges are integers.
When applying your calibration factor, it will happen that
-2 original uncalibrated bins will fall into the same calibrated bin
-vice versa, you may end up with non entries in a calibrated bin.

This is the reason, why in my previous mail, I was suggesting to reduce the number of bins in your calibrated histogram. Try 2000,4000

Rene