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