-
Notifications
You must be signed in to change notification settings - Fork 2
/
TrackPrinter.cc
137 lines (113 loc) · 4.09 KB
/
TrackPrinter.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// -*- C++ -*-
//
// Package: TestAnalyzer/TrackPrinter
// Class: TrackPrinter
//
/**\class TrackPrinter TrackPrinter.cc TestAnalyzer/TrackPrinter/plugins/TrackPrinter.cc
Description: [one line class summary]
Implementation:
[Notes on implementation]
*/
//
// Original Author: Thiago Tomei Fernandez
// Created: Wed, 13 Apr 2022 20:00:00 GMT
//
//
// system include files
#include <memory>
// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"
//
// class declaration
//
// If the analyzer does not use TFileService, please remove
// the template argument to the base class so the class inherits
// from edm::one::EDAnalyzer<>
// This will improve performance in multithreaded jobs.
using reco::TrackCollection;
class TrackPrinter : public edm::one::EDAnalyzer<edm::one::SharedResources> {
public:
explicit TrackPrinter(const edm::ParameterSet&);
~TrackPrinter();
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
private:
void beginJob() override;
void analyze(const edm::Event&, const edm::EventSetup&) override;
void endJob() override;
// ----------member data ---------------------------
edm::EDGetTokenT<TrackCollection> tracksToken_; //used to select what tracks to read from configuration file
#ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
edm::ESGetToken<SetupData, SetupRecord> setupToken_;
#endif
};
//
// constants, enums and typedefs
//
//
// static data member definitions
//
//
// constructors and destructor
//
TrackPrinter::TrackPrinter(const edm::ParameterSet& iConfig)
: tracksToken_(consumes<TrackCollection>(iConfig.getUntrackedParameter<edm::InputTag>("tracks"))) {
#ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
setupDataToken_ = esConsumes<SetupData, SetupRecord>();
#endif
//now do what ever initialization is needed
}
TrackPrinter::~TrackPrinter() {
// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)
//
// please remove this method altogether if it would be left empty
}
//
// member functions
//
// ------------ method called for each event ------------
void TrackPrinter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
using namespace edm;
const TrackCollection& theTracks = iEvent.get(tracksToken_);
for (const auto& track : theTracks) {
if(track.pt() > 3.0) {
std::cout << "This track pt is " << track.pt() << std::endl;
}
}
#ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
// if the SetupData is always needed
auto setup = iSetup.getData(setupToken_);
// if need the ESHandle to check if the SetupData was there or not
auto pSetup = iSetup.getHandle(setupToken_);
#endif
}
// ------------ method called once each job just before starting event loop ------------
void TrackPrinter::beginJob() {
// please remove this method if not needed
}
// ------------ method called once each job just after ending the event loop ------------
void TrackPrinter::endJob() {
// please remove this method if not needed
}
// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
void TrackPrinter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
//The following says we do not know what parameters are allowed so do no validation
// Please change this to state exactly what you do use, even if it is no parameters
edm::ParameterSetDescription desc;
desc.setUnknown();
descriptions.addDefault(desc);
//Specify that only 'tracks' is allowed
//To use, remove the default given above and uncomment below
//ParameterSetDescription desc;
//desc.addUntracked<edm::InputTag>("tracks","ctfWithMaterialTracks");
//descriptions.addWithDefaultLabel(desc);
}
//define this as a plug-in
DEFINE_FWK_MODULE(TrackPrinter);