CMS 3D CMS Logo

IsolatedPixelTrackCandidateProducer.cc
Go to the documentation of this file.
1 /* \class IsolatedPixelTrackCandidateProducer
2  *
3  *
4  */
5 
6 #include <vector>
7 #include <memory>
8 #include <algorithm>
9 #include <cmath>
10 
19 // L1Extra
23 
29 //vertices
32 // Framework
43 
44 // Math
45 #include "Math/GenVector/VectorUtil.h"
46 #include "Math/GenVector/PxPyPzE4D.h"
48 
49 //magF
53 
54 //for ECAL geometry
60 
61 //#define EDM_ML_DEBUG
62 
64 public:
67 
68  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
69 
70  void beginRun(const edm::Run&, const edm::EventSetup&) override;
71  void produce(edm::Event& evt, const edm::EventSetup& es) override;
72 
73  double getDistInCM(double eta1, double phi1, double eta2, double phi2);
74  std::pair<double, double> GetEtaPhiAtEcal(double etaIP, double phiIP, double pT, int charge, double vtxZ);
75 
76 private:
77  struct seedAtEC {
78  seedAtEC(unsigned int i, bool f, double et, double fi) : index(i), ok(f), eta(et), phi(fi) {}
79  unsigned int index;
80  bool ok;
81  double eta, phi;
82  };
83 
87  const std::vector<edm::EDGetTokenT<reco::TrackCollection> > toks_pix_;
90 
92  const double prelimCone_;
94  const double vtxCutSeed_;
95  const double vtxCutIsol_;
96  const double tauAssocCone_;
97  const double tauUnbiasCone_;
98  const double minPTrackValue_;
99  const double maxPForIsolationValue_;
100  const double ebEtaBoundary_;
101 
102  // these are read from the EventSetup, cannot be const
103  double rEB_;
104  double zEE_;
105  double bfVal_;
106 };
107 
109  : tok_hlt_(consumes<trigger::TriggerFilterObjectWithRefs>(config.getParameter<edm::InputTag>("L1GTSeedLabel"))),
110  tok_l1_(consumes<l1extra::L1JetParticleCollection>(config.getParameter<edm::InputTag>("L1eTauJetsSource"))),
111  tok_vert_(consumes<reco::VertexCollection>(config.getParameter<edm::InputTag>("VertexLabel"))),
112  toks_pix_(
113  edm::vector_transform(config.getParameter<std::vector<edm::InputTag> >("PixelTracksSources"),
114  [this](edm::InputTag const& tag) { return consumes<reco::TrackCollection>(tag); })),
115  tok_bFieldH_(esConsumes<MagneticField, IdealMagneticFieldRecord, edm::Transition::BeginRun>()),
116  tok_geom_(esConsumes<CaloGeometry, CaloGeometryRecord, edm::Transition::BeginRun>()),
117  bfield_(config.getParameter<std::string>("MagFieldRecordName")),
118  prelimCone_(config.getParameter<double>("ExtrapolationConeSize")),
119  pixelIsolationConeSizeAtEC_(config.getParameter<double>("PixelIsolationConeSizeAtEC")),
120  vtxCutSeed_(config.getParameter<double>("MaxVtxDXYSeed")),
121  vtxCutIsol_(config.getParameter<double>("MaxVtxDXYIsol")),
122  tauAssocCone_(config.getParameter<double>("tauAssociationCone")),
123  tauUnbiasCone_(config.getParameter<double>("tauUnbiasCone")),
124  minPTrackValue_(config.getParameter<double>("minPTrack")),
125  maxPForIsolationValue_(config.getParameter<double>("maxPTrackForIsolation")),
126  ebEtaBoundary_(config.getParameter<double>("EBEtaBoundary")),
127  rEB_(-1),
128  zEE_(-1),
129  bfVal_(0) {
130  // Register the product
131  produces<reco::IsolatedPixelTrackCandidateCollection>();
132 }
133 
135 
138  std::vector<edm::InputTag> tracksrc = {edm::InputTag("hltPixelTracks")};
139  desc.add<edm::InputTag>("L1eTauJetsSource", edm::InputTag("hltCaloStage2Digis", "Tau"));
140  desc.add<double>("tauAssociationCone", 0.0);
141  desc.add<double>("tauUnbiasCone", 1.2);
142  desc.add<std::vector<edm::InputTag> >("PixelTracksSources", tracksrc);
143  desc.add<double>("ExtrapolationConeSize", 1.0);
144  desc.add<double>("PixelIsolationConeSizeAtEC", 40);
145  desc.add<edm::InputTag>("L1GTSeedLabel", edm::InputTag("hltL1sIsoTrack"));
146  desc.add<double>("MaxVtxDXYSeed", 101.0);
147  desc.add<double>("MaxVtxDXYIsol", 101.0);
148  desc.add<edm::InputTag>("VertexLabel", edm::InputTag("hltTrimmedPixelVertices"));
149  desc.add<std::string>("MagFieldRecordName", "VolumeBasedMagneticField");
150  desc.add<double>("minPTrack", 5.0);
151  desc.add<double>("maxPTrackForIsolation", 3.0);
152  desc.add<double>("EBEtaBoundary", 1.479);
153  descriptions.add("isolPixelTrackProd", desc);
154 }
155 
157  const CaloGeometry* pG = &theEventSetup.getData(tok_geom_);
158 
159  const double rad(dynamic_cast<const EcalBarrelGeometry*>(pG->getSubdetectorGeometry(DetId::Ecal, EcalBarrel))
160  ->avgRadiusXYFrontFaceCenter());
161  const double zz(dynamic_cast<const EcalEndcapGeometry*>(pG->getSubdetectorGeometry(DetId::Ecal, EcalEndcap))
162  ->avgAbsZFrontFaceCenter());
163 
164  rEB_ = rad;
165  zEE_ = zz;
166 
167  const MagneticField* vbfField = &theEventSetup.getData(tok_bFieldH_);
168  const VolumeBasedMagneticField* vbfCPtr = dynamic_cast<const VolumeBasedMagneticField*>(&(*vbfField));
169  GlobalVector BField = vbfCPtr->inTesla(GlobalPoint(0, 0, 0));
170  bfVal_ = BField.mag();
171 }
172 
174  auto trackCollection = std::make_unique<reco::IsolatedPixelTrackCandidateCollection>();
175 
176  //create vector of refs from input collections
177  std::vector<reco::TrackRef> pixelTrackRefs;
178 #ifdef EDM_ML_DEBUG
179  edm::LogVerbatim("HcalIsoTrack") << "IsolatedPixelTrakCandidate: with" << toks_pix_.size()
180  << " candidates to start with\n";
181 #endif
182  for (unsigned int iPix = 0; iPix < toks_pix_.size(); iPix++) {
183  const edm::Handle<reco::TrackCollection>& iPixCol = theEvent.getHandle(toks_pix_[iPix]);
184  for (reco::TrackCollection::const_iterator pit = iPixCol->begin(); pit != iPixCol->end(); pit++) {
185  pixelTrackRefs.push_back(reco::TrackRef(iPixCol, pit - iPixCol->begin()));
186  }
187  }
188 
190 
192 
193  double drMaxL1Track_ = tauAssocCone_;
194 
195  int ntr = 0;
196  std::vector<seedAtEC> VecSeedsatEC;
197  //loop to select isolated tracks
198  for (unsigned iS = 0; iS < pixelTrackRefs.size(); iS++) {
199  bool vtxMatch = false;
200  //associate to vertex (in Z)
201  reco::VertexCollection::const_iterator vitSel;
202  double minDZ = 1000;
203  bool found(false);
204  for (reco::VertexCollection::const_iterator vit = pVert->begin(); vit != pVert->end(); vit++) {
205  if (std::abs(pixelTrackRefs[iS]->dz(vit->position())) < minDZ) {
206  minDZ = std::abs(pixelTrackRefs[iS]->dz(vit->position()));
207  vitSel = vit;
208  found = true;
209  }
210  }
211  //cut on dYX:
212  if (found) {
213  if (std::abs(pixelTrackRefs[iS]->dxy(vitSel->position())) < vtxCutSeed_)
214  vtxMatch = true;
215  } else {
216  vtxMatch = true;
217  }
218 
219  //check taujet matching
220  bool tmatch = false;
221  l1extra::L1JetParticleCollection::const_iterator selj;
222  for (l1extra::L1JetParticleCollection::const_iterator tj = l1eTauJets->begin(); tj != l1eTauJets->end(); tj++) {
223  if (reco::deltaR(pixelTrackRefs[iS]->momentum().eta(),
224  pixelTrackRefs[iS]->momentum().phi(),
225  tj->momentum().eta(),
226  tj->momentum().phi()) > drMaxL1Track_)
227  continue;
228  selj = tj;
229  tmatch = true;
230  } //loop over L1 tau
231 
232  //propagate seed track to ECAL surface:
233  std::pair<double, double> seedCooAtEC;
234  // in case vertex is found:
235  if (found)
236  seedCooAtEC = GetEtaPhiAtEcal(pixelTrackRefs[iS]->eta(),
237  pixelTrackRefs[iS]->phi(),
238  pixelTrackRefs[iS]->pt(),
239  pixelTrackRefs[iS]->charge(),
240  vitSel->z());
241  //in case vertex is not found:
242  else
243  seedCooAtEC = GetEtaPhiAtEcal(pixelTrackRefs[iS]->eta(),
244  pixelTrackRefs[iS]->phi(),
245  pixelTrackRefs[iS]->pt(),
246  pixelTrackRefs[iS]->charge(),
247  0);
248  seedAtEC seed(iS, (tmatch || vtxMatch), seedCooAtEC.first, seedCooAtEC.second);
249  VecSeedsatEC.push_back(seed);
250  }
251 #ifdef EDM_ML_DEBUG
252  edm::LogVerbatim("HcalIsoTrack") << "IsolatedPixelTrakCandidate: " << VecSeedsatEC.size()
253  << " seeds after propagation\n";
254 #endif
255 
256  for (unsigned int i = 0; i < VecSeedsatEC.size(); i++) {
257  unsigned int iSeed = VecSeedsatEC[i].index;
258  if (!VecSeedsatEC[i].ok)
259  continue;
260  if (pixelTrackRefs[iSeed]->p() < minPTrackValue_)
261  continue;
262  l1extra::L1JetParticleCollection::const_iterator selj;
263  for (l1extra::L1JetParticleCollection::const_iterator tj = l1eTauJets->begin(); tj != l1eTauJets->end(); tj++) {
264  if (reco::deltaR(pixelTrackRefs[iSeed]->momentum().eta(),
265  pixelTrackRefs[iSeed]->momentum().phi(),
266  tj->momentum().eta(),
267  tj->momentum().phi()) > drMaxL1Track_)
268  continue;
269  selj = tj;
270  } //loop over L1 tau
271  double maxP = 0;
272  double sumP = 0;
273  for (unsigned int j = 0; j < VecSeedsatEC.size(); j++) {
274  if (i == j)
275  continue;
276  unsigned int iSurr = VecSeedsatEC[j].index;
277  //define preliminary cone around seed track impact point from which tracks will be extrapolated:
278  if (reco::deltaR(pixelTrackRefs[iSeed]->eta(),
279  pixelTrackRefs[iSeed]->phi(),
280  pixelTrackRefs[iSurr]->eta(),
281  pixelTrackRefs[iSurr]->phi()) > prelimCone_)
282  continue;
283  double minDZ2(1000);
284  bool found(false);
285  reco::VertexCollection::const_iterator vitSel2;
286  for (reco::VertexCollection::const_iterator vit = pVert->begin(); vit != pVert->end(); vit++) {
287  if (std::abs(pixelTrackRefs[iSurr]->dz(vit->position())) < minDZ2) {
288  minDZ2 = std::abs(pixelTrackRefs[iSurr]->dz(vit->position()));
289  vitSel2 = vit;
290  found = true;
291  }
292  }
293  //cut ot dXY:
294  if (found && std::abs(pixelTrackRefs[iSurr]->dxy(vitSel2->position())) > vtxCutIsol_)
295  continue;
296  //calculate distance at ECAL surface and update isolation:
297  if (getDistInCM(VecSeedsatEC[i].eta, VecSeedsatEC[i].phi, VecSeedsatEC[j].eta, VecSeedsatEC[j].phi) <
299  sumP += pixelTrackRefs[iSurr]->p();
300  if (pixelTrackRefs[iSurr]->p() > maxP)
301  maxP = pixelTrackRefs[iSurr]->p();
302  }
303  }
306  pixelTrackRefs[iSeed], l1extra::L1JetParticleRef(l1eTauJets, selj - l1eTauJets->begin()), maxP, sumP);
307  newCandidate.setEtaPhiEcal(VecSeedsatEC[i].eta, VecSeedsatEC[i].phi);
308  trackCollection->push_back(newCandidate);
309  ntr++;
310  }
311  }
312  // put the product in the event
313  theEvent.put(std::move(trackCollection));
314 #ifdef EDM_ML_DEBUG
315  edm::LogVerbatim("HcalIsoTrack") << "IsolatedPixelTrackCandidate: Final # of candiates " << ntr << "\n";
316 #endif
317 }
318 
319 double IsolatedPixelTrackCandidateProducer::getDistInCM(double eta1, double phi1, double eta2, double phi2) {
320  double Rec;
321  double theta1 = 2 * atan(exp(-eta1));
322  double theta2 = 2 * atan(exp(-eta2));
323  if (std::abs(eta1) < 1.479)
324  Rec = rEB_; //radius of ECAL barrel
325  else if (std::abs(eta1) > 1.479 && std::abs(eta1) < 7.0)
326  Rec = tan(theta1) * zEE_; //distance from IP to ECAL endcap
327  else
328  return 1000;
329 
330  //|vect| times tg of acos(scalar product)
331  double angle =
332  acos((sin(theta1) * sin(theta2) * (sin(phi1) * sin(phi2) + cos(phi1) * cos(phi2)) + cos(theta1) * cos(theta2)));
333  if (angle < M_PI_2)
334  return std::abs((Rec / sin(theta1)) * tan(angle));
335  else
336  return 1000;
337 }
338 
340  double etaIP, double phiIP, double pT, int charge, double vtxZ) {
341  double deltaPhi = 0;
342  double etaEC = 100;
343  double phiEC = 100;
344 
345  double Rcurv = 9999999;
346  if (bfVal_ != 0)
347  Rcurv = pT * 33.3 * 100 / (bfVal_ * 10); //r(m)=pT(GeV)*33.3/B(kG)
348 
349  double ecDist = zEE_; //distance to ECAL andcap from IP (cm), 317 - ecal (not preshower), preshower -300
350  double ecRad = rEB_; //radius of ECAL barrel (cm)
351  double theta = 2 * atan(exp(-etaIP));
352  double zNew = 0;
353  if (theta > M_PI_2)
354  theta = M_PI - theta;
355  if (std::abs(etaIP) < ebEtaBoundary_) {
356  if ((0.5 * ecRad / Rcurv) > 1) {
357  etaEC = 10000;
358  deltaPhi = 0;
359  } else {
360  deltaPhi = -charge * asin(0.5 * ecRad / Rcurv);
361  double alpha1 = 2 * asin(0.5 * ecRad / Rcurv);
362  double z = ecRad / tan(theta);
363  if (etaIP > 0)
364  zNew = z * (Rcurv * alpha1) / ecRad + vtxZ; //new z-coordinate of track
365  else
366  zNew = -z * (Rcurv * alpha1) / ecRad + vtxZ; //new z-coordinate of track
367  double zAbs = std::abs(zNew);
368  if (zAbs < ecDist) {
369  etaEC = -log(tan(0.5 * atan(ecRad / zAbs)));
370  deltaPhi = -charge * asin(0.5 * ecRad / Rcurv);
371  }
372  if (zAbs > ecDist) {
373  zAbs = (std::abs(etaIP) / etaIP) * ecDist;
374  double Zflight = std::abs(zAbs - vtxZ);
375  double alpha = (Zflight * ecRad) / (z * Rcurv);
376  double Rec = 2 * Rcurv * sin(alpha / 2);
377  deltaPhi = -charge * alpha / 2;
378  etaEC = -log(tan(0.5 * atan(Rec / ecDist)));
379  }
380  }
381  } else {
382  zNew = (std::abs(etaIP) / etaIP) * ecDist;
383  double Zflight = std::abs(zNew - vtxZ);
384  double Rvirt = std::abs(Zflight * tan(theta));
385  double Rec = 2 * Rcurv * sin(Rvirt / (2 * Rcurv));
386  deltaPhi = -(charge) * (Rvirt / (2 * Rcurv));
387  etaEC = -log(tan(0.5 * atan(Rec / ecDist)));
388  }
389 
390  if (zNew < 0)
391  etaEC = -etaEC;
392  phiEC = phiIP + deltaPhi;
393 
394  if (phiEC < -M_PI)
395  phiEC += M_2_PI;
396  if (phiEC > M_PI)
397  phiEC -= M_2_PI;
398 
399  std::pair<double, double> retVal(etaEC, phiEC);
400  return retVal;
401 }
402 
405 
std::pair< double, double > GetEtaPhiAtEcal(double etaIP, double phiIP, double pT, int charge, double vtxZ)
Log< level::Info, true > LogVerbatim
float alpha
Definition: AMPTWrapper.h:105
const std::vector< edm::EDGetTokenT< reco::TrackCollection > > toks_pix_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > tok_geom_
void beginRun(const edm::Run &, const edm::EventSetup &) override
GlobalVector inTesla(const GlobalPoint &g) const override
Field value ad specified global point, in Tesla.
const edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > tok_hlt_
const edm::EDGetTokenT< l1extra::L1JetParticleCollection > tok_l1_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
IsolatedPixelTrackCandidateProducer(const edm::ParameterSet &ps)
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
#define M_PI_2
Definition: config.py:1
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
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
seedAtEC(unsigned int i, bool f, double et, double fi)
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > tok_bFieldH_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
void setEtaPhiEcal(double eta, double phi)
eta, phi at ECAL surface
bool getData(T &iHolder) const
Definition: EventSetup.h:122
#define M_PI
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const edm::EDGetTokenT< reco::VertexCollection > tok_vert_
fixed size matrix
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:563
HLT enums.
double getDistInCM(double eta1, double phi1, double eta2, double phi2)
void produce(edm::Event &evt, const edm::EventSetup &es) override
Geom::Theta< T > theta() const
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11