test
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&);
29  private:
30  virtual bool filter(edm::Event&, const edm::EventSetup&);
31 
32 // ----------member data ---------------------------
33  bool verbose_;
40 
42 };
43 
44 //
45 // constants, enums and typedefs
46 //
47 
48 //
49 // static data member definitions
50 //
51 
52 //
53 // constructors and destructor
54 //
56  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
57  vertexToken_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexTag"));
58  photonToken_ = consumes<reco::PhotonCollection>(iConfig.getParameter<edm::InputTag>("photonTag"));
59  particleFlowToken_ = consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("particleFlowTag"));
60 
61  nameIsoCh_ = iConfig.getParameter<std::string>("nameValueMapIsoCh");
62  nameIsoPh_ = iConfig.getParameter<std::string>("nameValueMapIsoPh");
63  nameIsoNh_ = iConfig.getParameter<std::string>("nameValueMapIsoNh");
64 
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 }
74 
75 
77 {
78 
79  // do anything here that needs to be done at desctruction time
80  // (e.g. close files, deallocate resources etc.)
81 
82 }
83 
84 
85 //
86 // member functions
87 //
88 
89 // ------------ method called on each new Event ------------
91 
92  std::unique_ptr<edm::ValueMap<double> > chIsoMap(new edm::ValueMap<double>() );
93  edm::ValueMap<double>::Filler chFiller(*chIsoMap);
94 
95  std::unique_ptr<edm::ValueMap<double> > phIsoMap(new edm::ValueMap<double>() );
96  edm::ValueMap<double>::Filler phFiller(*phIsoMap);
97 
98  std::unique_ptr<edm::ValueMap<double> > nhIsoMap(new edm::ValueMap<double>() );
99  edm::ValueMap<double>::Filler nhFiller(*nhIsoMap);
100 
102  iEvent.getByToken(vertexToken_, vertexCollection);
103 
105  iEvent.getByToken(photonToken_, phoCollection);
106  const reco::PhotonCollection *recoPho = phoCollection.product();
107 
108  // All PF Candidate for alternate isolation
110  iEvent.getByToken(particleFlowToken_, pfCandidatesH);
111  const reco::PFCandidateCollection thePfColl = *(pfCandidatesH.product());
112 
113  std::vector<double> chIsoValues;
114  std::vector<double> phIsoValues;
115  std::vector<double> nhIsoValues;
116  chIsoValues.reserve(phoCollection->size());
117  phIsoValues.reserve(phoCollection->size());
118  nhIsoValues.reserve(phoCollection->size());
119 
120  unsigned int ivtx = 0;
121  reco::VertexRef myVtxRef(vertexCollection, ivtx);
122 
123 
124  for (reco::PhotonCollection::const_iterator aPho = recoPho->begin(); aPho != recoPho->end(); ++aPho) {
125 
126  isolator.fGetIsolation(&*aPho,
127  &thePfColl,
128  myVtxRef,
129  vertexCollection);
130 
131  if(verbose_) {
132  std::cout << " run " << iEvent.id().run() << " lumi " << iEvent.id().luminosityBlock() << " event " << iEvent.id().event();
133  std::cout << " pt " << aPho->pt() << " eta " << aPho->eta() << " phi " << aPho->phi()
134  << " charge " << aPho->charge()<< " : " << std::endl;;
135 
136  std::cout << " ChargedIso " << isolator.getIsolationCharged() << std::endl;
137  std::cout << " PhotonIso " << isolator.getIsolationPhoton() << std::endl;
138  std::cout << " NeutralHadron Iso " << isolator.getIsolationNeutral() << std::endl;
139  }
140 
141  chIsoValues.push_back(isolator.getIsolationCharged());
142  phIsoValues.push_back(isolator.getIsolationPhoton());
143  nhIsoValues.push_back(isolator.getIsolationNeutral());
144 
145  }
146 
147  chFiller.insert(phoCollection, chIsoValues.begin(), chIsoValues.end() );
148  chFiller.fill();
149 
150  phFiller.insert(phoCollection, phIsoValues.begin(), phIsoValues.end() );
151  phFiller.fill();
152 
153  nhFiller.insert(phoCollection, nhIsoValues.begin(), nhIsoValues.end() );
154  nhFiller.fill();
155 
156 
157  iEvent.put(std::move(chIsoMap),nameIsoCh_);
158  iEvent.put(std::move(phIsoMap),nameIsoPh_);
159  iEvent.put(std::move(nhIsoMap),nameIsoNh_);
160 
161 
162  return true;
163 }
164 
165 //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
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#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
def move
Definition: eostools.py:510
PFIsolationEstimator isolator
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
edm::EDGetTokenT< reco::PFCandidateCollection > particleFlowToken_
virtual bool filter(edm::Event &, const edm::EventSetup &)
T const * product() const
Definition: Handle.h:81
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
edm::EDGetTokenT< reco::VertexCollection > vertexToken_
edm::EventID id() const
Definition: EventBase.h:58
void initializePhotonIsolation(Bool_t bApplyVeto)
float fGetIsolation(const reco::PFCandidate *pfCandidate, const reco::PFCandidateCollection *pfParticlesColl, reco::VertexRef vtx, edm::Handle< reco::VertexCollection > vertices)
tuple cout
Definition: gather_cfg.py:145
void setConeSize(float fValue=0.4)
PhotonIsoProducer(const edm::ParameterSet &)