Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-28 03:10:24

0001 #include "TrackingTools/TransientTrack/interface/TrackTransientTrack.h"
0002 #include "TrackingTools/PatternTools/interface/TransverseImpactPointExtrapolator.h"
0003 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
0004 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
0005 #include "TrackingTools/PatternTools/interface/TSCBLBuilderNoMaterial.h"
0006 #include <iostream>
0007 
0008 /*
0009  * ThreadSafe statement:
0010  * This class is using mutable member data: initialTSOS, initialTSCP,
0011  * trajectoryStateClosestToBeamLine. To guarantee thread safeness we
0012  * rely on helper member data: m_TSOS, m_TSCP and m_SCTBL, respectively.
0013  * Each time we'll change mutable member data we rely on specific order of the
0014  * operator= and the store. It is important since C++11 will guarantee that
0015  * the value changed by the operator= will be seen by all threads as occuring
0016  * before the call to store and therefore the kSet == m_TSOS.load is always
0017  * guaranteed to be true if and only if the thread will see the most recent
0018  * value of initialTSOS
0019  */
0020 
0021 using namespace reco;
0022 
0023 TrackTransientTrack::TrackTransientTrack()
0024     : Track(),
0025       tkr_(),
0026       hasTime(false),
0027       timeExt_(0.),
0028       dtErrorExt_(0.),
0029       theField(nullptr),
0030       m_TSOS(kUnset),
0031       m_TSCP(kUnset),
0032       m_SCTBL(kUnset)
0033 
0034 {}
0035 
0036 TrackTransientTrack::TrackTransientTrack(const Track& tk, const MagneticField* field)
0037     : Track(tk),
0038       tkr_(),
0039       hasTime(false),
0040       timeExt_(0.),
0041       dtErrorExt_(0.),
0042       theField(field),
0043       m_TSOS(kUnset),
0044       m_TSCP(kUnset),
0045       m_SCTBL(kUnset) {
0046   initialFTS = trajectoryStateTransform::initialFreeState(tk, field);
0047 }
0048 
0049 TrackTransientTrack::TrackTransientTrack(const Track& tk,
0050                                          const double time,
0051                                          const double dtime,
0052                                          const MagneticField* field)
0053     : Track(tk),
0054       tkr_(),
0055       hasTime(true),
0056       timeExt_(time),
0057       dtErrorExt_(dtime),
0058       theField(field),
0059       m_TSOS(kUnset),
0060       m_TSCP(kUnset),
0061       m_SCTBL(kUnset) {
0062   initialFTS = trajectoryStateTransform::initialFreeState(tk, field);
0063 }
0064 
0065 TrackTransientTrack::TrackTransientTrack(const TrackRef& tk, const MagneticField* field)
0066     : Track(*tk),
0067       tkr_(tk),
0068       hasTime(false),
0069       timeExt_(0.),
0070       dtErrorExt_(0.),
0071       theField(field),
0072       m_TSOS(kUnset),
0073       m_TSCP(kUnset),
0074       m_SCTBL(kUnset) {
0075   initialFTS = trajectoryStateTransform::initialFreeState(*tk, field);
0076 }
0077 
0078 TrackTransientTrack::TrackTransientTrack(const TrackRef& tk,
0079                                          const double time,
0080                                          const double dtime,
0081                                          const MagneticField* field)
0082     : Track(*tk),
0083       tkr_(tk),
0084       hasTime(true),
0085       timeExt_(time),
0086       dtErrorExt_(dtime),
0087       theField(field),
0088       m_TSOS(kUnset),
0089       m_TSCP(kUnset),
0090       m_SCTBL(kUnset) {
0091   initialFTS = trajectoryStateTransform::initialFreeState(*tk, field);
0092 }
0093 
0094 TrackTransientTrack::TrackTransientTrack(const Track& tk,
0095                                          const MagneticField* field,
0096                                          const edm::ESHandle<GlobalTrackingGeometry>& tg)
0097     : Track(tk),
0098       tkr_(),
0099       hasTime(false),
0100       timeExt_(0.),
0101       dtErrorExt_(0.),
0102       theField(field),
0103       m_TSOS(kUnset),
0104       m_TSCP(kUnset),
0105       m_SCTBL(kUnset),
0106       theTrackingGeometry(tg) {
0107   initialFTS = trajectoryStateTransform::initialFreeState(tk, field);
0108 }
0109 
0110 TrackTransientTrack::TrackTransientTrack(const TrackRef& tk,
0111                                          const MagneticField* field,
0112                                          const edm::ESHandle<GlobalTrackingGeometry>& tg)
0113     : Track(*tk),
0114       tkr_(tk),
0115       hasTime(false),
0116       timeExt_(0.),
0117       dtErrorExt_(0.),
0118       theField(field),
0119       m_TSOS(kUnset),
0120       m_TSCP(kUnset),
0121       m_SCTBL(kUnset),
0122       theTrackingGeometry(tg) {
0123   initialFTS = trajectoryStateTransform::initialFreeState(*tk, field);
0124 }
0125 
0126 TrackTransientTrack::TrackTransientTrack(const Track& tk,
0127                                          const double time,
0128                                          const double dtime,
0129                                          const MagneticField* field,
0130                                          const edm::ESHandle<GlobalTrackingGeometry>& tg)
0131     : Track(tk),
0132       tkr_(),
0133       hasTime(true),
0134       timeExt_(time),
0135       dtErrorExt_(dtime),
0136       theField(field),
0137       m_TSOS(kUnset),
0138       m_TSCP(kUnset),
0139       m_SCTBL(kUnset),
0140       theTrackingGeometry(tg) {
0141   initialFTS = trajectoryStateTransform::initialFreeState(tk, field);
0142 }
0143 
0144 TrackTransientTrack::TrackTransientTrack(const TrackRef& tk,
0145                                          const double time,
0146                                          const double dtime,
0147                                          const MagneticField* field,
0148                                          const edm::ESHandle<GlobalTrackingGeometry>& tg)
0149     : Track(*tk),
0150       tkr_(tk),
0151       hasTime(true),
0152       timeExt_(time),
0153       dtErrorExt_(dtime),
0154       theField(field),
0155       m_TSOS(kUnset),
0156       m_TSCP(kUnset),
0157       m_SCTBL(kUnset),
0158       theTrackingGeometry(tg) {
0159   initialFTS = trajectoryStateTransform::initialFreeState(*tk, field);
0160 }
0161 
0162 TrackTransientTrack::TrackTransientTrack(const TrackTransientTrack& tt)
0163     : Track(tt),
0164       tkr_(tt.persistentTrackRef()),
0165       hasTime(tt.hasTime),
0166       timeExt_(tt.timeExt()),
0167       dtErrorExt_(tt.dtErrorExt()),
0168       theField(tt.field()),
0169       initialFTS(tt.initialFreeState()),
0170       m_TSOS(kUnset),
0171       m_TSCP(kUnset) {
0172   // see ThreadSafe statement above about the order of operator= and store
0173   if (kSet == tt.m_TSOS.load()) {
0174     initialTSOS = tt.impactPointState();
0175     m_TSOS.store(kSet);
0176   }
0177   // see ThreadSafe statement above about the order of operator= and store
0178   if (kSet == tt.m_TSCP.load()) {
0179     initialTSCP = tt.impactPointTSCP();
0180     m_TSCP.store(kSet);
0181   }
0182 }
0183 
0184 void TrackTransientTrack::setTrackingGeometry(const edm::ESHandle<GlobalTrackingGeometry>& tg) {
0185   theTrackingGeometry = tg;
0186 }
0187 
0188 void TrackTransientTrack::setBeamSpot(const BeamSpot& beamSpot) {
0189   theBeamSpot = beamSpot;
0190   m_SCTBL = kUnset;
0191 }
0192 
0193 TrajectoryStateOnSurface TrackTransientTrack::impactPointState() const {
0194   // see ThreadSafe statement above about the order of operator= and store
0195   if (kSet == m_TSOS.load())
0196     return initialTSOS;
0197   TransverseImpactPointExtrapolator tipe(theField);
0198   auto tmp = tipe.extrapolate(initialFTS, initialFTS.position());
0199   char expected = kUnset;
0200   if (m_TSOS.compare_exchange_strong(expected, kSetting)) {
0201     initialTSOS = tmp;
0202     m_TSOS.store(kSet);
0203     return initialTSOS;
0204   }
0205   return tmp;
0206 }
0207 
0208 TrajectoryStateClosestToPoint TrackTransientTrack::impactPointTSCP() const {
0209   // see ThreadSafe statement above about the order of operator= and store
0210   if (kSet == m_TSCP.load())
0211     return initialTSCP;
0212   auto tmp = builder(initialFTS, initialFTS.position());
0213   char expected = kUnset;
0214   if (m_TSCP.compare_exchange_strong(expected, kSetting)) {
0215     initialTSCP = tmp;
0216     m_TSCP.store(kSet);
0217     return initialTSCP;
0218   }
0219   return tmp;
0220 }
0221 
0222 TrajectoryStateOnSurface TrackTransientTrack::outermostMeasurementState() const {
0223   return trajectoryStateTransform::outerStateOnSurface((*this), *theTrackingGeometry, theField);
0224 }
0225 
0226 TrajectoryStateOnSurface TrackTransientTrack::innermostMeasurementState() const {
0227   return trajectoryStateTransform::innerStateOnSurface((*this), *theTrackingGeometry, theField);
0228 }
0229 
0230 TrajectoryStateOnSurface TrackTransientTrack::stateOnSurface(const GlobalPoint& point) const {
0231   TransverseImpactPointExtrapolator tipe(theField);
0232   return tipe.extrapolate(initialFTS, point);
0233 }
0234 
0235 TrajectoryStateClosestToBeamLine TrackTransientTrack::stateAtBeamLine() const {
0236   // see ThreadSafe statement above about the order of operator= and store
0237   if (kSet == m_SCTBL.load())
0238     return trajectoryStateClosestToBeamLine;
0239   TSCBLBuilderNoMaterial blsBuilder;
0240   const auto tmp = blsBuilder(initialFTS, theBeamSpot);
0241   char expected = kUnset;
0242   if (m_SCTBL.compare_exchange_strong(expected, kSetting)) {
0243     trajectoryStateClosestToBeamLine = tmp;
0244     m_SCTBL.store(kSet);
0245     return trajectoryStateClosestToBeamLine;
0246   }
0247   return tmp;
0248 }