From 02ef592b0ab0cc5f681bdd9eba599296112c1377 Mon Sep 17 00:00:00 2001 From: Matti Kortelainen Date: Wed, 17 Aug 2016 17:17:38 +0200 Subject: [PATCH] Add MultiHitFromChi2EDProducer --- DataFormats/TrackerRecHit2D/src/classes.h | 6 +- .../TrackerRecHit2D/src/classes_def.xml | 4 + .../MultiHitGeneratorFromPairAndLayers.h | 4 +- .../plugins/MultiHitFromChi2EDProducer.cc | 141 ++++++++++++++++++ .../plugins/MultiHitGeneratorFromChi2.cc | 67 ++++++++- .../plugins/MultiHitGeneratorFromChi2.h | 19 +++ .../src/MultiHitGeneratorFromPairAndLayers.cc | 5 + 7 files changed, 238 insertions(+), 8 deletions(-) create mode 100644 RecoTracker/TkSeedGenerator/plugins/MultiHitFromChi2EDProducer.cc diff --git a/DataFormats/TrackerRecHit2D/src/classes.h b/DataFormats/TrackerRecHit2D/src/classes.h index e62dbf524dc7f..9bcb452602b3f 100644 --- a/DataFormats/TrackerRecHit2D/src/classes.h +++ b/DataFormats/TrackerRecHit2D/src/classes.h @@ -26,6 +26,7 @@ #include "DataFormats/TrackerRecHit2D/interface/FastProjectedTrackerRecHit.h" #include "DataFormats/TrackerRecHit2D/interface/FastTrackerRecHitCollection.h" #include "DataFormats/TrackerRecHit2D/interface/Phase2TrackerRecHit1D.h" +#include "DataFormats/TrackerRecHit2D/interface/BaseTrackerRecHit.h" #include namespace DataFormats_TrackerRecHit2D { @@ -62,7 +63,10 @@ namespace DataFormats_TrackerRecHit2D { edm::ClonePolicy > e3; edm::OwnVector >::const_iterator it10; - + + edm::OwnVector ovbtrh; + edm::Wrapper> wovbtrh; + edm::Wrapper< edm::RangeMap >, diff --git a/DataFormats/TrackerRecHit2D/src/classes_def.xml b/DataFormats/TrackerRecHit2D/src/classes_def.xml index 1d367bbac4bff..c4daab655997e 100644 --- a/DataFormats/TrackerRecHit2D/src/classes_def.xml +++ b/DataFormats/TrackerRecHit2D/src/classes_def.xml @@ -74,6 +74,10 @@ + + + + diff --git a/RecoTracker/TkSeedGenerator/interface/MultiHitGeneratorFromPairAndLayers.h b/RecoTracker/TkSeedGenerator/interface/MultiHitGeneratorFromPairAndLayers.h index ae78164e04558..90500ed94801c 100644 --- a/RecoTracker/TkSeedGenerator/interface/MultiHitGeneratorFromPairAndLayers.h +++ b/RecoTracker/TkSeedGenerator/interface/MultiHitGeneratorFromPairAndLayers.h @@ -12,7 +12,7 @@ #include "TrackingTools/TransientTrackingRecHit/interface/SeedingLayerSetsHits.h" #include "RecoTracker/TkHitPairs/interface/LayerHitMapCache.h" -namespace edm { class ParameterSet; class Event; class EventSetup; } +namespace edm { class ParameterSet; class Event; class EventSetup; class ParameterSetDescription;} class TrackingRegion; class HitPairGeneratorFromLayerPair; @@ -24,6 +24,8 @@ class MultiHitGeneratorFromPairAndLayers { explicit MultiHitGeneratorFromPairAndLayers(const edm::ParameterSet& pset); virtual ~MultiHitGeneratorFromPairAndLayers(); + static void fillDescriptions(edm::ParameterSetDescription& desc); + virtual void initES(const edm::EventSetup& es) = 0; void init(std::unique_ptr&& pairGenerator, LayerCacheType *layerCache); diff --git a/RecoTracker/TkSeedGenerator/plugins/MultiHitFromChi2EDProducer.cc b/RecoTracker/TkSeedGenerator/plugins/MultiHitFromChi2EDProducer.cc new file mode 100644 index 0000000000000..0eb5826c394db --- /dev/null +++ b/RecoTracker/TkSeedGenerator/plugins/MultiHitFromChi2EDProducer.cc @@ -0,0 +1,141 @@ +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "FWCore/Utilities/interface/EDGetToken.h" +#include "FWCore/Framework/interface/Event.h" +#include "DataFormats/Common/interface/Handle.h" +#include "FWCore/Utilities/interface/RunningAverage.h" + +#include "RecoTracker/TkHitPairs/interface/IntermediateHitDoublets.h" +#include "RecoTracker/TkHitPairs/interface/RegionsSeedingHitSets.h" +#include "DataFormats/Common/interface/OwnVector.h" +#include "RecoPixelVertexing/PixelTriplets/interface/LayerTriplets.h" +#include "MultiHitGeneratorFromChi2.h" + +class MultiHitFromChi2EDProducer: public edm::stream::EDProducer<> { +public: + MultiHitFromChi2EDProducer(const edm::ParameterSet& iConfig); + ~MultiHitFromChi2EDProducer() = default; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + virtual void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override; + +private: + edm::EDGetTokenT doubletToken_; + + edm::RunningAverage localRA_; + + MultiHitGeneratorFromChi2 generator_; +}; + +MultiHitFromChi2EDProducer::MultiHitFromChi2EDProducer(const edm::ParameterSet& iConfig): + doubletToken_(consumes(iConfig.getParameter("doublets"))), + generator_(iConfig) +{ + produces(); + produces >(); +} + +void MultiHitFromChi2EDProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + + desc.add("doublets", edm::InputTag("hitPairEDProducer")); + + MultiHitGeneratorFromChi2::fillDescriptions(desc); + + auto label = MultiHitGeneratorFromChi2::fillDescriptionsLabel() + std::string("EDProducer"); + descriptions.add(label, desc); +} + +void MultiHitFromChi2EDProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { + edm::Handle hdoublets; + iEvent.getByToken(doubletToken_, hdoublets); + const auto& regionDoublets = *hdoublets; + + const SeedingLayerSetsHits& seedingLayerHits = regionDoublets.seedingLayerHits(); + if(seedingLayerHits.numberOfLayersInSet() < 3) { + throw cms::Exception("Configuration") << "MultiHitFromChi2EDProducer expects SeedingLayerSetsHits::numberOfLayersInSet() to be >= 3, got " << seedingLayerHits.numberOfLayersInSet(); + } + + auto seedingHitSets = std::make_unique(); + if(regionDoublets.empty()) { + iEvent.put(std::move(seedingHitSets)); + return; + } + seedingHitSets->reserve(regionDoublets.regionSize(), localRA_.upper()); + generator_.initES(iSetup); + + // match-making of pair and triplet layers + std::vector trilayers = LayerTriplets::layers(seedingLayerHits); + + OrderedMultiHits multihits; + multihits.reserve(localRA_.upper()); + std::vector > refittedHitStorage; + refittedHitStorage.reserve(localRA_.upper()*2); + + LogDebug("MultiHitFromChi2EDProducer") << "Creating multihits for " << regionDoublets.regionSize() << " regions, and " << trilayers.size() << " pair+3rd layers from " << regionDoublets.layerPairsSize() << " layer pairs"; + + for(const auto& regionLayerPairs: regionDoublets) { + const TrackingRegion& region = regionLayerPairs.region(); + + auto seedingHitSetsFiller = RegionsSeedingHitSets::dummyFiller(); + seedingHitSetsFiller = seedingHitSets->beginRegion(®ion); + + LogTrace("MultiHitFromChi2EDProducer") << " starting region"; + + for(const auto& layerPair: regionLayerPairs) { + LogTrace("MultiHitFromChi2EDProducer") << " starting layer pair " << layerPair.innerLayerIndex() << "," << layerPair.outerLayerIndex(); + + auto found = std::find_if(trilayers.begin(), trilayers.end(), [&](const LayerTriplets::LayerSetAndLayers& a) { + return a.first[0].index() == layerPair.innerLayerIndex() && a.first[1].index() == layerPair.outerLayerIndex(); + }); + if(found == trilayers.end()) { + auto exp = cms::Exception("LogicError") << "Did not find the layer pair from vector. This is a sign of some internal inconsistency\n"; + exp << "I was looking for layer pair " << layerPair.innerLayerIndex() << "," << layerPair.outerLayerIndex() << ". Triplets have the following pairs:\n"; + for(const auto& a: trilayers) { + exp << " " << a.first[0].index() << "," << a.first[1].index() << ": 3rd layers"; + for(const auto& b: a.second) { + exp << " " << b.index(); + } + exp << "\n"; + } + throw exp; + } + const auto& thirdLayers = found->second; + + LayerHitMapCache hitCache; + hitCache.extend(layerPair.cache()); + LayerHitMapCache *hitCachePtr = &hitCache; + + generator_.hitSets(region, multihits, iEvent, iSetup, layerPair.doublets(), thirdLayers, *hitCachePtr, refittedHitStorage); + +#ifdef EDM_ML_DEBUG + LogTrace("MultiHitFromChi2EDProducer") << " created " << multihits.size() << " multihits for layer pair " << layerPair.innerLayerIndex() << "," << layerPair.outerLayerIndex() << " and 3rd layers"; + for(const auto& l: thirdLayers) { + LogTrace("MultiHitFromChi2EDProducer") << " " << l.index(); + } +#endif + + for(const SeedingHitSet& hitSet: multihits) { + seedingHitSetsFiller.emplace_back(hitSet); + } + multihits.clear(); + } + } + localRA_.update(seedingHitSets->size()); + + auto storage = std::make_unique >(); + storage->reserve(refittedHitStorage.size()); + for(auto& ptr: refittedHitStorage) + storage->push_back(ptr.release()); + + iEvent.put(std::move(seedingHitSets)); + iEvent.put(std::move(storage)); +} + +#include "FWCore/PluginManager/interface/ModuleDef.h" +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(MultiHitFromChi2EDProducer); diff --git a/RecoTracker/TkSeedGenerator/plugins/MultiHitGeneratorFromChi2.cc b/RecoTracker/TkSeedGenerator/plugins/MultiHitGeneratorFromChi2.cc index eaa95ccbbd1f7..7a15e372310c1 100644 --- a/RecoTracker/TkSeedGenerator/plugins/MultiHitGeneratorFromChi2.cc +++ b/RecoTracker/TkSeedGenerator/plugins/MultiHitGeneratorFromChi2.cc @@ -1,4 +1,5 @@ #include "RecoTracker/TkSeedGenerator/plugins/MultiHitGeneratorFromChi2.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "RecoPixelVertexing/PixelTriplets/interface/ThirdHitPredictionFromCircle.h" #include "RecoPixelVertexing/PixelTriplets/plugins/ThirdHitRZPrediction.h" @@ -109,6 +110,39 @@ MultiHitGeneratorFromChi2::MultiHitGeneratorFromChi2(const edm::ParameterSet& cf } MultiHitGeneratorFromChi2::~MultiHitGeneratorFromChi2() {} + + +void MultiHitGeneratorFromChi2::fillDescriptions(edm::ParameterSetDescription& desc) { + MultiHitGeneratorFromPairAndLayers::fillDescriptions(desc); + + // fixed phi filtering + desc.add("useFixedPreFiltering", false); + desc.add("phiPreFiltering", 0.3); + + // box properties + desc.add("extraHitRPhitolerance", 0); + desc.add("extraHitRZtolerance", 0); + desc.add("extraZKDBox", 0.2); + desc.add("extraRKDBox", 0.2); + desc.add("extraPhiKDBox", 0.005); + desc.add("fnSigmaRZ", 2.0); + + // refit&filter hits + desc.add("refitHits", true); + desc.add("ClusterShapeHitFilterName", "ClusterShapeHitFilter"); + desc.add("TTRHBuilder", "WithTrackAngle"); + + // chi2 cuts + desc.add("maxChi2", 5.0); + desc.add("chi2VsPtCut", true); + desc.add >("pt_interv", std::vector{{0.4,0.7,1.0,2.0}}); + desc.add >("chi2_cuts", std::vector{{3.0,4.0,5.0,5.0}}); + + // debugging + desc.add >("detIdsToDebug", std::vector{{0,0,0}}); +} + + void MultiHitGeneratorFromChi2::initES(const edm::EventSetup& es) { @@ -161,17 +195,29 @@ void MultiHitGeneratorFromChi2::hitSets(const TrackingRegion& region, // LogDebug("MultiHitGeneratorFromChi2") << "empy pairs"; return; } + + assert(theLayerCache); + hitSets(region, result, ev, es, doublets, thirdLayers, *theLayerCache, cache); +} + +void MultiHitGeneratorFromChi2::hitSets(const TrackingRegion& region, OrderedMultiHits& result, + const edm::Event& ev, const edm::EventSetup& es, + const HitDoublets& doublets, + const std::vector& thirdLayers, + LayerCacheType& layerCache, + cacheHits& refittedHitStorage) { int size = thirdLayers.size(); const RecHitsSortedInPhi * thirdHitMap[size]; vector thirdLayerDetLayer(size,0); for (int il=0; il & thirdLayerDetLayer, const int nThirdLayers) { + hitSets(region, result, es, doublets, thirdHitMap, thirdLayerDetLayer, nThirdLayers, cache); +} +void MultiHitGeneratorFromChi2::hitSets(const TrackingRegion& region, OrderedMultiHits& result, + const edm::EventSetup& es, + const HitDoublets& doublets, + const RecHitsSortedInPhi **thirdHitMap, + const std::vector& thirdLayerDetLayer, + const int nThirdLayers, + cacheHits& refittedHitStorage) { unsigned int debug_Id0 = detIdsToDebug[0]; unsigned int debug_Id1 = detIdsToDebug[1]; unsigned int debug_Id2 = detIdsToDebug[2]; @@ -637,12 +692,12 @@ void MultiHitGeneratorFromChi2::hitTriplets( assert(bestH2); result.emplace_back(&*hit0,&*hit1,&*bestH2); assert(hit0.isOwn()); assert(hit1.isOwn()); - cache.emplace_back(const_cast(hit0.release())); - cache.emplace_back(const_cast(hit1.release())); - cache.emplace_back(std::move(bestH2)); + refittedHitStorage.emplace_back(const_cast(hit0.release())); + refittedHitStorage.emplace_back(const_cast(hit1.release())); + refittedHitStorage.emplace_back(std::move(bestH2)); assert(hit0.empty()); assert(hit1.empty());assert(!bestH2); } - // LogTrace("MultiHitGeneratorFromChi2") << (usePair ? "pair " : "triplet ") << minChi2 <<' ' << cache.size(); + // LogTrace("MultiHitGeneratorFromChi2") << (usePair ? "pair " : "triplet ") << minChi2 <<' ' << refittedHitStorage.size(); }//loop over pairs diff --git a/RecoTracker/TkSeedGenerator/plugins/MultiHitGeneratorFromChi2.h b/RecoTracker/TkSeedGenerator/plugins/MultiHitGeneratorFromChi2.h index 0952fcf76fa8c..10180b64f66f9 100644 --- a/RecoTracker/TkSeedGenerator/plugins/MultiHitGeneratorFromChi2.h +++ b/RecoTracker/TkSeedGenerator/plugins/MultiHitGeneratorFromChi2.h @@ -33,6 +33,10 @@ typedef CombinedMultiHitGenerator::LayerCacheType LayerCacheType; virtual ~MultiHitGeneratorFromChi2(); + static void fillDescriptions(edm::ParameterSetDescription& desc); + static const char *fillDescriptionsLabel() { return "multiHitFromChi2"; } + + void initES(const edm::EventSetup& es) override; virtual void hitSets( const TrackingRegion& region, OrderedMultiHits & trs, @@ -40,6 +44,13 @@ typedef CombinedMultiHitGenerator::LayerCacheType LayerCacheType; SeedingLayerSetsHits::SeedingLayerSet pairLayers, std::vector thirdLayers); + void hitSets(const TrackingRegion& region, OrderedMultiHits& trs, + const edm::Event& ev, const edm::EventSetup& es, + const HitDoublets& doublets, + const std::vector& thirdLayers, + LayerCacheType& layerCache, + cacheHits& refittedHitStorage); + void hitTriplets( const TrackingRegion& region, OrderedMultiHits & result, @@ -48,6 +59,14 @@ typedef CombinedMultiHitGenerator::LayerCacheType LayerCacheType; const RecHitsSortedInPhi ** thirdHitMap, const std::vector & thirdLayerDetLayer, const int nThirdLayers)override; + + void hitSets(const TrackingRegion& region, OrderedMultiHits& result, + const edm::EventSetup& es, + const HitDoublets& doublets, + const RecHitsSortedInPhi **thirdHitMap, + const std::vector& thirdLayerDetLayer, + const int nThirdLayers, + cacheHits& refittedHitStorage); private: using HitOwnPtr = mayown_ptr; diff --git a/RecoTracker/TkSeedGenerator/src/MultiHitGeneratorFromPairAndLayers.cc b/RecoTracker/TkSeedGenerator/src/MultiHitGeneratorFromPairAndLayers.cc index c30bee5bf3dd6..7ee917ae14ab6 100644 --- a/RecoTracker/TkSeedGenerator/src/MultiHitGeneratorFromPairAndLayers.cc +++ b/RecoTracker/TkSeedGenerator/src/MultiHitGeneratorFromPairAndLayers.cc @@ -1,6 +1,7 @@ #include "RecoTracker/TkSeedGenerator/interface/MultiHitGeneratorFromPairAndLayers.h" #include "RecoTracker/TkHitPairs/interface/HitPairGeneratorFromLayerPair.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" MultiHitGeneratorFromPairAndLayers::MultiHitGeneratorFromPairAndLayers(const edm::ParameterSet& pset): theLayerCache(nullptr), @@ -9,6 +10,10 @@ MultiHitGeneratorFromPairAndLayers::MultiHitGeneratorFromPairAndLayers(const edm MultiHitGeneratorFromPairAndLayers::~MultiHitGeneratorFromPairAndLayers() {} +void MultiHitGeneratorFromPairAndLayers::fillDescriptions(edm::ParameterSetDescription& desc) { + desc.add("maxElement", 100000); +} + void MultiHitGeneratorFromPairAndLayers::init(std::unique_ptr&& pairGenerator, LayerCacheType *layerCache) { thePairGenerator = std::move(pairGenerator); theLayerCache = layerCache;