CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonTCMETValueMapProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: METProducers
4 // Class: MuonTCMETValueMapProducer
5 //
6 // Original Author: Frank Golf
7 // Created: Sun Mar 15 11:33:20 CDT 2009
8 //
9 //
10 
11 //____________________________________________________________________________||
13 
15 
28 
31 
34 
37 
38 #include "TVector3.h"
39 #include "TMath.h"
40 
41 //____________________________________________________________________________||
43 
44 //____________________________________________________________________________||
45 namespace cms
46 {
47 
49 {
50  produces<edm::ValueMap<reco::MuonMETCorrectionData> > ("muCorrData");
51 
52  rfType_ = iConfig.getParameter<int>("rf_type");
53 
54  nLayers_ = iConfig.getParameter<int> ("nLayers");
55  nLayersTight_ = iConfig.getParameter<int> ("nLayersTight");
56  vertexNdof_ = iConfig.getParameter<int> ("vertexNdof");
57  vertexZ_ = iConfig.getParameter<double> ("vertexZ");
58  vertexRho_ = iConfig.getParameter<double> ("vertexRho");
59  vertexMaxDZ_ = iConfig.getParameter<double> ("vertexMaxDZ");
60  maxpt_eta20_ = iConfig.getParameter<double> ("maxpt_eta20");
61  maxpt_eta25_ = iConfig.getParameter<double> ("maxpt_eta25");
62 
63  // get configuration parameters
64  maxTrackAlgo_ = iConfig.getParameter<int>("trackAlgo_max");
65  maxd0cut_ = iConfig.getParameter<double>("d0_max" );
66  minpt_ = iConfig.getParameter<double>("pt_min" );
67  maxpt_ = iConfig.getParameter<double>("pt_max" );
68  maxeta_ = iConfig.getParameter<double>("eta_max" );
69  maxchi2_ = iConfig.getParameter<double>("chi2_max" );
70  minhits_ = iConfig.getParameter<double>("nhits_min" );
71  maxPtErr_ = iConfig.getParameter<double>("ptErr_max" );
72 
73  trkQuality_ = iConfig.getParameter<std::vector<int> >("track_quality");
74  trkAlgos_ = iConfig.getParameter<std::vector<int> >("track_algos" );
75  maxchi2_tight_ = iConfig.getParameter<double>("chi2_max_tight");
76  minhits_tight_ = iConfig.getParameter<double>("nhits_min_tight");
77  maxPtErr_tight_ = iConfig.getParameter<double>("ptErr_max_tight");
78  usePvtxd0_ = iConfig.getParameter<bool>("usePvtxd0");
79  d0cuta_ = iConfig.getParameter<double>("d0cuta");
80  d0cutb_ = iConfig.getParameter<double>("d0cutb");
81 
82  muon_dptrel_ = iConfig.getParameter<double>("muon_dptrel");
83  muond0_ = iConfig.getParameter<double>("d0_muon" );
84  muonpt_ = iConfig.getParameter<double>("pt_muon" );
85  muoneta_ = iConfig.getParameter<double>("eta_muon" );
86  muonchi2_ = iConfig.getParameter<double>("chi2_muon" );
87  muonhits_ = iConfig.getParameter<double>("nhits_muon" );
88  muonGlobal_ = iConfig.getParameter<bool>("global_muon");
89  muonTracker_ = iConfig.getParameter<bool>("tracker_muon");
90  muonDeltaR_ = iConfig.getParameter<double>("deltaR_muon");
91  useCaloMuons_ = iConfig.getParameter<bool>("useCaloMuons");
92  muonMinValidStaHits_ = iConfig.getParameter<int>("muonMinValidStaHits");
93 
95  tcmetAlgo_=new TCMETAlgo();
96 
97  muonToken_ = consumes<reco::MuonCollection>(iConfig.getParameter<edm::InputTag>("muonInputTag"));
98  beamSpotToken_ = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpotInputTag"));
99  vertexToken_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexInputTag"));
100 
101 }
102 
103 //____________________________________________________________________________||
105 {
106  delete tcmetAlgo_;
107 }
108 
109 //____________________________________________________________________________||
111 {
112  iEvent.getByToken(muonToken_ , muons_);
114 
115  hasValidVertex = false;
116  if( usePvtxd0_ ){
118 
119  if( vertexHandle_.isValid() ) {
122  }
123  }
124 
125  edm::ESHandle<MagneticField> theMagField;
126  iSetup.get<IdealMagneticFieldRecord>().get(theMagField);
127  bField = theMagField.product();
128 
129  std::auto_ptr<edm::ValueMap<reco::MuonMETCorrectionData> > vm_muCorrData(new edm::ValueMap<reco::MuonMETCorrectionData>());
130 
131  std::vector<reco::MuonMETCorrectionData> v_muCorrData;
132 
133  unsigned int nMuons = muons_->size();
134 
135  for (unsigned int iMu = 0; iMu < nMuons; iMu++) {
136 
137  const reco::Muon* mu = &(*muons_)[iMu];
138  double deltax = 0.0;
139  double deltay = 0.0;
140 
142 
143  reco::TrackRef mu_track;
144  if( mu->isGlobalMuon() || mu->isTrackerMuon() || mu->isCaloMuon() )
145  mu_track = mu->innerTrack();
146  else {
147  v_muCorrData.push_back( muMETCorrData );
148  continue;
149  }
150 
151  // figure out depositions muons would make if they were treated as pions
152  if( isGoodTrack( mu ) ) {
153 
154  if( mu_track->pt() < minpt_ )
156 
157  else {
158  int bin_index = response_function->FindBin( mu_track->eta(), mu_track->pt() );
159  double response = response_function->GetBinContent( bin_index );
160 
161  TVector3 outerTrkPosition = propagateTrack( mu );
162 
163  deltax = response * mu_track->p() * sin( outerTrkPosition.Theta() ) * cos( outerTrkPosition.Phi() );
164  deltay = response * mu_track->p() * sin( outerTrkPosition.Theta() ) * sin( outerTrkPosition.Phi() );
165 
167  }
168  }
169 
170  // figure out muon flag
171  if( isGoodMuon( mu ) )
173 
174  else if( useCaloMuons_ && isGoodCaloMuon( mu, iMu ) )
176 
177  else v_muCorrData.push_back( muMETCorrData );
178  }
179 
180  edm::ValueMap<reco::MuonMETCorrectionData>::Filler dataFiller(*vm_muCorrData);
181 
182  dataFiller.insert( muons_, v_muCorrData.begin(), v_muCorrData.end());
183  dataFiller.fill();
184 
185  iEvent.put(vm_muCorrData, "muCorrData");
186 }
187 
188 //____________________________________________________________________________||
190 {
191 
192  if( rfType_ == 1 )
194  else if( rfType_ == 2 )
196 }
197 
198 //____________________________________________________________________________||
200 {
201 
202 }
203 
204 //____________________________________________________________________________||
206 {
207  double d0 = -999;
208  double nhits = 0;
209  double chi2 = 999;
210 
211  // get d0 corrected for beam spot
212  bool haveBeamSpot = true;
213  if( !beamSpot_.isValid() ) haveBeamSpot = false;
214 
215  if( muonGlobal_ && !muon->isGlobalMuon() ) return false;
216  if( muonTracker_ && !muon->isTrackerMuon() ) return false;
217 
218  const reco::TrackRef siTrack = muon->innerTrack();
219  const reco::TrackRef globalTrack = muon->globalTrack();
220 
221  Point bspot = haveBeamSpot ? beamSpot_->position() : Point(0,0,0);
222  if( siTrack.isNonnull() ) nhits = siTrack->numberOfValidHits();
223  if( globalTrack.isNonnull() )
224  {
225  d0 = -1 * globalTrack->dxy( bspot );
226  chi2 = globalTrack->normalizedChi2();
227  }
228 
229  if( fabs( d0 ) > muond0_ ) return false;
230  if( muon->pt() < muonpt_ ) return false;
231  if( fabs( muon->eta() ) > muoneta_ ) return false;
232  if( nhits < muonhits_ ) return false;
233  if( chi2 > muonchi2_ ) return false;
234  if( globalTrack->hitPattern().numberOfValidMuonHits() < muonMinValidStaHits_ ) return false;
235 
236  //reject muons with tracker dpt/pt > X
237  if( !siTrack.isNonnull() ) return false;
238  if( siTrack->ptError() / siTrack->pt() > muon_dptrel_ ) return false;
239 
240  else return true;
241 }
242 
243 //____________________________________________________________________________||
245 {
246 
247  if( muon->pt() < 10 ) return false;
248 
249  if( !isGoodTrack( muon ) ) return false;
250 
251  const reco::TrackRef inputSiliconTrack = muon->innerTrack();
252  if( !inputSiliconTrack.isNonnull() ) return false;
253 
254  //check if it is in the vicinity of a global or tracker muon
255  unsigned int nMuons = muons_->size();
256  for (unsigned int iMu = 0; iMu < nMuons; iMu++)
257  {
258 
259  if( iMu == index ) continue;
260 
261  const reco::Muon* mu = &(*muons_)[iMu];
262 
263  const reco::TrackRef testSiliconTrack = mu->innerTrack();
264  if( !testSiliconTrack.isNonnull() ) continue;
265 
266  double deltaEta = inputSiliconTrack.get()->eta() - testSiliconTrack.get()->eta();
267  double deltaPhi = acos( cos( inputSiliconTrack.get()->phi() - testSiliconTrack.get()->phi() ) );
268  double deltaR = TMath::Sqrt( deltaEta * deltaEta + deltaPhi * deltaPhi );
269 
270  if( deltaR < muonDeltaR_ ) return false;
271  }
272 
273  return true;
274 }
275 
276 //____________________________________________________________________________||
278 {
279  double d0 = -999;
280 
281  const reco::TrackRef siTrack = muon->innerTrack();
282  if (!siTrack.isNonnull())
283  return false;
284 
285  if( hasValidVertex )
286  {
287  //get d0 corrected for primary vertex
288 
289  const Point pvtx = Point(vertices_->begin()->x(),
290  vertices_->begin()->y(),
291  vertices_->begin()->z());
292 
293  d0 = -1 * siTrack->dxy( pvtx );
294 
295  double dz = siTrack->dz( pvtx );
296 
297  if( fabs( dz ) < vertexMaxDZ_ ){
298 
299  //get d0 corrected for pvtx
300  d0 = -1 * siTrack->dxy( pvtx );
301 
302  }else{
303 
304  // get d0 corrected for beam spot
305  bool haveBeamSpot = true;
306  if( !beamSpot_.isValid() ) haveBeamSpot = false;
307 
308  Point bspot = haveBeamSpot ? beamSpot_->position() : Point(0,0,0);
309  d0 = -1 * siTrack->dxy( bspot );
310 
311  }
312  }
313  else
314  {
315 
316  // get d0 corrected for beam spot
317  bool haveBeamSpot = true;
318  if( !beamSpot_.isValid() ) haveBeamSpot = false;
319 
320  Point bspot = haveBeamSpot ? beamSpot_->position() : Point(0,0,0);
321  d0 = -1 * siTrack->dxy( bspot );
322  }
323 
324  if( siTrack->algo() < maxTrackAlgo_ )
325  {
326  //1st 4 tracking iterations (pT-dependent d0 cut)
327 
328  float d0cut = sqrt(std::pow(d0cuta_,2) + std::pow(d0cutb_/siTrack->pt(),2));
329  if(d0cut > maxd0cut_) d0cut = maxd0cut_;
330 
331  if( fabs( d0 ) > d0cut ) return false;
332  if( nLayers( siTrack ) < nLayers_ ) return false;
333  }
334  else
335  {
336  //last 2 tracking iterations (tighten chi2, nhits, pt error cuts)
337 
338  if( siTrack->normalizedChi2() > maxchi2_tight_ ) return false;
339  if( siTrack->numberOfValidHits() < minhits_tight_ ) return false;
340  if( (siTrack->ptError() / siTrack->pt()) > maxPtErr_tight_ ) return false;
341  if( nLayers( siTrack ) < nLayersTight_ ) return false;
342  }
343 
344  if( siTrack->numberOfValidHits() < minhits_ ) return false;
345  if( siTrack->normalizedChi2() > maxchi2_ ) return false;
346  if( fabs( siTrack->eta() ) > maxeta_ ) return false;
347  if( siTrack->pt() > maxpt_ ) return false;
348  if( (siTrack->ptError() / siTrack->pt()) > maxPtErr_ ) return false;
349  if( fabs( siTrack->eta() ) > 2.5 && siTrack->pt() > maxpt_eta25_ ) return false;
350  if( fabs( siTrack->eta() ) > 2.0 && siTrack->pt() > maxpt_eta20_ ) return false;
351 
352  int cut = 0;
353  for( unsigned int i = 0; i < trkQuality_.size(); i++ )
354  {
355  cut |= (1 << trkQuality_.at(i));
356  }
357 
358  if( !( (siTrack->qualityMask() & cut) == cut ) ) return false;
359 
360  bool isGoodAlgo = false;
361  if( trkAlgos_.size() == 0 ) isGoodAlgo = true;
362  for( unsigned int i = 0; i < trkAlgos_.size(); i++ )
363  {
364  if( siTrack->algo() == trkAlgos_.at(i) ) isGoodAlgo = true;
365  }
366 
367  if( !isGoodAlgo ) return false;
368 
369  return true;
370 }
371 
372 //____________________________________________________________________________||
374 {
375 
376  TVector3 outerTrkPosition;
377 
378  outerTrkPosition.SetPtEtaPhi( 999., -10., 2 * TMath::Pi() );
379 
380  const reco::TrackRef track = muon->innerTrack();
381 
382  if( !track.isNonnull() )
383  {
384  return outerTrkPosition;
385  }
386 
387  GlobalPoint tpVertex ( track->vx(), track->vy(), track->vz() );
388  GlobalVector tpMomentum ( track.get()->px(), track.get()->py(), track.get()->pz() );
389  int tpCharge ( track->charge() );
390 
391  FreeTrajectoryState fts ( tpVertex, tpMomentum, tpCharge, bField);
392 
393  const double zdist = 314.;
394 
395  const double radius = 130.;
396 
397  const double corner = 1.479;
398 
401 
402  Cylinder::CylinderPointer barrel = Cylinder::build( Cylinder::PositionType (0, 0, 0), Cylinder::RotationType (), radius);
403 
405 
407 
408  if( track.get()->eta() < -corner )
409  {
410  tsos = myAP.propagate( fts, *lendcap);
411  }
412  else if( fabs(track.get()->eta()) < corner )
413  {
414  tsos = myAP.propagate( fts, *barrel);
415  }
416  else if( track.get()->eta() > corner )
417  {
418  tsos = myAP.propagate( fts, *rendcap);
419  }
420 
421  if( tsos.isValid() )
422  outerTrkPosition.SetXYZ( tsos.globalPosition().x(), tsos.globalPosition().y(), tsos.globalPosition().z() );
423 
424  else
425  outerTrkPosition.SetPtEtaPhi( 999., -10., 2 * TMath::Pi() );
426 
427  return outerTrkPosition;
428 }
429 
430 
431 //____________________________________________________________________________||
433 {
434  const reco::HitPattern& p = track->hitPattern();
435  return p.trackerLayersWithMeasurement();
436 }
437 
438 //____________________________________________________________________________||
440 {
441  if( vertices_->begin()->isFake() ) return false;
442  if( vertices_->begin()->ndof() < vertexNdof_ ) return false;
443  if( fabs( vertices_->begin()->z() ) > vertexZ_ ) return false;
444  if( sqrt( std::pow( vertices_->begin()->x() , 2 ) + std::pow( vertices_->begin()->y() , 2 ) ) > vertexRho_ ) return false;
445 
446  return true;
447 
448 }
449 
450 }
451 
452 //____________________________________________________________________________||
class TVector3 propagateTrack(const reco::Muon *)
TkRotation< Scalar > RotationType
Definition: Definitions.h:29
const double Pi
T getParameter(std::string const &) const
edm::Handle< reco::VertexCollection > vertexHandle_
int i
Definition: DBlmapReader.cc:9
MuonTCMETValueMapProducer(const edm::ParameterSet &)
TH2D * getResponseFunction_fit()
Definition: TCMETAlgo.cc:3582
virtual TrackRef innerTrack() const
Definition: Muon.h:48
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
bool isTrackerMuon() const
Definition: Muon.h:219
edm::EDGetTokenT< reco::VertexCollection > vertexToken_
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
const reco::VertexCollection * vertices_
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
T y() const
Definition: PV3DBase.h:63
bool isGlobalMuon() const
Definition: Muon.h:218
GlobalPoint globalPosition() const
std::pair< double, double > Point
Definition: CaloEllipse.h:18
bool isGoodCaloMuon(const reco::Muon *, const unsigned int)
bool isCaloMuon() const
Definition: Muon.h:221
Point3DBase< Scalar, GlobalTag > PositionType
Definition: Definitions.h:30
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
int trackerLayersWithMeasurement() const
Definition: HitPattern.h:733
T sqrt(T t)
Definition: SSEVec.h:48
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
static PlanePointer build(Args &&...args)
Definition: Plane.h:36
T z() const
Definition: PV3DBase.h:64
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
math::XYZPoint Point
edm::Handle< reco::MuonCollection > muons_
TH2D * getResponseFunction_mode()
Definition: TCMETAlgo.cc:5058
virtual void produce(edm::Event &, const edm::EventSetup &)
const int mu
Definition: Constants.h:22
bool isValid() const
Definition: HandleBase.h:76
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
#define M_PI
Definition: BFit3D.cc:3
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
T const * product() const
Definition: Handle.h:81
edm::Handle< reco::BeamSpot > beamSpot_
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:242
virtual float pt() const GCC11_FINAL
transverse momentum
T x() const
Definition: PV3DBase.h:62
edm::EDGetTokenT< reco::MuonCollection > muonToken_
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:54