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 
7 
9 
14 //#include "CommonTools/Utils/interface/deltaR.h"
15 //#include "PhysicsTools/Utilities/interface/deltaR.h"
17 //#include "PhysicsTools/Utilities/interface/normalizedPhi.h"
18 
19 using namespace edm;
20 using namespace std;
21 using namespace reco;
22 using namespace muonisolation;
24 
25 CaloExtractor::CaloExtractor(const ParameterSet& par, edm::ConsumesCollector && iC) :
26  theCaloTowerCollectionToken(iC.consumes<CaloTowerCollection>(par.getParameter<edm::InputTag>("CaloTowerCollectionLabel"))),
27  theDepositLabel(par.getUntrackedParameter<string>("DepositLabel")),
28  theWeight_E(par.getParameter<double>("Weight_E")),
29  theWeight_H(par.getParameter<double>("Weight_H")),
30  theThreshold_E(par.getParameter<double>("Threshold_E")),
31  theThreshold_H(par.getParameter<double>("Threshold_H")),
32  theDR_Veto_E(par.getParameter<double>("DR_Veto_E")),
33  theDR_Veto_H(par.getParameter<double>("DR_Veto_H")),
34  theDR_Max(par.getParameter<double>("DR_Max")),
35  vertexConstraintFlag_XY(par.getParameter<bool>("Vertex_Constraint_XY")),
36  vertexConstraintFlag_Z(par.getParameter<bool>("Vertex_Constraint_Z"))
37 {
38 }
39 
41 {
42  theVetoCollection.clear();
43 
45  event.getByToken(theCaloTowerCollectionToken,towers);
46 
48  eventSetup.get<CaloGeometryRecord>().get(caloGeom);
49 
51  eventSetup.get<IdealMagneticFieldRecord>().get(bField);
52  double bz = bField->inInverseGeV(GlobalPoint(0.,0.,0.)).z();
53 
54  TrackCollection::const_iterator mu;
55  TrackCollection::const_iterator muEnd(muons.end());
56 
58  CaloTowerCollection::const_iterator calEnd(towers->end());
59 
60  for ( mu = muons.begin(); mu != muEnd; ++mu ) {
61  for ( cal = towers->begin(); cal != calEnd; ++cal ) {
63  double dEta = fabs(mu->eta()-cal->eta());
64  if (fabs(dEta) > theDR_Max) continue;
65 
66  double deltar0 = reco::deltaR(*mu,*cal);
67  if (deltar0>theDR_Max) continue;
68 
69  double etecal = cal->emEt();
70  double eecal = cal->emEnergy();
71  bool doEcal = theWeight_E>0 && etecal>theThreshold_E && eecal>3*noiseEcal(*cal);
72  double ethcal = cal->hadEt();
73  double ehcal = cal->hadEnergy();
74  bool doHcal = theWeight_H>0 && ethcal>theThreshold_H && ehcal>3*noiseHcal(*cal);
75  if ((!doEcal) && (!doHcal)) 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) theVetoCollection.push_back(calId);
84  } else {
85  if (deltar<theDR_Veto_H) theVetoCollection.push_back(calId);
86  }
87  }
88  }
89 
90 }
91 
92 IsoDeposit CaloExtractor::deposit( const Event & event, const EventSetup& eventSetup, const Track & muon) const
93 {
94  IsoDeposit dep(muon.eta(), muon.phi() );
95  LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
96  << " >>> Muon: pt " << muon.pt()
97  << " eta " << muon.eta()
98  << " phi " << muon.phi();
99 
101  event.getByToken(theCaloTowerCollectionToken,towers);
102 
104  eventSetup.get<CaloGeometryRecord>().get(caloGeom);
105 
107  eventSetup.get<IdealMagneticFieldRecord>().get(bField);
108  double bz = bField->inInverseGeV(GlobalPoint(0.,0.,0.)).z();
109 
111  CaloTowerCollection::const_iterator calEnd(towers->end());
112  for ( cal = towers->begin(); cal != calEnd; ++cal ) {
114  double dEta = fabs(muon.eta()-cal->eta());
115  if (fabs(dEta) > theDR_Max) continue;
116 
117  double deltar0 = reco::deltaR(muon,*cal);
118  if (deltar0>theDR_Max) 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)) continue;
127 
128  DetId calId = cal->id();
129  GlobalPoint endpos = caloGeom->getPosition(calId);
131  double deltar = reco::deltaR(muatcal,endpos);
132 
133  if (deltar<theDR_Veto_H) {
134  dep.setVeto(IsoDeposit::Veto(reco::isodeposit::Direction(muatcal.eta(), muatcal.phi()), theDR_Veto_H));
135  }
136 
137  if (doEcal) {
138  if (deltar<theDR_Veto_E) {
139  double calodep = theWeight_E*etecal;
140  if (doHcal) calodep += theWeight_H*ethcal;
141  dep.addCandEnergy(calodep);
142  LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
143  << " >>> Calo deposit inside veto (with ECAL): deltar " << deltar
144  << " calodep " << calodep
145  << " ecaldep " << etecal
146  << " hcaldep " << ethcal
147  << " eta " << cal->eta()
148  << " phi " << cal->phi();
149  continue;
150  }
151  } else {
152  if (deltar<theDR_Veto_H) {
153  dep.addCandEnergy(theWeight_H*ethcal);
154  LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
155  << " >>> Calo deposit inside veto (no ECAL): deltar " << deltar
156  << " calodep " << theWeight_H*ethcal
157  << " eta " << cal->eta()
158  << " phi " << cal->phi();
159  continue;
160  }
161  }
162 
164  , calId)!=theVetoCollection.end()) {
165  LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
166  << " >>> Deposits belongs to other track: deltar, etecal, ethcal= "
167  << deltar << ", " << etecal << ", " << ethcal;
168  continue;
169  }
170 
171  if (doEcal) {
172  if (deltar>theDR_Veto_E) {
173  double calodep = theWeight_E*etecal;
174  if (doHcal) calodep += theWeight_H*ethcal;
175  dep.addDeposit(reco::isodeposit::Direction(endpos.eta(), endpos.phi()),calodep);
176  LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
177  << " >>> Calo deposit (with ECAL): deltar " << deltar
178  << " calodep " << calodep
179  << " ecaldep " << etecal
180  << " hcaldep " << ethcal
181  << " eta " << cal->eta()
182  << " phi " << cal->phi();
183  }
184  } else {
185  if (deltar>theDR_Veto_H) {
186  dep.addDeposit(reco::isodeposit::Direction(endpos.eta(), endpos.phi()),theWeight_H*ethcal);
187  LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
188  << " >>> Calo deposit (no ECAL): deltar " << deltar
189  << " calodep " << theWeight_H*ethcal
190  << " eta " << cal->eta()
191  << " phi " << cal->phi();
192  }
193  }
194  }
195 
196  return dep;
197 
198 }
199 
200 GlobalPoint CaloExtractor::MuonAtCaloPosition(const Track& muon, const double bz, const GlobalPoint& endpos, bool fixVxy, bool fixVz) {
201  double qoverp= muon.qoverp();
202  double cur = bz*muon.charge()/muon.pt();
203  double phi0 = muon.phi();
204  double dca = muon.dxy();
205  double theta = muon.theta();
206  double dz = muon.dz();
207 
208  //LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
209  //<< " Pt(GeV): " << muon.pt()
210  //<< ", phi0 " << muon.phi0()
211  //<< ", eta " << muon.eta();
212  //LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
213  //<< " d0 " << muon.d0()
214  //<< ", dz " << muon.dz();
215  //LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")
216  //<< " rhocal " << endpos.perp()
217  //<< ", zcal " << endpos.z();
218 
219  if (fixVxy && fixVz) {
220  // Note that here we assume no correlation between XY and Z projections
221  // This should be a reasonable approximation for our purposes
222  double errd02 = muon.covariance(muon.i_dxy,muon.i_dxy);
223  if (pow(muon.dxy(),2)<4*errd02) {
224  phi0 -= muon.dxy()*muon.covariance(muon.i_dxy,muon.i_phi)
225  /errd02;
226  cur -= muon.dxy()*muon.covariance(muon.i_dxy,muon.i_qoverp)
227  /errd02 * (cur/qoverp);
228  dca = 0;
229  }
230  double errdsz2 = muon.covariance(muon.i_dsz,muon.i_dsz);
231  if (pow(muon.dsz(),2)<4*errdsz2) {
232  theta += muon.dsz()*muon.covariance(muon.i_dsz,muon.i_lambda)
233  /errdsz2;
234  dz = 0;
235  }
236  } else if (fixVxy) {
237  double errd02 = muon.covariance(muon.i_dxy,muon.i_dxy);
238  if (pow(muon.dxy(),2)<4*errd02) {
239  phi0 -= muon.dxy()*muon.covariance(muon.i_dxy,muon.i_phi)
240  /errd02;
241  cur -= muon.dxy()*muon.covariance(muon.i_dxy,muon.i_qoverp)
242  /errd02 * (cur/qoverp);
243  theta += muon.dxy()*muon.covariance(muon.i_dxy,muon.i_lambda)
244  /errd02;
245  dz -= muon.dxy()*muon.covariance(muon.i_dxy,muon.i_dsz)
246  /errd02 * muon.p()/muon.pt();
247  dca = 0;
248  }
249  } else if (fixVz) {
250  double errdsz2 = muon.covariance(muon.i_dsz,muon.i_dsz);
251  if (pow(muon.dsz(),2)<4*errdsz2) {
252  theta += muon.dsz()*muon.covariance(muon.i_dsz,muon.i_lambda)
253  /errdsz2;
254  phi0 -= muon.dsz()*muon.covariance(muon.i_dsz,muon.i_phi)
255  /errdsz2;
256  cur -= muon.dsz()*muon.covariance(muon.i_dsz,muon.i_qoverp)
257  /errdsz2 * (cur/qoverp);
258  dca -= muon.dsz()*muon.covariance(muon.i_dsz,muon.i_dxy)
259  /errdsz2;
260  dz = 0;
261  }
262  }
263 
264  double sphi0 = sin(phi0);
265  double cphi0 = cos(phi0);
266 
267  double xsin = endpos.x()*sphi0 - endpos.y()*cphi0;
268  double xcos = endpos.x()*cphi0 + endpos.y()*sphi0;
269  double fcdca = fabs(1-cur*dca);
270  double phif = atan2( fcdca*sphi0-cur*endpos.x()
271  , fcdca*cphi0+cur*endpos.y());
272  double tphif2 = tan(0.5*(phif-phi0));
273  double dcaf = dca + xsin + xcos*tphif2;
274 
275  double x = endpos.x() - dcaf*sin(phif);
276  double y = endpos.y() + dcaf*cos(phif);
277 
278  double deltas = (x-muon.vx())*cphi0 + (y-muon.vy())*sphi0;
279  double deltaphi = normalizedPhi(phif-phi0);
280  if (deltaphi!=0) deltas = deltas*deltaphi/sin(deltaphi);
281 
282  double z =dz;
283  double tantheta = tan(theta);
284  if (tantheta!=0) {
285  z += deltas/tan(theta);
286  } else {
287  z = endpos.z();
288  }
289 
290  return GlobalPoint(x,y,z);
291 }
292 
293 double CaloExtractor::noiseEcal(const CaloTower& tower) const {
294  double noise = 0.04;
295  double eta = tower.eta();
296  if (fabs(eta)>1.479) noise = 0.15;
297  return noise;
298 }
299 
300 double CaloExtractor::noiseHcal(const CaloTower& tower) const {
301  double noise = 0.2;
302  return noise;
303 }
#define LogDebug(id)
double qoverp() const
q / p
Definition: TrackBase.h:560
double p() const
momentum vector magnitude
Definition: TrackBase.h:602
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:566
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
edm::EDGetTokenT< CaloTowerCollection > theCaloTowerCollectionToken
Definition: CaloExtractor.h:37
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:14
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:632
double deltaR(const T1 &t1, const T2 &t2)
Definition: deltaR.h:48
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:590
virtual double eta() const
momentum pseudorapidity
T x() const
Cartesian x coordinate.
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:638
CovarianceMatrix covariance() const
return track covariance matrix
Definition: TrackBase.h:718
double pt() const
track transverse momentum
Definition: TrackBase.h:608
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
double noiseHcal(const CaloTower &tower) const
const int mu
Definition: Constants.h:22
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
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:596
Definition: DetId.h:18
const T & get() const
Definition: EventSetup.h:56
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:650
tuple muons
Definition: patZpeak.py:38
int charge() const
track electric charge
Definition: TrackBase.h:554
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:578
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:644
std::vector< DetId > theVetoCollection
Definition: CaloExtractor.h:54