CMS 3D CMS Logo

RealisticSimClusterMapper.cc
Go to the documentation of this file.
1 // Author: Felice Pantaleo
3 // Date: 30/06/2017
4 // Email: felice@cern.ch
6 #include <unordered_map>
9 
16 
17 #ifdef PFLOW_DEBUG
18 #define LOGVERB(x) edm::LogVerbatim(x)
19 #define LOGWARN(x) edm::LogWarning(x)
20 #define LOGERR(x) edm::LogError(x)
21 #define LOGDRESSED(x) edm::LogInfo(x)
22 #else
23 #define LOGVERB(x) LogTrace(x)
24 #define LOGWARN(x) edm::LogWarning(x)
25 #define LOGERR(x) edm::LogError(x)
26 #define LOGDRESSED(x) LogDebug(x)
27 #endif
28 
29 namespace {
30 
31  inline bool isPi0(int pdgId) { return pdgId == 111; }
32 
33  inline bool isEGamma(int pdgId) {
34  pdgId = std::abs(pdgId);
35  return (pdgId == 11) or (pdgId == 22);
36  }
37 
38  inline bool isHadron(int pdgId) {
39  pdgId = std::abs(pdgId) % 10000;
40  return ((pdgId > 100 and pdgId < 900) or (pdgId > 1000 and pdgId < 9000));
41  }
42 } // namespace
43 
45 
50 }
51 
53  const std::vector<bool>& rechitMask,
54  const std::vector<bool>& seedable,
56  const SimClusterCollection& simClusters = *simClusterH_;
57  auto const& hits = *input;
58  RealisticHitToClusterAssociator realisticAssociator;
61  realisticAssociator.init(hits.size(), simClusters.size(), numberOfLayers + 1);
62  // for quick indexing back to hit energy
63  std::unordered_map<uint32_t, size_t> detIdToIndex(hits.size());
64  for (uint32_t i = 0; i < hits.size(); ++i) {
65  detIdToIndex[hits[i].detId()] = i;
66  auto ref = makeRefhit(input, i);
67  const auto& hitPos = rhtools_.getPosition(ref->detId());
68 
69  realisticAssociator.insertHitPosition(hitPos.x(), hitPos.y(), hitPos.z(), i);
70  realisticAssociator.insertHitEnergy(ref->energy(), i);
71  realisticAssociator.insertLayerId(rhtools_.getLayerWithOffset(ref->detId()), i);
72  }
73 
74  for (unsigned int ic = 0; ic < simClusters.size(); ++ic) {
75  const auto& sc = simClusters[ic];
76  const auto& hitsAndFractions = sc.hits_and_fractions();
77  for (const auto& hAndF : hitsAndFractions) {
78  auto itr = detIdToIndex.find(hAndF.first);
79  if (itr == detIdToIndex.end()) {
80  continue; // hit wasn't saved in reco or did not pass the SNR threshold
81  }
82  auto hitId = itr->second;
83  auto ref = makeRefhit(input, hitId);
84  float fraction = hAndF.second;
85  float associatedEnergy = fraction * ref->energy();
86  realisticAssociator.insertSimClusterIdAndFraction(ic, fraction, hitId, associatedEnergy);
87  }
88  }
89  realisticAssociator.computeAssociation(
92  realisticAssociator.findCentersOfGravity();
94  realisticAssociator.filterHitsByDistance(maxDistance_);
95 
96  const auto& realisticClusters = realisticAssociator.realisticClusters();
97  unsigned int nClusters = realisticClusters.size();
98  float bin_norm = 1. / (calibMaxEta_ - calibMinEta_);
99  float egamma_bin_norm = egammaCalib_.size() * bin_norm;
100  float hadron_bin_norm = hadronCalib_.size() * bin_norm;
101  for (unsigned ic = 0; ic < nClusters; ++ic) {
102  float highest_energy = 0.0f;
103  output.emplace_back();
104  reco::PFCluster& back = output.back();
106  float energyCorrection = 1.f;
107  float timeRealisticSC = -99.;
108  if (realisticClusters[ic].isVisible()) {
109  int pdgId = simClusters[ic].pdgId();
110  auto abseta = std::abs(simClusters[ic].eta());
111  if ((abseta >= calibMinEta_) and (abseta <= calibMaxEta_)) //protecting range
112  {
113  if ((isEGamma(pdgId) or isPi0(pdgId)) and !egammaCalib_.empty()) {
114  unsigned int etabin = std::floor(((abseta - calibMinEta_) * egamma_bin_norm));
115  energyCorrection = egammaCalib_[etabin];
116  } else if (isHadron(pdgId) and !(isPi0(pdgId)) and
117  !hadronCalib_
118  .empty()) // this function is expensive.. should we treat as hadron everything which is not egamma?
119  {
120  unsigned int etabin = std::floor(((abseta - calibMinEta_) * hadron_bin_norm));
121  energyCorrection = hadronCalib_[etabin];
122  }
123  }
124  std::vector<float> timeHits;
125  const auto& hitsIdsAndFractions = realisticClusters[ic].hitsIdsAndFractions();
126  for (const auto& idAndF : hitsIdsAndFractions) {
127  auto fraction = idAndF.second;
128  if (fraction > 0.f) {
129  auto ref = makeRefhit(input, idAndF.first);
131  const float hit_energy = fraction * ref->energy();
132  if (hit_energy > highest_energy || highest_energy == 0.0) {
133  highest_energy = hit_energy;
134  seed = ref;
135  }
136  //select hits good for timing
137  if (ref->time() > -1.) {
138  int rhLayer = rhtools_.getLayerWithOffset(ref->detId());
139  std::array<float, 3> scPosition = realisticClusters[ic].getCenterOfGravity(rhLayer);
140  float distanceSquared =
141  std::pow((ref->position().x() - scPosition[0]), 2) + std::pow((ref->position().y() - scPosition[1]), 2);
142  if (distanceSquared < maxDforTimingSquared_) {
143  timeHits.push_back(ref->time() - timeOffset_);
144  }
145  }
146  }
147  }
148  //assign time if minimum number of hits
150  timeRealisticSC = (timeEstimator.fixSizeHighestDensity(timeHits)).first;
151  }
152  if (!back.hitsAndFractions().empty()) {
153  back.setSeed(seed->detId());
154  back.setEnergy(realisticClusters[ic].getEnergy());
155  back.setCorrectedEnergy(energyCorrection * realisticClusters[ic].getEnergy()); //applying energy correction
156  back.setTime(timeRealisticSC);
157  } else {
158  back.setSeed(-1);
159  back.setEnergy(0.f);
160  }
161  }
162 }
reco::PFClusterCollection
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
Definition: PFClusterFwd.h:9
RealisticSimClusterMapper::simClusterH_
edm::Handle< SimClusterCollection > simClusterH_
Definition: RealisticSimClusterMapper.h:61
RealisticSimClusterMapper::maxDistanceFilter_
const bool maxDistanceFilter_
Definition: RealisticSimClusterMapper.h:49
heavyionUCCDQM_cfi.nClusters
nClusters
Definition: heavyionUCCDQM_cfi.py:9
RealisticSimClusterMapper::maxDistance_
const float maxDistance_
Definition: RealisticSimClusterMapper.h:50
reco::CaloCluster::setSeed
void setSeed(const DetId &id)
Definition: CaloCluster.h:146
SimClusterCollection
std::vector< SimCluster > SimClusterCollection
Definition: SimClusterFwd.h:8
mps_fire.i
i
Definition: mps_fire.py:428
reco::PFCluster::setTime
void setTime(float time, float timeError=0)
Definition: PFCluster.h:84
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
RealisticHitToClusterAssociator::findCentersOfGravity
void findCentersOfGravity()
Definition: RealisticHitToClusterAssociator.h:231
RealisticSimClusterMapper::hadronCalib_
std::vector< double > hadronCalib_
Definition: RealisticSimClusterMapper.h:57
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
ForwardEmpty
Definition: ForwardSubdetector.h:5
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
reco::PFRecHitFraction
Fraction of a PFRecHit (rechits can be shared between several PFCluster's)
Definition: PFRecHitFraction.h:18
RealisticSimClusterMapper::update
void update(const edm::EventSetup &) final
Definition: RealisticSimClusterMapper.cc:46
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
CaloGeometryRecord
Definition: CaloGeometryRecord.h:30
RealisticHitToClusterAssociator
Definition: RealisticHitToClusterAssociator.h:29
reco::CaloCluster::setCorrectedEnergy
void setCorrectedEnergy(double cenergy)
Definition: CaloCluster.h:137
RealisticSimClusterMapper::egammaCalib_
std::vector< double > egammaCalib_
Definition: RealisticSimClusterMapper.h:58
RealisticSimClusterMapper::simClusterToken_
edm::EDGetTokenT< SimClusterCollection > simClusterToken_
Definition: RealisticSimClusterMapper.h:60
RealisticSimClusterMapper::buildClusters
void buildClusters(const edm::Handle< reco::PFRecHitCollection > &, const std::vector< bool > &, const std::vector< bool > &, reco::PFClusterCollection &) override
Definition: RealisticSimClusterMapper.cc:52
edm::Handle< reco::PFRecHitCollection >
hgcal::RecHitTools::getGeometryType
int getGeometryType() const
Definition: RecHitTools.h:73
edm::Ref
Definition: AssociativeIterator.h:58
InitialClusteringStepBase::makeRefhit
reco::PFRecHitRef makeRefhit(const edm::Handle< reco::PFRecHitCollection > &h, const unsigned i) const
Definition: InitialClusteringStepBase.h:103
fileCollector.seed
seed
Definition: fileCollector.py:127
hgcalsimclustertime::ComputeClusterTime::fixSizeHighestDensity
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)
Definition: ComputeClusterTime.cc:66
hgcal::RecHitTools::lastLayerFH
unsigned int lastLayerFH() const
Definition: RecHitTools.h:65
SimCluster.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
RealisticSimClusterMapper::calibMinEta_
const float calibMinEta_
Definition: RealisticSimClusterMapper.h:55
RealisticHitToClusterAssociator::insertLayerId
void insertLayerId(unsigned int layerId, unsigned int hitIndex)
Definition: RealisticHitToClusterAssociator.h:58
HLT_FULL_cff.fraction
fraction
Definition: HLT_FULL_cff.py:52806
PVValHelper::eta
Definition: PVValidationHelpers.h:70
edm::ESHandle< CaloGeometry >
RealisticHitToClusterAssociator.h
relativeConstraints.geom
geom
Definition: relativeConstraints.py:72
RealisticHitToClusterAssociator::insertHitPosition
void insertHitPosition(float x, float y, float z, unsigned int hitIndex)
Definition: RealisticHitToClusterAssociator.h:54
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:112
spr::getEnergy
double getEnergy(HBHERecHitCollection::const_iterator hit, int useRaw=0, bool debug=false)
Definition: FindDistCone.cc:181
RealisticHitToClusterAssociator::realisticClusters
const std::vector< RealisticCluster > & realisticClusters() const
Definition: RealisticHitToClusterAssociator.h:283
ComputeClusterTime.h
RealisticCluster.h
Event.h
reco::CaloCluster::hitsAndFractions
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:210
hgcal::RecHitTools::getLayerWithOffset
unsigned int getLayerWithOffset(const DetId &) const
Definition: RecHitTools.cc:352
hgcal::RecHitTools::lastLayerEE
unsigned int lastLayerEE(bool nose=false) const
Definition: RecHitTools.h:64
RealisticSimClusterMapper::updateEvent
void updateEvent(const edm::Event &) final
Definition: RealisticSimClusterMapper.cc:44
RealisticHitToClusterAssociator::computeAssociation
void computeAssociation(float exclusiveFraction, bool useMCFractionsForExclEnergy, unsigned int fhOffset, unsigned int bhOffset)
Definition: RealisticHitToClusterAssociator.h:82
EgammaValidation_cff.pdgId
pdgId
Definition: EgammaValidation_cff.py:118
edm::EventSetup
Definition: EventSetup.h:58
RealisticHitToClusterAssociator::init
void init(std::size_t numberOfHits, std::size_t numberOfSimClusters, std::size_t numberOfLayers)
Definition: RealisticHitToClusterAssociator.h:47
get
#define get
RealisticSimClusterMapper::useMCFractionsForExclEnergy_
const bool useMCFractionsForExclEnergy_
Definition: RealisticSimClusterMapper.h:54
hgcal::RecHitTools::getLayer
unsigned int getLayer(DetId::Detector type, bool nose=false) const
Definition: RecHitTools.cc:294
RealisticSimClusterMapper::maxDforTimingSquared_
const float maxDforTimingSquared_
Definition: RealisticSimClusterMapper.h:51
RealisticSimClusterMapper::calibMaxEta_
const float calibMaxEta_
Definition: RealisticSimClusterMapper.h:56
reco::PFCluster::addRecHitFraction
void addRecHitFraction(const reco::PFRecHitFraction &frac)
add a given fraction of the rechit
Definition: PFCluster.cc:33
RealisticSimClusterMapper::timeOffset_
const float timeOffset_
Definition: RealisticSimClusterMapper.h:52
reco::CaloCluster::setEnergy
void setEnergy(double energy)
Definition: CaloCluster.h:136
HGCalDetId.h
hgcal::RecHitTools::setGeometry
void setGeometry(CaloGeometry const &)
Definition: RecHitTools.cc:68
RealisticSimClusterMapper.h
RealisticSimClusterMapper::exclusiveFraction_
const float exclusiveFraction_
Definition: RealisticSimClusterMapper.h:48
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
RealisticHitToClusterAssociator::insertSimClusterIdAndFraction
void insertSimClusterIdAndFraction(unsigned int scIdx, float fraction, unsigned int hitIndex, float associatedEnergy)
Definition: RealisticHitToClusterAssociator.h:62
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
reco::PFCluster
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:42
hgcalsimclustertime::ComputeClusterTime
Definition: ComputeClusterTime.h:23
or
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
RealisticHitToClusterAssociator::insertHitEnergy
void insertHitEnergy(float energy, unsigned int hitIndex)
Definition: RealisticHitToClusterAssociator.h:60
RealisticHitToClusterAssociator::findAndMergeInvisibleClusters
void findAndMergeInvisibleClusters(float invisibleFraction, float exclusiveFraction)
Definition: RealisticHitToClusterAssociator.h:158
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
RealisticSimClusterMapper::rhtools_
hgcal::RecHitTools rhtools_
Definition: RealisticSimClusterMapper.h:46
numberOfLayers
const map< TString, int > numberOfLayers(TString Year="2018")
Definition: DMRtrends.cc:253
DetId::Forward
Definition: DetId.h:30
RealisticHitToClusterAssociator::filterHitsByDistance
void filterHitsByDistance(float maxDistance)
Definition: RealisticHitToClusterAssociator.h:266
edm::Event
Definition: Event.h:73
hgcal::RecHitTools::getPosition
GlobalPoint getPosition(const DetId &id) const
Definition: RecHitTools.cc:126
RealisticSimClusterMapper::invisibleFraction_
const float invisibleFraction_
Definition: RealisticSimClusterMapper.h:47