Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:47

0001 #include "ShallowSimTracksProducer.h"
0002 #include "CalibTracker/SiStripCommon/interface/ShallowTools.h"
0003 
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "SimDataFormats/Associations/interface/TrackAssociation.h"
0007 
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 
0010 ShallowSimTracksProducer::ShallowSimTracksProducer(const edm::ParameterSet& conf)
0011     : Prefix(conf.getParameter<std::string>("Prefix")),
0012       Suffix(conf.getParameter<std::string>("Suffix")),
0013       trackingParticles_token_(
0014           consumes<TrackingParticleCollection>(conf.getParameter<edm::InputTag>("TrackingParticles"))),
0015       associator_token_(
0016           consumes<reco::TrackToTrackingParticleAssociator>(conf.getParameter<edm::InputTag>("Associator"))),
0017       tracks_token_(consumes<edm::View<reco::Track>>(conf.getParameter<edm::InputTag>("Tracks"))) {
0018   produces<std::vector<unsigned>>(Prefix + "multi" + Suffix);
0019   produces<std::vector<int>>(Prefix + "type" + Suffix);
0020   produces<std::vector<float>>(Prefix + "charge" + Suffix);
0021   produces<std::vector<float>>(Prefix + "momentum" + Suffix);
0022   produces<std::vector<float>>(Prefix + "pt" + Suffix);
0023   produces<std::vector<double>>(Prefix + "theta" + Suffix);
0024   produces<std::vector<double>>(Prefix + "phi" + Suffix);
0025   produces<std::vector<double>>(Prefix + "eta" + Suffix);
0026   produces<std::vector<double>>(Prefix + "qoverp" + Suffix);
0027   produces<std::vector<double>>(Prefix + "vx" + Suffix);
0028   produces<std::vector<double>>(Prefix + "vy" + Suffix);
0029   produces<std::vector<double>>(Prefix + "vz" + Suffix);
0030 }
0031 
0032 void ShallowSimTracksProducer::produce(edm::Event& event, const edm::EventSetup& iSetup) {
0033   edm::Handle<edm::View<reco::Track>> tracks;
0034   event.getByToken(tracks_token_, tracks);
0035   edm::Handle<TrackingParticleCollection> trackingParticles;
0036   event.getByToken(trackingParticles_token_, trackingParticles);
0037   edm::Handle<reco::TrackToTrackingParticleAssociator> associator;
0038   event.getByToken(associator_token_, associator);
0039 
0040   unsigned size = tracks->size();
0041   auto multi = std::make_unique<std::vector<unsigned>>(size, 0);
0042   auto type = std::make_unique<std::vector<int>>(size, 0);
0043   auto charge = std::make_unique<std::vector<float>>(size, 0);
0044   auto momentum = std::make_unique<std::vector<float>>(size, -1);
0045   auto pt = std::make_unique<std::vector<float>>(size, -1);
0046   auto theta = std::make_unique<std::vector<double>>(size, -1000);
0047   auto phi = std::make_unique<std::vector<double>>(size, -1000);
0048   auto eta = std::make_unique<std::vector<double>>(size, -1000);
0049   auto dxy = std::make_unique<std::vector<double>>(size, -1000);
0050   auto dsz = std::make_unique<std::vector<double>>(size, -1000);
0051   auto qoverp = std::make_unique<std::vector<double>>(size, -1000);
0052   auto vx = std::make_unique<std::vector<double>>(size, -1000);
0053   auto vy = std::make_unique<std::vector<double>>(size, -1000);
0054   auto vz = std::make_unique<std::vector<double>>(size, -1000);
0055 
0056   reco::RecoToSimCollection associations = associator->associateRecoToSim(tracks, trackingParticles);
0057 
0058   for (reco::RecoToSimCollection::const_iterator association = associations.begin(); association != associations.end();
0059        association++) {
0060     const reco::Track* track = association->key.get();
0061     const int matches = association->val.size();
0062     if (matches > 0) {
0063       const TrackingParticle* tparticle = association->val[0].first.get();
0064       unsigned i = shallow::findTrackIndex(tracks, track);
0065 
0066       multi->at(i) = matches;
0067       type->at(i) = tparticle->pdgId();
0068       charge->at(i) = tparticle->charge();
0069       momentum->at(i) = tparticle->p();
0070       pt->at(i) = tparticle->pt();
0071       theta->at(i) = tparticle->theta();
0072       phi->at(i) = tparticle->phi();
0073       eta->at(i) = tparticle->eta();
0074       qoverp->at(i) = tparticle->charge() / tparticle->p();
0075 
0076       const TrackingVertex* tvertex = tparticle->parentVertex().get();
0077       vx->at(i) = tvertex->position().x();
0078       vy->at(i) = tvertex->position().y();
0079       vz->at(i) = tvertex->position().z();
0080     }
0081   }
0082 
0083   event.put(std::move(multi), Prefix + "multi" + Suffix);
0084   event.put(std::move(type), Prefix + "type" + Suffix);
0085   event.put(std::move(charge), Prefix + "charge" + Suffix);
0086   event.put(std::move(momentum), Prefix + "momentum" + Suffix);
0087   event.put(std::move(pt), Prefix + "pt" + Suffix);
0088   event.put(std::move(theta), Prefix + "theta" + Suffix);
0089   event.put(std::move(phi), Prefix + "phi" + Suffix);
0090   event.put(std::move(eta), Prefix + "eta" + Suffix);
0091   event.put(std::move(qoverp), Prefix + "qoverp" + Suffix);
0092   event.put(std::move(vx), Prefix + "vx" + Suffix);
0093   event.put(std::move(vy), Prefix + "vy" + Suffix);
0094   event.put(std::move(vz), Prefix + "vz" + Suffix);
0095 }