Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing problems with TRestDetectorSignal fitting methods #119

Merged
merged 16 commits into from
Jun 4, 2024
Merged

Conversation

mariajmz
Copy link
Contributor

@mariajmz mariajmz commented May 30, 2024

mariajmz Medium: 104 Powered by Pull Request Badge

DON'T MERGE: This is a work in progress

@JPorron and me detected a problem with the fitting methods: the limits for the fits are hardcoded and are only valid for a sampling time of 20 ns.

@mariajmz
Copy link
Contributor Author

I think the problem was in this line
TH1F* h1 = new TH1F("h1", "h1", 1000, 0,10); // Histogram to store the signal. For now the number of bins is fixed.

The bin limits for the histogram were fixed. This works well with signals with 20 ns of sampling time (see figure) but not with signals of 40 ns of sampling time, for example.

imagen
Figure 1. Signal with 20 ns of sampling time. Left: histogram with 1000 bins, between 0 and 10 us. Right: TGraph of the signal.

old
Figure 2. Signal with 40 ns of sampling time. Left: histogram with 1000 bins, between 0 and 10 us. Right: TGraph of the signal

new
Figure 3. Same signal of 40 ns of sampling time with the new binning. The red point is the result of the gaussian fit (without changing the upper and lower limit)

What's new:

  • The number of bins and limits of this histogram that stores the signal.
  • The limits of the fit (this can be improved)

energy = gaus->GetParameter(0);
time = gaus->GetParameter(1);
energy = gaus.GetParameter(0);
time = gaus.GetParameter(1);
} else {
// the fit failed, return -1 to indicate failure
energy = -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can take this opportunity to rethink if we want to return energy -1 or do something else.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made #120 to address this.

@juanangp
Copy link
Member

juanangp commented May 31, 2024

Long time ago I did a pull request to add generic methods and this issue was addressed here https://github.com/rest-for-physics/framework/blob/48c4faed4b4942a1fa48b2b1b34acd9432ae950f/source/framework/analysis/src/TRestPulseShapeAnalysis.cxx#L396. There is no need to create a TH1 because you can do the fit directly on a TGraph that you can easily retrieve from TRestDetectorSignal

Pull request is here rest-for-physics/framework#379

@lobis lobis self-requested a review June 3, 2024 10:10
@@ -424,23 +435,22 @@ TRestDetectorSignal::GetMaxAget() // returns a 2vector with the time of the pea
Double_t lowerLimit = maxRawTime - 0.2; // us
Double_t upperLimit = maxRawTime + 0.7; // us
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't changed this limits (also in the landau fit). Maybe we should adjust them too

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think we should. The new dynamic time window should work better in most cases than what we have now.

}

TF1 gaus("gaus", "gaus", lowerLimit, upperLimit);
TH1F h1("h1", "h1", GetNumberOfPoints(), GetTime(0), GetTime(GetNumberOfPoints() - 1));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are maintaining the fit with the signal stored as histogram but as Juanan commented, it is not necessary as we can get the signal as TGraph with TRestDetectorSignal::GetGraph(Int_t color). What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think TGraph is a better choice but on practice I don't think it makes a difference since the histogram has one bin per signal time bin, so the information content of both representations is the same.

You can change them to use TGraph if you want but I would do it in a different PR (unless it's trivial to do so).

@mariajmz mariajmz marked this pull request as ready for review June 3, 2024 19:47
@lobis lobis merged commit 9df8c2f into master Jun 4, 2024
63 checks passed
@lobis lobis deleted the mariajmz_fits branch June 4, 2024 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants