Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-12-15 05:38:04

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   // Segment building selection
0014   enableGE0 = ps.getParameter<bool>("enableGE0");
0015   enableGE12 = ps.getParameter<bool>("enableGE12");
0016 
0017   // Algo name
0018   segAlgoName = ps.getParameter<std::string>("algo_name");
0019   ge0AlgoName = ps.getParameter<std::string>("ge0_name");
0020 
0021   edm::LogVerbatim("GEMSegmentBuilder") << "GEMSegmentBuilder algorithm : ge0 name : " << ge0AlgoName
0022                                         << " name: " << segAlgoName;
0023 
0024   // SegAlgo parameter set
0025   segAlgoPSet = ps.getParameter<edm::ParameterSet>("algo_pset");
0026   ge0AlgoPSet = ps.getParameter<edm::ParameterSet>("ge0_pset");
0027 
0028   // Ask factory to build these algorithms, giving them the appropriate ParameterSets
0029   segAlgo = GEMSegmentBuilderPluginFactory::get()->create(segAlgoName, segAlgoPSet);
0030   ge0Algo = GEMSegmentBuilderPluginFactory::get()->create(ge0AlgoName, ge0AlgoPSet);
0031 }
0032 GEMSegmentBuilder::~GEMSegmentBuilder() {}
0033 
0034 void GEMSegmentBuilder::fillDescription(edm::ParameterSetDescription& desc) {
0035   desc.add<bool>("enableGE0", true);
0036   desc.add<bool>("enableGE12", false);
0037   desc.add<std::string>("ge0_name", "GE0SegAlgoRU");
0038   desc.add<std::string>("algo_name", "GEMSegmentAlgorithm");
0039 
0040   edm::ParameterSetDescription ge0AlgoConfigDesc;
0041   ge0AlgoConfigDesc.add<bool>("allowWideSegments", true);
0042   ge0AlgoConfigDesc.add<bool>("doCollisions", true);
0043   ge0AlgoConfigDesc.add<double>("maxChi2Additional", 100);
0044   ge0AlgoConfigDesc.add<double>("maxChi2Prune", 50);
0045   ge0AlgoConfigDesc.add<double>("maxChi2GoodSeg", 50);
0046   ge0AlgoConfigDesc.add<double>("maxPhiSeeds", 0.001096605744)->setComment("Assuming 384 strips");
0047   ge0AlgoConfigDesc.add<double>("maxPhiAdditional", 0.001096605744)->setComment("Assuming 384 strips");
0048   ge0AlgoConfigDesc.add<double>("maxETASeeds", 0.1)->setComment("Assuming 8 eta partitions");
0049   ge0AlgoConfigDesc.add<double>("maxTOFDiff", 25);
0050   ge0AlgoConfigDesc.add<bool>("requireCentralBX", true)
0051       ->setComment("require that a majority of hits come from central BX");
0052   ge0AlgoConfigDesc.add<unsigned int>("minNumberOfHits", 4);
0053   ge0AlgoConfigDesc.add<unsigned int>("maxNumberOfHits", 300);
0054   ge0AlgoConfigDesc.add<unsigned int>("maxNumberOfHitsPerLayer", 100);
0055   desc.add<edm::ParameterSetDescription>("ge0_pset", ge0AlgoConfigDesc);
0056 
0057   edm::ParameterSetDescription recAlgoConfigDesc;
0058   recAlgoConfigDesc.addUntracked<bool>("GEMDebug", false);
0059   recAlgoConfigDesc.add<unsigned int>("minHitsPerSegment", 2);
0060   recAlgoConfigDesc.add<bool>("preClustering", true)
0061       ->setComment("False => all hits in chamber are given to the fitter");
0062   recAlgoConfigDesc.add<double>("dXclusBoxMax", 1)->setComment("Clstr Hit dPhi");
0063   recAlgoConfigDesc.add<double>("dYclusBoxMax", 5)->setComment("Clstr Hit dEta");
0064   recAlgoConfigDesc.add<bool>("preClusteringUseChaining", true)
0065       ->setComment("True ==> use Chaining() , False ==> use Clustering() Fnct");
0066   recAlgoConfigDesc.add<double>("dPhiChainBoxMax", .02)->setComment("Chain Hit dPhi");
0067   recAlgoConfigDesc.add<double>("dEtaChainBoxMax", .05)->setComment("Chain Hit dEta");
0068   recAlgoConfigDesc.add<int>("maxRecHitsInCluster", 4)->setComment("Does 4 make sense here?");
0069   recAlgoConfigDesc.add<bool>("clusterOnlySameBXRecHits", true)
0070       ->setComment("only working for (preClustering && preClusteringUseChaining)");
0071   desc.add<edm::ParameterSetDescription>("algo_pset", recAlgoConfigDesc);
0072 }
0073 
0074 void GEMSegmentBuilder::build(const GEMRecHitCollection* recHits, GEMSegmentCollection& oc) {
0075   edm::LogVerbatim("GEMSegmentBuilder") << "[GEMSegmentBuilder::build] Total number of rechits in this event: "
0076                                         << recHits->size();
0077 
0078   // Let's define the ensemble of GEM devices having the same region, chambers number (phi)
0079   // different eta partitions and different layers are allowed
0080 
0081   std::map<uint32_t, std::vector<const GEMRecHit*> > ensembleRH;
0082 
0083   // Loop on the GEM rechit and select the different GEM Ensemble
0084   for (GEMRecHitCollection::const_iterator it2 = recHits->begin(); it2 != recHits->end(); ++it2) {
0085     // GEM Ensemble is defined by assigning all the GEMDetIds of the same "superchamber"
0086     // (i.e. region same, chamber same) to the DetId of the first layer
0087 
0088     // here a reference GEMDetId is created: named "id"
0089     // - Ring 1 (no other rings available for GEM)
0090     // - Layer 1 = reference layer (effective layermask)
0091     // - Roll 0  = reference roll  (effective rollmask)
0092     // - Station == 1 (GE1/1) or == 2 (GE2/1)
0093     // this reference id serves to link all GEMEtaPartitions
0094     // and will also be used to determine the GEMSuperChamber
0095     // to which the GEMSegment is assigned (done inside GEMSegAlgoXX)
0096     GEMDetId id(it2->gemId().superChamberId());
0097     // save current GEMRecHit in vector associated to the reference id
0098     ensembleRH[id.rawId()].push_back(&(*it2));
0099   }
0100 
0101   // Loop on the entire map <ref id, vector of GEMRecHits>
0102   for (auto enIt = ensembleRH.begin(); enIt != ensembleRH.end(); ++enIt) {
0103     std::vector<const GEMRecHit*> gemRecHits;
0104     std::map<uint32_t, const GEMEtaPartition*> ens;
0105 
0106     // all detIds have been assigned to the to chamber
0107     const GEMSuperChamber* chamber = geom_->superChamber(enIt->first);
0108     for (auto rechit = enIt->second.begin(); rechit != enIt->second.end(); ++rechit) {
0109       gemRecHits.push_back(*rechit);
0110       ens[(*rechit)->gemId()] = geom_->etaPartition((*rechit)->gemId());
0111     }
0112 
0113 #ifdef EDM_ML_DEBUG  // have lines below only compiled when in debug mode
0114     LogTrace("GEMSegmentBuilder")
0115         << "[GEMSegmentBuilder::build] -----------------------------------------------------------------------------";
0116     LogTrace("GEMSegmentBuilder") << "[GEMSegmentBuilder::build] found " << gemRecHits.size()
0117                                   << " rechits in GEM Super Chamber " << chamber->id() << " ::";
0118     for (auto rh = gemRecHits.begin(); rh != gemRecHits.end(); ++rh) {
0119       auto gemid = (*rh)->gemId();
0120       // auto rhr = gemGeom->etaPartition(gemid);
0121       auto rhLP = (*rh)->localPosition();
0122       // auto rhGP = rhr->toGlobal(rhLP);
0123       // no sense to print local y because local y here is in the roll reference frame
0124       // in the roll reference frame the local y of a rechit is always the middle of the roll, and hence equal to 0.0
0125       LogTrace("GEMSegmentBuilder") << "[RecHit :: Loc x = " << std::showpos << std::setw(9)
0126                                     << rhLP.x() /*<<" Loc y = "<<std::showpos<<std::setw(9)<<rhLP.y()*/
0127                                     << " BX = " << (*rh)->BunchX() << " -- " << gemid.rawId() << " = " << gemid << " ]";
0128     }
0129 #endif
0130 
0131     GEMSegmentAlgorithmBase::GEMEnsemble ensemble(
0132         std::pair<const GEMSuperChamber*, std::map<uint32_t, const GEMEtaPartition*> >(chamber, ens));
0133 
0134 #ifdef EDM_ML_DEBUG  // have lines below only compiled when in debug mode
0135     LogTrace("GEMSegmentBuilder") << "[GEMSegmentBuilder::build] run the segment reconstruction algorithm now";
0136 #endif
0137 
0138     // given the superchamber select the appropriate algo... and run it
0139     std::vector<GEMSegment> segv;
0140     if (enableGE0 and chamber->id().station() == 0)
0141       segv = ge0Algo->run(ensemble, gemRecHits);
0142     else if (enableGE12)
0143       segv = segAlgo->run(ensemble, gemRecHits);
0144 #ifdef EDM_ML_DEBUG  // have lines below only compiled when in debug mode
0145     LogTrace("GEMSegmentBuilder") << "[GEMSegmentBuilder::build] found " << segv.size();
0146 #endif
0147 
0148     GEMDetId mid(enIt->first);
0149 
0150 #ifdef EDM_ML_DEBUG  // have lines below only compiled when in debug mode
0151     LogTrace("GEMSegmentBuilder") << "[GEMSegmentBuilder::build] found " << segv.size()
0152                                   << " segments in GEM Super Chamber " << mid;
0153     LogTrace("GEMSegmentBuilder")
0154         << "[GEMSegmentBuilder::build] -----------------------------------------------------------------------------";
0155 #endif
0156 
0157     // Add the segments to master collection
0158     oc.put(mid, segv.begin(), segv.end());
0159   }
0160 }
0161 
0162 void GEMSegmentBuilder::setGeometry(const GEMGeometry* geom) { geom_ = geom; }