CMS 3D CMS Logo

EDAnalyzer.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 
33 @example_histo#include "FWCore/ServiceRegistry/interface/Service.h"
34 @example_histo#include "CommonTools/UtilAlgos/interface/TFileService.h"
35 @example_histo#include "TH1.h"
36 //
37 // class declaration
38 //
39 
40 // If the analyzer does not use TFileService, please remove
41 // the template argument to the base class so the class inherits
42 // from edm::one::EDAnalyzer<>
43 // This will improve performance in multithreaded jobs.
44 
46 
47 class __class__ : public edm::one::EDAnalyzer<edm::one::SharedResources> {
48 public:
49  explicit __class__(const edm::ParameterSet&);
50  ~__class__() override;
51 
52  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
54 private:
55  void beginJob() override;
56  void analyze(const edm::Event&, const edm::EventSetup&) override;
57  void endJob() override;
58 
59  // ----------member data ---------------------------
60  edm::EDGetTokenT<TrackCollection> tracksToken_; //used to select what tracks to read from configuration file
61 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
63 #endif
64 @example_histo TH1I* histo;
65 };
66 
67 //
68 // constants, enums and typedefs
69 //
70 
71 //
72 // static data member definitions
73 //
74 
75 //
76 // constructors and destructor
77 //
79  : tracksToken_(consumes<TrackCollection>(iConfig.getUntrackedParameter<edm::InputTag>("tracks"))) {
80 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
81  setupDataToken_ = esConsumes<SetupData, SetupRecord>();
82 #endif
83  //now do what ever initialization is needed
84 @example_histo usesResource("TFileService");
85 @example_histo edm::Service<TFileService> fs;
86 @example_histo histo = fs->make<TH1I>("charge", "Charges", 2, -1, 1);
87 }
88 
90  // do anything here that needs to be done at desctruction time
91  // (e.g. close files, deallocate resources etc.)
92  //
93  // please remove this method altogether if it would be left empty
94 }
95 
96 //
97 // member functions
98 //
99 
100 // ------------ method called for each event ------------
101 void __class__::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
102  using namespace edm;
103 
104  for (const auto& track : iEvent.get(tracksToken_)) {
105  // do something with track parameters, e.g, plot the charge.
106  // int charge = track.charge();
107 @example_histo histo->Fill(track.charge());
108  }
109 
110 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
111  // if the SetupData is always needed
112  auto setup = iSetup.getData(setupToken_);
113  // if need the ESHandle to check if the SetupData was there or not
114  auto pSetup = iSetup.getHandle(setupToken_);
115 #endif
116 }
117 
118 // ------------ method called once each job just before starting event loop ------------
120  // please remove this method if not needed
121 }
122 
123 // ------------ method called once each job just after ending the event loop ------------
125  // please remove this method if not needed
126 }
127 
128 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
130  //The following says we do not know what parameters are allowed so do no validation
131  // Please change this to state exactly what you do use, even if it is no parameters
133  desc.setUnknown();
134  descriptions.addDefault(desc);
135 
136  //Specify that only 'tracks' is allowed
137  //To use, remove the default given above and uncomment below
138  //edm::ParameterSetDescription desc;
139  //desc.addUntracked<edm::InputTag>("tracks", edm::InputTag("ctfWithMaterialTracks"));
140  //descriptions.addWithDefaultLabel(desc);
141 }
142 
143 //define this as a plug-in
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
__class__()
Definition: Skeleton.cc:29
edm::EDGetTokenT< TrackCollection > tracksToken_
Definition: EDAnalyzer.cc:60
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
void analyze(const edm::Event &, const edm::EventSetup &) override
virtual ~__class__()
HLT enums.
bool include(const CollT &coll, const ItemT &item)
void endJob() override
Definition: EDAnalyzer.cc:124
void beginJob() override
Definition: EDAnalyzer.cc:119
example_histo TH1I * histo
Definition: EDAnalyzer.cc:64