CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlCaGammaJetProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 #include <string>
4 // user include files
13 
31 
34 #include<iostream>
35 
36 //
37 // class declaration
38 //
39 
41 
42 public:
43  explicit AlCaGammaJetProducer(const edm::ParameterSet&);
45  virtual void beginJob() ;
46  virtual void produce(edm::Event &, const edm::EventSetup&);
47  virtual void endJob();
48 
49 private:
51 
52  // ----------member data ---------------------------
53 
57 
73 };
74 
75 AlCaGammaJetProducer::AlCaGammaJetProducer(const edm::ParameterSet& iConfig) : nAll_(0), nSelect_(0) {
76  // Take input
77  labelPhoton_ = iConfig.getParameter<edm::InputTag>("PhoInput");
78  labelPFJet_ = iConfig.getParameter<edm::InputTag>("PFjetInput");
79  labelHBHE_ = iConfig.getParameter<edm::InputTag>("HBHEInput");
80  labelHF_ = iConfig.getParameter<edm::InputTag>("HFInput");
81  labelHO_ = iConfig.getParameter<edm::InputTag>("HOInput");
82  labelTrigger_ = iConfig.getParameter<edm::InputTag>("TriggerResults");
83  labelPFCandidate_= iConfig.getParameter<edm::InputTag>("particleFlowInput");
84  labelVertex_ = iConfig.getParameter<edm::InputTag>("VertexInput");
85  labelPFMET_ = iConfig.getParameter<edm::InputTag>("METInput");
86  labelGsfEle_ = iConfig.getParameter<edm::InputTag>("gsfeleInput");
87  labelRho_ = iConfig.getParameter<edm::InputTag>("rhoInput");
88  labelConv_ = iConfig.getParameter<edm::InputTag>("ConversionsInput");
89  labelBeamSpot_ = iConfig.getParameter<edm::InputTag>("BeamSpotInput");
90  labelLoosePhot_ = iConfig.getParameter<edm::InputTag>("PhoLoose");
91  labelTightPhot_ = iConfig.getParameter<edm::InputTag>("PhoTight");
92  minPtJet_ = iConfig.getParameter<double>("MinPtJet");
93  minPtPhoton_ = iConfig.getParameter<double>("MinPtPhoton");
94 
95  tok_Photon_ = consumes<reco::PhotonCollection>(labelPhoton_);
96  tok_PFJet_ = consumes<reco::PFJetCollection>(labelPFJet_);
97  tok_HBHE_ = consumes<edm::SortedCollection<HBHERecHit,edm::StrictWeakOrdering<HBHERecHit>>>(labelHBHE_);
98  tok_HF_ = consumes<edm::SortedCollection<HFRecHit,edm::StrictWeakOrdering<HFRecHit>>>(labelHF_);
99  tok_HO_ = consumes<edm::SortedCollection<HORecHit,edm::StrictWeakOrdering<HORecHit>>>(labelHO_);
100  tok_TrigRes_= consumes<edm::TriggerResults>(labelTrigger_);
101  tok_PFCand_ = consumes<reco::PFCandidateCollection>(labelPFCandidate_);
102  tok_Vertex_ = consumes<reco::VertexCollection>(labelVertex_);
103  tok_PFMET_ = consumes<reco::PFMETCollection>(labelPFMET_);
104  tok_loosePhoton_ = consumes<edm::ValueMap<Bool_t> >(labelLoosePhot_);
105  tok_tightPhoton_ = consumes<edm::ValueMap<Bool_t> >(labelTightPhot_);
106  tok_GsfElec_ = consumes<reco::GsfElectronCollection>(labelGsfEle_);
107  tok_Rho_ = consumes<double>(labelRho_);
108  tok_Conv_ = consumes<reco::ConversionCollection>(labelConv_);
109  tok_BS_ = consumes<reco::BeamSpot>(labelBeamSpot_);
110 
111  // register your products
112  produces<reco::PhotonCollection>(labelPhoton_.encode());
113  produces<reco::PFJetCollection>(labelPFJet_.encode());
114  produces<edm::SortedCollection<HBHERecHit,edm::StrictWeakOrdering<HBHERecHit>>>(labelHBHE_.encode());
115  produces<edm::SortedCollection<HFRecHit,edm::StrictWeakOrdering<HFRecHit>>>(labelHF_.encode());
116  produces<edm::SortedCollection<HORecHit,edm::StrictWeakOrdering<HORecHit>>>(labelHO_.encode());
117  produces<edm::TriggerResults>(labelTrigger_.encode());
118  produces<std::vector<Bool_t>>(labelLoosePhot_.encode());
119  produces<std::vector<Bool_t>>(labelTightPhot_.encode());
120  produces<double>(labelRho_.encode());
121  produces<reco::PFCandidateCollection>(labelPFCandidate_.encode());
122  produces<reco::VertexCollection>(labelVertex_.encode());
123  produces<reco::PFMETCollection>(labelPFMET_.encode());
124  produces<reco::GsfElectronCollection>(labelGsfEle_.encode());
125  produces<reco::ConversionCollection>(labelConv_.encode());
126  produces<reco::BeamSpot>(labelBeamSpot_.encode());
127 
128 }
129 
131 
133 
135  edm::LogInfo("AlcaGammaJet") << "Accepts " << nSelect_ << " events from a total of " << nAll_ << " events";
136 }
137 
139 
140  if (jt.size()<1) return false;
141  if (ph.size()<1) return false;
142  if (((jt.at(0)).pt())<minPtJet_) return false;
143  if (((ph.at(0)).pt())<minPtPhoton_) return false;
144  return true;
145 }
146 // ------------ method called to produce the data ------------
148  nAll_++;
149 
150  // Access the collections from iEvent
152  iEvent.getByToken(tok_Photon_,phoHandle);
153  if (!phoHandle.isValid()) {
154  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get the product " << labelPhoton_;
155  return ;
156  }
157  const reco::PhotonCollection photon = *(phoHandle.product());
158 
160  iEvent.getByToken(tok_PFJet_,pfjet);
161  if (!pfjet.isValid()) {
162  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelPFJet_;
163  return ;
164  }
165  const reco::PFJetCollection pfjets = *(pfjet.product());
166 
168  iEvent.getByToken(tok_PFCand_,pfc);
169  if (!pfc.isValid()) {
170  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelPFCandidate_;
171  return ;
172  }
173  const reco::PFCandidateCollection pfcand = *(pfc.product());
174 
176  iEvent.getByToken(tok_Vertex_,vt);
177  if (!vt.isValid()) {
178  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelVertex_;
179  return ;
180  }
181  const reco::VertexCollection vtx = *(vt.product());
182 
184  iEvent.getByToken(tok_PFMET_,pfmt);
185  if (!pfmt.isValid()) {
186  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelPFMET_;
187  return ;
188  }
189  const reco::PFMETCollection pfmet = *(pfmt.product());
190 
192  iEvent.getByToken(tok_HBHE_,hbhe);
193  if (!hbhe.isValid()) {
194  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelHBHE_;
195  return ;
196  }
198 
200  iEvent.getByToken(tok_HO_,ho);
201  if(!ho.isValid()) {
202  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelHO_;
203  return ;
204  }
206 
208  iEvent.getByToken(tok_HF_,hf);
209  if(!hf.isValid()) {
210  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelHF_;
211  return ;
212  }
214 
216  iEvent.getByToken(tok_TrigRes_,trig);
217  if (!trig.isValid()) {
218  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelTrigger_;
219  return ;
220  }
221  const edm::TriggerResults trigres = *(trig.product());
222 
224  iEvent.getByToken(tok_Rho_,rh);
225  if (!rh.isValid()) {
226  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelRho_;
227  return ;
228  }
229  const double rho_val = *(rh.product());
230 
232  iEvent.getByToken(tok_GsfElec_,gsf);
233  if (!gsf.isValid()){
234  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelGsfEle_;
235  return ;
236  }
237  const reco::GsfElectronCollection gsfele = *(gsf.product());
238 
240  iEvent.getByToken(tok_Conv_,con);
241  if (!con.isValid()){
242  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelConv_;
243  return ;
244  }
245  const reco::ConversionCollection conv = *(con.product());
246 
248  iEvent.getByToken(tok_BS_,bs);
249  if (!bs.isValid()){
250  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelBeamSpot_;
251  return ;
252  }
253  const reco::BeamSpot beam = *(bs.product());
254 
255  // declare variables
256  // copy from standard place, if the event is useful
257  std::auto_ptr<reco::PFJetCollection> miniPFjetCollection(new reco::PFJetCollection);
258  std::auto_ptr<reco::PhotonCollection> miniPhotonCollection(new reco::PhotonCollection);
259  std::auto_ptr<reco::PFCandidateCollection> miniPFCandCollection(new reco::PFCandidateCollection);
260  std::auto_ptr<reco::VertexCollection> miniVtxCollection(new reco::VertexCollection);
261  std::auto_ptr<reco::PFMETCollection> miniPFMETCollection(new reco::PFMETCollection);
262  std::auto_ptr<edm::SortedCollection<HBHERecHit,edm::StrictWeakOrdering<HBHERecHit>>> miniHBHECollection(new edm::SortedCollection<HBHERecHit,edm::StrictWeakOrdering<HBHERecHit>>);
263  std::auto_ptr<edm::SortedCollection<HORecHit,edm::StrictWeakOrdering<HORecHit>>> miniHOCollection(new edm::SortedCollection<HORecHit,edm::StrictWeakOrdering<HORecHit>>);
264  std::auto_ptr<edm::SortedCollection<HFRecHit,edm::StrictWeakOrdering<HFRecHit>>> miniHFCollection(new edm::SortedCollection<HFRecHit,edm::StrictWeakOrdering<HFRecHit>>);
265  std::auto_ptr<reco::GsfElectronCollection> miniGSFeleCollection(new reco::GsfElectronCollection);
266  std::auto_ptr<reco::ConversionCollection> miniConversionCollection(new reco::ConversionCollection);
267 
268  std::auto_ptr<reco::BeamSpot> miniBeamSpotCollection(new reco::BeamSpot(beam.position(),beam.sigmaZ(),
269  beam.dxdz(),beam.dydz(),beam.BeamWidthX(),
270  beam.covariance(),beam.type()));
271 
272  std::auto_ptr<edm::TriggerResults> miniTriggerCollection(new edm::TriggerResults);
273 
274  std::auto_ptr<double> miniRhoCollection(new double);
275  std::auto_ptr<std::vector<Bool_t> > miniLoosePhoton(new std::vector<Bool_t>());
276  std::auto_ptr<std::vector<Bool_t> > miniTightPhoton(new std::vector<Bool_t>());
277 
278  // See if this event is useful
279  bool accept = select(photon, pfjets);
280  if (accept) {
281  nSelect_++;
282 
283  //Copy from standard place
284  for(reco::PFJetCollection::const_iterator pfjetItr=pfjets.begin();
285  pfjetItr!=pfjets.end(); pfjetItr++) {
286  miniPFjetCollection->push_back(*pfjetItr);
287  }
288 
289  for(reco::PhotonCollection::const_iterator phoItr=photon.begin();
290  phoItr!=photon.end(); phoItr++) {
291  miniPhotonCollection->push_back(*phoItr);
292  }
293 
294  for(reco::PFCandidateCollection::const_iterator pfcItr=pfcand.begin();
295  pfcItr!=pfcand.end(); pfcItr++) {
296  miniPFCandCollection->push_back(*pfcItr);
297  }
298 
299  for(reco::VertexCollection::const_iterator vtxItr=vtx.begin();
300  vtxItr!=vtx.end(); vtxItr++) {
301  miniVtxCollection->push_back(*vtxItr);
302  }
303 
304  for(reco::PFMETCollection::const_iterator pfmetItr=pfmet.begin();
305  pfmetItr!=pfmet.end(); pfmetItr++) {
306  miniPFMETCollection->push_back(*pfmetItr);
307  }
308 
309  for(edm::SortedCollection<HBHERecHit,edm::StrictWeakOrdering<HBHERecHit> >::const_iterator hbheItr=Hithbhe.begin();
310  hbheItr!=Hithbhe.end(); hbheItr++) {
311  miniHBHECollection->push_back(*hbheItr);
312  }
313 
314  for(edm::SortedCollection<HORecHit,edm::StrictWeakOrdering<HORecHit> >::const_iterator hoItr=Hitho.begin();
315  hoItr!=Hitho.end(); hoItr++) {
316  miniHOCollection->push_back(*hoItr);
317  }
318 
319  for(edm::SortedCollection<HFRecHit,edm::StrictWeakOrdering<HFRecHit> >::const_iterator hfItr=Hithf.begin();
320  hfItr!=Hithf.end(); hfItr++) {
321  miniHFCollection->push_back(*hfItr);
322  }
323 
324  for(reco::GsfElectronCollection::const_iterator gsfItr=gsfele.begin();
325  gsfItr!=gsfele.end(); gsfItr++) {
326  miniGSFeleCollection->push_back(*gsfItr);
327  }
328 
329  for(reco::ConversionCollection::const_iterator convItr=conv.begin();
330  convItr!=conv.end(); convItr++) {
331  miniConversionCollection->push_back(*convItr);
332  }
333 
334  *miniTriggerCollection = trigres;
335  *miniRhoCollection = rho_val;
336 
337  edm::Handle<edm::ValueMap<Bool_t> > loosePhotonQual;
338  iEvent.getByToken(tok_loosePhoton_, loosePhotonQual);
339  edm::Handle<edm::ValueMap<Bool_t> > tightPhotonQual;
340  iEvent.getByToken(tok_tightPhoton_, tightPhotonQual);
341  if (loosePhotonQual.isValid() && tightPhotonQual.isValid()) {
342  miniLoosePhoton->reserve(miniPhotonCollection->size());
343  miniTightPhoton->reserve(miniPhotonCollection->size());
344  for (int iPho=0; iPho<int(miniPhotonCollection->size()); ++iPho) {
345  edm::Ref<reco::PhotonCollection> photonRef(phoHandle,iPho);
346  if (!photonRef) {
347  std::cout << "failed ref" << std::endl;
348  miniLoosePhoton->push_back(-1);
349  miniTightPhoton->push_back(-1);
350  }
351  else {
352  miniLoosePhoton->push_back((*loosePhotonQual)[photonRef]);
353  miniTightPhoton->push_back((*tightPhotonQual)[photonRef]);
354  }
355  }
356  }
357 
358  //Put them in the event
359  iEvent.put( miniPhotonCollection, labelPhoton_.encode());
360  iEvent.put( miniPFjetCollection, labelPFJet_.encode());
361  iEvent.put( miniHBHECollection, labelHBHE_.encode());
362  iEvent.put( miniHFCollection, labelHF_.encode());
363  iEvent.put( miniHOCollection, labelHO_.encode());
364  iEvent.put( miniTriggerCollection, labelTrigger_.encode());
365  iEvent.put( miniPFCandCollection, labelPFCandidate_.encode());
366  iEvent.put( miniVtxCollection, labelVertex_.encode());
367  iEvent.put( miniPFMETCollection, labelPFMET_.encode());
368  iEvent.put( miniGSFeleCollection, labelGsfEle_.encode());
369  iEvent.put( miniRhoCollection, labelRho_.encode());
370  iEvent.put( miniConversionCollection, labelConv_.encode());
371  iEvent.put( miniBeamSpotCollection, labelBeamSpot_.encode());
372  iEvent.put( miniLoosePhoton, labelLoosePhot_.encode());
373  iEvent.put( miniTightPhoton, labelTightPhot_.encode());
374  }
375 
376  return;
377 
378 }
379 
T getParameter(std::string const &) const
edm::EDGetTokenT< edm::SortedCollection< HBHERecHit, edm::StrictWeakOrdering< HBHERecHit > > > tok_HBHE_
bool select(reco::PhotonCollection, reco::PFJetCollection)
static HepMC::IO_HEPEVT conv
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void produce(edm::Event &, const edm::EventSetup &)
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
edm::EDGetTokenT< edm::ValueMap< Bool_t > > tok_tightPhoton_
edm::EDGetTokenT< reco::BeamSpot > tok_BS_
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:25
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
std::string encode() const
Definition: InputTag.cc:164
std::vector< Conversion > ConversionCollection
collectin of Conversion objects
Definition: ConversionFwd.h:9
return((rh^lh)&mask)
edm::EDGetTokenT< edm::SortedCollection< HORecHit, edm::StrictWeakOrdering< HORecHit > > > tok_HO_
double dydz() const
dydz slope
Definition: BeamSpot.h:84
int iEvent
Definition: GenABIO.cc:230
AlCaGammaJetProducer(const edm::ParameterSet &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
edm::EDGetTokenT< edm::SortedCollection< HFRecHit, edm::StrictWeakOrdering< HFRecHit > > > tok_HF_
edm::EDGetTokenT< reco::VertexCollection > tok_Vertex_
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:86
bool isValid() const
Definition: HandleBase.h:75
double dxdz() const
dxdz slope
Definition: BeamSpot.h:82
const_iterator end() const
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
edm::EDGetTokenT< double > tok_Rho_
T const * product() const
Definition: Handle.h:81
edm::EDGetTokenT< reco::PFJetCollection > tok_PFJet_
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
double sigmaZ() const
sigma z
Definition: BeamSpot.h:80
edm::EDGetTokenT< reco::PFMETCollection > tok_PFMET_
edm::EDGetTokenT< reco::ConversionCollection > tok_Conv_
double covariance(int i, int j) const
(i,j)-th element of error matrix
Definition: BeamSpot.h:112
edm::EDGetTokenT< edm::TriggerResults > tok_TrigRes_
std::vector< PFJet > PFJetCollection
collection of PFJet objects
std::vector< reco::PFMET > PFMETCollection
collection of PFMET objects
edm::EDGetTokenT< reco::GsfElectronCollection > tok_GsfElec_
tuple cout
Definition: gather_cfg.py:121
const Point & position() const
position
Definition: BeamSpot.h:62
edm::EDGetTokenT< reco::PhotonCollection > tok_Photon_
edm::EDGetTokenT< edm::ValueMap< Bool_t > > tok_loosePhoton_
edm::EDGetTokenT< reco::PFCandidateCollection > tok_PFCand_
const_iterator begin() const
BeamType type() const
return beam type
Definition: BeamSpot.h:129