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