CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/RecoCaloTools/Selectors/src/CaloDualConeSelector.cc

Go to the documentation of this file.
00001 #include "RecoCaloTools/Selectors/interface/CaloDualConeSelector.h"
00002 #include "RecoCaloTools/MetaCollections/interface/CaloRecHitMetaCollectionFast.h" 
00003 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00004 
00005 #include <algorithm>
00006 
00007 CaloDualConeSelector::CaloDualConeSelector(double dRmin, double dRmax, const CaloGeometry* geom) :
00008   geom_(geom),deltaRmin_(dRmin),deltaRmax_(dRmax),detector_(DetId::Detector(0)),subdet_(0) {
00009 }
00010 
00011 CaloDualConeSelector::CaloDualConeSelector(double dRmin, double dRmax, const CaloGeometry* geom, DetId::Detector detector, int subdet) : 
00012   geom_(geom),deltaRmin_(dRmin),deltaRmax_(dRmax),detector_(detector),subdet_(subdet) {
00013 }
00014 
00015 std::auto_ptr<CaloRecHitMetaCollectionV> CaloDualConeSelector::select(double eta, double phi, const CaloRecHitMetaCollectionV& inputCollection) {
00016   GlobalPoint p(GlobalPoint::Cylindrical(1,phi,tanh(eta)));
00017   return select(p,inputCollection);
00018 }
00019 
00020 std::auto_ptr<CaloRecHitMetaCollectionV> CaloDualConeSelector::select(const GlobalPoint& p, const CaloRecHitMetaCollectionV& inputCollection) {
00021   CaloRecHitMetaCollectionFast* c=new CaloRecHitMetaCollectionFast();
00022 
00023   // TODO: handle default setting of detector_ (loops over subdet)
00024   // TODO: heuristics of when it is better to loop over inputCollection instead (small # hits)
00025   for (int subdet=subdet_; subdet<=7 && (subdet_==0 || subdet_==subdet); subdet++) {
00026     const CaloSubdetectorGeometry* sdg=geom_->getSubdetectorGeometry(detector_,subdet);
00027     if (sdg!=0) {
00028       // get the list of detids within range (from geometry)
00029       CaloSubdetectorGeometry::DetIdSet dis_excl=sdg->getCells(p,deltaRmin_);
00030       CaloSubdetectorGeometry::DetIdSet dis_all=sdg->getCells(p,deltaRmax_);
00031       // use set operations to determine detids in annulus
00032       CaloSubdetectorGeometry::DetIdSet dis;
00033       std::set_difference(dis_all.begin(),dis_all.end(),
00034                           dis_excl.begin(),dis_excl.end(),
00035                           std::inserter(dis,dis.begin()));
00036       // loop over detids...
00037       CaloRecHitMetaCollectionV::const_iterator j,je=inputCollection.end();      
00038 
00039       for (CaloSubdetectorGeometry::DetIdSet::iterator i=dis.begin(); i!=dis.end(); i++) {
00040         if (i->subdetId()!=subdet) continue; // possible for HCAL where the same geometry object handles all the detectors
00041         j=inputCollection.find(*i);
00042         if (j!=je) c->add(&(*j));
00043       }
00044     }    
00045   }
00046 
00047   return std::auto_ptr<CaloRecHitMetaCollectionV>(c);
00048 }