Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:37

0001 // -*- C++ -*-
0002 //
0003 // Package:    ConeIsolation
0004 // Class:      ConeIsolation
0005 //
0006 /**\class ConeIsolation ConeIsolation.cc RecoBTag/ConeIsolation/src/ConeIsolation.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Simone Gennai
0015 //      Created:  Thu Apr  6 09:56:23 CEST 2006
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "ConeIsolation.h"
0025 
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 #include "FWCore/Framework/interface/makeRefToBaseProdFrom.h"
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 
0031 #include "DataFormats/BTauReco/interface/JetTag.h"
0032 #include "DataFormats/TrackReco/interface/Track.h"
0033 #include "DataFormats/BTauReco/interface/IsolatedTauTagInfo.h"
0034 
0035 #include "DataFormats/VertexReco/interface/Vertex.h"
0036 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0037 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0038 
0039 #include "FWCore/Framework/interface/EventSetup.h"
0040 #include "FWCore/Framework/interface/ESHandle.h"
0041 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0042 
0043 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0044 
0045 using namespace reco;
0046 using namespace edm;
0047 using namespace std;
0048 
0049 //
0050 // constructors and destructor
0051 //
0052 ConeIsolation::ConeIsolation(const edm::ParameterSet& iConfig) {
0053   jetTrackTag = iConfig.getParameter<InputTag>("JetTrackSrc");
0054   jetTrackToken = consumes<reco::JetTracksAssociationCollection>(jetTrackTag);
0055   vertexTag = iConfig.getParameter<InputTag>("vertexSrc");
0056   vertexToken = consumes<reco::VertexCollection>(vertexTag);
0057   beamSpotTag = iConfig.getParameter<edm::InputTag>("BeamSpotProducer");
0058   beamSpotToken = consumes<reco::BeamSpot>(beamSpotTag);
0059   usingBeamSpot = iConfig.getParameter<bool>("useBeamSpot");  //If false the OfflinePrimaryVertex will be used.
0060 
0061   m_algo = new ConeIsolationAlgorithm(iConfig);
0062 
0063   produces<reco::JetTagCollection>();
0064   produces<reco::IsolatedTauTagInfoCollection>();
0065 }
0066 
0067 ConeIsolation::~ConeIsolation() { delete m_algo; }
0068 
0069 //
0070 // member functions
0071 //
0072 
0073 void ConeIsolation::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0074   edm::ParameterSetDescription desc;
0075   desc.add<edm::InputTag>("JetTrackSrc", edm::InputTag("ic5JetTracksAssociatorAtVertex"));
0076   desc.add<edm::InputTag>("vertexSrc", edm::InputTag("offlinePrimaryVertices"));
0077   desc.add<edm::InputTag>("BeamSpotProducer", edm::InputTag("offlineBeamSpot"));
0078   desc.add<bool>("useBeamSpot", false);
0079   ConeIsolationAlgorithm::fillDescription(desc);
0080   descriptions.add("coneIsolationTauJetTags", desc);
0081 }
0082 
0083 // ------------ method called to produce the data  ------------
0084 void ConeIsolation::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0085   using namespace edm;
0086   //Get jets with tracks
0087   Handle<reco::JetTracksAssociationCollection> jetTracksAssociation;
0088   iEvent.getByToken(jetTrackToken, jetTracksAssociation);
0089 
0090   std::unique_ptr<reco::JetTagCollection> tagCollection;
0091   std::unique_ptr<reco::IsolatedTauTagInfoCollection> extCollection(new reco::IsolatedTauTagInfoCollection());
0092   if (not jetTracksAssociation->empty()) {
0093     RefToBaseProd<reco::Jet> prod(edm::makeRefToBaseProdFrom(jetTracksAssociation->begin()->first, iEvent));
0094     tagCollection = std::make_unique<reco::JetTagCollection>(prod);
0095   } else {
0096     tagCollection = std::make_unique<reco::JetTagCollection>();
0097   }
0098 
0099   Vertex::Error e;
0100   e(0, 0) = 1;
0101   e(1, 1) = 1;
0102   e(2, 2) = 1;
0103   Vertex::Point p(0, 0, -1000);
0104   Vertex myPVtmp(p, e);  //Fake vertex to be used in case no vertex is found
0105   Vertex myPV;
0106 
0107   //Get pixel vertices
0108   Handle<reco::VertexCollection> vertices;
0109   iEvent.getByToken(vertexToken, vertices);
0110   const reco::VertexCollection vertCollection = *(vertices.product());
0111   //Check if there is the PV!!!!
0112   if (vertCollection.begin() != vertCollection.end())
0113     myPVtmp = *(vertCollection.begin());
0114 
0115   //In case the beam spot is used, the Z of the vertex still comes from the PV, while the (x,y) is taken from the beamspot
0116   reco::BeamSpot vertexBeamSpot;
0117   edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
0118 
0119   if (usingBeamSpot) {
0120     //Create a new vertex with the information on x0 and Y0 from the beamspot, to be used in HLT.
0121     iEvent.getByToken(beamSpotToken, recoBeamSpotHandle);
0122     vertexBeamSpot = *recoBeamSpotHandle;
0123     Vertex::Point bspoint(vertexBeamSpot.x0(), vertexBeamSpot.y0(), myPVtmp.z());
0124     Vertex combinedVertex = Vertex(bspoint, myPVtmp.error(), myPVtmp.chi2(), myPVtmp.ndof(), myPVtmp.tracksSize());
0125     myPV = combinedVertex;
0126   } else {
0127     myPV = myPVtmp;
0128   }
0129 
0130   for (unsigned int i = 0; i < jetTracksAssociation->size(); ++i) {
0131     pair<float, IsolatedTauTagInfo> myPair =
0132         m_algo->tag(edm::Ref<JetTracksAssociationCollection>(jetTracksAssociation, i), myPV);
0133     tagCollection->setValue(i, myPair.first);
0134     extCollection->push_back(myPair.second);
0135   }
0136 
0137   iEvent.put(std::move(extCollection));
0138   iEvent.put(std::move(tagCollection));
0139 }
0140 
0141 // declare this class as a framework plugin
0142 //DEFINE_FWK_MODULE(ConeIsolation);