CMS 3D CMS Logo

ReducedRecHitCollectionProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ReducedRecHitCollectionProducer
4 // Class: ReducedRecHitCollectionProducer
5 //
14 #include <iostream>
15 #include <memory>
16 
35 
37 public:
42  void produce(edm::Event&, const edm::EventSetup&) override;
43 
44 private:
45  // ----------member data ---------------------------
47  std::vector<edm::EDGetTokenT<DetIdCollection>> interestingDetIdCollections_;
49 };
50 
53 
55  recHitsToken_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitsLabel"));
56 
58  edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag>>("interestingDetIdCollections"),
59  [this](edm::InputTag const& tag) { return consumes<DetIdCollection>(tag); });
60 
61  reducedHitsCollection_ = iConfig.getParameter<std::string>("reducedHitsCollection");
62 
63  //register your products
64  produces<EcalRecHitCollection>(reducedHitsCollection_);
65 }
66 
68 
69 // ------------ method called to produce the data ------------
71  using namespace edm;
72  using namespace std;
73 
74  if (interestingDetIdCollections_.empty()) {
75  edm::LogError("ReducedRecHitCollectionProducer") << "VInputTag collections empty";
76  return;
77  }
78 
80  iEvent.getByToken(interestingDetIdCollections_[0], detIds);
81  std::vector<DetId> xtalsToStore((*detIds).size());
82  std::copy((*detIds).begin(), (*detIds).end(), xtalsToStore.begin());
83 
84  //Merging DetIds from different collections
85  for (unsigned int t = 1; t < interestingDetIdCollections_.size(); ++t) {
87  iEvent.getByToken(interestingDetIdCollections_[t], detId);
88  if (!detId.isValid()) {
89  Labels labels;
90  labelsForToken(interestingDetIdCollections_[t], labels);
91  edm::LogError("MissingInput") << "no reason to skip detid from : (" << labels.module << ", "
92  << labels.productInstance << ", " << labels.process << ")" << std::endl;
93  continue;
94  }
95 
96  for (unsigned int ii = 0; ii < (*detId).size(); ii++) {
97  if (std::find(xtalsToStore.begin(), xtalsToStore.end(), (*detId)[ii]) == xtalsToStore.end())
98  xtalsToStore.push_back((*detId)[ii]);
99  }
100  }
101 
102  Handle<EcalRecHitCollection> recHitsHandle;
103  iEvent.getByToken(recHitsToken_, recHitsHandle);
104  if (!recHitsHandle.isValid()) {
105  edm::LogError("ReducedRecHitCollectionProducer") << "RecHit collection not found";
106  return;
107  }
108 
109  //Create empty output collections
110  auto miniRecHitCollection = std::make_unique<EcalRecHitCollection>();
111 
112  for (unsigned int iCry = 0; iCry < xtalsToStore.size(); iCry++) {
113  EcalRecHitCollection::const_iterator iRecHit = recHitsHandle->find(xtalsToStore[iCry]);
114  if ((iRecHit != recHitsHandle->end()) &&
115  (miniRecHitCollection->find(xtalsToStore[iCry]) == miniRecHitCollection->end()))
116  miniRecHitCollection->push_back(*iRecHit);
117  }
118 
119  std::sort(xtalsToStore.begin(), xtalsToStore.end());
120  std::unique(xtalsToStore.begin(), xtalsToStore.end());
121 
122  // std::cout << "New Collection " << reducedHitsCollection_ << " size is " << miniRecHitCollection->size() << " original is " << recHitsHandle->size() << std::endl;
123  iEvent.put(std::move(miniRecHitCollection), reducedHitsCollection_);
124 }
SummaryClient_cfi.labels
labels
Definition: SummaryClient_cfi.py:61
edm::SortedCollection< EcalRecHit >::const_iterator
std::vector< EcalRecHit >::const_iterator const_iterator
Definition: SortedCollection.h:80
MessageLogger.h
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
ESHandle.h
ReducedRecHitCollectionProducer::~ReducedRecHitCollectionProducer
~ReducedRecHitCollectionProducer() override
Definition: ReducedRecHitCollectionProducer.cc:67
BasicCluster.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
EBDetId.h
EEDetId.h
EDProducer.h
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::Handle
Definition: AssociativeIterator.h:50
ReducedRecHitCollectionProducer::ReducedRecHitCollectionProducer
ReducedRecHitCollectionProducer(const edm::ParameterSet &)
ctor
Definition: ReducedRecHitCollectionProducer.cc:54
EcalRecHitCollections.h
BasicClusterFwd.h
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ReducedRecHitCollectionProducer
Definition: ReducedRecHitCollectionProducer.cc:36
ReducedRecHitCollectionProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
producer
Definition: ReducedRecHitCollectionProducer.cc:70
edm::vector_transform
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
edm::ParameterSet
Definition: ParameterSet.h:47
ReducedRecHitCollectionProducer::recHitsToken_
edm::EDGetTokenT< EcalRecHitCollection > recHitsToken_
Definition: ReducedRecHitCollectionProducer.cc:46
Event.h
makeGlobalPositionRcd_cfg.tag
tag
Definition: makeGlobalPositionRcd_cfg.py:6
edm::SortedCollection::end
const_iterator end() const
Definition: SortedCollection.h:267
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::stream::EDProducer
Definition: EDProducer.h:36
ReducedRecHitCollectionProducer::reducedHitsCollection_
std::string reducedHitsCollection_
Definition: ReducedRecHitCollectionProducer.cc:48
edm::EventSetup
Definition: EventSetup.h:58
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
InputTag.h
CaloTopology.h
CaloSubdetectorTopology.h
CaloTopologyRecord.h
edm::SortedCollection::find
iterator find(key_type k)
Definition: SortedCollection.h:240
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
tier0.unique
def unique(seq, keepstr=True)
Definition: tier0.py:24
transform.h
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ParameterSet.h
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
cuy.ii
ii
Definition: cuy.py:589
edm::InputTag
Definition: InputTag.h:15
ReducedRecHitCollectionProducer::interestingDetIdCollections_
std::vector< edm::EDGetTokenT< DetIdCollection > > interestingDetIdCollections_
Definition: ReducedRecHitCollectionProducer.cc:47
DetIdCollection.h