CMS 3D CMS Logo

PhotonIsoProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
7 
10 
21 //
22 // class declaration
23 //
24 
26 public:
27  explicit PhotonIsoProducer(const edm::ParameterSet&);
28  ~PhotonIsoProducer() override;
29 
30 private:
31  bool filter(edm::Event&, const edm::EventSetup&) override;
32 
33  // ----------member data ---------------------------
34  bool verbose_;
41 
43 };
44 
45 //
46 // constants, enums and typedefs
47 //
48 
49 //
50 // static data member definitions
51 //
52 
53 //
54 // constructors and destructor
55 //
57  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
58  vertexToken_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexTag"));
59  photonToken_ = consumes<reco::PhotonCollection>(iConfig.getParameter<edm::InputTag>("photonTag"));
60  particleFlowToken_ = consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("particleFlowTag"));
61 
62  nameIsoCh_ = iConfig.getParameter<std::string>("nameValueMapIsoCh");
63  nameIsoPh_ = iConfig.getParameter<std::string>("nameValueMapIsoPh");
64  nameIsoNh_ = iConfig.getParameter<std::string>("nameValueMapIsoNh");
65 
66  produces<edm::ValueMap<double> >(nameIsoCh_);
67  produces<edm::ValueMap<double> >(nameIsoPh_);
68  produces<edm::ValueMap<double> >(nameIsoNh_);
69 
70  isolator.initializePhotonIsolation(kTRUE); //NOTE: this automatically set all the correct defaul veto values
71  isolator.setConeSize(0.3);
72 }
73 
75  // do anything here that needs to be done at desctruction time
76  // (e.g. close files, deallocate resources etc.)
77 }
78 
79 //
80 // member functions
81 //
82 
83 // ------------ method called on each new Event ------------
85  std::unique_ptr<edm::ValueMap<double> > chIsoMap(new edm::ValueMap<double>());
86  edm::ValueMap<double>::Filler chFiller(*chIsoMap);
87 
88  std::unique_ptr<edm::ValueMap<double> > phIsoMap(new edm::ValueMap<double>());
89  edm::ValueMap<double>::Filler phFiller(*phIsoMap);
90 
91  std::unique_ptr<edm::ValueMap<double> > nhIsoMap(new edm::ValueMap<double>());
92  edm::ValueMap<double>::Filler nhFiller(*nhIsoMap);
93 
96 
98  iEvent.getByToken(photonToken_, phoCollection);
99  const reco::PhotonCollection* recoPho = phoCollection.product();
100 
101  // All PF Candidate for alternate isolation
103  iEvent.getByToken(particleFlowToken_, pfCandidatesH);
104  const reco::PFCandidateCollection thePfColl = *(pfCandidatesH.product());
105 
106  std::vector<double> chIsoValues;
107  std::vector<double> phIsoValues;
108  std::vector<double> nhIsoValues;
109  chIsoValues.reserve(phoCollection->size());
110  phIsoValues.reserve(phoCollection->size());
111  nhIsoValues.reserve(phoCollection->size());
112 
113  unsigned int ivtx = 0;
114  reco::VertexRef myVtxRef(vertexCollection, ivtx);
115 
116  for (reco::PhotonCollection::const_iterator aPho = recoPho->begin(); aPho != recoPho->end(); ++aPho) {
117  isolator.fGetIsolation(&*aPho, &thePfColl, myVtxRef, vertexCollection);
118 
119  if (verbose_) {
120  std::cout << " run " << iEvent.id().run() << " lumi " << iEvent.id().luminosityBlock() << " event "
121  << iEvent.id().event();
122  std::cout << " pt " << aPho->pt() << " eta " << aPho->eta() << " phi " << aPho->phi() << " charge "
123  << aPho->charge() << " : " << std::endl;
124  ;
125 
126  std::cout << " ChargedIso " << isolator.getIsolationCharged() << std::endl;
127  std::cout << " PhotonIso " << isolator.getIsolationPhoton() << std::endl;
128  std::cout << " NeutralHadron Iso " << isolator.getIsolationNeutral() << std::endl;
129  }
130 
131  chIsoValues.push_back(isolator.getIsolationCharged());
132  phIsoValues.push_back(isolator.getIsolationPhoton());
133  nhIsoValues.push_back(isolator.getIsolationNeutral());
134  }
135 
136  chFiller.insert(phoCollection, chIsoValues.begin(), chIsoValues.end());
137  chFiller.fill();
138 
139  phFiller.insert(phoCollection, phIsoValues.begin(), phIsoValues.end());
140  phFiller.fill();
141 
142  nhFiller.insert(phoCollection, nhIsoValues.begin(), nhIsoValues.end());
143  nhFiller.fill();
144 
145  iEvent.put(std::move(chIsoMap), nameIsoCh_);
146  iEvent.put(std::move(phIsoMap), nameIsoPh_);
147  iEvent.put(std::move(nhIsoMap), nameIsoNh_);
148 
149  return true;
150 }
151 
152 //define this as a plug-in
PhotonIsoProducer::PhotonIsoProducer
PhotonIsoProducer(const edm::ParameterSet &)
Definition: PhotonIsoProducer.cc:56
edm::helper::Filler::insert
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
edm::Handle::product
T const * product() const
Definition: Handle.h:70
PFIsolationEstimator::initializePhotonIsolation
void initializePhotonIsolation(Bool_t bApplyVeto)
Definition: PFIsolationEstimator.cc:134
PFCandidate.h
edm::EDGetTokenT< reco::VertexCollection >
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::helper::Filler::fill
void fill()
Definition: ValueMap.h:65
EDFilter.h
PFIsolationEstimator::setConeSize
void setConeSize(float fValue=0.4)
Definition: PFIsolationEstimator.h:97
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
PhotonIsoProducer::nameIsoPh_
std::string nameIsoPh_
Definition: PhotonIsoProducer.cc:39
edm::Handle< reco::VertexCollection >
edm::Ref< VertexCollection >
PFIsolationEstimator::getIsolationPhoton
float getIsolationPhoton()
Definition: PFIsolationEstimator.h:144
MakerMacros.h
PhotonIsoProducer::nameIsoNh_
std::string nameIsoNh_
Definition: PhotonIsoProducer.cc:40
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PhotonIsoProducer::isolator
PFIsolationEstimator isolator
Definition: PhotonIsoProducer.cc:42
PFIsolationEstimator::getIsolationCharged
float getIsolationCharged()
Definition: PFIsolationEstimator.h:152
PhotonIsoProducer::filter
bool filter(edm::Event &, const edm::EventSetup &) override
Definition: PhotonIsoProducer.cc:84
GsfElectron.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
PhotonIsoProducer
Definition: PhotonIsoProducer.cc:25
GsfElectronFwd.h
PhotonIsoProducer::photonToken_
edm::EDGetTokenT< reco::PhotonCollection > photonToken_
Definition: PhotonIsoProducer.cc:36
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
PhotonIsoProducer::vertexToken_
edm::EDGetTokenT< reco::VertexCollection > vertexToken_
Definition: PhotonIsoProducer.cc:35
PFIsolationEstimator.h
PFIsolationEstimator::fGetIsolation
float fGetIsolation(const reco::PFCandidate *pfCandidate, const reco::PFCandidateCollection *pfParticlesColl, reco::VertexRef vtx, edm::Handle< reco::VertexCollection > vertices)
Definition: PFIsolationEstimator.cc:178
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EDFilter
Definition: EDFilter.h:39
edm::EventSetup
Definition: EventSetup.h:57
PFIsolationEstimator::getIsolationNeutral
float getIsolationNeutral()
Definition: PFIsolationEstimator.h:148
TransientTrackRecord.h
PFIsolationEstimator
Definition: PFIsolationEstimator.h:51
VertexFwd.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
eostools.move
def move(src, dest)
Definition: eostools.py:511
Frameworkfwd.h
PhotonIsoProducer::nameIsoCh_
std::string nameIsoCh_
Definition: PhotonIsoProducer.cc:38
spclusmultinvestigator_cfi.vertexCollection
vertexCollection
Definition: spclusmultinvestigator_cfi.py:4
edm::ValueMap
Definition: ValueMap.h:107
reco::PFCandidateCollection
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
Definition: PFCandidateFwd.h:12
PhotonIsoProducer::particleFlowToken_
edm::EDGetTokenT< reco::PFCandidateCollection > particleFlowToken_
Definition: PhotonIsoProducer.cc:37
PhotonIsoProducer::~PhotonIsoProducer
~PhotonIsoProducer() override
Definition: PhotonIsoProducer.cc:74
Electron.h
PhotonIsoProducer::verbose_
bool verbose_
Definition: PhotonIsoProducer.cc:34
reco::PhotonCollection
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
edm::helper::Filler
Definition: ValueMap.h:22
ParameterSet.h
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
PFCandidateFwd.h