00001 #include "TOBLayer.h"
00002
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004
00005 #include "LayerCrossingSide.h"
00006 #include "DetGroupMerger.h"
00007 #include "CompatibleDetToGroupAdder.h"
00008
00009 #include "TrackingTools/DetLayers/interface/DetLayerException.h"
00010 #include "TrackingTools/PatternTools/interface/MeasurementEstimator.h"
00011 #include "TrackingTools/GeomPropagators/interface/HelixBarrelCylinderCrossing.h"
00012 #include "TrackingTools/DetLayers/interface/CylinderBuilderFromDet.h"
00013 #include "TrackingTools/DetLayers/interface/PhiLess.h"
00014 #include "TrackingTools/DetLayers/interface/rangesIntersect.h"
00015
00016 using namespace std;
00017
00018 typedef GeometricSearchDet::DetWithState DetWithState;
00019
00020 TOBLayer::TOBLayer(vector<const TOBRod*>& innerRods,
00021 vector<const TOBRod*>& outerRods) :
00022 theInnerComps(innerRods.begin(),innerRods.end()),
00023 theOuterComps(outerRods.begin(),outerRods.end())
00024 {
00025 theComps.assign(theInnerComps.begin(),theInnerComps.end());
00026 theComps.insert(theComps.end(),theOuterComps.begin(),theOuterComps.end());
00027
00028 for(vector<const GeometricSearchDet*>::const_iterator it=theComps.begin();
00029 it!=theComps.end();it++){
00030 theBasicComps.insert(theBasicComps.end(),
00031 (**it).basicComponents().begin(),
00032 (**it).basicComponents().end());
00033 }
00034
00035 theInnerCylinder = cylinder( theInnerComps);
00036 theOuterCylinder = cylinder( theOuterComps);
00037
00038 if (theInnerComps.size())
00039 theInnerBinFinder = BinFinderType(theInnerComps.front()->position().phi(),
00040 theInnerComps.size());
00041
00042 if (theOuterComps.size())
00043 theOuterBinFinder = BinFinderType(theOuterComps.front()->position().phi(),
00044 theOuterComps.size());
00045
00046 BarrelDetLayer::initialize();
00047
00048
00049 LogDebug("TkDetLayers") << "==== DEBUG TOBLayer =====" ;
00050 LogDebug("TkDetLayers") << "innerCyl radius, thickness, lenght: "
00051 << theInnerCylinder->radius() << " , "
00052 << theInnerCylinder->bounds().thickness() << " , "
00053 << theInnerCylinder->bounds().length() ;
00054
00055 LogDebug("TkDetLayers") << "outerCyl radius, thickness, lenght: "
00056 << theOuterCylinder->radius() << " , "
00057 << theOuterCylinder->bounds().thickness() << " , "
00058 << theOuterCylinder->bounds().length() ;
00059
00060 LogDebug("TkDetLayers") << "Cyl radius, thickness, lenght: "
00061 << specificSurface().radius() << " , "
00062 << specificSurface().bounds().thickness() << " , "
00063 << specificSurface().bounds().length() ;
00064
00065 for (vector<const GeometricSearchDet*>::const_iterator i=theInnerComps.begin();
00066 i != theInnerComps.end(); i++){
00067 LogDebug("TkDetLayers") << "inner TOBRod pos z,perp,eta,phi: "
00068 << (**i).position().z() << " , "
00069 << (**i).position().perp() << " , "
00070 << (**i).position().eta() << " , "
00071 << (**i).position().phi() ;
00072 }
00073
00074 for (vector<const GeometricSearchDet*>::const_iterator i=theOuterComps.begin();
00075 i != theOuterComps.end(); i++){
00076 LogDebug("TkDetLayers") << "outer TOBRod pos z,perp,eta,phi: "
00077 << (**i).position().z() << " , "
00078 << (**i).position().perp() << " , "
00079 << (**i).position().eta() << " , "
00080 << (**i).position().phi() ;
00081 }
00082 LogDebug("TkDetLayers") << "==== end DEBUG TOBLayer =====" ;
00083 }
00084
00085
00086 TOBLayer::~TOBLayer(){
00087 vector<const GeometricSearchDet*>::const_iterator i;
00088 for (i=theComps.begin(); i!=theComps.end(); i++) {
00089 delete *i;
00090 }
00091 }
00092
00093
00094
00095 void
00096 TOBLayer::groupedCompatibleDetsV( const TrajectoryStateOnSurface& tsos,
00097 const Propagator& prop,
00098 const MeasurementEstimator& est,
00099 std::vector<DetGroup> & result) const
00100 {
00101 SubLayerCrossings crossings;
00102 crossings = computeCrossings( tsos, prop.propagationDirection());
00103 if(! crossings.isValid()) return;
00104
00105 vector<DetGroup> closestResult;
00106 addClosest( tsos, prop, est, crossings.closest(), closestResult);
00107 if (closestResult.empty()){
00108 addClosest( tsos, prop, est, crossings.other(), result);
00109 return;
00110 }
00111
00112 DetGroupElement closestGel( closestResult.front().front());
00113 float window = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
00114
00115 searchNeighbors( tsos, prop, est, crossings.closest(), window,
00116 closestResult, false);
00117
00118 vector<DetGroup> nextResult;
00119 searchNeighbors( tsos, prop, est, crossings.other(), window,
00120 nextResult, true);
00121
00122 int crossingSide = LayerCrossingSide().barrelSide( closestGel.trajectoryState(), prop);
00123 DetGroupMerger::orderAndMergeTwoLevels( closestResult, nextResult, result,
00124 crossings.closestIndex(), crossingSide);
00125 }
00126
00127
00128
00129
00130
00131 SubLayerCrossings TOBLayer::computeCrossings( const TrajectoryStateOnSurface& startingState,
00132 PropagationDirection propDir) const
00133 {
00134 GlobalPoint startPos( startingState.globalPosition());
00135 GlobalVector startDir( startingState.globalMomentum());
00136 double rho( startingState.transverseCurvature());
00137
00138 HelixBarrelCylinderCrossing innerCrossing( startPos, startDir, rho,
00139 propDir,*theInnerCylinder);
00140 if (!innerCrossing.hasSolution()) return SubLayerCrossings();
00141
00142 GlobalPoint gInnerPoint( innerCrossing.position());
00143 int innerIndex = theInnerBinFinder.binIndex(gInnerPoint.phi());
00144 float innerDist = theInnerBinFinder.binPosition(innerIndex) - gInnerPoint.phi();
00145 SubLayerCrossing innerSLC( 0, innerIndex, gInnerPoint);
00146
00147 HelixBarrelCylinderCrossing outerCrossing( startPos, startDir, rho,
00148 propDir,*theOuterCylinder);
00149 if (!outerCrossing.hasSolution()) return SubLayerCrossings();
00150
00151 GlobalPoint gOuterPoint( outerCrossing.position());
00152 int outerIndex = theOuterBinFinder.binIndex(gOuterPoint.phi());
00153 float outerDist = theOuterBinFinder.binPosition(outerIndex) - gOuterPoint.phi() ;
00154 SubLayerCrossing outerSLC( 1, outerIndex, gOuterPoint);
00155
00156 innerDist *= PhiLess()( theInnerBinFinder.binPosition(innerIndex),gInnerPoint.phi()) ? -1. : 1.;
00157 outerDist *= PhiLess()( theOuterBinFinder.binPosition(outerIndex),gOuterPoint.phi()) ? -1. : 1.;
00158 if (innerDist < 0.) { innerDist += 2.*Geom::pi();}
00159 if (outerDist < 0.) { outerDist += 2.*Geom::pi();}
00160
00161
00162 if (innerDist < outerDist) {
00163 return SubLayerCrossings( innerSLC, outerSLC, 0);
00164 }
00165 else {
00166 return SubLayerCrossings( outerSLC, innerSLC, 1);
00167 }
00168 }
00169
00170 bool TOBLayer::addClosest( const TrajectoryStateOnSurface& tsos,
00171 const Propagator& prop,
00172 const MeasurementEstimator& est,
00173 const SubLayerCrossing& crossing,
00174 vector<DetGroup>& result) const
00175 {
00176 const vector<const GeometricSearchDet*>& sub( subLayer( crossing.subLayerIndex()));
00177 const GeometricSearchDet* det(sub[crossing.closestDetIndex()]);
00178 return CompatibleDetToGroupAdder::add( *det, tsos, prop, est, result);
00179 }
00180
00181 float TOBLayer::computeWindowSize( const GeomDet* det,
00182 const TrajectoryStateOnSurface& tsos,
00183 const MeasurementEstimator& est) const
00184 {
00185 double xmax =
00186 est.maximalLocalDisplacement(tsos, det->surface()).x();
00187 return calculatePhiWindow( xmax, *det, tsos);
00188 }
00189
00190
00191 double TOBLayer::calculatePhiWindow( double Xmax, const GeomDet& det,
00192 const TrajectoryStateOnSurface& state) const
00193 {
00194
00195 LocalPoint startPoint = state.localPosition();
00196 LocalVector shift( Xmax , 0. , 0.);
00197 LocalPoint shift1 = startPoint + shift;
00198 LocalPoint shift2 = startPoint + (-shift);
00199
00200
00201
00202 double phi1 = det.surface().toGlobal(shift1).barePhi();
00203 double phi2 = det.surface().toGlobal(shift2).barePhi();
00204 double phiStart = state.globalPosition().barePhi();
00205 double phiWin = min(fabs(phiStart-phi1),fabs(phiStart-phi2));
00206
00207 return phiWin;
00208 }
00209
00210
00211 void TOBLayer::searchNeighbors( const TrajectoryStateOnSurface& tsos,
00212 const Propagator& prop,
00213 const MeasurementEstimator& est,
00214 const SubLayerCrossing& crossing,
00215 float window,
00216 vector<DetGroup>& result,
00217 bool checkClosest) const
00218 {
00219 GlobalPoint gCrossingPos = crossing.position();
00220
00221 const vector<const GeometricSearchDet*>& sLayer( subLayer( crossing.subLayerIndex()));
00222
00223 int closestIndex = crossing.closestDetIndex();
00224 int negStartIndex = closestIndex-1;
00225 int posStartIndex = closestIndex+1;
00226
00227 if (checkClosest) {
00228 if ( PhiLess()( gCrossingPos.phi(), sLayer[closestIndex]->surface().phi())) {
00229 posStartIndex = closestIndex;
00230 }
00231 else {
00232 negStartIndex = closestIndex;
00233 }
00234 }
00235
00236 const BinFinderType& binFinder = (crossing.subLayerIndex()==0 ? theInnerBinFinder : theOuterBinFinder);
00237
00238 typedef CompatibleDetToGroupAdder Adder;
00239 int quarter = sLayer.size()/4;
00240 for (int idet=negStartIndex; idet >= negStartIndex - quarter; idet--) {
00241 const GeometricSearchDet & neighborRod = *sLayer[binFinder.binIndex(idet)];
00242 if (!overlap( gCrossingPos, neighborRod, window)) break;
00243 if (!Adder::add( neighborRod, tsos, prop, est, result)) break;
00244
00245 }
00246 for (int idet=posStartIndex; idet < posStartIndex + quarter; idet++) {
00247 const GeometricSearchDet & neighborRod = *sLayer[binFinder.binIndex(idet)];
00248 if (!overlap( gCrossingPos, neighborRod, window)) break;
00249 if (!Adder::add( neighborRod, tsos, prop, est, result)) break;
00250
00251 }
00252 }
00253
00254 bool TOBLayer::overlap( const GlobalPoint& gpos, const GeometricSearchDet& gsdet, float phiWin) const
00255 {
00256 GlobalPoint crossPoint(gpos);
00257
00258
00259
00260 const float phiOffset = 0.00034;
00261 phiWin += phiOffset;
00262
00263
00264 std::pair<float,float> phiRange(crossPoint.phi()-phiWin, crossPoint.phi()+phiWin);
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274 return rangesIntersect(phiRange, gsdet.surface().phiSpan(), PhiLess());
00275 }
00276
00277
00278 BoundCylinder* TOBLayer::cylinder( const vector<const GeometricSearchDet*>& rods) const
00279 {
00280 vector<const GeomDet*> tmp;
00281 for (vector<const GeometricSearchDet*>::const_iterator it=rods.begin(); it!=rods.end(); it++) {
00282 tmp.insert(tmp.end(),(*it)->basicComponents().begin(),(*it)->basicComponents().end());
00283 }
00284 return CylinderBuilderFromDet()( tmp.begin(), tmp.end());
00285 }