CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 }
87 
89 
91 
92  //create vector of refs from input collections
93  std::vector<reco::TrackRef> pixelTrackRefs;
94 
95  for (unsigned int iPix=0; iPix<toks_pix_.size(); iPix++) {
97  theEvent.getByToken(toks_pix_[iPix],iPixCol);
98  for (reco::TrackCollection::const_iterator pit=iPixCol->begin(); pit!=iPixCol->end(); pit++) {
99  pixelTrackRefs.push_back(reco::TrackRef(iPixCol,pit-iPixCol->begin()));
100  }
101  }
102 
104  theEvent.getByToken(tok_l1_,l1eTauJets);
105 
107  theEvent.getByToken(tok_vert_,pVert);
108 
109  double ptTriggered = -10;
110  double etaTriggered = -100;
111  double phiTriggered = -100;
112 
114  theEvent.getByToken(tok_hlt_, l1trigobj);
115 
116  std::vector< edm::Ref<l1t::TauBxCollection> > l1tauobjref;
117  std::vector< edm::Ref<l1t::JetBxCollection> > l1jetobjref;
118 
119  l1trigobj->getObjects(trigger::TriggerTau, l1tauobjref);
120  l1trigobj->getObjects(trigger::TriggerJet, l1jetobjref);
121 
122  for (unsigned int p=0; p<l1tauobjref.size(); p++) {
123  if (l1tauobjref[p]->pt()>ptTriggered) {
124  ptTriggered = l1tauobjref[p]->pt();
125  phiTriggered = l1tauobjref[p]->phi();
126  etaTriggered = l1tauobjref[p]->eta();
127  }
128  }
129  for (unsigned int p=0; p<l1jetobjref.size(); p++) {
130  if (l1jetobjref[p]->pt()>ptTriggered) {
131  ptTriggered = l1jetobjref[p]->pt();
132  phiTriggered = l1jetobjref[p]->phi();
133  etaTriggered = l1jetobjref[p]->eta();
134  }
135  }
136 
137  double drMaxL1Track_ = tauAssocCone_;
138 
139  int ntr = 0;
140  std::vector<seedAtEC> VecSeedsatEC;
141  //loop to select isolated tracks
142  for (unsigned iS=0; iS<pixelTrackRefs.size(); iS++) {
143  bool vtxMatch = false;
144  //associate to vertex (in Z)
145  reco::VertexCollection::const_iterator vitSel;
146  double minDZ = 1000;
147  bool found(false);
148  for (reco::VertexCollection::const_iterator vit=pVert->begin(); vit!=pVert->end(); vit++) {
149  if (std::abs(pixelTrackRefs[iS]->dz(vit->position()))<minDZ) {
150  minDZ = std::abs(pixelTrackRefs[iS]->dz(vit->position()));
151  vitSel = vit;
152  found = true;
153  }
154  }
155  //cut on dYX:
156  if (found) {
157  if(std::abs(pixelTrackRefs[iS]->dxy(vitSel->position()))<vtxCutSeed_) vtxMatch=true;
158  } else {
159  vtxMatch=true;
160  }
161 
162  //select tracks not matched to triggered L1 jet
163  double R=reco::deltaR(etaTriggered, phiTriggered,
164  pixelTrackRefs[iS]->eta(), pixelTrackRefs[iS]->phi());
165  if (R<tauUnbiasCone_) continue;
166 
167  //check taujet matching
168  bool tmatch=false;
170  for (l1t::TauBxCollection::const_iterator tj=l1eTauJets->begin(); tj!=l1eTauJets->end(); tj++) {
171  if (reco::deltaR(pixelTrackRefs[iS]->momentum().eta(), pixelTrackRefs[iS]->momentum().phi(), tj->momentum().eta(), tj->momentum().phi()) > drMaxL1Track_) continue;
172  selj = tj;
173  tmatch = true;
174  } //loop over L1 tau
175 
176 
177  //propagate seed track to ECAL surface:
178  std::pair<double,double> seedCooAtEC;
179  // in case vertex is found:
180  if (found) seedCooAtEC=GetEtaPhiAtEcal(pixelTrackRefs[iS]->eta(), pixelTrackRefs[iS]->phi(), pixelTrackRefs[iS]->pt(), pixelTrackRefs[iS]->charge(), vitSel->z());
181  //in case vertex is not found:
182  else seedCooAtEC=GetEtaPhiAtEcal(pixelTrackRefs[iS]->eta(), pixelTrackRefs[iS]->phi(), pixelTrackRefs[iS]->pt(), pixelTrackRefs[iS]->charge(), 0);
183  seedAtEC seed(iS,(tmatch||vtxMatch),seedCooAtEC.first,seedCooAtEC.second);
184  VecSeedsatEC.push_back(seed);
185  }
186 
187  for (unsigned int i=0; i<VecSeedsatEC.size(); i++) {
188  unsigned int iSeed = VecSeedsatEC[i].index;
189  if (!VecSeedsatEC[i].ok) continue;
190  if(pixelTrackRefs[iSeed]->p()<minPTrackValue_) continue;
192  for (l1t::TauBxCollection::const_iterator tj=l1eTauJets->begin(); tj!=l1eTauJets->end(); tj++) {
193  if (reco::deltaR(pixelTrackRefs[iSeed]->momentum().eta(),pixelTrackRefs[iSeed]->momentum().phi(),tj->momentum().eta(),tj->momentum().phi()) > drMaxL1Track_) continue;
194  selj = tj;
195  } //loop over L1 tau
196  double maxP = 0;
197  double sumP = 0;
198  for(unsigned int j=0; j<VecSeedsatEC.size(); j++) {
199  if (i==j) continue;
200  unsigned int iSurr = VecSeedsatEC[j].index;
201  //define preliminary cone around seed track impact point from which tracks will be extrapolated:
202  if (reco::deltaR(pixelTrackRefs[iSeed]->eta(), pixelTrackRefs[iSeed]->phi(), pixelTrackRefs[iSurr]->eta(), pixelTrackRefs[iSurr]->phi())>prelimCone_) continue;
203  double minDZ2(1000);
204  bool found(false);
205  reco::VertexCollection::const_iterator vitSel2;
206  for (reco::VertexCollection::const_iterator vit=pVert->begin(); vit!=pVert->end(); vit++) {
207  if (std::abs(pixelTrackRefs[iSurr]->dz(vit->position()))<minDZ2) {
208  minDZ2 = std::abs(pixelTrackRefs[iSurr]->dz(vit->position()));
209  vitSel2 = vit;
210  found = true;
211  }
212  }
213  //cut ot dXY:
214  if (found&&std::abs(pixelTrackRefs[iSurr]->dxy(vitSel2->position()))>vtxCutIsol_) continue;
215  //calculate distance at ECAL surface and update isolation:
216  if (getDistInCM(VecSeedsatEC[i].eta, VecSeedsatEC[i].phi, VecSeedsatEC[j].eta, VecSeedsatEC[j].phi)<pixelIsolationConeSizeAtEC_) {
217  sumP+=pixelTrackRefs[iSurr]->p();
218  if(pixelTrackRefs[iSurr]->p()>maxP) maxP=pixelTrackRefs[iSurr]->p();
219  }
220  }
221  if (maxP<maxPForIsolationValue_) {
222  reco::IsolatedPixelTrackCandidate newCandidate(pixelTrackRefs[iSeed], l1t::TauRef(l1eTauJets,selj-l1eTauJets->begin()), maxP, sumP);
223  newCandidate.setEtaPhiEcal(VecSeedsatEC[i].eta, VecSeedsatEC[i].phi);
224  trackCollection->push_back(newCandidate);
225  ntr++;
226  }
227  }
228  // put the product in the event
229  std::auto_ptr< reco::IsolatedPixelTrackCandidateCollection > outCollection(trackCollection);
230  theEvent.put(outCollection);
231 }
232 
233 
234 double IsolatedPixelTrackCandidateL1TProducer::getDistInCM(double eta1, double phi1, double eta2, double phi2) {
235  double Rec;
236  double theta1=2*atan(exp(-eta1));
237  double theta2=2*atan(exp(-eta2));
238  if (std::abs(eta1)<1.479) Rec=rEB_; //radius of ECAL barrel
239  else if (std::abs(eta1)>1.479&&std::abs(eta1)<7.0) Rec=tan(theta1)*zEE_; //distance from IP to ECAL endcap
240  else return 1000;
241 
242  //|vect| times tg of acos(scalar product)
243  double angle=acos((sin(theta1)*sin(theta2)*(sin(phi1)*sin(phi2)+cos(phi1)*cos(phi2))+cos(theta1)*cos(theta2)));
244  if (angle<M_PI_2) return std::abs((Rec/sin(theta1))*tan(angle));
245  else return 1000;
246 }
247 
248 
249 std::pair<double,double> IsolatedPixelTrackCandidateL1TProducer::GetEtaPhiAtEcal(double etaIP, double phiIP, double pT, int charge, double vtxZ) {
250 
251  double deltaPhi=0;
252  double etaEC = 100;
253  double phiEC = 100;
254 
255  double Rcurv = 9999999;
256  if (bfVal_!=0) Rcurv=pT*33.3*100/(bfVal_*10); //r(m)=pT(GeV)*33.3/B(kG)
257 
258  double ecDist = zEE_; //distance to ECAL andcap from IP (cm), 317 - ecal (not preshower), preshower -300
259  double ecRad = rEB_; //radius of ECAL barrel (cm)
260  double theta = 2*atan(exp(-etaIP));
261  double zNew = 0;
262  if (theta>M_PI_2) theta=M_PI-theta;
263  if (std::abs(etaIP)<ebEtaBoundary_) {
264  if ((0.5*ecRad/Rcurv)>1) {
265  etaEC = 10000;
266  deltaPhi = 0;
267  } else {
268  deltaPhi =-charge*asin(0.5*ecRad/Rcurv);
269  double alpha1 = 2*asin(0.5*ecRad/Rcurv);
270  double z = ecRad/tan(theta);
271  if (etaIP>0) zNew = z*(Rcurv*alpha1)/ecRad+vtxZ; //new z-coordinate of track
272  else zNew =-z*(Rcurv*alpha1)/ecRad+vtxZ; //new z-coordinate of track
273  double zAbs=std::abs(zNew);
274  if (zAbs<ecDist) {
275  etaEC = -log(tan(0.5*atan(ecRad/zAbs)));
276  deltaPhi = -charge*asin(0.5*ecRad/Rcurv);
277  }
278  if (zAbs>ecDist) {
279  zAbs = (std::abs(etaIP)/etaIP)*ecDist;
280  double Zflight = std::abs(zAbs-vtxZ);
281  double alpha = (Zflight*ecRad)/(z*Rcurv);
282  double Rec = 2*Rcurv*sin(alpha/2);
283  deltaPhi =-charge*alpha/2;
284  etaEC =-log(tan(0.5*atan(Rec/ecDist)));
285  }
286  }
287  } else {
288  zNew = (std::abs(etaIP)/etaIP)*ecDist;
289  double Zflight = std::abs(zNew-vtxZ);
290  double Rvirt = std::abs(Zflight*tan(theta));
291  double Rec = 2*Rcurv*sin(Rvirt/(2*Rcurv));
292  deltaPhi =-(charge)*(Rvirt/(2*Rcurv));
293  etaEC =-log(tan(0.5*atan(Rec/ecDist)));
294  }
295 
296  if (zNew<0) etaEC=-etaEC;
297  phiEC = phiIP+deltaPhi;
298 
299  if (phiEC<-M_PI) phiEC += M_2_PI;
300  if (phiEC>M_PI) phiEC -= M_2_PI;
301 
302  std::pair<double,double> retVal(etaEC,phiEC);
303  return retVal;
304 }
305 
306 
zEE_(-1)
virtual void produce(edm::Event &evt, const edm::EventSetup &es) override
int i
Definition: DBlmapReader.cc:9
float alpha
Definition: AMPTWrapper.h:95
tauAssocCone_(config.getParameter< double >("tauAssociationCone"))
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
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
vtxCutIsol_(config.getParameter< double >("MaxVtxDXYIsol"))
rEB_(-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
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
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
int j
Definition: DBlmapReader.cc:9
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
std::vector< IsolatedPixelTrackCandidate > IsolatedPixelTrackCandidateCollection
collectin of IsolatedPixelTrackCandidate objects
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)
minPTrackValue_(config.getParameter< double >("minPTrack"))
vtxCutSeed_(config.getParameter< double >("MaxVtxDXYSeed"))
GlobalVector inTesla(const GlobalPoint &g) const
Field value ad specified global point, in Tesla.
#define M_PI
prelimCone_(config.getParameter< double >("ExtrapolationConeSize"))
tuple trackCollection
const T & get() const
Definition: EventSetup.h:56
string const
Definition: compareJSON.py:14
bfield_(config.getParameter< std::string >("MagFieldRecordName"))
tauUnbiasCone_(config.getParameter< double >("tauUnbiasCone"))
pixelIsolationConeSizeAtEC_(config.getParameter< double >("PixelIsolationConeSizeAtEC"))
maxPForIsolationValue_(config.getParameter< double >("maxPTrackForIsolation"))
ebEtaBoundary_(config.getParameter< double >("EBEtaBoundary"))
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_