23 LogTrace(metname) <<
"Muon Trajectory Cleaner called" << endl;
25 TrajectoryContainer::iterator
iter, jter;
26 Trajectory::DataContainer::const_iterator m1, m2;
28 if ( trajC.size() < 1 )
return;
30 LogTrace(metname) <<
"Number of trajectories in the container: " <<trajC.size()<< endl;
34 int nTot1DHits_i(0), nTot1DHits_j(0);
37 map<int, vector<int> > seedmap;
42 vector<bool> mask(trajC.size(),
true);
46 for ( iter = trajC.begin(); iter != trajC.end(); iter++ ) {
47 if ( !mask[
i] ) { i++;
continue; }
48 if ( !(*iter)->isValid() || (*iter)->empty() ) {mask[
i] =
false; i++;
continue; }
49 if(seedmap.count(i)==0) seedmap[i].push_back(i);
53 for ( jter = iter+1; jter != trajC.end(); jter++ ) {
54 if ( !mask[j] ) { j++;
continue; }
55 if(seedmap.count(j)==0) seedmap[j].push_back(j);
59 for( m1 = meas1.begin(); m1 != meas1.end(); m1++ ) {
62 else trhC1.push_back((*m1).recHit());
63 for( TransientTrackingRecHit::ConstRecHitContainer::const_iterator trh1=trhC1.begin(); trh1!=trhC1.end(); ++trh1, ++nTot1DHits_i) {
65 for( m2 = meas2.begin(); m2 != meas2.end(); m2++ ) {
68 else trhC2.push_back((*m2).recHit());
69 for( TransientTrackingRecHit::ConstRecHitContainer::const_iterator trh2=trhC2.begin(); trh2!=trhC2.end(); ++trh2, ++nTot1DHits_j) {
70 if( ( (*trh1)->globalPosition() - (*trh2)->globalPosition()).
mag() < 10
e-5 ) match++;
78 int nTotHits_i = (*iter)->measurements().size();
79 int nTotHits_j = (*jter)->measurements().size();
82 double chi2_dof_i = (*iter)->ndof() > 0 ? (*iter)->chiSquared()/(*iter)->ndof() : (*iter)->chiSquared()/1
e-10;
83 double chi2_dof_j = (*jter)->ndof() > 0 ? (*jter)->chiSquared()/(*jter)->ndof() : (*jter)->chiSquared()/1
e-10;
85 LogTrace(metname) <<
" MuonTrajectoryCleaner:";
86 LogTrace(metname) <<
" * trajC " << i
87 <<
" (pT="<<(*iter)->lastMeasurement().updatedState().globalMomentum().perp()
88 <<
" GeV) - chi2/nDOF = " << (*iter)->chiSquared() <<
"/" << (*iter)->ndof() <<
" = " << chi2_dof_i;
89 LogTrace(metname) <<
" - valid RH = " << (*iter)->foundHits() <<
" / total RH = " << nTotHits_i <<
" / total 1D RH = " << nTot1DHits_i;
90 LogTrace(metname) <<
" * trajC " << j
91 <<
" (pT="<<(*jter)->lastMeasurement().updatedState().globalMomentum().perp()
92 <<
" GeV) - chi2/nDOF = " << (*jter)->chiSquared() <<
"/" << (*jter)->ndof() <<
" = " << chi2_dof_j;
93 LogTrace(metname) <<
" - valid RH = " << (*jter)->foundHits() <<
" / total RH = " << nTotHits_j <<
" / total 1D RH = " << nTot1DHits_j;
96 int hit_diff = (*iter)->foundHits() - (*jter)->foundHits() ;
100 if (
abs(hit_diff) <= 4 ) {
105 double maxFraction = 0.95;
107 double fraction = (2.*
match)/((*iter)->measurements().size()+(*jter)->measurements().size());
111 if((*jter)->lastMeasurement().updatedState().globalMomentum().perp() <= minPt) ++belowLimit;
112 if((*iter)->lastMeasurement().updatedState().globalMomentum().perp() <= minPt) ++belowLimit;
114 if((*jter)->lastMeasurement().updatedState().globalMomentum().perp() >= dPt) ++above;
115 if((*iter)->lastMeasurement().updatedState().globalMomentum().perp() >= dPt) ++above;
118 if(fraction >= maxFraction && belowLimit == 1 && above == 1){
119 if((*iter)->lastMeasurement().updatedState().globalMomentum().perp() < minPt){
122 seedmap[
j].insert(seedmap[j].
end(), seedmap[i].
begin(), seedmap[i].
end());
124 LogTrace(metname) <<
"Trajectory # " << i <<
" (pT="<<(*iter)->lastMeasurement().updatedState().globalMomentum().perp()
125 <<
" GeV) rejected because it has too low pt";
129 seedmap[
i].insert(seedmap[i].
end(), seedmap[j].
begin(), seedmap[j].
end());
131 LogTrace(metname) <<
"Trajectory # " << j <<
" (pT="<<(*jter)->lastMeasurement().updatedState().globalMomentum().perp()
132 <<
" GeV) rejected because it has too low pt";
136 if (chi2_dof_i > chi2_dof_j) {
139 seedmap[
j].insert(seedmap[j].
end(), seedmap[i].
begin(), seedmap[i].
end());
141 LogTrace(metname) <<
"Trajectory # " << i <<
" (pT="<<(*iter)->lastMeasurement().updatedState().globalMomentum().perp() <<
" GeV) rejected";
145 seedmap[
i].insert(seedmap[i].
end(), seedmap[j].
begin(), seedmap[j].
end());
147 LogTrace(metname) <<
"Trajectory # " << j <<
" (pT="<<(*jter)->lastMeasurement().updatedState().globalMomentum().perp() <<
" GeV) rejected";
152 if ( hit_diff < 0 ) {
155 seedmap[
j].insert(seedmap[j].
end(), seedmap[i].
begin(), seedmap[i].
end());
157 LogTrace(metname) <<
"Trajectory # " << i <<
" (pT="<<(*iter)->lastMeasurement().updatedState().globalMomentum().perp() <<
" GeV) rejected";
161 seedmap[
i].insert(seedmap[i].
end(), seedmap[j].
begin(), seedmap[j].
end());
163 LogTrace(metname) <<
"Trajectory # " << j <<
" (pT="<<(*jter)->lastMeasurement().updatedState().globalMomentum().perp() <<
" GeV) rejected";
171 if(skipnext)
continue;
177 LogTrace(metname) <<
" Creating map between chosen seed and ghost seeds." << std::endl;
179 auto_ptr<L2SeedAssoc> seedToSeedsMap(
new L2SeedAssoc);
182 for(
map<
int, vector<int> >::iterator itmap=seedmap.begin(); itmap!=seedmap.end(); ++itmap, ++seedcnt) {
186 int tmpsize=(*itmap).second.size();
187 for(
int cnt=0; cnt!=tmpsize; ++cnt) {
190 seedToSeedsMap->insert(tmpL2SeedRef1, tmpL2SeedRef2);
194 event.put(seedToSeedsMap,
"");
199 for ( iter = trajC.begin(); iter != trajC.end(); iter++ ) {
201 result.push_back(*iter);
202 LogTrace(metname) <<
"Keep trajectory with pT = " << (*iter)->lastMeasurement().updatedState().globalMomentum().perp() <<
" GeV";
218 LogTrace(metname) <<
"Muon Trajectory Cleaner called" << endl;
220 if ( candC.size() < 2 )
return;
222 CandidateContainer::iterator
iter, jter;
223 Trajectory::DataContainer::const_iterator m1, m2;
227 const float deltaPt = 1.0;
229 LogTrace(metname) <<
"Number of muon candidates in the container: " <<candC.size()<< endl;
238 vector<bool> mask(candC.size(),
true);
242 for ( iter = candC.begin(); iter != candC.end(); iter++ ) {
243 if ( !mask[
i] ) { i++;
continue; }
251 innerTSOS = (*iter)->trajectory()->firstMeasurement().updatedState();
254 innerTSOS = (*iter)->trajectory()->lastMeasurement().updatedState();
256 if ( !(innerTSOS.
isValid()) )
continue;
261 for ( jter = iter+1; jter != candC.end(); jter++ ) {
262 if ( !mask[j] ) { j++;
continue; }
266 for ( m1 = meas1.begin(); m1 != meas1.end(); m1++ ) {
267 for ( m2 = meas2.begin(); m2 != meas2.end(); m2++ ) {
268 if ( (*m1).recHit()->isValid() && (*m2).recHit()->isValid() )
269 if ( ( (*m1).recHit()->globalPosition() - (*m2).recHit()->globalPosition()).
mag()< 10
e-5 ) match++;
274 <<
" MuonTrajectoryCleaner: candC " << i <<
" chi2/nRH = "
275 << (*iter)->trajectory()->chiSquared() <<
"/" << (*iter)->trajectory()->foundHits() <<
276 " vs trajC " << j <<
" chi2/nRH = " << (*jter)->trajectory()->chiSquared() <<
277 "/" << (*jter)->trajectory()->foundHits() <<
" Shared RecHits: " <<
match;
281 innerTSOS2 = (*jter)->trajectory()->firstMeasurement().updatedState();
284 innerTSOS2 = (*jter)->trajectory()->lastMeasurement().updatedState();
286 if ( !(innerTSOS2.
isValid()) )
continue;
292 float deta(fabs(eta1-eta2));
294 float dpt(fabs(pt1-pt2));
295 if ( dpt < deltaPt && deta < deltaEta && dphi < deltaPhi ) {
298 <<
" MuonTrajectoryCleaner: candC " << i<<
" and "<<j<<
" direction matched: "
303 bool hitsMatch = ((match > 0) && ((match/((*iter)->trajectory()->foundHits()) > 0.25) || (match/((*jter)->trajectory()->foundHits()) > 0.25))) ?
true :
false;
305 ( ( (*iter)->trackerTrack() == (*jter)->trackerTrack() ) &&
306 ( deltaR<double>((*iter)->muonTrack()->eta(),(*iter)->muonTrack()->phi(), (*jter)->muonTrack()->eta(),(*jter)->muonTrack()->phi()) < 0.2) );
309 if ( ( tracksMatch ) || (hitsMatch > 0) ) {
310 if ( (*iter)->trajectory()->foundHits() == (*jter)->trajectory()->foundHits() ) {
311 if ( (*iter)->trajectory()->chiSquared() > (*jter)->trajectory()->chiSquared() ) {
315 else mask[
j] =
false;
318 if ( (*iter)->trajectory()->foundHits() < (*jter)->trajectory()->foundHits() ) {
322 else mask[
j] =
false;
329 if(skipnext)
continue;
333 for ( iter = candC.begin(); iter != candC.end(); iter++ ) {
335 result.push_back(*iter);
337 delete (*iter)->trajectory();
338 delete (*iter)->trackerTrajectory();
const std::string metname
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Geom::Phi< T > phi() const
edm::AssociationMap< edm::OneToMany< L2MuonTrajectorySeedCollection, L2MuonTrajectorySeedCollection > > L2SeedAssoc
static TransientTrackingRecHit::ConstRecHitContainer breakInSubRecHits(TransientTrackingRecHit::ConstRecHitPointer, int granularity)
takes a muon rechit and returns its sub-rechits given a certain granularity
void clean(TrajectoryContainer &muonTrajectories, edm::Event &evt)
Clean the trajectories container, erasing the (worst) clone trajectory.
std::vector< TrajectoryMeasurement > DataContainer
MuonCandidate::CandidateContainer CandidateContainer
Abs< T >::type abs(const T &t)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
std::vector< ConstRecHitPointer > ConstRecHitContainer
MuonCandidate::TrajectoryContainer TrajectoryContainer
REF castTo() const
cast to a concrete type
GlobalVector globalMomentum() const
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.