Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:31:54

0001 #include "TrackingTools/TransientTrackingRecHit/interface/SeedingLayerSetsHits.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 #include <algorithm>
0006 #include <limits>
0007 #include <sstream>
0008 
0009 SeedingLayerSetsHits::SeedingLayerSetsHits(unsigned short nlayers,
0010                                            const std::vector<LayerSetIndex> *layerSetIndices,
0011                                            const std::vector<std::string> *layerNames,
0012                                            const std::vector<const DetLayer *> *layerDets)
0013     : nlayers_(nlayers), layerSetIndices_(layerSetIndices), layerNames_(layerNames), layerDets_(layerDets) {
0014   layerHitIndices_.reserve(layerNames->size());
0015 }
0016 
0017 void SeedingLayerSetsHits::shrink_to_fit() { rechits_.shrink_to_fit(); }
0018 
0019 void SeedingLayerSetsHits::addHits(LayerIndex layerIndex, OwnedHits &&hits) {
0020   if (layerIndex != layerHitIndices_.size()) {
0021     throw cms::Exception("Assert")
0022         << "SeedingLayerSetsHits::addHits() must be called in the order of the layers, got layer " << layerIndex
0023         << " while was expecting " << layerHitIndices_.size();
0024   }
0025 
0026   layerHitIndices_.push_back(rechits_.size());
0027   std::move(hits.begin(), hits.end(), std::back_inserter(rechits_));
0028 }
0029 
0030 SeedingLayerSetsHits::Hits SeedingLayerSetsHits::hits(LayerIndex layerIndex) const {
0031   HitIndex begin = layerHitIndices_[layerIndex];
0032   ++layerIndex;
0033   HitIndex end = layerIndex < layerHitIndices_.size() ? layerHitIndices_[layerIndex] : rechits_.size();
0034 
0035   Hits ret;
0036   ret.reserve(end - begin);
0037   std::transform(rechits_.begin() + begin, rechits_.begin() + end, std::back_inserter(ret), [](HitPointer const &p) {
0038     return p.get();
0039   });
0040   return ret;
0041 }
0042 
0043 void SeedingLayerSetsHits::print() const {
0044   std::stringstream ss;
0045   ss << "SeedingLayerSetsHits with " << numberOfLayersInSet() << " layers in each LayerSets, LayerSets has " << size()
0046      << " items\n";
0047   for (LayerSetIndex iLayers = 0; iLayers < size(); ++iLayers) {
0048     ss << " " << iLayers << ": ";
0049     SeedingLayerSet layers = operator[](iLayers);
0050     for (unsigned iLayer = 0; iLayer < layers.size(); ++iLayer) {
0051       SeedingLayer layer = layers[iLayer];
0052       ss << layer.name() << " (" << layer.index() << ", nhits " << layer.hits().size() << ") ";
0053     }
0054     ss << "\n";
0055   }
0056   LogDebug("SeedingLayerSetsHits") << ss.str();
0057 }