CMS 3D CMS Logo

DeltaBetaWeights.cc
Go to the documentation of this file.
2 
4  : src_(iConfig.getParameter<edm::InputTag>("src")),
5  pfCharged_(iConfig.getParameter<edm::InputTag>("chargedFromPV")),
6  pfPU_(iConfig.getParameter<edm::InputTag>("chargedFromPU")) {
7  produces<reco::PFCandidateCollection>();
8 
9  pfCharged_token = consumes<edm::View<reco::Candidate> >(pfCharged_);
10  pfPU_token = consumes<edm::View<reco::Candidate> >(pfPU_);
11  src_token = consumes<edm::View<reco::Candidate> >(src_);
12 
13  // pfCharged_token = consumes<reco::PFCandidateCollection>(pfCharged_);
14  // pfPU_token = consumes<reco::PFCandidateCollection>(pfPU_);
15  // src_token = consumes<reco::PFCandidateCollection>(src_);
16 }
17 
19  // do anything here that needs to be done at desctruction time
20  // (e.g. close files, deallocate resources etc.)
21 }
22 
23 //
24 // member functions
25 //
26 
27 // ------------ method called to produce the data ------------
29  using namespace edm;
30 
34 
35  iEvent.getByToken(src_token, src);
36  iEvent.getByToken(pfCharged_token, pfCharged);
37  iEvent.getByToken(pfPU_token, pfPU);
38 
39  double sumNPU = .0;
40  double sumPU = .0;
41 
42  std::unique_ptr<reco::PFCandidateCollection> out(new reco::PFCandidateCollection);
43 
44  for (const reco::Candidate& cand : *src) {
45  if (cand.charge() != 0) {
46  // this part of code should be executed only if input collection is not entirely composed of neutral candidates, i.e. never by default
47  edm::LogWarning("DeltaBetaWeights")
48  << "Trying to reweight charged particle... saving it to output collection without any change";
49  out->emplace_back(cand.charge(), cand.p4(), reco::PFCandidate::ParticleType::X);
50  (out->back()).setParticleType((out->back()).translatePdgIdToType(cand.pdgId()));
51  continue;
52  }
53 
54  sumNPU = 1.0;
55  sumPU = 1.0;
56  double eta = cand.eta();
57  double phi = cand.phi();
58  for (const reco::Candidate& chCand : *pfCharged) {
59  double sum = (chCand.pt() * chCand.pt()) / (deltaR2(eta, phi, chCand.eta(), chCand.phi()));
60  if (sum > 1.0)
61  sumNPU *= sum;
62  }
63  sumNPU = 0.5 * log(sumNPU);
64 
65  for (const reco::Candidate& puCand : *pfPU) {
66  double sum = (puCand.pt() * puCand.pt()) / (deltaR2(eta, phi, puCand.eta(), puCand.phi()));
67  if (sum > 1.0)
68  sumPU *= sum;
69  }
70  sumPU = 0.5 * log(sumPU);
71 
73  neutral.setParticleType(neutral.translatePdgIdToType(cand.pdgId()));
74  if (sumNPU + sumPU > 0)
75  neutral.setP4(((sumNPU) / (sumNPU + sumPU)) * neutral.p4());
76  out->push_back(neutral);
77  }
78 
79  iEvent.put(std::move(out));
80 }
X
#define X(str)
Definition: MuonsGrabber.cc:38
DeltaBetaWeights::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: DeltaBetaWeights.cc:28
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
DeltaBetaWeights::~DeltaBetaWeights
~DeltaBetaWeights() override
Definition: DeltaBetaWeights.cc:18
DeltaBetaWeights::pfPU_token
edm::EDGetTokenT< edm::View< reco::Candidate > > pfPU_token
Definition: DeltaBetaWeights.h:39
edm::Handle
Definition: AssociativeIterator.h:50
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
DeltaBetaWeights::pfCharged_token
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCharged_token
Definition: DeltaBetaWeights.h:38
pfElectronTranslator_cfi.PFCandidate
PFCandidate
Definition: pfElectronTranslator_cfi.py:6
PVValHelper::eta
Definition: PVValidationHelpers.h:69
DeltaBetaWeights::pfCharged_
edm::InputTag pfCharged_
Definition: DeltaBetaWeights.h:35
DeltaBetaWeights::pfPU_
edm::InputTag pfPU_
Definition: DeltaBetaWeights.h:36
edm::ParameterSet
Definition: ParameterSet.h:47
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
cand
Definition: decayParser.h:32
iEvent
int iEvent
Definition: GenABIO.cc:224
reco::LeafCandidate::p4
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:114
edm::EventSetup
Definition: EventSetup.h:57
reco::Candidate
Definition: Candidate.h:27
DDAxes::phi
DeltaBetaWeights::DeltaBetaWeights
DeltaBetaWeights(const edm::ParameterSet &)
Definition: DeltaBetaWeights.cc:3
reco::LeafCandidate::setP4
void setP4(const LorentzVector &p4) final
set 4-momentum
Definition: LeafCandidate.h:158
eostools.move
def move(src, dest)
Definition: eostools.py:511
HLTMuonOfflineAnalyzer_cfi.deltaR2
deltaR2
Definition: HLTMuonOfflineAnalyzer_cfi.py:105
reco::PFCandidateCollection
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
Definition: PFCandidateFwd.h:12
DeltaBetaWeights::src_
edm::InputTag src_
Definition: DeltaBetaWeights.h:34
reco::PFCandidate::translatePdgIdToType
ParticleType translatePdgIdToType(int pdgid) const
Definition: PFCandidate.cc:209
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
edm::Event
Definition: Event.h:73
DeltaBetaWeights::src_token
edm::EDGetTokenT< edm::View< reco::Candidate > > src_token
Definition: DeltaBetaWeights.h:40
DeltaBetaWeights.h
reco::PFCandidate::setParticleType
void setParticleType(ParticleType type)
set Particle Type
Definition: PFCandidate.cc:256