CMS 3D CMS Logo

MuMuForEmbeddingSelector.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TauAnalysis/EmbeddingProducer
4 // Class: MuMuForEmbeddingSelector
5 //
13 //
14 // Original Author: Artur Akhmetshin
15 // Created: Mon, 13 Jun 2016 11:05:32 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
31 
34 
38 
41 
42 //
43 // class declaration
44 //
45 
47 public:
49 
50  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
51 
52 private:
53  void produce(edm::Event &, const edm::EventSetup &) override;
54 
55  // ----------member data ---------------------------
61  bool use_zmass = false;
62  static constexpr double zmass = 91.1876;
63 };
64 
65 //
66 // constants, enums and typedefs
67 //
68 
69 //
70 // static data member definitions
71 //
72 
73 //
74 // constructors and destructor
75 //
77  : ZmumuCandidates_(consumes<edm::View<reco::CompositeCandidate>>(
78  iConfig.getParameter<edm::InputTag>("ZmumuCandidatesCollection"))) {
79  use_zmass = iConfig.getParameter<bool>("use_zmass");
80  produces<edm::RefVector<pat::MuonCollection>>();
81  produces<float>("oldMass");
82  produces<float>("newMass");
83  produces<float>("nPairCandidates");
84  produces<bool>("isMediumLeadingMuon");
85  produces<bool>("isTightLeadingMuon");
86  produces<bool>("isMediumTrailingMuon");
87  produces<bool>("isTightTrailingMuon");
88  produces<float>("initialMETEt");
89  produces<float>("initialMETphi");
90  produces<float>("initialPuppiMETEt");
91  produces<float>("initialPuppiMETphi");
92  theVertexLabel_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("inputTagVertex"));
93  theBeamSpotLabel_ = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("inputTagBeamSpot"));
94  theMETLabel_ = consumes<edm::View<pat::MET>>(iConfig.getParameter<edm::InputTag>("Met"));
95  thePuppiMETLabel_ = consumes<edm::View<pat::MET>>(iConfig.getParameter<edm::InputTag>("PuppiMet"));
96  // now do what ever other initialization is needed
97 }
98 
99 //
100 // member functions
101 //
102 
103 // ------------ method called to produce the data ------------
105  using namespace edm;
107  iEvent.getByToken(ZmumuCandidates_, ZmumuCandidatesHandle);
108  edm::View<reco::CompositeCandidate> ZmumuCandidates = *ZmumuCandidatesHandle;
109  const reco::CompositeCandidate *chosenZCand = nullptr;
110  const reco::CompositeCandidate *chosenZCand_zmass = nullptr;
111  const reco::CompositeCandidate *chosenZCand_largest = nullptr;
112  double massDifference = 9999;
114  iEvent.getByToken(theBeamSpotLabel_, beamSpot);
116  iEvent.getByToken(theVertexLabel_, vertex);
118  iEvent.getByToken(theMETLabel_, met);
120  iEvent.getByToken(thePuppiMETLabel_, puppimet);
121  // get primary vertex
122  reco::Vertex::Point posVtx;
123  reco::Vertex::Error errVtx;
124  for (const auto &vtx : *vertex) {
125  if (vtx.isValid() && !vtx.isFake()) {
126  posVtx = vtx.position();
127  errVtx = vtx.error();
128  break;
129  }
130  }
131  reco::Vertex primaryVertex(posVtx, errVtx);
132 
134  iZCand != ZmumuCandidates.end();
135  ++iZCand) {
136  if (std::abs(zmass - iZCand->mass()) < massDifference) {
137  massDifference = std::abs(zmass - iZCand->mass());
138  chosenZCand_zmass = &(*iZCand);
139  }
140  }
142  iZCand != ZmumuCandidates.end();
143  ++iZCand) {
144  if (chosenZCand_largest == nullptr) {
145  chosenZCand_largest = &(*iZCand);
146  } else {
147  if (iZCand->mass() > chosenZCand_largest->mass()) {
148  chosenZCand_largest = &(*iZCand);
149  }
150  }
151  }
152  if (use_zmass) {
153  chosenZCand = chosenZCand_zmass;
154  } else {
155  chosenZCand = chosenZCand_largest;
156  }
157 
158  std::unique_ptr<edm::RefVector<pat::MuonCollection>> prod(new edm::RefVector<pat::MuonCollection>());
159  prod->reserve(2);
160  prod->push_back(chosenZCand->daughter(0)->masterClone().castTo<pat::MuonRef>());
161  prod->push_back(chosenZCand->daughter(1)->masterClone().castTo<pat::MuonRef>());
162  iEvent.put(std::move(prod));
163  iEvent.put(std::make_unique<float>(chosenZCand_zmass->mass()), "oldMass");
164  iEvent.put(std::make_unique<float>(chosenZCand_largest->mass()), "newMass");
165  iEvent.put(std::make_unique<float>(ZmumuCandidates.size()), "nPairCandidates");
166  iEvent.put(std::make_unique<bool>(chosenZCand->daughter(0)->masterClone().castTo<pat::MuonRef>()->isMediumMuon()),
167  "isMediumLeadingMuon");
168  iEvent.put(std::make_unique<bool>(
170  "isTightLeadingMuon");
171  iEvent.put(std::make_unique<bool>(chosenZCand->daughter(1)->masterClone().castTo<pat::MuonRef>()->isMediumMuon()),
172  "isMediumTrailingMuon");
173  iEvent.put(std::make_unique<bool>(
175  "isTightTrailingMuon");
176  iEvent.put(std::make_unique<float>(met->at(0).et()), "initialMETEt");
177  iEvent.put(std::make_unique<float>(met->at(0).phi()), "initialMETphi");
178  iEvent.put(std::make_unique<float>(puppimet->at(0).et()), "initialPuppiMETEt");
179  iEvent.put(std::make_unique<float>(puppimet->at(0).phi()), "initialPuppiMETphi");
180 }
181 
182 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
184  // The following says we do not know what parameters are allowed so do no validation
185  // Please change this to state exactly what you do use, even if it is no parameters
187  desc.setUnknown();
188  descriptions.addDefault(desc);
189 }
190 
191 // define this as a plug-in
const Candidate * daughter(size_type) const override
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::EDGetTokenT< edm::View< pat::MET > > thePuppiMETLabel_
bool isMediumMuon(const reco::Muon &, bool run2016_hip_mitigation=false)
static constexpr double zmass
REF castTo() const
Definition: RefToBase.h:243
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:45
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< reco::VertexCollection > theVertexLabel_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< reco::BeamSpot > theBeamSpotLabel_
MuMuForEmbeddingSelector(const edm::ParameterSet &)
edm::EDGetTokenT< edm::View< pat::MET > > theMETLabel_
fixed size matrix
HLT enums.
double mass() const final
mass
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:88
edm::EDGetTokenT< edm::View< reco::CompositeCandidate > > ZmumuCandidates_
void produce(edm::Event &, const edm::EventSetup &) override
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
primaryVertex
hltOfflineBeamSpot for HLTMON
def move(src, dest)
Definition: eostools.py:511
virtual const CandidateBaseRef & masterClone() const =0