CMS 3D CMS Logo

Functions | Variables
reco::mlpf Namespace Reference

Functions

int argMax (std::vector< float > const &vec)
 
std::array< float, NUM_ELEMENT_FEATURESgetElementProperties (const reco::PFBlockElement &orig)
 
const std::vector< const reco::PFBlockElement * > getPFElements (const reco::PFBlockCollection &blocks)
 
reco::PFCandidate makeCandidate (int pred_pid, int pred_charge, float pred_pt, float pred_eta, float pred_sin_phi, float pred_cos_phi, float pred_e)
 
float normalize (float in)
 
void setCandidateRefs (reco::PFCandidate &cand, const std::vector< const reco::PFBlockElement *> elems, size_t ielem_originator)
 

Variables

static constexpr int BATCH_SIZE = 1
 
static const std::map< int, int > elem_type_encoding
 
static constexpr unsigned int IDX_CHARGE = 8
 
static constexpr unsigned int IDX_CLASS = 7
 
static constexpr unsigned int IDX_COS_PHI = 12
 
static constexpr unsigned int IDX_ENERGY = 13
 
static constexpr unsigned int IDX_ETA = 10
 
static constexpr unsigned int IDX_PT = 9
 
static constexpr unsigned int IDX_SIN_PHI = 11
 
static constexpr int LSH_BIN_SIZE = 64
 
static constexpr unsigned int NUM_ELEMENT_FEATURES = 25
 
static constexpr int NUM_MAX_ELEMENTS_BATCH = 200 * LSH_BIN_SIZE
 
static constexpr unsigned int NUM_OUTPUT_FEATURES = 14
 
static const std::vector< int > pdgid_encoding = {0, 211, 130, 1, 2, 22, 11, 13}
 
static constexpr float PI_MASS = 0.13957
 

Function Documentation

◆ argMax()

int reco::mlpf::argMax ( std::vector< float > const &  vec)

Definition at line 216 of file MLPFModel.cc.

References HLT_2023v11_cff::distance.

Referenced by MLPFProducer::produce().

216  {
217  return static_cast<int>(std::distance(vec.begin(), max_element(vec.begin(), vec.end())));
218  }

◆ getElementProperties()

std::array< float, NUM_ELEMENT_FEATURES > reco::mlpf::getElementProperties ( const reco::PFBlockElement orig)

Definition at line 17 of file MLPFModel.cc.

References reco::PFBlockElement::BREM, ALCARECOTkAlJpsiMuMu_cff::charge, LEDCalibrationChannels::depth, reco::PFBlockElement::ECAL, reco::PFTrajectoryPoint::ECALShowerMax, elem_type_encoding, HCALHighEnergyHPDFilter_cfi::energy, PVValHelper::eta, reco::PFBlockElement::GSF, reco::PFBlockElement::HCAL, reco::PFTrajectoryPoint::HCALEntrance, reco::PFBlockElement::HFEM, reco::PFBlockElement::HFHAD, reco::PFBlockElement::HO, edm::Ref< C, T, F >::isAvailable(), edm::Ref< C, T, F >::isNonnull(), reco::PFBlockElement::muonRef(), reco::PFBlockElement::PS1, reco::PFBlockElement::PS2, DiDispStaMuonMonitor_cfi::pt, multPhiCorr_741_25nsDY_cfi::px, multPhiCorr_741_25nsDY_cfi::py, reco::PFBlockElement::SC, reco::PFBlockElement::TRACK, reco::PFBlockElement::trackRefPF(), and reco::PFBlockElement::type().

Referenced by MLPFProducer::produce().

17  {
18  const auto type = orig.type();
19  float pt = 0.0;
20  float deltap = 0.0;
21  float sigmadeltap = 0.0;
22  float px = 0.0;
23  float py = 0.0;
24  float pz = 0.0;
25  float eta = 0.0;
26  float phi = 0.0;
27  float energy = 0.0;
28  float corr_energy = 0.0;
29  float trajpoint = 0.0;
30  float eta_ecal = 0.0;
31  float phi_ecal = 0.0;
32  float eta_hcal = 0.0;
33  float phi_hcal = 0.0;
34  float charge = 0;
35  float layer = 0;
36  float depth = 0;
37  float muon_dt_hits = 0.0;
38  float muon_csc_hits = 0.0;
39  float muon_type = 0.0;
40  float cluster_flags = 0.0;
41  float gsf_electronseed_trkorecal = 0.0;
42  float num_hits = 0.0;
43 
45  const auto& matched_pftrack = orig.trackRefPF();
46  if (matched_pftrack.isNonnull()) {
47  const auto& atECAL = matched_pftrack->extrapolatedPoint(reco::PFTrajectoryPoint::ECALShowerMax);
48  const auto& atHCAL = matched_pftrack->extrapolatedPoint(reco::PFTrajectoryPoint::HCALEntrance);
49  if (atHCAL.isValid()) {
50  eta_hcal = atHCAL.positionREP().eta();
51  phi_hcal = atHCAL.positionREP().phi();
52  }
53  if (atECAL.isValid()) {
54  eta_ecal = atECAL.positionREP().eta();
55  phi_ecal = atECAL.positionREP().phi();
56  }
57  }
58  const auto& ref = ((const reco::PFBlockElementTrack*)&orig)->trackRef();
59  pt = ref->pt();
60  px = ref->px();
61  py = ref->py();
62  pz = ref->pz();
63  eta = ref->eta();
64  phi = ref->phi();
65  energy = ref->p();
66  charge = ref->charge();
67  num_hits = ref->recHitsSize();
68 
69  reco::MuonRef muonRef = orig.muonRef();
70  if (muonRef.isNonnull()) {
71  reco::TrackRef standAloneMu = muonRef->standAloneMuon();
72  if (standAloneMu.isNonnull()) {
73  muon_dt_hits = standAloneMu->hitPattern().numberOfValidMuonDTHits();
74  muon_csc_hits = standAloneMu->hitPattern().numberOfValidMuonCSCHits();
75  }
76  muon_type = muonRef->type();
77  }
78 
79  } else if (type == reco::PFBlockElement::BREM) {
80  const auto* orig2 = (const reco::PFBlockElementBrem*)&orig;
81  const auto& ref = orig2->GsftrackRef();
82  trajpoint = orig2->indTrajPoint();
83  if (ref.isNonnull()) {
84  deltap = orig2->DeltaP();
85  sigmadeltap = orig2->SigmaDeltaP();
86  pt = ref->pt();
87  px = ref->px();
88  py = ref->py();
89  pz = ref->pz();
90  eta = ref->eta();
91  phi = ref->phi();
92  energy = ref->p();
93  charge = ref->charge();
94  }
95 
96  const auto& gsfextraref = ref->extra();
97  if (gsfextraref.isAvailable() && gsfextraref->seedRef().isAvailable()) {
98  reco::ElectronSeedRef seedref = gsfextraref->seedRef().castTo<reco::ElectronSeedRef>();
99  if (seedref.isAvailable()) {
100  if (seedref->isEcalDriven()) {
101  gsf_electronseed_trkorecal = 1.0;
102  } else if (seedref->isTrackerDriven()) {
103  gsf_electronseed_trkorecal = 2.0;
104  }
105  }
106  }
107 
108  } else if (type == reco::PFBlockElement::GSF) {
109  //requires to keep GsfPFRecTracks
110  const auto* orig2 = (const reco::PFBlockElementGsfTrack*)&orig;
111  const auto& vec = orig2->Pin();
112  pt = vec.pt();
113  px = vec.px();
114  py = vec.py();
115  pz = vec.pz();
116  eta = vec.eta();
117  phi = vec.phi();
118  energy = vec.energy();
119 
120  const auto& vec2 = orig2->Pout();
121  eta_ecal = vec2.eta();
122  phi_ecal = vec2.phi();
123 
124  if (!orig2->GsftrackRefPF().isNull()) {
125  charge = orig2->GsftrackRefPF()->charge();
126  num_hits = orig2->GsftrackRefPF()->PFRecBrem().size();
127  }
128 
129  const auto& ref = orig2->GsftrackRef();
130 
131  const auto& gsfextraref = ref->extra();
132  if (gsfextraref.isAvailable() && gsfextraref->seedRef().isAvailable()) {
133  reco::ElectronSeedRef seedref = gsfextraref->seedRef().castTo<reco::ElectronSeedRef>();
134  if (seedref.isAvailable()) {
135  if (seedref->isEcalDriven()) {
136  gsf_electronseed_trkorecal = 1.0;
137  } else if (seedref->isTrackerDriven()) {
138  gsf_electronseed_trkorecal = 2.0;
139  }
140  }
141  };
142 
147  const auto& ref = ((const reco::PFBlockElementCluster*)&orig)->clusterRef();
148  if (ref.isNonnull()) {
149  cluster_flags = ref->flags();
150  eta = ref->eta();
151  phi = ref->phi();
152  pt = ref->pt();
153  px = ref->position().x();
154  py = ref->position().y();
155  pz = ref->position().z();
156  energy = ref->energy();
157  corr_energy = ref->correctedEnergy();
158  layer = ref->layer();
159  depth = ref->depth();
160  num_hits = ref->recHitFractions().size();
161  }
162  } else if (type == reco::PFBlockElement::SC) {
163  const auto& clref = ((const reco::PFBlockElementSuperCluster*)&orig)->superClusterRef();
164  if (clref.isNonnull()) {
165  cluster_flags = clref->flags();
166  eta = clref->eta();
167  phi = clref->phi();
168  px = clref->position().x();
169  py = clref->position().y();
170  pz = clref->position().z();
171  energy = clref->energy();
172  num_hits = clref->clustersSize();
173  }
174  }
175 
176  float typ_idx = static_cast<float>(elem_type_encoding.at(orig.type()));
177 
178  //Must be the same order as in tf_model.py
179  return {{typ_idx,
180  pt,
181  eta,
182  phi,
183  energy,
184  layer,
185  depth,
186  charge,
187  trajpoint,
188  eta_ecal,
189  phi_ecal,
190  eta_hcal,
191  phi_hcal,
192  muon_dt_hits,
193  muon_csc_hits,
194  muon_type,
195  px,
196  py,
197  pz,
198  deltap,
199  sigmadeltap,
200  gsf_electronseed_trkorecal,
201  num_hits,
202  cluster_flags,
203  corr_energy}};
204  }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
virtual const PFRecTrackRef & trackRefPF() const
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
bool isAvailable() const
Definition: Ref.h:537
static const std::map< int, int > elem_type_encoding
Definition: MLPFModel.h:47
std::vector< vec1 > vec2
Definition: HCALResponse.h:16
virtual const MuonRef & muonRef() const

◆ getPFElements()

const std::vector< const reco::PFBlockElement * > reco::mlpf::getPFElements ( const reco::PFBlockCollection blocks)

Definition at line 263 of file MLPFModel.cc.

References groupFilesInBlocks::block, gather_cfg::blocks, and NUM_MAX_ELEMENTS_BATCH.

Referenced by MLPFProducer::produce().

263  {
264  std::vector<reco::PFCandidate> pOutputCandidateCollection;
265 
266  std::vector<const reco::PFBlockElement*> all_elements;
267  for (const auto& block : blocks) {
268  const auto& elems = block.elements();
269  for (const auto& elem : elems) {
270  if (all_elements.size() < NUM_MAX_ELEMENTS_BATCH) {
271  all_elements.push_back(&elem);
272  } else {
273  //model needs to be created with a bigger LSH codebook size
274  edm::LogError("MLPFProducer") << "too many input PFElements for predefined model size: " << elems.size();
275  break;
276  }
277  }
278  }
279  return all_elements;
280  }
Log< level::Error, false > LogError
static constexpr int NUM_MAX_ELEMENTS_BATCH
Definition: MLPFModel.h:15

◆ makeCandidate()

reco::PFCandidate reco::mlpf::makeCandidate ( int  pred_pid,
int  pred_charge,
float  pred_pt,
float  pred_eta,
float  pred_sin_phi,
float  pred_cos_phi,
float  pred_e 
)

Definition at line 220 of file MLPFModel.cc.

References ALCARECOTkAlJpsiMuMu_cff::charge, reco::PFCandidate::e, reco::PFCandidate::egamma_HF, reco::PFCandidate::gamma, reco::PFCandidate::h, reco::PFCandidate::h0, reco::PFCandidate::h_HF, reco::PFCandidate::mu, PbPb_ZMuSkimMuonDPG_cff::particleType, PI_MASS, and reco::PFCandidate::X.

Referenced by MLPFProducer::produce().

226  {
227  float pred_phi = std::atan2(pred_sin_phi, pred_cos_phi);
228 
229  //set the charge to +1 or -1 for PFCandidates that are charged, according to the sign of the predicted charge
231  if (pred_pid == 11 || pred_pid == 13 || pred_pid == 211) {
232  charge = pred_charge > 0 ? +1 : -1;
233  }
234 
235  math::PtEtaPhiELorentzVectorD p4(pred_pt, pred_eta, pred_phi, pred_e);
236 
238  if (pred_pid == 211)
240  else if (pred_pid == 130)
242  else if (pred_pid == 22)
244  else if (pred_pid == 11)
246  else if (pred_pid == 13)
248  else if (pred_pid == 1)
250  else if (pred_pid == 2)
252 
253  reco::PFCandidate cand(charge, math::XYZTLorentzVector(p4.X(), p4.Y(), p4.Z(), p4.E()), particleType);
254  cand.setMass(0.0);
255  if (pred_pid == 211)
256  cand.setMass(PI_MASS);
257  //cand.setPdgId(pred_pid);
258  //cand.setCharge(charge);
259 
260  return cand;
261  }
int Charge
electric charge type
Definition: Candidate.h:34
ParticleType
particle types
Definition: PFCandidate.h:44
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiE4D< double > > PtEtaPhiELorentzVectorD
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:12
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
static constexpr float PI_MASS
Definition: MLPFModel.h:39

◆ normalize()

float reco::mlpf::normalize ( float  in)

Definition at line 207 of file MLPFModel.cc.

References funct::abs(), recoMuon::in, and edm::isNotFinite().

Referenced by drawSingleHistogram(), Rivet::CMS_2013_I1224539_DIJET::finalize(), Geom::Phi< float >::normalize(), and MLPFProducer::produce().

207  {
208  if (std::abs(in) > 1e4f) {
209  return 0.0;
210  } else if (edm::isNotFinite(in)) {
211  return 0.0;
212  }
213  return in;
214  }
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
Abs< T >::type abs(const T &t)
Definition: Abs.h:22

◆ setCandidateRefs()

void reco::mlpf::setCandidateRefs ( reco::PFCandidate cand,
const std::vector< const reco::PFBlockElement *>  elems,
size_t  ielem_originator 
)

Definition at line 284 of file MLPFModel.cc.

References funct::abs(), reco::PFBlockElement::GSF, reco::PFBlockElementGsfTrack::GsftrackRef(), edm::Ref< C, T, F >::isNonnull(), reco::PFBlockElementTrack::muonRef(), reco::PFBlockElement::TRACK, reco::PFBlockElement::trackRef(), and reco::PFBlockElement::type().

Referenced by MLPFProducer::produce().

286  {
287  const reco::PFBlockElement* elem = elems[ielem_originator];
288 
289  //set the track ref in case the originating element was a track
290  if (std::abs(cand.pdgId()) == 211 && elem->type() == reco::PFBlockElement::TRACK && elem->trackRef().isNonnull()) {
291  const auto* eltTrack = dynamic_cast<const reco::PFBlockElementTrack*>(elem);
292  cand.setTrackRef(eltTrack->trackRef());
293  cand.setVertex(eltTrack->trackRef()->vertex());
294  cand.setPositionAtECALEntrance(eltTrack->positionAtECALEntrance());
295  }
296 
297  //set the muon ref
298  if (std::abs(cand.pdgId()) == 13) {
299  const auto* eltTrack = dynamic_cast<const reco::PFBlockElementTrack*>(elem);
300  const auto& muonRef = eltTrack->muonRef();
301  cand.setTrackRef(muonRef->track());
302  cand.setMuonTrackType(muonRef->muonBestTrackType());
303  cand.setVertex(muonRef->track()->vertex());
304  cand.setMuonRef(muonRef);
305  }
306 
307  if (std::abs(cand.pdgId()) == 11 && elem->type() == reco::PFBlockElement::GSF) {
308  const auto* eltTrack = dynamic_cast<const reco::PFBlockElementGsfTrack*>(elem);
309  const auto& ref = eltTrack->GsftrackRef();
310  cand.setGsfTrackRef(ref);
311  }
312  }
Abstract base class for a PFBlock element (track, cluster...)
virtual const reco::TrackRef & trackRef() const
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
const reco::GsfTrackRef & GsftrackRef() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const reco::MuonRef & muonRef() const override

Variable Documentation

◆ BATCH_SIZE

constexpr int reco::mlpf::BATCH_SIZE = 1
static

Definition at line 18 of file MLPFModel.h.

◆ elem_type_encoding

const std::map<int, int> reco::mlpf::elem_type_encoding
static
Initial value:
= {
{0, 0},
{1, 1},
{2, 2},
{3, 3},
{4, 4},
{5, 5},
{6, 6},
{7, 7},
{8, 8},
{9, 9},
{10, 10},
{11, 11},
}

Definition at line 47 of file MLPFModel.h.

Referenced by getElementProperties().

◆ IDX_CHARGE

constexpr unsigned int reco::mlpf::IDX_CHARGE = 8
static

Definition at line 30 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

◆ IDX_CLASS

constexpr unsigned int reco::mlpf::IDX_CLASS = 7
static

Definition at line 28 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

◆ IDX_COS_PHI

constexpr unsigned int reco::mlpf::IDX_COS_PHI = 12
static

Definition at line 35 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

◆ IDX_ENERGY

constexpr unsigned int reco::mlpf::IDX_ENERGY = 13
static

Definition at line 36 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

◆ IDX_ETA

constexpr unsigned int reco::mlpf::IDX_ETA = 10
static

Definition at line 33 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

◆ IDX_PT

constexpr unsigned int reco::mlpf::IDX_PT = 9
static

Definition at line 32 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

◆ IDX_SIN_PHI

constexpr unsigned int reco::mlpf::IDX_SIN_PHI = 11
static

Definition at line 34 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

◆ LSH_BIN_SIZE

constexpr int reco::mlpf::LSH_BIN_SIZE = 64
static

Definition at line 14 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

◆ NUM_ELEMENT_FEATURES

constexpr unsigned int reco::mlpf::NUM_ELEMENT_FEATURES = 25
static

Definition at line 10 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

◆ NUM_MAX_ELEMENTS_BATCH

constexpr int reco::mlpf::NUM_MAX_ELEMENTS_BATCH = 200 * LSH_BIN_SIZE
static

Definition at line 15 of file MLPFModel.h.

Referenced by getPFElements(), and MLPFProducer::produce().

◆ NUM_OUTPUT_FEATURES

constexpr unsigned int reco::mlpf::NUM_OUTPUT_FEATURES = 14
static

Definition at line 11 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

◆ pdgid_encoding

const std::vector<int> reco::mlpf::pdgid_encoding = {0, 211, 130, 1, 2, 22, 11, 13}
static

Definition at line 43 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

◆ PI_MASS

constexpr float reco::mlpf::PI_MASS = 0.13957
static

Definition at line 39 of file MLPFModel.h.

Referenced by makeCandidate().