00001 #include "PixelForwardLayer.h"
00002
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004
00005 #include "DataFormats/GeometrySurface/interface/BoundingBox.h"
00006 #include "DataFormats/GeometrySurface/interface/SimpleDiskBounds.h"
00007
00008 #include "TrackingTools/DetLayers/interface/simple_stat.h"
00009 #include "TrackingTools/DetLayers/interface/PhiLess.h"
00010 #include "TrackingTools/GeomPropagators/interface/HelixArbitraryPlaneCrossing2Order.h"
00011 #include "TrackingTools/GeomPropagators/interface/HelixArbitraryPlaneCrossing.h"
00012 #include "TrackingTools/PatternTools/interface/MeasurementEstimator.h"
00013
00014
00015 #include "LayerCrossingSide.h"
00016 #include "DetGroupMerger.h"
00017 #include "CompatibleDetToGroupAdder.h"
00018
00019 using namespace std;
00020
00021 typedef GeometricSearchDet::DetWithState DetWithState;
00022
00023 PixelForwardLayer::PixelForwardLayer(vector<const PixelBlade*>& blades):
00024 theComps(blades.begin(),blades.end())
00025 {
00026 for(vector<const GeometricSearchDet*>::const_iterator it=theComps.begin();
00027 it!=theComps.end();it++){
00028 theBasicComps.insert(theBasicComps.end(),
00029 (**it).basicComponents().begin(),
00030 (**it).basicComponents().end());
00031 }
00032
00033
00034
00035 setSurface( computeSurface() );
00036
00037
00038 theBinFinder = BinFinderType( theComps.front()->surface().position().phi(),
00039 theComps.size());
00040
00041
00042 LogDebug("TkDetLayers") << "DEBUG INFO for PixelForwardLayer" << "\n"
00043 << "PixelForwardLayer.surfcace.phi(): "
00044 << this->surface().position().phi() << "\n"
00045 << "PixelForwardLayer.surfcace.z(): "
00046 << this->surface().position().z() << "\n"
00047 << "PixelForwardLayer.surfcace.innerR(): "
00048 << this->specificSurface().innerRadius() << "\n"
00049 << "PixelForwardLayer.surfcace.outerR(): "
00050 << this->specificSurface().outerRadius() ;
00051
00052 for(vector<const GeometricSearchDet*>::const_iterator it=theComps.begin();
00053 it!=theComps.end(); it++){
00054 LogDebug("TkDetLayers") << "blades phi,z,r: "
00055 << (*it)->surface().position().phi() << " , "
00056 << (*it)->surface().position().z() << " , "
00057 << (*it)->surface().position().perp();
00058 }
00059
00060
00061
00062 }
00063
00064 PixelForwardLayer::~PixelForwardLayer(){
00065 vector<const GeometricSearchDet*>::const_iterator i;
00066 for (i=theComps.begin(); i!=theComps.end(); i++) {
00067 delete *i;
00068 }
00069 }
00070
00071 void
00072 PixelForwardLayer::groupedCompatibleDetsV( const TrajectoryStateOnSurface& tsos,
00073 const Propagator& prop,
00074 const MeasurementEstimator& est,
00075 std::vector<DetGroup> & result) const {
00076 vector<DetGroup> closestResult;
00077 SubTurbineCrossings crossings;
00078
00079 crossings = computeCrossings( tsos, prop.propagationDirection());
00080 if (!crossings.isValid){
00081
00082 return;
00083 }
00084
00085 typedef CompatibleDetToGroupAdder Adder;
00086 Adder::add( *theComps[theBinFinder.binIndex(crossings.closestIndex)],
00087 tsos, prop, est, closestResult);
00088
00089 if(closestResult.empty()){
00090 Adder::add( *theComps[theBinFinder.binIndex(crossings.nextIndex)],
00091 tsos, prop, est, result);
00092 return;
00093 }
00094
00095 DetGroupElement closestGel( closestResult.front().front());
00096 float window = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
00097
00098
00099
00100 vector<DetGroup> nextResult;
00101 if (Adder::add( *theComps[theBinFinder.binIndex(crossings.nextIndex)],
00102 tsos, prop, est, nextResult)) {
00103 int crossingSide = LayerCrossingSide().endcapSide( tsos, prop);
00104 int theHelicity = computeHelicity(theComps[theBinFinder.binIndex(crossings.closestIndex)],
00105 theComps[theBinFinder.binIndex(crossings.nextIndex)] );
00106 DetGroupMerger::orderAndMergeTwoLevels( closestResult, nextResult, result,
00107 theHelicity, crossingSide);
00108 }
00109 else {
00110 result.swap(closestResult);
00111 }
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 searchNeighbors( tsos, prop, est, crossings, window, result);
00124
00125 }
00126
00127
00128
00129 void
00130 PixelForwardLayer::searchNeighbors( const TrajectoryStateOnSurface& tsos,
00131 const Propagator& prop,
00132 const MeasurementEstimator& est,
00133 const SubTurbineCrossings& crossings,
00134 float window,
00135 vector<DetGroup>& result) const
00136 {
00137 typedef CompatibleDetToGroupAdder Adder;
00138 int crossingSide = LayerCrossingSide().endcapSide( tsos, prop);
00139 typedef DetGroupMerger Merger;
00140
00141 int negStart = min( crossings.closestIndex, crossings.nextIndex) - 1;
00142 int posStart = max( crossings.closestIndex, crossings.nextIndex) + 1;
00143
00144 int quarter = theComps.size()/4;
00145
00146 vector<DetGroup> tmp;
00147 vector<DetGroup> newResult;
00148 for (int idet=negStart; idet >= negStart - quarter+1; idet--) {
00149 tmp.clear();
00150 newResult.clear();
00151 const GeometricSearchDet* neighbor = theComps[theBinFinder.binIndex(idet)];
00152
00153
00154 if (!Adder::add( *neighbor, tsos, prop, est, tmp)) break;
00155 int theHelicity = computeHelicity(theComps[theBinFinder.binIndex(idet)],
00156 theComps[theBinFinder.binIndex(idet+1)] );
00157 Merger::orderAndMergeTwoLevels( tmp, result, newResult, theHelicity, crossingSide);
00158 result.swap(newResult);
00159 }
00160 for (int idet=posStart; idet < posStart + quarter-1; idet++) {
00161 tmp.clear();
00162 newResult.clear();
00163 const GeometricSearchDet* neighbor = theComps[theBinFinder.binIndex(idet)];
00164
00165
00166 if (!Adder::add( *neighbor, tsos, prop, est, tmp)) break;
00167 int theHelicity = computeHelicity(theComps[theBinFinder.binIndex(idet-1)],
00168 theComps[theBinFinder.binIndex(idet)] );
00169 Merger::orderAndMergeTwoLevels( result, tmp, newResult, theHelicity, crossingSide);
00170 result.swap(newResult);
00171 }
00172 }
00173
00174 int
00175 PixelForwardLayer::computeHelicity(const GeometricSearchDet* firstBlade,const GeometricSearchDet* secondBlade) const
00176 {
00177 if( fabs(firstBlade->position().z()) < fabs(secondBlade->position().z()) ) return 0;
00178 return 1;
00179 }
00180
00181 PixelForwardLayer::SubTurbineCrossings
00182 PixelForwardLayer::computeCrossings( const TrajectoryStateOnSurface& startingState,
00183 PropagationDirection propDir) const
00184 {
00185 typedef MeasurementEstimator::Local2DVector Local2DVector;
00186
00187 HelixPlaneCrossing::PositionType startPos( startingState.globalPosition());
00188 HelixPlaneCrossing::DirectionType startDir( startingState.globalMomentum());
00189 float rho( startingState.transverseCurvature());
00190
00191 HelixArbitraryPlaneCrossing turbineCrossing( startPos, startDir, rho,
00192 propDir);
00193
00194 pair<bool,double> thePath = turbineCrossing.pathLength( specificSurface() );
00195
00196 if (!thePath.first) {
00197
00198 return SubTurbineCrossings();
00199 }
00200
00201 HelixPlaneCrossing::PositionType turbinePoint( turbineCrossing.position(thePath.second));
00202 HelixPlaneCrossing::DirectionType turbineDir( turbineCrossing.direction(thePath.second));
00203 int closestIndex = theBinFinder.binIndex(turbinePoint.phi());
00204
00205 const BoundPlane& closestPlane( static_cast<const BoundPlane&>(
00206 theComps[closestIndex]->surface()));
00207
00208
00209 HelixArbitraryPlaneCrossing2Order theBladeCrossing(turbinePoint, turbineDir, rho);
00210
00211 pair<bool,double> theClosestBladePath = theBladeCrossing.pathLength( closestPlane );
00212 LocalPoint closestPos = closestPlane.toLocal(GlobalPoint(theBladeCrossing.position(theClosestBladePath.second)) );
00213
00214 float closestDist = closestPos.x();
00215
00216
00217 int nextIndex = PhiLess()( closestPlane.position().phi(), turbinePoint.phi()) ?
00218 closestIndex+1 : closestIndex-1;
00219
00220 const BoundPlane& nextPlane( static_cast<const BoundPlane&>(
00221 theComps[ theBinFinder.binIndex(nextIndex)]->surface()));
00222
00223 pair<bool,double> theNextBladePath = theBladeCrossing.pathLength( nextPlane );
00224 LocalPoint nextPos = nextPlane.toLocal(GlobalPoint(theBladeCrossing.position(theNextBladePath.second)) );
00225
00226 float nextDist = nextPos.x();
00227
00228 if (fabs(closestDist) < fabs(nextDist)) {
00229 return SubTurbineCrossings( closestIndex, nextIndex, nextDist);
00230 }
00231 else {
00232 return SubTurbineCrossings( nextIndex, closestIndex, closestDist);
00233 }
00234 }
00235
00236 float
00237 PixelForwardLayer::computeWindowSize( const GeomDet* det,
00238 const TrajectoryStateOnSurface& tsos,
00239 const MeasurementEstimator& est) const
00240 {
00241 return est.maximalLocalDisplacement(tsos, det->surface()).x();
00242 }
00243
00244