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 }
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
TrajectorySeed::range
std::pair< const_iterator, const_iterator > range
Definition: TrajectorySeed.h:21
edm::Run
Definition: Run.h:45
FastTSGFromL2Muon::theRegionBuilder
MuonTrackingRegionBuilder * theRegionBuilder
Definition: FastTSGFromL2Muon.h:49
ptMin
constexpr float ptMin
Definition: PhotonIDValueMapProducer.cc:153
MuonTrackingRegionBuilder::region
std::unique_ptr< RectangularEtaPhiTrackingRegion > region(const reco::TrackRef &) const
Define tracking region.
Definition: MuonTrackingRegionBuilder.cc:117
FastTrackerRecHit
Definition: FastTrackerRecHit.h:40
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:152
FastTrackerRecHit::simTrackId
virtual int32_t simTrackId(size_t i) const
Definition: FastTrackerRecHit.h:99
PixelRecoRange< float >
edm::ParameterSet
Definition: ParameterSet.h:36
iseed
int iseed
Definition: AMPTWrapper.h:134
Event.h
FastTSGFromL2Muon::~FastTSGFromL2Muon
~FastTSGFromL2Muon() override
Definition: FastTSGFromL2Muon.cc:33
RectangularEtaPhiTrackingRegion.h
TkTrackingRegionsMargin< float >
edm::EventSetup
Definition: EventSetup.h:57
TkTrackingRegionsMargin::right
const T & right() const
Definition: TkTrackingRegionsMargin.h:19
HLT_2018_cff.MuonTrackingRegionBuilder
MuonTrackingRegionBuilder
Definition: HLT_2018_cff.py:8346
looper.cfg
cfg
Definition: looper.py:297
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
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
HLT_2018_cff.region
region
Definition: HLT_2018_cff.py:81479
TrajectorySeed::recHits
range recHits() const
Definition: TrajectorySeed.h:52
TrajectorySeed
Definition: TrajectorySeed.h:17
FastTrackerRecHit.h
mps_fire.result
result
Definition: mps_fire.py:303
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:39
FastTSGFromL2Muon.h
deltaPhi.h
FastTSGFromL2Muon::produce
void produce(edm::Event &ev, const edm::EventSetup &es) override
Definition: FastTSGFromL2Muon.cc:55