CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/RecoTracker/TkNavigation/src/CosmicNavigationSchool.cc

Go to the documentation of this file.
00001 #include "RecoTracker/TkNavigation/interface/CosmicNavigationSchool.h"
00002 #include "RecoTracker/TkNavigation/interface/SimpleNavigationSchool.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 #include "RecoTracker/TkNavigation/interface/SimpleBarrelNavigableLayer.h"
00006 #include "RecoTracker/TkNavigation/interface/SimpleForwardNavigableLayer.h"
00007 #include "RecoTracker/TkNavigation/interface/SimpleNavigableLayer.h"
00008 #include "RecoTracker/TkNavigation/interface/DiskLessInnerRadius.h"
00009 #include "RecoTracker/TkNavigation/interface/SymmetricLayerFinder.h"
00010 
00011 #include "TrackingTools/DetLayers/interface/BarrelDetLayer.h"
00012 #include "TrackingTools/DetLayers/interface/ForwardDetLayer.h"
00013 #include "TrackingTools/DetLayers/src/DetBelowZ.h"
00014 #include "TrackingTools/DetLayers/src/DetLessZ.h"
00015 #include "TrackingTools/DetLayers/interface/NavigationSetter.h"
00016 
00017 #include "Utilities/General/interface/CMSexception.h"
00018 
00019 #include <functional>
00020 #include <algorithm>
00021 #include <map>
00022 #include <cmath>
00023 
00024 using namespace std;
00025 
00026 CosmicNavigationSchool::CosmicNavigationSchoolConfiguration::CosmicNavigationSchoolConfiguration(const edm::ParameterSet conf){
00027   noPXB=conf.getParameter<bool>("noPXB");
00028   noPXF=conf.getParameter<bool>("noPXF");
00029   noTIB=conf.getParameter<bool>("noTIB");
00030   noTID=conf.getParameter<bool>("noTID");
00031   noTOB=conf.getParameter<bool>("noTOB");
00032   noTEC=conf.getParameter<bool>("noTEC");
00033   self = conf.getParameter<bool>("selfSearch");
00034   allSelf = conf.getParameter<bool>("allSelf");
00035 }
00036 
00037 CosmicNavigationSchool::CosmicNavigationSchool(const GeometricSearchTracker* theInputTracker,
00038                                                const MagneticField* field)
00039 {
00040   build(theInputTracker, field, CosmicNavigationSchoolConfiguration());
00041 }
00042  
00043 void CosmicNavigationSchool::build(const GeometricSearchTracker* theInputTracker,
00044                                    const MagneticField* field,
00045                                    const CosmicNavigationSchoolConfiguration conf)
00046 {
00047   LogTrace("CosmicNavigationSchool") << "*********Running CosmicNavigationSchool***********" ;  
00048   theBarrelLength = 0;theField = field; theTracker = theInputTracker;
00049 
00050   theAllDetLayersInSystem=&theInputTracker->allLayers();
00051 
00052   // Get barrel layers
00053   vector<BarrelDetLayer*> blc = theTracker->barrelLayers();
00054   for ( vector<BarrelDetLayer*>::iterator i = blc.begin(); i != blc.end(); i++) {
00055     if (conf.noPXB && (*i)->subDetector() == GeomDetEnumerators::PixelBarrel) continue;
00056     if (conf.noTOB && (*i)->subDetector() == GeomDetEnumerators::TOB) continue;
00057     if (conf.noTIB && (*i)->subDetector() == GeomDetEnumerators::TIB) continue;
00058     theBarrelLayers.push_back( (*i) );
00059   }
00060 
00061   // get forward layers
00062   vector<ForwardDetLayer*> flc = theTracker->forwardLayers();
00063   for ( vector<ForwardDetLayer*>::iterator i = flc.begin(); i != flc.end(); i++) {
00064     if (conf.noPXF && (*i)->subDetector() == GeomDetEnumerators::PixelEndcap) continue;
00065     if (conf.noTEC && (*i)->subDetector() == GeomDetEnumerators::TEC) continue;
00066     if (conf.noTID && (*i)->subDetector() == GeomDetEnumerators::TID) continue;
00067     theForwardLayers.push_back( (*i) );
00068   }
00069 
00070   FDLI middle = find_if( theForwardLayers.begin(), theForwardLayers.end(),
00071                          not1(DetBelowZ(0)));
00072   theLeftLayers  = FDLC( theForwardLayers.begin(), middle);
00073   theRightLayers = FDLC( middle, theForwardLayers.end());
00074 
00075   SymmetricLayerFinder symFinder( theForwardLayers);
00076 
00077   // only work on positive Z side; negative by mirror symmetry later
00078   linkBarrelLayers( symFinder);
00079   linkForwardLayers( symFinder);
00080   establishInverseRelations( symFinder );
00081 
00082   if (conf.self){
00083 
00084     // set the self search by hand
00085     NavigationSetter setter(*this);
00086 
00087     //add TOB1->TOB1 inward link
00088     const std::vector< BarrelDetLayer * > &  tobL = theInputTracker->tobLayers();
00089     if (tobL.size()>=1){
00090       if (conf.allSelf){
00091         LogDebug("CosmicNavigationSchool")<<" adding all TOB self search.";
00092         for (std::vector< BarrelDetLayer * >::const_iterator lIt = tobL.begin(); lIt!=tobL.end(); ++lIt)
00093           dynamic_cast<SimpleNavigableLayer*>((*lIt)->navigableLayer())->theSelfSearch = true;
00094       }else{
00095         SimpleNavigableLayer* navigableLayer = dynamic_cast<SimpleNavigableLayer*>(tobL.front()->navigableLayer());
00096         LogDebug("CosmicNavigationSchool")<<" adding TOB1 to TOB1.";
00097         navigableLayer->theSelfSearch = true;
00098       }
00099     }
00100     const std::vector< BarrelDetLayer * > &  tibL = theInputTracker->tibLayers();
00101     if (tibL.size()>=1){
00102       if (conf.allSelf){
00103         LogDebug("CosmicNavigationSchool")<<" adding all TIB self search.";
00104         for (std::vector< BarrelDetLayer * >::const_iterator lIt = tibL.begin(); lIt!=tibL.end(); ++lIt)
00105           dynamic_cast<SimpleNavigableLayer*>((*lIt)->navigableLayer())->theSelfSearch = true;
00106       }else{
00107         SimpleNavigableLayer* navigableLayer = dynamic_cast<SimpleNavigableLayer*>(tibL.front()->navigableLayer());
00108         LogDebug("CosmicNavigationSchool")<<" adding tib1 to tib1.";
00109         navigableLayer->theSelfSearch = true;
00110       }
00111     }
00112     const std::vector< BarrelDetLayer * > &  pxbL = theInputTracker->pixelBarrelLayers();
00113     if (pxbL.size()>=1){
00114       if (conf.allSelf){
00115         LogDebug("CosmicNavigationSchool")<<" adding all PXB self search.";
00116         for (std::vector< BarrelDetLayer * >::const_iterator lIt = pxbL.begin(); lIt!=pxbL.end(); ++lIt)
00117           dynamic_cast<SimpleNavigableLayer*>((*lIt)->navigableLayer())->theSelfSearch = true;
00118       }else{
00119         SimpleNavigableLayer* navigableLayer = dynamic_cast<SimpleNavigableLayer*>(pxbL.front()->navigableLayer());
00120         LogDebug("CosmicNavigationSchool")<<" adding pxb1 to pxb1.";
00121         navigableLayer->theSelfSearch = true;
00122       }
00123     }
00124   }
00125 }
00126 
00127 void CosmicNavigationSchool::
00128 linkBarrelLayers( SymmetricLayerFinder& symFinder)
00129 {
00130   //identical to the SimpleNavigationSchool one, but it allows crossing over the tracker
00131   //is some non-standard link is needed, it should probably be added here
00132   
00133   // Link barrel layers outwards
00134   for ( BDLI i = theBarrelLayers.begin(); i != theBarrelLayers.end(); i++) {
00135     BDLC reachableBL;
00136     FDLC leftFL;
00137     FDLC rightFL;
00138 
00139     // always add next barrel layer first
00140     if ( i+1 != theBarrelLayers.end()) reachableBL.push_back(*(i+1));
00141 
00142     // Add closest reachable forward layer (except for last BarrelLayer)
00143     if (i != theBarrelLayers.end() - 1) {
00144       linkNextForwardLayer( *i, rightFL);
00145     }
00146 
00147     // Add next BarrelLayer with length larger than the current BL
00148     if ( i+2 < theBarrelLayers.end()) {
00149       linkNextLargerLayer( i, theBarrelLayers.end(), reachableBL);
00150     }
00151 
00152     theBarrelNLC.push_back( new
00153        SimpleBarrelNavigableLayer( *i, reachableBL,
00154                                    symFinder.mirror(rightFL),
00155                                    rightFL,theField, 5.,false));
00156   }
00157 }
00158 
00159 
00160 void CosmicNavigationSchool::establishInverseRelations(SymmetricLayerFinder& symFinder) {
00161     
00162     //again: standard part is identical to SimpleNavigationSchool one. 
00163     //After the standard link, special outsideIn links are added  
00164 
00165     NavigationSetter setter(*this);
00166 
00167     // find for each layer which are the barrel and forward
00168     // layers that point to it
00169     typedef map<const DetLayer*, vector<BarrelDetLayer*>, less<const DetLayer*> > BarrelMapType;
00170     typedef map<const DetLayer*, vector<ForwardDetLayer*>, less<const DetLayer*> > ForwardMapType;
00171 
00172 
00173     BarrelMapType reachedBarrelLayersMap;
00174     ForwardMapType reachedForwardLayersMap;
00175 
00176 
00177     for ( BDLI bli = theBarrelLayers.begin();
00178         bli!=theBarrelLayers.end(); bli++) {
00179       DLC reachedLC = (**bli).nextLayers( insideOut);
00180       for ( DLI i = reachedLC.begin(); i != reachedLC.end(); i++) {
00181         reachedBarrelLayersMap[*i].push_back( *bli);
00182       }
00183     }
00184 
00185     for ( FDLI fli = theForwardLayers.begin();
00186         fli!=theForwardLayers.end(); fli++) {
00187       DLC reachedLC = (**fli).nextLayers( insideOut);
00188       for ( DLI i = reachedLC.begin(); i != reachedLC.end(); i++) {
00189         reachedForwardLayersMap[*i].push_back( *fli);
00190       }
00191     }
00192 
00193 
00194     vector<DetLayer*> lc = theTracker->allLayers();
00195     for ( vector<DetLayer*>::iterator i = lc.begin(); i != lc.end(); i++) {
00196       SimpleNavigableLayer* navigableLayer = dynamic_cast<SimpleNavigableLayer*>((**i).navigableLayer());
00197       if (navigableLayer)
00198         navigableLayer->setInwardLinks( reachedBarrelLayersMap[*i],reachedForwardLayersMap[*i] );
00199     }   
00200     //buildAdditionalBarrelLinks();
00201     buildAdditionalForwardLinks(symFinder); 
00202 
00203 }
00204 
00205 
00206 void CosmicNavigationSchool::buildAdditionalBarrelLinks(){
00207     for ( vector<BarrelDetLayer*>::iterator i = theBarrelLayers.begin(); i != theBarrelLayers.end(); i++) {
00208       SimpleNavigableLayer* navigableLayer =
00209         dynamic_cast<SimpleNavigableLayer*>((**i).navigableLayer());
00210         if (i+1 != theBarrelLayers.end() )navigableLayer->setAdditionalLink(*(i+1), outsideIn);
00211     }
00212 }
00213 
00214 
00215 void CosmicNavigationSchool::buildAdditionalForwardLinks(SymmetricLayerFinder& symFinder){
00216     //the first layer of FPIX should not check the crossing side (since there are no inner layers to be tryed first)
00217     SimpleNavigableLayer* firstR = dynamic_cast<SimpleNavigableLayer*>(theRightLayers.front()->navigableLayer());
00218     SimpleNavigableLayer* firstL = dynamic_cast<SimpleNavigableLayer*>(theLeftLayers.front()->navigableLayer());
00219     firstR->setCheckCrossingSide(false);        
00220     firstL->setCheckCrossingSide(false);        
00221         
00222     for ( vector<ForwardDetLayer*>::iterator i = theRightLayers.begin(); i != theRightLayers.end(); i++){
00223         //look for first bigger barrel layer and link to it outsideIn
00224         SimpleForwardNavigableLayer*  nfl = dynamic_cast<SimpleForwardNavigableLayer*>((*i)->navigableLayer());
00225         SimpleForwardNavigableLayer* mnfl = dynamic_cast<SimpleForwardNavigableLayer*>(symFinder.mirror(*i)->navigableLayer());
00226         for (vector<BarrelDetLayer*>::iterator j = theBarrelLayers.begin(); j != theBarrelLayers.end(); j++){
00227             if ((*i)->specificSurface().outerRadius() < (*j)->specificSurface().radius() && 
00228                  fabs((*i)->specificSurface().position().z()) < (*j)->surface().bounds().length()/2.){ 
00229                 nfl ->setAdditionalLink(*j, outsideIn);
00230                 mnfl->setAdditionalLink(*j, outsideIn); 
00231                 break;
00232             }   
00233         }
00234     }           
00235 }
00236