CMS 3D CMS Logo

CaloExtractor.cc
Go to the documentation of this file.
1 #include "CaloExtractor.h"
2 
6 
9 
10 using namespace edm;
11 using namespace std;
12 using namespace reco;
13 using namespace muonisolation;
15 
16 CaloExtractor::CaloExtractor(const ParameterSet& par, edm::ConsumesCollector&& iC)
17  : theCaloTowerCollectionToken(
18  iC.consumes<CaloTowerCollection>(par.getParameter<edm::InputTag>("CaloTowerCollectionLabel"))),
19  theDepositLabel(par.getUntrackedParameter<string>("DepositLabel")),
20  theCaloGeomToken(iC.esConsumes()),
21  theFieldToken(iC.esConsumes()),
22  theWeight_E(par.getParameter<double>("Weight_E")),
23  theWeight_H(par.getParameter<double>("Weight_H")),
24  theThreshold_E(par.getParameter<double>("Threshold_E")),
25  theThreshold_H(par.getParameter<double>("Threshold_H")),
26  theDR_Veto_E(par.getParameter<double>("DR_Veto_E")),
27  theDR_Veto_H(par.getParameter<double>("DR_Veto_H")),
28  theDR_Max(par.getParameter<double>("DR_Max")),
29  vertexConstraintFlag_XY(par.getParameter<bool>("Vertex_Constraint_XY")),
30  vertexConstraintFlag_Z(par.getParameter<bool>("Vertex_Constraint_Z")) {}
31 
34  const TrackCollection& muons) {
35  theVetoCollection.clear();
36 
38  event.getByToken(theCaloTowerCollectionToken, towers);
39 
40  auto const& caloGeom = eventSetup.getData(theCaloGeomToken);
41 
42  auto const& bField = eventSetup.getData(theFieldToken);
43  double bz = bField.inInverseGeV(GlobalPoint(0., 0., 0.)).z();
44 
45  TrackCollection::const_iterator mu;
46  TrackCollection::const_iterator muEnd(muons.end());
47 
50 
51  for (mu = muons.begin(); mu != muEnd; ++mu) {
52  for (cal = towers->begin(); cal != calEnd; ++cal) {
54  double dEta = fabs(mu->eta() - cal->eta());
55  if (fabs(dEta) > theDR_Max)
56  continue;
57 
58  double deltar0 = reco::deltaR(*mu, *cal);
59  if (deltar0 > theDR_Max)
60  continue;
61 
62  double etecal = cal->emEt();
63  double eecal = cal->emEnergy();
64  bool doEcal = theWeight_E > 0 && etecal > theThreshold_E && eecal > 3 * noiseEcal(*cal);
65  double ethcal = cal->hadEt();
66  double ehcal = cal->hadEnergy();
67  bool doHcal = theWeight_H > 0 && ethcal > theThreshold_H && ehcal > 3 * noiseHcal(*cal);
68  if ((!doEcal) && (!doHcal))
69  continue;
70 
71  DetId calId = cal->id();
72  GlobalPoint endpos = caloGeom.getPosition(calId);
74  double deltar = reco::deltaR(muatcal, endpos);
75 
76  if (doEcal) {
77  if (deltar < theDR_Veto_E)
78  theVetoCollection.push_back(calId);
79  } else {
80  if (deltar < theDR_Veto_H)
81  theVetoCollection.push_back(calId);
82  }
83  }
84  }
85 }
86 
88  IsoDeposit dep(muon.eta(), muon.phi());
89  LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
90  << " >>> Muon: pt " << muon.pt() << " eta " << muon.eta() << " phi " << muon.phi();
91 
93  event.getByToken(theCaloTowerCollectionToken, towers);
94 
95  auto const& caloGeom = eventSetup.getData(theCaloGeomToken);
96 
97  auto const& bField = eventSetup.getData(theFieldToken);
98  double bz = bField.inInverseGeV(GlobalPoint(0., 0., 0.)).z();
99 
102  for (cal = towers->begin(); cal != calEnd; ++cal) {
104  double dEta = fabs(muon.eta() - cal->eta());
105  if (fabs(dEta) > theDR_Max)
106  continue;
107 
108  double deltar0 = reco::deltaR(muon, *cal);
109  if (deltar0 > theDR_Max)
110  continue;
111 
112  double etecal = cal->emEt();
113  double eecal = cal->emEnergy();
114  bool doEcal = theWeight_E > 0 && etecal > theThreshold_E && eecal > 3 * noiseEcal(*cal);
115  double ethcal = cal->hadEt();
116  double ehcal = cal->hadEnergy();
117  bool doHcal = theWeight_H > 0 && ethcal > theThreshold_H && ehcal > 3 * noiseHcal(*cal);
118  if ((!doEcal) && (!doHcal))
119  continue;
120 
121  DetId calId = cal->id();
122  GlobalPoint endpos = caloGeom.getPosition(calId);
124  double deltar = reco::deltaR(muatcal, endpos);
125 
126  if (deltar < theDR_Veto_H) {
127  dep.setVeto(IsoDeposit::Veto(reco::isodeposit::Direction(muatcal.eta(), muatcal.phi()), theDR_Veto_H));
128  }
129 
130  if (doEcal) {
131  if (deltar < theDR_Veto_E) {
132  double calodep = theWeight_E * etecal;
133  if (doHcal)
134  calodep += theWeight_H * ethcal;
135  dep.addCandEnergy(calodep);
136  LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
137  << " >>> Calo deposit inside veto (with ECAL): deltar " << deltar << " calodep " << calodep << " ecaldep "
138  << etecal << " hcaldep " << ethcal << " eta " << cal->eta() << " phi " << cal->phi();
139  continue;
140  }
141  } else {
142  if (deltar < theDR_Veto_H) {
143  dep.addCandEnergy(theWeight_H * ethcal);
144  LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
145  << " >>> Calo deposit inside veto (no ECAL): deltar " << deltar << " calodep " << theWeight_H * ethcal
146  << " eta " << cal->eta() << " phi " << cal->phi();
147  continue;
148  }
149  }
150 
151  if (std::find(theVetoCollection.begin(), theVetoCollection.end(), calId) != theVetoCollection.end()) {
152  LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
153  << " >>> Deposits belongs to other track: deltar, etecal, ethcal= " << deltar << ", " << etecal << ", "
154  << ethcal;
155  continue;
156  }
157 
158  if (doEcal) {
159  if (deltar > theDR_Veto_E) {
160  double calodep = theWeight_E * etecal;
161  if (doHcal)
162  calodep += theWeight_H * ethcal;
163  dep.addDeposit(reco::isodeposit::Direction(endpos.eta(), endpos.phi()), calodep);
164  LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
165  << " >>> Calo deposit (with ECAL): deltar " << deltar << " calodep " << calodep << " ecaldep " << etecal
166  << " hcaldep " << ethcal << " eta " << cal->eta() << " phi " << cal->phi();
167  }
168  } else {
169  if (deltar > theDR_Veto_H) {
170  dep.addDeposit(reco::isodeposit::Direction(endpos.eta(), endpos.phi()), theWeight_H * ethcal);
171  LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
172  << " >>> Calo deposit (no ECAL): deltar " << deltar << " calodep " << theWeight_H * ethcal << " eta "
173  << cal->eta() << " phi " << cal->phi();
174  }
175  }
176  }
177 
178  return dep;
179 }
180 
182  const Track& muon, const double bz, const GlobalPoint& endpos, bool fixVxy, bool fixVz) {
183  double qoverp = muon.qoverp();
184  double cur = bz * muon.charge() / muon.pt();
185  double phi0 = muon.phi();
186  double dca = muon.dxy();
187  double theta = muon.theta();
188  double dz = muon.dz();
189 
190  //LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
191  //<< " Pt(GeV): " << muon.pt()
192  //<< ", phi0 " << muon.phi0()
193  //<< ", eta " << muon.eta();
194  //LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
195  //<< " d0 " << muon.d0()
196  //<< ", dz " << muon.dz();
197  //LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
198  //<< " rhocal " << endpos.perp()
199  //<< ", zcal " << endpos.z();
200 
201  if (fixVxy && fixVz) {
202  // Note that here we assume no correlation between XY and Z projections
203  // This should be a reasonable approximation for our purposes
204  double errd02 = muon.covariance(muon.i_dxy, muon.i_dxy);
205  if (pow(muon.dxy(), 2) < 4 * errd02) {
206  phi0 -= muon.dxy() * muon.covariance(muon.i_dxy, muon.i_phi) / errd02;
207  cur -= muon.dxy() * muon.covariance(muon.i_dxy, muon.i_qoverp) / errd02 * (cur / qoverp);
208  dca = 0;
209  }
210  double errdsz2 = muon.covariance(muon.i_dsz, muon.i_dsz);
211  if (pow(muon.dsz(), 2) < 4 * errdsz2) {
212  theta += muon.dsz() * muon.covariance(muon.i_dsz, muon.i_lambda) / errdsz2;
213  dz = 0;
214  }
215  } else if (fixVxy) {
216  double errd02 = muon.covariance(muon.i_dxy, muon.i_dxy);
217  if (pow(muon.dxy(), 2) < 4 * errd02) {
218  phi0 -= muon.dxy() * muon.covariance(muon.i_dxy, muon.i_phi) / errd02;
219  cur -= muon.dxy() * muon.covariance(muon.i_dxy, muon.i_qoverp) / errd02 * (cur / qoverp);
220  theta += muon.dxy() * muon.covariance(muon.i_dxy, muon.i_lambda) / errd02;
221  dz -= muon.dxy() * muon.covariance(muon.i_dxy, muon.i_dsz) / errd02 * muon.p() / muon.pt();
222  dca = 0;
223  }
224  } else if (fixVz) {
225  double errdsz2 = muon.covariance(muon.i_dsz, muon.i_dsz);
226  if (pow(muon.dsz(), 2) < 4 * errdsz2) {
227  theta += muon.dsz() * muon.covariance(muon.i_dsz, muon.i_lambda) / errdsz2;
228  phi0 -= muon.dsz() * muon.covariance(muon.i_dsz, muon.i_phi) / errdsz2;
229  cur -= muon.dsz() * muon.covariance(muon.i_dsz, muon.i_qoverp) / errdsz2 * (cur / qoverp);
230  dca -= muon.dsz() * muon.covariance(muon.i_dsz, muon.i_dxy) / errdsz2;
231  dz = 0;
232  }
233  }
234 
235  double sphi0 = sin(phi0);
236  double cphi0 = cos(phi0);
237 
238  double xsin = endpos.x() * sphi0 - endpos.y() * cphi0;
239  double xcos = endpos.x() * cphi0 + endpos.y() * sphi0;
240  double fcdca = fabs(1 - cur * dca);
241  double phif = atan2(fcdca * sphi0 - cur * endpos.x(), fcdca * cphi0 + cur * endpos.y());
242  double tphif2 = tan(0.5 * (phif - phi0));
243  double dcaf = dca + xsin + xcos * tphif2;
244 
245  double x = endpos.x() - dcaf * sin(phif);
246  double y = endpos.y() + dcaf * cos(phif);
247 
248  double deltas = (x - muon.vx()) * cphi0 + (y - muon.vy()) * sphi0;
249  double deltaphi = normalizedPhi(phif - phi0);
250  if (deltaphi != 0)
251  deltas = deltas * deltaphi / sin(deltaphi);
252 
253  double z = dz;
254  double tantheta = tan(theta);
255  if (tantheta != 0) {
256  z += deltas / tan(theta);
257  } else {
258  z = endpos.z();
259  }
260 
261  return GlobalPoint(x, y, z);
262 }
263 
265  double noise = 0.04;
266  double eta = tower.eta();
267  if (fabs(eta) > 1.479)
268  noise = 0.15;
269  return noise;
270 }
271 
273  double noise = 0.2;
274  return noise;
275 }
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T z() const
Definition: PV3DBase.h:61
double noiseEcal(const CaloTower &tower) const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
constexpr T normalizedPhi(T phi)
Definition: normalizedPhi.h:8
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > theCaloGeomToken
Definition: CaloExtractor.h:48
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
T eta() const
Definition: PV3DBase.h:73
edm::EDGetTokenT< CaloTowerCollection > theCaloTowerCollectionToken
Definition: CaloExtractor.h:43
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::vector< CaloTower >::const_iterator const_iterator
constexpr int pow(int x)
Definition: conifer.h:24
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
double noiseHcal(const CaloTower &tower) const
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
reco::IsoDeposit deposit(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &track) const override
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
Definition: DetId.h:17
Definition: deltar.py:1
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > theFieldToken
Definition: CaloExtractor.h:49
static GlobalPoint MuonAtCaloPosition(const reco::Track &muon, const double bz, const GlobalPoint &endpos, bool fixVxy=false, bool fixVz=false)
Extrapolate muons to calorimeter-object positions.
fixed size matrix
HLT enums.
float x
void fillVetos(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::TrackCollection &tracks) override
Geom::Theta< T > theta() const
Definition: event.py:1
#define LogDebug(id)
std::vector< DetId > theVetoCollection
Definition: CaloExtractor.h:63