CMS 3D CMS Logo

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 
91  auto trackCollection = std::make_unique<reco::IsolatedPixelTrackCandidateCollection>();
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 
112  double drMaxL1Track_ = tauAssocCone_;
113 
114  int ntr = 0;
115  std::vector<seedAtEC> VecSeedsatEC;
116  //loop to select isolated tracks
117  for (unsigned iS=0; iS<pixelTrackRefs.size(); iS++) {
118  bool vtxMatch = false;
119  //associate to vertex (in Z)
120  reco::VertexCollection::const_iterator vitSel;
121  double minDZ = 1000;
122  bool found(false);
123  for (reco::VertexCollection::const_iterator vit=pVert->begin(); vit!=pVert->end(); vit++) {
124  if (std::abs(pixelTrackRefs[iS]->dz(vit->position()))<minDZ) {
125  minDZ = std::abs(pixelTrackRefs[iS]->dz(vit->position()));
126  vitSel = vit;
127  found = true;
128  }
129  }
130  //cut on dYX:
131  if (found) {
132  if(std::abs(pixelTrackRefs[iS]->dxy(vitSel->position()))<vtxCutSeed_) vtxMatch=true;
133  } else {
134  vtxMatch=true;
135  }
136 
137  //check taujet matching
138  bool tmatch=false;
139  l1extra::L1JetParticleCollection::const_iterator selj;
140  for (l1extra::L1JetParticleCollection::const_iterator tj=l1eTauJets->begin(); tj!=l1eTauJets->end(); tj++) {
141  if (reco::deltaR(pixelTrackRefs[iS]->momentum().eta(), pixelTrackRefs[iS]->momentum().phi(), tj->momentum().eta(), tj->momentum().phi()) > drMaxL1Track_) continue;
142  selj = tj;
143  tmatch = true;
144  } //loop over L1 tau
145 
146  //propagate seed track to ECAL surface:
147  std::pair<double,double> seedCooAtEC;
148  // in case vertex is found:
149  if (found) seedCooAtEC=GetEtaPhiAtEcal(pixelTrackRefs[iS]->eta(), pixelTrackRefs[iS]->phi(), pixelTrackRefs[iS]->pt(), pixelTrackRefs[iS]->charge(), vitSel->z());
150  //in case vertex is not found:
151  else seedCooAtEC=GetEtaPhiAtEcal(pixelTrackRefs[iS]->eta(), pixelTrackRefs[iS]->phi(), pixelTrackRefs[iS]->pt(), pixelTrackRefs[iS]->charge(), 0);
152  seedAtEC seed(iS,(tmatch||vtxMatch),seedCooAtEC.first,seedCooAtEC.second);
153  VecSeedsatEC.push_back(seed);
154  }
155 #ifdef DebugLog
156  edm::LogInfo("HcalIsoTrack") << "IsolatedPixelTrakCandidate: " << VecSeedsatEC.size() << " seeds after propagation\n";
157 #endif
158 
159  for (unsigned int i=0; i<VecSeedsatEC.size(); i++) {
160  unsigned int iSeed = VecSeedsatEC[i].index;
161  if (!VecSeedsatEC[i].ok) continue;
162  if(pixelTrackRefs[iSeed]->p()<minPTrackValue_) continue;
163  l1extra::L1JetParticleCollection::const_iterator selj;
164  for (l1extra::L1JetParticleCollection::const_iterator tj=l1eTauJets->begin(); tj!=l1eTauJets->end(); tj++) {
165  if (reco::deltaR(pixelTrackRefs[iSeed]->momentum().eta(),pixelTrackRefs[iSeed]->momentum().phi(),tj->momentum().eta(),tj->momentum().phi()) > drMaxL1Track_) continue;
166  selj = tj;
167  } //loop over L1 tau
168  double maxP = 0;
169  double sumP = 0;
170  for(unsigned int j=0; j<VecSeedsatEC.size(); j++) {
171  if (i==j) continue;
172  unsigned int iSurr = VecSeedsatEC[j].index;
173  //define preliminary cone around seed track impact point from which tracks will be extrapolated:
174  if (reco::deltaR(pixelTrackRefs[iSeed]->eta(), pixelTrackRefs[iSeed]->phi(), pixelTrackRefs[iSurr]->eta(), pixelTrackRefs[iSurr]->phi())>prelimCone_) continue;
175  double minDZ2(1000);
176  bool found(false);
177  reco::VertexCollection::const_iterator vitSel2;
178  for (reco::VertexCollection::const_iterator vit=pVert->begin(); vit!=pVert->end(); vit++) {
179  if (std::abs(pixelTrackRefs[iSurr]->dz(vit->position()))<minDZ2) {
180  minDZ2 = std::abs(pixelTrackRefs[iSurr]->dz(vit->position()));
181  vitSel2 = vit;
182  found = true;
183  }
184  }
185  //cut ot dXY:
186  if (found&&std::abs(pixelTrackRefs[iSurr]->dxy(vitSel2->position()))>vtxCutIsol_) continue;
187  //calculate distance at ECAL surface and update isolation:
188  if (getDistInCM(VecSeedsatEC[i].eta, VecSeedsatEC[i].phi, VecSeedsatEC[j].eta, VecSeedsatEC[j].phi)<pixelIsolationConeSizeAtEC_) {
189  sumP+=pixelTrackRefs[iSurr]->p();
190  if(pixelTrackRefs[iSurr]->p()>maxP) maxP=pixelTrackRefs[iSurr]->p();
191  }
192  }
193  if (maxP<maxPForIsolationValue_) {
194  reco::IsolatedPixelTrackCandidate newCandidate(pixelTrackRefs[iSeed], l1extra::L1JetParticleRef(l1eTauJets,selj-l1eTauJets->begin()), maxP, sumP);
195  newCandidate.setEtaPhiEcal(VecSeedsatEC[i].eta, VecSeedsatEC[i].phi);
196  trackCollection->push_back(newCandidate);
197  ntr++;
198  }
199  }
200  // put the product in the event
201  theEvent.put(std::move(trackCollection));
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)
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:44
float alpha
Definition: AMPTWrapper.h:95
const std::vector< edm::EDGetTokenT< reco::TrackCollection > > toks_pix_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
void beginRun(const edm::Run &, const edm::EventSetup &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
GlobalVector inTesla(const GlobalPoint &g) const override
Field value ad specified global point, in Tesla.
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
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
T mag() const
Definition: PV3DBase.h:67
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
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
#define M_PI
const T & get() const
Definition: EventSetup.h:59
const edm::EDGetTokenT< reco::VertexCollection > tok_vert_
fixed size matrix
HLT enums.
double getDistInCM(double eta1, double phi1, double eta2, double phi2)
void produce(edm::Event &evt, const edm::EventSetup &es) override
def move(src, dest)
Definition: eostools.py:510
Definition: Run.h:43
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11