CMS 3D CMS Logo

ReducedESRecHitCollectionProducer.cc
Go to the documentation of this file.
24 
25 #include <iostream>
26 #include <map>
27 #include <set>
28 #include <string>
29 #include <vector>
30 
32 public:
35  void beginRun(edm::Run const&, const edm::EventSetup&) final;
36  void produce(edm::Event& e, const edm::EventSetup& c) override;
37  void collectIds(const ESDetId strip1, const ESDetId strip2, const int& row = 0);
38 
39 private:
41  std::unique_ptr<CaloSubdetectorTopology> topology_p;
42 
43  double scEtThresh_;
44 
49  std::vector<edm::EDGetTokenT<DetIdCollection>> interestingDetIdCollections_;
50  std::vector<edm::EDGetTokenT<DetIdCollection>>
51  interestingDetIdCollectionsNotToClean_; //theres a hard coded cut on rec-hit quality which some collections would prefer not to have...
52 
53  std::set<DetId> collectedIds_;
54 };
55 
58 
59 using namespace edm;
60 using namespace std;
61 using namespace reco;
62 
64  : geometry_p(nullptr) {
65  scEtThresh_ = ps.getParameter<double>("scEtThreshold");
66 
67  InputRecHitES_ = consumes<ESRecHitCollection>(ps.getParameter<edm::InputTag>("EcalRecHitCollectionES"));
69  consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("EndcapSuperClusterCollection"));
70  caloGeometryToken_ = esConsumes<CaloGeometry, CaloGeometryRecord, edm::Transition::BeginRun>();
71 
72  OutputLabelES_ = ps.getParameter<std::string>("OutputLabel_ES");
73 
75  edm::vector_transform(ps.getParameter<std::vector<edm::InputTag>>("interestingDetIds"),
76  [this](edm::InputTag const& tag) { return consumes<DetIdCollection>(tag); });
77 
79  edm::vector_transform(ps.getParameter<std::vector<edm::InputTag>>("interestingDetIdsNotToClean"),
80  [this](edm::InputTag const& tag) { return consumes<DetIdCollection>(tag); });
81 
82  produces<EcalRecHitCollection>(OutputLabelES_);
83 }
84 
86 
89  geometry_p =
90  dynamic_cast<const EcalPreshowerGeometry*>(geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower));
91  if (!geometry_p) {
92  edm::LogError("WrongGeometry") << "could not cast the subdet geometry to preshower geometry";
93  }
94 
95  if (geometry_p)
96  topology_p = std::make_unique<EcalPreshowerTopology>();
97 }
98 
101  e.getByToken(InputRecHitES_, ESRecHits_);
102 
103  auto output = std::make_unique<EcalRecHitCollection>();
104 
105  edm::Handle<reco::SuperClusterCollection> pEndcapSuperClusters;
106  e.getByToken(InputSuperClusterEE_, pEndcapSuperClusters);
107  {
108  const reco::SuperClusterCollection* eeSuperClusters = pEndcapSuperClusters.product();
109 
110  for (reco::SuperClusterCollection::const_iterator isc = eeSuperClusters->begin(); isc != eeSuperClusters->end();
111  ++isc) {
112  if (isc->energy() < scEtThresh_)
113  continue;
114  if (fabs(isc->eta()) < 1.65 || fabs(isc->eta()) > 2.6)
115  continue;
116  //cout<<"SC energy : "<<isc->energy()<<" "<<isc->eta()<<endl;
117 
118  //Int_t nBC = 0;
119  reco::CaloCluster_iterator ibc = isc->clustersBegin();
120  for (; ibc != isc->clustersEnd(); ++ibc) {
121  //cout<<"BC : "<<nBC<<endl;
122 
123  const GlobalPoint point((*ibc)->x(), (*ibc)->y(), (*ibc)->z());
124 
127 
128  collectIds(esId1, esId2, 0);
129  collectIds(esId1, esId2, 1);
130  collectIds(esId1, esId2, -1);
131 
132  //nBC++;
133  }
134  }
135  }
136 
138  for (unsigned int t = 0; t < interestingDetIdCollections_.size(); ++t) {
139  e.getByToken(interestingDetIdCollections_[t], detId);
140  if (!detId.isValid()) {
141  Labels labels;
142  labelsForToken(interestingDetIdCollections_[t], labels);
143  edm::LogError("MissingInput") << "no reason to skip detid from : (" << labels.module << ", "
144  << labels.productInstance << ", " << labels.process << ")" << std::endl;
145  continue;
146  }
147  collectedIds_.insert(detId->begin(), detId->end());
148  }
149 
150  //screw it, cant think of a better solution, not the best but lets run over all the rec hits, remove the ones failing cleaning
151  //and then merge in the collection not to be cleaned
152  //mainly as I suspect its more efficient to find an object in the DetIdSet rather than the rec-hit in the rec-hit collecition
153  //with only a det id
154  //if its a CPU issues then revisit
155  for (const auto& hit : *ESRecHits_) {
156  if (hit.recoFlag() == 1 || hit.recoFlag() == 14 ||
157  (hit.recoFlag() <= 10 && hit.recoFlag() >= 5)) { //right we might need to erase it from the collection
158  auto idIt = collectedIds_.find(hit.id());
159  if (idIt != collectedIds_.end())
160  collectedIds_.erase(idIt);
161  }
162  }
163 
164  for (const auto& token : interestingDetIdCollectionsNotToClean_) {
165  e.getByToken(token, detId);
166  if (!detId.isValid()) { //meh might as well keep the warning
167  Labels labels;
168  labelsForToken(token, labels);
169  edm::LogError("MissingInput") << "no reason to skip detid from : (" << labels.module << ", "
170  << labels.productInstance << ", " << labels.process << ")" << std::endl;
171  continue;
172  }
173  collectedIds_.insert(detId->begin(), detId->end());
174  }
175 
176  output->reserve(collectedIds_.size());
178  for (it = ESRecHits_->begin(); it != ESRecHits_->end(); ++it) {
179  if (collectedIds_.find(it->id()) != collectedIds_.end()) {
180  output->push_back(*it);
181  }
182  }
183  collectedIds_.clear();
184 
186 }
187 
188 void ReducedESRecHitCollectionProducer::collectIds(const ESDetId esDetId1, const ESDetId esDetId2, const int& row) {
189  //cout<<row<<endl;
190 
191  map<DetId, const EcalRecHit*>::iterator it;
192  map<DetId, int>::iterator itu;
193  ESDetId next;
194  ESDetId strip1;
195  ESDetId strip2;
196 
197  strip1 = esDetId1;
198  strip2 = esDetId2;
199 
200  EcalPreshowerNavigator theESNav1(strip1, topology_p.get());
201  theESNav1.setHome(strip1);
202 
203  EcalPreshowerNavigator theESNav2(strip2, topology_p.get());
204  theESNav2.setHome(strip2);
205 
206  if (row == 1) {
207  if (strip1 != ESDetId(0))
208  strip1 = theESNav1.north();
209  if (strip2 != ESDetId(0))
210  strip2 = theESNav2.east();
211  } else if (row == -1) {
212  if (strip1 != ESDetId(0))
213  strip1 = theESNav1.south();
214  if (strip2 != ESDetId(0))
215  strip2 = theESNav2.west();
216  }
217 
218  // Plane 1
219  if (strip1 == ESDetId(0)) {
220  } else {
221  collectedIds_.insert(strip1);
222  //cout<<"center : "<<strip1<<endl;
223  // east road
224  for (int i = 0; i < 15; ++i) {
225  next = theESNav1.east();
226  //cout<<"east : "<<i<<" "<<next<<endl;
227  if (next != ESDetId(0)) {
228  collectedIds_.insert(next);
229  } else {
230  break;
231  }
232  }
233 
234  // west road
235  theESNav1.setHome(strip1);
236  theESNav1.home();
237  for (int i = 0; i < 15; ++i) {
238  next = theESNav1.west();
239  //cout<<"west : "<<i<<" "<<next<<endl;
240  if (next != ESDetId(0)) {
241  collectedIds_.insert(next);
242  } else {
243  break;
244  }
245  }
246  }
247 
248  if (strip2 == ESDetId(0)) {
249  } else {
250  collectedIds_.insert(strip2);
251  //cout<<"center : "<<strip2<<endl;
252  // north road
253  for (int i = 0; i < 15; ++i) {
254  next = theESNav2.north();
255  //cout<<"north : "<<i<<" "<<next<<endl;
256  if (next != ESDetId(0)) {
257  collectedIds_.insert(next);
258  } else {
259  break;
260  }
261  }
262 
263  // south road
264  theESNav2.setHome(strip2);
265  theESNav2.home();
266  for (int i = 0; i < 15; ++i) {
267  next = theESNav2.south();
268  //cout<<"south : "<<i<<" "<<next<<endl;
269  if (next != ESDetId(0)) {
270  collectedIds_.insert(next);
271  } else {
272  break;
273  }
274  }
275  }
276 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void beginRun(edm::Run const &, const edm::EventSetup &) final
std::vector< edm::EDGetTokenT< DetIdCollection > > interestingDetIdCollectionsNotToClean_
std::vector< edm::EDGetTokenT< DetIdCollection > > interestingDetIdCollections_
std::vector< EcalRecHit >::const_iterator const_iterator
Log< level::Error, false > LogError
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
void collectIds(const ESDetId strip1, const ESDetId strip2, const int &row=0)
void setHome(const T &startingPoint)
set the starting position
Definition: CaloNavigator.h:90
std::unique_ptr< CaloSubdetectorTopology > topology_p
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
const_iterator begin() const
Definition: EDCollection.h:117
unsigned int id
edm::EDGetTokenT< ESRecHitCollection > InputRecHitES_
void produce(edm::Event &e, const edm::EventSetup &c) override
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
edm::EDGetTokenT< reco::SuperClusterCollection > InputSuperClusterEE_
bool isValid() const
Definition: HandleBase.h:70
fixed size matrix
HLT enums.
virtual DetId getClosestCellInPlane(const GlobalPoint &r, int plane) const
Definition: output.py:1
const_iterator end() const
Definition: EDCollection.h:122
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
ReducedESRecHitCollectionProducer(const edm::ParameterSet &pset)
def move(src, dest)
Definition: eostools.py:511
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
Definition: Run.h:45