CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/ElectroWeakAnalysis/WMuNu/src/WMuNuProducer.cc

Go to the documentation of this file.
00001 
00002 //                                                                                                                      //
00003 //                                    WMuNuCandidate Producer                                                           //
00004 //                                                                                                                      //    
00006 //                                                                                                                      //      
00007 //    Productor of WMuNuCandidates for Analysis                                                                         //
00008 //    --> Creates a WMuNuCandidateCollection                                                                            //
00009 //    --> One Candidate is created per muon in the event, combinig the information with a selected kind of Met          //
00010 //        (met kind configurable via cfg)                                                                               //
00011 //    --> All WMuNuCandidates are stored in the event, ordered by muon pt.                                              //
00012 //    --> The WMuNuCandidate to be used for the Inclusive analysis is then the first one! (Highest Pt)                  //
00013 //                                                                                                                      //
00015 
00016 
00017 
00018 #include "FWCore/Utilities/interface/InputTag.h"
00019 #include "FWCore/Framework/interface/EDProducer.h"
00020 #include "FWCore/Framework/interface/Event.h"
00021 #include "FWCore/Framework/interface/MakerMacros.h"
00022 #include "TH1D.h"
00023 #include <map>
00024 // system include files
00025 #include <memory>
00026 #include <vector>
00027 
00028 #include "AnalysisDataFormats/EWK/interface/WMuNuCandidate.h"
00029 
00030 
00031 class WMuNuProducer : public edm::EDProducer {
00032 public:
00033   WMuNuProducer(const edm::ParameterSet&);
00034   ~WMuNuProducer();
00035 
00036 
00037 private:
00038 
00039   virtual void produce(edm::Event&, const edm::EventSetup&);
00040   virtual void beginJob();
00041   virtual void endJob();
00042 
00043   edm::InputTag muonTag_;
00044   edm::InputTag metTag_;
00045   const std::string WMuNuCollectionTag_;
00046 
00047   struct ComparePt {
00048             bool operator()(reco::WMuNuCandidate w1, reco::WMuNuCandidate w2 ) const {
00049                   double pt1 = w1.getMuon().pt();
00050                   double pt2 = w2.getMuon().pt();
00051                   return (pt1> pt2); 
00052             }
00053    };
00054   ComparePt ptComparator;
00055 
00056   unsigned int nall;
00057 
00058 
00059 };
00060 
00061 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00062 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00063 #include "DataFormats/Common/interface/Handle.h"
00064 
00065 #include "FWCore/ServiceRegistry/interface/Service.h"
00066 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00067 #include "DataFormats/TrackReco/interface/Track.h"
00068 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00069 
00070 #include "DataFormats/MuonReco/interface/Muon.h"
00071 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00072 #include "DataFormats/METReco/interface/MET.h"
00073 #include "DataFormats/JetReco/interface/Jet.h"
00074 
00075 #include "DataFormats/GeometryVector/interface/Phi.h"
00076 
00077 #include "DataFormats/Common/interface/TriggerResults.h"
00078 
00079 #include "DataFormats/Common/interface/View.h"
00080 
00081 
00082 
00083   
00084 using namespace edm;
00085 using namespace std;
00086 using namespace reco;
00087 
00088 WMuNuProducer::WMuNuProducer( const ParameterSet & cfg ) :
00089       // Input collections
00090       muonTag_(cfg.getUntrackedParameter<edm::InputTag> ("MuonTag", edm::InputTag("muons"))),
00091       metTag_(cfg.getUntrackedParameter<edm::InputTag> ("METTag", edm::InputTag("met")))
00092 {
00093   produces< WMuNuCandidateCollection >();
00094 }
00095 
00096 void WMuNuProducer::beginJob() {
00097 }
00098 
00099 void WMuNuProducer::endJob() {
00100    LogTrace("")<<"WMuNuCandidateCollection Stored in the Event";
00101 }
00102 
00103 
00104 WMuNuProducer::~WMuNuProducer()
00105 {
00106 
00107    // do anything here that needs to be done at desctruction time
00108    // (e.g. close files, deallocate resources etc.)
00109 
00110 }
00111 
00112 
00113 void WMuNuProducer::produce (Event & ev, const EventSetup &) {
00114 
00115       // Muon collection
00116       Handle<View<Muon> > muonCollection;
00117       if (!ev.getByLabel(muonTag_, muonCollection)) {
00118             LogError("") << ">>> Muon collection does not exist !!!";
00119             return;
00120       }
00121       int muonCollectionSize = muonCollection->size();
00122 
00123       // MET
00124       Handle<View<MET> > metCollection;
00125       if (!ev.getByLabel(metTag_, metCollection)) {
00126             LogError("") << ">>> MET collection does not exist !!!";
00127             return;
00128       }
00129       //const MET& Met = metCollection->at(0);
00130       edm::Ptr<reco::MET> met(metCollection,0);
00131 
00132 
00133       if (muonCollectionSize<1) return;
00134      
00135       auto_ptr< WMuNuCandidateCollection > WMuNuCandidates(new WMuNuCandidateCollection );
00136 
00137 
00138      // Fill Collection with n muons --> n W Candidates ordered by pt
00139  
00140      for (int indx=0; indx<muonCollectionSize; indx++){ 
00141             edm::Ptr<reco::Muon> muon(muonCollection,indx);
00142             if (!muon->isGlobalMuon()) continue;
00143             if (muon->globalTrack().isNull()) continue;
00144             if (muon->innerTrack().isNull()) continue;
00145  
00146       // Build WMuNuCandidate
00147       LogTrace("")<<"Building WMuNu Candidate!"; 
00148       WMuNuCandidate* WCand = new WMuNuCandidate(muon,met); 
00149       LogTrace("") << "\t... W mass, W_et: "<<WCand->massT()<<", "<<WCand->eT()<<"[GeV]";
00150       LogTrace("") << "\t... W_px, W_py: "<<WCand->px()<<", "<< WCand->py() <<"[GeV]";
00151       LogTrace("") << "\t... acop:  " << WCand->acop();
00152       LogTrace("") << "\t... Muon pt, px, py, pz: "<<WCand->getMuon().pt()<<", "<<WCand->getMuon().px()<<", "<<WCand->getMuon().py()<<", "<< WCand->getMuon().pz()<<" [GeV]";
00153       LogTrace("") << "\t... Met  met_et, met_px, met_py : "<<WCand->getNeutrino().pt()<<", "<<WCand->getNeutrino().px()<<", "<<WCand->getNeutrino().py()<<" [GeV]";
00154         WMuNuCandidates->push_back(*WCand);
00155        } 
00156 
00157       std::sort(WMuNuCandidates->begin(),WMuNuCandidates->end(),ptComparator);      
00158 
00159       ev.put(WMuNuCandidates);
00160 
00161 }
00162 
00163 DEFINE_FWK_MODULE(WMuNuProducer);