test
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.
6 #include "boost/intrusive_ptr.hpp"
10 
11 
12 #include <algorithm>
13 
14 using namespace std;
15 
17  if (!empty()) {
18  if(theData.back().recHit()->isValid()) {
19  theNumberOfFoundHits--;
20  theChiSquared -= theData.back().estimate();
21  }
22  else if(lost(* (theData.back().recHit()) )) {
23  theNumberOfLostHits--;
24  }
25  else if(isBad(* (theData.back().recHit()) ) && theData.back().recHit()->geographicalId().det()==DetId::Muon ) {
26  theChiSquaredBad -= theData.back().estimate();
27  }
28  else if(badForCCC(theData.back())) theNumberOfCCCBadHits_--;
29 
30  theData.pop_back();
31  }
32 }
33 
34 
36  push( tm, tm.estimate());
37 }
38 
39 
41  push( tm, tm.estimate());
42 }
43 
44 
45 
46 void Trajectory::push(const TrajectoryMeasurement & tm, double chi2Increment) {
47  theData.push_back(tm); pushAux(chi2Increment);
48 }
49 
50 void Trajectory::push(TrajectoryMeasurement && tm, double chi2Increment) {
51  theData.push_back(tm); pushAux(chi2Increment);
52 }
53 
54 
55 void Trajectory::pushAux(double chi2Increment) {
56  const TrajectoryMeasurement& tm = theData.back();
57  if ( tm.recHit()->isValid()) {
58  theChiSquared += chi2Increment;
59  theNumberOfFoundHits++;
60  }
61  // else if (lost( tm.recHit()) && !inactive(tm.recHit().det())) theNumberOfLostHits++;
62  else if (lost( *(tm.recHit()) ) ) {
63  theNumberOfLostHits++;
64  }
65 
66  else if (isBad( *(tm.recHit()) ) && tm.recHit()->geographicalId().det()==DetId::Muon ) {
67  theChiSquaredBad += chi2Increment;
68  }
69 
70  else if (badForCCC(tm)) theNumberOfCCCBadHits_++;
71 
72  // in case of a Trajectory constructed without direction,
73  // determine direction from the radii of the first two measurements
74 
75  if ( !theDirectionValidity && theData.size() >= 2) {
76  if (theData[0].updatedState().globalPosition().perp2() <
77  theData.back().updatedState().globalPosition().perp2())
78  theDirection = alongMomentum;
79  else theDirection = oppositeToMomentum;
80  theDirectionValidity = true;
81  }
82 }
83 
84 
85 int Trajectory::ndof(bool bon) const {
86  Trajectory::RecHitContainer && transRecHits = recHits();
87 
88  int dof = 0;
89  int dofBad = 0;
90 
91  for(Trajectory::RecHitContainer::const_iterator rechit = transRecHits.begin();
92  rechit != transRecHits.end(); ++rechit) {
93  if((*rechit)->isValid())
94  dof += (*rechit)->dimension();
95  else if( isBad(**rechit) && (*rechit)->geographicalId().det()==DetId::Muon )
96  dofBad += (*rechit)->dimension();
97  }
98 
99  // If dof!=0 (there is at least 1 valid hit),
100  // return ndof=ndof(fit)
101  // If dof=0 (all rec hits are invalid, only for STA trajectories),
102  // return ndof=ndof(invalid hits)
103  if(dof) {
104  int constr = bon ? 5 : 4;
105  return std::max(dof - constr, 0);
106  }
107  else {
108  // A STA can have < 5 (invalid) hits
109  // if this is the case ==> ndof = 1
110  // (to avoid divisions by 0)
111  int constr = bon ? 5 : 4;
112  return std::max(dofBad - constr, 1);
113  }
114 }
115 
116 
118  hits.reserve(foundHits());
119  for (Trajectory::DataContainer::const_iterator itm
120  = theData.begin(); itm != theData.end(); itm++)
121  if ((*itm).recHit()->isValid()) hits.push_back((*itm).recHit());
122 }
123 
124 
126  if (theDirectionValidity) return theDirection;
127  else throw cms::Exception("TrackingTools/PatternTools","Trajectory::direction() requested but not set");
128 }
129 
130 void Trajectory::check() const {
131  if ( theData.empty())
132  throw cms::Exception("TrackingTools/PatternTools","Trajectory::check() - information requested from empty Trajectory");
133 }
134 
136 {
137  if ( hit.isValid()) return false;
138  else {
139  // // A DetLayer is always inactive in this logic.
140  // // The DetLayer is the Det of an invalid RecHit only if no DetUnit
141  // // is compatible with the predicted state, so we don't really expect
142  // // a hit in this case.
143 
144  if(hit.geographicalId().rawId() == 0) {return false;}
145  else{
146  return hit.getType() == TrackingRecHit::missing;
147  }
148  }
149 }
150 
152 {
153  if ( hit.isValid()) return false;
154  else {
155  if(hit.geographicalId().rawId() == 0) {return false;}
156  else{
157  return hit.getType() == TrackingRecHit::bad;
158  }
159  }
160 }
161 
163  auto const * thit = dynamic_cast<const BaseTrackerRecHit*>( tm.recHit()->hit() );
164  if (!thit)
165  return false;
166  if (thit->isPixel())
167  return false;
168  if (!tm.updatedState().isValid())
169  return false;
170  return siStripClusterTools::chargePerCM(thit->rawId(),
171  thit->firstClusterRef().stripCluster(),
172  tm.updatedState().localParameters()) < theCCCThreshold_;
173 }
174 
175 void Trajectory::updateBadForCCC(float ccc_threshold) {
176  // If the supplied threshold is the same as the currently cached
177  // one, then return the current number of bad hits for CCC,
178  // otherwise do a new full rescan.
179  if (ccc_threshold == theCCCThreshold_)
180  return;
181 
182  theCCCThreshold_ = ccc_threshold;
183  theNumberOfCCCBadHits_ = 0;
184  for (auto const & h : theData) {
185  if (badForCCC(h))
186  theNumberOfCCCBadHits_++;
187  }
188 }
189 
190 int Trajectory::numberOfCCCBadHits(float ccc_threshold) {
191  updateBadForCCC(ccc_threshold);
192  return theNumberOfCCCBadHits_;
193 }
194 
196 
197  check();
198 
199  //if trajectory is in one half, return the end closer to origin point
200  if ( firstMeasurement().updatedState().globalMomentum().perp() > 1.0
201  && ( firstMeasurement().updatedState().globalPosition().basicVector().dot( firstMeasurement().updatedState().globalMomentum().basicVector() ) *
202  lastMeasurement().updatedState().globalPosition().basicVector().dot( lastMeasurement().updatedState().globalMomentum().basicVector() ) > 0 ) ) {
203  return (firstMeasurement().updatedState().globalPosition().mag() < lastMeasurement().updatedState().globalPosition().mag() ) ?
204  firstMeasurement().updatedState() : lastMeasurement().updatedState();
205  }
206 
207  //more complicated in case of traversing and low-pt trajectories with loops
208  return closestMeasurement(GlobalPoint(0.0,0.0,0.0)).updatedState();
209 
210 }
211 
212 
213 namespace {
215  struct LessMag {
216  LessMag(GlobalPoint point) : thePoint(point) {}
217  bool operator()(const TrajectoryMeasurement& lhs,
218  const TrajectoryMeasurement& rhs) const{
219  if (lhs.updatedState().isValid() && rhs.updatedState().isValid())
220  return (lhs.updatedState().globalPosition() - thePoint).mag2() < (rhs.updatedState().globalPosition() -thePoint).mag2();
221  else
222  {
223  edm::LogError("InvalidStateOnMeasurement")<<"an updated state is not valid. result of LessMag comparator will be wrong.";
224  return false;
225  }
226  }
227  GlobalPoint thePoint;
228  };
229 
230 }
231 
233  check();
234  vector<TrajectoryMeasurement>::const_iterator iter = std::min_element(measurements().begin(), measurements().end(), LessMag(point) );
235 
236  return (*iter);
237 }
238 
240  // reverse the direction (without changing it if it's not along or opposite)
241  if (theDirection == alongMomentum) theDirection = oppositeToMomentum;
242  else if (theDirection == oppositeToMomentum) theDirection = alongMomentum;
243  // reverse the order of the hits
244  std::reverse(theData.begin(), theData.end());
245 }
ConstRecHitPointer const & recHit() const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
const LocalTrajectoryParameters & localParameters() const
void pushAux(double chi2Increment)
Definition: Trajectory.cc:55
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
float chargePerCM(DetId detid, Iter a, Iter b)
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
GlobalPoint globalPosition() const
bool badForCCC(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:162
void check() const
Definition: Trajectory.cc:130
PropagationDirection
TrajectoryMeasurement const & closestMeasurement(GlobalPoint) const
Definition: Trajectory.cc:232
TrajectoryStateOnSurface geometricalInnermostState() const
Definition: Trajectory.cc:195
PropagationDirection const & direction() const
Definition: Trajectory.cc:125
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
void updateBadForCCC(float ccc_threshold)
Definition: Trajectory.cc:175
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
void validRecHits(ConstRecHitContainer &cont) const
Definition: Trajectory.cc:117
#define end
Definition: vmac.h:37
int ndof(bool bon=true) const
Definition: Trajectory.cc:85
Type getType() const
ConstRecHitContainer RecHitContainer
Definition: Trajectory.h:46
void pop()
Definition: Trajectory.cc:16
static bool isBad(const TrackingRecHit &hit)
Definition: Trajectory.cc:151
bool isValid() const
TrackingRecHit::ConstRecHitContainer ConstRecHitContainer
Definition: Trajectory.h:45
int numberOfCCCBadHits(float ccc_threshold)
Definition: Trajectory.cc:190
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:239
TrajectoryStateOnSurface const & updatedState() const
DetId geographicalId() const
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:35
*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:135