39 <<
"[ME0SegmentAlgorithm::ctor] Parameters to build segments :: "
40 <<
"preClustering = " << preClustering <<
" preClustering_useChaining = " << preClustering_useChaining
41 <<
" dPhiChainBoxMax = " << dPhiChainBoxMax <<
" dEtaChainBoxMax = " << dEtaChainBoxMax
42 <<
" dTimeChainBoxMax = " << dTimeChainBoxMax <<
" minHitsPerSegment = " << minHitsPerSegment
52 #ifdef EDM_ML_DEBUG // have lines below only compiled when in debug mode
54 edm::LogVerbatim(
"ME0SegAlgoMM") <<
"[ME0SegmentAlgorithm::run] build segments in chamber " << chId
55 <<
" which contains " << rechits.size() <<
" rechits";
56 for (
auto rh = rechits.begin(); rh != rechits.end(); ++rh) {
57 auto me0id = rh->rh->me0Id();
60 <<
"[RecHit :: Loc x = " << std::showpos << std::setw(9) << rhLP.x() <<
" Loc y = " << std::showpos
61 << std::setw(9) << rhLP.y() <<
" Time = " << std::showpos << rh->rh->tof() <<
" -- " << me0id.rawId() <<
" = "
67 std::vector<ME0Segment> segments_temp;
68 std::vector<ME0Segment> segments;
76 rechits_clusters = this->
chainHits(chamber, rechits);
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());
93 ptrRH.reserve(rechits.size());
94 for (
const auto& rh : rechits)
105 float dXclus_box = 0.0;
106 float dYclus_box = 0.0;
109 seeds.reserve(rechits.size());
111 std::vector<float> running_meanX;
112 running_meanX.reserve(rechits.size());
113 std::vector<float> running_meanY;
114 running_meanY.reserve(rechits.size());
116 std::vector<float> seed_minX;
117 seed_minX.reserve(rechits.size());
118 std::vector<float> seed_maxX;
119 seed_maxX.reserve(rechits.size());
120 std::vector<float> seed_minY;
121 seed_minY.reserve(rechits.size());
122 std::vector<float> seed_maxY;
123 seed_maxY.reserve(rechits.size());
128 for (
unsigned int i = 0;
i < rechits.size(); ++
i) {
134 running_meanX.push_back(rechits[i].lp.x());
135 running_meanY.push_back(rechits[i].lp.y());
138 seed_minX.push_back(rechits[i].lp.x());
139 seed_maxX.push_back(rechits[i].lp.x());
140 seed_minY.push_back(rechits[i].lp.y());
141 seed_maxY.push_back(rechits[i].lp.y());
146 for (
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
147 for (
size_t MMM = NNN + 1; MMM < seeds.size(); ++MMM) {
149 LogDebug(
"ME0SegmentAlgorithm") <<
"[ME0SegmentAlgorithm::clusterHits]: ALARM! Skipping used seeds, this "
150 "should not happen - inform developers!";
158 if (running_meanX[NNN] > running_meanX[MMM])
159 dXclus_box = seed_minX[NNN] - seed_maxX[MMM];
161 dXclus_box = seed_minX[MMM] - seed_maxX[NNN];
162 if (running_meanY[NNN] > running_meanY[MMM])
163 dYclus_box = seed_minY[NNN] - seed_maxY[MMM];
165 dYclus_box = seed_minY[MMM] - seed_maxY[NNN];
172 if (seeds[NNN].
size() + seeds[MMM].
size() != 0) {
173 running_meanX[MMM] = (running_meanX[NNN] * seeds[NNN].size() + running_meanX[MMM] * seeds[MMM].size()) /
174 (seeds[NNN].
size() + seeds[MMM].size());
175 running_meanY[MMM] = (running_meanY[NNN] * seeds[NNN].size() + running_meanY[MMM] * seeds[MMM].size()) /
176 (seeds[NNN].
size() + seeds[MMM].size());
180 if (seed_minX[NNN] < seed_minX[MMM])
181 seed_minX[MMM] = seed_minX[NNN];
182 if (seed_maxX[NNN] > seed_maxX[MMM])
183 seed_maxX[MMM] = seed_maxX[NNN];
184 if (seed_minY[NNN] < seed_minY[MMM])
185 seed_minY[MMM] = seed_minY[NNN];
186 if (seed_maxY[NNN] > seed_maxY[MMM])
187 seed_maxY[MMM] = seed_maxY[NNN];
190 seeds[MMM].insert(seeds[MMM].
end(), seeds[NNN].
begin(), seeds[NNN].
end());
205 for (
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
208 rechits_clusters.push_back(seeds[NNN]);
211 return rechits_clusters;
218 seeds.reserve(rechits.size());
219 std::vector<bool> usedCluster(rechits.size(),
false);
224 for (
unsigned int i = 0;
i < rechits.size(); ++
i) {
231 for (
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
232 for (
size_t MMM = NNN + 1; MMM < seeds.size(); ++MMM) {
233 if (usedCluster[MMM] || usedCluster[NNN]) {
247 bool goodToMerge =
isGoodToMerge(chamber, seeds[NNN], seeds[MMM]);
253 seeds[MMM].insert(seeds[MMM].
end(), seeds[NNN].
begin(), seeds[NNN].
end());
256 usedCluster[NNN] =
true;
268 for (
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
269 if (usedCluster[NNN])
271 rechits_chains.push_back(seeds[NNN]);
276 return rechits_chains;
282 for (
size_t iRH_new = 0; iRH_new < newChain.size(); ++iRH_new) {
285 for (
size_t iRH_old = 0; iRH_old < oldChain.size(); ++iRH_old) {
316 std::vector<ME0Segment>& me0segs) {
320 #ifdef EDM_ML_DEBUG // have lines below only compiled when in debug mode
322 <<
"[ME0SegmentAlgorithm::buildSegments] will now try to fit a ME0Segment from collection of " << rechits.size()
324 for (
auto rh = rechits.begin(); rh != rechits.end(); ++rh) {
325 auto me0id = (*rh)->rh->me0Id();
326 auto rhLP = (*rh)->lp;
328 <<
"[RecHit :: Loc x = " << std::showpos << std::setw(9) << rhLP.x() <<
" Loc y = " << std::showpos
329 << std::setw(9) << rhLP.y() <<
" Time = " << std::showpos << (*rh)->rh->tof() <<
" -- " << me0id.rawId()
330 <<
" = " << me0id <<
" ]";
335 std::vector<const ME0RecHit*> bareRHs;
338 for (
auto rh = rechits.begin(); rh != rechits.end(); rh++) {
339 bareRHs.push_back((*rh)->rh);
345 muonRecHits.push_back(trkRecHit);
349 sfit_ = std::make_unique<MuonSegFit>(muonRecHits);
350 bool goodfit =
sfit_->fit();
351 edm::LogVerbatim(
"ME0SegmentAlgorithm") <<
"[ME0SegmentAlgorithm::buildSegments] ME0Segment fit done";
355 for (
auto rh : muonRecHits)
364 double protoChi2 =
sfit_->chi2();
366 float averageTime = 0.;
367 for (
auto rh = rechits.begin(); rh != rechits.end(); ++rh) {
368 averageTime += (*rh)->rh->tof();
370 if (!rechits.empty())
371 averageTime = averageTime / (rechits.size());
372 float timeUncrt = 0.;
373 for (
auto rh = rechits.begin(); rh != rechits.end(); ++rh) {
374 timeUncrt +=
pow((*rh)->rh->tof() - averageTime, 2);
377 if (rechits.size() > 1)
378 timeUncrt = timeUncrt / (rechits.size() - 1);
379 timeUncrt =
sqrt(timeUncrt);
381 const float dPhi = chamber->
computeDeltaPhi(protoIntercept, protoDirection);
385 <<
"[ME0SegmentAlgorithm::buildSegments] will now try to make ME0Segment from collection of " << rechits.size()
387 ME0Segment tmp(bareRHs, protoIntercept, protoDirection, protoErrors, protoChi2, averageTime, timeUncrt, dPhi);
389 edm::LogVerbatim(
"ME0SegmentAlgorithm") <<
"[ME0SegmentAlgorithm::buildSegments] ME0Segment made";
392 for (
auto rh : muonRecHits)
394 me0segs.push_back(tmp);
std::shared_ptr< TrackingRecHit > MuonRecHitPtr
constexpr double deltaPhi(double phi1, double phi2)
Log< level::Info, true > LogVerbatim
T getUntrackedParameter(std::string const &, T const &) const
static constexpr float running_max
bool isGoodToMerge(const ME0Chamber *chamber, const HitAndPositionPtrContainer &newChain, const HitAndPositionPtrContainer &oldChain)
void setPosition(LocalPoint pos)
Set local position.
void buildSegments(const ME0Chamber *chamber, const HitAndPositionPtrContainer &rechits, std::vector< ME0Segment > &me0segs)
unsigned int minHitsPerSegment
Geom::Phi< T > phi() const
ME0DetId id() const
Return the ME0DetId of this chamber.
std::vector< ME0Segment > run(const ME0Chamber *chamber, const HitAndPositionContainer &rechits) override
std::vector< HitAndPosition > HitAndPositionContainer
ProtoSegments chainHits(const ME0Chamber *chamber, const HitAndPositionContainer &rechits)
constexpr std::array< uint8_t, layerIndexSize > layer
~ME0SegmentAlgorithm() override
Destructor.
std::vector< const HitAndPosition * > HitAndPositionPtrContainer
bool preClustering_useChaining
ProtoSegments clusterHits(const HitAndPositionContainer &rechits)
Utility functions.
float computeDeltaPhi(const LocalPoint &position, const LocalVector &direction) const
std::unique_ptr< MuonSegFit > sfit_
std::vector< MuonRecHitPtr > MuonRecHitContainer
Abs< T >::type abs(const T &t)
std::vector< HitAndPositionPtrContainer > ProtoSegments
Typedefs.
ME0RecHit * clone() const override
T getParameter(std::string const &) const
int nlayers() const
For future modifications (implement more layers)
CLHEP::HepSymMatrix AlgebraicSymMatrix
tuple size
Write out results.
Power< A, B >::type pow(const A &a, const B &b)
ME0SegmentAlgorithm(const edm::ParameterSet &ps)
Constructor.