Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef RECOCALOTOOLS_SELECTORS_CALODUALCONESELECTOR_H
0002 #define RECOCALOTOOLS_SELECTORS_CALODUALCONESELECTOR_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 CaloDualConeSelector
0010   *  
0011   * \author J. Mans - Minnesota
0012   */
0013 template <class T>
0014 class CaloDualConeSelector {
0015 public:
0016   CaloDualConeSelector(double dRmin, double dRmax, const CaloGeometry* geom)
0017       : geom_(geom), deltaRmin_(dRmin), deltaRmax_(dRmax), detector_(DetId::Detector(0)), subdet_(0) {}
0018 
0019   CaloDualConeSelector(double dRmin, double dRmax, const CaloGeometry* geom, DetId::Detector detector, int subdet = 0)
0020       : geom_(geom), deltaRmin_(dRmin), deltaRmax_(dRmax), detector_(detector), subdet_(subdet) {}
0021 
0022   void inline selectCallback(double eta,
0023                              double phi,
0024                              const edm::SortedCollection<T>& inputCollection,
0025                              std::function<void(const T&)> callback) {
0026     GlobalPoint p(GlobalPoint::Cylindrical(1, phi, tanh(eta)));
0027     return selectCallback(p, inputCollection, callback);
0028   }
0029 
0030   void inline selectCallback(const GlobalPoint& p,
0031                              const edm::SortedCollection<T>& inputCollection,
0032                              std::function<void(const T&)> callback) {
0033     // TODO: handle default setting of detector_ (loops over subdet)
0034     // TODO: heuristics of when it is better to loop over inputCollection instead (small # hits)
0035     for (int subdet = subdet_; subdet <= 7 && (subdet_ == 0 || subdet_ == subdet); subdet++) {
0036       const CaloSubdetectorGeometry* sdg = geom_->getSubdetectorGeometry(detector_, subdet);
0037       if (sdg != nullptr) {
0038         // get the list of detids within range (from geometry)
0039         CaloSubdetectorGeometry::DetIdSet dis_excl = sdg->getCells(p, deltaRmin_);
0040         CaloSubdetectorGeometry::DetIdSet dis_all = sdg->getCells(p, deltaRmax_);
0041         // use set operations to determine detids in annulus
0042         CaloSubdetectorGeometry::DetIdSet dis;
0043         std::set_difference(
0044             dis_all.begin(), dis_all.end(), dis_excl.begin(), dis_excl.end(), std::inserter(dis, dis.begin()));
0045 
0046         // loop over detids...
0047         typename edm::SortedCollection<T>::const_iterator j, je = inputCollection.end();
0048 
0049         for (CaloSubdetectorGeometry::DetIdSet::iterator i = dis.begin(); i != dis.end(); i++) {
0050           if (i->subdetId() != subdet)
0051             continue;  // possible for HCAL where the same geometry object handles all the detectors
0052           j = inputCollection.find(*i);
0053           if (j != je)
0054             callback(*j);
0055         }
0056       }
0057     }
0058   }
0059 
0060 private:
0061   const CaloGeometry* geom_;
0062   double deltaRmin_, deltaRmax_;
0063   DetId::Detector detector_;
0064   int subdet_;
0065 };
0066 
0067 #endif