CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/RecoTracker/TkNavigation/src/BeamHaloNavigationSchool.cc

Go to the documentation of this file.
00001 #include "RecoTracker/TkNavigation/interface/BeamHaloNavigationSchool.h"
00002 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 #include "TrackingTools/DetLayers/src/DetBelowZ.h"
00006 #include "TrackingTools/DetLayers/src/DetLessZ.h"
00007 #include "TrackingTools/DetLayers/interface/BarrelDetLayer.h"
00008 #include "TrackingTools/DetLayers/interface/ForwardDetLayer.h"
00009 
00010 #include "RecoTracker/TkNavigation/interface/SymmetricLayerFinder.h"
00011 #include "RecoTracker/TkNavigation/interface/SimpleBarrelNavigableLayer.h"
00012 #include "RecoTracker/TkNavigation/interface/SimpleForwardNavigableLayer.h"
00013 #include "RecoTracker/TkNavigation/interface/SimpleNavigableLayer.h"
00014 
00015 #include "TrackingTools/DetLayers/interface/NavigationSetter.h"
00016 
00017 using namespace std;
00018 
00019 BeamHaloNavigationSchool::BeamHaloNavigationSchool(const GeometricSearchTracker* theInputTracker,
00020                                                const MagneticField* field) 
00021 {
00022   edm::LogInfo("BeamHaloNavigationSchool")<<"*********Running BeamHaloNavigationSchool *********";
00023   theBarrelLength = 0;theField = field; theTracker = theInputTracker;
00024   theAllDetLayersInSystem=&theInputTracker->allLayers();
00025   // Get barrel layers
00026   /*sideways does not need barrels*/
00027   /*  vector<BarrelDetLayer*> blc = theTracker->barrelLayers(); 
00028       for ( vector<BarrelDetLayer*>::iterator i = blc.begin(); i != blc.end(); i++) {
00029       theBarrelLayers.push_back( (*i) );
00030       }*/
00031 
00032   // get forward layers
00033   vector<ForwardDetLayer*> flc = theTracker->forwardLayers(); 
00034   for ( vector<ForwardDetLayer*>::iterator i = flc.begin(); i != flc.end(); i++) {
00035     theForwardLayers.push_back( (*i) );
00036   }
00037   
00038   FDLI middle = find_if( theForwardLayers.begin(), theForwardLayers.end(),
00039                          not1(DetBelowZ(0)));
00040   theLeftLayers  = FDLC( theForwardLayers.begin(), middle);
00041   theRightLayers = FDLC( middle, theForwardLayers.end());
00042   
00043   SymmetricLayerFinder symFinder( theForwardLayers);
00044 
00045   // only work on positive Z side; negative by mirror symmetry later
00046   /*sideways does not need barrels*/
00047   //  linkBarrelLayers( symFinder);
00048 
00049   linkForwardLayers( symFinder);
00050   LogDebug("BeamHaloNavigationSchool")<<"inverse relation";
00051   establishInverseRelations();
00052 
00053 
00054   //add the necessary inward links to end caps
00055   LogDebug("BeamHaloNavigationSchool")<<"linkOtherEndLayer";
00056   linkOtherEndLayers( symFinder);
00057 
00058   //set checkCrossing = false to all layers
00059   SimpleNavigationSchool::StateType allLayers=navigableLayers();
00060   SimpleNavigationSchool::StateType::iterator layerIt=allLayers.begin();
00061   SimpleNavigationSchool::StateType::iterator layerIt_end=allLayers.end();
00062   for (;layerIt!=layerIt_end;++layerIt)
00063     {
00064       //convert to SimpleNavigableLayer
00065       SimpleNavigableLayer* snl=dynamic_cast<SimpleNavigableLayer*>(*layerIt);
00066       if (!snl){
00067         edm::LogError("BeamHaloNavigationSchool")<<"navigable layer not casting to simplenavigablelayer.";
00068         continue;}
00069       snl->setCheckCrossingSide(false);
00070     }
00071 
00072 }
00073 
00074 void BeamHaloNavigationSchool::establishInverseRelations() {
00075   NavigationSetter setter(*this);
00076 
00077   // find for each layer which are the barrel and forward
00078   // layers that point to it
00079   typedef map<const DetLayer*, vector<BarrelDetLayer*>, less<const DetLayer*> > BarrelMapType;
00080   typedef map<const DetLayer*, vector<ForwardDetLayer*>, less<const DetLayer*> > ForwardMapType;
00081 
00082 
00083   BarrelMapType reachedBarrelLayersMap;
00084   ForwardMapType reachedForwardLayersMap;
00085 
00086   for ( BDLI bli = theBarrelLayers.begin();
00087         bli!=theBarrelLayers.end(); bli++) {
00088     DLC reachedLC = (**bli).nextLayers( insideOut);
00089     for ( DLI i = reachedLC.begin(); i != reachedLC.end(); i++) {
00090       reachedBarrelLayersMap[*i].push_back( *bli);
00091     }
00092   }
00093 
00094   for ( FDLI fli = theForwardLayers.begin();
00095         fli!=theForwardLayers.end(); fli++) {
00096     DLC reachedLC = (**fli).nextLayers( insideOut);
00097     for ( DLI i = reachedLC.begin(); i != reachedLC.end(); i++) {
00098       reachedForwardLayersMap[*i].push_back( *fli);
00099     }
00100   }
00101 
00102 
00103   vector<DetLayer*> lc = theTracker->allLayers();
00104   for ( vector<DetLayer*>::iterator i = lc.begin(); i != lc.end(); i++) {
00105     SimpleNavigableLayer* navigableLayer =
00106       dynamic_cast<SimpleNavigableLayer*>((**i).navigableLayer());
00107     if (!navigableLayer) {edm::LogInfo("BeamHaloNavigationSchool")<<"a detlayer does not have a navigable layer, which is normal in beam halo navigation.";}
00108     if (navigableLayer){navigableLayer->setInwardLinks( reachedBarrelLayersMap[*i],reachedForwardLayersMap[*i], TkLayerLess(outsideIn, (*i)) );}
00109   }
00110 
00111 }
00112 
00113 
00114 void BeamHaloNavigationSchool::
00115 linkOtherEndLayers(  SymmetricLayerFinder& symFinder){
00116   NavigationSetter setter(*this);
00117 
00118   LogDebug("BeamHaloNavigationSchool")<<"reachable from horizontal";
00119   //generally, on the right side, what are the forward layers reachable from the horizontal
00120   FDLC reachableFL= reachableFromHorizontal();
00121 
00122   //even simpler navigation from end to end.
00123   //for each of them
00124   for (FDLI fl=reachableFL.begin();fl!=reachableFL.end();fl++)
00125     {
00126       LogDebug("BeamHaloNavigationSchool")<<"adding inward from right";
00127       //link it inward to the mirror reachable from horizontal
00128       addInward((DetLayer*)*fl,symFinder.mirror(*fl));
00129       
00130       LogDebug("BeamHaloNavigationSchool")<<"adding inward from mirror of right (left?)";
00131       addInward((DetLayer*)symFinder.mirror(*fl),*fl);
00132     }
00133 
00134   /* this is not enough to set reachable from each of them: too few links
00135      //this is enough in the end
00136      //for each of them
00137      for (FDLI fl=reachableFL.begin();fl!=reachableFL.end();fl++)
00138      {
00139      LogDebug("BeamHaloNavigationSchool")<<"adding inward from right";
00140      //link it inward to the mirror reachable from horizontal
00141      addInward((DetLayer*)*fl,symFinder.mirror(reachableFL));
00142      
00143      LogDebug("BeamHaloNavigationSchool")<<"adding inward from mirror of right (left?)";
00144      //do the same from the the mirrored layer to the reachable from horizontal
00145      addInward((DetLayer*)symFinder.mirror(*fl),reachableFL);
00146      }
00147   */
00148 
00149 
00150   /* what about linking every not masked layer in each group.
00151      except for within the same group
00152      
00153      vector<FDLC> groups splitForwardLayers();
00154      FDLC reachable;
00155      
00156      for ( vector<FDLC>::iterator group = groups.begin();
00157      group != groups.end(); group++) {
00158      //for each group
00159      
00160      for ( FDLI i = group->begin(); i != group->end(); i++) {
00161      
00162      for ( vector<FDLC>::iterator other_group = groups.begin();
00163      other_group != groups.end(); other_group++) {
00164      //for each other group
00165      
00166      if (other_group==group && i==group->begin()){
00167      //other_group is the same as group and dealing with the first layer of the group
00168      //link the first of each group
00169      reachable.push_back(other_group.front());
00170      continue;}
00171      
00172      //now dealing as if other_group is different than group
00173      for ( FDLI other_i = other_group->begin(); other_i != other_group->end(); other_i++) {
00174      //for each of other group
00175      //is the layer in the other group "masking" this one
00176      //inner radius smaller OR outer radius bigger
00177      if ((**other_i).specificSurface().innerRadius() < (**i).specificSurface().innerRadius() ||
00178      (**other_i).specificSurface().outerRadius() > (**i).specificSurface().outerRadius())
00179      {         //not masked
00180      reachableFL.push_back(*other_i);
00181      }
00182      }
00183      //do something special with the first of each group
00184      //do somethign special with layers in its own group
00185      }
00186      }
00187      } 
00188   */
00189 
00190 
00191 
00192    /* this is too much links between layers
00193       FDLC myRightLayers( theRightLayers);
00194       FDLI begin = myRightLayers.begin();
00195       FDLI end   = myRightLayers.end();
00196       
00197       //  for each of the right layers
00198       for (FDLI fl = begin;fl!=end;++fl)
00199       {
00200       //get the navigable layer for this DetLayer
00201       SimpleNavigableLayer* navigableLayer =
00202       dynamic_cast<SimpleNavigableLayer*>((*fl)->navigableLayer());
00203       
00204       LogDebug("BeamHaloNavigationSchool")<<"retreive the next layers outsidein";
00205       //get the OUTward reachable layers.
00206       DLC inwardsLayers(navigableLayer->nextLayers(insideOut));
00207 
00208       //what is reachable horizontaly
00209       FDLC thisReachableFL (reachableFL);
00210 
00211       LogDebug("BeamHaloNavigationSchool")<<"combine";
00212       //combine the two vector with a conversion to forward layer
00213       for (DLI i=inwardsLayers.begin();i!=inwardsLayers.end();++i)
00214       {
00215       ForwardDetLayer* fd=dynamic_cast<ForwardDetLayer*>(const_cast<DetLayer*>(*i));
00216       //          ForwardDetLayer* fd=const_cast<ForwardDetLayer*>(*i);
00217       if (fd){
00218       //            if (thisReachableFL.find(fd)==thisReachableFL.end())
00219       //              {//no duplicate. insert it
00220       thisReachableFL.push_back(fd);
00221       //}
00222       }
00223       LogDebug("BeamHaloNavigationSchool")<<"investigate";
00224       }
00225       
00226       //please no duplicate !!!
00227       LogDebug("BeamHaloNavigationSchool")<<"no duplicate";
00228       FDLI new_end =unique(thisReachableFL.begin(),thisReachableFL.end());
00229       thisReachableFL.erase(new_end,thisReachableFL.end());
00230 
00231       //then set the inwards links
00232       LogDebug("BeamHaloNavigationSchool")<<"adding inward from right";
00233       //link it inward to the mirror reachable from horizontal
00234       addInward((DetLayer*)*fl,symFinder.mirror(thisReachableFL));
00235       
00236       LogDebug("BeamHaloNavigationSchool")<<"adding inward from mirror of right (left?)";
00237       //do the same from the the mirrored layer to the reachable from horizontal
00238       addInward((DetLayer*)symFinder.mirror(*fl),thisReachableFL);
00239       }
00240    */
00241 
00242 
00243 }
00244 
00245 void BeamHaloNavigationSchool::
00246 addInward(DetLayer * det, ForwardDetLayer * newF){
00247   //get the navigable layer for this DetLayer
00248   SimpleNavigableLayer* navigableLayer =
00249     dynamic_cast<SimpleNavigableLayer*>((*det).navigableLayer());
00250 
00251   LogDebug("BeamHaloNavigationSchool")<<"retreive the nextlayer outsidein";
00252   //get the inward reachable layers.
00253   DLC inwardsLayers(navigableLayer->nextLayers(outsideIn));
00254   
00255   LogDebug("BeamHaloNavigationSchool")<<"split them barrel/forward";
00256   // split barrel and forward layers
00257   BDLC inwardsBarrel;
00258   FDLC inwardsForward;
00259   for ( DLC::iterator dli=inwardsLayers.begin();dli!=inwardsLayers.end();dli++)
00260     {
00261       if ((**dli).location()==GeomDetEnumerators::barrel)
00262         inwardsBarrel.push_back((BarrelDetLayer*)*dli);
00263       else
00264         inwardsForward.push_back((ForwardDetLayer*)*dli);
00265     }
00266   LogDebug("BeamHaloNavigationSchool")<<"add the new ones";
00267   //add the other forward layers provided
00268   inwardsForward.push_back(newF);
00269 
00270   LogDebug("BeamHaloNavigationSchool")<<"no duplicate please";
00271   sort(inwardsForward.begin(),inwardsForward.end()); //if you don't sort, unique will not work
00272   //  FDLI read = inwardsForward.begin();
00273   //  std::stringstream showMe;
00274   //  for (;read !=inwardsForward.end();++read)  showMe<<" layer p: "<<*read<<"\n";
00275   //  LogDebug("BeamHaloNavigationSchool")<<"list of layer pointers: \n"<<showMe.str();
00276 
00277   FDLI new_end =unique(inwardsForward.begin(),inwardsForward.end());
00278   //  if (new_end!=inwardsForward.end()) LogDebug("BeamHaloNavigationSchool")<<"removing duplicates here";
00279   inwardsForward.erase(new_end,inwardsForward.end());
00280 
00281   LogDebug("BeamHaloNavigationSchool")<<"set back the inward links (no duplicate)";
00282   //  set them back to the navigable layer
00283   navigableLayer->setInwardLinks( inwardsBarrel, inwardsForward, TkLayerLess(outsideIn, det));
00284 }
00285 
00286 void BeamHaloNavigationSchool::
00287 addInward(DetLayer * det, FDLC news){
00288   //get the navigable layer for this DetLayer
00289   SimpleNavigableLayer* navigableLayer =
00290     dynamic_cast<SimpleNavigableLayer*>((*det).navigableLayer());
00291 
00292   LogDebug("BeamHaloNavigationSchool")<<"retreive the nextlayer outsidein";
00293   //get the inward reachable layers.
00294   DLC inwardsLayers(navigableLayer->nextLayers(outsideIn));
00295 
00296   LogDebug("BeamHaloNavigationSchool")<<"split them barrel/forward";
00297   // split barrel and forward layers
00298   BDLC inwardsBarrel;
00299   FDLC inwardsForward;
00300   for ( DLC::iterator dli=inwardsLayers.begin();dli!=inwardsLayers.end();dli++)
00301     {
00302       if ((**dli).location()==GeomDetEnumerators::barrel)
00303         inwardsBarrel.push_back((BarrelDetLayer*)*dli); 
00304       else
00305         inwardsForward.push_back((ForwardDetLayer*)*dli);
00306     }
00307   
00308   LogDebug("BeamHaloNavigationSchool")<<"add the new ones";
00309   //add the other forward layers provided
00310   inwardsForward.insert( inwardsForward.end(), news.begin(), news.end());
00311 
00312   LogDebug("BeamHaloNavigationSchool")<<"no duplicate please";
00313   FDLI new_end =unique(inwardsForward.begin(),inwardsForward.end());
00314   inwardsForward.erase(new_end,inwardsForward.end());
00315 
00316   LogDebug("BeamHaloNavigationSchool")<<"set back the inward links (no duplicate)";
00317   //  set them back to the navigable layer
00318   navigableLayer->setInwardLinks( inwardsBarrel, inwardsForward, TkLayerLess(outsideIn, det));
00319 }
00320 
00321 BeamHaloNavigationSchool::FDLC
00322 BeamHaloNavigationSchool::reachableFromHorizontal()
00323 {    
00324   //determine which is the list of forward layers that can be reached from inside-out
00325   //at horizontal direction
00326 
00327   FDLC myRightLayers( theRightLayers);
00328   FDLI begin = myRightLayers.begin();
00329   FDLI end   = myRightLayers.end();
00330 
00331   //sort along Z to be sure
00332   sort(begin, end, DetLessZ());
00333 
00334   FDLC reachableFL;
00335 
00336   begin = myRightLayers.begin();
00337   end   = myRightLayers.end();
00338 
00339   //the first one is always reachable
00340   reachableFL.push_back(*begin);
00341   FDLI current = begin;
00342   for (FDLI i = begin+1; i!= end; i++)
00343     {
00344       //is the previous layer NOT masking this one
00345       //inner radius smaller OR outer radius bigger
00346       if ((**i).specificSurface().innerRadius() < (**current).specificSurface().innerRadius() ||
00347           (**i).specificSurface().outerRadius() > (**current).specificSurface().outerRadius())
00348         {         //not masked
00349           reachableFL.push_back(*i);
00350           current=i;
00351         }
00352     }
00353   return reachableFL;
00354 }