CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/PhysicsTools/JetCharge/plugins/JetChargeProducer.cc

Go to the documentation of this file.
00001 #include "PhysicsTools/JetCharge/plugins/JetChargeProducer.h"
00002 
00003 JetChargeProducer::JetChargeProducer(const edm::ParameterSet &cfg) :
00004 src_(cfg.getParameter<edm::InputTag>("src")),
00005 algo_(cfg) {
00006     produces<JetChargeCollection>();
00007 }
00008 
00009 void JetChargeProducer::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) {
00010     edm::Handle<reco::JetTracksAssociationCollection> hJTAs;
00011     iEvent.getByLabel(src_, hJTAs);
00012     typedef reco::JetTracksAssociationCollection::const_iterator IT;
00013     typedef edm::RefToBase<reco::Jet>  JetRef;
00014 
00015     if (hJTAs->keyProduct().isNull()) {
00016         // need to work around this bug someway, altough it's not stricly my fault
00017         std::auto_ptr<JetChargeCollection> ret(new JetChargeCollection());
00018         iEvent.put(ret);
00019         return;
00020     }
00021     std::auto_ptr<JetChargeCollection> ret(new JetChargeCollection(hJTAs->keyProduct()));
00022     for (IT it = hJTAs->begin(), ed = hJTAs->end(); it != ed; ++it) {
00023         const JetRef &jet = it->first;
00024         const reco::TrackRefVector &tracks = it->second;
00025         float  val = static_cast<float>( algo_.charge(jet->p4(), tracks) );
00026         reco::JetFloatAssociation::setValue(*ret, jet, val);
00027     }
00028 
00029     iEvent.put(ret);        
00030 }