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  edm::ParameterSet regionBuilderPSet = cfg.getParameter<edm::ParameterSet>("MuonTrackingRegionBuilder");
32  theRegionBuilder = std::make_unique<MuonTrackingRegionBuilder>(regionBuilderPSet, consumesCollector());
33 }
34 
36 
38  //region builder
39 
40  /*
41  if(useTFileService_) {
42  edm::Service<TFileService> fs;
43  h_nSeedPerTrack = fs->make<TH1F>("nSeedPerTrack","nSeedPerTrack",76,-0.5,75.5);
44  h_nGoodSeedPerTrack = fs->make<TH1F>("nGoodSeedPerTrack","nGoodSeedPerTrack",75,-0.5,75.5);
45  h_nGoodSeedPerEvent = fs->make<TH1F>("nGoodSeedPerEvent","nGoodSeedPerEvent",75,-0.5,75.5);
46  } else {
47  h_nSeedPerTrack = 0;
48  h_nGoodSeedPerEvent = 0;
49  h_nGoodSeedPerTrack = 0;
50  }
51  */
52 }
53 
55  // Initialize the output product
56  std::unique_ptr<L3MuonTrajectorySeedCollection> result(new L3MuonTrajectorySeedCollection());
57 
58  // Region builder
59  theRegionBuilder->setEvent(ev, es);
60 
61  // Retrieve the Monte Carlo truth (SimTracks)
63  ev.getByLabel(theSimTrackCollectionLabel, theSimTracks);
64 
65  // Retrieve L2 muon collection
67  ev.getByLabel(theL2CollectionLabel, l2muonH);
68 
69  // Retrieve Seed collection
70  unsigned seedCollections = theSeedCollectionLabels.size();
71  std::vector<edm::Handle<edm::View<TrajectorySeed> > > theSeeds;
72  theSeeds.resize(seedCollections);
73  unsigned seed_size = 0;
74  for (unsigned iseed = 0; iseed < seedCollections; ++iseed) {
75  ev.getByLabel(theSeedCollectionLabels[iseed], theSeeds[iseed]);
76  seed_size += theSeeds[iseed]->size();
77  }
78 
79  // Loop on L2 muons
80  unsigned int imu = 0;
81  unsigned int imuMax = l2muonH->size();
82  // std::cout << "Found " << imuMax << " L2 muons" << std::endl;
83  for (; imu != imuMax; ++imu) {
84  // Make a ref to l2 muon
85  reco::TrackRef muRef(l2muonH, imu);
86 
87  // Cut on muons with low momenta
88  if (muRef->pt() < thePtCut || muRef->innerMomentum().Rho() < thePtCut || muRef->innerMomentum().R() < 2.5)
89  continue;
90 
91  // Define the region of interest
92  std::unique_ptr<RectangularEtaPhiTrackingRegion> region = theRegionBuilder->region(muRef);
93 
94  // Copy the collection of seeds (ahem, this is time consuming!)
95  std::vector<TrajectorySeed> tkSeeds;
96  std::set<unsigned> tkIds;
97  tkSeeds.reserve(seed_size);
98  for (unsigned iseed = 0; iseed < seedCollections; ++iseed) {
99  edm::Handle<edm::View<TrajectorySeed> > aSeedCollection = theSeeds[iseed];
100  unsigned nSeeds = aSeedCollection->size();
101  for (unsigned seednr = 0; seednr < nSeeds; ++seednr) {
102  // The seed
103  const BasicTrajectorySeed* aSeed = &((*aSeedCollection)[seednr]);
104 
105  // The SimTrack id associated to the first hit of the Seed
106  int simTrackId = static_cast<FastTrackerRecHit const&>(*aSeed->recHits().begin()).simTrackId(0);
107 
108  // Track already associated to a seed
109  std::set<unsigned>::iterator tkId = tkIds.find(simTrackId);
110  if (tkId != tkIds.end())
111  continue;
112 
113  const SimTrack& theSimTrack = (*theSimTracks)[simTrackId];
114 
115  if (clean(muRef, region.get(), aSeed, theSimTrack))
116  tkSeeds.push_back(*aSeed);
117  tkIds.insert(simTrackId);
118 
119  } // End loop on seeds
120 
121  } // End loop on seed collections
122 
123  // A plot
124  // if(h_nSeedPerTrack) h_nSeedPerTrack->Fill(tkSeeds.size());
125 
126  // Another plot
127  // if(h_nGoodSeedPerTrack) h_nGoodSeedPerTrack->Fill(tkSeeds.size());
128 
129  // Now create the Muon Trajectory Seed
130  unsigned int is = 0;
131  unsigned int isMax = tkSeeds.size();
132  for (; is != isMax; ++is) {
133  result->push_back(L3MuonTrajectorySeed(tkSeeds[is], muRef));
134  } // End of tk seed loop
135 
136  } // End of l2 muon loop
137 
138  // std::cout << "Found " << result->size() << " seeds for muons" << std::endl;
139 
140  // And yet another plot
141  // if(h_nGoodSeedPerEvent) h_nGoodSeedPerEvent->Fill(result->size());
142 
143  //put in the event
144  ev.put(std::move(result));
145 }
146 
149  const BasicTrajectorySeed* aSeed,
150  const SimTrack& theSimTrack) {
151  // Eta cleaner
152  const PixelRecoRange<float>& etaRange = region->etaRange();
153  double etaSeed = theSimTrack.momentum().Eta();
154  double etaLimit = (fabs(fabs(etaRange.max()) - fabs(etaRange.mean())) < 0.05)
155  ? 0.05
156  : fabs(fabs(etaRange.max()) - fabs(etaRange.mean()));
157  bool inEtaRange = etaSeed >= (etaRange.mean() - etaLimit) && etaSeed <= (etaRange.mean() + etaLimit);
158  if (!inEtaRange)
159  return false;
160 
161  // Phi cleaner
162  const TkTrackingRegionsMargin<float>& phiMargin = region->phiMargin();
163  double phiSeed = theSimTrack.momentum().Phi();
164  double phiLimit = (phiMargin.right() < 0.05) ? 0.05 : phiMargin.right();
165  bool inPhiRange = (fabs(deltaPhi(phiSeed, double(region->direction().phi()))) < phiLimit);
166  if (!inPhiRange)
167  return false;
168 
169  // pt cleaner
170  double ptSeed = std::sqrt(theSimTrack.momentum().Perp2());
171  double ptMin = (region->ptMin() > 3.5) ? 3.5 : region->ptMin();
172  bool inPtRange = ptSeed >= ptMin && ptSeed <= 2 * (muRef->pt());
173  return inPtRange;
174 }
std::vector< edm::InputTag > theSeedCollectionLabels
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
edm::InputTag theSimTrackCollectionLabel
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:19
~FastTSGFromL2Muon() override
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
edm::InputTag theL2CollectionLabel
void beginRun(edm::Run const &run, edm::EventSetup const &es) override
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45