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 
35 //
36 // class declaration
37 //
38 
40 public:
42 
43  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
44 
45 private:
46  void produce(edm::Event&, const edm::EventSetup&) override;
47 
48  // ----------member data ---------------------------
50  double ZMass = 91.0;
51 };
52 
53 //
54 // constants, enums and typedefs
55 //
56 
57 //
58 // static data member definitions
59 //
60 
61 //
62 // constructors and destructor
63 //
65  : ZmumuCandidates_(consumes<edm::View<reco::CompositeCandidate>>(
66  iConfig.getParameter<edm::InputTag>("ZmumuCandidatesCollection"))) {
67  //register your products
68  /* Examples
69  produces<ExampleData2>();
70 
71  //if do put with a label
72  produces<ExampleData2>("label");
73 
74  //if you want to put into the Run
75  produces<ExampleData2,InRun>();
76 */
77  produces<edm::RefVector<pat::MuonCollection>>();
78 
79  //now do what ever other initialization is needed
80 }
81 
82 //
83 // member functions
84 //
85 
86 // ------------ method called to produce the data ------------
88  using namespace edm;
90  iEvent.getByToken(ZmumuCandidates_, ZmumuCandidatesHandle);
92 
93  const reco::CompositeCandidate* chosenZCand = nullptr;
94  double massDifference = -1.0;
96  iZCand != ZmumuCandidates.end();
97  ++iZCand) {
98  if (std::abs(ZMass - iZCand->mass()) < massDifference || massDifference < 0) {
99  massDifference = std::abs(ZMass - iZCand->mass());
100  chosenZCand = &(*iZCand);
101  }
102  }
103  std::unique_ptr<edm::RefVector<pat::MuonCollection>> prod(new edm::RefVector<pat::MuonCollection>());
104  prod->reserve(2);
105  prod->push_back(chosenZCand->daughter(0)->masterClone().castTo<pat::MuonRef>());
106  prod->push_back(chosenZCand->daughter(1)->masterClone().castTo<pat::MuonRef>());
107  iEvent.put(std::move(prod));
108 }
109 
110 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
112  //The following says we do not know what parameters are allowed so do no validation
113  // Please change this to state exactly what you do use, even if it is no parameters
115  desc.setUnknown();
116  descriptions.addDefault(desc);
117 }
118 
119 //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) ...
REF castTo() const
Definition: RefToBase.h:259
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MuMuForEmbeddingSelector(const edm::ParameterSet &)
fixed size matrix
HLT enums.
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
def move(src, dest)
Definition: eostools.py:511
virtual const CandidateBaseRef & masterClone() const =0