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 namespace alcaHcalDiJet {
37  struct Counters {
38  Counters() : nAll_(0), nSelect_(0) {}
39  mutable std::atomic<unsigned int> nAll_, nSelect_;
40  };
41 } // namespace alcaHcalDiJet
42 
43 //
44 // class declaration
45 //
46 
47 class AlCaDiJetsProducer : public edm::global::EDProducer<edm::RunCache<alcaHcalDiJet::Counters>> {
48 public:
49  explicit AlCaDiJetsProducer(const edm::ParameterSet&);
50  ~AlCaDiJetsProducer() override = default;
51 
52  std::shared_ptr<alcaHcalDiJet::Counters> globalBeginRun(edm::Run const&, edm::EventSetup const&) const override {
53  return std::make_shared<alcaHcalDiJet::Counters>();
54  }
55  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
56  void globalEndRun(edm::Run const& iRun, edm::EventSetup const&) const override;
57  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
58 
59 private:
60  bool select(reco::PFJetCollection) const;
61 
62  // ----------member data ---------------------------
63 
65  double minPtJet_;
66 
71  //edm::EDGetTokenT<edm::TriggerResults> tok_TrigRes_;
74 };
75 
77  // Take input
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  minPtJet_ = iConfig.getParameter<double>("MinPtJet");
86 
87  tok_PFJet_ = consumes<reco::PFJetCollection>(labelPFJet_);
88  tok_HBHE_ = consumes<edm::SortedCollection<HBHERecHit, edm::StrictWeakOrdering<HBHERecHit>>>(labelHBHE_);
89  tok_HF_ = consumes<edm::SortedCollection<HFRecHit, edm::StrictWeakOrdering<HFRecHit>>>(labelHF_);
90  tok_HO_ = consumes<edm::SortedCollection<HORecHit, edm::StrictWeakOrdering<HORecHit>>>(labelHO_);
91  //tok_TrigRes_= consumes<edm::TriggerResults>(labelTrigger_);
92  tok_PFCand_ = consumes<reco::PFCandidateCollection>(labelPFCandidate_);
93  tok_Vertex_ = consumes<reco::VertexCollection>(labelVertex_);
94 
95  // register your products
96  produces<reco::PFJetCollection>(labelPFJet_.encode());
97  produces<edm::SortedCollection<HBHERecHit, edm::StrictWeakOrdering<HBHERecHit>>>(labelHBHE_.encode());
98  produces<edm::SortedCollection<HFRecHit, edm::StrictWeakOrdering<HFRecHit>>>(labelHF_.encode());
99  produces<edm::SortedCollection<HORecHit, edm::StrictWeakOrdering<HORecHit>>>(labelHO_.encode());
100  //produces<edm::TriggerResults>(labelTrigger_.encode());
101  produces<reco::PFCandidateCollection>(labelPFCandidate_.encode());
102  produces<reco::VertexCollection>(labelVertex_.encode());
103 }
104 
106  edm::LogVerbatim("AlcaDiJets") << "Accepts " << runCache(iRun.index())->nSelect_ << " events from a total of "
107  << runCache(iRun.index())->nAll_ << " events";
108 }
109 
111  if (jt.size() < 2)
112  return false;
113  if (((jt.at(0)).pt()) < minPtJet_)
114  return false;
115  return true;
116 }
117 
118 // ------------ method called to produce the data ------------
120  ++(runCache(iEvent.getRun().index())->nAll_);
121 
122  // Access the collections from iEvent
124  if (!pfjet.isValid()) {
125  edm::LogWarning("AlCaDiJets") << "AlCaDiJetsProducer: Error! can't get product " << labelPFJet_;
126  return;
127  }
128  const reco::PFJetCollection pfjets = *(pfjet.product());
129 
131  if (!pfc.isValid()) {
132  edm::LogWarning("AlCaDiJets") << "AlCaDiJetsProducer: Error! can't get product " << labelPFCandidate_;
133  return;
134  }
135  const reco::PFCandidateCollection pfcand = *(pfc.product());
136 
138  if (!vt.isValid()) {
139  edm::LogWarning("AlCaDiJets") << "AlCaDiJetsProducer: Error! can't get product " << labelVertex_;
140  return;
141  }
142  const reco::VertexCollection vtx = *(vt.product());
143 
144  auto hbhe = iEvent.getHandle(tok_HBHE_);
145  if (!hbhe.isValid()) {
146  edm::LogWarning("AlCaDiJets") << "AlCaDiJetsProducer: Error! can't get product " << labelHBHE_;
147  return;
148  }
150 
151  auto ho = iEvent.getHandle(tok_HO_);
152  if (!ho.isValid()) {
153  edm::LogWarning("AlCaDiJets") << "AlCaDiJetsProducer: Error! can't get product " << labelHO_;
154  return;
155  }
157 
158  auto hf = iEvent.getHandle(tok_HF_);
159  if (!hf.isValid()) {
160  edm::LogWarning("AlCaDiJets") << "AlCaDiJetsProducer: Error! can't get product " << labelHF_;
161  return;
162  }
164 
165  // See if this event is useful
166  bool accept = select(pfjets);
167  if (accept) {
168  ++(runCache(iEvent.getRun().index())->nSelect_);
169 
170  //Copy from standard place
171  auto miniPFjetCollection = std::make_unique<reco::PFJetCollection>();
172  for (reco::PFJetCollection::const_iterator pfjetItr = pfjets.begin(); pfjetItr != pfjets.end(); pfjetItr++) {
173  miniPFjetCollection->push_back(*pfjetItr);
174  }
175 
176  auto miniPFCandCollection = std::make_unique<reco::PFCandidateCollection>();
177  for (reco::PFCandidateCollection::const_iterator pfcItr = pfcand.begin(); pfcItr != pfcand.end(); pfcItr++) {
178  miniPFCandCollection->push_back(*pfcItr);
179  }
180 
181  auto miniVtxCollection = std::make_unique<reco::VertexCollection>();
182  for (reco::VertexCollection::const_iterator vtxItr = vtx.begin(); vtxItr != vtx.end(); vtxItr++) {
183  miniVtxCollection->push_back(*vtxItr);
184  }
185 
186  auto miniHBHECollection =
187  std::make_unique<edm::SortedCollection<HBHERecHit, edm::StrictWeakOrdering<HBHERecHit>>>();
189  Hithbhe.begin();
190  hbheItr != Hithbhe.end();
191  hbheItr++) {
192  miniHBHECollection->push_back(*hbheItr);
193  }
194 
195  auto miniHOCollection = std::make_unique<edm::SortedCollection<HORecHit, edm::StrictWeakOrdering<HORecHit>>>();
196  for (edm::SortedCollection<HORecHit, edm::StrictWeakOrdering<HORecHit>>::const_iterator hoItr = Hitho.begin();
197  hoItr != Hitho.end();
198  hoItr++) {
199  miniHOCollection->push_back(*hoItr);
200  }
201 
202  auto miniHFCollection = std::make_unique<edm::SortedCollection<HFRecHit, edm::StrictWeakOrdering<HFRecHit>>>();
203  for (edm::SortedCollection<HFRecHit, edm::StrictWeakOrdering<HFRecHit>>::const_iterator hfItr = Hithf.begin();
204  hfItr != Hithf.end();
205  hfItr++) {
206  miniHFCollection->push_back(*hfItr);
207  }
208 
209  //Put them in the event
210  iEvent.put(std::move(miniPFjetCollection), labelPFJet_.encode());
211  iEvent.put(std::move(miniHBHECollection), labelHBHE_.encode());
212  iEvent.put(std::move(miniHFCollection), labelHF_.encode());
213  iEvent.put(std::move(miniHOCollection), labelHO_.encode());
214  //iEvent.put(std::move(miniTriggerCollection), labelTrigger_.encode());
215  iEvent.put(std::move(miniPFCandCollection), labelPFCandidate_.encode());
216  iEvent.put(std::move(miniVtxCollection), labelVertex_.encode());
217  }
218  return;
219 }
220 
223  desc.add<edm::InputTag>("PFjetInput", edm::InputTag("ak4PFJetsCHS")),
224  desc.add<edm::InputTag>("HBHEInput", edm::InputTag("hbhereco"));
225  desc.add<edm::InputTag>("HFInput", edm::InputTag("hfreco"));
226  desc.add<edm::InputTag>("HOInput", edm::InputTag("horeco"));
227  desc.add<edm::InputTag>("particleFlowInput", edm::InputTag("particleFlow"));
228  desc.add<edm::InputTag>("VertexInput", edm::InputTag("offlinePrimaryVertices"));
229  desc.add<double>("MinPtJet", 20.0);
230  descriptions.add("alcaDiJetsProducer", desc);
231 }
232 
Log< level::Info, true > LogVerbatim
edm::EDGetTokenT< edm::SortedCollection< HBHERecHit, edm::StrictWeakOrdering< HBHERecHit > > > tok_HBHE_
std::atomic< unsigned int > nAll_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::InputTag labelPFCandidate_
std::string encode() const
Definition: InputTag.cc:159
~AlCaDiJetsProducer() override=default
edm::EDGetTokenT< edm::SortedCollection< HORecHit, edm::StrictWeakOrdering< HORecHit > > > tok_HO_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T const * product() const
Definition: Handle.h:70
edm::InputTag labelHBHE_
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
edm::EDGetTokenT< reco::PFJetCollection > tok_PFJet_
std::atomic< unsigned int > nSelect_
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
void globalEndRun(edm::Run const &iRun, edm::EventSetup const &) const override
edm::EDGetTokenT< edm::SortedCollection< HFRecHit, edm::StrictWeakOrdering< HFRecHit > > > tok_HF_
bool select(reco::PFJetCollection) const
int iEvent
Definition: GenABIO.cc:224
edm::InputTag labelPFJet_
edm::EDGetTokenT< reco::VertexCollection > tok_Vertex_
const_iterator begin() const
std::shared_ptr< alcaHcalDiJet::Counters > globalBeginRun(edm::Run const &, edm::EventSetup const &) const override
edm::EDGetTokenT< reco::PFCandidateCollection > tok_PFCand_
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
const_iterator end() const
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool isValid() const
Definition: HandleBase.h:70
std::vector< PFJet > PFJetCollection
collection of PFJet objects
RunIndex index() const
Definition: Run.cc:26
Log< level::Warning, false > LogWarning
AlCaDiJetsProducer(const edm::ParameterSet &)
edm::InputTag labelVertex_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45