Crombie Tools
PlotStack.h
Go to the documentation of this file.
1 /**
2  @file PlotStack.h
3 
4  Header of PlotStack class.
5 
6  @author Daniel Abercrombie <dabercro@mit.edu>
7 */
8 
9 #ifndef CROMBIETOOLS_PLOTTOOLS_PLOTSTACK_H
10 #define CROMBIETOOLS_PLOTTOOLS_PLOTSTACK_H
11 
12 #include "HistHolder.h"
13 #include "PlotPreparer.h"
14 
15 /**
16  @ingroup plotgroup
17  @class PlotStack
18  Class used for making stack plots.
19  Most easy way to use this class is through CrombieTools.PlotTools.PlotStack
20  convenience functions and using an [MC Configuration](@ref formatmc).
21  Many appearance flags must be set through this class's methods though.
22 */
23 
24 class PlotStack : public PlotPreparer
25 {
26  public:
27  PlotStack();
28  virtual ~PlotStack();
29 
30  /// Copy this PlotStack for parallelization
31  PlotStack* Copy ();
32 
33  /// Merge a vector of histograms into a vector of HistHolders
34  std::vector<HistHolder*> MergeHistograms ( FileType type, std::vector<TH1D*> hists );
35 
36  /// Choose the binning of your plots and make then
37  void MakeCanvas ( TString FileBase, Int_t NumXBins, Double_t *XBins,
38  TString XLabel, TString YLabel = "", Bool_t logY = false );
39 
40  /// Binning with fixed width
41  void MakeCanvas ( TString FileBase, Int_t NumXBins, Double_t MinX, Double_t MaxX,
42  TString XLabel, TString YLabel = "", Bool_t logY = false );
43 
44  /// Make plots with the PlotPreparer
45  void MakeCanvas ( TString FileBase, TString XLabel, TString YLabel = "", Bool_t logY = false );
46 
47  /**
48  Sets the legend entry that will be on the top of the stack.
49  @param force should match a legend entry. It should have spaces instead of underscores
50  if matching an entry in an [MC Configuration](formatmc).
51  */
52  void SetForceTop ( TString force ) { fForceTop = force; }
53  /// Set the minimum fraction of background that shows up on the plot's legend separately
54  void SetMinLegendFrac ( Double_t frac ) { fMinLegendFrac = frac; }
55  /// Set the minimum fraction of backgrounds that are not plotted or mentioned in linear scale
56  void SetIgnoreInLinear ( Double_t ignore ) { fIgnoreInLinear = ignore; }
57  /// Set the color of the "Others" legend entry
58  void SetOthersColor ( Color_t color ) { fOthersColor = color; }
59  /// Set the line width of the stack plots
60  void SetStackLineWidth ( Int_t width ) { fStackLineWidth = width; }
61 
62  /// This dumps out some raw values for you to check yields.
63  void SetDebug ( Bool_t debug ) { fDebug = debug; }
64  /// Set the name of a .root file to dump the separate histograms used in the plots.
65  void SetDumpFileName ( TString dumpName ) { fDumpRootName = dumpName; }
66 
67  /// Set the suffix of dumped histograms
68  void SetHistSuff ( TString suff ) { fHistSuff = suff; }
69 
70  /**
71  Insert a histogram from file into the stack plot.
72  Most histograms in the stack plot are created from TTree::Draw() functions acting on trees.
73  It is also possible to just insert a histogram generated by someone else into the stack plot.
74  @param fileName is the name of the file containing the histogram.
75  @param histName is the name of the TH1 inside the file.
76  @param LegendEntry is the entry in the legend. It does not require underscores for spaces
77  like in the [MC Configurations](@ref formatmc).
78  */
79  void InsertTemplate ( TString fileName, TString histName, TString LegendEntry )
80  { fTemplateFiles.push_back(fileName);
81  fTemplateHists.push_back(histName);
82  fTemplateEntries.push_back(LegendEntry); }
83 
84  /// Use this to change the automatic sorting of backgrounds based on yields
85  void SetSortBackground ( Bool_t doSort ) { fSortBackground = doSort; }
86 
87  /// Use this to change the automatic sorting of signals based on yields
88  void SetSortSignal ( Bool_t doSort ) { fSortSignal = doSort; }
89 
90  /// Use this to set whether the signal sits on top or not
91  void SetAddSignal ( Bool_t add ) { fAddSignal = add; }
92 
93  /// Use this to get a post-fit line
94  void SetPostFitFile ( TString file_name, TString region )
95  { fPostFitFile = file_name; fRegion = region; }
96 
97  private:
98  TString fForceTop = ""; ///< A legend entry that is on the top of backgrounds
99  Double_t fMinLegendFrac = 0.0; ///< If a background contributes less than this, it's grouped in others
100  Double_t fIgnoreInLinear = 0.0; ///< If background less than this, do not draw in linear-scale plot
101  Int_t fStackLineWidth = 1; ///< Line width of the histograms
102  Color_t fOthersColor = 0; ///< Color of the "Others" legend entry
103 
104  std::vector<TString> fTemplateFiles; ///< Holds file name of the templates
105  std::vector<TString> fTemplateHists; ///< Holds histogram name of the templates
106  std::vector<TString> fTemplateEntries; ///< Holds legend entries of the templates
107 
108  Bool_t fDebug = false; ///< Dumps yield tests
109  TString fDumpRootName = ""; ///< File where each histogram in stack is dumped
110  TString fHistSuff = "";
111  Bool_t fSortBackground = true; ///< Bool to sort the backgrounds
112  Bool_t fSortSignal = true; ///< Bool to sort the signals
113  Bool_t fAddSignal = true; ///< Bool to determine where the signal sits
114  TString fPostFitFile = ""; ///< Holds the location of post-fit plots
115  TString fRegion = ""; ///< Holds the region for post-fit plots
116 
117  /// Makes the canvas from histogram vectors. All other MakeCanvas pass through here.
118  void MakeCanvas (TString FileBase, std::vector<TH1D*> DataHists, std::vector<TH1D*> MCHists, std::vector<TH1D*> SignalHists,
119  TString XLabel, TString YLabel, Bool_t logY);
120 
121  ClassDef(PlotStack, 1)
122 };
123 
124 #endif