CommonTools/ParticleFlow/plugins/DeltaBetaWeights.cc
// ------------ method called to produce the data  ------------
method called to produce the data
method called to produce the data
void DeltaBetaWeights::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
  using namespace edm;
  edm::View<reco::Candidate> const pfCharged = iEvent.get(pfCharged_token);
  edm::View<reco::Candidate> const& pfPU = iEvent.get(pfPU_token);
  edm::View<reco::Candidate> const& src = iEvent.get(src_token);
  double sumNPU = .0;
  double sumPU = .0;
  std::unique_ptr<reco::PFCandidateCollection> out(new reco::PFCandidateCollection);
  out->reserve(src.size());
  for (const reco::Candidate& cand : src) {
    if (cand.charge() != 0) {
      edm::LogWarning("DeltaBetaWeights")
          << "Trying to reweight charged particle... saving it to output collection without any change";
      out->emplace_back(cand.charge(), cand.p4(), reco::PFCandidate::ParticleType::X);
      (out->back()).setParticleType((out->back()).translatePdgIdToType(cand.pdgId()));
      continue;
    }
    sumNPU = 1.0;
    sumPU = 1.0;
    double eta = cand.eta();
    double phi = cand.phi();
    for (const reco::Candidate& chCand : pfCharged) {
      double sum = (chCand.pt() * chCand.pt()) / (deltaR2(eta, phi, chCand.eta(), chCand.phi()));
      if (sum > 1.0)
        sumNPU *= sum;
    }
    sumNPU = 0.5 * log(sumNPU);
    for (const reco::Candidate& puCand : pfPU) {
      double sum = (puCand.pt() * puCand.pt()) / (deltaR2(eta, phi, puCand.eta(), puCand.phi()));
      if (sum > 1.0)
        sumPU *= sum;
    }
    sumPU = 0.5 * log(sumPU);
    reco::PFCandidate neutral = reco::PFCandidate(cand.charge(), cand.p4(), reco::PFCandidate::ParticleType::X);
    neutral.setParticleType(neutral.translatePdgIdToType(cand.pdgId()));
    if (sumNPU + sumPU > 0)
      neutral.setP4(((sumNPU) / (sumNPU + sumPU)) * neutral.p4());
    out->push_back(neutral);
  }
  iEvent.put(std::move(out));
}
void DeltaBetaWeights :: produce ( edm :: StreamID , edm :: Event & iEvent , const edm :: EventSetup & iSetup ) const { using namespace edm ; edm :: View < reco :: Candidate > const pfCharged = iEvent . get ( pfCharged_token ) ; edm :: View < reco :: Candidate > const & pfPU = iEvent . get ( pfPU_token ) ; edm :: View < reco :: Candidate > const & src = iEvent . get ( src_token ) ; double sumNPU = .0 ; double sumPU = .0 ; std :: unique_ptr < reco :: PFCandidateCollection > out ( new reco :: PFCandidateCollection ) ; out -> reserve ( src . size ( ) ) ; for ( const reco :: Candidate & cand : src ) { if ( cand . charge ( ) != 0 ) { edm :: LogWarning ( " " ) << " " ; out -> emplace_back ( cand . charge ( ) , cand . p4 ( ) , reco :: PFCandidate :: ParticleType :: X ) ; ( out -> back ( ) ) . setParticleType ( ( out -> back ( ) ) . translatePdgIdToType ( cand . pdgId ( ) ) ) ; continue ; } sumNPU = 1.0 ; sumPU = 1.0 ; double eta = cand . eta ( ) ; double phi = cand . phi ( ) ; for ( const reco :: Candidate & chCand : pfCharged ) { double sum = ( chCand . pt ( ) * chCand . pt ( ) ) / ( deltaR2 ( eta , phi , chCand . eta ( ) , chCand . phi ( ) ) ) ; if ( sum > 1.0 ) sumNPU *= sum ; } sumNPU = 0.5 * log ( sumNPU ) ; for ( const reco :: Candidate & puCand : pfPU ) { double sum = ( puCand . pt ( ) * puCand . pt ( ) ) / ( deltaR2 ( eta , phi , puCand . eta ( ) , puCand . phi ( ) ) ) ; if ( sum > 1.0 ) sumPU *= sum ; } sumPU = 0.5 * log ( sumPU ) ; reco :: PFCandidate neutral = reco :: PFCandidate ( cand . charge ( ) , cand . p4 ( ) , reco :: PFCandidate :: ParticleType :: X ) ; neutral . setParticleType ( neutral . translatePdgIdToType ( cand . pdgId ( ) ) ) ; if ( sumNPU + sumPU > 0 ) neutral . setP4 ( ( ( sumNPU ) / ( sumNPU + sumPU ) ) * neutral . p4 ( ) ) ; out -> push_back ( neutral ) ; } iEvent . put ( std :: move ( out ) ) ; }
method called to produce the data
method called to produce the data
// this part of code should be executed only if input collection is not entirely composed of neutral candidates, i.e. never by default