File indexing completed on 2024-05-10 02:21:29
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 "FWCore/Framework/interface/stream/EDProducer.h"
0025
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "FWCore/Utilities/interface/StreamID.h"
0031
0032 #include <CLHEP/Units/GlobalPhysicalConstants.h>
0033 #include <CLHEP/Units/SystemOfUnits.h>
0034
0035 #include "DataFormats/Math/interface/LorentzVector.h"
0036 #include "DataFormats/Math/interface/LorentzVectorFwd.h"
0037 #include "DataFormats/VertexReco/interface/Vertex.h"
0038 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0039 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0040
0041 #include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"
0042 #include "CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h"
0043 #include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h"
0044 #include "CondFormats/DataRecord/interface/SimBeamSpotObjectsRcd.h"
0045
0046 #include "FWCore/Framework/interface/EventSetup.h"
0047 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0048
0049 namespace HepMC {
0050 class FourVector;
0051 }
0052
0053
0054
0055
0056
0057 class EmbeddingVertexCorrector : public edm::stream::EDProducer<> {
0058 public:
0059 explicit EmbeddingVertexCorrector(const edm::ParameterSet &);
0060 ~EmbeddingVertexCorrector() override;
0061
0062 static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0063
0064 private:
0065 void produce(edm::Event &, const edm::EventSetup &) override;
0066
0067
0068 edm::InputTag sourceLabel;
0069 edm::InputTag vertexPositionLabel;
0070 };
0071
0072
0073
0074
0075 EmbeddingVertexCorrector::EmbeddingVertexCorrector(const edm::ParameterSet &iConfig) {
0076 produces<edm::HepMCProduct>();
0077
0078 sourceLabel = iConfig.getParameter<edm::InputTag>("src");
0079 consumes<edm::HepMCProduct>(sourceLabel);
0080 vertexPositionLabel = edm::InputTag("externalLHEProducer", "vertexPosition");
0081 consumes<math::XYZTLorentzVectorD>(vertexPositionLabel);
0082 }
0083
0084 EmbeddingVertexCorrector::~EmbeddingVertexCorrector() {}
0085
0086
0087
0088
0089
0090
0091 void EmbeddingVertexCorrector::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) {
0092 using namespace edm;
0093
0094
0095 Handle<edm::HepMCProduct> InputGenEvent;
0096 iEvent.getByLabel(sourceLabel, InputGenEvent);
0097 HepMC::GenEvent *genevent = new HepMC::GenEvent(*InputGenEvent->GetEvent());
0098 std::unique_ptr<edm::HepMCProduct> CorrectedGenEvent(new edm::HepMCProduct(genevent));
0099
0100
0101 Handle<math::XYZTLorentzVectorD> vertex_position;
0102 iEvent.getByLabel(vertexPositionLabel, vertex_position);
0103 HepMC::FourVector vertex_shift(vertex_position.product()->x() * CLHEP::cm,
0104 vertex_position.product()->y() * CLHEP::cm,
0105 vertex_position.product()->z() * CLHEP::cm);
0106
0107
0108 CorrectedGenEvent->applyVtxGen(&vertex_shift);
0109 iEvent.put(std::move(CorrectedGenEvent));
0110 }
0111
0112
0113 void EmbeddingVertexCorrector::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0114
0115
0116 edm::ParameterSetDescription desc;
0117 desc.setUnknown();
0118 descriptions.addDefault(desc);
0119 }
0120
0121
0122 DEFINE_FWK_MODULE(EmbeddingVertexCorrector);