From c1769365354fb76f50373d4b1fe8328a48c847aa Mon Sep 17 00:00:00 2001 From: Abhirikshma Date: Wed, 11 May 2022 17:57:05 +0200 Subject: [PATCH] Preliminary TICLGraph --- DataFormats/HGCalReco/interface/TICLGraph.h | 40 ++++ DataFormats/HGCalReco/src/classes.h | 1 + DataFormats/HGCalReco/src/classes_def.xml | 12 ++ .../python/RecoHGCal_EventContent_cff.py | 3 +- .../TICL/plugins/LinkingAlgoByPCAGeometric.cc | 8 +- RecoHGCal/TICL/plugins/TICLGraphProducer.cc | 189 ++++++++++++++++++ .../TICL/plugins/TrackstersMergeProducer.cc | 31 ++- RecoHGCal/TICL/python/iterativeTICL_cff.py | 5 +- 8 files changed, 281 insertions(+), 8 deletions(-) create mode 100644 DataFormats/HGCalReco/interface/TICLGraph.h create mode 100644 RecoHGCal/TICL/plugins/TICLGraphProducer.cc diff --git a/DataFormats/HGCalReco/interface/TICLGraph.h b/DataFormats/HGCalReco/interface/TICLGraph.h new file mode 100644 index 0000000000000..6150199bf1339 --- /dev/null +++ b/DataFormats/HGCalReco/interface/TICLGraph.h @@ -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 getInner() const { return innerNodes_; } + std::vector getOuter() const { return outerNodes_; } + + ~Node() = default; + +private: + unsigned index_; + bool isTrackster_; + std::vector innerNodes_; + std::vector outerNodes_; +}; + +class TICLGraph { +public: + TICLGraph() = default; + TICLGraph(std::vector &n) { nodes_ = n; }; + const std::vector &getNodes() const { return nodes_; } + const Node &getNode(int i) const { return nodes_[i]; } + ~TICLGraph() = default; + +private: + std::vector nodes_; +}; + +#endif \ No newline at end of file diff --git a/DataFormats/HGCalReco/src/classes.h b/DataFormats/HGCalReco/src/classes.h index d871bfb485a71..87f8c7bb7c8b0 100644 --- a/DataFormats/HGCalReco/src/classes.h +++ b/DataFormats/HGCalReco/src/classes.h @@ -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" diff --git a/DataFormats/HGCalReco/src/classes_def.xml b/DataFormats/HGCalReco/src/classes_def.xml index 9ac5b29b4f2e2..e8eacdafcc557 100644 --- a/DataFormats/HGCalReco/src/classes_def.xml +++ b/DataFormats/HGCalReco/src/classes_def.xml @@ -54,4 +54,16 @@ + + + + + + + + + + + + diff --git a/RecoHGCal/Configuration/python/RecoHGCal_EventContent_cff.py b/RecoHGCal/Configuration/python/RecoHGCal_EventContent_cff.py index e09337210efe2..3f65923eec478 100644 --- a/RecoHGCal/Configuration/python/RecoHGCal_EventContent_cff.py +++ b/RecoHGCal/Configuration/python/RecoHGCal_EventContent_cff.py @@ -19,7 +19,8 @@ 'keep *_ticlTrackstersHFNoseMIP_*_*', 'keep *_ticlTrackstersHFNoseHAD_*_*', 'keep *_ticlTrackstersHFNoseMerge_*_*',] + - ['keep *_pfTICL_*_*'] + ['keep *_pfTICL_*_*'] + + ['keep *_ticlGraph_*_*'] ) ) TICL_RECO.outputCommands.extend(TICL_AOD.outputCommands) diff --git a/RecoHGCal/TICL/plugins/LinkingAlgoByPCAGeometric.cc b/RecoHGCal/TICL/plugins/LinkingAlgoByPCAGeometric.cc index 3be353d6bea0c..834802789992b 100644 --- a/RecoHGCal/TICL/plugins/LinkingAlgoByPCAGeometric.cc +++ b/RecoHGCal/TICL/plugins/LinkingAlgoByPCAGeometric.cc @@ -435,8 +435,8 @@ void LinkingAlgoByPCAGeometric::linkTracksters(const edm::Handle bool { @@ -450,8 +450,8 @@ void LinkingAlgoByPCAGeometric::linkTracksters(const edm::Handle + +#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> tracksters_clue3d_token_; + const edm::EDGetTokenT> tracks_token_; + const StringCutObjectSelector cutTk_; + const edm::ESGetToken geometry_token_; + const std::string detector_; + const std::string propName_; + const edm::ESGetToken bfield_token_; + const edm::ESGetToken propagator_token_; + + const HGCalDDDConstants *hgcons_; + hgcal::RecHitTools rhtools_; + edm::ESGetToken hdc_token_; +}; + +TICLGraphProducer::TICLGraphProducer(const edm::ParameterSet &ps) + : tracksters_clue3d_token_(consumes>(ps.getParameter("trackstersclue3d"))), + tracks_token_(consumes>(ps.getParameter("tracks"))), + cutTk_(ps.getParameter("cutTk")), + geometry_token_(esConsumes()), + detector_(ps.getParameter("detector")), + propName_(ps.getParameter("propagator")), + bfield_token_(esConsumes()), + propagator_token_( + esConsumes(edm::ESInputTag("", propName_))) { + produces(); + std::string detectorName_ = (detector_ == "HFNose") ? "HGCalHFNoseSensitive" : "HGCalEESensitive"; + hdc_token_ = + esConsumes(edm::ESInputTag("", detectorName_)); +} + +void TICLGraphProducer::beginJob() {} + +void TICLGraphProducer::endJob(){}; + +void TICLGraphProducer::beginRun(edm::Run const &iEvent, edm::EventSetup const &es) { + edm::ESHandle hdc = es.getHandle(hdc_token_); + hgcons_ = hdc.product(); + + edm::ESHandle geom = es.getHandle(geometry_token_); + rhtools_.setGeometry(*geom); + + edm::ESHandle bfield = es.getHandle(bfield_token_); + edm::ESHandle propagator = es.getHandle(propagator_token_); +}; + +void TICLGraphProducer::produce(edm::Event &evt, const edm::EventSetup &es) { + edm::Handle> trackstersclue3d_h; + evt.getByToken(tracksters_clue3d_token_, trackstersclue3d_h); + auto trackstersclue3d = *trackstersclue3d_h; + + //std::vector 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 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 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 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(allNodes); + + evt.put(std::move(resultGraph)); +} + +void TICLGraphProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { + edm::ParameterSetDescription desc; + + desc.add("trackstersclue3d", edm::InputTag("ticlTrackstersCLUE3DHigh")); + desc.add("tracks", edm::InputTag("generalTracks")); + desc.add("muons", edm::InputTag("muons1stStep")); + desc.add("detector", "HGCAL"); + desc.add("propagator", "PropagatorWithMaterial"); + desc.add("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); \ No newline at end of file diff --git a/RecoHGCal/TICL/plugins/TrackstersMergeProducer.cc b/RecoHGCal/TICL/plugins/TrackstersMergeProducer.cc index 92d786c2993af..b2486f8c80e17 100644 --- a/RecoHGCal/TICL/plugins/TrackstersMergeProducer.cc +++ b/RecoHGCal/TICL/plugins/TrackstersMergeProducer.cc @@ -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" @@ -97,6 +98,7 @@ class TrackstersMergeProducer : public edm::stream::EDProducer<> { const edm::EDGetTokenT> tracksterstrk_token_; const edm::EDGetTokenT> trackstershad_token_; const edm::EDGetTokenT> tracksters_clue3d_token_; + const edm::EDGetTokenT ticlGraph_token_; const edm::EDGetTokenT> seedingTrk_token_; const edm::EDGetTokenT> clusters_token_; const edm::EDGetTokenT>> clustersTime_token_; @@ -165,6 +167,7 @@ TrackstersMergeProducer::TrackstersMergeProducer(const edm::ParameterSet &ps) tracksterstrk_token_(consumes>(ps.getParameter("tracksterstrk"))), trackstershad_token_(consumes>(ps.getParameter("trackstershad"))), tracksters_clue3d_token_(consumes>(ps.getParameter("trackstersclue3d"))), + ticlGraph_token_(consumes(ps.getParameter("ticlgraph"))), seedingTrk_token_(consumes>(ps.getParameter("seedingTrk"))), clusters_token_(consumes>(ps.getParameter("layer_clusters"))), clustersTime_token_( @@ -339,6 +342,10 @@ void TrackstersMergeProducer::produce(edm::Event &evt, const edm::EventSetup &es edm::Handle> trackstersclue3d_h; evt.getByToken(tracksters_clue3d_token_, trackstersclue3d_h); + edm::Handle ticlGraph_h; + evt.getByToken(ticlGraph_token_, ticlGraph_h); + const auto &ticlGraph = *ticlGraph_h; + edm::Handle> muons_h; evt.getByToken(muons_token_, muons_h); const auto &muons = *muons_h; @@ -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 &tracksterLinkingDebug = *resultTrackstersLinked; for (auto cand : tracksterLinkingDebug) { @@ -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(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(); @@ -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)); } @@ -971,6 +997,7 @@ void TrackstersMergeProducer::fillDescriptions(edm::ConfigurationDescriptions &d desc.add("tracksterstrk", edm::InputTag("ticlTrackstersTrk")); desc.add("trackstershad", edm::InputTag("ticlTrackstersHAD")); desc.add("trackstersclue3d", edm::InputTag("ticlTrackstersCLUE3DHigh")); + desc.add("ticlgraph", edm::InputTag("ticlGraph")); desc.add("seedingTrk", edm::InputTag("ticlSeedingTrk")); desc.add("layer_clusters", edm::InputTag("hgcalLayerClusters")); desc.add("layer_clustersTime", edm::InputTag("hgcalLayerClusters", "timeLayerCluster")); diff --git a/RecoHGCal/TICL/python/iterativeTICL_cff.py b/RecoHGCal/TICL/python/iterativeTICL_cff.py index d5d63b29e9139..a1e65412fc654 100644 --- a/RecoHGCal/TICL/python/iterativeTICL_cff.py +++ b/RecoHGCal/TICL/python/iterativeTICL_cff.py @@ -12,12 +12,13 @@ from RecoHGCal.TICL.ticlLayerTileProducer_cfi import ticlLayerTileProducer from RecoHGCal.TICL.pfTICLProducer_cfi import pfTICLProducer as _pfTICLProducer from RecoHGCal.TICL.trackstersMergeProducer_cfi import trackstersMergeProducer as _trackstersMergeProducer +from RecoHGCal.TICL.ticlGraphProducer_cfi import ticlGraphProducer as _ticlGraphProducer from RecoHGCal.TICL.tracksterSelectionTf_cfi import * ticlLayerTileTask = cms.Task(ticlLayerTileProducer) ticlTrackstersMerge = _trackstersMergeProducer.clone() - +ticlGraph = _ticlGraphProducer.clone() pfTICL = _pfTICLProducer.clone() @@ -43,11 +44,13 @@ ticlIterLabels = [_step.itername.value() for _iteration in ticlIterationsTask for _step in _iteration if (_step._TypedParameterizable__type == "TrackstersProducer")] ticlTracksterMergeTask = cms.Task(ticlTrackstersMerge) +ticlGraphTask = cms.Task(ticlGraph) iterTICLTask = cms.Task(ticlLayerTileTask ,ticlIterationsTask ,ticlTracksterMergeTask ,ticlPFTask + ,ticlGraphTask ) ticlIterLabelsMerge = ticlIterLabels + ["Merge"]