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 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
32 
35 
36 //
37 // class declaration
38 //
39 
41  public:
43  ~MuMuForEmbeddingSelector() override;
44 
45  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
46 
47  private:
48  void beginStream(edm::StreamID) override;
49  void produce(edm::Event&, const edm::EventSetup&) override;
50  void endStream() override;
51 
52  //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
53  //virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
54  //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
55  //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
56 
57  // ----------member data ---------------------------
59  double ZMass = 91.0;
60 };
61 
62 //
63 // constants, enums and typedefs
64 //
65 
66 
67 //
68 // static data member definitions
69 //
70 
71 //
72 // constructors and destructor
73 //
75  ZmumuCandidates_(consumes< edm::View<reco::CompositeCandidate> >(iConfig.getParameter<edm::InputTag>("ZmumuCandidatesCollection")))
76 {
77  //register your products
78 /* Examples
79  produces<ExampleData2>();
80 
81  //if do put with a label
82  produces<ExampleData2>("label");
83 
84  //if you want to put into the Run
85  produces<ExampleData2,InRun>();
86 */
87  produces<edm::RefVector<pat::MuonCollection>>();
88 
89  //now do what ever other initialization is needed
90 }
91 
92 
94 {
95 
96  // do anything here that needs to be done at destruction time
97  // (e.g. close files, deallocate resources etc.)
98 
99 }
100 
101 
102 //
103 // member functions
104 //
105 
106 // ------------ method called to produce the data ------------
107 void
109 {
110  using namespace edm;
111  edm::Handle< edm::View<reco::CompositeCandidate> > ZmumuCandidatesHandle;
112  iEvent.getByToken(ZmumuCandidates_, ZmumuCandidatesHandle);
113  edm::View<reco::CompositeCandidate> ZmumuCandidates = *ZmumuCandidatesHandle;
114 
115  const reco::CompositeCandidate* chosenZCand = nullptr;
116  double massDifference = -1.0;
117  for (edm::View<reco::CompositeCandidate>::const_iterator iZCand = ZmumuCandidates.begin(); iZCand != ZmumuCandidates.end(); ++iZCand)
118  {
119  if (std::abs(ZMass - iZCand->mass()) < massDifference || massDifference < 0)
120  {
121  massDifference = std::abs(ZMass - iZCand->mass());
122  chosenZCand = &(*iZCand);
123  }
124 
125  }
126  std::unique_ptr<edm::RefVector<pat::MuonCollection>> prod(new edm::RefVector<pat::MuonCollection>());
127  prod->reserve(2);
128  prod->push_back(chosenZCand->daughter(0)->masterClone().castTo<pat::MuonRef>());
129  prod->push_back(chosenZCand->daughter(1)->masterClone().castTo<pat::MuonRef>());
130  iEvent.put(std::move(prod));
131 }
132 
133 
134 // ------------ method called once each stream before processing any runs, lumis or events ------------
135 void
137 {
138 }
139 
140 // ------------ method called once each stream after processing all runs, lumis and events ------------
141 void
143 }
144 
145 // ------------ method called when starting to processes a run ------------
146 /*
147 void
148 MuMuForEmbeddingSelector::beginRun(edm::Run const&, edm::EventSetup const&)
149 {
150 }
151 */
152 
153 // ------------ method called when ending the processing of a run ------------
154 /*
155 void
156 MuMuForEmbeddingSelector::endRun(edm::Run const&, edm::EventSetup const&)
157 {
158 }
159 */
160 
161 // ------------ method called when starting to processes a luminosity block ------------
162 /*
163 void
164 MuMuForEmbeddingSelector::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
165 {
166 }
167 */
168 
169 // ------------ method called when ending the processing of a luminosity block ------------
170 /*
171 void
172 MuMuForEmbeddingSelector::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
173 {
174 }
175 */
176 
177 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
178 void
180  //The following says we do not know what parameters are allowed so do no validation
181  // Please change this to state exactly what you do use, even if it is no parameters
183  desc.setUnknown();
184  descriptions.addDefault(desc);
185 }
186 
187 //define this as a plug-in
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
const_iterator begin() const
void beginStream(edm::StreamID) override
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const Candidate * daughter(size_type) const override
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
MuMuForEmbeddingSelector(const edm::ParameterSet &)
virtual const CandidateBaseRef & masterClone() const =0
REF castTo() const
Definition: RefToBase.h:286
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_
const_iterator end() const
void produce(edm::Event &, const edm::EventSetup &) override
def move(src, dest)
Definition: eostools.py:510