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  ~MuMuForEmbeddingSelector() override;
43 
44  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
45 
46 private:
47  void beginStream(edm::StreamID) override;
48  void produce(edm::Event&, const edm::EventSetup&) override;
49  void endStream() override;
50 
51  //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
52  //virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
53  //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
54  //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
55 
56  // ----------member data ---------------------------
58  double ZMass = 91.0;
59 };
60 
61 //
62 // constants, enums and typedefs
63 //
64 
65 //
66 // static data member definitions
67 //
68 
69 //
70 // constructors and destructor
71 //
73  : ZmumuCandidates_(consumes<edm::View<reco::CompositeCandidate>>(
74  iConfig.getParameter<edm::InputTag>("ZmumuCandidatesCollection"))) {
75  //register your products
76  /* Examples
77  produces<ExampleData2>();
78 
79  //if do put with a label
80  produces<ExampleData2>("label");
81 
82  //if you want to put into the Run
83  produces<ExampleData2,InRun>();
84 */
85  produces<edm::RefVector<pat::MuonCollection>>();
86 
87  //now do what ever other initialization is needed
88 }
89 
91  // do anything here that needs to be done at destruction time
92  // (e.g. close files, deallocate resources etc.)
93 }
94 
95 //
96 // member functions
97 //
98 
99 // ------------ method called to produce the data ------------
101  using namespace edm;
103  iEvent.getByToken(ZmumuCandidates_, ZmumuCandidatesHandle);
104  edm::View<reco::CompositeCandidate> ZmumuCandidates = *ZmumuCandidatesHandle;
105 
106  const reco::CompositeCandidate* chosenZCand = nullptr;
107  double massDifference = -1.0;
109  iZCand != ZmumuCandidates.end();
110  ++iZCand) {
111  if (std::abs(ZMass - iZCand->mass()) < massDifference || massDifference < 0) {
112  massDifference = std::abs(ZMass - iZCand->mass());
113  chosenZCand = &(*iZCand);
114  }
115  }
116  std::unique_ptr<edm::RefVector<pat::MuonCollection>> prod(new edm::RefVector<pat::MuonCollection>());
117  prod->reserve(2);
118  prod->push_back(chosenZCand->daughter(0)->masterClone().castTo<pat::MuonRef>());
119  prod->push_back(chosenZCand->daughter(1)->masterClone().castTo<pat::MuonRef>());
120  iEvent.put(std::move(prod));
121 }
122 
123 // ------------ method called once each stream before processing any runs, lumis or events ------------
125 
126 // ------------ method called once each stream after processing all runs, lumis and events ------------
128 
129 // ------------ method called when starting to processes a run ------------
130 /*
131 void
132 MuMuForEmbeddingSelector::beginRun(edm::Run const&, edm::EventSetup const&)
133 {
134 }
135 */
136 
137 // ------------ method called when ending the processing of a run ------------
138 /*
139 void
140 MuMuForEmbeddingSelector::endRun(edm::Run const&, edm::EventSetup const&)
141 {
142 }
143 */
144 
145 // ------------ method called when starting to processes a luminosity block ------------
146 /*
147 void
148 MuMuForEmbeddingSelector::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
149 {
150 }
151 */
152 
153 // ------------ method called when ending the processing of a luminosity block ------------
154 /*
155 void
156 MuMuForEmbeddingSelector::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
157 {
158 }
159 */
160 
161 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
163  //The following says we do not know what parameters are allowed so do no validation
164  // Please change this to state exactly what you do use, even if it is no parameters
166  desc.setUnknown();
167  descriptions.addDefault(desc);
168 }
169 
170 //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)
void beginStream(edm::StreamID) override
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:86
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