CMS 3D CMS Logo

VIDNestedWPBitmapProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PhysicsTools/NanoAOD
4 // Class: VIDNestedWPBitmapProducer
5 //
13 //
14 // Original Author: Marco Peruzzi
15 // Created: Mon, 04 Sep 2017 22:43:53 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
31 
34 
36 
37 //
38 // class declaration
39 //
40 
41 template <typename T>
43 public:
45  : src_(consumes<edm::View<T>>(iConfig.getParameter<edm::InputTag>("src"))), isInit_(false) {
46  auto const& vwp = iConfig.getParameter<std::vector<std::string>>("WorkingPoints");
47  for (auto const& wp : vwp) {
48  src_bitmaps_.push_back(consumes<edm::ValueMap<unsigned int>>(edm::InputTag(wp + std::string("Bitmap"))));
50  }
51  nWP = src_bitmaps_.size();
52  produces<edm::ValueMap<int>>();
53  }
54 
55  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
56 
57 private:
58  void produce(edm::Event&, const edm::EventSetup&) override;
59 
60  // ----------member data ---------------------------
61 
63  std::vector<edm::EDGetTokenT<edm::ValueMap<unsigned int>>> src_bitmaps_;
64  std::vector<edm::EDGetTokenT<edm::ValueMap<vid::CutFlowResult>>> src_cutflows_;
65 
66  unsigned int nWP;
67  unsigned int nBits;
68  unsigned int nCuts = 0;
69  std::vector<unsigned int> res_;
70  bool isInit_;
71 
72  void initNCuts(unsigned int);
73 };
74 
75 template <typename T>
78  iEvent.getByToken(src_, src);
79  std::vector<edm::Handle<edm::ValueMap<unsigned int>>> src_bitmaps(nWP);
80  for (unsigned int i = 0; i < nWP; i++)
81  iEvent.getByToken(src_bitmaps_[i], src_bitmaps[i]);
82  std::vector<edm::Handle<edm::ValueMap<vid::CutFlowResult>>> src_cutflows(nWP);
83  for (unsigned int i = 0; i < nWP; i++)
84  iEvent.getByToken(src_cutflows_[i], src_cutflows[i]);
85 
86  std::vector<unsigned int> res;
87 
88  for (auto const& obj : src->ptrs()) {
89  for (unsigned int j = 0; j < nWP; j++) {
90  auto cutflow = (*(src_cutflows[j]))[obj];
91  if (!isInit_)
92  initNCuts(cutflow.cutFlowSize());
93  if (cutflow.cutFlowSize() != nCuts)
94  throw cms::Exception("Configuration", "Trying to compress VID bitmaps for cutflows of different size");
95  auto bitmap = (*(src_bitmaps[j]))[obj];
96  for (unsigned int k = 0; k < nCuts; k++) {
97  if (j == 0)
98  res_[k] = 0;
99  if (bitmap >> k & 1) {
100  if (res_[k] != j)
101  throw cms::Exception(
102  "Configuration",
103  "Trying to compress VID bitmaps which are not nested in the correct order for all cuts");
104  res_[k]++;
105  }
106  }
107  }
108 
109  int out = 0;
110  for (unsigned int k = 0; k < nCuts; k++)
111  out |= (res_[k] << (nBits * k));
112  res.push_back(out);
113  }
114 
115  auto resV = std::make_unique<edm::ValueMap<int>>();
117  filler.insert(src, res.begin(), res.end());
118  filler.fill();
119 
120  iEvent.put(std::move(resV));
121 }
122 
123 template <typename T>
125  nCuts = n;
126  nBits = ceil(log2(nWP + 1));
127  if (nBits * nCuts > sizeof(int) * 8)
128  throw cms::Exception("Configuration", "Integer cannot contain the compressed VID bitmap information");
129  res_.resize(nCuts, 0);
130  isInit_ = true;
131 }
132 
133 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
134 template <typename T>
137  desc.add<edm::InputTag>("src")->setComment("input physics object collection");
138  desc.add<std::vector<std::string>>("WorkingPoints")->setComment("working points to be saved in the bitmask");
140  if (typeid(T) == typeid(pat::Electron))
141  modname += "Ele";
142  else if (typeid(T) == typeid(pat::Photon))
143  modname += "Pho";
144  modname += "VIDNestedWPBitmapProducer";
145  descriptions.add(modname, desc);
146 }
147 
150 
151 //define this as a plug-in
VIDNestedWPBitmapProducer::src_cutflows_
std::vector< edm::EDGetTokenT< edm::ValueMap< vid::CutFlowResult > > > src_cutflows_
Definition: VIDNestedWPBitmapProducer.cc:64
mps_fire.i
i
Definition: mps_fire.py:428
VIDNestedWPBitmapProducer::initNCuts
void initNCuts(unsigned int)
Definition: VIDNestedWPBitmapProducer.cc:124
VIDNestedWPBitmapProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: VIDNestedWPBitmapProducer.cc:76
funct::false
false
Definition: Factorize.h:29
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
sistrip::View
View
Definition: ConstantsForView.h:26
VIDNestedWPBitmapProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: VIDNestedWPBitmapProducer.cc:135
pfClustersFromHGC3DClusters_cfi.wp
wp
Definition: pfClustersFromHGC3DClusters_cfi.py:20
VIDNestedWPBitmapProducer::nWP
unsigned int nWP
Definition: VIDNestedWPBitmapProducer.cc:66
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
Photon.h
pat::Photon
Analysis-level Photon class.
Definition: Photon.h:46
VIDNestedWPBitmapProducer::nBits
unsigned int nBits
Definition: VIDNestedWPBitmapProducer.cc:67
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EleVIDNestedWPBitmapProducer
VIDNestedWPBitmapProducer< pat::Electron > EleVIDNestedWPBitmapProducer
Definition: VIDNestedWPBitmapProducer.cc:148
EDProducer.h
edm::Handle
Definition: AssociativeIterator.h:50
VIDNestedWPBitmapProducer
Definition: VIDNestedWPBitmapProducer.cc:42
VIDNestedWPBitmapProducer::src_bitmaps_
std::vector< edm::EDGetTokenT< edm::ValueMap< unsigned int > > > src_bitmaps_
Definition: VIDNestedWPBitmapProducer.cc:63
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
reco::ceil
constexpr int32_t ceil(float num)
Definition: constexpr_cmath.h:7
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
dqmdumpme.k
k
Definition: dqmdumpme.py:60
VIDNestedWPBitmapProducer::isInit_
bool isInit_
Definition: VIDNestedWPBitmapProducer.cc:70
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
VIDNestedWPBitmapProducer::VIDNestedWPBitmapProducer
VIDNestedWPBitmapProducer(const edm::ParameterSet &iConfig)
Definition: VIDNestedWPBitmapProducer.cc:44
VIDNestedWPBitmapProducer::res_
std::vector< unsigned int > res_
Definition: VIDNestedWPBitmapProducer.cc:69
edm::ParameterSet
Definition: ParameterSet.h:47
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
Event.h
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
VIDNestedWPBitmapProducer::nCuts
unsigned int nCuts
Definition: VIDNestedWPBitmapProducer.cc:68
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:58
res
Definition: Electron.h:6
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
VIDCutFlowResult.h
Frameworkfwd.h
T
long double T
Definition: Basic3DVectorLD.h:48
edm::ValueMap
Definition: ValueMap.h:107
Exception
Definition: hltDiff.cc:245
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Electron.h
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
cms::Exception
Definition: Exception.h:70
edm::helper::Filler
Definition: ValueMap.h:22
pat::Electron
Analysis-level electron class.
Definition: Electron.h:51
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
PhoVIDNestedWPBitmapProducer
VIDNestedWPBitmapProducer< pat::Photon > PhoVIDNestedWPBitmapProducer
Definition: VIDNestedWPBitmapProducer.cc:149
VIDNestedWPBitmapProducer::src_
edm::EDGetTokenT< edm::View< T > > src_
Definition: VIDNestedWPBitmapProducer.cc:62
StreamID.h
timingPdfMaker.modname
modname
Definition: timingPdfMaker.py:218
edm::InputTag
Definition: InputTag.h:15