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(0),
22  topology_p(0)
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  geometry_p = dynamic_cast<const EcalPreshowerGeometry *>(geometry);
60  if (!geometry_p){
61  edm::LogError("WrongGeometry")<<
62  "could not cast the subdet geometry to preshower geometry";
63  }
64 
65  if (geometry) topology_p = new EcalPreshowerTopology(geoHandle);
66 
67 }
68 
70 
71 
73  e.getByToken(InputRecHitES_, ESRecHits_);
74 
75  auto output = std::make_unique<EcalRecHitCollection>();
76 
77  edm::Handle<reco::SuperClusterCollection> pEndcapSuperClusters;
78  e.getByToken(InputSuperClusterEE_, pEndcapSuperClusters);
79  {
80  const reco::SuperClusterCollection* eeSuperClusters = pEndcapSuperClusters.product();
81 
82  for (reco::SuperClusterCollection::const_iterator isc = eeSuperClusters->begin(); isc != eeSuperClusters->end(); ++isc) {
83 
84  if (isc->energy() < scEtThresh_) continue;
85  if (fabs(isc->eta()) < 1.65 || fabs(isc->eta()) > 2.6) continue;
86  //cout<<"SC energy : "<<isc->energy()<<" "<<isc->eta()<<endl;
87 
88  //Int_t nBC = 0;
89  reco::CaloCluster_iterator ibc = isc->clustersBegin();
90  for ( ; ibc != isc->clustersEnd(); ++ibc ) {
91 
92  //cout<<"BC : "<<nBC<<endl;
93 
94  const GlobalPoint point((*ibc)->x(),(*ibc)->y(),(*ibc)->z());
95 
98 
99  collectIds(esId1, esId2, 0);
100  collectIds(esId1, esId2, 1);
101  collectIds(esId1, esId2, -1);
102 
103  //nBC++;
104  }
105 
106  }
107 
108  }
109 
110 
112  for( unsigned int t = 0; t < interestingDetIdCollections_.size(); ++t )
113  {
115  if(!detId.isValid())
116  {
117  Labels labels;
119  edm::LogError("MissingInput")<<"no reason to skip detid from : (" << labels.module << ", "
120  << labels.productInstance << ", "
121  << labels.process << ")" << std::endl;
122  continue;
123  }
124  collectedIds_.insert(detId->begin(),detId->end());
125  }
126 
127 
128  //screw it, cant think of a better solution, not the best but lets run over all the rec hits, remove the ones failing cleaning
129  //and then merge in the collection not to be cleaned
130  //mainly as I suspect its more efficient to find an object in the DetIdSet rather than the rec-hit in the rec-hit collecition
131  //with only a det id
132  //if its a CPU issues then revisit
133  for(const auto& hit : *ESRecHits_) {
134  if(hit.recoFlag()==1 || hit.recoFlag()==14 || (hit.recoFlag()<=10 && hit.recoFlag()>=5)){ //right we might need to erase it from the collection
135  auto idIt = collectedIds_.find(hit.id());
136  if(idIt!=collectedIds_.end()) collectedIds_.erase(idIt);
137  }
138  }
139 
140 
141  for(const auto& token : interestingDetIdCollectionsNotToClean_) {
142  e.getByToken(token,detId);
143  if(!detId.isValid()){ //meh might as well keep the warning
144  Labels labels;
145  labelsForToken(token, labels);
146  edm::LogError("MissingInput")<<"no reason to skip detid from : (" << labels.module << ", "
147  << labels.productInstance << ", "
148  << labels.process << ")" << std::endl;
149  continue;
150  }
151  collectedIds_.insert(detId->begin(),detId->end());
152  }
153 
154 
155  output->reserve( collectedIds_.size());
157  for (it = ESRecHits_->begin(); it != ESRecHits_->end(); ++it) {
158  if (collectedIds_.find(it->id())!=collectedIds_.end()){
159  output->push_back(*it);
160  }
161  }
162  collectedIds_.clear();
163 
165 
166 }
167 
168 
169 void ReducedESRecHitCollectionProducer::collectIds(const ESDetId esDetId1, const ESDetId esDetId2, const int & row) {
170 
171  //cout<<row<<endl;
172 
173  map<DetId,const EcalRecHit*>::iterator it;
174  map<DetId, int>::iterator itu;
175  ESDetId next;
176  ESDetId strip1;
177  ESDetId strip2;
178 
179  strip1 = esDetId1;
180  strip2 = esDetId2;
181 
182  EcalPreshowerNavigator theESNav1(strip1, topology_p);
183  theESNav1.setHome(strip1);
184 
185  EcalPreshowerNavigator theESNav2(strip2, topology_p);
186  theESNav2.setHome(strip2);
187 
188  if (row == 1) {
189  if (strip1 != ESDetId(0)) strip1 = theESNav1.north();
190  if (strip2 != ESDetId(0)) strip2 = theESNav2.east();
191  } else if (row == -1) {
192  if (strip1 != ESDetId(0)) strip1 = theESNav1.south();
193  if (strip2 != ESDetId(0)) strip2 = theESNav2.west();
194  }
195 
196  // Plane 1
197  if (strip1 == ESDetId(0)) {
198  } else {
199  collectedIds_.insert(strip1);
200  //cout<<"center : "<<strip1<<endl;
201  // east road
202  for (int i=0; i<15; ++i) {
203  next = theESNav1.east();
204  //cout<<"east : "<<i<<" "<<next<<endl;
205  if (next != ESDetId(0)) {
206  collectedIds_.insert(next);
207  } else {
208  break;
209  }
210  }
211 
212  // west road
213  theESNav1.setHome(strip1);
214  theESNav1.home();
215  for (int i=0; i<15; ++i) {
216  next = theESNav1.west();
217  //cout<<"west : "<<i<<" "<<next<<endl;
218  if (next != ESDetId(0)) {
219  collectedIds_.insert(next);
220  } else {
221  break;
222  }
223  }
224 
225  }
226 
227  if (strip2 == ESDetId(0)) {
228  } else {
229  collectedIds_.insert(strip2);
230  //cout<<"center : "<<strip2<<endl;
231  // north road
232  for (int i=0; i<15; ++i) {
233  next = theESNav2.north();
234  //cout<<"north : "<<i<<" "<<next<<endl;
235  if (next != ESDetId(0)) {
236  collectedIds_.insert(next);
237  } else {
238  break;
239  }
240  }
241 
242  // south road
243  theESNav2.setHome(strip2);
244  theESNav2.home();
245  for (int i=0; i<15; ++i) {
246  next = theESNav2.south();
247  //cout<<"south : "<<i<<" "<<next<<endl;
248  if (next != ESDetId(0)) {
249  collectedIds_.insert(next);
250  } else {
251  break;
252  }
253  }
254  }
255 }
256 
257 
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:45
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
virtual void beginRun(edm::Run const &, const edm::EventSetup &) override final
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
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
void collectIds(const ESDetId strip1, const ESDetId strip2, const int &row=0)
char const * process
Definition: ProductLabels.h:7
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
char const * module
Definition: ProductLabels.h:5
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
const T & get() const
Definition: EventSetup.h:56
edm::EDGetTokenT< reco::SuperClusterCollection > InputSuperClusterEE_
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
ESHandle< TrackerGeometry > geometry
char const * productInstance
Definition: ProductLabels.h:6
fixed size matrix
HLT enums.
T north() const
move the navigator north
Definition: CaloNavigator.h:38
ReducedESRecHitCollectionProducer(const edm::ParameterSet &pset)
def move(src, dest)
Definition: eostools.py:510
*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:42