CMS 3D CMS Logo

ParticleBasedIsoProducer.cc
Go to the documentation of this file.
7 
9  photonTmpProducer_ = conf_.getParameter<edm::InputTag>("photonTmpProducer");
10  photonProducer_ = conf_.getParameter<edm::InputTag>("photonProducer");
11  electronProducer_ = conf_.getParameter<edm::InputTag>("electronProducer");
12  electronTmpProducer_ = conf_.getParameter<edm::InputTag>("electronTmpProducer");
13 
14  photonProducerT_ = consumes<reco::PhotonCollection>(photonProducer_);
15 
16  photonTmpProducerT_ = consumes<reco::PhotonCollection>(photonTmpProducer_);
17 
18  electronProducerT_ = consumes<reco::GsfElectronCollection>(electronProducer_);
19 
20  electronTmpProducerT_ = consumes<reco::GsfElectronCollection>(electronTmpProducer_);
21 
22  pfCandidates_ = consumes<reco::PFCandidateCollection>(conf_.getParameter<edm::InputTag>("pfCandidates"));
23 
24  pfEgammaCandidates_ = consumes<reco::PFCandidateCollection>(conf_.getParameter<edm::InputTag>("pfEgammaCandidates"));
25 
27  valueMapPFCandEle_ = conf_.getParameter<std::string>("valueMapEleToEG");
28 
29  valMapPFCandToPhoton_ = consumes<edm::ValueMap<reco::PhotonRef>>({"gedPhotonsTmp", valueMapPFCandPhoton_});
30 
32  consumes<edm::ValueMap<reco::GsfElectronRef>>({"gedGsfElectronValueMapsTmp", valueMapPFCandEle_});
33 
34  valueMapPhoPFCandIso_ = conf_.getParameter<std::string>("valueMapPhoPFblockIso");
35  valueMapElePFCandIso_ = conf_.getParameter<std::string>("valueMapElePFblockIso");
36 
37  produces<edm::ValueMap<std::vector<reco::PFCandidateRef>>>(valueMapPhoPFCandIso_);
38  produces<edm::ValueMap<std::vector<reco::PFCandidateRef>>>(valueMapElePFCandIso_);
39 }
40 
42 
47 }
48 
51 }
52 
55  theEvent.getByToken(photonProducerT_, photonHandle);
56 
58  theEvent.getByToken(photonTmpProducerT_, photonTmpHandle);
59 
61  theEvent.getByToken(electronTmpProducerT_, electronTmpHandle);
62 
64  theEvent.getByToken(electronProducerT_, electronHandle);
65 
66  edm::Handle<reco::PFCandidateCollection> pfEGCandidateHandle;
67  // Get the PF refined cluster collection
68  theEvent.getByToken(pfEgammaCandidates_, pfEGCandidateHandle);
69 
71  // Get the PF candidates collection
72  theEvent.getByToken(pfCandidates_, pfCandidateHandle);
73 
74  edm::ValueMap<reco::PhotonRef> pfEGCandToPhotonMap;
75  edm::Handle<edm::ValueMap<reco::PhotonRef>> pfEGCandToPhotonMapHandle;
76  theEvent.getByToken(valMapPFCandToPhoton_, pfEGCandToPhotonMapHandle);
77  pfEGCandToPhotonMap = *(pfEGCandToPhotonMapHandle.product());
78 
79  edm::ValueMap<reco::GsfElectronRef> pfEGCandToElectronMap;
80  edm::Handle<edm::ValueMap<reco::GsfElectronRef>> pfEGCandToElectronMapHandle;
81  theEvent.getByToken(valMapPFCandToEle_, pfEGCandToElectronMapHandle);
82  pfEGCandToElectronMap = *(pfEGCandToElectronMapHandle.product());
83 
84  std::vector<std::vector<reco::PFCandidateRef>> pfCandIsoPairVecPho;
85 
87  // std::cout << " ParticleBasedIsoProducer photonHandle size " << photonHandle->size() << std::endl;
88  for (unsigned int lSC = 0; lSC < photonTmpHandle->size(); lSC++) {
89  reco::PhotonRef phoRef(reco::PhotonRef(photonTmpHandle, lSC));
90 
91  // loop over the unbiased candidates to retrieve the ref to the unbiased candidate corresponding to this photon
92  unsigned nObj = pfEGCandidateHandle->size();
93  reco::PFCandidateRef pfEGCandRef;
94 
95  std::vector<reco::PFCandidateRef> pfCandIsoPairPho;
96  for (unsigned int lCand = 0; lCand < nObj; lCand++) {
97  pfEGCandRef = reco::PFCandidateRef(pfEGCandidateHandle, lCand);
98  reco::PhotonRef myPho = (pfEGCandToPhotonMap)[pfEGCandRef];
99 
100  if (myPho.isNonnull()) {
101  //std::cout << "ParticleBasedIsoProducer photons PF SC " << pfEGCandRef->superClusterRef()->energy() << " Photon SC " << myPho->superCluster()->energy() << std::endl;
102  if (myPho != phoRef)
103  continue;
104  // std::cout << " ParticleBasedIsoProducer photons This is my egammaunbiased guy energy " << pfEGCandRef->superClusterRef()->energy() << std::endl;
105  pfCandIsoPairPho = thePFBlockBasedIsolation_->calculate(myPho->p4(), pfEGCandRef, pfCandidateHandle);
106 
108  // for ( std::vector<reco::PFCandidateRef>::const_iterator iPair=pfCandIsoPairPho.begin(); iPair<pfCandIsoPairPho.end(); iPair++) {
109  // float dR= deltaR(myPho->eta(), myPho->phi(), (*iPair)->eta(), (*iPair)->phi() );
110  // std::cout << " ParticleBasedIsoProducer photons checking the pfCand bool pair " << (*iPair)->particleId() << " dR " << dR << " pt " << (*iPair)->pt() << std::endl;
111  // }
112  }
113  }
114 
115  pfCandIsoPairVecPho.push_back(pfCandIsoPairPho);
116  }
117 
119  std::vector<std::vector<reco::PFCandidateRef>> pfCandIsoPairVecEle;
120  // std::cout << " ParticleBasedIsoProducer electronHandle size " << electronHandle->size() << std::endl;
121  for (unsigned int lSC = 0; lSC < electronTmpHandle->size(); lSC++) {
122  reco::GsfElectronRef eleRef(reco::GsfElectronRef(electronTmpHandle, lSC));
123 
124  // loop over the unbiased candidates to retrieve the ref to the unbiased candidate corresponding to this electron
125  unsigned nObj = pfEGCandidateHandle->size();
126  reco::PFCandidateRef pfEGCandRef;
127 
128  std::vector<reco::PFCandidateRef> pfCandIsoPairEle;
129  for (unsigned int lCand = 0; lCand < nObj; lCand++) {
130  pfEGCandRef = reco::PFCandidateRef(pfEGCandidateHandle, lCand);
131  reco::GsfElectronRef myEle = (pfEGCandToElectronMap)[pfEGCandRef];
132 
133  if (myEle.isNonnull()) {
134  // std::cout << "ParticleBasedIsoProducer Electorns PF SC " << pfEGCandRef->superClusterRef()->energy() << " Electron SC " << myEle->superCluster()->energy() << std::endl;
135  if (myEle != eleRef)
136  continue;
137 
138  //math::XYZVector candidateMomentum(myEle->p4().px(),myEle->p4().py(),myEle->p4().pz());
139  //math::XYZVector myDir=candidateMomentum.Unit();
140  // std::cout << " ParticleBasedIsoProducer Electrons This is my egammaunbiased guy energy " << pfEGCandRef->superClusterRef()->energy() << std::endl;
141  // std::cout << " Ele direction " << myDir << " eta " << myEle->eta() << " phi " << myEle->phi() << std::endl;
142  pfCandIsoPairEle = thePFBlockBasedIsolation_->calculate(myEle->p4(), pfEGCandRef, pfCandidateHandle);
144  //for ( std::vector<reco::PFCandidateRef>::const_iterator iPair=pfCandIsoPairEle.begin(); iPair<pfCandIsoPairEle.end(); iPair++) {
145  // float dR= deltaR(myEle->eta(), myEle->phi(), (*iPair)->eta(), (*iPair)->phi() );
146  // std::cout << " ParticleBasedIsoProducer Electron checking the pfCand bool pair " << (*iPair)->particleId() << " dR " << dR << " pt " << (*iPair)->pt() << " eta " << (*iPair)->eta() << " phi " << (*iPair)->phi() << std::endl;
147  // }
148  }
149  }
150 
151  pfCandIsoPairVecEle.push_back(pfCandIsoPairEle);
152  }
153 
154  auto phoToPFCandIsoMap_p = std::make_unique<edm::ValueMap<std::vector<reco::PFCandidateRef>>>();
155  edm::ValueMap<std::vector<reco::PFCandidateRef>>::Filler fillerPhotons(*phoToPFCandIsoMap_p);
156 
158  fillerPhotons.insert(photonHandle, pfCandIsoPairVecPho.begin(), pfCandIsoPairVecPho.end());
159  fillerPhotons.fill();
160  theEvent.put(std::move(phoToPFCandIsoMap_p), valueMapPhoPFCandIso_);
161 
162  auto eleToPFCandIsoMap_p = std::make_unique<edm::ValueMap<std::vector<reco::PFCandidateRef>>>();
163  edm::ValueMap<std::vector<reco::PFCandidateRef>>::Filler fillerElectrons(*eleToPFCandIsoMap_p);
164 
166  fillerElectrons.insert(electronHandle, pfCandIsoPairVecEle.begin(), pfCandIsoPairVecEle.end());
167  fillerElectrons.fill();
168  theEvent.put(std::move(eleToPFCandIsoMap_p), valueMapElePFCandIso_);
169 }
ParticleBasedIsoProducer::beginRun
void beginRun(edm::Run const &r, edm::EventSetup const &es) override
Definition: ParticleBasedIsoProducer.cc:43
ParticleBasedIsoProducer::valueMapElePFCandIso_
std::string valueMapElePFCandIso_
Definition: ParticleBasedIsoProducer.h:49
ParticleBasedIsoProducer::pfEgammaCandidates_
edm::EDGetTokenT< reco::PFCandidateCollection > pfEgammaCandidates_
Definition: ParticleBasedIsoProducer.h:41
ParticleBasedIsoProducer::valueMapPhoPFCandIso_
std::string valueMapPhoPFCandIso_
Definition: ParticleBasedIsoProducer.h:47
ParticleBasedIsoProducer::photonTmpProducer_
edm::InputTag photonTmpProducer_
Definition: ParticleBasedIsoProducer.h:32
ParticleBasedIsoProducer::photonProducerT_
edm::EDGetTokenT< reco::PhotonCollection > photonProducerT_
Definition: ParticleBasedIsoProducer.h:37
edm::Handle::product
T const * product() const
Definition: Handle.h:70
PFCandidate.h
ParticleBasedIsoProducer::thePFBlockBasedIsolation_
PFBlockBasedIsolation * thePFBlockBasedIsolation_
Definition: ParticleBasedIsoProducer.h:51
edm::Run
Definition: Run.h:45
PFBlockBasedIsolation::calculate
std::vector< reco::PFCandidateRef > calculate(math::XYZTLorentzVectorD p4, const reco::PFCandidateRef pfEGCand, const edm::Handle< reco::PFCandidateCollection > pfCandidateHandle)
Definition: PFBlockBasedIsolation.cc:21
ParticleBasedIsoProducer::photonProducer_
edm::InputTag photonProducer_
Definition: ParticleBasedIsoProducer.h:31
edm::Handle< reco::PhotonCollection >
PFBlockBasedIsolation::setup
void setup(const edm::ParameterSet &conf)
Definition: PFBlockBasedIsolation.cc:19
edm::Ref< PhotonCollection >
Photon.h
ParticleBasedIsoProducer::produce
void produce(edm::Event &e, const edm::EventSetup &c) override
Definition: ParticleBasedIsoProducer.cc:53
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:531
ParticleBasedIsoProducer::photonTmpProducerT_
edm::EDGetTokenT< reco::PhotonCollection > photonTmpProducerT_
Definition: ParticleBasedIsoProducer.h:38
ParticleBasedIsoProducer::conf_
edm::ParameterSet conf_
Definition: ParticleBasedIsoProducer.h:27
GsfElectron.h
ParticleBasedIsoProducer.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
particleBasedIsoProducer_cfi.pfBlockBasedIsolationSetUp
pfBlockBasedIsolationSetUp
Definition: particleBasedIsoProducer_cfi.py:18
ParticleBasedIsoProducer::~ParticleBasedIsoProducer
~ParticleBasedIsoProducer() override
Definition: ParticleBasedIsoProducer.cc:41
edm::ParameterSet
Definition: ParameterSet.h:47
ParticleBasedIsoProducer::valMapPFCandToPhoton_
edm::EDGetTokenT< edm::ValueMap< reco::PhotonRef > > valMapPFCandToPhoton_
Definition: ParticleBasedIsoProducer.h:43
deltaR.h
ParticleBasedIsoProducer::electronTmpProducerT_
edm::EDGetTokenT< reco::GsfElectronCollection > electronTmpProducerT_
Definition: ParticleBasedIsoProducer.h:40
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
reco::PFCandidateRef
edm::Ref< PFCandidateCollection > PFCandidateRef
persistent reference to a PFCandidate
Definition: PFCandidateFwd.h:24
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::EventSetup
Definition: EventSetup.h:57
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
ParticleBasedIsoProducer::electronProducer_
edm::InputTag electronProducer_
Definition: ParticleBasedIsoProducer.h:34
ValueMap.h
ParticleBasedIsoProducer::ParticleBasedIsoProducer
ParticleBasedIsoProducer(const edm::ParameterSet &conf)
Definition: ParticleBasedIsoProducer.cc:8
ParticleBasedIsoProducer::valMapPFCandToEle_
edm::EDGetTokenT< edm::ValueMap< reco::GsfElectronRef > > valMapPFCandToEle_
Definition: ParticleBasedIsoProducer.h:44
eostools.move
def move(src, dest)
Definition: eostools.py:511
writedatasetfile.run
run
Definition: writedatasetfile.py:27
edm::ValueMap
Definition: ValueMap.h:107
ParticleBasedIsoProducer::endRun
void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: ParticleBasedIsoProducer.cc:49
ParticleBasedIsoProducer::valueMapPFCandPhoton_
std::string valueMapPFCandPhoton_
Definition: ParticleBasedIsoProducer.h:46
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ParticleBasedIsoProducer::pfCandidates_
edm::EDGetTokenT< reco::PFCandidateCollection > pfCandidates_
Definition: ParticleBasedIsoProducer.h:42
ParticleBasedIsoProducer::electronProducerT_
edm::EDGetTokenT< reco::GsfElectronCollection > electronProducerT_
Definition: ParticleBasedIsoProducer.h:39
PFBlockBasedIsolation
Definition: PFBlockBasedIsolation.h:19
edm::Event
Definition: Event.h:73
ParticleBasedIsoProducer::valueMapPFCandEle_
std::string valueMapPFCandEle_
Definition: ParticleBasedIsoProducer.h:48
edm::InputTag
Definition: InputTag.h:15
ParticleBasedIsoProducer::electronTmpProducer_
edm::InputTag electronTmpProducer_
Definition: ParticleBasedIsoProducer.h:35