CMS 3D CMS Logo

ReducedESRecHitCollectionProducer.cc
Go to the documentation of this file.
15 
16 using namespace edm;
17 using namespace std;
18 using namespace reco;
19 
21  geometry_p(nullptr)
22 {
23 
24  scEtThresh_ = ps.getParameter<double>("scEtThreshold");
25 
27  consumes<ESRecHitCollection>(ps.getParameter<edm::InputTag>("EcalRecHitCollectionES"));
29  consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("EndcapSuperClusterCollection"));
30 
31  OutputLabelES_ = ps.getParameter<std::string>("OutputLabel_ES");
32 
35  ps.getParameter<std::vector<edm::InputTag>>("interestingDetIds"),
36  [this](edm::InputTag const & tag) {
37  return consumes<DetIdCollection>(tag);
38  }
39  );
40 
41  interestingDetIdCollectionsNotToClean_ = edm::vector_transform(ps.getParameter<std::vector<edm::InputTag>>("interestingDetIdsNotToClean"),
42  [this](edm::InputTag const & tag)
43  { return consumes<DetIdCollection>(tag); }
44  );
45 
46  produces< EcalRecHitCollection > (OutputLabelES_);
47 
48 }
49 
51 
53  ESHandle<CaloGeometry> geoHandle;
54  iSetup.get<CaloGeometryRecord>().get(geoHandle);
56  if (!geometry_p){
57  edm::LogError("WrongGeometry")<<
58  "could not cast the subdet geometry to preshower geometry";
59  }
60 
61  if (geometry_p) topology_p = std::make_unique<EcalPreshowerTopology>();
62 
63 }
64 
66 
67 
69  e.getByToken(InputRecHitES_, ESRecHits_);
70 
71  auto output = std::make_unique<EcalRecHitCollection>();
72 
73  edm::Handle<reco::SuperClusterCollection> pEndcapSuperClusters;
74  e.getByToken(InputSuperClusterEE_, pEndcapSuperClusters);
75  {
76  const reco::SuperClusterCollection* eeSuperClusters = pEndcapSuperClusters.product();
77 
78  for (reco::SuperClusterCollection::const_iterator isc = eeSuperClusters->begin(); isc != eeSuperClusters->end(); ++isc) {
79 
80  if (isc->energy() < scEtThresh_) continue;
81  if (fabs(isc->eta()) < 1.65 || fabs(isc->eta()) > 2.6) continue;
82  //cout<<"SC energy : "<<isc->energy()<<" "<<isc->eta()<<endl;
83 
84  //Int_t nBC = 0;
85  reco::CaloCluster_iterator ibc = isc->clustersBegin();
86  for ( ; ibc != isc->clustersEnd(); ++ibc ) {
87 
88  //cout<<"BC : "<<nBC<<endl;
89 
90  const GlobalPoint point((*ibc)->x(),(*ibc)->y(),(*ibc)->z());
91 
94 
95  collectIds(esId1, esId2, 0);
96  collectIds(esId1, esId2, 1);
97  collectIds(esId1, esId2, -1);
98 
99  //nBC++;
100  }
101 
102  }
103 
104  }
105 
106 
108  for( unsigned int t = 0; t < interestingDetIdCollections_.size(); ++t )
109  {
111  if(!detId.isValid())
112  {
113  Labels labels;
114  labelsForToken(interestingDetIdCollections_[t], labels);
115  edm::LogError("MissingInput")<<"no reason to skip detid from : (" << labels.module << ", "
116  << labels.productInstance << ", "
117  << labels.process << ")" << std::endl;
118  continue;
119  }
120  collectedIds_.insert(detId->begin(),detId->end());
121  }
122 
123 
124  //screw it, cant think of a better solution, not the best but lets run over all the rec hits, remove the ones failing cleaning
125  //and then merge in the collection not to be cleaned
126  //mainly as I suspect its more efficient to find an object in the DetIdSet rather than the rec-hit in the rec-hit collecition
127  //with only a det id
128  //if its a CPU issues then revisit
129  for(const auto& hit : *ESRecHits_) {
130  if(hit.recoFlag()==1 || hit.recoFlag()==14 || (hit.recoFlag()<=10 && hit.recoFlag()>=5)){ //right we might need to erase it from the collection
131  auto idIt = collectedIds_.find(hit.id());
132  if(idIt!=collectedIds_.end()) collectedIds_.erase(idIt);
133  }
134  }
135 
136 
137  for(const auto& token : interestingDetIdCollectionsNotToClean_) {
138  e.getByToken(token,detId);
139  if(!detId.isValid()){ //meh might as well keep the warning
140  Labels labels;
141  labelsForToken(token, labels);
142  edm::LogError("MissingInput")<<"no reason to skip detid from : (" << labels.module << ", "
143  << labels.productInstance << ", "
144  << labels.process << ")" << std::endl;
145  continue;
146  }
147  collectedIds_.insert(detId->begin(),detId->end());
148  }
149 
150 
151  output->reserve( collectedIds_.size());
153  for (it = ESRecHits_->begin(); it != ESRecHits_->end(); ++it) {
154  if (collectedIds_.find(it->id())!=collectedIds_.end()){
155  output->push_back(*it);
156  }
157  }
158  collectedIds_.clear();
159 
161 
162 }
163 
164 
165 void ReducedESRecHitCollectionProducer::collectIds(const ESDetId esDetId1, const ESDetId esDetId2, const int & row) {
166 
167  //cout<<row<<endl;
168 
169  map<DetId,const EcalRecHit*>::iterator it;
170  map<DetId, int>::iterator itu;
171  ESDetId next;
172  ESDetId strip1;
173  ESDetId strip2;
174 
175  strip1 = esDetId1;
176  strip2 = esDetId2;
177 
178  EcalPreshowerNavigator theESNav1(strip1, topology_p.get());
179  theESNav1.setHome(strip1);
180 
181  EcalPreshowerNavigator theESNav2(strip2, topology_p.get());
182  theESNav2.setHome(strip2);
183 
184  if (row == 1) {
185  if (strip1 != ESDetId(0)) strip1 = theESNav1.north();
186  if (strip2 != ESDetId(0)) strip2 = theESNav2.east();
187  } else if (row == -1) {
188  if (strip1 != ESDetId(0)) strip1 = theESNav1.south();
189  if (strip2 != ESDetId(0)) strip2 = theESNav2.west();
190  }
191 
192  // Plane 1
193  if (strip1 == ESDetId(0)) {
194  } else {
195  collectedIds_.insert(strip1);
196  //cout<<"center : "<<strip1<<endl;
197  // east road
198  for (int i=0; i<15; ++i) {
199  next = theESNav1.east();
200  //cout<<"east : "<<i<<" "<<next<<endl;
201  if (next != ESDetId(0)) {
202  collectedIds_.insert(next);
203  } else {
204  break;
205  }
206  }
207 
208  // west road
209  theESNav1.setHome(strip1);
210  theESNav1.home();
211  for (int i=0; i<15; ++i) {
212  next = theESNav1.west();
213  //cout<<"west : "<<i<<" "<<next<<endl;
214  if (next != ESDetId(0)) {
215  collectedIds_.insert(next);
216  } else {
217  break;
218  }
219  }
220 
221  }
222 
223  if (strip2 == ESDetId(0)) {
224  } else {
225  collectedIds_.insert(strip2);
226  //cout<<"center : "<<strip2<<endl;
227  // north road
228  for (int i=0; i<15; ++i) {
229  next = theESNav2.north();
230  //cout<<"north : "<<i<<" "<<next<<endl;
231  if (next != ESDetId(0)) {
232  collectedIds_.insert(next);
233  } else {
234  break;
235  }
236  }
237 
238  // south road
239  theESNav2.setHome(strip2);
240  theESNav2.home();
241  for (int i=0; i<15; ++i) {
242  next = theESNav2.south();
243  //cout<<"south : "<<i<<" "<<next<<endl;
244  if (next != ESDetId(0)) {
245  collectedIds_.insert(next);
246  } else {
247  break;
248  }
249  }
250  }
251 }
252 
253 
T getParameter(std::string const &) const
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:49
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
void beginRun(edm::Run const &, const edm::EventSetup &) final
const_iterator end() const
Definition: EDCollection.h:153
std::vector< edm::EDGetTokenT< DetIdCollection > > interestingDetIdCollectionsNotToClean_
#define nullptr
std::vector< edm::EDGetTokenT< DetIdCollection > > interestingDetIdCollections_
std::vector< EcalRecHit >::const_iterator const_iterator
void collectIds(const ESDetId strip1, const ESDetId strip2, const int &row=0)
void setHome(const T &startingPoint)
set the starting position
std::unique_ptr< CaloSubdetectorTopology > topology_p
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
virtual DetId getClosestCellInPlane(const GlobalPoint &r, int plane) const
bool isValid() const
Definition: HandleBase.h:74
unsigned int id
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
const_iterator begin() const
Definition: EDCollection.h:146
edm::EDGetTokenT< ESRecHitCollection > InputRecHitES_
void produce(edm::Event &e, const edm::EventSetup &c) override
edm::EDGetTokenT< reco::SuperClusterCollection > InputSuperClusterEE_
fixed size matrix
HLT enums.
T get() const
Definition: EventSetup.h:71
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