CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ParticleBasedIsoProducer.cc
Go to the documentation of this file.
7 
8 
9 
11 
12  photonTmpProducer_ = conf_.getParameter<edm::InputTag>("photonTmpProducer");
13  photonProducer_ = conf_.getParameter<edm::InputTag>("photonProducer");
14  electronProducer_ = conf_.getParameter<edm::InputTag>("electronProducer");
15  electronTmpProducer_ = conf_.getParameter<edm::InputTag>("electronTmpProducer");
16 
18  consumes<reco::PhotonCollection>(photonProducer_);
19 
20 
22  consumes<reco::PhotonCollection>(photonTmpProducer_);
23 
24 
26  consumes<reco::GsfElectronCollection>(electronProducer_);
27 
29  consumes<reco::GsfElectronCollection>(electronTmpProducer_);
30 
31  pfCandidates_ =
32  consumes<reco::PFCandidateCollection>(conf_.getParameter<edm::InputTag>("pfCandidates"));
33 
35  consumes<reco::PFCandidateCollection>(conf_.getParameter<edm::InputTag>("pfEgammaCandidates"));
36 
37  valueMapPFCandPhoton_ = conf_.getParameter<std::string>("valueMapPhoToEG");
38  valueMapPFCandEle_ = conf_.getParameter<std::string>("valueMapEleToEG");
39 
41  consumes<edm::ValueMap<reco::PhotonRef> >(edm::InputTag("gedPhotonsTmp",valueMapPFCandPhoton_));
42 
44  consumes<edm::ValueMap<reco::GsfElectronRef> >(edm::InputTag("gedGsfElectronsTmp",valueMapPFCandEle_));
45 
46  valueMapPhoPFCandIso_ = conf_.getParameter<std::string>("valueMapPhoPFblockIso");
47  valueMapElePFCandIso_ = conf_.getParameter<std::string>("valueMapElePFblockIso");
48 
49 
50  produces< edm::ValueMap<std::vector<reco::PFCandidateRef> > > (valueMapPhoPFCandIso_);
51  produces< edm::ValueMap<std::vector<reco::PFCandidateRef> > > (valueMapElePFCandIso_);
52 
53 }
54 
56 
57 
58 }
59 
60 
62 
64  edm::ParameterSet pfBlockBasedIsolationSetUp = conf_.getParameter<edm::ParameterSet>("pfBlockBasedIsolationSetUp");
65  thePFBlockBasedIsolation_ ->setup(pfBlockBasedIsolationSetUp);
66 
67 }
68 
70 
72 
73 }
74 
75 
76 
78 
80  theEvent.getByToken(photonProducerT_,photonHandle);
81 
83  theEvent.getByToken(photonTmpProducerT_,photonTmpHandle);
84 
86  theEvent.getByToken(electronTmpProducerT_,electronTmpHandle);
87 
89  theEvent.getByToken(electronProducerT_,electronHandle);
90 
91  edm::Handle<reco::PFCandidateCollection> pfEGCandidateHandle;
92  // Get the PF refined cluster collection
93  theEvent.getByToken(pfEgammaCandidates_,pfEGCandidateHandle);
94 
96  // Get the PF candidates collection
97  theEvent.getByToken(pfCandidates_,pfCandidateHandle);
98 
99  edm::ValueMap<reco::PhotonRef> pfEGCandToPhotonMap;
100  edm::Handle<edm::ValueMap<reco::PhotonRef> > pfEGCandToPhotonMapHandle;
101  theEvent.getByToken(valMapPFCandToPhoton_,pfEGCandToPhotonMapHandle);
102  pfEGCandToPhotonMap = *(pfEGCandToPhotonMapHandle.product());
103 
104  edm::ValueMap<reco::GsfElectronRef> pfEGCandToElectronMap;
105  edm::Handle<edm::ValueMap<reco::GsfElectronRef> > pfEGCandToElectronMapHandle;
106  theEvent.getByToken(valMapPFCandToEle_,pfEGCandToElectronMapHandle);
107  pfEGCandToElectronMap = *(pfEGCandToElectronMapHandle.product());
108 
109  std::vector<std::vector<reco::PFCandidateRef>> pfCandIsoPairVecPho;
110 
112  // std::cout << " ParticleBasedIsoProducer photonHandle size " << photonHandle->size() << std::endl;
113  for(unsigned int lSC=0; lSC < photonTmpHandle->size(); lSC++) {
114 
115  reco::PhotonRef phoRef(reco::PhotonRef(photonTmpHandle, lSC));
116 
117  // loop over the unbiased candidates to retrieve the ref to the unbiased candidate corresponding to this photon
118  unsigned nObj = pfEGCandidateHandle->size();
119  reco::PFCandidateRef pfEGCandRef;
120 
121  std::vector<reco::PFCandidateRef> pfCandIsoPairPho;
122  for(unsigned int lCand=0; lCand < nObj; lCand++) {
123  pfEGCandRef=reco::PFCandidateRef(pfEGCandidateHandle,lCand);
124  reco::PhotonRef myPho= (pfEGCandToPhotonMap)[pfEGCandRef];
125 
126  if ( myPho.isNonnull() ) {
127  //std::cout << "ParticleBasedIsoProducer photons PF SC " << pfEGCandRef->superClusterRef()->energy() << " Photon SC " << myPho->superCluster()->energy() << std::endl;
128  if (myPho != phoRef) continue;
129  // std::cout << " ParticleBasedIsoProducer photons This is my egammaunbiased guy energy " << pfEGCandRef->superClusterRef()->energy() << std::endl;
130  pfCandIsoPairPho=thePFBlockBasedIsolation_->calculate (myPho->p4(), pfEGCandRef, pfCandidateHandle);
131 
133  // for ( std::vector<reco::PFCandidateRef>::const_iterator iPair=pfCandIsoPairPho.begin(); iPair<pfCandIsoPairPho.end(); iPair++) {
134  // float dR= deltaR(myPho->eta(), myPho->phi(), (*iPair)->eta(), (*iPair)->phi() );
135  // std::cout << " ParticleBasedIsoProducer photons checking the pfCand bool pair " << (*iPair)->particleId() << " dR " << dR << " pt " << (*iPair)->pt() << std::endl;
136  // }
137 
138 
139  }
140 
141  }
142 
143  pfCandIsoPairVecPho.push_back(pfCandIsoPairPho);
144  }
145 
146 
147 
149  std::vector<std::vector<reco::PFCandidateRef>> pfCandIsoPairVecEle;
150  // std::cout << " ParticleBasedIsoProducer electronHandle size " << electronHandle->size() << std::endl;
151  for(unsigned int lSC=0; lSC < electronTmpHandle->size(); lSC++) {
152  reco::GsfElectronRef eleRef(reco::GsfElectronRef(electronTmpHandle, lSC));
153 
154  // loop over the unbiased candidates to retrieve the ref to the unbiased candidate corresponding to this electron
155  unsigned nObj = pfEGCandidateHandle->size();
156  reco::PFCandidateRef pfEGCandRef;
157 
158  std::vector<reco::PFCandidateRef> pfCandIsoPairEle;
159  for(unsigned int lCand=0; lCand < nObj; lCand++) {
160  pfEGCandRef=reco::PFCandidateRef(pfEGCandidateHandle,lCand);
161  reco::GsfElectronRef myEle= (pfEGCandToElectronMap)[pfEGCandRef];
162 
163  if ( myEle.isNonnull() ) {
164  // std::cout << "ParticleBasedIsoProducer Electorns PF SC " << pfEGCandRef->superClusterRef()->energy() << " Electron SC " << myEle->superCluster()->energy() << std::endl;
165  if (myEle != eleRef) continue;
166 
167  //math::XYZVector candidateMomentum(myEle->p4().px(),myEle->p4().py(),myEle->p4().pz());
168  //math::XYZVector myDir=candidateMomentum.Unit();
169  // std::cout << " ParticleBasedIsoProducer Electrons This is my egammaunbiased guy energy " << pfEGCandRef->superClusterRef()->energy() << std::endl;
170  // std::cout << " Ele direction " << myDir << " eta " << myEle->eta() << " phi " << myEle->phi() << std::endl;
171  pfCandIsoPairEle=thePFBlockBasedIsolation_->calculate (myEle->p4(), pfEGCandRef, pfCandidateHandle);
173  //for ( std::vector<reco::PFCandidateRef>::const_iterator iPair=pfCandIsoPairEle.begin(); iPair<pfCandIsoPairEle.end(); iPair++) {
174  // float dR= deltaR(myEle->eta(), myEle->phi(), (*iPair)->eta(), (*iPair)->phi() );
175  // std::cout << " ParticleBasedIsoProducer Electron checking the pfCand bool pair " << (*iPair)->particleId() << " dR " << dR << " pt " << (*iPair)->pt() << " eta " << (*iPair)->eta() << " phi " << (*iPair)->phi() << std::endl;
176  // }
177 
178 
179  }
180 
181  }
182 
183  pfCandIsoPairVecEle.push_back(pfCandIsoPairEle);
184 }
185 
186 
187 
188 
189 
190  std::auto_ptr<edm::ValueMap<std::vector<reco::PFCandidateRef>> >
191  phoToPFCandIsoMap_p(new edm::ValueMap<std::vector<reco::PFCandidateRef>>());
193  fillerPhotons(*phoToPFCandIsoMap_p);
194 
196  fillerPhotons.insert(photonHandle,pfCandIsoPairVecPho.begin(),pfCandIsoPairVecPho.end());
197  fillerPhotons.fill();
198  theEvent.put(phoToPFCandIsoMap_p,valueMapPhoPFCandIso_);
199 
200 
201  std::auto_ptr<edm::ValueMap<std::vector<reco::PFCandidateRef>> >
202  eleToPFCandIsoMap_p(new edm::ValueMap<std::vector<reco::PFCandidateRef>>());
204  fillerElectrons(*eleToPFCandIsoMap_p);
205 
207  fillerElectrons.insert(electronHandle,pfCandIsoPairVecEle.begin(),pfCandIsoPairVecEle.end());
208  fillerElectrons.fill();
209  theEvent.put(eleToPFCandIsoMap_p,valueMapElePFCandIso_);
210 
211 
212 
213 
214 
215 
216 
217 
218 
219 
220 }
edm::EDGetTokenT< reco::GsfElectronCollection > electronTmpProducerT_
T getParameter(std::string const &) const
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
PFBlockBasedIsolation * thePFBlockBasedIsolation_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
virtual void produce(edm::Event &e, const edm::EventSetup &c)
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_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
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
virtual void endRun(edm::Run const &, edm::EventSetup const &) override
virtual void beginRun(edm::Run const &r, edm::EventSetup const &es) override
tuple conf
Definition: dbtoconf.py:185
T const * product() const
Definition: Handle.h:81
ParticleBasedIsoProducer(const edm::ParameterSet &conf)
edm::EDGetTokenT< reco::PFCandidateCollection > pfEgammaCandidates_
Definition: Run.h:41
edm::EDGetTokenT< edm::ValueMap< reco::PhotonRef > > valMapPFCandToPhoton_