CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EgammaHLTTimeCleanedRechitProducer.cc
Go to the documentation of this file.
1 // C/C++ headers
2 #include <iostream>
3 #include <vector>
4 #include <memory>
5 
6 // Framework
15 
18 
20 
22 
23  timeMax_ = ps.getParameter<double>("TimeMax");
24  timeMin_ = ps.getParameter<double>("TimeMin");
25  hitLabels = ps.getParameter<std::vector<edm::InputTag>>("ecalhitLabels");
26  productLabels = ps.getParameter<std::vector<std::string>>("productLabels");
27 
28  if (!(hitLabels.size() == 2)) throw cms::Exception("ConfigError","ecalhitLabels should contain 2 labels: one for RecHits in barrel, the other for RecHits in endcaps");
29  if (!(productLabels.size() == 2)) throw cms::Exception("ConfigError","productLabels should contain 2 labels: one for RecHits in barrel, the other for RecHits in endcaps");
30 
31 
32  for (unsigned int i=0; i<hitLabels.size(); i++) {
33  hitTokens.push_back(consumes<EcalRecHitCollection>(hitLabels[i]));
34  produces<EcalRecHitCollection> (productLabels[i]);
35  }
36 }
37 
38 
40 {}
41 
44  std::vector<std::string> productTags;
45  productTags.push_back("EcalTimeCleanedRecHitsEB");
46  productTags.push_back("EcalTimeCleanedRecHitsEE");
47  desc.add<std::vector<std::string>>("productLabels", productTags);
48  std::vector<edm::InputTag> inputTags;
49  inputTags.push_back(edm::InputTag("hltEcalRecHitAll:EcalRecHitsEB"));
50  inputTags.push_back(edm::InputTag("hltEcalRecHitAll:EcalRecHitsEE"));
51  desc.add<std::vector<edm::InputTag>>("ecalhitLabels", inputTags);
52  desc.add<double>("TimeMax", 10);
53  desc.add<double>("TimeMin", -10);
54  descriptions.add(("hltEgammaHLTTimeCleanedRechitProducer"), desc);
55 }
56 
58 
60 
61 
62  for (unsigned int i=0; i<hitLabels.size(); i++) {
63  std::auto_ptr<EcalRecHitCollection> hits(new EcalRecHitCollection);
64 
65  evt.getByToken(hitTokens[i], rhcH[i]);
66  if (!(rhcH[i].isValid())) {
67  edm::LogError("ProductNotFound")<< "could not get a handle on the EcalRecHitCollection! (" << hitLabels[i].encode() << ")" << std::endl;
68  return;
69  }
70  const EcalRecHitCollection* recHits = rhcH[i].product();
71 
73  for (it = recHits->begin(); it != recHits->end(); it++){
74  if (((*it).time() < timeMax_) && ((*it).time() > timeMin_))
75  hits->push_back(*it);
76  }
77 
78  evt.put(hits, productLabels[i]);
79  }
80 }
81 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
EgammaHLTTimeCleanedRechitProducer(const edm::ParameterSet &ps)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
std::vector< EcalRecHit >::const_iterator const_iterator
virtual void produce(edm::Event &, const edm::EventSetup &) override
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const_iterator end() const
T const * product() const
Definition: Handle.h:81
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< edm::EDGetTokenT< EcalRecHitCollection > > hitTokens
const_iterator begin() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)