CMS 3D CMS Logo

GroupedDAFHitCollector.cc

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 // #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00020 // #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00021 // #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00022 // #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00023 // #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00024 // #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00025 
00026 // string giulioGetLayer(const DetId& detId){
00027 //         unsigned int iSubDet = detId.subdetId();
00028 //      stringstream out;
00029 
00030 //      if (iSubDet == PixelSubdetector::PixelBarrel){
00031 //              PXBDetId pxbId(detId);
00032 //              out << pxbId;
00033 //         } else if (iSubDet == PixelSubdetector::PixelEndcap){
00034 //              PXFDetId pxfId(detId);
00035 //              out << pxfId;
00036 //      } else if (iSubDet == StripSubdetector::TIB){
00037 //                 TIBDetId  tibId(detId);
00038 //              out << tibId;
00039 //         } else if (iSubDet == StripSubdetector::TID){
00040 //                 TIDDetId tidId(detId);
00041 //              out << tidId;
00042 //         } else if (iSubDet == StripSubdetector::TOB){
00043 //                 TOBDetId tobId(detId);
00044 //              out << tobId;
00045 //         } else if(iSubDet == StripSubdetector::TEC){
00046 //                 TECDetId tecId(detId);
00047 //              out << tecId;
00048 //         }
00049 //         return out.str();
00050         
00051 // }
00052 
00053 
00054 
00055 vector<TrajectoryMeasurement> GroupedDAFHitCollector::recHits(const Trajectory& traj) const{
00056 
00057         //it assumes that the measurements are sorted in the smoothing direction
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()) //return TransientTrackingRecHit::ConstRecHitContainer();     
00066                 return vector<TrajectoryMeasurement>();
00067 
00068         vector<pair<const DetLayer*, vector<TrajectoryMeasurement> > > mol = MeasurementByLayerGrouper(getMeasurementTracker()->geometricSearchTracker())(meas);
00069 
00070         //TransientTrackingRecHit::ConstRecHitContainer result;
00071         vector<TrajectoryMeasurement> result;
00072 
00073         //first layer
00074         //  cout<<"DAFHitCollectionFromRecTrack: first layer"<<endl;
00075 
00076         //it assumes that the measurements are sorted in the smoothing direction
00077         //TrajectoryStateOnSurface current = (*(mol.begin()+1)).second.front().updatedState();
00078         TrajectoryStateOnSurface current = (*(mol.rbegin()+1)).second.back().updatedState();
00079         //if (current.isValid()) current.rescaleError(10);
00080 
00081         
00082         vector<TrajectoryMeasurementGroup> groupedMeas;
00083         //protection for layers with invalid meas with no id associated
00084         //to be fixed
00085         //for the moment no hit are lookerd for in these layers
00086         //remind that:
00087         //groupedMeasurements will return at least a measurement with an invalid hit with no detid
00088         LogDebug("MultiRecHitCollector") << "Layer "  << mol.back().first  << " has " << mol.back().second.size() << " measurements";
00089         //debug
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                     //                                             << " on " << giulioGetLayer(imeas->recHit()->geographicalId());
00098                 } else {
00099                   LogTrace("MultiRecHitCollector") << "Invalid Hit with DetId " << imeas->recHit()->geographicalId().rawId(); 
00100                     //" on " << giulioGetLayer(imeas->recHit()->geographicalId());
00101                 }
00102         }
00103         //debug          
00104         if (mol.back().first) groupedMeas = theLM.groupedMeasurements(*(mol.back().first), current, *backwardPropagator, *(getEstimator()));
00105         //in this case we have to sort the detGroups in the opposite way (according the forward propagator, not the backward one)
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         //other layers
00114         current = mol.back().second.front().updatedState();
00115         //if (current.isValid()) current.rescaleError(10);
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                 //debug
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                             //<< " on " << giulioGetLayer(imeas->recHit()->geographicalId());
00128                         } else {
00129                           LogTrace("MultiRecHitCollector") << "Invalid Hit with DetId " << imeas->recHit()->geographicalId().rawId();
00130                           //<< " on " << giulioGetLayer(imeas->recHit()->geographicalId());
00131                         }
00132                 }
00133                 //debug 
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                 //if (current.isValid()) current.rescaleError(10);
00139         }
00140         LogTrace("MultiRecHitCollector") << "Original Measurement size "  << meas.size() << " GroupedDAFHitCollector returned " << result.size() << " measurements";
00141         //results are sorted in the fitting direction
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         //TransientTrackingRecHit::ConstRecHitContainer rhits;
00149         if (measgroup.empty()) {
00150                 LogTrace("MultiRecHitCollector") << "No TrajectoryMeasurementGroups found for this layer" ; 
00151                 //should we do something?
00152                 //result.push_back(InvalidTransientRecHit::build(0,TrackingRecHit::missing));
00153                 return;
00154         } 
00155 
00156         //we build a MultiRecHit out of each group
00157         //groups are sorted along momentum or opposite to momentum, 
00158         //measurements in groups are sorted with increating chi2
00159         LogTrace("MultiRecHitCollector") << "Found " << measgroup.size() << " groups for this layer";
00160         //trajectory state to store the last valid TrajectoryState (if present) to be used 
00161         //to add an invalid Measurement in case no valid state or no valid hits are found in any group
00162         for (vector<TrajectoryMeasurementGroup>::const_iterator igroup = measgroup.begin(); igroup != measgroup.end(); igroup++ ){
00163                 //the TrajectoryState is the first one
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                 //debug
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                           // " on " << giulioGetLayer(idet->det()->geographicalId());
00175                 }
00176                 //debug
00177                 vector<const TrackingRecHit*> hits;
00178                 for (vector<TrajectoryMeasurement>::const_iterator imeas = igroup->measurements().begin(); imeas != igroup->measurements().end(); imeas++){
00179                         //collect the non missing hits to build the MultiRecHits
00180                         //we ese the recHits method; anyway only simple hits, not MultiHits should be present 
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         //can this happen? it means that the measgroup was not empty but no valid measurement was found inside
00208         //in this case we add an invalid measuremnt for this layer 
00209         if (result.size() == initial_size){
00210                 LogTrace("MultiRecHitCollector") << "no valid measuremnt or no valid TSOS in none of the groups";
00211                 //measgroup has been already checked for size != 0
00212                 if (measgroup.back().measurements().size() != 0){       
00213                         result.push_back(measgroup.back().measurements().back());
00214                 } 
00215         }
00216 }
00217 
00218 

Generated on Tue Jun 9 17:45:43 2009 for CMSSW by  doxygen 1.5.4