47 bool equal(
const T& lhs,
const T& rhs) {
48 return lhs.superCluster()->seed()->seed().rawId() == rhs.superCluster()->seed()->seed().rawId();
56 if (objColl.isValid()) {
57 for (
auto& objToMatch : objColl->ptrs()) {
76 auto const& vwp = iConfig.
getParameter<std::vector<std::string>>(
"WorkingPoints");
77 for (
auto const&
wp : vwp) {
82 produces<edm::ValueMap<int>>();
94 std::vector<edm::EDGetTokenT<edm::ValueMap<unsigned int>>>
src_bitmaps_;
95 std::vector<edm::EDGetTokenT<edm::ValueMap<vid::CutFlowResult>>>
src_cutflows_;
100 std::vector<unsigned int>
res_;
106 template <
typename T>
111 auto srcForIDHandle =
iEvent.getHandle(srcForIDToken_);
113 std::vector<edm::Handle<edm::ValueMap<unsigned int>>> src_bitmaps(nWP);
114 for (
unsigned int i = 0;
i < nWP;
i++)
115 iEvent.getByToken(src_bitmaps_[
i], src_bitmaps[
i]);
116 std::vector<edm::Handle<edm::ValueMap<vid::CutFlowResult>>> src_cutflows(nWP);
117 for (
unsigned int i = 0;
i < nWP;
i++)
118 iEvent.getByToken(src_cutflows_[
i], src_cutflows[
i]);
120 std::vector<unsigned int>
res;
122 for (
auto const&
obj :
src->ptrs()) {
123 auto objForID = getObjInColl(
obj, srcForIDHandle);
124 for (
unsigned int j = 0;
j < nWP;
j++) {
125 auto cutflow = (*(src_cutflows[
j]))[objForID];
127 initNCuts(cutflow.cutFlowSize());
128 if (cutflow.cutFlowSize() != nCuts)
129 throw cms::Exception(
"Configuration",
"Trying to compress VID bitmaps for cutflows of different size");
130 auto bitmap = (*(src_bitmaps[
j]))[objForID];
131 for (
unsigned int k = 0;
k < nCuts;
k++) {
134 if (bitmap >>
k & 1) {
138 "Trying to compress VID bitmaps which are not nested in the correct order for all cuts");
145 for (
unsigned int k = 0;
k < nCuts;
k++)
146 out |= (res_[
k] << (nBits *
k));
150 auto resV = std::make_unique<edm::ValueMap<int>>();
158 template <
typename T>
161 nBits =
ceil(log2(nWP + 1));
162 if (nBits * nCuts >
sizeof(
int) * 8)
163 throw cms::Exception(
"Configuration",
"Integer cannot contain the compressed VID bitmap information");
164 res_.resize(nCuts, 0);
169 template <
typename T>
174 desc.add<std::vector<std::string>>(
"WorkingPoints")->setComment(
"working points to be saved in the bitmask");
180 modname +=
"VIDNestedWPBitmapProducer";
constexpr int32_t ceil(float num)
T getParameter(std::string const &) const
void produce(edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
std::vector< edm::EDGetTokenT< edm::ValueMap< vid::CutFlowResult > > > src_cutflows_
void initNCuts(unsigned int)
VIDNestedWPBitmapProducer< reco::Photon > PhoVIDNestedWPBitmapProducer
VIDNestedWPBitmapProducer< reco::GsfElectron > EleVIDNestedWPBitmapProducer
bool equal(const T &first, const T &second)
std::vector< unsigned int > res_
VIDNestedWPBitmapProducer(const edm::ParameterSet &iConfig)
edm::EDGetTokenT< edm::View< T > > srcForIDToken_
edm::EDGetTokenT< edm::View< T > > src_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< edm::EDGetTokenT< edm::ValueMap< unsigned int > > > src_bitmaps_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)