00001 #include "RecoTracker/SiTrackerMRHTools/interface/GroupedDAFHitCollector.h"
00002 #include "RecoTracker/SiTrackerMRHTools/interface/SiTrackerMultiRecHitUpdator.h"
00003 #include "RecoTracker/SiTrackerMRHTools/interface/MeasurementByLayerGrouper.h"
00004 #include "RecoTracker/TransientTrackingRecHit/interface/TSiTrackerMultiRecHit.h"
00005 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00006 #include "TrackingTools/PatternTools/interface/MeasurementEstimator.h"
00007 #include "TrackingTools/DetLayers/interface/DetLayer.h"
00008 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00009 #include "TrackingTools/MeasurementDet/interface/TrajectoryMeasurementGroup.h"
00010 #include "TrackingTools/TransientTrackingRecHit/interface/InvalidTransientRecHit.h"
00011
00012 #include <vector>
00013 #include <map>
00014
00015 #define _debug_GroupedDAFHitCollector_
00016
00017 using namespace std;
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 vector<TrajectoryMeasurement> GroupedDAFHitCollector::recHits(const Trajectory& traj) const{
00056
00057
00058 const vector<TrajectoryMeasurement>& meas = traj.measurements();
00059 const Propagator* forwardPropagator = getPropagator();
00060 const Propagator* backwardPropagator = getReversePropagator();
00061 if (traj.direction() == alongMomentum){
00062 forwardPropagator = getReversePropagator();
00063 backwardPropagator = getPropagator();
00064 }
00065 if (meas.empty())
00066 return vector<TrajectoryMeasurement>();
00067
00068 vector<pair<const DetLayer*, vector<TrajectoryMeasurement> > > mol = MeasurementByLayerGrouper(getMeasurementTracker()->geometricSearchTracker())(meas);
00069
00070
00071 vector<TrajectoryMeasurement> result;
00072
00073
00074
00075
00076
00077
00078 TrajectoryStateOnSurface current = (*(mol.rbegin()+1)).second.back().updatedState();
00079
00080
00081
00082 vector<TrajectoryMeasurementGroup> groupedMeas;
00083
00084
00085
00086
00087
00088 LogDebug("MultiRecHitCollector") << "Layer " << mol.back().first << " has " << mol.back().second.size() << " measurements";
00089
00090 LogTrace("MultiRecHitCollector") << "Original measurements are:";
00091 vector<TrajectoryMeasurement>::const_iterator ibeg = mol.back().second.begin();
00092 vector<TrajectoryMeasurement>::const_iterator iend = mol.back().second.end();
00093 for (vector<TrajectoryMeasurement>::const_iterator imeas = ibeg; imeas != iend; ++imeas){
00094 if (imeas->recHit()->isValid()){
00095 LogTrace("MultiRecHitCollector") << "Valid Hit with DetId " << imeas->recHit()->geographicalId().rawId()
00096 << " local position " << imeas->recHit()->hit()->localPosition();
00097
00098 } else {
00099 LogTrace("MultiRecHitCollector") << "Invalid Hit with DetId " << imeas->recHit()->geographicalId().rawId();
00100
00101 }
00102 }
00103
00104 if (mol.back().first) groupedMeas = theLM.groupedMeasurements(*(mol.back().first), current, *backwardPropagator, *(getEstimator()));
00105
00106 vector<TrajectoryMeasurementGroup> sortedgroupedMeas;
00107 for (vector<TrajectoryMeasurementGroup>::reverse_iterator iter = groupedMeas.rbegin(); iter != groupedMeas.rend(); iter++){
00108 sortedgroupedMeas.push_back(*iter);
00109 }
00110 buildMultiRecHits(sortedgroupedMeas, result);
00111
00112
00113
00114 current = mol.back().second.front().updatedState();
00115
00116 for(vector<pair<const DetLayer*, vector<TrajectoryMeasurement> > >::reverse_iterator imol = mol.rbegin() + 1; imol != mol.rend(); imol++) {
00117 const DetLayer* lay = (*imol).first;
00118 LogDebug("MultiRecHitCollector") << "Layer " << lay << " has " << (*imol).second.size() << " measurements";
00119
00120 LogTrace("MultiRecHitCollector") << "Original measurements are:";
00121 vector<TrajectoryMeasurement>::const_iterator ibeg = (*imol).second.begin();
00122 vector<TrajectoryMeasurement>::const_iterator iend = (*imol).second.end();
00123 for (vector<TrajectoryMeasurement>::const_iterator imeas = ibeg; imeas != iend; ++imeas){
00124 if (imeas->recHit()->isValid()){
00125 LogTrace("MultiRecHitCollector") << "Valid Hit with DetId " << imeas->recHit()->geographicalId().rawId()
00126 << " local position " << imeas->recHit()->hit()->localPosition();
00127
00128 } else {
00129 LogTrace("MultiRecHitCollector") << "Invalid Hit with DetId " << imeas->recHit()->geographicalId().rawId();
00130
00131 }
00132 }
00133
00134 vector<TrajectoryMeasurementGroup> currentLayerMeas;
00135 if (lay) currentLayerMeas = theLM.groupedMeasurements(*lay, current, *forwardPropagator, *(getEstimator()));
00136 buildMultiRecHits(currentLayerMeas, result);
00137 current = (*imol).second.front().updatedState();
00138
00139 }
00140 LogTrace("MultiRecHitCollector") << "Original Measurement size " << meas.size() << " GroupedDAFHitCollector returned " << result.size() << " measurements";
00141
00142 return result;
00143 }
00144
00145 void GroupedDAFHitCollector::buildMultiRecHits(const vector<TrajectoryMeasurementGroup>& measgroup, vector<TrajectoryMeasurement>& result) const {
00146
00147 unsigned int initial_size = result.size();
00148
00149 if (measgroup.empty()) {
00150 LogTrace("MultiRecHitCollector") << "No TrajectoryMeasurementGroups found for this layer" ;
00151
00152
00153 return;
00154 }
00155
00156
00157
00158
00159 LogTrace("MultiRecHitCollector") << "Found " << measgroup.size() << " groups for this layer";
00160
00161
00162 for (vector<TrajectoryMeasurementGroup>::const_iterator igroup = measgroup.begin(); igroup != measgroup.end(); igroup++ ){
00163
00164 TrajectoryStateOnSurface state = igroup->measurements().front().predictedState();
00165 if (!state.isValid()){
00166 LogTrace("MultiRecHitCollector") << "Something wrong! no valid TSOS found in current group ";
00167 continue;
00168 }
00169
00170 LogTrace("MultiRecHitCollector") << "This group has " << igroup->measurements().size() << " measurements";
00171 LogTrace("MultiRecHitCollector") << "This group has the following " << igroup->detGroup().size() << " detector ids: " << endl;
00172 for (DetGroup::const_iterator idet = igroup->detGroup().begin(); idet != igroup->detGroup().end(); ++idet){
00173 LogTrace("MultiRecHitCollector") << idet->det()->geographicalId().rawId();
00174
00175 }
00176
00177 vector<const TrackingRecHit*> hits;
00178 for (vector<TrajectoryMeasurement>::const_iterator imeas = igroup->measurements().begin(); imeas != igroup->measurements().end(); imeas++){
00179
00180
00181 if (imeas->recHit()->getType() != TrackingRecHit::missing) {
00182 LogTrace("MultiRecHitCollector") << "This hit is valid ";
00183 hits.push_back(imeas->recHit()->hit());
00184 }
00185 }
00186 if (hits.empty()){
00187 LogTrace("MultiRecHitCollector") << "No valid hits found in current group ";
00188 continue;
00189 }
00190 LogTrace("MultiRecHitCollector") << "The best TSOS in this group is " << state << " it lays on surface located at " << state.surface().position();
00191 #ifdef _debug_GroupedDAFHitCollector_
00192 LogTrace("MultiRecHitCollector") << "For the MRH on this group the following hits will be used";
00193 for (vector<const TrackingRecHit*>::iterator iter = hits.begin(); iter != hits.end(); iter++){
00194 string validity = "valid";
00195 if ((*iter)->getType() == TrackingRecHit::missing ) validity = "missing !should not happen!";
00196 else if ((*iter)->getType() == TrackingRecHit::inactive) validity = "inactive";
00197 else if ((*iter)->getType() == TrackingRecHit::bad) validity = "bad";
00198 LogTrace("MultiRecHitCollector") << "DetId " << (*iter)->geographicalId().rawId() << " validity: " << validity
00199 << " surface position " << getMeasurementTracker()->geomTracker()->idToDet((*iter)->geographicalId())->position()
00200 << " hit local position " << (*iter)->localPosition();
00201 }
00202 #endif
00203
00204 result.push_back(TrajectoryMeasurement(state,theUpdator->buildMultiRecHit(hits, state)));
00205 }
00206
00207
00208
00209 if (result.size() == initial_size){
00210 LogTrace("MultiRecHitCollector") << "no valid measuremnt or no valid TSOS in none of the groups";
00211
00212 if (measgroup.back().measurements().size() != 0){
00213 result.push_back(measgroup.back().measurements().back());
00214 }
00215 }
00216 }
00217
00218