Crombie Tools
Corrector.py
Go to the documentation of this file.
1 """@package CrombieTools.SkimmingTools.Corrector
2 
3 Submodule of CrombieTools.SkimmingTools
4 Contains the constructor and default object for Corrector and CorrectorApplicator.
5 A couple of convenience functions are also used to create these objects with
6 some parameters filled.
7 
8 @author Daniel Abercrombie <dabercro@mit.edu>
9 """
10 
11 
12 from .. import Load
13 
14 
15 newCorrector = Load('Corrector')
16 """Corrector constructor"""
17 newApplicator = Load('CorrectorApplicator')
18 """CorrectorApplicator constructor"""
19 
20 
21 def MakeApplicator(name, saveAll, inputTree='events', outputTree='events', reportFreq=100000, isUnc=False):
22  """Make a CorrectorApplicator with parameters filled
23 
24  @param name is a string that names the branch to merge all of the correction factors into.
25  @param saveAll is a bool to determine whether or not to save each correction factor
26  in their own branch.
27  @param inputTree is the name of the tree to read as input.
28  @param outputTree is the name of the tree to place the output branches.
29  @param reportFreq is the number of events to pass between reporting progress.
30  @param isUnc sets whether this corrector is for uncertainties or not
31  @returns a CorrectorApplicator object.
32  """
33  applicator = newApplicator(name, saveAll)
34  applicator.SetInputTreeName(inputTree)
35  applicator.SetOutputTreeName(outputTree)
36  applicator.SetReportFrequency(reportFreq)
37  applicator.SetIsUncertainty(isUnc)
38  return applicator
39 
40 
41 def MakeCorrector(Name, inExpressions, inCut, correctionFile, correctionHist):
42  """Make a Corrector object
43 
44  @param Name is the name of the branch for this Corrector if the CorrectorApplicator
45  is saving all branches.
46  @param inExpressions is the expression to evaluate before reading from the Correction histogram.
47  If the histogram is multi-dimensional, a list can be passed to this parameter.
48  @param inCut is the cut that a tree must pass in order for the Correction to be applied.
49  @param correctionFile is the name of the file holding the correction histogram
50  @param correctionHist is the name of the histograms to apply corrections with.
51  Two histograms from the same file can be divided by passing a list
52  of [numerator_name, denominator_name].
53  @returns a filled Corrector object.
54  """
55  corrector = newCorrector(Name)
56  if type(inExpressions) is list:
57  for inExpr in inExpressions:
58  corrector.AddInExpression(inExpr)
59  else:
60  corrector.AddInExpression(inExpressions)
61 
62  corrector.SetInCut(inCut)
63  corrector.SetCorrectionFile(correctionFile)
64  if type(correctionHist) is list:
65  corrector.SetCorrectionHist(correctionHist[0], correctionHist[1])
66  else:
67  corrector.SetCorrectionHist(correctionHist)
68 
69  return corrector