CMS 3D CMS Logo

JetSpecific.cc
Go to the documentation of this file.
1 //
3 // JetSpecific
4 // -----------
5 //
7 
9 
21 
22 #include <cmath>
23 
25 // implementation of global functions
27 
28 //______________________________________________________________________________
29 // Overloaded methods to write out specific types
30 
31 // CaloJet
35  std::vector<reco::CandidatePtr> const& constituents,
36  CaloGeometry const& geometry,
37  HcalTopology const& topology) {
38  const CaloSubdetectorGeometry* towerGeometry = geometry.getSubdetectorGeometry(DetId::Calo, CaloTowerDetId::SubdetId);
39 
40  // Make the specific
42  makeSpecific(constituents, towerGeometry, &specific, topology);
43  // Set the calo jet
44  jet = reco::CaloJet(p4, point, specific, constituents);
45 }
46 
47 // BasicJet
51  std::vector<reco::CandidatePtr> const& constituents) {
52  jet = reco::BasicJet(p4, point, constituents);
53 }
54 
55 // GenJet
59  std::vector<reco::CandidatePtr> const& constituents) {
60  // Make the specific
62  makeSpecific(constituents, &specific);
63  // Set to the jet
64  jet = reco::GenJet(p4, point, specific, constituents);
65 }
66 
67 // PFJet
71  std::vector<reco::CandidatePtr> const& constituents,
73  // Make the specific
75  makeSpecific(constituents, &specific, weights);
76  // now make jet charge
77  int charge = 0.;
78  for (std::vector<reco::CandidatePtr>::const_iterator ic = constituents.begin(), icend = constituents.end();
79  ic != icend;
80  ++ic) {
81  float weight = (weights != nullptr) ? (*weights)[*ic] : 1.0;
82  charge += (*ic)->charge() * weight;
83  }
84  jet = reco::PFJet(p4, point, specific, constituents);
85  jet.setCharge(charge);
86 }
87 
88 // TrackJet
92  std::vector<reco::CandidatePtr> const& constituents) {
93  jet = reco::TrackJet(p4, point, constituents);
94 }
95 
96 // PFClusterJet
100  std::vector<reco::CandidatePtr> const& constituents) {
101  jet = reco::PFClusterJet(p4, point, constituents);
102 }
103 
104 //______________________________________________________________________________
105 bool reco::makeSpecific(std::vector<reco::CandidatePtr> const& towers,
106  const CaloSubdetectorGeometry* towerGeometry,
107  CaloJet::Specific* caloJetSpecific,
108  const HcalTopology& topology) {
109  if (nullptr == caloJetSpecific)
110  return false;
111 
112  // 1.- Loop over the tower Ids,
113  // 2.- Get the corresponding CaloTower
114  // 3.- Calculate the different CaloJet specific quantities
115  std::vector<double> eECal_i;
116  std::vector<double> eHCal_i;
117  double eInHad = 0.;
118  double eInEm = 0.;
119  double eInHO = 0.;
120  double eInHB = 0.;
121  double eInHE = 0.;
122  double eHadInHF = 0.;
123  double eEmInHF = 0.;
124  double eInEB = 0.;
125  double eInEE = 0.;
126  double jetArea = 0.;
127 
128  std::vector<reco::CandidatePtr>::const_iterator itTower;
129  for (itTower = towers.begin(); itTower != towers.end(); ++itTower) {
130  if (itTower->isNull() || !itTower->isAvailable()) {
131  edm::LogWarning("DataNotFound") << " JetSpecific: Tower is invalid\n";
132  continue;
133  }
134  const CaloTower* tower = dynamic_cast<const CaloTower*>(itTower->get());
135  if (tower) {
136  //Array of energy in EM Towers:
137  eECal_i.push_back(tower->emEnergy());
138  eInEm += tower->emEnergy();
139  //Array of energy in HCAL Towers:
140  eHCal_i.push_back(tower->hadEnergy());
141  eInHad += tower->hadEnergy();
142 
143  // figure out contributions
144  switch (reco::hcalSubdetector(tower->id().ieta(), topology)) {
145  case HcalBarrel:
146  eInHB += tower->hadEnergy();
147  eInHO += tower->outerEnergy();
148  eInEB += tower->emEnergy();
149  break;
150  case HcalEndcap:
151  eInHE += tower->hadEnergy();
152  eInEE += tower->emEnergy();
153  break;
154  case HcalForward:
155  eHadInHF += tower->hadEnergy();
156  eEmInHF += tower->emEnergy();
157  break;
158  default:
159  break;
160  }
161  // get area of the tower (++ minus --)
162  auto geometry = towerGeometry->getGeometry(tower->id());
163  if (geometry) {
164  jetArea += geometry->etaSpan() * geometry->phiSpan();
165  } else {
166  edm::LogWarning("DataNotFound") << "reco::makeCaloJetSpecific: Geometry for cell " << tower->id()
167  << " can not be found. Ignoring cell\n";
168  }
169  } else {
170  edm::LogWarning("DataNotFound") << "reco::makeCaloJetSpecific: Constituent is not of "
171  << "CaloTower type\n";
172  }
173  }
174 
175  double towerEnergy = eInHad + eInEm;
176  caloJetSpecific->mHadEnergyInHO = eInHO;
177  caloJetSpecific->mHadEnergyInHB = eInHB;
178  caloJetSpecific->mHadEnergyInHE = eInHE;
179  caloJetSpecific->mHadEnergyInHF = eHadInHF;
180  caloJetSpecific->mEmEnergyInHF = eEmInHF;
181  caloJetSpecific->mEmEnergyInEB = eInEB;
182  caloJetSpecific->mEmEnergyInEE = eInEE;
183  if (towerEnergy > 0) {
184  caloJetSpecific->mEnergyFractionHadronic = eInHad / towerEnergy;
185  caloJetSpecific->mEnergyFractionEm = eInEm / towerEnergy;
186  } else { // HO only jet
187  caloJetSpecific->mEnergyFractionHadronic = 1.;
188  caloJetSpecific->mEnergyFractionEm = 0.;
189  }
190  caloJetSpecific->mTowersArea = jetArea;
191  caloJetSpecific->mMaxEInEmTowers = 0;
192  caloJetSpecific->mMaxEInHadTowers = 0;
193 
194  //Sort the arrays
195  sort(eECal_i.begin(), eECal_i.end(), std::greater<double>());
196  sort(eHCal_i.begin(), eHCal_i.end(), std::greater<double>());
197 
198  if (!towers.empty()) {
199  //Highest value in the array is the first element of the array
200  caloJetSpecific->mMaxEInEmTowers = eECal_i.front();
201  caloJetSpecific->mMaxEInHadTowers = eHCal_i.front();
202  }
203 
204  return true;
205 }
206 
207 //______________________________________________________________________________
208 bool reco::makeSpecific(std::vector<reco::CandidatePtr> const& particles,
209  PFJet::Specific* pfJetSpecific,
210  edm::ValueMap<float> const* weights) {
211  if (nullptr == pfJetSpecific)
212  return false;
213 
214  // 1.- Loop over PFCandidates,
215  // 2.- Get the corresponding PFCandidate
216  // 3.- Calculate the different PFJet specific quantities
217 
218  float chargedHadronEnergy = 0.;
219  float neutralHadronEnergy = 0.;
220  float photonEnergy = 0.;
221  float electronEnergy = 0.;
222  float muonEnergy = 0.;
223  float HFHadronEnergy = 0.;
224  float HFEMEnergy = 0.;
225  float chargedHadronMultiplicity = 0;
226  float neutralHadronMultiplicity = 0;
227  float photonMultiplicity = 0;
228  float electronMultiplicity = 0;
229  float muonMultiplicity = 0;
230  float HFHadronMultiplicity = 0;
231  float HFEMMultiplicity = 0;
232 
233  float chargedEmEnergy = 0.;
234  float neutralEmEnergy = 0.;
235  float chargedMuEnergy = 0.;
236  float chargedMultiplicity = 0;
237  float neutralMultiplicity = 0;
238 
239  float HOEnergy = 0.;
240 
241  std::vector<reco::CandidatePtr>::const_iterator itParticle;
242  for (itParticle = particles.begin(); itParticle != particles.end(); ++itParticle) {
243  if (itParticle->isNull() || !itParticle->isAvailable()) {
244  edm::LogWarning("DataNotFound") << " JetSpecific: PF Particle is invalid\n";
245  continue;
246  }
247  const Candidate* pfCand = itParticle->get();
248  if (pfCand) {
249  const PFCandidate* pfCandCast = dynamic_cast<const PFCandidate*>(pfCand);
250  float weight = (weights != nullptr) ? (*weights)[*itParticle] : 1.0;
251  if (pfCandCast)
252  HOEnergy += pfCandCast->hoEnergy() * weight;
253 
254  switch (std::abs(pfCand->pdgId())) {
255  case 211: //PFCandidate::h: // charged hadron
256  chargedHadronEnergy += pfCand->energy() * weight;
258  chargedMultiplicity += weight;
259  break;
260 
261  case 130: //PFCandidate::h0 : // neutral hadron
262  neutralHadronEnergy += pfCand->energy() * weight;
264  neutralMultiplicity += weight;
265  break;
266 
267  case 22: //PFCandidate::gamma: // photon
268  photonEnergy += pfCand->energy() * weight;
270  neutralEmEnergy += pfCand->energy() * weight;
271  neutralMultiplicity += weight;
272  break;
273 
274  case 11: // PFCandidate::e: // electron
275  electronEnergy += pfCand->energy() * weight;
277  chargedEmEnergy += pfCand->energy() * weight;
278  chargedMultiplicity += weight;
279  break;
280 
281  case 13: //PFCandidate::mu: // muon
282  muonEnergy += pfCand->energy() * weight;
284  chargedMuEnergy += pfCand->energy() * weight;
285  chargedMultiplicity += weight;
286  break;
287 
288  case 1: // PFCandidate::h_HF : // hadron in HF
289  HFHadronEnergy += pfCand->energy() * weight;
291  neutralHadronEnergy += pfCand->energy() * weight;
292  neutralMultiplicity += weight;
293  break;
294 
295  case 2: //PFCandidate::egamma_HF : // electromagnetic in HF
296  HFEMEnergy += pfCand->energy() * weight;
298  neutralEmEnergy += pfCand->energy() * weight;
299  neutralMultiplicity += weight;
300  break;
301 
302  default:
303  edm::LogWarning("DataNotFound")
304  << "reco::makePFJetSpecific: Unknown PFCandidate::ParticleType: " << pfCand->pdgId() << " is ignored\n";
305  break;
306  }
307  } else {
308  edm::LogWarning("DataNotFound") << "reco::makePFJetSpecific: Referred constituent is not "
309  << "a PFCandidate\n";
310  }
311  }
312 
313  pfJetSpecific->mChargedHadronEnergy = chargedHadronEnergy;
314  pfJetSpecific->mNeutralHadronEnergy = neutralHadronEnergy;
315  pfJetSpecific->mPhotonEnergy = photonEnergy;
316  pfJetSpecific->mElectronEnergy = electronEnergy;
317  pfJetSpecific->mMuonEnergy = muonEnergy;
318  pfJetSpecific->mHFHadronEnergy = HFHadronEnergy;
319  pfJetSpecific->mHFEMEnergy = HFEMEnergy;
320 
321  pfJetSpecific->mChargedHadronMultiplicity = std::round(chargedHadronMultiplicity);
322  pfJetSpecific->mNeutralHadronMultiplicity = std::round(neutralHadronMultiplicity);
323  pfJetSpecific->mPhotonMultiplicity = std::round(photonMultiplicity);
324  pfJetSpecific->mElectronMultiplicity = std::round(electronMultiplicity);
325  pfJetSpecific->mMuonMultiplicity = std::round(muonMultiplicity);
326  pfJetSpecific->mHFHadronMultiplicity = std::round(HFHadronMultiplicity);
327  pfJetSpecific->mHFEMMultiplicity = std::round(HFEMMultiplicity);
328 
329  pfJetSpecific->mChargedEmEnergy = chargedEmEnergy;
330  pfJetSpecific->mChargedMuEnergy = chargedMuEnergy;
331  pfJetSpecific->mNeutralEmEnergy = neutralEmEnergy;
332  pfJetSpecific->mChargedMultiplicity = std::round(chargedMultiplicity);
333  pfJetSpecific->mNeutralMultiplicity = std::round(neutralMultiplicity);
334 
335  pfJetSpecific->mHOEnergy = HOEnergy;
336 
337  return true;
338 }
339 
340 //______________________________________________________________________________
341 bool reco::makeSpecific(std::vector<reco::CandidatePtr> const& mcparticles, GenJet::Specific* genJetSpecific) {
342  if (nullptr == genJetSpecific)
343  return false;
344 
345  std::vector<reco::CandidatePtr>::const_iterator itMcParticle = mcparticles.begin();
346  for (; itMcParticle != mcparticles.end(); ++itMcParticle) {
347  if (itMcParticle->isNull() || !itMcParticle->isAvailable()) {
348  edm::LogWarning("DataNotFound") << " JetSpecific: MC Particle is invalid\n";
349  continue;
350  }
351 
352  const Candidate* candidate = itMcParticle->get();
353  if (candidate->hasMasterClone())
354  candidate = candidate->masterClone().get();
355  //const GenParticle* genParticle = GenJet::genParticle(candidate);
356 
357  if (candidate) {
358  double e = candidate->energy();
359 
360  // Legacy calo-like definitions
361  switch (std::abs(candidate->pdgId())) {
362  case 22: // photon
363  case 11: // e
364  genJetSpecific->m_EmEnergy += e;
365  break;
366  case 211: // pi
367  case 321: // K
368  case 130: // KL
369  case 2212: // p
370  case 2112: // n
371  genJetSpecific->m_HadEnergy += e;
372  break;
373  case 13: // muon
374  case 12: // nu_e
375  case 14: // nu_mu
376  case 16: // nu_tau
377  genJetSpecific->m_InvisibleEnergy += e;
378  break;
379  default:
380  genJetSpecific->m_AuxiliaryEnergy += e;
381  }
382 
383  // PF-like definitions
384  switch (std::abs(candidate->pdgId())) {
385  case 11: //electron
386  genJetSpecific->m_ChargedEmEnergy += e;
387  ++(genJetSpecific->m_ChargedEmMultiplicity);
388  break;
389  case 13: // muon
390  genJetSpecific->m_MuonEnergy += e;
391  ++(genJetSpecific->m_MuonMultiplicity);
392  break;
393  case 211: //pi+-
394  case 321: //K
395  case 2212: //p
396  case 3222: //Sigma+
397  case 3112: //Sigma-
398  case 3312: //Xi-
399  case 3334: //Omega-
400  genJetSpecific->m_ChargedHadronEnergy += e;
401  ++(genJetSpecific->m_ChargedHadronMultiplicity);
402  break;
403  case 310: //KS0
404  case 130: //KL0
405  case 3122: //Lambda0
406  case 3212: //Sigma0
407  case 3322: //Xi0
408  case 2112: //n0
409  genJetSpecific->m_NeutralHadronEnergy += e;
410  ++(genJetSpecific->m_NeutralHadronMultiplicity);
411  break;
412  case 22: //photon
413  genJetSpecific->m_NeutralEmEnergy += e;
414  ++(genJetSpecific->m_NeutralEmMultiplicity);
415  break;
416  }
417  } // end if found a candidate
418  else {
419  edm::LogWarning("DataNotFound") << "reco::makeGenJetSpecific: Referred GenParticleCandidate "
420  << "is not available in the event\n";
421  }
422  } // end for loop over MC particles
423 
424  return true;
425 }
426 
427 //______________________________________________________________________________
429  int eta = std::abs(iEta);
430  if (eta <= topology.lastHBRing())
431  return HcalBarrel;
432  else if (eta <= topology.lastHERing())
433  return HcalEndcap;
434  else if (eta <= topology.lastHFRing())
435  return HcalForward;
436  return HcalEmpty;
437 }
float mMaxEInEmTowers
Maximum energy in EM towers.
Definition: CaloJet.h:48
virtual CellMayOwnPtr getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
virtual double energy() const =0
energy
Jets made from CaloTowers.
Definition: CaloJet.h:27
float mEmEnergyInHF
Em energy in HF.
Definition: CaloJet.h:64
float mEnergyFractionHadronic
Hadronic energy fraction.
Definition: CaloJet.h:66
int mChargedMultiplicity
Definition: PFJet.h:72
float m_NeutralHadronEnergy
K0, etc.
Definition: GenJet.h:56
T get() const
get a component
Definition: Candidate.h:221
float mEmEnergyInEB
Em energy in EB.
Definition: CaloJet.h:60
HcalSubdetector hcalSubdetector(int iEta, const HcalTopology &topology)
converts eta to the corresponding HCAL subdetector.
Definition: JetSpecific.cc:428
int m_ChargedEmMultiplicity
Definition: GenJet.h:66
float m_MuonEnergy
Muons.
Definition: GenJet.h:62
Definition: weight.py:1
void writeSpecific(reco::CaloJet &jet, reco::Particle::LorentzVector const &p4, reco::Particle::Point const &point, std::vector< reco::CandidatePtr > const &constituents, CaloGeometry const &geometry, HcalTopology const &topology)
Definition: JetSpecific.cc:32
int mPhotonMultiplicity
Definition: PFJet.h:61
float mNeutralHadronEnergy
Definition: PFJet.h:52
float mChargedMuEnergy
Definition: PFJet.h:70
float mHadEnergyInHB
Hadronic energy in HB.
Definition: CaloJet.h:54
Jets made from CaloTowers.
Definition: BasicJet.h:19
float m_ChargedEmEnergy
Electrons.
Definition: GenJet.h:58
Jets made from PFObjects.
Definition: PFJet.h:20
float mChargedHadronEnergy
Definition: PFJet.h:51
int m_NeutralEmMultiplicity
Definition: GenJet.h:67
float mChargedEmEnergy
Definition: PFJet.h:69
virtual bool hasMasterClone() const =0
Jets made out of PFClusters.
Definition: PFClusterJet.h:23
float mElectronEnergy
Definition: PFJet.h:54
static const int SubdetId
int mChargedHadronMultiplicity
Definition: PFJet.h:59
float mPhotonEnergy
Definition: PFJet.h:53
float mNeutralEmEnergy
Definition: PFJet.h:71
HcalSubdetector
Definition: HcalAssistant.h:31
math::XYZPoint Point
point in the space
Definition: Particle.h:25
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Jets made from MC generator particles.
Definition: GenJet.h:23
float mEnergyFractionEm
Em energy fraction.
Definition: CaloJet.h:68
int m_ChargedHadronMultiplicity
Corresponding multiplicities:
Definition: GenJet.h:64
float mHadEnergyInHF
Hadronic energy in HF.
Definition: CaloJet.h:56
float m_InvisibleEnergy
Invisible energy (mu, nu, ...)
Definition: GenJet.h:48
float mMaxEInHadTowers
Maximum energy in HCAL towers.
Definition: CaloJet.h:50
int mElectronMultiplicity
Definition: PFJet.h:62
Jets made out of tracks.
Definition: TrackJet.h:24
float m_ChargedHadronEnergy
Definition: GenJet.h:54
virtual int pdgId() const =0
PDG identifier.
double hoEnergy() const
return corrected Hcal energy
Definition: PFCandidate.h:245
int mNeutralHadronMultiplicity
Definition: PFJet.h:60
int mNeutralMultiplicity
Definition: PFJet.h:73
float m_AuxiliaryEnergy
Anything else (undecayed Sigmas etc.)
Definition: GenJet.h:50
float mHadEnergyInHO
Hadronic nergy fraction in HO.
Definition: CaloJet.h:52
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
float m_NeutralEmEnergy
Photons.
Definition: GenJet.h:60
float mHFHadronEnergy
Definition: PFJet.h:56
bool makeSpecific(std::vector< reco::CandidatePtr > const &towers, const CaloSubdetectorGeometry *towerGeometry, reco::CaloJet::Specific *caloJetSpecific, const HcalTopology &topology)
Make CaloJet specifics. Assumes PseudoJet is made from CaloTowerCandidates.
Definition: JetSpecific.cc:105
int m_NeutralHadronMultiplicity
Definition: GenJet.h:65
float m_HadEnergy
Energy of Hadrons.
Definition: GenJet.h:46
float mTowersArea
Area of contributing CaloTowers.
Definition: CaloJet.h:70
Log< level::Warning, false > LogWarning
int mHFHadronMultiplicity
Definition: PFJet.h:64
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
value_type const * get() const
Definition: RefToBase.h:216
float mEmEnergyInEE
Em energy in EE.
Definition: CaloJet.h:62
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
float mHadEnergyInHE
Hadronic energy in HE.
Definition: CaloJet.h:58
virtual const CandidateBaseRef & masterClone() const =0