Clean the trajectories container, erasing the (worst) clone trajectory.
23 const std::string
metname =
"Muon|RecoMuon|MuonTrajectoryCleaner";
25 LogTrace(metname) <<
"Muon Trajectory Cleaner called" << endl;
27 TrajectoryContainer::iterator iter, jter;
28 Trajectory::DataContainer::const_iterator m1, m2;
30 if ( trajC.size() < 1 )
return;
32 LogTrace(metname) <<
"Number of trajectories in the container: " <<trajC.size()<< endl;
36 int nTot1DHits_i(0), nTot1DHits_j(0);
39 map<int, vector<int> > seedmap;
44 vector<bool> mask(trajC.size(),
true);
48 for ( iter = trajC.begin(); iter != trajC.end(); iter++ ) {
49 if ( !mask[
i] ) { i++;
continue; }
50 if ( !(*iter)->isValid() || (*iter)->empty() ) {mask[
i] =
false; i++;
continue; }
51 if(seedmap.count(i)==0) seedmap[i].push_back(i);
55 for ( jter = iter+1; jter != trajC.end(); jter++ ) {
56 if ( !mask[
j] ) { j++;
continue; }
57 if(seedmap.count(j)==0) seedmap[j].push_back(j);
61 for( m1 = meas1.begin(); m1 != meas1.end(); m1++ ) {
64 else trhC1.push_back((*m1).recHit());
65 for( TransientTrackingRecHit::ConstRecHitContainer::const_iterator trh1=trhC1.begin(); trh1!=trhC1.end(); ++trh1, ++nTot1DHits_i) {
67 for( m2 = meas2.begin(); m2 != meas2.end(); m2++ ) {
70 else trhC2.push_back((*m2).recHit());
71 for( TransientTrackingRecHit::ConstRecHitContainer::const_iterator trh2=trhC2.begin(); trh2!=trhC2.end(); ++trh2, ++nTot1DHits_j) {
72 if( ( (*trh1)->globalPosition() - (*trh2)->globalPosition()).
mag() < 10
e-5 )
match++;
80 int nTotHits_i = (*iter)->measurements().size();
81 int nTotHits_j = (*jter)->measurements().size();
84 double chi2_dof_i = (*iter)->ndof() > 0 ? (*iter)->chiSquared()/(*iter)->ndof() : (*iter)->chiSquared()/1
e-10;
85 double chi2_dof_j = (*jter)->ndof() > 0 ? (*jter)->chiSquared()/(*jter)->ndof() : (*jter)->chiSquared()/1
e-10;
87 LogTrace(metname) <<
" MuonTrajectoryCleaner:";
88 LogTrace(metname) <<
" * trajC " << i
89 <<
" (pT="<<(*iter)->lastMeasurement().updatedState().globalMomentum().perp()
90 <<
" GeV) - chi2/nDOF = " << (*iter)->chiSquared() <<
"/" << (*iter)->ndof() <<
" = " << chi2_dof_i;
91 LogTrace(metname) <<
" - valid RH = " << (*iter)->foundHits() <<
" / total RH = " << nTotHits_i <<
" / total 1D RH = " << nTot1DHits_i;
92 LogTrace(metname) <<
" * trajC " << j
93 <<
" (pT="<<(*jter)->lastMeasurement().updatedState().globalMomentum().perp()
94 <<
" GeV) - chi2/nDOF = " << (*jter)->chiSquared() <<
"/" << (*jter)->ndof() <<
" = " << chi2_dof_j;
95 LogTrace(metname) <<
" - valid RH = " << (*jter)->foundHits() <<
" / total RH = " << nTotHits_j <<
" / total 1D RH = " << nTot1DHits_j;
98 int hit_diff = (*iter)->foundHits() - (*jter)->foundHits() ;
102 if (
abs(hit_diff) <= 4 ) {
107 double maxFraction = 0.95;
109 double fraction = (2.*
match)/((*iter)->measurements().size()+(*jter)->measurements().size());
113 if((*jter)->lastMeasurement().updatedState().globalMomentum().perp() <=
minPt) ++belowLimit;
114 if((*iter)->lastMeasurement().updatedState().globalMomentum().perp() <=
minPt) ++belowLimit;
116 if((*jter)->lastMeasurement().updatedState().globalMomentum().perp() >= dPt) ++above;
117 if((*iter)->lastMeasurement().updatedState().globalMomentum().perp() >= dPt) ++above;
120 if(fraction >= maxFraction && belowLimit == 1 && above == 1){
121 if((*iter)->lastMeasurement().updatedState().globalMomentum().perp() <
minPt){
124 seedmap[
j].insert(seedmap[j].
end(), seedmap[i].
begin(), seedmap[i].
end());
126 LogTrace(metname) <<
"Trajectory # " << i <<
" (pT="<<(*iter)->lastMeasurement().updatedState().globalMomentum().perp()
127 <<
" GeV) rejected because it has too low pt";
131 seedmap[
i].insert(seedmap[i].
end(), seedmap[j].
begin(), seedmap[j].
end());
133 LogTrace(metname) <<
"Trajectory # " << j <<
" (pT="<<(*jter)->lastMeasurement().updatedState().globalMomentum().perp()
134 <<
" GeV) rejected because it has too low pt";
138 if (chi2_dof_i > chi2_dof_j) {
141 seedmap[
j].insert(seedmap[j].
end(), seedmap[i].
begin(), seedmap[i].
end());
143 LogTrace(metname) <<
"Trajectory # " << i <<
" (pT="<<(*iter)->lastMeasurement().updatedState().globalMomentum().perp() <<
" GeV) rejected";
147 seedmap[
i].insert(seedmap[i].
end(), seedmap[j].
begin(), seedmap[j].
end());
149 LogTrace(metname) <<
"Trajectory # " << j <<
" (pT="<<(*jter)->lastMeasurement().updatedState().globalMomentum().perp() <<
" GeV) rejected";
154 if ( hit_diff < 0 ) {
157 seedmap[
j].insert(seedmap[j].
end(), seedmap[i].
begin(), seedmap[i].
end());
159 LogTrace(metname) <<
"Trajectory # " << i <<
" (pT="<<(*iter)->lastMeasurement().updatedState().globalMomentum().perp() <<
" GeV) rejected";
163 seedmap[
i].insert(seedmap[i].
end(), seedmap[j].
begin(), seedmap[j].
end());
165 LogTrace(metname) <<
"Trajectory # " << j <<
" (pT="<<(*jter)->lastMeasurement().updatedState().globalMomentum().perp() <<
" GeV) rejected";
173 if(skipnext)
continue;
179 LogTrace(metname) <<
" Creating map between chosen seed and ghost seeds." << std::endl;
181 auto_ptr<L2SeedAssoc> seedToSeedsMap(
new L2SeedAssoc);
184 for(
map<
int, vector<int> >::iterator itmap=seedmap.begin(); itmap!=seedmap.end(); ++itmap, ++seedcnt) {
188 int tmpsize=(*itmap).second.size();
189 for(
int cnt=0; cnt!=tmpsize; ++cnt) {
192 seedToSeedsMap->insert(tmpL2SeedRef1, tmpL2SeedRef2);
196 event.put(seedToSeedsMap,
"");
201 for ( iter = trajC.begin(); iter != trajC.end(); iter++ ) {
203 result.push_back(*iter);
204 LogTrace(metname) <<
"Keep trajectory with pT = " << (*iter)->lastMeasurement().updatedState().globalMomentum().perp() <<
" GeV";
const std::string metname
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
static TransientTrackingRecHit::ConstRecHitContainer breakInSubRecHits(TransientTrackingRecHit::ConstRecHitPointer, int granularity)
takes a muon rechit and returns its sub-rechits given a certain granularity
std::vector< TrajectoryMeasurement > DataContainer
std::vector< ConstRecHitPointer > ConstRecHitContainer
MuonCandidate::TrajectoryContainer TrajectoryContainer
REF castTo() const
cast to a concrete type
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.