CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/HLTrigger/special/src/HLTCSCOverlapFilter.cc

Go to the documentation of this file.
00001 #include "HLTrigger/special/interface/HLTCSCOverlapFilter.h"
00002 
00003 #include "DataFormats/Common/interface/Handle.h"
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 
00007 #include "DataFormats/CSCRecHit/interface/CSCRecHit2DCollection.h"
00008 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00009 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
00010 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00011 #include "FWCore/ServiceRegistry/interface/Service.h"
00012 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00013 
00014 HLTCSCOverlapFilter::HLTCSCOverlapFilter(const edm::ParameterSet& iConfig)
00015    : m_input(iConfig.getParameter<edm::InputTag>("input"))
00016      , m_minHits(iConfig.getParameter<unsigned int>("minHits"))
00017      , m_xWindow(iConfig.getParameter<double>("xWindow"))
00018      , m_yWindow(iConfig.getParameter<double>("yWindow"))
00019      , m_ring1(iConfig.getParameter<bool>("ring1"))
00020      , m_ring2(iConfig.getParameter<bool>("ring2"))
00021      , m_fillHists(iConfig.getParameter<bool>("fillHists"))
00022 {
00023    if (m_fillHists) {
00024       edm::Service<TFileService> tfile;
00025       m_nhitsNoWindowCut = tfile->make<TH1F>("nhitsNoWindowCut", "nhitsNoWindowCut", 16, -0.5, 15.5);
00026       m_xdiff = tfile->make<TH1F>("xdiff", "xdiff", 200, 0., 10.);
00027       m_ydiff = tfile->make<TH1F>("ydiff", "ydiff", 200, 0., 10.);
00028       m_pairsWithWindowCut = tfile->make<TH1F>("pairsWithWindowCut", "pairsWithWindowCut", 226, -0.5, 225.5);
00029    }
00030 }
00031 
00032 HLTCSCOverlapFilter::~HLTCSCOverlapFilter() { }
00033 
00034 bool HLTCSCOverlapFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
00035    edm::Handle<CSCRecHit2DCollection> hits;
00036    iEvent.getByLabel(m_input, hits);
00037 
00038    edm::ESHandle<CSCGeometry> cscGeometry;
00039    bool got_cscGeometry = false;
00040 
00041    std::map<int, std::vector<const CSCRecHit2D*> > chamber_tohit;
00042 
00043    for (CSCRecHit2DCollection::const_iterator hit = hits->begin();  hit != hits->end();  ++hit) {
00044       CSCDetId id(hit->geographicalId());
00045       int chamber_id = CSCDetId(id.endcap(), id.station(), id.ring(), id.chamber(), 0).rawId();
00046 
00047       if ((m_ring1  &&  (id.ring() == 1  ||  id.ring() == 4))  ||
00048           (m_ring2  &&  id.ring() == 2)) {
00049          std::map<int, std::vector<const CSCRecHit2D*> >::const_iterator chamber_iter = chamber_tohit.find(chamber_id);
00050          if (chamber_iter == chamber_tohit.end()) {
00051             std::vector<const CSCRecHit2D*> newlist;
00052             newlist.push_back(&(*hit));
00053          }
00054          chamber_tohit[chamber_id].push_back(&(*hit));
00055       } // end if this ring is selected
00056    } // end loop over hits
00057 
00058    bool keep = false;
00059    unsigned int minHitsSquared = m_minHits * m_minHits;
00060    for (std::map<int, std::vector<const CSCRecHit2D*> >::const_iterator chamber_iter = chamber_tohit.begin();
00061         chamber_iter != chamber_tohit.end();
00062         ++chamber_iter) {
00063 
00064       if (m_fillHists) {
00065          m_nhitsNoWindowCut->Fill(chamber_iter->second.size());
00066       }
00067 
00068       if (chamber_iter->second.size() >= m_minHits) {
00069          CSCDetId chamber_id(chamber_iter->first);
00070          int chamber = chamber_id.chamber();
00071          int next = chamber + 1;
00072       
00073          // Some rings have 36 chambers, others have 18.  This will still be valid when ME4/2 is added.
00074          if (next == 37  &&  (std::abs(chamber_id.station()) == 1  ||  chamber_id.ring() == 2)) next = 1;
00075          if (next == 19  &&  (std::abs(chamber_id.station()) != 1  &&  chamber_id.ring() == 1)) next = 1;
00076       
00077          int next_id = CSCDetId(chamber_id.endcap(), chamber_id.station(), chamber_id.ring(), next, 0).rawId();
00078 
00079          std::map<int, std::vector<const CSCRecHit2D*> >::const_iterator chamber_next = chamber_tohit.find(next_id);
00080          if (chamber_next != chamber_tohit.end()  &&  chamber_next->second.size() >= m_minHits) {
00081             if (!got_cscGeometry) {
00082                iSetup.get<MuonGeometryRecord>().get(cscGeometry);
00083                got_cscGeometry = true;
00084             }
00085 
00086             unsigned int pairs_in_window = 0;
00087             for (std::vector<const CSCRecHit2D*>::const_iterator hit1 = chamber_iter->second.begin();  hit1 != chamber_iter->second.end();  ++hit1) {
00088                for (std::vector<const CSCRecHit2D*>::const_iterator hit2 = chamber_next->second.begin();  hit2 != chamber_next->second.end();  ++hit2) {
00089                   GlobalPoint pos1 = cscGeometry->idToDet((*hit1)->geographicalId())->surface().toGlobal((*hit1)->localPosition());
00090                   GlobalPoint pos2 = cscGeometry->idToDet((*hit2)->geographicalId())->surface().toGlobal((*hit2)->localPosition());
00091 
00092                   if (m_fillHists) {
00093                      m_xdiff->Fill(pos1.x() - pos2.x());
00094                      m_ydiff->Fill(pos1.y() - pos2.y());
00095                   }
00096 
00097                   if (fabs(pos1.x() - pos2.x()) < m_xWindow  &&  fabs(pos1.y() - pos2.y()) < m_yWindow) pairs_in_window++;
00098 
00099                   if (pairs_in_window >= minHitsSquared) {
00100                      keep = true;
00101                      if (!m_fillHists) return true;
00102                   }
00103                } // end loop over hits in chamber 2
00104             } // end loop over hits in chamber 1
00105 
00106             if (m_fillHists) {
00107                m_pairsWithWindowCut->Fill(pairs_in_window);
00108             }
00109 
00110          } // end if chamber 2 has enough hits
00111       } // end if chamber 1 has enough hits
00112    } // end loop over chambers
00113 
00114    return keep;
00115 }
00116