CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
95  iEvent.getByToken(vertexToken_, vertexCollection);
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
RunNumber_t run() const
Definition: EventID.h:38
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:40
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:39
bool filter(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< reco::PhotonCollection > photonToken_
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PFIsolationEstimator isolator
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
edm::EDGetTokenT< reco::PFCandidateCollection > particleFlowToken_
T const * product() const
Definition: Handle.h:69
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
edm::EDGetTokenT< reco::VertexCollection > vertexToken_
~PhotonIsoProducer() override
edm::EventID id() const
Definition: EventBase.h:59
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 &)