test
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
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 //#define DebugLog
41 
43  tok_hlt_( consumes<trigger::TriggerFilterObjectWithRefs>(config.getParameter<edm::InputTag>("L1GTSeedLabel")) ),
44  tok_l1_( consumes<l1extra::L1JetParticleCollection>(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 
69 }
70 
72 
74  theEventSetup.get<CaloGeometryRecord>().get(pG);
75 
76  const double rad (dynamic_cast<const EcalBarrelGeometry*>( pG->getSubdetectorGeometry(DetId::Ecal, EcalBarrel ))->avgRadiusXYFrontFaceCenter() ) ;
77  const double zz (dynamic_cast<const EcalEndcapGeometry*>( pG->getSubdetectorGeometry(DetId::Ecal, EcalEndcap ))->avgAbsZFrontFaceCenter() ) ;
78 
79  rEB_ = rad;
80  zEE_ = zz;
81 
83  theEventSetup.get<IdealMagneticFieldRecord>().get(vbfField);
84  const VolumeBasedMagneticField* vbfCPtr = dynamic_cast<const VolumeBasedMagneticField*>(&(*vbfField));
85  GlobalVector BField = vbfCPtr->inTesla(GlobalPoint(0,0,0));
86  bfVal_=BField.mag();
87 }
88 
90 
92 
93  //create vector of refs from input collections
94  std::vector<reco::TrackRef> pixelTrackRefs;
95 #ifdef DebugLog
96  edm::LogInfo("HcalIsoTrack") << "IsolatedPixelTrakCandidate: with" << toks_pix_.size() << " candidates to start with\n";
97 #endif
98  for (unsigned int iPix=0; iPix<toks_pix_.size(); iPix++) {
100  theEvent.getByToken(toks_pix_[iPix],iPixCol);
101  for (reco::TrackCollection::const_iterator pit=iPixCol->begin(); pit!=iPixCol->end(); pit++) {
102  pixelTrackRefs.push_back(reco::TrackRef(iPixCol,pit-iPixCol->begin()));
103  }
104  }
105 
107  theEvent.getByToken(tok_l1_,l1eTauJets);
108 
110  theEvent.getByToken(tok_vert_,pVert);
111  double drMaxL1Track_ = tauAssocCone_;
112 
113  int ntr = 0;
114  std::vector<seedAtEC> VecSeedsatEC;
115  //loop to select isolated tracks
116  for (unsigned iS=0; iS<pixelTrackRefs.size(); iS++) {
117  bool vtxMatch = false;
118  //associate to vertex (in Z)
119  reco::VertexCollection::const_iterator vitSel;
120  double minDZ = 1000;
121  bool found(false);
122  for (reco::VertexCollection::const_iterator vit=pVert->begin(); vit!=pVert->end(); vit++) {
123  if (std::abs(pixelTrackRefs[iS]->dz(vit->position()))<minDZ) {
124  minDZ = std::abs(pixelTrackRefs[iS]->dz(vit->position()));
125  vitSel = vit;
126  found = true;
127  }
128  }
129  //cut on dYX:
130  if (found) {
131  if(std::abs(pixelTrackRefs[iS]->dxy(vitSel->position()))<vtxCutSeed_) vtxMatch=true;
132  } else {
133  vtxMatch=true;
134  }
135 
136  //check taujet matching
137  bool tmatch=false;
138  l1extra::L1JetParticleCollection::const_iterator selj;
139  for (l1extra::L1JetParticleCollection::const_iterator tj=l1eTauJets->begin(); tj!=l1eTauJets->end(); tj++) {
140  if (reco::deltaR(pixelTrackRefs[iS]->momentum().eta(), pixelTrackRefs[iS]->momentum().phi(), tj->momentum().eta(), tj->momentum().phi()) > drMaxL1Track_) continue;
141  selj = tj;
142  tmatch = true;
143  } //loop over L1 tau
144 
145  //propagate seed track to ECAL surface:
146  std::pair<double,double> seedCooAtEC;
147  // in case vertex is found:
148  if (found) seedCooAtEC=GetEtaPhiAtEcal(pixelTrackRefs[iS]->eta(), pixelTrackRefs[iS]->phi(), pixelTrackRefs[iS]->pt(), pixelTrackRefs[iS]->charge(), vitSel->z());
149  //in case vertex is not found:
150  else seedCooAtEC=GetEtaPhiAtEcal(pixelTrackRefs[iS]->eta(), pixelTrackRefs[iS]->phi(), pixelTrackRefs[iS]->pt(), pixelTrackRefs[iS]->charge(), 0);
151  seedAtEC seed(iS,(tmatch||vtxMatch),seedCooAtEC.first,seedCooAtEC.second);
152  VecSeedsatEC.push_back(seed);
153  }
154 #ifdef DebugLog
155  edm::LogInfo("HcalIsoTrack") << "IsolatedPixelTrakCandidate: " << VecSeedsatEC.size() << " seeds after propagation\n";
156 #endif
157 
158  for (unsigned int i=0; i<VecSeedsatEC.size(); i++) {
159  unsigned int iSeed = VecSeedsatEC[i].index;
160  if (!VecSeedsatEC[i].ok) continue;
161  if(pixelTrackRefs[iSeed]->p()<minPTrackValue_) continue;
162  l1extra::L1JetParticleCollection::const_iterator selj;
163  for (l1extra::L1JetParticleCollection::const_iterator tj=l1eTauJets->begin(); tj!=l1eTauJets->end(); tj++) {
164  if (reco::deltaR(pixelTrackRefs[iSeed]->momentum().eta(),pixelTrackRefs[iSeed]->momentum().phi(),tj->momentum().eta(),tj->momentum().phi()) > drMaxL1Track_) continue;
165  selj = tj;
166  } //loop over L1 tau
167  double maxP = 0;
168  double sumP = 0;
169  for(unsigned int j=0; j<VecSeedsatEC.size(); j++) {
170  if (i==j) continue;
171  unsigned int iSurr = VecSeedsatEC[j].index;
172  //define preliminary cone around seed track impact point from which tracks will be extrapolated:
173  if (reco::deltaR(pixelTrackRefs[iSeed]->eta(), pixelTrackRefs[iSeed]->phi(), pixelTrackRefs[iSurr]->eta(), pixelTrackRefs[iSurr]->phi())>prelimCone_) continue;
174  double minDZ2(1000);
175  bool found(false);
176  reco::VertexCollection::const_iterator vitSel2;
177  for (reco::VertexCollection::const_iterator vit=pVert->begin(); vit!=pVert->end(); vit++) {
178  if (std::abs(pixelTrackRefs[iSurr]->dz(vit->position()))<minDZ2) {
179  minDZ2 = std::abs(pixelTrackRefs[iSurr]->dz(vit->position()));
180  vitSel2 = vit;
181  found = true;
182  }
183  }
184  //cut ot dXY:
185  if (found&&std::abs(pixelTrackRefs[iSurr]->dxy(vitSel2->position()))>vtxCutIsol_) continue;
186  //calculate distance at ECAL surface and update isolation:
187  if (getDistInCM(VecSeedsatEC[i].eta, VecSeedsatEC[i].phi, VecSeedsatEC[j].eta, VecSeedsatEC[j].phi)<pixelIsolationConeSizeAtEC_) {
188  sumP+=pixelTrackRefs[iSurr]->p();
189  if(pixelTrackRefs[iSurr]->p()>maxP) maxP=pixelTrackRefs[iSurr]->p();
190  }
191  }
192  if (maxP<maxPForIsolationValue_) {
193  reco::IsolatedPixelTrackCandidate newCandidate(pixelTrackRefs[iSeed], l1extra::L1JetParticleRef(l1eTauJets,selj-l1eTauJets->begin()), maxP, sumP);
194  newCandidate.setEtaPhiEcal(VecSeedsatEC[i].eta, VecSeedsatEC[i].phi);
195  trackCollection->push_back(newCandidate);
196  ntr++;
197  }
198  }
199  // put the product in the event
200  std::auto_ptr< reco::IsolatedPixelTrackCandidateCollection > outCollection(trackCollection);
201  theEvent.put(outCollection);
202 #ifdef DebugLog
203  edm::LogInfo("HcalIsoTrack") << "IsolatedPixelTrackCandidate: Final # of candiates " << ntr << "\n";
204 #endif
205 }
206 
207 
208 double IsolatedPixelTrackCandidateProducer::getDistInCM(double eta1, double phi1, double eta2, double phi2) {
209  double Rec;
210  double theta1=2*atan(exp(-eta1));
211  double theta2=2*atan(exp(-eta2));
212  if (std::abs(eta1)<1.479) Rec=rEB_; //radius of ECAL barrel
213  else if (std::abs(eta1)>1.479&&std::abs(eta1)<7.0) Rec=tan(theta1)*zEE_; //distance from IP to ECAL endcap
214  else return 1000;
215 
216  //|vect| times tg of acos(scalar product)
217  double angle=acos((sin(theta1)*sin(theta2)*(sin(phi1)*sin(phi2)+cos(phi1)*cos(phi2))+cos(theta1)*cos(theta2)));
218  if (angle<M_PI_2) return std::abs((Rec/sin(theta1))*tan(angle));
219  else return 1000;
220 }
221 
222 
223 std::pair<double,double> IsolatedPixelTrackCandidateProducer::GetEtaPhiAtEcal(double etaIP, double phiIP, double pT, int charge, double vtxZ) {
224 
225  double deltaPhi=0;
226  double etaEC = 100;
227  double phiEC = 100;
228 
229  double Rcurv = 9999999;
230  if (bfVal_!=0) Rcurv=pT*33.3*100/(bfVal_*10); //r(m)=pT(GeV)*33.3/B(kG)
231 
232  double ecDist = zEE_; //distance to ECAL andcap from IP (cm), 317 - ecal (not preshower), preshower -300
233  double ecRad = rEB_; //radius of ECAL barrel (cm)
234  double theta = 2*atan(exp(-etaIP));
235  double zNew = 0;
236  if (theta>M_PI_2) theta=M_PI-theta;
237  if (std::abs(etaIP)<ebEtaBoundary_) {
238  if ((0.5*ecRad/Rcurv)>1) {
239  etaEC = 10000;
240  deltaPhi = 0;
241  } else {
242  deltaPhi =-charge*asin(0.5*ecRad/Rcurv);
243  double alpha1 = 2*asin(0.5*ecRad/Rcurv);
244  double z = ecRad/tan(theta);
245  if (etaIP>0) zNew = z*(Rcurv*alpha1)/ecRad+vtxZ; //new z-coordinate of track
246  else zNew =-z*(Rcurv*alpha1)/ecRad+vtxZ; //new z-coordinate of track
247  double zAbs=std::abs(zNew);
248  if (zAbs<ecDist) {
249  etaEC = -log(tan(0.5*atan(ecRad/zAbs)));
250  deltaPhi = -charge*asin(0.5*ecRad/Rcurv);
251  }
252  if (zAbs>ecDist) {
253  zAbs = (std::abs(etaIP)/etaIP)*ecDist;
254  double Zflight = std::abs(zAbs-vtxZ);
255  double alpha = (Zflight*ecRad)/(z*Rcurv);
256  double Rec = 2*Rcurv*sin(alpha/2);
257  deltaPhi =-charge*alpha/2;
258  etaEC =-log(tan(0.5*atan(Rec/ecDist)));
259  }
260  }
261  } else {
262  zNew = (std::abs(etaIP)/etaIP)*ecDist;
263  double Zflight = std::abs(zNew-vtxZ);
264  double Rvirt = std::abs(Zflight*tan(theta));
265  double Rec = 2*Rcurv*sin(Rvirt/(2*Rcurv));
266  deltaPhi =-(charge)*(Rvirt/(2*Rcurv));
267  etaEC =-log(tan(0.5*atan(Rec/ecDist)));
268  }
269 
270  if (zNew<0) etaEC=-etaEC;
271  phiEC = phiIP+deltaPhi;
272 
273  if (phiEC<-M_PI) phiEC += M_2_PI;
274  if (phiEC>M_PI) phiEC -= M_2_PI;
275 
276  std::pair<double,double> retVal(etaEC,phiEC);
277  return retVal;
278 }
279 
280 
std::pair< double, double > GetEtaPhiAtEcal(double etaIP, double phiIP, double pT, int charge, double vtxZ)
zEE_(-1)
int i
Definition: DBlmapReader.cc:9
float alpha
Definition: AMPTWrapper.h:95
const std::vector< edm::EDGetTokenT< reco::TrackCollection > > toks_pix_
tauAssocCone_(config.getParameter< double >("tauAssociationCone"))
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
const edm::EDGetTokenT< l1extra::L1JetParticleCollection > tok_l1_
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
#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
T mag() const
Definition: PV3DBase.h:67
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
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
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
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"))
const T & get() const
Definition: EventSetup.h:56
string const
Definition: compareJSON.py:14
const edm::EDGetTokenT< reco::VertexCollection > tok_vert_
bfield_(config.getParameter< std::string >("MagFieldRecordName"))
double getDistInCM(double eta1, double phi1, double eta2, double phi2)
tauUnbiasCone_(config.getParameter< double >("tauUnbiasCone"))
pixelIsolationConeSizeAtEC_(config.getParameter< double >("PixelIsolationConeSizeAtEC"))
virtual void produce(edm::Event &evt, const edm::EventSetup &es) override
maxPForIsolationValue_(config.getParameter< double >("maxPTrackForIsolation"))
ebEtaBoundary_(config.getParameter< double >("EBEtaBoundary"))
Definition: Run.h:43
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11