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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
|
/* \class IsolatedPixelTrackCandidateProducer
*
*
*/
#include <vector>
#include <memory>
#include <algorithm>
#include <cmath>
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Common/interface/Ref.h"
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidateFwd.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/L1Trigger/interface/L1JetParticle.h"
#include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidate.h"
#include "DataFormats/Common/interface/TriggerResults.h"
// L1Extra
#include "DataFormats/L1Trigger/interface/L1EmParticle.h"
#include "DataFormats/L1Trigger/interface/L1JetParticleFwd.h"
#include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMapRecord.h"
#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMapFwd.h"
#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMap.h"
//vertices
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
// Framework
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Utilities/interface/transform.h"
// Math
#include "Math/GenVector/VectorUtil.h"
#include "Math/GenVector/PxPyPzE4D.h"
#include "DataFormats/Math/interface/deltaR.h"
//magF
#include "MagneticField/VolumeBasedEngine/interface/VolumeBasedMagneticField.h"
#include "MagneticField/Engine/interface/MagneticField.h"
#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
//for ECAL geometry
#include "Geometry/EcalAlgo/interface/EcalBarrelGeometry.h"
#include "Geometry/EcalAlgo/interface/EcalEndcapGeometry.h"
#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
//#define EDM_ML_DEBUG
class IsolatedPixelTrackCandidateProducer : public edm::stream::EDProducer<> {
public:
IsolatedPixelTrackCandidateProducer(const edm::ParameterSet& ps);
~IsolatedPixelTrackCandidateProducer() override;
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
void beginRun(const edm::Run&, const edm::EventSetup&) override;
void produce(edm::Event& evt, const edm::EventSetup& es) override;
double getDistInCM(double eta1, double phi1, double eta2, double phi2);
std::pair<double, double> GetEtaPhiAtEcal(double etaIP, double phiIP, double pT, int charge, double vtxZ);
private:
struct seedAtEC {
seedAtEC(unsigned int i, bool f, double et, double fi) : index(i), ok(f), eta(et), phi(fi) {}
unsigned int index;
bool ok;
double eta, phi;
};
const edm::EDGetTokenT<trigger::TriggerFilterObjectWithRefs> tok_hlt_;
const edm::EDGetTokenT<l1extra::L1JetParticleCollection> tok_l1_;
const edm::EDGetTokenT<reco::VertexCollection> tok_vert_;
const std::vector<edm::EDGetTokenT<reco::TrackCollection> > toks_pix_;
const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> tok_bFieldH_;
const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_geom_;
const std::string bfield_;
const double prelimCone_;
const double pixelIsolationConeSizeAtEC_;
const double vtxCutSeed_;
const double vtxCutIsol_;
const double tauAssocCone_;
const double tauUnbiasCone_;
const double minPTrackValue_;
const double maxPForIsolationValue_;
const double ebEtaBoundary_;
// these are read from the EventSetup, cannot be const
double rEB_;
double zEE_;
double bfVal_;
};
IsolatedPixelTrackCandidateProducer::IsolatedPixelTrackCandidateProducer(const edm::ParameterSet& config)
: tok_hlt_(consumes<trigger::TriggerFilterObjectWithRefs>(config.getParameter<edm::InputTag>("L1GTSeedLabel"))),
tok_l1_(consumes<l1extra::L1JetParticleCollection>(config.getParameter<edm::InputTag>("L1eTauJetsSource"))),
tok_vert_(consumes<reco::VertexCollection>(config.getParameter<edm::InputTag>("VertexLabel"))),
toks_pix_(
edm::vector_transform(config.getParameter<std::vector<edm::InputTag> >("PixelTracksSources"),
[this](edm::InputTag const& tag) { return consumes<reco::TrackCollection>(tag); })),
tok_bFieldH_(esConsumes<MagneticField, IdealMagneticFieldRecord, edm::Transition::BeginRun>()),
tok_geom_(esConsumes<CaloGeometry, CaloGeometryRecord, edm::Transition::BeginRun>()),
bfield_(config.getParameter<std::string>("MagFieldRecordName")),
prelimCone_(config.getParameter<double>("ExtrapolationConeSize")),
pixelIsolationConeSizeAtEC_(config.getParameter<double>("PixelIsolationConeSizeAtEC")),
vtxCutSeed_(config.getParameter<double>("MaxVtxDXYSeed")),
vtxCutIsol_(config.getParameter<double>("MaxVtxDXYIsol")),
tauAssocCone_(config.getParameter<double>("tauAssociationCone")),
tauUnbiasCone_(config.getParameter<double>("tauUnbiasCone")),
minPTrackValue_(config.getParameter<double>("minPTrack")),
maxPForIsolationValue_(config.getParameter<double>("maxPTrackForIsolation")),
ebEtaBoundary_(config.getParameter<double>("EBEtaBoundary")),
rEB_(-1),
zEE_(-1),
bfVal_(0) {
// Register the product
produces<reco::IsolatedPixelTrackCandidateCollection>();
}
IsolatedPixelTrackCandidateProducer::~IsolatedPixelTrackCandidateProducer() {}
void IsolatedPixelTrackCandidateProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
std::vector<edm::InputTag> tracksrc = {edm::InputTag("hltPixelTracks")};
desc.add<edm::InputTag>("L1eTauJetsSource", edm::InputTag("hltCaloStage2Digis", "Tau"));
desc.add<double>("tauAssociationCone", 0.0);
desc.add<double>("tauUnbiasCone", 1.2);
desc.add<std::vector<edm::InputTag> >("PixelTracksSources", tracksrc);
desc.add<double>("ExtrapolationConeSize", 1.0);
desc.add<double>("PixelIsolationConeSizeAtEC", 40);
desc.add<edm::InputTag>("L1GTSeedLabel", edm::InputTag("hltL1sIsoTrack"));
desc.add<double>("MaxVtxDXYSeed", 101.0);
desc.add<double>("MaxVtxDXYIsol", 101.0);
desc.add<edm::InputTag>("VertexLabel", edm::InputTag("hltTrimmedPixelVertices"));
desc.add<std::string>("MagFieldRecordName", "VolumeBasedMagneticField");
desc.add<double>("minPTrack", 5.0);
desc.add<double>("maxPTrackForIsolation", 3.0);
desc.add<double>("EBEtaBoundary", 1.479);
descriptions.add("isolPixelTrackProd", desc);
}
void IsolatedPixelTrackCandidateProducer::beginRun(const edm::Run& run, const edm::EventSetup& theEventSetup) {
const CaloGeometry* pG = &theEventSetup.getData(tok_geom_);
const double rad(dynamic_cast<const EcalBarrelGeometry*>(pG->getSubdetectorGeometry(DetId::Ecal, EcalBarrel))
->avgRadiusXYFrontFaceCenter());
const double zz(dynamic_cast<const EcalEndcapGeometry*>(pG->getSubdetectorGeometry(DetId::Ecal, EcalEndcap))
->avgAbsZFrontFaceCenter());
rEB_ = rad;
zEE_ = zz;
const MagneticField* vbfField = &theEventSetup.getData(tok_bFieldH_);
const VolumeBasedMagneticField* vbfCPtr = dynamic_cast<const VolumeBasedMagneticField*>(&(*vbfField));
GlobalVector BField = vbfCPtr->inTesla(GlobalPoint(0, 0, 0));
bfVal_ = BField.mag();
}
void IsolatedPixelTrackCandidateProducer::produce(edm::Event& theEvent, const edm::EventSetup& theEventSetup) {
auto trackCollection = std::make_unique<reco::IsolatedPixelTrackCandidateCollection>();
//create vector of refs from input collections
std::vector<reco::TrackRef> pixelTrackRefs;
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HcalIsoTrack") << "IsolatedPixelTrakCandidate: with" << toks_pix_.size()
<< " candidates to start with\n";
#endif
for (unsigned int iPix = 0; iPix < toks_pix_.size(); iPix++) {
const edm::Handle<reco::TrackCollection>& iPixCol = theEvent.getHandle(toks_pix_[iPix]);
for (reco::TrackCollection::const_iterator pit = iPixCol->begin(); pit != iPixCol->end(); pit++) {
pixelTrackRefs.push_back(reco::TrackRef(iPixCol, pit - iPixCol->begin()));
}
}
const edm::Handle<l1extra::L1JetParticleCollection>& l1eTauJets = theEvent.getHandle(tok_l1_);
const edm::Handle<reco::VertexCollection>& pVert = theEvent.getHandle(tok_vert_);
double drMaxL1Track_ = tauAssocCone_;
#ifdef EDM_ML_DEBUG
int ntr = 0;
#endif
std::vector<seedAtEC> VecSeedsatEC;
//loop to select isolated tracks
for (unsigned iS = 0; iS < pixelTrackRefs.size(); iS++) {
bool vtxMatch = false;
//associate to vertex (in Z)
reco::VertexCollection::const_iterator vitSel;
double minDZ = 1000;
bool found(false);
for (reco::VertexCollection::const_iterator vit = pVert->begin(); vit != pVert->end(); vit++) {
if (std::abs(pixelTrackRefs[iS]->dz(vit->position())) < minDZ) {
minDZ = std::abs(pixelTrackRefs[iS]->dz(vit->position()));
vitSel = vit;
found = true;
}
}
//cut on dYX:
if (found) {
if (std::abs(pixelTrackRefs[iS]->dxy(vitSel->position())) < vtxCutSeed_)
vtxMatch = true;
} else {
vtxMatch = true;
}
//check taujet matching
bool tmatch = false;
l1extra::L1JetParticleCollection::const_iterator selj;
for (l1extra::L1JetParticleCollection::const_iterator tj = l1eTauJets->begin(); tj != l1eTauJets->end(); tj++) {
if (reco::deltaR(pixelTrackRefs[iS]->momentum().eta(),
pixelTrackRefs[iS]->momentum().phi(),
tj->momentum().eta(),
tj->momentum().phi()) > drMaxL1Track_)
continue;
selj = tj;
tmatch = true;
} //loop over L1 tau
//propagate seed track to ECAL surface:
std::pair<double, double> seedCooAtEC;
// in case vertex is found:
if (found)
seedCooAtEC = GetEtaPhiAtEcal(pixelTrackRefs[iS]->eta(),
pixelTrackRefs[iS]->phi(),
pixelTrackRefs[iS]->pt(),
pixelTrackRefs[iS]->charge(),
vitSel->z());
//in case vertex is not found:
else
seedCooAtEC = GetEtaPhiAtEcal(pixelTrackRefs[iS]->eta(),
pixelTrackRefs[iS]->phi(),
pixelTrackRefs[iS]->pt(),
pixelTrackRefs[iS]->charge(),
0);
seedAtEC seed(iS, (tmatch || vtxMatch), seedCooAtEC.first, seedCooAtEC.second);
VecSeedsatEC.push_back(seed);
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HcalIsoTrack") << "IsolatedPixelTrakCandidate: " << VecSeedsatEC.size()
<< " seeds after propagation\n";
#endif
for (unsigned int i = 0; i < VecSeedsatEC.size(); i++) {
unsigned int iSeed = VecSeedsatEC[i].index;
if (!VecSeedsatEC[i].ok)
continue;
if (pixelTrackRefs[iSeed]->p() < minPTrackValue_)
continue;
l1extra::L1JetParticleCollection::const_iterator selj;
for (l1extra::L1JetParticleCollection::const_iterator tj = l1eTauJets->begin(); tj != l1eTauJets->end(); tj++) {
if (reco::deltaR(pixelTrackRefs[iSeed]->momentum().eta(),
pixelTrackRefs[iSeed]->momentum().phi(),
tj->momentum().eta(),
tj->momentum().phi()) > drMaxL1Track_)
continue;
selj = tj;
} //loop over L1 tau
double maxP = 0;
double sumP = 0;
for (unsigned int j = 0; j < VecSeedsatEC.size(); j++) {
if (i == j)
continue;
unsigned int iSurr = VecSeedsatEC[j].index;
//define preliminary cone around seed track impact point from which tracks will be extrapolated:
if (reco::deltaR(pixelTrackRefs[iSeed]->eta(),
pixelTrackRefs[iSeed]->phi(),
pixelTrackRefs[iSurr]->eta(),
pixelTrackRefs[iSurr]->phi()) > prelimCone_)
continue;
double minDZ2(1000);
bool found(false);
reco::VertexCollection::const_iterator vitSel2;
for (reco::VertexCollection::const_iterator vit = pVert->begin(); vit != pVert->end(); vit++) {
if (std::abs(pixelTrackRefs[iSurr]->dz(vit->position())) < minDZ2) {
minDZ2 = std::abs(pixelTrackRefs[iSurr]->dz(vit->position()));
vitSel2 = vit;
found = true;
}
}
//cut ot dXY:
if (found && std::abs(pixelTrackRefs[iSurr]->dxy(vitSel2->position())) > vtxCutIsol_)
continue;
//calculate distance at ECAL surface and update isolation:
if (getDistInCM(VecSeedsatEC[i].eta, VecSeedsatEC[i].phi, VecSeedsatEC[j].eta, VecSeedsatEC[j].phi) <
pixelIsolationConeSizeAtEC_) {
sumP += pixelTrackRefs[iSurr]->p();
if (pixelTrackRefs[iSurr]->p() > maxP)
maxP = pixelTrackRefs[iSurr]->p();
}
}
if (maxP < maxPForIsolationValue_) {
reco::IsolatedPixelTrackCandidate newCandidate(
pixelTrackRefs[iSeed], l1extra::L1JetParticleRef(l1eTauJets, selj - l1eTauJets->begin()), maxP, sumP);
newCandidate.setEtaPhiEcal(VecSeedsatEC[i].eta, VecSeedsatEC[i].phi);
trackCollection->push_back(newCandidate);
#ifdef EDM_ML_DEBUG
ntr++;
#endif
}
}
// put the product in the event
theEvent.put(std::move(trackCollection));
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HcalIsoTrack") << "IsolatedPixelTrackCandidate: Final # of candiates " << ntr << "\n";
#endif
}
double IsolatedPixelTrackCandidateProducer::getDistInCM(double eta1, double phi1, double eta2, double phi2) {
double Rec;
double theta1 = 2 * atan(exp(-eta1));
double theta2 = 2 * atan(exp(-eta2));
if (std::abs(eta1) < 1.479)
Rec = rEB_; //radius of ECAL barrel
else if (std::abs(eta1) > 1.479 && std::abs(eta1) < 7.0)
Rec = tan(theta1) * zEE_; //distance from IP to ECAL endcap
else
return 1000;
//|vect| times tg of acos(scalar product)
double angle =
acos((sin(theta1) * sin(theta2) * (sin(phi1) * sin(phi2) + cos(phi1) * cos(phi2)) + cos(theta1) * cos(theta2)));
if (angle < M_PI_2)
return std::abs((Rec / sin(theta1)) * tan(angle));
else
return 1000;
}
std::pair<double, double> IsolatedPixelTrackCandidateProducer::GetEtaPhiAtEcal(
double etaIP, double phiIP, double pT, int charge, double vtxZ) {
double deltaPhi = 0;
double etaEC = 100;
double phiEC = 100;
double Rcurv = 9999999;
if (bfVal_ != 0)
Rcurv = pT * 33.3 * 100 / (bfVal_ * 10); //r(m)=pT(GeV)*33.3/B(kG)
double ecDist = zEE_; //distance to ECAL andcap from IP (cm), 317 - ecal (not preshower), preshower -300
double ecRad = rEB_; //radius of ECAL barrel (cm)
double theta = 2 * atan(exp(-etaIP));
double zNew = 0;
if (theta > M_PI_2)
theta = M_PI - theta;
if (std::abs(etaIP) < ebEtaBoundary_) {
if ((0.5 * ecRad / Rcurv) > 1) {
etaEC = 10000;
deltaPhi = 0;
} else {
deltaPhi = -charge * asin(0.5 * ecRad / Rcurv);
double alpha1 = 2 * asin(0.5 * ecRad / Rcurv);
double z = ecRad / tan(theta);
if (etaIP > 0)
zNew = z * (Rcurv * alpha1) / ecRad + vtxZ; //new z-coordinate of track
else
zNew = -z * (Rcurv * alpha1) / ecRad + vtxZ; //new z-coordinate of track
double zAbs = std::abs(zNew);
if (zAbs < ecDist) {
etaEC = -log(tan(0.5 * atan(ecRad / zAbs)));
deltaPhi = -charge * asin(0.5 * ecRad / Rcurv);
}
if (zAbs > ecDist) {
zAbs = (std::abs(etaIP) / etaIP) * ecDist;
double Zflight = std::abs(zAbs - vtxZ);
double alpha = (Zflight * ecRad) / (z * Rcurv);
double Rec = 2 * Rcurv * sin(alpha / 2);
deltaPhi = -charge * alpha / 2;
etaEC = -log(tan(0.5 * atan(Rec / ecDist)));
}
}
} else {
zNew = (std::abs(etaIP) / etaIP) * ecDist;
double Zflight = std::abs(zNew - vtxZ);
double Rvirt = std::abs(Zflight * tan(theta));
double Rec = 2 * Rcurv * sin(Rvirt / (2 * Rcurv));
deltaPhi = -(charge) * (Rvirt / (2 * Rcurv));
etaEC = -log(tan(0.5 * atan(Rec / ecDist)));
}
if (zNew < 0)
etaEC = -etaEC;
phiEC = phiIP + deltaPhi;
if (phiEC < -M_PI)
phiEC += M_2_PI;
if (phiEC > M_PI)
phiEC -= M_2_PI;
std::pair<double, double> retVal(etaEC, phiEC);
return retVal;
}
#include "FWCore/PluginManager/interface/ModuleDef.h"
#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(IsolatedPixelTrackCandidateProducer);
|