CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/RecoMET/METProducers/src/MuonMETValueMapProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    MuonMETValueMapProducer
00004 // Class:      MuonMETValueMapProducer
00005 // 
00013 //
00014 // Original Author:  Puneeth Kalavase
00015 //         Created:  Sun Mar 15 11:33:20 CDT 2009
00016 // $Id: MuonMETValueMapProducer.cc,v 1.3 2012/01/28 16:01:24 eulisse Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "RecoMET/METProducers/interface/MuonMETValueMapProducer.h"
00026 #include "RecoMET/METAlgorithms/interface/MuonMETAlgo.h"
00027 #include "DataFormats/MuonReco/interface/Muon.h"
00028 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00029 #include "DataFormats/TrackReco/interface/Track.h"
00030 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00031 #include "DataFormats/Common/interface/ValueMap.h" 
00032 #include "MagneticField/Engine/interface/MagneticField.h"
00033 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00034 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00035 
00036 
00037 #include "DataFormats/MuonReco/interface/MuonMETCorrectionData.h"
00038 #include "FWCore/Framework/interface/MakerMacros.h"
00039 
00040 typedef math::XYZTLorentzVector LorentzVector;
00041 typedef math::XYZPoint Point;
00042 
00043 
00044 namespace cms {
00045   MuonMETValueMapProducer::MuonMETValueMapProducer(const edm::ParameterSet& iConfig) {
00046 
00047     using namespace edm;
00048   
00049     produces<ValueMap<reco::MuonMETCorrectionData> >   ("muCorrData");
00050 
00051     //get configuration parameters
00052     minPt_            = iConfig.getParameter<double>("minPt"               );
00053     maxEta_           = iConfig.getParameter<double>("maxEta"              );
00054     isAlsoTkMu_       = iConfig.getParameter<bool>  ("isAlsoTkMu"          );
00055     maxNormChi2_      = iConfig.getParameter<double>("maxNormChi2"         );
00056     maxd0_            = iConfig.getParameter<double>("maxd0"               );
00057     minnHits_         = iConfig.getParameter<int>   ("minnHits"            );
00058     minnValidStaHits_ = iConfig.getParameter<int>   ("minnValidStaHits"    );
00059   
00060     beamSpotInputTag_            = iConfig.getParameter<InputTag>("beamSpotInputTag"         );
00061     muonInputTag_   = iConfig.getParameter<InputTag>("muonInputTag");
00062   
00063     //Parameters from earlier
00064     useTrackAssociatorPositions_ = iConfig.getParameter<bool>("useTrackAssociatorPositions");
00065     useHO_                       = iConfig.getParameter<bool>("useHO"                      );
00066   
00067     ParameterSet trackAssociatorParams =
00068       iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
00069     trackAssociatorParameters_.loadParameters(trackAssociatorParams);
00070     trackAssociator_.useDefaultPropagator();
00071   
00072     towerEtThreshold_ = iConfig.getParameter<double>("towerEtThreshold");
00073     useRecHits_     = iConfig.getParameter<bool>("useRecHits");
00074   
00075   }
00076 
00077 
00078   MuonMETValueMapProducer::~MuonMETValueMapProducer()
00079   {
00080  
00081     // do anything here that needs to be done at desctruction time
00082     // (e.g. close files, deallocate resources etc.)
00083 
00084   }
00085 
00086 
00087   //
00088   // member functions
00089   //
00090 
00091   // ------------ method called to produce the data  ------------
00092   void MuonMETValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
00093   
00094     using namespace edm;
00095     using namespace reco;
00096   
00097     //get the Muon collection
00098     Handle<View<reco::Muon> > muons;
00099     iEvent.getByLabel(muonInputTag_,muons);
00100 
00101     //use the BeamSpot
00102     Handle<BeamSpot> beamSpotH;
00103     iEvent.getByLabel(beamSpotInputTag_, beamSpotH);
00104 
00105     //get the Bfield
00106     edm::ESHandle<MagneticField> magneticField;
00107     iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
00108     //get the B-field at the origin
00109     double bfield = magneticField->inTesla(GlobalPoint(0.,0.,0.)).z();
00110 
00111     //make a ValueMap of ints => flags for 
00112     //met correction. The values and meanings of the flags are :
00113     // flag==0 --->    The muon is not used to correct the MET by default
00114     // flag==1 --->    The muon is used to correct the MET. The Global pt is used. For backward compatibility only
00115     // flag==2 --->    The muon is used to correct the MET. The tracker pt is used. For backward compatibility only
00116     // flag==3 --->    The muon is used to correct the MET. The standalone pt is used. For backward compatibility only
00117     // In general, the flag should never be 3. You do not want to correct the MET using
00118     // the pt measurement from the standalone system (unless you really know what you're 
00119     // doing
00120     //flag == 4 -->    The muon was treated as a Pion. This is used for the tcMET producer
00121     //flag == 5 -->    The default fit is used, i.e, we get the pt from muon->pt
00122     std::auto_ptr<ValueMap<MuonMETCorrectionData> > vm_muCorrData(new ValueMap<MuonMETCorrectionData>());
00123     
00124     unsigned int nMuons = muons->size();
00125     
00126     std::vector<MuonMETCorrectionData> v_muCorrData;
00127     for (unsigned int iMu=0; iMu<nMuons; iMu++) {
00128 
00129       const reco::Muon* mu = &(*muons)[iMu];
00130       double deltax = 0.0;
00131       double deltay = 0.0;
00132         
00133       TrackRef mu_track;
00134       if(mu->isGlobalMuon()) {
00135         mu_track = mu->globalTrack();
00136       } else if(mu->isTrackerMuon()) {
00137         mu_track = mu->innerTrack();
00138       } else 
00139         mu_track = mu->outerTrack();
00140     
00141       TrackDetMatchInfo info = trackAssociator_.associate(iEvent, iSetup,
00142                                                           trackAssociator_.getFreeTrajectoryState(iSetup, *mu_track),
00143                                                           trackAssociatorParameters_);
00144       MuonMETAlgo alg;
00145       alg.GetMuDepDeltas(mu, info,
00146                           useTrackAssociatorPositions_, useRecHits_,
00147                           useHO_, towerEtThreshold_, 
00148                           deltax, deltay, bfield);
00149 
00150     
00151       //now we have to figure out the flags
00152       MuonMETCorrectionData muMETCorrData(MuonMETCorrectionData::NotUsed, deltax, deltay);
00153       //have to be a global muon!
00154       if(!mu->isGlobalMuon()) {
00155         v_muCorrData.push_back(muMETCorrData);
00156         continue;
00157       }
00158     
00159       //if we require that the muon be both a global muon and tkmuon
00160       //but the muon fails the tkmuon requirement, we fail it
00161       if(!mu->isTrackerMuon() && isAlsoTkMu_) {
00162         v_muCorrData.push_back(muMETCorrData);
00163         continue;
00164       }
00165 
00166       //if we have gotten here, we only have muons which are both global and tracker
00167         
00168       TrackRef globTk = mu->globalTrack();
00169       TrackRef siTk   = mu->innerTrack();
00170         
00171       if(mu->pt() < minPt_ || fabs(mu->eta()) > maxEta_) {
00172         v_muCorrData.push_back(muMETCorrData);
00173         continue;
00174       }
00175       if(globTk->chi2()/globTk->ndof() > maxNormChi2_) {
00176         v_muCorrData.push_back(muMETCorrData);
00177         continue;
00178       }
00179       if(fabs(globTk->dxy(beamSpotH->position())) > fabs(maxd0_) ) {
00180         v_muCorrData.push_back(muMETCorrData);
00181         continue;
00182       }
00183       if(siTk->numberOfValidHits() < minnHits_) {
00184         v_muCorrData.push_back(muMETCorrData);
00185         continue;
00186       }
00187 
00188       if(globTk->hitPattern().numberOfValidMuonHits() < minnValidStaHits_) {
00189          v_muCorrData.push_back(muMETCorrData);
00190         continue;
00191       }   
00192       //if we've gotten here. the global muon has passed all the tests
00193       v_muCorrData.push_back(MuonMETCorrectionData(MuonMETCorrectionData::MuonCandidateValuesUsed, deltax, deltay));
00194     }
00195     
00196     ValueMap<MuonMETCorrectionData>::Filler dataFiller(*vm_muCorrData);
00197      
00198     dataFiller.insert(muons, v_muCorrData.begin(), v_muCorrData.end());
00199     dataFiller.fill();
00200 
00201     iEvent.put(vm_muCorrData, "muCorrData");
00202     
00203   }
00204   
00205   // ------------ method called once each job just before starting event loop  ------------
00206   void MuonMETValueMapProducer::beginJob()
00207   {
00208   }
00209 
00210   // ------------ method called once each job just after ending the event loop  ------------
00211   void MuonMETValueMapProducer::endJob() {
00212   }
00213 }
00214 
00215