CMS 3D CMS Logo

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