CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/HLTrigger/Muon/src/HLTMuonL2PreFilter.cc

Go to the documentation of this file.
00001 
00009 #include "HLTrigger/Muon/interface/HLTMuonL2PreFilter.h"
00010 #include "HLTrigger/Muon/interface/HLTMuonL2ToL1Map.h"
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 #include "DataFormats/Common/interface/Handle.h"
00013 #include "DataFormats/Common/interface/RefToBase.h"
00014 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00015 #include "DataFormats/TrackReco/interface/Track.h"
00016 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00017 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
00018 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00019 
00020 //
00021 // constructors and destructor
00022 //
00023 
00024 HLTMuonL2PreFilter::HLTMuonL2PreFilter(const edm::ParameterSet& iConfig):
00025   beamSpotTag_( iConfig.getParameter<edm::InputTag>("BeamSpotTag") ),
00026   candTag_( iConfig.getParameter<edm::InputTag >("CandTag") ),
00027   previousCandTag_( iConfig.getParameter<edm::InputTag >("PreviousCandTag") ),
00028   seedMapTag_( iConfig.getParameter<edm::InputTag >("SeedMapTag") ),
00029   minN_( iConfig.getParameter<int>("MinN") ),
00030   maxEta_( iConfig.getParameter<double>("MaxEta") ),
00031   minNhits_( iConfig.getParameter<int>("MinNhits") ),
00032   maxDr_( iConfig.getParameter<double>("MaxDr") ),
00033   maxDz_( iConfig.getParameter<double>("MaxDz") ),
00034   minPt_( iConfig.getParameter<double>("MinPt") ),
00035   nSigmaPt_( iConfig.getParameter<double>("NSigmaPt") ), 
00036   saveTag_( iConfig.getUntrackedParameter<bool>("SaveTag", false) )
00037 {
00038   using namespace std;
00039 
00040   // dump parameters for debugging
00041   if(edm::isDebugEnabled()){
00042     ostringstream ss;
00043     ss<<"Constructed with parameters:"<<endl;
00044     ss<<"    BeamSpotTag = "<<beamSpotTag_.encode()<<endl;
00045     ss<<"    CandTag = "<<candTag_.encode()<<endl;
00046     ss<<"    PreviousCandTag = "<<previousCandTag_.encode()<<endl;
00047     ss<<"    SeedMapTag = "<<seedMapTag_.encode()<<endl;
00048     ss<<"    MinN = "<<minN_<<endl;
00049     ss<<"    MaxEta = "<<maxEta_<<endl;
00050     ss<<"    MinNhits = "<<minNhits_<<endl;
00051     ss<<"    MaxDr = "<<maxDr_<<endl;
00052     ss<<"    MaxDz = "<<maxDz_<<endl;
00053     ss<<"    MinPt = "<<minPt_<<endl;
00054     ss<<"    NSigmaPt = "<<nSigmaPt_<<endl;
00055     ss<<"    SaveTag = "<<saveTag_;
00056     LogDebug("HLTMuonL2PreFilter")<<ss.str();
00057   }
00058 
00059   //register your products
00060   produces<trigger::TriggerFilterObjectWithRefs>();
00061 }
00062 
00063 HLTMuonL2PreFilter::~HLTMuonL2PreFilter()
00064 {
00065 }
00066 
00067 //
00068 // member functions
00069 //
00070 
00071 // ------------ method called to produce the data  ------------
00072 bool HLTMuonL2PreFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00073 {
00074   // All HLT filters must create and fill an HLT filter object,
00075   // recording any reconstructed physics objects satisfying (or not)
00076   // this HLT filter, and place it in the Event.
00077 
00078   using namespace std;
00079   using namespace edm;
00080   using namespace reco;
00081   using namespace trigger;
00082   using namespace l1extra;
00083 
00084   // The filter object
00085   auto_ptr<TriggerFilterObjectWithRefs> filterproduct(new TriggerFilterObjectWithRefs(path(), module()));
00086 
00087   // save Tag
00088   if(saveTag_) filterproduct->addCollectionTag(candTag_);
00089 
00090   // get hold of all muon candidates available at this level
00091   Handle<RecoChargedCandidateCollection> allMuons;
00092   iEvent.getByLabel(candTag_, allMuons);
00093 
00094   // get hold of the beam spot
00095   Handle<BeamSpot> beamSpotHandle;
00096   iEvent.getByLabel(beamSpotTag_, beamSpotHandle);
00097   BeamSpot::Point beamSpot = beamSpotHandle->position();
00098 
00099   // get the L2 to L1 map object for this event
00100   HLTMuonL2ToL1Map mapL2ToL1(previousCandTag_, seedMapTag_, iEvent);
00101 
00102   // look at all allMuons,  check cuts and add to filter object
00103   int n = 0;
00104   for(RecoChargedCandidateCollection::const_iterator cand=allMuons->begin(); cand!=allMuons->end(); cand++){
00105     TrackRef mu = cand->get<TrackRef>();
00106 
00107     // check if this muon passed previous level 
00108     if(!mapL2ToL1.isTriggeredByL1(mu)) continue;
00109 
00110     // eta cut
00111     if(fabs(mu->eta()) > maxEta_) continue;
00112 
00113     // cut on number of hits
00114     if(mu->numberOfValidHits() < minNhits_) continue;
00115 
00116     //dr cut
00117     if(fabs(mu->dxy(beamSpot)) > maxDr_) continue;
00118 
00119     //dz cut
00120     if(fabs(mu->dz(beamSpot)) > maxDz_) continue;
00121 
00122     // Pt threshold cut
00123     double pt = mu->pt();
00124     double abspar0 = fabs(mu->parameter(0));
00125     double ptLx = pt;
00126     // convert 50% efficiency threshold to 90% efficiency threshold
00127     if(abspar0 > 0) ptLx += nSigmaPt_*mu->error(0)/abspar0*pt;
00128     if(ptLx < minPt_) continue;
00129 
00130     // add the good candidate to the filter object
00131     filterproduct->addObject(TriggerMuon, RecoChargedCandidateRef(Ref<RecoChargedCandidateCollection>(allMuons, cand-allMuons->begin())));
00132 
00133     n++;
00134   }
00135 
00136   // filter decision
00137   const bool accept (n >= minN_);
00138    
00139   // dump event for debugging
00140   if(edm::isDebugEnabled()){
00141     ostringstream ss;
00142     ss<<"L2mu#"
00143       <<'\t'<<"q*pt"<<'\t' //scientific is too wide
00144       <<'\t'<<"q*ptLx"<<'\t' //scientific is too wide
00145       <<'\t'<<"eta"
00146       <<'\t'<<"phi"
00147       <<'\t'<<"nHits"
00148       <<'\t'<<"dr"<<'\t' //scientific is too wide
00149       <<'\t'<<"dz"<<'\t' //scientific is too wide
00150       <<'\t'<<"L1seed#"
00151       <<'\t'<<"isPrev"
00152       <<'\t'<<"isFired"
00153       <<endl;
00154     ss<<"-----------------------------------------------------------------------------------------------------------------------"<<endl;
00155     for (RecoChargedCandidateCollection::const_iterator cand = allMuons->begin(); cand != allMuons->end(); cand++) {
00156       TrackRef mu = cand->get<TrackRef>();
00157       ss<<setprecision(2)
00158         <<cand-allMuons->begin()
00159         <<'\t'<<scientific<<mu->charge()*mu->pt()
00160         <<'\t'<<scientific<<mu->charge()*mu->pt()*(1. + ((mu->parameter(0) != 0) ? nSigmaPt_*mu->error(0)/fabs(mu->parameter(0)) : 0.))
00161         <<'\t'<<fixed<<mu->eta()
00162         <<'\t'<<fixed<<mu->phi()
00163         <<'\t'<<mu->numberOfValidHits()
00164         <<'\t'<<scientific<<mu->d0()
00165         <<'\t'<<scientific<<mu->dz()
00166         <<'\t'<<mapL2ToL1.getL1Keys(mu)
00167         <<'\t'<<mapL2ToL1.isTriggeredByL1(mu);
00168       vector<RecoChargedCandidateRef> firedMuons;
00169       filterproduct->getObjects(TriggerMuon, firedMuons);
00170       ss<<'\t'<<(find(firedMuons.begin(), firedMuons.end(), RecoChargedCandidateRef(Ref<RecoChargedCandidateCollection>(allMuons, cand-allMuons->begin()))) != firedMuons.end())
00171         <<endl;
00172     }
00173     ss<<"-----------------------------------------------------------------------------------------------------------------------"<<endl;
00174     ss<<"Decision of filter is "<<accept<<", number of muons passing = "<<filterproduct->muonSize();
00175     LogDebug("HLTMuonL2PreFilter")<<ss.str();
00176   }
00177 
00178   // put filter object into the Event
00179   iEvent.put(filterproduct);
00180    
00181   return accept;
00182 }
00183