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