Hi,

I got a problem with my pedestal script. I was trying to add one more branch to my previous tree where this new branch was a pedestal subtracted branch. I used branch x3 to be my original branch, and the subtracted pedestal branch was named as x33. However, after running my script, the branch x33 was so strange and got a huge negative average. Obviously, it was not the correct result. It must be something wrong with my script, but I could not figure out my problem. I uploaded my script here, and could anyone help with my question? Thanks so much!

pedestal00.root (140.9 KB)

pedestal.C (2.0 KB)

Hi Hao,

Thanks for posting. Can you perhaps reduce the code to a minimal reproducer of the problem and maybe formulate a more precise question?

Thanks a lot in advance.

Cheers,

Danilo

pedestal.C (1.1 KB)

Hi Danilo,

Here is the code. My question is I am trying to pick up a branch from a tree while the branch name is x3, and minus 42 from the counts of branch x3 to derive a new branch x33. It is not minus 42 from every entries of branch x3 but the counts of branch x3. The counts is the vertical axis, and I want to minus the vertical axis number by 42. It is like to shrink the vertical axis, but the histogram keeps the same shape but with lower vertical axis. The data I obtained from the new added branch x33 was wrong (with some negative average), but I could not figure out the reason. I know my error should be in this line: “inputBranch -= pedestalValue;” , but I cannot make it correct.

Thanks so much for your time!

And another question is can I change the counts numbers from the original data file? I mean not just make a canvas and plot the histogram, but also change the counts (i.e. the bins) from the original data file. Thanks so much if anyone can help.

Hi Danilo, I restate my questions and uploaded a new .C file. Thanks for your time!

Hi Hao,

I do not see so far any issue which is strictly related to ROOT: please correct me if I am wrong.

The data I obtained from the new added branch x33 was wrong (with some negative average)

Do you understand why wrong? Can you point to a ROOT bug?

Cheers,

Danilo

Hi Danilo,

I think the problem was because this line “inputBranch -= pedestalValue” was not the correct algorithm for my question.

Do you know how to run [TH1::Fill(Double_t x, Double_t weight) ] (where “x” would be the “channel number” and “weight” would be the “number of counts”)? I found this function was mentioned online which is related to my question but without more details there. I am basically doing the same research, the x is my channel number and the weight is my number of counts, I want to populate the weight (number of counts), but I could not do it with TH1F. If possible, could you show me an example on how to use TH1::Fill function? Thanks so much for your time.

Best,

Hao

Hi Danilo,

I found I may need to use GetBinContent() function from my case. However, when I tried to write a script, it gives me 0 as a result. I could not figure out how to call or how to make GetBinContent() run correctly. Could you please help check my script if possible? Thanks so much for your time.

Best,

Hao

pedestalhistest.C (841 Bytes)

```
void pedestalhistest()
{
TH1F *hist = new TH1F("hist","Histogram",15000,0,300);
fstream file;
file.open("Pedestal_0_2_5_2023_002.ascii", ios::in);
Double_t n;
Int_t i;
while(1)
{
double x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11;
file >> x1 >> x2 >> x3 >> x4 >> x5 >> x6 >> x7 >> x8 >> x9 >> x10 >> x11;
hist->Fill(x4);
if(file.eof()) break;
}
for (i=1; i<= hist->GetNbinsX();i++){
n = hist->GetBinContent(i); }
file.close();
hist->Scale(1);
hist->GetXaxis()->SetTitle("Channels");
hist->GetYaxis()->SetTitle("Particle counts");
TCanvas *c1 = new TCanvas();
hist->Draw();
cout << "Bin counts: "<< n << endl;
}
```

Yes, I submitted another question and was answered there. Thank you for your time!

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