fill-histos
This tool allows you to recursively fill predefined histograms event by event. Histograms should be
contained in a Python dictionary called histo
and follow the formats below:
For Efficiencies
histos.update({
"HISTONAME": {
"type": "eff",
"histoDen": r.TH1D("Denominator name", r';TitleX; Events', nBins, firstBin, lastBin),
"histoNum": r.TH1D("Numerator name", r';TitleX; Events', nBins, firstBin, lastBin),
"func": __function_for_filling_histogram__,
"numdef": __condition_for_numerator__
},
})
Where:
HISTONAME
: The name that will appear in the output.root
file.func
: A function that provides the value for filling the histogram. It takes thereader
as input and can fetch all the objects reconstructed by thereader
. Examples:lambda reader: reader.genmuons[0].pt
fills a histogram with the leading muon pT.lambda reader: [seg.wh for seg in fcns.get_best_matches(reader, station=1)]
gets the best matching segments in MB1 (station=1
) and fills with the wheel value of the matching segment. Theget_best_matches
function is defined inutils/functions.py
.
numdef
: A boolean function to differentiate between the denominator and numerator. The numerator is filled only when this function returnsTrue
. Iffunc
returns a list, this must return a list of booleans of the same length.
For Flat Distributions
"HISTONAME": {
"type": "distribution", # it also supports distribution2d, distribution3d
"histo": r.TH1D("HISTONAME", r';TitleX; Events', nBins, firstBin, lastBin),
"func": __function_for_filling_histograms__,
}
The reader
argument in functions represents an event
entry, which should be an instance of
dtpr.base.Event
. A set of predefined histograms is available in dtpr/utils/histograms
.
Once your histograms are defined, you can include them in the configuration file by specifying:
# ...
histo_sources:
# Define the source modules of the histograms
- dtpr.utils.histograms.baseHistos
# Add additional source modules as needed
# ...
histo_names:
# List the histograms to fill - Uncomment or add histograms as needed
# They should exist in any of the source modules
# ============ efficiencies ============ #
- seg_eff_MB1
- seg_eff_MB2
# ...
And then, by running the command:
dtpr fill-histos -i [INPATH] -o [OUTPATH] -cf [CONFIGFILE] #... Other options can be added as needed
You will get a .root
file in the --outpath
directory containing the filled histograms.
You can also use directly the methods fill_histograms
and save_histograms
from the dtpr.analysis.fill_histograms
module.