Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:19:27

0001 #include "RecoLocalMuon/GEMSegment/plugins/ME0SegmentBuilder.h"
0002 #include "DataFormats/MuonDetId/interface/ME0DetId.h"
0003 #include "DataFormats/GEMRecHit/interface/ME0RecHit.h"
0004 #include "Geometry/GEMGeometry/interface/ME0Geometry.h"
0005 #include "Geometry/GEMGeometry/interface/ME0EtaPartition.h"
0006 #include "Geometry/GEMGeometry/interface/ME0Chamber.h"
0007 #include "RecoLocalMuon/GEMSegment/plugins/ME0SegmentAlgorithmBase.h"
0008 #include "RecoLocalMuon/GEMSegment/plugins/ME0SegmentBuilderPluginFactory.h"
0009 
0010 #include "FWCore/Utilities/interface/Exception.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 
0013 ME0SegmentBuilder::ME0SegmentBuilder(const edm::ParameterSet& ps) : geom_(nullptr) {
0014   // Algo type (indexed)
0015   int chosenAlgo = ps.getParameter<int>("algo_type") - 1;
0016   // Find appropriate ParameterSets for each algo type
0017 
0018   std::vector<edm::ParameterSet> algoPSets = ps.getParameter<std::vector<edm::ParameterSet> >("algo_psets");
0019 
0020   edm::ParameterSet segAlgoPSet = algoPSets[chosenAlgo].getParameter<edm::ParameterSet>("algo_pset");
0021   std::string algoName = algoPSets[chosenAlgo].getParameter<std::string>("algo_name");
0022   LogDebug("ME0SegmentBuilder") << "ME0SegmentBuilder algorithm name: " << algoName;
0023 
0024   // Ask factory to build this algorithm, giving it appropriate ParameterSet
0025   algo = ME0SegmentBuilderPluginFactory::get()->create(algoName, segAlgoPSet);
0026 }
0027 
0028 ME0SegmentBuilder::~ME0SegmentBuilder() {}
0029 
0030 void ME0SegmentBuilder::build(const ME0RecHitCollection* recHits, ME0SegmentCollection& oc) {
0031   LogDebug("ME0SegmentBuilder") << "Total number of rechits in this event: " << recHits->size();
0032 
0033   std::map<ME0DetId, bool> foundChambers;
0034   for (ME0RecHitCollection::const_iterator it = recHits->begin(); it != recHits->end(); it++) {
0035     const auto chId = it->me0Id().chamberId();
0036     auto chIt = foundChambers.find(chId);
0037     if (chIt != foundChambers.end())
0038       continue;
0039     foundChambers[chId] = true;
0040     ME0SegmentAlgorithmBase::HitAndPositionContainer hitAndPositions;
0041     const ME0Chamber* chamber = geom_->chamber(chId);
0042     for (ME0RecHitCollection::const_iterator it2 = it; it2 != recHits->end(); it2++) {
0043       if (it2->me0Id().chamberId() != chId)
0044         continue;
0045 
0046       const auto* part = geom_->etaPartition(it2->me0Id());
0047       GlobalPoint glb = part->toGlobal(it2->localPosition());
0048       LocalPoint nLoc = chamber->toLocal(glb);
0049       hitAndPositions.emplace_back(&(*it2), nLoc, glb, hitAndPositions.size());
0050     }
0051 
0052     LogDebug("ME0Segment|ME0") << "found " << hitAndPositions.size() << " rechits in chamber " << chId;
0053     //sort by layer
0054     auto getLayer = [&](int iL) -> const ME0Layer* {  //function is broken in the geo currently
0055       for (auto layer : chamber->layers()) {
0056         if (layer->id().layer() == iL)
0057           return layer;
0058       }
0059       return nullptr;
0060     };
0061     float z1 = getLayer(1)->position().z();
0062     float z6 = getLayer(6)->position().z();
0063     if (z1 < z6)
0064       std::sort(hitAndPositions.begin(),
0065                 hitAndPositions.end(),
0066                 [](const ME0SegmentAlgorithmBase::HitAndPosition& h1,
0067                    const ME0SegmentAlgorithmBase::HitAndPosition& h2) { return h1.layer < h2.layer; });
0068     else
0069       std::sort(hitAndPositions.begin(),
0070                 hitAndPositions.end(),
0071                 [](const ME0SegmentAlgorithmBase::HitAndPosition& h1,
0072                    const ME0SegmentAlgorithmBase::HitAndPosition& h2) { return h1.layer > h2.layer; });
0073 
0074     // given the chamber select the appropriate algo... and run it
0075     std::vector<ME0Segment> segv = algo->run(chamber, hitAndPositions);
0076 
0077     LogDebug("ME0Segment|ME0") << "found " << segv.size() << " segments in chamber " << chId;
0078 
0079     // Add the segments to master collection
0080     if (!segv.empty())
0081       oc.put(chId, segv.begin(), segv.end());
0082   }
0083 }
0084 
0085 void ME0SegmentBuilder::setGeometry(const ME0Geometry* geom) { geom_ = geom; }