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/one/EDAnalyzer.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/InputTag.h"
0031 #include "DataFormats/TrackReco/interface/Track.h"
0032 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0033 @example_histo#include "FWCore/ServiceRegistry/interface/Service.h"
0034 @example_histo#include "CommonTools/UtilAlgos/interface/TFileService.h"
0035 @example_histo#include "TH1.h"
0036 //
0037 // class declaration
0038 //
0039 
0040 // If the analyzer does not use TFileService, please remove
0041 // the template argument to the base class so the class inherits
0042 // from  edm::one::EDAnalyzer<>
0043 // This will improve performance in multithreaded jobs.
0044 
0045 using reco::TrackCollection;
0046 
0047 class __class__ : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0048 public:
0049   explicit __class__(const edm::ParameterSet&);
0050   ~__class__() override;
0051 
0052   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0053 
0054 private:
0055   void beginJob() override;
0056   void analyze(const edm::Event&, const edm::EventSetup&) override;
0057   void endJob() override;
0058 
0059   // ----------member data ---------------------------
0060   edm::EDGetTokenT<TrackCollection> tracksToken_;  //used to select what tracks to read from configuration file
0061 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
0062   edm::ESGetToken<SetupData, SetupRecord> setupToken_;
0063 #endif
0064 @example_histo  TH1I* histo;
0065 };
0066 
0067 //
0068 // constants, enums and typedefs
0069 //
0070 
0071 //
0072 // static data member definitions
0073 //
0074 
0075 //
0076 // constructors and destructor
0077 //
0078 __class__::__class__(const edm::ParameterSet& iConfig)
0079     : tracksToken_(consumes<TrackCollection>(iConfig.getUntrackedParameter<edm::InputTag>("tracks"))) {
0080 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
0081   setupDataToken_ = esConsumes<SetupData, SetupRecord>();
0082 #endif
0083   //now do what ever initialization is needed
0084 @example_histo  usesResource("TFileService");
0085 @example_histo  edm::Service<TFileService> fs;
0086 @example_histo  histo = fs->make<TH1I>("charge", "Charges", 2, -1, 1);
0087 }
0088 
0089 __class__::~__class__() {
0090   // do anything here that needs to be done at desctruction time
0091   // (e.g. close files, deallocate resources etc.)
0092   //
0093   // please remove this method altogether if it would be left empty
0094 }
0095 
0096 //
0097 // member functions
0098 //
0099 
0100 // ------------ method called for each event  ------------
0101 void __class__::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0102   using namespace edm;
0103 
0104   for (const auto& track : iEvent.get(tracksToken_)) {
0105     // do something with track parameters, e.g, plot the charge.
0106     // int charge = track.charge();
0107 @example_histo    histo->Fill(track.charge());
0108   }
0109 
0110 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
0111   // if the SetupData is always needed
0112   auto setup = iSetup.getData(setupToken_);
0113   // if need the ESHandle to check if the SetupData was there or not
0114   auto pSetup = iSetup.getHandle(setupToken_);
0115 #endif
0116 }
0117 
0118 // ------------ method called once each job just before starting event loop  ------------
0119 void __class__::beginJob() {
0120   // please remove this method if not needed
0121 }
0122 
0123 // ------------ method called once each job just after ending the event loop  ------------
0124 void __class__::endJob() {
0125   // please remove this method if not needed
0126 }
0127 
0128 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0129 void __class__::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0130   //The following says we do not know what parameters are allowed so do no validation
0131   // Please change this to state exactly what you do use, even if it is no parameters
0132   edm::ParameterSetDescription desc;
0133   desc.setUnknown();
0134   descriptions.addDefault(desc);
0135 
0136   //Specify that only 'tracks' is allowed
0137   //To use, remove the default given above and uncomment below
0138   //ParameterSetDescription desc;
0139   //desc.addUntracked<edm::InputTag>("tracks","ctfWithMaterialTracks");
0140   //descriptions.addWithDefaultLabel(desc);
0141 }
0142 
0143 //define this as a plug-in
0144 DEFINE_FWK_MODULE(__class__);