CMS 3D CMS Logo

EDProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: __subsys__/__pkgname__
4 // Class: __class__
5 //
13 //
14 // Original Author: __author__
15 // Created: __date__
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
31 
32 @example_myparticle#include "DataFormats/Candidate/interface/Particle.h"
33 @example_myparticle#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
34 @example_myparticle#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
35 @example_myparticle#include "DataFormats/MuonReco/interface/Muon.h"
36 @example_myparticle#include "DataFormats/MuonReco/interface/MuonFwd.h"
37 @example_myparticle#include "FWCore/MessageLogger/interface/MessageLogger.h"
38 @example_myparticle#include "FWCore/Utilities/interface/InputTag.h"
39 @example_myparticle
40 //
41 // class declaration
42 //
43 
44 class __class__ : public edm::stream::EDProducer<> {
45 public:
46  explicit __class__(const edm::ParameterSet&);
47  ~__class__() override;
48 
49  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
50 
51 private:
52  void beginStream(edm::StreamID) override;
53  void produce(edm::Event&, const edm::EventSetup&) override;
54  void endStream() override;
55 
56  //void beginRun(edm::Run const&, edm::EventSetup const&) override;
57  //void endRun(edm::Run const&, edm::EventSetup const&) override;
58  //void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
59  //void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
60 
61 @example_myparticle // define container that will be booked into event
62 @example_myparticle typedef std::vector<reco::Particle> MyParticleCollection;
63 @example_myparticle
64  // ----------member data ---------------------------
68 };
69 
70 //
71 // constants, enums and typedefs
72 //
73 
74 //
75 // static data member definitions
76 //
77 
78 //
79 // constructors and destructor
80 //
83 @example_myparticle : muonToken_(consumes<reco::MuonCollection>(iConfig.getParameter<edm::InputTag>("muons"))),
84 @example_myparticle electronToken_(consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electrons"))),
85 @example_myparticle putToken_(produces<MyParticleCollection>("particles")) {
86  //register your products
87  /* Examples
88  produces<ExampleData2>();
89 
90  //if do put with a label
91  produces<ExampleData2>("label");
92 
93  //if you want to put into the Run
94  produces<ExampleData2,InRun>();
95  */
96  //now do what ever other initialization is needed
97 }
98 
100  // do anything here that needs to be done at destruction time
101  // (e.g. close files, deallocate resources etc.)
102  //
103  // please remove this method altogether if it would be left empty
104 }
105 
106 //
107 // member functions
108 //
109 
110 // ------------ method called to produce the data ------------
111 void __class__::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
112  using namespace edm;
113 @example_myparticle using namespace reco;
114 @example_myparticle using namespace std;
115  /* This is an event example
116  //Read 'ExampleData' from the Event
117  ExampleData const& in = iEvent.get(inToken_);
118 
119  //Use the ExampleData to create an ExampleData2 which
120  // is put into the Event
121  iEvent.put(std::make_unique<ExampleData2>(in));
122  */
123 
124  /* this is an EventSetup example
125  //Read SetupData from the SetupRecord in the EventSetup
126  SetupData& setup = iSetup.getData(setupToken_);
127  */
128 @example_myparticle
129 @example_myparticle auto const& muons = iEvent.get(muonToken_);
130 @example_myparticle auto const& electrons = iEvent.get(electronToken_);
131 @example_myparticle
132 @example_myparticle // create a new collection of Particle objects
133 @example_myparticle auto newParticles = std::make_unique<MyParticleCollection>();
134 @example_myparticle
135 @example_myparticle // if the number of electrons or muons is 4 (or 2 and 2), costruct a new particle
136 @example_myparticle if (muons.size() == 4 || electrons.size() == 4 || (muons.size() == 2 && electrons.size() == 2)) {
137 @example_myparticle // sums of momenta and charges will be calculated
138 @example_myparticle Particle::LorentzVector totalP4(0, 0, 0, 0);
139 @example_myparticle Particle::Charge charge(0);
140 @example_myparticle
141 @example_myparticle // loop over muons, sum over p4s and charges. Later same for electrons
142 @example_myparticle for (auto const& muon : muons) {
143 @example_myparticle totalP4 += muon.p4();
144 @example_myparticle charge += muon.charge();
145 @example_myparticle }
146 @example_myparticle
147 @example_myparticle for (auto const& electron : electrons) {
148 @example_myparticle totalP4 += electron.p4();
149 @example_myparticle charge += electron.charge();
150 @example_myparticle }
151 @example_myparticle
152 @example_myparticle // create a particle in the vector with momentum and charge from muons and electrons
153 @example_myparticle newParticles->emplace_back(charge, totalP4);
154 @example_myparticle }
155 @example_myparticle
156 @example_myparticle // save the vector
157 @example_myparticle iEvent.put(putToken_, move(newParticles));
158 }
159 
160 // ------------ method called once each stream before processing any runs, lumis or events ------------
162  // please remove this method if not needed
163 }
164 
165 // ------------ method called once each stream after processing all runs, lumis and events ------------
166 void __class__::endStream() {
167  // please remove this method if not needed
168 }
169 
170 // ------------ method called when starting to processes a run ------------
171 /*
172 void
173 __class__::beginRun(edm::Run const&, edm::EventSetup const&)
174 {
175 }
176 */
177 
178 // ------------ method called when ending the processing of a run ------------
179 /*
180 void
181 __class__::endRun(edm::Run const&, edm::EventSetup const&)
182 {
183 }
184 */
185 
186 // ------------ method called when starting to processes a luminosity block ------------
187 /*
188 void
189 __class__::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
190 {
191 }
192 */
193 
194 // ------------ method called when ending the processing of a luminosity block ------------
195 /*
196 void
197 __class__::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
198 {
199 }
200 */
201 
202 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
204  //The following says we do not know what parameters are allowed so do no validation
205  // Please change this to state exactly what you do use, even if it is no parameters
207  desc.setUnknown();
208  descriptions.addDefault(desc);
209 @example_myparticle
210 @example_myparticle //Specify that only 'muons' and 'electrons' are allowed
211 @example_myparticle //To use, remove the default given above and uncomment below
212 @example_myparticle //ParameterSetDescription desc;
213 @example_myparticle //desc.add<edm::InputTag>("muons","muons");
214 @example_myparticle //desc.add<edm::InputTag>("electrons","gedGsfElectrons");
215 @example_myparticle //descriptions.addWithDefaultLabel(desc);
216 }
217 
218 //define this as a plug-in
void produce(edm::Event &, const edm::EventSetup &) override
Definition: EDLooper.cc:90
example_myparticle example_myparticle edm::EDGetTokenT< reco::MuonCollection > muonToken_
Definition: EDProducer.cc:65
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
example_myparticle edm::EDPutTokenT< MyParticleCollection > putToken_
Definition: EDProducer.cc:67
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
example_myparticle edm::EDGetTokenT< reco::GsfElectronCollection > electronToken_
Definition: EDProducer.cc:66
__class__()
Definition: Skeleton.cc:29
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:212
example_global example_streamclass __class__
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
void endStream() override
Definition: EDFilter.cc:113
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
virtual ~__class__()
fixed size matrix
HLT enums.
bool include(const CollT &coll, const ItemT &item)
def move(src, dest)
Definition: eostools.py:511
void beginStream(edm::StreamID) override
Definition: EDFilter.cc:108
math::PtEtaPhiELorentzVectorF LorentzVector
example_myparticle example_myparticle typedef std::vector< reco::Particle > MyParticleCollection
Definition: EDProducer.cc:62