40 messageCategory_(
"CaloTruthAccumulator"),
41 maximumPreviousBunchCrossing_( config.getParameter<unsigned int>(
"maximumPreviousBunchCrossing") ),
42 maximumSubsequentBunchCrossing_( config.getParameter<unsigned int>(
"maximumSubsequentBunchCrossing") ),
43 simTrackLabel_( config.getParameter<edm::
InputTag>(
"simTrackCollection") ),
44 simVertexLabel_( config.getParameter<edm::
InputTag>(
"simVertexCollection") ),
46 genParticleLabel_( config.getParameter<edm::
InputTag>(
"genParticleCollection") ),
47 hepMCproductLabel_( config.getParameter<edm::
InputTag>(
"HepMCProductLabel") ),
48 minEnergy_( config.getParameter<double>(
"MinEnergy") ),
49 maxPseudoRapidity_( config.getParameter<double>(
"MaxPseudoRapidity") )
64 std::vector<std::string> parameterNames=simHitCollectionConfig.
getParameterNames();
66 for(
const auto& parameterName : parameterNames )
68 std::vector<edm::InputTag>
tags=simHitCollectionConfig.getParameter<std::vector<edm::InputTag> >(parameterName);
73 iC.
consumes<std::vector<PCaloHit> >(collectionTag);
90 for(
unsigned i = 0;
i < 2; ++
i ) {
140 <<
" CaloParticles to the event.";
148 for(
auto& hAndE : hitsAndEnergies ) {
204 std::vector<std::pair<DetId,const PCaloHit*> > simHitPointers;
210 for (
unsigned int i = 0 ;
i < simHitPointers.size(); ++
i) {
215 for (
unsigned int i = 0 ;
i < hGenParticles->size() ; ++
i) {
246 std::vector<Index_t> tracksToBecomeClustersInitial;
247 std::vector<Barcode_t> descendantTracks;
249 std::vector<std::unique_ptr<SimHitInfoPerSimTrack_t> > hitInfoList;
250 std::vector<std::vector<uint32_t> > simClusterPrimitives;
251 std::unordered_multimap<Index_t,Index_t> genPartsToSimClusters;
254 for (
unsigned int i = 0 ;
i < simTracks.size() ; ++
i) {
256 if ( simTracks[
i].noGenpart() )
continue;
261 auto mbegin = std::make_move_iterator(
temp.begin());
262 auto mend = std::make_move_iterator(
temp.end());
270 std::vector<Barcode_t>
result;
273 for (
auto vertex_iter = vertex_range.first ; vertex_iter != vertex_range.second ; vertex_iter++ ) {
274 Index_t decayVertexIndex = vertex_iter->second;
277 for (
auto track_iter = track_range.first ; track_iter != track_range.second ; track_iter++ ) {
278 result.push_back( track_iter->second );
280 result.insert(result.end(),daughter_result.begin(),daughter_result.end());
291 LogDebug(
"CaloParticles") <<
"SCZ DEBUG Ignoring descendantSimClusters call because this particle is already marked used: " << barcode << std::endl;
303 if (hit_info->size() > 0) {
306 std::unique_ptr<SimHitInfoPerSimTrack_t> marked_hit_info;
315 if( marked_hit_info->size() != 0 ) {
316 result.emplace_back(simTrack);
317 auto& simcluster = result.back();
319 std::unordered_map<uint32_t,float> acc_energy;
321 for(
const auto& hit_and_energy : *marked_hit_info ) {
322 const uint32_t
id = hit_and_energy.first.rawId();
323 if( acc_energy.count(
id) ) acc_energy[
id] += hit_and_energy.second;
324 else acc_energy[
id] = hit_and_energy.second;
327 for(
const auto& hit_and_energy : acc_energy ) {
328 simcluster.addRecHitAndFraction(hit_and_energy.first,hit_and_energy.second);
335 for (
auto vertex_iter = vertex_range.first ; vertex_iter != vertex_range.second ; vertex_iter++ ) {
336 Index_t decayVertexIndex = vertex_iter->second;
339 for (
auto track_iter = track_range.first ; track_iter != track_range.second ; track_iter++ ) {
342 result.insert(result.end(),daughter_result.begin(),daughter_result.end());
351 bool includeOwn ,
bool includeOther,
bool markUsed ) {
366 for (
auto iter = range.first ; iter != range.second ; iter++ ) {
367 const auto& the_hit = hits[iter->second];
368 result->emplace_back(the_hit.first,the_hit.second->energy());
378 for (
auto vertex_iter = vertex_range.first ; vertex_iter != vertex_range.second ; vertex_iter++ ) {
379 Index_t decayVertexIndex = vertex_iter->second;
380 const auto& nextVtx = (*hSimVertices)[decayVertexIndex];
385 for (
auto track_iter = track_range.first ; track_iter != track_range.second ; track_iter++ ) {
390 const auto& daughter = simTracks[m_simTrackBarcodeToIndex[track_iter->second]];
392 if( includeOther || nextInCalo ) {
394 result->insert(result->end(),daughter_result->begin(),daughter_result->end());
395 }
else if ( daughter.type() == simTrack.type() ) {
397 result->insert(result->end(),daughter_result->begin(),daughter_result->end());
405 std::unique_ptr<SimHitInfoPerSimTrack_t>
407 const std::vector<std::pair<DetId,const PCaloHit*> >& hits,
412 std::unique_ptr<SimHitInfoPerSimTrack_t>
414 const std::vector<std::pair<DetId,const PCaloHit*> >& hits,
423 const bool isHcal = ( collectionTag.instance().find(
"HcalHits") != std::string::npos );
424 event.getByLabel( collectionTag, hSimHits );
425 for(
const auto& simHit : *hSimHits ) {
427 const uint32_t simId = simHit.id();
429 int subdet,
z, depth0, eta0, phi0, lay;
431 int sign = (z==0) ? (-1):(1);
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);
int bunchCrossing() const
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void swap(ora::Record &rh, ora::Record &lh)
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
virtual void initializeEvent(const edm::Event &event, const edm::EventSetup &setup) override
std::vector< Barcode_t > descendantTrackBarcodes(Barcode_t barcode)
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)
virtual void beginLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &setup) override
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
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
virtual 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)
HcalID getHCID(int subdet, int ieta, int iphi, int lay, int idepth) const
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)
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
const edm::InputTag simVertexLabel_
void addSimCluster(const SimClusterRef &ref)
std::vector< std::string > getParameterNames() const
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
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...
CaloTruthAccumulator(const edm::ParameterSet &config, edm::stream::EDProducerBase &mixMod, edm::ConsumesCollector &iC)
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_
virtual 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]
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