File indexing completed on 2024-04-06 12:28:27
0001 #include "RecoTracker/NuclearSeedGenerator/interface/NuclearSeedsEDProducer.h"
0002 #include "RecoTracker/NuclearSeedGenerator/interface/NuclearInteractionFinder.h"
0003
0004 #include "FWCore/Utilities/interface/InputTag.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006
0007 #include "TrackingTools/KalmanUpdators/interface/Chi2MeasurementEstimatorBase.h"
0008 #include "RecoTracker/Record/interface/NavigationSchoolRecord.h"
0009 #include "RecoTracker/Record/interface/CkfComponentsRecord.h"
0010
0011 #include "DataFormats/TrackReco/interface/Track.h"
0012 #include "DataFormats/TrackReco/interface/TrackBase.h"
0013
0014 using namespace edm;
0015 using namespace std;
0016 using namespace reco;
0017
0018
0019
0020
0021 NuclearSeedsEDProducer::NuclearSeedsEDProducer(const edm::ParameterSet& iConfig)
0022 : config_(),
0023 improveSeeds(iConfig.getParameter<bool>("improveSeeds")),
0024 producer_(consumes<TrajectoryCollection>(iConfig.getParameter<std::string>("producer"))),
0025 mteToken_(consumes<MeasurementTrackerEvent>(edm::InputTag("MeasurementTrackerEvents"))) {
0026 produces<TrajectorySeedCollection>();
0027 produces<TrajectoryToSeedsMap>();
0028
0029 trackerGeomToken_ = esConsumes<edm::Transition::BeginRun>();
0030 propagatorToken_ = esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", "PropagatorWithMaterial"));
0031 estimatorToken_ = esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", "Chi2"));
0032
0033 std::string measurementTrackerName = iConfig.getParameter<std::string>("MeasurementTrackerName");
0034 measurementTrackerToken_ = esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", measurementTrackerName));
0035 geomSearchTrackerToken_ = esConsumes<edm::Transition::BeginRun>();
0036
0037 auto navigationSchoolName = iConfig.getParameter<std::string>("NavigationSchool");
0038 navigationToken_ = esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", navigationSchoolName));
0039
0040 config_.maxHits = iConfig.getParameter<int>("maxHits");
0041 config_.rescaleErrorFactor = iConfig.getParameter<double>("rescaleErrorFactor");
0042 config_.checkCompletedTrack = iConfig.getParameter<bool>("checkCompletedTrack");
0043 config_.ptMin = iConfig.getParameter<double>("ptMin");
0044 }
0045
0046 NuclearSeedsEDProducer::~NuclearSeedsEDProducer() {}
0047
0048
0049
0050
0051
0052
0053 void NuclearSeedsEDProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0054 typedef TrajectoryMeasurement TM;
0055
0056 edm::Handle<TrajectoryCollection> m_TrajectoryCollection;
0057 iEvent.getByToken(producer_, m_TrajectoryCollection);
0058
0059 LogDebug("NuclearSeedGenerator") << "Number of trajectory in event :" << m_TrajectoryCollection->size() << "\n";
0060
0061 auto output = std::make_unique<TrajectorySeedCollection>();
0062 auto outAssoc = std::make_unique<TrajectoryToSeedsMap>();
0063
0064 edm::Handle<MeasurementTrackerEvent> data;
0065 iEvent.getByToken(mteToken_, data);
0066
0067
0068
0069 std::vector<std::pair<int, int> > assocPair;
0070 int i = 0;
0071
0072 for (std::vector<Trajectory>::const_iterator iTraj = m_TrajectoryCollection->begin();
0073 iTraj != m_TrajectoryCollection->end();
0074 iTraj++, i++) {
0075
0076 theNuclearInteractionFinder->run(*iTraj, *data);
0077
0078
0079 if (improveSeeds == true)
0080 theNuclearInteractionFinder->improveSeeds(*data);
0081
0082
0083 std::unique_ptr<TrajectorySeedCollection> newSeeds(theNuclearInteractionFinder->getPersistentSeeds());
0084 output->insert(output->end(), newSeeds->begin(), newSeeds->end());
0085
0086
0087 for (unsigned int j = 0; j < newSeeds->size(); j++) {
0088 assocPair.push_back(std::make_pair(i, output->size() - newSeeds->size() + j));
0089 }
0090 }
0091
0092 const edm::OrphanHandle<TrajectorySeedCollection> refprodTrajSeedColl = iEvent.put(std::move(output));
0093
0094 for (std::vector<std::pair<int, int> >::const_iterator iVecP = assocPair.begin(); iVecP != assocPair.end(); iVecP++) {
0095 outAssoc->insert(edm::Ref<TrajectoryCollection>(m_TrajectoryCollection, iVecP->first),
0096 edm::Ref<TrajectorySeedCollection>(refprodTrajSeedColl, iVecP->second));
0097 }
0098 iEvent.put(std::move(outAssoc));
0099 }
0100
0101
0102 void NuclearSeedsEDProducer::beginRun(edm::Run const& run, const edm::EventSetup& es) {
0103 theNuclearInteractionFinder = std::make_unique<NuclearInteractionFinder>(config_,
0104 &es.getData(trackerGeomToken_),
0105 &es.getData(propagatorToken_),
0106 &es.getData(estimatorToken_),
0107 &es.getData(measurementTrackerToken_),
0108 &es.getData(geomSearchTrackerToken_),
0109 &es.getData(navigationToken_));
0110 }
0111
0112 DEFINE_FWK_MODULE(NuclearSeedsEDProducer);