59 : makeCellsCollection_(
config.getParameter<
bool>(
"makeCellsCollection")),
68 produces<CaloToCellsMap>();
69 produces<l1t::HGCalClusterBxCollection>();
70 produces<l1t::HGCalMulticlusterBxCollection>();
72 produces<l1t::HGCalTriggerCellBxCollection>();
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);
242 std::unordered_map<uint32_t, double> hitMap;
244 typedef std::function<DetId(DetId const&)> DetIdMapper;
245 typedef std::pair<edm::EDGetTokenT<std::vector<PCaloHit>>
const*, DetIdMapper> SimHitSpec;
261 event.getByToken(*
tt.first,
handle);
264 for (
auto const& simhit :
simhits)
265 hitMap.emplace(
tt.second(simhit.id()), simhit.energy());
void addConstituent(const edm::Ptr< C > &c, bool updateCentre=true, float fraction=1.)
HGCalClusteringDummyImpl dummyClustering_
void beginRun(const edm::Run &, const edm::EventSetup &) override
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.
T const * product() const
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_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
edm::EDGetTokenT< std::vector< PCaloHit > > simHitsTokenHEback_
bool makeCellsCollection_
edm::EDGetTokenT< std::vector< PCaloHit > > simHitsTokenHEfront_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::ESHandle< HGCalTriggerGeometryBase > triggerGeomHandle_
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