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  // The SimTrack id associated to the first hit of the Seed
107  int simTrackId = static_cast<FastTrackerRecHit const&>(*aSeed->recHits().begin()).simTrackId(0);
108 
109  // Track already associated to a seed
110  std::set<unsigned>::iterator tkId = tkIds.find(simTrackId);
111  if (tkId != tkIds.end())
112  continue;
113 
114  const SimTrack& theSimTrack = (*theSimTracks)[simTrackId];
115 
116  if (clean(muRef, region.get(), aSeed, theSimTrack))
117  tkSeeds.push_back(*aSeed);
118  tkIds.insert(simTrackId);
119 
120  } // End loop on seeds
121 
122  } // End loop on seed collections
123 
124  // A plot
125  // if(h_nSeedPerTrack) h_nSeedPerTrack->Fill(tkSeeds.size());
126 
127  // Another plot
128  // if(h_nGoodSeedPerTrack) h_nGoodSeedPerTrack->Fill(tkSeeds.size());
129 
130  // Now create the Muon Trajectory Seed
131  unsigned int is = 0;
132  unsigned int isMax = tkSeeds.size();
133  for (; is != isMax; ++is) {
134  result->push_back(L3MuonTrajectorySeed(tkSeeds[is], muRef));
135  } // End of tk seed loop
136 
137  } // End of l2 muon loop
138 
139  // std::cout << "Found " << result->size() << " seeds for muons" << std::endl;
140 
141  // And yet another plot
142  // if(h_nGoodSeedPerEvent) h_nGoodSeedPerEvent->Fill(result->size());
143 
144  //put in the event
145  ev.put(std::move(result));
146 }
147 
150  const BasicTrajectorySeed* aSeed,
151  const SimTrack& theSimTrack) {
152  // Eta cleaner
153  const PixelRecoRange<float>& etaRange = region->etaRange();
154  double etaSeed = theSimTrack.momentum().Eta();
155  double etaLimit = (fabs(fabs(etaRange.max()) - fabs(etaRange.mean())) < 0.05)
156  ? 0.05
157  : fabs(fabs(etaRange.max()) - fabs(etaRange.mean()));
158  bool inEtaRange = etaSeed >= (etaRange.mean() - etaLimit) && etaSeed <= (etaRange.mean() + etaLimit);
159  if (!inEtaRange)
160  return false;
161 
162  // Phi cleaner
163  const TkTrackingRegionsMargin<float>& phiMargin = region->phiMargin();
164  double phiSeed = theSimTrack.momentum().Phi();
165  double phiLimit = (phiMargin.right() < 0.05) ? 0.05 : phiMargin.right();
166  bool inPhiRange = (fabs(deltaPhi(phiSeed, double(region->direction().phi()))) < phiLimit);
167  if (!inPhiRange)
168  return false;
169 
170  // pt cleaner
171  double ptSeed = std::sqrt(theSimTrack.momentum().Perp2());
172  double ptMin = (region->ptMin() > 3.5) ? 3.5 : region->ptMin();
173  bool inPtRange = ptSeed >= ptMin && ptSeed <= 2 * (muRef->pt());
174  return inPtRange;
175 }
CoreSimTrack::momentum
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:19
FastTSGFromL2Muon::thePtCut
double thePtCut
Definition: FastTSGFromL2Muon.h:48
FastTSGFromL2Muon::theSimTrackCollectionLabel
edm::InputTag theSimTrackCollectionLabel
Definition: FastTSGFromL2Muon.h:41
RectangularEtaPhiTrackingRegion
Definition: RectangularEtaPhiTrackingRegion.h:25
L3MuonTrajectorySeedCollection.h
generateTowerEtThresholdLUT.etaRange
etaRange
Definition: generateTowerEtThresholdLUT.py:55
edm::Run
Definition: Run.h:45
deltaPhi.h
FastTSGFromL2Muon::theRegionBuilder
MuonTrackingRegionBuilder * theRegionBuilder
Definition: FastTSGFromL2Muon.h:49
ptMin
constexpr float ptMin
Definition: PhotonIDValueMapProducer.cc:155
MuonTrackingRegionBuilder::region
std::unique_ptr< RectangularEtaPhiTrackingRegion > region(const reco::TrackRef &) const
Define tracking region.
Definition: MuonTrackingRegionBuilder.cc:117
MuonTrackingRegionBuilder.h
edm::Handle< edm::SimTrackContainer >
edm::Ref< TrackCollection >
L3MuonTrajectorySeedCollection
std::vector< L3MuonTrajectorySeed > L3MuonTrajectorySeedCollection
Definition: L3MuonTrajectorySeedCollection.h:13
MuonTrackingRegionBuilder::setEvent
virtual void setEvent(const edm::Event &)
Pass the Event to the algo at each event.
Definition: MuonTrackingRegionBuilder.cc:124
seedmultiplicitymonitor_cfi.seedCollections
seedCollections
Definition: seedmultiplicitymonitor_cfi.py:5
Track.h
SiPixelRawToDigiRegional_cfi.deltaPhi
deltaPhi
Definition: SiPixelRawToDigiRegional_cfi.py:9
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
FastTSGFromL2Muon::FastTSGFromL2Muon
FastTSGFromL2Muon(const edm::ParameterSet &cfg)
Definition: FastTSGFromL2Muon.cc:20
FastTSGFromL2Muon::theConfig
edm::ParameterSet theConfig
Definition: FastTSGFromL2Muon.h:40
FastTSGFromL2Muon::clean
bool clean(reco::TrackRef muRef, RectangularEtaPhiTrackingRegion *region, const BasicTrajectorySeed *aSeed, const SimTrack &theSimTrack)
Definition: FastTSGFromL2Muon.cc:148
PixelRecoRange< float >
edm::ParameterSet
Definition: ParameterSet.h:47
iseed
int iseed
Definition: AMPTWrapper.h:134
edm::Range::begin
T begin() const
Definition: Range.h:15
Event.h
FastTSGFromL2Muon::~FastTSGFromL2Muon
~FastTSGFromL2Muon() override
Definition: FastTSGFromL2Muon.cc:33
HLT_FULL_cff.region
region
Definition: HLT_FULL_cff.py:84949
RectangularEtaPhiTrackingRegion.h
TkTrackingRegionsMargin< float >
edm::EventSetup
Definition: EventSetup.h:57
TrajectorySeed::recHits
RecHitRange recHits() const
Definition: TrajectorySeed.h:52
TkTrackingRegionsMargin::right
const T & right() const
Definition: TkTrackingRegionsMargin.h:19
looper.cfg
cfg
Definition: looper.py:297
FastTSGFromL2Muon::theL2CollectionLabel
edm::InputTag theL2CollectionLabel
Definition: FastTSGFromL2Muon.h:42
eostools.move
def move(src, dest)
Definition: eostools.py:511
writedatasetfile.run
run
Definition: writedatasetfile.py:27
SimTrack
Definition: SimTrack.h:6
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
TrajectorySeed
Definition: TrajectorySeed.h:18
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
FastTrackerRecHit.h
mps_fire.result
result
Definition: mps_fire.py:311
HLT_FULL_cff.MuonTrackingRegionBuilder
MuonTrackingRegionBuilder
Definition: HLT_FULL_cff.py:9730
edm::Event
Definition: Event.h:73
FastTSGFromL2Muon::theSeedCollectionLabels
std::vector< edm::InputTag > theSeedCollectionLabels
Definition: FastTSGFromL2Muon.h:43
L3MuonTrajectorySeed
Definition: L3MuonTrajectorySeed.h:16
SimTrackContainer.h
edm::InputTag
Definition: InputTag.h:15
FastTSGFromL2Muon::beginRun
void beginRun(edm::Run const &run, edm::EventSetup const &es) override
Definition: FastTSGFromL2Muon.cc:35
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
FastTSGFromL2Muon.h
FastTSGFromL2Muon::produce
void produce(edm::Event &ev, const edm::EventSetup &es) override
Definition: FastTSGFromL2Muon.cc:55