Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:52

0001 #ifndef RECOCALOTOOLS_SELECTORS_CALOCONESELECTOR_H
0002 #define RECOCALOTOOLS_SELECTORS_CALOCONESELECTOR_H 1
0003 
0004 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0005 #include "DataFormats/Common/interface/SortedCollection.h"
0006 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0007 #include <memory>
0008 
0009 /** \class CaloConeSelector
0010   *  
0011   * \author J. Mans - Minnesota
0012   */
0013 
0014 template <class T>
0015 class CaloConeSelector {
0016 public:
0017   CaloConeSelector(double dR, const CaloGeometry* geom)
0018       : geom_(geom), deltaR_(dR), detector_(DetId::Detector(0)), subdet_(0) {}
0019 
0020   CaloConeSelector(double dR, const CaloGeometry* geom, DetId::Detector detector, int subdet = 0)
0021       : geom_(geom), deltaR_(dR), detector_(detector), subdet_(subdet) {}
0022 
0023   void inline selectCallback(double eta,
0024                              double phi,
0025                              const edm::SortedCollection<T>& inputCollection,
0026                              std::function<void(const T&)> callback) {
0027     GlobalPoint p(GlobalPoint::Cylindrical(1, phi, tanh(eta)));
0028     return selectCallback(p, inputCollection, callback);
0029   }
0030 
0031   void inline selectCallback(const GlobalPoint& p,
0032                              const edm::SortedCollection<T>& inputCollection,
0033                              std::function<void(const T&)> callback) {
0034     // TODO: handle default setting of detector_ (loops over subdet)
0035     // TODO: heuristics of when it is better to loop over inputCollection instead (small # hits)
0036     for (int subdet = subdet_; subdet <= 7 && (subdet_ == 0 || subdet_ == subdet); subdet++) {
0037       const CaloSubdetectorGeometry* sdg = geom_->getSubdetectorGeometry(detector_, subdet);
0038       if (sdg != nullptr) {
0039         // get the list of detids within range (from geometry)
0040         CaloSubdetectorGeometry::DetIdSet dis = sdg->getCells(p, deltaR_);
0041         // loop over detids...
0042         typename edm::SortedCollection<T>::const_iterator j, je = inputCollection.end();
0043 
0044         for (CaloSubdetectorGeometry::DetIdSet::iterator i = dis.begin(); i != dis.end(); i++) {
0045           if (i->subdetId() != subdet)
0046             continue;  // possible for HCAL where the same geometry object handles all the detectors
0047           j = inputCollection.find(*i);
0048           if (j != je)
0049             callback(*j);
0050         }
0051       }
0052     }
0053   }
0054 
0055 private:
0056   const CaloGeometry* geom_;
0057   double deltaR_;
0058   DetId::Detector detector_;
0059   int subdet_;
0060 };
0061 
0062 #endif