Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-12 23:30:37

0001 #include "SimpleBarrelNavigableLayer.h"
0002 
0003 #include "DataFormats/GeometrySurface/interface/BoundCylinder.h"
0004 #include "DataFormats/GeometrySurface/interface/BoundDisk.h"
0005 
0006 #include "TrackingTools/DetLayers/interface/DetLayerException.h"
0007 #include "TrackingTools/DetLayers/interface/BarrelDetLayer.h"
0008 #include "TrackingTools/DetLayers/interface/ForwardDetLayer.h"
0009 
0010 #include "TrackingTools/DetLayers/interface/TkLayerLess.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "FWCore/Utilities/interface/Likely.h"
0013 
0014 #include <algorithm>
0015 #include <map>
0016 #include <cmath>
0017 
0018 using namespace std;
0019 
0020 SimpleBarrelNavigableLayer::SimpleBarrelNavigableLayer(const BarrelDetLayer* detLayer,
0021                                                        const BDLC& outerBLC,
0022                                                        const FDLC& outerLeftFL,
0023                                                        const FDLC& outerRightFL,
0024                                                        const MagneticField* field,
0025                                                        float epsilon,
0026                                                        bool checkCrossingSide)
0027     : SimpleNavigableLayer(field, epsilon, checkCrossingSide),
0028       theDetLayer(detLayer),
0029       theOuterBarrelLayers(outerBLC),
0030       theOuterLeftForwardLayers(outerLeftFL),
0031       theOuterRightForwardLayers(outerRightFL)
0032 
0033 {
0034   // put barrel and forward layers together
0035   theNegOuterLayers.reserve(outerBLC.size() + outerLeftFL.size());
0036   thePosOuterLayers.reserve(outerBLC.size() + outerRightFL.size());
0037 
0038   for (ConstBDLI bl = outerBLC.begin(); bl != outerBLC.end(); bl++)
0039     theNegOuterLayers.push_back(*bl);
0040   thePosOuterLayers = theNegOuterLayers;  // barrel part the same
0041 
0042   for (ConstFDLI fl = outerLeftFL.begin(); fl != outerLeftFL.end(); fl++)
0043     theNegOuterLayers.push_back(*fl);
0044   for (ConstFDLI fl = outerRightFL.begin(); fl != outerRightFL.end(); fl++)
0045     thePosOuterLayers.push_back(*fl);
0046 
0047   // sort the outer layers
0048   sort(theNegOuterLayers.begin(), theNegOuterLayers.end(), TkLayerLess());
0049   sort(thePosOuterLayers.begin(), thePosOuterLayers.end(), TkLayerLess());
0050   sort(theOuterBarrelLayers.begin(), theOuterBarrelLayers.end(), TkLayerLess());
0051   sort(theOuterLeftForwardLayers.begin(), theOuterLeftForwardLayers.end(), TkLayerLess());
0052   sort(theOuterRightForwardLayers.begin(), theOuterRightForwardLayers.end(), TkLayerLess());
0053 }
0054 
0055 vector<const DetLayer*> SimpleBarrelNavigableLayer::nextLayers(NavigationDirection dir) const {
0056   vector<const DetLayer*> result;
0057 
0058   // the order is the one in which layers
0059   // should be checked for a reasonable trajectory
0060 
0061   if (dir == insideOut) {
0062     result = theNegOuterLayers;
0063     for (DLC::const_iterator i = thePosOuterLayers.begin(); i != thePosOuterLayers.end(); i++) {
0064       // avoid duplication of barrel layers
0065       if ((**i).location() == GeomDetEnumerators::endcap)
0066         result.push_back(*i);
0067     }
0068   } else {
0069     result = theNegInnerLayers;
0070     for (DLC::const_iterator i = thePosInnerLayers.begin(); i != thePosInnerLayers.end(); i++) {
0071       // avoid duplication of barrel layers
0072       if ((**i).location() == GeomDetEnumerators::endcap)
0073         result.push_back(*i);
0074     }
0075   }
0076   return result;
0077 }
0078 
0079 vector<const DetLayer*> SimpleBarrelNavigableLayer::nextLayers(const FreeTrajectoryState& fts,
0080                                                                PropagationDirection dir) const {
0081   // This method contains the sequence in which the layers are tested.
0082   // The iteration stops as soon as a layer contains the propagated state
0083   // within epsilon.
0084 
0085   vector<const DetLayer*> result;
0086 
0087   FreeTrajectoryState ftsWithoutErrors = (fts.hasError()) ? FreeTrajectoryState(fts.parameters()) : fts;
0088 
0089   auto const position = fts.position();
0090   auto const momentum = fts.momentum();
0091 
0092   //establish whether the tracks is crossing the tracker from outer layers to inner ones
0093   //or from inner to outer.
0094   GlobalVector transversePosition(position.x(), position.y(), 0);
0095   bool isInOutTrackBarrel = (transversePosition.dot(momentum) > 0);
0096 
0097   float zpos = position.z();
0098   bool isInOutTrackFWD = momentum.z() * zpos > 0;
0099 
0100   //establish whether inner or outer layers are crossed after propagation, according
0101   //to BOTH propagationDirection AND track momentum
0102   bool dirOppositeXORisInOutTrackBarrel =
0103       (!(dir == oppositeToMomentum) && isInOutTrackBarrel) || ((dir == oppositeToMomentum) && !isInOutTrackBarrel);
0104   bool dirOppositeXORisInOutTrackFWD =
0105       (!(dir == oppositeToMomentum) && isInOutTrackFWD) || ((dir == oppositeToMomentum) && !isInOutTrackFWD);
0106 
0107   LogDebug("SimpleBarrelNavigableLayer") << "is alongMomentum? " << (dir == alongMomentum) << endl
0108                                          << "isInOutTrackBarrel: " << isInOutTrackBarrel << endl
0109                                          << "isInOutTrackFWD: " << isInOutTrackFWD << endl
0110                                          << "dirOppositeXORisInOutTrackFWD: " << dirOppositeXORisInOutTrackFWD << endl
0111                                          << "dirOppositeXORisInOutTrackBarrel: " << dirOppositeXORisInOutTrackBarrel
0112                                          << endl;
0113 
0114   bool signZmomentumXORdir =
0115       (((momentum.z() > 0) && !(dir == alongMomentum)) || (!(momentum.z() > 0) && (dir == alongMomentum)));
0116 
0117   if LIKELY (dirOppositeXORisInOutTrackBarrel && dirOppositeXORisInOutTrackFWD) {
0118     if (signZmomentumXORdir) {
0119       wellInside(ftsWithoutErrors, dir, theNegOuterLayers, result);
0120     } else {
0121       wellInside(ftsWithoutErrors, dir, thePosOuterLayers, result);
0122     }
0123   } else if (!dirOppositeXORisInOutTrackBarrel && !dirOppositeXORisInOutTrackFWD) {
0124     if (signZmomentumXORdir) {
0125       wellInside(ftsWithoutErrors, dir, thePosInnerLayers, result);
0126     } else {
0127       wellInside(ftsWithoutErrors, dir, theNegInnerLayers, result);
0128     }
0129   } else if (!dirOppositeXORisInOutTrackBarrel && dirOppositeXORisInOutTrackFWD) {
0130     wellInside(ftsWithoutErrors, dir, theInnerBarrelLayers.begin(), theInnerBarrelLayers.end(), result);
0131 
0132     if (signZmomentumXORdir) {
0133       wellInside(ftsWithoutErrors, dir, theInnerLeftForwardLayers.begin(), theInnerLeftForwardLayers.end(), result);
0134       wellInside(ftsWithoutErrors, dir, theOuterLeftForwardLayers.begin(), theOuterLeftForwardLayers.end(), result);
0135     } else {
0136       wellInside(ftsWithoutErrors, dir, theInnerRightForwardLayers.begin(), theInnerRightForwardLayers.end(), result);
0137       wellInside(ftsWithoutErrors, dir, theOuterRightForwardLayers.begin(), theOuterRightForwardLayers.end(), result);
0138     }
0139   } else {
0140     if (signZmomentumXORdir) {
0141       wellInside(ftsWithoutErrors, dir, theInnerLeftForwardLayers.begin(), theInnerLeftForwardLayers.end(), result);
0142     } else {
0143       wellInside(ftsWithoutErrors, dir, theInnerRightForwardLayers.begin(), theInnerRightForwardLayers.end(), result);
0144     }
0145     wellInside(ftsWithoutErrors, dir, theOuterBarrelLayers.begin(), theOuterBarrelLayers.end(), result);
0146   }
0147 
0148   bool goingIntoTheBarrel =
0149       (!isInOutTrackBarrel && dir == alongMomentum) || (isInOutTrackBarrel && dir == oppositeToMomentum);
0150 
0151   LogDebug("SimpleBarrelNavigableLayer") << "goingIntoTheBarrel: " << goingIntoTheBarrel;
0152 
0153   if UNLIKELY (theSelfSearch && result.empty()) {
0154     if (!goingIntoTheBarrel) {
0155       LogDebug("SimpleBarrelNavigableLayer")
0156           << " state is not going toward the center of the barrel. not adding self search.";
0157     } else {
0158       const BarrelDetLayer* bl = reinterpret_cast<const BarrelDetLayer*>(detLayer());
0159       unsigned int before = result.size();
0160       LogDebug("SimpleBarrelNavigableLayer") << " I am trying to added myself as a next layer.";
0161       wellInside(ftsWithoutErrors, dir, bl, result);
0162       unsigned int after = result.size();
0163       if (before != after)
0164         LogDebug("SimpleBarrelNavigableLayer") << " I have added myself as a next layer.";
0165     }
0166   }
0167 
0168   return result;
0169 }
0170 
0171 vector<const DetLayer*> SimpleBarrelNavigableLayer::compatibleLayers(NavigationDirection dir) const {
0172   edm::LogError("TkNavigation") << "ERROR: compatibleLayers() method used without all reachableLayers are set";
0173   throw DetLayerException("compatibleLayers() method used without all reachableLayers are set");
0174   return vector<const DetLayer*>();
0175 }
0176 
0177 void SimpleBarrelNavigableLayer::setDetLayer(const DetLayer* dl) {
0178   cerr << "Warniong: SimpleBarrelNavigableLayer::setDetLayer called." << endl << "This should never happen!" << endl;
0179 }
0180 
0181 void SimpleBarrelNavigableLayer::setInwardLinks(const BDLC& theBarrelv, const FDLC& theForwardv, TkLayerLess sorter) {
0182   theInnerBarrelLayers = theBarrelv;
0183   // sort the inner layers
0184   sort(theInnerBarrelLayers.begin(), theInnerBarrelLayers.end(), sorter);
0185 
0186   ConstFDLI middle = find_if(
0187       theForwardv.begin(), theForwardv.end(), [](const GeometricSearchDet* a) { return a->position().z() >= 0.0; });
0188   theInnerLeftForwardLayers = FDLC(theForwardv.begin(), middle);
0189   theInnerRightForwardLayers = FDLC(middle, theForwardv.end());
0190 
0191   // sort the inner layers
0192   sort(theInnerLeftForwardLayers.begin(), theInnerLeftForwardLayers.end(), sorter);
0193   sort(theInnerRightForwardLayers.begin(), theInnerRightForwardLayers.end(), sorter);
0194 
0195   // put barrel and forward layers together
0196   theNegInnerLayers.reserve(theInnerBarrelLayers.size() + theInnerLeftForwardLayers.size());
0197   thePosInnerLayers.reserve(theInnerBarrelLayers.size() + theInnerRightForwardLayers.size());
0198 
0199   for (ConstBDLI bl = theInnerBarrelLayers.begin(); bl != theInnerBarrelLayers.end(); bl++)
0200     theNegInnerLayers.push_back(*bl);
0201   thePosInnerLayers = theNegInnerLayers;  // barrel part the same
0202 
0203   for (ConstFDLI fl = theInnerLeftForwardLayers.begin(); fl != theInnerLeftForwardLayers.end(); fl++)
0204     theNegInnerLayers.push_back(*fl);
0205   for (ConstFDLI fl = theInnerRightForwardLayers.begin(); fl != theInnerRightForwardLayers.end(); fl++)
0206     thePosInnerLayers.push_back(*fl);
0207 
0208   // sort the inner layers
0209   sort(theNegInnerLayers.begin(), theNegInnerLayers.end(), sorter);
0210   sort(thePosInnerLayers.begin(), thePosInnerLayers.end(), sorter);
0211   sort(theInnerBarrelLayers.begin(), theInnerBarrelLayers.end(), sorter);
0212   sort(theInnerLeftForwardLayers.begin(), theInnerLeftForwardLayers.end(), sorter);
0213   sort(theInnerRightForwardLayers.begin(), theInnerRightForwardLayers.end(), sorter);
0214 }
0215 
0216 void SimpleBarrelNavigableLayer::setAdditionalLink(const DetLayer* additional, NavigationDirection direction) {
0217   const ForwardDetLayer* fadditional = dynamic_cast<const ForwardDetLayer*>(additional);
0218   const BarrelDetLayer* badditional = dynamic_cast<const BarrelDetLayer*>(additional);
0219   if (badditional) {
0220     if (direction == insideOut) {
0221       theOuterBarrelLayers.push_back(badditional);
0222       theNegOuterLayers.push_back(badditional);
0223       thePosOuterLayers.push_back(badditional);
0224       return;
0225     }
0226     theInnerBarrelLayers.push_back(badditional);
0227     theNegInnerLayers.push_back(badditional);
0228     thePosInnerLayers.push_back(badditional);
0229     return;
0230   } else if (fadditional) {
0231     double zpos = fadditional->position().z();
0232     if (direction == insideOut) {
0233       if (zpos > 0) {
0234         theOuterRightForwardLayers.push_back(fadditional);
0235         thePosOuterLayers.push_back(fadditional);
0236         return;
0237       }
0238       theOuterLeftForwardLayers.push_back(fadditional);
0239       theNegOuterLayers.push_back(fadditional);
0240       return;
0241     }
0242     if (zpos > 0) {
0243       theInnerRightForwardLayers.push_back(fadditional);
0244       thePosInnerLayers.push_back(fadditional);
0245       return;
0246     }
0247     theInnerLeftForwardLayers.push_back(fadditional);
0248     theNegInnerLayers.push_back(fadditional);
0249     return;
0250   }
0251   edm::LogError("TkNavigation") << "trying to add neither a ForwardDetLayer nor a BarrelDetLayer";
0252   return;
0253 }