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