CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackerValidationVariables.cc
Go to the documentation of this file.
1 
11 
17 
20 
28 
30 
40 
42 
44 
45 #include "TMath.h"
46 
47 #include <string>
48 
50 {
51 
52 }
53 
56 {
57  trajCollectionToken_ = iC.consumes<std::vector<Trajectory> >(edm::InputTag(config.getParameter<std::string>("trajectoryInput")));
59 }
60 
62 {
63 
64 }
65 
66 void
67 TrackerValidationVariables::fillHitQuantities(const Trajectory* trajectory, std::vector<AVHitStruct> & v_avhitout)
68 {
69  TrajectoryStateCombiner tsoscomb;
70 
71  const std::vector<TrajectoryMeasurement> &tmColl = trajectory->measurements();
72  for(std::vector<TrajectoryMeasurement>::const_iterator itTraj = tmColl.begin();
73  itTraj != tmColl.end();
74  ++itTraj) {
75 
76  if (!itTraj->updatedState().isValid()) continue;
77 
78  TrajectoryStateOnSurface tsos = tsoscomb( itTraj->forwardPredictedState(), itTraj->backwardPredictedState() );
80 
81  if(!hit->isValid() || hit->geographicalId().det() != DetId::Tracker) continue;
82 
83  AVHitStruct hitStruct;
84  const DetId& hit_detId = hit->geographicalId();
85  unsigned int IntRawDetID = (hit_detId.rawId());
86  unsigned int IntSubDetID = (hit_detId.subdetId());
87 
88  if(IntSubDetID == 0) continue;
89 
90  //first calculate residuals in cartesian coordinates in the local module coordinate system
91 
92  LocalPoint lPHit = hit->localPosition();
93  LocalPoint lPTrk = tsos.localPosition();
94  LocalVector lVTrk = tsos.localDirection();
95 
96  hitStruct.localAlpha = atan2(lVTrk.x(), lVTrk.z()); // wrt. normal tg(alpha)=x/z
97  hitStruct.localBeta = atan2(lVTrk.y(), lVTrk.z()); // wrt. normal tg(beta)= y/z
98 
99  LocalError errHit = hit->localPositionError();
100  // no need to add APE to hitError anymore
101  // AlgebraicROOTObject<2>::SymMatrix mat = asSMatrix<2>(hit->parametersError());
102  // LocalError errHit = LocalError( mat(0,0),mat(0,1),mat(1,1) );
103  LocalError errTrk = tsos.localError().positionError();
104 
105  //check for negative error values: track error can have negative value, if matrix inversion fails (very rare case)
106  //hit error should always give positive values
107  if(errHit.xx()<0. || errHit.yy()<0. || errTrk.xx()<0. || errTrk.yy()<0.){
108  edm::LogError("TrackerValidationVariables") << "@SUB=TrackerValidationVariables::fillHitQuantities"
109  << "One of the squared error methods gives negative result"
110  << "\n\terrHit.xx()\terrHit.yy()\terrTrk.xx()\terrTrk.yy()"
111  << "\n\t" << errHit.xx()
112  << "\t" << errHit.yy()
113  << "\t" << errTrk.xx()
114  << "\t" << errTrk.yy();
115  continue;
116  }
117 
118  align::LocalVector res = lPTrk - lPHit;
119 
120  float resXErr = std::sqrt( errHit.xx() + errTrk.xx() );
121  float resYErr = std::sqrt( errHit.yy() + errTrk.yy() );
122 
123  hitStruct.resX = res.x();
124  hitStruct.resY = res.y();
125  hitStruct.resErrX = resXErr;
126  hitStruct.resErrY = resYErr;
127 
128  // hitStruct.localX = lPhit.x();
129  // hitStruct.localY = lPhit.y();
130  // EM: use predictions for local coordinates
131  hitStruct.localX = lPTrk.x();
132  hitStruct.localY = lPTrk.y();
133 
134  // now calculate residuals taking global orientation of modules and radial topology in TID/TEC into account
135  float resXprime(999.F), resYprime(999.F);
136  float resXatTrkY(999.F);
137  float resXprimeErr(999.F), resYprimeErr(999.F);
138 
139  if(hit->detUnit()){ // is it a single physical module?
140  const GeomDetUnit& detUnit = *(hit->detUnit());
141  float uOrientation(-999.F), vOrientation(-999.F);
142  float resXTopol(999.F), resYTopol(999.F);
143  float resXatTrkYTopol(999.F);
144 
145  const Surface& surface = hit->detUnit()->surface();
146  const BoundPlane& boundplane = hit->detUnit()->surface();
147  const Bounds& bound = boundplane.bounds();
148 
149  float length = 0;
150  float width = 0;
151 
152  LocalPoint lPModule(0.,0.,0.), lUDirection(1.,0.,0.), lVDirection(0.,1.,0.);
153  GlobalPoint gPModule = surface.toGlobal(lPModule),
154  gUDirection = surface.toGlobal(lUDirection),
155  gVDirection = surface.toGlobal(lVDirection);
156 
157  if (IntSubDetID == PixelSubdetector::PixelBarrel ||
158  IntSubDetID == StripSubdetector::TIB ||
159  IntSubDetID == StripSubdetector::TOB) {
160 
161  uOrientation = deltaPhi(gUDirection.phi(),gPModule.phi()) >= 0. ? +1.F : -1.F;
162  vOrientation = gVDirection.z() - gPModule.z() >= 0 ? +1.F : -1.F;
163  resXTopol = res.x();
164  resXatTrkYTopol = res.x();
165  resYTopol = res.y();
166  resXprimeErr = resXErr;
167  resYprimeErr = resYErr;
168 
169  const RectangularPlaneBounds *rectangularBound = dynamic_cast<const RectangularPlaneBounds*>(&bound);
170  if (rectangularBound!=NULL) {
171  hitStruct.inside = rectangularBound->inside(lPTrk);
172  length = rectangularBound->length();
173  width = rectangularBound->width();
174  hitStruct.localXnorm = 2*hitStruct.localX/width;
175  hitStruct.localYnorm = 2*hitStruct.localY/length;
176  } else {
177  throw cms::Exception("Geometry Error")
178  << "[TrackerValidationVariables] Cannot cast bounds to RectangularPlaneBounds as expected for TPB, TIB and TOB";
179  }
180 
181  } else if (IntSubDetID == PixelSubdetector::PixelEndcap) {
182 
183  uOrientation = gUDirection.perp() - gPModule.perp() >= 0 ? +1.F : -1.F;
184  vOrientation = deltaPhi(gVDirection.phi(),gPModule.phi()) >= 0. ? +1.F : -1.F;
185  resXTopol = res.x();
186  resXatTrkYTopol = res.x();
187  resYTopol = res.y();
188  resXprimeErr = resXErr;
189  resYprimeErr = resYErr;
190 
191  const RectangularPlaneBounds *rectangularBound = dynamic_cast<const RectangularPlaneBounds*>(&bound);
192  if (rectangularBound!=NULL) {
193  hitStruct.inside = rectangularBound->inside(lPTrk);
194  length = rectangularBound->length();
195  width = rectangularBound->width();
196  hitStruct.localXnorm = 2*hitStruct.localX/width;
197  hitStruct.localYnorm = 2*hitStruct.localY/length;
198  } else {
199  throw cms::Exception("Geometry Error")
200  << "[TrackerValidationVariables] Cannot cast bounds to RectangularPlaneBounds as expected for TPE";
201  }
202 
203  } else if (IntSubDetID == StripSubdetector::TID ||
204  IntSubDetID == StripSubdetector::TEC) {
205 
206  uOrientation = deltaPhi(gUDirection.phi(),gPModule.phi()) >= 0. ? +1.F : -1.F;
207  vOrientation = gVDirection.perp() - gPModule.perp() >= 0. ? +1.F : -1.F;
208 
209  if (!dynamic_cast<const RadialStripTopology*>(&detUnit.type().topology()))continue;
210  const RadialStripTopology& topol = dynamic_cast<const RadialStripTopology&>(detUnit.type().topology());
211 
212  MeasurementPoint measHitPos = topol.measurementPosition(lPHit);
213  MeasurementPoint measTrkPos = topol.measurementPosition(lPTrk);
214 
215  MeasurementError measHitErr = topol.measurementError(lPHit,errHit);
216  MeasurementError measTrkErr = topol.measurementError(lPTrk,errTrk);
217 
218  if (measHitErr.uu()<0. ||
219  measHitErr.vv()<0. ||
220  measTrkErr.uu()<0. ||
221  measTrkErr.vv()<0.){
222  edm::LogError("TrackerValidationVariables") << "@SUB=TrackerValidationVariables::fillHitQuantities"
223  << "One of the squared error methods gives negative result"
224  << "\n\tmeasHitErr.uu()\tmeasHitErr.vv()\tmeasTrkErr.uu()\tmeasTrkErr.vv()"
225  << "\n\t" << measHitErr.uu()
226  << "\t" << measHitErr.vv()
227  << "\t" << measTrkErr.uu()
228  << "\t" << measTrkErr.vv();
229  continue;
230  }
231 
232  float localStripLengthHit = topol.localStripLength(lPHit);
233  float localStripLengthTrk = topol.localStripLength(lPTrk);
234  float phiHit = topol.stripAngle(measHitPos.x());
235  float phiTrk = topol.stripAngle(measTrkPos.x());
236  float r_0 = topol.originToIntersection();
237 
238  resXTopol = (phiTrk-phiHit)*r_0;
239 // resXTopol = (tan(phiTrk)-tan(phiHit))*r_0;
240 
241  LocalPoint LocalHitPosCor= topol.localPosition(MeasurementPoint(measHitPos.x(), measTrkPos.y()));
242  resXatTrkYTopol = lPTrk.x() - LocalHitPosCor.x();
243 
244 
245  //resYTopol = measTrkPos.y()*localStripLengthTrk - measHitPos.y()*localStripLengthHit;
246  float cosPhiHit(cos(phiHit)), cosPhiTrk(cos(phiTrk)),
247  sinPhiHit(sin(phiHit)), sinPhiTrk(sin(phiTrk));
248  float l_0 = r_0 - topol.detHeight()/2;
249  resYTopol = measTrkPos.y()*localStripLengthTrk - measHitPos.y()*localStripLengthHit + l_0*(1/cosPhiTrk - 1/cosPhiHit);
250 
251  resXprimeErr = std::sqrt(measHitErr.uu()+measTrkErr.uu())*topol.angularWidth()*r_0;
252  //resYprimeErr = std::sqrt(measHitErr.vv()*localStripLengthHit*localStripLengthHit + measTrkErr.vv()*localStripLengthTrk*localStripLengthTrk);
253  float helpSummand = l_0*l_0*topol.angularWidth()*topol.angularWidth()*(sinPhiHit*sinPhiHit/pow(cosPhiHit,4)*measHitErr.uu()
254  + sinPhiTrk*sinPhiTrk/pow(cosPhiTrk,4)*measTrkErr.uu() );
255  resYprimeErr = std::sqrt(measHitErr.vv()*localStripLengthHit*localStripLengthHit
256  + measTrkErr.vv()*localStripLengthTrk*localStripLengthTrk + helpSummand );
257 
258 
259  const TrapezoidalPlaneBounds *trapezoidalBound = dynamic_cast < const TrapezoidalPlaneBounds * >(& bound);
260  if (trapezoidalBound!=NULL) {
261  hitStruct.inside = trapezoidalBound->inside(lPTrk);
262  length = trapezoidalBound->length();
263  width = trapezoidalBound->width();
264  //float widthAtHalfLength = trapezoidalBound->widthAtHalfLength();
265 
266  // int yAxisOrientation=trapezoidalBound->yAxisOrientation();
267  // for trapezoidal shape modules, scale with as function of local y coordinate
268  // float widthAtlocalY=width-(1-yAxisOrientation*2*lPTrk.y()/length)*(width-widthAtHalfLength);
269  // hitStruct.localXnorm = 2*hitStruct.localX/widthAtlocalY;
270  hitStruct.localXnorm = 2*hitStruct.localX/width;
271  hitStruct.localYnorm = 2*hitStruct.localY/length;
272  } else {
273  throw cms::Exception("Geometry Error")
274  << "[TrackerValidationVariables] Cannot cast bounds to TrapezoidalPlaneBounds as expected for TID and TEC";
275  }
276 
277  } else {
278  edm::LogWarning("TrackerValidationVariables") << "@SUB=TrackerValidationVariables::fillHitQuantities"
279  << "No valid tracker subdetector " << IntSubDetID;
280  continue;
281  }
282 
283  resXprime = resXTopol*uOrientation;
284  resXatTrkY = resXatTrkYTopol;
285  resYprime = resYTopol*vOrientation;
286 
287  } else { // not a detUnit, so must be a virtual 2D-Module
288  // FIXME: at present only for det units residuals are calculated and filled in the hitStruct
289  // But in principle this method should also be useable for the gluedDets (2D modules in TIB, TID, TOB, TEC)
290  // In this case, only orientation should be taken into account for primeResiduals, but not the radial topology
291  // At present, default values (999.F) are given out
292  }
293 
294  hitStruct.resXprime = resXprime;
295  hitStruct.resXatTrkY = resXatTrkY;
296  hitStruct.resYprime = resYprime;
297  hitStruct.resXprimeErr = resXprimeErr;
298  hitStruct.resYprimeErr = resYprimeErr;
299 
300  hitStruct.rawDetId = IntRawDetID;
301  hitStruct.phi = tsos.globalDirection().phi();
302  hitStruct.eta = tsos.globalDirection().eta();
303 
304  v_avhitout.push_back(hitStruct);
305  }
306 }
307 
308 void
310  const edm::EventSetup& eventSetup,
311  std::vector<AVTrackStruct> & v_avtrackout)
312 {
314  eventSetup.get<IdealMagneticFieldRecord>().get(magneticField);
315 
317  event.getByToken(trajTracksToken_, TrajTracksMap);
318  LogDebug("TrackerValidationVariables") << "TrajTrack collection size " << TrajTracksMap->size();
319 
320  const Trajectory* trajectory;
321  const reco::Track* track;
322 
323  for ( TrajTrackAssociationCollection::const_iterator iPair = TrajTracksMap->begin();
324  iPair != TrajTracksMap->end();
325  ++iPair) {
326 
327  trajectory = &(*(*iPair).key);
328  track = &(*(*iPair).val);
329 
330  AVTrackStruct trackStruct;
331 
332  trackStruct.p = track->p();
333  trackStruct.pt = track->pt();
334  trackStruct.ptError = track->ptError();
335  trackStruct.px = track->px();
336  trackStruct.py = track->py();
337  trackStruct.pz = track->pz();
338  trackStruct.eta = track->eta();
339  trackStruct.phi = track->phi();
340  trackStruct.chi2 = track->chi2();
341  trackStruct.chi2Prob= TMath::Prob(track->chi2(),track->ndof());
342  trackStruct.normchi2 = track->normalizedChi2();
343  GlobalPoint gPoint(track->vx(), track->vy(), track->vz());
344  double theLocalMagFieldInInverseGeV = magneticField->inInverseGeV(gPoint).z();
345  trackStruct.kappa = -track->charge()*theLocalMagFieldInInverseGeV/track->pt();
346  trackStruct.charge = track->charge();
347  trackStruct.d0 = track->d0();
348  trackStruct.dz = track->dz();
349  trackStruct.numberOfValidHits = track->numberOfValidHits();
350  trackStruct.numberOfLostHits = track->numberOfLostHits();
351 
352  fillHitQuantities(trajectory, trackStruct.hits);
353 
354  v_avtrackout.push_back(trackStruct);
355  }
356 }
357 
358 void
359 TrackerValidationVariables::fillHitQuantities(const edm::Event& event, std::vector<AVHitStruct> & v_avhitout)
360 {
361  edm::Handle<std::vector<Trajectory> > trajCollectionHandle;
362  event.getByToken(trajCollectionToken_, trajCollectionHandle);
363 
364  LogDebug("TrackerValidationVariables") << "trajColl->size(): " << trajCollectionHandle->size() ;
365 
366  for (std::vector<Trajectory>::const_iterator it = trajCollectionHandle->begin(), itEnd = trajCollectionHandle->end();
367  it!=itEnd;
368  ++it) {
369 
370  fillHitQuantities(&(*it), v_avhitout);
371  }
372 }
#define LogDebug(id)
double p() const
momentum vector magnitude
Definition: TrackBase.h:568
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:114
T getParameter(std::string const &) const
float xx() const
Definition: LocalError.h:24
float vv() const
T y() const
Definition: PV2DBase.h:46
T perp() const
Definition: PV3DBase.h:72
virtual float localStripLength(const LocalPoint &) const =0
double d0() const
dxy parameter in perigee convention (d0 = -dxy)
Definition: TrackBase.h:550
virtual const GeomDetType & type() const
Definition: GeomDet.cc:90
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
Definition: TrackBase.h:514
LocalVector localDirection() const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
T y() const
Definition: PV3DBase.h:63
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:598
unsigned short numberOfLostHits() const
number of cases where track crossed a layer without getting a hit.
Definition: TrackBase.h:779
#define NULL
Definition: scimark2.h:8
void fillHitQuantities(const Trajectory *trajectory, std::vector< AVHitStruct > &v_avhitout)
virtual LocalPoint localPosition(float strip) const =0
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:580
virtual float detHeight() const =0
LocalError positionError() const
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
virtual bool inside(const Local2DPoint &p) const
DataContainer const & measurements() const
Definition: Trajectory.h:203
Measurement2DPoint MeasurementPoint
Measurement points are two-dimensional by default.
virtual MeasurementError measurementError(const LocalPoint &, const LocalError &) const =0
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:604
float yy() const
Definition: LocalError.h:26
double chi2() const
chi-squared of the fit
Definition: TrackBase.h:502
edm::EDGetTokenT< std::vector< Trajectory > > trajCollectionToken_
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
double ndof() const
number of degrees of freedom of the fit
Definition: TrackBase.h:508
T sqrt(T t)
Definition: SSEVec.h:48
double pt() const
track transverse momentum
Definition: TrackBase.h:574
T z() const
Definition: PV3DBase.h:64
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:716
float uu() const
virtual MeasurementPoint measurementPosition(const LocalPoint &) const =0
virtual float angularWidth() const =0
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:773
const LocalTrajectoryError & localError() const
virtual float width() const
Width along local X.
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:592
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:562
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:622
virtual float stripAngle(float strip) const =0
Definition: DetId.h:18
void fillTrackQuantities(const edm::Event &, const edm::EventSetup &, std::vector< AVTrackStruct > &v_avtrackout)
edm::EDGetTokenT< TrajTrackAssociationCollection > trajTracksToken_
const T & get() const
Definition: EventSetup.h:55
virtual float originToIntersection() const =0
virtual const Topology & topology() const =0
T eta() const
Definition: PV3DBase.h:76
double vy() const
y coordinate of the reference point on track
Definition: TrackBase.h:616
virtual float length() const
Lenght along local Y.
int charge() const
track electric charge
Definition: TrackBase.h:520
Definition: Bounds.h:22
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
T x() const
Definition: PV2DBase.h:45
T x() const
Definition: PV3DBase.h:62
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:586
double vx() const
x coordinate of the reference point on track
Definition: TrackBase.h:610
GlobalVector globalDirection() const