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 #include <cmath>
5 
6 // Class header file
9 // Framework
15 //
16 
17 
18 // Math
19 #include "Math/GenVector/VectorUtil.h"
20 #include "Math/GenVector/PxPyPzE4D.h"
22 
26 
27 //magF
31 
32 //for ECAL geometry
38 
39 
41 
42  tok_l1_ = consumes<l1extra::L1JetParticleCollection>(config.getParameter<edm::InputTag>("L1eTauJetsSource"));
43  tauAssocCone_ = config.getParameter<double>("tauAssociationCone");
44  tauUnbiasCone_ = config.getParameter<double>("tauUnbiasCone");
45  pixelTracksSources_ = config.getParameter<std::vector<edm::InputTag> >("PixelTracksSources");
46  const unsigned nLabels = pixelTracksSources_.size();
47  for ( unsigned i=0; i != nLabels; i++ )
48  toks_pix_.push_back(consumes<reco::TrackCollection>(pixelTracksSources_[i]));
49  prelimCone_ = config.getParameter<double>("ExtrapolationConeSize");
50  pixelIsolationConeSizeAtEC_ = config.getParameter<double>("PixelIsolationConeSizeAtEC");
51  tok_hlt_ = consumes<trigger::TriggerFilterObjectWithRefs>(config.getParameter<edm::InputTag>("L1GTSeedLabel"));
52  vtxCutSeed_ = config.getParameter<double>("MaxVtxDXYSeed");
53  vtxCutIsol_ = config.getParameter<double>("MaxVtxDXYIsol");
54  tok_vert_ = consumes<reco::VertexCollection>(config.getParameter<edm::InputTag>("VertexLabel"));
55  bfield_ = config.getParameter<std::string>("MagFieldRecordName");
56  minPTrackValue_ = config.getParameter<double>("minPTrack");
57  maxPForIsolationValue_ = config.getParameter<double>("maxPTrackForIsolation");
58  ebEtaBoundary_ = config.getParameter<double>("EBEtaBoundary");
59  rEB_ = zEE_ = -1;
60  bfVal = 0;
61  // Register the product
62  produces< reco::IsolatedPixelTrackCandidateCollection >();
63 }
64 
66 
67 }
68 
70 
72 
74  theEventSetup.get<CaloGeometryRecord>().get(pG);
75 
76  const double rad (dynamic_cast<const EcalBarrelGeometry*>( pG->getSubdetectorGeometry(DetId::Ecal, EcalBarrel ))->avgRadiusXYFrontFaceCenter() ) ;
77 
78  const double zz (dynamic_cast<const EcalEndcapGeometry*>( pG->getSubdetectorGeometry(DetId::Ecal, EcalEndcap ))->avgAbsZFrontFaceCenter() ) ;
79 
80  rEB_=rad;
81  zEE_=zz;
82 
84  theEventSetup.get<IdealMagneticFieldRecord>().get(vbfField);
85  const VolumeBasedMagneticField* vbfCPtr = dynamic_cast<const VolumeBasedMagneticField*>(&(*vbfField));
86  GlobalVector BField=vbfCPtr->inTesla(GlobalPoint(0,0,0));
87  bfVal=BField.mag();
88 }
89 
91 
93 
94  //create vector of refs from input collections
95  std::vector<reco::TrackRef> pixelTrackRefs;
96 
97  for (unsigned int iPix=0; iPix<pixelTracksSources_.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<l1extra::L1JetParticleCollection> > l1tauobjref;
119  std::vector< edm::Ref<l1extra::L1JetParticleCollection> > l1jetobjref;
120  std::vector< edm::Ref<l1extra::L1JetParticleCollection> > l1forjetobjref;
121 
122  l1trigobj->getObjects(trigger::TriggerL1TauJet, l1tauobjref);
123  l1trigobj->getObjects(trigger::TriggerL1CenJet, l1jetobjref);
124  l1trigobj->getObjects(trigger::TriggerL1ForJet, l1forjetobjref);
125 
126  for (unsigned int p=0; p<l1tauobjref.size(); p++) {
127  if (l1tauobjref[p]->pt()>ptTriggered) {
128  ptTriggered = l1tauobjref[p]->pt();
129  phiTriggered = l1tauobjref[p]->phi();
130  etaTriggered = l1tauobjref[p]->eta();
131  }
132  }
133  for (unsigned int p=0; p<l1jetobjref.size(); p++) {
134  if (l1jetobjref[p]->pt()>ptTriggered) {
135  ptTriggered = l1jetobjref[p]->pt();
136  phiTriggered = l1jetobjref[p]->phi();
137  etaTriggered = l1jetobjref[p]->eta();
138  }
139  }
140  for (unsigned int p=0; p<l1forjetobjref.size(); p++) {
141  if (l1forjetobjref[p]->pt()>ptTriggered) {
142  ptTriggered=l1forjetobjref[p]->pt();
143  phiTriggered=l1forjetobjref[p]->phi();
144  etaTriggered=l1forjetobjref[p]->eta();
145  }
146  }
147 
148  double drMaxL1Track_ = tauAssocCone_;
149 
150  int ntr = 0;
151  std::vector<seedAtEC> VecSeedsatEC;
152  //loop to select isolated tracks
153  for (unsigned iS=0; iS<pixelTrackRefs.size(); iS++) {
154  bool vtxMatch = false;
155  //associate to vertex (in Z)
156  reco::VertexCollection::const_iterator vitSel;
157  double minDZ = 1000;
158  bool found(false);
159  for (reco::VertexCollection::const_iterator vit=pVert->begin(); vit!=pVert->end(); vit++) {
160  if (std::abs(pixelTrackRefs[iS]->dz(vit->position()))<minDZ) {
161  minDZ = std::abs(pixelTrackRefs[iS]->dz(vit->position()));
162  vitSel = vit;
163  found = true;
164  }
165  }
166  //cut on dYX:
167  if (found) {
168  if(std::abs(pixelTrackRefs[iS]->dxy(vitSel->position()))<vtxCutSeed_) vtxMatch=true;
169  } else {
170  vtxMatch=true;
171  }
172 
173  //select tracks not matched to triggered L1 jet
174  double R=reco::deltaR(etaTriggered, phiTriggered,
175  pixelTrackRefs[iS]->eta(), pixelTrackRefs[iS]->phi());
176  if (R<tauUnbiasCone_) continue;
177 
178  //check taujet matching
179  bool tmatch=false;
180  l1extra::L1JetParticleCollection::const_iterator selj;
181  for (l1extra::L1JetParticleCollection::const_iterator tj=l1eTauJets->begin(); tj!=l1eTauJets->end(); tj++) {
182  if (reco::deltaR(pixelTrackRefs[iS]->momentum().eta(), pixelTrackRefs[iS]->momentum().phi(), tj->momentum().eta(), tj->momentum().phi()) > drMaxL1Track_) continue;
183  selj = tj;
184  tmatch = true;
185  } //loop over L1 tau
186 
187 
188  //propagate seed track to ECAL surface:
189  std::pair<double,double> seedCooAtEC;
190  // in case vertex is found:
191  if (found) seedCooAtEC=GetEtaPhiAtEcal(pixelTrackRefs[iS]->eta(), pixelTrackRefs[iS]->phi(), pixelTrackRefs[iS]->pt(), pixelTrackRefs[iS]->charge(), vitSel->z());
192  //in case vertex is not found:
193  else seedCooAtEC=GetEtaPhiAtEcal(pixelTrackRefs[iS]->eta(), pixelTrackRefs[iS]->phi(), pixelTrackRefs[iS]->pt(), pixelTrackRefs[iS]->charge(), 0);
194  seedAtEC seed(iS,(tmatch||vtxMatch),seedCooAtEC.first,seedCooAtEC.second);
195  VecSeedsatEC.push_back(seed);
196  }
197 
198  for (unsigned int i=0; i<VecSeedsatEC.size(); i++) {
199  unsigned int iSeed = VecSeedsatEC[i].index;
200  if (!VecSeedsatEC[i].ok) continue;
201  if(pixelTrackRefs[iSeed]->p()<minPTrackValue_) continue;
202  l1extra::L1JetParticleCollection::const_iterator selj;
203  for (l1extra::L1JetParticleCollection::const_iterator tj=l1eTauJets->begin(); tj!=l1eTauJets->end(); tj++) {
204  if (reco::deltaR(pixelTrackRefs[iSeed]->momentum().eta(),pixelTrackRefs[iSeed]->momentum().phi(),tj->momentum().eta(),tj->momentum().phi()) > drMaxL1Track_) continue;
205  selj = tj;
206  } //loop over L1 tau
207  double maxP = 0;
208  double sumP = 0;
209  for(unsigned int j=0; j<VecSeedsatEC.size(); j++) {
210  if (i==j) continue;
211  unsigned int iSurr = VecSeedsatEC[j].index;
212  //define preliminary cone around seed track impact point from which tracks will be extrapolated:
213  if (reco::deltaR(pixelTrackRefs[iSeed]->eta(), pixelTrackRefs[iSeed]->phi(), pixelTrackRefs[iSurr]->eta(), pixelTrackRefs[iSurr]->phi())>prelimCone_) continue;
214  double minDZ2(1000);
215  bool found(false);
216  reco::VertexCollection::const_iterator vitSel2;
217  for (reco::VertexCollection::const_iterator vit=pVert->begin(); vit!=pVert->end(); vit++) {
218  if (std::abs(pixelTrackRefs[iSurr]->dz(vit->position()))<minDZ2) {
219  minDZ2 = std::abs(pixelTrackRefs[iSurr]->dz(vit->position()));
220  vitSel2 = vit;
221  found = true;
222  }
223  }
224  //cut ot dXY:
225  if (found&&std::abs(pixelTrackRefs[iSurr]->dxy(vitSel2->position()))>vtxCutIsol_) continue;
226  //calculate distance at ECAL surface and update isolation:
227  if (getDistInCM(VecSeedsatEC[i].eta, VecSeedsatEC[i].phi, VecSeedsatEC[j].eta, VecSeedsatEC[j].phi)<pixelIsolationConeSizeAtEC_) {
228  sumP+=pixelTrackRefs[iSurr]->p();
229  if(pixelTrackRefs[iSurr]->p()>maxP) maxP=pixelTrackRefs[iSurr]->p();
230  }
231  }
232  if (maxP<maxPForIsolationValue_) {
233  reco::IsolatedPixelTrackCandidate newCandidate(pixelTrackRefs[iSeed], l1extra::L1JetParticleRef(l1eTauJets,selj-l1eTauJets->begin()), maxP, sumP);
234  newCandidate.SetEtaPhiEcal(VecSeedsatEC[i].eta, VecSeedsatEC[i].phi);
235  trackCollection->push_back(newCandidate);
236  ntr++;
237  }
238  }
239  // put the product in the event
240  std::auto_ptr< reco::IsolatedPixelTrackCandidateCollection > outCollection(trackCollection);
241  theEvent.put(outCollection);
242 }
243 
244 
245 double IsolatedPixelTrackCandidateProducer::getDistInCM(double eta1, double phi1, double eta2, double phi2) {
246  double Rec;
247  double theta1=2*atan(exp(-eta1));
248  double theta2=2*atan(exp(-eta2));
249  if (std::abs(eta1)<1.479) Rec=rEB_; //radius of ECAL barrel
250  else if (std::abs(eta1)>1.479&&std::abs(eta1)<7.0) Rec=tan(theta1)*zEE_; //distance from IP to ECAL endcap
251  else return 1000;
252 
253  //|vect| times tg of acos(scalar product)
254  double angle=acos((sin(theta1)*sin(theta2)*(sin(phi1)*sin(phi2)+cos(phi1)*cos(phi2))+cos(theta1)*cos(theta2)));
255  if (angle<M_PI_2) return std::abs((Rec/sin(theta1))*tan(angle));
256  else return 1000;
257 }
258 
259 
260 std::pair<double,double> IsolatedPixelTrackCandidateProducer::GetEtaPhiAtEcal(double etaIP, double phiIP, double pT, int charge, double vtxZ) {
261 
262  double deltaPhi=0;
263  double etaEC = 100;
264  double phiEC = 100;
265 
266  double Rcurv = 9999999;
267  if (bfVal!=0) Rcurv=pT*33.3*100/(bfVal*10); //r(m)=pT(GeV)*33.3/B(kG)
268 
269  double ecDist = zEE_; //distance to ECAL andcap from IP (cm), 317 - ecal (not preshower), preshower -300
270  double ecRad = rEB_; //radius of ECAL barrel (cm)
271  double theta = 2*atan(exp(-etaIP));
272  double zNew = 0;
273  if (theta>M_PI_2) theta=M_PI-theta;
274  if (std::abs(etaIP)<ebEtaBoundary_) {
275  if ((0.5*ecRad/Rcurv)>1) {
276  etaEC = 10000;
277  deltaPhi = 0;
278  } else {
279  deltaPhi =-charge*asin(0.5*ecRad/Rcurv);
280  double alpha1 = 2*asin(0.5*ecRad/Rcurv);
281  double z = ecRad/tan(theta);
282  if (etaIP>0) zNew = z*(Rcurv*alpha1)/ecRad+vtxZ; //new z-coordinate of track
283  else zNew =-z*(Rcurv*alpha1)/ecRad+vtxZ; //new z-coordinate of track
284  double zAbs=std::abs(zNew);
285  if (zAbs<ecDist) {
286  etaEC = -log(tan(0.5*atan(ecRad/zAbs)));
287  deltaPhi = -charge*asin(0.5*ecRad/Rcurv);
288  }
289  if (zAbs>ecDist) {
290  zAbs = (std::abs(etaIP)/etaIP)*ecDist;
291  double Zflight = std::abs(zAbs-vtxZ);
292  double alpha = (Zflight*ecRad)/(z*Rcurv);
293  double Rec = 2*Rcurv*sin(alpha/2);
294  deltaPhi =-charge*alpha/2;
295  etaEC =-log(tan(0.5*atan(Rec/ecDist)));
296  }
297  }
298  } else {
299  zNew = (std::abs(etaIP)/etaIP)*ecDist;
300  double Zflight = std::abs(zNew-vtxZ);
301  double Rvirt = std::abs(Zflight*tan(theta));
302  double Rec = 2*Rcurv*sin(Rvirt/(2*Rcurv));
303  deltaPhi =-(charge)*(Rvirt/(2*Rcurv));
304  etaEC =-log(tan(0.5*atan(Rec/ecDist)));
305  }
306 
307  if (zNew<0) etaEC=-etaEC;
308  phiEC = phiIP+deltaPhi;
309 
310  if (phiEC<-M_PI) phiEC += M_2_PI;
311  if (phiEC>M_PI) phiEC -= M_2_PI;
312 
313  std::pair<double,double> retVal(etaEC,phiEC);
314  return retVal;
315 }
316 
317 
std::pair< double, double > GetEtaPhiAtEcal(double etaIP, double phiIP, double pT, int charge, double vtxZ)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
float alpha
Definition: AMPTWrapper.h:95
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
IsolatedPixelTrackCandidateProducer(const edm::ParameterSet &ps)
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Geom::Theta< T > theta() const
#define M_PI_2
std::vector< edm::EDGetTokenT< reco::TrackCollection > > toks_pix_
double deltaR(const T1 &t1, const T2 &t2)
Definition: deltaR.h:48
edm::EDGetTokenT< reco::VertexCollection > tok_vert_
T eta() const
float float float z
T mag() const
Definition: PV3DBase.h:67
edm::EDGetTokenT< l1extra::L1JetParticleCollection > tok_l1_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
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
int j
Definition: DBlmapReader.cc:9
std::vector< IsolatedPixelTrackCandidate > IsolatedPixelTrackCandidateCollection
collectin of IsolatedPixelTrackCandidate objects
#define M_PI
GlobalVector inTesla(const GlobalPoint &g) const
Field value ad specified global point, in Tesla.
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)
edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > tok_hlt_
Definition: Run.h:41
void SetEtaPhiEcal(double eta, double phi)
eta, phi at ECAL surface
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11
Definition: DDAxes.h:10