HLTMuonL2ToL1TMap

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
#ifndef HLTMuonL2ToL1TMap_h
#define HLTMuonL2ToL1TMap_h

/** \class HLTMuonL2ToL1TMap
 *
 *  
 *  This is a helper class to check L2 to L1 links
 *
 *  \author Z. Gecse
 *
 */

#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"
#include "DataFormats/MuonSeed/interface/L2MuonTrajectorySeedCollection.h"
#include "DataFormats/Common/interface/AssociationMap.h"
#include "DataFormats/Common/interface/OneToMany.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
#include "DataFormats/L1Trigger/interface/Muon.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Utilities/interface/EDGetToken.h"

typedef edm::AssociationMap<edm::OneToMany<std::vector<L2MuonTrajectorySeed>, std::vector<L2MuonTrajectorySeed> > >
    SeedMap;

class HLTMuonL2ToL1TMap {
public:
  /// construct with the Token of the L1 filter object, the Token of the L2 seed map ("hltL2Muons") and the Event
  explicit HLTMuonL2ToL1TMap(const edm::EDGetTokenT<trigger::TriggerFilterObjectWithRefs>& previousCandToken,
                             const edm::EDGetTokenT<SeedMap> seedMapToken,
                             const edm::Event& iEvent) {
    // get hold of muons that fired the previous level
    edm::Handle<trigger::TriggerFilterObjectWithRefs> previousLevelCands;
    iEvent.getByToken(previousCandToken, previousLevelCands);
    previousLevelCands->getObjects(trigger::TriggerL1Mu, firedL1Muons_);

    // get hold of the seed map
    iEvent.getByToken(seedMapToken, seedMapHandle_);
  }

  ~HLTMuonL2ToL1TMap() {}

  /// checks if a L2 muon was seeded by a fired L1
  bool isTriggeredByL1(reco::TrackRef& l2muon) {
    bool isTriggered = false;
    const edm::RefVector<L2MuonTrajectorySeedCollection>& seeds =
        (*seedMapHandle_)[l2muon->seedRef().castTo<edm::Ref<L2MuonTrajectorySeedCollection> >()];
    for (size_t i = 0; i < seeds.size(); i++) {
      if (find(firedL1Muons_.begin(), firedL1Muons_.end(), seeds[i]->l1tParticle()) != firedL1Muons_.end()) {
        isTriggered = true;
        break;
      }
    }
    return isTriggered;
  }

  /// returns the indices of L1 seeds
  std::string getL1Keys(reco::TrackRef& l2muon) {
    std::ostringstream ss;
    const edm::RefVector<L2MuonTrajectorySeedCollection>& seeds =
        (*seedMapHandle_)[l2muon->seedRef().castTo<edm::Ref<L2MuonTrajectorySeedCollection> >()];
    for (size_t i = 0; i < seeds.size(); i++) {
      ss << seeds[i]->l1tParticle().key() << " ";
    }
    return ss.str();
  }

private:
  /// contains the vector of references to fired L1 candidates
  std::vector<l1t::MuonRef> firedL1Muons_;

  /// containes the map from a L2 seed to its sister seeds the track of which has been cleaned
  edm::Handle<SeedMap> seedMapHandle_;
};

#endif  //HLTMuonL2ToL1TMap_h