Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticlv4 graph #13

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions DataFormats/HGCalReco/interface/TICLGraph.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef DataFormats_HGCalReco_TICLGraph_h
#define DataFormats_HGCalReco_TICLGraph_h

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

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

void addInner(unsigned int trackster_id) { innerNodes_.push_back(trackster_id); }
void addOuter(unsigned int trackster_id) { outerNodes_.push_back(trackster_id); }

const unsigned int getId() const { return index_; }
std::vector<unsigned int> getInner() const { return innerNodes_; }
std::vector<unsigned int> getOuter() const { return outerNodes_; }

~Node() = default;

private:
unsigned index_;
bool isTrackster_;
std::vector<unsigned int> innerNodes_;
std::vector<unsigned int> outerNodes_;
};

class TICLGraph {
public:
TICLGraph() = default;
TICLGraph(std::vector<Node> &n) { nodes_ = n; };
const std::vector<Node> &getNodes() const { return nodes_; }
const Node &getNode(int i) const { return nodes_[i]; }
~TICLGraph() = default;

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

#endif
1 change: 1 addition & 0 deletions DataFormats/HGCalReco/src/classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
#include "DataFormats/HGCalReco/interface/TICLSeedingRegion.h"
#include "DataFormats/HGCalReco/interface/TICLCandidate.h"
#include "DataFormats/Common/interface/Wrapper.h"
#include "DataFormats/HGCalReco/interface/TICLGraph.h"
12 changes: 12 additions & 0 deletions DataFormats/HGCalReco/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,16 @@
<class name="std::vector<TICLCandidate>" />
<class name="edm::Wrapper<TICLCandidate>" />
<class name="edm::Wrapper<std::vector<TICLCandidate> >" />

<class name="Node">
</class>
<class name="std::vector<Node>" />
<class name="edm::Wrapper<Node>" />
<class name="edm::Wrapper<std::vector<Node> >" />

<class name="TICLGraph">
</class>
<class name="std::vector<TICLGraph>" />
<class name="edm::Wrapper<TICLGraph>" />
<class name="edm::Wrapper<std::vector<TICLGraph> >" />
</lcgdict>
3 changes: 2 additions & 1 deletion RecoHGCal/Configuration/python/RecoHGCal_EventContent_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
'keep *_ticlTrackstersHFNoseMIP_*_*',
'keep *_ticlTrackstersHFNoseHAD_*_*',
'keep *_ticlTrackstersHFNoseMerge_*_*',] +
['keep *_pfTICL_*_*']
['keep *_pfTICL_*_*'] +
['keep *_ticlGraph_*_*']
)
)
TICL_RECO.outputCommands.extend(TICL_AOD.outputCommands)
Expand Down
8 changes: 4 additions & 4 deletions RecoHGCal/TICL/plugins/LinkingAlgoByPCAGeometric.cc
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ void LinkingAlgoByPCAGeometric::linkTracksters(const edm::Handle<std::vector<rec
// compatible if accumulated energy does not
// exceed track momentum by more than threshold
double threshold = std::min(0.2*ts.raw_energy(), 10.0);
if (!(total_raw_energy + ts.raw_energy() < tk.p() + threshold))
std::cout << "track p : " << tk.p() << " trackster energy : " << ts.raw_energy() << std::endl;
/*if (!(total_raw_energy + ts.raw_energy() < tk.p() + threshold))
std::cout << "track p : " << tk.p() << " trackster energy : " << ts.raw_energy() << std::endl;*/
return (total_raw_energy + ts.raw_energy() < tk.p() + threshold);
};
auto timeCompatible = [&](const Trackster & ts, const reco::TrackRef tk) -> bool {
Expand All @@ -450,8 +450,8 @@ void LinkingAlgoByPCAGeometric::linkTracksters(const edm::Handle<std::vector<rec
double tkTErr = tkTimeErr[tk];

if (tsT == -99. or tkTimeQual[tk] < tkTimeQualThreshold) return true;
if (!(std::abs(tsT - tkT) < maxDeltaT * sqrt(tsTErr * tsTErr + tkTErr * tkTErr)))
std::cout << "track time : " << tkT << " trackster time : " << tsT << std::endl;
/*if (!(std::abs(tsT - tkT) < maxDeltaT * sqrt(tsTErr * tsTErr + tkTErr * tkTErr)))
std::cout << "track time : " << tkT << " trackster time : " << tsT << std::endl;*/
return (std::abs(tsT - tkT) < maxDeltaT * sqrt(tsTErr * tsTErr + tkTErr * tkTErr));
};
auto tkRef = reco::TrackRef(tkH, i);
Expand Down
189 changes: 189 additions & 0 deletions RecoHGCal/TICL/plugins/TICLGraphProducer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
#include <memory>

#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/ESGetToken.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

#include "DataFormats/HGCalReco/interface/TICLGraph.h"
#include "DataFormats/HGCalReco/interface/Trackster.h"
#include "DataFormats/HGCalReco/interface/TICLLayerTile.h"

#include "DataFormats/TrackReco/interface/Track.h"

#include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
#include "TrackingTools/GeomPropagators/interface/Propagator.h"
#include "TrackingTools/Records/interface/TrackingComponentsRecord.h"

#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"
#include "CommonTools/Utils/interface/StringCutObjectSelector.h"

#include "MagneticField/Engine/interface/MagneticField.h"
#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"

#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"
#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "Geometry/CommonDetUnit/interface/GeomDet.h"

using namespace ticl;

class TICLGraphProducer : public edm::stream::EDProducer<> {
public:
explicit TICLGraphProducer(const edm::ParameterSet &ps);
~TICLGraphProducer() override{};
void produce(edm::Event &, const edm::EventSetup &) override;
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);

void beginJob();
void endJob();

void beginRun(edm::Run const &iEvent, edm::EventSetup const &es) override;

private:
typedef math::XYZVector Vector;
const edm::EDGetTokenT<std::vector<Trackster>> tracksters_clue3d_token_;
const edm::EDGetTokenT<std::vector<reco::Track>> tracks_token_;
const StringCutObjectSelector<reco::Track> cutTk_;
const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometry_token_;
const std::string detector_;
const std::string propName_;
const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> bfield_token_;
const edm::ESGetToken<Propagator, TrackingComponentsRecord> propagator_token_;

const HGCalDDDConstants *hgcons_;
hgcal::RecHitTools rhtools_;
edm::ESGetToken<HGCalDDDConstants, IdealGeometryRecord> hdc_token_;
};

TICLGraphProducer::TICLGraphProducer(const edm::ParameterSet &ps)
: tracksters_clue3d_token_(consumes<std::vector<Trackster>>(ps.getParameter<edm::InputTag>("trackstersclue3d"))),
tracks_token_(consumes<std::vector<reco::Track>>(ps.getParameter<edm::InputTag>("tracks"))),
cutTk_(ps.getParameter<std::string>("cutTk")),
geometry_token_(esConsumes<CaloGeometry, CaloGeometryRecord, edm::Transition::BeginRun>()),
detector_(ps.getParameter<std::string>("detector")),
propName_(ps.getParameter<std::string>("propagator")),
bfield_token_(esConsumes<MagneticField, IdealMagneticFieldRecord, edm::Transition::BeginRun>()),
propagator_token_(
esConsumes<Propagator, TrackingComponentsRecord, edm::Transition::BeginRun>(edm::ESInputTag("", propName_))) {
produces<TICLGraph>();
std::string detectorName_ = (detector_ == "HFNose") ? "HGCalHFNoseSensitive" : "HGCalEESensitive";
hdc_token_ =
esConsumes<HGCalDDDConstants, IdealGeometryRecord, edm::Transition::BeginRun>(edm::ESInputTag("", detectorName_));
}

void TICLGraphProducer::beginJob() {}

void TICLGraphProducer::endJob(){};

void TICLGraphProducer::beginRun(edm::Run const &iEvent, edm::EventSetup const &es) {
edm::ESHandle<HGCalDDDConstants> hdc = es.getHandle(hdc_token_);
hgcons_ = hdc.product();

edm::ESHandle<CaloGeometry> geom = es.getHandle(geometry_token_);
rhtools_.setGeometry(*geom);

edm::ESHandle<MagneticField> bfield = es.getHandle(bfield_token_);
edm::ESHandle<Propagator> propagator = es.getHandle(propagator_token_);
};

void TICLGraphProducer::produce(edm::Event &evt, const edm::EventSetup &es) {
edm::Handle<std::vector<Trackster>> trackstersclue3d_h;
evt.getByToken(tracksters_clue3d_token_, trackstersclue3d_h);
auto trackstersclue3d = *trackstersclue3d_h;

//std::vector<Trackster> trackstersclue3d_sorted(trackstersclue3d);
//std::sort(trackstersclue3d_sorted.begin(), trackstersclue3d_sorted.end(), [](Trackster& t1, Trackster& t2){return t1.barycenter().z() < t2.barycenter().z();});

TICLLayerTile tracksterTilePos;
TICLLayerTile tracksterTileNeg;

for (size_t id_t = 0; id_t < trackstersclue3d.size(); ++id_t) {
auto t = trackstersclue3d[id_t];
if (t.barycenter().eta() > 0.) {
tracksterTilePos.fill(t.barycenter().eta(), t.barycenter().phi(), id_t);
} else if (t.barycenter().eta() < 0.) {
tracksterTileNeg.fill(t.barycenter().eta(), t.barycenter().phi(), id_t);
}
}

std::vector<Node> allNodes;

for (size_t id_t = 0; id_t < trackstersclue3d.size(); ++id_t) {
auto t = trackstersclue3d[id_t];

Node tNode(id_t);

auto bary = t.barycenter();
double del = 0.1;

double eta_min = std::max(abs(bary.eta()) - del, (double)TileConstants::minEta);
double eta_max = std::min(abs(bary.eta()) + del, (double)TileConstants::maxEta);

if (bary.eta() > 0.) {
std::array<int, 4> search_box =
tracksterTilePos.searchBoxEtaPhi(eta_min, eta_max, bary.phi() - del, bary.phi() + del);
if (search_box[2] > search_box[3]) {
search_box[3] += TileConstants::nPhiBins;
}

for (int eta_i = search_box[0]; eta_i <= search_box[1]; ++eta_i) {
for (int phi_i = search_box[2]; phi_i <= search_box[3]; ++phi_i) {
auto &neighbours = tracksterTilePos[tracksterTilePos.globalBin(eta_i, (phi_i % TileConstants::nPhiBins))];
for (auto n : neighbours) {
if (trackstersclue3d[n].barycenter().z() < bary.z()) {
tNode.addInner(n);
} else if (trackstersclue3d[n].barycenter().z() > bary.z()) {
tNode.addOuter(n);
}
}
}
}
}

else if (bary.eta() < 0.) {
std::array<int, 4> search_box =
tracksterTileNeg.searchBoxEtaPhi(eta_min, eta_max, bary.phi() - del, bary.phi() + del);
if (search_box[2] > search_box[3]) {
search_box[3] += TileConstants::nPhiBins;
}

for (int eta_i = search_box[0]; eta_i <= search_box[1]; ++eta_i) {
for (int phi_i = search_box[2]; phi_i <= search_box[3]; ++phi_i) {
auto &neighbours = tracksterTileNeg[tracksterTileNeg.globalBin(eta_i, (phi_i % TileConstants::nPhiBins))];
for (auto n : neighbours) {
if (abs(trackstersclue3d[n].barycenter().z()) < abs(bary.z())) {
tNode.addInner(n);
} else if (abs(trackstersclue3d[n].barycenter().z()) > abs(bary.z())) {
tNode.addOuter(n);
}
}
}
}
}
allNodes.push_back(tNode);
}
auto resultGraph = std::make_unique<TICLGraph>(allNodes);

evt.put(std::move(resultGraph));
}

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

desc.add<edm::InputTag>("trackstersclue3d", edm::InputTag("ticlTrackstersCLUE3DHigh"));
desc.add<edm::InputTag>("tracks", edm::InputTag("generalTracks"));
desc.add<edm::InputTag>("muons", edm::InputTag("muons1stStep"));
desc.add<std::string>("detector", "HGCAL");
desc.add<std::string>("propagator", "PropagatorWithMaterial");
desc.add<std::string>("cutTk",
"1.48 < abs(eta) < 3.0 && pt > 1. && quality(\"highPurity\") && "
"hitPattern().numberOfLostHits(\"MISSING_OUTER_HITS\") < 5");
descriptions.add("ticlGraphProducer", desc);
}

DEFINE_FWK_MODULE(TICLGraphProducer);
31 changes: 29 additions & 2 deletions RecoHGCal/TICL/plugins/TrackstersMergeProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "DataFormats/HGCalReco/interface/TICLLayerTile.h"
#include "DataFormats/HGCalReco/interface/Trackster.h"
#include "DataFormats/HGCalReco/interface/TICLSeedingRegion.h"
#include "DataFormats/HGCalReco/interface/TICLGraph.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/MuonReco/interface/Muon.h"
#include "DataFormats/GeometrySurface/interface/BoundDisk.h"
Expand Down Expand Up @@ -97,6 +98,7 @@ class TrackstersMergeProducer : public edm::stream::EDProducer<> {
const edm::EDGetTokenT<std::vector<Trackster>> tracksterstrk_token_;
const edm::EDGetTokenT<std::vector<Trackster>> trackstershad_token_;
const edm::EDGetTokenT<std::vector<Trackster>> tracksters_clue3d_token_;
const edm::EDGetTokenT<TICLGraph> ticlGraph_token_;
const edm::EDGetTokenT<std::vector<TICLSeedingRegion>> seedingTrk_token_;
const edm::EDGetTokenT<std::vector<reco::CaloCluster>> clusters_token_;
const edm::EDGetTokenT<edm::ValueMap<std::pair<float, float>>> clustersTime_token_;
Expand Down Expand Up @@ -165,6 +167,7 @@ TrackstersMergeProducer::TrackstersMergeProducer(const edm::ParameterSet &ps)
tracksterstrk_token_(consumes<std::vector<Trackster>>(ps.getParameter<edm::InputTag>("tracksterstrk"))),
trackstershad_token_(consumes<std::vector<Trackster>>(ps.getParameter<edm::InputTag>("trackstershad"))),
tracksters_clue3d_token_(consumes<std::vector<Trackster>>(ps.getParameter<edm::InputTag>("trackstersclue3d"))),
ticlGraph_token_(consumes<TICLGraph>(ps.getParameter<edm::InputTag>("ticlgraph"))),
seedingTrk_token_(consumes<std::vector<TICLSeedingRegion>>(ps.getParameter<edm::InputTag>("seedingTrk"))),
clusters_token_(consumes<std::vector<reco::CaloCluster>>(ps.getParameter<edm::InputTag>("layer_clusters"))),
clustersTime_token_(
Expand Down Expand Up @@ -339,6 +342,10 @@ void TrackstersMergeProducer::produce(edm::Event &evt, const edm::EventSetup &es
edm::Handle<std::vector<Trackster>> trackstersclue3d_h;
evt.getByToken(tracksters_clue3d_token_, trackstersclue3d_h);

edm::Handle<TICLGraph> ticlGraph_h;
evt.getByToken(ticlGraph_token_, ticlGraph_h);
const auto &ticlGraph = *ticlGraph_h;

edm::Handle<std::vector<reco::Muon>> muons_h;
evt.getByToken(muons_token_, muons_h);
const auto &muons = *muons_h;
Expand All @@ -361,7 +368,12 @@ void TrackstersMergeProducer::produce(edm::Event &evt, const edm::EventSetup &es
// Print debug info
if (debug_) {
std::cout << "No. of Tracks : " << tracks.size() << std::endl;
std::cout << "No. of Tracksters : " << (*trackstersclue3d_h).size() << std::endl;
const auto &tss = *trackstersclue3d_h;
std::cout << "No. of Tracksters : " << tss.size() << std::endl;
std::cout << "Trackster id | x | y | z | eta | phi | E " << std::endl;
for (unsigned i = 0; i < tss.size(); ++i)
std::cout << " " << i << " " << tss[i].barycenter().x() << " " << tss[i].barycenter().y() << " " << tss[i].barycenter().z() << " " <<
tss[i].barycenter().eta() << " " << tss[i].barycenter().phi() << " " << tss[i].raw_energy() << std::endl;
}
std::vector<TICLCandidate> &tracksterLinkingDebug = *resultTrackstersLinked;
for (auto cand : tracksterLinkingDebug) {
Expand All @@ -379,7 +391,7 @@ void TrackstersMergeProducer::produce(edm::Event &evt, const edm::EventSetup &es
for (auto ts_ptr : trackster_ptrs) {
if (debug_) {
auto ts_idx = ts_ptr.get() - (edm::Ptr<ticl::Trackster>(trackstersclue3d_h, 0)).get();
std::cout << ts_idx << " (" << ts_ptr->raw_energy() << ")";
std::cout << ts_idx << " ";
}
auto &thisTrackster = *ts_ptr;
updated_size += thisTrackster.vertices().size();
Expand Down Expand Up @@ -439,6 +451,20 @@ void TrackstersMergeProducer::produce(edm::Event &evt, const edm::EventSetup &es
// Compute timing
assignTimeToCandidates(*resultCandidates);

if (debug_) {
// print info from graph
std::cout << "From graph:" << std::endl;
const auto nodes = ticlGraph.getNodes();
for (const auto &n : nodes) {
std::cout << "Trackster : " << n.getId() << std::endl;
std::cout << "inners : ";
for (auto &inner : n.getInner()) std::cout << (int)inner << " ";
std::cout << std::endl << "outers : ";
for (auto &outer : n.getOuter()) std::cout << (int)outer << " ";
std::cout << std::endl;
}
}

evt.put(std::move(resultTrackstersMerged));
evt.put(std::move(resultTrackstersLinked));
}
Expand Down Expand Up @@ -971,6 +997,7 @@ void TrackstersMergeProducer::fillDescriptions(edm::ConfigurationDescriptions &d
desc.add<edm::InputTag>("tracksterstrk", edm::InputTag("ticlTrackstersTrk"));
desc.add<edm::InputTag>("trackstershad", edm::InputTag("ticlTrackstersHAD"));
desc.add<edm::InputTag>("trackstersclue3d", edm::InputTag("ticlTrackstersCLUE3DHigh"));
desc.add<edm::InputTag>("ticlgraph", edm::InputTag("ticlGraph"));
desc.add<edm::InputTag>("seedingTrk", edm::InputTag("ticlSeedingTrk"));
desc.add<edm::InputTag>("layer_clusters", edm::InputTag("hgcalLayerClusters"));
desc.add<edm::InputTag>("layer_clustersTime", edm::InputTag("hgcalLayerClusters", "timeLayerCluster"));
Expand Down
Loading