CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Trajectory.cc
Go to the documentation of this file.
2 #include "boost/intrusive_ptr.hpp"
6 
7 
8 #include <algorithm>
9 
10 using namespace std;
11 
13  if (!empty()) {
14  if(theData.back().recHit()->isValid()) {
15  theNumberOfFoundHits--;
16  theChiSquared -= theData.back().estimate();
17  }
18  else if(lost(* (theData.back().recHit()) )) {
19  theNumberOfLostHits--;
20  }
21  else if(isBad(* (theData.back().recHit()) ) && theData.back().recHit()->geographicalId().det()==DetId::Muon ) {
22  theChiSquaredBad -= theData.back().estimate();
23  }
24 
25  theData.pop_back();
26  }
27 }
28 
29 
31  push( tm, tm.estimate());
32 }
33 
34 
36  push( tm, tm.estimate());
37 }
38 
39 
40 
41 void Trajectory::push(const TrajectoryMeasurement & tm, double chi2Increment) {
42  theData.push_back(tm); pushAux(chi2Increment);
43 }
44 
45 void Trajectory::push(TrajectoryMeasurement && tm, double chi2Increment) {
46  theData.push_back(tm); pushAux(chi2Increment);
47 }
48 
49 
50 void Trajectory::pushAux(double chi2Increment) {
51  const TrajectoryMeasurement& tm = theData.back();
52  if ( tm.recHit()->isValid()) {
53  theChiSquared += chi2Increment;
54  theNumberOfFoundHits++;
55  }
56  // else if (lost( tm.recHit()) && !inactive(tm.recHit().det())) theNumberOfLostHits++;
57  else if (lost( *(tm.recHit()) ) ) {
58  theNumberOfLostHits++;
59  }
60 
61  else if (isBad( *(tm.recHit()) ) && tm.recHit()->geographicalId().det()==DetId::Muon ) {
62  theChiSquaredBad += chi2Increment;
63  }
64 
65  // in case of a Trajectory constructed without direction,
66  // determine direction from the radii of the first two measurements
67 
68  if ( !theDirectionValidity && theData.size() >= 2) {
69  if (theData[0].updatedState().globalPosition().perp2() <
70  theData.back().updatedState().globalPosition().perp2())
71  theDirection = alongMomentum;
72  else theDirection = oppositeToMomentum;
73  theDirectionValidity = true;
74  }
75 }
76 
77 
78 int Trajectory::ndof(bool bon) const {
79  Trajectory::RecHitContainer && transRecHits = recHits();
80 
81  int dof = 0;
82  int dofBad = 0;
83 
84  for(Trajectory::RecHitContainer::const_iterator rechit = transRecHits.begin();
85  rechit != transRecHits.end(); ++rechit) {
86  if((*rechit)->isValid())
87  dof += (*rechit)->dimension();
88  else if( isBad(**rechit) && (*rechit)->geographicalId().det()==DetId::Muon )
89  dofBad += (*rechit)->dimension();
90  }
91 
92  // If dof!=0 (there is at least 1 valid hit),
93  // return ndof=ndof(fit)
94  // If dof=0 (all rec hits are invalid, only for STA trajectories),
95  // return ndof=ndof(invalid hits)
96  if(dof) {
97  int constr = bon ? 5 : 4;
98  return std::max(dof - constr, 0);
99  }
100  else {
101  // A STA can have < 5 (invalid) hits
102  // if this is the case ==> ndof = 1
103  // (to avoid divisions by 0)
104  int constr = bon ? 5 : 4;
105  return std::max(dofBad - constr, 1);
106  }
107 }
108 
109 
110 void Trajectory::validRecHits(ConstRecHitContainer & hits) const {
111  hits.reserve(foundHits());
112  for (Trajectory::DataContainer::const_iterator itm
113  = theData.begin(); itm != theData.end(); itm++)
114  if ((*itm).recHit()->isValid()) hits.push_back((*itm).recHit());
115 }
116 
117 
119  if (theDirectionValidity) return theDirection;
120  else throw cms::Exception("TrackingTools/PatternTools","Trajectory::direction() requested but not set");
121 }
122 
123 void Trajectory::check() const {
124  if ( theData.empty())
125  throw cms::Exception("TrackingTools/PatternTools","Trajectory::check() - information requested from empty Trajectory");
126 }
127 
129 {
130  if ( hit.isValid()) return false;
131  else {
132  // // A DetLayer is always inactive in this logic.
133  // // The DetLayer is the Det of an invalid RecHit only if no DetUnit
134  // // is compatible with the predicted state, so we don't really expect
135  // // a hit in this case.
136 
137  if(hit.geographicalId().rawId() == 0) {return false;}
138  else{
139  return hit.getType() == TrackingRecHit::missing;
140  }
141  }
142 }
143 
145 {
146  if ( hit.isValid()) return false;
147  else {
148  if(hit.geographicalId().rawId() == 0) {return false;}
149  else{
150  return hit.getType() == TrackingRecHit::bad;
151  }
152  }
153 }
154 
156 
157  check();
158 
159  //if trajectory is in one half, return the end closer to origin point
160  if ( firstMeasurement().updatedState().globalMomentum().perp() > 1.0
161  && ( firstMeasurement().updatedState().globalPosition().basicVector().dot( firstMeasurement().updatedState().globalMomentum().basicVector() ) *
162  lastMeasurement().updatedState().globalPosition().basicVector().dot( lastMeasurement().updatedState().globalMomentum().basicVector() ) > 0 ) ) {
163  return (firstMeasurement().updatedState().globalPosition().mag() < lastMeasurement().updatedState().globalPosition().mag() ) ?
164  firstMeasurement().updatedState() : lastMeasurement().updatedState();
165  }
166 
167  //more complicated in case of traversing and low-pt trajectories with loops
168  return closestMeasurement(GlobalPoint(0.0,0.0,0.0)).updatedState();
169 
170 }
171 
172 
173 namespace {
175  struct LessMag {
176  LessMag(GlobalPoint point) : thePoint(point) {}
177  bool operator()(const TrajectoryMeasurement& lhs,
178  const TrajectoryMeasurement& rhs) const{
179  if (lhs.updatedState().isValid() && rhs.updatedState().isValid())
180  return (lhs.updatedState().globalPosition() - thePoint).mag2() < (rhs.updatedState().globalPosition() -thePoint).mag2();
181  else
182  {
183  edm::LogError("InvalidStateOnMeasurement")<<"an updated state is not valid. result of LessMag comparator will be wrong.";
184  return false;
185  }
186  }
187  GlobalPoint thePoint;
188  };
189 
190 }
191 
193  check();
194  vector<TrajectoryMeasurement>::const_iterator iter = std::min_element(measurements().begin(), measurements().end(), LessMag(point) );
195 
196  return (*iter);
197 }
198 
200  // reverse the direction (without changing it if it's not along or opposite)
201  if (theDirection == alongMomentum) theDirection = oppositeToMomentum;
202  else if (theDirection == oppositeToMomentum) theDirection = alongMomentum;
203  // reverse the order of the hits
204  std::reverse(theData.begin(), theData.end());
205 }
ConstRecHitPointer const & recHit() const
void pushAux(double chi2Increment)
Definition: Trajectory.cc:50
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
GlobalPoint globalPosition() const
void check() const
Definition: Trajectory.cc:123
PropagationDirection
TrajectoryMeasurement const & closestMeasurement(GlobalPoint) const
Definition: Trajectory.cc:192
TrajectoryStateOnSurface geometricalInnermostState() const
Definition: Trajectory.cc:155
PropagationDirection const & direction() const
Definition: Trajectory.cc:118
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
bool check(const DataFrame &df, bool capcheck, bool dvercheck)
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
#define end
Definition: vmac.h:37
int ndof(bool bon=true) const
Definition: Trajectory.cc:78
Type getType() const
void pop()
Definition: Trajectory.cc:12
ConstRecHitContainer RecHitContainer
Definition: Trajectory.h:48
static bool isBad(const TrackingRecHit &hit)
Definition: Trajectory.cc:144
bool isValid() const
T perp() const
Magnitude of transverse component.
#define begin
Definition: vmac.h:30
T dot(const Basic3DVector &v) const
Scalar product, or &quot;dot&quot; product, with a vector of same type.
void reverse()
Definition: Trajectory.cc:199
TransientTrackingRecHit::ConstRecHitContainer ConstRecHitContainer
TrajectoryStateOnSurface const & updatedState() const
DetId geographicalId() const
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:30
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
static bool lost(const TrackingRecHit &hit)
Definition: Trajectory.cc:128