CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

SimpleMTFHitCollector Class Reference

#include <SimpleMTFHitCollector.h>

Inheritance diagram for SimpleMTFHitCollector:
MultiTrackFilterHitCollector

List of all members.

Public Member Functions

const MeasurementEstimatorgetEstimator () const
const PropagatorgetPropagator () const
const
SiTrackerMultiRecHitUpdatorMTF
getUpdator () const
virtual std::vector
< TrajectoryMeasurement
recHits (const std::map< int, std::vector< TrajectoryMeasurement > > &tmmap, int i, double annealing=1.) const
 SimpleMTFHitCollector (const MeasurementTracker *measurementTracker, const SiTrackerMultiRecHitUpdatorMTF *updator, const MeasurementEstimator *est, const Propagator *propagator)
virtual ~SimpleMTFHitCollector ()

Private Member Functions

void buildMultiRecHits (const std::vector< std::pair< int, TrajectoryMeasurement > > &measgroup, MultiTrajectoryMeasurement *mtm, std::vector< TrajectoryMeasurement > &result, double annealing=1.) const
void getMeasurements (std::vector< std::pair< int, TrajectoryMeasurement > > &layermeas, const std::map< int, std::vector< TrajectoryMeasurement > > &tmmap, TrajectoryMeasurement &pmeas, int i) const
MultiTrajectoryMeasurement getTSOS (const std::vector< std::pair< int, TrajectoryMeasurement > > &layermeas, TransientTrackingRecHit::ConstRecHitPointer rechit, int i) const
MultiTrajectoryMeasurement TSOSfinder (const std::map< int, std::vector< TrajectoryMeasurement > > &tmmap, TrajectoryMeasurement &pmeas, int i) const

Private Attributes

const MeasurementEstimatortheEstimator
const PropagatorthePropagator
const
SiTrackerMultiRecHitUpdatorMTF
theUpdator

Detailed Description

Definition at line 18 of file SimpleMTFHitCollector.h.


Constructor & Destructor Documentation

SimpleMTFHitCollector::SimpleMTFHitCollector ( const MeasurementTracker measurementTracker,
const SiTrackerMultiRecHitUpdatorMTF updator,
const MeasurementEstimator est,
const Propagator propagator 
) [inline, explicit]

Definition at line 20 of file SimpleMTFHitCollector.h.

                                  :MultiTrackFilterHitCollector(measurementTracker), theUpdator(updator), theEstimator(est), thePropagator(propagator){}
virtual SimpleMTFHitCollector::~SimpleMTFHitCollector ( ) [inline, virtual]

Definition at line 27 of file SimpleMTFHitCollector.h.

{}

Member Function Documentation

void SimpleMTFHitCollector::buildMultiRecHits ( const std::vector< std::pair< int, TrajectoryMeasurement > > &  measgroup,
MultiTrajectoryMeasurement mtm,
std::vector< TrajectoryMeasurement > &  result,
double  annealing = 1. 
) const [private]

Definition at line 132 of file GroupedDAFHitCollector.cc.

References cond::ecalcond::bad(), TrackingRecHit::inactive, TrajectoryStateOnSurface::isValid(), LogTrace, combine::missing, position, GloballyPositioned< T >::position(), and TrajectoryStateOnSurface::surface().

                                                                                                                                               {

        unsigned int initial_size = result.size();
        //TransientTrackingRecHit::ConstRecHitContainer rhits;
        if (measgroup.empty()) {
                LogTrace("MultiRecHitCollector") << "No TrajectoryMeasurementGroups found for this layer" ; 
                //should we do something?
                //result.push_back(InvalidTransientRecHit::build(0,TrackingRecHit::missing));
                return;
        } 

        //we build a MultiRecHit out of each group
        //groups are sorted along momentum or opposite to momentum, 
        //measurements in groups are sorted with increating chi2
        LogTrace("MultiRecHitCollector") << "Found " << measgroup.size() << " groups for this layer";
        //trajectory state to store the last valid TrajectoryState (if present) to be used 
        //to add an invalid Measurement in case no valid state or no valid hits are found in any group
        for (vector<TrajectoryMeasurementGroup>::const_iterator igroup = measgroup.begin(); igroup != measgroup.end(); igroup++ ){
                //the TrajectoryState is the first one
                TrajectoryStateOnSurface state = igroup->measurements().front().predictedState();
                if (!state.isValid()){
                        LogTrace("MultiRecHitCollector") << "Something wrong! no valid TSOS found in current group ";
                        continue;               
                }
                //debug
                LogTrace("MultiRecHitCollector") << "This group has " << igroup->measurements().size() << " measurements";
                LogTrace("MultiRecHitCollector") << "This group has the following " << igroup->detGroup().size() << " detector ids: " << endl;
                for (DetGroup::const_iterator idet = igroup->detGroup().begin(); idet != igroup->detGroup().end(); ++idet){
                  LogTrace("MultiRecHitCollector") << idet->det()->geographicalId().rawId();
                          // " on " << giulioGetLayer(idet->det()->geographicalId());
                }
                //debug
                vector<const TrackingRecHit*> hits;
                for (vector<TrajectoryMeasurement>::const_iterator imeas = igroup->measurements().begin(); imeas != igroup->measurements().end(); imeas++){
                        //collect the non missing hits to build the MultiRecHits
                        //we ese the recHits method; anyway only simple hits, not MultiHits should be present 
                        if (imeas->recHit()->getType() != TrackingRecHit::missing) {
                                LogTrace("MultiRecHitCollector") << "This hit is valid ";
                                hits.push_back(imeas->recHit()->hit());
                        }
                }
                if (hits.empty()){
                        LogTrace("MultiRecHitCollector") << "No valid hits found in current group ";
                        continue;
                }
                LogTrace("MultiRecHitCollector") << "The best TSOS in this group is " << state << " it lays on surface located at " << state.surface().position();
#ifdef _debug_GroupedDAFHitCollector_   
                LogTrace("MultiRecHitCollector") << "For the MRH on this group the following hits will be used"; 
                for (vector<const TrackingRecHit*>::iterator iter = hits.begin(); iter != hits.end(); iter++){  
                        string validity = "valid";
                        if ((*iter)->getType() == TrackingRecHit::missing ) validity = "missing !should not happen!";
                        else if ((*iter)->getType() == TrackingRecHit::inactive) validity = "inactive";
                        else if ((*iter)->getType() == TrackingRecHit::bad) validity = "bad";   
                        LogTrace("MultiRecHitCollector") << "DetId " << (*iter)->geographicalId().rawId()  << " validity: " << validity 
                                << " surface position " << getMeasurementTracker()->geomTracker()->idToDet((*iter)->geographicalId())->position()  
                                << " hit local position " << (*iter)->localPosition();
                }
#endif
                
                result.push_back(TrajectoryMeasurement(state,theUpdator->buildMultiRecHit(hits, state)));
        }

        //can this happen? it means that the measgroup was not empty but no valid measurement was found inside
        //in this case we add an invalid measuremnt for this layer 
        if (result.size() == initial_size){
                LogTrace("MultiRecHitCollector") << "no valid measuremnt or no valid TSOS in none of the groups";
                //measgroup has been already checked for size != 0
                if (measgroup.back().measurements().size() != 0){       
                        result.push_back(measgroup.back().measurements().back());
                } 
        }
}
const MeasurementEstimator* SimpleMTFHitCollector::getEstimator ( ) const [inline]

Definition at line 41 of file SimpleMTFHitCollector.h.

References theEstimator.

{return theEstimator;}
void SimpleMTFHitCollector::getMeasurements ( std::vector< std::pair< int, TrajectoryMeasurement > > &  layermeas,
const std::map< int, std::vector< TrajectoryMeasurement > > &  tmmap,
TrajectoryMeasurement pmeas,
int  i 
) const [private]

Definition at line 170 of file SimpleMTFHitCollector.cc.

References LogDebug, python::multivaluedict::map(), and TrajectoryMeasurement::recHit().

                                                   {
  
  uint32_t id = pmeas.recHit()->geographicalId().rawId();
  
  LogDebug("SimpleMTFHitCollector") << "Detector Id: " << id << std::endl;
  
  //vector<std::pair<int, TrajectoryMeasurement> > layermeas;
  
  if( pmeas.recHit()->geographicalId().rawId() )
    {
      //search for hits only on the same detector, comparing the detId. Fill also the vector layermeas with the original measurement. 
      
      
      //use the method fastmeas to search for compatible hits and put it into a vector
      // vector<TrajectoryMeasurement> veclayermeas = 
      //        getMeasurementTracker()->idToDet
      //        (pmeas.recHit()->geographicalId().rawId())->fastMeasurements(pmeas.updatedState(), 
      //    pmeas.updatedState(), 
      //        *thePropagator, 
      //        *(getEstimator()));
  
  
  //LogDebug("SimpleMTFHitCollector") << " method veclayermeas returned a vector of size: " 
  //                            << veclayermeas.size() 
  //                            << std::endl;
      
      //        for(vector<TrajectoryMeasurement>::iterator iveclayermeas=veclayermeas.begin();
      //      iveclayermeas!=veclayermeas.end();
      //      iveclayermeas++)
      
      // {
      
        //  layermeas.push_back(make_pair(i,pmeas));
          
      for (std::map< int, vector<TrajectoryMeasurement> >::const_iterator immap=tmmap.begin(); 
           immap!=tmmap.end(); 
           immap++)
        {
          int ntraj2 = immap->first;
          //LogDebug("SimpleMTFHitCollector") << " number of the trajectory examined: " << ntraj2 << std::endl;
              //map< int, vector<TrajectoryMeasurement> >::const_iterator k = immap->second;
          const vector<TrajectoryMeasurement> & vecmeas = immap->second;
          
          //    if(ntraj2 == i) continue;
          
          
          for(vector<TrajectoryMeasurement>::const_reverse_iterator itvmeas = vecmeas.rbegin(); itvmeas!=vecmeas.rend(); itvmeas++)
            {
              //    if ( ( itvmeas->recHit()->geographicalId().rawId() == id) && (itvmeas->recHit()->isValid()) && !(itvmeas->recHit()->hit()->sharesInput(pmeas.recHit()->hit(), TrackingRecHit::all)) ) //modoficare per inludere il layer nella ricerca
              
              //if(itvmeas->recHit()->hit()->sharesInput(iveclayermeas->recHit()->hit(), TrackingRecHit::some) )
              if ( (itvmeas->recHit()->geographicalId().rawId() == id) )
                { 
                      LogDebug("SimpleMTFHitCollector") << "found a matching rechit in the collector";
                      //    if(iveclayermeas->updatedState() == itvmeas->updatedState())
                      
                      layermeas.push_back(make_pair(ntraj2,*itvmeas));
                      
                }
              
              //if(itvmeas->recHit()->geographicalId().rawId() == id)
              
              //layermeas.push_back(make_pair(ntraj2,*itvmeas));
              
            }
          
        }
          
       
      //vector<TrajectoryMeasurement> 
      
      //currentLayerMeas=getMeasurementTracker()->idToDet(imeas->recHit()->geographicalId().rawId())->fastMeasurements(imeas->updatedState(), 
      //                                                                                                         imeas->updatedState(), 
      //                                                                                                         *thePropagator, 
      //                                                                                                         *(getEstimator()));
      LogDebug("SimpleMTFHitCollector") << " built a vector of Trajectory Measurements all on the same layer, of size: " 
                                        << layermeas.size() 
                                        << std::endl;
    }
  
  else layermeas.push_back(make_pair(i,pmeas));
  
  
}
const Propagator* SimpleMTFHitCollector::getPropagator ( ) const [inline]

Definition at line 42 of file SimpleMTFHitCollector.h.

References thePropagator.

{return thePropagator;}
MultiTrajectoryMeasurement SimpleMTFHitCollector::getTSOS ( const std::vector< std::pair< int, TrajectoryMeasurement > > &  layermeas,
TransientTrackingRecHit::ConstRecHitPointer  rechit,
int  i 
) const [private]

Definition at line 258 of file SimpleMTFHitCollector.cc.

References TrajectoryStateCombiner::combine(), and LogDebug.

                                                                      {
  
  //we should search even for compatible tsos on this layer and build the multirechit with this knowledge...we can build an MTM.
  uint32_t id = rechit->geographicalId().rawId();
  
  LogDebug("SimpleMTFHitCollector") << "Detector Id: " << id << std::endl;

  LogDebug("SimpleMTFHitCollector") << "LayerMeas size: " << layermeas.size() << std::endl;
  
  const DetLayer* layer = layermeas.front().second.layer();
  
  std::map<int,TSOS> predictions; 
  std::map<int,TSOS> updates;
  LogDebug("SimpleMTFHitCollector") << " about to build a map with predicted and updated states " << std::endl;
  
  //we insert initially at least the original predicted & updated states
  //if(imeas->predictedState().isValid())       
  //  predictions[i] = imeas->predictedState();
  //else if ( imeas->backwardPredictedState().isValid() )
  //  predictions[i] = imeas->backwardPredictedState();
  //else viva il dale
  //  LogDebug("SimpleMTFHitCollector") << "error:invalid predicted and backward predicted states" << std::endl;
  
  //first fill the map with the state relative to the measurement we are analizing
  //if(imeas->updatedState().isValid())
  //  updates[i] = imeas->updatedState();
  
  //LogDebug("SimpleMTFHitCollector") << "Local Position of predicted state" << imeas->predictedState().localPosition() << std::endl;
  //LogDebug("SimpleMTFHitCollector") << "Local Position of updated state" << imeas->updatedState().localPosition() << std::endl;           
  TrajectoryStateCombiner statecombiner;
  
  for (std::vector<std::pair<int,TrajectoryMeasurement> >::const_iterator itmeas=layermeas.begin(); itmeas!=layermeas.end(); itmeas++)
    {
      
      //we now have to build 2 maps, with the (predicted & updated) tsos for each track; then we can construct a MTM
      LogDebug("SimpleMTFHitCollector") << " number of the trajectory examined: " << itmeas->first << std::endl;
      
      //get the vector from the map
      //LogDebug("SimpleMTFHitCollector") << " size of the vector examining: " << vmeas.size() << std::endl;
      
      //if(ntraj == i)
      //{
      //          LogDebug("SimpleMTFHitCollector") << " skipping trajectory number: " << ntraj << std::endl;
      //  continue;
      //        }
      
      //begin a cicle to search for measurements compatible(same layer)
      //check if the _detid_ of the original measurement is the same of this one and if the rechits are not the same one
      if ( (itmeas->second.recHit()->geographicalId().rawId() == id) ) //controlla che siano sullo stesso layer (cambiare!!!)
        {
          
          //      LogDebug("SimpleMTFHitCollector") << "found a compatible hit " << std::endl;

          //add an element to the maps with predicted and updated states 
          if(itmeas->second.predictedState().isValid())
            {
              predictions[itmeas->first] = itmeas->second.predictedState();
              //              LogDebug("SimpleMTFHitCollector") << "predicted state inserted in the map " << std::endl;
              if ( itmeas->second.backwardPredictedState().isValid() ){
                updates[itmeas->first]= statecombiner.combine(itmeas->second.predictedState(), itmeas->second.backwardPredictedState());
              }
            }
          
          //      else if ( itmeas->second.backwardPredictedState().isValid() )
          //        {
          //          predictions[itmeas->first] = itmeas->second.backwardPredictedState();
          //          LogDebug("SimpleMTFHitCollector") << "bacwardpredicted state inserted in the map " << std::endl;
          //        }
          
          else 
            LogDebug("SimpleMTFHitCollector") << "error:invalid predicted state" << std::endl; 
          
//        if(itmeas->second.updatedState().isValid()){
            
//          updates[itmeas->first] = itmeas->second.updatedState();
//          LogDebug("SimpleMTFHitCollector") << "updated state inserted in the map " << std::endl;
//        }
//         else if ( itmeas->second.predictedState().isValid() )
//           {
//             LogDebug("SimpleMTFHitCollector") << "error: invalid updated state, taking the predicted one instead " << std::endl; 
//             updates[itmeas->first] = itmeas->second.predictedState();
//           }
          
//        else 
//          LogDebug("SimpleMTFHitCollector") << "error:invalid updated and backward predicted states" << std::endl;
          
          
          //get the iterator to the predicted & updated states of the maps, to print the TSOS predicted and updated 
          //      map<int,TSOS>::iterator ipred = predictions.find(itmeas->first); 
          //map<int,TSOS>::iterator iupd = updates.find(itmeas->first); 
          
          //controlla che siano giusti gli stati!!!
          //LogDebug("SimpleMTFHitCollector") << "Local Position of predicted state " << ipred->second.localPosition() << std::endl
          //                        << " of trajectory number " << ipred->first <<"\n" << std::endl;
          //LogDebug("SimpleMTFHitCollector") << "Local Position of updated state " << iupd->second.localPosition() << std::endl
          //<< " of trajectory number " << iupd->first <<"\n" << std::endl;
          
        }
    }
  
  //create a MTM
  MultiTrajectoryMeasurement mtm = MultiTrajectoryMeasurement(rechit,predictions,updates,layer);
  return mtm;
}
const SiTrackerMultiRecHitUpdatorMTF* SimpleMTFHitCollector::getUpdator ( ) const [inline]

Definition at line 40 of file SimpleMTFHitCollector.h.

References theUpdator.

{return theUpdator;}
virtual std::vector<TrajectoryMeasurement> SimpleMTFHitCollector::recHits ( const std::map< int, std::vector< TrajectoryMeasurement > > &  tmmap,
int  i,
double  annealing = 1. 
) const [virtual]
MultiTrajectoryMeasurement SimpleMTFHitCollector::TSOSfinder ( const std::map< int, std::vector< TrajectoryMeasurement > > &  tmmap,
TrajectoryMeasurement pmeas,
int  i 
) const [private, virtual]

Implements MultiTrackFilterHitCollector.

Definition at line 367 of file SimpleMTFHitCollector.cc.

References LogDebug, TrajectoryMeasurement::recHit(), and query::result.

                                                                         {
  
  
  //it assumes that the measurements are sorted in the smoothing direction
  //map< int, vector<TrajectoryMeasurement> >::const_iterator itmeas = tmmap.find(i);
  //LogDebug("SimpleMTFHitCollector") << "found the element "<< i << "in the map" << std::endl;
  
  //vector<TrajectoryMeasurement> meas = itmeas->second;
  //LogDebug("SimpleMTFHitCollector") << "got the vector corresponding to " << i << " element of the map "<< std::endl;
  
  //if (meas.empty())   
  // return vector<TrajectoryMeasurement>();
  
  
  //TransientTrackingRecHit::ConstRecHitContainer result;
  vector<TrajectoryMeasurement> result;
   
  
  //  if(pmeas.recHit()->isValid())
    
    
    
      //define the rechit
      TransientTrackingRecHit::ConstRecHitPointer rechit = pmeas.recHit();
      
      //      const DetLayer* layer = pmeas.layer();
      
      uint32_t id = pmeas.recHit()->geographicalId().rawId();
      
      LogDebug("SimpleMTFHitCollector") << "Detector Id: " << id << std::endl;

      //get all the measurement on the same layer, searching in the map
      vector<std::pair<int, TrajectoryMeasurement> > layermeas; 
      getMeasurements(layermeas, tmmap,pmeas,i);
      
      
      //create a MTM, by knowledge of the measurements on the same layer and the rechit...
      return getTSOS(layermeas, rechit, i);
    
      
    }

Member Data Documentation

Definition at line 65 of file SimpleMTFHitCollector.h.

Referenced by getEstimator().

Definition at line 67 of file SimpleMTFHitCollector.h.

Referenced by getPropagator().

Definition at line 64 of file SimpleMTFHitCollector.h.

Referenced by getUpdator().