1 |
#include "TrackingTools/PatternTools/interface/TempTrajectory.h"
|
2 |
#include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
|
3 |
#include "FWCore/Utilities/interface/Exception.h"
|
4 |
|
5 |
#include <ext/slist>
|
6 |
|
7 |
TempTrajectory::TempTrajectory( const Trajectory& traj):
|
8 |
theSeed( traj.sharedSeed() ),
|
9 |
theChiSquared(0),
|
10 |
theNumberOfFoundHits(0), theNumberOfLostHits(0),
|
11 |
theDirection(traj.direction()), theDirectionValidity(true),
|
12 |
theValid(traj.isValid()) {
|
13 |
|
14 |
Trajectory::DataContainer::const_iterator begin=traj.measurements().begin();
|
15 |
Trajectory::DataContainer::const_iterator end=traj.measurements().end();
|
16 |
|
17 |
for(Trajectory::DataContainer::const_iterator it=begin; it!=end; ++it){
|
18 |
push(*it);
|
19 |
}
|
20 |
|
21 |
}
|
22 |
|
23 |
TempTrajectory::~TempTrajectory() {}
|
24 |
|
25 |
void TempTrajectory::pop() {
|
26 |
if (!empty()) {
|
27 |
if (theData.back().recHit()->isValid()) theNumberOfFoundHits--;
|
28 |
else if(lost(* (theData.back().recHit()) )) theNumberOfLostHits--;
|
29 |
theData.pop_back();
|
30 |
}
|
31 |
}
|
32 |
|
33 |
void TempTrajectory::push( const TrajectoryMeasurement& tm) {
|
34 |
push( tm, tm.estimate());
|
35 |
}
|
36 |
|
37 |
#if defined( __GXX_EXPERIMENTAL_CXX0X__)
|
38 |
void TempTrajectory::push( TrajectoryMeasurement&& tm) {
|
39 |
push( std::forward<TrajectoryMeasurement>(tm), tm.estimate());
|
40 |
}
|
41 |
#endif
|
42 |
|
43 |
void TempTrajectory::push( const TrajectoryMeasurement& tm, double chi2Increment){
|
44 |
pushAux(tm,chi2Increment);
|
45 |
theData.push_back(tm);
|
46 |
}
|
47 |
|
48 |
#if defined( __GXX_EXPERIMENTAL_CXX0X__)
|
49 |
void TempTrajectory::push(TrajectoryMeasurement&& tm, double chi2Increment){
|
50 |
pushAux(tm,chi2Increment);
|
51 |
theData.push_back(std::move(tm));
|
52 |
}
|
53 |
#endif
|
54 |
|
55 |
void TempTrajectory::pushAux( const TrajectoryMeasurement& tm, double chi2Increment)
|
56 |
{
|
57 |
if ( tm.recHit()->isValid()) {
|
58 |
theNumberOfFoundHits++;
|
59 |
}
|
60 |
//else if (lost( tm.recHit()) && !inactive(tm.recHit().det())) theNumberOfLostHits++;
|
61 |
else if (lost( *(tm.recHit()) ) ) theNumberOfLostHits++;
|
62 |
|
63 |
|
64 |
theChiSquared += chi2Increment;
|
65 |
|
66 |
// in case of a Trajectory constructed without direction,
|
67 |
// determine direction from the radii of the first two measurements
|
68 |
|
69 |
if ( !theDirectionValidity && theData.size() >= 2) {
|
70 |
if (theData.front().updatedState().globalPosition().perp() <
|
71 |
theData.back().updatedState().globalPosition().perp())
|
72 |
theDirection = alongMomentum;
|
73 |
else theDirection = oppositeToMomentum;
|
74 |
theDirectionValidity = true;
|
75 |
}
|
76 |
}
|
77 |
|
78 |
void TempTrajectory::push( const TempTrajectory& segment) {
|
79 |
assert (segment.direction() == theDirection) ;
|
80 |
__gnu_cxx::slist<const TrajectoryMeasurement*> list;
|
81 |
for (DataContainer::const_iterator it = segment.measurements().rbegin(), ed = segment.measurements().rend(); it != ed; --it) {
|
82 |
list.push_front(&(*it));
|
83 |
}
|
84 |
for(__gnu_cxx::slist<const TrajectoryMeasurement*>::const_iterator it = list.begin(), ed = list.end(); it != ed; ++it) {
|
85 |
push(**it);
|
86 |
}
|
87 |
}
|
88 |
|
89 |
void TempTrajectory::join( TempTrajectory& segment) {
|
90 |
assert (segment.direction() == theDirection) ;
|
91 |
if (segment.theData.shared()) {
|
92 |
push(segment);
|
93 |
segment.theData.clear(); // obey the contract, and increase the chances it will be not shared one day
|
94 |
} else {
|
95 |
for (DataContainer::const_iterator it = segment.measurements().rbegin(), ed = segment.measurements().rend(); it != ed; --it) {
|
96 |
if ( it->recHit()->isValid()) theNumberOfFoundHits++;
|
97 |
else if (lost( *(it->recHit()) ) ) theNumberOfLostHits++;
|
98 |
theChiSquared += it->estimate();
|
99 |
}
|
100 |
theData.join(segment.theData);
|
101 |
|
102 |
if ( !theDirectionValidity && theData.size() >= 2) {
|
103 |
if (theData.front().updatedState().globalPosition().perp() <
|
104 |
theData.back().updatedState().globalPosition().perp())
|
105 |
theDirection = alongMomentum;
|
106 |
else theDirection = oppositeToMomentum;
|
107 |
theDirectionValidity = true;
|
108 |
}
|
109 |
}
|
110 |
}
|
111 |
|
112 |
|
113 |
/*
|
114 |
Trajectory::RecHitContainer Trajectory::recHits() const {
|
115 |
RecHitContainer hits;
|
116 |
hits.reserve(theData.size());
|
117 |
|
118 |
for (Trajectory::DataContainer::const_iterator itm
|
119 |
= theData.begin(); itm != theData.end(); itm++) {
|
120 |
hits.push_back((*itm).recHit());
|
121 |
}
|
122 |
return hits;
|
123 |
}
|
124 |
|
125 |
*/
|
126 |
|
127 |
PropagationDirection TempTrajectory::direction() const {
|
128 |
if (theDirectionValidity) return theDirection;
|
129 |
else throw cms::Exception("TrackingTools/PatternTools","Trajectory::direction() requested but not set");
|
130 |
}
|
131 |
|
132 |
void TempTrajectory::check() const {
|
133 |
if ( theData.size() == 0)
|
134 |
throw cms::Exception("TrackingTools/PatternTools","Trajectory::check() - information requested from empty Trajectory");
|
135 |
}
|
136 |
|
137 |
bool TempTrajectory::lost( const TransientTrackingRecHit& hit)
|
138 |
{
|
139 |
if ( hit.isValid()) return false;
|
140 |
else {
|
141 |
// // A DetLayer is always inactive in this logic.
|
142 |
// // The DetLayer is the Det of an invalid RecHit only if no DetUnit
|
143 |
// // is compatible with the predicted state, so we don't really expect
|
144 |
// // a hit in this case.
|
145 |
|
146 |
if(hit.geographicalId().rawId() == 0) {return false;}
|
147 |
else{
|
148 |
return hit.getType() == TrackingRecHit::missing;
|
149 |
}
|
150 |
}
|
151 |
}
|
152 |
|
153 |
Trajectory TempTrajectory::toTrajectory() const {
|
154 |
Trajectory traj(theSeed, theDirection);
|
155 |
|
156 |
traj.reserve(theData.size());
|
157 |
static std::vector<const TrajectoryMeasurement*> work;
|
158 |
work.resize(theData.size(), 0);
|
159 |
std::vector<const TrajectoryMeasurement*>::iterator workend = work.end(), itwork = workend;
|
160 |
for (TempTrajectory::DataContainer::const_iterator it = theData.rbegin(), ed = theData.rend(); it != ed; --it) {
|
161 |
--itwork; *itwork = (&(*it));
|
162 |
}
|
163 |
for (; itwork != workend; ++itwork) {
|
164 |
traj.push(**itwork);
|
165 |
}
|
166 |
return traj;
|
167 |
}
|
168 |
|