Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:00

0001 // -*- C++ -*-
0002 //
0003 // Package:    TrackMCQuality
0004 // Class:      TrackMCQuality
0005 //
0006 /**\class TrackMCQuality TrackMCQuality.cc
0007  SimTracker/TrackMCQuality/src/TrackMCQuality.cc
0008 
0009  Description: <one line class summary>
0010 
0011  Implementation:
0012      <Notes on implementation>
0013 */
0014 //
0015 // Original Author:  Jean-Roch Vlimant
0016 //         Created:  Fri Mar 27 15:19:03 CET 2009
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 // user include files
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 // class decleration
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   // ----------member data ---------------------------
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 // constants, enums and typedefs
0060 //
0061 
0062 //
0063 // static data member definitions
0064 //
0065 
0066 //
0067 // constructors and destructor
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 // member functions
0080 //
0081 
0082 // ------------ method called to produce the data  ------------
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   // then loop the track collection
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     // find it in the map
0105     if (recSimColl.find(track) == recSimColl.end())
0106       continue;
0107 
0108     auto const &tp = recSimColl[track];
0109 
0110     if (tp.empty())
0111       continue;  // can it be?
0112     // nSimHits = tp[0].first->numberOfTrackerHits();
0113     prod = tp[0].second;
0114     // if (tp[0].first->charge() != track->charge()) isChargeMatched = false;
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 // define this as a plug-in
0123 DEFINE_FWK_MODULE(TrackMCQuality);