CMS 3D CMS Logo

WMuNuProducer.cc
Go to the documentation of this file.
1 // //
3 // WMuNuCandidate Producer //
4 // //
6 // //
7 // Productor of WMuNuCandidates for Analysis //
8 // --> Creates a WMuNuCandidateCollection //
9 // --> One Candidate is created per muon in the event, combinig the information with a selected kind of Met //
10 // (met kind configurable via cfg) //
11 // --> All WMuNuCandidates are stored in the event, ordered by muon pt. //
12 // --> The WMuNuCandidate to be used for the Inclusive analysis is then the first one! (Highest Pt) //
13 // //
15 
16 
17 
22 #include "TH1D.h"
23 #include <map>
24 // system include files
25 #include <memory>
26 #include <vector>
27 
32 
33 
35 public:
37  ~WMuNuProducer() override;
38 
39 
40 private:
41 
42  void produce(edm::Event&, const edm::EventSetup&) override;
43  void beginJob() override;
44  void endJob() override;
45 
48 
49  struct ComparePt {
51  double pt1 = w1.getMuon().pt();
52  double pt2 = w2.getMuon().pt();
53  return (pt1> pt2);
54  }
55  };
57 
58  unsigned int nall;
59 
60 
61 };
62 
66 
71 
74 
76 
78 
80 
81 
82 
83 
84 using namespace edm;
85 using namespace std;
86 using namespace reco;
87 
89  // Input collections
90  muonToken_(consumes<View<Muon> >(cfg.getUntrackedParameter<edm::InputTag> ("MuonTag", edm::InputTag("muons")))),
91  metToken_(consumes<View<MET> >(cfg.getUntrackedParameter<edm::InputTag> ("METTag", edm::InputTag("met"))))
92 {
93  produces< WMuNuCandidateCollection >();
94 }
95 
97 }
98 
100  LogTrace("")<<"WMuNuCandidateCollection Stored in the Event";
101 }
102 
103 
105 {
106 
107  // do anything here that needs to be done at desctruction time
108  // (e.g. close files, deallocate resources etc.)
109 
110 }
111 
112 
114 
115  // Muon collection
117  if (!ev.getByToken(muonToken_, muonCollection)) {
118  LogError("") << ">>> Muon collection does not exist !!!";
119  return;
120  }
121  int muonCollectionSize = muonCollection->size();
122 
123  // MET
125  if (!ev.getByToken(metToken_, metCollection)) {
126  LogError("") << ">>> MET collection does not exist !!!";
127  return;
128  }
129  //const MET& Met = metCollection->at(0);
130  edm::Ptr<reco::MET> met(metCollection,0);
131 
132 
133  if (muonCollectionSize<1) return;
134 
135  unique_ptr< WMuNuCandidateCollection > WMuNuCandidates(new WMuNuCandidateCollection );
136 
137 
138  // Fill Collection with n muons --> n W Candidates ordered by pt
139 
140  for (int indx=0; indx<muonCollectionSize; indx++){
141  edm::Ptr<reco::Muon> muon(muonCollection,indx);
142  if (!muon->isGlobalMuon()) continue;
143  if (muon->globalTrack().isNull()) continue;
144  if (muon->innerTrack().isNull()) continue;
145 
146  // Build WMuNuCandidate
147  LogTrace("")<<"Building WMuNu Candidate!";
148  WMuNuCandidate* WCand = new WMuNuCandidate(muon,met);
149  LogTrace("") << "\t... W mass, W_et: "<<WCand->massT()<<", "<<WCand->eT()<<"[GeV]";
150  LogTrace("") << "\t... W_px, W_py: "<<WCand->px()<<", "<< WCand->py() <<"[GeV]";
151  LogTrace("") << "\t... acop: " << WCand->acop();
152  LogTrace("") << "\t... Muon pt, px, py, pz: "<<WCand->getMuon().pt()<<", "<<WCand->getMuon().px()<<", "<<WCand->getMuon().py()<<", "<< WCand->getMuon().pz()<<" [GeV]";
153  LogTrace("") << "\t... Met met_et, met_px, met_py : "<<WCand->getNeutrino().pt()<<", "<<WCand->getNeutrino().px()<<", "<<WCand->getNeutrino().py()<<" [GeV]";
154  WMuNuCandidates->push_back(*WCand);
155  }
156 
157  std::sort(WMuNuCandidates->begin(),WMuNuCandidates->end(),ptComparator);
158 
159  ev.put(std::move(WMuNuCandidates));
160 
161 }
162 
~WMuNuProducer() override
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
common ppss p3p6s2 common epss epspn46 common const1 w2
Definition: inclppp.h:1
virtual TrackRef innerTrack() const
Definition: Muon.h:48
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
edm::EDGetTokenT< edm::View< reco::MET > > metToken_
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
double px() const final
x coordinate of momentum vector
void beginJob() override
double pt() const final
transverse momentum
bool ev
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void produce(edm::Event &, const edm::EventSetup &) override
Definition: Muon.py:1
bool isGlobalMuon() const override
Definition: Muon.h:265
double pz() const final
z coordinate of momentum vector
Definition: MET.h:42
double eT() const
double acop() const
unsigned int nall
bool isNull() const
Checks for null.
Definition: Ref.h:250
#define LogTrace(id)
std::vector< reco::WMuNuCandidate > WMuNuCandidateCollection
met
===> hadronic RAZOR
double py() const final
y coordinate of momentum vector
bool operator()(reco::WMuNuCandidate w1, reco::WMuNuCandidate w2) const
double massT() const
ComparePt ptComparator
fixed size matrix
HLT enums.
WMuNuProducer(const edm::ParameterSet &)
const reco::Muon & getMuon() const
const reco::MET & getNeutrino() const
def move(src, dest)
Definition: eostools.py:510
void endJob() override
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:54