Skip to content

Commit

Permalink
Add MultiHitFromChi2EDProducer
Browse files Browse the repository at this point in the history
  • Loading branch information
makortel committed Nov 18, 2016
1 parent ec52d99 commit 02ef592
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 8 deletions.
6 changes: 5 additions & 1 deletion DataFormats/TrackerRecHit2D/src/classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <vector>

namespace DataFormats_TrackerRecHit2D {
Expand Down Expand Up @@ -62,7 +63,10 @@ namespace DataFormats_TrackerRecHit2D {
edm::ClonePolicy<SiTrackerMultiRecHit> > e3;
edm::OwnVector<SiTrackerMultiRecHit,
edm::ClonePolicy<SiTrackerMultiRecHit> >::const_iterator it10;


edm::OwnVector<BaseTrackerRecHit> ovbtrh;
edm::Wrapper<edm::OwnVector<BaseTrackerRecHit>> wovbtrh;

edm::Wrapper< edm::RangeMap<DetId,
edm::OwnVector<SiStripRecHit2D,
edm::ClonePolicy<SiStripRecHit2D> >,
Expand Down
4 changes: 4 additions & 0 deletions DataFormats/TrackerRecHit2D/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
<class name="edm::OwnVector<SiStripRecHit1D,edm::ClonePolicy<SiStripRecHit1D> >::const_iterator"/>

<class name="edm::OwnVector<SiTrackerMultiRecHit,edm::ClonePolicy<SiTrackerMultiRecHit> >::const_iterator"/>

<class name="edm::OwnVector<BaseTrackerRecHit>" persistent="false"/>
<class name="edm::Wrapper<edm::OwnVector<BaseTrackerRecHit> >" persistent="false"/>

<class name="edm::RangeMap<DetId, edm::OwnVector<SiStripRecHit2D, edm::ClonePolicy<SiStripRecHit2D> >, edm::ClonePolicy<SiStripRecHit2D> >"/>
<class name="edm::RangeMap<DetId, edm::OwnVector<SiStripRecHit1D, edm::ClonePolicy<SiStripRecHit1D> >, edm::ClonePolicy<SiStripRecHit1D> >"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<HitPairGeneratorFromLayerPair>&& pairGenerator, LayerCacheType *layerCache);
Expand Down
141 changes: 141 additions & 0 deletions RecoTracker/TkSeedGenerator/plugins/MultiHitFromChi2EDProducer.cc
Original file line number Diff line number Diff line change
@@ -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<IntermediateHitDoublets> doubletToken_;

edm::RunningAverage localRA_;

MultiHitGeneratorFromChi2 generator_;
};

MultiHitFromChi2EDProducer::MultiHitFromChi2EDProducer(const edm::ParameterSet& iConfig):
doubletToken_(consumes<IntermediateHitDoublets>(iConfig.getParameter<edm::InputTag>("doublets"))),
generator_(iConfig)
{
produces<RegionsSeedingHitSets>();
produces<edm::OwnVector<BaseTrackerRecHit> >();
}

void MultiHitFromChi2EDProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;

desc.add<edm::InputTag>("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<IntermediateHitDoublets> 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<RegionsSeedingHitSets>();
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<LayerTriplets::LayerSetAndLayers> trilayers = LayerTriplets::layers(seedingLayerHits);

OrderedMultiHits multihits;
multihits.reserve(localRA_.upper());
std::vector<std::unique_ptr<BaseTrackerRecHit> > 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(&region);

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<pair+third layers>. 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<edm::OwnVector<BaseTrackerRecHit> >();
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);
67 changes: 61 additions & 6 deletions RecoTracker/TkSeedGenerator/plugins/MultiHitGeneratorFromChi2.cc
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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<bool>("useFixedPreFiltering", false);
desc.add<double>("phiPreFiltering", 0.3);

// box properties
desc.add<double>("extraHitRPhitolerance", 0);
desc.add<double>("extraHitRZtolerance", 0);
desc.add<double>("extraZKDBox", 0.2);
desc.add<double>("extraRKDBox", 0.2);
desc.add<double>("extraPhiKDBox", 0.005);
desc.add<double>("fnSigmaRZ", 2.0);

// refit&filter hits
desc.add<bool>("refitHits", true);
desc.add<std::string>("ClusterShapeHitFilterName", "ClusterShapeHitFilter");
desc.add<std::string>("TTRHBuilder", "WithTrackAngle");

// chi2 cuts
desc.add<double>("maxChi2", 5.0);
desc.add<bool>("chi2VsPtCut", true);
desc.add<std::vector<double> >("pt_interv", std::vector<double>{{0.4,0.7,1.0,2.0}});
desc.add<std::vector<double> >("chi2_cuts", std::vector<double>{{3.0,4.0,5.0,5.0}});

// debugging
desc.add<std::vector<int> >("detIdsToDebug", std::vector<int>{{0,0,0}});
}


void MultiHitGeneratorFromChi2::initES(const edm::EventSetup& es)
{

Expand Down Expand Up @@ -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<SeedingLayerSetsHits::SeedingLayer>& thirdLayers,
LayerCacheType& layerCache,
cacheHits& refittedHitStorage) {
int size = thirdLayers.size();
const RecHitsSortedInPhi * thirdHitMap[size];
vector<const DetLayer *> thirdLayerDetLayer(size,0);
for (int il=0; il<size; ++il)
{
thirdHitMap[il] = &(*theLayerCache)(thirdLayers[il], region, es);
thirdHitMap[il] = &layerCache(thirdLayers[il], region, es);

thirdLayerDetLayer[il] = thirdLayers[il].detLayer();
}
hitTriplets(region,result,es,doublets,thirdHitMap,thirdLayerDetLayer,size);
hitSets(region, result, es, doublets, thirdHitMap, thirdLayerDetLayer, size, refittedHitStorage);
}

void MultiHitGeneratorFromChi2::hitTriplets(
const TrackingRegion& region,
OrderedMultiHits & result,
Expand All @@ -181,7 +227,16 @@ void MultiHitGeneratorFromChi2::hitTriplets(
const std::vector<const DetLayer *> & 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<const DetLayer *>& thirdLayerDetLayer,
const int nThirdLayers,
cacheHits& refittedHitStorage) {
unsigned int debug_Id0 = detIdsToDebug[0];
unsigned int debug_Id1 = detIdsToDebug[1];
unsigned int debug_Id2 = detIdsToDebug[2];
Expand Down Expand Up @@ -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<BaseTrackerRecHit*>(hit0.release()));
cache.emplace_back(const_cast<BaseTrackerRecHit*>(hit1.release()));
cache.emplace_back(std::move(bestH2));
refittedHitStorage.emplace_back(const_cast<BaseTrackerRecHit*>(hit0.release()));
refittedHitStorage.emplace_back(const_cast<BaseTrackerRecHit*>(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
Expand Down
19 changes: 19 additions & 0 deletions RecoTracker/TkSeedGenerator/plugins/MultiHitGeneratorFromChi2.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,24 @@ 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,
const edm::Event & ev, const edm::EventSetup& es,
SeedingLayerSetsHits::SeedingLayerSet pairLayers,
std::vector<SeedingLayerSetsHits::SeedingLayer> thirdLayers);

void hitSets(const TrackingRegion& region, OrderedMultiHits& trs,
const edm::Event& ev, const edm::EventSetup& es,
const HitDoublets& doublets,
const std::vector<SeedingLayerSetsHits::SeedingLayer>& thirdLayers,
LayerCacheType& layerCache,
cacheHits& refittedHitStorage);

void hitTriplets(
const TrackingRegion& region,
OrderedMultiHits & result,
Expand All @@ -48,6 +59,14 @@ typedef CombinedMultiHitGenerator::LayerCacheType LayerCacheType;
const RecHitsSortedInPhi ** thirdHitMap,
const std::vector<const DetLayer *> & 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<const DetLayer *>& thirdLayerDetLayer,
const int nThirdLayers,
cacheHits& refittedHitStorage);
private:
using HitOwnPtr = mayown_ptr<BaseTrackerRecHit>;

Expand Down
Original file line number Diff line number Diff line change
@@ -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),
Expand All @@ -9,6 +10,10 @@ MultiHitGeneratorFromPairAndLayers::MultiHitGeneratorFromPairAndLayers(const edm

MultiHitGeneratorFromPairAndLayers::~MultiHitGeneratorFromPairAndLayers() {}

void MultiHitGeneratorFromPairAndLayers::fillDescriptions(edm::ParameterSetDescription& desc) {
desc.add<unsigned int>("maxElement", 100000);
}

void MultiHitGeneratorFromPairAndLayers::init(std::unique_ptr<HitPairGeneratorFromLayerPair>&& pairGenerator, LayerCacheType *layerCache) {
thePairGenerator = std::move(pairGenerator);
theLayerCache = layerCache;
Expand Down

0 comments on commit 02ef592

Please sign in to comment.