File indexing completed on 2024-04-06 12:31:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <memory>
0022
0023
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/global/EDProducer.h"
0026
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031
0032 #include "SimDataFormats/Associations/interface/TrackToTrackingParticleAssociator.h"
0033
0034 #include "DataFormats/TrackReco/interface/Track.h"
0035 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
0036
0037
0038
0039
0040
0041 class TrackMCQuality final : public edm::global::EDProducer<> {
0042 public:
0043 explicit TrackMCQuality(const edm::ParameterSet &);
0044 ~TrackMCQuality() override;
0045
0046 private:
0047 void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
0048
0049
0050
0051 edm::EDGetTokenT<reco::TrackToTrackingParticleAssociator> label_assoc;
0052 edm::EDGetTokenT<TrackingParticleCollection> label_tp;
0053 edm::EDGetTokenT<edm::View<reco::Track>> label_tr;
0054
0055 using Product = std::vector<float>;
0056 };
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069 TrackMCQuality::TrackMCQuality(const edm::ParameterSet &pset)
0070 : label_assoc(consumes<reco::TrackToTrackingParticleAssociator>(pset.getParameter<edm::InputTag>("associator"))),
0071 label_tp(consumes<TrackingParticleCollection>(pset.getParameter<edm::InputTag>("trackingParticles"))),
0072 label_tr(consumes<edm::View<reco::Track>>(pset.getParameter<edm::InputTag>("tracks"))) {
0073 produces<Product>();
0074 }
0075
0076 TrackMCQuality::~TrackMCQuality() {}
0077
0078
0079
0080
0081
0082
0083 void TrackMCQuality::produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const {
0084 using namespace edm;
0085 Handle<reco::TrackToTrackingParticleAssociator> associator;
0086 iEvent.getByToken(label_assoc, associator);
0087
0088 Handle<TrackingParticleCollection> TPCollection;
0089 iEvent.getByToken(label_tp, TPCollection);
0090
0091 Handle<edm::View<reco::Track>> trackCollection;
0092 iEvent.getByToken(label_tr, trackCollection);
0093
0094 reco::RecoToSimCollection recSimColl = associator->associateRecoToSim(trackCollection, TPCollection);
0095
0096
0097 std::unique_ptr<Product> product(new Product(trackCollection->size(), 0));
0098
0099 for (unsigned int iT = 0; iT != trackCollection->size(); ++iT) {
0100 auto &prod = (*product)[iT];
0101
0102 edm::RefToBase<reco::Track> track(trackCollection, iT);
0103
0104
0105 if (recSimColl.find(track) == recSimColl.end())
0106 continue;
0107
0108 auto const &tp = recSimColl[track];
0109
0110 if (tp.empty())
0111 continue;
0112
0113 prod = tp[0].second;
0114
0115 if ((tp[0].first->eventId().event() != 0) || (tp[0].first->eventId().bunchCrossing() != 0))
0116 prod = -prod;
0117 }
0118
0119 iEvent.put(std::move(product));
0120 }
0121
0122
0123 DEFINE_FWK_MODULE(TrackMCQuality);