File indexing completed on 2024-04-06 12:24:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0013 #include "DataFormats/Common/interface/Handle.h"
0014 #include "DataFormats/EgammaTrackReco/interface/ConversionTrack.h"
0015 #include "DataFormats/EgammaTrackReco/interface/ConversionTrackFwd.h"
0016 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0017 #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
0018 #include "DataFormats/TrackReco/interface/Track.h"
0019 #include "DataFormats/TrackReco/interface/TrackBase.h"
0020 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0021 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
0022 #include "FWCore/Framework/interface/ESHandle.h"
0023 #include "FWCore/Framework/interface/Event.h"
0024 #include "FWCore/Framework/interface/EventSetup.h"
0025 #include "FWCore/Framework/interface/stream/EDProducer.h"
0026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0028 #include "MagneticField/Engine/interface/MagneticField.h"
0029 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0030 #include "RecoTracker/ConversionSeedGenerators/interface/IdealHelixParameters.h"
0031 #include "TrackingTools/GsfTracking/interface/TrajGsfTrackAssociation.h"
0032 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
0033 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0034
0035 #include <string>
0036 #include <vector>
0037
0038 class ConversionTrackProducer : public edm::stream::EDProducer<> {
0039 typedef edm::AssociationMap<edm::OneToOne<std::vector<Trajectory>, reco::GsfTrackCollection, unsigned short> >
0040 TrajGsfTrackAssociationCollection;
0041
0042 public:
0043 explicit ConversionTrackProducer(const edm::ParameterSet& conf);
0044
0045 ~ConversionTrackProducer() override;
0046
0047 void produce(edm::Event& e, const edm::EventSetup& c) override;
0048
0049 private:
0050 edm::EDGetTokenT<edm::View<reco::Track> > genericTracks;
0051 edm::EDGetTokenT<TrajTrackAssociationCollection> kfTrajectories;
0052 edm::EDGetTokenT<TrajGsfTrackAssociationCollection> gsfTrajectories;
0053 bool useTrajectory;
0054 bool setTrackerOnly;
0055 bool setIsGsfTrackOpen;
0056 bool setArbitratedEcalSeeded;
0057 bool setArbitratedMerged;
0058 bool setArbitratedMergedEcalGeneral;
0059
0060
0061
0062
0063
0064
0065 edm::EDGetTokenT<reco::BeamSpot> beamSpotInputTag;
0066 edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magFieldToken;
0067 bool filterOnConvTrackHyp;
0068 double minConvRadius;
0069 IdealHelixParameters ConvTrackPreSelector;
0070 };
0071
0072 #include "FWCore/Framework/interface/MakerMacros.h"
0073 DEFINE_FWK_MODULE(ConversionTrackProducer);
0074
0075 ConversionTrackProducer::ConversionTrackProducer(edm::ParameterSet const& conf)
0076 : useTrajectory(conf.getParameter<bool>("useTrajectory")),
0077 setTrackerOnly(conf.getParameter<bool>("setTrackerOnly")),
0078 setIsGsfTrackOpen(conf.getParameter<bool>("setIsGsfTrackOpen")),
0079 setArbitratedEcalSeeded(conf.getParameter<bool>("setArbitratedEcalSeeded")),
0080 setArbitratedMerged(conf.getParameter<bool>("setArbitratedMerged")),
0081 setArbitratedMergedEcalGeneral(conf.getParameter<bool>("setArbitratedMergedEcalGeneral")),
0082 beamSpotInputTag(consumes<reco::BeamSpot>(conf.getParameter<edm::InputTag>("beamSpotInputTag"))),
0083 filterOnConvTrackHyp(conf.getParameter<bool>("filterOnConvTrackHyp")),
0084 minConvRadius(conf.getParameter<double>("minConvRadius")) {
0085 edm::InputTag thetp(conf.getParameter<std::string>("TrackProducer"));
0086 genericTracks = consumes<edm::View<reco::Track> >(thetp);
0087 if (useTrajectory) {
0088 kfTrajectories = consumes<TrajTrackAssociationCollection>(thetp);
0089 gsfTrajectories = consumes<TrajGsfTrackAssociationCollection>(thetp);
0090 }
0091 magFieldToken = esConsumes();
0092 produces<reco::ConversionTrackCollection>();
0093 }
0094
0095
0096 ConversionTrackProducer::~ConversionTrackProducer() {}
0097
0098
0099 void ConversionTrackProducer::produce(edm::Event& e, const edm::EventSetup& es) {
0100
0101 edm::View<reco::Track> const& trks = e.get(genericTracks);
0102
0103
0104 std::map<reco::TrackRef, edm::Ref<std::vector<Trajectory> > > tracktrajmap;
0105 std::map<reco::GsfTrackRef, edm::Ref<std::vector<Trajectory> > > gsftracktrajmap;
0106
0107 if (useTrajectory) {
0108 if (!trks.empty()) {
0109 if (dynamic_cast<const reco::GsfTrack*>(&trks.at(0))) {
0110
0111 for (auto const& pair : e.get(gsfTrajectories)) {
0112 gsftracktrajmap[pair.val] = pair.key;
0113 }
0114 } else {
0115
0116 for (auto const& pair : e.get(kfTrajectories)) {
0117 tracktrajmap[pair.val] = pair.key;
0118 }
0119 }
0120 }
0121 }
0122
0123
0124 auto outputTrks = std::make_unique<reco::ConversionTrackCollection>();
0125
0126
0127
0128
0129
0130
0131 math::XYZVector beamSpot{e.get(beamSpotInputTag).position()};
0132
0133 ConvTrackPreSelector.setMagnField(&es.getData(magFieldToken));
0134
0135
0136
0137
0138 for (size_t i = 0; i < trks.size(); ++i) {
0139
0140
0141
0142
0143
0144 edm::RefToBase<reco::Track> trackBaseRef = trks.refAt(i);
0145 if (filterOnConvTrackHyp &&
0146 ConvTrackPreSelector.isTangentPointDistanceLessThan(minConvRadius, trackBaseRef.get(), beamSpot))
0147 continue;
0148
0149
0150 reco::ConversionTrack convTrack(trackBaseRef);
0151 convTrack.setIsTrackerOnly(setTrackerOnly);
0152 convTrack.setIsGsfTrackOpen(setIsGsfTrackOpen);
0153 convTrack.setIsArbitratedEcalSeeded(setArbitratedEcalSeeded);
0154 convTrack.setIsArbitratedMerged(setArbitratedMerged);
0155 convTrack.setIsArbitratedMergedEcalGeneral(setArbitratedMergedEcalGeneral);
0156
0157
0158 if (useTrajectory) {
0159 if (!gsftracktrajmap.empty()) {
0160 convTrack.setTrajRef(gsftracktrajmap.find(trackBaseRef.castTo<reco::GsfTrackRef>())->second);
0161 } else {
0162 convTrack.setTrajRef(tracktrajmap.find(trackBaseRef.castTo<reco::TrackRef>())->second);
0163 }
0164 }
0165
0166 outputTrks->push_back(convTrack);
0167 }
0168
0169 e.put(std::move(outputTrks));
0170 return;
0171
0172 }