Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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