CMS 3D CMS Logo

PatternRecognitionbyFastJet.cc
Go to the documentation of this file.
1 // Author: Marco Rovere - marco.rovere@cern.ch
2 // Date: 10/2021
3 #include <algorithm>
4 #include <set>
5 #include <vector>
6 
7 #include "tbb/task_arena.h"
8 #include "tbb/tbb.h"
9 
17 
18 #include "TrackstersPCA.h"
22 
23 #include "fastjet/ClusterSequence.hh"
24 
25 using namespace ticl;
26 using namespace fastjet;
27 
28 template <typename TILES>
31  : PatternRecognitionAlgoBaseT<TILES>(conf, iC),
32  caloGeomToken_(iC.esConsumes<CaloGeometry, CaloGeometryRecord>()),
33  antikt_radius_(conf.getParameter<double>("antikt_radius")),
34  minNumLayerCluster_(conf.getParameter<int>("minNumLayerCluster")),
35  computeLocalTime_(conf.getParameter<bool>("computeLocalTime")){};
36 
37 template <typename TILES>
38 void PatternRecognitionbyFastJet<TILES>::buildJetAndTracksters(std::vector<PseudoJet> &fjInputs,
39  std::vector<ticl::Trackster> &result) {
41  edm::LogVerbatim("PatternRecogntionbyFastJet")
42  << "Creating FastJet with " << fjInputs.size() << " LayerClusters in input";
43  }
44  fastjet::ClusterSequence sequence(fjInputs, JetDefinition(antikt_algorithm, antikt_radius_));
45  auto jets = fastjet::sorted_by_pt(sequence.inclusive_jets(0));
47  edm::LogVerbatim("PatternRecogntionbyFastJet") << "FastJet produced " << jets.size() << " jets/trackster";
48  }
49 
50  auto trackster_idx = result.size();
51  auto jetsSize = std::count_if(jets.begin(), jets.end(), [this](fastjet::PseudoJet jet) {
52  return jet.constituents().size() > static_cast<unsigned int>(minNumLayerCluster_);
53  });
54  result.resize(trackster_idx + jetsSize);
55 
56  for (const auto &pj : jets) {
57  if (pj.constituents().size() > static_cast<unsigned int>(minNumLayerCluster_)) {
58  for (const auto &component : pj.constituents()) {
59  result[trackster_idx].vertices().push_back(component.user_index());
60  result[trackster_idx].vertex_multiplicity().push_back(1);
62  edm::LogVerbatim("PatternRecogntionbyFastJet")
63  << "Jet has " << pj.constituents().size() << " components that are stored in trackster " << trackster_idx;
64  }
65  }
66  trackster_idx++;
67  } else {
69  edm::LogVerbatim("PatternRecogntionbyFastJet")
70  << "Jet with " << pj.constituents().size() << " constituents discarded since too small wrt "
71  << minNumLayerCluster_;
72  }
73  }
74  }
75  fjInputs.clear();
76 }
77 
78 template <typename TILES>
81  std::vector<Trackster> &result,
82  std::unordered_map<int, std::vector<int>> &seedToTracksterAssociation) {
83  // Protect from events with no seeding regions
84  if (input.regions.empty())
85  return;
86 
87  edm::EventSetup const &es = input.es;
88  const CaloGeometry &geom = es.getData(caloGeomToken_);
89  rhtools_.setGeometry(geom);
90 
94 
95  // We need to partition the two sides of the HGCAL detector
96  auto lastLayerPerSide = static_cast<unsigned int>(rhtools_.lastLayer(isHFnose)) - 1;
97  unsigned int maxLayer = 2 * lastLayerPerSide - 1;
98  std::vector<fastjet::PseudoJet> fjInputs;
99  fjInputs.clear();
100  for (unsigned int currentLayer = 0; currentLayer <= maxLayer; ++currentLayer) {
101  if (currentLayer == lastLayerPerSide) {
102  buildJetAndTracksters(fjInputs, result);
103  }
104  const auto &tileOnLayer = input.tiles[currentLayer];
105  for (int ieta = 0; ieta <= nEtaBin; ++ieta) {
106  auto offset = ieta * nPhiBin;
108  edm::LogVerbatim("PatternRecogntionbyFastJet") << "offset: " << offset;
109  }
110  for (int iphi = 0; iphi <= nPhiBin; ++iphi) {
112  edm::LogVerbatim("PatternRecogntionbyFastJet") << "iphi: " << iphi;
113  edm::LogVerbatim("PatternRecogntionbyFastJet") << "Entries in tileBin: " << tileOnLayer[offset + iphi].size();
114  }
115  for (auto clusterIdx : tileOnLayer[offset + iphi]) {
116  // Skip masked layer clusters
117  if (input.mask[clusterIdx] == 0.) {
119  edm::LogVerbatim("PatternRecogntionbyFastJet") << "Skipping masked layerIdx " << clusterIdx;
120  }
121  continue;
122  }
123  // Should we correct for the position of the PV?
124  auto const &cl = input.layerClusters[clusterIdx];
125  math::XYZVector direction(cl.x(), cl.y(), cl.z());
126  direction = direction.Unit();
127  direction *= cl.energy();
128  auto fpj = fastjet::PseudoJet(direction.X(), direction.Y(), direction.Z(), cl.energy());
129  fpj.set_user_index(clusterIdx);
130  fjInputs.push_back(fpj);
131  } // End of loop on the clusters on currentLayer
132  } // End of loop over phi-bin region
133  } // End of loop over eta-bin region
134  } // End of loop over layers
135 
136  // Collect the jet from the other side wrt to the one taken care of inside the main loop above.
137  buildJetAndTracksters(fjInputs, result);
138 
140  input.layerClusters,
141  input.layerClustersTime,
142  rhtools_.getPositionLayer(rhtools_.lastLayerEE(isHFnose), isHFnose).z(),
143  rhtools_,
144  computeLocalTime_);
145 
146  // run energy regression and ID
148  for (auto const &t : result) {
149  edm::LogVerbatim("PatternRecogntionbyFastJet") << "Barycenter: " << t.barycenter();
150  edm::LogVerbatim("PatternRecogntionbyFastJet") << "LCs: " << t.vertices().size();
151  edm::LogVerbatim("PatternRecogntionbyFastJet") << "Energy: " << t.raw_energy();
152  edm::LogVerbatim("PatternRecogntionbyFastJet") << "Regressed: " << t.regressed_energy();
153  }
154  }
155 }
156 
157 template <typename TILES>
159  const std::vector<Trackster> &inTracksters,
161  std::unordered_map<int, std::vector<int>> &seedToTracksterAssociation) {
162  output = inTracksters;
163 }
164 
165 template <typename TILES>
167  iDesc.add<int>("algo_verbosity", 0);
168  iDesc.add<double>("antikt_radius", 0.09)->setComment("Radius to be used while running the Anti-kt clustering");
169  iDesc.add<int>("minNumLayerCluster", 5)->setComment("Not Inclusive");
170  iDesc.add<bool>("computeLocalTime", false);
171 }
172 
Log< level::Info, true > LogVerbatim
void setComment(std::string const &value)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
void assignPCAtoTracksters(std::vector< Trackster > &tracksters, const std::vector< reco::CaloCluster > &layerClusters, const edm::ValueMap< std::pair< float, float >> &layerClustersTime, double z_limit_em, hgcal::RecHitTools const &rhTools, bool computeLocalTime=false, bool energyWeight=true, bool clean=false, int minLayer=10, int maxLayer=10)
static std::string const input
Definition: EdmProvDump.cc:50
PatternRecognitionbyFastJet(const edm::ParameterSet &conf, edm::ConsumesCollector)
static void fillPSetDescription(edm::ParameterSetDescription &iDesc)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void makeTracksters(const typename PatternRecognitionAlgoBaseT< TILES >::Inputs &input, std::vector< Trackster > &result, std::unordered_map< int, std::vector< int >> &seedToTracksterAssociation) override
void buildJetAndTracksters(std::vector< fastjet::PseudoJet > &, std::vector< ticl::Trackster > &)
void filter(std::vector< Trackster > &output, const std::vector< Trackster > &inTracksters, const typename PatternRecognitionAlgoBaseT< TILES >::Inputs &input, std::unordered_map< int, std::vector< int >> &seedToTracksterAssociation) override
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
static constexpr int nPhiBins
Definition: Common.h:10
Definition: output.py:1