CMS 3D CMS Logo

Public Member Functions | Private Types | Private Member Functions | Private Attributes

DAFTrackProducerAlgorithm Class Reference

#include <DAFTrackProducerAlgorithm.h>

List of all members.

Public Member Functions

 DAFTrackProducerAlgorithm (const edm::ParameterSet &pset)
 Constructor.
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.
 ~DAFTrackProducerAlgorithm ()
 Destructor.

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.
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
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.

:conf_(pset){}
DAFTrackProducerAlgorithm::~DAFTrackProducerAlgorithm ( ) [inline]

Destructor.

Definition at line 33 of file DAFTrackProducerAlgorithm.h.

{}

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().

                                                                         {
  //variable declarations
  reco::Track * theTrack;
  Trajectory * theTraj; 
      
  //perform the fit: the result's size is 1 if it succeded, 0 if fails
  
  
  //LogDebug("TrackProducer") <<" FITTER FOUND "<< vtraj.size() << " TRAJECTORIES" <<"\n";
  LogDebug("DAFTrackProducerAlgorithm") <<" FITTER FOUND "<< vtraj.size() << " TRAJECTORIES" << std::endl;;
  TrajectoryStateOnSurface innertsos;
  
  if (vtraj.size() != 0){

    theTraj = new Trajectory( vtraj.front() );
    
    if (theTraj->direction() == alongMomentum) {
    //if (theTraj->direction() == oppositeToMomentum) {
      innertsos = theTraj->firstMeasurement().updatedState();
      //std::cout << "Inner momentum " << innertsos.globalParameters().momentum().mag() << std::endl;   
    } else { 
      innertsos = theTraj->lastMeasurement().updatedState();
    }
    
    TSCBLBuilderNoMaterial tscblBuilder;
    TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(*(innertsos.freeState()),bs);

    if (tscbl.isValid()==false) return false;

    GlobalPoint v = tscbl.trackStateAtPCA().position();
    math::XYZPoint  pos( v.x(), v.y(), v.z() );
    GlobalVector p = tscbl.trackStateAtPCA().momentum();
    math::XYZVector mom( p.x(), p.y(), p.z() );

    //    LogDebug("TrackProducer") <<v<<p<<std::endl;

    theTrack = new reco::Track(theTraj->chiSquared(),
                               ndof, //in the DAF the ndof is not-integer
                               pos, mom, tscbl.trackStateAtPCA().charge(), tscbl.trackStateAtPCA().curvilinearError());



    AlgoProduct aProduct(theTraj,std::make_pair(theTrack,theTraj->direction()));

    algoResults.push_back(aProduct);

    
    return true;
  } 
  else  return false;
}
float DAFTrackProducerAlgorithm::calculateNdof ( const std::vector< Trajectory > &  vtraj) const [private]

Definition at line 249 of file DAFTrackProducerAlgorithm.cc.

Referenced by runWithCandidate().

                                                                                       {
        if (vtraj.empty()) return 0;
        float ndof = 0;
        const std::vector<TrajectoryMeasurement>& meas = vtraj.front().measurements();
        for (std::vector<TrajectoryMeasurement>::const_iterator iter = meas.begin(); iter != meas.end(); iter++){
                if (iter->recHit()->isValid()){
                        TransientTrackingRecHit::ConstRecHitContainer components = iter->recHit()->transientHits();
                        TransientTrackingRecHit::ConstRecHitContainer::const_iterator iter2;
                        for (iter2 = components.begin(); iter2 != components.end(); iter2++){
                                if ((*iter2)->isValid())ndof+=((*iter2)->dimension())*(*iter2)->weight();
                        }
                }
        }
        return ndof-5;
}
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().

                                                                                              {
        TransientTrackingRecHit::RecHitContainer hits;
        std::vector<TrajectoryMeasurement> collectedmeas = measurementCollector->recHits(vtraj.front());
        if (collectedmeas.empty()) return std::make_pair(TransientTrackingRecHit::RecHitContainer(), TrajectoryStateOnSurface());
        for (std::vector<TrajectoryMeasurement>::const_iterator iter = collectedmeas.begin(); iter!=collectedmeas.end(); iter++){
                hits.push_back(iter->recHit());
        }
        return std::make_pair(hits,TrajectoryStateWithArbitraryError()(collectedmeas.front().predictedState()));        
}
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 combine::missing.

                                                                                                                                                      {
        if (input.empty()) return;

        int ngoodhits = 0;

        std::vector<TrajectoryMeasurement> vtm = input[0].measurements();       

        TransientTrackingRecHit::RecHitContainer hits;

        //count the number of non-outlier and non-invalid hits  
        for (std::vector<TrajectoryMeasurement>::reverse_iterator tm=vtm.rbegin(); tm!=vtm.rend();tm++){
                //if the rechit is valid
                if (tm->recHit()->isValid()) {
                        TransientTrackingRecHit::ConstRecHitContainer components = tm->recHit()->transientHits();
                        bool isGood = false;
                        for (TransientTrackingRecHit::ConstRecHitContainer::iterator rechit = components.begin(); rechit != components.end(); rechit++){
                                //if there is at least one component with weight higher than 1e-6 then the hit is not an outlier
                                if ((*rechit)->weight()>1e-6) {ngoodhits++; isGood = true; break;}
                        }
                        if (isGood) hits.push_back(tm->recHit()->clone(tm->updatedState()));
                        else hits.push_back(InvalidTransientRecHit::build(tm->recHit()->det(), TrackingRecHit::missing));
                } else {
                        hits.push_back(tm->recHit()->clone(tm->updatedState()));
                }
        }


        LogDebug("DAFTrackProducerAlgorithm") << "Original number of valid hits " << input[0].foundHits() << "; after filtering " << ngoodhits;
        //debug
        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();
        
        if (ngoodhits < minhits) return;        

        TrajectoryStateOnSurface curstartingTSOS = input.front().lastMeasurement().updatedState();
        LogDebug("DAFTrackProducerAlgorithm") << "starting tsos for final refitting " << curstartingTSOS ;
        //curstartingTSOS.rescaleError(100);

        output = fitter->fit(TrajectorySeed(PTrajectoryStateOnDet(),
                                                BasicTrajectorySeed::recHitContainer(),
                                                input.front().seed().direction()),
                                hits,
                                TrajectoryStateWithArbitraryError()(curstartingTSOS));
        LogDebug("DAFTrackProducerAlgorithm") << "After filtering " << output.size() << " trajectories";

}
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().

                                                                        {
        std::vector<Trajectory> newVec = theFitter->fit(TrajectorySeed(PTrajectoryStateOnDet(),
                                                                       BasicTrajectorySeed::recHitContainer(),
                                                                       vtraj.front().seed().direction()),
                                                        hits.first,
                                                        hits.second);
        vtraj.reserve(newVec.size());
        vtraj.swap(newVec);
        LogDebug("DAFTrackProducerAlgorithm") << "swapped!" << std::endl;
}
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().

{
  edm::LogInfo("TrackProducer") << "Number of Trajectories: " << theTrajectoryCollection.size() << "\n";
  int cont = 0;
  for (std::vector<Trajectory>::const_iterator i=theTrajectoryCollection.begin(); i!=theTrajectoryCollection.end() ;i++)


{
    
      

      
    float ndof=0;

      //first of all do a fit-smooth round to get the trajectory
      LogDebug("DAFTrackProducerAlgorithm") << "About to build the trajectory for the first round...";          
      //theMRHChi2Estimator->setAnnealingFactor(1);
      //  std::vector<Trajectory> vtraj = theFitter->fit(seed, hits, theTSOS);
        std::vector<Trajectory> vtraj;
        vtraj.push_back(*i);
      
        LogDebug("DAFTrackProducerAlgorithm") << "done" << std::endl;   
        LogDebug("DAFTrackProducerAlgorithm") << "after the first round found " << vtraj.size() << " trajectories"  << std::endl; 

      if (vtraj.size() != 0){

        //bool isFirstIteration=true;
        std::pair<TransientTrackingRecHit::RecHitContainer, TrajectoryStateOnSurface> hits = collectHits(vtraj, measurementCollector);
        fit(hits, theFitter, vtraj);

        for (std::vector<double>::const_iterator ian = updator->getAnnealingProgram().begin(); ian != updator->getAnnealingProgram().end(); ian++){
                if (vtraj.size()){
                        LogDebug("DAFTrackProducerAlgorithm") << "Seed direction is " << vtraj.front().seed().direction() 
                                                              << "  Traj direction is " << vtraj.front().direction(); 
                        std::pair<TransientTrackingRecHit::RecHitContainer, TrajectoryStateOnSurface> curiterationhits = updateHits(vtraj,updator,*ian);
                        fit(curiterationhits, theFitter, vtraj);
                                
                        LogDebug("DAFTrackProducerAlgorithm") << "done annealing value "  <<  (*ian) << " with " << vtraj.size() << " trajectories";
                } else break;
                LogDebug("DAFTrackProducerAlgorithm") << "number of trajectories after annealing value " << (*ian) << " annealing step " << vtraj.size();
        }
        LogDebug("DAFTrackProducerAlgorithm") << "Ended annealing program with " << vtraj.size() << " trajectories" << std::endl;

        //check the trajectory to see that the number of valid hits with 
        //reasonable weight (>1e-6) is higher than the minimum set in the DAFTrackProducer.
        //This is a kind of filter to remove tracks with too many outliers.
        //Outliers are mrhits with all components with weight less than 1e-6 
  
        //std::vector<Trajectory> filtered;
        //filter(theFitter, vtraj, conf_.getParameter<int>("MinHits"), filtered);                               
        //ndof = calculateNdof(filtered);       
        ndof=calculateNdof(vtraj);
        //bool ok = buildTrack(filtered, algoResults, ndof, bs);
        if (vtraj.size()){
          if(vtraj.front().foundHits()>=conf_.getParameter<int>("MinHits"))
            {
              
              bool ok = buildTrack(vtraj, algoResults, ndof, bs) ;
              if(ok) cont++;
            }
          
          else{
            LogDebug("DAFTrackProducerAlgorithm")  << "Rejecting trajectory with " << vtraj.front().foundHits()<<" hits"; 
          }
        }

        else LogDebug("DAFTrackProducerAlgorithm") << "Rejecting empty trajectory" << std::endl;
        

      }
  }
  LogDebug("TrackProducer") << "Number of Tracks found: " << cont << "\n";
}
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().

                                                              {
        TransientTrackingRecHit::RecHitContainer hits;
        std::vector<TrajectoryMeasurement> vmeas = vtraj.front().measurements();
        std::vector<TrajectoryMeasurement>::reverse_iterator imeas;
        for (imeas = vmeas.rbegin(); imeas != vmeas.rend(); imeas++){
                TransientTrackingRecHit::RecHitPointer updated = updator->update(imeas->recHit(), imeas->updatedState(), annealing);
                hits.push_back(updated);
        }
        return std::make_pair(hits,TrajectoryStateWithArbitraryError()(vmeas.back().updatedState()));
}

Member Data Documentation

Definition at line 78 of file DAFTrackProducerAlgorithm.h.

Referenced by runWithCandidate().