57 : makeCellsCollection_(
config.getParameter<
bool>(
"makeCellsCollection")),
66 produces<CaloToCellsMap>();
67 produces<l1t::HGCalClusterBxCollection>();
68 produces<l1t::HGCalMulticlusterBxCollection>();
70 produces<l1t::HGCalTriggerCellBxCollection>();
89 std::unordered_map<uint32_t, CaloParticleRef> tcToCalo;
92 std::unordered_map<uint32_t, std::pair<double, double>>
95 for (
auto const&
he : hitToEnergy) {
98 uint32_t tcId(
geometry.getTriggerCellFromCell(hitId));
99 tcToEnergies[tcId].first +=
he.second;
103 std::map<int, CaloParticleRef> orderedCaloRefs;
107 if (caloParticle.g4Tracks().at(0).eventId().event() != 0)
114 for (
auto const& hAndF : simCluster->hits_and_fractions()) {
115 DetId hitId(hAndF.first);
118 tcId =
geometry.getTriggerCellFromCell(hitId);
124 tcToCalo.emplace(tcId, ref);
125 tcToEnergies[tcId].second += hitToEnergy[hAndF.first] * hAndF.second;
130 int genIndex(caloParticle.g4Tracks().at(0).genpartIndex() - 1);
131 orderedCaloRefs[genIndex] = ref;
134 auto outMap(std::make_unique<CaloToCellsMap>(caloParticlesHandle, triggerCellsHandle));
135 std::unique_ptr<l1t::HGCalTriggerCellBxCollection> outCollection;
137 outCollection = std::make_unique<l1t::HGCalTriggerCellBxCollection>();
143 std::vector<TriggerCellPtr> triggerCellPtrs;
148 auto const& cell(*cItr);
150 auto mapElem(tcToCalo.find(cell.detId()));
151 if (mapElem == tcToCalo.end())
154 outMap->insert(mapElem->second,
158 auto const& simEnergies(tcToEnergies.at(cell.detId()));
159 if (simEnergies.first > 0.) {
160 double eFraction(simEnergies.second / simEnergies.first);
162 outCollection->push_back(
bx, cell);
163 auto& newCell((*outCollection)[outCollection->size() - 1]);
165 newCell.setMipPt(cell.mipPt() * eFraction);
166 newCell.setP4(cell.p4() * eFraction);
170 triggerCellPtrs.emplace_back(triggerCellsHandle,
triggerCells.key(cItr));
178 auto outClusters(std::make_unique<l1t::HGCalClusterBxCollection>());
181 [](TriggerCellPtr
const& lhs, TriggerCellPtr
const& rhs) ->
bool {
return lhs->mipPt() > rhs->mipPt(); });
183 std::sort(triggerCellPtrs.begin(), triggerCellPtrs.end(), sortCellPtrs);
186 std::unordered_map<unsigned, std::vector<unsigned>> caloToClusterIndices;
187 for (
unsigned iC(0); iC != outClusters->size(); ++iC) {
188 auto const& cluster((*outClusters)[iC]);
190 auto caloRef(tcToCalo.at(cluster.detId()));
191 caloToClusterIndices[caloRef.key()].push_back(iC);
196 auto outMulticlusters(std::make_unique<l1t::HGCalMulticlusterBxCollection>());
198 for (
auto const& ocr : orderedCaloRefs) {
199 auto const& ref(ocr.second);
204 auto const& caloParticle(*ref);
208 for (
unsigned iC : caloToClusterIndices[ref.key()]) {
209 ClusterPtr clPtr(clustersHandle, iC);
214 multicluster.
setDetId(caloParticle.g4Tracks().at(0).genpartIndex() - 1);
216 auto const& centre(multicluster.
centre());
218 multicluster.
setP4(multiclusterP4);
227 outMulticlusters->push_back(0, multicluster);
235 std::unordered_map<uint32_t, double> hitMap;
237 typedef std::function<DetId(DetId const&)> DetIdMapper;
238 typedef std::pair<edm::EDGetTokenT<std::vector<PCaloHit>>
const*, DetIdMapper> SimHitSpec;
254 event.getByToken(*
tt.first,
handle);
257 for (
auto const& simhit :
simhits)
258 hitMap.emplace(
tt.second(simhit.id()), simhit.energy());
void addConstituent(const edm::Ptr< C > &c, bool updateCentre=true, float fraction=1.)
HGCalClusteringDummyImpl dummyClustering_
BXVector< HGCalTriggerCell > HGCalTriggerCellBxCollection
void setDetId(uint32_t id)
edm::EDGetTokenT< std::vector< PCaloHit > > simHitsTokenEE_
void setGeometry(const HGCalTriggerGeometryBase *const geom)
edm::ESGetToken< HGCalTriggerGeometryBase, CaloGeometryRecord > triggerGeomToken_
void produce(edm::Event &, edm::EventSetup const &) override
Log< level::Error, false > LogError
void clusterizeDummy(const std::vector< edm::Ptr< l1t::HGCalTriggerCell >> &triggerCellsPtrs, l1t::HGCalClusterBxCollection &clusters)
~CaloTruthCellsProducer() override
const GlobalPoint & centre() const
std::unordered_map< uint32_t, double > makeHitMap(edm::Event const &, edm::EventSetup const &, HGCalTriggerGeometryBase const &) const
CaloTruthCellsProducer(edm::ParameterSet const &)
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
void addDefault(ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< l1t::HGCalTriggerCellBxCollection > triggerCellsToken_
void setGeometry(const HGCalTriggerGeometryBase *const geom)
void fillShapes(l1t::HGCalMulticluster &, const HGCalTriggerGeometryBase &) const
#define DEFINE_FWK_MODULE(type)
edm::EDGetTokenT< CaloParticleCollection > caloParticlesToken_
edm::EDGetTokenT< std::vector< PCaloHit > > simHitsTokenHEback_
bool makeCellsCollection_
edm::EDGetTokenT< std::vector< PCaloHit > > simHitsTokenHEfront_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ParameterSet const & getParameterSet(ParameterSetID const &id)
HGCalTriggerTools triggerTools_
std::vector< CaloParticle > CaloParticleCollection
edm::AssociationMap< edm::OneToMany< CaloParticleCollection, l1t::HGCalTriggerCellBxCollection > > CaloToCellsMap
HGCalShowerShape showerShape_
char const * what() const noexcept override
void setP4(const LorentzVector &p4) final
set 4-momentum