Histogram unify


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.18.00
Platform: UBUNTU
Compiler: Not Provided


Good evening!!

I’m trying to unify the data generated from root in one file with 4 histogram, I want to save the data of the 4 histograms in a file txt, considering the counts generated in 2 histogram per bins of energy. For this I generated the code that produce the txt file with the energy but with zeros for the other 2 histogram, could anyone help me?

Thanks

Best regards

SomaEI1.txt (111.8 KB)
SPEC_IONEXCElecDNA3L.root (22.2 KB)

Do you have a script ? you posted only data files.

@couet Thanks for reply. Yes, I’m forget this, but I place here, now:

SumDiv1.C (1.7 KB)

I get:

Processing SumDiv1.C...
In file included from input_line_9:1:
/Users/couet/Downloads/SumDiv1.C:22:22: error: invalid suffix 'idx1' on integer constant
for (int idx=0,idx3=0idx1=0,idx2=0; idx<trEI->GetNbinsX(),idx2<trEE->GetNbinsX() idx1<trCI->GetNbinsX(),  idx3<trCE->GetNbinsX();++idx,++idx3, ++idx1,++idx2) {
                     ^
/Users/couet/Downloads/SumDiv1.C:22:82: error: expected ';' in 'for' statement specifier
for (int idx=0,idx3=0idx1=0,idx2=0; idx<trEI->GetNbinsX(),idx2<trEE->GetNbinsX() idx1<trCI->GetNbinsX(),  idx3<trCE->GetNbinsX();++idx,++idx3, ++idx1,++idx2) {
                                                                                 ^
/Users/couet/Downloads/SumDiv1.C:22:82: error: use of undeclared identifier 'idx1'
/Users/couet/Downloads/SumDiv1.C:22:129: error: expected ')'
for (int idx=0,idx3=0idx1=0,idx2=0; idx<trEI->GetNbinsX(),idx2<trEE->GetNbinsX() idx1<trCI->GetNbinsX(),  idx3<trCE->GetNbinsX();++idx,++idx3, ++idx1,++idx2) {
                                                                                                                                ^
/Users/couet/Downloads/SumDiv1.C:22:5: note: to match this '('
for (int idx=0,idx3=0idx1=0,idx2=0; idx<trEI->GetNbinsX(),idx2<trEE->GetNbinsX() idx1<trCI->GetNbinsX(),  idx3<trCE->GetNbinsX();++idx,++idx3, ++idx1,++idx2) {
    ^
/Users/couet/Downloads/SumDiv1.C:22:132: error: use of undeclared identifier 'idx'
for (int idx=0,idx3=0idx1=0,idx2=0; idx<trEI->GetNbinsX(),idx2<trEE->GetNbinsX() idx1<trCI->GetNbinsX(),  idx3<trCE->GetNbinsX();++idx,++idx3, ++idx1,++idx2) {
                                                                                                                                   ^
/Users/couet/Downloads/SumDiv1.C:22:138: error: use of undeclared identifier 'idx3'
for (int idx=0,idx3=0idx1=0,idx2=0; idx<trEI->GetNbinsX(),idx2<trEE->GetNbinsX() idx1<trCI->GetNbinsX(),  idx3<trCE->GetNbinsX();++idx,++idx3, ++idx1,++idx2) {
                                                                                                                                         ^
/Users/couet/Downloads/SumDiv1.C:22:146: error: use of undeclared identifier 'idx1'
for (int idx=0,idx3=0idx1=0,idx2=0; idx<trEI->GetNbinsX(),idx2<trEE->GetNbinsX() idx1<trCI->GetNbinsX(),  idx3<trCE->GetNbinsX();++idx,++idx3, ++idx1,++idx2) {
                                                                                                                                                 ^
/Users/couet/Downloads/SumDiv1.C:22:153: error: use of undeclared identifier 'idx2'
for (int idx=0,idx3=0idx1=0,idx2=0; idx<trEI->GetNbinsX(),idx2<trEE->GetNbinsX() idx1<trCI->GetNbinsX(),  idx3<trCE->GetNbinsX();++idx,++idx3, ++idx1,++idx2) {

But the way you wrote the for loop is really weird…

yes I understand that’s weird, but what I want is related the X data from energies (energy and energy3) to Y axis of counts (energy1 and energy2) generated a file with corresponds counts per bins of the energies.

I fix this, but the result isn’t what I imagine, because return the energies and values 0, like the txt file send before:

SumDiv1.C (1.8 KB)

I don’t know if this is the way to do it, but I did this for I could related every histogram and related the counts of histogram energy1 - trCI and energy3 - trCE, with the bins of the energies histogram (energy - trEI, energy2 - trEE).

Please, if anyone have any suggestions, I appreciate.

Thanks Best regards

I do not understand what you are trying to do with this loop. try:

   for (int idx=0,idx3=0,idx1=0,idx2=0;
        idx<trEI->GetNbinsX(),idx3<trEE->GetNbinsX(), idx1<trCI->GetNbinsX(), idx2<trCI->GetNbinsX();
        ++idx,++idx3,++idx1,++idx2) {
      printf("%d %d %d %d\n",idx,idx3,idx1,idx2);
   }

It shows that your 4 indices are always all the same. She why having a so complex for loop ?

I think this to run in one loop and unify in one filé what I mencioned before. But seeing your print it is wrong…

But that is a way to reproduce what I was said?

Thanks

What do you mean exactly by “unify” ?

First, each histogram of counts has a related histogram of energy, (get(“energy”) = it is the energy histogram of get(“energy1”) count histogram and get(“energy2”) = it is the energy histogram of get("energy3) count histogram.

For each bin of the energy histogram I want to produce a txt file:

energy countFromEnergy energy2 countFromEnergy2

Some like this, if it is possible. This is what I mean with unify.

best regards

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