CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IsolatedPixelTrackCandidateProducer.cc
Go to the documentation of this file.
1 #include <vector>
2 #include <memory>
3 #include <algorithm>
4 
5 // Class header file
8 // Framework
14 //
16 // L1Extra
20 
22 
26 //#include "DataFormats/L1GlobalTrigger/interface/L1GtLogicParser.h"
27 
30 
31 // Math
32 #include "Math/GenVector/VectorUtil.h"
33 #include "Math/GenVector/PxPyPzE4D.h"
35 
36 //vertices
39 
43 
44 //magF
48 
49 //for ECAL geometry
55 
56 
58 
59  l1eTauJetsSource_ = config.getParameter<edm::InputTag>("L1eTauJetsSource");
60  tauAssocCone_ = config.getParameter<double>("tauAssociationCone");
61  tauUnbiasCone_ = config.getParameter<double>("tauUnbiasCone");
62  pixelTracksSources_ = config.getParameter<std::vector<edm::InputTag> >("PixelTracksSources");
63  prelimCone_ = config.getParameter<double>("ExtrapolationConeSize");
64  pixelIsolationConeSizeAtEC_ = config.getParameter<double>("PixelIsolationConeSizeAtEC");
65  hltGTseedlabel_ = config.getParameter<edm::InputTag>("L1GTSeedLabel");
66  vtxCutSeed_ = config.getParameter<double>("MaxVtxDXYSeed");
67  vtxCutIsol_ = config.getParameter<double>("MaxVtxDXYIsol");
68  vertexLabel_ = config.getParameter<edm::InputTag>("VertexLabel");
69  bfield_ = config.getParameter<std::string>("MagFieldRecordName");
70  minPTrackValue_ = config.getParameter<double>("minPTrack");
71  maxPForIsolationValue_ = config.getParameter<double>("maxPTrackForIsolation");
72  ebEtaBoundary_ = config.getParameter<double>("EBEtaBoundary");
73  rEB_ = zEE_ = -1;
74 
75  // Register the product
76  produces< reco::IsolatedPixelTrackCandidateCollection >();
77 }
78 
80 
81 }
82 
84 
86 {
87 
89  theEventSetup.get<CaloGeometryRecord>().get(pG);
90 
91  const double rad (dynamic_cast<const EcalBarrelGeometry*>( pG->getSubdetectorGeometry(DetId::Ecal, EcalBarrel ))->avgRadiusXYFrontFaceCenter() ) ;
92 
93  const double zz (dynamic_cast<const EcalEndcapGeometry*>( pG->getSubdetectorGeometry(DetId::Ecal, EcalEndcap ))->avgAbsZFrontFaceCenter() ) ;
94 
95  rEB_=rad;
96  zEE_=zz;
97 
98 }
99 
101 
103 
104  //create vector of refs from input collections
105  std::vector<reco::TrackRef> pixelTrackRefs;
106 
107  for (unsigned int iPix=0; iPix<pixelTracksSources_.size(); iPix++)
108  {
110  theEvent.getByLabel(pixelTracksSources_[iPix],iPixCol);
111  for (reco::TrackCollection::const_iterator pit=iPixCol->begin(); pit!=iPixCol->end(); pit++)
112  {
113  pixelTrackRefs.push_back(reco::TrackRef(iPixCol,pit-iPixCol->begin()));
114  }
115  }
116 
118  theEvent.getByLabel(l1eTauJetsSource_,l1eTauJets);
119 
121  theEvent.getByLabel(vertexLabel_,pVert);
122 
123  double ptTriggered = -10;
124  double etaTriggered = -100;
125  double phiTriggered = -100;
126 
128  theEvent.getByLabel(hltGTseedlabel_, l1trigobj);
129 
130  std::vector< edm::Ref<l1extra::L1JetParticleCollection> > l1tauobjref;
131  std::vector< edm::Ref<l1extra::L1JetParticleCollection> > l1jetobjref;
132  std::vector< edm::Ref<l1extra::L1JetParticleCollection> > l1forjetobjref;
133 
134  l1trigobj->getObjects(trigger::TriggerL1TauJet, l1tauobjref);
135  l1trigobj->getObjects(trigger::TriggerL1CenJet, l1jetobjref);
136  l1trigobj->getObjects(trigger::TriggerL1ForJet, l1forjetobjref);
137 
138  for (unsigned int p=0; p<l1tauobjref.size(); p++)
139  {
140  if (l1tauobjref[p]->pt()>ptTriggered)
141  {
142  ptTriggered = l1tauobjref[p]->pt();
143  phiTriggered = l1tauobjref[p]->phi();
144  etaTriggered = l1tauobjref[p]->eta();
145  }
146  }
147  for (unsigned int p=0; p<l1jetobjref.size(); p++)
148  {
149  if (l1jetobjref[p]->pt()>ptTriggered)
150  {
151  ptTriggered = l1jetobjref[p]->pt();
152  phiTriggered = l1jetobjref[p]->phi();
153  etaTriggered = l1jetobjref[p]->eta();
154  }
155  }
156  for (unsigned int p=0; p<l1forjetobjref.size(); p++)
157  {
158  if (l1forjetobjref[p]->pt()>ptTriggered)
159  {
160  ptTriggered=l1forjetobjref[p]->pt();
161  phiTriggered=l1forjetobjref[p]->phi();
162  etaTriggered=l1forjetobjref[p]->eta();
163  }
164  }
165 
166  double minPTrack_ = minPTrackValue_;
167  double drMaxL1Track_ = tauAssocCone_;
168 
169  int ntr = 0;
170 
171  //loop to select isolated tracks
172  for (unsigned iSeed=0; iSeed<pixelTrackRefs.size(); iSeed++)
173  {
174  if(pixelTrackRefs[iSeed]->p()<minPTrack_) continue;
175 
176  bool good = false;
177  bool vtxMatch = false;
178 
179  //associate to vertex (in Z)
180  reco::VertexCollection::const_iterator vitSel;
181  double minDZ = 100;
182  for (reco::VertexCollection::const_iterator vit=pVert->begin(); vit!=pVert->end(); vit++)
183  {
184  if (fabs(pixelTrackRefs[iSeed]->dz(vit->position()))<minDZ)
185  {
186  minDZ = fabs(pixelTrackRefs[iSeed]->dz(vit->position()));
187  vitSel = vit;
188  }
189  }
190  //cut on dYX:
191  if (minDZ!=100&&fabs(pixelTrackRefs[iSeed]->dxy(vitSel->position()))<vtxCutSeed_) vtxMatch=true;
192  if (minDZ==100) vtxMatch=true;
193 
194  //select tracks not matched to triggered L1 jet
195  double R=deltaR(etaTriggered, phiTriggered, pixelTrackRefs[iSeed]->eta(), pixelTrackRefs[iSeed]->phi());
196  if (R<tauUnbiasCone_) continue;
197 
198  //check taujet matching
199  bool tmatch=false;
200  l1extra::L1JetParticleCollection::const_iterator selj;
201  for (l1extra::L1JetParticleCollection::const_iterator tj=l1eTauJets->begin(); tj!=l1eTauJets->end(); tj++)
202  {
203  if(ROOT::Math::VectorUtil::DeltaR(pixelTrackRefs[iSeed]->momentum(),tj->momentum()) > drMaxL1Track_) continue;
204  selj = tj;
205  tmatch = true;
206  } //loop over L1 tau
207 
208  //propagate seed track to ECAL surface:
209  std::pair<double,double> seedCooAtEC;
210  // in case vertex is found:
211  if (minDZ!=100) seedCooAtEC=GetEtaPhiAtEcal(theEventSetup, pixelTrackRefs[iSeed]->eta(), pixelTrackRefs[iSeed]->phi(), pixelTrackRefs[iSeed]->pt(), pixelTrackRefs[iSeed]->charge(), vitSel->z());
212  //in case vertex is not found:
213  else seedCooAtEC=GetEtaPhiAtEcal(theEventSetup, pixelTrackRefs[iSeed]->eta(), pixelTrackRefs[iSeed]->phi(), pixelTrackRefs[iSeed]->pt(), pixelTrackRefs[iSeed]->charge(), 0);
214 
215  //calculate isolation
216  double maxP = 0;
217  double sumP = 0;
218  for (unsigned iSurr=0; iSurr<pixelTrackRefs.size(); iSurr++)
219  {
220  if(iSeed==iSurr) continue;
221  //define preliminary cone around seed track impact point from which tracks will be extrapolated:
222  if (deltaR(seedCooAtEC.first, seedCooAtEC.second, pixelTrackRefs[iSurr]->eta(), pixelTrackRefs[iSurr]->phi())>prelimCone_) continue;
223  //associate to vertex (in Z):
224  double minDZ2=100;
225  reco::VertexCollection::const_iterator vitSel2;
226  for (reco::VertexCollection::const_iterator vit=pVert->begin(); vit!=pVert->end(); vit++)
227  {
228  if (fabs(pixelTrackRefs[iSurr]->dz(vit->position()))<minDZ2)
229  {
230  minDZ2 = fabs(pixelTrackRefs[iSurr]->dz(vit->position()));
231  vitSel2 = vit;
232  }
233  }
234  //cut ot dXY:
235  if (minDZ2!=100&&fabs(pixelTrackRefs[iSurr]->dxy(vitSel2->position()))>vtxCutIsol_) continue;
236  //propagate to ECAL surface:
237  std::pair<double,double> cooAtEC;
238  // in case vertex is found:
239  if (minDZ2!=100) cooAtEC=GetEtaPhiAtEcal(theEventSetup, pixelTrackRefs[iSurr]->eta(), pixelTrackRefs[iSurr]->phi(), pixelTrackRefs[iSurr]->pt(), pixelTrackRefs[iSurr]->charge(), vitSel2->z());
240  // in case vertex is not found:
241  else cooAtEC=GetEtaPhiAtEcal(theEventSetup, pixelTrackRefs[iSurr]->eta(), pixelTrackRefs[iSurr]->phi(), pixelTrackRefs[iSurr]->pt(), pixelTrackRefs[iSurr]->charge(), 0);
242 
243  //calculate distance at ECAL surface and update isolation:
244  if (getDistInCM(seedCooAtEC.first, seedCooAtEC.second, cooAtEC.first, cooAtEC.second)<pixelIsolationConeSizeAtEC_)
245  {
246  sumP+=pixelTrackRefs[iSurr]->p();
247  if(pixelTrackRefs[iSurr]->p()>maxP) maxP=pixelTrackRefs[iSurr]->p();
248  }
249  }
250 
251  if (tmatch||vtxMatch) good=true;
252 
253  if (good&&maxP<maxPForIsolationValue_)
254  {
255  reco::IsolatedPixelTrackCandidate newCandidate(pixelTrackRefs[iSeed], l1extra::L1JetParticleRef(l1eTauJets,selj-l1eTauJets->begin()), maxP, sumP);
256  trackCollection->push_back(newCandidate);
257  ntr++;
258  }
259  }//loop over pixel tracks
260 
261  // put the product in the event
262  std::auto_ptr< reco::IsolatedPixelTrackCandidateCollection > outCollection(trackCollection);
263  theEvent.put(outCollection);
264 
265 }
266 
267 
268 double IsolatedPixelTrackCandidateProducer::getDistInCM(double eta1, double phi1, double eta2, double phi2)
269 {
270  double Rec;
271  double theta1=2*atan(exp(-eta1));
272  double theta2=2*atan(exp(-eta2));
273  if (fabs(eta1)<1.479) Rec=129; //radius of ECAL barrel
274  else if (fabs(eta1)>1.479&&fabs(eta1)<7.0) Rec=tan(theta1)*317; //distance from IP to ECAL endcap
275  else return 1000;
276 
277  //|vect| times tg of acos(scalar product)
278  double angle=acos((sin(theta1)*sin(theta2)*(sin(phi1)*sin(phi2)+cos(phi1)*cos(phi2))+cos(theta1)*cos(theta2)));
279  if (angle<acos(-1)/2) return fabs((Rec/sin(theta1))*tan(angle));
280  else return 1000;
281 }
282 
283 
284 std::pair<double,double>
285 IsolatedPixelTrackCandidateProducer::GetEtaPhiAtEcal(const edm::EventSetup& iSetup, double etaIP, double phiIP, double pT, int charge, double vtxZ)
286 {
288  iSetup.get<IdealMagneticFieldRecord>().get(vbfField);
289  const VolumeBasedMagneticField* vbfCPtr = dynamic_cast<const VolumeBasedMagneticField*>(&(*vbfField));
290  GlobalVector BField=vbfCPtr->inTesla(GlobalPoint(0,0,0));
291  //test
292  //int curvSgn=int(BField.z()/fabs(BField.z()));
293 
294  double bfVal=BField.mag();
295 
296  double deltaPhi=0;
297  double etaEC = 100;
298  double phiEC = 100;
299 
300  double Rcurv = 9999999;
301  if (bfVal!=0) Rcurv=pT*33.3*100/(bfVal*10); //r(m)=pT(GeV)*33.3/B(kG)
302 
303  double ecDist = zEE_; //distance to ECAL andcap from IP (cm), 317 - ecal (not preshower), preshower -300
304  double ecRad = rEB_; //radius of ECAL barrel (cm)
305  double theta=2*atan(exp(-etaIP));
306  double zNew=0;
307  if (theta>0.5*acos(-1)) theta=acos(-1)-theta;
308  if (fabs(etaIP)<ebEtaBoundary_)
309  {
310  if ((0.5*ecRad/Rcurv)>1)
311  {
312  etaEC=10000;
313  deltaPhi=0;
314  }
315  else
316  {
317  deltaPhi =-charge*asin(0.5*ecRad/Rcurv);
318  double alpha1 = 2*asin(0.5*ecRad/Rcurv);
319  double z = ecRad/tan(theta);
320  if (etaIP>0) zNew = z*(Rcurv*alpha1)/ecRad+vtxZ; //new z-coordinate of track
321  else zNew =-z*(Rcurv*alpha1)/ecRad+vtxZ; //new z-coordinate of track
322  double zAbs=fabs(zNew);
323  if (zAbs<ecDist)
324  {
325  etaEC = -log(tan(0.5*atan(ecRad/zAbs)));
326  deltaPhi = -charge*asin(0.5*ecRad/Rcurv);
327  }
328  if (zAbs>ecDist)
329  {
330  zAbs = (fabs(etaIP)/etaIP)*ecDist;
331  double Zflight = fabs(zAbs-vtxZ);
332  double alpha = (Zflight*ecRad)/(z*Rcurv);
333  double Rec = 2*Rcurv*sin(alpha/2);
334  deltaPhi =-charge*alpha/2;
335  etaEC =-log(tan(0.5*atan(Rec/ecDist)));
336  }
337  }
338  }
339  else
340  {
341  zNew = (fabs(etaIP)/etaIP)*ecDist;
342  double Zflight = fabs(zNew-vtxZ);
343  double Rvirt = fabs(Zflight*tan(theta));
344  double Rec = 2*Rcurv*sin(Rvirt/(2*Rcurv));
345  deltaPhi =-(charge)*(Rvirt/(2*Rcurv));
346  etaEC =-log(tan(0.5*atan(Rec/ecDist)));
347  }
348 
349  if (zNew<0) etaEC=-etaEC;
350  phiEC = phiIP+deltaPhi;
351 
352  if (phiEC<-acos(-1)) phiEC = 2*acos(-1)+phiEC;
353  if (phiEC>acos(-1)) phiEC =-2*acos(-1)+phiEC;
354 
355  std::pair<double,double> retVal(etaEC,phiEC);
356  return retVal;
357 }
358 
359 
T getParameter(std::string const &) const
float alpha
Definition: AMPTWrapper.h:95
virtual void beginRun(edm::Run &, const edm::EventSetup &)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
IsolatedPixelTrackCandidateProducer(const edm::ParameterSet &ps)
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Geom::Theta< T > theta() const
T eta() const
double charge(const std::vector< uint8_t > &Ampls)
std::pair< double, double > GetEtaPhiAtEcal(const edm::EventSetup &iSetup, double etaIP, double phiIP, double pT, int charge, double vtxZ)
double double double z
T mag() const
Definition: PV3DBase.h:66
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
std::vector< IsolatedPixelTrackCandidate > IsolatedPixelTrackCandidateCollection
collectin of IsolatedPixelTrackCandidate objects
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
GlobalVector inTesla(const GlobalPoint &g) const
Field value ad specified global point, in Tesla.
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
const T & get() const
Definition: EventSetup.h:55
virtual void produce(edm::Event &evt, const edm::EventSetup &es)
double getDistInCM(double eta1, double phi1, double eta2, double phi2)
Definition: Run.h:33
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11
Definition: DDAxes.h:10