59 std::vector<GEMSegment> segments_temp;
60 std::vector<GEMSegment> segments;
68 edm::LogVerbatim(
"GEMSegmentAlgorithm") <<
"[GEMSegmentAlgorithm::run] preClustering :: use Chaining";
69 rechits_clusters = this->
chainHits(ensemble, rechits);
72 edm::LogVerbatim(
"GEMSegmentAlgorithm") <<
"[GEMSegmentAlgorithm::run] Clustering";
73 rechits_clusters = this->
clusterHits(ensemble, rechits);
76 edm::LogVerbatim(
"GEMSegmentAlgorithm") <<
"[GEMSegmentAlgorithm::run] Loop over clusters and build segments";
77 for (
auto sub_rechits = rechits_clusters.begin(); sub_rechits != rechits_clusters.end(); ++sub_rechits) {
79 segments_temp.clear();
83 segments.insert(segments.end(), segments_temp.begin(), segments_temp.end());
100 float dXclus_box = 0.0;
101 float dYclus_box = 0.0;
104 seeds.reserve(rechits.size());
106 std::vector<float> running_meanX;
107 running_meanX.reserve(rechits.size());
108 std::vector<float> running_meanY;
109 running_meanY.reserve(rechits.size());
111 std::vector<float> seed_minX;
112 seed_minX.reserve(rechits.size());
113 std::vector<float> seed_maxX;
114 seed_maxX.reserve(rechits.size());
115 std::vector<float> seed_minY;
116 seed_minY.reserve(rechits.size());
117 std::vector<float> seed_maxY;
118 seed_maxY.reserve(rechits.size());
123 for (
unsigned int i = 0;
i < rechits.size(); ++
i) {
130 <<
"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());
148 for (
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
149 for (
size_t MMM = NNN + 1; MMM < seeds.size(); ++MMM) {
151 LogDebug(
"GEMSegmentAlgorithm") <<
"[GEMSegmentAlgorithm::clusterHits]: ALARM! Skipping used seeds, this "
152 "should not happen - inform developers!";
160 if (running_meanX[NNN] > running_meanX[MMM])
161 dXclus_box = seed_minX[NNN] - seed_maxX[MMM];
163 dXclus_box = seed_minX[MMM] - seed_maxX[NNN];
164 if (running_meanY[NNN] > running_meanY[MMM])
165 dYclus_box = seed_minY[NNN] - seed_maxY[MMM];
167 dYclus_box = seed_minY[MMM] - seed_maxY[NNN];
174 if (seeds[NNN].
size() + seeds[MMM].
size() != 0) {
175 running_meanX[MMM] = (running_meanX[NNN] * seeds[NNN].size() + running_meanX[MMM] * seeds[MMM].size()) /
176 (seeds[NNN].
size() + seeds[MMM].size());
177 running_meanY[MMM] = (running_meanY[NNN] * seeds[NNN].size() + running_meanY[MMM] * seeds[MMM].size()) /
178 (seeds[NNN].
size() + seeds[MMM].size());
182 if (seed_minX[NNN] < seed_minX[MMM])
183 seed_minX[MMM] = seed_minX[NNN];
184 if (seed_maxX[NNN] > seed_maxX[MMM])
185 seed_maxX[MMM] = seed_maxX[NNN];
186 if (seed_minY[NNN] < seed_minY[MMM])
187 seed_minY[MMM] = seed_minY[NNN];
188 if (seed_maxY[NNN] > seed_maxY[MMM])
189 seed_maxY[MMM] = seed_maxY[NNN];
192 seeds[MMM].insert(seeds[MMM].
end(), seeds[NNN].
begin(), seeds[NNN].
end());
207 for (
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
210 rechits_clusters.push_back(seeds[NNN]);
213 return rechits_clusters;
220 seeds.reserve(rechits.size());
221 std::vector<bool> usedCluster(rechits.size(),
false);
226 for (
unsigned int i = 0;
i < rechits.size(); ++
i)
230 for (
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
231 for (
size_t MMM = NNN + 1; MMM < seeds.size(); ++MMM) {
232 if (usedCluster[MMM] || usedCluster[NNN]) {
246 bool goodToMerge =
isGoodToMerge(ensemble, seeds[NNN], seeds[MMM]);
252 seeds[MMM].insert(seeds[MMM].
end(), seeds[NNN].
begin(), seeds[NNN].
end());
255 usedCluster[NNN] =
true;
266 for (
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
267 if (usedCluster[NNN])
269 rechits_chains.push_back(seeds[NNN]);
274 return rechits_chains;
280 bool phiRequirementOK =
false;
281 bool etaRequirementOK =
false;
282 bool bxRequirementOK =
false;
284 for (
size_t iRH_new = 0; iRH_new < newChain.size(); ++iRH_new) {
285 int layer_new = (newChain[iRH_new]->gemId().station() - 1) * 2 + newChain[iRH_new]->gemId().layer();
290 for (
size_t iRH_old = 0; iRH_old < oldChain.size(); ++iRH_old) {
291 int layer_old = (oldChain[iRH_old]->gemId().station() - 1) * 2 + oldChain[iRH_old]->gemId().layer();
293 if (layer_new == layer_old)
300 if (phiRequirementOK ==
false)
302 if (etaRequirementOK ==
false)
306 if (bxRequirementOK ==
false) {
308 bxRequirementOK =
true;
310 if (newChain[iRH_new]->BunchX() == oldChain[iRH_old]->BunchX())
311 bxRequirementOK =
true;
315 if (phiRequirementOK && etaRequirementOK && bxRequirementOK)
324 std::vector<GEMSegment>& gemsegs) {
333 for (
auto rh = rechits.begin(); rh != rechits.end(); rh++) {
337 const GEMEtaPartition* thePartition = (ensemble.second.find((*rh)->gemId()))->second;
344 muonRecHits.push_back(trkRecHit);
347 #ifdef EDM_ML_DEBUG // have lines below only compiled when in debug mode
349 <<
"[GEMSegmentAlgorithm::buildSegments] will now try to fit a GEMSegment from collection of " << rechits.size()
351 for (
auto rh = rechits.begin(); rh != rechits.end(); ++rh) {
352 auto gemid = (*rh)->gemId();
353 auto rhLP = (*rh)->localPosition();
355 <<
"[RecHit :: Loc x = " << std::showpos << std::setw(9) << rhLP.x() <<
" Loc y = " << std::showpos
356 << std::setw(9) << rhLP.y() <<
" BX = " << std::showpos << (*rh)->BunchX() <<
" -- " << gemid.rawId() <<
" = "
362 sfit_ = std::make_unique<MuonSegFit>(muonRecHits);
363 bool goodfit =
sfit_->fit();
365 <<
"[GEMSegmentAlgorithm::buildSegments] GEMSegment fit done :: fit is good = " << goodfit;
369 for (
auto rh : muonRecHits)
377 double protoChi2 =
sfit_->chi2();
381 for (
auto rh = rechits.begin(); rh != rechits.end(); ++rh) {
382 bx += (*rh)->BunchX();
384 if (!rechits.empty())
385 bx = bx * 1.0 / (rechits.size());
413 <<
"[GEMSegmentAlgorithm::buildSegments] will now wrap fit info in GEMSegment dataformat";
418 <<
"[GEMSegmentAlgorithm::buildSegments] GEMSegment made in " << tmp.
gemDetId();
421 for (
auto rh : muonRecHits)
423 gemsegs.push_back(tmp);
std::shared_ptr< TrackingRecHit > MuonRecHitPtr
constexpr double deltaPhi(double phi1, double phi2)
Log< level::Info, true > LogVerbatim
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
constexpr uint32_t rawId() const
get the raw id
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
U second(std::pair< T, U > const &p)
bool isGoodToMerge(const GEMEnsemble &ensemble, const EnsembleHitContainer &newChain, const EnsembleHitContainer &oldChain)
unsigned int minHitsPerSegment
GEMRecHit * clone() const override
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_
GEMSegmentAlgorithm(const edm::ParameterSet &ps)
Constructor.
static constexpr float running_max
T getParameter(std::string const &) const
CLHEP::HepSymMatrix AlgebraicSymMatrix
bool clusterOnlySameBXRecHits
EnsembleHitContainer proto_segment
void setPosition(LocalPoint pos)
Set local position.
tuple size
Write out results.
std::vector< GEMSegment > run(const GEMEnsemble &ensemble, const EnsembleHitContainer &rechits) override
void buildSegments(const GEMEnsemble &ensemble, const EnsembleHitContainer &rechits, std::vector< GEMSegment > &gemsegs)