CMS 3D CMS Logo

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

PFElectronTranslator Class Reference

#include <PFElectronTranslator.h>

Inheritance diagram for PFElectronTranslator:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Types

typedef std::vector
< edm::Handle< edm::ValueMap
< double > > > 
IsolationValueMaps

Public Member Functions

virtual void beginRun (edm::Run &run, const edm::EventSetup &c)
 PFElectronTranslator (const edm::ParameterSet &)
virtual void produce (edm::Event &, const edm::EventSetup &)
 ~PFElectronTranslator ()

Private Member Functions

const reco::PFCandidatecorrespondingDaughterCandidate (const reco::PFCandidate &cand, const reco::PFBlockElement &pfbe) const
void createBasicCluster (const reco::PFBlockElement &, reco::BasicClusterCollection &basicClusters, std::vector< const reco::PFCluster * > &, const reco::PFCandidate &coCandidate) const
void createBasicClusterPtrs (const edm::OrphanHandle< reco::BasicClusterCollection > &basicClustersHandle)
void createGsfElectronCoreRefs (const edm::OrphanHandle< reco::GsfElectronCoreCollection > &gsfElectronCoreHandle)
void createGsfElectronCores (reco::GsfElectronCoreCollection &) const
void createGsfElectrons (const reco::PFCandidateCollection &, const IsolationValueMaps &isolationValues, reco::GsfElectronCollection &)
void createPreshowerCluster (const reco::PFBlockElement &PFBE, reco::PreshowerClusterCollection &preshowerClusters, unsigned plane) const
void createPreshowerClusterPtrs (const edm::OrphanHandle< reco::PreshowerClusterCollection > &preshowerClustersHandle)
void createSuperClusterGsfMapRefs (const edm::OrphanHandle< reco::SuperClusterCollection > &superClustersHandle)
void createSuperClusters (const reco::PFCandidateCollection &, reco::SuperClusterCollection &superClusters) const
bool fetchCandidateCollection (edm::Handle< reco::PFCandidateCollection > &c, const edm::InputTag &tag, const edm::Event &iEvent) const
void fetchGsfCollection (edm::Handle< reco::GsfTrackCollection > &c, const edm::InputTag &tag, const edm::Event &iEvent) const
void fillMVAValueMap (edm::Event &iEvent, edm::ValueMap< float >::Filler &filler)
void fillSCRefValueMap (edm::Event &iEvent, edm::ValueMap< reco::SuperClusterRef >::Filler &filler) const
void fillValueMap (edm::Event &iEvent, edm::ValueMap< float >::Filler &filler) const
void getAmbiguousGsfTracks (const reco::PFBlockElement &PFBE, std::vector< reco::GsfTrackRef > &) const

Private Attributes

std::vector< std::vector
< reco::GsfTrackRef > > 
ambiguousGsfTracks_
std::vector
< reco::CaloClusterPtrVector
basicClusterPtr_
std::vector
< reco::BasicClusterCollection
basicClusters_
std::vector< reco::CandidatePtrCandidatePtr_
bool checkStatusFlag_
bool emptyIsOk_
std::string GsfElectronCollection_
std::string GsfElectronCoreCollection_
std::vector
< reco::GsfElectronCoreRef
gsfElectronCoreRefs_
std::map< reco::GsfTrackRef,
float > 
gsfMvaMap_
std::vector< int > gsfPFCandidateIndex_
std::vector< reco::GsfTrackRefGsfTrackRef_
edm::InputTag inputTagGSFTracks_
std::vector< edm::InputTaginputTagIsoVals_
edm::InputTag inputTagPFCandidateElectrons_
edm::InputTag inputTagPFCandidates_
std::vector< reco::TrackRefkfTrackRef_
double MVACut_
std::string PFBasicClusterCollection_
std::vector< std::vector
< const reco::PFCluster * > > 
pfClusters_
std::string PFMVAValueMap_
std::string PFPreshowerClusterCollection_
std::string PFSCValueMap_
std::string PFSuperClusterCollection_
std::vector
< reco::CaloClusterPtrVector
preshowerClusterPtr_
std::vector
< reco::PreshowerClusterCollection
preshowerClusters_
std::map< reco::GsfTrackRef,
reco::SuperClusterRef
scMap_
std::vector
< reco::SuperClusterCollection
superClusters_

Detailed Description

Definition at line 23 of file PFElectronTranslator.h.


Member Typedef Documentation

Definition at line 32 of file PFElectronTranslator.h.


Constructor & Destructor Documentation

PFElectronTranslator::PFElectronTranslator ( const edm::ParameterSet iConfig) [explicit]

Definition at line 22 of file PFElectronTranslator.cc.

References checkStatusFlag_, emptyIsOk_, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), GsfElectronCollection_, GsfElectronCoreCollection_, inputTagGSFTracks_, inputTagIsoVals_, inputTagPFCandidateElectrons_, inputTagPFCandidates_, MVACut_, PFBasicClusterCollection_, PFMVAValueMap_, PFPreshowerClusterCollection_, PFSCValueMap_, and PFSuperClusterCollection_.

                                                                          {
  inputTagPFCandidates_ 
    = iConfig.getParameter<edm::InputTag>("PFCandidate");
  inputTagPFCandidateElectrons_ 
    = iConfig.getParameter<edm::InputTag>("PFCandidateElectron");
  inputTagGSFTracks_
    = iConfig.getParameter<edm::InputTag>("GSFTracks");

  edm::ParameterSet isoVals  = iConfig.getParameter<edm::ParameterSet> ("isolationValues");
  inputTagIsoVals_.push_back(isoVals.getParameter<edm::InputTag>("pfChargedHadrons"));
  inputTagIsoVals_.push_back(isoVals.getParameter<edm::InputTag>("pfPhotons"));
  inputTagIsoVals_.push_back(isoVals.getParameter<edm::InputTag>("pfNeutralHadrons"));

  PFBasicClusterCollection_ = iConfig.getParameter<std::string>("PFBasicClusters");
  PFPreshowerClusterCollection_ = iConfig.getParameter<std::string>("PFPreshowerClusters");
  PFSuperClusterCollection_ = iConfig.getParameter<std::string>("PFSuperClusters");
  GsfElectronCoreCollection_ = iConfig.getParameter<std::string>("PFGsfElectronCore");
  GsfElectronCollection_ = iConfig.getParameter<std::string>("PFGsfElectron");
  
  PFMVAValueMap_ = iConfig.getParameter<std::string>("ElectronMVA");
  PFSCValueMap_ = iConfig.getParameter<std::string>("ElectronSC");
  MVACut_ = (iConfig.getParameter<edm::ParameterSet>("MVACutBlock")).getParameter<double>("MVACut");
  checkStatusFlag_ = iConfig.getParameter<bool>("CheckStatusFlag");
  
  if (iConfig.exists("emptyIsOk")) emptyIsOk_ = iConfig.getParameter<bool>("emptyIsOk");
  else emptyIsOk_=false;

  produces<reco::BasicClusterCollection>(PFBasicClusterCollection_); 
  produces<reco::PreshowerClusterCollection>(PFPreshowerClusterCollection_); 
  produces<reco::SuperClusterCollection>(PFSuperClusterCollection_); 
  produces<reco::GsfElectronCoreCollection>(GsfElectronCoreCollection_);
  produces<reco::GsfElectronCollection>(GsfElectronCollection_);
  produces<edm::ValueMap<float> >(PFMVAValueMap_);
  produces<edm::ValueMap<reco::SuperClusterRef> >(PFSCValueMap_);
}
PFElectronTranslator::~PFElectronTranslator ( )

Definition at line 58 of file PFElectronTranslator.cc.

{}

Member Function Documentation

void PFElectronTranslator::beginRun ( edm::Run run,
const edm::EventSetup c 
) [virtual]

Reimplemented from edm::EDProducer.

Definition at line 60 of file PFElectronTranslator.cc.

{}
const reco::PFCandidate & PFElectronTranslator::correspondingDaughterCandidate ( const reco::PFCandidate cand,
const reco::PFBlockElement pfbe 
) const [private]

Definition at line 522 of file PFElectronTranslator.cc.

References reco::CompositeCandidate::begin(), reco::PFCandidate::elementsInBlocks(), reco::CompositeCandidate::end(), and reco::PFBlockElement::index().

Referenced by produce().

{
  unsigned refindex=pfbe.index();
  //  std::cout << " N daughters " << cand.numberOfDaughters() << std::endl;
  reco::PFCandidate::const_iterator myDaughterCandidate=cand.begin();
  reco::PFCandidate::const_iterator itend=cand.end();

  for(;myDaughterCandidate!=itend;++myDaughterCandidate)
    {
      const reco::PFCandidate * myPFCandidate = (const reco::PFCandidate*)&*myDaughterCandidate;
      if(myPFCandidate->elementsInBlocks().size()!=1)
        {
          //      std::cout << " Daughter with " << myPFCandidate.elementsInBlocks().size()<< " element in block " << std::endl;
          return cand;
        }
      if(myPFCandidate->elementsInBlocks()[0].second==refindex) 
        {
          //      std::cout << " Found it " << cand << std::endl;
          return *myPFCandidate;
        }      
    }
  return cand;
}
void PFElectronTranslator::createBasicCluster ( const reco::PFBlockElement PFBE,
reco::BasicClusterCollection basicClusters,
std::vector< const reco::PFCluster * > &  pfClusters,
const reco::PFCandidate coCandidate 
) const [private]

Definition at line 279 of file PFElectronTranslator.cc.

References reco::CaloCluster::algo(), reco::CaloCluster::caloID(), reco::PFBlockElement::clusterRef(), reco::CaloCluster::hitsAndFractions(), edm::Ref< C, T, F >::isNull(), reco::CaloCluster::position(), reco::PFCandidate::rawEcalEnergy(), and reco::CaloCluster::seed().

Referenced by produce().

{
  reco::PFClusterRef myPFClusterRef= PFBE.clusterRef();
  if(myPFClusterRef.isNull()) return;  

  const reco::PFCluster & myPFCluster (*myPFClusterRef);
  pfClusters.push_back(&myPFCluster);
//  std::cout << " Creating BC " << myPFCluster.energy() << " " << coCandidate.ecalEnergy() <<" "<<  coCandidate.rawEcalEnergy() <<std::endl;
//  std::cout << " # hits " << myPFCluster.hitsAndFractions().size() << std::endl;

//  basicClusters.push_back(reco::CaloCluster(myPFCluster.energy(),
  basicClusters.push_back(reco::CaloCluster(
                                            //      myPFCluster.energy(),
                                            coCandidate.rawEcalEnergy(),
                                            myPFCluster.position(),
                                            myPFCluster.caloID(),
                                            myPFCluster.hitsAndFractions(),
                                            myPFCluster.algo(),
                                            myPFCluster.seed()));
}
void PFElectronTranslator::createBasicClusterPtrs ( const edm::OrphanHandle< reco::BasicClusterCollection > &  basicClustersHandle) [private]

Definition at line 311 of file PFElectronTranslator.cc.

References basicClusterPtr_, basicClusters_, GsfTrackRef_, and findQualityFiles::size.

Referenced by produce().

{
  unsigned size=GsfTrackRef_.size();
  unsigned basicClusterCounter=0;
  basicClusterPtr_.resize(size);

  for(unsigned iGSF=0;iGSF<size;++iGSF) // loop on tracks
    {
      unsigned nbc=basicClusters_[iGSF].size();
      for(unsigned ibc=0;ibc<nbc;++ibc) // loop on basic clusters
        {
          //      std::cout <<  "Track "<< iGSF << " ref " << basicClusterCounter << std::endl;
          reco::CaloClusterPtr bcPtr(basicClustersHandle,basicClusterCounter);
          basicClusterPtr_[iGSF].push_back(bcPtr);
          ++basicClusterCounter;
        }
    }
}
void PFElectronTranslator::createGsfElectronCoreRefs ( const edm::OrphanHandle< reco::GsfElectronCoreCollection > &  gsfElectronCoreHandle) [private]

Definition at line 560 of file PFElectronTranslator.cc.

References gsfElectronCoreRefs_, GsfTrackRef_, and findQualityFiles::size.

Referenced by produce().

                                                                                                                                 {
  unsigned size=GsfTrackRef_.size();
  
  for(unsigned iGSF=0;iGSF<size;++iGSF) // loop on tracks
    {
      edm::Ref<reco::GsfElectronCoreCollection> elecCoreRef(gsfElectronCoreHandle,iGSF);
      gsfElectronCoreRefs_.push_back(elecCoreRef);
    }  
}
void PFElectronTranslator::createGsfElectronCores ( reco::GsfElectronCoreCollection gsfElectronCores) const [private]

Definition at line 546 of file PFElectronTranslator.cc.

References GsfTrackRef_, kfTrackRef_, scMap_, reco::GsfElectronCore::setCtfTrack(), and reco::GsfElectronCore::setPflowSuperCluster().

Referenced by produce().

                                                                                                        {
  unsigned nGSF=GsfTrackRef_.size();
  for(unsigned iGSF=0;iGSF<nGSF;++iGSF)
    {
      reco::GsfElectronCore myElectronCore(GsfTrackRef_[iGSF]);
      myElectronCore.setCtfTrack(kfTrackRef_[iGSF],-1.);
      std::map<reco::GsfTrackRef,reco::SuperClusterRef>::const_iterator 
        itcheck=scMap_.find(GsfTrackRef_[iGSF]);
      if(itcheck!=scMap_.end())
        myElectronCore.setPflowSuperCluster(itcheck->second);
      gsfElectronCores.push_back(myElectronCore);
    }
}
void PFElectronTranslator::createGsfElectrons ( const reco::PFCandidateCollection pfcand,
const IsolationValueMaps isolationValues,
reco::GsfElectronCollection gsfelectrons 
) [private]

Definition at line 581 of file PFElectronTranslator.cc.

References reco::GsfElectron::addAmbiguousGsfTrack(), ambiguousGsfTracks_, CandidatePtr_, reco::GsfElectron::PflowIsolationVariables::chargedHadronIso, reco::GsfElectron::MvaInput::deltaEta, reco::PFCandidate::deltaP(), reco::GsfElectron::MvaInput::earlyBrem, reco::PFCandidate::electronExtraRef(), reco::GsfElectron::MvaInput::etOutsideMustache, gsfElectronCoreRefs_, gsfPFCandidateIndex_, GsfTrackRef_, reco::GsfElectron::MvaInput::hadEnergy, reco::GsfElectron::MvaInput::lateBrem, reco::Mustache::MustacheID(), reco::GsfElectron::MvaOutput::mva, reco::PFCandidateElectronExtra::MVA_DeltaEtaTrackCluster, reco::PFCandidate::mva_e_pi(), reco::PFCandidateElectronExtra::MVA_FirstBrem, reco::PFCandidateElectronExtra::MVA_LateBrem, reco::GsfElectron::MvaInput::nClusterOutsideMustache, reco::GsfElectron::PflowIsolationVariables::neutralHadronIso, reco::LeafCandidate::p4(), reco::GsfElectron::P4_PFLOW_COMBINATION, reco::GsfElectron::PflowIsolationVariables::photonIso, reco::GsfElectron::setMvaInput(), reco::GsfElectron::setMvaOutput(), reco::GsfElectron::setP4(), reco::GsfElectron::setPfIsolationVariables(), reco::GsfElectron::MvaInput::sigmaEtaEta, findQualityFiles::size, and reco::GsfElectron::MvaOutput::status.

Referenced by produce().

                                                                                       {
  unsigned size=GsfTrackRef_.size();
  
  for(unsigned iGSF=0;iGSF<size;++iGSF) // loop on tracks
    {
      const reco::PFCandidate& pfCandidate(pfcand[gsfPFCandidateIndex_[iGSF]]);
      // Electron
      reco::GsfElectron myElectron(gsfElectronCoreRefs_[iGSF]);
      // Warning set p4 error ! 
      myElectron.setP4(reco::GsfElectron::P4_PFLOW_COMBINATION, pfCandidate.p4(),pfCandidate.deltaP(), true);
      
      // MVA inputs
      reco::GsfElectron::MvaInput myMvaInput;
      myMvaInput.earlyBrem = pfCandidate.electronExtraRef()->mvaVariable(reco::PFCandidateElectronExtra::MVA_FirstBrem);
      myMvaInput.lateBrem = pfCandidate.electronExtraRef()->mvaVariable(reco::PFCandidateElectronExtra::MVA_LateBrem);
      myMvaInput.deltaEta = pfCandidate.electronExtraRef()->mvaVariable(reco::PFCandidateElectronExtra::MVA_DeltaEtaTrackCluster);
      myMvaInput.sigmaEtaEta = pfCandidate.electronExtraRef()->sigmaEtaEta();
      myMvaInput.hadEnergy = pfCandidate.electronExtraRef()->hadEnergy();

      // Mustache
      reco::Mustache myMustache;
      myMustache.MustacheID(*(myElectron. pflowSuperCluster()), myMvaInput.nClusterOutsideMustache, myMvaInput.etOutsideMustache );

      myElectron.setMvaInput(myMvaInput);

      // MVA output
      reco::GsfElectron::MvaOutput myMvaOutput;
      myMvaOutput.status = pfCandidate.electronExtraRef()->electronStatus();
      myMvaOutput.mva = pfCandidate.mva_e_pi();
      myElectron.setMvaOutput(myMvaOutput);
      
      // ambiguous tracks
      unsigned ntracks=ambiguousGsfTracks_[iGSF].size();
      for(unsigned it=0;it<ntracks;++it) {
        myElectron.addAmbiguousGsfTrack(ambiguousGsfTracks_[iGSF][it]);
      }

      // isolation
      reco::GsfElectron::PflowIsolationVariables myPFIso;
      myPFIso.chargedHadronIso=(*isolationValues[0])[CandidatePtr_[iGSF]];
      myPFIso.photonIso=(*isolationValues[1])[CandidatePtr_[iGSF]];
      myPFIso.neutralHadronIso=(*isolationValues[2])[CandidatePtr_[iGSF]];      
      myElectron.setPfIsolationVariables(myPFIso);
      
      gsfelectrons.push_back(myElectron);
    }

}
void PFElectronTranslator::createPreshowerCluster ( const reco::PFBlockElement PFBE,
reco::PreshowerClusterCollection preshowerClusters,
unsigned  plane 
) const [private]

Definition at line 304 of file PFElectronTranslator.cc.

References reco::PFBlockElement::clusterRef().

Referenced by produce().

{
  reco::PFClusterRef  myPFClusterRef= PFBE.clusterRef();
  preshowerClusters.push_back(reco::PreshowerCluster(myPFClusterRef->energy(),myPFClusterRef->position(),
                                               myPFClusterRef->hitsAndFractions(),plane));
}
void PFElectronTranslator::createPreshowerClusterPtrs ( const edm::OrphanHandle< reco::PreshowerClusterCollection > &  preshowerClustersHandle) [private]

Definition at line 330 of file PFElectronTranslator.cc.

References GsfTrackRef_, preshowerClusterPtr_, preshowerClusters_, and findQualityFiles::size.

Referenced by produce().

{
  unsigned size=GsfTrackRef_.size();
  unsigned psClusterCounter=0;
  preshowerClusterPtr_.resize(size);

  for(unsigned iGSF=0;iGSF<size;++iGSF) // loop on tracks
    {
      unsigned nbc=preshowerClusters_[iGSF].size();
      for(unsigned ibc=0;ibc<nbc;++ibc) // loop on basic clusters
        {
          //      std::cout <<  "Track "<< iGSF << " ref " << basicClusterCounter << std::endl;
          reco::CaloClusterPtr psPtr(preshowerClustersHandle,psClusterCounter);
          preshowerClusterPtr_[iGSF].push_back(psPtr);
          ++psClusterCounter;
        }
    }
}
void PFElectronTranslator::createSuperClusterGsfMapRefs ( const edm::OrphanHandle< reco::SuperClusterCollection > &  superClustersHandle) [private]

Definition at line 349 of file PFElectronTranslator.cc.

References GsfTrackRef_, scMap_, and findQualityFiles::size.

Referenced by produce().

{
  unsigned size=GsfTrackRef_.size();

  for(unsigned iGSF=0;iGSF<size;++iGSF) // loop on tracks
    {
      edm::Ref<reco::SuperClusterCollection> scRef(superClustersHandle,iGSF);
      scMap_[GsfTrackRef_[iGSF]]=scRef;
    }
}
void PFElectronTranslator::createSuperClusters ( const reco::PFCandidateCollection pfCand,
reco::SuperClusterCollection superClusters 
) const [private]

Definition at line 432 of file PFElectronTranslator.cc.

References reco::SuperCluster::addCluster(), reco::CaloCluster::addHitAndFraction(), reco::SuperCluster::addPreshowerCluster(), basicClusterPtr_, basicClusters_, alignCSCRings::e, gsfPFCandidateIndex_, GsfTrackRef_, pfClusters_, PFClusterWidthAlgo::pflowEtaWidth(), PFClusterWidthAlgo::pflowPhiWidth(), preshowerClusterPtr_, reco::SuperCluster::rawEnergy(), reco::SuperCluster::setEtaWidth(), reco::SuperCluster::setPhiWidth(), reco::SuperCluster::setPreshowerEnergy(), and reco::SuperCluster::setSeed().

Referenced by produce().

{
  unsigned nGSF=GsfTrackRef_.size();
  for(unsigned iGSF=0;iGSF<nGSF;++iGSF)
    {

      // Computes energy position a la e/gamma 
      double sclusterE=0;
      double posX=0.;
      double posY=0.;
      double posZ=0.;
      
      unsigned nbasics=basicClusters_[iGSF].size();
      for(unsigned ibc=0;ibc<nbasics;++ibc)
        {
          double e = basicClusters_[iGSF][ibc].energy();
          sclusterE += e;
          posX += e * basicClusters_[iGSF][ibc].position().X();
          posY += e * basicClusters_[iGSF][ibc].position().Y();
          posZ += e * basicClusters_[iGSF][ibc].position().Z();   
        }
      posX /=sclusterE;
      posY /=sclusterE;
      posZ /=sclusterE;
      
      if(pfCand[gsfPFCandidateIndex_[iGSF]].gsfTrackRef()!=GsfTrackRef_[iGSF])
        {
          edm::LogError("PFElectronTranslator") << " Major problem in PFElectron Translator" << std::endl;
        }
      
      // compute the width
      PFClusterWidthAlgo pfwidth(pfClusters_[iGSF]);
      
      double correctedEnergy=pfCand[gsfPFCandidateIndex_[iGSF]].ecalEnergy();
      reco::SuperCluster mySuperCluster(correctedEnergy,math::XYZPoint(posX,posY,posZ));
      // protection against empty basic cluster collection ; the value is -2 in this case
      if(nbasics)
        {
//        std::cout << "SuperCluster creation; energy " << pfCand[gsfPFCandidateIndex_[iGSF]].ecalEnergy();
//        std::cout << " " <<   pfCand[gsfPFCandidateIndex_[iGSF]].rawEcalEnergy() << std::endl;
//        std::cout << "Seed energy from basic " << basicClusters_[iGSF][0].energy() << std::endl;
          mySuperCluster.setSeed(basicClusterPtr_[iGSF][0]);
        }
      else
        {
          //      std::cout << "SuperCluster creation ; seed energy " << 0 << std::endl;
//        std::cout << "SuperCluster creation ; energy " << pfCand[gsfPFCandidateIndex_[iGSF]].ecalEnergy();
//        std::cout << " " <<   pfCand[gsfPFCandidateIndex_[iGSF]].rawEcalEnergy() << std::endl;
//        std::cout << " No seed found " << 0 << std::endl;       
//        std::cout << " MVA " << pfCand[gsfPFCandidateIndex_[iGSF]].mva_e_pi() << std::endl;
          mySuperCluster.setSeed(reco::CaloClusterPtr());
        }
      // the seed should be the first basic cluster

      for(unsigned ibc=0;ibc<nbasics;++ibc)
        {
          mySuperCluster.addCluster(basicClusterPtr_[iGSF][ibc]);
          //      std::cout <<"Adding Ref to SC " << basicClusterPtr_[iGSF][ibc].index() << std::endl;
          const std::vector< std::pair<DetId, float> > & v1 = basicClusters_[iGSF][ibc].hitsAndFractions();
          //      std::cout << " Number of cells " << v1.size() << std::endl;
          for( std::vector< std::pair<DetId, float> >::const_iterator diIt = v1.begin();
               diIt != v1.end();
               ++diIt ) {
            //      std::cout << " Adding DetId " << (diIt->first).rawId() << " " << diIt->second << std::endl;
            mySuperCluster.addHitAndFraction(diIt->first,diIt->second);
          } // loop over rechits      
        }      

      unsigned nps=preshowerClusterPtr_[iGSF].size();
      for(unsigned ips=0;ips<nps;++ips)
        {
          mySuperCluster.addPreshowerCluster(preshowerClusterPtr_[iGSF][ips]);
        }
      

      // Set the preshower energy
      mySuperCluster.setPreshowerEnergy(pfCand[gsfPFCandidateIndex_[iGSF]].pS1Energy()+
                                        pfCand[gsfPFCandidateIndex_[iGSF]].pS2Energy());

      // Set the cluster width
      mySuperCluster.setEtaWidth(pfwidth.pflowEtaWidth());
      mySuperCluster.setPhiWidth(pfwidth.pflowPhiWidth());
      // Force the computation of rawEnergy_ of the reco::SuperCluster
      mySuperCluster.rawEnergy();
      superClusters.push_back(mySuperCluster);
   }
}
bool PFElectronTranslator::fetchCandidateCollection ( edm::Handle< reco::PFCandidateCollection > &  c,
const edm::InputTag tag,
const edm::Event iEvent 
) const [private]

Definition at line 246 of file PFElectronTranslator.cc.

References emptyIsOk_, newFWLiteAna::found, and edm::Event::getByLabel().

Referenced by fillMVAValueMap(), and produce().

                                                                            {  
  bool found = iEvent.getByLabel(tag, c);

  if(!found && !emptyIsOk_)
    {
      std::ostringstream  err;
      err<<" cannot get PFCandidates: "
         <<tag<<std::endl;
      edm::LogError("PFElectronTranslator")<<err.str();
    }
  return found;
      
}
void PFElectronTranslator::fetchGsfCollection ( edm::Handle< reco::GsfTrackCollection > &  c,
const edm::InputTag tag,
const edm::Event iEvent 
) const [private]

Definition at line 262 of file PFElectronTranslator.cc.

References Exception, newFWLiteAna::found, and edm::Event::getByLabel().

Referenced by fillMVAValueMap(), and fillSCRefValueMap().

                                                                            {  
  bool found = iEvent.getByLabel(tag, c);
  
  if(!found ) {
    std::ostringstream  err;
    err<<" cannot get GSFTracks: "
       <<tag<<std::endl;
    edm::LogError("PFElectronTranslator")<<err.str();
    throw cms::Exception( "MissingProduct", err.str());
  }  
}
void PFElectronTranslator::fillMVAValueMap ( edm::Event iEvent,
edm::ValueMap< float >::Filler &  filler 
) [private]

Definition at line 361 of file PFElectronTranslator.cc.

References alignCSCRings::e, fetchCandidateCollection(), fetchGsfCollection(), gsfMvaMap_, reco::PFCandidate::gsfTrackRef(), i, inputTagGSFTracks_, inputTagPFCandidateElectrons_, edm::helper::Filler< Map >::insert(), edm::Ref< C, T, F >::isNull(), reco::PFCandidate::mva_e_pi(), reco::PFCandidate::particleId(), reco::tau::pfCandidates(), ntuplemaker::status, and makeHLTPrescaleTable::values.

Referenced by produce().

{
  gsfMvaMap_.clear();
  edm::Handle<reco::PFCandidateCollection> pfCandidates;
  bool status=fetchCandidateCollection(pfCandidates, 
                                       inputTagPFCandidateElectrons_, 
                                       iEvent );
  
  unsigned ncand=(status)?pfCandidates->size():0;
  for( unsigned i=0; i<ncand; ++i ) {
    
    const reco::PFCandidate& cand = (*pfCandidates)[i];    
    if(cand.particleId()!=reco::PFCandidate::e) continue; 
    if(cand.gsfTrackRef().isNull()) continue;
    // Fill the MVA map
    gsfMvaMap_[cand.gsfTrackRef()]=cand.mva_e_pi();       
  }
  
  edm::Handle<reco::GsfTrackCollection> gsfTracks;
  fetchGsfCollection(gsfTracks,
                     inputTagGSFTracks_,
                     iEvent);
  unsigned ngsf=gsfTracks->size();
  std::vector<float> values;
  for(unsigned igsf=0;igsf<ngsf;++igsf)
    {
      reco::GsfTrackRef theTrackRef(gsfTracks, igsf);
      std::map<reco::GsfTrackRef,float>::const_iterator itcheck=gsfMvaMap_.find(theTrackRef);
      if(itcheck==gsfMvaMap_.end())
        {
          //      edm::LogWarning("PFElectronTranslator") << "MVA Map, missing GSF track ref " << std::endl;
          values.push_back(-99.);
          //      std::cout << " Push_back -99. " << std::endl;
        }
      else
        {
          //      std::cout <<  " Value " << itcheck->second << std::endl;
          values.push_back(itcheck->second);      
        }
    }
  filler.insert(gsfTracks,values.begin(),values.end());
}
void PFElectronTranslator::fillSCRefValueMap ( edm::Event iEvent,
edm::ValueMap< reco::SuperClusterRef >::Filler &  filler 
) const [private]

Definition at line 405 of file PFElectronTranslator.cc.

References fetchGsfCollection(), inputTagGSFTracks_, edm::helper::Filler< Map >::insert(), scMap_, and makeHLTPrescaleTable::values.

Referenced by produce().

{
  edm::Handle<reco::GsfTrackCollection> gsfTracks;
  fetchGsfCollection(gsfTracks,
                     inputTagGSFTracks_,
                     iEvent);
  unsigned ngsf=gsfTracks->size();
  std::vector<reco::SuperClusterRef> values;
  for(unsigned igsf=0;igsf<ngsf;++igsf)
    {
      reco::GsfTrackRef theTrackRef(gsfTracks, igsf);
      std::map<reco::GsfTrackRef,reco::SuperClusterRef>::const_iterator itcheck=scMap_.find(theTrackRef);
      if(itcheck==scMap_.end())
        {
          //      edm::LogWarning("PFElectronTranslator") << "SCRef Map, missing GSF track ref" << std::endl;
          values.push_back(reco::SuperClusterRef());
        }
      else
        {
          values.push_back(itcheck->second);      
        }
    }
  filler.insert(gsfTracks,values.begin(),values.end());
}
void PFElectronTranslator::fillValueMap ( edm::Event iEvent,
edm::ValueMap< float >::Filler &  filler 
) const [private]
void PFElectronTranslator::getAmbiguousGsfTracks ( const reco::PFBlockElement PFBE,
std::vector< reco::GsfTrackRef > &  tracks 
) const [private]

Definition at line 570 of file PFElectronTranslator.cc.

References reco::PFBlockElementGsfTrack::GsftrackRefPF().

Referenced by produce().

                                                                                                                          {
  const reco::PFBlockElementGsfTrack *  GsfEl =  dynamic_cast<const reco::PFBlockElementGsfTrack*>(&PFBE);
  if(GsfEl==0) return;
  const std::vector<reco::GsfPFRecTrackRef>& ambPFRecTracks(GsfEl->GsftrackRefPF()->convBremGsfPFRecTrackRef());
  unsigned ntracks=ambPFRecTracks.size();
  for(unsigned it=0;it<ntracks;++it) {
    tracks.push_back(ambPFRecTracks[it]->gsfTrackRef());
  }
}
void PFElectronTranslator::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDProducer.

Definition at line 62 of file PFElectronTranslator.cc.

References ambiguousGsfTracks_, basicClusterPtr_, basicClusters_, CandidatePtr_, checkStatusFlag_, correspondingDaughterCandidate(), createBasicCluster(), createBasicClusterPtrs(), createGsfElectronCoreRefs(), createGsfElectronCores(), createGsfElectrons(), createPreshowerCluster(), createPreshowerClusterPtrs(), createSuperClusterGsfMapRefs(), createSuperClusters(), alignCSCRings::e, ECAL, reco::PFCandidate::electronExtraRef(), asciidump::elements, reco::PFCandidate::elementsInBlocks(), fetchCandidateCollection(), edm::helper::Filler< Map >::fill(), fillMVAValueMap(), fillSCRefValueMap(), getAmbiguousGsfTracks(), edm::Event::getByLabel(), reco::PFBlockElement::GSF, GsfElectronCollection_, GsfElectronCoreCollection_, gsfElectronCoreRefs_, gsfPFCandidateIndex_, reco::PFCandidate::gsfTrackRef(), GsfTrackRef_, i, inputTagIsoVals_, inputTagPFCandidates_, edm::Ref< C, T, F >::isNull(), j, kfTrackRef_, reco::PFCandidate::mva_e_pi(), MVACut_, reco::PFCandidate::particleId(), PFBasicClusterCollection_, reco::tau::pfCandidates(), pfClusters_, PFMVAValueMap_, PFPreshowerClusterCollection_, PFSCValueMap_, PFSuperClusterCollection_, preshowerClusterPtr_, preshowerClusters_, reco::PFBlockElement::PS1, reco::PFBlockElement::PS2, edm::Event::put(), scMap_, reco::PFCandidateElectronExtra::Selected, ntuplemaker::status, superClusters_, reco::PFCandidate::trackRef(), and reco::PFBlockElement::type().

                                                                 { 
  
  std::auto_ptr<reco::GsfElectronCoreCollection>
    gsfElectronCores_p(new reco::GsfElectronCoreCollection);

  std::auto_ptr<reco::GsfElectronCollection>
    gsfElectrons_p(new reco::GsfElectronCollection);

  std::auto_ptr<reco::SuperClusterCollection> 
    superClusters_p(new reco::SuperClusterCollection);

  std::auto_ptr<reco::BasicClusterCollection> 
    basicClusters_p(new reco::BasicClusterCollection);

  std::auto_ptr<reco::PreshowerClusterCollection>
    psClusters_p(new reco::PreshowerClusterCollection);
  
  std::auto_ptr<edm::ValueMap<float> > mvaMap_p(new edm::ValueMap<float>());
  edm::ValueMap<float>::Filler mvaFiller(*mvaMap_p);

  std::auto_ptr<edm::ValueMap<reco::SuperClusterRef> > 
    scMap_p(new edm::ValueMap<reco::SuperClusterRef>());
  edm::ValueMap<reco::SuperClusterRef>::Filler scRefFiller(*scMap_p);
  

  edm::Handle<reco::PFCandidateCollection> pfCandidates;
  bool status=fetchCandidateCollection(pfCandidates, 
                                       inputTagPFCandidates_, 
                                       iEvent );

  IsolationValueMaps isolationValues(inputTagIsoVals_.size());
  for (size_t j = 0; j<inputTagIsoVals_.size(); ++j) {
    iEvent.getByLabel(inputTagIsoVals_[j], isolationValues[j]);
  }


  // clear the vectors
  GsfTrackRef_.clear();
  CandidatePtr_.clear();
  ambiguousGsfTracks_.clear();
  kfTrackRef_.clear();
  basicClusters_.clear();
  pfClusters_.clear();
  preshowerClusters_.clear();
  superClusters_.clear();
  basicClusterPtr_.clear();
  preshowerClusterPtr_.clear();
  gsfPFCandidateIndex_.clear();
  gsfElectronCoreRefs_.clear();
  scMap_.clear();

 
  // loop on the candidates 
  //CC@@
  // we need first to create AND put the SuperCluster, 
  // basic clusters and presh clusters collection 
  // in order to get a working Handle
  unsigned ncand=(status)?pfCandidates->size():0;
  unsigned iGSF=0;
  for( unsigned i=0; i<ncand; ++i ) {

    const reco::PFCandidate& cand = (*pfCandidates)[i];    
    if(cand.particleId()!=reco::PFCandidate::e) continue; 
    if(cand.gsfTrackRef().isNull()) continue;
    // Note that -1 will still cut some total garbage candidates 
    // Fill the MVA map
    if(cand.mva_e_pi()<MVACut_) continue;
    
    // Check the status flag
    if(checkStatusFlag_ && !cand.electronExtraRef()->electronStatus(reco::PFCandidateElectronExtra::Selected)) {
      continue;
    }

    GsfTrackRef_.push_back(cand.gsfTrackRef());
    kfTrackRef_.push_back(cand.trackRef());
    gsfPFCandidateIndex_.push_back(i);

    reco::PFCandidatePtr ptrToPFElectron(pfCandidates,i);
    //CandidatePtr_.push_back(ptrToPFElectron->sourceCandidatePtr(0));
    CandidatePtr_.push_back(ptrToPFElectron);    

    basicClusters_.push_back(reco::BasicClusterCollection());
    pfClusters_.push_back(std::vector<const reco::PFCluster *>());
    preshowerClusters_.push_back(reco::PreshowerClusterCollection());
    ambiguousGsfTracks_.push_back(std::vector<reco::GsfTrackRef>());

    for(unsigned iele=0; iele<cand.elementsInBlocks().size(); ++iele) {
      // first get the block 
      reco::PFBlockRef blockRef = cand.elementsInBlocks()[iele].first;
      //
      unsigned elementIndex = cand.elementsInBlocks()[iele].second;
      // check it actually exists 
      if(blockRef.isNull()) continue;
      
      // then get the elements of the block
      const edm::OwnVector< reco::PFBlockElement >&  elements = (*blockRef).elements();
      
      const reco::PFBlockElement & pfbe (elements[elementIndex]); 
      // The first ECAL element should be the cluster associated to the GSF; defined as the seed
      if(pfbe.type()==reco::PFBlockElement::ECAL)
        {         
          //      const reco::PFCandidate * coCandidate = &cand;
          // the Brem photons are saved as daughter PFCandidate; this 
          // is convenient to access the corrected energy
          //      std::cout << " Found candidate "  << correspondingDaughterCandidate(coCandidate,pfbe) << " " << coCandidate << std::endl;
          createBasicCluster(pfbe,basicClusters_[iGSF],pfClusters_[iGSF],correspondingDaughterCandidate(cand,pfbe));
        }
      if(pfbe.type()==reco::PFBlockElement::PS1)
        {
          createPreshowerCluster(pfbe,preshowerClusters_[iGSF],1);
        }
      if(pfbe.type()==reco::PFBlockElement::PS2)
        {
          createPreshowerCluster(pfbe,preshowerClusters_[iGSF],2);
        }      
      if(pfbe.type()==reco::PFBlockElement::GSF)
        {
          getAmbiguousGsfTracks(pfbe,ambiguousGsfTracks_[iGSF]);
        }

    }   // loop on the elements

    // save the basic clusters
    basicClusters_p->insert(basicClusters_p->end(),basicClusters_[iGSF].begin(), basicClusters_[iGSF].end());
    // save the preshower clusters
    psClusters_p->insert(psClusters_p->end(),preshowerClusters_[iGSF].begin(),preshowerClusters_[iGSF].end());

    ++iGSF;
  } // loop on PFCandidates

  
   //Save the basic clusters and get an handle as to be able to create valid Refs (thanks to Claude)
  //  std::cout << " Number of basic clusters " << basicClusters_p->size() << std::endl;
  const edm::OrphanHandle<reco::BasicClusterCollection> bcRefProd = 
    iEvent.put(basicClusters_p,PFBasicClusterCollection_);

  //preshower clusters
  const edm::OrphanHandle<reco::PreshowerClusterCollection> psRefProd = 
    iEvent.put(psClusters_p,PFPreshowerClusterCollection_);

  // now that the Basic clusters are in the event, the Ref can be created
  createBasicClusterPtrs(bcRefProd);
  // now that the preshower clusters are in the event, the Ref can be created
  createPreshowerClusterPtrs(psRefProd);
  
  // and now the Super cluster can be created with valid references  
  if(status) createSuperClusters(*pfCandidates,*superClusters_p);
  
  // Let's put the super clusters in the event
  const edm::OrphanHandle<reco::SuperClusterCollection> scRefProd = iEvent.put(superClusters_p,PFSuperClusterCollection_); 
  // create the super cluster Ref
  createSuperClusterGsfMapRefs(scRefProd);

  // Now create the GsfElectronCoers
  createGsfElectronCores(*gsfElectronCores_p);
  // Put them in the as to get to be able to build a Ref
  const edm::OrphanHandle<reco::GsfElectronCoreCollection> gsfElectronCoreRefProd = 
    iEvent.put(gsfElectronCores_p,GsfElectronCoreCollection_);

  // now create the Refs 
  createGsfElectronCoreRefs(gsfElectronCoreRefProd);

  // now make the GsfElectron
  createGsfElectrons(*pfCandidates,isolationValues,*gsfElectrons_p);
  iEvent.put(gsfElectrons_p,GsfElectronCollection_);

  fillMVAValueMap(iEvent,mvaFiller);
  mvaFiller.fill();

  fillSCRefValueMap(iEvent,scRefFiller);
  scRefFiller.fill();

  // MVA map
  iEvent.put(mvaMap_p,PFMVAValueMap_);
  // Gsf-SC map
  iEvent.put(scMap_p,PFSCValueMap_);


  
}

Member Data Documentation

std::vector<std::vector<reco::GsfTrackRef> > PFElectronTranslator::ambiguousGsfTracks_ [private]

Definition at line 111 of file PFElectronTranslator.h.

Referenced by createGsfElectrons(), and produce().

Definition at line 121 of file PFElectronTranslator.h.

Referenced by createBasicClusterPtrs(), createSuperClusters(), and produce().

Definition at line 113 of file PFElectronTranslator.h.

Referenced by createBasicClusterPtrs(), createSuperClusters(), and produce().

Definition at line 107 of file PFElectronTranslator.h.

Referenced by createGsfElectrons(), and produce().

Definition at line 101 of file PFElectronTranslator.h.

Referenced by PFElectronTranslator(), and produce().

Definition at line 132 of file PFElectronTranslator.h.

Referenced by fetchCandidateCollection(), and PFElectronTranslator().

Definition at line 99 of file PFElectronTranslator.h.

Referenced by PFElectronTranslator(), and produce().

Definition at line 98 of file PFElectronTranslator.h.

Referenced by PFElectronTranslator(), and produce().

Definition at line 125 of file PFElectronTranslator.h.

Referenced by createGsfElectronCoreRefs(), createGsfElectrons(), and produce().

Definition at line 130 of file PFElectronTranslator.h.

Referenced by fillMVAValueMap().

std::vector<int> PFElectronTranslator::gsfPFCandidateIndex_ [private]

Definition at line 127 of file PFElectronTranslator.h.

Referenced by createGsfElectrons(), createSuperClusters(), and produce().

Definition at line 91 of file PFElectronTranslator.h.

Referenced by fillMVAValueMap(), fillSCRefValueMap(), and PFElectronTranslator().

Definition at line 92 of file PFElectronTranslator.h.

Referenced by PFElectronTranslator(), and produce().

Definition at line 90 of file PFElectronTranslator.h.

Referenced by fillMVAValueMap(), and PFElectronTranslator().

Definition at line 89 of file PFElectronTranslator.h.

Referenced by PFElectronTranslator(), and produce().

Definition at line 109 of file PFElectronTranslator.h.

Referenced by createGsfElectronCores(), and produce().

Definition at line 100 of file PFElectronTranslator.h.

Referenced by PFElectronTranslator(), and produce().

Definition at line 93 of file PFElectronTranslator.h.

Referenced by PFElectronTranslator(), and produce().

std::vector<std::vector<const reco::PFCluster *> > PFElectronTranslator::pfClusters_ [private]

Definition at line 115 of file PFElectronTranslator.h.

Referenced by createSuperClusters(), and produce().

std::string PFElectronTranslator::PFMVAValueMap_ [private]

Definition at line 96 of file PFElectronTranslator.h.

Referenced by PFElectronTranslator(), and produce().

Definition at line 94 of file PFElectronTranslator.h.

Referenced by PFElectronTranslator(), and produce().

std::string PFElectronTranslator::PFSCValueMap_ [private]

Definition at line 97 of file PFElectronTranslator.h.

Referenced by PFElectronTranslator(), and produce().

Definition at line 95 of file PFElectronTranslator.h.

Referenced by PFElectronTranslator(), and produce().

Definition at line 117 of file PFElectronTranslator.h.

Referenced by createPreshowerClusterPtrs(), and produce().

Definition at line 119 of file PFElectronTranslator.h.

Referenced by produce().