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