File indexing completed on 2024-04-06 12:15:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021
0022
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
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");
0060
0061 produces<reco::JetTagCollection>();
0062 produces<reco::IsolatedTauTagInfoCollection>();
0063 }
0064
0065
0066
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
0080 void ConeIsolation::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0081 using namespace edm;
0082
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);
0101 Vertex myPV;
0102
0103
0104 Handle<reco::VertexCollection> vertices;
0105 iEvent.getByToken(vertexToken, vertices);
0106 const reco::VertexCollection vertCollection = *(vertices.product());
0107
0108 if (vertCollection.begin() != vertCollection.end())
0109 myPVtmp = *(vertCollection.begin());
0110
0111
0112 reco::BeamSpot vertexBeamSpot;
0113 edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
0114
0115 if (usingBeamSpot) {
0116
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
0138