Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "TrackingTools/TransientTrack/interface/CandidatePtrTransientTrack.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 CandidatePtrTransientTrack::CandidatePtrTransientTrack()
0024     : Track(),
0025       ptr_(),
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 CandidatePtrTransientTrack::CandidatePtrTransientTrack(const CandidatePtr& ptr, const MagneticField* field)
0035     : Track(*ptr->bestTrack()),
0036       ptr_(ptr),
0037       hasTime(false),
0038       timeExt_(0),
0039       dtErrorExt_(0),
0040       theField(field),
0041       m_TSOS(kUnset),
0042       m_TSCP(kUnset),
0043       m_SCTBL(kUnset) {
0044   initialFTS = trajectoryStateTransform::initialFreeState(*ptr->bestTrack(), field);
0045 }
0046 
0047 CandidatePtrTransientTrack::CandidatePtrTransientTrack(const CandidatePtr& ptr,
0048                                                        const double time,
0049                                                        const double dtime,
0050                                                        const MagneticField* field)
0051     : Track(*ptr->bestTrack()),
0052       ptr_(ptr),
0053       hasTime(true),
0054       timeExt_(time),
0055       dtErrorExt_(dtime),
0056       theField(field),
0057       m_TSOS(kUnset),
0058       m_TSCP(kUnset),
0059       m_SCTBL(kUnset) {
0060   initialFTS = trajectoryStateTransform::initialFreeState(*ptr->bestTrack(), field);
0061 }
0062 
0063 CandidatePtrTransientTrack::CandidatePtrTransientTrack(const CandidatePtr& ptr,
0064                                                        const MagneticField* field,
0065                                                        const edm::ESHandle<GlobalTrackingGeometry>& tg)
0066     : Track(*ptr->bestTrack()),
0067       ptr_(ptr),
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       theTrackingGeometry(tg) {
0076   initialFTS = trajectoryStateTransform::initialFreeState(*ptr->bestTrack(), field);
0077 }
0078 
0079 CandidatePtrTransientTrack::CandidatePtrTransientTrack(const CandidatePtr& ptr,
0080                                                        const double time,
0081                                                        const double dtime,
0082                                                        const MagneticField* field,
0083                                                        const edm::ESHandle<GlobalTrackingGeometry>& tg)
0084     : Track(*ptr->bestTrack()),
0085       ptr_(ptr),
0086       hasTime(true),
0087       timeExt_(time),
0088       dtErrorExt_(dtime),
0089       theField(field),
0090       m_TSOS(kUnset),
0091       m_TSCP(kUnset),
0092       m_SCTBL(kUnset),
0093       theTrackingGeometry(tg) {
0094   initialFTS = trajectoryStateTransform::initialFreeState(*ptr->bestTrack(), field);
0095 }
0096 
0097 CandidatePtrTransientTrack::CandidatePtrTransientTrack(const CandidatePtrTransientTrack& tt)
0098     : Track(tt),
0099       ptr_(tt.candidate()),
0100       hasTime(tt.hasTime),
0101       timeExt_(tt.timeExt_),
0102       dtErrorExt_(tt.dtErrorExt_),
0103       theField(tt.field()),
0104       initialFTS(tt.initialFreeState()),
0105       m_TSOS(kUnset),
0106       m_TSCP(kUnset) {
0107   // see ThreadSafe statement above about the order of operator= and store
0108   if (kSet == tt.m_TSOS.load()) {
0109     initialTSOS = tt.impactPointState();
0110     m_TSOS.store(kSet);
0111   }
0112   // see ThreadSafe statement above about the order of operator= and store
0113   if (kSet == tt.m_TSCP.load()) {
0114     initialTSCP = tt.impactPointTSCP();
0115     m_TSCP.store(kSet);
0116   }
0117 }
0118 
0119 void CandidatePtrTransientTrack::setTrackingGeometry(const edm::ESHandle<GlobalTrackingGeometry>& tg) {
0120   theTrackingGeometry = tg;
0121 }
0122 
0123 void CandidatePtrTransientTrack::setBeamSpot(const BeamSpot& beamSpot) {
0124   theBeamSpot = beamSpot;
0125   m_SCTBL = kUnset;
0126 }
0127 
0128 TrajectoryStateOnSurface CandidatePtrTransientTrack::impactPointState() const {
0129   // see ThreadSafe statement above about the order of operator= and store
0130   if (kSet == m_TSOS.load())
0131     return initialTSOS;
0132   TransverseImpactPointExtrapolator tipe(theField);
0133   auto tmp = tipe.extrapolate(initialFTS, initialFTS.position());
0134   char expected = kUnset;
0135   if (m_TSOS.compare_exchange_strong(expected, kSetting)) {
0136     initialTSOS = tmp;
0137     m_TSOS.store(kSet);
0138     return initialTSOS;
0139   }
0140   return tmp;
0141 }
0142 
0143 TrajectoryStateClosestToPoint CandidatePtrTransientTrack::impactPointTSCP() const {
0144   // see ThreadSafe statement above about the order of operator= and store
0145   if (kSet == m_TSCP.load())
0146     return initialTSCP;
0147   auto tmp = builder(initialFTS, initialFTS.position());
0148   char expected = kUnset;
0149   if (m_TSCP.compare_exchange_strong(expected, kSetting)) {
0150     initialTSCP = tmp;
0151     m_TSCP.store(kSet);
0152     return initialTSCP;
0153   }
0154   return tmp;
0155 }
0156 
0157 TrajectoryStateOnSurface CandidatePtrTransientTrack::outermostMeasurementState() const {
0158   return trajectoryStateTransform::outerStateOnSurface((*this), *theTrackingGeometry, theField);
0159 }
0160 
0161 TrajectoryStateOnSurface CandidatePtrTransientTrack::innermostMeasurementState() const {
0162   return trajectoryStateTransform::innerStateOnSurface((*this), *theTrackingGeometry, theField);
0163 }
0164 
0165 TrajectoryStateOnSurface CandidatePtrTransientTrack::stateOnSurface(const GlobalPoint& point) const {
0166   TransverseImpactPointExtrapolator tipe(theField);
0167   return tipe.extrapolate(initialFTS, point);
0168 }
0169 
0170 TrajectoryStateClosestToBeamLine CandidatePtrTransientTrack::stateAtBeamLine() const {
0171   // see ThreadSafe statement above about the order of operator= and store
0172   if (kSet == m_SCTBL.load())
0173     return trajectoryStateClosestToBeamLine;
0174   TSCBLBuilderNoMaterial blsBuilder;
0175   const auto tmp = blsBuilder(initialFTS, theBeamSpot);
0176   char expected = kUnset;
0177   if (m_SCTBL.compare_exchange_strong(expected, kSetting)) {
0178     trajectoryStateClosestToBeamLine = tmp;
0179     m_SCTBL.store(kSet);
0180     return trajectoryStateClosestToBeamLine;
0181   }
0182   return tmp;
0183 }