4 #pragma GCC diagnostic pop 11 #include <unordered_map> 51 using Index_t = unsigned;
52 using Barcode_t =
int;
53 const std::string messageCategoryGraph_(
"CaloTruthAccumulatorGraphProducer");
76 std::unordered_map<
int, std::map<int, float>> &simTrackDetIdEnergyMap,
148 class CaloParticle_dfs_visitor :
public boost::default_dfs_visitor {
152 std::unordered_multimap<Barcode_t, Index_t> &simHitBarcodeToIndex,
153 std::unordered_map<
int, std::map<int, float>> &simTrackDetIdEnergyMap,
157 simHitBarcodeToIndex_(simHitBarcodeToIndex),
158 simTrackDetIdEnergyMap_(simTrackDetIdEnergyMap),
160 template <
typename Vertex,
typename Graph>
166 auto const vertex_property =
get(vertex_name,
g, u);
167 if (!vertex_property.simTrack)
169 auto trackIdx = vertex_property.simTrack->trackId();
171 <<
" Found " << simHitBarcodeToIndex_.count(trackIdx) <<
" associated simHits" << std::endl;
172 if (simHitBarcodeToIndex_.count(trackIdx)) {
173 output_.pSimClusters->emplace_back(*vertex_property.simTrack);
174 auto &simcluster = output_.pSimClusters->back();
175 std::unordered_map<uint32_t, float> acc_energy;
176 for (
auto const &hit_and_energy : simTrackDetIdEnergyMap_[trackIdx]) {
177 acc_energy[hit_and_energy.first] += hit_and_energy.second;
179 for (
auto const &hit_and_energy : acc_energy) {
180 simcluster.addRecHitAndFraction(hit_and_energy.first, hit_and_energy.second);
184 template <
typename Edge,
typename Graph>
185 void examine_edge(Edge
e,
const Graph &
g) {
187 auto vertex_property =
get(vertex_name,
g,
src);
188 if (
src == 0
or (vertex_property.simTrack ==
nullptr)) {
189 auto edge_property =
get(edge_weight,
g,
e);
190 IfLogDebug(
DEBUG, messageCategoryGraph_) <<
"Considering CaloParticle: " << edge_property.simTrack->trackId();
191 if (selector_(edge_property)) {
192 IfLogDebug(
DEBUG, messageCategoryGraph_) <<
"Adding CaloParticle: " << edge_property.simTrack->trackId();
193 output_.pCaloParticles->emplace_back(*(edge_property.simTrack));
194 caloParticles_.sc_start_.push_back(output_.pSimClusters->size());
199 template <
typename Edge,
typename Graph>
200 void finish_edge(Edge
e,
const Graph &
g) {
202 auto vertex_property =
get(vertex_name,
g,
src);
203 if (
src == 0
or (vertex_property.simTrack ==
nullptr)) {
204 auto edge_property =
get(edge_weight,
g,
e);
205 if (selector_(edge_property)) {
206 caloParticles_.sc_stop_.push_back(output_.pSimClusters->size());
214 std::unordered_multimap<Barcode_t, Index_t> &simHitBarcodeToIndex_;
215 std::unordered_map<int, std::map<int, float>> &simTrackDetIdEnergyMap_;
223 : messageCategory_(
"CaloTruthAccumulator"),
224 maximumPreviousBunchCrossing_(
config.getParameter<unsigned
int>(
"maximumPreviousBunchCrossing")),
225 maximumSubsequentBunchCrossing_(
config.getParameter<unsigned
int>(
"maximumSubsequentBunchCrossing")),
232 minEnergy_(
config.getParameter<double>(
"MinEnergy")),
233 maxPseudoRapidity_(
config.getParameter<double>(
"MaxPseudoRapidity")),
234 premixStage1_(
config.getParameter<
bool>(
"premixStage1")),
240 producesCollector.
produces<std::vector<std::pair<unsigned int, float>>>(
"MergedCaloTruth");
251 std::vector<std::string> parameterNames = simHitCollectionConfig.getParameterNames();
253 for (
auto const ¶meterName : parameterNames) {
254 std::vector<edm::InputTag>
tags = simHitCollectionConfig.getParameter<std::vector<edm::InputTag>>(parameterName);
259 iC.
consumes<std::vector<PCaloHit>>(collectionTag);
292 hgtopo_[1] = &(fhgeom->topology());
294 hgtopo_[2] = &(bhgeomnew->topology());
296 for (
unsigned i = 0;
i < 3; ++
i) {
331 <<
event.bunchCrossing();
348 auto totalEnergies = std::make_unique<std::vector<std::pair<unsigned int, float>>>();
351 std::sort(totalEnergies->begin(), totalEnergies->end());
352 event.put(
std::move(totalEnergies),
"MergedCaloTruth");
355 auto hitsAndEnergies = sc.hits_and_fractions();
356 sc.clearHitsAndFractions();
357 sc.clearHitsEnergy();
358 for (
auto &hAndE : hitsAndEnergies) {
362 fraction = hAndE.second / totalenergy;
365 <<
"TotalSimEnergy for hit " << hAndE.first <<
" is 0! The fraction for this hit cannot be computed.";
366 sc.addRecHitAndFraction(hAndE.first,
fraction);
367 sc.addHitEnergy(hAndE.second);
380 cp.addSimCluster(ref);
405 std::vector<std::pair<DetId, const PCaloHit *>> simHitPointers;
406 std::unordered_map<int, std::map<int, float>> simTrackDetIdEnergyMap;
411 for (
unsigned int i = 0;
i < simHitPointers.size(); ++
i) {
417 std::unordered_map<int, int> trackid_to_track_index;
424 trackid_to_track_index[
t.trackId()] =
idx;
455 std::vector<int> used_sim_tracks(
tracks.size(), 0);
456 std::vector<int> collapsed_vertices(
vertices.size(), 0);
460 if (
v.parentIndex() != -1) {
461 auto trk_idx = trackid_to_track_index[
v.parentIndex()];
462 auto origin_vtx =
tracks[trk_idx].vertIndex();
463 if (used_sim_tracks[trk_idx]) {
467 collapsed_vertices[
v.vertexId()] = used_sim_tracks[trk_idx];
471 if (collapsed_vertices[origin_vtx])
472 origin_vtx = collapsed_vertices[origin_vtx];
477 used_sim_tracks[trk_idx] =
v.vertexId();
481 auto const &vertexMothersProp =
get(vertex_name,
decay);
485 for (
size_t i = 0;
i <
tracks.size(); ++
i) {
486 if (!used_sim_tracks[
i]) {
487 auto origin_vtx =
tracks[
i].vertIndex();
489 if (collapsed_vertices[origin_vtx])
490 origin_vtx = collapsed_vertices[origin_vtx];
501 if (
v.parentIndex() != -1) {
503 if (collapsed_vertices[
v.vertexId()])
508 SimHitsAccumulator_dfs_visitor
vis;
509 depth_first_search(
decay, visitor(
vis));
510 CaloParticle_dfs_visitor caloParticleCreator(
514 simTrackDetIdEnergyMap,
524 depth_first_search(
decay, visitor(caloParticleCreator));
529 make_label_writer(make_transform_value_property_map(&graphviz_vertex,
get(vertex_name,
decay))),
530 make_label_writer(make_transform_value_property_map(&graphviz_edge,
get(edge_weight,
decay))));
536 std::unordered_map<
int, std::map<int, float>> &simTrackDetIdEnergyMap,
541 const bool isHcal = (collectionTag.instance().find(
"HcalHits") != std::string::npos);
542 event.getByLabel(collectionTag, hSimHits);
544 for (
auto const &
simHit : *hSimHits) {
549 const uint32_t simId =
simHit.id();
558 int subdet,
layer, cell,
sec, subsec, zp;
562 cell = recoLayerCell.first;
563 layer = recoLayerCell.second;
578 if (
id ==
DetId(0)) {
581 if (
simHit.geantTrackId() == 0) {
585 returnValue.emplace_back(
id, &
simHit);
586 simTrackDetIdEnergyMap[
simHit.geantTrackId()][
id.rawId()] +=
simHit.energy();
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::unordered_multimap< Barcode_t, Index_t > m_simHitBarcodeToIndex
calo_particles m_caloParticles
edm::Handle< std::vector< SimVertex > > hSimVertices
void fillSimHits(std::vector< std::pair< DetId, const PCaloHit *>> &returnValue, std::unordered_map< int, std::map< int, float >> &simTrackDetIdEnergyMap, const T &event, const edm::EventSetup &setup)
Fills the supplied vector with pointers to the SimHits, checking for bad modules if required...
void initializeEvent(const edm::Event &event, const edm::EventSetup &setup) override
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
const HGCalTopology * hgtopo_[3]
const unsigned int maximumSubsequentBunchCrossing_
void swap(calo_particles &oth)
std::vector< edm::InputTag > collectionTags_
edm::InputTag genParticleLabel_
OutputCollections output_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
void swap(Association< C > &lhs, Association< C > &rhs)
const math::XYZTLorentzVectorD & momentum() const
void put(edm::Event &evt, double value, const char *instanceName)
edm::ESWatcher< CaloGeometryRecord > geomWatcher_
const SimTrack * simTrack
U second(std::pair< T, U > const &p)
constexpr HcalSubdetector subdet() const
get the subdetector
edm::InputTag hepMCproductLabel_
Needed to add HepMC::GenVertex to SimVertex.
#define IfLogDebug(cond, cat)
const std::string messageCategory_
adjacency_list< listS, vecS, directedS, VertexMotherParticleProperty, EdgeParticleClustersProperty > DecayChain
void accumulate(const edm::Event &event, const edm::EventSetup &setup) override
const double maxPseudoRapidity_
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geomToken_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Abs< T >::type abs(const T &t)
std::pair< int, int > simToReco(int cell, int layer, int mod, bool half) const
CaloTruthAccumulator(const edm::ParameterSet &config, edm::ProducesCollector, edm::ConsumesCollector &iC)
std::unordered_map< Index_t, float > m_detIdToTotalSimEnergy
const edm::InputTag simVertexLabel_
DetId relabel(const uint32_t testId) const
Functor that operates on <T>
const HGCalDDDConstants * hgddd_[3]
const edm::InputTag simTrackLabel_
Log< level::Info, false > LogInfo
edm::Handle< std::vector< SimTrack > > hSimTracks
void accumulateEvent(const T &event, const edm::EventSetup &setup, const edm::Handle< edm::HepMCProduct > &hepMCproduct)
Both forms of accumulate() delegate to this templated method.
std::unique_ptr< CaloParticleCollection > pCaloParticles
std::vector< uint32_t > sc_stop_
const HcalDDDRecConstants * hcddd_
void finalizeEvent(edm::Event &event, const edm::EventSetup &setup) override
bool check(const edm::EventSetup &iSetup)
#define DEFINE_DIGI_ACCUMULATOR(type)
std::vector< CaloParticle > CaloParticleCollection
std::vector< uint32_t > sc_start_
const HcalDDDRecConstants * dddConstants() const
std::unique_ptr< SimClusterCollection > pSimClusters
Log< level::Warning, false > LogWarning
std::vector< SimCluster > SimClusterCollection
static std::string const source
const HGCalDDDConstants & dddConstants() const
static void unpackHexagonIndex(const uint32_t &idx, int &subdet, int &z, int &lay, int &wafer, int &celltyp, int &cell)
const unsigned int maximumPreviousBunchCrossing_
const HcalTopology & topology() const