CMS 3D CMS Logo

GroupedDAFHitCollector.cc
Go to the documentation of this file.
12 
13 #include <vector>
14 #include <map>
15 
16 using namespace std;
17 
18 vector<TrajectoryMeasurement> GroupedDAFHitCollector::recHits(const Trajectory& traj,
19  const MeasurementTrackerEvent* theMTE) const {
20  LayerMeasurements theLM(theMTE->measurementTracker(), *theMTE);
21 
22  //WARNING: At the moment the trajectories has the measurements with reversed sorting after the track smoothing
23  const vector<TrajectoryMeasurement>& meas = traj.measurements();
24  const Propagator* forwardPropagator = getPropagator();
25  const Propagator* backwardPropagator = getReversePropagator();
26  if (traj.direction() == alongMomentum) {
27  forwardPropagator = getReversePropagator();
28  backwardPropagator = getPropagator();
29  }
30  if (meas.empty()) //return TransientTrackingRecHit::ConstRecHitContainer();
31  return vector<TrajectoryMeasurement>();
32 
33  //groups the TrajectoryMeasurements on a layer by layer
34  vector<pair<const DetLayer*, vector<TrajectoryMeasurement> > > mol;
35  mol = MeasurementByLayerGrouper(getMeasurementTracker()->geometricSearchTracker())(meas);
36 
37  vector<TrajectoryMeasurement> result;
38 
39  //add a protection if all the measurement are on the same layer
40  if (mol.size() < 2)
41  return vector<TrajectoryMeasurement>();
42 
43  //it assumes that the measurements are sorted in the smoothing direction
44  //TrajectoryStateOnSurface current = (*(mol.begin()+1)).second.front().updatedState();
45  TrajectoryStateOnSurface current = (*(mol.rbegin() + 1)).second.back().updatedState();
46  //if (current.isValid()) current.rescaleError(10);
47 
48  //protection for layers with invalid meas with no id associated
49  //to be fixed
50  //for the moment no hit are lookerd for in these layers
51  //remind that:
52  //groupedMeasurements will return at least a measurement with an invalid hit with no detid
53  LogDebug("MultiRecHitCollector") << "Layer " << mol.back().first << " has " << mol.back().second.size()
54  << " measurements";
55  LogTrace("MultiRecHitCollector") << "Original measurements are:";
56  for (unsigned int iLay = 0; iLay < mol.size(); iLay++) {
57  LogTrace("MultiRecHitCollector") << " Layer " << mol.at(iLay).first << " has " << mol.at(iLay).second.size()
58  << " measurements:";
59  vector<TrajectoryMeasurement>::const_iterator ibeg = (mol.at(iLay)).second.begin();
60  vector<TrajectoryMeasurement>::const_iterator iend = (mol.at(iLay)).second.end();
61  for (vector<TrajectoryMeasurement>::const_iterator imeas = ibeg; imeas != iend; ++imeas) {
62  if (imeas->recHit()->isValid()) {
63  LogTrace("MultiRecHitCollector") << " Valid Hit with DetId " << imeas->recHit()->geographicalId().rawId()
64  << " local position " << imeas->recHit()->hit()->localPosition()
65  << " global position " << imeas->recHit()->hit()->globalPosition();
66  } else {
67  LogTrace("MultiRecHitCollector") << " Invalid Hit with DetId " << imeas->recHit()->geographicalId().rawId();
68  }
69  }
70  }
71 
72  //ERICA: I have to understand how are set the TM now. REPLACE THIS PART!!
73  vector<TrajectoryMeasurementGroup> groupedMeas;
74  if (mol.back().first)
75  groupedMeas = theLM.groupedMeasurements(*(mol.back().first), current, *backwardPropagator, *(getEstimator()));
76 
77  //Since we have passed the backwardPropagator, we have to sort the detGroups in the opposite way
78  //(according the forward propagator, not the backward one)
79  vector<TrajectoryMeasurementGroup> sortedgroupedMeas;
80  for (vector<TrajectoryMeasurementGroup>::reverse_iterator iter = groupedMeas.rbegin(); iter != groupedMeas.rend();
81  iter++) {
82  sortedgroupedMeas.push_back(*iter);
83  }
84 
85  //for the first layer
86  buildMultiRecHits(sortedgroupedMeas, result, theMTE);
87 
88  //for other layers
89  current = mol.back().second.front().updatedState();
90  //if (current.isValid()) current.rescaleError(10);
91 
92  for (vector<pair<const DetLayer*, vector<TrajectoryMeasurement> > >::reverse_iterator imol = mol.rbegin() + 1;
93  imol != mol.rend();
94  imol++) {
95  const DetLayer* lay = (*imol).first;
96  LogDebug("MultiRecHitCollector") << "Layer " << lay << " has " << (*imol).second.size() << " measurements";
97  //debug
98  vector<TrajectoryMeasurementGroup> currentLayerMeas;
99  if (lay) {
100  currentLayerMeas = theLM.groupedMeasurements(*lay, current, *forwardPropagator, *(getEstimator()));
101  }
102 
103  buildMultiRecHits(currentLayerMeas, result, theMTE);
104  current = (*imol).second.front().updatedState();
105  //if (current.isValid()) current.rescaleError(10);
106  }
107 
108  LogTrace("MultiRecHitCollector") << " Ending GroupedDAFHitCollector::recHits >> Original Measurement size "
109  << meas.size()
110  << "\n >> GroupedDAFHitCollector returned "
111  << result.size() << " measurements";
112  //results are sorted in the fitting direction
113 
114  // adding a protection against too few hits and invalid hits (due to failed propagation on the same surface of the original hits)
115  if (result.size() > 2) {
116  int hitcounter = 0;
117  //check if the vector result has more than 3 valid hits
118  for (vector<TrajectoryMeasurement>::const_iterator iimeas = result.begin(); iimeas != result.end(); ++iimeas) {
119  if (iimeas->recHit()->isValid())
120  hitcounter++;
121  }
122 
123  if (hitcounter > 2) {
124  return result;
125  }
126 
127  else
128  return vector<TrajectoryMeasurement>();
129  }
130 
131  else {
132  return vector<TrajectoryMeasurement>();
133  }
134 }
135 
136 void GroupedDAFHitCollector::buildMultiRecHits(const vector<TrajectoryMeasurementGroup>& measgroup,
137  vector<TrajectoryMeasurement>& result,
138  const MeasurementTrackerEvent*& theMTE) const {
139  unsigned int initial_size = result.size();
140 
141  //TransientTrackingRecHit::ConstRecHitContainer rhits;
142  if (measgroup.empty()) {
143  LogTrace("MultiRecHitCollector") << "No TrajectoryMeasurementGroups found for this layer\n";
144  //should we do something?
145  //result.push_back(InvalidTransientRecHit::build(0,TrackingRecHit::missing));
146  return;
147  }
148 
149  //we build a MultiRecHit out of each group
150  //groups are sorted along momentum or opposite to momentum,
151  //measurements in groups are sorted with increating chi2
152  LogTrace("MultiRecHitCollector") << "Found " << measgroup.size() << " groups for this layer";
153 
154  //trajectory state to store the last valid TrajectoryState (if present) to be used
155  //to add an invalid Measurement in case no valid state or no valid hits are found in any group
156  for (vector<TrajectoryMeasurementGroup>::const_iterator igroup = measgroup.begin(); igroup != measgroup.end();
157  igroup++) {
158  //the TrajectoryState is the first one
159  TrajectoryStateOnSurface state = igroup->measurements().front().predictedState();
160  if (!state.isValid()) {
161  LogTrace("MultiRecHitCollector") << "Something wrong! no valid TSOS found in current group ";
162  continue;
163  }
164 
165  LogTrace("MultiRecHitCollector") << "This group has " << igroup->measurements().size() << " measurements";
166  LogTrace("MultiRecHitCollector") << "This group has the following " << igroup->detGroup().size()
167  << " detector ids: " << endl;
168  for (DetGroup::const_iterator idet = igroup->detGroup().begin(); idet != igroup->detGroup().end(); ++idet) {
169  LogTrace("MultiRecHitCollector") << idet->det()->geographicalId().rawId();
170  }
171 
172  vector<const TrackingRecHit*> hits;
173  for (vector<TrajectoryMeasurement>::const_iterator imeas = igroup->measurements().begin();
174  imeas != igroup->measurements().end();
175  imeas++) {
176  //should be fixed!!
177  //DetId id = imeas->recHit()->geographicalId();
178  //MeasurementDetWithData measDet = theMTE->idToDet(id);
179 
180  //collect the non missing hits to build the MultiRecHits
181  //we use the recHits method; anyway only simple hits, not MultiHits should be present
182  if (imeas->recHit()->getType() != TrackingRecHit::missing) {
183  LogTrace("MultiRecHitCollector") << "This hit is valid ";
184  hits.push_back(imeas->recHit()->hit());
185  } else {
186  LogTrace("MultiRecHitCollector") << " This hit is not valid and will not enter in the MRH. ";
187  }
188  }
189 
190  if (hits.empty()) {
191  LogTrace("MultiRecHitCollector") << "No valid hits found in current group ";
192  continue;
193  }
194 
195  LogTrace("MultiRecHitCollector") << "The best TSOS in this group is " << state << " it lays on surface located at "
196  << state.surface().position();
197 
198  LogTrace("MultiRecHitCollector") << "For the MRH on this group the following hits will be used";
199  for (vector<const TrackingRecHit*>::iterator iter = hits.begin(); iter != hits.end(); iter++) {
200  string validity = "valid";
201  if ((*iter)->getType() == TrackingRecHit::missing)
202  validity = "missing !should not happen!";
203  else if ((*iter)->getType() == TrackingRecHit::inactive)
204  validity = "inactive";
205  else if ((*iter)->getType() == TrackingRecHit::bad)
206  validity = "bad";
207  LogTrace("MultiRecHitCollector")
208  << "DetId " << (*iter)->geographicalId().rawId() << " validity: " << validity << " surface position "
209  << getMeasurementTracker()->geomTracker()->idToDet((*iter)->geographicalId())->position()
210  << " hit local position " << (*iter)->localPosition();
211  }
212  //should be fixed!!
213  //result.push_back(TrajectoryMeasurement(state,theUpdator->buildMultiRecHit(hits, state, *MeasurementDetWithData())));
214  }
215  //can this happen? it means that the measgroup was not empty but no valid measurement was found inside
216  //in this case we add an invalid measuremnt for this layer
217  if (result.size() == initial_size) {
218  LogTrace("MultiRecHitCollector") << "no valid measuremnt or no valid TSOS in none of the groups";
219  //measgroup has been already checked for size != 0
220  if (!measgroup.back().measurements().empty()) {
221  result.push_back(measgroup.back().measurements().back());
222  }
223  }
224 }
Propagator.h
TrajMeasLessEstim.h
MeasurementTrackerEvent.h
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
DetLayer
Definition: DetLayer.h:21
Trajectory::direction
PropagationDirection const & direction() const
Definition: Trajectory.cc:133
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
TrajectoryMeasurementGroup.h
Propagator
Definition: Propagator.h:44
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
LayerMeasurements
Definition: LayerMeasurements.h:18
MeasurementEstimator.h
GroupedDAFHitCollector.h
GroupedDAFHitCollector::buildMultiRecHits
void buildMultiRecHits(const std::vector< TrajectoryMeasurementGroup > &measgroup, std::vector< TrajectoryMeasurement > &result, const MeasurementTrackerEvent *&theMTE) const
Definition: GroupedDAFHitCollector.cc:136
TrackingRecHit::bad
Definition: TrackingRecHit.h:49
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
TrackingRecHit::missing
Definition: TrackingRecHit.h:47
position
static int position[264][3]
Definition: ReadPGInfo.cc:289
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
Trajectory::measurements
DataContainer const & measurements() const
Definition: Trajectory.h:178
Trajectory.h
std
Definition: JetResolutionObject.h:76
RunInfoPI::state
state
Definition: RunInfoPayloadInspectoHelper.h:16
Trajectory
Definition: Trajectory.h:38
DetLayer.h
TrackingRecHit::inactive
Definition: TrackingRecHit.h:48
MeasurementByLayerGrouper
Definition: MeasurementByLayerGrouper.h:13
mps_fire.result
result
Definition: mps_fire.py:311
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
MeasurementByLayerGrouper.h
alongMomentum
Definition: PropagationDirection.h:4
GroupedDAFHitCollector::recHits
std::vector< TrajectoryMeasurement > recHits(const Trajectory &, const MeasurementTrackerEvent *theMT) const override
Definition: GroupedDAFHitCollector.cc:18
SiTrackerMultiRecHitUpdator.h
InvalidTransientRecHit.h
HLTSiStripMonitoring_cff.MeasurementTrackerEvent
MeasurementTrackerEvent
Definition: HLTSiStripMonitoring_cff.py:224