25 NavVolume6Faces::NavVolume6Faces(
const PositionType& pos,
28 const std::vector<NavVolumeSide>& faces,
32 for (std::vector<NavVolumeSide>::const_iterator
i=faces.begin();
33 i != faces.end();
i++) {
34 theFaces.push_back(
VolumeSide( const_cast<Surface*>(&(
i->surface().surface())),
35 i->globalFace(),
i->surfaceSide()));
44 NavVolume6Faces::NavVolume6Faces(
const MagVolume& magvol,
bool isIron) :
46 theFaces(magvol.faces()), isThisIron(isIron)
48 std::vector<NavVolumeSide> navSides;
49 std::vector<VolumeSide> magSides( magvol.
faces());
52 for (std::vector<VolumeSide>::const_iterator
i=magSides.begin();
53 i != magSides.end();
i++) {
54 NavSurface* navSurface = navBuilder.build(
i->surface());
55 navSides.push_back(
NavVolumeSide( navSurface,
i->globalFace(),
i->surfaceSide()));
57 computeBounds(navSides);
61 bool NavVolume6Faces::inside(
const GlobalPoint& gp,
double tolerance)
const
64 for (std::vector<VolumeSide>::const_iterator
i=theFaces.begin();
i!=theFaces.end();
i++) {
73 void NavVolume6Faces::computeBounds(
const std::vector<NavVolumeSide>& faces)
75 bool allPlanes =
true;
77 std::vector<const Plane*> planes;
78 for (std::vector<NavVolumeSide>::const_iterator iface=faces.begin(); iface!=faces.end(); iface++) {
79 const Plane* plane =
dynamic_cast<const Plane*
>(&(iface->surface()));
81 planes.push_back(plane);
83 else allPlanes =
false;
86 for (
unsigned int i=0;
i<faces.size();
i++) {
93 myBounds = computeBounds(
i, planes);
96 myBounds = computeBounds(
i, faces);
98 navSurf.
addVolume(
this, myBounds, faces[
i].surfaceSide());
106 theNavSurfaces.push_back(
SurfaceAndBounds(&navSurf, navSurf.
bounds(
this), faces[
i].surfaceSide(), faces[
i].globalFace()));
111 const std::vector<const Plane*>& bpc)
113 const Plane* plane( bpc[index]);
116 int startIndex = 2*(1+index/2);
117 std::vector<const Plane*> crossed; crossed.reserve(4);
118 for (
int j = startIndex;
j < startIndex+4;
j++) {
119 crossed.push_back(bpc[
j%6]);
123 std::vector<GlobalPoint> corners; corners.reserve(4);
125 for (
int i=0;
i<2;
i++) {
126 for (
int j=2;
j<4;
j++) {
128 corners.push_back(corner);
131 std::cout <<
"Crossing of planes is " << corner << std::endl;
133 <<
" " << crossed[
i]->normalVector() <<
" " << crossed[
j]->normalVector() << std::endl;
135 <<
" " << crossed[
i]->position() <<
" " << crossed[
j]->position() << std::endl;
139 std::cout <<
"Crossing is really on all three surfaces" << std::endl;
142 std::cout <<
"CROSSING IS NOT ON SURFACES!!!" << std::endl;
144 std::cout << crossed[
i]->localZ(corner) << std::endl;
145 std::cout << crossed[
j]->localZ(corner) << std::endl;
157 Bounds* NavVolume6Faces::computeBounds(
int index,
const std::vector<NavVolumeSide>& faces)
159 typedef GeneralNSurfaceDelimitedBounds::SurfaceAndSide SurfaceAndSide;
160 typedef GeneralNSurfaceDelimitedBounds::SurfaceContainer SurfaceContainer;
163 int startIndex = 2*(1+index/2);
164 SurfaceContainer crossed; crossed.reserve(4);
165 for (
int j = startIndex; j < startIndex+4; j++) {
167 crossed.push_back( SurfaceAndSide(&(face.surface().surface()), face.surfaceSide()));
169 return new GeneralNSurfaceDelimitedBounds( &(faces[index].surface().surface()), crossed);
178 typedef std::map<double,SurfaceAndBounds> SortedContainer;
184 SortedContainer sortedSurfaces;
190 for (Container::const_iterator i=theNavSurfaces.begin(); i!=theNavSurfaces.end(); i++) {
191 std::pair<bool,double> dist = i->surface().distanceAlongLine( gpos, gdir);
193 if (dist.second > epsilon) sortedSurfaces[dist.second] = *
i;
194 else verycloseSurfaces.push_back(*i);
196 else unreachableSurfaces.push_back(*i);
199 for (SortedContainer::const_iterator i=sortedSurfaces.begin(); i!=sortedSurfaces.end(); ++
i) {
200 result.push_back(i->second);
202 result.insert( result.end(), unreachableSurfaces.begin(), unreachableSurfaces.end());
203 result.insert( result.end(), verycloseSurfaces.begin(), verycloseSurfaces.end());
213 typedef std::map<double,SurfaceAndBounds> SortedContainer;
219 SortedContainer sortedSurfaces;
223 double epsilon = 0.01;
224 bool surfaceMatched =
false;
226 for (Container::const_iterator i=theNavSurfaces.begin(); i!=theNavSurfaces.end(); i++) {
227 if (&(i->surface().surface()) == NotThisSurfaceP) surfaceMatched =
true;
230 for (Container::const_iterator i=theNavSurfaces.begin(); i!=theNavSurfaces.end(); i++) {
231 std::pair<bool,double> dist = i->surface().distanceAlongLine( gpos, gdir);
233 if ( &(i->surface().surface()) == NotThisSurfaceP || (!surfaceMatched && dist.second < epsilon))
234 verycloseSurfaces.push_back(*i);
235 else sortedSurfaces[dist.second] = *
i;
237 else unreachableSurfaces.push_back(*i);
241 for (SortedContainer::const_iterator i=sortedSurfaces.begin(); i!=sortedSurfaces.end(); ++
i) {
242 result.push_back(i->second);
244 result.insert( result.end(), unreachableSurfaces.begin(), unreachableSurfaces.end());
245 result.insert( result.end(), verycloseSurfaces.begin(), verycloseSurfaces.end());
253 typedef std::pair<TSOS,double> TSOSwithPath;
261 for (NavVolume::Container::const_iterator isur = nsc.begin(); isur!=nsc.end(); isur++) {
263 LogDebug(
"NavGeometry") <<
"crossToNextVolume: trying Surface no. " << itry ;
267 state = isur->surface().propagateWithPath( prop, startingState);
270 LogDebug(
"NavGeometry") <<
"Ohoh... failed to stay inside magnetic field !! skip this surface " ;
275 if (!state.first.isValid()) {
280 LogDebug(
"NavGeometry") <<
"crossToNextVolume: reached Valid State at Surface no. " << itry ;
281 LogDebug(
"NavGeometry") <<
" --> local position of Valid state is " << state.first.localPosition() ;
282 LogDebug(
"NavGeometry") <<
" --> global position of Valid state is " << state.first.globalPosition() ;
284 if (isur->bounds().inside(state.first.localPosition())) {
294 state.first, state.second );
299 LogDebug(
"NavGeometry") <<
"crossToNextVolume: BUT not inside the Bounds !! " ;
304 return VolumeCrossResult;
TkRotation< Scalar > RotationType
EcalChannelStatus Container
virtual SurfaceOrientation::Side side(const LocalPoint &p, Scalar toler) const GCC11_FINAL
GlobalVector normalVector() const
float localZ(const GlobalPoint &gp) const
GlobalPoint globalPosition() const
helper: builde a NavSurface for a Surface
LocalVector toLocal(const reco::Track::Vector &v, const Surface &s)
Plane::GlobalPoint crossing(const Plane &a, const Plane &b, const Plane &c) const
std::vector< SurfaceAndBounds > Container
static int position[TOTALCHAMBERS][3]
Point3DBase< Scalar, GlobalTag > PositionType
GloballyPositioned< float >::LocalPoint LocalPoint
GloballyPositioned< float >::LocalVector LocalVector
const SurfaceType & surface() const
LocalPoint toLocal(const GlobalPoint &gp) const
SurfaceOrientation::Side oppositeSide(SurfaceOrientation::Side side=SurfaceOrientation::onSurface)
TrajectoryStateOnSurface TSOS
virtual const Bounds * bounds(const NavVolume *vol)=0
Bounds corresponding to a NavVolume if present.
virtual const std::vector< VolumeSide > & faces() const =0
Access to volume faces.
virtual void addVolume(const NavVolume *vol, const Bounds *bounds, SurfaceOrientation::Side side)=0
NavVolumes are supposed to call this method to "register" with the NavSurface.
GlobalVector globalMomentum() const
const PositionType & position() const