File indexing completed on 2024-04-06 12:27:06
0001
0002
0003
0004
0005 #include "RecoMuon/MuonSeedGenerator/plugins/SETMuonSeedProducer.h"
0006
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/Framework/interface/ConsumesCollector.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
0011 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
0012 #include "DataFormats/TrajectoryState/interface/PTrajectoryStateOnDet.h"
0013 #include "DataFormats/TrajectorySeed/interface/PropagationDirection.h"
0014
0015 #include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h"
0016 #include "RecoMuon/Navigation/interface/DirectMuonNavigation.h"
0017
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019
0020 #include "DataFormats/TrajectoryState/interface/PTrajectoryStateOnDet.h"
0021 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
0022 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0023 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
0024 #include "TrackingTools/DetLayers/interface/DetLayer.h"
0025 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0026 #include "TMath.h"
0027
0028 using namespace edm;
0029 using namespace std;
0030
0031 SETMuonSeedProducer::SETMuonSeedProducer(const ParameterSet& parameterSet)
0032 : theSeedFinder(parameterSet), theBeamSpotTag(parameterSet.getParameter<edm::InputTag>("beamSpotTag")) {
0033 edm::ConsumesCollector iC = consumesCollector();
0034 thePatternRecognition = new SETPatternRecognition(parameterSet, iC);
0035
0036 const string metname = "Muon|RecoMuon|SETMuonSeedSeed";
0037
0038
0039 ParameterSet serviceParameters = parameterSet.getParameter<ParameterSet>("ServiceParameters");
0040 theService = new MuonServiceProxy(serviceParameters, consumesCollector());
0041 thePatternRecognition->setServiceProxy(theService);
0042 theSeedFinder.setServiceProxy(theService);
0043
0044 ParameterSet trajectoryBuilderParameters = parameterSet.getParameter<ParameterSet>("SETTrajBuilderParameters");
0045
0046 LogTrace(metname) << "constructor called" << endl;
0047
0048 apply_prePruning = trajectoryBuilderParameters.getParameter<bool>("Apply_prePruning");
0049
0050 useSegmentsInTrajectory = trajectoryBuilderParameters.getParameter<bool>("UseSegmentsInTrajectory");
0051
0052
0053 ParameterSet filterPSet = trajectoryBuilderParameters.getParameter<ParameterSet>("FilterParameters");
0054 filterPSet.addUntrackedParameter("UseSegmentsInTrajectory", useSegmentsInTrajectory);
0055 theFilter = new SETFilter(filterPSet, theService);
0056
0057
0058
0059 beamspotToken = consumes<reco::BeamSpot>(theBeamSpotTag);
0060 produces<TrajectorySeedCollection>();
0061 }
0062
0063 SETMuonSeedProducer::~SETMuonSeedProducer() {
0064 LogTrace("Muon|RecoMuon|SETMuonSeedProducer") << "SETMuonSeedProducer destructor called" << endl;
0065
0066 if (theFilter)
0067 delete theFilter;
0068 if (theService)
0069 delete theService;
0070 if (thePatternRecognition)
0071 delete thePatternRecognition;
0072 }
0073
0074 void SETMuonSeedProducer::produce(edm::Event& event, const edm::EventSetup& eventSetup) {
0075
0076 const string metname = "Muon|RecoMuon|SETMuonSeedSeed";
0077
0078 MuonPatternRecoDumper debug;
0079
0080
0081 theService->update(eventSetup);
0082
0083 auto output = std::make_unique<TrajectorySeedCollection>();
0084
0085 Handle<View<TrajectorySeed> > seeds;
0086
0087 setEvent(event);
0088
0089 reco::BeamSpot beamSpot;
0090 edm::Handle<reco::BeamSpot> beamSpotHandle;
0091 event.getByToken(beamspotToken, beamSpotHandle);
0092 if (beamSpotHandle.isValid()) {
0093 beamSpot = *beamSpotHandle;
0094
0095 } else {
0096 edm::LogInfo("MuonSeedGenerator") << "No beam spot available from EventSetup \n";
0097 }
0098
0099
0100 GlobalVector gv(beamSpot.x0(), beamSpot.y0(), beamSpot.z0());
0101 theSeedFinder.setBeamSpot(gv);
0102
0103 bool fwFitFailed = true;
0104
0105 std::vector<SeedCandidate> seedCandidates_AllChosen;
0106 std::vector<MuonRecHitContainer> MuonRecHitContainer_clusters;
0107
0108 thePatternRecognition->produce(event, eventSetup, MuonRecHitContainer_clusters);
0109
0110
0111
0112 for (unsigned int cluster = 0; cluster < MuonRecHitContainer_clusters.size(); ++cluster) {
0113
0114 std::vector<SeedCandidate> seedCandidates_inCluster;
0115
0116
0117
0118 std::vector<MuonRecHitContainer> MuonRecHitContainer_perLayer =
0119 theSeedFinder.sortByLayer(MuonRecHitContainer_clusters[cluster]);
0120
0121
0122 theSeedFinder.limitCombinatorics(MuonRecHitContainer_perLayer);
0123
0124 std::vector<MuonRecHitContainer> allValidSets = theSeedFinder.findAllValidSets(MuonRecHitContainer_perLayer);
0125 if (apply_prePruning) {
0126
0127 theSeedFinder.validSetsPrePruning(allValidSets);
0128 }
0129
0130
0131
0132 if (allValidSets.size() < 500) {
0133 seedCandidates_inCluster = theSeedFinder.fillSeedCandidates(allValidSets);
0134 }
0135
0136
0137 if (!seedCandidates_inCluster.empty()) {
0138
0139 std::vector<SeedCandidate> bestSets_inCluster;
0140 fwFitFailed = !(filter()->fwfit_SET(seedCandidates_inCluster, bestSets_inCluster));
0141
0142
0143 if (fwFitFailed) {
0144
0145 continue;
0146 }
0147 for (unsigned int iSet = 0; iSet < bestSets_inCluster.size(); ++iSet) {
0148 seedCandidates_AllChosen.push_back(bestSets_inCluster[iSet]);
0149 }
0150 }
0151 }
0152
0153 for (unsigned int iMuon = 0; iMuon < seedCandidates_AllChosen.size(); ++iMuon) {
0154
0155 Trajectory::DataContainer finalCandidate;
0156 SeedCandidate* aFinalSet = &(seedCandidates_AllChosen[iMuon]);
0157 fwFitFailed = !(filter()->buildTrajectoryMeasurements(aFinalSet, finalCandidate));
0158 if (fwFitFailed) {
0159
0160 continue;
0161 }
0162
0163 if (!filter()->layers().empty())
0164 LogTrace(metname) << debug.dumpLayer(filter()->lastDetLayer());
0165 else {
0166 continue;
0167 }
0168
0169
0170
0171
0172 if (filter()->goodState()) {
0173 TransientTrackingRecHit::ConstRecHitContainer hitContainer;
0174 TrajectoryStateOnSurface firstTSOS;
0175 bool conversionPassed = false;
0176 if (!useSegmentsInTrajectory) {
0177
0178 conversionPassed = filter()->transform(finalCandidate, hitContainer, firstTSOS);
0179 } else {
0180
0181 conversionPassed = filter()->transformLight(finalCandidate, hitContainer, firstTSOS);
0182 }
0183 if (conversionPassed && !finalCandidate.empty() && !hitContainer.empty()) {
0184
0185
0186
0187 edm::OwnVector<TrackingRecHit> recHitsContainer;
0188 for (unsigned int iHit = 0; iHit < hitContainer.size(); ++iHit) {
0189 recHitsContainer.push_back(hitContainer.at(iHit)->hit()->clone());
0190 }
0191 PropagationDirection dir = oppositeToMomentum;
0192 if (useSegmentsInTrajectory) {
0193 dir = alongMomentum;
0194 }
0195
0196 PTrajectoryStateOnDet seedTSOS =
0197 trajectoryStateTransform::persistentState(firstTSOS, hitContainer.at(0)->geographicalId().rawId());
0198 TrajectorySeed seed(seedTSOS, recHitsContainer, dir);
0199
0200
0201
0202
0203
0204
0205
0206 output->push_back(seed);
0207 } else {
0208
0209 continue;
0210 }
0211 } else {
0212
0213 continue;
0214 }
0215 }
0216 event.put(std::move(output));
0217 theFilter->reset();
0218 }
0219
0220
0221 void SETMuonSeedProducer::setEvent(const edm::Event& event) { theFilter->setEvent(event); }