CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/RecoTracker/TkNavigation/src/SymmetricLayerFinder.cc

Go to the documentation of this file.
00001 #include "RecoTracker/TkNavigation/interface/SymmetricLayerFinder.h"
00002 #include "TrackingTools/DetLayers/interface/ForwardDetLayer.h"
00003 #include "DataFormats/GeometrySurface/interface/BoundCylinder.h"
00004 #include "DataFormats/GeometrySurface/interface/BoundDisk.h"
00005 #include "TrackingTools/DetLayers/src/DetBelowZ.h"
00006 #include "Utilities/General/interface/CMSexception.h"
00007 
00008 #include <functional>
00009 #include <algorithm>
00010 #include <cmath>
00011 
00012 using namespace std;
00013 
00014 class ForwardLayerMirrorImage : 
00015   public unary_function< const ForwardDetLayer*, bool> {
00016 public:
00017 
00018   ForwardLayerMirrorImage( const ForwardDetLayer* layer) : theLayer(layer) {}
00019 
00020   bool operator()( const ForwardDetLayer* a) {
00021     float zdiff = a->position().z() + theLayer->position().z();
00022     float rdiff = a->specificSurface().innerRadius() - 
00023       theLayer->specificSurface().innerRadius();
00024 
00025     // equality based on z position and inner radius
00026     if ( fabs( zdiff) < 1. && fabs( rdiff) < 1.) return true; // units are cm
00027     else return false;
00028   }
00029 
00030 private:
00031   const ForwardDetLayer* theLayer;
00032 };
00033 
00034 SymmetricLayerFinder::SymmetricLayerFinder( const FDLC& flc)
00035 {
00036   ConstFDLI middle = find_if( flc.begin(), flc.end(), not1(DetBelowZ(0)));
00037 
00038   FDLC leftLayers = FDLC( flc.begin(),  middle);
00039   FDLC rightLayers = FDLC( middle, flc.end());
00040   vector<PairType> foundPairs;
00041 
00042   for ( FDLI i = leftLayers.begin(); i != leftLayers.end(); i++) {
00043     ForwardDetLayer* partner = mirrorPartner( *i, rightLayers);
00044     //if ( partner == 0) throw DetLogicError("Assymmetric forward layers in Tracker");
00045     if ( partner == 0) throw Genexception("Assymmetric forward layers in Tracker");
00046 
00047     foundPairs.push_back( make_pair( *i, partner));
00048   }
00049 
00050   // fill the map
00051   for ( vector<PairType>::iterator ipair = foundPairs.begin();
00052         ipair != foundPairs.end(); ipair++) {
00053     theForwardMap[ipair->first]  = ipair->second;
00054     theForwardMap[ipair->second] = ipair->first;
00055   }
00056 }
00057 
00058 ForwardDetLayer* SymmetricLayerFinder::mirrorPartner( const ForwardDetLayer* layer,
00059                                                       const FDLC& rightLayers)
00060 {
00061   ConstFDLI result =
00062     find_if( rightLayers.begin(), rightLayers.end(), ForwardLayerMirrorImage(layer));
00063   if ( result == rightLayers.end()) return 0;
00064   else return *result;
00065 }
00066 
00067 SymmetricLayerFinder::FDLC 
00068 SymmetricLayerFinder::mirror( const FDLC& input) {
00069   FDLC result;
00070   for ( ConstFDLI  i = input.begin(); i != input.end(); i++) {
00071     result.push_back( mirror(*i));
00072   }
00073   return result;
00074 }