CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GenSpecificAlgo.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: METAlgorithms
4 // Class: GenSpecificAlgo
5 //
6 // Original Authors: R. Cavanaugh (taken from F.Ratnikov, UMd)
7 // Created: June 6, 2006
8 // $Id: GenSpecificAlgo.cc,v 1.11 2013/05/03 18:53:44 salee Exp $
9 //
10 //
11 //____________________________________________________________________________||
13 #include "TMath.h"
14 
15 #include <set>
16 
17 //____________________________________________________________________________||
18 reco::GenMET GenSpecificAlgo::addInfo(edm::Handle<edm::View<reco::Candidate> > particles, CommonMETData *met, double globalThreshold, bool onlyFiducial,bool applyFiducialThresholdForFractions, bool usePt)
19 {
20  fillCommonMETData(met, particles, globalThreshold, onlyFiducial, usePt);
21 
22  SpecificGenMETData specific = mkSpecificGenMETData(particles, globalThreshold, onlyFiducial, applyFiducialThresholdForFractions, usePt);
23 
24  const LorentzVector p4( met->mex, met->mey, met->mez, met->met );
25  const Point vtx( 0.0, 0.0, 0.0 );
26 
27  reco::GenMET genMet(specific, met->sumet, p4, vtx );
28  return genMet;
29 }
30 
31 //____________________________________________________________________________||
32 void GenSpecificAlgo::fillCommonMETData(CommonMETData *met, edm::Handle<edm::View<reco::Candidate> >& particles, double globalThreshold, bool onlyFiducial, bool usePt)
33 {
34  double sum_et = 0.0;
35  double sum_ex = 0.0;
36  double sum_ey = 0.0;
37  double sum_ez = 0.0;
38 
39  for( edm::View<reco::Candidate>::const_iterator iParticle = (particles.product())->begin(); iParticle != (particles.product())->end(); ++iParticle)
40  {
41  if( (onlyFiducial && TMath::Abs(iParticle->eta()) >= 5.0)) continue;
42 
43  if( iParticle->et() <= globalThreshold ) continue;
44 
45  if(usePt)
46  {
47  double phi = iParticle->phi();
48  double et = iParticle->pt();
49  sum_ez += iParticle->pz();
50  sum_et += et;
51  sum_ex += et*cos(phi);
52  sum_ey += et*sin(phi);
53  }
54  else
55  {
56  double phi = iParticle->phi();
57  double theta = iParticle->theta();
58  double e = iParticle->energy();
59  double et = e*sin(theta);
60  sum_ez += e*cos(theta);
61  sum_et += et;
62  sum_ex += et*cos(phi);
63  sum_ey += et*sin(phi);
64  }
65  }
66 
67  met->mex = -sum_ex;
68  met->mey = -sum_ey;
69  met->mez = -sum_ez;
70  met->met = sqrt( sum_ex*sum_ex + sum_ey*sum_ey );
71  met->sumet = sum_et;
72  met->phi = atan2( -sum_ey, -sum_ex );
73 }
74 
75 //____________________________________________________________________________||
76 SpecificGenMETData GenSpecificAlgo::mkSpecificGenMETData(edm::Handle<edm::View<reco::Candidate> >& particles,double globalThreshold, bool onlyFiducial,bool applyFiducialThresholdForFractions, bool usePt)
77 {
78  const static int neutralEMpdgId[] = { 22 /* photon */ };
79  const static std::set<int> neutralEMpdgIdSet(neutralEMpdgId, neutralEMpdgId + sizeof(neutralEMpdgId)/sizeof(int));
80 
81  const static int chargedEMpdgId[] = { 11 /* e */ };
82  const static std::set<int> chargedEMpdgIdSet(chargedEMpdgId, chargedEMpdgId + sizeof(chargedEMpdgId)/sizeof(int));
83 
84  const static int muonpdgId[] = { 13 /* muon */ };
85  const static std::set<int> muonpdgIdSet(muonpdgId, muonpdgId + sizeof(muonpdgId)/sizeof(int));
86 
87  const static int neutralHADpdgId[] = {
88  130 /* K_long */,
89  310 /* K_short */,
90  3122 /* Lambda */,
91  2112 /* n */,
92  3222 /* Neutral Cascade */
93  };
94  const static std::set<int> neutralHADpdgIdSet(neutralHADpdgId, neutralHADpdgId + sizeof(neutralHADpdgId)/sizeof(int));
95 
96  const static int chargedHADpdgId[] = {
97  211 /* pi */,
98  321 /* K+/K- */,
99  2212 /* p */,
100  3312 /* Cascade - */,
101  3112 /* Sigma - */,
102  3322 /* Sigma + */,
103  3334 /* Omega - */
104  };
105  const static std::set<int> chargedHADpdgIdSet(chargedHADpdgId, chargedHADpdgId + sizeof(chargedHADpdgId)/sizeof(int));
106 
107  const static int invisiblepdgId[] = {
108  12 /* e_nu */,
109  14 /* mu_nu */,
110  16 /* tau_nu */,
111  1000022 /* Neutral ~Chi_0 */,
112  1000012 /* LH ~e_nu */,
113  1000014 /* LH ~mu_nu */,
114  1000016 /* LH ~tau_nu */,
115  2000012 /* RH ~e_nu */,
116  2000014 /* RH ~mu_nu */,
117  2000016 /* RH ~tau_nu */,
118  39 /* G */,
119  1000039 /* ~G */,
120  5100039 /* KK G */,
121  4000012 /* excited e_nu */,
122  4000014 /* excited mu_nu */,
123  4000016 /* excited tau_nu */,
124  9900012 /* Maj e_nu */,
125  9900014 /* Maj mu_nu */,
126  9900016 /* Maj tau_nu */,
127  };
128  const static std::set<int> invisiblepdgIdSet(invisiblepdgId, invisiblepdgId + sizeof(invisiblepdgId)/sizeof(int));
129 
131  specific.NeutralEMEtFraction = 0.0;
132  specific.NeutralHadEtFraction = 0.0;
133  specific.ChargedEMEtFraction = 0.0;
134  specific.ChargedHadEtFraction = 0.0;
135  specific.MuonEtFraction = 0.0;
136  specific.InvisibleEtFraction = 0.0;
137  double Et_unclassified = 0.0;
138 
139  for(edm::View<reco::Candidate>::const_iterator iParticle = (particles.product())->begin(); iParticle != (particles.product())->end(); ++iParticle)
140  {
141  if(applyFiducialThresholdForFractions) if( onlyFiducial && (TMath::Abs(iParticle->eta()) >= 5.0) ) continue;
142  if(applyFiducialThresholdForFractions) if( iParticle->et() <= globalThreshold ) continue;
143 
144  int pdgId = TMath::Abs( iParticle->pdgId() ) ;
145  double pt = (usePt) ? iParticle->pt() : iParticle->et();
146  if(neutralEMpdgIdSet.count(pdgId)) specific.NeutralEMEtFraction += pt;
147  else if(chargedEMpdgIdSet.count(pdgId)) specific.ChargedEMEtFraction += pt;
148  else if(muonpdgIdSet.count(pdgId)) specific.MuonEtFraction += pt;
149  else if(neutralHADpdgIdSet.count(pdgId)) specific.NeutralHadEtFraction += pt;
150  else if(chargedHADpdgIdSet.count(pdgId)) specific.ChargedHadEtFraction += pt;
151  else if(invisiblepdgIdSet.count(pdgId)) specific.InvisibleEtFraction += pt;
152  else Et_unclassified += pt;
153  }
154 
155  double Et_Total = specific.NeutralEMEtFraction + specific.NeutralHadEtFraction + specific.ChargedEMEtFraction +
156  specific.ChargedHadEtFraction + specific.MuonEtFraction + specific.InvisibleEtFraction + Et_unclassified;
157 
158  if(Et_Total)
159  {
160  specific.NeutralEMEtFraction /= Et_Total;
161  specific.NeutralHadEtFraction /= Et_Total;
162  specific.ChargedEMEtFraction /= Et_Total;
163  specific.ChargedHadEtFraction /= Et_Total;
164  specific.MuonEtFraction /= Et_Total;
165  specific.InvisibleEtFraction /= Et_Total;
166  }
167 
168  return specific;
169 }
170 
171 //____________________________________________________________________________||
dictionary specific
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
reco::GenMET addInfo(edm::Handle< edm::View< reco::Candidate > > particles, CommonMETData *met, double globalThreshold=0, bool onlyFiducial=false, bool applyFiducialThresholdForFractions=false, bool usePt=false)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
math::XYZPoint Point
Geom::Theta< T > theta() const
T sqrt(T t)
Definition: SSEVec.h:48
double p4[4]
Definition: TauolaWrapper.h:92
void fillCommonMETData(CommonMETData *met, edm::Handle< edm::View< reco::Candidate > > &particles, double globalThreshold, bool onlyFiducial, bool usePt)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
MET made from CaloTowers.
Structure containing data common to all types of MET.
Definition: CommonMETData.h:22
#define end
Definition: vmac.h:38
TLorentzVector genMet(const HepMC::GenEvent *all, double etamin=-9999., double etamax=9999.)
#define begin
Definition: vmac.h:31
SpecificGenMETData mkSpecificGenMETData(edm::Handle< edm::View< reco::Candidate > > &particles, double globalThreshold, bool onlyFiducial, bool applyFiducialThresholdForFractions, bool usePt)
math::XYZTLorentzVector LorentzVector
Definition: DDAxes.h:10