CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RegionMapper.cc
Go to the documentation of this file.
2 
3 using namespace l1tpf_impl;
4 
5 RegionMapper::RegionMapper(const edm::ParameterSet &iConfig) : useRelativeRegionalCoordinates_(false) {
6  if (iConfig.existsAs<std::vector<edm::ParameterSet>>("regions")) {
7  useRelativeRegionalCoordinates_ = iConfig.getParameter<bool>("useRelativeRegionalCoordinates");
8  for (const edm::ParameterSet &preg : iConfig.getParameter<std::vector<edm::ParameterSet>>("regions")) {
9  std::vector<double> etaBoundaries = preg.getParameter<std::vector<double>>("etaBoundaries");
10  unsigned int phiSlices = preg.getParameter<uint32_t>("phiSlices");
11  float etaExtra = preg.getParameter<double>("etaExtra");
12  float phiExtra = preg.getParameter<double>("phiExtra");
13  float phiWidth = 2 * M_PI / phiSlices;
14  unsigned int ncalomax = 0, nemcalomax = 0, ntrackmax = 0, nmuonmax = 0, npfmax = 0, npuppimax = 0;
15  if (preg.existsAs<uint32_t>("caloNMax"))
16  ncalomax = preg.getParameter<uint32_t>("caloNMax");
17  if (preg.existsAs<uint32_t>("emcaloNMax"))
18  nemcalomax = preg.getParameter<uint32_t>("emcaloNMax");
19  if (preg.existsAs<uint32_t>("trackNMax"))
20  ntrackmax = preg.getParameter<uint32_t>("trackNMax");
21  if (preg.existsAs<uint32_t>("muonNMax"))
22  nmuonmax = preg.getParameter<uint32_t>("muonNMax");
23  if (preg.existsAs<uint32_t>("pfNMax"))
24  npfmax = preg.getParameter<uint32_t>("pfNMax");
25  if (preg.existsAs<uint32_t>("puppiNMax"))
26  npuppimax = preg.getParameter<uint32_t>("puppiNMax");
27  for (unsigned int ieta = 0, neta = etaBoundaries.size() - 1; ieta < neta; ++ieta) {
28  for (unsigned int iphi = 0; iphi < phiSlices; ++iphi) {
29  float phiCenter = (iphi + 0.5) * phiWidth - M_PI;
30  regions_.push_back(Region(etaBoundaries[ieta],
31  etaBoundaries[ieta + 1],
32  phiCenter,
33  phiWidth,
34  etaExtra,
35  phiExtra,
37  ncalomax,
38  nemcalomax,
39  ntrackmax,
40  nmuonmax,
41  npfmax,
42  npuppimax));
43  }
44  }
45  }
46  std::string trackRegionMode = "TrackAssoMode::any";
47  if (iConfig.existsAs<std::string>("trackRegionMode"))
48  trackRegionMode = iConfig.getParameter<std::string>("trackRegionMode");
49  if (trackRegionMode == "atVertex")
51  else if (trackRegionMode == "atCalo")
53  else if (trackRegionMode == "any")
55  else
56  throw cms::Exception(
57  "Configuration",
58  "Unsupported value for trackRegionMode: " + trackRegionMode + " (allowed are 'atVertex', 'atCalo', 'any')");
59  } else {
60  // start off with a dummy region
61  unsigned int ncalomax = 0, nemcalomax = 0, ntrackmax = 0, nmuonmax = 0, npfmax = 0, npuppimax = 0;
62  regions_.emplace_back(-5.5,
63  5.5,
64  0,
65  2 * M_PI,
66  0.5,
67  0.5,
69  ncalomax,
70  nemcalomax,
71  ntrackmax,
72  nmuonmax,
73  npfmax,
74  npuppimax);
75  }
76 }
77 
79  for (Region &r : regions_)
80  r.zero();
81  clusterRefMap_.clear();
82  trackRefMap_.clear();
83  muonRefMap_.clear();
84 }
85 
87  // now let's be optimistic and make things very simple
88  // we propagate in floating point the track to the calo
89  // we add the track to the region corresponding to its vertex (eta,phi) coordinates AND its (eta,phi) calo coordinates
90  for (Region &r : regions_) {
91  bool inside = true;
92  switch (trackRegionMode_) {
94  inside = r.contains(t.eta(), t.phi());
95  break;
97  inside = r.contains(t.caloEta(), t.caloPhi());
98  break;
99  case TrackAssoMode::any:
100  inside = r.contains(t.eta(), t.phi()) || r.contains(t.caloEta(), t.caloPhi());
101  break;
102  }
103  if (inside) {
104  PropagatedTrack prop;
105  prop.fillInput(t.pt(), r.localEta(t.eta()), r.localPhi(t.phi()), t.charge(), t.vertex().Z(), t.quality(), &t);
106  prop.fillPropagated(t.pt(),
107  t.trkPtError(),
108  t.caloPtError(),
109  r.localEta(t.caloEta()),
110  r.localPhi(t.caloPhi()),
111  t.quality(),
112  t.isMuon());
113  prop.hwStubs = t.nStubs();
114  prop.hwChi2 = round(t.chi2() * 10);
115  r.track.push_back(prop);
116  }
117  }
118 }
120  addTrack(t);
121  trackRefMap_[&t] = ref;
122 }
123 
125  // now let's be optimistic and make things very simple
126  // we don't propagate anything
127  for (Region &r : regions_) {
128  if (r.contains(mu.eta(), mu.phi())) {
129  Muon prop;
130  prop.fill(mu.pt(), r.localEta(mu.eta()), r.localPhi(mu.phi()), mu.charge(), mu.hwQual(), &mu);
131  r.muon.push_back(prop);
132  }
133  }
134 }
135 
137  // now let's be optimistic and make things very simple
138  // we don't propagate anything
139  for (Region &r : regions_) {
140  if (r.contains(mu.eta(), mu.phi())) {
141  Muon prop;
142  prop.fill(mu.pt(), r.localEta(mu.eta()), r.localPhi(mu.phi()), mu.charge(), mu.hwQual());
143  r.muon.push_back(prop);
144  }
145  }
146 }
147 
149  addMuon(mu);
150  muonRefMap_[&mu] = ref;
151 }
152 
154  if (p.pt() == 0)
155  return;
156  for (Region &r : regions_) {
157  if (r.contains(p.eta(), p.phi())) {
158  CaloCluster calo;
159  calo.fill(p.pt(), p.emEt(), p.ptError(), r.localEta(p.eta()), r.localPhi(p.phi()), p.isEM(), 0, &p);
160  r.calo.push_back(calo);
161  }
162  }
163 }
165  addCalo(p);
166  clusterRefMap_[&p] = ref;
167 }
168 
170  if (p.pt() == 0)
171  return;
172  for (Region &r : regions_) {
173  if (r.contains(p.eta(), p.phi())) {
174  CaloCluster calo;
175  calo.fill(p.pt(), p.emEt(), p.ptError(), r.localEta(p.eta()), r.localPhi(p.phi()), p.isEM(), 0, &p);
176  r.emcalo.push_back(calo);
177  }
178  }
179 }
181  addEmCalo(p);
182  clusterRefMap_[&p] = ref;
183 }
184 
185 std::unique_ptr<l1t::PFCandidateCollection> RegionMapper::fetch(bool puppi, float ptMin) const {
186  auto ret = std::make_unique<l1t::PFCandidateCollection>();
187  for (const Region &r : regions_) {
188  for (const PFParticle &p : (puppi ? r.puppi : r.pf)) {
189  bool inside = true;
190  switch (trackRegionMode_) {
192  inside = r.fiducialLocal(p.floatVtxEta(), p.floatVtxPhi());
193  break;
195  inside = r.fiducialLocal(p.floatEta(), p.floatPhi());
196  break;
197  case TrackAssoMode::any:
198  inside = r.fiducialLocal(p.floatVtxEta(), p.floatVtxPhi());
199  break; // WARNING: this may not be the best choice
200  }
201  if (!inside)
202  continue;
203  if (p.floatPt() > ptMin) {
205  p.floatPt(), r.globalEta(p.floatVtxEta()), r.globalPhi(p.floatVtxPhi()), 0.13f);
206  ret->emplace_back(l1t::PFCandidate::ParticleType(p.hwId), p.intCharge(), p4, p.floatPuppiW());
207  ret->back().setVertex(reco::Particle::Point(0, 0, p.floatDZ()));
208  ret->back().setStatus(p.hwStatus);
209  if (p.cluster.src) {
210  auto match = clusterRefMap_.find(p.cluster.src);
211  if (match == clusterRefMap_.end()) {
212  throw cms::Exception("CorruptData") << "Invalid cluster pointer in PF candidate id " << p.hwId << " pt "
213  << p4.pt() << " eta " << p4.eta() << " phi " << p4.phi();
214  }
215  ret->back().setPFCluster(match->second);
216  }
217  if (p.track.src) {
218  auto match = trackRefMap_.find(p.track.src);
219  if (match == trackRefMap_.end()) {
220  throw cms::Exception("CorruptData") << "Invalid track pointer in PF candidate id " << p.hwId << " pt "
221  << p4.pt() << " eta " << p4.eta() << " phi " << p4.phi();
222  }
223  ret->back().setPFTrack(match->second);
224  }
225  if (p.muonsrc) {
226  auto match = muonRefMap_.find(p.muonsrc);
227  if (match == muonRefMap_.end()) {
228  throw cms::Exception("CorruptData") << "Invalid muon pointer in PF candidate id " << p.hwId << " pt "
229  << p4.pt() << " eta " << p4.eta() << " phi " << p4.phi();
230  }
231  ret->back().setMuon(match->second);
232  }
233  }
234  }
235  }
236  return ret;
237 }
238 
239 std::unique_ptr<l1t::PFCandidateCollection> RegionMapper::fetchCalo(float ptMin, bool emcalo) const {
240  auto ret = std::make_unique<l1t::PFCandidateCollection>();
241  for (const Region &r : regions_) {
242  for (const CaloCluster &p : (emcalo ? r.emcalo : r.calo)) {
243  if (!r.fiducialLocal(p.floatEta(), p.floatPhi()))
244  continue;
245  if (p.floatPt() > ptMin) {
246  reco::Particle::PolarLorentzVector p4(p.floatPt(), r.globalEta(p.floatEta()), r.globalPhi(p.floatPhi()), 0.13f);
249  ret->emplace_back(kind, 0, p4);
250  if (p.src) {
251  auto match = clusterRefMap_.find(p.src);
252  if (match == clusterRefMap_.end()) {
253  throw cms::Exception("CorruptData")
254  << "Invalid cluster pointer in cluster pt " << p4.pt() << " eta " << p4.eta() << " phi " << p4.phi();
255  }
256  ret->back().setPFCluster(match->second);
257  }
258  }
259  }
260  }
261  return ret;
262 }
263 
264 std::unique_ptr<l1t::PFCandidateCollection> RegionMapper::fetchTracks(float ptMin, bool fromPV) const {
265  auto ret = std::make_unique<l1t::PFCandidateCollection>();
266  for (const Region &r : regions_) {
267  for (const PropagatedTrack &p : r.track) {
268  if (fromPV && !p.fromPV)
269  continue;
270  bool inside = true;
271  switch (trackRegionMode_) {
273  inside = r.fiducialLocal(p.floatVtxEta(), p.floatVtxPhi());
274  break;
276  inside = r.fiducialLocal(p.floatEta(), p.floatPhi());
277  break;
278  case TrackAssoMode::any:
279  inside = r.fiducialLocal(p.floatVtxEta(), p.floatVtxPhi());
280  break; // WARNING: this may not be the best choice
281  }
282  if (!inside)
283  continue;
284  if (p.floatPt() > ptMin) {
286  p.floatVtxPt(), r.globalEta(p.floatVtxEta()), r.globalPhi(p.floatVtxPhi()), 0.13f);
288  ret->emplace_back(kind, p.intCharge(), p4);
289  ret->back().setVertex(reco::Particle::Point(0, 0, p.floatDZ()));
290  if (p.src) {
291  auto match = trackRefMap_.find(p.src);
292  if (match == trackRefMap_.end()) {
293  throw cms::Exception("CorruptData")
294  << "Invalid track pointer in PF track pt " << p4.pt() << " eta " << p4.eta() << " phi " << p4.phi();
295  }
296  ret->back().setPFTrack(match->second);
297  }
298  }
299  }
300  }
301  return ret;
302 }
303 
304 std::pair<unsigned, unsigned> RegionMapper::totAndMaxInput(int type) const {
305  unsigned ntot = 0, nmax = 0;
306  for (const auto &r : regions_) {
307  unsigned int ni = r.nInput(Region::InputType(type));
308  ntot += ni;
309  nmax = std::max(nmax, ni);
310  }
311  return std::make_pair(ntot, nmax);
312 }
313 
314 std::unique_ptr<std::vector<unsigned>> RegionMapper::vecInput(int type) const {
315  auto v = std::make_unique<std::vector<unsigned>>();
316  for (const auto &r : regions_) {
317  unsigned ni = r.nInput(Region::InputType(type));
318  v->push_back(ni);
319  }
320  return v;
321 }
322 
323 std::pair<unsigned, unsigned> RegionMapper::totAndMaxOutput(int type, bool puppi) const {
324  unsigned ntot = 0, nmax = 0;
325  for (const auto &r : regions_) {
326  unsigned int ni = r.nOutput(Region::OutputType(type), puppi);
327  ntot += ni;
328  nmax = std::max(nmax, ni);
329  }
330  return std::make_pair(ntot, nmax);
331 }
332 
333 std::unique_ptr<std::vector<unsigned>> RegionMapper::vecOutput(int type, bool puppi) const {
334  auto v = std::make_unique<std::vector<unsigned>>();
335  for (const auto &r : regions_) {
336  unsigned ni = r.nOutput(Region::OutputType(type), puppi);
337  v->push_back(ni);
338  }
339  return v;
340 }
tuple ret
prodAgent to be discontinued
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
void addMuon(const l1t::Muon &t)
bool isMuon() const override
Definition: PFTrack.h:64
double pt() const final
transverse momentum
std::unordered_map< const l1t::PFTrack *, l1t::PFTrackRef > trackRefMap_
Definition: RegionMapper.h:52
enum l1tpf_impl::RegionMapper::TrackAssoMode trackRegionMode_
RegionMapper(const edm::ParameterSet &)
Definition: RegionMapper.cc:5
std::unordered_map< const l1t::PFCluster *, l1t::PFClusterRef > clusterRefMap_
Definition: RegionMapper.h:51
constexpr float ptMin
float chi2() const
Definition: PFTrack.h:73
const Point & vertex() const override
vertex position (overwritten by PF...)
std::unique_ptr< std::vector< unsigned > > vecInput(int type) const
float caloEta() const
eta coordinate propagated at the calorimeter surface used for track-cluster matching ...
Definition: PFTrack.h:48
float trkPtError() const
uncertainty on track pt
Definition: PFTrack.h:57
std::pair< unsigned, unsigned > totAndMaxInput(int type) const
std::pair< unsigned, unsigned > totAndMaxOutput(int type, bool puppi) const
const int neta
std::unique_ptr< l1t::PFCandidateCollection > fetchTracks(float ptMin=0.01, bool fromPV=false) const
void addTrack(const l1t::PFTrack &t)
Definition: RegionMapper.cc:86
math::XYZPoint Point
point in the space
Definition: Particle.h:25
std::vector< Region > regions_
Definition: RegionMapper.h:46
const l1t::PFTrack * src
void addCalo(const l1t::PFCluster &t)
const int mu
Definition: Constants.h:22
std::unique_ptr< l1t::PFCandidateCollection > fetch(bool puppi=true, float ptMin=0.01) const
std::unique_ptr< std::vector< unsigned > > vecOutput(int type, bool puppi) const
int hwQual() const
Definition: L1Candidate.h:38
#define M_PI
Definition: Muon.h:21
std::unordered_map< const l1t::Muon *, l1t::PFCandidate::MuonRef > muonRefMap_
Definition: RegionMapper.h:53
bool isEM() const
Definition: PFCluster.h:59
tuple puppi
Definition: Puppi_cff.py:30
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void addEmCalo(const l1t::PFCluster &t)
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Particle.h:23
std::unique_ptr< l1t::PFCandidateCollection > fetchCalo(float ptMin=0.01, bool emcalo=false) const
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
float emEt() const
Definition: PFCluster.h:40
int quality() const
Definition: PFTrack.h:67
preg
Definition: Schedule.cc:687
double phi() const final
momentum azimuthal angle
float caloPhi() const
phi coordinate propagated at the calorimeter surface used for track-cluster matching ...
Definition: PFTrack.h:50
unsigned int nStubs() const
Definition: PFTrack.h:71
float ptError() const
Definition: PFCluster.h:56
__shared__ uint32_t ntot
int charge() const final
electric charge
float caloPtError() const
uncertainty on calorimetric response for a hadron with pt equal to this track&#39;s pt ...
Definition: PFTrack.h:61
double eta() const final
momentum pseudorapidity