Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-14 00:04:41

0001 // -*- C++ -*-
0002 //
0003 // Package:    __subsys__/__pkgname__
0004 // Class:      __class__
0005 //
0006 /**\class __class__ __class__.cc __subsys__/__pkgname__/plugins/__class__.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  __author__
0015 //         Created:  __date__
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/stream/EDProducer.h"
0025 
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "FWCore/Utilities/interface/StreamID.h"
0031 
0032 @example_myparticle#include "DataFormats/Candidate/interface/Particle.h"
0033 @example_myparticle#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0034 @example_myparticle#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0035 @example_myparticle#include "DataFormats/MuonReco/interface/Muon.h"
0036 @example_myparticle#include "DataFormats/MuonReco/interface/MuonFwd.h"
0037 @example_myparticle#include "FWCore/MessageLogger/interface/MessageLogger.h"
0038 @example_myparticle#include "FWCore/Utilities/interface/InputTag.h"
0039 @example_myparticle
0040 //
0041 // class declaration
0042 //
0043 
0044 class __class__ : public edm::stream::EDProducer<> {
0045 public:
0046   explicit __class__(const edm::ParameterSet&);
0047   ~__class__() override;
0048 
0049   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0050 
0051 private:
0052   void beginStream(edm::StreamID) override;
0053   void produce(edm::Event&, const edm::EventSetup&) override;
0054   void endStream() override;
0055 
0056   //void beginRun(edm::Run const&, edm::EventSetup const&) override;
0057   //void endRun(edm::Run const&, edm::EventSetup const&) override;
0058   //void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0059   //void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0060 
0061 @example_myparticle  // define container that will be booked into event
0062 @example_myparticle  typedef std::vector<reco::Particle> MyParticleCollection;
0063 @example_myparticle
0064   // ----------member data ---------------------------
0065 @example_myparticle  edm::EDGetTokenT<reco::MuonCollection> muonToken_;
0066 @example_myparticle  edm::EDGetTokenT<reco::GsfElectronCollection> electronToken_;
0067 @example_myparticle  edm::EDPutTokenT<MyParticleCollection> putToken_;
0068 };
0069 
0070 //
0071 // constants, enums and typedefs
0072 //
0073 
0074 //
0075 // static data member definitions
0076 //
0077 
0078 //
0079 // constructors and destructor
0080 //
0081 @default__class__::__class__(const edm::ParameterSet& iConfig) {
0082 @example_myparticle__class__::__class__(const edm::ParameterSet& iConfig)
0083 @example_myparticle    : muonToken_(consumes<reco::MuonCollection>(iConfig.getParameter<edm::InputTag>("muons"))),
0084 @example_myparticle      electronToken_(consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electrons"))),
0085 @example_myparticle      putToken_(produces<MyParticleCollection>("particles")) {
0086   //register your products
0087   /* Examples
0088   produces<ExampleData2>();
0089 
0090   //if do put with a label
0091   produces<ExampleData2>("label");
0092  
0093   //if you want to put into the Run
0094   produces<ExampleData2,InRun>();
0095   */
0096   //now do what ever other initialization is needed
0097 }
0098 
0099 __class__::~__class__() {
0100   // do anything here that needs to be done at destruction time
0101   // (e.g. close files, deallocate resources etc.)
0102   //
0103   // please remove this method altogether if it would be left empty
0104 }
0105 
0106 //
0107 // member functions
0108 //
0109 
0110 // ------------ method called to produce the data  ------------
0111 void __class__::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0112   using namespace edm;
0113 @example_myparticle  using namespace reco;
0114 @example_myparticle  using namespace std;
0115   /* This is an event example
0116   //Read 'ExampleData' from the Event
0117   ExampleData const& in = iEvent.get(inToken_);
0118 
0119   //Use the ExampleData to create an ExampleData2 which 
0120   // is put into the Event
0121   iEvent.put(std::make_unique<ExampleData2>(in));
0122   */
0123 
0124   /* this is an EventSetup example
0125   //Read SetupData from the SetupRecord in the EventSetup
0126   SetupData& setup = iSetup.getData(setupToken_);
0127   */
0128 @example_myparticle
0129 @example_myparticle  auto const& muons = iEvent.get(muonToken_);
0130 @example_myparticle  auto const& electrons = iEvent.get(electronToken_);
0131 @example_myparticle
0132 @example_myparticle  // create a new collection of Particle objects
0133 @example_myparticle  auto newParticles = std::make_unique<MyParticleCollection>();
0134 @example_myparticle
0135 @example_myparticle  // if the number of electrons or muons is 4 (or 2 and 2), costruct a new particle
0136 @example_myparticle  if (muons.size() == 4 || electrons.size() == 4 || (muons.size() == 2 && electrons.size() == 2)) {
0137 @example_myparticle    // sums of momenta and charges will be calculated
0138 @example_myparticle    Particle::LorentzVector totalP4(0, 0, 0, 0);
0139 @example_myparticle    Particle::Charge charge(0);
0140 @example_myparticle
0141 @example_myparticle    // loop over muons, sum over p4s and charges. Later same for electrons
0142 @example_myparticle    for (auto const& muon : muons) {
0143 @example_myparticle      totalP4 += muon.p4();
0144 @example_myparticle      charge += muon.charge();
0145 @example_myparticle    }
0146 @example_myparticle
0147 @example_myparticle    for (auto const& electron : electrons) {
0148 @example_myparticle      totalP4 += electron.p4();
0149 @example_myparticle      charge += electron.charge();
0150 @example_myparticle    }
0151 @example_myparticle
0152 @example_myparticle    // create a particle in the vector with momentum and charge from muons and electrons
0153 @example_myparticle    newParticles->emplace_back(charge, totalP4);
0154 @example_myparticle  }
0155 @example_myparticle
0156 @example_myparticle  // save the vector
0157 @example_myparticle  iEvent.put(putToken_, move(newParticles));
0158 }
0159 
0160 // ------------ method called once each stream before processing any runs, lumis or events  ------------
0161 void __class__::beginStream(edm::StreamID) {
0162   // please remove this method if not needed
0163 }
0164 
0165 // ------------ method called once each stream after processing all runs, lumis and events  ------------
0166 void __class__::endStream() {
0167   // please remove this method if not needed
0168 }
0169 
0170 // ------------ method called when starting to processes a run  ------------
0171 /*
0172 void
0173 __class__::beginRun(edm::Run const&, edm::EventSetup const&)
0174 {
0175 }
0176 */
0177 
0178 // ------------ method called when ending the processing of a run  ------------
0179 /*
0180 void
0181 __class__::endRun(edm::Run const&, edm::EventSetup const&)
0182 {
0183 }
0184 */
0185 
0186 // ------------ method called when starting to processes a luminosity block  ------------
0187 /*
0188 void
0189 __class__::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
0190 {
0191 }
0192 */
0193 
0194 // ------------ method called when ending the processing of a luminosity block  ------------
0195 /*
0196 void
0197 __class__::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
0198 {
0199 }
0200 */
0201 
0202 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0203 void __class__::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0204   //The following says we do not know what parameters are allowed so do no validation
0205   // Please change this to state exactly what you do use, even if it is no parameters
0206   edm::ParameterSetDescription desc;
0207   desc.setUnknown();
0208   descriptions.addDefault(desc);
0209 @example_myparticle
0210 @example_myparticle  //Specify that only 'muons' and 'electrons' are allowed
0211 @example_myparticle  //To use, remove the default given above and uncomment below
0212 @example_myparticle  //ParameterSetDescription desc;
0213 @example_myparticle  //desc.add<edm::InputTag>("muons","muons");
0214 @example_myparticle  //desc.add<edm::InputTag>("electrons","gedGsfElectrons");
0215 @example_myparticle  //descriptions.addWithDefaultLabel(desc);
0216 }
0217 
0218 //define this as a plug-in
0219 DEFINE_FWK_MODULE(__class__);