CMS 3D CMS Logo

ParticleBasedIsoProducer.cc
Go to the documentation of this file.
15 
17 public:
19 
20  void beginRun(edm::Run const& r, edm::EventSetup const& es) override;
21  void produce(edm::Event& e, const edm::EventSetup& c) override;
22 
23  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
24 
25 private:
29 
32 
35 
44 
49 
50  std::unique_ptr<PFBlockBasedIsolation> thePFBlockBasedIsolation_;
51 };
52 
55 
57  photonTmpProducer_ = conf_.getParameter<edm::InputTag>("photonTmpProducer");
58  photonProducer_ = conf_.getParameter<edm::InputTag>("photonProducer");
59  electronProducer_ = conf_.getParameter<edm::InputTag>("electronProducer");
60  electronTmpProducer_ = conf_.getParameter<edm::InputTag>("electronTmpProducer");
61 
62  photonProducerT_ = consumes<reco::PhotonCollection>(photonProducer_);
63 
64  photonTmpProducerT_ = consumes<reco::PhotonCollection>(photonTmpProducer_);
65 
66  electronProducerT_ = consumes<reco::GsfElectronCollection>(electronProducer_);
67 
68  electronTmpProducerT_ = consumes<reco::GsfElectronCollection>(electronTmpProducer_);
69 
70  pfCandidates_ = consumes<reco::PFCandidateCollection>(conf_.getParameter<edm::InputTag>("pfCandidates"));
71 
72  pfEgammaCandidates_ = consumes<reco::PFCandidateCollection>(conf_.getParameter<edm::InputTag>("pfEgammaCandidates"));
73 
75  valueMapPFCandEle_ = conf_.getParameter<std::string>("valueMapEleToEG");
76 
77  valMapPFCandToPhoton_ = consumes<edm::ValueMap<reco::PhotonRef>>({"gedPhotonsTmp", valueMapPFCandPhoton_});
78 
80  consumes<edm::ValueMap<reco::GsfElectronRef>>({"gedGsfElectronValueMapsTmp", valueMapPFCandEle_});
81 
82  valueMapPhoPFCandIso_ = conf_.getParameter<std::string>("valueMapPhoPFblockIso");
83  valueMapElePFCandIso_ = conf_.getParameter<std::string>("valueMapElePFblockIso");
84 
85  produces<edm::ValueMap<std::vector<reco::PFCandidateRef>>>(valueMapPhoPFCandIso_);
86  produces<edm::ValueMap<std::vector<reco::PFCandidateRef>>>(valueMapElePFCandIso_);
87 }
88 
90  thePFBlockBasedIsolation_ = std::make_unique<PFBlockBasedIsolation>();
91  edm::ParameterSet pfBlockBasedIsolationSetUp = conf_.getParameter<edm::ParameterSet>("pfBlockBasedIsolationSetUp");
92  thePFBlockBasedIsolation_->setup(pfBlockBasedIsolationSetUp);
93 }
94 
96  auto photonHandle = theEvent.getHandle(photonProducerT_);
97  auto photonTmpHandle = theEvent.getHandle(photonTmpProducerT_);
98  auto electronTmpHandle = theEvent.getHandle(electronTmpProducerT_);
99  auto electronHandle = theEvent.getHandle(electronProducerT_);
100  auto pfEGCandidateHandle = theEvent.getHandle(pfEgammaCandidates_);
101  auto pfCandidateHandle = theEvent.getHandle(pfCandidates_);
102  auto const& pfEGCandToPhotonMap = theEvent.get(valMapPFCandToPhoton_);
103  auto const& pfEGCandToElectronMap = theEvent.get(valMapPFCandToEle_);
104 
105  std::vector<std::vector<reco::PFCandidateRef>> pfCandIsoPairVecPho;
106 
108  // std::cout << " ParticleBasedIsoProducer photonHandle size " << photonHandle->size() << std::endl;
109  for (unsigned int lSC = 0; lSC < photonTmpHandle->size(); lSC++) {
110  reco::PhotonRef phoRef(reco::PhotonRef(photonTmpHandle, lSC));
111 
112  // loop over the unbiased candidates to retrieve the ref to the unbiased candidate corresponding to this photon
113  unsigned nObj = pfEGCandidateHandle->size();
114  reco::PFCandidateRef pfEGCandRef;
115 
116  std::vector<reco::PFCandidateRef> pfCandIsoPairPho;
117  for (unsigned int lCand = 0; lCand < nObj; lCand++) {
118  pfEGCandRef = reco::PFCandidateRef(pfEGCandidateHandle, lCand);
119  const reco::PhotonRef& myPho = (pfEGCandToPhotonMap)[pfEGCandRef];
120 
121  if (myPho.isNonnull()) {
122  //std::cout << "ParticleBasedIsoProducer photons PF SC " << pfEGCandRef->superClusterRef()->energy() << " Photon SC " << myPho->superCluster()->energy() << std::endl;
123  if (myPho != phoRef)
124  continue;
125  // std::cout << " ParticleBasedIsoProducer photons This is my egammaunbiased guy energy " << pfEGCandRef->superClusterRef()->energy() << std::endl;
126  pfCandIsoPairPho = thePFBlockBasedIsolation_->calculate(myPho->p4(), pfEGCandRef, pfCandidateHandle);
127 
129  // for ( std::vector<reco::PFCandidateRef>::const_iterator iPair=pfCandIsoPairPho.begin(); iPair<pfCandIsoPairPho.end(); iPair++) {
130  // float dR= deltaR(myPho->eta(), myPho->phi(), (*iPair)->eta(), (*iPair)->phi() );
131  // std::cout << " ParticleBasedIsoProducer photons checking the pfCand bool pair " << (*iPair)->particleId() << " dR " << dR << " pt " << (*iPair)->pt() << std::endl;
132  // }
133  }
134  }
135 
136  pfCandIsoPairVecPho.push_back(pfCandIsoPairPho);
137  }
138 
140  std::vector<std::vector<reco::PFCandidateRef>> pfCandIsoPairVecEle;
141  // std::cout << " ParticleBasedIsoProducer electronHandle size " << electronHandle->size() << std::endl;
142  for (unsigned int lSC = 0; lSC < electronTmpHandle->size(); lSC++) {
143  reco::GsfElectronRef eleRef(reco::GsfElectronRef(electronTmpHandle, lSC));
144 
145  // loop over the unbiased candidates to retrieve the ref to the unbiased candidate corresponding to this electron
146  unsigned nObj = pfEGCandidateHandle->size();
147  reco::PFCandidateRef pfEGCandRef;
148 
149  std::vector<reco::PFCandidateRef> pfCandIsoPairEle;
150  for (unsigned int lCand = 0; lCand < nObj; lCand++) {
151  pfEGCandRef = reco::PFCandidateRef(pfEGCandidateHandle, lCand);
152  const reco::GsfElectronRef& myEle = (pfEGCandToElectronMap)[pfEGCandRef];
153 
154  if (myEle.isNonnull()) {
155  // std::cout << "ParticleBasedIsoProducer Electorns PF SC " << pfEGCandRef->superClusterRef()->energy() << " Electron SC " << myEle->superCluster()->energy() << std::endl;
156  if (myEle != eleRef)
157  continue;
158 
159  //math::XYZVector candidateMomentum(myEle->p4().px(),myEle->p4().py(),myEle->p4().pz());
160  //math::XYZVector myDir=candidateMomentum.Unit();
161  // std::cout << " ParticleBasedIsoProducer Electrons This is my egammaunbiased guy energy " << pfEGCandRef->superClusterRef()->energy() << std::endl;
162  // std::cout << " Ele direction " << myDir << " eta " << myEle->eta() << " phi " << myEle->phi() << std::endl;
163  pfCandIsoPairEle = thePFBlockBasedIsolation_->calculate(myEle->p4(), pfEGCandRef, pfCandidateHandle);
165  //for ( std::vector<reco::PFCandidateRef>::const_iterator iPair=pfCandIsoPairEle.begin(); iPair<pfCandIsoPairEle.end(); iPair++) {
166  // float dR= deltaR(myEle->eta(), myEle->phi(), (*iPair)->eta(), (*iPair)->phi() );
167  // std::cout << " ParticleBasedIsoProducer Electron checking the pfCand bool pair " << (*iPair)->particleId() << " dR " << dR << " pt " << (*iPair)->pt() << " eta " << (*iPair)->eta() << " phi " << (*iPair)->phi() << std::endl;
168  // }
169  }
170  }
171 
172  pfCandIsoPairVecEle.push_back(pfCandIsoPairEle);
173  }
174 
175  auto phoToPFCandIsoMap_p = std::make_unique<edm::ValueMap<std::vector<reco::PFCandidateRef>>>();
176  edm::ValueMap<std::vector<reco::PFCandidateRef>>::Filler fillerPhotons(*phoToPFCandIsoMap_p);
177 
179  fillerPhotons.insert(photonHandle, pfCandIsoPairVecPho.begin(), pfCandIsoPairVecPho.end());
180  fillerPhotons.fill();
181  theEvent.put(std::move(phoToPFCandIsoMap_p), valueMapPhoPFCandIso_);
182 
183  auto eleToPFCandIsoMap_p = std::make_unique<edm::ValueMap<std::vector<reco::PFCandidateRef>>>();
184  edm::ValueMap<std::vector<reco::PFCandidateRef>>::Filler fillerElectrons(*eleToPFCandIsoMap_p);
185 
187  fillerElectrons.insert(electronHandle, pfCandIsoPairVecEle.begin(), pfCandIsoPairVecEle.end());
188  fillerElectrons.fill();
189  theEvent.put(std::move(eleToPFCandIsoMap_p), valueMapElePFCandIso_);
190 }
191 
193  // particleBasedIsolation
195  desc.add<std::string>("valueMapEleToEG", "");
196  desc.add<std::string>("valueMapPhoToEG", "valMapPFEgammaCandToPhoton");
197  desc.add<edm::InputTag>("electronTmpProducer", {"gedGsfElectronsTmp"});
198  desc.add<edm::InputTag>("pfCandidates", {"particleFlow"});
199  desc.add<std::string>("valueMapElePFblockIso", "gedGsfElectrons");
200  desc.add<edm::InputTag>("electronProducer", {"gedGsfElectrons"});
201  desc.add<edm::InputTag>("photonTmpProducer", {"gedPhotonsTmp"});
202  desc.add<edm::InputTag>("pfEgammaCandidates", {"particleFlowEGamma"});
203  {
205  psd0.add<std::string>("ComponentName", "pfBlockBasedIsolation");
206  psd0.add<double>("coneSize", 9999999999.);
207  desc.add<edm::ParameterSetDescription>("pfBlockBasedIsolationSetUp", psd0);
208  }
209  desc.add<edm::InputTag>("photonProducer", {"gedPhotons"});
210  desc.add<std::string>("valueMapPhoPFblockIso", "gedPhotons");
211  descriptions.add("particleBasedIsolation", desc);
212  // or use the following to generate the label from the module's C++ type
213  //descriptions.addWithDefaultLabel(desc);
214 }
edm::EDGetTokenT< reco::GsfElectronCollection > electronTmpProducerT_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:347
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
edm::EDGetTokenT< reco::PhotonCollection > photonTmpProducerT_
edm::EDGetTokenT< reco::GsfElectronCollection > electronProducerT_
std::unique_ptr< PFBlockBasedIsolation > thePFBlockBasedIsolation_
edm::EDGetTokenT< reco::PFCandidateCollection > pfCandidates_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< reco::PhotonCollection > photonProducerT_
edm::EDGetTokenT< edm::ValueMap< reco::GsfElectronRef > > valMapPFCandToEle_
edm::Ref< PFCandidateCollection > PFCandidateRef
persistent reference to a PFCandidate
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void beginRun(edm::Run const &r, edm::EventSetup const &es) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:564
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_