CMS 3D CMS Logo

FastTSGFromL2Muon.cc
Go to the documentation of this file.
2 
7 
9 
11 
13 
15 
16 //#include <TH1.h>
17 
18 #include <set>
19 
21  produces<L3MuonTrajectorySeedCollection>();
22 
23  edm::ParameterSet serviceParameters = cfg.getParameter<edm::ParameterSet>("ServiceParameters");
24 
25  thePtCut = cfg.getParameter<double>("PtCut");
26 
27  theL2CollectionLabel = cfg.getParameter<edm::InputTag>("MuonCollectionLabel");
28  theSeedCollectionLabels = cfg.getParameter<std::vector<edm::InputTag> >("SeedCollectionLabels");
29  theSimTrackCollectionLabel = cfg.getParameter<edm::InputTag>("SimTrackCollectionLabel");
30  // useTFileService_ = cfg.getUntrackedParameter<bool>("UseTFileService",false);
31 }
32 
34 
36  //region builder
37  edm::ParameterSet regionBuilderPSet = theConfig.getParameter<edm::ParameterSet>("MuonTrackingRegionBuilder");
38  edm::ConsumesCollector iC = consumesCollector();
39  theRegionBuilder = new MuonTrackingRegionBuilder(regionBuilderPSet, iC);
40 
41  /*
42  if(useTFileService_) {
43  edm::Service<TFileService> fs;
44  h_nSeedPerTrack = fs->make<TH1F>("nSeedPerTrack","nSeedPerTrack",76,-0.5,75.5);
45  h_nGoodSeedPerTrack = fs->make<TH1F>("nGoodSeedPerTrack","nGoodSeedPerTrack",75,-0.5,75.5);
46  h_nGoodSeedPerEvent = fs->make<TH1F>("nGoodSeedPerEvent","nGoodSeedPerEvent",75,-0.5,75.5);
47  } else {
48  h_nSeedPerTrack = 0;
49  h_nGoodSeedPerEvent = 0;
50  h_nGoodSeedPerTrack = 0;
51  }
52  */
53 }
54 
56  // Initialize the output product
57  std::unique_ptr<L3MuonTrajectorySeedCollection> result(new L3MuonTrajectorySeedCollection());
58 
59  // Region builder
61 
62  // Retrieve the Monte Carlo truth (SimTracks)
64  ev.getByLabel(theSimTrackCollectionLabel, theSimTracks);
65 
66  // Retrieve L2 muon collection
68  ev.getByLabel(theL2CollectionLabel, l2muonH);
69 
70  // Retrieve Seed collection
71  unsigned seedCollections = theSeedCollectionLabels.size();
72  std::vector<edm::Handle<edm::View<TrajectorySeed> > > theSeeds;
73  theSeeds.resize(seedCollections);
74  unsigned seed_size = 0;
75  for (unsigned iseed = 0; iseed < seedCollections; ++iseed) {
76  ev.getByLabel(theSeedCollectionLabels[iseed], theSeeds[iseed]);
77  seed_size += theSeeds[iseed]->size();
78  }
79 
80  // Loop on L2 muons
81  unsigned int imu = 0;
82  unsigned int imuMax = l2muonH->size();
83  // std::cout << "Found " << imuMax << " L2 muons" << std::endl;
84  for (; imu != imuMax; ++imu) {
85  // Make a ref to l2 muon
86  reco::TrackRef muRef(l2muonH, imu);
87 
88  // Cut on muons with low momenta
89  if (muRef->pt() < thePtCut || muRef->innerMomentum().Rho() < thePtCut || muRef->innerMomentum().R() < 2.5)
90  continue;
91 
92  // Define the region of interest
93  std::unique_ptr<RectangularEtaPhiTrackingRegion> region = theRegionBuilder->region(muRef);
94 
95  // Copy the collection of seeds (ahem, this is time consuming!)
96  std::vector<TrajectorySeed> tkSeeds;
97  std::set<unsigned> tkIds;
98  tkSeeds.reserve(seed_size);
99  for (unsigned iseed = 0; iseed < seedCollections; ++iseed) {
100  edm::Handle<edm::View<TrajectorySeed> > aSeedCollection = theSeeds[iseed];
101  unsigned nSeeds = aSeedCollection->size();
102  for (unsigned seednr = 0; seednr < nSeeds; ++seednr) {
103  // The seed
104  const BasicTrajectorySeed* aSeed = &((*aSeedCollection)[seednr]);
105 
106  // Find the first hit of the Seed
107  TrajectorySeed::range theSeedingRecHitRange = aSeed->recHits();
108  const FastTrackerRecHit* theFirstSeedingRecHit = (const FastTrackerRecHit*)(&(*(theSeedingRecHitRange.first)));
109 
110  // The SimTrack id associated to that recHit
111  int simTrackId = theFirstSeedingRecHit->simTrackId(0);
112 
113  // Track already associated to a seed
114  std::set<unsigned>::iterator tkId = tkIds.find(simTrackId);
115  if (tkId != tkIds.end())
116  continue;
117 
118  const SimTrack& theSimTrack = (*theSimTracks)[simTrackId];
119 
120  if (clean(muRef, region.get(), aSeed, theSimTrack))
121  tkSeeds.push_back(*aSeed);
122  tkIds.insert(simTrackId);
123 
124  } // End loop on seeds
125 
126  } // End loop on seed collections
127 
128  // A plot
129  // if(h_nSeedPerTrack) h_nSeedPerTrack->Fill(tkSeeds.size());
130 
131  // Another plot
132  // if(h_nGoodSeedPerTrack) h_nGoodSeedPerTrack->Fill(tkSeeds.size());
133 
134  // Now create the Muon Trajectory Seed
135  unsigned int is = 0;
136  unsigned int isMax = tkSeeds.size();
137  for (; is != isMax; ++is) {
138  result->push_back(L3MuonTrajectorySeed(tkSeeds[is], muRef));
139  } // End of tk seed loop
140 
141  } // End of l2 muon loop
142 
143  // std::cout << "Found " << result->size() << " seeds for muons" << std::endl;
144 
145  // And yet another plot
146  // if(h_nGoodSeedPerEvent) h_nGoodSeedPerEvent->Fill(result->size());
147 
148  //put in the event
149  ev.put(std::move(result));
150 }
151 
154  const BasicTrajectorySeed* aSeed,
155  const SimTrack& theSimTrack) {
156  // Eta cleaner
157  const PixelRecoRange<float>& etaRange = region->etaRange();
158  double etaSeed = theSimTrack.momentum().Eta();
159  double etaLimit = (fabs(fabs(etaRange.max()) - fabs(etaRange.mean())) < 0.05)
160  ? 0.05
161  : fabs(fabs(etaRange.max()) - fabs(etaRange.mean()));
162  bool inEtaRange = etaSeed >= (etaRange.mean() - etaLimit) && etaSeed <= (etaRange.mean() + etaLimit);
163  if (!inEtaRange)
164  return false;
165 
166  // Phi cleaner
167  const TkTrackingRegionsMargin<float>& phiMargin = region->phiMargin();
168  double phiSeed = theSimTrack.momentum().Phi();
169  double phiLimit = (phiMargin.right() < 0.05) ? 0.05 : phiMargin.right();
170  bool inPhiRange = (fabs(deltaPhi(phiSeed, double(region->direction().phi()))) < phiLimit);
171  if (!inPhiRange)
172  return false;
173 
174  // pt cleaner
175  double ptSeed = std::sqrt(theSimTrack.momentum().Perp2());
176  double ptMin = (region->ptMin() > 3.5) ? 3.5 : region->ptMin();
177  bool inPtRange = ptSeed >= ptMin && ptSeed <= 2 * (muRef->pt());
178  return inPtRange;
179 }
T getParameter(std::string const &) const
std::pair< const_iterator, const_iterator > range
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
std::vector< edm::InputTag > theSeedCollectionLabels
T max() const
void produce(edm::Event &ev, const edm::EventSetup &es) override
virtual void setEvent(const edm::Event &)
Pass the Event to the algo at each event.
std::vector< L3MuonTrajectorySeed > L3MuonTrajectorySeedCollection
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
edm::InputTag theSimTrackCollectionLabel
bool ev
MuonTrackingRegionBuilder * theRegionBuilder
edm::ParameterSet theConfig
std::unique_ptr< RectangularEtaPhiTrackingRegion > region(const reco::TrackRef &) const
Define tracking region.
GlobalVector const & direction() const
the direction around which region is constructed
~FastTSGFromL2Muon() override
T sqrt(T t)
Definition: SSEVec.h:19
virtual int32_t simTrackId(size_t i) const
bool clean(reco::TrackRef muRef, RectangularEtaPhiTrackingRegion *region, const BasicTrajectorySeed *aSeed, const SimTrack &theSimTrack)
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
FastTSGFromL2Muon(const edm::ParameterSet &cfg)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:488
int iseed
Definition: AMPTWrapper.h:134
T mean() const
range recHits() const
float ptMin() const
minimal pt of interest
edm::InputTag theL2CollectionLabel
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:19
void beginRun(edm::Run const &run, edm::EventSetup const &es) override
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
const Range & etaRange() const
allowed eta range [eta_min, eta_max] interval