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: prodname
4 // Class: prodname
5 //
13 //
14 // Original Author: John Doe
15 // Created: day-mon-xx
16 // RCS(Id)
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
27 
30 
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 prodname : public edm::EDProducer {
44  public:
45  explicit prodname(const edm::ParameterSet&);
46  ~prodname();
47 
48  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
49 
50  private:
51  virtual void beginJob() ;
52  virtual void produce(edm::Event&, const edm::EventSetup&);
53  virtual void endJob() ;
54 
55  virtual void beginRun(edm::Run&, edm::EventSetup const&);
56  virtual void endRun(edm::Run&, edm::EventSetup const&);
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 desctruction 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::auto_ptr<ExampleData2> pOut(new ExampleData2(*pIn));
128  iEvent.put(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 auto_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( newParticles, "particles" );
175 }
176 
177 // ------------ method called once each job just before starting event loop ------------
178 void
180 {
181 }
182 
183 // ------------ method called once each job just after ending the event loop ------------
184 void
186 }
187 
188 // ------------ method called when starting to processes a run ------------
189 void
191 {
192 }
193 
194 // ------------ method called when ending the processing of a run ------------
195 void
197 {
198 }
199 
200 // ------------ method called when starting to processes a luminosity block ------------
201 void
203 {
204 }
205 
206 // ------------ method called when ending the processing of a luminosity block ------------
207 void
209 {
210 }
211 
212 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
213 void
215  //The following says we do not know what parameters are allowed so do no validation
216  // Please change this to state exactly what you do use, even if it is no parameters
218  desc.setUnknown();
219  descriptions.addDefault(desc);
220 @example_myparticle
221 @example_myparticle //Specify that only 'muons' and 'electrons' are allowed
222 @example_myparticle //To use, remove the default given above and uncomment below
223 @example_myparticle //ParameterSetDescription desc;
224 @example_myparticle //desc.add<edm::InputTag>("muons","muons");
225 @example_myparticle //desc.add<edm::InputTag>("electrons","pixelMatchGsfElectrons");
226 @example_myparticle //descriptions.addDefault(desc);
227 }
228 
229 //define this as a plug-in
virtual void endLuminosityBlock(edm::LuminosityBlock &, edm::EventSetup const &)
Definition: edproducer.cc:208
virtual void produce(edm::Event &, const edm::EventSetup &)
Definition: edproducer.cc:115
virtual void beginLuminosityBlock(edm::LuminosityBlock &, edm::EventSetup const &)
Definition: edproducer.cc:202
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: edproducer.cc:214
int Charge
electric charge type
Definition: Particle.h:23
double charge(const std::vector< uint8_t > &Ampls)
example_myparticle edm::InputTag electronTags_
Definition: edproducer.cc:62
int iEvent
Definition: GenABIO.cc:243
void addDefault(ParameterSetDescription const &psetDescription)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
virtual void beginRun(edm::Run &, edm::EventSetup const &)
Definition: edproducer.cc:190
example_myparticle edm::InputTag muonTags_
Definition: edproducer.cc:61
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
virtual void endJob()
Definition: edproducer.cc:185
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
tuple muons
Definition: patZpeak.py:38
bool include(const CollT &coll, const ItemT &item)
virtual void beginJob()
Definition: edproducer.cc:179
prodname(const edm::ParameterSet &)
Definition: edproducer.cc:79
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
example_myparticle example_myparticle typedef std::vector< reco::Particle > MyParticleCollection
Definition: edproducer.cc:70
Definition: Run.h:33
virtual void endRun(edm::Run &, edm::EventSetup const &)
Definition: edproducer.cc:196