42 messageCategory_(
"CaloTruthAccumulator"),
43 maximumPreviousBunchCrossing_( config.getParameter<unsigned
int>(
"maximumPreviousBunchCrossing") ),
44 maximumSubsequentBunchCrossing_( config.getParameter<unsigned
int>(
"maximumSubsequentBunchCrossing") ),
45 simTrackLabel_( config.getParameter<
edm::InputTag>(
"simTrackCollection") ),
46 simVertexLabel_( config.getParameter<
edm::InputTag>(
"simVertexCollection") ),
48 genParticleLabel_( config.getParameter<
edm::InputTag>(
"genParticleCollection") ),
49 hepMCproductLabel_( config.getParameter<
edm::InputTag>(
"HepMCProductLabel") ),
50 minEnergy_( config.getParameter<double>(
"MinEnergy") ),
51 maxPseudoRapidity_( config.getParameter<double>(
"MaxPseudoRapidity") )
66 std::vector<std::string> parameterNames=simHitCollectionConfig.
getParameterNames();
68 for(
const auto& parameterName : parameterNames )
70 std::vector<edm::InputTag> tags=simHitCollectionConfig.getParameter<std::vector<edm::InputTag> >(parameterName);
75 iC.
consumes<std::vector<PCaloHit> >(collectionTag);
92 for(
unsigned i = 0;
i < 2; ++
i ) {
142 <<
" CaloParticles to the event.";
150 for(
auto& hAndE : hitsAndEnergies ) {
153 if(totalenergy>0) fraction = hAndE.second/totalenergy;
154 else edm::LogWarning(
"CaloTruthAccumulator") <<
"TotalSimEnergy for hit " << hAndE.first <<
" is 0! The fraction for this hit cannot be computed.";
209 std::vector<std::pair<DetId,const PCaloHit*> > simHitPointers;
215 for (
unsigned int i = 0 ;
i < simHitPointers.size(); ++
i) {
220 for (
unsigned int i = 0 ;
i < hGenParticles->size() ; ++
i) {
251 std::vector<Index_t> tracksToBecomeClustersInitial;
252 std::vector<Barcode_t> descendantTracks;
254 std::vector<std::unique_ptr<SimHitInfoPerSimTrack_t> > hitInfoList;
255 std::vector<std::vector<uint32_t> > simClusterPrimitives;
256 std::unordered_multimap<Index_t,Index_t> genPartsToSimClusters;
263 if( !
temp.empty() ) {
266 auto mbegin = std::make_move_iterator(
temp.begin());
267 auto mend = std::make_move_iterator(
temp.end());
275 std::vector<Barcode_t>
result;
278 for (
auto vertex_iter = vertex_range.first ; vertex_iter != vertex_range.second ; vertex_iter++ ) {
279 Index_t decayVertexIndex = vertex_iter->second;
282 for (
auto track_iter = track_range.first ; track_iter != track_range.second ; track_iter++ ) {
283 result.push_back( track_iter->second );
285 result.insert(result.end(),daughter_result.begin(),daughter_result.end());
296 LogDebug(
"CaloParticles") <<
"SCZ DEBUG Ignoring descendantSimClusters call because this particle is already marked used: " << barcode << std::endl;
308 if (!hit_info->empty()) {
311 std::unique_ptr<SimHitInfoPerSimTrack_t> marked_hit_info;
320 if( !marked_hit_info->empty() ) {
322 auto& simcluster = result.back();
324 std::unordered_map<uint32_t,float> acc_energy;
326 for(
const auto& hit_and_energy : *marked_hit_info ) {
327 const uint32_t
id = hit_and_energy.first.rawId();
328 if( acc_energy.count(
id) ) acc_energy[
id] += hit_and_energy.second;
329 else acc_energy[
id] = hit_and_energy.second;
332 for(
const auto& hit_and_energy : acc_energy ) {
333 simcluster.addRecHitAndFraction(hit_and_energy.first,hit_and_energy.second);
340 for (
auto vertex_iter = vertex_range.first ; vertex_iter != vertex_range.second ; vertex_iter++ ) {
341 Index_t decayVertexIndex = vertex_iter->second;
344 for (
auto track_iter = track_range.first ; track_iter != track_range.second ; track_iter++ ) {
347 result.insert(result.end(),daughter_result.begin(),daughter_result.end());
356 bool includeOwn ,
bool includeOther,
bool markUsed ) {
371 for (
auto iter = range.first ; iter != range.second ; iter++ ) {
372 const auto& the_hit =
hits[iter->second];
373 result->emplace_back(the_hit.first,the_hit.second->energy());
383 for (
auto vertex_iter = vertex_range.first ; vertex_iter != vertex_range.second ; vertex_iter++ ) {
384 Index_t decayVertexIndex = vertex_iter->second;
385 const auto& nextVtx = (*hSimVertices)[decayVertexIndex];
390 for (
auto track_iter = track_range.first ; track_iter != track_range.second ; track_iter++ ) {
395 const auto& daughter =
simTracks[m_simTrackBarcodeToIndex[track_iter->second]];
397 if( includeOther || nextInCalo ) {
399 result->insert(result->end(),daughter_result->begin(),daughter_result->end());
400 }
else if ( daughter.type() ==
simTrack.type() ) {
402 result->insert(result->end(),daughter_result->begin(),daughter_result->end());
410 std::unique_ptr<SimHitInfoPerSimTrack_t>
412 const std::vector<std::pair<DetId,const PCaloHit*> >&
hits,
417 std::unique_ptr<SimHitInfoPerSimTrack_t>
419 const std::vector<std::pair<DetId,const PCaloHit*> >&
hits,
428 const bool isHcal = ( collectionTag.instance().find(
"HcalHits") != std::string::npos );
429 event.getByLabel( collectionTag, hSimHits );
430 for(
const auto&
simHit : *hSimHits ) {
432 const uint32_t simId =
simHit.id();
437 int subdet, layer, cell, sec, subsec, zp;
440 std::pair<int,int> recoLayerCell = ddd->
simToReco(cell,layer,sec,
441 hgtopo_[subdet-3]->detectorType());
442 cell = recoLayerCell.first;
443 layer = recoLayerCell.second;
445 if( layer == -1 ||
simHit.geantTrackId() == 0 )
continue;
449 if(
DetId(0) ==
id )
continue;
451 uint32_t detId =
id.rawId();
452 returnValue.emplace_back(
id, &
simHit);
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
int bunchCrossing() const
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
void setConsideredBarcode(Barcode_t barcode)
calo_particles m_caloParticles
const HcalDDDRecConstants * dddConstants() const
std::unordered_multimap< Index_t, Index_t > m_detIdToCluster
edm::Handle< std::vector< SimVertex > > hSimVertices
std::unordered_multimap< Barcode_t, Index_t > m_simTrackToSimVertex
void initializeEvent(const edm::Event &event, const edm::EventSetup &setup) override
std::vector< Barcode_t > descendantTrackBarcodes(Barcode_t barcode)
HcalSubdetector subdet() const
get the subdetector
std::unordered_multimap< Barcode_t, Index_t > m_simHitBarcodeToIndex
std::vector< std::pair< uint32_t, float > > hits_and_fractions() const
Returns list of rechit IDs and fractions for this SimCluster.
const unsigned int maximumSubsequentBunchCrossing_
void swap(calo_particles &oth)
void beginLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &setup) override
def setup(process, global_tag, zero_tesla=False)
std::unordered_map< Barcode_t, Index_t > m_genParticleBarcodeToIndex
std::unordered_map< Barcode_t, Index_t > m_genBarcodeToSimTrackIndex
std::vector< edm::InputTag > collectionTags_
edm::InputTag genParticleLabel_
std::unique_ptr< SimHitInfoPerSimTrack_t > attachedSimHitInfo(Barcode_t st, const std::vector< std::pair< DetId, const PCaloHit * > > &hits, bool includeOwn=true, bool includeOther=false, bool markUsed=false)
OutputCollections output_
void addRecHitAndFraction(uint32_t hit, float fraction)
add rechit with fraction
void swap(Association< C > &lhs, Association< C > &rhs)
const HcalTopology & topology() const
U second(std::pair< T, U > const &p)
edm::InputTag hepMCproductLabel_
Needed to add HepMC::GenVertex to SimVertex.
const std::string messageCategory_
The message category used to send messages to MessageLogger.
std::pair< int, int > simToReco(int cell, int layer, int mod, bool half) const
void accumulate(const edm::Event &event, const edm::EventSetup &setup) override
const double maxPseudoRapidity_
std::unique_ptr< SimHitInfoPerSimTrack_t > allAttachedSimHitInfo(Barcode_t st, const std::vector< std::pair< DetId, const PCaloHit * > > &hits, bool markUsed=false)
simTrack
per collection params
CaloTruthAccumulator(const edm::ParameterSet &config, edm::ProducerBase &mixMod, edm::ConsumesCollector &iC)
const HGCalTopology & topology() const
void fillSimHits(std::vector< std::pair< DetId, const PCaloHit * > > &returnValue, const T &event, const edm::EventSetup &setup)
Fills the supplied vector with pointers to the SimHits, checking for bad modules if required...
void clearHitsAndFractions()
clear the hits and fractions list
Abs< T >::type abs(const T &t)
const edm::InputTag simVertexLabel_
void addSimCluster(const SimClusterRef &ref)
std::vector< std::string > getParameterNames() const
bool consideredBarcode(Barcode_t barcode)
std::unordered_map< Barcode_t, Barcode_t > m_simTrackBarcodeToSimVertexParentBarcode
const HGCalDDDConstants * hgddd_[2]
std::vector< Barcode_t > m_simVertexBarcodes
double waferZ(int layer, bool reco) const
const edm::InputTag simTrackLabel_
If bremsstrahlung merging, whether to also add the unmerged collection to the event or not...
std::unordered_map< Barcode_t, Index_t > m_simTrackBarcodeToIndex
edm::Handle< std::vector< SimTrack > > hSimTracks
std::unordered_map< Barcode_t, Index_t > m_simVertexBarcodeToIndex
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
const HGCalDDDConstants & dddConstants() const
ParameterSet const & getParameterSet(std::string const &) const
std::vector< uint32_t > sc_stop_
bool barcodeLogicWarningAlready_
std::unique_ptr< SimHitInfoPerSimTrack_t > descendantOnlySimHitInfo(Barcode_t st, const std::vector< std::pair< DetId, const PCaloHit * > > &hits, bool markUsed=false)
const HcalDDDRecConstants * hcddd_
void finalizeEvent(edm::Event &event, const edm::EventSetup &setup) override
std::vector< SimHitInfoPerRecoDetId_t > SimHitInfoPerSimTrack_t
std::set< Barcode_t > m_simTracksConsideredForSimClusters
#define DEFINE_DIGI_ACCUMULATOR(type)
std::vector< CaloParticle > CaloParticleCollection
std::vector< uint32_t > sc_start_
SimClusterCollection descendantSimClusters(Barcode_t barcode, const std::vector< std::pair< DetId, const PCaloHit * > > &hits)
std::unique_ptr< SimClusterCollection > pSimClusters
const HGCalTopology * hgtopo_[2]
DetId relabel(const uint32_t testId) const
std::unordered_multimap< Barcode_t, Index_t > m_simVertexToSimTrackParent
std::vector< SimCluster > SimClusterCollection
std::unordered_map< Index_t, float > m_detIdToTotalSimEnergy
std::unordered_multimap< Barcode_t, Barcode_t > m_simVertexBarcodeToSimTrackBarcode
static void unpackHexagonIndex(const uint32_t &idx, int &subdet, int &z, int &lay, int &wafer, int &celltyp, int &cell)
const unsigned int maximumPreviousBunchCrossing_
maximum distance for HepMC::GenVertex to be added to SimVertex