CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
32 
33 @example_myparticle #include "DataFormats/MuonReco/interface/Muon.h"
34 @example_myparticle #include "DataFormats/EgammaCandidates/interface/PixelMatchGsfElectron.h"
35 @example_myparticle #include "DataFormats/Candidate/interface/Particle.h"
36 @example_myparticle #include "FWCore/MessageLogger/interface/MessageLogger.h"
37 @example_myparticle #include "FWCore/Utilities/interface/InputTag.h"
38 
39 //
40 // class declaration
41 //
42 
43 class __class__ : public edm::stream::EDProducer<> {
44  public:
45  explicit __class__(const edm::ParameterSet&);
46  ~__class__();
47 
48  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
49 
50  private:
51  virtual void beginStream(edm::StreamID) override;
52  virtual void produce(edm::Event&, const edm::EventSetup&) override;
53  virtual void endStream() override;
54 
55  //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
56  //virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
57  //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
58  //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
59 
60  // ----------member data ---------------------------
61 @example_myparticle edm::InputTag muonTags_;
62 @example_myparticle edm::InputTag electronTags_;
63 };
64 
65 //
66 // constants, enums and typedefs
67 //
68 
69 @example_myparticle // define container that will be booked into event
70 @example_myparticle typedef std::vector<reco::Particle> MyParticleCollection;
71 
72 //
73 // static data member definitions
74 //
75 
76 //
77 // constructors and destructor
78 //
80 @example_myparticle :
81 @example_myparticle muonTags_( iConfig.getParameter<edm::InputTag>( "muons" )),
82 @example_myparticle electronTags_( iConfig.getParameter<edm::InputTag>( "electrons" ))
83 {
84  //register your products
85 /* Examples
86  produces<ExampleData2>();
87 
88  //if do put with a label
89  produces<ExampleData2>("label");
90 
91  //if you want to put into the Run
92  produces<ExampleData2,InRun>();
93 */
94 @example_myparticle produces<MyParticleCollection>( "particles" );
95  //now do what ever other initialization is needed
96 
97 }
98 
99 
101 {
102 
103  // do anything here that needs to be done at destruction time
104  // (e.g. close files, deallocate resources etc.)
105 
106 }
107 
108 
109 //
110 // member functions
111 //
112 
113 // ------------ method called to produce the data ------------
114 void
116 {
117  using namespace edm;
118 @example_myparticle using namespace reco;
119 @example_myparticle using namespace std;
120 /* This is an event example
121  //Read 'ExampleData' from the Event
122  Handle<ExampleData> pIn;
123  iEvent.getByLabel("example",pIn);
124 
125  //Use the ExampleData to create an ExampleData2 which
126  // is put into the Event
127  std::unique_ptr<ExampleData2> pOut(new ExampleData2(*pIn));
128  iEvent.put(std::move(pOut));
129 */
130 
131 /* this is an EventSetup example
132  //Read SetupData from the SetupRecord in the EventSetup
133  ESHandle<SetupData> pSetup;
134  iSetup.get<SetupRecord>().get(pSetup);
135 */
136 
137 @example_myparticle Handle<MuonCollection> muons;
138 @example_myparticle iEvent.getByLabel( muonTags_, muons );
139 @example_myparticle
141 @example_myparticle iEvent.getByLabel( electronTags_, electrons );
142 @example_myparticle
143 @example_myparticle // create a new collection of Particle objects
144 @example_myparticle unique_ptr<MyParticleCollection> newParticles( new MyParticleCollection );
145 @example_myparticle
146 @example_myparticle // if the number of electrons or muons is 4 (or 2 and 2), costruct a new particle
147 @example_myparticle if( muons->size() == 4 || electrons->size() == 4 || ( muons->size() == 2 && electrons->size() == 2 ) ) {
148 @example_myparticle
149 @example_myparticle // sums of momenta and charges will be calculated
150 @example_myparticle Particle::LorentzVector totalP4( 0, 0, 0, 0 );
151 @example_myparticle Particle::Charge charge( 0 );
152 @example_myparticle
153 @example_myparticle // loop over muons, sum over p4s and charges. Later same for electrons
154 @example_myparticle for( MuonCollection::const_iterator muon = muons->begin(); muon != muons->end(); ++muon ) {
155 @example_myparticle totalP4 += muon->p4();
156 @example_myparticle charge += muon->charge();
157 @example_myparticle }
158 @example_myparticle
159 @example_myparticle for( PixelMatchGsfElectronCollection::const_iterator electron = electrons->begin(); electron != electrons->end(); ++electron ) {
160 @example_myparticle totalP4 += electron->p4();
161 @example_myparticle charge += electron->charge();
162 @example_myparticle }
163 @example_myparticle
164 @example_myparticle // create a particle with momentum and charge from muons and electrons
165 @example_myparticle Particle h;
166 @example_myparticle h.setP4(totalP4);
167 @example_myparticle h.setCharge(charge);
168 @example_myparticle
169 @example_myparticle // fill the particles into the vector
170 @example_myparticle newParticles->push_back( h );
171 @example_myparticle }
172 @example_myparticle
173 @example_myparticle // save the vector
174 @example_myparticle iEvent.put( move(newParticles), "particles" );
175 }
176 
177 // ------------ method called once each stream before processing any runs, lumis or events ------------
178 void
180 {
181 }
182 
183 // ------------ method called once each stream after processing all runs, lumis and events ------------
184 void
186 }
187 
188 // ------------ method called when starting to processes a run ------------
189 /*
190 void
191 __class__::beginRun(edm::Run const&, edm::EventSetup const&)
192 {
193 }
194 */
195 
196 // ------------ method called when ending the processing of a run ------------
197 /*
198 void
199 __class__::endRun(edm::Run const&, edm::EventSetup const&)
200 {
201 }
202 */
203 
204 // ------------ method called when starting to processes a luminosity block ------------
205 /*
206 void
207 __class__::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
208 {
209 }
210 */
211 
212 // ------------ method called when ending the processing of a luminosity block ------------
213 /*
214 void
215 __class__::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
216 {
217 }
218 */
219 
220 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
221 void
223  //The following says we do not know what parameters are allowed so do no validation
224  // Please change this to state exactly what you do use, even if it is no parameters
226  desc.setUnknown();
227  descriptions.addDefault(desc);
228 @example_myparticle
229 @example_myparticle //Specify that only 'muons' and 'electrons' are allowed
230 @example_myparticle //To use, remove the default given above and uncomment below
231 @example_myparticle //ParameterSetDescription desc;
232 @example_myparticle //desc.add<edm::InputTag>("muons","muons");
233 @example_myparticle //desc.add<edm::InputTag>("electrons","pixelMatchGsfElectrons");
234 @example_myparticle //descriptions.addDefault(desc);
235 }
236 
237 //define this as a plug-in
virtual void produce(edm::Event &, const edm::EventSetup &) override
Definition: EDLooper.cc:98
example_myparticle edm::InputTag electronTags_
Definition: EDProducer.cc:62
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: EDAnalyzer.cc:146
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
__class__()
Definition: Skeleton.cc:30
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
virtual void endStream() override
Definition: EDFilter.cc:113
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
def move
Definition: eostools.py:510
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:420
virtual ~__class__()
Definition: EDAnalyzer.cc:89
tuple muons
Definition: patZpeak.py:38
bool include(const CollT &coll, const ItemT &item)
example_myparticle example_myparticle typedef std::vector< reco::Particle > MyParticleCollection
Definition: EDProducer.cc:70
example_myparticle edm::InputTag muonTags_
Definition: EDProducer.cc:61
virtual void beginStream(edm::StreamID) override
Definition: EDFilter.cc:107
math::PtEtaPhiELorentzVectorF LorentzVector