alcap-org/AlcapDAQ — pull request #231 by benkrikler (2014-09-08 10:21:23+00:00)
Title: Feature/bk si r2 pile up templates

So to progress with the SiR2 pile-up I've returned to the template fitting. I've put in a bunch of changes, predominantly tidying up code and some refactoring to make the code easier to understand.

This builds on work from issues:
- #7 (The original ticket discussing this)
- #129 (Previous discussion and example template pulses)
- #154 (Discusses finishing touches to the fitter)

I'll try and summarize the changes below. Specific to Template fitting:
- Moved Template fitting code into a sub-directory at `src/TAP_generators/template_fitting`
- Added a TTemplate class. I think John originally suggested this and it seems like a good idea. Largely it wraps a TH1 to the template, but it allows us to store other values such as the number of pulses a template contains and the refine factor that was used. This class also implements the addition of a pulse histogram to itself, although the relative offsets and scalings must be deduced elsewhere.
- The `TemplateArchive` uses the new `TTemplate` class and has the option to store templates in the normal output file or a separate one.
- The `TemplateFitter` class uses the new `TTemplate` class.
- The `TemplateCreator` module has undergone a LOT of changes:
* The underlying algorithm is the basically the same. The only change is to when we decide convergence of a template is reached. It used to be done on the stability of the error on the max bin. I've replaced to use the stability of the sum of all errors on all bins.
* Many changes to refactor of code or tidy up the aesthetics (code wrapping, indentation).
* I replaced the 4 or 5 maps that were in use with a single container of a struct which contains all the various fields we use to fit each channel.
* I've added in the option to specify an integral ratio and integral range which selects pulses to add to the template.
* The cut that the PCF only sees 1 pulse on a TPI for it to be used in the template is now optional.
* The module ends the run when all channels have template that are deemed as 'converged'.
* New / tidied up modules file arguments

Some of the changes are a bit off-topic for this feature I'm afraid:
- SetupNavigator exceptions changed / added as discussed on issue #216
- EventNavigator has a method to get the name of the output file

I was curious about a couple of things I saw:
1. The final template is normalised so the integral is 1. I thought we wanted the template's amplitude (max bin) to be scaled to 1. Is there a particular reason why we normalize to the integral and not the max bin and can I change it?
2. We check the max bin is less than 1/5th away from the edge of the waveform. Would a fixed number of samples not make more sense?

I want to start using the templates this makes but I'll do that on a separate branch, so I'd like to merge this in as soon as I can.