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