CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FlavorHistoryEvent.h
Go to the documentation of this file.
1 #ifndef HepMCCandidate_FlavorHistoryEvent_h
2 #define HepMCCandidate_FlavorHistoryEvent_h
3 
20 // -------------------------------------------------------------
21 // Identify the class of the event
22 //
23 // Reports nb, nc, nlight genjets that are matched
24 // to partons.
25 //
26 // -------------------------------------------------------------
27 
33 
34 #include <fstream>
35 
36 namespace reco {
37 
38  namespace helpers {
39  // Helper class to decide which type of event this should be classified as.
40  //
41  // Decision is based on a priority weighting of:
42  // 1. flavor (5 > 4)
43  // 2. type:
44  // 2a. Flavor decay
45  // 2b. Matrix element
46  // 2c. Flavor excitation
47  // 2d. Gluon splitting
48  // 3. delta R (if applicable)
49  //
51  FlavorHistoryEventHelper(int iflavor, FlavorHistory::FLAVOR_T iflavorSource, double idR)
52  : flavor(iflavor), flavorSource(iflavorSource), dR(idR) {}
54 
55  // Data members
56  int flavor; // pdg id
58  double dR; // if there is a sister, dR
59 
60  // Comparison operators
61  bool operator<(FlavorHistoryEventHelper const& right) const {
62  if (flavor > right.flavor)
63  return false;
64  if (flavorSource > right.flavorSource)
65  return false;
66  if (dR > right.dR)
67  return false;
68  return true;
69  }
70 
71  bool operator==(FlavorHistoryEventHelper const& right) const {
72  return flavor == right.flavor && flavorSource == right.flavorSource && dR == right.dR;
73  }
74 
75  friend std::ostream& operator<<(std::ostream& out, FlavorHistoryEventHelper helper) {
76  char buff[1000];
77  sprintf(buff, "Flavor = %2d, type = %2d, dR = %6f", helper.flavor, helper.flavorSource, helper.dR);
78  out << buff << std::endl;
79  return out;
80  }
81  };
82  } // namespace helpers
83 
85  public:
86  // convenient typedefs
88  typedef std::vector<value_type> collection_type;
90  typedef collection_type::iterator iterator;
91  typedef collection_type::const_iterator const_iterator;
92  typedef collection_type::reverse_iterator reverse_iterator;
93  typedef collection_type::const_reverse_iterator const_reverse_iterator;
94  typedef collection_type::pointer pointer;
95  typedef collection_type::const_pointer const_pointer;
97  typedef collection_type::const_reference const_reference;
99 
102 
103  // Set up the heavy flavor content
104  void cache();
105  bool isCached() const { return cached_; }
106 
107  // Accessors to heavy flavor content
108  unsigned int nb() const {
109  if (isCached())
110  return nb_;
111  else
112  return 0;
113  }
114  unsigned int nc() const {
115  if (isCached())
116  return nc_;
117  else
118  return 0;
119  }
120 
121  // Accessor to maximum delta R between highest flavor constituents
122  double deltaR() const {
123  if (isCached())
124  return dR_;
125  else
126  return -1.0;
127  }
128  unsigned int highestFlavor() const {
129  if (isCached())
130  return highestFlavor_;
131  else
132  return 0;
133  }
135  if (isCached())
136  return flavorSource_;
137  else
139  }
140 
141  // vector interface.. when mutable, make sure cache is set to false.
142  // only allow const access via begin, end, rbegin, rend
143  size_type size() const { return histories_.size(); }
144  const_iterator begin() const { return histories_.begin(); }
145  const_iterator end() const { return histories_.end(); }
146  const_reverse_iterator rbegin() const { return histories_.rbegin(); }
147  const_reverse_iterator rend() const { return histories_.rend(); }
148  // here is the proper mutable interface... this is done so that the cache is
149  // set by us, not the user
150  void push_back(const value_type& v) {
151  cached_ = false;
152  histories_.push_back(v);
153  }
154  void resize(size_t n) {
155  cached_ = false;
156  histories_.resize(n);
157  }
158  void clear() {
159  cached_ = false;
160  histories_.clear();
161  nb_ = nc_ = 0;
162  dR_ = 0.0;
163  highestFlavor_ = 0;
165  }
166 
167  protected:
168  collection_type histories_; // FlavorHistory vector
169  bool cached_; // cached flag
170  unsigned int nb_; // number of b quark partons with a matched jet
171  unsigned int nc_; // number of c quark partons with a matched jet
172  double dR_; // maximum delta R between highest flavor constituents
173  unsigned int highestFlavor_; // highest flavor, corresponds to dR
174  flavor_type flavorSource_; // flavor source
175  };
176 
177 } // namespace reco
178 
179 #endif
const_iterator begin() const
const_reverse_iterator rend() const
unsigned int nc() const
collection_type::iterator iterator
collection_type::reverse_iterator reverse_iterator
flavor_type flavorSource() const
const_iterator end() const
FlavorHistoryEventHelper(int iflavor, FlavorHistory::FLAVOR_T iflavorSource, double idR)
uint16_t size_type
collection_type::const_iterator const_iterator
unsigned int nb() const
FlavorHistory::FLAVOR_T flavor_type
void push_back(const value_type &v)
unsigned int highestFlavor() const
bool operator==(FlavorHistoryEventHelper const &right) const
collection_type::const_pointer const_pointer
bool operator<(FlavorHistoryEventHelper const &right) const
friend std::ostream & operator<<(std::ostream &out, FlavorHistoryEventHelper helper)
const_reverse_iterator rbegin() const
collection_type::const_reverse_iterator const_reverse_iterator
collection_type::const_reference const_reference
std::vector< value_type > collection_type
collection_type::reference reference
collection_type::size_type size_type
collection_type::pointer pointer