CMS 3D CMS Logo

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