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 130 of file TrajectoryCleanerMerger.cc.

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

Reimplemented from TrajectoryCleaner.

Definition at line 226 of file TrajectoryCleanerMerger.cc.

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

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

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

Definition at line 135 of file TrajectoryCleanerMerger.cc.

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

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

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

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