Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:20

0001 #ifndef HepMCCandidate_FlavorHistoryEvent_h
0002 #define HepMCCandidate_FlavorHistoryEvent_h
0003 
0004 /** \class reco::FlavorHistoryEvent
0005  *
0006  * Stores a vector of information about the flavor history of partons
0007  * as well as a classification of the event. 
0008  *
0009  * It will return the following:
0010  *    nb = number of genjets that are matched to b partons
0011  *    nc = number of genjets that are matched to c partons
0012  * 
0013  * This can be used to classify the event, for instance, as W+bb (2 b partons),
0014  * W+c (1 c parton), etc.
0015  *
0016  * \author: Salvatore Rappoccio (JHU)
0017  *
0018  */
0019 
0020 // -------------------------------------------------------------
0021 // Identify the class of the event
0022 //
0023 // Reports nb, nc, nlight genjets that are matched
0024 // to partons.
0025 //
0026 // -------------------------------------------------------------
0027 
0028 #include "DataFormats/Common/interface/Ptr.h"
0029 #include "DataFormats/Common/interface/OwnVector.h"
0030 #include "DataFormats/Common/interface/Handle.h"
0031 #include "DataFormats/Common/interface/View.h"
0032 #include "DataFormats/HepMCCandidate/interface/FlavorHistory.h"
0033 
0034 #include <fstream>
0035 
0036 namespace reco {
0037 
0038   namespace helpers {
0039     // Helper class to decide which type of event this should be classified as.
0040     //
0041     // Decision is based on a priority weighting of:
0042     //  1. flavor (5 > 4)
0043     //  2. type:
0044     //      2a. Flavor decay
0045     //      2b. Matrix element
0046     //      2c. Flavor excitation
0047     //      2d. Gluon splitting
0048     //  3. delta R (if applicable)
0049     //
0050     struct FlavorHistoryEventHelper {
0051       FlavorHistoryEventHelper(int iflavor, FlavorHistory::FLAVOR_T iflavorSource, double idR)
0052           : flavor(iflavor), flavorSource(iflavorSource), dR(idR) {}
0053       ~FlavorHistoryEventHelper() {}
0054 
0055       // Data members
0056       int flavor;                            // pdg id
0057       FlavorHistory::FLAVOR_T flavorSource;  // flavor source
0058       double dR;                             // if there is a sister, dR
0059 
0060       // Comparison operators
0061       bool operator<(FlavorHistoryEventHelper const& right) const {
0062         if (flavor > right.flavor)
0063           return false;
0064         if (flavorSource > right.flavorSource)
0065           return false;
0066         if (dR > right.dR)
0067           return false;
0068         return true;
0069       }
0070 
0071       bool operator==(FlavorHistoryEventHelper const& right) const {
0072         return flavor == right.flavor && flavorSource == right.flavorSource && dR == right.dR;
0073       }
0074 
0075       friend std::ostream& operator<<(std::ostream& out, FlavorHistoryEventHelper helper) {
0076         char buff[1000];
0077         sprintf(buff, "Flavor = %2d, type = %2d, dR = %6f", helper.flavor, helper.flavorSource, helper.dR);
0078         out << buff << std::endl;
0079         return out;
0080       }
0081     };
0082   }  // namespace helpers
0083 
0084   class FlavorHistoryEvent {
0085   public:
0086     // convenient typedefs
0087     typedef FlavorHistory value_type;
0088     typedef std::vector<value_type> collection_type;
0089     typedef collection_type::size_type size_type;
0090     typedef collection_type::iterator iterator;
0091     typedef collection_type::const_iterator const_iterator;
0092     typedef collection_type::reverse_iterator reverse_iterator;
0093     typedef collection_type::const_reverse_iterator const_reverse_iterator;
0094     typedef collection_type::pointer pointer;
0095     typedef collection_type::const_pointer const_pointer;
0096     typedef collection_type::reference reference;
0097     typedef collection_type::const_reference const_reference;
0098     typedef FlavorHistory::FLAVOR_T flavor_type;
0099 
0100     FlavorHistoryEvent() { clear(); }
0101     ~FlavorHistoryEvent() {}
0102 
0103     // Set up the heavy flavor content
0104     void cache();
0105     bool isCached() const { return cached_; }
0106 
0107     // Accessors to heavy flavor content
0108     unsigned int nb() const {
0109       if (isCached())
0110         return nb_;
0111       else
0112         return 0;
0113     }
0114     unsigned int nc() const {
0115       if (isCached())
0116         return nc_;
0117       else
0118         return 0;
0119     }
0120 
0121     // Accessor to maximum delta R between highest flavor constituents
0122     double deltaR() const {
0123       if (isCached())
0124         return dR_;
0125       else
0126         return -1.0;
0127     }
0128     unsigned int highestFlavor() const {
0129       if (isCached())
0130         return highestFlavor_;
0131       else
0132         return 0;
0133     }
0134     flavor_type flavorSource() const {
0135       if (isCached())
0136         return flavorSource_;
0137       else
0138         return FlavorHistory::FLAVOR_NULL;
0139     }
0140 
0141     // vector interface.. when mutable, make sure cache is set to false.
0142     // only allow const access via begin, end, rbegin, rend
0143     size_type size() const { return histories_.size(); }
0144     const_iterator begin() const { return histories_.begin(); }
0145     const_iterator end() const { return histories_.end(); }
0146     const_reverse_iterator rbegin() const { return histories_.rbegin(); }
0147     const_reverse_iterator rend() const { return histories_.rend(); }
0148     // here is the proper mutable interface... this is done so that the cache is
0149     // set by us, not the user
0150     void push_back(const value_type& v) {
0151       cached_ = false;
0152       histories_.push_back(v);
0153     }
0154     void resize(size_t n) {
0155       cached_ = false;
0156       histories_.resize(n);
0157     }
0158     void clear() {
0159       cached_ = false;
0160       histories_.clear();
0161       nb_ = nc_ = 0;
0162       dR_ = 0.0;
0163       highestFlavor_ = 0;
0164       flavorSource_ = FlavorHistory::FLAVOR_NULL;
0165     }
0166 
0167   protected:
0168     collection_type histories_;   // FlavorHistory vector
0169     bool cached_;                 // cached flag
0170     unsigned int nb_;             // number of b quark partons with a matched jet
0171     unsigned int nc_;             // number of c quark partons with a matched jet
0172     double dR_;                   // maximum delta R between highest flavor constituents
0173     unsigned int highestFlavor_;  // highest flavor, corresponds to dR
0174     flavor_type flavorSource_;    // flavor source
0175   };
0176 
0177 }  // namespace reco
0178 
0179 #endif