CMS 3D CMS Logo

HLTMuonL1toL3TkPreFilter.cc
Go to the documentation of this file.
1 
10 
13 
16 
25 
27 
28 //
29 // constructors and destructor
30 //
31 using namespace std;
32 using namespace edm;
33 using namespace reco;
34 using namespace trigger;
35 
37  beamspotTag_ (iConfig.getParameter< edm::InputTag > ("BeamSpotTag")),
38  beamspotToken_ (consumes<reco::BeamSpot>(beamspotTag_)),
39  candTag_ (iConfig.getParameter<InputTag > ("CandTag")),
40  candToken_ (consumes<reco::RecoChargedCandidateCollection>(candTag_)),
41  previousCandTag_ (iConfig.getParameter<InputTag > ("PreviousCandTag")),
42  previousCandToken_ (consumes<trigger::TriggerFilterObjectWithRefs>(previousCandTag_)),
43  min_N_ (iConfig.getParameter<int> ("MinN")),
44  max_Eta_ (iConfig.getParameter<double> ("MaxEta")),
45  min_Nhits_ (iConfig.getParameter<int> ("MinNhits")),
46  max_Dr_ (iConfig.getParameter<double> ("MaxDr")),
47  max_Dz_ (iConfig.getParameter<double> ("MaxDz")),
48  min_Pt_ (iConfig.getParameter<double> ("MinPt")),
49  nsigma_Pt_ (iConfig.getParameter<double> ("NSigmaPt"))
50 {
51 
52  LogDebug("HLTMuonL1toL3TkPreFilter")
53  << " CandTag/MinN/MaxEta/MinNhits/MaxDr/MaxDz/MinPt/NSigmaPt : "
54  << candTag_.encode()
55  << " " << min_N_
56  << " " << max_Eta_
57  << " " << min_Nhits_
58  << " " << max_Dr_
59  << " " << max_Dz_
60  << " " << min_Pt_
61  << " " << nsigma_Pt_;
62 
63  //register your products
64  produces<TriggerFilterObjectWithRefs>();
65 }
66 
68 
69 //
70 // member functions
71 //
72 void
76  desc.add<edm::InputTag>("BeamSpotTag",edm::InputTag("hltBeamSpotTag"));
77  desc.add<edm::InputTag>("CandTag",edm::InputTag("hltCandTag"));
78  desc.add<edm::InputTag>("PreviousCandTag",edm::InputTag("hltPreviousCandTag"));
79  desc.add<int>("MinN",0);
80  desc.add<double>("MaxEta",9999.0);
81  desc.add<int>("MinNhits",0);
82  desc.add<double>("MaxDr",9999.0);
83  desc.add<double>("MaxDz",9999.0);
84  desc.add<double>("MinPt",0.0);
85  desc.add<double>("NSigmaPt",9999.0);
86  descriptions.add("hltMuonL1toL3TkPreFilter", desc);
87 }
88 
89 // ------------ method called to produce the data ------------
90 bool
92 {
93 
94  // All HLT filters must create and fill an HLT filter object,
95  // recording any reconstructed physics objects satisfying (or not)
96  // this HLT filter, and place it in the Event.
97 
98  // get hold of trks
100  iEvent.getByToken(candToken_,mucands);
101  if (saveTags()) filterproduct.addCollectionTag(candTag_);
102  // sort them by L2Track
103  std::map<l1extra::L1MuonParticleRef, std::vector<RecoChargedCandidateRef> > L1toL3s;
104  unsigned int n = 0;
105  unsigned int maxN = mucands->size();
106  for (;n!=maxN;n++){
107  TrackRef tk = (*mucands)[n].track();
109  l1extra::L1MuonParticleRef l1mu = l3seedRef->l1Particle();
110  L1toL3s[l1mu].push_back(RecoChargedCandidateRef(mucands,n));
111  }
112 
113  // additionnal objects needed
114  Handle<TriggerFilterObjectWithRefs> previousLevelCands;
115  iEvent.getByToken(previousCandToken_,previousLevelCands);
117  Handle<BeamSpot> recoBeamSpotHandle;
118  iEvent.getByToken(beamspotToken_,recoBeamSpotHandle);
119  beamSpot = *recoBeamSpotHandle;
120 
121 
122  //needed to compare to L1
123  vector<l1extra::L1MuonParticleRef> vl1cands;
124  previousLevelCands->getObjects(TriggerL1Mu,vl1cands);
125 
126  auto L1toL3s_it = L1toL3s.begin();
127  auto L1toL3s_end = L1toL3s.end();
128  for (; L1toL3s_it!=L1toL3s_end; ++L1toL3s_it){
129 
130  if (!triggeredAtL1(L1toL3s_it->first,vl1cands)) continue;
131 
132  //loop over the L3Tk reconstructed for this L1.
133  unsigned int iTk=0;
134  unsigned int maxItk=L1toL3s_it->second.size();
135  for (; iTk!=maxItk; iTk++){
136 
137  RecoChargedCandidateRef & cand=L1toL3s_it->second[iTk];
138  TrackRef tk = cand->track();
139 
140  if (fabs(tk->eta())>max_Eta_) continue;
141 
142  // cut on number of hits
143  if (tk->numberOfValidHits()<min_Nhits_) continue;
144 
145  //dr cut
146  //if (fabs(tk->d0())>max_Dr_) continue;
147  if (fabs(tk->dxy(beamSpot.position()))>max_Dr_) continue;
148 
149  //dz cut
150  if (fabs(tk->dz())>max_Dz_) continue;
151 
152  // Pt threshold cut
153  double pt = tk->pt();
154  double err0 = tk->error(0);
155  double abspar0 = fabs(tk->parameter(0));
156  double ptLx = pt;
157  // convert 50% efficiency threshold to 90% efficiency threshold
158  if (abspar0>0) ptLx += nsigma_Pt_*err0/abspar0*pt;
159  LogTrace("HLTMuonL1toL3TkPreFilter") << " ...Muon in loop, pt= "
160  << pt << ", ptLx= " << ptLx;
161  if (ptLx<min_Pt_) continue;
162 
163  //one good L3Tk
164  filterproduct.addObject(TriggerMuon,cand);
165  break; // and go on with the next L1 association
166  }
167 
168  }//loop over L1s from L3 grouping
169 
170 
171  vector<RecoChargedCandidateRef> vref;
172  filterproduct.getObjects(TriggerMuon,vref);
173  for (auto & i : vref) {
174  TrackRef tk = i->track();
175  LogDebug("HLTMuonL1toL3TkPreFilter")
176  << " Track passing filter: pt= " << tk->pt() << ", eta: "
177  << tk->eta();
178  }
179 
180  // filter decision
181  const bool accept ((int)n >= min_N_);
182 
183  LogDebug("HLTMuonL1toL3TkPreFilter") << " >>>>> Result of HLTMuonL1toL3TkPreFilter is " << accept << ", number of muons passing thresholds= " << n;
184 
185  return accept;
186 }
187 
188 bool
189 HLTMuonL1toL3TkPreFilter::triggeredAtL1(const l1extra::L1MuonParticleRef & l1mu,std::vector<l1extra::L1MuonParticleRef>& vcands) const
190 {
191  bool ok=false;
192 
193  // compare to previously triggered L1
194  for (auto & vcand : vcands) {
195  // l1extra::L1MuonParticleRef candref = L1MuonParticleRef(vcands[i]);
196  if (vcand == l1mu){
197  ok=true;
198  LogDebug("HLTMuonL1toL3TkPreFilter") << "The L1 mu triggered";
199  break;}
200  }
201  return ok;
202 }
203 
204 
205 // declare this class as a framework plugin
#define LogDebug(id)
edm::EDGetTokenT< reco::BeamSpot > beamspotToken_
bool hltFilter(edm::Event &, const edm::EventSetup &, trigger::TriggerFilterObjectWithRefs &filterproduct) const override
void getObjects(Vids &ids, VRphoton &refs) const
various physics-level getters:
edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > previousCandToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
enum start value shifted to 81 so as to avoid clashes with PDG codes
HLTMuonL1toL3TkPreFilter(const edm::ParameterSet &)
edm::Ref< RecoChargedCandidateCollection > RecoChargedCandidateRef
reference to an object in a collection of RecoChargedCandidate objects
edm::EDGetTokenT< reco::RecoChargedCandidateCollection > candToken_
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
std::string encode() const
Definition: InputTag.cc:159
void addObject(int id, const reco::RecoEcalCandidateRef &ref)
setters for L3 collections: (id=physics type, and Ref<C>)
~HLTMuonL1toL3TkPreFilter() override
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ParameterDescriptionBase * add(U const &iLabel, T const &value)
#define LogTrace(id)
std::vector< RecoChargedCandidate > RecoChargedCandidateCollection
collectin of RecoChargedCandidate objects
bool triggeredAtL1(const l1extra::L1MuonParticleRef &l1mu, std::vector< l1extra::L1MuonParticleRef > &vcands) const
static void makeHLTFilterDescription(edm::ParameterSetDescription &desc)
Definition: HLTFilter.cc:29
void addCollectionTag(const edm::InputTag &collectionTag)
collectionTags
void add(std::string const &label, ParameterSetDescription const &psetDescription)
fixed size matrix
bool saveTags() const
Definition: HLTFilter.h:45
HLT enums.
const Point & position() const
position
Definition: BeamSpot.h:62
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)