CMS 3D CMS Logo

FastTSGFromL2Muon.cc
Go to the documentation of this file.
2 
5 
10 
13 
14 #include <set>
15 
17  : thePtCut(cfg.getParameter<double>("PtCut")),
18  theL2CollectionLabel(cfg.getParameter<edm::InputTag>("MuonCollectionLabel")),
19  theSeedCollectionLabels(cfg.getParameter<std::vector<edm::InputTag> >("SeedCollectionLabels")),
20  theSimTrackCollectionLabel(cfg.getParameter<edm::InputTag>("SimTrackCollectionLabel")),
21  simTrackToken_(consumes<edm::SimTrackContainer>(theSimTrackCollectionLabel)),
22  l2TrackToken_(consumes<reco::TrackCollection>(theL2CollectionLabel)) {
23  produces<L3MuonTrajectorySeedCollection>();
24 
25  for (auto& seed : theSeedCollectionLabels)
26  seedToken_.emplace_back(consumes<edm::View<TrajectorySeed> >(seed));
27 
28  edm::ParameterSet regionBuilderPSet = cfg.getParameter<edm::ParameterSet>("MuonTrackingRegionBuilder");
29  theRegionBuilder = std::make_unique<MuonTrackingRegionBuilder>(regionBuilderPSet, consumesCollector());
30 }
31 
33  // Initialize the output product
34  std::unique_ptr<L3MuonTrajectorySeedCollection> result(new L3MuonTrajectorySeedCollection());
35 
36  // Region builder
37  theRegionBuilder->setEvent(ev, es);
38 
39  // Retrieve the Monte Carlo truth (SimTracks)
40  const edm::Handle<edm::SimTrackContainer>& theSimTracks = ev.getHandle(simTrackToken_);
41 
42  // Retrieve L2 muon collection
43  const edm::Handle<reco::TrackCollection>& l2muonH = ev.getHandle(l2TrackToken_);
44 
45  // Retrieve Seed collection
46  unsigned seedCollections = theSeedCollectionLabels.size();
47  std::vector<edm::Handle<edm::View<TrajectorySeed> > > theSeeds;
48  theSeeds.resize(seedCollections);
49  unsigned seed_size = 0;
50  for (unsigned iseed = 0; iseed < seedCollections; ++iseed) {
51  ev.getByToken(seedToken_[iseed], theSeeds[iseed]);
52  seed_size += theSeeds[iseed]->size();
53  }
54 
55  // Loop on L2 muons
56  unsigned int imu = 0;
57  unsigned int imuMax = l2muonH->size();
58  edm::LogVerbatim("FastTSGFromL2Muon") << "Found " << imuMax << " L2 muons";
59  for (; imu != imuMax; ++imu) {
60  // Make a ref to l2 muon
61  reco::TrackRef muRef(l2muonH, imu);
62 
63  // Cut on muons with low momenta
64  if (muRef->pt() < thePtCut || muRef->innerMomentum().Rho() < thePtCut || muRef->innerMomentum().R() < 2.5)
65  continue;
66 
67  // Define the region of interest
68  std::unique_ptr<RectangularEtaPhiTrackingRegion> region = theRegionBuilder->region(muRef);
69 
70  // Copy the collection of seeds (ahem, this is time consuming!)
71  std::vector<TrajectorySeed> tkSeeds;
72  std::set<unsigned> tkIds;
73  tkSeeds.reserve(seed_size);
74  for (unsigned iseed = 0; iseed < seedCollections; ++iseed) {
75  edm::Handle<edm::View<TrajectorySeed> > aSeedCollection = theSeeds[iseed];
76  unsigned nSeeds = aSeedCollection->size();
77  for (unsigned seednr = 0; seednr < nSeeds; ++seednr) {
78  // The seed
79  const BasicTrajectorySeed* aSeed = &((*aSeedCollection)[seednr]);
80 
81  // The SimTrack id associated to the first hit of the Seed
82  int simTrackId = static_cast<FastTrackerRecHit const&>(*aSeed->recHits().begin()).simTrackId(0);
83 
84  // Track already associated to a seed
85  std::set<unsigned>::iterator tkId = tkIds.find(simTrackId);
86  if (tkId != tkIds.end())
87  continue;
88 
89  const SimTrack& theSimTrack = (*theSimTracks)[simTrackId];
90 
91  if (clean(muRef, region.get(), aSeed, theSimTrack))
92  tkSeeds.push_back(*aSeed);
93  tkIds.insert(simTrackId);
94 
95  } // End loop on seeds
96 
97  } // End loop on seed collections
98 
99  // Now create the Muon Trajectory Seed
100  unsigned int is = 0;
101  unsigned int isMax = tkSeeds.size();
102  for (; is != isMax; ++is) {
103  result->push_back(L3MuonTrajectorySeed(tkSeeds[is], muRef));
104  } // End of tk seed loop
105 
106  } // End of l2 muon loop
107 
108  edm::LogVerbatim("FastTSGFromL2Muon") << "Found " << result->size() << " seeds for muons";
109 
110  //put in the event
111  ev.put(std::move(result));
112 }
113 
116  const BasicTrajectorySeed* aSeed,
117  const SimTrack& theSimTrack) {
118  // Eta cleaner
119  const PixelRecoRange<float>& etaRange = region->etaRange();
120  double etaSeed = theSimTrack.momentum().Eta();
121  double etaLimit = (fabs(fabs(etaRange.max()) - fabs(etaRange.mean())) < 0.05)
122  ? 0.05
123  : fabs(fabs(etaRange.max()) - fabs(etaRange.mean()));
124  bool inEtaRange = etaSeed >= (etaRange.mean() - etaLimit) && etaSeed <= (etaRange.mean() + etaLimit);
125  if (!inEtaRange)
126  return false;
127 
128  // Phi cleaner
129  const TkTrackingRegionsMargin<float>& phiMargin = region->phiMargin();
130  double phiSeed = theSimTrack.momentum().Phi();
131  double phiLimit = (phiMargin.right() < 0.05) ? 0.05 : phiMargin.right();
132  bool inPhiRange = (fabs(deltaPhi(phiSeed, double(region->direction().phi()))) < phiLimit);
133  if (!inPhiRange)
134  return false;
135 
136  // pt cleaner
137  double ptSeed = std::sqrt(theSimTrack.momentum().Perp2());
138  double ptMin = (region->ptMin() > 3.5) ? 3.5 : region->ptMin();
139  bool inPtRange = ptSeed >= ptMin && ptSeed <= 2 * (muRef->pt());
140  return inPtRange;
141 }
Log< level::Info, true > LogVerbatim
const double thePtCut
const edm::EDGetTokenT< edm::SimTrackContainer > simTrackToken_
void produce(edm::Event &ev, const edm::EventSetup &es) override
T begin() const
Definition: Range.h:15
RecHitRange recHits() const
std::vector< L3MuonTrajectorySeed > L3MuonTrajectorySeedCollection
constexpr float ptMin
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::vector< edm::EDGetTokenT< edm::View< TrajectorySeed > > > seedToken_
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:19
const edm::EDGetTokenT< reco::TrackCollection > l2TrackToken_
T sqrt(T t)
Definition: SSEVec.h:19
std::unique_ptr< MuonTrackingRegionBuilder > theRegionBuilder
bool clean(reco::TrackRef muRef, RectangularEtaPhiTrackingRegion *region, const BasicTrajectorySeed *aSeed, const SimTrack &theSimTrack)
FastTSGFromL2Muon(const edm::ParameterSet &cfg)
int iseed
Definition: AMPTWrapper.h:134
const std::vector< edm::InputTag > theSeedCollectionLabels
fixed size matrix
HLT enums.
std::vector< SimTrack > SimTrackContainer
def move(src, dest)
Definition: eostools.py:511