CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/RecoJets/JetAssociationProducers/src/JetExtender.cc

Go to the documentation of this file.
00001 // \class JetExtender JetExtender.cc 
00002 //
00003 // Combines different Jet associations into single compact object
00004 // which extends basic Jet information
00005 // Fedor Ratnikov Sep. 10, 2007
00006 // $Id: JetExtender.cc,v 1.4 2007/10/01 19:24:45 fedor Exp $
00007 //
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 
00010 #include "FWCore/Framework/interface/ESHandle.h"
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "DataFormats/Common/interface/View.h"
00013 #include "DataFormats/JetReco/interface/Jet.h"
00014 #include "DataFormats/JetReco/interface/JetExtendedAssociation.h"
00015 #include "DataFormats/JetReco/interface/JetTracksAssociation.h"
00016 
00017 #include "JetExtender.h"
00018 
00019 JetExtender::JetExtender(const edm::ParameterSet& fConfig)
00020   : mJets (fConfig.getParameter<edm::InputTag> ("jets")),
00021     mJet2TracksAtVX (fConfig.getParameter<edm::InputTag> ("jet2TracksAtVX")),
00022     mJet2TracksAtCALO (fConfig.getParameter<edm::InputTag> ("jet2TracksAtCALO"))
00023 {
00024   produces<reco::JetExtendedAssociation::Container> ();
00025 }
00026 
00027 JetExtender::~JetExtender() {}
00028 
00029 void JetExtender::produce(edm::Event& fEvent, const edm::EventSetup& fSetup) {
00030   // get stuff from Event
00031   edm::Handle <edm::View <reco::Jet> > jets_h;
00032   fEvent.getByLabel (mJets, jets_h);
00033   edm::Handle <reco::JetTracksAssociation::Container> j2tVX_h;
00034   if (!(mJet2TracksAtVX.label().empty())) fEvent.getByLabel (mJet2TracksAtVX, j2tVX_h);
00035   edm::Handle <reco::JetTracksAssociation::Container> j2tCALO_h;
00036   if (!(mJet2TracksAtCALO.label().empty())) fEvent.getByLabel (mJet2TracksAtCALO, j2tCALO_h);
00037   
00038   std::auto_ptr<reco::JetExtendedAssociation::Container> 
00039     jetExtender (new reco::JetExtendedAssociation::Container (reco::JetRefBaseProd(jets_h)));
00040   
00041   // loop over jets (make sure jets in associations are the same as in collection
00042 
00043   for (unsigned j = 0; j < jets_h->size(); ++j) {
00044     edm::RefToBase<reco::Jet> jet = jets_h->refAt(j);
00045     reco::JetExtendedAssociation::JetExtendedData extendedData;
00046     if (j2tVX_h.isValid ()) { // fill tracks@VX  summary
00047       try {
00048         extendedData.mTracksAtVertexNumber = reco::JetTracksAssociation::tracksNumber (*j2tVX_h, jet);
00049         extendedData.mTracksAtVertexP4 = reco::JetTracksAssociation::tracksP4 (*j2tVX_h, jet);
00050       }
00051       catch (cms::Exception e) {
00052         edm::LogError ("MismatchedJets") << "Jets in original collection " << mJets 
00053                                     << " mismatch jets in j2t VX association " << mJet2TracksAtVX
00054                                     << ". Wrong collections?";
00055         throw e;
00056       }
00057     }
00058     if (j2tCALO_h.isValid ()) { // fill tracks@CALO  summary
00059       try {
00060         extendedData.mTracksAtCaloNumber = reco::JetTracksAssociation::tracksNumber (*j2tCALO_h, jet);
00061         extendedData.mTracksAtCaloP4 = reco::JetTracksAssociation::tracksP4 (*j2tCALO_h, jet);
00062       }
00063       catch (cms::Exception e) {
00064         edm::LogError ("MismatchedJets") << "Jets in original collection " << mJets 
00065                                     << " mismatch jets in j2t CALO association " << mJet2TracksAtCALO
00066                                     << ". Wrong collections?";
00067         throw e;
00068       }
00069     }
00070     reco::JetExtendedAssociation::setValue (&*jetExtender, jet, extendedData);
00071   }
00072   fEvent.put (jetExtender);
00073 }