Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:22

0001 #ifndef __DataFormats_PatCandidates_VIDResult_H__
0002 #define __DataFormats_PatCandidates_VIDResult_H__
0003 
0004 #include <map>
0005 #include <vector>
0006 #include <string>
0007 
0008 /*********
0009  *
0010  * Class: vid::CutFlowResult
0011  * Author: L. Gray (FNAL)
0012  * 
0013  * A synthesis of the output of a VID selector into an easily
0014  * manipulated class, such that cuts can be masked and sidebands
0015  * created without major intervention on the part of the person
0016  * doing analysis.
0017  *
0018  * The class is self-describing and the original cut-names, the
0019  * values cut upon, the result of each cut used, and final cutflow 
0020  * decision can be accessed with this class. Using this information
0021  * the cut flow can be masked interactively by the user, allowing
0022  * for a large degree of flexibility at the analysis level.
0023  *
0024  *********/
0025 
0026 namespace vid {
0027   class CutFlowResult {
0028     template <class T>
0029     friend class VersionedSelector;
0030 
0031   public:
0032     CutFlowResult() : bitmap_(0) {}
0033     CutFlowResult(const std::string& name,
0034                   const std::string& hash,
0035                   const std::map<std::string, unsigned>& n2idx,
0036                   const std::vector<double>& values,
0037                   unsigned bitmap,
0038                   unsigned mask = 0);
0039 
0040     // get the original name of this cutflow
0041     const std::string& cutFlowName() const { return name_; }
0042     // get the md5 hash for this cutflow
0043     const std::string& cutFlowHash() const { return hash_; }
0044     // did this cutflow (in its current state!) pass?
0045     bool cutFlowPassed() const {
0046       const unsigned all_pass = (1 << indices_.size()) - 1;
0047       return (all_pass & bitmap_) == all_pass;
0048     }
0049     // how many cuts in this cutflow?
0050     size_t cutFlowSize() const { return indices_.size(); }
0051 
0052     // get the name of a cut in the cutflow
0053     // indexed by order it was executed
0054     const std::string& getNameAtIndex(const unsigned idx) const;
0055 
0056     // get the individual cut result (pass/fail) either by name or by index
0057     bool getCutResultByIndex(const unsigned idx) const;
0058     bool getCutResultByName(const std::string& name) const;
0059 
0060     // return true if the cut as index/name is masked out
0061     bool isCutMasked(const unsigned idx) const;
0062     bool isCutMasked(const std::string& name) const;
0063 
0064     // get the value of variable that was cut on, either by name or by index
0065     double getValueCutUpon(const unsigned idx) const;
0066     double getValueCutUpon(const std::string& name) const;
0067 
0068     // create a new copy of this cutflow masking out the listed cuts
0069     // can be done either by name or by index
0070     CutFlowResult getCutFlowResultMasking(const unsigned idx) const;
0071     CutFlowResult getCutFlowResultMasking(const std::string& name) const;
0072 
0073     CutFlowResult getCutFlowResultMasking(const std::vector<unsigned>& idxs) const;
0074     CutFlowResult getCutFlowResultMasking(const std::vector<std::string>& names) const;
0075 
0076   private:
0077     std::string name_, hash_;
0078     unsigned bitmap_, mask_;
0079     std::vector<double> values_;
0080     std::vector<std::string> names_;
0081     std::vector<unsigned> indices_;
0082 
0083     CutFlowResult(const std::string& name,
0084                   const std::string& hash,
0085                   const std::vector<std::string>& names,
0086                   const std::vector<unsigned>& indices,
0087                   const std::vector<double>& values,
0088                   unsigned bitmap,
0089                   unsigned mask)
0090         : name_(name), hash_(hash), bitmap_(bitmap), mask_(mask), values_(values), names_(names), indices_(indices) {}
0091 
0092     bool getMaskBit(const unsigned idx) const { return (bool)(0x1 & (mask_ >> idx)); }
0093 
0094     bool getCutBit(const unsigned idx) const { return (bool)(0x1 & (bitmap_ >> idx)); }
0095 
0096     double getCutValue(const unsigned idx) const { return values_[idx]; }
0097   };
0098 }  // namespace vid
0099 
0100 #endif