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: MuonMETValueMapProducer
4 // Class: MuonMETValueMapProducer
5 //
13 //
14 // Original Author: Puneeth Kalavase
15 // Created: Sun Mar 15 11:33:20 CDT 2009
16 // $Id: MuonMETValueMapProducer.cc,v 1.3 2012/01/28 16:01:24 eulisse Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
35 
36 
39 
42 
43 
44 namespace cms {
46 
47  using namespace edm;
48 
49  produces<ValueMap<reco::MuonMETCorrectionData> > ("muCorrData");
50 
51  //get configuration parameters
52  minPt_ = iConfig.getParameter<double>("minPt" );
53  maxEta_ = iConfig.getParameter<double>("maxEta" );
54  isAlsoTkMu_ = iConfig.getParameter<bool> ("isAlsoTkMu" );
55  maxNormChi2_ = iConfig.getParameter<double>("maxNormChi2" );
56  maxd0_ = iConfig.getParameter<double>("maxd0" );
57  minnHits_ = iConfig.getParameter<int> ("minnHits" );
58  minnValidStaHits_ = iConfig.getParameter<int> ("minnValidStaHits" );
59 
60  beamSpotInputTag_ = iConfig.getParameter<InputTag>("beamSpotInputTag" );
61  muonInputTag_ = iConfig.getParameter<InputTag>("muonInputTag");
62 
63  //Parameters from earlier
64  useTrackAssociatorPositions_ = iConfig.getParameter<bool>("useTrackAssociatorPositions");
65  useHO_ = iConfig.getParameter<bool>("useHO" );
66 
67  ParameterSet trackAssociatorParams =
68  iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
69  trackAssociatorParameters_.loadParameters(trackAssociatorParams);
71 
72  towerEtThreshold_ = iConfig.getParameter<double>("towerEtThreshold");
73  useRecHits_ = iConfig.getParameter<bool>("useRecHits");
74 
75  }
76 
77 
79  {
80 
81  // do anything here that needs to be done at desctruction time
82  // (e.g. close files, deallocate resources etc.)
83 
84  }
85 
86 
87  //
88  // member functions
89  //
90 
91  // ------------ method called to produce the data ------------
93 
94  using namespace edm;
95  using namespace reco;
96 
97  //get the Muon collection
100 
101  //use the BeamSpot
102  Handle<BeamSpot> beamSpotH;
103  iEvent.getByLabel(beamSpotInputTag_, beamSpotH);
104 
105  //get the Bfield
106  edm::ESHandle<MagneticField> magneticField;
107  iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
108  //get the B-field at the origin
109  double bfield = magneticField->inTesla(GlobalPoint(0.,0.,0.)).z();
110 
111  //make a ValueMap of ints => flags for
112  //met correction. The values and meanings of the flags are :
113  // flag==0 ---> The muon is not used to correct the MET by default
114  // flag==1 ---> The muon is used to correct the MET. The Global pt is used. For backward compatibility only
115  // flag==2 ---> The muon is used to correct the MET. The tracker pt is used. For backward compatibility only
116  // flag==3 ---> The muon is used to correct the MET. The standalone pt is used. For backward compatibility only
117  // In general, the flag should never be 3. You do not want to correct the MET using
118  // the pt measurement from the standalone system (unless you really know what you're
119  // doing
120  //flag == 4 --> The muon was treated as a Pion. This is used for the tcMET producer
121  //flag == 5 --> The default fit is used, i.e, we get the pt from muon->pt
122  std::auto_ptr<ValueMap<MuonMETCorrectionData> > vm_muCorrData(new ValueMap<MuonMETCorrectionData>());
123 
124  unsigned int nMuons = muons->size();
125 
126  std::vector<MuonMETCorrectionData> v_muCorrData;
127  for (unsigned int iMu=0; iMu<nMuons; iMu++) {
128 
129  const reco::Muon* mu = &(*muons)[iMu];
130  double deltax = 0.0;
131  double deltay = 0.0;
132 
133  TrackRef mu_track;
134  if(mu->isGlobalMuon()) {
135  mu_track = mu->globalTrack();
136  } else if(mu->isTrackerMuon()) {
137  mu_track = mu->innerTrack();
138  } else
139  mu_track = mu->outerTrack();
140 
142  trackAssociator_.getFreeTrajectoryState(iSetup, *mu_track),
144  MuonMETAlgo alg;
145  alg.GetMuDepDeltas(mu, info,
148  deltax, deltay, bfield);
149 
150 
151  //now we have to figure out the flags
152  MuonMETCorrectionData muMETCorrData(MuonMETCorrectionData::NotUsed, deltax, deltay);
153  //have to be a global muon!
154  if(!mu->isGlobalMuon()) {
155  v_muCorrData.push_back(muMETCorrData);
156  continue;
157  }
158 
159  //if we require that the muon be both a global muon and tkmuon
160  //but the muon fails the tkmuon requirement, we fail it
161  if(!mu->isTrackerMuon() && isAlsoTkMu_) {
162  v_muCorrData.push_back(muMETCorrData);
163  continue;
164  }
165 
166  //if we have gotten here, we only have muons which are both global and tracker
167 
168  TrackRef globTk = mu->globalTrack();
169  TrackRef siTk = mu->innerTrack();
170 
171  if(mu->pt() < minPt_ || fabs(mu->eta()) > maxEta_) {
172  v_muCorrData.push_back(muMETCorrData);
173  continue;
174  }
175  if(globTk->chi2()/globTk->ndof() > maxNormChi2_) {
176  v_muCorrData.push_back(muMETCorrData);
177  continue;
178  }
179  if(fabs(globTk->dxy(beamSpotH->position())) > fabs(maxd0_) ) {
180  v_muCorrData.push_back(muMETCorrData);
181  continue;
182  }
183  if(siTk->numberOfValidHits() < minnHits_) {
184  v_muCorrData.push_back(muMETCorrData);
185  continue;
186  }
187 
188  if(globTk->hitPattern().numberOfValidMuonHits() < minnValidStaHits_) {
189  v_muCorrData.push_back(muMETCorrData);
190  continue;
191  }
192  //if we've gotten here. the global muon has passed all the tests
193  v_muCorrData.push_back(MuonMETCorrectionData(MuonMETCorrectionData::MuonCandidateValuesUsed, deltax, deltay));
194  }
195 
196  ValueMap<MuonMETCorrectionData>::Filler dataFiller(*vm_muCorrData);
197 
198  dataFiller.insert(muons, v_muCorrData.begin(), v_muCorrData.end());
199  dataFiller.fill();
200 
201  iEvent.put(vm_muCorrData, "muCorrData");
202 
203  }
204 
205  // ------------ method called once each job just before starting event loop ------------
207  {
208  }
209 
210  // ------------ method called once each job just after ending the event loop ------------
212  }
213 }
214 
215 
T getParameter(std::string const &) const
virtual TrackRef innerTrack() const
Definition: Muon.h:49
bool isTrackerMuon() const
Definition: Muon.h:220
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:53
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
bool isGlobalMuon() const
Definition: Muon.h:219
TrackDetectorAssociator trackAssociator_
std::pair< double, double > Point
Definition: CaloEllipse.h:18
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
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:104
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
TrackAssociatorParameters trackAssociatorParameters_
const int mu
Definition: Constants.h:23
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:52
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
virtual void produce(edm::Event &, const edm::EventSetup &)
const T & get() const
Definition: EventSetup.h:55
MuonMETValueMapProducer(const edm::ParameterSet &)
tuple muons
Definition: patZpeak.py:38
TrackDetMatchInfo associate(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const AssociatorParameters &)
virtual float pt() const GCC11_FINAL
transverse momentum
void loadParameters(const edm::ParameterSet &)
math::PtEtaPhiELorentzVectorF LorentzVector
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:55