25 LogTrace(metname) <<
"Muon Trajectory Cleaner called" << endl;
27 TrajectoryContainer::iterator iter, jter;
28 Trajectory::DataContainer::const_iterator m1,
m2;
33 LogTrace(metname) <<
"Number of trajectories in the container: " << trajC.size() << endl;
39 map<int, vector<int> > seedmap;
44 vector<bool> mask(trajC.size(),
true);
48 for (iter = trajC.begin(); iter != trajC.end(); iter++) {
53 if (!(*iter)->isValid() || (*iter)->empty()) {
58 if (seedmap.count(i) == 0)
59 seedmap[i].push_back(i);
62 bool skipnext =
false;
63 for (jter = iter + 1; jter != trajC.end(); jter++) {
68 if (seedmap.count(j) == 0)
69 seedmap[j].push_back(j);
72 for (m1 = meas1.begin(); m1 != meas1.end(); m1++) {
73 for (m2 = meas2.begin(); m2 != meas2.end(); m2++) {
74 if (((*m1).recHit()->globalPosition() - (*m2).recHit()->globalPosition()).
mag() < 10
e-5)
80 double chi2_dof_i = (*iter)->ndof() > 0 ? (*iter)->chiSquared() / (*iter)->ndof() : (*iter)->chiSquared() / 1
e-10;
81 double chi2_dof_j = (*jter)->ndof() > 0 ? (*jter)->chiSquared() / (*jter)->ndof() : (*jter)->chiSquared() / 1
e-10;
83 LogTrace(metname) <<
" MuonTrajectoryCleaner:";
84 LogTrace(metname) <<
" * trajC " << i
85 <<
" (pT=" << (*iter)->lastMeasurement().updatedState().globalMomentum().perp()
86 <<
" GeV) - chi2/nDOF = " << (*iter)->chiSquared() <<
"/" << (*iter)->ndof() <<
" = "
88 LogTrace(metname) <<
" - valid RH = " << (*iter)->foundHits()
89 <<
" / total RH = " << (*iter)->measurements().size();
90 LogTrace(metname) <<
" * trajC " << j
91 <<
" (pT=" << (*jter)->lastMeasurement().updatedState().globalMomentum().perp()
92 <<
" GeV) - chi2/nDOF = " << (*jter)->chiSquared() <<
"/" << (*jter)->ndof() <<
" = "
94 LogTrace(metname) <<
" - valid RH = " << (*jter)->foundHits()
95 <<
" / total RH = " << (*jter)->measurements().size();
98 int hit_diff = (*iter)->foundHits() - (*jter)->foundHits();
102 if (
abs(hit_diff) == 0) {
109 double fraction = (2. *
match) / ((*iter)->measurements().size() + (*jter)->measurements().size());
113 if ((*jter)->lastMeasurement().updatedState().globalMomentum().perp() <=
minPt)
115 if ((*iter)->lastMeasurement().updatedState().globalMomentum().perp() <=
minPt)
118 if ((*jter)->lastMeasurement().updatedState().globalMomentum().perp() >= dPt)
120 if ((*iter)->lastMeasurement().updatedState().globalMomentum().perp() >= dPt)
123 if (fraction >= maxFraction && belowLimit == 1 && above == 1) {
124 if ((*iter)->lastMeasurement().updatedState().globalMomentum().perp() <
minPt) {
127 seedmap[
j].insert(seedmap[j].
end(), seedmap[i].
begin(), seedmap[i].
end());
129 LogTrace(metname) <<
"Trajectory # " << i
130 <<
" (pT=" << (*iter)->lastMeasurement().updatedState().globalMomentum().perp()
131 <<
" GeV) rejected because it has too low pt";
134 seedmap[
i].insert(seedmap[i].
end(), seedmap[j].
begin(), seedmap[j].
end());
136 LogTrace(metname) <<
"Trajectory # " << j
137 <<
" (pT=" << (*jter)->lastMeasurement().updatedState().globalMomentum().perp()
138 <<
" GeV) rejected because it has too low pt";
141 if (chi2_dof_i > chi2_dof_j) {
144 seedmap[
j].insert(seedmap[j].
end(), seedmap[i].
begin(), seedmap[i].
end());
146 LogTrace(metname) <<
"Trajectory # " << i
147 <<
" (pT=" << (*iter)->lastMeasurement().updatedState().globalMomentum().perp()
151 seedmap[
i].insert(seedmap[i].
end(), seedmap[j].
begin(), seedmap[j].
end());
153 LogTrace(metname) <<
"Trajectory # " << j
154 <<
" (pT=" << (*jter)->lastMeasurement().updatedState().globalMomentum().perp()
162 seedmap[
j].insert(seedmap[j].
end(), seedmap[i].
begin(), seedmap[i].
end());
164 LogTrace(metname) <<
"Trajectory # " << i
165 <<
" (pT=" << (*iter)->lastMeasurement().updatedState().globalMomentum().perp()
169 seedmap[
i].insert(seedmap[i].
end(), seedmap[j].
begin(), seedmap[j].
end());
171 LogTrace(metname) <<
"Trajectory # " << j
172 <<
" (pT=" << (*jter)->lastMeasurement().updatedState().globalMomentum().perp()
188 LogTrace(metname) <<
" Creating map between chosen seed and ghost seeds." << std::endl;
190 auto seedToSeedsMap = std::make_unique<L2SeedAssoc>();
191 if (!
seeds->empty()) {
194 event.get(ptr.
id(), seedsHandle);
195 seedToSeedsMap = std::make_unique<L2SeedAssoc>(seedsHandle, seedsHandle);
200 for (map<
int, vector<int> >::iterator itmap = seedmap.begin(); itmap != seedmap.end(); ++itmap, ++seedcnt) {
205 int tmpsize = (*itmap).second.size();
206 for (
int cnt = 0; cnt != tmpsize; ++cnt) {
210 seedToSeedsMap->insert(tmpL2SeedRef1, tmpL2SeedRef2);
214 event.put(
std::move(seedToSeedsMap),
"");
219 auto c =
std::count(mask.begin(), mask.end(),
true);
221 for (iter = trajC.begin(); iter != trajC.end(); iter++) {
223 LogTrace(metname) <<
"Keep trajectory with pT = "
224 << (*iter)->lastMeasurement().updatedState().globalMomentum().perp() <<
" GeV";
239 LogTrace(metname) <<
"Muon Trajectory Cleaner called" << endl;
241 if (candC.size() < 2)
244 CandidateContainer::iterator iter, jter;
245 Trajectory::DataContainer::const_iterator m1,
m2;
249 const float deltaPt = 1.0;
251 LogTrace(metname) <<
"Number of muon candidates in the container: " << candC.size() << endl;
260 vector<bool> mask(candC.size(),
true);
264 for (iter = candC.begin(); iter != candC.end(); iter++) {
271 bool skipnext =
false;
276 innerTSOS = (*iter)->trajectory()->firstMeasurement().updatedState();
278 innerTSOS = (*iter)->trajectory()->lastMeasurement().updatedState();
286 for (jter = iter + 1; jter != candC.end(); jter++) {
294 for (m1 = meas1.begin(); m1 != meas1.end(); m1++) {
295 for (m2 = meas2.begin(); m2 != meas2.end(); m2++) {
296 if ((*m1).recHit()->isValid() && (*m2).recHit()->isValid())
297 if (((*m1).recHit()->globalPosition() - (*m2).recHit()->globalPosition()).
mag() < 10
e-5)
302 LogTrace(metname) <<
" MuonTrajectoryCleaner: candC " << i
303 <<
" chi2/nRH = " << (*iter)->trajectory()->chiSquared() <<
"/"
304 << (*iter)->trajectory()->foundHits() <<
" vs trajC " << j
305 <<
" chi2/nRH = " << (*jter)->trajectory()->chiSquared() <<
"/"
306 << (*jter)->trajectory()->foundHits() <<
" Shared RecHits: " <<
match;
310 innerTSOS2 = (*jter)->trajectory()->firstMeasurement().updatedState();
312 innerTSOS2 = (*jter)->trajectory()->lastMeasurement().updatedState();
321 float deta(fabs(eta1 - eta2));
323 float dpt(fabs(pt1 - pt2));
324 if (dpt < deltaPt && deta < deltaEta && dphi < deltaPhi) {
326 LogTrace(metname) <<
" MuonTrajectoryCleaner: candC " << i <<
" and " << j
327 <<
" direction matched: " << innerTSOS.
globalMomentum() <<
" and "
332 bool hitsMatch = ((match > 0) && ((match / ((*iter)->trajectory()->foundHits()) > 0.25) ||
333 (match / ((*jter)->trajectory()->foundHits()) > 0.25)))
337 (((*iter)->trackerTrack() == (*jter)->trackerTrack()) && (deltaR<double>((*iter)->muonTrack()->eta(),
338 (*iter)->muonTrack()->phi(),
339 (*jter)->muonTrack()->eta(),
340 (*jter)->muonTrack()->phi()) < 0.2));
343 if ((tracksMatch) || (hitsMatch > 0)) {
344 if ((*iter)->trajectory()->foundHits() == (*jter)->trajectory()->foundHits()) {
345 if ((*iter)->trajectory()->chiSquared() > (*jter)->trajectory()->chiSquared()) {
351 if ((*iter)->trajectory()->foundHits() < (*jter)->trajectory()->foundHits()) {
367 auto c =
std::count(mask.begin(), mask.end(),
true);
370 for (iter = candC.begin(); iter != candC.end(); iter++) {
const edm::EventSetup & c
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.