CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

EgammaHLTPixelMatchElectronAlgo Class Reference

#include <EgammaHLTPixelMatchElectronAlgo.h>

List of all members.

Public Member Functions

 EgammaHLTPixelMatchElectronAlgo (const edm::ParameterSet &conf)
void run (edm::Event &, reco::ElectronCollection &)
void setupES (const edm::EventSetup &setup)
 ~EgammaHLTPixelMatchElectronAlgo ()

Private Member Functions

 EgammaHLTPixelMatchElectronAlgo (const EgammaHLTPixelMatchElectronAlgo &rhs)
bool isInnerMostWithLostHits (const reco::GsfTrackRef &, const reco::GsfTrackRef &, bool &)
EgammaHLTPixelMatchElectronAlgooperator= (const EgammaHLTPixelMatchElectronAlgo &rhs)
void process (edm::Handle< reco::TrackCollection > tracksH, edm::Handle< reco::GsfTrackCollection > gsfTracksH, reco::ElectronCollection &outEle, Global3DPoint &bs)

Private Attributes

edm::InputTag bsProducer_
unsigned long long cacheIDMagField_
int unsigned long long cacheIDTDGeom_
edm::InputTag gsfTrackProducer_
edm::ESHandle< MagneticFieldmagField_
MultiTrajectoryStateModemtsMode_
MultiTrajectoryStateTransformmtsTransform_
edm::ESHandle< TrackerGeometrytrackerGeom_
edm::InputTag trackProducer_
bool useGsfTracks_

Detailed Description

Class to reconstruct electron tracks from electron pixel seeds keep track of information about the initiating supercluster

Author:
Monica Vazquez Acosta (CERN)

Description: top algorithm producing TrackCandidate and Electron objects from supercluster driven pixel seeded Ckf tracking for HLT

Definition at line 31 of file EgammaHLTPixelMatchElectronAlgo.h.


Constructor & Destructor Documentation

EgammaHLTPixelMatchElectronAlgo::EgammaHLTPixelMatchElectronAlgo ( const edm::ParameterSet conf)

Definition at line 50 of file EgammaHLTPixelMatchElectronAlgo.cc.

                                                                                            :
  trackProducer_(conf.getParameter<edm::InputTag>("TrackProducer")),
  gsfTrackProducer_(conf.getParameter<edm::InputTag>("GsfTrackProducer")),
  useGsfTracks_(conf.getParameter<bool>("UseGsfTracks")),
  bsProducer_(conf.getParameter<edm::InputTag>("BSProducer")), 
  mtsMode_(new MultiTrajectoryStateMode()),
  mtsTransform_(0),
  cacheIDTDGeom_(0),
  cacheIDMagField_(0)
{

}
EgammaHLTPixelMatchElectronAlgo::~EgammaHLTPixelMatchElectronAlgo ( )

Definition at line 63 of file EgammaHLTPixelMatchElectronAlgo.cc.

References mtsMode_, and mtsTransform_.

{
  delete mtsTransform_;
  delete mtsMode_;
 }
EgammaHLTPixelMatchElectronAlgo::EgammaHLTPixelMatchElectronAlgo ( const EgammaHLTPixelMatchElectronAlgo rhs) [inline, private]

Definition at line 41 of file EgammaHLTPixelMatchElectronAlgo.h.

{}

Member Function Documentation

bool EgammaHLTPixelMatchElectronAlgo::isInnerMostWithLostHits ( const reco::GsfTrackRef nGsfTrack,
const reco::GsfTrackRef iGsfTrack,
bool &  sameLayer 
) [private]

Definition at line 234 of file EgammaHLTPixelMatchElectronAlgo.cc.

Referenced by process().

                                                                                                                                                 {
  
  // define closest using the lost hits on the expectedhitsineer
  unsigned int nLostHits = nGsfTrack->trackerExpectedHitsInner().numberOfLostHits();
  unsigned int iLostHits = iGsfTrack->trackerExpectedHitsInner().numberOfLostHits();
  
  if (nLostHits!=iLostHits) {
    return (nLostHits > iLostHits);
  } else {
    sameLayer = true;
    return  false; 
  }
}
EgammaHLTPixelMatchElectronAlgo& EgammaHLTPixelMatchElectronAlgo::operator= ( const EgammaHLTPixelMatchElectronAlgo rhs) [inline, private]

Definition at line 42 of file EgammaHLTPixelMatchElectronAlgo.h.

{return *this;}
void EgammaHLTPixelMatchElectronAlgo::process ( edm::Handle< reco::TrackCollection tracksH,
edm::Handle< reco::GsfTrackCollection gsfTracksH,
reco::ElectronCollection outEle,
Global3DPoint bs 
) [private]

Definition at line 119 of file EgammaHLTPixelMatchElectronAlgo.cc.

References MultiTrajectoryStateTransform::extrapolatedState(), i, trajectoryStateTransform::innerFreeState(), MultiTrajectoryStateTransform::innerStateOnSurface(), isInnerMostWithLostHits(), TrajectoryStateOnSurface::isValid(), j, PV3DBase< T, PVType, FrameType >::mag(), magField_, MultiTrajectoryStateMode::momentumFromModeCartesian(), mtsMode_, mtsTransform_, edm::ESHandle< T >::product(), pileupReCalc_HLTpaths::scale, reco::Electron::setSuperCluster(), useGsfTracks_, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by run().

                                                                                                                                                                           {

  if (!useGsfTracks_) {

    for (unsigned int i=0; i<tracksH->size(); ++i) {
      
      const TrackRef trackRef = edm::Ref<TrackCollection>(tracksH, i);
      edm::RefToBase<TrajectorySeed> seed = trackRef->extra()->seedRef();
      ElectronSeedRef elseed=seed.castTo<ElectronSeedRef>();
      
      edm::RefToBase<CaloCluster> caloCluster = elseed->caloCluster() ;
      SuperClusterRef scRef = caloCluster.castTo<SuperClusterRef>() ;
      
      // Get the momentum at vertex (not at the innermost layer)
      TSCPBuilderNoMaterial tscpBuilder;
      
      FreeTrajectoryState fts = trajectoryStateTransform::innerFreeState(*trackRef, magField_.product());
      TrajectoryStateClosestToPoint tscp = tscpBuilder(fts, bs);
      
      float scale = scRef->energy()/tscp.momentum().mag();
      
      const math::XYZTLorentzVector momentum(tscp.momentum().x()*scale,
                                             tscp.momentum().y()*scale,
                                             tscp.momentum().z()*scale,
                                             scRef->energy());

      Electron ele(trackRef->charge(), momentum, trackRef->vertex());
      ele.setSuperCluster(scRef);
      edm::Ref<TrackCollection> myRef(tracksH, i);
      ele.setTrack(myRef);
      outEle.push_back(ele);
    }  // loop over tracks
  } else {

    // clean gsf tracks
    std::vector<unsigned int> flag(gsfTracksH->size(), 0);
    if (gsfTracksH->size() == 0)
      return;

    for (unsigned int i=0; i<gsfTracksH->size()-1; ++i) {
      const GsfTrackRef trackRef1 = edm::Ref<GsfTrackCollection>(gsfTracksH, i);
      ElectronSeedRef elseed1 = trackRef1->extra()->seedRef().castTo<ElectronSeedRef>();
      SuperClusterRef scRef1 = elseed1->caloCluster().castTo<SuperClusterRef>();

      TrajectoryStateOnSurface inTSOS = mtsTransform_->innerStateOnSurface((*trackRef1));
      TrajectoryStateOnSurface fts = mtsTransform_->extrapolatedState(inTSOS, bs);
      GlobalVector innMom;
      float pin1 = trackRef1->pMode();
      if (fts.isValid()) {
        mtsMode_->momentumFromModeCartesian(fts, innMom);  
        pin1 = innMom.mag();
      }

      for (unsigned int j=i+1; j<gsfTracksH->size(); ++j) {
        const GsfTrackRef trackRef2 = edm::Ref<GsfTrackCollection>(gsfTracksH, j);
        ElectronSeedRef elseed2 = trackRef2->extra()->seedRef().castTo<ElectronSeedRef>();
        SuperClusterRef scRef2 = elseed2->caloCluster().castTo<SuperClusterRef>();

        TrajectoryStateOnSurface inTSOS = mtsTransform_->innerStateOnSurface((*trackRef2));
        TrajectoryStateOnSurface fts = mtsTransform_->extrapolatedState(inTSOS, bs);
        GlobalVector innMom;
        float pin2 = trackRef2->pMode();
        if (fts.isValid()) {
          mtsMode_->momentumFromModeCartesian(fts, innMom);  
          pin2 = innMom.mag();
        }
        
        if (scRef1 == scRef2) {
          bool isSameLayer = false;
          bool iGsfInnermostWithLostHits = isInnerMostWithLostHits(trackRef2, trackRef1, isSameLayer);
          
          if (iGsfInnermostWithLostHits) {
            flag[j] = 1;
          } else if(isSameLayer) {
            if(fabs((scRef1->energy()/pin1)-1) < fabs((scRef2->energy()/pin2)-1))
              flag[j] = 1;
          } else {
            flag[i] = 1;
          }
        }
      }
    }

    for (unsigned int i=0; i<gsfTracksH->size(); ++i) {
      if (flag[i] == 1)
        continue;

      const GsfTrackRef trackRef = edm::Ref<GsfTrackCollection>(gsfTracksH, i);
      ElectronSeedRef elseed = trackRef->extra()->seedRef().castTo<ElectronSeedRef>();
      SuperClusterRef scRef = elseed->caloCluster().castTo<SuperClusterRef>();
      
      // Get the momentum at vertex (not at the innermost layer)
      TrajectoryStateOnSurface inTSOS = mtsTransform_->innerStateOnSurface((*trackRef));
      TrajectoryStateOnSurface fts = mtsTransform_->extrapolatedState(inTSOS, bs);
      GlobalVector innMom;
      mtsMode_->momentumFromModeCartesian(inTSOS, innMom);
      if (fts.isValid()) {
        mtsMode_->momentumFromModeCartesian(fts, innMom);  
      }
      
      float scale = scRef->energy()/innMom.mag();
      const math::XYZTLorentzVector momentum(innMom.x()*scale,
                                             innMom.y()*scale,
                                             innMom.z()*scale,
                                             scRef->energy());
      
      Electron ele(trackRef->charge(), momentum, trackRef->vertex());
      ele.setSuperCluster(scRef);
      edm::Ref<GsfTrackCollection> myRef(gsfTracksH, i);
      ele.setGsfTrack(myRef);
      outEle.push_back(ele);
    }
  }
}
void EgammaHLTPixelMatchElectronAlgo::run ( edm::Event e,
reco::ElectronCollection outEle 
)

Definition at line 95 of file EgammaHLTPixelMatchElectronAlgo.cc.

References bsProducer_, edm::Event::getByLabel(), gsfTrackProducer_, process(), trackProducer_, and useGsfTracks_.

Referenced by EgammaHLTPixelMatchElectronProducers::produce().

                                                                                {
  
  // get the input 
  edm::Handle<TrackCollection> tracksH;
  if (!useGsfTracks_)
    e.getByLabel(trackProducer_,tracksH);

  // get the input 
  edm::Handle<GsfTrackCollection> gsfTracksH;
  if (useGsfTracks_)
    e.getByLabel(gsfTrackProducer_, gsfTracksH);

  //Get the Beam Spot position
  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
  e.getByLabel(bsProducer_,recoBeamSpotHandle);

  // gets its position
  const BeamSpot::Point& bsPosition = recoBeamSpotHandle->position(); 
  Global3DPoint bs(bsPosition.x(),bsPosition.y(),0);
  process(tracksH, gsfTracksH, outEle, bs);
  
  return;
}
void EgammaHLTPixelMatchElectronAlgo::setupES ( const edm::EventSetup setup)

Definition at line 69 of file EgammaHLTPixelMatchElectronAlgo.cc.

References edm::eventsetup::EventSetupRecord::cacheIdentifier(), cacheIDMagField_, cacheIDTDGeom_, edm::EventSetup::get(), magField_, mtsTransform_, edm::ESHandle< T >::product(), trackerGeom_, and useGsfTracks_.

Referenced by EgammaHLTPixelMatchElectronProducers::produce().

                                                                     {
  //services
  
  bool updateField(false);
  if (cacheIDMagField_!=es.get<IdealMagneticFieldRecord>().cacheIdentifier()){
    updateField = true;
    cacheIDMagField_=es.get<IdealMagneticFieldRecord>().cacheIdentifier();
    es.get<IdealMagneticFieldRecord>().get(magField_);
  }
  
  if(useGsfTracks_){ //only need the geom and mtsTransform if we are doing gsf tracks
    bool updateGeometry(false);
    if (cacheIDTDGeom_!=es.get<TrackerDigiGeometryRecord>().cacheIdentifier()){
      updateGeometry = true;
       cacheIDTDGeom_=es.get<TrackerDigiGeometryRecord>().cacheIdentifier();
       es.get<TrackerDigiGeometryRecord>().get(trackerGeom_);
    }
    if ( updateField || updateGeometry || !mtsTransform_ ) {
      delete mtsTransform_;
      mtsTransform_ = new MultiTrajectoryStateTransform(trackerGeom_.product(),magField_.product());
    }
  }
  
  
}

Member Data Documentation

Definition at line 58 of file EgammaHLTPixelMatchElectronAlgo.h.

Referenced by run().

Definition at line 66 of file EgammaHLTPixelMatchElectronAlgo.h.

Referenced by setupES().

int unsigned long long EgammaHLTPixelMatchElectronAlgo::cacheIDTDGeom_ [private]

Definition at line 65 of file EgammaHLTPixelMatchElectronAlgo.h.

Referenced by setupES().

Definition at line 56 of file EgammaHLTPixelMatchElectronAlgo.h.

Referenced by run().

Definition at line 63 of file EgammaHLTPixelMatchElectronAlgo.h.

Referenced by process(), and setupES().

Definition at line 60 of file EgammaHLTPixelMatchElectronAlgo.h.

Referenced by process(), and ~EgammaHLTPixelMatchElectronAlgo().

Definition at line 64 of file EgammaHLTPixelMatchElectronAlgo.h.

Referenced by setupES().

Definition at line 55 of file EgammaHLTPixelMatchElectronAlgo.h.

Referenced by run().

Definition at line 57 of file EgammaHLTPixelMatchElectronAlgo.h.

Referenced by process(), run(), and setupES().