Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:34

0001 #include "PhysicsTools/JetCharge/plugins/JetChargeProducer.h"
0002 
0003 JetChargeProducer::JetChargeProducer(const edm::ParameterSet &cfg)
0004     : srcToken_(consumes<reco::JetTracksAssociationCollection>(cfg.getParameter<edm::InputTag>("src"))), algo_(cfg) {
0005   produces<JetChargeCollection>();
0006 }
0007 
0008 void JetChargeProducer::produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const {
0009   edm::Handle<reco::JetTracksAssociationCollection> hJTAs;
0010   iEvent.getByToken(srcToken_, hJTAs);
0011   typedef reco::JetTracksAssociationCollection::const_iterator IT;
0012   typedef edm::RefToBase<reco::Jet> JetRef;
0013 
0014   if (hJTAs->keyProduct().isNull()) {
0015     // need to work around this bug someway, altough it's not stricly my fault

0016     iEvent.put(std::make_unique<JetChargeCollection>());
0017     return;
0018   }
0019   auto ret = std::make_unique<JetChargeCollection>(hJTAs->keyProduct());
0020   for (IT it = hJTAs->begin(), ed = hJTAs->end(); it != ed; ++it) {
0021     const JetRef &jet = it->first;
0022     const reco::TrackRefVector &tracks = it->second;
0023     float val = static_cast<float>(algo_.charge(jet->p4(), tracks));
0024     reco::JetFloatAssociation::setValue(*ret, jet, val);
0025   }
0026 
0027   iEvent.put(std::move(ret));
0028 }