Skip to content

Commit

Permalink
Added support for excluding collections used for initial seed hit cre…
Browse files Browse the repository at this point in the history
…ation. Added per-step debug histograms
  • Loading branch information
Nazar Bartosik committed Nov 10, 2020
1 parent 6b655fe commit 1cd68dc
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 14 deletions.
14 changes: 12 additions & 2 deletions include/ConformalTracking.h
Expand Up @@ -76,8 +76,8 @@ class ConformalTracking : public Processor {
virtual void parseStepParameters();

// Track finding
void buildNewTracks(UniqueKDTracks&, SharedKDClusters&, UKDTree&, Parameters const&, bool radialSearch = false,
bool vertexToTracker = true);
void buildNewTracks(UniqueKDTracks&, SharedKDClusters&, SharedKDClusters&, UKDTree&, Parameters const&,
bool radialSearch = false, bool vertexToTracker = true);
bool neighbourIsCompatible(const SKDCluster& neighbourHit, const SKDCluster& seedHit, const double slopeZRange);
void extendTracks(UniqueKDTracks&, SharedKDClusters&, UKDTree&, Parameters const&);
void combineCollections(SharedKDClusters&, UKDTree&, std::vector<int> const&, std::map<int, SharedKDClusters> const&);
Expand Down Expand Up @@ -199,6 +199,16 @@ class ConformalTracking : public Processor {
TH2F* m_xyDistribution = nullptr;
TH3F* m_xyzDistribution = nullptr;

// Conformal search histograms
std::vector<TH1F*> m_search_cell_angle{};
std::vector<TH1F*> m_search_cell_angleRZ{};
std::vector<TH1F*> m_search_cell_slopeZ{};
std::vector<TH1F*> m_search_cell_length{};
std::vector<TH1F*> m_search_track_nClusters{};
std::vector<TH1F*> m_search_track_chi2{};
std::vector<TH1F*> m_search_track_chi2ZS{};

// Timing histograms
std::vector<TH1F*> m_timing_buildNewTracks{};
std::vector<TH1F*> m_timing_buildNewTracks_neighbourSearch{};
std::vector<TH1F*> m_timing_buildNewTracks_seeding{};
Expand Down
4 changes: 3 additions & 1 deletion include/Parameters.h
Expand Up @@ -15,6 +15,7 @@ struct Parameters {

public:
std::vector<int> _collections; /// which collections to combine
std::vector<int> _seedCollections; /// which collections to use for seeding
double _maxCellAngle;
double _maxCellAngleRZ;
double _chi2cut;
Expand Down Expand Up @@ -44,11 +45,12 @@ struct Parameters {
"MaxCellAngle", "MaxCellAngleRZ", "Chi2Cut", "MinClustersOnTrack", "MaxDistance", "SlopeZRange", "HighPTCut",
};

Parameters(std::vector<int> const& collections, double maxCellAngle, double maxCellAngleRZ, double chi2cut,
Parameters(std::vector<int> const& collections, std::vector<int> const& seedCollections, double maxCellAngle, double maxCellAngleRZ, double chi2cut,
int minClustersOnTrack, double maxDistance, double maxSlopeZ, double highPTcut, bool highPTfit,
bool onlyZSchi2cut, bool radialSearch, bool vertexToTracker, bool kalmanFitForward, int step, bool combine,
bool build, bool extend, bool sortTracks)
: _collections(collections),
_seedCollections(seedCollections),
_maxCellAngle(maxCellAngle),
_maxCellAngleRZ(maxCellAngleRZ),
_chi2cut(chi2cut),
Expand Down
96 changes: 86 additions & 10 deletions src/ConformalTracking.cc
Expand Up @@ -240,6 +240,28 @@ void ConformalTracking::init() {
new TCanvas("canvConformalEventDisplayMCunreconstructed", "canvConformalEventDisplayMCunreconstructed");
}

// Initialize conformal search histograms
if (m_debugPlots) {
for (auto const& parameters : _stepParameters) {
char hname[100];
sprintf(hname, "search_angle_%d", parameters._step);
m_search_cell_angle.push_back(new TH1F(hname, ";Cell angle;Cells", 1e3, 0., 0.1));
sprintf(hname, "search_angleRZ_%d", parameters._step);
m_search_cell_angleRZ.push_back(new TH1F(hname, ";Cell angleRZ;Cells", 1e3, 0., 0.1));
sprintf(hname, "search_slopeZ_%d", parameters._step);
m_search_cell_slopeZ.push_back(new TH1F(hname, ";slopeZ;Cells", 2e3, -20, 20));
sprintf(hname, "search_length_%d", parameters._step);
m_search_cell_length.push_back(new TH1F(hname, ";Length;Cells", 1e3, 0., 0.1));
sprintf(hname, "search_nClusters_%d", parameters._step);
m_search_track_nClusters.push_back(new TH1F(hname, ";# clusters;Conformal tracks", 30, 0, 30));
sprintf(hname, "search_chi2_%d", parameters._step);
m_search_track_chi2.push_back(new TH1F(hname, ";#chi^{2}/NDF;Conformal tracks", 2e3, 0, 200));
sprintf(hname, "search_chi2ZS_%d", parameters._step);
m_search_track_chi2ZS.push_back(new TH1F(hname, ";#chi^{2}_{ZS}/NDF;Conformal tracks", 2e3, 0, 200));

}
}

// Initialize timing monitoring histograms
if (m_debugTime) {
for (auto const& parameters : _stepParameters) {
Expand Down Expand Up @@ -279,53 +301,53 @@ void ConformalTracking::parseStepParameters() {

int step = 0;
// Build tracks in the vertex barrel
Parameters initialParameters(m_vertexBarrelHits, m_maxCellAngle, m_maxCellAngleRZ, m_chi2cut, m_minClustersOnTrack,
Parameters initialParameters(m_vertexBarrelHits, m_vertexBarrelHits,m_maxCellAngle, m_maxCellAngleRZ, m_chi2cut, m_minClustersOnTrack,
m_maxDistance, m_slopeZRange, m_highPTcut, /*highPT*/ true, /*OnlyZS*/ false,
/*rSearch*/ false,
/*vtt*/ true, /*kalmanFitForward*/ true, step++,
/*combine*/ true, /*build*/ true, /*extend*/ false, /*sort*/ false);
// Extend through the endcap
Parameters parameters2(m_vertexEndcapHits, m_maxCellAngle, m_maxCellAngleRZ, m_chi2cut, m_minClustersOnTrack,
Parameters parameters2(m_vertexEndcapHits, m_vertexEndcapHits, m_maxCellAngle, m_maxCellAngleRZ, m_chi2cut, m_minClustersOnTrack,
m_maxDistance, m_slopeZRange, m_highPTcut, /*highPT*/ true, /*OnlyZS*/ false,
/*rSearch*/ false, /*vtt*/ true,
/*kalmanFitForward*/ true, step++,
/*combine*/ true, /*build*/ false, /*extend*/ true, /*sort*/ false);
// Make combined vertex tracks
Parameters parametersTCVC(m_vertexCombinedHits, m_maxCellAngle, m_maxCellAngleRZ, m_chi2cut, m_minClustersOnTrack,
Parameters parametersTCVC(m_vertexCombinedHits, m_vertexCombinedHits, m_maxCellAngle, m_maxCellAngleRZ, m_chi2cut, m_minClustersOnTrack,
m_maxDistance, m_slopeZRange, m_highPTcut, /*highPT*/ true, /*OnlyZS*/ false,
/*rSearch*/ false, /*vtt*/ true,
/*kalmanFitForward*/ true, step++,
/*combine*/ true, /*build*/ true, /*extend*/ false, /*sort*/ false);
// Make leftover tracks in the vertex with lower requirements
// 1. open the cell angles
Parameters lowerCellAngleParameters(m_vertexCombinedHits, m_maxCellAngle * 5.0, m_maxCellAngleRZ * 5.0, m_chi2cut,
Parameters lowerCellAngleParameters(m_vertexCombinedHits, m_vertexCombinedHits, m_maxCellAngle * 5.0, m_maxCellAngleRZ * 5.0, m_chi2cut,
m_minClustersOnTrack, m_maxDistance, m_slopeZRange, m_highPTcut,
/*highPT*/ true, /*OnlyZS*/ false,
/*rSearch*/ true, /*vtt*/ true, /*kalmanFitForward*/ true, step++,
/*combine*/ not m_enableTCVC, /*build*/ true, /*extend*/ false, /*sort*/ false);
// 2. open further the cell angles and increase the chi2cut
Parameters lowerCellAngleParameters2({}, m_maxCellAngle * 10.0, m_maxCellAngleRZ * 10.0, m_chi2cut * 20.0,
Parameters lowerCellAngleParameters2({}, {}, m_maxCellAngle * 10.0, m_maxCellAngleRZ * 10.0, m_chi2cut * 20.0,
m_minClustersOnTrack, m_maxDistance, m_slopeZRange, m_highPTcut,
/*highPT*/ true, /*OnlyZS*/ false,
/*rSearch*/ true, /*vtt*/ true, /*kalmanFitForward*/ true, step++,
/*combine*/ false, /*build*/ true, /*extend*/ false, /*sort*/ false);
// 3. min number of hits on the track = 4

Parameters lowNumberHitsParameters({}, m_maxCellAngle * 10.0, m_maxCellAngleRZ * 10.0, m_chi2cut * 20.0,
Parameters lowNumberHitsParameters({}, {}, m_maxCellAngle * 10.0, m_maxCellAngleRZ * 10.0, m_chi2cut * 20.0,
/*m_minClustersOnTrack*/ 4, m_maxDistance, m_slopeZRange, m_highPTcut,
/*highPT*/ true,
/*OnlyZS*/ false,
/*rSearch*/ true, /*vtt*/ true, /*kalmanFitForward*/ true, step++,
/*combine*/ false, /*build*/ true, /*extend*/ false, /*sort*/ true);
// Extend through inner and outer trackers
Parameters trackerParameters(m_trackerHits, m_maxCellAngle * 10.0, m_maxCellAngleRZ * 10.0, m_chi2cut * 20.0,
Parameters trackerParameters(m_trackerHits, m_trackerHits, m_maxCellAngle * 10.0, m_maxCellAngleRZ * 10.0, m_chi2cut * 20.0,
/*m_minClustersOnTrack*/ 4, m_maxDistance, m_slopeZRange, /*highPTcut*/ 1.0,
/*highPT*/ true,
/*OnlyZS*/ false,
/*rSearch*/ true, /*vtt*/ true, /*kalmanFitForward*/ true, step++,
/*combine*/ true, /*build*/ false, /*extend*/ true, /*sort*/ false);
// Finally reconstruct displaced tracks
Parameters displacedParameters(m_allHits, m_maxCellAngle * 10.0, m_maxCellAngleRZ * 10.0, m_chi2cut * 10.0,
Parameters displacedParameters(m_allHits, m_allHits, m_maxCellAngle * 10.0, m_maxCellAngleRZ * 10.0, m_chi2cut * 10.0,
/*m_minClustersOnTrack*/ 5, 0.015, m_slopeZRange, m_highPTcut,
/*highPT*/ false, /*OnlyZS*/ true,
/*rSearch*/ true,
Expand Down Expand Up @@ -625,6 +647,48 @@ void ConformalTracking::processEvent(LCEvent* evt) {
for (auto const& parameters : _stepParameters) {
runStep(kdClusters, nearestNeighbours, conformalTracks, collectionClusters, parameters);
streamlog_out(DEBUG9) << "STEP " << parameters._step << ": nr tracks = " << conformalTracks.size() << std::endl;

// Filling debug plots with track/cell properties
if (m_debugPlots) {
for (auto const& confTrack : conformalTracks) {
m_search_track_nClusters.at(parameters._step)->Fill(confTrack->m_clusters.size());
m_search_track_chi2.at(parameters._step)->Fill(confTrack->chi2ndof());
m_search_track_chi2ZS .at(parameters._step)->Fill(confTrack->chi2ndofZS());
if (confTrack->m_clusters.size() < 3) continue;
// Creating cells for each pair of consecutive hits in the track
SCell cell0 = nullptr;
SCell cell1 = nullptr;
for (unsigned int ht = 0; ht < confTrack->m_clusters.size()-1; ht++) {
// Get the conformal clusters
const SKDCluster& cl0 = confTrack->m_clusters.at(ht);
const SKDCluster& cl1 = confTrack->m_clusters.at(ht+1);

// Calculating slopeZ between the two hits
double dX = cl1->getX() - cl0->getX();
double dY = cl1->getY() - cl0->getY();
double dZ = cl1->getZ() - cl0->getZ();
double slopeZ = dZ / sqrt(dX * dX + dY * dY);
m_search_cell_slopeZ.at(parameters._step)->Fill(slopeZ);

// Making a cell connecting the two hits
cell1 = std::make_shared<Cell>(cl0, cl1);
cell1->setWeight(ht);

double cell_length = sqrt(pow(cl0->getU() - cl1->getU(), 2) + pow(cl0->getV() - cl1->getV(), 2));
m_search_cell_length.at(parameters._step)->Fill(cell_length);

// Calculating angles between the previous and this cell
if (cell0) {
double angle = cell0->getAngle(cell1);
double angleRZ = cell0->getAngleRZ(cell1);
m_search_cell_angle.at(parameters._step)->Fill(angle);
m_search_cell_angleRZ.at(parameters._step)->Fill(angleRZ);
}
cell0 = SCell(cell1);
}
}
}

if (streamlog_level(DEBUG9)) {
for (auto const& confTrack : conformalTracks) {
streamlog_out(DEBUG9) << "- Track " << &confTrack << " has " << confTrack->m_clusters.size() << " hits" << std::endl;
Expand Down Expand Up @@ -949,10 +1013,11 @@ void ConformalTracking::combineCollections(SharedKDClusters& kdClusters, UKDTree
}

// Take a collection of hits and try to produce tracks out of them
void ConformalTracking::buildNewTracks(UniqueKDTracks& conformalTracks, SharedKDClusters& collection,
void ConformalTracking::buildNewTracks(UniqueKDTracks& conformalTracks, SharedKDClusters& collection, SharedKDClusters& seedCollection,
UKDTree& nearestNeighbours, Parameters const& parameters, bool radialSearch,
bool vertexToTracker) {
streamlog_out(DEBUG9) << "*** buildNewTracks" << std::endl;
streamlog_out(DEBUG9) << "Seeding from " << seedCollection.size() << " hits in a collection of total " << collection.size() << " hits" << std::endl;

// Sort the input collection by radius - higher to lower if starting with the vertex detector (high R in conformal space)
std::sort(collection.begin(), collection.end(), (vertexToTracker ? sort_by_radiusKD : sort_by_lower_radiusKD));
Expand All @@ -970,6 +1035,12 @@ void ConformalTracking::buildNewTracks(UniqueKDTracks& conformalTracks, SharedKD

streamlog_out(DEBUG9) << "Seed hit " << nKDHit << ": [x,y,z] = [" << kdhit->getX() << ", " << kdhit->getY() << ", "
<< kdhit->getZ() << "]" << std::endl;
// Skipping if the hit is not present in the seeding collection
if (std::find(seedCollection.begin(), seedCollection.end(), kdhit) == seedCollection.end()) {
streamlog_out(DEBUG7) << "hit not in the seeding collection" << std::endl;
continue;
}

if (m_debugPlots) {
m_X->Fill(kdhit->getX());
m_Y->Fill(kdhit->getY());
Expand Down Expand Up @@ -3048,10 +3119,15 @@ void ConformalTracking::runStep(SharedKDClusters& kdClusters, UKDTree& nearestNe
if (parameters._build) {
bool caughtException = false;
Parameters thisParameters(parameters);
// Creating a subset collection with clusters that should be used as first seed hits (improves seeding performance)
SharedKDClusters kdSeedClusters;
for (auto& colId : parameters._seedCollections) {
kdSeedClusters.insert(kdSeedClusters.end(), collectionClusters.at(colId).begin(), collectionClusters.at(colId).end());
}
do {
caughtException = false;
try {
buildNewTracks(conformalTracks, kdClusters, nearestNeighbours, thisParameters, parameters._radialSearch,
buildNewTracks(conformalTracks, kdClusters, kdSeedClusters, nearestNeighbours, thisParameters, parameters._radialSearch,
parameters._vertexToTracker);
} catch (TooManyTracksException& e) {
streamlog_out(MESSAGE) << "caught too many tracks, tightening parameters" << std::endl;
Expand Down
11 changes: 10 additions & 1 deletion src/Parameters.cc
Expand Up @@ -9,6 +9,7 @@ bool findEntry(std::vector<std::string> const& functions, std::string const& ent

Parameters::Parameters(ParameterParser::ParsedParameters const& ps, std::vector<std::string> const& allCollections, int step)
: _collections({}),
_seedCollections({}),
_maxCellAngle(ps._parameters.at("MaxCellAngle")),
_maxCellAngleRZ(ps._parameters.at("MaxCellAngleRZ")),
_chi2cut(ps._parameters.at("Chi2Cut")),
Expand All @@ -26,14 +27,22 @@ Parameters::Parameters(ParameterParser::ParsedParameters const& ps, std::vector<
_build(findEntry(ps._functions, "BuildNewTracks")),
_extend(findEntry(ps._functions, "ExtendTracks")),
_sortTracks(findEntry(ps._functions, "SortTracks")) {
for (auto const& colName : ps._collections) {
for (auto const& fullColName : ps._collections) {
std::string colName(fullColName);
bool skipFromSeed(false);
// Stripping potential "-" from the beginning
if (colName.at(0) == '-') {
colName = colName.substr(1);
skipFromSeed = true;
}
auto it = std::find(allCollections.begin(), allCollections.end(), colName);
if (it == allCollections.end()) {
std::stringstream error;
error << ": Collection name \"" << colName << "\" not found in Collection parameter! Check your config";
throw marlin::ParseException(error.str());
}
_collections.push_back(it - allCollections.begin());
if (!skipFromSeed) _seedCollections.push_back(it - allCollections.begin());

check(ps._parameters, _existingParameters, "Parameter");
check(ps._functions, _existingFunctions, "Function");
Expand Down

0 comments on commit 1cd68dc

Please sign in to comment.