CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DataFormats/HepMCCandidate/interface/FlavorHistoryEvent.h

Go to the documentation of this file.
00001 #ifndef HepMCCandidate_FlavorHistoryEvent_h
00002 #define HepMCCandidate_FlavorHistoryEvent_h
00003 
00021 // -------------------------------------------------------------
00022 // Identify the class of the event
00023 // 
00024 // Reports nb, nc, nlight genjets that are matched
00025 // to partons.
00026 // 
00027 // -------------------------------------------------------------
00028 
00029 
00030 #include "DataFormats/Common/interface/Ptr.h"
00031 #include "DataFormats/Common/interface/OwnVector.h"
00032 #include "DataFormats/Common/interface/Handle.h"
00033 #include "DataFormats/Common/interface/View.h"
00034 #include "DataFormats/HepMCCandidate/interface/FlavorHistory.h"
00035 
00036 #include <fstream>
00037 
00038 namespace reco {
00039 
00040   namespace helpers {
00041     // Helper class to decide which type of event this should be classified as.
00042     // 
00043     // Decision is based on a priority weighting of:
00044     //  1. flavor (5 > 4)
00045     //  2. type:
00046     //      2a. Flavor decay
00047     //      2b. Matrix element
00048     //      2c. Flavor excitation
00049     //      2d. Gluon splitting
00050     //  3. delta R (if applicable)
00051     //
00052     struct FlavorHistoryEventHelper{
00053 
00054       FlavorHistoryEventHelper( int iflavor,
00055                                 FlavorHistory::FLAVOR_T iflavorSource,
00056                                 double idR ) :
00057         flavor(iflavor), flavorSource(iflavorSource), dR(idR)
00058       {}
00059       ~FlavorHistoryEventHelper() {}
00060 
00061 
00062       // Data members
00063       int                     flavor;         // pdg id
00064       FlavorHistory::FLAVOR_T flavorSource;   // flavor source
00065       double                  dR;             // if there is a sister, dR
00066 
00067       // Comparison operators
00068       bool operator< ( FlavorHistoryEventHelper const & right) const {
00069         if ( flavor       > right.flavor       ) return false;
00070         if ( flavorSource > right.flavorSource ) return false;
00071         if ( dR           > right.dR           ) return false;
00072         return true;
00073       }
00074 
00075       bool operator== ( FlavorHistoryEventHelper const & right) const {
00076         return flavor == right.flavor &&
00077           flavorSource == right.flavorSource &&
00078           dR == right.dR;
00079       }
00080 
00081       friend std::ostream & operator<< ( std::ostream & out, 
00082                                          FlavorHistoryEventHelper helper ) {
00083         char buff[1000];
00084         sprintf(buff, "Flavor = %2d, type = %2d, dR = %6f",
00085                 helper.flavor, helper.flavorSource, helper.dR );
00086         out << buff << std::endl;
00087         return out;
00088       }
00089     };
00090   }
00091 
00092 class FlavorHistoryEvent {
00093 public:
00094 
00095   // convenient typedefs
00096   typedef FlavorHistory                           value_type;
00097   typedef std::vector<value_type>                 collection_type;
00098   typedef collection_type::size_type              size_type;
00099   typedef collection_type::iterator               iterator;
00100   typedef collection_type::const_iterator         const_iterator;
00101   typedef collection_type::reverse_iterator       reverse_iterator;
00102   typedef collection_type::const_reverse_iterator const_reverse_iterator;
00103   typedef collection_type::pointer                pointer;
00104   typedef collection_type::const_pointer          const_pointer;
00105   typedef collection_type::reference              reference;
00106   typedef collection_type::const_reference        const_reference;
00107   typedef FlavorHistory::FLAVOR_T                 flavor_type;
00108 
00109   FlavorHistoryEvent() { clear(); }
00110   ~FlavorHistoryEvent(){}
00111 
00112   // Set up the heavy flavor content
00113   void                 cache();
00114   bool                 isCached() const { return cached_; }
00115 
00116   // Accessors to heavy flavor content
00117   unsigned int         nb() const { if ( isCached() ) return nb_; else return 0;}
00118   unsigned int         nc() const { if ( isCached() ) return nc_; else return 0;}
00119 
00120   // Accessor to maximum delta R between highest flavor constituents
00121   double               deltaR() const { if ( isCached() ) return dR_; else return -1.0; }
00122   unsigned int         highestFlavor() const { if ( isCached() ) return highestFlavor_; else return 0; }
00123   flavor_type          flavorSource() const { if ( isCached() ) return flavorSource_; else return FlavorHistory::FLAVOR_NULL; }
00124 
00125   // vector interface.. when mutable, make sure cache is set to false.
00126   // only allow const access via begin, end, rbegin, rend
00127   size_type               size()   const { return histories_.size(); }
00128   const_iterator          begin()  const { return histories_.begin(); }
00129   const_iterator          end()    const { return histories_.end(); }
00130   const_reverse_iterator  rbegin() const { return histories_.rbegin(); }
00131   const_reverse_iterator  rend()   const { return histories_.rend(); }
00132   // here is the proper mutable interface... this is done so that the cache is
00133   // set by us, not the user
00134   void                    push_back( value_type v ) { cached_ = false; histories_.push_back(v); }
00135   void                    resize( size_t n )        { cached_ = false; histories_.resize(n); }
00136   void                    clear() { cached_ = false; histories_.clear(); nb_ = nc_ = 0; dR_ = 0.0; highestFlavor_ = 0; flavorSource_ = FlavorHistory::FLAVOR_NULL; }
00137 
00138 protected:
00139   collection_type         histories_;           // FlavorHistory vector
00140   bool                    cached_;              // cached flag
00141   unsigned int            nb_;                  // number of b quark partons with a matched jet
00142   unsigned int            nc_;                  // number of c quark partons with a matched jet
00143   double                  dR_;                  // maximum delta R between highest flavor constituents
00144   unsigned int            highestFlavor_;       // highest flavor, corresponds to dR
00145   flavor_type             flavorSource_;        // flavor source
00146 };
00147 
00148 }
00149 
00150 #endif