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 
20 // Math
21 #include "Math/GenVector/VectorUtil.h"
22 #include "Math/GenVector/PxPyPzE4D.h"
24 
28 
29 //magF
33 
34 //for ECAL geometry
40 
41 
43  tok_hlt_( consumes<trigger::TriggerFilterObjectWithRefs>(config.getParameter<edm::InputTag>("L1GTSeedLabel")) ),
44  tok_l1_( consumes<l1t::TauBxCollection>(config.getParameter<edm::InputTag>("L1eTauJetsSource")) ),
45  tok_vert_( consumes<reco::VertexCollection>(config.getParameter<edm::InputTag>("VertexLabel")) ),
46  toks_pix_( edm::vector_transform(
47  config.getParameter<std::vector<edm::InputTag> >("PixelTracksSources"),
48  [this](edm::InputTag const & tag){return consumes<reco::TrackCollection>(tag);}) ),
49  bfield_( config.getParameter<std::string>("MagFieldRecordName") ),
50  prelimCone_( config.getParameter<double>("ExtrapolationConeSize") ),
51  pixelIsolationConeSizeAtEC_( config.getParameter<double>("PixelIsolationConeSizeAtEC") ),
52  vtxCutSeed_( config.getParameter<double>("MaxVtxDXYSeed") ),
53  vtxCutIsol_( config.getParameter<double>("MaxVtxDXYIsol") ),
54  tauAssocCone_( config.getParameter<double>("tauAssociationCone") ),
55  tauUnbiasCone_( config.getParameter<double>("tauUnbiasCone") ),
56  minPTrackValue_( config.getParameter<double>("minPTrack") ),
57  maxPForIsolationValue_( config.getParameter<double>("maxPTrackForIsolation") ),
58  ebEtaBoundary_( config.getParameter<double>("EBEtaBoundary") ),
59  rEB_( -1 ),
60  zEE_( -1 ),
61  bfVal_( 0 )
62 {
63  // Register the product
64  produces< reco::IsolatedPixelTrackCandidateCollection >();
65 }
66 
68 
71  std::vector<edm::InputTag> tracksrc = {edm::InputTag("hltPixelTracks")};
72  desc.add<edm::InputTag>("L1eTauJetsSource",edm::InputTag("hltGtStage2Digis","Tau"));
73  desc.add<double>("tauAssociationCone", 0.0 );
74  desc.add<double>("tauUnbiasCone", 1.2 );
75  desc.add<std::vector<edm::InputTag> >("PixelTracksSources",tracksrc);
76  desc.add<double>("ExtrapolationConeSize", 1.0);
77  desc.add<double>("PixelIsolationConeSizeAtEC",40);
78  desc.add<edm::InputTag>("L1GTSeedLabel",edm::InputTag("hltL1sV0SingleJet60"));
79  desc.add<double>("MaxVtxDXYSeed", 101.0);
80  desc.add<double>("MaxVtxDXYIsol", 101.0);
81  desc.add<edm::InputTag>("VertexLabel",edm::InputTag("hltTrimmedPixelVertices"));
82  desc.add<std::string>("MagFieldRecordName","VolumeBasedMagneticField");
83  desc.add<double>("minPTrack", 5.0);
84  desc.add<double>("maxPTrackForIsolation", 3.0);
85  desc.add<double>("EBEtaBoundary", 1.479);
86  descriptions.add("isolPixelTrackProdL1T",desc);
87 }
88 
90 
92  theEventSetup.get<CaloGeometryRecord>().get(pG);
93 
94  const double rad (dynamic_cast<const EcalBarrelGeometry*>( pG->getSubdetectorGeometry(DetId::Ecal, EcalBarrel ))->avgRadiusXYFrontFaceCenter() ) ;
95  const double zz (dynamic_cast<const EcalEndcapGeometry*>( pG->getSubdetectorGeometry(DetId::Ecal, EcalEndcap ))->avgAbsZFrontFaceCenter() ) ;
96 
97  rEB_ = rad;
98  zEE_ = zz;
99 
101  theEventSetup.get<IdealMagneticFieldRecord>().get(vbfField);
102  const VolumeBasedMagneticField* vbfCPtr = dynamic_cast<const VolumeBasedMagneticField*>(&(*vbfField));
103  GlobalVector BField = vbfCPtr->inTesla(GlobalPoint(0,0,0));
104  bfVal_=BField.mag();
105  edm::LogVerbatim("IsoTrack") << "rEB " << rEB_ << " zEE " << zEE_ << " B "
106  << bfVal_ << std::endl;
107 }
108 
110 
111  auto trackCollection = std::make_unique<reco::IsolatedPixelTrackCandidateCollection>();
112 
113  //create vector of refs from input collections
114  std::vector<reco::TrackRef> pixelTrackRefs;
115 
116  for (unsigned int iPix=0; iPix<toks_pix_.size(); iPix++) {
118  theEvent.getByToken(toks_pix_[iPix],iPixCol);
119  for (reco::TrackCollection::const_iterator pit=iPixCol->begin(); pit!=iPixCol->end(); pit++) {
120  pixelTrackRefs.push_back(reco::TrackRef(iPixCol,pit-iPixCol->begin()));
121  }
122  }
123 
125  theEvent.getByToken(tok_l1_,l1eTauJets);
126 
128  theEvent.getByToken(tok_vert_,pVert);
129 
130  double ptTriggered = -10;
131  double etaTriggered = -100;
132  double phiTriggered = -100;
133 
135  theEvent.getByToken(tok_hlt_, l1trigobj);
136 
137  std::vector< edm::Ref<l1t::TauBxCollection> > l1tauobjref;
138  std::vector< edm::Ref<l1t::JetBxCollection> > l1jetobjref;
139 
140  // l1trigobj->getObjects(trigger::TriggerTau, l1tauobjref);
141  l1trigobj->getObjects(trigger::TriggerL1Tau, l1tauobjref);
142  // l1trigobj->getObjects(trigger::TriggerJet, l1jetobjref);
143  l1trigobj->getObjects(trigger::TriggerL1Jet, l1jetobjref);
144 
145  for (auto p : l1tauobjref) {
146  if (p->pt()>ptTriggered) {
147  ptTriggered = p->pt();
148  phiTriggered = p->phi();
149  etaTriggered = p->eta();
150  }
151  }
152  for (auto p : l1jetobjref) {
153  if (p->pt()>ptTriggered) {
154  ptTriggered = p->pt();
155  phiTriggered = p->phi();
156  etaTriggered = p->eta();
157  }
158  }
159  edm::LogVerbatim("IsoTrack") << "Sizes " << l1tauobjref.size() << ":"
160  << l1jetobjref.size() << " Trig " << ptTriggered
161  << ":" << etaTriggered << ":" << phiTriggered
162  << std::endl;
163 
164  double drMaxL1Track_ = tauAssocCone_;
165  int ntr = 0;
166  std::vector<seedAtEC> VecSeedsatEC;
167  //loop to select isolated tracks
168  for (unsigned iS=0; iS<pixelTrackRefs.size(); iS++) {
169  bool vtxMatch = false;
170  //associate to vertex (in Z)
171  reco::VertexCollection::const_iterator vitSel;
172  double minDZ = 1000;
173  bool found(false);
174  for (reco::VertexCollection::const_iterator vit=pVert->begin(); vit!=pVert->end(); vit++) {
175  if (std::abs(pixelTrackRefs[iS]->dz(vit->position()))<minDZ) {
176  minDZ = std::abs(pixelTrackRefs[iS]->dz(vit->position()));
177  vitSel = vit;
178  found = true;
179  }
180  }
181  //cut on dYX:
182  if (found) {
183  if(std::abs(pixelTrackRefs[iS]->dxy(vitSel->position()))<vtxCutSeed_) vtxMatch=true;
184  } else {
185  vtxMatch=true;
186  }
187  edm::LogVerbatim("IsoTrack") << "minZD " << minDZ << " Found " << found
188  << ":" << vtxMatch << std::endl;
189 
190  //select tracks not matched to triggered L1 jet
191  double R=reco::deltaR(etaTriggered, phiTriggered,
192  pixelTrackRefs[iS]->eta(), pixelTrackRefs[iS]->phi());
193  edm::LogVerbatim("IsoTrack") << "Distance to L1 " << R << ":"
194  << tauUnbiasCone_ << " Result "
195  << (R<tauUnbiasCone_) << std::endl;
196  if (R<tauUnbiasCone_) continue;
197 
198  //check taujet matching
199  bool tmatch=false;
201  for (l1t::TauBxCollection::const_iterator tj=l1eTauJets->begin(); tj!=l1eTauJets->end(); tj++) {
202  if (reco::deltaR(pixelTrackRefs[iS]->momentum().eta(), pixelTrackRefs[iS]->momentum().phi(), tj->momentum().eta(), tj->momentum().phi()) > drMaxL1Track_) continue;
203  selj = tj;
204  tmatch = true;
205  } //loop over L1 tau
206  edm::LogVerbatim("IsoTrack") << "tMatch " << tmatch << std::endl;
207 
208  //propagate seed track to ECAL surface:
209  std::pair<double,double> seedCooAtEC;
210  // in case vertex is found:
211  if (found) seedCooAtEC=GetEtaPhiAtEcal(pixelTrackRefs[iS]->eta(), pixelTrackRefs[iS]->phi(), pixelTrackRefs[iS]->pt(), pixelTrackRefs[iS]->charge(), vitSel->z());
212  //in case vertex is not found:
213  else seedCooAtEC=GetEtaPhiAtEcal(pixelTrackRefs[iS]->eta(), pixelTrackRefs[iS]->phi(), pixelTrackRefs[iS]->pt(), pixelTrackRefs[iS]->charge(), 0);
214  seedAtEC seed(iS,(tmatch||vtxMatch),seedCooAtEC.first,seedCooAtEC.second);
215  VecSeedsatEC.push_back(seed);
216  edm::LogVerbatim("IsoTrack") << "Seed " << seedCooAtEC.first
217  << seedCooAtEC.second << std::endl;
218  }
219  for (unsigned int i=0; i<VecSeedsatEC.size(); i++) {
220  unsigned int iSeed = VecSeedsatEC[i].index;
221  if (!VecSeedsatEC[i].ok) continue;
222  if(pixelTrackRefs[iSeed]->p()<minPTrackValue_) continue;
224  for (l1t::TauBxCollection::const_iterator tj=l1eTauJets->begin(); tj!=l1eTauJets->end(); tj++) {
225  if (reco::deltaR(pixelTrackRefs[iSeed]->momentum().eta(),pixelTrackRefs[iSeed]->momentum().phi(),tj->momentum().eta(),tj->momentum().phi()) > drMaxL1Track_) continue;
226  selj = tj;
227  } //loop over L1 tau
228  double maxP = 0;
229  double sumP = 0;
230  for(unsigned int j=0; j<VecSeedsatEC.size(); j++) {
231  if (i==j) continue;
232  unsigned int iSurr = VecSeedsatEC[j].index;
233  //define preliminary cone around seed track impact point from which tracks will be extrapolated:
234  if (reco::deltaR(pixelTrackRefs[iSeed]->eta(), pixelTrackRefs[iSeed]->phi(), pixelTrackRefs[iSurr]->eta(), pixelTrackRefs[iSurr]->phi())>prelimCone_) continue;
235  double minDZ2(1000);
236  bool found(false);
237  reco::VertexCollection::const_iterator vitSel2;
238  for (reco::VertexCollection::const_iterator vit=pVert->begin(); vit!=pVert->end(); vit++) {
239  if (std::abs(pixelTrackRefs[iSurr]->dz(vit->position()))<minDZ2) {
240  minDZ2 = std::abs(pixelTrackRefs[iSurr]->dz(vit->position()));
241  vitSel2 = vit;
242  found = true;
243  }
244  }
245  //cut ot dXY:
246  if (found&&std::abs(pixelTrackRefs[iSurr]->dxy(vitSel2->position()))>vtxCutIsol_) continue;
247  //calculate distance at ECAL surface and update isolation:
248  if (getDistInCM(VecSeedsatEC[i].eta, VecSeedsatEC[i].phi, VecSeedsatEC[j].eta, VecSeedsatEC[j].phi)<pixelIsolationConeSizeAtEC_) {
249  sumP+=pixelTrackRefs[iSurr]->p();
250  if(pixelTrackRefs[iSurr]->p()>maxP) maxP=pixelTrackRefs[iSurr]->p();
251  }
252  }
253  if (maxP<maxPForIsolationValue_) {
254  reco::IsolatedPixelTrackCandidate newCandidate(pixelTrackRefs[iSeed], l1t::TauRef(l1eTauJets,selj-l1eTauJets->begin()), maxP, sumP);
255  newCandidate.setEtaPhiEcal(VecSeedsatEC[i].eta, VecSeedsatEC[i].phi);
256  trackCollection->push_back(newCandidate);
257  ntr++;
258  }
259  }
260  edm::LogVerbatim("IsoTrack") << "Number of Isolated Track " << ntr << "\n";
261  // put the product in the event
262  theEvent.put(std::move(trackCollection));
263 }
264 
265 
266 double IsolatedPixelTrackCandidateL1TProducer::getDistInCM(double eta1, double phi1, double eta2, double phi2) {
267  double Rec;
268  double theta1=2*atan(exp(-eta1));
269  double theta2=2*atan(exp(-eta2));
270  if (std::abs(eta1)<1.479) Rec=rEB_; //radius of ECAL barrel
271  else if (std::abs(eta1)>1.479&&std::abs(eta1)<7.0) Rec=tan(theta1)*zEE_; //distance from IP to ECAL endcap
272  else return 1000;
273 
274  //|vect| times tg of acos(scalar product)
275  double angle=acos((sin(theta1)*sin(theta2)*(sin(phi1)*sin(phi2)+cos(phi1)*cos(phi2))+cos(theta1)*cos(theta2)));
276  if (angle<M_PI_2) return std::abs((Rec/sin(theta1))*tan(angle));
277  else return 1000;
278 }
279 
280 
281 std::pair<double,double> IsolatedPixelTrackCandidateL1TProducer::GetEtaPhiAtEcal(double etaIP, double phiIP, double pT, int charge, double vtxZ) {
282 
283  double deltaPhi=0;
284  double etaEC = 100;
285  double phiEC = 100;
286 
287  double Rcurv = 9999999;
288  if (bfVal_!=0) Rcurv=pT*33.3*100/(bfVal_*10); //r(m)=pT(GeV)*33.3/B(kG)
289 
290  double ecDist = zEE_; //distance to ECAL andcap from IP (cm), 317 - ecal (not preshower), preshower -300
291  double ecRad = rEB_; //radius of ECAL barrel (cm)
292  double theta = 2*atan(exp(-etaIP));
293  double zNew = 0;
294  if (theta>M_PI_2) theta=M_PI-theta;
295  if (std::abs(etaIP)<ebEtaBoundary_) {
296  if ((0.5*ecRad/Rcurv)>1) {
297  etaEC = 10000;
298  deltaPhi = 0;
299  } else {
300  deltaPhi =-charge*asin(0.5*ecRad/Rcurv);
301  double alpha1 = 2*asin(0.5*ecRad/Rcurv);
302  double z = ecRad/tan(theta);
303  if (etaIP>0) zNew = z*(Rcurv*alpha1)/ecRad+vtxZ; //new z-coordinate of track
304  else zNew =-z*(Rcurv*alpha1)/ecRad+vtxZ; //new z-coordinate of track
305  double zAbs=std::abs(zNew);
306  if (zAbs<ecDist) {
307  etaEC = -log(tan(0.5*atan(ecRad/zAbs)));
308  deltaPhi = -charge*asin(0.5*ecRad/Rcurv);
309  }
310  if (zAbs>ecDist) {
311  zAbs = (std::abs(etaIP)/etaIP)*ecDist;
312  double Zflight = std::abs(zAbs-vtxZ);
313  double alpha = (Zflight*ecRad)/(z*Rcurv);
314  double Rec = 2*Rcurv*sin(alpha/2);
315  deltaPhi =-charge*alpha/2;
316  etaEC =-log(tan(0.5*atan(Rec/ecDist)));
317  }
318  }
319  } else {
320  zNew = (std::abs(etaIP)/etaIP)*ecDist;
321  double Zflight = std::abs(zNew-vtxZ);
322  double Rvirt = std::abs(Zflight*tan(theta));
323  double Rec = 2*Rcurv*sin(Rvirt/(2*Rcurv));
324  deltaPhi =-(charge)*(Rvirt/(2*Rcurv));
325  etaEC =-log(tan(0.5*atan(Rec/ecDist)));
326  }
327 
328  if (zNew<0) etaEC=-etaEC;
329  phiEC = phiIP+deltaPhi;
330 
331  if (phiEC<-M_PI) phiEC += M_2_PI;
332  if (phiEC>M_PI) phiEC -= M_2_PI;
333 
334  std::pair<double,double> retVal(etaEC,phiEC);
335  return retVal;
336 }
337 
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:137
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:579
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
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
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
void add(std::string const &label, ParameterSetDescription const &psetDescription)
fixed size matrix
HLT enums.
T get() const
Definition: EventSetup.h:63
const_iterator begin(int bx) const
def move(src, dest)
Definition: eostools.py:510
Definition: Run.h:44
std::vector< Tau >::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_