CMS 3D CMS Logo

TriggerMatcherToHLTDebug.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MuonAnalysis/MuonAssociators
4 // Class: TriggerMatcherToHLTDebug
5 //
13 //
14 // Original Author: Cristina Botta (Torino), Giovanni Petrucciani (UCSD)
15 // Created: Fri 30 Apr 2010
16 //
17 
18 
20 
22 
26 
29 
38 
39 //new for association map
47 
48 
53 
62 
66 
67 
68 
69 
70 
71 
73 
74  public:
75  // Constructor
77 
79  virtual ~TriggerMatcherToHLTDebug();
80 
81  // Operations
82  void produce(edm::Event & event, const edm::EventSetup& eventSetup) override;
83  void beginRun(const edm::Run &run, const edm::EventSetup &eventSetup) override;
84 
85  private:
86  typedef edm::AssociationMap<edm::OneToMany<std::vector<L2MuonTrajectorySeed>, std::vector<L2MuonTrajectorySeed> > > SeedMap;
87 
91 
93 
94  //ForL1Assoc
95  double deltaR_;
96 
97  //ForL1Quality
99 
100  //ForL2Filter
102  int min_N_L2;
103  double max_Eta_L2;
105  double max_Dr_L2;
106  double max_Dz_L2;
107  double min_Pt_L2;
108  double nsigma_Pt_L2;
109 
110  //ForL3Filter
111  int min_N_L3;
112  double max_Eta_L3;
114  double max_Dr_L3;
115  double max_Dz_L3;
116  double min_Pt_L3;
117  double nsigma_Pt_L3;
118 
125 
127  template<typename T>
130  const std::vector<T> & values,
131  const std::string & label) const ;
132 
133 };
134 
135 using namespace std;
136 using namespace edm;
137 using namespace l1extra;
138 using namespace reco;
139 
140 // Constructor
142  tagToken_(consumes<View<reco::Muon> >(pset.getParameter<edm::InputTag>("tags"))),
143  l1Token_(consumes<L1MuonParticleCollection>(pset.getParameter<edm::InputTag>("l1s"))),
144  l1matcher_(pset.getParameter<edm::ParameterSet>("l1matcherConfig")),
145  deltaR_(pset.getParameter<double>("deltaR")),
146  minL1Quality_(pset.getParameter<int32_t>("MinL1Quality")),
147  beamspotToken_(consumes<BeamSpot>(pset.getParameter<edm::InputTag>("BeamSpotTag"))),
148  min_N_L2(pset.getParameter<int> ("MinN_L2")),
149  max_Eta_L2(pset.getParameter<double> ("MaxEta_L2")),
150  min_Nhits_L2(pset.getParameter<int> ("MinNhits_L2")),
151  max_Dr_L2(pset.getParameter<double> ("MaxDr_L2")),
152  max_Dz_L2(pset.getParameter<double> ("MaxDz_L2")),
153  min_Pt_L2(pset.getParameter<double> ("MinPt_L2")),
154  nsigma_Pt_L2(pset.getParameter<double> ("NSigmaPt_L2")),
155  min_N_L3(pset.getParameter<int> ("MinN_L3")),
156  max_Eta_L3(pset.getParameter<double> ("MaxEta_L3")),
157  min_Nhits_L3(pset.getParameter<int> ("MinNhits_L3")),
158  max_Dr_L3(pset.getParameter<double> ("MaxDr_L3")),
159  max_Dz_L3(pset.getParameter<double> ("MaxDz_L3")),
160  min_Pt_L3(pset.getParameter<double> ("MinPt_L3")),
161  nsigma_Pt_L3(pset.getParameter<double> ("NSigmaPt_L3")),
162  seedMapToken_(consumes<SeedMap>(pset.getParameter<edm::InputTag >("SeedMapTag")))
163 {
164 
165 
166  theL2SeedsToken_ = consumes<L2MuonTrajectorySeedCollection>(pset.getParameter<InputTag>("L2Seeds_Collection"));
167  theL2MuonsToken_ = consumes<RecoChargedCandidateCollection>(pset.getParameter<InputTag>("L2Muons_Collection"));
168  theL3SeedsToken_ = consumes<L3MuonTrajectorySeedCollection>(pset.getParameter<InputTag>("L3Seeds_Collection"));
169  theL3TkTracksToken_ = consumes<TrackCollection>(pset.getParameter<InputTag>("L3TkTracks_Collection"));
170  theL3MuonsToken_ = consumes<RecoChargedCandidateCollection>(pset.getParameter<InputTag>("L3Muons_Collection"));
171 
172 
173  metname = "TriggerMatcherToHLTDebug";
174 
175  produces<edm::ValueMap<int> > ("propagatesToM2");
176  produces<edm::ValueMap<int> > ("hasL1Particle");
177  produces<edm::ValueMap<int> > ("hasL1Filtered");
178  produces<edm::ValueMap<int> > ("hasL2Seed");
179  produces<edm::ValueMap<int> > ("hasL2Muon");
180  produces<edm::ValueMap<int> > ("hasL2MuonFiltered");
181  produces<edm::ValueMap<int> > ("hasL3Seed");
182  produces<edm::ValueMap<int> > ("hasL3Track");
183  produces<edm::ValueMap<int> > ("hasL3Muon");
184  produces<edm::ValueMap<int> > ("hasL3MuonFiltered");
185 
186  produces<edm::ValueMap<reco::CandidatePtr> > ("l1Candidate");
187  produces<edm::ValueMap<reco::CandidatePtr> > ("l2Candidate");
188  produces<edm::ValueMap<reco::CandidatePtr> > ("l3Candidate");
189 }
190 
191 
192 
193 // Destructor
195 
196 // Analyzer
198 
200  event.getByToken(tagToken_,muons);
201 
203  event.getByToken(l1Token_,L1Muons);
204 
206  event.getByToken(theL2SeedsToken_,L2Seeds);
207 
209  event.getByToken(theL2MuonsToken_,L2Muons);
210 
212  event.getByToken(theL3SeedsToken_,L3Seeds);
213 
215  event.getByToken(theL3TkTracksToken_,L3TkTracks);
216 
218  event.getByToken(theL3MuonsToken_,L3Muons);
219 
220  //beam spot
222  Handle<BeamSpot> recoBeamSpotHandle;
223  event.getByToken(beamspotToken_,recoBeamSpotHandle);
224  beamSpot = *recoBeamSpotHandle;
225 
226  //new for the MAP!!!!
227  edm::Handle<SeedMap> seedMapHandle;
228  event.getByToken(seedMapToken_, seedMapHandle);
229 
230 
231  size_t nmu = muons->size();
232  std::vector<int> propagatesToM2(nmu), hasL1Particle(nmu), hasL1Filtered(nmu);
233  std::vector<int> hasL2Seed(nmu), hasL2Muon(nmu), hasL2MuonFiltered(nmu);
234  std::vector<int> hasL3Seed(nmu), hasL3Track(nmu), hasL3TrackFiltered(nmu), hasL3Muon(nmu), hasL3MuonFiltered(nmu);
235  std::vector<reco::CandidatePtr> l1ptr(nmu), l2ptr(nmu), l3ptr(nmu);
236 
237  for (size_t i = 0; i < nmu; ++i) {
238  const reco::Muon &mu = (*muons)[i];
239 
240  // Propagate to muon station (using the L1 tool)
242  if (!stateAtMB2.isValid()) continue;
243  propagatesToM2[i] = 1;
244 
245  double etaTk = stateAtMB2.globalPosition().eta();
246  double phiTk = stateAtMB2.globalPosition().phi();
247  l1extra::L1MuonParticleCollection::const_iterator it;
248  vector<l1extra::L1MuonParticleRef>::const_iterator itMu3;
249  L2MuonTrajectorySeedCollection::const_iterator iSeed;
250  L3MuonTrajectorySeedCollection::const_iterator iSeedL3;
251  RecoChargedCandidateCollection::const_iterator iL2Muon;
252  reco::TrackCollection::const_iterator tktrackL3;
253  RecoChargedCandidateCollection::const_iterator iL3Muon;
254 
255  reco::CandidatePtr thisL1, thisL2, thisL3;
256  for(it = L1Muons->begin(); it != L1Muons->end(); ++it) {
257 
258  const L1MuGMTExtendedCand muonCand = (*it).gmtMuonCand();
259  unsigned int quality = muonCand.quality();
260 
261  double L1phi =(*it).phi();
262  double L1eta =(*it).eta();
263  double L1pt =(*it).pt();
264  double dR=deltaR(etaTk,phiTk,L1eta,L1phi);
265 
266  //CONDIZIONE-> CE NE E' UNA ASSOCIATA?
267  if (dR >= deltaR_) continue;
268  thisL1 = reco::CandidatePtr(L1Muons, it - L1Muons->begin());
269  if (!hasL1Particle[i]) l1ptr[i] = thisL1; // if nobody reached L1 before, then we're the best L1 found up to now.
270  hasL1Particle[i]++;
271 
272  if ((quality <= 3) || (L1pt<7)) continue;
273  if (!hasL1Filtered[i]) l1ptr[i] = thisL1; // if nobody reached L1 before, then we're the best L1 found up to now.
274  hasL1Filtered[i]++;
275 
276  if(!L2Seeds.isValid()) continue;
277  //LOOP SULLA COLLEZIONE DEI SEED
278  for( iSeed = L2Seeds->begin(); iSeed != L2Seeds->end(); ++iSeed) {
279 
280  l1extra::L1MuonParticleRef l1FromSeed = iSeed->l1Particle();
281  if (l1FromSeed.id() != L1Muons.id()) throw cms::Exception("CorruptData") << "You're using a different L1 collection than the one used by L2 seeds.\n";
282  if (l1FromSeed.key() != thisL1.key()) continue;
283  if (!hasL2Seed[i]) l1ptr[i] = thisL1; // if nobody reached here before, we're the best L1
284  hasL2Seed[i]++;
285 
286  if(!L2Muons.isValid()) continue;
287  //LOOP SULLA COLLEZIONE L2MUON
288  for( iL2Muon = L2Muons->begin(); iL2Muon != L2Muons->end(); ++iL2Muon) {
289 
290 
291  //MI FACCIO DARE REF E GUARDO SE E' UGUALE AL L2SEED ASSOCIATO
292  //BEFORE THE ASSOCIATION MAP!!!!!
293  //edm::Ref<L2MuonTrajectorySeedCollection> l2seedRef = iL2Muon->track()->seedRef().castTo<edm::Ref<L2MuonTrajectorySeedCollection> >();
294  //l1extra::L1MuonParticleRef l1FromL2 = l2seedRef->l1Particle();
295 
296  //if (l1FromL2.id() != l1FromSeed.id()) throw cms::Exception("CorruptData") << "You're using L2s with a different L1 collection than the one used by L2 seeds.\n";
297  //if (l1FromL2 != l1FromSeed) continue;
298 
299  //AFTER THE ASSOCIATION MAP
300  const edm::RefVector<L2MuonTrajectorySeedCollection>& seeds = (*seedMapHandle)[iL2Muon->track()->seedRef().castTo<edm::Ref<L2MuonTrajectorySeedCollection> >()];
301  // bool isTriggered = false;
302  for(size_t jjj=0; jjj<seeds.size(); jjj++){
303 
304  if(seeds[jjj]->l1Particle()!= l1FromSeed) continue;
305 
306  }
307 
308 
309  thisL2 = reco::CandidatePtr(L2Muons, iL2Muon - L2Muons->begin()) ;
310  if (!hasL2Muon[i]) { l1ptr[i] = thisL1; l2ptr[i] = thisL2; } // if nobody reached here before, we're the best L1 and L2)
311  hasL2Muon[i]++;
312 
313  LogTrace(metname) <<"L2MUON TROVATO!"<<endl;
314  const reco::Track & L2Track = *iL2Muon->track();
315  double Eta_L2= L2Track.eta();
316  double Pt_L2= L2Track.pt();
317  int nValidHits_L2= L2Track.numberOfValidHits();
318  double BSPos_L2 = L2Track.dxy(beamSpot.position());
319  double dz_L2 =L2Track.dz();
320  double err0_L2 = L2Track.error(0);
321  double abspar0_L2 = fabs(L2Track.parameter(0));
322  double ptLx_L2 = Pt_L2;
323  if (abspar0_L2>0) ptLx_L2 += nsigma_Pt_L2*err0_L2/abspar0_L2*Pt_L2;
324 
325  //GUARDO SE L2MUON ASSOCIATO AVREBBE PASSATO IL FILTRO
326  bool passFilter = (((fabs(Eta_L2))<=max_Eta_L2)&&(nValidHits_L2>=min_Nhits_L2)&&((fabs(BSPos_L2))<=max_Dr_L2)&&((fabs(dz_L2))<=max_Dz_L2)&&(ptLx_L2>=min_Pt_L2));
327  if (!passFilter) continue;
328  if (!hasL2MuonFiltered[i]) { l1ptr[i] = thisL1; l2ptr[i] = thisL2; } // if nobody reached here before, we're the best L1 and L2)
329  hasL2MuonFiltered[i]++;
330 
331  const reco::TrackRef L2FilteredRef = iL2Muon->track();
332 
333  //########L3 PART##############
334  if (!L3Seeds.isValid()) continue;
335  for (iSeedL3 = L3Seeds->begin(); iSeedL3!= L3Seeds->end(); ++iSeedL3){
336 
337  TrackRef staTrack = iSeedL3->l2Track();
338  if (staTrack!=L2FilteredRef) continue;
339  if (!hasL3Seed[i]) { l1ptr[i] = thisL1; l2ptr[i] = thisL2; } // if nobody reached here before, we're the best L1 and L2)
340  hasL3Seed[i]++;
341 
342  if (!L3TkTracks.isValid()) continue;
343  for (tktrackL3 = L3TkTracks->begin(); tktrackL3!= L3TkTracks->end(); ++tktrackL3){
344 
346  TrackRef staTrack2 = l3seedRef->l2Track();
347 
348  if (staTrack2!=L2FilteredRef) continue;
349  if (!hasL3Track[i]) { l1ptr[i] = thisL1; l2ptr[i] = thisL2; } // if nobody reached here before, we're the best L1 and L2)
350  hasL3Track[i]++;
351 
352  if (!L3Muons.isValid()) continue;
353  for (iL3Muon = L3Muons->begin(); iL3Muon != L3Muons->end(); ++iL3Muon) {
354 
355  edm::Ref<L3MuonTrajectorySeedCollection> l3seedRef2 = iL3Muon->track()->seedRef().castTo<edm::Ref<L3MuonTrajectorySeedCollection> >();
356  TrackRef staTrack3 = l3seedRef2->l2Track();
357 
358  if (staTrack3!=L2FilteredRef) continue;
359  thisL3 = reco::CandidatePtr(L3Muons, iL3Muon - L3Muons->begin());
360 
361  if (!hasL3Muon[i]) { l1ptr[i] = thisL1; l2ptr[i] = thisL2; l3ptr[i] = thisL3; } // if nobody reached here before, we're the best L1, L2, L3
362  hasL3Muon[i]++;
363 
364  const reco::Track &L3Track = *iL3Muon->track();
365  double Eta_L3= L3Track.eta();
366  double Pt_L3= L3Track.pt();
367  int nValidHits_L3= L3Track.numberOfValidHits();
368  double BSPos_L3 = L3Track.dxy(beamSpot.position());
369  double dz_L3 =L3Track.dz();
370  double err0_L3 = L3Track.error(0);
371  double abspar0_L3 = fabs(L3Track.parameter(0));
372  double ptLx_L3 = Pt_L3;
373 
374  if (abspar0_L3>0) ptLx_L3 += nsigma_Pt_L3*err0_L3/abspar0_L3*Pt_L3;
375 
376  if(((fabs(Eta_L3))<=max_Eta_L3)&&(nValidHits_L3>=min_Nhits_L3)&&((fabs(BSPos_L3))<=max_Dr_L3)&&((fabs(dz_L3))<=max_Dz_L3)&&(ptLx_L3>=min_Pt_L3)){
377 
378  if (!hasL3MuonFiltered[i]) { l1ptr[i] = thisL1; l2ptr[i] = thisL2; l3ptr[i] = thisL3; } // if nobody reached here before, we're the best L1, L2, L3
379  hasL3MuonFiltered[i]++;
380 
381  }//L3MUON FILTERED ASSOCIATO TROVATO
382  }//L3MUON LOOP
383  }// L3 TRACKS
384  }// L3 SEEDS
385  }//T L2 MUONS
386  }// L2 SEEDS
387  }//L1 MUONS
388  } // RECO MUONS
389  storeValueMap<int>(event, muons, propagatesToM2, "propagatesToM2");
390  storeValueMap<int>(event, muons, hasL1Particle, "hasL1Particle");
391  storeValueMap<int>(event, muons, hasL1Filtered, "hasL1Filtered");
392  storeValueMap<int>(event, muons, hasL2Seed, "hasL2Seed");
393  storeValueMap<int>(event, muons, hasL2Muon, "hasL2Muon");
394  storeValueMap<int>(event, muons, hasL2MuonFiltered, "hasL2MuonFiltered");
395  storeValueMap<int>(event, muons, hasL3Seed, "hasL3Seed");
396  storeValueMap<int>(event, muons, hasL3Track, "hasL3Track");
397  storeValueMap<int>(event, muons, hasL3Muon, "hasL3Muon");
398  storeValueMap<int>(event, muons, hasL3MuonFiltered, "hasL3MuonFiltered");
399  storeValueMap<reco::CandidatePtr>(event, muons, l1ptr, "l1Candidate");
400  storeValueMap<reco::CandidatePtr>(event, muons, l2ptr, "l2Candidate");
401  storeValueMap<reco::CandidatePtr>(event, muons, l3ptr, "l3Candidate");
402 } // METHOD
403 
404 void
406  l1matcher_.init(iSetup);
407 }
408 
409 template<typename T>
410 void
413  const std::vector<T> & values,
414  const std::string & label) const {
415  using namespace edm; using namespace std;
416  unique_ptr<ValueMap<T> > valMap(new ValueMap<T>());
417  typename edm::ValueMap<T>::Filler filler(*valMap);
418  filler.insert(handle, values.begin(), values.end());
419  filler.fill();
420  iEvent.put(std::move(valMap), label);
421 }
422 
423 
424 
425 
T getParameter(std::string const &) const
TrajectoryStateOnSurface extrapolate(const reco::Track &tk) const
Extrapolate reco::Track to the muon station 2, return an invalid TSOS if it fails.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
key_type key() const
Definition: Ptr.h:185
ProductID id() const
Definition: HandleBase.cc:15
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void storeValueMap(edm::Event &iEvent, const edm::Handle< edm::View< reco::Muon > > &handle, const std::vector< T > &values, const std::string &label) const
Store extra information in a ValueMap.
edm::EDGetTokenT< l1extra::L1MuonParticleCollection > l1Token_
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
edm::EDGetTokenT< L3MuonTrajectorySeedCollection > theL3SeedsToken_
edm::EDGetTokenT< L2MuonTrajectorySeedCollection > theL2SeedsToken_
edm::EDGetTokenT< reco::RecoChargedCandidateCollection > theL2MuonsToken_
GlobalPoint globalPosition() const
key_type key() const
Accessor for product key.
Definition: Ref.h:265
edm::AssociationMap< edm::OneToMany< std::vector< L2MuonTrajectorySeed >, std::vector< L2MuonTrajectorySeed > > > SeedMap
edm::EDGetTokenT< reco::RecoChargedCandidateCollection > theL3MuonsToken_
ProductID id() const
Accessor for product ID.
Definition: Ref.h:259
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:230
Propagate an object (usually a track) to the second muon station. Support for other muon stations wil...
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:651
Definition: Muon.py:1
TriggerMatcherToHLTDebug(const edm::ParameterSet &pset)
virtual ~TriggerMatcherToHLTDebug()
Destructor.
double pt() const
track transverse momentum
Definition: TrackBase.h:621
double error(int i) const
error on specified element
Definition: TrackBase.h:751
edm::EDGetTokenT< SeedMap > seedMapToken_
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:820
const int mu
Definition: Constants.h:22
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:74
#define LogTrace(id)
double parameter(int i) const
i-th parameter ( i = 0, ... 4 )
Definition: TrackBase.h:739
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:609
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
edm::EDGetTokenT< edm::View< reco::Muon > > tagToken_
unsigned int quality() const
get quality
Definition: L1MuGMTCand.h:93
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
void init(const edm::EventSetup &iSetup)
Call this method at the beginning of each run, to initialize geometry, magnetic field and propagators...
void beginRun(const edm::Run &run, const edm::EventSetup &eventSetup) override
void produce(edm::Event &event, const edm::EventSetup &eventSetup) override
T eta() const
Definition: PV3DBase.h:76
fixed size matrix
HLT enums.
edm::EDGetTokenT< reco::BeamSpot > beamspotToken_
edm::EDGetTokenT< reco::TrackCollection > theL3TkTracksToken_
size_type size() const
Size of the RefVector.
Definition: RefVector.h:107
const Point & position() const
position
Definition: BeamSpot.h:62
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:591
def move(src, dest)
Definition: eostools.py:510
Definition: event.py:1
Definition: Run.h:42