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_e, float pred_eta, float pred_phi)
 
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 = 11
 
static constexpr unsigned int IDX_ENERGY = 10
 
static constexpr unsigned int IDX_ETA = 8
 
static constexpr unsigned int IDX_PHI = 9
 
static constexpr int LSH_BIN_SIZE = 100
 
static constexpr unsigned int NUM_CLASS = 7
 
static constexpr unsigned int NUM_ELEMENT_FEATURES = 15
 
static constexpr int NUM_MAX_ELEMENTS_BATCH = 20000
 
static constexpr unsigned int NUM_OUTPUTS = 12
 
static const std::vector< int > pdgid_encoding = {0, 1, 2, 11, 13, 22, 130, 211}
 

Function Documentation

◆ argMax()

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

Definition at line 158 of file MLPFModel.cc.

158  {
159  return static_cast<int>(std::distance(vec.begin(), max_element(vec.begin(), vec.end())));
160  }

References HLT_FULL_cff::distance.

Referenced by MLPFProducer::produce().

◆ getElementProperties()

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

Definition at line 15 of file MLPFModel.cc.

15  {
16  const auto type = orig.type();
17  float pt = 0.0;
18  //these are placeholders for the the future
19  [[maybe_unused]] float deltap = 0.0;
20  [[maybe_unused]] float sigmadeltap = 0.0;
21  [[maybe_unused]] float px = 0.0;
22  [[maybe_unused]] float py = 0.0;
23  [[maybe_unused]] float pz = 0.0;
24  float eta = 0.0;
25  float phi = 0.0;
26  float energy = 0.0;
27  float trajpoint = 0.0;
28  float eta_ecal = 0.0;
29  float phi_ecal = 0.0;
30  float eta_hcal = 0.0;
31  float phi_hcal = 0.0;
32  float charge = 0;
33  float layer = 0;
34  float depth = 0;
35  float muon_dt_hits = 0.0;
36  float muon_csc_hits = 0.0;
37 
39  const auto& matched_pftrack = orig.trackRefPF();
40  if (matched_pftrack.isNonnull()) {
41  const auto& atECAL = matched_pftrack->extrapolatedPoint(reco::PFTrajectoryPoint::ECALShowerMax);
42  const auto& atHCAL = matched_pftrack->extrapolatedPoint(reco::PFTrajectoryPoint::HCALEntrance);
43  if (atHCAL.isValid()) {
44  eta_hcal = atHCAL.positionREP().eta();
45  phi_hcal = atHCAL.positionREP().phi();
46  }
47  if (atECAL.isValid()) {
48  eta_ecal = atECAL.positionREP().eta();
49  phi_ecal = atECAL.positionREP().phi();
50  }
51  }
52  const auto& ref = ((const reco::PFBlockElementTrack*)&orig)->trackRef();
53  pt = ref->pt();
54  px = ref->px();
55  py = ref->py();
56  pz = ref->pz();
57  eta = ref->eta();
58  phi = ref->phi();
59  energy = ref->p();
60  charge = ref->charge();
61 
62  reco::MuonRef muonRef = orig.muonRef();
63  if (muonRef.isNonnull()) {
64  reco::TrackRef standAloneMu = muonRef->standAloneMuon();
65  if (standAloneMu.isNonnull()) {
66  muon_dt_hits = standAloneMu->hitPattern().numberOfValidMuonDTHits();
67  muon_csc_hits = standAloneMu->hitPattern().numberOfValidMuonCSCHits();
68  }
69  }
70 
71  } else if (type == reco::PFBlockElement::BREM) {
72  const auto* orig2 = (const reco::PFBlockElementBrem*)&orig;
73  const auto& ref = orig2->GsftrackRef();
74  if (ref.isNonnull()) {
75  deltap = orig2->DeltaP();
76  sigmadeltap = orig2->SigmaDeltaP();
77  pt = ref->pt();
78  px = ref->px();
79  py = ref->py();
80  pz = ref->pz();
81  eta = ref->eta();
82  phi = ref->phi();
83  energy = ref->p();
84  trajpoint = orig2->indTrajPoint();
85  charge = ref->charge();
86  }
87  } else if (type == reco::PFBlockElement::GSF) {
88  //requires to keep GsfPFRecTracks
89  const auto* orig2 = (const reco::PFBlockElementGsfTrack*)&orig;
90  const auto& vec = orig2->Pin();
91  pt = vec.pt();
92  px = vec.px();
93  py = vec.py();
94  pz = vec.pz();
95  eta = vec.eta();
96  phi = vec.phi();
97  energy = vec.energy();
98  if (!orig2->GsftrackRefPF().isNull()) {
99  charge = orig2->GsftrackRefPF()->charge();
100  }
105  const auto& ref = ((const reco::PFBlockElementCluster*)&orig)->clusterRef();
106  if (ref.isNonnull()) {
107  eta = ref->eta();
108  phi = ref->phi();
109  px = ref->position().x();
110  py = ref->position().y();
111  pz = ref->position().z();
112  energy = ref->energy();
113  layer = ref->layer();
114  depth = ref->depth();
115  }
116  } else if (type == reco::PFBlockElement::SC) {
117  const auto& clref = ((const reco::PFBlockElementSuperCluster*)&orig)->superClusterRef();
118  if (clref.isNonnull()) {
119  eta = clref->eta();
120  phi = clref->phi();
121  px = clref->position().x();
122  py = clref->position().y();
123  pz = clref->position().z();
124  energy = clref->energy();
125  }
126  }
127 
128  float typ_idx = static_cast<float>(elem_type_encoding.at(orig.type()));
129 
130  //Must be the same order as in tf_model.py
131  return std::array<float, NUM_ELEMENT_FEATURES>({{typ_idx,
132  pt,
133  eta,
134  phi,
135  energy,
136  layer,
137  depth,
138  charge,
139  trajpoint,
140  eta_ecal,
141  phi_ecal,
142  eta_hcal,
143  phi_hcal,
144  muon_dt_hits,
145  muon_csc_hits}});
146  }

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 >::isNonnull(), phase1PixelTopology::layer, 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().

◆ getPFElements()

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

Definition at line 185 of file MLPFModel.cc.

185  {
186  std::vector<reco::PFCandidate> pOutputCandidateCollection;
187 
188  std::vector<const reco::PFBlockElement*> all_elements;
189  for (const auto& block : blocks) {
190  const auto& elems = block.elements();
191  for (const auto& elem : elems) {
192  if (all_elements.size() < NUM_MAX_ELEMENTS_BATCH) {
193  all_elements.push_back(&elem);
194  } else {
195  //model needs to be created with a bigger LSH codebook size
196  edm::LogError("MLPFProducer") << "too many input PFElements for predefined model size: " << elems.size();
197  break;
198  }
199  }
200  }
201  return all_elements;
202  }

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

Referenced by MLPFProducer::produce().

◆ makeCandidate()

reco::PFCandidate reco::mlpf::makeCandidate ( int  pred_pid,
int  pred_charge,
float  pred_e,
float  pred_eta,
float  pred_phi 
)

Definition at line 162 of file MLPFModel.cc.

162  {
163  pred_phi = angle0to2pi::make0To2pi(pred_phi);
164 
165  //currently, set the pT from a massless approximation.
166  //later versions of the model may predict predict both the energy and pT of the particle
167  float pred_pt = pred_e / cosh(pred_eta);
168 
169  //set the charge to +1 or -1 for PFCandidates that are charged, according to the sign of the predicted charge
171  if (pred_pid == 11 || pred_pid == 13 || pred_pid == 211) {
172  charge = pred_charge > 0 ? +1 : -1;
173  }
174 
175  math::PtEtaPhiELorentzVectorD p4(pred_pt, pred_eta, pred_phi, pred_e);
176 
179  cand.setPdgId(pred_pid);
180  cand.setCharge(charge);
181 
182  return cand;
183  }

References ALCARECOTkAlJpsiMuMu_cff::charge, angle0to2pi::make0To2pi(), and p4.

Referenced by MLPFProducer::produce().

◆ normalize()

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

Definition at line 149 of file MLPFModel.cc.

149  {
150  if (std::abs(in) > 1e4f) {
151  return 0.0;
152  } else if (edm::isNotFinite(in)) {
153  return 0.0;
154  }
155  return in;
156  }

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

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

◆ setCandidateRefs()

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

Definition at line 204 of file MLPFModel.cc.

206  {
207  const reco::PFBlockElement* elem = elems[ielem_originator];
208  //set the track ref in case the originating element was a track
209  if (elem->type() == reco::PFBlockElement::TRACK && cand.charge() != 0 && elem->trackRef().isNonnull()) {
210  cand.setTrackRef(elem->trackRef());
211 
212  //set the muon ref in case the originator was a muon
213  const auto& muonref = elem->muonRef();
214  if (muonref.isNonnull()) {
215  cand.setMuonRef(muonref);
216  }
217  }
218  }

References edm::Ref< C, T, F >::isNonnull(), reco::PFBlockElement::muonRef(), reco::PFBlockElement::TRACK, reco::PFBlockElement::trackRef(), and reco::PFBlockElement::type().

Referenced by MLPFProducer::produce().

Variable Documentation

◆ BATCH_SIZE

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

Definition at line 17 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

◆ 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 38 of file MLPFModel.h.

Referenced by getElementProperties().

◆ IDX_CHARGE

constexpr unsigned int reco::mlpf::IDX_CHARGE = 11
staticconstexpr

Definition at line 30 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

◆ IDX_ENERGY

constexpr unsigned int reco::mlpf::IDX_ENERGY = 10
staticconstexpr

Definition at line 29 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

◆ IDX_ETA

constexpr unsigned int reco::mlpf::IDX_ETA = 8
staticconstexpr

Definition at line 27 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

◆ IDX_PHI

constexpr unsigned int reco::mlpf::IDX_PHI = 9
staticconstexpr

Definition at line 28 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

◆ LSH_BIN_SIZE

constexpr int reco::mlpf::LSH_BIN_SIZE = 100
staticconstexpr

Definition at line 14 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

◆ NUM_CLASS

constexpr unsigned int reco::mlpf::NUM_CLASS = 7
staticconstexpr

Definition at line 26 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

◆ NUM_ELEMENT_FEATURES

constexpr unsigned int reco::mlpf::NUM_ELEMENT_FEATURES = 15
staticconstexpr

Definition at line 10 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

◆ NUM_MAX_ELEMENTS_BATCH

constexpr int reco::mlpf::NUM_MAX_ELEMENTS_BATCH = 20000
staticconstexpr

Definition at line 13 of file MLPFModel.h.

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

◆ NUM_OUTPUTS

constexpr unsigned int reco::mlpf::NUM_OUTPUTS = 12
staticconstexpr

Definition at line 25 of file MLPFModel.h.

◆ pdgid_encoding

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

Definition at line 34 of file MLPFModel.h.

Referenced by MLPFProducer::produce().

reco::PFBlockElement::HO
Definition: PFBlockElement.h:42
math::PtEtaPhiELorentzVectorD
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiE4D< double > > PtEtaPhiELorentzVectorD
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:12
reco::PFBlockElement::trackRefPF
virtual const PFRecTrackRef & trackRefPF() const
Definition: PFBlockElement.h:89
edm::isNotFinite
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
multPhiCorr_741_25nsDY_cfi.py
py
Definition: multPhiCorr_741_25nsDY_cfi.py:12
reco::PFBlockElementSuperCluster
Cluster Element.
Definition: PFBlockElementSuperCluster.h:15
reco::PFBlockElement::SC
Definition: PFBlockElement.h:41
reco::Candidate::Charge
int Charge
electric charge type
Definition: Candidate.h:34
reco::PFBlockElement::HCAL
Definition: PFBlockElement.h:36
reco::mlpf::elem_type_encoding
static const std::map< int, int > elem_type_encoding
Definition: MLPFModel.h:38
edm::Ref< MuonCollection >
reco::mlpf::NUM_MAX_ELEMENTS_BATCH
static constexpr int NUM_MAX_ELEMENTS_BATCH
Definition: MLPFModel.h:13
reco::PFBlockElement::TRACK
Definition: PFBlockElement.h:32
PVValHelper::eta
Definition: PVValidationHelpers.h:70
reco::PFTrajectoryPoint::ECALShowerMax
Definition: PFTrajectoryPoint.h:46
reco::PFBlockElementBrem
Track Element.
Definition: PFBlockElementBrem.h:17
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
LEDCalibrationChannels.depth
depth
Definition: LEDCalibrationChannels.py:65
phase1PixelTopology::layer
constexpr std::array< uint8_t, layerIndexSize > layer
Definition: phase1PixelTopology.h:99
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
reco::PFBlockElement::HFEM
Definition: PFBlockElement.h:39
reco::PFBlockElement::GSF
Definition: PFBlockElement.h:37
PVValHelper::phi
Definition: PVValidationHelpers.h:69
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
recoMuon::in
Definition: RecoMuonEnumerators.h:6
reco::PFBlockElement::ECAL
Definition: PFBlockElement.h:35
reco::PFTrajectoryPoint::HCALEntrance
HCAL front face.
Definition: PFTrajectoryPoint.h:48
cand
Definition: decayParser.h:32
reco::PFBlockElement::BREM
Definition: PFBlockElement.h:38
reco::PFBlockElement::trackRef
virtual const reco::TrackRef & trackRef() const
Definition: PFBlockElement.h:88
reco::PFBlockElement::muonRef
virtual const MuonRef & muonRef() const
Definition: PFBlockElement.h:93
p4
double p4[4]
Definition: TauolaWrapper.h:92
groupFilesInBlocks.block
block
Definition: groupFilesInBlocks.py:150
reco::PFBlockElement::HFHAD
Definition: PFBlockElement.h:40
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
reco::PFBlockElement
Abstract base class for a PFBlock element (track, cluster...)
Definition: PFBlockElement.h:26
angle0to2pi::make0To2pi
constexpr valType make0To2pi(valType angle)
Definition: deltaPhi.h:67
multPhiCorr_741_25nsDY_cfi.px
px
Definition: multPhiCorr_741_25nsDY_cfi.py:10
reco::PFBlockElementGsfTrack
Track Element.
Definition: PFBlockElementGsfTrack.h:18
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
reco::PFBlockElementCluster
Cluster Element.
Definition: PFBlockElementCluster.h:16
reco::PFBlockElementTrack
Track Element.
Definition: PFBlockElementTrack.h:17
reco::PFBlockElement::type
Type type() const
Definition: PFBlockElement.h:69
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
reco::PFBlockElement::PS1
Definition: PFBlockElement.h:33
reco::PFCandidate::ParticleType
ParticleType
particle types
Definition: PFCandidate.h:44
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7746
gather_cfg.blocks
blocks
Definition: gather_cfg.py:90
reco::PFBlockElement::PS2
Definition: PFBlockElement.h:34