00001 #include "RecoTracker/TkDetLayers/interface/CompositeTECPetal.h"
00002
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004
00005 #include "RecoTracker/TkDetLayers/interface/ForwardDiskSectorBuilderFromWedges.h"
00006 #include "RecoTracker/TkDetLayers/interface/LayerCrossingSide.h"
00007 #include "RecoTracker/TkDetLayers/interface/DetGroupMerger.h"
00008 #include "RecoTracker/TkDetLayers/interface/CompatibleDetToGroupAdder.h"
00009
00010 #include "TrackingTools/DetLayers/interface/DetLayerException.h"
00011 #include "TrackingTools/PatternTools/interface/MeasurementEstimator.h"
00012 #include "TrackingTools/GeomPropagators/interface/HelixForwardPlaneCrossing.h"
00013
00014 #include "RecoTracker/TkDetLayers/interface/TkDetUtil.h"
00015 #include "DataFormats/GeometryVector/interface/VectorUtil.h"
00016
00017 #include <boost/function.hpp>
00018 #include <boost/bind.hpp>
00019 #include<algorithm>
00020 #include<numeric>
00021 #include<iterator>
00022
00023 using namespace std;
00024
00025 typedef GeometricSearchDet::DetWithState DetWithState;
00026
00027
00028 namespace details {
00029
00030 struct Mean {
00031 float operator()(const GeometricSearchDet* a, const GeometricSearchDet* b) const {
00032 return 0.5*(b->position().perp()+a->position().perp());
00033 }
00034 float operator()(float a, float b) const {
00035 return 0.5*(b+a);
00036 }
00037 };
00038
00039 void fillBoundaries(std::vector<const GeometricSearchDet*> const & dets,
00040 std::vector<float> & boundaries) {
00041 boundaries.resize(dets.size());
00042 std::transform(dets.begin(), dets.end(), boundaries.begin(),
00043 boost::bind(&GlobalPoint::perp,boost::bind(&GeometricSearchDet::position,_1))
00044 );
00045 std::adjacent_difference(boundaries.begin(),boundaries.end(), boundaries.begin(), Mean());
00046 }
00047
00048 int findBin(std::vector<float> const & boundaries, float r) {
00049 return
00050 std::lower_bound(boundaries.begin()+1,boundaries.end(),r)
00051 -boundaries.begin()-1;
00052 }
00053
00054 }
00055
00056
00057 CompositeTECPetal::CompositeTECPetal(vector<const TECWedge*>& innerWedges,
00058 vector<const TECWedge*>& outerWedges) :
00059 theFrontComps(innerWedges.begin(),innerWedges.end()),
00060 theBackComps(outerWedges.begin(),outerWedges.end())
00061 {
00062 theComps.assign(theFrontComps.begin(),theFrontComps.end());
00063 theComps.insert(theComps.end(),theBackComps.begin(),theBackComps.end());
00064
00065 details::fillBoundaries( theFrontComps, theFrontBoundaries);
00066 details::fillBoundaries( theBackComps, theBackBoundaries);
00067
00068
00069 for(vector<const GeometricSearchDet*>::const_iterator it=theComps.begin();
00070 it!=theComps.end();it++){
00071 theBasicComps.insert(theBasicComps.end(),
00072 (**it).basicComponents().begin(),
00073 (**it).basicComponents().end());
00074 }
00075
00076
00077
00078
00079
00080
00081 vector<const TECWedge*> allWedges;
00082 allWedges.assign(innerWedges.begin(),innerWedges.end());
00083 allWedges.insert(allWedges.end(),outerWedges.begin(),outerWedges.end());
00084
00085 theDiskSector = ForwardDiskSectorBuilderFromWedges()( allWedges );
00086 theFrontSector = ForwardDiskSectorBuilderFromWedges()( innerWedges);
00087 theBackSector = ForwardDiskSectorBuilderFromWedges()( outerWedges);
00088
00089
00090 LogDebug("TkDetLayers") << "DEBUG INFO for CompositeTECPetal" ;
00091
00092 for(vector<const GeometricSearchDet*>::const_iterator it=theFrontComps.begin();
00093 it!=theFrontComps.end(); it++){
00094 LogDebug("TkDetLayers") << "frontWedge phi,z,r: "
00095 << (*it)->surface().position().phi() << " , "
00096 << (*it)->surface().position().z() << " , "
00097 << (*it)->surface().position().perp() ;
00098 }
00099
00100 for(vector<const GeometricSearchDet*>::const_iterator it=theBackComps.begin();
00101 it!=theBackComps.end(); it++){
00102 LogDebug("TkDetLayers") << "backWedge phi,z,r: "
00103 << (*it)->surface().position().phi() << " , "
00104 << (*it)->surface().position().z() << " , "
00105 << (*it)->surface().position().perp() ;
00106 }
00107
00108
00109
00110 }
00111
00112
00113 CompositeTECPetal::~CompositeTECPetal(){
00114 vector<const GeometricSearchDet*>::const_iterator i;
00115 for (i=theComps.begin(); i!=theComps.end(); i++) {
00116 delete *i;
00117 }
00118 }
00119
00120
00121 pair<bool, TrajectoryStateOnSurface>
00122 CompositeTECPetal::compatible( const TrajectoryStateOnSurface& ts, const Propagator&,
00123 const MeasurementEstimator&) const{
00124 edm::LogError("TkDetLayers") << "temporary dummy implementation of CompositeTECPetal::compatible()!!" ;
00125 return pair<bool,TrajectoryStateOnSurface>();
00126 }
00127
00128
00129 void
00130 CompositeTECPetal::groupedCompatibleDetsV( const TrajectoryStateOnSurface& tsos,
00131 const Propagator& prop,
00132 const MeasurementEstimator& est,
00133 std::vector<DetGroup> & result) const {
00134
00135 vector<DetGroup> closestResult;
00136 SubLayerCrossings crossings;
00137 crossings = computeCrossings( tsos, prop.propagationDirection());
00138 if(! crossings.isValid()) return;
00139
00140 addClosest( tsos, prop, est, crossings.closest(), closestResult);
00141 LogDebug("TkDetLayers") << "in TECPetal, closestResult.size(): "<< closestResult.size();
00142
00143 if (closestResult.empty()){
00144 vector<DetGroup> nextResult;
00145 addClosest( tsos, prop, est, crossings.other(), nextResult);
00146 LogDebug("TkDetLayers") << "in TECPetal, nextResult.size(): "<< nextResult.size() ;
00147 if(nextResult.empty()) return;
00148
00149 DetGroupElement nextGel( nextResult.front().front());
00150 int crossingSide = LayerCrossingSide().endcapSide( nextGel.trajectoryState(), prop);
00151 DetGroupMerger::orderAndMergeTwoLevels( closestResult, nextResult, result,
00152 crossings.closestIndex(), crossingSide);
00153 } else {
00154
00155 DetGroupElement closestGel( closestResult.front().front());
00156 float window = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
00157
00158 searchNeighbors( tsos, prop, est, crossings.closest(), window,
00159 closestResult, false);
00160
00161 vector<DetGroup> nextResult;
00162 searchNeighbors( tsos, prop, est, crossings.other(), window,
00163 nextResult, true);
00164
00165 int crossingSide = LayerCrossingSide().endcapSide( closestGel.trajectoryState(), prop);
00166 DetGroupMerger::orderAndMergeTwoLevels( closestResult, nextResult, result,
00167 crossings.closestIndex(), crossingSide);
00168 }
00169 }
00170
00171 SubLayerCrossings
00172 CompositeTECPetal::computeCrossings(const TrajectoryStateOnSurface& startingState,
00173 PropagationDirection propDir) const
00174 {
00175 double rho( startingState.transverseCurvature());
00176
00177 HelixPlaneCrossing::PositionType startPos( startingState.globalPosition() );
00178 HelixPlaneCrossing::DirectionType startDir( startingState.globalMomentum() );
00179 HelixForwardPlaneCrossing crossing(startPos,startDir,rho,propDir);
00180 pair<bool,double> frontPath = crossing.pathLength( *theFrontSector);
00181
00182 if (!frontPath.first) return SubLayerCrossings();
00183
00184 GlobalPoint gFrontPoint(crossing.position(frontPath.second));
00185 LogDebug("TkDetLayers")
00186 << "in TECPetal,front crossing : r,z,phi: ("
00187 << gFrontPoint.perp() << ","
00188 << gFrontPoint.z() << ","
00189 << gFrontPoint.phi() << ")";
00190
00191
00192 int frontIndex = findBin(gFrontPoint.perp(),0);
00193 float frontDist = fabs( findPosition(frontIndex,0).perp() - gFrontPoint.perp());
00194 SubLayerCrossing frontSLC( 0, frontIndex, gFrontPoint);
00195
00196
00197
00198 pair<bool,double> backPath = crossing.pathLength( *theBackSector);
00199
00200 if (!backPath.first) return SubLayerCrossings();
00201
00202
00203 GlobalPoint gBackPoint( crossing.position(backPath.second));
00204 LogDebug("TkDetLayers")
00205 << "in TECPetal,back crossing r,z,phi: ("
00206 << gBackPoint.perp() << ","
00207 << gBackPoint.z() << ","
00208 << gBackPoint.phi() << ")" ;
00209
00210 int backIndex = findBin(gBackPoint.perp(),1);
00211 float backDist = fabs( findPosition(backIndex,1).perp() - gBackPoint.perp());
00212
00213 SubLayerCrossing backSLC( 1, backIndex, gBackPoint);
00214
00215
00216
00217 if (frontDist < backDist) {
00218 return SubLayerCrossings( frontSLC, backSLC, 0);
00219 }
00220 else {
00221 return SubLayerCrossings( backSLC, frontSLC, 1);
00222 }
00223 }
00224
00225 bool CompositeTECPetal::addClosest( const TrajectoryStateOnSurface& tsos,
00226 const Propagator& prop,
00227 const MeasurementEstimator& est,
00228 const SubLayerCrossing& crossing,
00229 vector<DetGroup>& result) const
00230 {
00231 const vector<const GeometricSearchDet*>& sub( subLayer( crossing.subLayerIndex()));
00232 const GeometricSearchDet* det(sub[crossing.closestDetIndex()]);
00233
00234 LogDebug("TkDetLayers")
00235 << "in TECPetal, adding Wedge at r,z,phi: ("
00236 << det->position().perp() << ","
00237 << det->position().z() << ","
00238 << det->position().phi() << ")" ;
00239 LogDebug("TkDetLayers")
00240 << "wedge comps size: "
00241 << det->basicComponents().size();
00242
00243 return CompatibleDetToGroupAdder::add( *det, tsos, prop, est, result);
00244 }
00245
00246
00247
00248 void
00249 CompositeTECPetal::searchNeighbors( const TrajectoryStateOnSurface& tsos,
00250 const Propagator& prop,
00251 const MeasurementEstimator& est,
00252 const SubLayerCrossing& crossing,
00253 float window,
00254 vector<DetGroup>& result,
00255 bool checkClosest) const
00256 {
00257 GlobalPoint gCrossingPos = crossing.position();
00258
00259 const vector<const GeometricSearchDet*>& sLayer( subLayer( crossing.subLayerIndex()));
00260
00261 int closestIndex = crossing.closestDetIndex();
00262 int negStartIndex = closestIndex-1;
00263 int posStartIndex = closestIndex+1;
00264
00265 if (checkClosest) {
00266 if ( gCrossingPos.perp() < sLayer[closestIndex]->position().perp() ) {
00267 posStartIndex = closestIndex;
00268 }
00269 else {
00270 negStartIndex = closestIndex;
00271 }
00272 }
00273
00274
00275
00276 int theSize = crossing.subLayerIndex()==0 ? theFrontComps.size() : theBackComps.size();
00277
00278 typedef CompatibleDetToGroupAdder Adder;
00279 for (int idet=negStartIndex; idet >= 0; idet--) {
00280
00281 const GeometricSearchDet & neighborWedge = *sLayer[idet];
00282 if (!overlap( gCrossingPos, neighborWedge, window)) break;
00283 if (!Adder::add( neighborWedge, tsos, prop, est, result)) break;
00284
00285 }
00286 for (int idet=posStartIndex; idet <theSize; idet++) {
00287
00288 const GeometricSearchDet & neighborWedge = *sLayer[idet];
00289 if (!overlap( gCrossingPos, neighborWedge, window)) break;
00290 if (!Adder::add( neighborWedge, tsos, prop, est, result)) break;
00291
00292 }
00293 }
00294
00295 bool
00296 CompositeTECPetal::overlap( const GlobalPoint& gpos, const GeometricSearchDet& gsdet, float ymax)
00297 {
00298
00299
00300
00301
00302 float tsRadius = gpos.perp();
00303 float thetamin = ( max((float)0.,tsRadius-ymax))/(fabs(gpos.z())+10.);
00304 float thetamax = ( tsRadius + ymax)/(fabs(gpos.z())-10.);
00305
00306 const BoundDiskSector& wedgeSector = static_cast<const BoundDiskSector&>( gsdet.surface());
00307 float wedgeMinZ = fabs( wedgeSector.position().z()) - 0.5*wedgeSector.bounds().thickness();
00308 float wedgeMaxZ = fabs( wedgeSector.position().z()) + 0.5*wedgeSector.bounds().thickness();
00309 float thetaWedgeMin = wedgeSector.innerRadius()/ wedgeMaxZ;
00310 float thetaWedgeMax = wedgeSector.outerRadius()/ wedgeMinZ;
00311
00312
00313
00314 return !( thetamin > thetaWedgeMax || thetaWedgeMin > thetamax);
00315
00316 }
00317
00318
00319
00320
00321
00322 float CompositeTECPetal::computeWindowSize( const GeomDet* det,
00323 const TrajectoryStateOnSurface& tsos,
00324 const MeasurementEstimator& est)
00325 {
00326 return est.maximalLocalDisplacement(tsos, det->surface()).y();
00327 }
00328
00329
00330 int CompositeTECPetal::findBin( float R, int diskSectorType) const
00331 {
00332 return details::findBin(diskSectorType==0 ? theFrontBoundaries : theBackBoundaries,R);
00333 }
00334
00335
00336
00337
00338 GlobalPoint CompositeTECPetal::findPosition(int index,int diskSectorType) const
00339 {
00340 vector<const GeometricSearchDet*> const & diskSector = diskSectorType == 0 ? theFrontComps : theBackComps;
00341 return (diskSector[index])->position();
00342 }
00343