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 
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  edm::LogPrint("PhotonIsoProducer") << " run " << iEvent.id().run() << " lumi " << iEvent.id().luminosityBlock()
121  << " event " << iEvent.id().event();
122  edm::LogPrint("PhotonIsoProducer") << " pt " << aPho->pt() << " eta " << aPho->eta() << " phi " << aPho->phi()
123  << " charge " << aPho->charge() << " : ";
124 
125  edm::LogPrint("PhotonIsoProducer") << " ChargedIso " << isolator.getIsolationCharged();
126  edm::LogPrint("PhotonIsoProducer") << " PhotonIso " << isolator.getIsolationPhoton();
127  edm::LogPrint("PhotonIsoProducer") << " NeutralHadron Iso " << isolator.getIsolationNeutral();
128  }
129 
130  chIsoValues.push_back(isolator.getIsolationCharged());
131  phIsoValues.push_back(isolator.getIsolationPhoton());
132  nhIsoValues.push_back(isolator.getIsolationNeutral());
133  }
134 
135  chFiller.insert(phoCollection, chIsoValues.begin(), chIsoValues.end());
136  chFiller.fill();
137 
138  phFiller.insert(phoCollection, phIsoValues.begin(), phIsoValues.end());
139  phFiller.fill();
140 
141  nhFiller.insert(phoCollection, nhIsoValues.begin(), nhIsoValues.end());
142  nhFiller.fill();
143 
144  iEvent.put(std::move(chIsoMap), nameIsoCh_);
145  iEvent.put(std::move(phIsoMap), nameIsoPh_);
146  iEvent.put(std::move(nhIsoMap), nameIsoNh_);
147 
148  return true;
149 }
150 
151 //define this as a plug-in
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T const * product() const
Definition: Handle.h:70
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
bool filter(edm::Event &, const edm::EventSetup &) override
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< reco::PhotonCollection > photonToken_
int iEvent
Definition: GenABIO.cc:224
PFIsolationEstimator isolator
Log< level::Warning, true > LogPrint
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
edm::EDGetTokenT< reco::PFCandidateCollection > particleFlowToken_
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
edm::EDGetTokenT< reco::VertexCollection > vertexToken_
~PhotonIsoProducer() override
void initializePhotonIsolation(Bool_t bApplyVeto)
float fGetIsolation(const reco::PFCandidate *pfCandidate, const reco::PFCandidateCollection *pfParticlesColl, reco::VertexRef vtx, edm::Handle< reco::VertexCollection > vertices)
void setConeSize(float fValue=0.4)
def move(src, dest)
Definition: eostools.py:511
PhotonIsoProducer(const edm::ParameterSet &)