CMS 3D CMS Logo

SuperclusValueMapProducer.cc
Go to the documentation of this file.
7 
13 
15 
16 // copy-pasted from ElectronHEEPIDValueMapProducer
17 
19 public:
21  ~SuperclusValueMapProducer() = default;
22 
23 private:
24  void produce(edm::Event&, const edm::EventSetup&) override;
25 
26  std::vector<edm::EDGetTokenT<pat::PackedCandidateCollection>> setTokens(const std::vector<edm::InputTag>& tags);
27 
28  template <typename T>
29  static void writeValueMap(edm::Event& iEvent,
31  const std::vector<T>& values,
32  const std::string& label);
33 
34  std::vector<SuperclusTkIsolFromCands::PIDVeto> candVetos_;
35 
36  const std::vector<edm::InputTag> candTags_;
37  const std::vector<edm::EDGetTokenT<pat::PackedCandidateCollection>> candTokens_;
41 
43 
44  const std::string superclusTkIsoLabel_ = "superclusTkIso";
45 };
46 
48  : candTags_(iConfig.getParameter<std::vector<edm::InputTag>>("cands")),
49  candTokens_(setTokens(candTags_)),
50  scToken_(consumes<edm::View<reco::SuperCluster>>(iConfig.getParameter<edm::InputTag>("srcSc"))),
51  pvToken_(consumes<edm::View<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("srcPv"))),
52  bsToken_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("srcBs"))),
53  trkIsoCalcCfg_(iConfig.getParameter<edm::ParameterSet>("trkIsoConfig")) {
54  auto fillVetos = [](const auto& in, auto& out) {
55  std::transform(in.begin(), in.end(), std::back_inserter(out), SuperclusTkIsolFromCands::pidVetoFromStr);
56  };
57 
58  fillVetos(iConfig.getParameter<std::vector<std::string>>("candVetos"), candVetos_);
59 
60  if (candVetos_.size() != candTags_.size())
61  throw cms::Exception("ConfigError") << "Error candVetos should be the same size as cands" << std::endl;
62 
63  produces<edm::ValueMap<float>>(superclusTkIsoLabel_);
64 }
65 
68  iEvent.getByToken(scToken_, scHandle);
69 
71  iEvent.getByToken(pvToken_, pvHandle);
72 
74  iEvent.getByToken(bsToken_, bsHandle);
75 
77 
78  if (pvHandle.isValid() && !pvHandle->empty())
79  pos = pvHandle->front().position(); // first try PV
80  else
81  pos = (*bsHandle).position(); // fall back to BS
82 
83  std::vector<edm::Handle<pat::PackedCandidateCollection>> candHandles(candTokens_.size());
84  std::vector<std::unique_ptr<SuperclusTkIsolFromCands>> tkIsoCalc;
85 
86  for (unsigned idx = 0; idx < candTokens_.size(); idx++) {
87  iEvent.getByToken(candTokens_.at(idx), candHandles.at(idx));
88  tkIsoCalc.push_back(
89  std::make_unique<SuperclusTkIsolFromCands>(trkIsoCalcCfg_, *(candHandles.at(idx)), candVetos_.at(idx)));
90  }
91 
92  std::vector<float> vecTkIso;
93  vecTkIso.reserve(scHandle->size());
94 
95  for (const auto& sc : *scHandle) {
96  float tkIso = 0.;
97 
98  for (auto& calc : tkIsoCalc)
99  tkIso += (*calc)(sc, pos).ptSum;
100 
101  vecTkIso.push_back(tkIso);
102  }
103 
104  writeValueMap(iEvent, scHandle, vecTkIso, superclusTkIsoLabel_);
105 }
106 
107 std::vector<edm::EDGetTokenT<pat::PackedCandidateCollection>> SuperclusValueMapProducer::setTokens(
108  const std::vector<edm::InputTag>& tags) {
109  std::vector<edm::EDGetTokenT<pat::PackedCandidateCollection>> out;
110 
111  for (const auto& tag : tags)
112  out.push_back(consumes<pat::PackedCandidateCollection>(tag));
113 
114  return out;
115 }
116 
117 template <typename T>
120  const std::vector<T>& values,
121  const std::string& label) {
122  std::unique_ptr<edm::ValueMap<T>> valMap(new edm::ValueMap<T>());
123  typename edm::ValueMap<T>::Filler filler(*valMap);
124  filler.insert(handle, values.begin(), values.end());
125  filler.fill();
126  iEvent.put(std::move(valMap), label);
127 }
128 
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::vector< SuperclusTkIsolFromCands::PIDVeto > candVetos_
std::vector< edm::EDGetTokenT< pat::PackedCandidateCollection > > setTokens(const std::vector< edm::InputTag > &tags)
SuperclusValueMapProducer(const edm::ParameterSet &)
const std::vector< edm::InputTag > candTags_
char const * label
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< edm::View< reco::SuperCluster > > scToken_
const std::vector< edm::EDGetTokenT< pat::PackedCandidateCollection > > candTokens_
static void writeValueMap(edm::Event &iEvent, const edm::Handle< edm::View< reco::SuperCluster >> &handle, const std::vector< T > &values, const std::string &label)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const SuperclusTkIsolFromCands::Configuration trkIsoCalcCfg_
~SuperclusValueMapProducer()=default
static PIDVeto pidVetoFromStr(const std::string &vetoStr)
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const edm::EDGetTokenT< reco::BeamSpot > bsToken_
bool isValid() const
Definition: HandleBase.h:70
const edm::EDGetTokenT< edm::View< reco::Vertex > > pvToken_
fixed size matrix
HLT enums.
void produce(edm::Event &, const edm::EventSetup &) override
def move(src, dest)
Definition: eostools.py:511
unsigned transform(const HcalDetId &id, unsigned transformCode)