CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 
00009 #include "HLTrigger/Muon/interface/HLTMuonL1toL3TkPreFilter.h"
00010 
00011 #include "DataFormats/Common/interface/Handle.h"
00012 #include "DataFormats/Common/interface/RefToBase.h"
00013 
00014 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00015 #include "DataFormats/HLTReco/interface/TriggerRefsCollections.h"
00016 
00017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00018 #include "DataFormats/TrackReco/interface/Track.h"
00019 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00020 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
00021 #include "DataFormats/MuonReco/interface/MuonTrackLinks.h"
00022 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00023 #include "DataFormats/MuonSeed/interface/L3MuonTrajectorySeed.h"
00024 #include "DataFormats/MuonSeed/interface/L3MuonTrajectorySeedCollection.h"
00025 
00026 //
00027 // constructors and destructor
00028 //
00029 using namespace std;
00030 using namespace edm;
00031 using namespace reco;
00032 using namespace trigger;
00033 
00034 HLTMuonL1toL3TkPreFilter::HLTMuonL1toL3TkPreFilter(const ParameterSet& iConfig) :
00035    beamspotTag_   (iConfig.getParameter< edm::InputTag > ("BeamSpotTag")),
00036    candTag_   (iConfig.getParameter<InputTag > ("CandTag")),
00037    previousCandTag_   (iConfig.getParameter<InputTag > ("PreviousCandTag")),
00038    min_N_     (iConfig.getParameter<int> ("MinN")),
00039    max_Eta_   (iConfig.getParameter<double> ("MaxEta")),
00040    min_Nhits_ (iConfig.getParameter<int> ("MinNhits")),
00041    max_Dr_    (iConfig.getParameter<double> ("MaxDr")),
00042    max_Dz_    (iConfig.getParameter<double> ("MaxDz")),
00043    min_Pt_    (iConfig.getParameter<double> ("MinPt")),
00044    nsigma_Pt_  (iConfig.getParameter<double> ("NSigmaPt")), 
00045    saveTag_  (iConfig.getUntrackedParameter<bool> ("SaveTag",true)) 
00046 {
00047 
00048    LogDebug("HLTMuonL1toL3TkPreFilter")
00049       << " CandTag/MinN/MaxEta/MinNhits/MaxDr/MaxDz/MinPt/NSigmaPt : " 
00050       << candTag_.encode()
00051       << " " << min_N_ 
00052       << " " << max_Eta_
00053       << " " << min_Nhits_
00054       << " " << max_Dr_
00055       << " " << max_Dz_
00056       << " " << min_Pt_
00057       << " " << nsigma_Pt_;
00058 
00059    //register your products
00060    produces<TriggerFilterObjectWithRefs>();
00061 }
00062 
00063 HLTMuonL1toL3TkPreFilter::~HLTMuonL1toL3TkPreFilter()
00064 {
00065 }
00066 
00067 //
00068 // member functions
00069 //
00070 
00071 // ------------ method called to produce the data  ------------
00072 bool
00073 HLTMuonL1toL3TkPreFilter::filter(Event& iEvent, const EventSetup& iSetup)
00074 {
00075 
00076    // All HLT filters must create and fill an HLT filter object,
00077    // recording any reconstructed physics objects satisfying (or not)
00078    // this HLT filter, and place it in the Event.
00079 
00080    // The filter object
00081    auto_ptr<TriggerFilterObjectWithRefs>
00082      filterproduct (new TriggerFilterObjectWithRefs(path(),module()));
00083 
00084    // get hold of trks
00085    //   Handle<reco::TrackCollection> mucands;
00086    Handle<RecoChargedCandidateCollection> mucands;
00087    iEvent.getByLabel(candTag_,mucands);
00088    if(saveTag_)filterproduct->addCollectionTag(candTag_);
00089    // sort them by L2Track
00090    std::map<l1extra::L1MuonParticleRef, std::vector<RecoChargedCandidateRef> > L1toL3s;
00091    unsigned int n = 0;
00092    unsigned int maxN = mucands->size();
00093    for (;n!=maxN;n++){
00094      TrackRef tk = (*mucands)[n].track();
00095      edm::Ref<L3MuonTrajectorySeedCollection> l3seedRef = tk->seedRef().castTo<edm::Ref<L3MuonTrajectorySeedCollection> >();
00096      l1extra::L1MuonParticleRef l1mu = l3seedRef->l1Particle();
00097        L1toL3s[l1mu].push_back(RecoChargedCandidateRef(mucands,n));
00098    }
00099 
00100    // additionnal objects needed
00101    Handle<TriggerFilterObjectWithRefs> previousLevelCands;
00102    iEvent.getByLabel (previousCandTag_,previousLevelCands);
00103    BeamSpot beamSpot;
00104    Handle<BeamSpot> recoBeamSpotHandle;
00105    iEvent.getByLabel(beamspotTag_,recoBeamSpotHandle);
00106    beamSpot = *recoBeamSpotHandle;
00107 
00108 
00109    //needed to compare to L1 
00110    vector<l1extra::L1MuonParticleRef> vl1cands;
00111    previousLevelCands->getObjects(TriggerL1Mu,vl1cands);
00112 
00113    std::map<l1extra::L1MuonParticleRef, std::vector<RecoChargedCandidateRef> > ::iterator L1toL3s_it = L1toL3s.begin();
00114    std::map<l1extra::L1MuonParticleRef, std::vector<RecoChargedCandidateRef> > ::iterator L1toL3s_end = L1toL3s.end();
00115    for (; L1toL3s_it!=L1toL3s_end; ++L1toL3s_it){
00116      
00117      if (!triggeredAtL1(L1toL3s_it->first,vl1cands)) continue;
00118      
00119      //loop over the L3Tk reconstructed for this L1.
00120      unsigned int iTk=0;
00121      unsigned int maxItk=L1toL3s_it->second.size();
00122      for (; iTk!=maxItk; iTk++){
00123        
00124        RecoChargedCandidateRef & cand=L1toL3s_it->second[iTk];
00125        TrackRef tk = cand->track();
00126 
00127       if (fabs(tk->eta())>max_Eta_) continue;
00128 
00129       // cut on number of hits
00130       if (tk->numberOfValidHits()<min_Nhits_) continue;
00131 
00132       //dr cut
00133       //if (fabs(tk->d0())>max_Dr_) continue;
00134       if (fabs(tk->dxy(beamSpot.position()))>max_Dr_) continue;
00135 
00136       //dz cut
00137       if (fabs(tk->dz())>max_Dz_) continue;
00138 
00139       // Pt threshold cut
00140       double pt = tk->pt();
00141       double err0 = tk->error(0);
00142       double abspar0 = fabs(tk->parameter(0));
00143       double ptLx = pt;
00144       // convert 50% efficiency threshold to 90% efficiency threshold
00145       if (abspar0>0) ptLx += nsigma_Pt_*err0/abspar0*pt;
00146       LogTrace("HLTMuonL1toL3TkPreFilter") << " ...Muon in loop, pt= "
00147             << pt << ", ptLx= " << ptLx;
00148       if (ptLx<min_Pt_) continue;
00149 
00150       //one good L3Tk
00151       filterproduct->addObject(TriggerMuon,cand);      
00152       break; // and go on with the next L1 association
00153      }
00154 
00155    }//loop over L1s from L3 grouping
00156 
00157 
00158    vector<RecoChargedCandidateRef> vref;
00159    filterproduct->getObjects(TriggerMuon,vref);
00160    for (unsigned int i=0; i<vref.size(); i++ ) {
00161      TrackRef tk = vref[i]->track();
00162      LogDebug("HLTMuonL1toL3TkPreFilter")
00163        << " Track passing filter: pt= " << tk->pt() << ", eta: " 
00164        << tk->eta();
00165    }
00166    
00167    // filter decision
00168    const bool accept ((int)n >= min_N_);
00169    
00170    // put filter object into the Event
00171    iEvent.put(filterproduct);
00172    
00173    LogDebug("HLTMuonL1toL3TkPreFilter") << " >>>>> Result of HLTMuonL1toL3TkPreFilter is " << accept << ", number of muons passing thresholds= " << n; 
00174    
00175    return accept;
00176 }
00177 bool
00178 HLTMuonL1toL3TkPreFilter::triggeredAtL1(const l1extra::L1MuonParticleRef & l1mu,std::vector<l1extra::L1MuonParticleRef>& vcands)
00179 {
00180   bool ok=false;
00181 
00182   // compare to previously triggered L1
00183   for (unsigned int i=0; i<vcands.size(); i++) {
00184     //    l1extra::L1MuonParticleRef candref =  L1MuonParticleRef(vcands[i]);
00185     if (vcands[i] == l1mu){
00186       ok=true;
00187       LogDebug("HLTMuonL1toL3TkPreFilter") << "The L1 mu triggered";
00188       break;}
00189   }
00190   return ok;
00191 }
00192