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 54 ME0DetId chId((ensemble.first)->id());
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();
58 auto rhLP = (*rh)->lp;
59 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<<
" ]";
64 std::vector<ME0Segment> segments_temp;
65 std::vector<ME0Segment> segments;
73 rechits_clusters = this->
chainHits(chamber, rechits );
80 for(
auto sub_rechits = rechits_clusters.begin(); sub_rechits != rechits_clusters.end(); ++sub_rechits ) {
82 segments_temp.clear();
86 segments.insert( segments.end(), segments_temp.begin(), segments_temp.end() );
92 for(
const auto& rh : rechits) ptrRH.push_back(&rh);
105 float dXclus_box = 0.0;
106 float dYclus_box = 0.0;
110 std::vector<float> running_meanX; running_meanX.reserve(rechits.size());
111 std::vector<float> running_meanY; running_meanY.reserve(rechits.size());
113 std::vector<float> seed_minX; seed_minX.reserve(rechits.size());
114 std::vector<float> seed_maxX; seed_maxX.reserve(rechits.size());
115 std::vector<float> seed_minY; seed_minY.reserve(rechits.size());
116 std::vector<float> seed_maxY; seed_maxY.reserve(rechits.size());
121 for(
unsigned int i = 0;
i < rechits.size(); ++
i) {
127 running_meanX.push_back( rechits[i].lp.x() );
128 running_meanY.push_back( rechits[i].lp.y() );
131 seed_minX.push_back( rechits[i].lp.x() );
132 seed_maxX.push_back( rechits[i].lp.x() );
133 seed_minY.push_back( rechits[i].lp.y() );
134 seed_maxY.push_back( rechits[i].lp.y() );
139 for(
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
140 for(
size_t MMM = NNN+1; MMM < seeds.size(); ++MMM) {
142 LogDebug(
"ME0SegmentAlgorithm") <<
"[ME0SegmentAlgorithm::clusterHits]: ALARM! Skipping used seeds, this should not happen - inform developers!";
150 if ( running_meanX[NNN] > running_meanX[MMM] ) dXclus_box = seed_minX[NNN] - seed_maxX[MMM];
151 else dXclus_box = seed_minX[MMM] - seed_maxX[NNN];
152 if ( running_meanY[NNN] > running_meanY[MMM] ) dYclus_box = seed_minY[NNN] - seed_maxY[MMM];
153 else dYclus_box = seed_minY[MMM] - seed_maxY[NNN];
161 if(seeds[NNN].
size()+seeds[MMM].
size() != 0) {
162 running_meanX[MMM] = (running_meanX[NNN]*seeds[NNN].size() + running_meanX[MMM]*seeds[MMM].size()) / (seeds[NNN].
size()+seeds[MMM].size());
163 running_meanY[MMM] = (running_meanY[NNN]*seeds[NNN].size() + running_meanY[MMM]*seeds[MMM].size()) / (seeds[NNN].
size()+seeds[MMM].size());
167 if ( seed_minX[NNN] < seed_minX[MMM] ) seed_minX[MMM] = seed_minX[NNN];
168 if ( seed_maxX[NNN] > seed_maxX[MMM] ) seed_maxX[MMM] = seed_maxX[NNN];
169 if ( seed_minY[NNN] < seed_minY[MMM] ) seed_minY[MMM] = seed_minY[NNN];
170 if ( seed_maxY[NNN] > seed_maxY[MMM] ) seed_maxY[MMM] = seed_maxY[NNN];
173 seeds[MMM].insert(seeds[MMM].
end(),seeds[NNN].
begin(),seeds[NNN].
end());
188 for(
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
190 rechits_clusters.push_back(seeds[NNN]);
193 return rechits_clusters;
202 seeds.reserve(rechits.size());
203 std::vector<bool> usedCluster(rechits.size(),
false);
208 for (
unsigned int i=0;
i<rechits.size(); ++
i){
214 for(
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
215 for(
size_t MMM = NNN+1; MMM < seeds.size(); ++MMM) {
216 if(usedCluster[MMM] || usedCluster[NNN]){
230 bool goodToMerge =
isGoodToMerge(chamber, seeds[NNN], seeds[MMM]);
236 seeds[MMM].insert(seeds[MMM].
end(),seeds[NNN].
begin(),seeds[NNN].
end());
239 usedCluster[NNN] =
true;
252 for(
size_t NNN = 0; NNN < seeds.size(); ++NNN) {
253 if(usedCluster[NNN])
continue;
254 rechits_chains.push_back(seeds[NNN]);
259 return rechits_chains;
263 for(
size_t iRH_new = 0;iRH_new<newChain.size();++iRH_new){
266 for(
size_t iRH_old = 0;iRH_old<oldChain.size();++iRH_old){
280 if (
std::abs(
int(newChain[iRH_new]->layer) -
int(oldChain[iRH_old]->layer)) >= (chamber->
id().
nlayers()-1))
continue;
294 #ifdef EDM_ML_DEBUG // have lines below only compiled when in debug mode 295 edm::LogVerbatim(
"ME0SegmentAlgorithm") <<
"[ME0SegmentAlgorithm::buildSegments] will now try to fit a ME0Segment from collection of "<<rechits.size()<<
" ME0 RecHits";
296 for (
auto rh=rechits.begin(); rh!=rechits.end(); ++rh){
297 auto me0id = (*rh)->rh->me0Id();
298 auto rhLP = (*rh)->lp;
299 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<<
" ]";
304 std::vector<const ME0RecHit*> bareRHs;
307 for (
auto rh=rechits.begin(); rh!=rechits.end();rh++){
308 bareRHs.push_back((*rh)->rh );
314 muonRecHits.push_back(trkRecHit);
318 sfit_ = std::make_unique<MuonSegFit>(muonRecHits);
319 bool goodfit =
sfit_->fit();
320 edm::LogVerbatim(
"ME0SegmentAlgorithm") <<
"[ME0SegmentAlgorithm::buildSegments] ME0Segment fit done";
324 for (
auto rh:muonRecHits) rh.reset();
332 double protoChi2 =
sfit_->chi2();
334 float averageTime=0.;
335 for (
auto rh=rechits.begin(); rh!=rechits.end(); ++rh){
336 averageTime += (*rh)->rh->tof();
338 if(rechits.size() != 0) averageTime=averageTime/(rechits.size());
340 for (
auto rh=rechits.begin(); rh!=rechits.end(); ++rh){
341 timeUncrt +=
pow((*rh)->rh->tof()-averageTime,2);
344 if(rechits.size() > 1) timeUncrt=timeUncrt/(rechits.size()-1);
345 timeUncrt =
sqrt(timeUncrt);
347 const float dPhi = chamber->
computeDeltaPhi(protoIntercept,protoDirection);
350 edm::LogVerbatim(
"ME0SegmentAlgorithm") <<
"[ME0SegmentAlgorithm::buildSegments] will now try to make ME0Segment from collection of "<<rechits.size()<<
" ME0 RecHits";
351 ME0Segment tmp(bareRHs, protoIntercept, protoDirection, protoErrors, protoChi2, averageTime, timeUncrt, dPhi);
353 edm::LogVerbatim(
"ME0SegmentAlgorithm") <<
"[ME0SegmentAlgorithm::buildSegments] ME0Segment made";
356 for (
auto rh:muonRecHits) rh.reset();
357 me0segs.push_back(tmp);
std::shared_ptr< TrackingRecHit > MuonRecHitPtr
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< ME0Segment > run(const ME0Chamber *chamber, const HitAndPositionContainer &rechits)
bool isGoodToMerge(const ME0Chamber *chamber, const HitAndPositionPtrContainer &newChain, const HitAndPositionPtrContainer &oldChain)
virtual ME0RecHit * clone() const
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< HitAndPosition > HitAndPositionContainer
ProtoSegments chainHits(const ME0Chamber *chamber, const HitAndPositionContainer &rechits)
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.
double deltaPhi(double phi1, double phi2)
std::vector< std::vector< double > > tmp
int nlayers() const
For future modifications (implement more layers)
CLHEP::HepSymMatrix AlgebraicSymMatrix
virtual ~ME0SegmentAlgorithm()
Destructor.
Power< A, B >::type pow(const A &a, const B &b)
ME0SegmentAlgorithm(const edm::ParameterSet &ps)
Constructor.