From 26ffbf33817164bbde05fddebee97080a2805f05 Mon Sep 17 00:00:00 2001 From: Paolo Andreetto Date: Tue, 22 Oct 2024 15:48:31 +0200 Subject: [PATCH] New Bin Schema for seeding --- ACTSTracking/ACTSSeededCKFTrackingProc.hxx | 7 ++- ACTSTracking/Helpers.hxx | 6 ++ src/ACTSSeededCKFTrackingProc.cxx | 73 +++++++++++++--------- src/Helpers.cxx | 41 ++++++++++++ 4 files changed, 97 insertions(+), 30 deletions(-) diff --git a/ACTSTracking/ACTSSeededCKFTrackingProc.hxx b/ACTSTracking/ACTSSeededCKFTrackingProc.hxx index c81df60..f7ced83 100644 --- a/ACTSTracking/ACTSSeededCKFTrackingProc.hxx +++ b/ACTSTracking/ACTSSeededCKFTrackingProc.hxx @@ -22,6 +22,7 @@ #include "SourceLink.hxx" #endif +#include /** * This code performs a true pattern recognition by looping over all MC @@ -91,12 +92,16 @@ class ACTSSeededCKFTrackingProc : public ACTSProcBase { float _seedFinding_radLengthPerSeed = 0.1; float _seedFinding_minPt = 500; float _seedFinding_impactMax = 3 * Acts::UnitConstants::mm; + float _seedFinding_cotThetaMax = 7.40627; - StringVec _seedFinding_zBinEdges; + StringVec _seedFinding_zBinSchema; int _zTopBinLen = 1; int _zBottomBinLen = 1; int _phiTopBinLen = 1; int _phiBottomBinLen = 1; + std::vector _zBinEdges; + std::vector> _ZTopBinSchema; + std::vector> _ZBottomBinSchema; // Track fit parameters double _initialTrackError_pos; diff --git a/ACTSTracking/Helpers.hxx b/ACTSTracking/Helpers.hxx index 1a2a9e3..2c7544a 100644 --- a/ACTSTracking/Helpers.hxx +++ b/ACTSTracking/Helpers.hxx @@ -15,12 +15,16 @@ #include "SourceLink.hxx" +#include + namespace ACTSTracking { using TrackResult = Acts::TrackContainer::TrackProxy; +using ZBinSchema = std::tuple; + //! Get path to a resource file /** * Get absolute file of a file `inpath` by looking in the following places: @@ -124,5 +128,7 @@ EVENT::LCCollection* getCollection(EVENT::LCEvent* evt, */ Acts::ParticleHypothesis getParticleHypothesis(const EVENT::MCParticle* mcParticle); +ZBinSchema parseZBinSchema(std::string schema_str); + } // namespace ACTSTracking diff --git a/src/ACTSSeededCKFTrackingProc.cxx b/src/ACTSSeededCKFTrackingProc.cxx index 8652845..0eadd63 100644 --- a/src/ACTSSeededCKFTrackingProc.cxx +++ b/src/ACTSSeededCKFTrackingProc.cxx @@ -130,9 +130,13 @@ ACTSSeededCKFTrackingProc::ACTSSeededCKFTrackingProc() "Number of bottom bins along phi for seeding", _phiBottomBinLen, 1); - registerProcessorParameter("SeedFinding_zBinEdges", - "Bins placement along Z for seeding.", - _seedFinding_zBinEdges, StringVec(0)); + registerProcessorParameter("SeedFinding_zBinSchema", + "Bins schema along Z for seeding.", + _seedFinding_zBinSchema, StringVec(0)); + + registerProcessorParameter("SeedFinding_cotThetaMax", + "Max theta angle for seeding", + _seedFinding_cotThetaMax, 7.40627f); registerProcessorParameter( "SeedFinding_CollisionRegion", @@ -223,6 +227,37 @@ void ACTSSeededCKFTrackingProc::init() { if (_seedFinding_deltaRMaxTop == 0.f) _seedFinding_deltaRMaxTop = _seedFinding_deltaRMax; if (_seedFinding_deltaRMinBottom == 0.f) _seedFinding_deltaRMinBottom = _seedFinding_deltaRMin; if (_seedFinding_deltaRMaxBottom == 0.f) _seedFinding_deltaRMaxBottom = _seedFinding_deltaRMax; + + if (_seedFinding_zBinSchema.size() > 0) + { + for (std::string token : _seedFinding_zBinSchema) + { + auto [ pos, ztop_sx, ztop_dx, zbottom_sx, zbottom_dx, err ] = ACTSTracking::parseZBinSchema(token); + if (err || pos < -_seedFinding_zMax || pos >= _seedFinding_zMax) + { + streamlog_out(WARNING) << "Wrong parameter SeedFinding_zBinSchema; default used" << std::endl; + _zBinEdges.clear(); + break; + } + _zBinEdges.push_back(pos); + _ZTopBinSchema.emplace_back(ztop_sx, ztop_dx); + _ZBottomBinSchema.emplace_back(zbottom_sx, zbottom_dx); + } + } + + if (_zBinEdges.empty()) + { + // taken from Acts::CylindricalSpacePointGridCreator::createGrid + float tmpf = 2 * _seedFinding_zMax / (_seedFinding_cotThetaMax * _seedFinding_deltaRMax); + int num_bins = static_cast(std::max(1.f, std::floor(tmpf))); + + for (int bin = 0; bin < num_bins; bin++) + { + _zBinEdges.push_back(-_seedFinding_zMax + bin * 2 * _seedFinding_zMax / num_bins); + _ZTopBinSchema.emplace_back(_zTopBinLen, _zTopBinLen); + _ZBottomBinSchema.emplace_back(_zBottomBinLen, _zBottomBinLen); + } + } } void ACTSSeededCKFTrackingProc::processRunHeader(LCRunHeader *) {} @@ -281,9 +316,7 @@ void ACTSSeededCKFTrackingProc::processEvent(LCEvent *evt) { sortedHits) { // Convert to Acts hit const Acts::Surface *surface = trackingGeometry()->findSurface(hit.first); - - std::cout << "hit: " << hit.first.volume() << " " << hit.first.boundary() << " " << hit.first.layer() << " " << hit.first.approach() << " " << hit.first.sensitive() << std::endl; - + if (surface == nullptr) throw std::runtime_error("Surface not found"); const double *lcioglobalpos = hit.second->getPosition(); @@ -319,9 +352,6 @@ void ACTSSeededCKFTrackingProc::processEvent(LCEvent *evt) { measurements.push_back(meas); sourceLinks.emplace_hint(sourceLinks.end(), sourceLink); - std::cout << surface->geometryId() << std::endl; - std::cout << _seedGeometrySelection.check(surface->geometryId()) << std::endl; - // // Seed selection and conversion to useful coordinates if (_seedGeometrySelection.check(surface->geometryId())) { @@ -455,7 +485,7 @@ void ACTSSeededCKFTrackingProc::processEvent(LCEvent *evt) { finderCfg.zMin = -_seedFinding_zMax; finderCfg.zMax = _seedFinding_zMax; finderCfg.maxSeedsPerSpM = 1; - finderCfg.cotThetaMax = 7.40627; // 2.7 eta; + finderCfg.cotThetaMax = _seedFinding_cotThetaMax; finderCfg.sigmaScattering = _seedFinding_sigmaScattering; finderCfg.radLengthPerSeed = _seedFinding_radLengthPerSeed; finderCfg.minPt = _seedFinding_minPt * Acts::UnitConstants::MeV; @@ -484,25 +514,9 @@ void ACTSSeededCKFTrackingProc::processEvent(LCEvent *evt) { gridCfg.zMax = finderCfg.zMax; gridCfg.zMin = finderCfg.zMin; gridCfg.impactMax = finderCfg.impactMax; - if (_seedFinding_zBinEdges.size() > 0) - { - gridCfg.zBinEdges.resize(_seedFinding_zBinEdges.size()); - for (int k = 0; k < _seedFinding_zBinEdges.size(); k++) - { - float pos = std::atof(_seedFinding_zBinEdges[k].c_str()); - if (pos >= finderCfg.zMin && pos < finderCfg.zMax) - { - gridCfg.zBinEdges[k] = pos; - } - else - { - streamlog_out(WARNING) << "Wrong parameter SeedFinding_zBinEdges; " - << "default used" << std::endl; - gridCfg.zBinEdges.clear(); - break; - } - } - } + + gridCfg.zBinEdges.resize(_zBinEdges.size()); + for (int k = 0; k < _zBinEdges.size(); k++) gridCfg.zBinEdges[k] = _zBinEdges[k]; Acts::CylindricalSpacePointGridOptions gridOpts; gridOpts.bFieldInZ = (*magneticField()->getField(zeropos, magCache))[2]; @@ -529,6 +543,7 @@ void ACTSSeededCKFTrackingProc::processEvent(LCEvent *evt) { spacePointPtrs.begin(), spacePointPtrs.end(), extractGlobalQuantities, rRangeSPExtent); + //TODO replace with schemas const Acts::GridBinFinder<2ul> bottomBinFinder(_phiBottomBinLen, _zBottomBinLen); const Acts::GridBinFinder<2ul> topBinFinder(_phiTopBinLen, _zTopBinLen); diff --git a/src/Helpers.cxx b/src/Helpers.cxx index c774af9..c3157d6 100644 --- a/src/Helpers.cxx +++ b/src/Helpers.cxx @@ -12,6 +12,7 @@ #include #include +#include #include "config.h" @@ -529,5 +530,45 @@ Acts::ParticleHypothesis getParticleHypothesis(const EVENT::MCParticle* mcPartic return Acts::ParticleHypothesis { pdg, mass, charge_type }; } +ZBinSchema parseZBinSchema(std::string schema_str) +{ + float pos = 0.0; + int t1 = 1; + int t2 = 1; + int b1 = 1; + int b2 = 1; + bool err = true; + + try + { + std::regex separator { "," }; + std::sregex_token_iterator item(schema_str.begin(), schema_str.end(), separator, -1); + std::sregex_token_iterator end_it; + for(int k = 0; item != end_it; k++) + { + switch(k) + { + case 0: + pos = std::stof(*item); break; + case 1: + t1 = std::stoi(*item); break; + case 2: + t2 = std::stoi(*item); break; + case 3: + b1 = std::stoi(*item); break; + case 4: + b2 = std::stoi(*item); err = false; + } + item++; + } + } + catch (std::invalid_argument const& ex) + {} + catch (std::out_of_range const& ex) + {} + + ZBinSchema result { pos, t1, t2, b1, b2, err }; + return result; +} } // namespace ACTSTracking