Skip to content

Commit

Permalink
New Bin Schema for seeding
Browse files Browse the repository at this point in the history
  • Loading branch information
pandreetto committed Oct 22, 2024
1 parent 8f30bab commit 26ffbf3
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 30 deletions.
7 changes: 6 additions & 1 deletion ACTSTracking/ACTSSeededCKFTrackingProc.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "SourceLink.hxx"
#endif

#include <utility>

/**
* This code performs a true pattern recognition by looping over all MC
Expand Down Expand Up @@ -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<float> _zBinEdges;
std::vector<std::pair<int, int>> _ZTopBinSchema;
std::vector<std::pair<int, int>> _ZBottomBinSchema;

// Track fit parameters
double _initialTrackError_pos;
Expand Down
6 changes: 6 additions & 0 deletions ACTSTracking/Helpers.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@

#include "SourceLink.hxx"

#include <tuple>

namespace ACTSTracking {

using TrackResult = Acts::TrackContainer<Acts::VectorTrackContainer,
Acts::VectorMultiTrajectory,
std::shared_ptr>::TrackProxy;

using ZBinSchema = std::tuple<float, int, int, int, int, bool>;

//! Get path to a resource file
/**
* Get absolute file of a file `inpath` by looking in the following places:
Expand Down Expand Up @@ -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

73 changes: 44 additions & 29 deletions src/ACTSSeededCKFTrackingProc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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<int>(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 *) {}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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())) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand All @@ -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);

Expand Down
41 changes: 41 additions & 0 deletions src/Helpers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <Acts/EventData/ParticleHypothesis.hpp>

#include <filesystem>
#include <regex>

#include "config.h"

Expand Down Expand Up @@ -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

0 comments on commit 26ffbf3

Please sign in to comment.