00001 #include "RecoTracker/TkDetLayers/interface/TIDRing.h"
00002
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004
00005 #include "TrackingTools/DetLayers/interface/DetLayerException.h"
00006 #include "TrackingTools/DetLayers/interface/DetLayerException.h"
00007 #include "TrackingTools/PatternTools/interface/MeasurementEstimator.h"
00008 #include "TrackingTools/GeomPropagators/interface/HelixForwardPlaneCrossing.h"
00009 #include "TrackingTools/DetLayers/interface/rangesIntersect.h"
00010 #include "TrackingTools/DetLayers/interface/PhiLess.h"
00011 #include "TrackingTools/DetLayers/interface/ForwardRingDiskBuilderFromDet.h"
00012
00013 #include "RecoTracker/TkDetLayers/interface/LayerCrossingSide.h"
00014 #include "RecoTracker/TkDetLayers/interface/DetGroupMerger.h"
00015 #include "RecoTracker/TkDetLayers/interface/CompatibleDetToGroupAdder.h"
00016
00017 #include "RecoTracker/TkDetLayers/interface/TkDetUtil.h"
00018 #include "DataFormats/GeometryVector/interface/VectorUtil.h"
00019 #include <boost/function.hpp>
00020
00021 using namespace std;
00022
00023 typedef GeometricSearchDet::DetWithState DetWithState;
00024
00025 TIDRing::TIDRing(vector<const GeomDet*>& innerDets,
00026 vector<const GeomDet*>& outerDets):
00027 theFrontDets(innerDets.begin(),innerDets.end()),
00028 theBackDets(outerDets.begin(),outerDets.end())
00029 {
00030 theDets.assign(theFrontDets.begin(),theFrontDets.end());
00031 theDets.insert(theDets.end(),theBackDets.begin(),theBackDets.end());
00032
00033
00034
00035
00036
00037
00038 theDisk = ForwardRingDiskBuilderFromDet()( theDets );
00039
00040 theFrontDisk = ForwardRingDiskBuilderFromDet()( theFrontDets );
00041 theBackDisk = ForwardRingDiskBuilderFromDet()( theBackDets );
00042
00043 theFrontBinFinder = BinFinderType( theFrontDets.front()->surface().position().phi(),
00044 theFrontDets.size());
00045 theBackBinFinder = BinFinderType( theBackDets.front()->surface().position().phi(),
00046 theBackDets.size());
00047
00048
00049
00050 LogDebug("TkDetLayers") << "DEBUG INFO for TIDRing" ;
00051 for(vector<const GeomDet*>::const_iterator it=theFrontDets.begin();
00052 it!=theFrontDets.end(); it++){
00053 LogDebug("TkDetLayers") << "frontDet phi,z,r: "
00054 << (*it)->surface().position().phi() << " , "
00055 << (*it)->surface().position().z() << " , "
00056 << (*it)->surface().position().perp() ;
00057 }
00058
00059 for(vector<const GeomDet*>::const_iterator it=theBackDets.begin();
00060 it!=theBackDets.end(); it++){
00061 LogDebug("TkDetLayers") << "backDet phi,z,r: "
00062 << (*it)->surface().position().phi() << " , "
00063 << (*it)->surface().position().z() << " , "
00064 << (*it)->surface().position().perp() ;
00065 }
00066
00067
00068 }
00069
00070 TIDRing::~TIDRing(){
00071
00072 }
00073
00074 const vector<const GeometricSearchDet*>&
00075 TIDRing::components() const
00076 {
00077 throw DetLayerException("TIDRing doesn't have GeometricSearchDet components");
00078 }
00079
00080
00081 pair<bool, TrajectoryStateOnSurface>
00082 TIDRing::compatible( const TrajectoryStateOnSurface&, const Propagator&,
00083 const MeasurementEstimator&) const{
00084 edm::LogError("TkDetLayers") << "temporary dummy implementation of TIDRing::compatible()!!" ;
00085 return pair<bool,TrajectoryStateOnSurface>();
00086 }
00087
00088
00089
00090 void
00091 TIDRing::groupedCompatibleDetsV( const TrajectoryStateOnSurface& tsos,
00092 const Propagator& prop,
00093 const MeasurementEstimator& est,
00094 std::vector<DetGroup>& result) const
00095 {
00096 SubLayerCrossings crossings;
00097 crossings = computeCrossings( tsos, prop.propagationDirection());
00098 if(! crossings.isValid()) return;
00099
00100 std::vector<DetGroup> closestResult;
00101 addClosest( tsos, prop, est, crossings.closest(), closestResult);
00102 if (closestResult.empty()) return;
00103
00104 DetGroupElement closestGel( closestResult.front().front());
00105 float phiWindow = tkDetUtil::computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
00106 searchNeighbors( tsos, prop, est, crossings.closest(), phiWindow,
00107 closestResult, false);
00108
00109 vector<DetGroup> nextResult;
00110 searchNeighbors( tsos, prop, est, crossings.other(), phiWindow,
00111 nextResult, true);
00112
00113 int crossingSide = LayerCrossingSide().endcapSide( closestGel.trajectoryState(), prop);
00114 DetGroupMerger::orderAndMergeTwoLevels( closestResult, nextResult, result,
00115 crossings.closestIndex(), crossingSide);
00116 }
00117
00118
00119 SubLayerCrossings
00120 TIDRing::computeCrossings(const TrajectoryStateOnSurface& startingState,
00121 PropagationDirection propDir) const
00122 {
00123 double rho( startingState.transverseCurvature());
00124
00125 HelixPlaneCrossing::PositionType startPos( startingState.globalPosition() );
00126 HelixPlaneCrossing::DirectionType startDir( startingState.globalMomentum() );
00127 HelixForwardPlaneCrossing crossing(startPos,startDir,rho,propDir);
00128
00129 pair<bool,double> frontPath = crossing.pathLength( *theFrontDisk);
00130 if (!frontPath.first) return SubLayerCrossings();
00131
00132 GlobalPoint gFrontPoint(crossing.position(frontPath.second));
00133
00134 int frontIndex = theFrontBinFinder.binIndex(gFrontPoint.phi());
00135 SubLayerCrossing frontSLC( 0, frontIndex, gFrontPoint);
00136
00137
00138
00139 pair<bool,double> backPath = crossing.pathLength( *theBackDisk);
00140 if (!backPath.first) return SubLayerCrossings();
00141
00142 GlobalPoint gBackPoint( crossing.position(backPath.second));
00143 int backIndex = theBackBinFinder.binIndex(gBackPoint.phi());
00144 SubLayerCrossing backSLC( 1, backIndex, gBackPoint);
00145
00146
00147
00148 float frontDist = std::abs(Geom::deltaPhi( double(gFrontPoint.barePhi()),
00149 double(theFrontDets[frontIndex]->surface().phi())));
00150 float backDist = std::abs(Geom::deltaPhi( double(gBackPoint.barePhi()),
00151 double(theBackDets[backIndex]->surface().phi())));
00152
00153
00154 if (frontDist < backDist) {
00155 return SubLayerCrossings( frontSLC, backSLC, 0);
00156 }
00157 else {
00158 return SubLayerCrossings( backSLC, frontSLC, 1);
00159 }
00160 }
00161
00162 bool TIDRing::addClosest( const TrajectoryStateOnSurface& tsos,
00163 const Propagator& prop,
00164 const MeasurementEstimator& est,
00165 const SubLayerCrossing& crossing,
00166 vector<DetGroup>& result) const
00167 {
00168 const vector<const GeomDet*>& sub( subLayer( crossing.subLayerIndex()));
00169 const GeomDet* det(sub[crossing.closestDetIndex()]);
00170 return CompatibleDetToGroupAdder::add( *det, tsos, prop, est, result);
00171 }
00172
00173
00174
00175 void TIDRing::searchNeighbors( const TrajectoryStateOnSurface& tsos,
00176 const Propagator& prop,
00177 const MeasurementEstimator& est,
00178 const SubLayerCrossing& crossing,
00179 float window,
00180 vector<DetGroup>& result,
00181 bool checkClosest) const
00182 {
00183 GlobalPoint gCrossingPos = crossing.position();
00184
00185 const vector<const GeomDet*>& sLayer( subLayer( crossing.subLayerIndex()));
00186
00187 int closestIndex = crossing.closestDetIndex();
00188 int negStartIndex = closestIndex-1;
00189 int posStartIndex = closestIndex+1;
00190
00191 if (checkClosest) {
00192 if ( Geom::phiLess( gCrossingPos.barePhi(), sLayer[closestIndex]->surface().phi())) {
00193 posStartIndex = closestIndex;
00194 }
00195 else {
00196 negStartIndex = closestIndex;
00197 }
00198 }
00199
00200 const BinFinderType& binFinder = (crossing.subLayerIndex()==0 ? theFrontBinFinder : theBackBinFinder);
00201
00202 typedef CompatibleDetToGroupAdder Adder;
00203 int half = sLayer.size()/2;
00204 for (int idet=negStartIndex; idet >= negStartIndex - half; idet--) {
00205 const GeomDet & neighborDet = *sLayer[binFinder.binIndex(idet)];
00206 if (!tkDetUtil::overlapInPhi( gCrossingPos, neighborDet, window)) break;
00207 if (!Adder::add( neighborDet, tsos, prop, est, result)) break;
00208
00209 }
00210 for (int idet=posStartIndex; idet < posStartIndex + half; idet++) {
00211 const GeomDet & neighborDet = *sLayer[binFinder.binIndex(idet)];
00212 if (!tkDetUtil::overlapInPhi( gCrossingPos, neighborDet, window)) break;
00213 if (!Adder::add( neighborDet, tsos, prop, est, result)) break;
00214
00215 }
00216 }