00001 #include "CompositeTECWedge.h"
00002
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004
00005 #include "ForwardDiskSectorBuilderFromDet.h"
00006 #include "LayerCrossingSide.h"
00007 #include "DetGroupMerger.h"
00008 #include "CompatibleDetToGroupAdder.h"
00009
00010 #include "TrackingTools/DetLayers/interface/DetLayerException.h"
00011
00012 #include "TrackingTools/DetLayers/interface/rangesIntersect.h"
00013 #include "TrackingTools/PatternTools/interface/MeasurementEstimator.h"
00014 #include "TrackingTools/GeomPropagators/interface/HelixForwardPlaneCrossing.h"
00015
00016 #include "TkDetUtil.h"
00017 #include "DataFormats/GeometryVector/interface/VectorUtil.h"
00018 #include <boost/function.hpp>
00019
00020 using namespace std;
00021
00022 typedef GeometricSearchDet::DetWithState DetWithState;
00023
00024
00025 class DetPhiLess {
00026 public:
00027 bool operator()(const GeomDet* a,const GeomDet* b)
00028 {
00029 return Geom::phiLess(a->surface(), b->surface());
00030 }
00031 };
00032
00033
00034 CompositeTECWedge::CompositeTECWedge(vector<const GeomDet*>& innerDets,
00035 vector<const GeomDet*>& outerDets):
00036 theFrontDets(innerDets.begin(),innerDets.end()), theBackDets(outerDets.begin(),outerDets.end())
00037 {
00038 theDets.assign(theFrontDets.begin(),theFrontDets.end());
00039 theDets.insert(theDets.end(),theBackDets.begin(),theBackDets.end());
00040
00041
00042
00043 std::sort( theFrontDets.begin(), theFrontDets.end(), DetPhiLess() );
00044 std::sort( theBackDets.begin(), theBackDets.end(), DetPhiLess() );
00045
00046 theFrontSector = ForwardDiskSectorBuilderFromDet()( theFrontDets );
00047 theBackSector = ForwardDiskSectorBuilderFromDet()( theBackDets );
00048 theDiskSector = ForwardDiskSectorBuilderFromDet()( theDets );
00049
00050
00051 LogDebug("TkDetLayers") << "DEBUG INFO for CompositeTECWedge" << "\n"
00052 << "TECWedge z, perp,innerRadius,outerR: "
00053 << this->position().z() << " , "
00054 << this->position().perp() << " , "
00055 << theDiskSector->innerRadius() << " , "
00056 << theDiskSector->outerRadius() ;
00057
00058
00059 for(vector<const GeomDet*>::const_iterator it=theFrontDets.begin();
00060 it!=theFrontDets.end(); it++){
00061 LogDebug("TkDetLayers") << "frontDet phi,z,r: "
00062 << (*it)->surface().position().phi() << " , "
00063 << (*it)->surface().position().z() << " , "
00064 << (*it)->surface().position().perp();
00065 }
00066
00067 for(vector<const GeomDet*>::const_iterator it=theBackDets.begin();
00068 it!=theBackDets.end(); it++){
00069 LogDebug("TkDetLayers") << "backDet phi,z,r: "
00070 << (*it)->surface().phi() << " , "
00071 << (*it)->surface().position().z() << " , "
00072 << (*it)->surface().position().perp() ;
00073 }
00074
00075
00076
00077 }
00078
00079 CompositeTECWedge::~CompositeTECWedge(){
00080
00081 }
00082
00083
00084 const vector<const GeometricSearchDet*>&
00085 CompositeTECWedge::components() const{
00086 throw DetLayerException("CompositeTECWedge doesn't have GeometricSearchDet components");
00087 }
00088
00089
00090 pair<bool, TrajectoryStateOnSurface>
00091 CompositeTECWedge::compatible( const TrajectoryStateOnSurface& ts, const Propagator&,
00092 const MeasurementEstimator&) const{
00093 edm::LogError("TkDetLayers") << "temporary dummy implementation of CompositeTECWedge::compatible()!!" ;
00094 return pair<bool,TrajectoryStateOnSurface>();
00095 }
00096
00097
00098 void
00099 CompositeTECWedge::groupedCompatibleDetsV( const TrajectoryStateOnSurface& tsos,
00100 const Propagator& prop,
00101 const MeasurementEstimator& est,
00102 std::vector<DetGroup> & result) const{
00103 SubLayerCrossings crossings;
00104 crossings = computeCrossings( tsos, prop.propagationDirection());
00105 if(! crossings.isValid()) return;
00106
00107 std::vector<DetGroup> closestResult;
00108 addClosest( tsos, prop, est, crossings.closest(), closestResult);
00109 LogDebug("TkDetLayers")
00110 << "in CompositeTECWedge::groupedCompatibleDets,closestResult.size(): "
00111 << closestResult.size() ;
00112
00113 if (closestResult.empty()) return;
00114
00115 DetGroupElement closestGel( closestResult.front().front());
00116 float window = tkDetUtil::computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
00117
00118 searchNeighbors( tsos, prop, est, crossings.closest(), window,
00119 closestResult, false);
00120
00121 vector<DetGroup> nextResult;
00122 searchNeighbors( tsos, prop, est, crossings.other(), window,
00123 nextResult, true);
00124
00125 int crossingSide = LayerCrossingSide().endcapSide( closestGel.trajectoryState(), prop);
00126 DetGroupMerger::orderAndMergeTwoLevels( closestResult, nextResult, result,
00127 crossings.closestIndex(), crossingSide);
00128 }
00129
00130
00131
00132
00133
00134
00135
00136 SubLayerCrossings
00137 CompositeTECWedge::computeCrossings( const TrajectoryStateOnSurface& startingState,
00138 PropagationDirection propDir) const
00139 {
00140 HelixPlaneCrossing::PositionType startPos( startingState.globalPosition() );
00141 HelixPlaneCrossing::DirectionType startDir( startingState.globalMomentum() );
00142 float rho( startingState.transverseCurvature());
00143
00144 HelixForwardPlaneCrossing crossing( startPos, startDir, rho, propDir);
00145
00146 pair<bool,double> frontPath = crossing.pathLength( *theFrontSector);
00147 if (!frontPath.first) return SubLayerCrossings();
00148
00149 GlobalPoint gFrontPoint( crossing.position(frontPath.second));
00150 LogDebug("TkDetLayers") << "in TECWedge,front crossing r,z,phi: ("
00151 << gFrontPoint.perp() << ","
00152 << gFrontPoint.z() << ","
00153 << gFrontPoint.phi() << ")" ;
00154
00155
00156 int frontIndex = findClosestDet(gFrontPoint,0);
00157 SubLayerCrossing frontSLC( 0, frontIndex, gFrontPoint);
00158
00159 pair<bool,double> backPath = crossing.pathLength( *theBackSector);
00160 if (!backPath.first) return SubLayerCrossings();
00161
00162 GlobalPoint gBackPoint( crossing.position(backPath.second));
00163 LogDebug("TkDetLayers")
00164 << "in TECWedge,back crossing r,z,phi: ("
00165 << gBackPoint.perp() << ","
00166 << gBackPoint.z() << ","
00167 << gBackPoint.phi() << ")" << endl;
00168
00169 int backIndex = findClosestDet(gBackPoint,1);
00170 SubLayerCrossing backSLC( 1, backIndex, gBackPoint);
00171
00172 float frontDist = std::abs(Geom::deltaPhi( double(gFrontPoint.barePhi()),
00173 double(theFrontDets[frontIndex]->surface().phi())));
00174
00175
00176
00177
00178
00179 float backDist = std::abs(Geom::deltaPhi( double(gBackPoint.barePhi()),
00180 double(theBackDets[backIndex]->surface().phi())));
00181
00182
00183
00184
00185
00186
00187 if (frontDist < backDist) {
00188 return SubLayerCrossings( frontSLC, backSLC, 0);
00189 }
00190 else {
00191 return SubLayerCrossings( backSLC, frontSLC, 1);
00192 }
00193 }
00194
00195
00196 bool CompositeTECWedge::addClosest( const TrajectoryStateOnSurface& tsos,
00197 const Propagator& prop,
00198 const MeasurementEstimator& est,
00199 const SubLayerCrossing& crossing,
00200 vector<DetGroup>& result) const
00201 {
00202 const vector<const GeomDet*>& sWedge( subWedge( crossing.subLayerIndex()));
00203
00204 LogDebug("TkDetLayers")
00205 << "in CompositeTECWedge,adding GeomDet at r,z,phi: ("
00206 << sWedge[crossing.closestDetIndex()]->position().perp() << ","
00207 << sWedge[crossing.closestDetIndex()]->position().z() << ","
00208 << sWedge[crossing.closestDetIndex()]->position().phi() << ")" ;
00209
00210 return CompatibleDetToGroupAdder().add( *sWedge[crossing.closestDetIndex()],
00211 tsos, prop, est, result);
00212 }
00213
00214
00215 void CompositeTECWedge::searchNeighbors( const TrajectoryStateOnSurface& tsos,
00216 const Propagator& prop,
00217 const MeasurementEstimator& est,
00218 const SubLayerCrossing& crossing,
00219 float window,
00220 vector<DetGroup>& result,
00221 bool checkClosest) const
00222 {
00223 GlobalPoint gCrossingPos = crossing.position();
00224
00225 const vector<const GeomDet*>& sWedge( subWedge( crossing.subLayerIndex()));
00226
00227 int closestIndex = crossing.closestDetIndex();
00228 int negStartIndex = closestIndex-1;
00229 int posStartIndex = closestIndex+1;
00230
00231 if (checkClosest) {
00232 if ( Geom::phiLess(gCrossingPos.barePhi(), sWedge[closestIndex]->surface().phi()) ) {
00233 posStartIndex = closestIndex;
00234 }
00235 else {
00236 negStartIndex = closestIndex;
00237 }
00238 }
00239
00240 typedef CompatibleDetToGroupAdder Adder;
00241 for (int idet=negStartIndex; idet >= 0; idet--) {
00242
00243 if (!tkDetUtil::overlapInPhi( gCrossingPos, *sWedge[idet], window)) break;
00244 if (!Adder::add( *sWedge[idet], tsos, prop, est, result)) break;
00245 }
00246 for (int idet=posStartIndex; idet < static_cast<int>(sWedge.size()); idet++) {
00247
00248 if (!tkDetUtil::overlapInPhi( gCrossingPos, *sWedge[idet], window)) break;
00249 if (!Adder::add( *sWedge[idet], tsos, prop, est, result)) break;
00250 }
00251 }
00252
00253
00254
00255 int
00256 CompositeTECWedge::findClosestDet( const GlobalPoint& startPos,int sectorId) const
00257 {
00258 vector<const GeomDet*> myDets = sectorId==0 ? theFrontDets : theBackDets;
00259
00260 int close = 0;
00261 float closeDist = fabs( (myDets.front()->toLocal(startPos)).x());
00262 for (unsigned int i = 0; i < myDets.size(); i++ ) {
00263 float dist = (myDets[i]->surface().toLocal(startPos)).x();
00264 if ( fabs(dist) < fabs(closeDist) ) {
00265 close = i;
00266 closeDist = dist;
00267 }
00268 }
00269 return close;
00270 }