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  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  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 }
ConfigurationDescriptions.h
ParticleBasedIsoProducer::beginRun
void beginRun(edm::Run const &r, edm::EventSetup const &es) override
Definition: ParticleBasedIsoProducer.cc:89
ParticleBasedIsoProducer::valueMapElePFCandIso_
std::string valueMapElePFCandIso_
Definition: ParticleBasedIsoProducer.cc:48
Handle.h
ParticleBasedIsoProducer::pfEgammaCandidates_
edm::EDGetTokenT< reco::PFCandidateCollection > pfEgammaCandidates_
Definition: ParticleBasedIsoProducer.cc:40
ParticleBasedIsoProducer::valueMapPhoPFCandIso_
std::string valueMapPhoPFCandIso_
Definition: ParticleBasedIsoProducer.cc:46
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
ParticleBasedIsoProducer::photonTmpProducer_
edm::InputTag photonTmpProducer_
Definition: ParticleBasedIsoProducer.cc:31
ParticleBasedIsoProducer::photonProducerT_
edm::EDGetTokenT< reco::PhotonCollection > photonProducerT_
Definition: ParticleBasedIsoProducer.cc:36
ParticleBasedIsoProducer::thePFBlockBasedIsolation_
std::unique_ptr< PFBlockBasedIsolation > thePFBlockBasedIsolation_
Definition: ParticleBasedIsoProducer.cc:50
PFCandidate.h
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< reco::PhotonCollection >
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
ParticleBasedIsoProducer::electronCollection_
std::string electronCollection_
Definition: ParticleBasedIsoProducer.cc:28
EDProducer.h
PhotonFwd.h
ParticleBasedIsoProducer::photonProducer_
edm::InputTag photonProducer_
Definition: ParticleBasedIsoProducer.cc:30
ParticleBasedIsoProducer
Definition: ParticleBasedIsoProducer.cc:16
edm::Ref< PhotonCollection >
MakerMacros.h
Photon.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
ParticleBasedIsoProducer::produce
void produce(edm::Event &e, const edm::EventSetup &c) override
Definition: ParticleBasedIsoProducer.cc:95
ParticleBasedIsoProducer::photonTmpProducerT_
edm::EDGetTokenT< reco::PhotonCollection > photonTmpProducerT_
Definition: ParticleBasedIsoProducer.cc:37
ParticleBasedIsoProducer::conf_
edm::ParameterSet conf_
Definition: ParticleBasedIsoProducer.cc:26
ParameterSetDescription.h
GsfElectron.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
GsfElectronFwd.h
edm::ParameterSet
Definition: ParameterSet.h:47
ParticleBasedIsoProducer::valMapPFCandToPhoton_
edm::EDGetTokenT< edm::ValueMap< reco::PhotonRef > > valMapPFCandToPhoton_
Definition: ParticleBasedIsoProducer.cc:42
deltaR.h
ParticleBasedIsoProducer::electronTmpProducerT_
edm::EDGetTokenT< reco::GsfElectronCollection > electronTmpProducerT_
Definition: ParticleBasedIsoProducer.cc:39
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::stream::EDProducer
Definition: EDProducer.h:38
PFBlockBasedIsolation.h
edm::EventSetup
Definition: EventSetup.h:58
ParticleBasedIsoProducer::electronProducer_
edm::InputTag electronProducer_
Definition: ParticleBasedIsoProducer.cc:33
alignCSCRings.r
r
Definition: alignCSCRings.py:93
ValueMap.h
ParticleBasedIsoProducer::ParticleBasedIsoProducer
ParticleBasedIsoProducer(const edm::ParameterSet &conf)
Definition: ParticleBasedIsoProducer.cc:56
ParticleBasedIsoProducer::valMapPFCandToEle_
edm::EDGetTokenT< edm::ValueMap< reco::GsfElectronRef > > valMapPFCandToEle_
Definition: ParticleBasedIsoProducer.cc:43
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
writedatasetfile.run
run
Definition: writedatasetfile.py:27
ParticleBasedIsoProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: ParticleBasedIsoProducer.cc:192
edm::ValueMap
Definition: ValueMap.h:107
ParticleBasedIsoProducer::valueMapPFCandPhoton_
std::string valueMapPFCandPhoton_
Definition: ParticleBasedIsoProducer.cc:45
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ParticleBasedIsoProducer::pfCandidates_
edm::EDGetTokenT< reco::PFCandidateCollection > pfCandidates_
Definition: ParticleBasedIsoProducer.cc:41
ParticleBasedIsoProducer::electronProducerT_
edm::EDGetTokenT< reco::GsfElectronCollection > electronProducerT_
Definition: ParticleBasedIsoProducer.cc:38
ParameterSet.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
ParticleBasedIsoProducer::photonCollection_
std::string photonCollection_
Definition: ParticleBasedIsoProducer.cc:27
edm::Event
Definition: Event.h:73
ParticleBasedIsoProducer::valueMapPFCandEle_
std::string valueMapPFCandEle_
Definition: ParticleBasedIsoProducer.cc:47
edm::Event::get
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:342
edm::Event::getHandle
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:559
edm::InputTag
Definition: InputTag.h:15
ParticleBasedIsoProducer::electronTmpProducer_
edm::InputTag electronTmpProducer_
Definition: ParticleBasedIsoProducer.cc:34
PFCandidateFwd.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37