96 std::unordered_map<uint32_t, CaloParticleRef> tcToCalo;
99 std::unordered_map<uint32_t, std::pair<double, double>>
102 for (
auto const&
he : hitToEnergy) {
105 uint32_t tcId(
geometry.getTriggerCellFromCell(hitId));
106 tcToEnergies[tcId].first +=
he.second;
110 std::map<int, CaloParticleRef> orderedCaloRefs;
114 if (caloParticle.g4Tracks().at(0).eventId().event() != 0)
120 for (
auto const& simCluster : simClusters) {
121 for (
auto const& hAndF : simCluster->hits_and_fractions()) {
122 DetId hitId(hAndF.first);
125 tcId =
geometry.getTriggerCellFromCell(hitId);
131 tcToCalo.emplace(tcId, ref);
132 tcToEnergies[tcId].second += hitToEnergy[hAndF.first] * hAndF.second;
137 int genIndex(caloParticle.g4Tracks().at(0).genpartIndex() - 1);
138 orderedCaloRefs[genIndex] = ref;
141 auto outMap(std::make_unique<CaloToCellsMap>(caloParticlesHandle, triggerCellsHandle));
142 std::unique_ptr<l1t::HGCalTriggerCellBxCollection> outCollection;
144 outCollection = std::make_unique<l1t::HGCalTriggerCellBxCollection>();
150 std::vector<TriggerCellPtr> triggerCellPtrs;
155 auto const& cell(*cItr);
157 auto mapElem(tcToCalo.find(cell.detId()));
158 if (mapElem == tcToCalo.end())
161 outMap->insert(mapElem->second,
165 auto const& simEnergies(tcToEnergies.at(cell.detId()));
166 if (simEnergies.first > 0.) {
167 double eFraction(simEnergies.second / simEnergies.first);
169 outCollection->push_back(
bx, cell);
170 auto& newCell((*outCollection)[outCollection->size() - 1]);
172 newCell.setMipPt(cell.mipPt() * eFraction);
173 newCell.setP4(cell.p4() * eFraction);
177 triggerCellPtrs.emplace_back(triggerCellsHandle,
triggerCells.key(cItr));
185 auto outClusters(std::make_unique<l1t::HGCalClusterBxCollection>());
188 [](TriggerCellPtr
const& lhs, TriggerCellPtr
const& rhs) ->
bool {
return lhs->mipPt() > rhs->mipPt(); });
190 std::sort(triggerCellPtrs.begin(), triggerCellPtrs.end(), sortCellPtrs);
193 std::unordered_map<unsigned, std::vector<unsigned>> caloToClusterIndices;
194 for (
unsigned iC(0); iC != outClusters->size(); ++iC) {
195 auto const& cluster((*outClusters)[iC]);
197 auto caloRef(tcToCalo.at(cluster.detId()));
198 caloToClusterIndices[caloRef.key()].push_back(iC);
203 auto outMulticlusters(std::make_unique<l1t::HGCalMulticlusterBxCollection>());
205 for (
auto const& ocr : orderedCaloRefs) {
206 auto const& ref(ocr.second);
211 auto const& caloParticle(*ref);
215 for (
unsigned iC : caloToClusterIndices[ref.key()]) {
216 ClusterPtr clPtr(clustersHandle, iC);
221 multicluster.
setDetId(caloParticle.g4Tracks().at(0).genpartIndex() - 1);
223 auto const& centre(multicluster.
centre());
225 multicluster.
setP4(multiclusterP4);
234 outMulticlusters->push_back(0, multicluster);
void addConstituent(const edm::Ptr< C > &c, bool updateCentre=true, float fraction=1.)
HGCalClusteringDummyImpl dummyClustering_
void setDetId(uint32_t id)
void setGeometry(const HGCalTriggerGeometryBase *const geom)
Log< level::Error, false > LogError
void clusterizeDummy(const std::vector< edm::Ptr< l1t::HGCalTriggerCell >> &triggerCellsPtrs, l1t::HGCalClusterBxCollection &clusters)
const GlobalPoint & centre() const
std::unordered_map< uint32_t, double > makeHitMap(edm::Event const &, edm::EventSetup const &, HGCalTriggerGeometryBase const &) const
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
T const * product() const
edm::EDGetTokenT< l1t::HGCalTriggerCellBxCollection > triggerCellsToken_
void setGeometry(const HGCalTriggerGeometryBase *const geom)
void fillShapes(l1t::HGCalMulticluster &, const HGCalTriggerGeometryBase &) const
edm::EDGetTokenT< CaloParticleCollection > caloParticlesToken_
bool makeCellsCollection_
edm::ESHandle< HGCalTriggerGeometryBase > triggerGeomHandle_
HGCalTriggerTools triggerTools_
HGCalShowerShape showerShape_
char const * what() const noexcept override
void setP4(const LorentzVector &p4) final
set 4-momentum