CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
RealisticSimClusterMapper Class Reference
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 &cc)
 
 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 &cc)
 
 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
 
edm::ESGetToken< CaloGeometry, CaloGeometryRecordgeomToken_
 
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 22 of file RealisticSimClusterMapper.cc.

Constructor & Destructor Documentation

◆ RealisticSimClusterMapper() [1/2]

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

Definition at line 24 of file RealisticSimClusterMapper.cc.

25  : InitialClusteringStepBase(conf, cc),
26  invisibleFraction_(conf.getParameter<double>("invisibleFraction")),
27  exclusiveFraction_(conf.getParameter<double>("exclusiveFraction")),
28  maxDistanceFilter_(conf.getParameter<bool>("maxDistanceFilter")),
29  maxDistance_(conf.getParameter<double>("maxDistance")),
30  maxDforTimingSquared_(conf.getParameter<double>("maxDforTimingSquared")),
31  timeOffset_(conf.getParameter<double>("timeOffset")),
32  minNHitsforTiming_(conf.getParameter<unsigned int>("minNHitsforTiming")),
33  useMCFractionsForExclEnergy_(conf.getParameter<bool>("useMCFractionsForExclEnergy")),
34  calibMinEta_(conf.getParameter<double>("calibMinEta")),
35  calibMaxEta_(conf.getParameter<double>("calibMaxEta")),
36  hadronCalib_(conf.getParameter<std::vector<double> >("hadronCalib")),
37  egammaCalib_(conf.getParameter<std::vector<double> >("egammaCalib")),
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
InitialClusteringStepBase(const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
edm::EDGetTokenT< SimClusterCollection > simClusterToken_
std::vector< SimCluster > SimClusterCollection
Definition: SimClusterFwd.h:8
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geomToken_

◆ ~RealisticSimClusterMapper()

RealisticSimClusterMapper::~RealisticSimClusterMapper ( )
inlineoverride

Definition at line 41 of file RealisticSimClusterMapper.cc.

41 {}

◆ RealisticSimClusterMapper() [2/2]

RealisticSimClusterMapper::RealisticSimClusterMapper ( const RealisticSimClusterMapper )
delete

Member Function Documentation

◆ buildClusters()

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 107 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(), first, hgcalsimclustertime::ComputeClusterTime::fixSizeHighestDensity(), DetId::Forward, ForwardEmpty, HLT_2022v11_cff::fraction, spr::getEnergy(), hgcal::RecHitTools::getGeometryType(), hgcal::RecHitTools::getLayer(), hgcal::RecHitTools::getLayerWithOffset(), hgcal::RecHitTools::getPosition(), hadronCalib_, hfClusterShapes_cfi::hits, 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_, heavyionUCCDQM_cfi::nClusters, numberOfLayers(), or, convertSQLitetoXML_cfg::output, EgammaValidation_cff::pdgId, funct::pow(), RealisticHitToClusterAssociator::realisticClusters(), rhtools_, fileCollector::seed, reco::CaloCluster::setCorrectedEnergy(), reco::CaloCluster::setEnergy(), reco::CaloCluster::setSeed(), reco::PFCluster::setTime(), simClusterH_, timeOffset_, and useMCFractionsForExclEnergy_.

110  {
111  const SimClusterCollection& simClusters = *simClusterH_;
112  auto const& hits = *input;
113  RealisticHitToClusterAssociator realisticAssociator;
116  realisticAssociator.init(hits.size(), simClusters.size(), numberOfLayers + 1);
117  // for quick indexing back to hit energy
118  std::unordered_map<uint32_t, size_t> detIdToIndex(hits.size());
119  for (uint32_t i = 0; i < hits.size(); ++i) {
120  detIdToIndex[hits[i].detId()] = i;
121  auto ref = makeRefhit(input, i);
122  const auto& hitPos = rhtools_.getPosition(ref->detId());
123 
124  realisticAssociator.insertHitPosition(hitPos.x(), hitPos.y(), hitPos.z(), i);
125  realisticAssociator.insertHitEnergy(ref->energy(), i);
126  realisticAssociator.insertLayerId(rhtools_.getLayerWithOffset(ref->detId()), i);
127  }
128 
129  for (unsigned int ic = 0; ic < simClusters.size(); ++ic) {
130  const auto& sc = simClusters[ic];
131  const auto& hitsAndFractions = sc.hits_and_fractions();
132  for (const auto& hAndF : hitsAndFractions) {
133  auto itr = detIdToIndex.find(hAndF.first);
134  if (itr == detIdToIndex.end()) {
135  continue; // hit wasn't saved in reco or did not pass the SNR threshold
136  }
137  auto hitId = itr->second;
138  auto ref = makeRefhit(input, hitId);
139  float fraction = hAndF.second;
140  float associatedEnergy = fraction * ref->energy();
141  realisticAssociator.insertSimClusterIdAndFraction(ic, fraction, hitId, associatedEnergy);
142  }
143  }
144  realisticAssociator.computeAssociation(
147  realisticAssociator.findCentersOfGravity();
148  if (maxDistanceFilter_)
149  realisticAssociator.filterHitsByDistance(maxDistance_);
150 
151  const auto& realisticClusters = realisticAssociator.realisticClusters();
152  unsigned int nClusters = realisticClusters.size();
153  float bin_norm = 1. / (calibMaxEta_ - calibMinEta_);
154  float egamma_bin_norm = egammaCalib_.size() * bin_norm;
155  float hadron_bin_norm = hadronCalib_.size() * bin_norm;
156  for (unsigned ic = 0; ic < nClusters; ++ic) {
157  float highest_energy = 0.0f;
158  output.emplace_back();
159  reco::PFCluster& back = output.back();
161  float energyCorrection = 1.f;
162  float timeRealisticSC = -99.;
163  if (realisticClusters[ic].isVisible()) {
164  int pdgId = simClusters[ic].pdgId();
165  auto abseta = std::abs(simClusters[ic].eta());
166  if ((abseta >= calibMinEta_) and (abseta <= calibMaxEta_)) //protecting range
167  {
168  if ((isEGamma(pdgId) or isPi0(pdgId)) and !egammaCalib_.empty()) {
169  unsigned int etabin = std::floor(((abseta - calibMinEta_) * egamma_bin_norm));
170  energyCorrection = egammaCalib_[etabin];
171  } else if (isHadron(pdgId) and !(isPi0(pdgId)) and
172  !hadronCalib_
173  .empty()) // this function is expensive.. should we treat as hadron everything which is not egamma?
174  {
175  unsigned int etabin = std::floor(((abseta - calibMinEta_) * hadron_bin_norm));
176  energyCorrection = hadronCalib_[etabin];
177  }
178  }
179  std::vector<float> timeHits;
180  const auto& hitsIdsAndFractions = realisticClusters[ic].hitsIdsAndFractions();
181  for (const auto& idAndF : hitsIdsAndFractions) {
182  auto fraction = idAndF.second;
183  if (fraction > 0.f) {
184  auto ref = makeRefhit(input, idAndF.first);
186  const float hit_energy = fraction * ref->energy();
187  if (hit_energy > highest_energy || highest_energy == 0.0) {
188  highest_energy = hit_energy;
189  seed = ref;
190  }
191  //select hits good for timing
192  if (ref->time() > -1.) {
193  int rhLayer = rhtools_.getLayerWithOffset(ref->detId());
194  std::array<float, 3> scPosition = realisticClusters[ic].getCenterOfGravity(rhLayer);
195  float distanceSquared =
196  std::pow((ref->position().x() - scPosition[0]), 2) + std::pow((ref->position().y() - scPosition[1]), 2);
197  if (distanceSquared < maxDforTimingSquared_) {
198  timeHits.push_back(ref->time() - timeOffset_);
199  }
200  }
201  }
202  }
203  //assign time if minimum number of hits
205  timeRealisticSC = (timeEstimator.fixSizeHighestDensity(timeHits)).first;
206  }
207  if (!back.hitsAndFractions().empty()) {
208  back.setSeed(seed->detId());
209  back.setEnergy(realisticClusters[ic].getEnergy());
210  back.setCorrectedEnergy(energyCorrection * realisticClusters[ic].getEnergy()); //applying energy correction
211  back.setTime(timeRealisticSC);
212  } else {
213  back.setSeed(-1);
214  back.setEnergy(0.f);
215  }
216  }
217 }
void insertLayerId(unsigned int layerId, unsigned int hitIndex)
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:210
reco::PFRecHitRef makeRefhit(const edm::Handle< reco::PFRecHitCollection > &h, const unsigned i) const
unsigned int getLayer(DetId::Detector type, bool nose=false) const
Definition: RecHitTools.cc:307
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:42
double getEnergy(HBHERecHitCollection::const_iterator hit, int useRaw=0, bool debug=false)
void setTime(float time, float timeError=0)
Definition: PFCluster.h:84
Fraction of a PFRecHit (rechits can be shared between several PFCluster&#39;s)
void setEnergy(double energy)
Definition: CaloCluster.h:136
int getGeometryType() const
Definition: RecHitTools.h:85
static std::string const input
Definition: EdmProvDump.cc:47
void setSeed(const DetId &id)
Definition: CaloCluster.h:146
std::pair< float, float > fixSizeHighestDensity(std::vector< float > &time, std::vector< float > weight=std::vector< float >(), unsigned int minNhits=3, float deltaT=0.210, float timeWidthBy=0.5)
void init(std::size_t numberOfHits, std::size_t numberOfSimClusters, std::size_t numberOfLayers)
unsigned int lastLayerFH() const
Definition: RecHitTools.h:76
GlobalPoint getPosition(const DetId &id) const
Definition: RecHitTools.cc:129
const std::vector< RealisticCluster > & realisticClusters() const
void setCorrectedEnergy(double cenergy)
Definition: CaloCluster.h:137
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 map< TString, int > numberOfLayers(TString Year="2018")
Definition: DMRtrends.cc:254
void insertHitEnergy(float energy, unsigned int hitIndex)
void addRecHitFraction(const reco::PFRecHitFraction &frac)
add a given fraction of the rechit
Definition: PFCluster.cc:33
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:29
unsigned int lastLayerEE(bool nose=false) const
Definition: RecHitTools.h:75
unsigned int getLayerWithOffset(const DetId &) const
Definition: RecHitTools.cc:365

◆ operator=()

RealisticSimClusterMapper& RealisticSimClusterMapper::operator= ( const RealisticSimClusterMapper )
delete

◆ update()

void RealisticSimClusterMapper::update ( const edm::EventSetup es)
finalvirtual

◆ updateEvent()

void RealisticSimClusterMapper::updateEvent ( const edm::Event ev)
finalvirtual

Reimplemented from InitialClusteringStepBase.

Definition at line 103 of file RealisticSimClusterMapper.cc.

References makeMEIFBenchmarkPlots::ev, simClusterH_, and simClusterToken_.

103 { ev.getByToken(simClusterToken_, simClusterH_); }
edm::EDGetTokenT< SimClusterCollection > simClusterToken_
edm::Handle< SimClusterCollection > simClusterH_

Member Data Documentation

◆ calibMaxEta_

const float RealisticSimClusterMapper::calibMaxEta_ = 3.0
private

Definition at line 64 of file RealisticSimClusterMapper.cc.

Referenced by buildClusters().

◆ calibMinEta_

const float RealisticSimClusterMapper::calibMinEta_ = 1.4
private

Definition at line 63 of file RealisticSimClusterMapper.cc.

Referenced by buildClusters().

◆ egammaCalib_

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

Definition at line 66 of file RealisticSimClusterMapper.cc.

Referenced by buildClusters().

◆ exclusiveFraction_

const float RealisticSimClusterMapper::exclusiveFraction_ = 0.7f
private

Definition at line 56 of file RealisticSimClusterMapper.cc.

Referenced by buildClusters().

◆ geomToken_

edm::ESGetToken<CaloGeometry, CaloGeometryRecord> RealisticSimClusterMapper::geomToken_
private

Definition at line 71 of file RealisticSimClusterMapper.cc.

Referenced by update().

◆ hadronCalib_

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

Definition at line 65 of file RealisticSimClusterMapper.cc.

Referenced by buildClusters().

◆ invisibleFraction_

const float RealisticSimClusterMapper::invisibleFraction_ = 0.3f
private

Definition at line 55 of file RealisticSimClusterMapper.cc.

Referenced by buildClusters().

◆ maxDforTimingSquared_

const float RealisticSimClusterMapper::maxDforTimingSquared_ = 4.0f
private

Definition at line 59 of file RealisticSimClusterMapper.cc.

Referenced by buildClusters().

◆ maxDistance_

const float RealisticSimClusterMapper::maxDistance_ = 10.f
private

Definition at line 58 of file RealisticSimClusterMapper.cc.

Referenced by buildClusters().

◆ maxDistanceFilter_

const bool RealisticSimClusterMapper::maxDistanceFilter_ = false
private

Definition at line 57 of file RealisticSimClusterMapper.cc.

Referenced by buildClusters().

◆ minNHitsforTiming_

const unsigned int RealisticSimClusterMapper::minNHitsforTiming_ = 3
private

Definition at line 61 of file RealisticSimClusterMapper.cc.

◆ rhtools_

hgcal::RecHitTools RealisticSimClusterMapper::rhtools_
private

Definition at line 54 of file RealisticSimClusterMapper.cc.

Referenced by buildClusters(), and update().

◆ simClusterH_

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

Definition at line 69 of file RealisticSimClusterMapper.cc.

Referenced by buildClusters(), and updateEvent().

◆ simClusterToken_

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

Definition at line 68 of file RealisticSimClusterMapper.cc.

Referenced by updateEvent().

◆ timeOffset_

const float RealisticSimClusterMapper::timeOffset_
private

Definition at line 60 of file RealisticSimClusterMapper.cc.

Referenced by buildClusters().

◆ useMCFractionsForExclEnergy_

const bool RealisticSimClusterMapper::useMCFractionsForExclEnergy_ = false
private

Definition at line 62 of file RealisticSimClusterMapper.cc.

Referenced by buildClusters().