Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:29:44

0001 #ifndef INCLUDE_HISTFACTORYNAVIGATION_H
0002 #define INCLUDE_HISTFACTORYNAVIGATION_H
0003 
0004 #include <map>
0005 #include <vector>
0006 #include <string>
0007 
0008 #include "TH1.h"
0009 #include "THStack.h"
0010 
0011 #include "RooDataSet.h"
0012 #include "RooRealVar.h"
0013 #include "RooProduct.h"
0014 #include "RooStats/HistFactory/Measurement.h"
0015 
0016 namespace RooStats {
0017   class ModelConfig;
0018   namespace HistFactory {
0019 
0020     class HistFactoryNavigation {
0021 
0022     public:
0023 
0024       /// Initialize based on an already-created HistFactory Model
0025       HistFactoryNavigation(ModelConfig* mc);
0026       HistFactoryNavigation(const std::string& File,
0027              const std::string& WorkspaceName="combined",
0028              const std::string& ModelConfigName="ModelConfig");
0029       HistFactoryNavigation(RooAbsPdf* model, RooArgSet* observables);
0030 
0031       virtual ~HistFactoryNavigation() {}
0032 
0033       /// Should pretty print all channels and the current values

0034       void PrintState();
0035       /// Should pretty print this and the current values
0036       void PrintState(const std::string& channel);
0037 
0038       /// Print the current values and errors of pdf parameters
0039       void PrintParameters(bool IncludeConstantParams=false);
0040 
0041       /// Print parameters that effect a particular channel
0042       void PrintChannelParameters(const std::string& channel,
0043               bool IncludeConstantParams=false);
0044 
0045       /// Print parameters that effect a particular sample
0046       void PrintSampleParameters(const std::string& channel, const std::string& sample,
0047              bool IncludeConstantParams=false);
0048 
0049       /// Print the different components that make up a sample
0050       /// (NormFactors, Statistical Uncertainties, Interpolation, etc)
0051       void PrintSampleComponents(const std::string& channel, const std::string& sample);
0052 
0053       /// Print a "HistFactory style" RooDataSet in a readable way
0054       void PrintDataSet(RooDataSet* data, const std::string& channel="");
0055 
0056       /// Print the model and the data, comparing channel by channel
0057       void PrintModelAndData(RooDataSet* data);
0058 
0059       /// The value of the ith bin for the total in that channel
0060       double GetBinValue(int bin, const std::string& channel);
0061       /// The value of the ith bin for that sample and channel

0062       double GetBinValue(int bin, const std::string& channel, const std::string& sample);
0063 
0064       /// The (current) histogram for that sample
0065       /// This includes all parameters and interpolation
0066       TH1* GetSampleHist(const std::string& channel,
0067           const std::string& sample, const std::string& name="");
0068 
0069       /// Get the total channel histogram for this channel
0070       TH1* GetChannelHist(const std::string& channel, const std::string& name="");
0071 
0072       /// Get a histogram from the dataset for this channel
0073       TH1* GetDataHist(RooDataSet* data, const std::string& channel, const std::string& name="");
0074 
0075       /// Get a stack of all samples in a channel
0076       THStack* GetChannelStack(const std::string& channel, const std::string& name="");
0077 
0078       /// Draw a stack of the channel, and include data if the pointer is supplied
0079       void DrawChannel(const std::string& channel, RooDataSet* data=nullptr);
0080 
0081       /// Get the RooAbsReal function for a given sample in a given channel
0082       RooAbsReal* SampleFunction(const std::string& channel, const std::string& sample);
0083 
0084       /// Get the set of observables for a given channel
0085       RooArgSet* GetObservableSet(const std::string& channel);
0086 
0087       /// Get the constraint term for a given systematic (alpha or gamma)
0088       RooAbsReal* GetConstraintTerm(const std::string& parameter);
0089 
0090       /// Get the uncertainty based on the constraint term for a given systematic
0091       double GetConstraintUncertainty(const std::string& parameter);
0092 
0093       /// Find a node in the pdf and replace it with a new node
0094       /// These nodes can be functions, pdf's, RooRealVar's, etc
0095       /// Will do minimal checking to make sure the replacement makes sense
0096       void ReplaceNode(const std::string& ToReplace, RooAbsArg* ReplaceWith);
0097 
0098       // Set any RooRealVar's const (or not const) if they match
0099       // the supplied regular expression
0100       void SetConstant(const std::string& regExpr=".*", bool constant=true);
0101 
0102       void SetMaxBinToPrint(int max) { _maxBinToPrint = max; }
0103       int GetMaxBinToPrint() const { return _maxBinToPrint; }
0104 
0105       void SetMinBinToPrint(int min) { _minBinToPrint = min; }
0106       int GetMinBinToPrint() const { return _minBinToPrint; }
0107 
0108       /// Get the model for this channel
0109       RooAbsPdf* GetModel() const { return fModel; }
0110 
0111       //
0112       RooAbsPdf* GetChannelPdf(const std::string& channel);
0113 
0114 
0115       std::vector< std::string > GetChannelSampleList(const std::string& channel);
0116 
0117       // Return the RooRealVar by the same name used in the model
0118       // If not found, return nullptr
0119       RooRealVar* var(const std::string& varName) const;
0120 
0121       /*
0122       // Add a channel to the pdf
0123       // Combine the data if it is provided
0124       void AddChannel(const std::string& channel, RooAbsPdf* pdf, RooDataSet* data=nullptr);
0125       */
0126 
0127       /*
0128       // Add a constraint term to the pdf
0129       // This method requires that the pdf NOT be simultaneous
0130       void AddConstraintTerm(RooAbsArg* constraintTerm);
0131 
0132       // Add a constraint term to the pdf of a particular channel
0133       // This method requires that the pdf be simultaneous
0134       // OR that the channel string match the channel that the pdf represents
0135       void AddConstraintTerm(RooAbsArg* constraintTerm, const std::string& channel);
0136       */
0137 
0138     protected:
0139 
0140       /// Set the title and bin widths
0141       void SetPrintWidths(const std::string& channel);
0142 
0143       /// Fetch the node information for the pdf in question, and
0144       /// save it in the various collections in this class
0145       void _GetNodes(ModelConfig* mc);
0146       void _GetNodes(RooAbsPdf* model, const RooArgSet* observables);
0147 
0148       /// Print a histogram's contents to the screen
0149       /// void PrettyPrintHistogram(TH1* hist);
0150       void PrintMultiDimHist(TH1* hist, int bin_print_width);
0151 
0152       /// Make a histogram from a function
0153       /// Edit so it can take a RooArgSet of parameters
0154       TH1* MakeHistFromRooFunction( RooAbsReal* func, RooArgList vars, std::string name="Hist" );
0155 
0156       /// Get a map of sample names to their functions for a particular channel
0157       std::map< std::string, RooAbsReal*> GetSampleFunctionMap(const std::string& channel);
0158 
0159     private:
0160 
0161       /// The HistFactory Pdf Pointer
0162       RooAbsPdf* fModel;
0163 
0164       /// The observables
0165       RooArgSet* fObservables;
0166 
0167       int _minBinToPrint;
0168       int _maxBinToPrint;
0169 
0170       int _label_print_width;
0171       int _bin_print_width;
0172 
0173       /// The list of channels
0174       std::vector<std::string> fChannelNameVec;
0175 
0176       /// Map of channel names to their full pdf's
0177       std::map< std::string, RooAbsPdf* > fChannelPdfMap;
0178 
0179       /// Map of channel names to pdf without constraint
0180       std::map< std::string, RooAbsPdf* > fChannelSumNodeMap;
0181 
0182       /// Map of channel names to their set of ovservables
0183       std::map< std::string, RooArgSet*> fChannelObservMap;
0184 
0185       /// Map of Map of Channel, Sample names to Function Nodes
0186       /// Used by doing: fChannelSampleFunctionMap["MyChannel"]["MySample"]
0187       std::map< std::string, std::map< std::string, RooAbsReal*> > fChannelSampleFunctionMap;
0188 
0189       /// Internal method implementation of finding a daughter node
0190       /// from a parent node (looping over all generations)
0191       RooAbsArg* findChild(const std::string& name, RooAbsReal* parent) const;
0192 
0193       /// Recursively get all products of products
0194       RooArgSet _GetAllProducts(RooProduct* node);
0195 
0196 
0197     protected:
0198       ClassDef(RooStats::HistFactory::HistFactoryNavigation,2)
0199 
0200     };
0201 
0202   }
0203 }
0204 #endif // INCLUDE_HISTFACTORYNAVIGATION_H