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