CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions
TrajectoryCleanerMerger Class Reference

#include <TrajectoryCleanerMerger.h>

Inheritance diagram for TrajectoryCleanerMerger:
TrajectoryCleaner

Public Member Functions

virtual void clean (TrajectoryPointerContainer &) const
 
void clean (TrajectoryContainer &trajs) const
 
 TrajectoryCleanerMerger (const edm::ParameterSet &iConfig)
 
virtual ~TrajectoryCleanerMerger ()
 
- Public Member Functions inherited from TrajectoryCleaner
 TrajectoryCleaner ()
 
 TrajectoryCleaner (edm::ParameterSet &iConfig)
 
virtual ~TrajectoryCleaner ()
 

Private Member Functions

int getLayer (const DetId &id) const
 
void reOrderMeasurements (Trajectory &traj) const
 
bool sameSeed (const TrajectorySeed &s1, const TrajectorySeed &s2) const
 

Additional Inherited Members

- Public Types inherited from TrajectoryCleaner
typedef TrackingComponentsRecord Record
 
typedef std::vector< TrajectoryTrajectoryContainer
 
typedef
TrajectoryContainer::iterator 
TrajectoryIterator
 
typedef std::vector< Trajectory * > TrajectoryPointerContainer
 
typedef
TrajectoryPointerContainer::iterator 
TrajectoryPointerIterator
 

Detailed Description

Definition at line 6 of file TrajectoryCleanerMerger.h.

Constructor & Destructor Documentation

TrajectoryCleanerMerger::TrajectoryCleanerMerger ( const edm::ParameterSet iConfig)
inline

Definition at line 9 of file TrajectoryCleanerMerger.h.

9 {};
virtual TrajectoryCleanerMerger::~TrajectoryCleanerMerger ( )
inlinevirtual

Definition at line 10 of file TrajectoryCleanerMerger.h.

10 {};

Member Function Documentation

void TrajectoryCleanerMerger::clean ( TrajectoryPointerContainer ) const
virtual

Implements TrajectoryCleaner.

Definition at line 131 of file TrajectoryCleanerMerger.cc.

132 {
133 }
void TrajectoryCleanerMerger::clean ( TrajectoryContainer trajs) const
virtual

Reimplemented from TrajectoryCleaner.

Definition at line 227 of file TrajectoryCleanerMerger.cc.

References benchmark_cfg::cerr, i, TrackingRecHit::isValid(), j, keep, python.multivaluedict::map(), match(), min, convertSQLiteXML::ok, and funct::true.

228 {
229  if(trajs.size() == 0) return;
230 
231  // Fill the rechit map
232  typedef std::map<const TransientTrackingRecHit*,
233  std::vector<unsigned int>, HitComparator> RecHitMap;
234  RecHitMap recHitMap;
235 
236  std::vector<bool> keep(trajs.size(),true);
237 
238  for(unsigned int i = 0; i < trajs.size(); i++)
239  {
240  std::vector<TrajectoryMeasurement> meas = trajs[i].measurements();
241 
242  for(std::vector<TrajectoryMeasurement>::iterator im = meas.begin();
243  im!= meas.end(); im++)
244  if(im->recHit()->isValid())
245  {
246  const TransientTrackingRecHit* recHit = &(*(im->recHit()));
247  if(recHit->isValid())
248  recHitMap[recHit].push_back(i);
249  }
250  }
251 
252  // Look at each track
253  typedef std::map<unsigned int,int,less<unsigned int> > TrajMap;
254 
255  for(unsigned int i = 0; i < trajs.size(); i++)
256  if(keep[i])
257  {
258  TrajMap trajMap;
259  std::vector<DetId> detIds;
260  std::vector<int> detLayers;
261 
262  // Go trough all rechits of this track
263  std::vector<TrajectoryMeasurement> meas = trajs[i].measurements();
264  for(std::vector<TrajectoryMeasurement>::iterator im = meas.begin();
265  im!= meas.end(); im++)
266  {
267  if(im->recHit()->isValid())
268  {
269  // Get trajs sharing this rechit
270  const TransientTrackingRecHit* recHit = &(*(im->recHit()));
271  const std::vector<unsigned int>& sharing(recHitMap[recHit]);
272 
273  for(std::vector<unsigned int>::const_iterator j = sharing.begin();
274  j!= sharing.end(); j++)
275  if(i < *j) trajMap[*j]++;
276 
277  // Fill detLayers vector
278  detIds.push_back(recHit->geographicalId());
279  detLayers.push_back(getLayer(recHit->geographicalId()));
280  }
281  }
282 
283  // Check for trajs with shared rechits
284  for(TrajMap::iterator sharing = trajMap.begin();
285  sharing!= trajMap.end(); sharing++)
286  {
287  unsigned int j = (*sharing).first;
288  if(!keep[i] || !keep[j]) continue;
289 
290  // More than 50% shared
291  if((*sharing).second > min(trajs[i].foundHits(),
292  trajs[j].foundHits())/2)
293  {
294  if( sameSeed(trajs[i].seed(), trajs[j].seed()) )
295  {
296  bool hasCommonLayer = false;
297 
298 /*
299  std::vector<TrajectoryMeasurement> measi = trajs[i].measurements();
300  std::vector<TrajectoryMeasurement> measj = trajs[j].measurements();
301  for(std::vector<TrajectoryMeasurement>::iterator
302  tmj = measj.begin(); tmj!= measj.end(); tmj++)
303  if(find(measi.begin(), measi.end(), tmj) == measi.end())
304  if(find(detLayers.begin(),detLayers.end(),
305  getLayer(tmj->recHit()->geographicalId()))
306  != detLayers.end())
307  hasCommonLayer = true;
308 */
309 
310  if(hasCommonLayer == false)
311  { // merge tracks, add separate hits of the second to the first one
312  std::vector<TrajectoryMeasurement> measj = trajs[j].measurements();
313  for(std::vector<TrajectoryMeasurement>::iterator
314  tmj = measj.begin(); tmj!= measj.end(); tmj++)
315  if(tmj->recHit()->isValid())
316  {
317  bool match = false;
318 
319  std::vector<TrajectoryMeasurement> measi = trajs[i].measurements();
320  for(std::vector<TrajectoryMeasurement>::iterator
321  tmi = measi.begin(); tmi!= measi.end(); tmi++)
322  if(tmi->recHit()->isValid())
323  if(!HitComparator()(&(*(tmi->recHit())),
324  &(*(tmj->recHit()))) &&
325  !HitComparator()(&(*(tmj->recHit())),
326  &(*(tmi->recHit()))))
327  { match = true ; break; }
328 
329  if(!match)
330  trajs[i].push(*tmj);
331  }
332 
333  // Remove second track
334  keep[j] = false;
335  }
336  else
337  {
338  // remove track with higher impact / chi2
339  if(trajs[i].chiSquared() < trajs[j].chiSquared())
340  keep[j] = false;
341  else
342  keep[i] = false;
343  }
344  }
345  }
346  }
347  }
348 
349  // Final copy
350  int ok = 0;
351  for(unsigned int i = 0; i < trajs.size(); i++)
352  if(keep[i])
353  {
354  reOrderMeasurements(trajs[i]);
355  ok++;
356  }
357  else
358  trajs[i].invalidate();
359 
360  std::cerr << " [TrajecCleaner] cleaned trajs : " << ok << "/" << trajs.size() <<
361 " (with " << trajs[0].measurements().size() << "/" << recHitMap.size() << " hits)" << std::endl;
362 }
int i
Definition: DBlmapReader.cc:9
void reOrderMeasurements(Trajectory &traj) const
#define min(a, b)
Definition: mlp_lapack.h:161
const int keep
bool sameSeed(const TrajectorySeed &s1, const TrajectorySeed &s2) const
int j
Definition: DBlmapReader.cc:9
int getLayer(const DetId &id) const
bool isValid() const
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
DetId geographicalId() const
int TrajectoryCleanerMerger::getLayer ( const DetId id) const
private

Definition at line 196 of file TrajectoryCleanerMerger.cc.

References PXFDetId::disk(), PXBDetId::ladder(), PXBDetId::layer(), TOBDetId::layer(), TIBDetId::layer(), TOBDetId::module(), TIBDetId::module(), PXFDetId::panel(), evf::utils::pid, PixelSubdetector::PixelBarrel, PixelSubdetector::PixelEndcap, TIDDetId::ring(), TECDetId::ring(), StripSubdetector::TEC, StripSubdetector::TIB, StripSubdetector::TID, StripSubdetector::TOB, TIDDetId::wheel(), and TECDetId::wheel().

197 {
198  // PXB layer, ladder -> (layer - 1)<<2 + (ladder-1)%2
199  // PXF disk , panel
200  // TIB layer, module
201  // TOB layer, module
202  // TID wheel, ring
203  // TEC wheel, ring
204 
205  if(id.subdetId() == (unsigned int) PixelSubdetector::PixelBarrel)
206  { PXBDetId pid(id); return (100 * id.subdetId()+ ((pid.layer() - 1)<<1) + (pid.ladder() - 1)%2); }
207 
208  if(id.subdetId() == (unsigned int) PixelSubdetector::PixelEndcap)
209  { PXFDetId pid(id); return (100 * id.subdetId()+ ((pid.disk() - 1)<<1) + (pid.panel() - 1)%2); }
210 
211  if(id.subdetId() == StripSubdetector::TIB)
212  { TIBDetId pid(id); return (100 * id.subdetId()+ ((pid.layer() - 1)<<1) + (pid.module() - 1)%2); }
213  if(id.subdetId() == StripSubdetector::TOB)
214  { TOBDetId pid(id); return (100 * id.subdetId()+ ((pid.layer() - 1)<<1) + (pid.module() - 1)%2); }
215 
216  if(id.subdetId() == StripSubdetector::TID)
217  { TIDDetId pid(id); return (100 * id.subdetId()+ ((pid.wheel() - 1)<<1) + (pid.ring() - 1)%2); }
218  if(id.subdetId() == StripSubdetector::TEC)
219  { TECDetId pid(id); return (100 * id.subdetId()+ ((pid.wheel() - 1)<<1) + (pid.ring() - 1)%2); }
220 
221  return 0;
222 }
void TrajectoryCleanerMerger::reOrderMeasurements ( Trajectory traj) const
private

Definition at line 136 of file TrajectoryCleanerMerger.cc.

References i, Trajectory::measurements(), Trajectory::pop(), Trajectory::push(), and std::swap().

137 {
138  std::vector<TrajectoryMeasurement> meas_ = traj.measurements();
139  std::vector<TrajectoryMeasurement> meas;
140 
141  for(std::vector<TrajectoryMeasurement>::iterator
142  im = meas_.begin();
143  im!= meas_.end(); im++)
144  if(im->recHit()->isValid())
145  meas.push_back(*im);
146 
147  bool changed;
148 
149  do
150  {
151  changed = false;
152 
153  for(std::vector<TrajectoryMeasurement>::iterator im = meas.begin();
154  im!= meas.end()-1; im++)
155  if( (*im).recHit()->globalPosition().mag2() >
156  (*(im+1)).recHit()->globalPosition().mag2() + 1e-6)
157  {
158  swap(*im,*(im+1));
159  changed = true;
160  }
161  }
162  while(changed);
163 
164  for(unsigned int i = 0 ; i < meas.size(); i++)
165  traj.pop();
166 
167  for(std::vector<TrajectoryMeasurement>::iterator im = meas.begin();
168  im!= meas.end(); im++)
169  traj.push(*im);
170 }
void swap(ora::Record &rh, ora::Record &lh)
Definition: Record.h:74
int i
Definition: DBlmapReader.cc:9
DataContainer const & measurements() const
Definition: Trajectory.h:169
void pop()
Definition: Trajectory.cc:17
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:35
bool TrajectoryCleanerMerger::sameSeed ( const TrajectorySeed s1,
const TrajectorySeed s2 
) const
private

Definition at line 172 of file TrajectoryCleanerMerger.cc.

References TrackingRecHit::all, TrajectorySeed::nHits(), and TrajectorySeed::recHits().

173 {
174  if(s1.nHits() != s2.nHits()) return false;
175 
176  TrajectorySeed::range r1 = s1.recHits();
177  TrajectorySeed::range r2 = s2.recHits();
178 
179  TrajectorySeed::const_iterator h1 = r1.first;
180  TrajectorySeed::const_iterator h2 = r2.first;
181 
182  do
183  {
184  if(!(h1->sharesInput(&(*h2),TrackingRecHit::all)))
185  return false;
186 
187  h1++; h2++;
188  }
189  while(h1 != s1.recHits().second &&
190  h2 != s2.recHits().second);
191 
192  return true;
193 }
recHitContainer::const_iterator const_iterator
std::pair< const_iterator, const_iterator > range
range recHits() const
unsigned int nHits() const