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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
//Framework
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Utilities/interface/EDMException.h"
#include "FWCore/Utilities/interface/InputTag.h"
//DataFormats
#include <DataFormats/Candidate/interface/Particle.h>
#include <DataFormats/Candidate/interface/Candidate.h>
#include <DataFormats/TrackReco/interface/Track.h>
#include <DataFormats/JetReco/interface/CaloJet.h>
#include <DataFormats/MuonReco/interface/Muon.h>
#include <DataFormats/RecoCandidate/interface/RecoCandidate.h> //for the get<TrackRef>() Call
#include <DataFormats/Math/interface/deltaR.h>
//STL
#include <cmath>
#include "Alignment/CommonAlignmentProducer/interface/AlignmentGlobalTrackSelector.h"
using namespace std;
using namespace edm;
// constructor ----------------------------------------------------------------
AlignmentGlobalTrackSelector::AlignmentGlobalTrackSelector(const edm::ParameterSet& cfg, edm::ConsumesCollector& iC)
: theGMFilterSwitch(cfg.getParameter<bool>("applyGlobalMuonFilter")),
theIsoFilterSwitch(cfg.getParameter<bool>("applyIsolationtest")),
theJetCountFilterSwitch(cfg.getParameter<bool>("applyJetCountFilter")) {
if (theGMFilterSwitch || theIsoFilterSwitch || theJetCountFilterSwitch)
LogDebug("Alignment") << "> applying global Trackfilter ...";
if (theGMFilterSwitch) {
edm::InputTag theMuonSource = cfg.getParameter<InputTag>("muonSource");
theMuonToken = iC.consumes<reco::MuonCollection>(theMuonSource);
theMaxTrackDeltaR = cfg.getParameter<double>("maxTrackDeltaR");
theMinGlobalMuonCount = cfg.getParameter<int>("minGlobalMuonCount");
LogDebug("Alignment") << "> GlobalMuonFilter : source, maxTrackDeltaR, min. Count : " << theMuonSource
<< " , " << theMaxTrackDeltaR << " , " << theMinIsolatedCount;
}
if (theIsoFilterSwitch) {
edm::InputTag theJetIsoSource = cfg.getParameter<InputTag>("jetIsoSource");
theJetIsoToken = iC.consumes<reco::CaloJetCollection>(theJetIsoSource);
theMaxJetPt = cfg.getParameter<double>("maxJetPt");
theMinJetDeltaR = cfg.getParameter<double>("minJetDeltaR");
theMinIsolatedCount = cfg.getParameter<int>("minIsolatedCount");
LogDebug("Alignment") << "> Isolationtest : source, maxJetPt, minJetDeltaR, min. Count: " << theJetIsoSource
<< " , " << theMaxJetPt << " ," << theMinJetDeltaR << " ," << theMinGlobalMuonCount;
}
if (theJetCountFilterSwitch) {
edm::InputTag theJetCountSource = cfg.getParameter<InputTag>("jetCountSource");
theJetCountToken = iC.consumes<reco::CaloJetCollection>(theJetCountSource);
theMinJetPt = cfg.getParameter<double>("minJetPt");
theMaxJetCount = cfg.getParameter<int>("maxJetCount");
LogDebug("Alignment") << "> JetCountFilter : source, minJetPt, maxJetCount : " << theJetCountSource
<< " , " << theMinJetPt << " ," << theMaxJetCount;
}
}
void AlignmentGlobalTrackSelector::fillPSetDescription(edm::ParameterSetDescription& desc) {
// Global muon finding
desc.add<bool>("applyGlobalMuonFilter", false);
desc.add<edm::InputTag>("muonSource", edm::InputTag("muons"));
desc.add<double>("maxTrackDeltaR", 0.001);
desc.add<int>("minGlobalMuonCount", 1);
// Isolation tests
desc.add<bool>("applyIsolationtest", false);
desc.add<edm::InputTag>("jetIsoSource", edm::InputTag("kt6CaloJets"));
desc.add<double>("maxJetPt", 40.0); // GeV
desc.add<double>("minJetDeltaR", 0.2);
desc.add<int>("minIsolatedCount", 0);
// Jet count filter
desc.add<bool>("applyJetCountFilter", false);
desc.add<edm::InputTag>("jetCountSource", edm::InputTag("kt6CaloJets"));
desc.add<double>("minJetPt", 40.0); // GeV
desc.add<int>("maxJetCount", 3);
}
// destructor -----------------------------------------------------------------
AlignmentGlobalTrackSelector::~AlignmentGlobalTrackSelector() {}
///returns if any of the Filters is used.
bool AlignmentGlobalTrackSelector::useThisFilter() {
return theGMFilterSwitch || theIsoFilterSwitch || theJetCountFilterSwitch;
}
// do selection ---------------------------------------------------------------
AlignmentGlobalTrackSelector::Tracks AlignmentGlobalTrackSelector::select(const Tracks& tracks,
const edm::Event& iEvent,
const edm::EventSetup& iSetup) {
Tracks result = tracks;
if (theGMFilterSwitch)
result = findMuons(result, iEvent);
if (theIsoFilterSwitch)
result = checkIsolation(result, iEvent);
if (theJetCountFilterSwitch)
result = checkJetCount(result, iEvent);
LogDebug("Alignment") << "> Global: tracks all, kept: " << tracks.size() << ", " << result.size();
// LogDebug("Alignment")<<"> o kept:";
// printTracks(result);
return result;
}
///filter for Tracks that match the Track of a global Muon
AlignmentGlobalTrackSelector::Tracks AlignmentGlobalTrackSelector::findMuons(const Tracks& tracks,
const edm::Event& iEvent) const {
Tracks result;
Tracks globalMuons;
//fill globalMuons with muons
Handle<reco::MuonCollection> muons;
iEvent.getByToken(theMuonToken, muons);
if (muons.isValid()) {
for (reco::MuonCollection::const_iterator itMuon = muons->begin(); itMuon != muons->end(); ++itMuon) {
const reco::Track* muonTrack = (*itMuon).get<reco::TrackRef>().get();
if (!muonTrack) {
LogDebug("Alignment") << "@SUB=AlignmentGlobalTrackSelector::findMuons"
<< "Found muon without track: Standalone Muon!";
} else {
globalMuons.push_back(muonTrack);
}
}
} else {
LogError("Alignment") << "@SUB=AlignmentGlobalTrackSelector::findMuons"
<< "> could not optain mounCollection!";
}
result = this->matchTracks(tracks, globalMuons);
if (static_cast<int>(result.size()) < theMinGlobalMuonCount)
result.clear();
return result;
}
///returns only isolated tracks in [cands]
AlignmentGlobalTrackSelector::Tracks AlignmentGlobalTrackSelector::checkIsolation(const Tracks& cands,
const edm::Event& iEvent) const {
Tracks result;
result.clear();
Handle<reco::CaloJetCollection> jets;
iEvent.getByToken(theJetIsoToken, jets);
if (jets.isValid()) {
for (Tracks::const_iterator it = cands.begin(); it != cands.end(); ++it) {
bool isolated = true;
for (reco::CaloJetCollection::const_iterator itJet = jets->begin(); itJet != jets->end(); ++itJet)
isolated &= !((*itJet).pt() > theMaxJetPt && deltaR(*(*it), (*itJet)) < theMinJetDeltaR);
if (isolated)
result.push_back(*it);
}
// LogDebug("Alignment") << "D Found "<<result.size()<<" isolated of "<< cands.size()<<" Tracks!";
} else
LogError("Alignment") << "@SUB=AlignmentGlobalTrackSelector::checkIsolation"
<< "> could not optain jetCollection!";
if (static_cast<int>(result.size()) < theMinIsolatedCount)
result.clear();
return result;
}
///returns [tracks] if there are less than theMaxCount Jets with theMinJetPt and an empty set if not
AlignmentGlobalTrackSelector::Tracks AlignmentGlobalTrackSelector::checkJetCount(const Tracks& tracks,
const edm::Event& iEvent) const {
Tracks result;
result.clear();
Handle<reco::CaloJetCollection> jets;
iEvent.getByToken(theJetCountToken, jets);
if (jets.isValid()) {
int jetCount = 0;
for (reco::CaloJetCollection::const_iterator itJet = jets->begin(); itJet != jets->end(); ++itJet) {
if ((*itJet).pt() > theMinJetPt)
jetCount++;
}
if (jetCount <= theMaxJetCount)
result = tracks;
LogDebug("Alignment") << "> found " << jetCount << " Jets";
} else
LogError("Alignment") << "@SUB=AlignmentGlobalTrackSelector::checkJetCount"
<< "> could not optain jetCollection!";
return result;
}
//===================HELPERS===================
///matches [src] with [comp] returns collection with matching Tracks coming from [src]
AlignmentGlobalTrackSelector::Tracks AlignmentGlobalTrackSelector::matchTracks(const Tracks& src,
const Tracks& comp) const {
Tracks result;
for (Tracks::const_iterator itComp = comp.begin(); itComp != comp.end(); ++itComp) {
int match = -1;
double min = theMaxTrackDeltaR;
for (unsigned int i = 0; i < src.size(); i++) {
// LogDebug("Alignment") << "> Trackmatch dist: "<<deltaR(src.at(i),*itComp);
if (min > deltaR(*(src.at(i)), *(*itComp))) {
min = deltaR(*(src.at(i)), *(*itComp));
match = static_cast<int>(i);
}
}
if (match > -1)
result.push_back(src.at(match));
}
return result;
}
///print Information on Track-Collection
void AlignmentGlobalTrackSelector::printTracks(const Tracks& col) const {
int count = 0;
LogDebug("Alignment") << ">......................................";
for (Tracks::const_iterator it = col.begin(); it < col.end(); ++it, ++count) {
LogDebug("Alignment") << "> Track No. " << count << ": p = (" << (*it)->px() << "," << (*it)->py() << ","
<< (*it)->pz() << ")\n"
<< "> pT = " << (*it)->pt() << " eta = " << (*it)->eta()
<< " charge = " << (*it)->charge();
}
LogDebug("Alignment") << ">......................................";
}
|