CMS 3D CMS Logo

AlCaDiJetsProducer.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 public:
42  explicit AlCaDiJetsProducer(const edm::ParameterSet&);
43  ~AlCaDiJetsProducer() override;
44  void beginJob() override;
45  void produce(edm::Event&, const edm::EventSetup&) override;
46  void endJob() override;
47 
48 private:
50 
51  // ----------member data ---------------------------
52 
54  double minPtJet_;
56 
61  //edm::EDGetTokenT<edm::TriggerResults> tok_TrigRes_;
64 };
65 
67  // Take input
68  labelPFJet_ = iConfig.getParameter<edm::InputTag>("PFjetInput");
69  labelHBHE_ = iConfig.getParameter<edm::InputTag>("HBHEInput");
70  labelHF_ = iConfig.getParameter<edm::InputTag>("HFInput");
71  labelHO_ = iConfig.getParameter<edm::InputTag>("HOInput");
72  //labelTrigger_ = iConfig.getParameter<edm::InputTag>("TriggerResults");
73  labelPFCandidate_ = iConfig.getParameter<edm::InputTag>("particleFlowInput");
74  labelVertex_ = iConfig.getParameter<edm::InputTag>("VertexInput");
75  minPtJet_ = iConfig.getParameter<double>("MinPtJet");
76 
77  tok_PFJet_ = consumes<reco::PFJetCollection>(labelPFJet_);
78  tok_HBHE_ = consumes<edm::SortedCollection<HBHERecHit, edm::StrictWeakOrdering<HBHERecHit>>>(labelHBHE_);
79  tok_HF_ = consumes<edm::SortedCollection<HFRecHit, edm::StrictWeakOrdering<HFRecHit>>>(labelHF_);
80  tok_HO_ = consumes<edm::SortedCollection<HORecHit, edm::StrictWeakOrdering<HORecHit>>>(labelHO_);
81  //tok_TrigRes_= consumes<edm::TriggerResults>(labelTrigger_);
82  tok_PFCand_ = consumes<reco::PFCandidateCollection>(labelPFCandidate_);
83  tok_Vertex_ = consumes<reco::VertexCollection>(labelVertex_);
84 
85  // register your products
86  produces<reco::PFJetCollection>(labelPFJet_.encode());
87  produces<edm::SortedCollection<HBHERecHit, edm::StrictWeakOrdering<HBHERecHit>>>(labelHBHE_.encode());
88  produces<edm::SortedCollection<HFRecHit, edm::StrictWeakOrdering<HFRecHit>>>(labelHF_.encode());
89  produces<edm::SortedCollection<HORecHit, edm::StrictWeakOrdering<HORecHit>>>(labelHO_.encode());
90  //produces<edm::TriggerResults>(labelTrigger_.encode());
91  produces<reco::PFCandidateCollection>(labelPFCandidate_.encode());
92  produces<reco::VertexCollection>(labelVertex_.encode());
93 }
94 
96 
98 
100  edm::LogInfo("AlcaDiJets") << "Accepts " << nSelect_ << " events from a total of " << nAll_ << " events";
101 }
102 
104  if (jt.size() < 2)
105  return false;
106  if (((jt.at(0)).pt()) < minPtJet_)
107  return false;
108  return true;
109 }
110 // ------------ method called to produce the data ------------
112  nAll_++;
113 
114  // Access the collections from iEvent
116  iEvent.getByToken(tok_PFJet_, pfjet);
117  if (!pfjet.isValid()) {
118  edm::LogWarning("AlCaDiJets") << "AlCaDiJetsProducer: Error! can't get product " << labelPFJet_;
119  return;
120  }
121  const reco::PFJetCollection pfjets = *(pfjet.product());
122 
124  iEvent.getByToken(tok_PFCand_, pfc);
125  if (!pfc.isValid()) {
126  edm::LogWarning("AlCaDiJets") << "AlCaDiJetsProducer: Error! can't get product " << labelPFCandidate_;
127  return;
128  }
129  const reco::PFCandidateCollection pfcand = *(pfc.product());
130 
132  iEvent.getByToken(tok_Vertex_, vt);
133  if (!vt.isValid()) {
134  edm::LogWarning("AlCaDiJets") << "AlCaDiJetsProducer: Error! can't get product " << labelVertex_;
135  return;
136  }
137  const reco::VertexCollection vtx = *(vt.product());
138 
140  iEvent.getByToken(tok_HBHE_, hbhe);
141  if (!hbhe.isValid()) {
142  edm::LogWarning("AlCaDiJets") << "AlCaDiJetsProducer: Error! can't get product " << labelHBHE_;
143  return;
144  }
146 
148  iEvent.getByToken(tok_HO_, ho);
149  if (!ho.isValid()) {
150  edm::LogWarning("AlCaDiJets") << "AlCaDiJetsProducer: Error! can't get product " << labelHO_;
151  return;
152  }
154 
156  iEvent.getByToken(tok_HF_, hf);
157  if (!hf.isValid()) {
158  edm::LogWarning("AlCaDiJets") << "AlCaDiJetsProducer: Error! can't get product " << labelHF_;
159  return;
160  }
162 
163  // See if this event is useful
164  bool accept = select(pfjets);
165  if (accept) {
166  nSelect_++;
167 
168  //Copy from standard place
169  auto miniPFjetCollection = std::make_unique<reco::PFJetCollection>();
170  for (reco::PFJetCollection::const_iterator pfjetItr = pfjets.begin(); pfjetItr != pfjets.end(); pfjetItr++) {
171  miniPFjetCollection->push_back(*pfjetItr);
172  }
173 
174  auto miniPFCandCollection = std::make_unique<reco::PFCandidateCollection>();
175  for (reco::PFCandidateCollection::const_iterator pfcItr = pfcand.begin(); pfcItr != pfcand.end(); pfcItr++) {
176  miniPFCandCollection->push_back(*pfcItr);
177  }
178 
179  auto miniVtxCollection = std::make_unique<reco::VertexCollection>();
180  for (reco::VertexCollection::const_iterator vtxItr = vtx.begin(); vtxItr != vtx.end(); vtxItr++) {
181  miniVtxCollection->push_back(*vtxItr);
182  }
183 
184  auto miniHBHECollection =
185  std::make_unique<edm::SortedCollection<HBHERecHit, edm::StrictWeakOrdering<HBHERecHit>>>();
187  Hithbhe.begin();
188  hbheItr != Hithbhe.end();
189  hbheItr++) {
190  miniHBHECollection->push_back(*hbheItr);
191  }
192 
193  auto miniHOCollection = std::make_unique<edm::SortedCollection<HORecHit, edm::StrictWeakOrdering<HORecHit>>>();
194  for (edm::SortedCollection<HORecHit, edm::StrictWeakOrdering<HORecHit>>::const_iterator hoItr = Hitho.begin();
195  hoItr != Hitho.end();
196  hoItr++) {
197  miniHOCollection->push_back(*hoItr);
198  }
199 
200  auto miniHFCollection = std::make_unique<edm::SortedCollection<HFRecHit, edm::StrictWeakOrdering<HFRecHit>>>();
201  for (edm::SortedCollection<HFRecHit, edm::StrictWeakOrdering<HFRecHit>>::const_iterator hfItr = Hithf.begin();
202  hfItr != Hithf.end();
203  hfItr++) {
204  miniHFCollection->push_back(*hfItr);
205  }
206 
207  //Put them in the event
208  iEvent.put(std::move(miniPFjetCollection), labelPFJet_.encode());
209  iEvent.put(std::move(miniHBHECollection), labelHBHE_.encode());
210  iEvent.put(std::move(miniHFCollection), labelHF_.encode());
211  iEvent.put(std::move(miniHOCollection), labelHO_.encode());
212  //iEvent.put(std::move(miniTriggerCollection), labelTrigger_.encode());
213  iEvent.put(std::move(miniPFCandCollection), labelPFCandidate_.encode());
214  iEvent.put(std::move(miniVtxCollection), labelVertex_.encode());
215  }
216  return;
217 }
218 
T getParameter(std::string const &) const
edm::EDGetTokenT< edm::SortedCollection< HBHERecHit, edm::StrictWeakOrdering< HBHERecHit > > > tok_HBHE_
bool select(reco::PFJetCollection)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
edm::InputTag labelPFCandidate_
void endJob() override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
edm::EDGetTokenT< edm::SortedCollection< HORecHit, edm::StrictWeakOrdering< HORecHit > > > tok_HO_
edm::InputTag labelHBHE_
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
edm::EDGetTokenT< reco::PFJetCollection > tok_PFJet_
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
std::string encode() const
Definition: InputTag.cc:159
edm::EDGetTokenT< edm::SortedCollection< HFRecHit, edm::StrictWeakOrdering< HFRecHit > > > tok_HF_
~AlCaDiJetsProducer() override
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::InputTag labelPFJet_
edm::EDGetTokenT< reco::VertexCollection > tok_Vertex_
bool isValid() const
Definition: HandleBase.h:74
edm::EDGetTokenT< reco::PFCandidateCollection > tok_PFCand_
const_iterator end() const
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
T const * product() const
Definition: Handle.h:74
std::vector< PFJet > PFJetCollection
collection of PFJet objects
void produce(edm::Event &, const edm::EventSetup &) override
AlCaDiJetsProducer(const edm::ParameterSet &)
edm::InputTag labelVertex_
def move(src, dest)
Definition: eostools.py:511
const_iterator begin() const
void beginJob() override