test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonMETValueMapProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: METProducers
4 // Class: MuonMETValueMapProducer
5 //
6 //
7 // Original Author: Puneeth Kalavase
8 // Created: Sun Mar 15 11:33:20 CDT 2009
9 //
10 
11 /*
12  The meanings ofr reco::MuonMETCorrectionData::Type
13  NotUsed = 0:
14  The muon is not used to correct the MET by default
15 
16  CombinedTrackUsed = 1, GlobalTrackUsed = 1:
17 
18  The muon is used to correct the MET. The Global pt is used. For
19  backward compatibility only
20 
21  InnerTrackUsed = 2, TrackUsed = 2:
22  The muon is used to correct the MET. The tracker pt is used. For
23  backward compatibility only
24 
25  OuterTrackUsed = 3, StandAloneTrackUsed = 3:
26  The muon is used to correct the MET. The standalone pt is used.
27  For backward compatibility only. In general, the flag should
28  never be 3. You do not want to correct the MET using the pt
29  measurement from the standalone system (unless you really know
30  what you're doing.
31 
32  TreatedAsPion = 4:
33  The muon was treated as a Pion. This is used for the tcMET
34  producer
35 
36  MuonP4V4QUsed = 5, MuonCandidateValuesUsed = 5:
37  The default fit is used, i.e, we get the pt from muon->pt
38 
39  (see DataFormats/MuonReco/interface/MuonMETCorrectionData.h)
40 */
41 
42 //____________________________________________________________________________||
44 
53 
54 //____________________________________________________________________________||
55 namespace cms
56 {
57 
59  : minPt_(iConfig.getParameter<double>("minPt"))
60  , maxEta_(iConfig.getParameter<double>("maxEta"))
61  , isAlsoTkMu_(iConfig.getParameter<bool>("isAlsoTkMu"))
62  , maxNormChi2_(iConfig.getParameter<double>("maxNormChi2"))
63  , maxd0_(iConfig.getParameter<double>("maxd0"))
64  , minnHits_(iConfig.getParameter<int>("minnHits"))
65  , minnValidStaHits_(iConfig.getParameter<int>("minnValidStaHits"))
66  , useTrackAssociatorPositions_(iConfig.getParameter<bool>("useTrackAssociatorPositions"))
67  , useHO_(iConfig.getParameter<bool>("useHO"))
68  , towerEtThreshold_(iConfig.getParameter<double>("towerEtThreshold"))
69  , useRecHits_(iConfig.getParameter<bool>("useRecHits"))
70 {
71  muonToken_ = consumes<edm::View<reco::Muon> >(iConfig.getParameter<edm::InputTag>("muonInputTag"));
72  beamSpotToken_ = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpotInputTag"));
73 
74  edm::ParameterSet trackAssociatorParams = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
76  trackAssociatorParameters_.loadParameters(trackAssociatorParams, iC);
78 
79  produces<edm::ValueMap<reco::MuonMETCorrectionData> >("muCorrData");
80 }
81 
82 //____________________________________________________________________________||
84 {
86  iEvent.getByToken(muonToken_, muons);
87 
89  iEvent.getByToken(beamSpotToken_, beamSpot);
90 
91  edm::ESHandle<MagneticField> magneticField;
92  iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
93 
94  double bfield = magneticField->inTesla(GlobalPoint(0.,0.,0.)).z();
95 
96  std::vector<reco::MuonMETCorrectionData> muCorrDataList;
97 
98  for(edm::View<reco::Muon>::const_iterator muon = muons->begin(); muon != muons->end(); ++muon)
99  {
100  double deltax = 0.0;
101  double deltay = 0.0;
102  determine_deltax_deltay(deltax, deltay, *muon, bfield, iEvent, iSetup);
103 
104  reco::MuonMETCorrectionData::Type muCorrType = decide_correction_type(*muon, beamSpot->position());
105 
106  reco::MuonMETCorrectionData muMETCorrData(muCorrType, deltax, deltay);
107  muCorrDataList.push_back(muMETCorrData);
108 
109  }
110 
111  std::auto_ptr<edm::ValueMap<reco::MuonMETCorrectionData> > valueMapMuCorrData(new edm::ValueMap<reco::MuonMETCorrectionData>());
112 
113  edm::ValueMap<reco::MuonMETCorrectionData>::Filler dataFiller(*valueMapMuCorrData);
114 
115  dataFiller.insert(muons, muCorrDataList.begin(), muCorrDataList.end());
116  dataFiller.fill();
117 
118  iEvent.put(valueMapMuCorrData, "muCorrData");
119 
120 }
121 
122 //____________________________________________________________________________||
123 void MuonMETValueMapProducer::determine_deltax_deltay(double& deltax, double& deltay, const reco::Muon& muon, double bfield, edm::Event& iEvent, const edm::EventSetup& iSetup)
124 {
125  reco::TrackRef mu_track;
126  if(muon.isGlobalMuon()) mu_track = muon.globalTrack();
127  else if(muon.isTrackerMuon()) mu_track = muon.innerTrack();
128  else mu_track = muon.outerTrack();
129 
131  trackAssociator_.getFreeTrajectoryState(iSetup, *mu_track),
133 
134  MuonMETAlgo alg;
135  alg.GetMuDepDeltas(&muon, info,
138  deltax, deltay, bfield);
139 
140 }
141 
142 //____________________________________________________________________________||
144 {
145  if(should_type_MuonCandidateValuesUsed(muon, beamSpotPosition))
146  return reco::MuonMETCorrectionData::Type::MuonCandidateValuesUsed;
147 
148  return reco::MuonMETCorrectionData::Type::NotUsed;
149 }
150 
151 //____________________________________________________________________________||
153 {
154  if(!muon.isGlobalMuon()) return false;
155  if(!muon.isTrackerMuon() && isAlsoTkMu_) return false;
156  reco::TrackRef globTk = muon.globalTrack();
157  reco::TrackRef siTk = muon.innerTrack();
158  if(muon.pt() < minPt_ || fabs(muon.eta()) > maxEta_) return false;
159  if(globTk->chi2()/globTk->ndof() > maxNormChi2_) return false;
160  if(fabs(globTk->dxy(beamSpotPosition)) > fabs(maxd0_)) return false;
161  if(siTk->numberOfValidHits() < minnHits_) return false;
162  if(globTk->hitPattern().numberOfValidMuonHits() < minnValidStaHits_) return false;
163  return true;
164 }
165 
166 //____________________________________________________________________________||
167 }
168 
169 //____________________________________________________________________________||
170 
T getParameter(std::string const &) const
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
static const TGPicture * info(bool iBackgroundIsBlack)
virtual float pt() const
transverse momentum
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
static FreeTrajectoryState getFreeTrajectoryState(const edm::EventSetup &, const reco::Track &)
get FreeTrajectoryState from different track representations
void useDefaultPropagator()
use the default propagator
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
void loadParameters(const edm::ParameterSet &, edm::ConsumesCollector &)
bool isGlobalMuon() const
Definition: Muon.h:218
TrackDetectorAssociator trackAssociator_
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
reco::MuonMETCorrectionData::Type decide_correction_type(const reco::Muon &muon, const math::XYZPoint &beamSpotPosition)
void GetMuDepDeltas(const reco::Muon *inputMuon, TrackDetMatchInfo &info, bool useTrackAssociatorPositions, bool useRecHits, bool useHO, double towerEtThreshold, double &deltax, double &deltay, double Bfield)
Definition: MuonMETAlgo.cc:101
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
TrackAssociatorParameters trackAssociatorParameters_
virtual float eta() const
momentum pseudorapidity
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
void determine_deltax_deltay(double &deltax, double &deltay, const reco::Muon &muon, double bfield, edm::Event &iEvent, const edm::EventSetup &iSetup)
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:51
virtual void produce(edm::Event &, const edm::EventSetup &) override
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const T & get() const
Definition: EventSetup.h:55
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
MuonMETValueMapProducer(const edm::ParameterSet &)
tuple muons
Definition: patZpeak.py:38
bool should_type_MuonCandidateValuesUsed(const reco::Muon &muon, const math::XYZPoint &beamSpotPosition)
TrackDetMatchInfo associate(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const AssociatorParameters &)
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:54