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 
25 using namespace std;
26 using namespace reco;
28  public:
29  explicit PhotonIsoProducer(const edm::ParameterSet&);
31  private:
32  virtual bool filter(edm::Event&, const edm::EventSetup&);
33 
34 // ----------member data ---------------------------
35  bool verbose_;
42 
44 };
45 
46 //
47 // constants, enums and typedefs
48 //
49 
50 //
51 // static data member definitions
52 //
53 
54 //
55 // constructors and destructor
56 //
58  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
59  vertexToken_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexTag"));
60  photonToken_ = consumes<reco::PhotonCollection>(iConfig.getParameter<edm::InputTag>("photonTag"));
61  particleFlowToken_ = consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("particleFlowTag"));
62 
63  nameIsoCh_ = iConfig.getParameter<std::string>("nameValueMapIsoCh");
64  nameIsoPh_ = iConfig.getParameter<std::string>("nameValueMapIsoPh");
65  nameIsoNh_ = iConfig.getParameter<std::string>("nameValueMapIsoNh");
66 
67 
68  produces<edm::ValueMap<double> >(nameIsoCh_);
69  produces<edm::ValueMap<double> >(nameIsoPh_);
70  produces<edm::ValueMap<double> >(nameIsoNh_);
71 
72  isolator.initializePhotonIsolation(kTRUE); //NOTE: this automatically set all the correct defaul veto values
73  isolator.setConeSize(0.3);
74 
75 }
76 
77 
79 {
80 
81  // do anything here that needs to be done at desctruction time
82  // (e.g. close files, deallocate resources etc.)
83 
84 }
85 
86 
87 //
88 // member functions
89 //
90 
91 // ------------ method called on each new Event ------------
93  using namespace edm;
94 
95  std::auto_ptr<edm::ValueMap<double> > chIsoMap(new edm::ValueMap<double>() );
96  edm::ValueMap<double>::Filler chFiller(*chIsoMap);
97 
98  std::auto_ptr<edm::ValueMap<double> > phIsoMap(new edm::ValueMap<double>() );
99  edm::ValueMap<double>::Filler phFiller(*phIsoMap);
100 
101  std::auto_ptr<edm::ValueMap<double> > nhIsoMap(new edm::ValueMap<double>() );
102  edm::ValueMap<double>::Filler nhFiller(*nhIsoMap);
103 
105  iEvent.getByToken(vertexToken_, vertexCollection);
106 
107  Handle<reco::PhotonCollection> phoCollection;
108  iEvent.getByToken(photonToken_, phoCollection);
109  const reco::PhotonCollection *recoPho = phoCollection.product();
110 
111  // All PF Candidate for alternate isolation
113  iEvent.getByToken(particleFlowToken_, pfCandidatesH);
114  const PFCandidateCollection thePfColl = *(pfCandidatesH.product());
115 
116  std::vector<double> chIsoValues;
117  std::vector<double> phIsoValues;
118  std::vector<double> nhIsoValues;
119  chIsoValues.reserve(phoCollection->size());
120  phIsoValues.reserve(phoCollection->size());
121  nhIsoValues.reserve(phoCollection->size());
122 
123  unsigned int ivtx = 0;
124  VertexRef myVtxRef(vertexCollection, ivtx);
125 
126 
127  for (reco::PhotonCollection::const_iterator aPho = recoPho->begin(); aPho != recoPho->end(); ++aPho) {
128 
129  isolator.fGetIsolation(&*aPho,
130  &thePfColl,
131  myVtxRef,
133 
134  if(verbose_) {
135  std::cout << " run " << iEvent.id().run() << " lumi " << iEvent.id().luminosityBlock() << " event " << iEvent.id().event();
136  std::cout << " pt " << aPho->pt() << " eta " << aPho->eta() << " phi " << aPho->phi()
137  << " charge " << aPho->charge()<< " : " << std::endl;;
138 
139  std::cout << " ChargedIso " << isolator.getIsolationCharged() << std::endl;
140  std::cout << " PhotonIso " << isolator.getIsolationPhoton() << std::endl;
141  std::cout << " NeutralHadron Iso " << isolator.getIsolationNeutral() << std::endl;
142  }
143 
144  chIsoValues.push_back(isolator.getIsolationCharged());
145  phIsoValues.push_back(isolator.getIsolationPhoton());
146  nhIsoValues.push_back(isolator.getIsolationNeutral());
147 
148  }
149 
150  chFiller.insert(phoCollection, chIsoValues.begin(), chIsoValues.end() );
151  chFiller.fill();
152 
153  phFiller.insert(phoCollection, phIsoValues.begin(), phIsoValues.end() );
154  phFiller.fill();
155 
156  nhFiller.insert(phoCollection, nhIsoValues.begin(), nhIsoValues.end() );
157  nhFiller.fill();
158 
159 
160  iEvent.put(chIsoMap,nameIsoCh_);
161  iEvent.put(phIsoMap,nameIsoPh_);
162  iEvent.put(nhIsoMap,nameIsoNh_);
163 
164 
165  return true;
166 }
167 
168 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
tuple vertexCollection
edm::EDGetTokenT< reco::PhotonCollection > photonToken_
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
PFIsolationEstimator isolator
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
edm::EDGetTokenT< reco::PFCandidateCollection > particleFlowToken_
virtual bool filter(edm::Event &, const edm::EventSetup &)
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
edm::EDGetTokenT< reco::VertexCollection > vertexToken_
edm::EventID id() const
Definition: EventBase.h:56
tuple cout
Definition: gather_cfg.py:121
PhotonIsoProducer(const edm::ParameterSet &)