Skip to content

Commit

Permalink
TICLv5 configuration and Skeletons linking (cms-sw#22)
Browse files Browse the repository at this point in the history
* ticlv5: configure ticlv5 for validation

* ticlv5: first skeletons implementation for trackster linking

* replace cout with LogDebug in TICLGraph

* make parameters configurable in Linking with skeletons

* code-format

* ticlv5: fixing hgcalvalidation in ticlv5 modifier

---------

Co-authored-by: Wahid Redjeb <wredjeb@olivb-27.cern.ch>
  • Loading branch information
waredjeb and Wahid Redjeb committed Jan 9, 2024
1 parent 43c83c9 commit 060beca
Show file tree
Hide file tree
Showing 11 changed files with 773 additions and 6 deletions.
9 changes: 9 additions & 0 deletions RecoHGCal/TICL/interface/TracksterLinkingAlgoBase.h
Expand Up @@ -20,6 +20,10 @@
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "PhysicsTools/TensorFlow/interface/TensorFlow.h"
#include "CommonTools/RecoAlgos/interface/MultiVectorManager.h"
#include "MagneticField/Engine/interface/MagneticField.h"
#include "TrackingTools/GeomPropagators/interface/Propagator.h"
#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"
#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"

namespace edm {
class Event;
Expand Down Expand Up @@ -53,6 +57,11 @@ namespace ticl {
std::vector<std::vector<unsigned int>>& linkedResultTracksters,
std::vector<std::vector<unsigned int>>& linkedTracksterIdToInputTracksterId) = 0;

virtual void initialize(const HGCalDDDConstants* hgcons,
const hgcal::RecHitTools rhtools,
const edm::ESHandle<MagneticField> bfieldH,
const edm::ESHandle<Propagator> propH) = 0;

static void fillPSetDescription(edm::ParameterSetDescription& desc) { desc.add<int>("algo_verbosity", 0); };

protected:
Expand Down
57 changes: 57 additions & 0 deletions RecoHGCal/TICL/plugins/TICLGraph.cc
@@ -0,0 +1,57 @@
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "TICLGraph.h"

void Node::findSubComponents(std::vector<Node>& graph, std::vector<unsigned int>& subComponent, std::string tabs) {
tabs += "\t";
if (!alreadyVisited_) {
LogDebug("TICLGraph") << tabs << " Visiting node " << index_ << std::endl;
alreadyVisited_ = true;
subComponent.push_back(index_);
for (auto const& neighbour : neighboursId_) {
LogDebug("TICLGraph") << tabs << " Trying to visit " << neighbour << std::endl;
graph[neighbour].findSubComponents(graph, subComponent, tabs);
}
}
}

std::vector<std::vector<unsigned int>> TICLGraph::findSubComponents() {
std::vector<std::vector<unsigned int>> components;
for (auto const& node : nodes_) {
auto const id = node.getId();
if (isRootNode_[id]) {
//LogDebug("TICLGraph") << "DFS Starting From " << id << std::endl;
std::string tabs = "\t";
std::vector<unsigned int> tmpSubComponents;
nodes_[id].findSubComponents(nodes_, tmpSubComponents, tabs);
components.push_back(tmpSubComponents);
}
}
return components;
}

void TICLGraph::dfsForCC(unsigned int nodeIndex,
std::unordered_set<unsigned int>& visited,
std::vector<unsigned int>& component) const {
visited.insert(nodeIndex);
component.push_back(nodeIndex);

for (auto const& neighbourIndex : nodes_[nodeIndex].getNeighbours()) {
if (visited.find(neighbourIndex) == visited.end()) {
dfsForCC(neighbourIndex, visited, component);
}
}
}

std::vector<std::vector<unsigned int>> TICLGraph::getConnectedComponents() const {
std::unordered_set<unsigned int> visited;
std::vector<std::vector<unsigned int>> components;

for (unsigned int i = 0; i < nodes_.size(); ++i) {
if (visited.find(i) == visited.end()) {
std::vector<unsigned int> component;
dfsForCC(i, visited, component);
components.push_back(component);
}
}
return components;
}
58 changes: 58 additions & 0 deletions RecoHGCal/TICL/plugins/TICLGraph.h
@@ -0,0 +1,58 @@
#ifndef DataFormats_HGCalReco_TICLGraph_h
#define DataFormats_HGCalReco_TICLGraph_h

#include "DataFormats/HGCalReco/interface/Trackster.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include <unordered_set>

class Node {
public:
Node() = default;
Node(unsigned index, bool isTrackster = true) : index_(index), isTrackster_(isTrackster), alreadyVisited_{false} {};

inline void addNeighbour(unsigned int trackster_id) { neighboursId_.push_back(trackster_id); }

inline const unsigned int getId() const { return index_; }
std::vector<unsigned int> getNeighbours() const { return neighboursId_; }
void findSubComponents(std::vector<Node>& graph, std::vector<unsigned int>& subComponent, std::string tabs);

~Node() = default;

private:
unsigned index_;
bool isTrackster_;

std::vector<unsigned int> neighboursId_;
bool alreadyVisited_;

//bool areCompatible(const std::vector<Node>& graph, const unsigned int& outerNode) { return true; };
};

class TICLGraph {
public:
// can i remove default constructor ?? edm::Wrapper problem
// without default constructor i could initialize connectedComponents when building the Graph
TICLGraph() = default;
TICLGraph(std::vector<Node>& n, std::vector<int> isRootNode) {
nodes_ = n;
isRootNode_ = isRootNode;
};
inline const std::vector<Node>& getNodes() const { return nodes_; }
inline const Node& getNode(int i) const { return nodes_[i]; }

std::vector<std::vector<unsigned int>> findSubComponents();

~TICLGraph() = default;

void dfsForCC(unsigned int nodeIndex,
std::unordered_set<unsigned int>& visited,
std::vector<unsigned int>& component) const;

std::vector<std::vector<unsigned int>> getConnectedComponents() const;

private:
std::vector<Node> nodes_;
std::vector<int> isRootNode_;
};

#endif
4 changes: 2 additions & 2 deletions RecoHGCal/TICL/plugins/TracksterLinkingPluginFactory.cc
@@ -1,11 +1,11 @@
// #include "TracksterLinkingbySkeletons.h"
// #include "TracksterLinkingbySuperClustering.h"
#include "FWCore/ParameterSet/interface/ValidatedPluginFactoryMacros.h"
#include "FWCore/ParameterSet/interface/ValidatedPluginMacros.h"
#include "TracksterLinkingbyFastJet.h"
#include "TracksterLinkingbySkeletons.h"
#include "RecoHGCal/TICL/plugins/TracksterLinkingPluginFactory.h"

EDM_REGISTER_VALIDATED_PLUGINFACTORY(TracksterLinkingPluginFactory, "TracksterLinkingPluginFactory");
// DEFINE_EDM_VALIDATED_PLUGIN(TracksterLinkingPluginFactory, ticl::TracksterLinkingbySkeletons, "Skeletons");
DEFINE_EDM_VALIDATED_PLUGIN(TracksterLinkingPluginFactory, ticl::TracksterLinkingbySkeletons, "Skeletons");
// DEFINE_EDM_VALIDATED_PLUGIN(TracksterLinkingPluginFactory, ticl::TracksterLinkingbySuperClustering, "SuperClustering");
DEFINE_EDM_VALIDATED_PLUGIN(TracksterLinkingPluginFactory, ticl::TracksterLinkingbyFastJet, "FastJet");
2 changes: 1 addition & 1 deletion RecoHGCal/TICL/plugins/TracksterLinkingbyFastJet.cc
Expand Up @@ -45,4 +45,4 @@ void TracksterLinkingbyFastJet::linkTracksters(
linkedResultTracksters.push_back(linkedTracksters);
}
}
}
}
6 changes: 6 additions & 0 deletions RecoHGCal/TICL/plugins/TracksterLinkingbyFastJet.h
Expand Up @@ -37,6 +37,12 @@ namespace ticl {
std::vector<Trackster>& resultTracksters,
std::vector<std::vector<unsigned int>>& linkedResultTracksters,
std::vector<std::vector<unsigned int>>& linkedTracksterIdToInputTracksterId) override;

void initialize(const HGCalDDDConstants* hgcons,
const hgcal::RecHitTools rhtools,
const edm::ESHandle<MagneticField> bfieldH,
const edm::ESHandle<Propagator> propH) override{};

static void fillPSetDescription(edm::ParameterSetDescription& iDesc) {
iDesc.add<int>("algo_verbosity", 0);
iDesc.add<int>("jet_algorithm", 2)
Expand Down

0 comments on commit 060beca

Please sign in to comment.