kdlong / SelectorTools

Analysis code for WZ and ZZ leptonic analyses
0 stars 16 forks source link

Allow selection specific histogram setting #17

Open dteague opened 5 years ago

dteague commented 5 years ago

Problem

The selection variable is set in the Init() function as well as the histograms. If one wants selection specific histograms, since the hists1D variable (initialized per analysis) is used to set up the histograms used, it would be nice to allow to have selection specific setting of hists1D vector without having to recompile the code every time

Possible Solution

This would require probably splitting up the init and the initializehistograms section of the code and have the user call SelectionBase::Init(), set their hists1D, and then run the initializehistograms function.

pretty low priority, especially since don't really need this for running over grid, but might be nice, especially since it should be a relatively easy fix. Might create a PR soon for a fix.

kdlong commented 5 years ago

Thanks @dteague for the detailed description of the situation and use. In fact, a version of this already exists.

Note that the hists1D_ variable only defines the set of possible histograms. The actual histograms that are created for the selector and selection must be a subset of this, as defined by the names of histograms in the PlotObjects// file in AnalysisDatasetManager, and further pared down by the -b/--hist_names argument in makeHistFile.py. This why the plotobjects file is selection specific (though I agree with having a generic, selection-indepedent definition to fall back to if a per-selection definition isn't needed).

These lines just create empty entries in the histMap: https://github.com/kdlong/VVAnalysis/blob/master/src/SelectorBase.cc#L181-L192

This parses the histogram names and binning info passed in from the python code: https://github.com/kdlong/VVAnalysis/blob/master/src/SelectorBase.cc#L197 https://github.com/kdlong/VVAnalysis/blob/master/Utilities/scripts/makeHistFile.py#L98 https://github.com/kdlong/VVAnalysis/blob/master/Utilities/scripts/makeHistFile.py#L114

Where the names of the histgrams to be created are filtered by the (optional) -b/--hist_names arguments: https://github.com/kdlong/VVAnalysis/blob/master/Utilities/python/UserInput.py#L99-L100

When the histograms are initiated, there is a check to see if the histogram name passed in from the python code is either defined as a possible 1D or 2D histogram in the map. If it is, a TH1 object is instantiated in the map, otherwise it's just a null pointer. If it isn't a possible histogram in the map, a warning message is printed out that the histogram you've specified in the PlotObjects file isn't actually supported by the Selector: https://github.com/kdlong/VVAnalysis/blob/master/src/SelectorBase.cc#L206

Note that systhists and systhists2D need to be a subset of the hists1D_ selected from the PlotObjects since it's only initiated if the hist1D/hist2D is found in their respective maps.

Then SafeHistFill just checks to see that the entry in the map is not a null pointer: https://github.com/kdlong/VVAnalysis/blob/master/interface/SelectorBase.h#L233 If it is it won't be filled for that selector/selection.

If you tried to call SafeHistFill on a histogram that isn't included in the hists1D or hists2D it would give you an exception from trying to access an entry that isn't in the map (so you can't just add a SafeHistsFill("blah", ...) call). Probably not a bad to have some better error checking and warning if someone tried this.

So sorry this isn't documented or clear, but I hope that explains better what the situation is.