CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloExtractor.cc
Go to the documentation of this file.
1 #include "CaloExtractor.h"
2 
9 
12 
17 //#include "CommonTools/Utils/interface/deltaR.h"
18 //#include "PhysicsTools/Utilities/interface/deltaR.h"
20 //#include "PhysicsTools/Utilities/interface/normalizedPhi.h"
21 
22 using namespace edm;
23 using namespace std;
24 using namespace reco;
25 using namespace muonisolation;
27 
28 CaloExtractor::CaloExtractor(const ParameterSet& par) :
29  theCaloTowerCollectionLabel(par.getParameter<edm::InputTag>("CaloTowerCollectionLabel")),
30  theDepositLabel(par.getUntrackedParameter<string>("DepositLabel")),
31  theWeight_E(par.getParameter<double>("Weight_E")),
32  theWeight_H(par.getParameter<double>("Weight_H")),
33  theThreshold_E(par.getParameter<double>("Threshold_E")),
34  theThreshold_H(par.getParameter<double>("Threshold_H")),
35  theDR_Veto_E(par.getParameter<double>("DR_Veto_E")),
36  theDR_Veto_H(par.getParameter<double>("DR_Veto_H")),
37  theDR_Max(par.getParameter<double>("DR_Max")),
38  vertexConstraintFlag_XY(par.getParameter<bool>("Vertex_Constraint_XY")),
39  vertexConstraintFlag_Z(par.getParameter<bool>("Vertex_Constraint_Z"))
40 {
41 }
42 
44 {
45  theVetoCollection.clear();
46 
48  event.getByLabel(theCaloTowerCollectionLabel,towers);
49 
51  eventSetup.get<CaloGeometryRecord>().get(caloGeom);
52 
54  eventSetup.get<IdealMagneticFieldRecord>().get(bField);
55  double bz = bField->inInverseGeV(GlobalPoint(0.,0.,0.)).z();
56 
57  TrackCollection::const_iterator mu;
58  TrackCollection::const_iterator muEnd(muons.end());
59 
61  CaloTowerCollection::const_iterator calEnd(towers->end());
62 
63  for ( mu = muons.begin(); mu != muEnd; ++mu ) {
64  for ( cal = towers->begin(); cal != calEnd; ++cal ) {
66  double dEta = fabs(mu->eta()-cal->eta());
67  if (fabs(dEta) > theDR_Max) continue;
68 
69  double deltar0 = reco::deltaR(*mu,*cal);
70  if (deltar0>theDR_Max) continue;
71 
72  double etecal = cal->emEt();
73  double eecal = cal->emEnergy();
74  bool doEcal = theWeight_E>0 && etecal>theThreshold_E && eecal>3*noiseEcal(*cal);
75  double ethcal = cal->hadEt();
76  double ehcal = cal->hadEnergy();
77  bool doHcal = theWeight_H>0 && ethcal>theThreshold_H && ehcal>3*noiseHcal(*cal);
78  if ((!doEcal) && (!doHcal)) continue;
79 
80  DetId calId = cal->id();
81  GlobalPoint endpos = caloGeom->getPosition(calId);
83  double deltar = reco::deltaR(muatcal,endpos);
84 
85  if (doEcal) {
86  if (deltar<theDR_Veto_E) theVetoCollection.push_back(calId);
87  } else {
88  if (deltar<theDR_Veto_H) theVetoCollection.push_back(calId);
89  }
90  }
91  }
92 
93 }
94 
95 IsoDeposit CaloExtractor::deposit( const Event & event, const EventSetup& eventSetup, const Track & muon) const
96 {
97  IsoDeposit dep(muon.eta(), muon.phi() );
98  LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
99  << " >>> Muon: pt " << muon.pt()
100  << " eta " << muon.eta()
101  << " phi " << muon.phi();
102 
104  event.getByLabel(theCaloTowerCollectionLabel,towers);
105 
107  eventSetup.get<CaloGeometryRecord>().get(caloGeom);
108 
110  eventSetup.get<IdealMagneticFieldRecord>().get(bField);
111  double bz = bField->inInverseGeV(GlobalPoint(0.,0.,0.)).z();
112 
114  CaloTowerCollection::const_iterator calEnd(towers->end());
115  for ( cal = towers->begin(); cal != calEnd; ++cal ) {
117  double dEta = fabs(muon.eta()-cal->eta());
118  if (fabs(dEta) > theDR_Max) continue;
119 
120  double deltar0 = reco::deltaR(muon,*cal);
121  if (deltar0>theDR_Max) continue;
122 
123  double etecal = cal->emEt();
124  double eecal = cal->emEnergy();
125  bool doEcal = theWeight_E>0 && etecal>theThreshold_E && eecal>3*noiseEcal(*cal);
126  double ethcal = cal->hadEt();
127  double ehcal = cal->hadEnergy();
128  bool doHcal = theWeight_H>0 && ethcal>theThreshold_H && ehcal>3*noiseHcal(*cal);
129  if ((!doEcal) && (!doHcal)) continue;
130 
131  DetId calId = cal->id();
132  GlobalPoint endpos = caloGeom->getPosition(calId);
134  double deltar = reco::deltaR(muatcal,endpos);
135 
136  if (deltar<theDR_Veto_H) {
137  dep.setVeto(IsoDeposit::Veto(reco::isodeposit::Direction(muatcal.eta(), muatcal.phi()), theDR_Veto_H));
138  }
139 
140  if (doEcal) {
141  if (deltar<theDR_Veto_E) {
142  double calodep = theWeight_E*etecal;
143  if (doHcal) calodep += theWeight_H*ethcal;
144  dep.addCandEnergy(calodep);
145  LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
146  << " >>> Calo deposit inside veto (with ECAL): deltar " << deltar
147  << " calodep " << calodep
148  << " ecaldep " << etecal
149  << " hcaldep " << ethcal
150  << " eta " << cal->eta()
151  << " phi " << cal->phi();
152  continue;
153  }
154  } else {
155  if (deltar<theDR_Veto_H) {
156  dep.addCandEnergy(theWeight_H*ethcal);
157  LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
158  << " >>> Calo deposit inside veto (no ECAL): deltar " << deltar
159  << " calodep " << theWeight_H*ethcal
160  << " eta " << cal->eta()
161  << " phi " << cal->phi();
162  continue;
163  }
164  }
165 
167  , calId)!=theVetoCollection.end()) {
168  LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
169  << " >>> Deposits belongs to other track: deltar, etecal, ethcal= "
170  << deltar << ", " << etecal << ", " << ethcal;
171  continue;
172  }
173 
174  if (doEcal) {
175  if (deltar>theDR_Veto_E) {
176  double calodep = theWeight_E*etecal;
177  if (doHcal) calodep += theWeight_H*ethcal;
178  dep.addDeposit(reco::isodeposit::Direction(endpos.eta(), endpos.phi()),calodep);
179  LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
180  << " >>> Calo deposit (with ECAL): deltar " << deltar
181  << " calodep " << calodep
182  << " ecaldep " << etecal
183  << " hcaldep " << ethcal
184  << " eta " << cal->eta()
185  << " phi " << cal->phi();
186  }
187  } else {
188  if (deltar>theDR_Veto_H) {
189  dep.addDeposit(reco::isodeposit::Direction(endpos.eta(), endpos.phi()),theWeight_H*ethcal);
190  LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
191  << " >>> Calo deposit (no ECAL): deltar " << deltar
192  << " calodep " << theWeight_H*ethcal
193  << " eta " << cal->eta()
194  << " phi " << cal->phi();
195  }
196  }
197  }
198 
199  return dep;
200 
201 }
202 
203 GlobalPoint CaloExtractor::MuonAtCaloPosition(const Track& muon, const double bz, const GlobalPoint& endpos, bool fixVxy, bool fixVz) {
204  double qoverp= muon.qoverp();
205  double cur = bz*muon.charge()/muon.pt();
206  double phi0 = muon.phi();
207  double dca = muon.dxy();
208  double theta = muon.theta();
209  double dz = muon.dz();
210 
211  //LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
212  //<< " Pt(GeV): " << muon.pt()
213  //<< ", phi0 " << muon.phi0()
214  //<< ", eta " << muon.eta();
215  //LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
216  //<< " d0 " << muon.d0()
217  //<< ", dz " << muon.dz();
218  //LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
219  //<< " rhocal " << endpos.perp()
220  //<< ", zcal " << endpos.z();
221 
222  if (fixVxy && fixVz) {
223  // Note that here we assume no correlation between XY and Z projections
224  // This should be a reasonable approximation for our purposes
225  double errd02 = muon.covariance(muon.i_dxy,muon.i_dxy);
226  if (pow(muon.dxy(),2)<4*errd02) {
227  phi0 -= muon.dxy()*muon.covariance(muon.i_dxy,muon.i_phi)
228  /errd02;
229  cur -= muon.dxy()*muon.covariance(muon.i_dxy,muon.i_qoverp)
230  /errd02 * (cur/qoverp);
231  dca = 0;
232  }
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)
236  /errdsz2;
237  dz = 0;
238  }
239  } else if (fixVxy) {
240  double errd02 = muon.covariance(muon.i_dxy,muon.i_dxy);
241  if (pow(muon.dxy(),2)<4*errd02) {
242  phi0 -= muon.dxy()*muon.covariance(muon.i_dxy,muon.i_phi)
243  /errd02;
244  cur -= muon.dxy()*muon.covariance(muon.i_dxy,muon.i_qoverp)
245  /errd02 * (cur/qoverp);
246  theta += muon.dxy()*muon.covariance(muon.i_dxy,muon.i_lambda)
247  /errd02;
248  dz -= muon.dxy()*muon.covariance(muon.i_dxy,muon.i_dsz)
249  /errd02 * muon.p()/muon.pt();
250  dca = 0;
251  }
252  } else if (fixVz) {
253  double errdsz2 = muon.covariance(muon.i_dsz,muon.i_dsz);
254  if (pow(muon.dsz(),2)<4*errdsz2) {
255  theta += muon.dsz()*muon.covariance(muon.i_dsz,muon.i_lambda)
256  /errdsz2;
257  phi0 -= muon.dsz()*muon.covariance(muon.i_dsz,muon.i_phi)
258  /errdsz2;
259  cur -= muon.dsz()*muon.covariance(muon.i_dsz,muon.i_qoverp)
260  /errdsz2 * (cur/qoverp);
261  dca -= muon.dsz()*muon.covariance(muon.i_dsz,muon.i_dxy)
262  /errdsz2;
263  dz = 0;
264  }
265  }
266 
267  double sphi0 = sin(phi0);
268  double cphi0 = cos(phi0);
269 
270  double xsin = endpos.x()*sphi0 - endpos.y()*cphi0;
271  double xcos = endpos.x()*cphi0 + endpos.y()*sphi0;
272  double fcdca = fabs(1-cur*dca);
273  double phif = atan2( fcdca*sphi0-cur*endpos.x()
274  , fcdca*cphi0+cur*endpos.y());
275  double tphif2 = tan(0.5*(phif-phi0));
276  double dcaf = dca + xsin + xcos*tphif2;
277 
278  double x = endpos.x() - dcaf*sin(phif);
279  double y = endpos.y() + dcaf*cos(phif);
280 
281  double deltas = (x-muon.vx())*cphi0 + (y-muon.vy())*sphi0;
282  double deltaphi = normalizedPhi(phif-phi0);
283  if (deltaphi!=0) deltas = deltas*deltaphi/sin(deltaphi);
284 
285  double z =dz;
286  double tantheta = tan(theta);
287  if (tantheta!=0) {
288  z += deltas/tan(theta);
289  } else {
290  z = endpos.z();
291  }
292 
293  return GlobalPoint(x,y,z);
294 }
295 
296 double CaloExtractor::noiseEcal(const CaloTower& tower) const {
297  double noise = 0.04;
298  double eta = tower.eta();
299  if (fabs(eta)>1.479) noise = 0.15;
300  return noise;
301 }
302 
303 double CaloExtractor::noiseHcal(const CaloTower& tower) const {
304  double noise = 0.2;
305  return noise;
306 }
#define LogDebug(id)
double qoverp() const
q/p
Definition: TrackBase.h:115
double p() const
momentum vector magnitude
Definition: TrackBase.h:129
virtual reco::IsoDeposit deposit(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &track) const
double theta() const
polar angle
Definition: TrackBase.h:117
virtual void fillVetos(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::TrackCollection &tracks)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
double noiseEcal(const CaloTower &tower) const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
std::vector< CaloTower >::const_iterator const_iterator
Geom::Theta< T > theta() const
T y() const
Definition: PV3DBase.h:63
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:139
edm::InputTag theCaloTowerCollectionLabel
Definition: CaloExtractor.h:35
T eta() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
double dsz() const
dsz parameter (THIS IS NOT the SZ impact parameter to (0,0,0) if refPoint is far from (0...
Definition: TrackBase.h:125
float float float z
CovarianceMatrix covariance() const
return track covariance matrix
Definition: TrackBase.h:182
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:141
double pt() const
track transverse momentum
Definition: TrackBase.h:131
T z() const
Definition: PV3DBase.h:64
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
double noiseHcal(const CaloTower &tower) const
const int mu
Definition: Constants.h:23
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:127
Definition: DetId.h:20
const T & get() const
Definition: EventSetup.h:55
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.
T eta() const
Definition: PV3DBase.h:76
double vy() const
y coordinate of the reference point on track
Definition: TrackBase.h:145
tuple muons
Definition: patZpeak.py:38
int charge() const
track electric charge
Definition: TrackBase.h:113
Definition: DDAxes.h:10
double normalizedPhi(double phi)
Definition: normalizedPhi.cc:5
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:121
T x() const
Definition: PV3DBase.h:62
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
double vx() const
x coordinate of the reference point on track
Definition: TrackBase.h:143
std::vector< DetId > theVetoCollection
Definition: CaloExtractor.h:52