CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
31 @example_track #include "FWCore/Utilities/interface/InputTag.h"
32 @example_track #include "DataFormats/TrackReco/interface/Track.h"
33 @example_track #include "DataFormats/TrackReco/interface/TrackFwd.h"
34 @example_histo #include "FWCore/ServiceRegistry/interface/Service.h"
35 @example_histo #include "CommonTools/UtilAlgos/interface/TFileService.h"
36 @example_histo #include "TH1.h"
37 //
38 // class declaration
39 //
40 
41 // If the analyzer does not use TFileService, please remove
42 // the template argument to the base class so the class inherits
43 // from edm::one::EDAnalyzer<> and also remove the line from
44 // constructor "usesResource("TFileService");"
45 // This will improve performance in multithreaded jobs.
46 
47 class __class__ : public edm::one::EDAnalyzer<edm::one::SharedResources> {
48  public:
49  explicit __class__(const edm::ParameterSet&);
50  ~__class__();
51 
52  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
54 
55  private:
56  virtual void beginJob() override;
57  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
58  virtual void endJob() override;
59 
60  // ----------member data ---------------------------
61 @example_track edm::InputTag trackTags_; //used to select what tracks to read from configuration file
62 @example_histo TH1D * histo;
63 };
64 
65 //
66 // constants, enums and typedefs
67 //
68 
69 //
70 // static data member definitions
71 //
72 
73 //
74 // constructors and destructor
75 //
77 @example_track :
78 @example_track trackTags_(iConfig.getUntrackedParameter<edm::InputTag>("tracks"))
79 
80 {
81  //now do what ever initialization is needed
82  usesResource("TFileService");
83 @example_histo edm::Service<TFileService> fs;
84 @example_histo histo = fs->make<TH1D>("charge" , "Charges" , 200 , -2 , 2 );
85 
86 }
87 
88 
90 {
91 
92  // do anything here that needs to be done at desctruction time
93  // (e.g. close files, deallocate resources etc.)
94 
95 }
96 
97 
98 //
99 // member functions
100 //
101 
102 // ------------ method called for each event ------------
103 void
105 {
106  using namespace edm;
107 
108 @example_track using reco::TrackCollection;
109 
110 @example_track Handle<TrackCollection> tracks;
111 @example_track iEvent.getByLabel(trackTags_,tracks);
112 @example_track for(TrackCollection::const_iterator itTrack = tracks->begin();
113 @example_track itTrack != tracks->end();
114 @example_track ++itTrack) {
115 @example_track int charge = 0;
116 @example_track charge = itTrack->charge();
117 @example_histo histo->Fill( charge );
118 @example_track }
119 
120 #ifdef THIS_IS_AN_EVENT_EXAMPLE
122  iEvent.getByLabel("example",pIn);
123 #endif
124 
125 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
126  ESHandle<SetupData> pSetup;
127  iSetup.get<SetupRecord>().get(pSetup);
128 #endif
129 }
130 
131 
132 // ------------ method called once each job just before starting event loop ------------
133 void
135 {
136 }
137 
138 // ------------ method called once each job just after ending the event loop ------------
139 void
141 {
142 }
143 
144 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
145 void
147  //The following says we do not know what parameters are allowed so do no validation
148  // Please change this to state exactly what you do use, even if it is no parameters
150  desc.setUnknown();
151  descriptions.addDefault(desc);
152 @example_track
153 @example_track //Specify that only 'tracks' is allowed
154 @example_track //To use, remove the default given above and uncomment below
155 @example_track //ParameterSetDescription desc;
156 @example_track //desc.addUntracked<edm::InputTag>("tracks","ctfWithMaterialTracks");
157 @example_track //descriptions.addDefault(desc);
158 }
159 
160 //define this as a plug-in
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: EDAnalyzer.cc:146
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
__class__()
Definition: Skeleton.cc:30
example_track edm::InputTag trackTags_
Definition: EDAnalyzer.cc:61
example_histo TH1D * histo
Definition: EDAnalyzer.cc:62
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:420
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: EDAnalyzer.cc:104
tuple tracks
Definition: testEve_cfg.py:39
const T & get() const
Definition: EventSetup.h:56
virtual ~__class__()
Definition: EDAnalyzer.cc:89
bool include(const CollT &coll, const ItemT &item)
virtual void endJob() override
Definition: EDAnalyzer.cc:140
virtual void beginJob() override
Definition: EDAnalyzer.cc:134