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 }
ReducedESRecHitCollectionProducer::InputRecHitES_
edm::EDGetTokenT< ESRecHitCollection > InputRecHitES_
Definition: ReducedESRecHitCollectionProducer.cc:45
EcalPreshowerTopology.h
SummaryClient_cfi.labels
labels
Definition: SummaryClient_cfi.py:61
edm::EDCollection::begin
const_iterator begin() const
Definition: EDCollection.h:117
Handle.h
mps_fire.i
i
Definition: mps_fire.py:428
edm::SortedCollection< EcalRecHit >::const_iterator
std::vector< EcalRecHit >::const_iterator const_iterator
Definition: SortedCollection.h:80
MessageLogger.h
hit::id
unsigned int id
Definition: SiStripHitEffFromCalibTree.cc:92
edm::Handle::product
T const * product() const
Definition: Handle.h:70
ReducedESRecHitCollectionProducer::beginRun
void beginRun(edm::Run const &, const edm::EventSetup &) final
Definition: ReducedESRecHitCollectionProducer.cc:87
ESHandle.h
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
edm::Run
Definition: Run.h:45
BasicCluster.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
CaloGeometry::getSubdetectorGeometry
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
ReducedESRecHitCollectionProducer::produce
void produce(edm::Event &e, const edm::EventSetup &c) override
Definition: ReducedESRecHitCollectionProducer.cc:99
edm::PtrVectorItr
Definition: PtrVector.h:51
EDProducer.h
ESDetId
Definition: ESDetId.h:15
ESDetId.h
ReducedESRecHitCollectionProducer::caloGeometryToken_
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
Definition: ReducedESRecHitCollectionProducer.cc:47
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
edm::Handle
Definition: AssociativeIterator.h:50
ESGetToken.h
EcalRecHitCollections.h
reco::SuperClusterCollection
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
Definition: SuperClusterFwd.h:9
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ReducedESRecHitCollectionProducer::collectIds
void collectIds(const ESDetId strip1, const ESDetId strip2, const int &row=0)
Definition: ReducedESRecHitCollectionProducer.cc:188
EcalPreshowerGeometry
Definition: EcalPreshowerGeometry.h:15
edm::ESHandle< CaloGeometry >
ReducedESRecHitCollectionProducer::InputSuperClusterEE_
edm::EDGetTokenT< reco::SuperClusterCollection > InputSuperClusterEE_
Definition: ReducedESRecHitCollectionProducer.cc:46
CaloNavigator::setHome
void setHome(const T &startingPoint)
set the starting position
Definition: CaloNavigator.h:90
ReducedESRecHitCollectionProducer::topology_p
std::unique_ptr< CaloSubdetectorTopology > topology_p
Definition: ReducedESRecHitCollectionProducer.cc:41
EcalPreshowerGeometry.h
Point3DBase< float, GlobalTag >
CaloGeometryRecord.h
ReducedESRecHitCollectionProducer::scEtThresh_
double scEtThresh_
Definition: ReducedESRecHitCollectionProducer.cc:43
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
EcalPreshowerGeometry::getClosestCellInPlane
virtual DetId getClosestCellInPlane(const GlobalPoint &r, int plane) const
Definition: EcalPreshowerGeometry.cc:139
EcalPreshowerNavigator.h
CaloSubdetectorGeometry.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
makeGlobalPositionRcd_cfg.tag
tag
Definition: makeGlobalPositionRcd_cfg.py:6
ReducedESRecHitCollectionProducer::geometry_p
const EcalPreshowerGeometry * geometry_p
Definition: ReducedESRecHitCollectionProducer.cc:40
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
ReducedESRecHitCollectionProducer::ReducedESRecHitCollectionProducer
ReducedESRecHitCollectionProducer(const edm::ParameterSet &pset)
Definition: ReducedESRecHitCollectionProducer.cc:63
edm::stream::EDProducer
Definition: EDProducer.h:36
edm::EventSetup
Definition: EventSetup.h:58
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
DetId::Ecal
Definition: DetId.h:27
ReducedESRecHitCollectionProducer::interestingDetIdCollectionsNotToClean_
std::vector< edm::EDGetTokenT< DetIdCollection > > interestingDetIdCollectionsNotToClean_
Definition: ReducedESRecHitCollectionProducer.cc:51
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ESGetToken< CaloGeometry, CaloGeometryRecord >
ReducedESRecHitCollectionProducer::interestingDetIdCollections_
std::vector< edm::EDGetTokenT< DetIdCollection > > interestingDetIdCollections_
Definition: ReducedESRecHitCollectionProducer.cc:49
ReducedESRecHitCollectionProducer::collectedIds_
std::set< DetId > collectedIds_
Definition: ReducedESRecHitCollectionProducer.cc:53
ReducedESRecHitCollectionProducer::OutputLabelES_
std::string OutputLabelES_
Definition: ReducedESRecHitCollectionProducer.cc:48
EcalPreshower
Definition: EcalSubdetector.h:10
CaloNavigator
Definition: CaloNavigator.h:7
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
SuperClusterFwd.h
DetId.h
transform.h
SuperCluster.h
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
ParameterSet.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
point
*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
edm::Event
Definition: Event.h:73
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
ReducedESRecHitCollectionProducer::~ReducedESRecHitCollectionProducer
~ReducedESRecHitCollectionProducer() override
edm::InputTag
Definition: InputTag.h:15
edm::EDCollection::end
const_iterator end() const
Definition: EDCollection.h:122
DetIdCollection.h
ReducedESRecHitCollectionProducer
Definition: ReducedESRecHitCollectionProducer.cc:31
hit
Definition: SiStripHitEffFromCalibTree.cc:88
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
GetRecoTauVFromDQM_MC_cff.next
next
Definition: GetRecoTauVFromDQM_MC_cff.py:31
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316