CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SimpleDAFHitCollector.cc
Go to the documentation of this file.
8 
9 #include <vector>
10 #include <map>
11 
12 #define _debug_SimpleDAFHitCollector_
13 
14 using namespace std;
15 
16 vector<TrajectoryMeasurement> SimpleDAFHitCollector::recHits(const Trajectory& traj, const MeasurementTrackerEvent *theMTE) const{
17 
18  LogTrace("MultiRecHitCollector") << " Calling SimpleDAFHitCollector::recHits" << std::endl;
19 
20  //WARNING: At the moment the trajectories has the measurements
21  //with reversed sorting after the track smoothing
22  const vector<TrajectoryMeasurement>& meas = traj.measurements();
23 
24  if (meas.empty()) return vector<TrajectoryMeasurement>();
25 
26  //debug
27  LogTrace("MultiRecHitCollector") << "Original measurements are:";
28  for(vector<TrajectoryMeasurement>::const_iterator itrajmeas = meas.begin(); itrajmeas < meas.end();
29  itrajmeas++) {
30  if (itrajmeas->recHit()->isValid()){
31  LogTrace("MultiRecHitCollector") << " Valid Hit with DetId " << itrajmeas->recHit()->geographicalId().rawId()
32  << " local position " << itrajmeas->recHit()->hit()->localPosition()
33  << " global position " << itrajmeas->recHit()->hit()->globalPosition() ;
34  } else {
35  LogTrace("MultiRecHitCollector") << " Invalid Hit with DetId " << itrajmeas->recHit()->geographicalId().rawId();
36  }
37  }
38 
39  //groups the TrajectoryMeasurements on a sensor by sensor
40  //we have to sort the TrajectoryMeasurements in the opposite way in the fitting direction
41  vector<TrajectoryMeasurement> result;
42  for(vector<TrajectoryMeasurement>::const_reverse_iterator itrajmeas = meas.rbegin(); itrajmeas < meas.rend();
43  itrajmeas++) {
44 
45  DetId id = itrajmeas->recHit()->geographicalId();
46  MeasurementDetWithData measDet = theMTE->idToDet(id);
48  std::vector<const TrackingRecHit*> hits;
49 
50  TrajectoryStateOnSurface current = itrajmeas->updatedState();
51  //the error is scaled in order to take more "compatible" hits
52  if (current.isValid()) current.rescaleError(10);
53 
54  TrajectoryStateOnSurface state = itrajmeas->predictedState();
55  if (!state.isValid()){
56  LogTrace("MultiRecHitCollector") << "Something wrong! no valid TSOS found in current group ";
57  continue;
58  }
59  //collected hits compatible with the itrajmeas
60  if( measDet.measurements(current, *(getEstimator()), tmps)){
61  LogTrace("MultiRecHitCollector") << " Found " << tmps.size() << " compatible measurements";
62  for (std::size_t i=0; i!=tmps.size(); ++i){
63  DetId idtemps = tmps.hits[i]->geographicalId();
64 
65  if( idtemps == id && tmps.hits[i]->hit()->isValid() ) {
66  hits.push_back(tmps.hits[i]->hit());
67  }
68  }
69 
70  //I will keep the Invalid hit, IF this is not the first one
71  if (hits.empty()){
72  LogTrace("MultiRecHitCollector") << " -> but no valid hits found in current group.";
73 
74  if( result.empty() ) continue;
75 
76  result.push_back(TrajectoryMeasurement(state,
77  std::make_shared<InvalidTrackingRecHit>(measDet.mdet().geomDet(), TrackingRecHit::missing)));
78  } else {
79  //measurements in groups are sorted with increating chi2
80  //sort( *hits.begin(), *hits.end(), TrajMeasLessEstim());
81 
82  LogTrace("MultiRecHitCollector") << " -> " << hits.size() << " valid hits for this sensor.";
83 
84  //building a MultiRecHit out of each sensor group
85  result.push_back(TrajectoryMeasurement(state,theUpdator->buildMultiRecHit(hits, state)));
86  }
87  } else {
88  LogTrace("MultiRecHitCollector") << " No measurements found in current group.";
89 
90  if( result.empty() ) continue;
91 
92  result.push_back(TrajectoryMeasurement(state,
93  std::make_shared<InvalidTrackingRecHit>(measDet.mdet().geomDet(), TrackingRecHit::missing)));
94 
95  }
96 
97  }
98  LogTrace("MultiRecHitCollector") << " Ending SimpleDAFHitCollector::recHits >> " << result.size();
99 
100  //adding a protection against too few hits and invalid hits
101  //(due to failed propagation on the same surface of the original hits)
102  if (result.size()>2)
103  {
104  int hitcounter=0;
105  //check if the vector result has more than 3 valid hits
106  for (vector<TrajectoryMeasurement>::const_iterator iimeas = result.begin(); iimeas != result.end(); ++iimeas) {
107  if(iimeas->recHit()->isValid()) hitcounter++;
108  }
109 
110  if(hitcounter>2)
111  return result;
112  else return vector<TrajectoryMeasurement>();
113  }
114 
115  else{return vector<TrajectoryMeasurement>();}
116 
117 }
118 
119 /*vector<TrajectoryMeasurement> SimpleDAFHitCollector::recHits(const Trajectory& traj, const MeasurementTrackerEvent *theMTE) const{
120 
121 
122  //it assumes that the measurements are sorted in the smoothing direction
123  vector<TrajectoryMeasurement> meas = traj.measurements();
124  if (meas.empty()) //return TransientTrackingRecHit::ConstRecHitContainer();
125  return vector<TrajectoryMeasurement>();
126 
127 
128  //TransientTrackingRecHit::ConstRecHitContainer result;
129  vector<TrajectoryMeasurement> result;
130 
131  for(vector<TrajectoryMeasurement>::reverse_iterator imeas = meas.rbegin(); imeas != meas.rend(); imeas++) {
132  //if the rechit is associated to a valid detId
133  if(imeas->recHit()->geographicalId().rawId()){
134  MeasurementDetWithData md = theMTE->idToDet(imeas->recHit()->geographicalId());
135  vector<TrajectoryMeasurement> currentLayerMeas = md.fastMeasurements(imeas->updatedState(), imeas->updatedState(), *thePropagator, *(getEstimator()));
136  buildMultiRecHits(currentLayerMeas, result);
137  } else {
138  result.push_back(*imeas);
139  }
140  }
141  LogTrace("MultiRecHitCollector") << "Original Measurement size " << meas.size() << " SimpleDAFHitCollector returned " << result.size() << " rechits";
142  //results are sorted in the fitting direction
143  return result;
144 }
145 
146 void SimpleDAFHitCollector::buildMultiRecHits(const vector<TrajectoryMeasurement>& vmeas, vector<TrajectoryMeasurement>& result) const {
147 
148  if (vmeas.empty()) {
149  LogTrace("MultiRecHitCollector") << "fastMeasurements returned an empty vector, should not happen " ;
150  //should we do something?
151  //result.push_back(InvalidTransientRecHit::build(0,TrackingRecHit::missing));
152  return;
153  }
154 
155  TrajectoryStateOnSurface state = vmeas.front().predictedState();
156 
157  if (state.isValid()==false){
158  LogTrace("MultiRecHitCollector") << "first state is invalid; skipping ";
159  return;
160  }
161 
162  vector<const TrackingRecHit*> hits;
163  // TransientTrackingRecHit::ConstRecHitContainer hits;
164 
165  for (vector<TrajectoryMeasurement>::const_iterator imeas = vmeas.begin(); imeas != vmeas.end(); imeas++){
166  if (imeas->recHit()->getType() != TrackingRecHit::missing) {
167  LogTrace("MultiRecHitCollector") << "This hit is valid ";
168  hits.push_back(imeas->recHit()->hit());
169  }
170  }
171 
172  if (hits.empty()){
173  LogTrace("MultiRecHitCollector") << "No valid hits found ";
174  return;
175  }
176 
177  result.push_back(TrajectoryMeasurement(state,theUpdator->buildMultiRecHit(hits, state)));
178  // result.push_back(TrajectoryMeasurement(state,theUpdator->update(hits, state)));
179 
180 }
181 
182 */
int i
Definition: DBlmapReader.cc:9
std::size_t size() const
virtual const GeomDet & geomDet() const
DataContainer const & measurements() const
Definition: Trajectory.h:203
tuple result
Definition: query.py:137
const MeasurementDet & mdet() const
#define LogTrace(id)
Definition: DetId.h:18
virtual std::vector< TrajectoryMeasurement > recHits(const Trajectory &, const MeasurementTrackerEvent *theMTE) const
bool measurements(const TrajectoryStateOnSurface &stateOnThisDet, const MeasurementEstimator &est, TempMeasurements &result) const