Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-09 04:50:31

0001 #include "RecoLocalMuon/GEMSegment/plugins/GEMSegmentBuilder.h"
0002 #include "DataFormats/MuonDetId/interface/GEMDetId.h"
0003 #include "DataFormats/GEMRecHit/interface/GEMRecHit.h"
0004 #include "Geometry/GEMGeometry/interface/GEMGeometry.h"
0005 #include "Geometry/GEMGeometry/interface/GEMEtaPartition.h"
0006 #include "RecoLocalMuon/GEMSegment/plugins/GEMSegmentAlgorithmBase.h"
0007 #include "RecoLocalMuon/GEMSegment/plugins/GEMSegmentBuilderPluginFactory.h"
0008 
0009 #include "FWCore/Utilities/interface/Exception.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 
0012 GEMSegmentBuilder::GEMSegmentBuilder(const edm::ParameterSet& ps) : geom_(nullptr) {
0013   // Algo name
0014   segAlgoName = ps.getParameter<std::string>("algo_name");
0015   ge0AlgoName = ps.getParameter<std::string>("ge0_name");
0016 
0017   edm::LogVerbatim("GEMSegmentBuilder") << "GEMSegmentBuilder algorithm : ge0 name : " << ge0AlgoName
0018                                         << " name: " << segAlgoName;
0019 
0020   // SegAlgo parameter set
0021   segAlgoPSet = ps.getParameter<edm::ParameterSet>("algo_pset");
0022   ge0AlgoPSet = ps.getParameter<edm::ParameterSet>("ge0_pset");
0023 
0024   // Ask factory to build these algorithms, giving them the appropriate ParameterSets
0025   segAlgo = GEMSegmentBuilderPluginFactory::get()->create(segAlgoName, segAlgoPSet);
0026   ge0Algo = GEMSegmentBuilderPluginFactory::get()->create(ge0AlgoName, ge0AlgoPSet);
0027 }
0028 GEMSegmentBuilder::~GEMSegmentBuilder() {}
0029 
0030 void GEMSegmentBuilder::build(const GEMRecHitCollection* recHits, GEMSegmentCollection& oc) {
0031   edm::LogVerbatim("GEMSegmentBuilder") << "[GEMSegmentBuilder::build] Total number of rechits in this event: "
0032                                         << recHits->size();
0033 
0034   // Let's define the ensemble of GEM devices having the same region, chambers number (phi)
0035   // different eta partitions and different layers are allowed
0036 
0037   std::map<uint32_t, std::vector<const GEMRecHit*> > ensembleRH;
0038 
0039   // Loop on the GEM rechit and select the different GEM Ensemble
0040   for (GEMRecHitCollection::const_iterator it2 = recHits->begin(); it2 != recHits->end(); ++it2) {
0041     // GEM Ensemble is defined by assigning all the GEMDetIds of the same "superchamber"
0042     // (i.e. region same, chamber same) to the DetId of the first layer
0043 
0044     // here a reference GEMDetId is created: named "id"
0045     // - Ring 1 (no other rings available for GEM)
0046     // - Layer 1 = reference layer (effective layermask)
0047     // - Roll 0  = reference roll  (effective rollmask)
0048     // - Station == 1 (GE1/1) or == 2 (GE2/1)
0049     // this reference id serves to link all GEMEtaPartitions
0050     // and will also be used to determine the GEMSuperChamber
0051     // to which the GEMSegment is assigned (done inside GEMSegAlgoXX)
0052     GEMDetId id(it2->gemId().superChamberId());
0053     // save current GEMRecHit in vector associated to the reference id
0054     ensembleRH[id.rawId()].push_back(&(*it2));
0055   }
0056 
0057   // Loop on the entire map <ref id, vector of GEMRecHits>
0058   for (auto enIt = ensembleRH.begin(); enIt != ensembleRH.end(); ++enIt) {
0059     std::vector<const GEMRecHit*> gemRecHits;
0060     std::map<uint32_t, const GEMEtaPartition*> ens;
0061 
0062     // all detIds have been assigned to the to chamber
0063     const GEMSuperChamber* chamber = geom_->superChamber(enIt->first);
0064     for (auto rechit = enIt->second.begin(); rechit != enIt->second.end(); ++rechit) {
0065       gemRecHits.push_back(*rechit);
0066       ens[(*rechit)->gemId()] = geom_->etaPartition((*rechit)->gemId());
0067     }
0068 
0069 #ifdef EDM_ML_DEBUG  // have lines below only compiled when in debug mode
0070     LogTrace("GEMSegmentBuilder")
0071         << "[GEMSegmentBuilder::build] -----------------------------------------------------------------------------";
0072     LogTrace("GEMSegmentBuilder") << "[GEMSegmentBuilder::build] found " << gemRecHits.size()
0073                                   << " rechits in GEM Super Chamber " << chamber->id() << " ::";
0074     for (auto rh = gemRecHits.begin(); rh != gemRecHits.end(); ++rh) {
0075       auto gemid = (*rh)->gemId();
0076       // auto rhr = gemGeom->etaPartition(gemid);
0077       auto rhLP = (*rh)->localPosition();
0078       // auto rhGP = rhr->toGlobal(rhLP);
0079       // no sense to print local y because local y here is in the roll reference frame
0080       // in the roll reference frame the local y of a rechit is always the middle of the roll, and hence equal to 0.0
0081       LogTrace("GEMSegmentBuilder") << "[RecHit :: Loc x = " << std::showpos << std::setw(9)
0082                                     << rhLP.x() /*<<" Loc y = "<<std::showpos<<std::setw(9)<<rhLP.y()*/
0083                                     << " BX = " << (*rh)->BunchX() << " -- " << gemid.rawId() << " = " << gemid << " ]";
0084     }
0085 #endif
0086 
0087     GEMSegmentAlgorithmBase::GEMEnsemble ensemble(
0088         std::pair<const GEMSuperChamber*, std::map<uint32_t, const GEMEtaPartition*> >(chamber, ens));
0089 
0090 #ifdef EDM_ML_DEBUG  // have lines below only compiled when in debug mode
0091     LogTrace("GEMSegmentBuilder") << "[GEMSegmentBuilder::build] run the segment reconstruction algorithm now";
0092 #endif
0093 
0094     // given the superchamber select the appropriate algo... and run it
0095     std::vector<GEMSegment> segv;
0096     if (chamber->id().station() == 0)
0097       segv = ge0Algo->run(ensemble, gemRecHits);
0098     else
0099       segv = segAlgo->run(ensemble, gemRecHits);
0100 #ifdef EDM_ML_DEBUG  // have lines below only compiled when in debug mode
0101     LogTrace("GEMSegmentBuilder") << "[GEMSegmentBuilder::build] found " << segv.size();
0102 #endif
0103 
0104     GEMDetId mid(enIt->first);
0105 
0106 #ifdef EDM_ML_DEBUG  // have lines below only compiled when in debug mode
0107     LogTrace("GEMSegmentBuilder") << "[GEMSegmentBuilder::build] found " << segv.size()
0108                                   << " segments in GEM Super Chamber " << mid;
0109     LogTrace("GEMSegmentBuilder")
0110         << "[GEMSegmentBuilder::build] -----------------------------------------------------------------------------";
0111 #endif
0112 
0113     // Add the segments to master collection
0114     oc.put(mid, segv.begin(), segv.end());
0115   }
0116 }
0117 
0118 void GEMSegmentBuilder::setGeometry(const GEMGeometry* geom) { geom_ = geom; }