23 LogTrace(metname) <<
"Muon Trajectory Cleaner called" << endl;
25 TrajectoryContainer::iterator iter, jter;
26 Trajectory::DataContainer::const_iterator m1, m2;
28 if ( trajC.empty() )
return;
30 LogTrace(metname) <<
"Number of trajectories in the container: " <<trajC.size()<< endl;
36 map<int, vector<int> > seedmap;
41 vector<bool>
mask(trajC.size(),
true);
45 for ( iter = trajC.begin(); iter != trajC.end(); iter++ ) {
46 if ( !
mask[
i] ) { i++;
continue; }
47 if ( !(*iter)->isValid() || (*iter)->empty() ) {
mask[
i] =
false; i++;
continue; }
48 if(seedmap.count(i)==0) seedmap[i].push_back(i);
52 for ( jter = iter+1; jter != trajC.end(); jter++ ) {
53 if ( !
mask[j] ) { j++;
continue; }
54 if(seedmap.count(j)==0) seedmap[j].push_back(j);
57 for( m1 = meas1.begin(); m1 != meas1.end(); m1++ ) {
58 for( m2 = meas2.begin(); m2 != meas2.end(); m2++ ) {
59 if ( ( (*m1).recHit()->globalPosition() - (*m2).recHit()->globalPosition()).
mag()< 10
e-5 ) match++;
64 double chi2_dof_i = (*iter)->ndof() > 0 ? (*iter)->chiSquared()/(*iter)->ndof() : (*iter)->chiSquared()/1
e-10;
65 double chi2_dof_j = (*jter)->ndof() > 0 ? (*jter)->chiSquared()/(*jter)->ndof() : (*jter)->chiSquared()/1
e-10;
67 LogTrace(metname) <<
" MuonTrajectoryCleaner:";
68 LogTrace(metname) <<
" * trajC " << i
69 <<
" (pT="<<(*iter)->lastMeasurement().updatedState().globalMomentum().perp()
70 <<
" GeV) - chi2/nDOF = " << (*iter)->chiSquared() <<
"/" << (*iter)->ndof() <<
" = " << chi2_dof_i;
71 LogTrace(metname) <<
" - valid RH = " << (*iter)->foundHits() <<
" / total RH = " << (*iter)->measurements().size();
72 LogTrace(metname) <<
" * trajC " << j
73 <<
" (pT="<<(*jter)->lastMeasurement().updatedState().globalMomentum().perp()
74 <<
" GeV) - chi2/nDOF = " << (*jter)->chiSquared() <<
"/" << (*jter)->ndof() <<
" = " << chi2_dof_j;
75 LogTrace(metname) <<
" - valid RH = " << (*jter)->foundHits() <<
" / total RH = " << (*jter)->measurements().size();
78 int hit_diff = (*iter)->foundHits() - (*jter)->foundHits() ;
82 if (
abs(hit_diff) == 0 ) {
89 double fraction = (2.*
match)/((*iter)->measurements().size()+(*jter)->measurements().size());
93 if((*jter)->lastMeasurement().updatedState().globalMomentum().perp() <=
minPt) ++belowLimit;
94 if((*iter)->lastMeasurement().updatedState().globalMomentum().perp() <=
minPt) ++belowLimit;
96 if((*jter)->lastMeasurement().updatedState().globalMomentum().perp() >= dPt) ++above;
97 if((*iter)->lastMeasurement().updatedState().globalMomentum().perp() >= dPt) ++above;
100 if(fraction >= maxFraction && belowLimit == 1 && above == 1){
101 if((*iter)->lastMeasurement().updatedState().globalMomentum().perp() <
minPt){
104 seedmap[j].insert(seedmap[j].
end(), seedmap[i].
begin(), seedmap[i].
end());
106 LogTrace(metname) <<
"Trajectory # " << i <<
" (pT="<<(*iter)->lastMeasurement().updatedState().globalMomentum().perp()
107 <<
" GeV) rejected because it has too low pt";
111 seedmap[
i].insert(seedmap[i].
end(), seedmap[j].
begin(), seedmap[j].
end());
113 LogTrace(metname) <<
"Trajectory # " << j <<
" (pT="<<(*jter)->lastMeasurement().updatedState().globalMomentum().perp()
114 <<
" GeV) rejected because it has too low pt";
118 if (chi2_dof_i > chi2_dof_j) {
121 seedmap[j].insert(seedmap[j].
end(), seedmap[i].
begin(), seedmap[i].
end());
123 LogTrace(metname) <<
"Trajectory # " << i <<
" (pT="<<(*iter)->lastMeasurement().updatedState().globalMomentum().perp() <<
" GeV) rejected";
127 seedmap[
i].insert(seedmap[i].
end(), seedmap[j].
begin(), seedmap[j].
end());
129 LogTrace(metname) <<
"Trajectory # " << j <<
" (pT="<<(*jter)->lastMeasurement().updatedState().globalMomentum().perp() <<
" GeV) rejected";
134 if ( hit_diff < 0 ) {
137 seedmap[j].insert(seedmap[j].
end(), seedmap[i].
begin(), seedmap[i].
end());
139 LogTrace(metname) <<
"Trajectory # " << i <<
" (pT="<<(*iter)->lastMeasurement().updatedState().globalMomentum().perp() <<
" GeV) rejected";
143 seedmap[
i].insert(seedmap[i].
end(), seedmap[j].
begin(), seedmap[j].
end());
145 LogTrace(metname) <<
"Trajectory # " << j <<
" (pT="<<(*jter)->lastMeasurement().updatedState().globalMomentum().perp() <<
" GeV) rejected";
153 if(skipnext)
continue;
159 LogTrace(metname) <<
" Creating map between chosen seed and ghost seeds." << std::endl;
161 auto seedToSeedsMap = std::make_unique<L2SeedAssoc>();
162 if(!seeds->empty()) {
165 event.get(ptr.
id(), seedsHandle);
166 seedToSeedsMap = std::make_unique<L2SeedAssoc>(seedsHandle, seedsHandle);
171 for(
map<
int, vector<int> >::iterator itmap=seedmap.begin(); itmap!=seedmap.end(); ++itmap, ++seedcnt) {
175 int tmpsize=(*itmap).second.size();
176 for(
int cnt=0; cnt!=tmpsize; ++cnt) {
179 seedToSeedsMap->insert(tmpL2SeedRef1, tmpL2SeedRef2);
183 event.put(
std::move(seedToSeedsMap),
"");
188 for ( iter = trajC.begin(); iter != trajC.end(); iter++ ) {
190 result.push_back(*iter);
191 LogTrace(metname) <<
"Keep trajectory with pT = " << (*iter)->lastMeasurement().updatedState().globalMomentum().perp() <<
" GeV";
207 LogTrace(metname) <<
"Muon Trajectory Cleaner called" << endl;
209 if ( candC.size() < 2 )
return;
211 CandidateContainer::iterator iter, jter;
212 Trajectory::DataContainer::const_iterator m1, m2;
218 LogTrace(metname) <<
"Number of muon candidates in the container: " <<candC.size()<< endl;
227 vector<bool>
mask(candC.size(),
true);
231 for ( iter = candC.begin(); iter != candC.end(); iter++ ) {
232 if ( !
mask[
i] ) { i++;
continue; }
240 innerTSOS = (*iter)->trajectory()->firstMeasurement().updatedState();
243 innerTSOS = (*iter)->trajectory()->lastMeasurement().updatedState();
245 if ( !(innerTSOS.
isValid()) )
continue;
250 for ( jter = iter+1; jter != candC.end(); jter++ ) {
251 if ( !
mask[j] ) { j++;
continue; }
255 for ( m1 = meas1.begin(); m1 != meas1.end(); m1++ ) {
256 for ( m2 = meas2.begin(); m2 != meas2.end(); m2++ ) {
257 if ( (*m1).recHit()->isValid() && (*m2).recHit()->isValid() )
258 if ( ( (*m1).recHit()->globalPosition() - (*m2).recHit()->globalPosition()).
mag()< 10
e-5 ) match++;
263 <<
" MuonTrajectoryCleaner: candC " << i <<
" chi2/nRH = " 264 << (*iter)->trajectory()->chiSquared() <<
"/" << (*iter)->trajectory()->foundHits() <<
265 " vs trajC " << j <<
" chi2/nRH = " << (*jter)->trajectory()->chiSquared() <<
266 "/" << (*jter)->trajectory()->foundHits() <<
" Shared RecHits: " <<
match;
270 innerTSOS2 = (*jter)->trajectory()->firstMeasurement().updatedState();
273 innerTSOS2 = (*jter)->trajectory()->lastMeasurement().updatedState();
275 if ( !(innerTSOS2.
isValid()) )
continue;
281 float deta(fabs(eta1-eta2));
283 float dpt(fabs(pt1-pt2));
284 if ( dpt < deltaPt && deta < deltaEta && dphi < deltaPhi ) {
287 <<
" MuonTrajectoryCleaner: candC " << i<<
" and "<<j<<
" direction matched: " 292 bool hitsMatch = ((match > 0) && ((match/((*iter)->trajectory()->foundHits()) > 0.25) || (match/((*jter)->trajectory()->foundHits()) > 0.25))) ?
true :
false;
294 ( ( (*iter)->trackerTrack() == (*jter)->trackerTrack() ) &&
295 ( deltaR<double>((*iter)->muonTrack()->eta(),(*iter)->muonTrack()->phi(), (*jter)->muonTrack()->eta(),(*jter)->muonTrack()->phi()) < 0.2) );
298 if ( ( tracksMatch ) || (hitsMatch > 0) ) {
299 if ( (*iter)->trajectory()->foundHits() == (*jter)->trajectory()->foundHits() ) {
300 if ( (*iter)->trajectory()->chiSquared() > (*jter)->trajectory()->chiSquared() ) {
304 else mask[j] =
false;
307 if ( (*iter)->trajectory()->foundHits() < (*jter)->trajectory()->foundHits() ) {
311 else mask[j] =
false;
318 if(skipnext)
continue;
322 for ( iter = candC.begin(); iter != candC.end(); iter++ ) {
324 result.push_back(*iter);
326 delete (*iter)->trajectory();
327 delete (*iter)->trackerTrajectory();
void clean(TrajectoryContainer &muonTrajectories, edm::Event &evt, const edm::Handle< edm::View< TrajectorySeed > > &seeds)
Clean the trajectories container, erasing the (worst) clone trajectory.
const std::string metname
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Geom::Phi< T > phi() const
static const double deltaEta
edm::AssociationMap< edm::OneToMany< L2MuonTrajectorySeedCollection, L2MuonTrajectorySeedCollection > > L2SeedAssoc
std::vector< TrajectoryMeasurement > DataContainer
MuonCandidate::CandidateContainer CandidateContainer
Abs< T >::type abs(const T &t)
MuonCandidate::TrajectoryContainer TrajectoryContainer
ProductID id() const
Accessor for product ID.
GlobalVector globalMomentum() const
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.