Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:50:30

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) : m_algo{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   produces<reco::JetTagCollection>();
0062   produces<reco::IsolatedTauTagInfoCollection>();
0063 }
0064 
0065 //
0066 // member functions
0067 //
0068 
0069 void ConeIsolation::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0070   edm::ParameterSetDescription desc;
0071   desc.add<edm::InputTag>("JetTrackSrc", edm::InputTag("ic5JetTracksAssociatorAtVertex"));
0072   desc.add<edm::InputTag>("vertexSrc", edm::InputTag("offlinePrimaryVertices"));
0073   desc.add<edm::InputTag>("BeamSpotProducer", edm::InputTag("offlineBeamSpot"));
0074   desc.add<bool>("useBeamSpot", false);
0075   ConeIsolationAlgorithm::fillDescription(desc);
0076   descriptions.add("coneIsolationTauJetTags", desc);
0077 }
0078 
0079 // ------------ method called to produce the data  ------------
0080 void ConeIsolation::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0081   using namespace edm;
0082   //Get jets with tracks
0083   Handle<reco::JetTracksAssociationCollection> jetTracksAssociation;
0084   iEvent.getByToken(jetTrackToken, jetTracksAssociation);
0085 
0086   std::unique_ptr<reco::JetTagCollection> tagCollection;
0087   std::unique_ptr<reco::IsolatedTauTagInfoCollection> extCollection(new reco::IsolatedTauTagInfoCollection());
0088   if (not jetTracksAssociation->empty()) {
0089     RefToBaseProd<reco::Jet> prod(edm::makeRefToBaseProdFrom(jetTracksAssociation->begin()->first, iEvent));
0090     tagCollection = std::make_unique<reco::JetTagCollection>(prod);
0091   } else {
0092     tagCollection = std::make_unique<reco::JetTagCollection>();
0093   }
0094 
0095   Vertex::Error e;
0096   e(0, 0) = 1;
0097   e(1, 1) = 1;
0098   e(2, 2) = 1;
0099   Vertex::Point p(0, 0, -1000);
0100   Vertex myPVtmp(p, e);  //Fake vertex to be used in case no vertex is found
0101   Vertex myPV;
0102 
0103   //Get pixel vertices
0104   Handle<reco::VertexCollection> vertices;
0105   iEvent.getByToken(vertexToken, vertices);
0106   const reco::VertexCollection vertCollection = *(vertices.product());
0107   //Check if there is the PV!!!!
0108   if (vertCollection.begin() != vertCollection.end())
0109     myPVtmp = *(vertCollection.begin());
0110 
0111   //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
0112   reco::BeamSpot vertexBeamSpot;
0113   edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
0114 
0115   if (usingBeamSpot) {
0116     //Create a new vertex with the information on x0 and Y0 from the beamspot, to be used in HLT.
0117     iEvent.getByToken(beamSpotToken, recoBeamSpotHandle);
0118     vertexBeamSpot = *recoBeamSpotHandle;
0119     Vertex::Point bspoint(vertexBeamSpot.x0(), vertexBeamSpot.y0(), myPVtmp.z());
0120     Vertex combinedVertex = Vertex(bspoint, myPVtmp.error(), myPVtmp.chi2(), myPVtmp.ndof(), myPVtmp.tracksSize());
0121     myPV = combinedVertex;
0122   } else {
0123     myPV = myPVtmp;
0124   }
0125 
0126   for (unsigned int i = 0; i < jetTracksAssociation->size(); ++i) {
0127     pair<float, IsolatedTauTagInfo> myPair =
0128         m_algo.tag(edm::Ref<JetTracksAssociationCollection>(jetTracksAssociation, i), myPV);
0129     tagCollection->setValue(i, myPair.first);
0130     extCollection->push_back(myPair.second);
0131   }
0132 
0133   iEvent.put(std::move(extCollection));
0134   iEvent.put(std::move(tagCollection));
0135 }
0136 
0137 // declare this class as a framework plugin
0138 //DEFINE_FWK_MODULE(ConeIsolation);