Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:37

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 #include <functional>
0009 
0010 /** \class CaloDualConeSelector
0011   *  
0012   * \author J. Mans - Minnesota
0013   */
0014 template <class T>
0015 class CaloDualConeSelector {
0016 public:
0017   CaloDualConeSelector(double dRmin, double dRmax, const CaloGeometry* geom)
0018       : geom_(geom), deltaRmin_(dRmin), deltaRmax_(dRmax), detector_(DetId::Detector(0)), subdet_(0) {}
0019 
0020   CaloDualConeSelector(double dRmin, double dRmax, const CaloGeometry* geom, DetId::Detector detector, int subdet = 0)
0021       : geom_(geom), deltaRmin_(dRmin), deltaRmax_(dRmax), 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_excl = sdg->getCells(p, deltaRmin_);
0041         CaloSubdetectorGeometry::DetIdSet dis_all = sdg->getCells(p, deltaRmax_);
0042         // use set operations to determine detids in annulus
0043         CaloSubdetectorGeometry::DetIdSet dis;
0044         std::set_difference(
0045             dis_all.begin(), dis_all.end(), dis_excl.begin(), dis_excl.end(), std::inserter(dis, dis.begin()));
0046 
0047         // loop over detids...
0048         typename edm::SortedCollection<T>::const_iterator j, je = inputCollection.end();
0049 
0050         for (CaloSubdetectorGeometry::DetIdSet::iterator i = dis.begin(); i != dis.end(); i++) {
0051           if (i->subdetId() != subdet)
0052             continue;  // possible for HCAL where the same geometry object handles all the detectors
0053           j = inputCollection.find(*i);
0054           if (j != je)
0055             callback(*j);
0056         }
0057       }
0058     }
0059   }
0060 
0061 private:
0062   const CaloGeometry* geom_;
0063   double deltaRmin_, deltaRmax_;
0064   DetId::Detector detector_;
0065   int subdet_;
0066 };
0067 
0068 #endif