CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloSpecificAlgo.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: METAlgorithms
4 // Class: CaloSpecificAlgo
5 //
6 // Original Author: R. Cavanaugh (taken from F.Ratnikov, UMd)
7 // Created: June 6, 2006
8 //
9 //
14 
15 #include <iostream>
16 
17 using namespace reco;
18 
19 //____________________________________________________________________________||
20 // This algorithm adds calorimeter specific global event information to
21 // the MET object which may be useful/needed for MET Data Quality Monitoring
22 // and MET cleaning.
23 //____________________________________________________________________________||
24 
25 //____________________________________________________________________________||
26 reco::CaloMET CaloSpecificAlgo::addInfo(edm::Handle<edm::View<Candidate> > towers, const CommonMETData& umet, bool noHF, double globalThreshold)
27 {
29  initializeSpecificCaloMETData(specific);
30  CommonMETData met = umet;
31  double totalEt = 0.0;
32  double totalEm = 0.0;
33 
34  double sumEtInpHF = 0.0;
35  double sumEtInmHF = 0.0;
36  double MExInpHF = 0.0;
37  double MEyInpHF = 0.0;
38  double MExInmHF = 0.0;
39  double MEyInmHF = 0.0;
40 
41  for(edm::View<Candidate>::const_iterator towerCand = towers->begin(); towerCand != towers->end(); ++towerCand )
42  {
43  const CaloTower* calotower = dynamic_cast<const CaloTower*> (&(*towerCand));
44  if (!calotower) continue;
45  if(calotower->et() < globalThreshold) continue;
46  update_totalEt_totalEm(totalEt, totalEm, calotower, noHF);
47  update_MaxTowerEm_MaxTowerHad(specific.MaxEtInEmTowers, specific.MaxEtInHadTowers, calotower, noHF);
48  update_EmEtInEB_EmEtInEE(specific.EmEtInEB, specific.EmEtInEE, calotower);
49  update_HadEtInHB_HadEtInHE_HadEtInHO_HadEtInHF_EmEtInHF(specific.HadEtInHB, specific.HadEtInHE, specific.HadEtInHO, specific.HadEtInHF, specific.EmEtInHF, calotower, noHF);
50  update_sumEtInpHF_MExInpHF_MEyInpHF_sumEtInmHF_MExInmHF_MEyInmHF(sumEtInpHF, MExInpHF, MEyInpHF, sumEtInmHF, MExInmHF, MEyInmHF, calotower);
51  }
52 
53  double totalHad = totalEt - totalEm;
54 
55  if(noHF) remove_HF_from_MET(met, sumEtInpHF, MExInpHF, MEyInpHF, sumEtInmHF, MExInmHF, MEyInmHF);
56 
57  if(!noHF) add_MET_in_HF(specific, sumEtInpHF, MExInpHF, MEyInpHF, sumEtInmHF, MExInmHF, MEyInmHF);
58 
59  specific.EtFractionHadronic = (totalEt == 0.0)? 0.0 : totalHad/totalEt;
60  specific.EtFractionEm = (totalEt == 0.0)? 0.0 : totalEm/totalEt;
61 
62  const LorentzVector p4( met.mex, met.mey, 0.0, met.met);
63  const Point vtx(0.0, 0.0, 0.0);
64  CaloMET caloMET(specific, met.sumet, p4, vtx);
65  return caloMET;
66 }
67 
68 //____________________________________________________________________________||
70 {
71  specific.MaxEtInEmTowers = 0.0; // Maximum energy in EM towers
72  specific.MaxEtInHadTowers = 0.0; // Maximum energy in HCAL towers
73  specific.HadEtInHO = 0.0; // Hadronic energy fraction in HO
74  specific.HadEtInHB = 0.0; // Hadronic energy in HB
75  specific.HadEtInHF = 0.0; // Hadronic energy in HF
76  specific.HadEtInHE = 0.0; // Hadronic energy in HE
77  specific.EmEtInEB = 0.0; // Em energy in EB
78  specific.EmEtInEE = 0.0; // Em energy in EE
79  specific.EmEtInHF = 0.0; // Em energy in HF
80  specific.EtFractionHadronic = 0.0; // Hadronic energy fraction
81  specific.EtFractionEm = 0.0; // Em energy fraction
82  specific.METSignificance = 0.0;
83  specific.CaloMETInpHF = 0.0; // CaloMET in HF+
84  specific.CaloMETInmHF = 0.0; // CaloMET in HF-
85  specific.CaloSETInpHF = 0.0; // CaloSET in HF+
86  specific.CaloSETInmHF = 0.0; // CaloSET in HF-
87  specific.CaloMETPhiInpHF = 0.0; // CaloMET-phi in HF+
88  specific.CaloMETPhiInmHF = 0.0; // CaloMET-phi in HF-
89 }
90 
91 //____________________________________________________________________________||
92 void CaloSpecificAlgo::update_totalEt_totalEm(double &totalEt, double& totalEm, const CaloTower* calotower, bool noHF)
93 {
94  if( noHF )
95  {
96  DetId detIdHcal = find_DetId_of_HCAL_cell_in_constituent_of(calotower);
97  if(!detIdHcal.null())
98  {
99  HcalSubdetector subdet = HcalDetId(detIdHcal).subdet();
100  if( subdet == HcalForward ) return;
101  }
102  }
103 
104  totalEt += calotower->et();
105  totalEm += calotower->emEt();
106 }
107 
108 //____________________________________________________________________________||
109 void CaloSpecificAlgo::update_MaxTowerEm_MaxTowerHad(double &MaxTowerEm, double &MaxTowerHad, const CaloTower* calotower, bool noHF)
110 {
111  DetId detIdHcal = find_DetId_of_HCAL_cell_in_constituent_of(calotower);
112  DetId detIdEcal = find_DetId_of_ECAL_cell_in_constituent_of(calotower);
113 
114  if( !detIdHcal.null() )
115  {
116  HcalSubdetector subdet = HcalDetId(detIdHcal).subdet();
117  if( subdet == HcalBarrel || subdet == HcalOuter || subdet == HcalEndcap || (!noHF && subdet == HcalForward))
118  {
119  if( calotower->hadEt() > MaxTowerHad ) MaxTowerHad = calotower->hadEt();
120  if( calotower->emEt() > MaxTowerEm ) MaxTowerEm = calotower->emEt();
121  }
122 
123  }
124 
125  if( !detIdEcal.null() )
126  {
127  if( calotower->emEt() > MaxTowerEm ) MaxTowerEm = calotower->emEt();
128  }
129 }
130 
131 //____________________________________________________________________________||
132 void CaloSpecificAlgo::update_EmEtInEB_EmEtInEE(double &EmEtInEB, double &EmEtInEE, const CaloTower* calotower)
133 {
134  DetId detIdEcal = find_DetId_of_ECAL_cell_in_constituent_of(calotower);
135  if(detIdEcal.null()) return;
136 
137  EcalSubdetector subdet = EcalSubdetector( detIdEcal.subdetId() );
138  if( subdet == EcalBarrel )
139  {
140  EmEtInEB += calotower->emEt();
141  }
142  else if( subdet == EcalEndcap )
143  {
144  EmEtInEE += calotower->emEt();
145  }
146 }
147 
148 //____________________________________________________________________________||
149 void CaloSpecificAlgo::update_HadEtInHB_HadEtInHE_HadEtInHO_HadEtInHF_EmEtInHF(double &HadEtInHB, double &HadEtInHE, double &HadEtInHO, double &HadEtInHF, double &EmEtInHF, const CaloTower* calotower, bool noHF)
150 {
151  DetId detIdHcal = find_DetId_of_HCAL_cell_in_constituent_of(calotower);
152  if(detIdHcal.null()) return;
153 
154  HcalSubdetector subdet = HcalDetId(detIdHcal).subdet();
155  if( subdet == HcalBarrel || subdet == HcalOuter )
156  {
157  HadEtInHB += calotower->hadEt();
158  HadEtInHO += calotower->outerEt();
159  }
160 
161  if( subdet == HcalEndcap )
162  {
163  HadEtInHE += calotower->hadEt();
164  }
165 
166  if( subdet == HcalForward && !noHF)
167  {
168  HadEtInHF += calotower->hadEt();
169  EmEtInHF += calotower->emEt();
170  }
171 }
172 
173 //____________________________________________________________________________||
174 void CaloSpecificAlgo::update_sumEtInpHF_MExInpHF_MEyInpHF_sumEtInmHF_MExInmHF_MEyInmHF(double &sumEtInpHF, double &MExInpHF, double &MEyInpHF, double &sumEtInmHF, double &MExInmHF, double &MEyInmHF, const CaloTower* calotower)
175 {
176  DetId detIdHcal = find_DetId_of_HCAL_cell_in_constituent_of(calotower);
177  if(detIdHcal.null()) return;
178 
179  HcalSubdetector subdet = HcalDetId(detIdHcal).subdet();
180  if( !(subdet == HcalForward) ) return;
181 
182  if (calotower->eta() >= 0)
183  {
184  sumEtInpHF += calotower->et();
185  MExInpHF -= (calotower->et() * cos(calotower->phi()));
186  MEyInpHF -= (calotower->et() * sin(calotower->phi()));
187  }
188  else
189  {
190  sumEtInmHF += calotower->et();
191  MExInmHF -= (calotower->et() * cos(calotower->phi()));
192  MEyInmHF -= (calotower->et() * sin(calotower->phi()));
193  }
194 }
195 
196 //____________________________________________________________________________||
197 void CaloSpecificAlgo::remove_HF_from_MET(CommonMETData &met, double sumEtInpHF, double MExInpHF, double MEyInpHF, double sumEtInmHF, double MExInmHF, double MEyInmHF)
198 {
199  met.mex -= (MExInmHF + MExInpHF);
200  met.mey -= (MEyInmHF + MEyInpHF);
201  met.sumet -= (sumEtInpHF + sumEtInmHF);
202  met.met = sqrt(met.mex*met.mex + met.mey*met.mey);
203 }
204 
205 //____________________________________________________________________________||
206 void CaloSpecificAlgo::add_MET_in_HF(SpecificCaloMETData &specific, double sumEtInpHF, double MExInpHF, double MEyInpHF, double sumEtInmHF, double MExInmHF, double MEyInmHF)
207 {
208  LorentzVector METpHF(MExInpHF, MEyInpHF, 0, sqrt(MExInpHF*MExInpHF + MEyInpHF*MEyInpHF));
209  LorentzVector METmHF(MExInmHF, MEyInmHF, 0, sqrt(MExInmHF*MExInmHF + MEyInmHF*MEyInmHF));
210  specific.CaloMETInpHF = METpHF.pt();
211  specific.CaloMETInmHF = METmHF.pt();
212  specific.CaloMETPhiInpHF = METpHF.Phi();
213  specific.CaloMETPhiInmHF = METmHF.Phi();
214  specific.CaloSETInpHF = sumEtInpHF;
215  specific.CaloSETInmHF = sumEtInmHF;
216 }
217 
218 //____________________________________________________________________________||
220 {
221  DetId ret;
222  for (int cell = calotower->constituentsSize() - 1; cell >= 0; --cell)
223  {
224  DetId id = calotower->constituent( cell );
225  if( id.det() == DetId::Hcal )
226  {
227  ret = id;
228  break;
229  }
230  }
231  return ret;
232 }
233 
234 //____________________________________________________________________________||
236 {
237  DetId ret;
238  for (int cell = calotower->constituentsSize() - 1; cell >= 0; --cell)
239  {
240  DetId id = calotower->constituent( cell );
241  if( id.det() == DetId::Ecal )
242  {
243  ret = id;
244  break;
245  }
246  }
247  return ret;
248 }
249 
250 //____________________________________________________________________________||
DetId find_DetId_of_HCAL_cell_in_constituent_of(const CaloTower *calotower)
void initializeSpecificCaloMETData(SpecificCaloMETData &specific)
dictionary specific
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
void remove_HF_from_MET(CommonMETData &met, double sumEtInpHF, double MExInpHF, double MEyInpHF, double sumEtInmHF, double MExInmHF, double MEyInmHF)
tuple met
____________________________________________________________________________||
Definition: CaloMET_cfi.py:7
size_t constituentsSize() const
Definition: CaloTower.h:72
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:30
void update_HadEtInHB_HadEtInHE_HadEtInHO_HadEtInHF_EmEtInHF(double &HadEtInHB, double &HadEtInHE, double &HadEtInHO, double &HadEtInHF, double &EmEtInHF, const CaloTower *calotower, bool noHF)
void add_MET_in_HF(SpecificCaloMETData &specific, double sumEtInpHF, double MExInpHF, double MEyInpHF, double sumEtInmHF, double MExInmHF, double MEyInmHF)
DetId constituent(size_t i) const
Definition: CaloTower.h:73
double hadEt() const
Definition: CaloTower.h:83
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
double outerEt() const
Definition: CaloTower.h:84
void update_EmEtInEB_EmEtInEE(double &EmEtInEB, double &EmEtInEE, const CaloTower *calotower)
void update_MaxTowerEm_MaxTowerHad(double &MaxTowerEm, double &MaxTowerHad, const CaloTower *calotower, bool noHF)
MET made from CaloTowers.
void update_totalEt_totalEm(double &totalEt, double &totalEm, const CaloTower *calotower, bool noHF)
virtual float phi() const GCC11_FINAL
momentum azimuthal angle
void update_sumEtInpHF_MExInpHF_MEyInpHF_sumEtInmHF_MExInmHF_MEyInmHF(double &sumEtInpHF, double &MExInpHF, double &MEyInpHF, double &sumEtInmHF, double &MExInmHF, double &MEyInmHF, const CaloTower *calotower)
T sqrt(T t)
Definition: SSEVec.h:48
double p4[4]
Definition: TauolaWrapper.h:92
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
HcalSubdetector
Definition: HcalAssistant.h:31
Structure containing data common to all types of MET.
Definition: CommonMETData.h:12
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
Definition: DetId.h:18
reco::CaloMET addInfo(edm::Handle< edm::View< reco::Candidate > > towers, const CommonMETData &met, bool noHF, double globalThreshold)
bool null() const
is this a null id ?
Definition: DetId.h:45
math::XYZTLorentzVector LorentzVector
math::XYZPoint Point
double et(double vtxZ) const
Definition: CaloTower.h:99
EcalSubdetector
double emEt() const
Definition: CaloTower.h:82
DetId find_DetId_of_ECAL_cell_in_constituent_of(const CaloTower *calotower)