File indexing completed on 2023-03-17 11:25:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021 #include <set>
0022
0023
0024 #include "PileupVertexAccumulator.h"
0025
0026 #include "DataFormats/Common/interface/Handle.h"
0027 #include "FWCore/Framework/interface/ConsumesCollector.h"
0028 #include "FWCore/Framework/interface/EventSetup.h"
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0031
0032 #include "SimDataFormats/GeneratorProducts/interface/GenRunInfoProduct.h"
0033 #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
0034 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0035 #include "SimDataFormats/PileupSummaryInfo/interface/PileupVertexContent.h"
0036
0037
0038 #include "FWCore/Framework/interface/Frameworkfwd.h"
0039
0040 #include "FWCore/Framework/interface/Event.h"
0041 #include "FWCore/Framework/interface/MakerMacros.h"
0042
0043 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0044 #include "SimGeneral/MixingModule/interface/PileUpEventPrincipal.h"
0045
0046 #include "FWCore/Utilities/interface/StreamID.h"
0047 #include "FWCore/Utilities/interface/Exception.h"
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062 namespace cms {
0063 PileupVertexAccumulator::PileupVertexAccumulator(const edm::ParameterSet& iConfig,
0064 edm::ProducesCollector producesCollector,
0065 edm::ConsumesCollector& iC)
0066 : Mtag_(iConfig.getParameter<edm::InputTag>("vtxTag")),
0067 fallbackMtag_(iConfig.getParameter<edm::InputTag>("vtxFallbackTag")),
0068 saveVtxTimes_(iConfig.getParameter<bool>("saveVtxTimes")) {
0069 edm::LogInfo("PixelDigitizer ") << "Enter the Pixel Digitizer";
0070
0071 const std::string alias("PileupVertexAccum");
0072
0073 producesCollector.produces<PileupVertexContent>().setBranchAlias(alias);
0074
0075 iC.consumes<edm::HepMCProduct>(Mtag_);
0076 iC.mayConsume<edm::HepMCProduct>(fallbackMtag_);
0077 }
0078
0079 PileupVertexAccumulator::~PileupVertexAccumulator() {}
0080
0081
0082
0083
0084
0085 void PileupVertexAccumulator::initializeEvent(edm::Event const& e, edm::EventSetup const& iSetup) {
0086
0087
0088 pT_Hats_.clear();
0089 z_posns_.clear();
0090 t_posns_.clear();
0091 }
0092
0093 void PileupVertexAccumulator::accumulate(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
0094
0095 }
0096
0097 void PileupVertexAccumulator::accumulate(PileUpEventPrincipal const& iEvent,
0098 edm::EventSetup const& iSetup,
0099 edm::StreamID const& streamID) {
0100 edm::Handle<edm::HepMCProduct> MCevt;
0101 iEvent.getByLabel(Mtag_, MCevt);
0102 if (MCevt.whyFailed()) {
0103 iEvent.getByLabel(fallbackMtag_, MCevt);
0104 }
0105
0106 const HepMC::GenEvent* myGenEvent = MCevt->GetEvent();
0107
0108 double pthat = myGenEvent->event_scale();
0109 float pt_hat = float(pthat);
0110
0111 pT_Hats_.push_back(pt_hat);
0112
0113 HepMC::GenEvent::vertex_const_iterator viter;
0114 HepMC::GenEvent::vertex_const_iterator vbegin = myGenEvent->vertices_begin();
0115 HepMC::GenEvent::vertex_const_iterator vend = myGenEvent->vertices_end();
0116
0117
0118 viter = vbegin;
0119
0120 if (viter != vend) {
0121
0122 HepMC::GenVertex* v = *viter;
0123 float zpos = v->position().z() * 0.1;
0124
0125 z_posns_.push_back(zpos);
0126
0127 if (saveVtxTimes_) {
0128 float tpos = v->position().t() / 299792458e-6;
0129 t_posns_.push_back(tpos);
0130 }
0131 }
0132
0133
0134 }
0135
0136
0137 void PileupVertexAccumulator::finalizeEvent(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0138 std::unique_ptr<PileupVertexContent> PUVtxC(new PileupVertexContent(pT_Hats_, z_posns_, t_posns_));
0139
0140
0141 iEvent.put(std::move(PUVtxC));
0142 }
0143
0144 }