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 157 of file MLPFModel.cc.

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

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 14 of file MLPFModel.cc.

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

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 184 of file MLPFModel.cc.

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

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 161 of file MLPFModel.cc.

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

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

Referenced by MLPFProducer::produce().

◆ normalize()

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

Definition at line 148 of file MLPFModel.cc.

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

References funct::abs(), recoMuon::in, and CommonMethods::isnan().

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 203 of file MLPFModel.cc.

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

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
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
CommonMethods.isnan
def isnan(num)
Definition: CommonMethods.py:98
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:37
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:7733
gather_cfg.blocks
blocks
Definition: gather_cfg.py:90
reco::PFBlockElement::PS2
Definition: PFBlockElement.h:34