File indexing completed on 2024-04-06 12:04:20
0001 #ifndef HepMCCandidate_FlavorHistoryEvent_h
0002 #define HepMCCandidate_FlavorHistoryEvent_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
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
0040
0041
0042
0043
0044
0045
0046
0047
0048
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
0056 int flavor;
0057 FlavorHistory::FLAVOR_T flavorSource;
0058 double dR;
0059
0060
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 }
0083
0084 class FlavorHistoryEvent {
0085 public:
0086
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
0104 void cache();
0105 bool isCached() const { return cached_; }
0106
0107
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
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
0142
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
0149
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_;
0169 bool cached_;
0170 unsigned int nb_;
0171 unsigned int nc_;
0172 double dR_;
0173 unsigned int highestFlavor_;
0174 flavor_type flavorSource_;
0175 };
0176
0177 }
0178
0179 #endif