CMS 3D CMS Logo

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