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 Types | Private Member Functions | Private Attributes
DAFTrackProducerAlgorithm Class Reference

#include <DAFTrackProducerAlgorithm.h>

Public Member Functions

 DAFTrackProducerAlgorithm (const edm::ParameterSet &pset)
 Constructor. More...
 
void runWithCandidate (const TrackingGeometry *, const MagneticField *, const std::vector< Trajectory > &, const TrajectoryFitter *, const TransientTrackingRecHitBuilder *, const MultiRecHitCollector *measurementTracker, const SiTrackerMultiRecHitUpdator *, const reco::BeamSpot &, AlgoProductCollection &) const
 Run the Final Fit taking TrackCandidates as input. More...
 
 ~DAFTrackProducerAlgorithm ()
 Destructor. More...
 

Private Types

typedef std::pair< Trajectory
*, std::pair< reco::Track
*, PropagationDirection > > 
AlgoProduct
 
typedef std::vector< AlgoProductAlgoProductCollection
 

Private Member Functions

bool buildTrack (const std::vector< Trajectory > &, AlgoProductCollection &algoResults, float, const reco::BeamSpot &) const
 Construct Tracks to be put in the event. More...
 
float calculateNdof (const std::vector< Trajectory > &vtraj) const
 
std::pair
< TransientTrackingRecHit::RecHitContainer,
TrajectoryStateOnSurface
collectHits (const std::vector< Trajectory > &vtraj, const MultiRecHitCollector *measurementCollector) const
 
void filter (const TrajectoryFitter *fitter, std::vector< Trajectory > &input, int minhits, std::vector< Trajectory > &output) const
 
void fit (const std::pair< TransientTrackingRecHit::RecHitContainer, TrajectoryStateOnSurface > &hits, const TrajectoryFitter *theFitter, std::vector< Trajectory > &vtraj) const
 accomplishes the fitting-smoothing step for each annealing value More...
 
std::pair
< TransientTrackingRecHit::RecHitContainer,
TrajectoryStateOnSurface
updateHits (const std::vector< Trajectory > &vtraj, const SiTrackerMultiRecHitUpdator *updator, double annealing) const
 

Private Attributes

edm::ParameterSet conf_
 

Detailed Description

Definition at line 22 of file DAFTrackProducerAlgorithm.h.

Member Typedef Documentation

Definition at line 24 of file DAFTrackProducerAlgorithm.h.

Definition at line 25 of file DAFTrackProducerAlgorithm.h.

Constructor & Destructor Documentation

DAFTrackProducerAlgorithm::DAFTrackProducerAlgorithm ( const edm::ParameterSet pset)
inline

Constructor.

Definition at line 30 of file DAFTrackProducerAlgorithm.h.

30 :conf_(pset){}
DAFTrackProducerAlgorithm::~DAFTrackProducerAlgorithm ( )
inline

Destructor.

Definition at line 33 of file DAFTrackProducerAlgorithm.h.

33 {}

Member Function Documentation

bool DAFTrackProducerAlgorithm::buildTrack ( const std::vector< Trajectory > &  vtraj,
AlgoProductCollection algoResults,
float  ndof,
const reco::BeamSpot bs 
) const
private

Construct Tracks to be put in the event.

Definition at line 148 of file DAFTrackProducerAlgorithm.cc.

References alongMomentum, FreeTrajectoryState::charge(), Trajectory::chiSquared(), FreeTrajectoryState::curvilinearError(), Trajectory::direction(), Trajectory::firstMeasurement(), TrajectoryStateOnSurface::freeState(), TrajectoryStateClosestToBeamLine::isValid(), Trajectory::lastMeasurement(), LogDebug, FreeTrajectoryState::momentum(), L1TEmulatorMonitor_cff::p, pos, FreeTrajectoryState::position(), TrajectoryStateClosestToBeamLine::trackStateAtPCA(), TrajectoryMeasurement::updatedState(), v, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by runWithCandidate().

151  {
152  //variable declarations
153  reco::Track * theTrack;
154  Trajectory * theTraj;
155 
156  //perform the fit: the result's size is 1 if it succeded, 0 if fails
157 
158 
159  //LogDebug("TrackProducer") <<" FITTER FOUND "<< vtraj.size() << " TRAJECTORIES" <<"\n";
160  LogDebug("DAFTrackProducerAlgorithm") <<" FITTER FOUND "<< vtraj.size() << " TRAJECTORIES" << std::endl;;
161  TrajectoryStateOnSurface innertsos;
162 
163  if (vtraj.size() != 0){
164 
165  theTraj = new Trajectory( vtraj.front() );
166 
167  if (theTraj->direction() == alongMomentum) {
168  //if (theTraj->direction() == oppositeToMomentum) {
169  innertsos = theTraj->firstMeasurement().updatedState();
170  //std::cout << "Inner momentum " << innertsos.globalParameters().momentum().mag() << std::endl;
171  } else {
172  innertsos = theTraj->lastMeasurement().updatedState();
173  }
174 
175  TSCBLBuilderNoMaterial tscblBuilder;
176  TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(*(innertsos.freeState()),bs);
177 
178  if (tscbl.isValid()==false) return false;
179 
181  math::XYZPoint pos( v.x(), v.y(), v.z() );
183  math::XYZVector mom( p.x(), p.y(), p.z() );
184 
185  // LogDebug("TrackProducer") <<v<<p<<std::endl;
186 
187  theTrack = new reco::Track(theTraj->chiSquared(),
188  ndof, //in the DAF the ndof is not-integer
189  pos, mom, tscbl.trackStateAtPCA().charge(), tscbl.trackStateAtPCA().curvilinearError());
190 
191 
192 
193  AlgoProduct aProduct(theTraj,std::make_pair(theTrack,theTraj->direction()));
194 
195  algoResults.push_back(aProduct);
196 
197 
198  return true;
199  }
200  else return false;
201 }
#define LogDebug(id)
std::pair< Trajectory *, std::pair< reco::Track *, PropagationDirection > > AlgoProduct
T y() const
Definition: PV3DBase.h:57
TrackCharge charge() const
const CurvilinearTrajectoryError & curvilinearError() const
PropagationDirection const & direction() const
Definition: Trajectory.cc:195
FreeTrajectoryState * freeState(bool withErrors=true) const
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:147
T z() const
Definition: PV3DBase.h:58
TrajectoryStateOnSurface updatedState() const
GlobalVector momentum() const
GlobalPoint position() const
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:160
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
T x() const
Definition: PV3DBase.h:56
mathSSE::Vec4< T > v
double chiSquared() const
Definition: Trajectory.h:208
float DAFTrackProducerAlgorithm::calculateNdof ( const std::vector< Trajectory > &  vtraj) const
private

Definition at line 249 of file DAFTrackProducerAlgorithm.cc.

Referenced by runWithCandidate().

249  {
250  if (vtraj.empty()) return 0;
251  float ndof = 0;
252  const std::vector<TrajectoryMeasurement>& meas = vtraj.front().measurements();
253  for (std::vector<TrajectoryMeasurement>::const_iterator iter = meas.begin(); iter != meas.end(); iter++){
254  if (iter->recHit()->isValid()){
255  TransientTrackingRecHit::ConstRecHitContainer components = iter->recHit()->transientHits();
256  TransientTrackingRecHit::ConstRecHitContainer::const_iterator iter2;
257  for (iter2 = components.begin(); iter2 != components.end(); iter2++){
258  if ((*iter2)->isValid())ndof+=((*iter2)->dimension())*(*iter2)->weight();
259  }
260  }
261  }
262  return ndof-5;
263 }
std::vector< ConstRecHitPointer > ConstRecHitContainer
std::pair< TransientTrackingRecHit::RecHitContainer, TrajectoryStateOnSurface > DAFTrackProducerAlgorithm::collectHits ( const std::vector< Trajectory > &  vtraj,
const MultiRecHitCollector measurementCollector 
) const
private

Definition at line 109 of file DAFTrackProducerAlgorithm.cc.

References MultiRecHitCollector::recHits().

Referenced by runWithCandidate().

110  {
112  std::vector<TrajectoryMeasurement> collectedmeas = measurementCollector->recHits(vtraj.front());
113  if (collectedmeas.empty()) return std::make_pair(TransientTrackingRecHit::RecHitContainer(), TrajectoryStateOnSurface());
114  for (std::vector<TrajectoryMeasurement>::const_iterator iter = collectedmeas.begin(); iter!=collectedmeas.end(); iter++){
115  hits.push_back(iter->recHit());
116  }
117  return std::make_pair(hits,TrajectoryStateWithArbitraryError()(collectedmeas.front().predictedState()));
118 }
std::vector< ConstRecHitPointer > RecHitContainer
virtual std::vector< TrajectoryMeasurement > recHits(const Trajectory &) const =0
void DAFTrackProducerAlgorithm::filter ( const TrajectoryFitter fitter,
std::vector< Trajectory > &  input,
int  minhits,
std::vector< Trajectory > &  output 
) const
private

Definition at line 203 of file DAFTrackProducerAlgorithm.cc.

References InvalidTransientRecHit::build(), ExpressReco_HICollisions_FallBack::e, TrajectoryFitter::fit(), edm::OwnVector< T, P >::front(), LogDebug, and TrackingRecHit::missing.

203  {
204  if (input.empty()) return;
205 
206  int ngoodhits = 0;
207 
208  std::vector<TrajectoryMeasurement> vtm = input[0].measurements();
209 
211 
212  //count the number of non-outlier and non-invalid hits
213  for (std::vector<TrajectoryMeasurement>::reverse_iterator tm=vtm.rbegin(); tm!=vtm.rend();tm++){
214  //if the rechit is valid
215  if (tm->recHit()->isValid()) {
216  TransientTrackingRecHit::ConstRecHitContainer components = tm->recHit()->transientHits();
217  bool isGood = false;
218  for (TransientTrackingRecHit::ConstRecHitContainer::iterator rechit = components.begin(); rechit != components.end(); rechit++){
219  //if there is at least one component with weight higher than 1e-6 then the hit is not an outlier
220  if ((*rechit)->weight()>1e-6) {ngoodhits++; isGood = true; break;}
221  }
222  if (isGood) hits.push_back(tm->recHit()->clone(tm->updatedState()));
223  else hits.push_back(InvalidTransientRecHit::build(tm->recHit()->det(), TrackingRecHit::missing));
224  } else {
225  hits.push_back(tm->recHit()->clone(tm->updatedState()));
226  }
227  }
228 
229 
230  LogDebug("DAFTrackProducerAlgorithm") << "Original number of valid hits " << input[0].foundHits() << "; after filtering " << ngoodhits;
231  //debug
232  if (ngoodhits>input[0].foundHits()) edm::LogError("DAFTrackProducerAlgorithm") << "Something wrong: the number of good hits from DAFTrackProducerAlgorithm::filter " << ngoodhits << " is higher than the original one " << input[0].foundHits();
233 
234  if (ngoodhits < minhits) return;
235 
236  TrajectoryStateOnSurface curstartingTSOS = input.front().lastMeasurement().updatedState();
237  LogDebug("DAFTrackProducerAlgorithm") << "starting tsos for final refitting " << curstartingTSOS ;
238  //curstartingTSOS.rescaleError(100);
239 
242  input.front().seed().direction()),
243  hits,
244  TrajectoryStateWithArbitraryError()(curstartingTSOS));
245  LogDebug("DAFTrackProducerAlgorithm") << "After filtering " << output.size() << " trajectories";
246 
247 }
#define LogDebug(id)
static RecHitPointer build(const GeomDet *geom, Type type=TrackingRecHit::missing, const DetLayer *layer=0)
std::vector< ConstRecHitPointer > RecHitContainer
tuple input
Definition: collect_tpl.py:10
std::vector< ConstRecHitPointer > ConstRecHitContainer
virtual std::vector< Trajectory > fit(const Trajectory &) const =0
void DAFTrackProducerAlgorithm::fit ( const std::pair< TransientTrackingRecHit::RecHitContainer, TrajectoryStateOnSurface > &  hits,
const TrajectoryFitter theFitter,
std::vector< Trajectory > &  vtraj 
) const
private

accomplishes the fitting-smoothing step for each annealing value

Definition at line 134 of file DAFTrackProducerAlgorithm.cc.

References TrajectoryFitter::fit(), edm::OwnVector< T, P >::front(), and LogDebug.

Referenced by runWithCandidate().

136  {
137  std::vector<Trajectory> newVec = theFitter->fit(TrajectorySeed(PTrajectoryStateOnDet(),
139  vtraj.front().seed().direction()),
140  hits.first,
141  hits.second);
142  vtraj.reserve(newVec.size());
143  vtraj.swap(newVec);
144  LogDebug("DAFTrackProducerAlgorithm") << "swapped!" << std::endl;
145 }
#define LogDebug(id)
virtual std::vector< Trajectory > fit(const Trajectory &) const =0
reference front()
Definition: OwnVector.h:371
void DAFTrackProducerAlgorithm::runWithCandidate ( const TrackingGeometry theG,
const MagneticField theMF,
const std::vector< Trajectory > &  theTrajectoryCollection,
const TrajectoryFitter theFitter,
const TransientTrackingRecHitBuilder builder,
const MultiRecHitCollector measurementTracker,
const SiTrackerMultiRecHitUpdator updator,
const reco::BeamSpot bs,
AlgoProductCollection algoResults 
) const

Run the Final Fit taking TrackCandidates as input.

Definition at line 25 of file DAFTrackProducerAlgorithm.cc.

References buildTrack(), calculateNdof(), collectHits(), conf_, cont, fit(), SiTrackerMultiRecHitUpdator::getAnnealingProgram(), edm::ParameterSet::getParameter(), i, LogDebug, convertSQLiteXML::ok, and updateHits().

Referenced by DAFTrackProducer::produce().

35 {
36  edm::LogInfo("TrackProducer") << "Number of Trajectories: " << theTrajectoryCollection.size() << "\n";
37  int cont = 0;
38  for (std::vector<Trajectory>::const_iterator i=theTrajectoryCollection.begin(); i!=theTrajectoryCollection.end() ;i++)
39 
40 
41 {
42 
43 
44 
45 
46  float ndof=0;
47 
48  //first of all do a fit-smooth round to get the trajectory
49  LogDebug("DAFTrackProducerAlgorithm") << "About to build the trajectory for the first round...";
50  //theMRHChi2Estimator->setAnnealingFactor(1);
51  // std::vector<Trajectory> vtraj = theFitter->fit(seed, hits, theTSOS);
52  std::vector<Trajectory> vtraj;
53  vtraj.push_back(*i);
54 
55  LogDebug("DAFTrackProducerAlgorithm") << "done" << std::endl;
56  LogDebug("DAFTrackProducerAlgorithm") << "after the first round found " << vtraj.size() << " trajectories" << std::endl;
57 
58  if (vtraj.size() != 0){
59 
60  //bool isFirstIteration=true;
61  std::pair<TransientTrackingRecHit::RecHitContainer, TrajectoryStateOnSurface> hits = collectHits(vtraj, measurementCollector);
62  fit(hits, theFitter, vtraj);
63 
64  for (std::vector<double>::const_iterator ian = updator->getAnnealingProgram().begin(); ian != updator->getAnnealingProgram().end(); ian++){
65  if (vtraj.size()){
66  LogDebug("DAFTrackProducerAlgorithm") << "Seed direction is " << vtraj.front().seed().direction()
67  << " Traj direction is " << vtraj.front().direction();
68  std::pair<TransientTrackingRecHit::RecHitContainer, TrajectoryStateOnSurface> curiterationhits = updateHits(vtraj,updator,*ian);
69  fit(curiterationhits, theFitter, vtraj);
70 
71  LogDebug("DAFTrackProducerAlgorithm") << "done annealing value " << (*ian) << " with " << vtraj.size() << " trajectories";
72  } else break;
73  LogDebug("DAFTrackProducerAlgorithm") << "number of trajectories after annealing value " << (*ian) << " annealing step " << vtraj.size();
74  }
75  LogDebug("DAFTrackProducerAlgorithm") << "Ended annealing program with " << vtraj.size() << " trajectories" << std::endl;
76 
77  //check the trajectory to see that the number of valid hits with
78  //reasonable weight (>1e-6) is higher than the minimum set in the DAFTrackProducer.
79  //This is a kind of filter to remove tracks with too many outliers.
80  //Outliers are mrhits with all components with weight less than 1e-6
81 
82  //std::vector<Trajectory> filtered;
83  //filter(theFitter, vtraj, conf_.getParameter<int>("MinHits"), filtered);
84  //ndof = calculateNdof(filtered);
85  ndof=calculateNdof(vtraj);
86  //bool ok = buildTrack(filtered, algoResults, ndof, bs);
87  if (vtraj.size()){
88  if(vtraj.front().foundHits()>=conf_.getParameter<int>("MinHits"))
89  {
90 
91  bool ok = buildTrack(vtraj, algoResults, ndof, bs) ;
92  if(ok) cont++;
93  }
94 
95  else{
96  LogDebug("DAFTrackProducerAlgorithm") << "Rejecting trajectory with " << vtraj.front().foundHits()<<" hits";
97  }
98  }
99 
100  else LogDebug("DAFTrackProducerAlgorithm") << "Rejecting empty trajectory" << std::endl;
101 
102 
103  }
104  }
105  LogDebug("TrackProducer") << "Number of Tracks found: " << cont << "\n";
106 }
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
float calculateNdof(const std::vector< Trajectory > &vtraj) const
const std::vector< double > & getAnnealingProgram() const
bool buildTrack(const std::vector< Trajectory > &, AlgoProductCollection &algoResults, float, const reco::BeamSpot &) const
Construct Tracks to be put in the event.
std::pair< TransientTrackingRecHit::RecHitContainer, TrajectoryStateOnSurface > updateHits(const std::vector< Trajectory > &vtraj, const SiTrackerMultiRecHitUpdator *updator, double annealing) const
std::pair< TransientTrackingRecHit::RecHitContainer, TrajectoryStateOnSurface > collectHits(const std::vector< Trajectory > &vtraj, const MultiRecHitCollector *measurementCollector) const
int cont
void fit(const std::pair< TransientTrackingRecHit::RecHitContainer, TrajectoryStateOnSurface > &hits, const TrajectoryFitter *theFitter, std::vector< Trajectory > &vtraj) const
accomplishes the fitting-smoothing step for each annealing value
std::pair< TransientTrackingRecHit::RecHitContainer, TrajectoryStateOnSurface > DAFTrackProducerAlgorithm::updateHits ( const std::vector< Trajectory > &  vtraj,
const SiTrackerMultiRecHitUpdator updator,
double  annealing 
) const
private

Definition at line 121 of file DAFTrackProducerAlgorithm.cc.

References SiTrackerMultiRecHitUpdator::update().

Referenced by runWithCandidate().

123  {
125  std::vector<TrajectoryMeasurement> vmeas = vtraj.front().measurements();
126  std::vector<TrajectoryMeasurement>::reverse_iterator imeas;
127  for (imeas = vmeas.rbegin(); imeas != vmeas.rend(); imeas++){
128  TransientTrackingRecHit::RecHitPointer updated = updator->update(imeas->recHit(), imeas->updatedState(), annealing);
129  hits.push_back(updated);
130  }
131  return std::make_pair(hits,TrajectoryStateWithArbitraryError()(vmeas.back().updatedState()));
132 }
std::vector< ConstRecHitPointer > RecHitContainer
virtual TransientTrackingRecHit::RecHitPointer update(TransientTrackingRecHit::ConstRecHitPointer original, TrajectoryStateOnSurface tsos, double annealing=1.) const

Member Data Documentation

edm::ParameterSet DAFTrackProducerAlgorithm::conf_
private

Definition at line 78 of file DAFTrackProducerAlgorithm.h.

Referenced by runWithCandidate().