38 edm::LogVerbatim(
"ME0SegmentAlgorithm") <<
"[ME0SegmentAlgorithm::ctor] Parameters to build segments :: " 39 <<
"preClustering = "<<preClustering<<
" preClustering_useChaining = "<<preClustering_useChaining
40 <<
" dPhiChainBoxMax = "<<dPhiChainBoxMax<<
" dEtaChainBoxMax = "<<dEtaChainBoxMax<<
" dTimeChainBoxMax = "<<dTimeChainBoxMax
41 <<
" minHitsPerSegment = "<<minHitsPerSegment<<
" maxRecHitsInCluster = "<<
maxRecHitsInCluster;
53 #ifdef EDM_ML_DEBUG // have lines below only compiled when in debug mode 55 edm::LogVerbatim(
"ME0SegAlgoMM") <<
"[ME0SegmentAlgorithm::run] build segments in chamber " << chId <<
" which contains "<<rechits.size()<<
" rechits";
56 for (
auto rh=rechits.begin(); rh!=rechits.end(); ++rh){
57 auto me0id = rh->rh->me0Id();
59 edm::LogVerbatim(
"ME0SegmentAlgorithm") <<
"[RecHit :: Loc x = "<<std::showpos<<std::setw(9)<<rhLP.x()<<
" Loc y = "<<std::showpos<<std::setw(9)<<rhLP.y()
60 <<
" Time = "<<std::showpos<<rh->rh->tof()<<
" -- "<<me0id.rawId()<<
" = "<<me0id<<
" ]";
65 std::vector<ME0Segment> segments_temp;
66 std::vector<ME0Segment> segments;
74 rechits_clusters = this->
chainHits(chamber, rechits );
81 for(
auto sub_rechits = rechits_clusters.begin(); sub_rechits != rechits_clusters.end(); ++sub_rechits ) {
83 segments_temp.clear();
87 segments.insert( segments.end(), segments_temp.begin(), segments_temp.end() );
93 for(
const auto& rh : rechits) ptrRH.push_back(&rh);
106 float dXclus_box = 0.0;
107 float dYclus_box = 0.0;
111 std::vector<float> running_meanX; running_meanX.reserve(rechits.size());
112 std::vector<float> running_meanY; running_meanY.reserve(rechits.size());
114 std::vector<float> seed_minX; seed_minX.reserve(rechits.size());
115 std::vector<float> seed_maxX; seed_maxX.reserve(rechits.size());
116 std::vector<float> seed_minY; seed_minY.reserve(rechits.size());
117 std::vector<float> seed_maxY; seed_maxY.reserve(rechits.size());
122 for(
unsigned int i = 0;
i < rechits.size(); ++
i) {
128 running_meanX.push_back( rechits[i].lp.x() );
129 running_meanY.push_back( rechits[i].lp.y() );
132 seed_minX.push_back( rechits[i].lp.x() );
133 seed_maxX.push_back( rechits[i].lp.x() );
134 seed_minY.push_back( rechits[i].lp.y() );
135 seed_maxY.push_back( rechits[i].lp.y() );
140 for(
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
141 for(
size_t MMM = NNN+1; MMM < seeds.size(); ++MMM) {
143 LogDebug(
"ME0SegmentAlgorithm") <<
"[ME0SegmentAlgorithm::clusterHits]: ALARM! Skipping used seeds, this should not happen - inform developers!";
151 if ( running_meanX[NNN] > running_meanX[MMM] ) dXclus_box = seed_minX[NNN] - seed_maxX[MMM];
152 else dXclus_box = seed_minX[MMM] - seed_maxX[NNN];
153 if ( running_meanY[NNN] > running_meanY[MMM] ) dYclus_box = seed_minY[NNN] - seed_maxY[MMM];
154 else dYclus_box = seed_minY[MMM] - seed_maxY[NNN];
162 if(seeds[NNN].
size()+seeds[MMM].
size() != 0) {
163 running_meanX[MMM] = (running_meanX[NNN]*seeds[NNN].size() + running_meanX[MMM]*seeds[MMM].size()) / (seeds[NNN].
size()+seeds[MMM].size());
164 running_meanY[MMM] = (running_meanY[NNN]*seeds[NNN].size() + running_meanY[MMM]*seeds[MMM].size()) / (seeds[NNN].
size()+seeds[MMM].size());
168 if ( seed_minX[NNN] < seed_minX[MMM] ) seed_minX[MMM] = seed_minX[NNN];
169 if ( seed_maxX[NNN] > seed_maxX[MMM] ) seed_maxX[MMM] = seed_maxX[NNN];
170 if ( seed_minY[NNN] < seed_minY[MMM] ) seed_minY[MMM] = seed_minY[NNN];
171 if ( seed_maxY[NNN] > seed_maxY[MMM] ) seed_maxY[MMM] = seed_maxY[NNN];
174 seeds[MMM].insert(seeds[MMM].
end(),seeds[NNN].
begin(),seeds[NNN].
end());
189 for(
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
191 rechits_clusters.push_back(seeds[NNN]);
194 return rechits_clusters;
203 seeds.reserve(rechits.size());
204 std::vector<bool> usedCluster(rechits.size(),
false);
209 for (
unsigned int i=0;
i<rechits.size(); ++
i){
215 for(
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
216 for(
size_t MMM = NNN+1; MMM < seeds.size(); ++MMM) {
217 if(usedCluster[MMM] || usedCluster[NNN]){
231 bool goodToMerge =
isGoodToMerge(chamber, seeds[NNN], seeds[MMM]);
237 seeds[MMM].insert(seeds[MMM].
end(),seeds[NNN].
begin(),seeds[NNN].
end());
240 usedCluster[NNN] =
true;
253 for(
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
254 if(usedCluster[NNN])
continue;
255 rechits_chains.push_back(seeds[NNN]);
260 return rechits_chains;
264 for(
size_t iRH_new = 0;iRH_new<newChain.size();++iRH_new){
267 for(
size_t iRH_old = 0;iRH_old<oldChain.size();++iRH_old){
281 if (
std::abs(
int(newChain[iRH_new]->layer) -
int(oldChain[iRH_old]->layer)) >= (chamber->
id().
nlayers()-1))
continue;
295 #ifdef EDM_ML_DEBUG // have lines below only compiled when in debug mode 296 edm::LogVerbatim(
"ME0SegmentAlgorithm") <<
"[ME0SegmentAlgorithm::buildSegments] will now try to fit a ME0Segment from collection of "<<rechits.size()<<
" ME0 RecHits";
297 for (
auto rh=rechits.begin(); rh!=rechits.end(); ++rh){
298 auto me0id = (*rh)->rh->me0Id();
299 auto rhLP = (*rh)->lp;
300 edm::LogVerbatim(
"ME0SegmentAlgorithm") <<
"[RecHit :: Loc x = "<<std::showpos<<std::setw(9)<<rhLP.x()<<
" Loc y = "<<std::showpos<<std::setw(9)<<rhLP.y()<<
" Time = "<<std::showpos<<(*rh)->rh->tof()<<
" -- "<<me0id.rawId()<<
" = "<<me0id<<
" ]";
305 std::vector<const ME0RecHit*> bareRHs;
308 for (
auto rh=rechits.begin(); rh!=rechits.end();rh++){
309 bareRHs.push_back((*rh)->rh );
315 muonRecHits.push_back(trkRecHit);
319 sfit_ = std::make_unique<MuonSegFit>(muonRecHits);
320 bool goodfit =
sfit_->fit();
321 edm::LogVerbatim(
"ME0SegmentAlgorithm") <<
"[ME0SegmentAlgorithm::buildSegments] ME0Segment fit done";
325 for (
auto rh:muonRecHits) rh.reset();
333 double protoChi2 =
sfit_->chi2();
335 float averageTime=0.;
336 for (
auto rh=rechits.begin(); rh!=rechits.end(); ++rh){
337 averageTime += (*rh)->rh->tof();
339 if(!rechits.empty()) averageTime=averageTime/(rechits.size());
341 for (
auto rh=rechits.begin(); rh!=rechits.end(); ++rh){
342 timeUncrt +=
pow((*rh)->rh->tof()-averageTime,2);
345 if(rechits.size() > 1) timeUncrt=timeUncrt/(rechits.size()-1);
346 timeUncrt =
sqrt(timeUncrt);
348 const float dPhi = chamber->
computeDeltaPhi(protoIntercept,protoDirection);
351 edm::LogVerbatim(
"ME0SegmentAlgorithm") <<
"[ME0SegmentAlgorithm::buildSegments] will now try to make ME0Segment from collection of "<<rechits.size()<<
" ME0 RecHits";
352 ME0Segment tmp(bareRHs, protoIntercept, protoDirection, protoErrors, protoChi2, averageTime, timeUncrt, dPhi);
354 edm::LogVerbatim(
"ME0SegmentAlgorithm") <<
"[ME0SegmentAlgorithm::buildSegments] ME0Segment made";
357 for (
auto rh:muonRecHits) rh.reset();
358 me0segs.push_back(tmp);
std::shared_ptr< TrackingRecHit > MuonRecHitPtr
constexpr double deltaPhi(double phi1, double phi2)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
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)
~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
std::vector< std::vector< double > > tmp
int nlayers() const
For future modifications (implement more layers)
CLHEP::HepSymMatrix AlgebraicSymMatrix
Power< A, B >::type pow(const A &a, const B &b)
ME0SegmentAlgorithm(const edm::ParameterSet &ps)
Constructor.