CMS 3D CMS Logo

IsolatedPixelTrackCandidateL1TProducer.cc
Go to the documentation of this file.
1 #include <vector>
2 #include <memory>
3 #include <algorithm>
4 #include <cmath>
5 
6 // Class header file
9 // Framework
17 //
18 
19 // Math
20 #include "Math/GenVector/VectorUtil.h"
21 #include "Math/GenVector/PxPyPzE4D.h"
23 
27 
28 //magF
32 
33 //for ECAL geometry
39 
41  : tok_hlt_(consumes<trigger::TriggerFilterObjectWithRefs>(config.getParameter<edm::InputTag>("L1GTSeedLabel"))),
42  tok_l1_(consumes<l1t::TauBxCollection>(config.getParameter<edm::InputTag>("L1eTauJetsSource"))),
43  tok_vert_(consumes<reco::VertexCollection>(config.getParameter<edm::InputTag>("VertexLabel"))),
44  toks_pix_(
45  edm::vector_transform(config.getParameter<std::vector<edm::InputTag> >("PixelTracksSources"),
46  [this](edm::InputTag const& tag) { return consumes<reco::TrackCollection>(tag); })),
47  bfield_(config.getParameter<std::string>("MagFieldRecordName")),
48  prelimCone_(config.getParameter<double>("ExtrapolationConeSize")),
49  pixelIsolationConeSizeAtEC_(config.getParameter<double>("PixelIsolationConeSizeAtEC")),
50  vtxCutSeed_(config.getParameter<double>("MaxVtxDXYSeed")),
51  vtxCutIsol_(config.getParameter<double>("MaxVtxDXYIsol")),
52  tauAssocCone_(config.getParameter<double>("tauAssociationCone")),
53  tauUnbiasCone_(config.getParameter<double>("tauUnbiasCone")),
54  minPTrackValue_(config.getParameter<double>("minPTrack")),
55  maxPForIsolationValue_(config.getParameter<double>("maxPTrackForIsolation")),
56  ebEtaBoundary_(config.getParameter<double>("EBEtaBoundary")),
57  rEB_(-1),
58  zEE_(-1),
59  bfVal_(0) {
60  // Register the product
61  produces<reco::IsolatedPixelTrackCandidateCollection>();
62 }
63 
65 
68  std::vector<edm::InputTag> tracksrc = {edm::InputTag("hltPixelTracks")};
69  desc.add<edm::InputTag>("L1eTauJetsSource", edm::InputTag("hltGtStage2Digis", "Tau"));
70  desc.add<double>("tauAssociationCone", 0.0);
71  desc.add<double>("tauUnbiasCone", 1.2);
72  desc.add<std::vector<edm::InputTag> >("PixelTracksSources", tracksrc);
73  desc.add<double>("ExtrapolationConeSize", 1.0);
74  desc.add<double>("PixelIsolationConeSizeAtEC", 40);
75  desc.add<edm::InputTag>("L1GTSeedLabel", edm::InputTag("hltL1sV0SingleJet60"));
76  desc.add<double>("MaxVtxDXYSeed", 101.0);
77  desc.add<double>("MaxVtxDXYIsol", 101.0);
78  desc.add<edm::InputTag>("VertexLabel", edm::InputTag("hltTrimmedPixelVertices"));
79  desc.add<std::string>("MagFieldRecordName", "VolumeBasedMagneticField");
80  desc.add<double>("minPTrack", 5.0);
81  desc.add<double>("maxPTrackForIsolation", 3.0);
82  desc.add<double>("EBEtaBoundary", 1.479);
83  descriptions.add("isolPixelTrackProdL1T", desc);
84 }
85 
88  theEventSetup.get<CaloGeometryRecord>().get(pG);
89 
90  const double rad(dynamic_cast<const EcalBarrelGeometry*>(pG->getSubdetectorGeometry(DetId::Ecal, EcalBarrel))
91  ->avgRadiusXYFrontFaceCenter());
92  const double zz(dynamic_cast<const EcalEndcapGeometry*>(pG->getSubdetectorGeometry(DetId::Ecal, EcalEndcap))
93  ->avgAbsZFrontFaceCenter());
94 
95  rEB_ = rad;
96  zEE_ = zz;
97 
99  theEventSetup.get<IdealMagneticFieldRecord>().get(vbfField);
100  const VolumeBasedMagneticField* vbfCPtr = dynamic_cast<const VolumeBasedMagneticField*>(&(*vbfField));
101  GlobalVector BField = vbfCPtr->inTesla(GlobalPoint(0, 0, 0));
102  bfVal_ = BField.mag();
103  edm::LogVerbatim("IsoTrack") << "rEB " << rEB_ << " zEE " << zEE_ << " B " << bfVal_ << std::endl;
104 }
105 
107  auto trackCollection = std::make_unique<reco::IsolatedPixelTrackCandidateCollection>();
108 
109  //create vector of refs from input collections
110  std::vector<reco::TrackRef> pixelTrackRefs;
111 
112  for (unsigned int iPix = 0; iPix < toks_pix_.size(); iPix++) {
114  theEvent.getByToken(toks_pix_[iPix], iPixCol);
115  for (reco::TrackCollection::const_iterator pit = iPixCol->begin(); pit != iPixCol->end(); pit++) {
116  pixelTrackRefs.push_back(reco::TrackRef(iPixCol, pit - iPixCol->begin()));
117  }
118  }
119 
121  theEvent.getByToken(tok_l1_, l1eTauJets);
122 
124  theEvent.getByToken(tok_vert_, pVert);
125 
126  double ptTriggered = -10;
127  double etaTriggered = -100;
128  double phiTriggered = -100;
129 
131  theEvent.getByToken(tok_hlt_, l1trigobj);
132 
133  std::vector<edm::Ref<l1t::TauBxCollection> > l1tauobjref;
134  std::vector<edm::Ref<l1t::JetBxCollection> > l1jetobjref;
135 
136  // l1trigobj->getObjects(trigger::TriggerTau, l1tauobjref);
137  l1trigobj->getObjects(trigger::TriggerL1Tau, l1tauobjref);
138  // l1trigobj->getObjects(trigger::TriggerJet, l1jetobjref);
139  l1trigobj->getObjects(trigger::TriggerL1Jet, l1jetobjref);
140 
141  for (auto p : l1tauobjref) {
142  if (p->pt() > ptTriggered) {
143  ptTriggered = p->pt();
144  phiTriggered = p->phi();
145  etaTriggered = p->eta();
146  }
147  }
148  for (auto p : l1jetobjref) {
149  if (p->pt() > ptTriggered) {
150  ptTriggered = p->pt();
151  phiTriggered = p->phi();
152  etaTriggered = p->eta();
153  }
154  }
155  edm::LogVerbatim("IsoTrack") << "Sizes " << l1tauobjref.size() << ":" << l1jetobjref.size() << " Trig " << ptTriggered
156  << ":" << etaTriggered << ":" << phiTriggered << std::endl;
157 
158  double drMaxL1Track_ = tauAssocCone_;
159  int ntr = 0;
160  std::vector<seedAtEC> VecSeedsatEC;
161  //loop to select isolated tracks
162  for (unsigned iS = 0; iS < pixelTrackRefs.size(); iS++) {
163  bool vtxMatch = false;
164  //associate to vertex (in Z)
165  reco::VertexCollection::const_iterator vitSel;
166  double minDZ = 1000;
167  bool found(false);
168  for (reco::VertexCollection::const_iterator vit = pVert->begin(); vit != pVert->end(); vit++) {
169  if (std::abs(pixelTrackRefs[iS]->dz(vit->position())) < minDZ) {
170  minDZ = std::abs(pixelTrackRefs[iS]->dz(vit->position()));
171  vitSel = vit;
172  found = true;
173  }
174  }
175  //cut on dYX:
176  if (found) {
177  if (std::abs(pixelTrackRefs[iS]->dxy(vitSel->position())) < vtxCutSeed_)
178  vtxMatch = true;
179  } else {
180  vtxMatch = true;
181  }
182  edm::LogVerbatim("IsoTrack") << "minZD " << minDZ << " Found " << found << ":" << vtxMatch << std::endl;
183 
184  //select tracks not matched to triggered L1 jet
185  double R = reco::deltaR(etaTriggered, phiTriggered, pixelTrackRefs[iS]->eta(), pixelTrackRefs[iS]->phi());
186  edm::LogVerbatim("IsoTrack") << "Distance to L1 " << R << ":" << tauUnbiasCone_ << " Result "
187  << (R < tauUnbiasCone_) << std::endl;
188  if (R < tauUnbiasCone_)
189  continue;
190 
191  //check taujet matching
192  bool tmatch = false;
194  for (l1t::TauBxCollection::const_iterator tj = l1eTauJets->begin(); tj != l1eTauJets->end(); tj++) {
195  if (reco::deltaR(pixelTrackRefs[iS]->momentum().eta(),
196  pixelTrackRefs[iS]->momentum().phi(),
197  tj->momentum().eta(),
198  tj->momentum().phi()) > drMaxL1Track_)
199  continue;
200  selj = tj;
201  tmatch = true;
202  } //loop over L1 tau
203  edm::LogVerbatim("IsoTrack") << "tMatch " << tmatch << std::endl;
204 
205  //propagate seed track to ECAL surface:
206  std::pair<double, double> seedCooAtEC;
207  // in case vertex is found:
208  if (found)
209  seedCooAtEC = GetEtaPhiAtEcal(pixelTrackRefs[iS]->eta(),
210  pixelTrackRefs[iS]->phi(),
211  pixelTrackRefs[iS]->pt(),
212  pixelTrackRefs[iS]->charge(),
213  vitSel->z());
214  //in case vertex is not found:
215  else
216  seedCooAtEC = GetEtaPhiAtEcal(pixelTrackRefs[iS]->eta(),
217  pixelTrackRefs[iS]->phi(),
218  pixelTrackRefs[iS]->pt(),
219  pixelTrackRefs[iS]->charge(),
220  0);
221  seedAtEC seed(iS, (tmatch || vtxMatch), seedCooAtEC.first, seedCooAtEC.second);
222  VecSeedsatEC.push_back(seed);
223  edm::LogVerbatim("IsoTrack") << "Seed " << seedCooAtEC.first << seedCooAtEC.second << std::endl;
224  }
225  for (unsigned int i = 0; i < VecSeedsatEC.size(); i++) {
226  unsigned int iSeed = VecSeedsatEC[i].index;
227  if (!VecSeedsatEC[i].ok)
228  continue;
229  if (pixelTrackRefs[iSeed]->p() < minPTrackValue_)
230  continue;
232  for (l1t::TauBxCollection::const_iterator tj = l1eTauJets->begin(); tj != l1eTauJets->end(); tj++) {
233  if (reco::deltaR(pixelTrackRefs[iSeed]->momentum().eta(),
234  pixelTrackRefs[iSeed]->momentum().phi(),
235  tj->momentum().eta(),
236  tj->momentum().phi()) > drMaxL1Track_)
237  continue;
238  selj = tj;
239  } //loop over L1 tau
240  double maxP = 0;
241  double sumP = 0;
242  for (unsigned int j = 0; j < VecSeedsatEC.size(); j++) {
243  if (i == j)
244  continue;
245  unsigned int iSurr = VecSeedsatEC[j].index;
246  //define preliminary cone around seed track impact point from which tracks will be extrapolated:
247  if (reco::deltaR(pixelTrackRefs[iSeed]->eta(),
248  pixelTrackRefs[iSeed]->phi(),
249  pixelTrackRefs[iSurr]->eta(),
250  pixelTrackRefs[iSurr]->phi()) > prelimCone_)
251  continue;
252  double minDZ2(1000);
253  bool found(false);
254  reco::VertexCollection::const_iterator vitSel2;
255  for (reco::VertexCollection::const_iterator vit = pVert->begin(); vit != pVert->end(); vit++) {
256  if (std::abs(pixelTrackRefs[iSurr]->dz(vit->position())) < minDZ2) {
257  minDZ2 = std::abs(pixelTrackRefs[iSurr]->dz(vit->position()));
258  vitSel2 = vit;
259  found = true;
260  }
261  }
262  //cut ot dXY:
263  if (found && std::abs(pixelTrackRefs[iSurr]->dxy(vitSel2->position())) > vtxCutIsol_)
264  continue;
265  //calculate distance at ECAL surface and update isolation:
266  if (getDistInCM(VecSeedsatEC[i].eta, VecSeedsatEC[i].phi, VecSeedsatEC[j].eta, VecSeedsatEC[j].phi) <
268  sumP += pixelTrackRefs[iSurr]->p();
269  if (pixelTrackRefs[iSurr]->p() > maxP)
270  maxP = pixelTrackRefs[iSurr]->p();
271  }
272  }
273  if (maxP < maxPForIsolationValue_) {
275  pixelTrackRefs[iSeed], l1t::TauRef(l1eTauJets, selj - l1eTauJets->begin()), maxP, sumP);
276  newCandidate.setEtaPhiEcal(VecSeedsatEC[i].eta, VecSeedsatEC[i].phi);
277  trackCollection->push_back(newCandidate);
278  ntr++;
279  }
280  }
281  edm::LogVerbatim("IsoTrack") << "Number of Isolated Track " << ntr << "\n";
282  // put the product in the event
283  theEvent.put(std::move(trackCollection));
284 }
285 
286 double IsolatedPixelTrackCandidateL1TProducer::getDistInCM(double eta1, double phi1, double eta2, double phi2) {
287  double Rec;
288  double theta1 = 2 * atan(exp(-eta1));
289  double theta2 = 2 * atan(exp(-eta2));
290  if (std::abs(eta1) < 1.479)
291  Rec = rEB_; //radius of ECAL barrel
292  else if (std::abs(eta1) > 1.479 && std::abs(eta1) < 7.0)
293  Rec = tan(theta1) * zEE_; //distance from IP to ECAL endcap
294  else
295  return 1000;
296 
297  //|vect| times tg of acos(scalar product)
298  double angle =
299  acos((sin(theta1) * sin(theta2) * (sin(phi1) * sin(phi2) + cos(phi1) * cos(phi2)) + cos(theta1) * cos(theta2)));
300  if (angle < M_PI_2)
301  return std::abs((Rec / sin(theta1)) * tan(angle));
302  else
303  return 1000;
304 }
305 
307  double etaIP, double phiIP, double pT, int charge, double vtxZ) {
308  double deltaPhi = 0;
309  double etaEC = 100;
310  double phiEC = 100;
311 
312  double Rcurv = 9999999;
313  if (bfVal_ != 0)
314  Rcurv = pT * 33.3 * 100 / (bfVal_ * 10); //r(m)=pT(GeV)*33.3/B(kG)
315 
316  double ecDist = zEE_; //distance to ECAL andcap from IP (cm), 317 - ecal (not preshower), preshower -300
317  double ecRad = rEB_; //radius of ECAL barrel (cm)
318  double theta = 2 * atan(exp(-etaIP));
319  double zNew = 0;
320  if (theta > M_PI_2)
321  theta = M_PI - theta;
322  if (std::abs(etaIP) < ebEtaBoundary_) {
323  if ((0.5 * ecRad / Rcurv) > 1) {
324  etaEC = 10000;
325  deltaPhi = 0;
326  } else {
327  deltaPhi = -charge * asin(0.5 * ecRad / Rcurv);
328  double alpha1 = 2 * asin(0.5 * ecRad / Rcurv);
329  double z = ecRad / tan(theta);
330  if (etaIP > 0)
331  zNew = z * (Rcurv * alpha1) / ecRad + vtxZ; //new z-coordinate of track
332  else
333  zNew = -z * (Rcurv * alpha1) / ecRad + vtxZ; //new z-coordinate of track
334  double zAbs = std::abs(zNew);
335  if (zAbs < ecDist) {
336  etaEC = -log(tan(0.5 * atan(ecRad / zAbs)));
337  deltaPhi = -charge * asin(0.5 * ecRad / Rcurv);
338  }
339  if (zAbs > ecDist) {
340  zAbs = (std::abs(etaIP) / etaIP) * ecDist;
341  double Zflight = std::abs(zAbs - vtxZ);
342  double alpha = (Zflight * ecRad) / (z * Rcurv);
343  double Rec = 2 * Rcurv * sin(alpha / 2);
344  deltaPhi = -charge * alpha / 2;
345  etaEC = -log(tan(0.5 * atan(Rec / ecDist)));
346  }
347  }
348  } else {
349  zNew = (std::abs(etaIP) / etaIP) * ecDist;
350  double Zflight = std::abs(zNew - vtxZ);
351  double Rvirt = std::abs(Zflight * tan(theta));
352  double Rec = 2 * Rcurv * sin(Rvirt / (2 * Rcurv));
353  deltaPhi = -(charge) * (Rvirt / (2 * Rcurv));
354  etaEC = -log(tan(0.5 * atan(Rec / ecDist)));
355  }
356 
357  if (zNew < 0)
358  etaEC = -etaEC;
359  phiEC = phiIP + deltaPhi;
360 
361  if (phiEC < -M_PI)
362  phiEC += M_2_PI;
363  if (phiEC > M_PI)
364  phiEC -= M_2_PI;
365 
366  std::pair<double, double> retVal(etaEC, phiEC);
367  return retVal;
368 }
const_iterator end(int bx) const
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:49
void produce(edm::Event &evt, const edm::EventSetup &es) override
float alpha
Definition: AMPTWrapper.h:95
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
void getObjects(Vids &ids, VRphoton &refs) const
various physics-level getters:
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
void beginRun(const edm::Run &, const edm::EventSetup &) override
GlobalVector inTesla(const GlobalPoint &g) const override
Field value ad specified global point, in Tesla.
double getDistInCM(double eta1, double phi1, double eta2, double phi2)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Geom::Theta< T > theta() const
#define M_PI_2
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
delete x;
Definition: CaloConfig.h:22
Definition: config.py:1
BXVector< Tau > TauBxCollection
Definition: Tau.h:11
const edm::EDGetTokenT< reco::VertexCollection > tok_vert_
T mag() const
Definition: PV3DBase.h:67
const edm::EDGetTokenT< l1t::TauBxCollection > tok_l1_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
const std::vector< edm::EDGetTokenT< reco::TrackCollection > > toks_pix_
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void setEtaPhiEcal(double eta, double phi)
eta, phi at ECAL surface
std::pair< double, double > GetEtaPhiAtEcal(double etaIP, double phiIP, double pT, int charge, double vtxZ)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
#define M_PI
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
void add(std::string const &label, ParameterSetDescription const &psetDescription)
fixed size matrix
HLT enums.
T get() const
Definition: EventSetup.h:71
const_iterator begin(int bx) const
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
std::vector< T >::const_iterator const_iterator
Definition: BXVector.h:20
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11
const edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > tok_hlt_