63 std::vector<GEMSegment> segments_temp;
64 std::vector<GEMSegment> segments;
72 edm::LogVerbatim(
"GEMSegmentAlgorithm") <<
"[GEMSegmentAlgorithm::run] preClustering :: use Chaining";
73 rechits_clusters = this->
chainHits(ensemble, rechits );
77 edm::LogVerbatim(
"GEMSegmentAlgorithm") <<
"[GEMSegmentAlgorithm::run] Clustering";
78 rechits_clusters = this->
clusterHits(ensemble, rechits );
81 edm::LogVerbatim(
"GEMSegmentAlgorithm") <<
"[GEMSegmentAlgorithm::run] Loop over clusters and build segments";
82 for(
auto sub_rechits = rechits_clusters.begin(); sub_rechits != rechits_clusters.end(); ++sub_rechits ) {
84 segments_temp.clear();
88 segments.insert( segments.end(), segments_temp.begin(), segments_temp.end() );
109 float dXclus_box = 0.0;
110 float dYclus_box = 0.0;
114 std::vector<float> running_meanX; running_meanX.reserve(rechits.size());
115 std::vector<float> running_meanY; running_meanY.reserve(rechits.size());
117 std::vector<float> seed_minX; seed_minX.reserve(rechits.size());
118 std::vector<float> seed_maxX; seed_maxX.reserve(rechits.size());
119 std::vector<float> seed_minY; seed_minY.reserve(rechits.size());
120 std::vector<float> seed_maxY; seed_maxY.reserve(rechits.size());
125 for(
unsigned int i = 0;
i < rechits.size(); ++
i) {
130 if(!rhEP)
throw cms::Exception(
"GEMEtaPartition not found") <<
"Corresponding GEMEtaPartition to GEMDetId: "<<rhID<<
" not found in the GEMEnsemble";
132 LocalPoint rhLP_inEtaPartFrame = rechits[
i]->localPosition();
136 running_meanX.push_back(rhLP_inChamberFrame.
x());
137 running_meanY.push_back(rhLP_inChamberFrame.
y() );
140 seed_minX.push_back( rhLP_inChamberFrame.
x() );
141 seed_maxX.push_back( rhLP_inChamberFrame.
x() );
142 seed_minY.push_back( rhLP_inChamberFrame.
y() );
143 seed_maxY.push_back( rhLP_inChamberFrame.
y() );
149 for(
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
150 for(
size_t MMM = NNN+1; MMM < seeds.size(); ++MMM) {
152 LogDebug(
"GEMSegmentAlgorithm") <<
"[GEMSegmentAlgorithm::clusterHits]: ALARM! Skipping used seeds, this should not happen - inform developers!";
160 if ( running_meanX[NNN] > running_meanX[MMM] ) dXclus_box = seed_minX[NNN] - seed_maxX[MMM];
161 else dXclus_box = seed_minX[MMM] - seed_maxX[NNN];
162 if ( running_meanY[NNN] > running_meanY[MMM] ) dYclus_box = seed_minY[NNN] - seed_maxY[MMM];
163 else dYclus_box = seed_minY[MMM] - seed_maxY[NNN];
171 if(seeds[NNN].
size()+seeds[MMM].
size() != 0) {
172 running_meanX[MMM] = (running_meanX[NNN]*seeds[NNN].size() + running_meanX[MMM]*seeds[MMM].size()) / (seeds[NNN].
size()+seeds[MMM].size());
173 running_meanY[MMM] = (running_meanY[NNN]*seeds[NNN].size() + running_meanY[MMM]*seeds[MMM].size()) / (seeds[NNN].
size()+seeds[MMM].size());
177 if ( seed_minX[NNN] < seed_minX[MMM] ) seed_minX[MMM] = seed_minX[NNN];
178 if ( seed_maxX[NNN] > seed_maxX[MMM] ) seed_maxX[MMM] = seed_maxX[NNN];
179 if ( seed_minY[NNN] < seed_minY[MMM] ) seed_minY[MMM] = seed_minY[NNN];
180 if ( seed_maxY[NNN] > seed_maxY[MMM] ) seed_maxY[MMM] = seed_maxY[NNN];
183 seeds[MMM].insert(seeds[MMM].
end(),seeds[NNN].
begin(),seeds[NNN].
end());
198 for(
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
200 rechits_clusters.push_back(seeds[NNN]);
203 return rechits_clusters;
212 seeds.reserve(rechits.size());
213 std::vector<bool> usedCluster(rechits.size(),
false);
218 for (
unsigned int i=0;
i<rechits.size(); ++
i)
222 for(
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
223 for(
size_t MMM = NNN+1; MMM < seeds.size(); ++MMM) {
224 if(usedCluster[MMM] || usedCluster[NNN]){
238 bool goodToMerge =
isGoodToMerge(ensemble, seeds[NNN], seeds[MMM]);
244 seeds[MMM].insert(seeds[MMM].
end(),seeds[NNN].
begin(),seeds[NNN].
end());
247 usedCluster[NNN] =
true;
259 for(
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
260 if(usedCluster[NNN])
continue;
261 rechits_chains.push_back(seeds[NNN]);
266 return rechits_chains;
271 bool phiRequirementOK =
false;
272 bool etaRequirementOK =
false;
273 bool bxRequirementOK =
false;
275 for(
size_t iRH_new = 0;iRH_new<newChain.size();++iRH_new){
276 int layer_new = (newChain[iRH_new]->gemId().station() - 1)*2 + newChain[iRH_new]->gemId().layer();
281 for(
size_t iRH_old = 0;iRH_old<oldChain.size();++iRH_old){
282 int layer_old = (oldChain[iRH_old]->gemId().station() - 1)*2 + oldChain[iRH_old]->gemId().layer();
284 if ( layer_new == layer_old )
return false;
286 const GEMEtaPartition * oldrhEP = (ensemble.second.find(oldChain[iRH_old]->gemId().rawId()))->
second;
294 if(bxRequirementOK==
false) {
296 bxRequirementOK =
true;
299 if (newChain[iRH_new]->BunchX() == oldChain[iRH_old]->BunchX()) bxRequirementOK =
true;
303 if( phiRequirementOK && etaRequirementOK && bxRequirementOK)
318 for (
auto rh=rechits.begin(); rh!=rechits.end();rh++){
322 const GEMEtaPartition * thePartition = (ensemble.second.find((*rh)->gemId()))->second;
329 muonRecHits.push_back(trkRecHit);
332 #ifdef EDM_ML_DEBUG // have lines below only compiled when in debug mode 333 edm::LogVerbatim(
"GEMSegmentAlgorithm") <<
"[GEMSegmentAlgorithm::buildSegments] will now try to fit a GEMSegment from collection of "<<rechits.size()<<
" GEM RecHits";
334 for (
auto rh=rechits.begin(); rh!=rechits.end(); ++rh){
335 auto gemid = (*rh)->gemId();
336 auto rhLP = (*rh)->localPosition();
337 edm::LogVerbatim(
"GEMSegmentAlgorithm") <<
"[RecHit :: Loc x = "<<std::showpos<<std::setw(9)<<rhLP.x()<<
" Loc y = "<<std::showpos<<std::setw(9)<<rhLP.y()
338 <<
" BX = "<<std::showpos<<(*rh)->BunchX()<<
" -- "<<gemid.rawId()<<
" = "<<gemid<<
" ]";
343 sfit_ = std::make_unique<MuonSegFit>(muonRecHits);
344 bool goodfit =
sfit_->fit();
345 edm::LogVerbatim(
"GEMSegmentAlgorithm") <<
"[GEMSegmentAlgorithm::buildSegments] GEMSegment fit done :: fit is good = "<<goodfit;
349 for (
auto rh:muonRecHits) rh.reset();
356 double protoChi2 =
sfit_->chi2();
360 for (
auto rh=rechits.begin(); rh!=rechits.end(); ++rh){
361 bx += (*rh)->BunchX();
363 if(!rechits.empty()) bx=bx*1.0/(rechits.size());
390 edm::LogVerbatim(
"GEMSegmentAlgorithm") <<
"[GEMSegmentAlgorithm::buildSegments] will now wrap fit info in GEMSegment dataformat";
394 edm::LogVerbatim(
"GEMSegmentAlgorithm") <<
"[GEMSegmentAlgorithm::buildSegments] GEMSegment made in "<<tmp.
gemDetId();
397 for (
auto rh:muonRecHits) rh.reset();
398 gemsegs.push_back(tmp);
std::shared_ptr< TrackingRecHit > MuonRecHitPtr
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
bool preClustering_useChaining
GEMDetId gemDetId() const
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
~GEMSegmentAlgorithm() override
Destructor.
ProtoSegments chainHits(const GEMEnsemble &ensemble, const EnsembleHitContainer &rechits)
std::vector< const GEMRecHit * > EnsembleHitContainer
Typedefs.
Geom::Phi< T > phi() const
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
std::pair< const GEMSuperChamber *, std::map< uint32_t, const GEMEtaPartition * > > GEMEnsemble
uint32_t rawId() const
get the raw id
U second(std::pair< T, U > const &p)
bool isGoodToMerge(const GEMEnsemble &ensemble, const EnsembleHitContainer &newChain, const EnsembleHitContainer &oldChain)
unsigned int minHitsPerSegment
std::vector< MuonRecHitPtr > MuonRecHitContainer
ProtoSegments clusterHits(const GEMEnsemble &ensemble, const EnsembleHitContainer &rechits)
Utility functions.
Abs< T >::type abs(const T &t)
std::vector< EnsembleHitContainer > ProtoSegments
std::unique_ptr< MuonSegFit > sfit_
double deltaPhi(double phi1, double phi2)
GEMSegmentAlgorithm(const edm::ParameterSet &ps)
Constructor.
GEMRecHit * clone() const override
std::vector< std::vector< double > > tmp
CLHEP::HepSymMatrix AlgebraicSymMatrix
bool clusterOnlySameBXRecHits
EnsembleHitContainer proto_segment
void setPosition(LocalPoint pos)
Set local position.
std::vector< GEMSegment > run(const GEMEnsemble &ensemble, const EnsembleHitContainer &rechits) override
void buildSegments(const GEMEnsemble &ensemble, const EnsembleHitContainer &rechits, std::vector< GEMSegment > &gemsegs)