CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
RealisticSimClusterMapper Class Reference

#include <RealisticSimClusterMapper.h>

Inheritance diagram for RealisticSimClusterMapper:
InitialClusteringStepBase

Public Member Functions

void buildClusters (const edm::Handle< reco::PFRecHitCollection > &, const std::vector< bool > &, const std::vector< bool > &, reco::PFClusterCollection &) override
 
RealisticSimClusterMapperoperator= (const RealisticSimClusterMapper &)=delete
 
 RealisticSimClusterMapper (const edm::ParameterSet &conf, edm::ConsumesCollector &sumes)
 
 RealisticSimClusterMapper (const RealisticSimClusterMapper &)=delete
 
void update (const edm::EventSetup &) final
 
void updateEvent (const edm::Event &) final
 
 ~RealisticSimClusterMapper () override
 
- Public Member Functions inherited from InitialClusteringStepBase
 InitialClusteringStepBase (const edm::ParameterSet &conf, edm::ConsumesCollector &sumes)
 
 InitialClusteringStepBase (const ICSB &)=delete
 
std::ostream & operator<< (std::ostream &o) const
 
ICSBoperator= (const ICSB &)=delete
 
void reset ()
 
virtual ~InitialClusteringStepBase ()=default
 

Private Attributes

const float calibMaxEta_ = 3.0
 
const float calibMinEta_ = 1.4
 
std::vector< double > egammaCalib_
 
const float exclusiveFraction_ = 0.7f
 
std::vector< double > hadronCalib_
 
const float invisibleFraction_ = 0.3f
 
const float maxDforTimingSquared_ = 4.0f
 
const float maxDistance_ = 10.f
 
const bool maxDistanceFilter_ = false
 
const unsigned int minNHitsforTiming_ = 3
 
hgcal::RecHitTools rhtools_
 
edm::Handle< SimClusterCollectionsimClusterH_
 
edm::EDGetTokenT< SimClusterCollectionsimClusterToken_
 
const float timeOffset_
 
const bool useMCFractionsForExclEnergy_ = false
 

Additional Inherited Members

- Protected Types inherited from InitialClusteringStepBase
typedef std::tuple< std::vector< int >, std::vector< double >, std::vector< double > > I3tuple
 
- Protected Member Functions inherited from InitialClusteringStepBase
reco::PFRecHitRef makeRefhit (const edm::Handle< reco::PFRecHitCollection > &h, const unsigned i) const
 
- Protected Attributes inherited from InitialClusteringStepBase
const std::unordered_map< std::string, int > _layerMap
 
unsigned _nClustersFound
 
unsigned _nSeeds
 
std::unordered_map< int, I3tuple_thresholds
 

Detailed Description

Definition at line 14 of file RealisticSimClusterMapper.h.

Constructor & Destructor Documentation

RealisticSimClusterMapper::RealisticSimClusterMapper ( const edm::ParameterSet conf,
edm::ConsumesCollector sumes 
)
inline

Definition at line 16 of file RealisticSimClusterMapper.h.

References edm::ConsumesCollector::consumes(), egammaCalib_, edm::ParameterSet::getParameter(), hadronCalib_, and simClusterToken_.

Referenced by ~RealisticSimClusterMapper().

17  : InitialClusteringStepBase(conf, sumes),
18  invisibleFraction_(conf.getParameter<double>("invisibleFraction")),
19  exclusiveFraction_(conf.getParameter<double>("exclusiveFraction")),
20  maxDistanceFilter_(conf.getParameter<bool>("maxDistanceFilter")),
21  maxDistance_(conf.getParameter<double>("maxDistance")),
22  maxDforTimingSquared_(conf.getParameter<double>("maxDforTimingSquared")),
23  timeOffset_(conf.getParameter<double>("timeOffset")),
24  minNHitsforTiming_(conf.getParameter<unsigned int>("minNHitsforTiming")),
25  useMCFractionsForExclEnergy_(conf.getParameter<bool>("useMCFractionsForExclEnergy")),
26  calibMinEta_(conf.getParameter<double>("calibMinEta")),
27  calibMaxEta_(conf.getParameter<double>("calibMaxEta")) {
29  hadronCalib_ = conf.getParameter<std::vector<double> >("hadronCalib");
30  egammaCalib_ = conf.getParameter<std::vector<double> >("egammaCalib");
31  }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
edm::EDGetTokenT< SimClusterCollection > simClusterToken_
std::vector< double > egammaCalib_
InitialClusteringStepBase(const edm::ParameterSet &conf, edm::ConsumesCollector &sumes)
std::vector< double > hadronCalib_
std::vector< SimCluster > SimClusterCollection
Definition: SimClusterFwd.h:8
RealisticSimClusterMapper::~RealisticSimClusterMapper ( )
inlineoverride
RealisticSimClusterMapper::RealisticSimClusterMapper ( const RealisticSimClusterMapper )
delete

Member Function Documentation

void RealisticSimClusterMapper::buildClusters ( const edm::Handle< reco::PFRecHitCollection > &  input,
const std::vector< bool > &  rechitMask,
const std::vector< bool > &  seedable,
reco::PFClusterCollection output 
)
overridevirtual

Implements InitialClusteringStepBase.

Definition at line 48 of file RealisticSimClusterMapper.cc.

References funct::abs(), reco::PFCluster::addRecHitFraction(), calibMaxEta_, calibMinEta_, RealisticHitToClusterAssociator::computeAssociation(), egammaCalib_, relativeConstraints::empty, PVValHelper::eta, exclusiveFraction_, f, RealisticHitToClusterAssociator::filterHitsByDistance(), RealisticHitToClusterAssociator::findAndMergeInvisibleClusters(), RealisticHitToClusterAssociator::findCentersOfGravity(), hgcalsimclustertime::fixSizeHighestDensity(), DetId::Forward, ForwardEmpty, HLT_2018_cff::fraction, spr::getEnergy(), hgcal::RecHitTools::getGeometryType(), hgcal::RecHitTools::getLayer(), hgcal::RecHitTools::getLayerWithOffset(), hgcal::RecHitTools::getPosition(), hadronCalib_, hfClusterShapes_cfi::hits, SimCluster::hits_and_fractions(), reco::CaloCluster::hitsAndFractions(), mps_fire::i, RealisticHitToClusterAssociator::init(), input, RealisticHitToClusterAssociator::insertHitEnergy(), RealisticHitToClusterAssociator::insertHitPosition(), RealisticHitToClusterAssociator::insertLayerId(), RealisticHitToClusterAssociator::insertSimClusterIdAndFraction(), invisibleFraction_, hgcal::RecHitTools::lastLayerEE(), hgcal::RecHitTools::lastLayerFH(), InitialClusteringStepBase::makeRefhit(), maxDforTimingSquared_, maxDistance_, maxDistanceFilter_, minNHitsforTiming_, heavyionUCCDQM_cfi::nClusters, numberOfLayers(), or, EgammaValidation_cff::pdgId, funct::pow(), RealisticHitToClusterAssociator::realisticClusters(), rhtools_, SimDataFormats::CaloAnalysis::sc, SurveyInfoScenario_cff::seed, reco::CaloCluster::setCorrectedEnergy(), reco::CaloCluster::setEnergy(), reco::CaloCluster::setSeed(), reco::PFCluster::setTime(), simClusterH_, timeOffset_, and useMCFractionsForExclEnergy_.

Referenced by ~RealisticSimClusterMapper().

51  {
52  const SimClusterCollection& simClusters = *simClusterH_;
53  auto const& hits = *input;
54  RealisticHitToClusterAssociator realisticAssociator;
57  realisticAssociator.init(hits.size(), simClusters.size(), numberOfLayers + 1);
58  // for quick indexing back to hit energy
59  std::unordered_map<uint32_t, size_t> detIdToIndex(hits.size());
60  for (uint32_t i = 0; i < hits.size(); ++i) {
61  detIdToIndex[hits[i].detId()] = i;
62  auto ref = makeRefhit(input, i);
63  const auto& hitPos = rhtools_.getPosition(ref->detId());
64 
65  realisticAssociator.insertHitPosition(hitPos.x(), hitPos.y(), hitPos.z(), i);
66  realisticAssociator.insertHitEnergy(ref->energy(), i);
67  realisticAssociator.insertLayerId(rhtools_.getLayerWithOffset(ref->detId()), i);
68  }
69 
70  for (unsigned int ic = 0; ic < simClusters.size(); ++ic) {
71  const auto& sc = simClusters[ic];
72  const auto& hitsAndFractions = sc.hits_and_fractions();
73  for (const auto& hAndF : hitsAndFractions) {
74  auto itr = detIdToIndex.find(hAndF.first);
75  if (itr == detIdToIndex.end()) {
76  continue; // hit wasn't saved in reco or did not pass the SNR threshold
77  }
78  auto hitId = itr->second;
79  auto ref = makeRefhit(input, hitId);
80  float fraction = hAndF.second;
81  float associatedEnergy = fraction * ref->energy();
82  realisticAssociator.insertSimClusterIdAndFraction(ic, fraction, hitId, associatedEnergy);
83  }
84  }
85  realisticAssociator.computeAssociation(
88  realisticAssociator.findCentersOfGravity();
90  realisticAssociator.filterHitsByDistance(maxDistance_);
91 
92  const auto& realisticClusters = realisticAssociator.realisticClusters();
93  unsigned int nClusters = realisticClusters.size();
94  float bin_norm = 1. / (calibMaxEta_ - calibMinEta_);
95  float egamma_bin_norm = egammaCalib_.size() * bin_norm;
96  float hadron_bin_norm = hadronCalib_.size() * bin_norm;
97  for (unsigned ic = 0; ic < nClusters; ++ic) {
98  float highest_energy = 0.0f;
99  output.emplace_back();
100  reco::PFCluster& back = output.back();
102  float energyCorrection = 1.f;
103  float timeRealisticSC = -99.;
104  if (realisticClusters[ic].isVisible()) {
105  int pdgId = simClusters[ic].pdgId();
106  auto abseta = std::abs(simClusters[ic].eta());
107  if ((abseta >= calibMinEta_) and (abseta <= calibMaxEta_)) //protecting range
108  {
109  if ((isEGamma(pdgId) or isPi0(pdgId)) and !egammaCalib_.empty()) {
110  unsigned int etabin = std::floor(((abseta - calibMinEta_) * egamma_bin_norm));
111  energyCorrection = egammaCalib_[etabin];
112  } else if (isHadron(pdgId) and !(isPi0(pdgId)) and
113  !hadronCalib_
114  .empty()) // this function is expensive.. should we treat as hadron everything which is not egamma?
115  {
116  unsigned int etabin = std::floor(((abseta - calibMinEta_) * hadron_bin_norm));
117  energyCorrection = hadronCalib_[etabin];
118  }
119  }
120  std::vector<float> timeHits;
121  const auto& hitsIdsAndFractions = realisticClusters[ic].hitsIdsAndFractions();
122  for (const auto& idAndF : hitsIdsAndFractions) {
123  auto fraction = idAndF.second;
124  if (fraction > 0.f) {
125  auto ref = makeRefhit(input, idAndF.first);
126  back.addRecHitFraction(reco::PFRecHitFraction(ref, fraction));
127  const float hit_energy = fraction * ref->energy();
128  if (hit_energy > highest_energy || highest_energy == 0.0) {
129  highest_energy = hit_energy;
130  seed = ref;
131  }
132  //select hits good for timing
133  if (ref->time() > -1.) {
134  int rhLayer = rhtools_.getLayerWithOffset(ref->detId());
135  std::array<float, 3> scPosition = realisticClusters[ic].getCenterOfGravity(rhLayer);
136  float distanceSquared =
137  std::pow((ref->position().x() - scPosition[0]), 2) + std::pow((ref->position().y() - scPosition[1]), 2);
138  if (distanceSquared < maxDforTimingSquared_) {
139  timeHits.push_back(ref->time() - timeOffset_);
140  }
141  }
142  }
143  }
144  //assign time if minimum number of hits
145  if (timeHits.size() >= minNHitsforTiming_)
146  timeRealisticSC = hgcalsimclustertime::fixSizeHighestDensity(timeHits);
147  }
148  if (!back.hitsAndFractions().empty()) {
149  back.setSeed(seed->detId());
150  back.setEnergy(realisticClusters[ic].getEnergy());
151  back.setCorrectedEnergy(energyCorrection * realisticClusters[ic].getEnergy()); //applying energy correction
152  back.setTime(timeRealisticSC);
153  } else {
154  back.setSeed(-1);
155  back.setEnergy(0.f);
156  }
157  }
158 }
float fixSizeHighestDensity(std::vector< float > &t, float deltaT=0.210, float timeWidthBy=0.5)
void insertLayerId(unsigned int layerId, unsigned int hitIndex)
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:46
double getEnergy(HBHERecHitCollection::const_iterator hit, int useRaw=0, bool debug=false)
void setTime(float time, float timeError=0)
Definition: PFCluster.h:88
Fraction of a PFRecHit (rechits can be shared between several PFCluster&#39;s)
void setEnergy(double energy)
Definition: CaloCluster.h:135
static std::string const input
Definition: EdmProvDump.cc:48
void setSeed(const DetId &id)
Definition: CaloCluster.h:145
reco::PFRecHitRef makeRefhit(const edm::Handle< reco::PFRecHitCollection > &h, const unsigned i) const
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:209
void init(std::size_t numberOfHits, std::size_t numberOfSimClusters, std::size_t numberOfLayers)
void setCorrectedEnergy(double cenergy)
Definition: CaloCluster.h:136
void insertSimClusterIdAndFraction(unsigned int scIdx, float fraction, unsigned int hitIndex, float associatedEnergy)
void computeAssociation(float exclusiveFraction, bool useMCFractionsForExclEnergy, unsigned int fhOffset, unsigned int bhOffset)
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
Definition: Activities.doc:12
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void findAndMergeInvisibleClusters(float invisibleFraction, float exclusiveFraction)
void insertHitPosition(float x, float y, float z, unsigned int hitIndex)
double f[11][100]
const std::vector< RealisticCluster > & realisticClusters() const
unsigned int lastLayerEE() const
Definition: RecHitTools.h:62
unsigned int getLayer(DetId::Detector type, bool nose=false) const
Definition: RecHitTools.cc:297
const map< TString, int > numberOfLayers(TString Year="2018")
Definition: DMRtrends.cc:254
unsigned int getLayerWithOffset(const DetId &) const
Definition: RecHitTools.cc:355
void insertHitEnergy(float energy, unsigned int hitIndex)
std::vector< double > egammaCalib_
int getGeometryType() const
Definition: RecHitTools.h:70
GlobalPoint getPosition(const DetId &id) const
Definition: RecHitTools.cc:129
void addRecHitFraction(const reco::PFRecHitFraction &frac)
add a given fraction of the rechit
Definition: PFCluster.cc:77
std::vector< double > hadronCalib_
edm::Handle< SimClusterCollection > simClusterH_
std::vector< SimCluster > SimClusterCollection
Definition: SimClusterFwd.h:8
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
std::vector< std::pair< uint32_t, float > > hits_and_fractions() const
Returns list of rechit IDs and fractions for this SimCluster.
Definition: SimCluster.h:181
unsigned int lastLayerFH() const
Definition: RecHitTools.h:63
RealisticSimClusterMapper& RealisticSimClusterMapper::operator= ( const RealisticSimClusterMapper )
delete
void RealisticSimClusterMapper::update ( const edm::EventSetup es)
finalvirtual

Reimplemented from InitialClusteringStepBase.

Definition at line 46 of file RealisticSimClusterMapper.cc.

References hgcal::RecHitTools::getEventSetup(), and rhtools_.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), Vispa.Gui.VispaWidget.VispaWidget::autosize(), Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Views.LineDecayView.LineDecayContainer::deselectAllObjects(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::deselectAllWidgets(), Vispa.Gui.VispaWidget.VispaWidget::enableAutosizing(), progressbar.ProgressBar::finish(), Vispa.Gui.MenuWidget.MenuWidget::leaveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseMoveEvent(), Vispa.Gui.MenuWidget.MenuWidget::mouseMoveEvent(), Vispa.Views.LineDecayView.LineDecayContainer::mouseMoveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseReleaseEvent(), Vispa.Views.LineDecayView.LineDecayContainer::objectMoved(), MatrixUtil.Steps::overwrite(), Vispa.Views.LineDecayView.LineDecayContainer::removeObject(), Vispa.Gui.ConnectableWidget.ConnectableWidget::removePorts(), Vispa.Gui.FindDialog.FindDialog::reset(), Vispa.Gui.PortConnection.PointToPointConnection::select(), Vispa.Gui.VispaWidget.VispaWidget::select(), Vispa.Views.LineDecayView.LineDecayContainer::select(), Vispa.Gui.VispaWidget.VispaWidget::setText(), Vispa.Gui.VispaWidget.VispaWidget::setTitle(), Vispa.Gui.ZoomableWidget.ZoomableWidget::setZoom(), Vispa.Views.LineDecayView.LineDecayContainer::setZoom(), Vispa.Gui.PortConnection.PointToPointConnection::updateConnection(), and ~RealisticSimClusterMapper().

46 { rhtools_.getEventSetup(es); }
void getEventSetup(const edm::EventSetup &)
Definition: RecHitTools.cc:70
void RealisticSimClusterMapper::updateEvent ( const edm::Event ev)
finalvirtual

Reimplemented from InitialClusteringStepBase.

Definition at line 44 of file RealisticSimClusterMapper.cc.

References edm::Event::getByToken(), simClusterH_, and simClusterToken_.

Referenced by ~RealisticSimClusterMapper().

bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
edm::EDGetTokenT< SimClusterCollection > simClusterToken_
edm::Handle< SimClusterCollection > simClusterH_

Member Data Documentation

const float RealisticSimClusterMapper::calibMaxEta_ = 3.0
private

Definition at line 56 of file RealisticSimClusterMapper.h.

Referenced by buildClusters().

const float RealisticSimClusterMapper::calibMinEta_ = 1.4
private

Definition at line 55 of file RealisticSimClusterMapper.h.

Referenced by buildClusters().

std::vector<double> RealisticSimClusterMapper::egammaCalib_
private

Definition at line 58 of file RealisticSimClusterMapper.h.

Referenced by buildClusters(), and RealisticSimClusterMapper().

const float RealisticSimClusterMapper::exclusiveFraction_ = 0.7f
private

Definition at line 48 of file RealisticSimClusterMapper.h.

Referenced by buildClusters().

std::vector<double> RealisticSimClusterMapper::hadronCalib_
private

Definition at line 57 of file RealisticSimClusterMapper.h.

Referenced by buildClusters(), and RealisticSimClusterMapper().

const float RealisticSimClusterMapper::invisibleFraction_ = 0.3f
private

Definition at line 47 of file RealisticSimClusterMapper.h.

Referenced by buildClusters().

const float RealisticSimClusterMapper::maxDforTimingSquared_ = 4.0f
private

Definition at line 51 of file RealisticSimClusterMapper.h.

Referenced by buildClusters().

const float RealisticSimClusterMapper::maxDistance_ = 10.f
private

Definition at line 50 of file RealisticSimClusterMapper.h.

Referenced by buildClusters().

const bool RealisticSimClusterMapper::maxDistanceFilter_ = false
private

Definition at line 49 of file RealisticSimClusterMapper.h.

Referenced by buildClusters().

const unsigned int RealisticSimClusterMapper::minNHitsforTiming_ = 3
private

Definition at line 53 of file RealisticSimClusterMapper.h.

Referenced by buildClusters().

hgcal::RecHitTools RealisticSimClusterMapper::rhtools_
private

Definition at line 46 of file RealisticSimClusterMapper.h.

Referenced by buildClusters(), and update().

edm::Handle<SimClusterCollection> RealisticSimClusterMapper::simClusterH_
private

Definition at line 61 of file RealisticSimClusterMapper.h.

Referenced by buildClusters(), and updateEvent().

edm::EDGetTokenT<SimClusterCollection> RealisticSimClusterMapper::simClusterToken_
private

Definition at line 60 of file RealisticSimClusterMapper.h.

Referenced by RealisticSimClusterMapper(), and updateEvent().

const float RealisticSimClusterMapper::timeOffset_
private

Definition at line 52 of file RealisticSimClusterMapper.h.

Referenced by buildClusters().

const bool RealisticSimClusterMapper::useMCFractionsForExclEnergy_ = false
private

Definition at line 54 of file RealisticSimClusterMapper.h.

Referenced by buildClusters().