Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-07 23:36:47

0001 // -*- C++ -*-
0002 //
0003 // Package:    PileupVertexAccumulator
0004 // Class:      PileupVertexAccumulator
0005 //
0006 /**\class PileupVertexAccumulator PileupVertexAccumulator.cc SimTracker/PileupVertexAccumulator/src/PileupVertexAccumulator.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author: Mike Hildreth - Notre Dame
0015 //         Created:  Wed Jan 21 05:14:48 CET 2015
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <set>
0022 
0023 // user include files
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 // user include files
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 // constants, enums and typedefs
0051 //
0052 
0053 //
0054 // static data member definitions
0055 //
0056 
0057 //
0058 // constructors and destructor
0059 //
0060 //using namespace std;
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   // member functions
0083   //
0084 
0085   void PileupVertexAccumulator::initializeEvent(edm::Event const& e, edm::EventSetup const& iSetup) {
0086     // Make sure that the first crossing processed starts indexing the minbias events from zero.
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     // don't do anything for hard-scatter signal events
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     // for production point, pick first vertex
0118     viter = vbegin;
0119 
0120     if (viter != vend) {
0121       // The origin vertex (turn it to cm's from GenEvent mm's)
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;  // turn from mm to ns
0129         t_posns_.push_back(tpos);
0130       }
0131     }
0132 
0133     //    delete myGenEvent;
0134   }
0135 
0136   // ------------ method called to produce write the data  ------------
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     // write output to event
0141     iEvent.put(std::move(PUVtxC));
0142   }
0143 
0144 }  // namespace cms